From efbc9d9043ff8ff92716ddd00a5f61412d535593 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 9 Apr 2010 14:12:59 +0000 Subject: revert r1783 git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1785 10f7b99b-c216-0410-bff0-8a66a9350fd8 --- src/filters/parser/AviSplitter/AviFile.cpp | 1051 +++--- src/filters/parser/AviSplitter/AviFile.h | 90 +- src/filters/parser/AviSplitter/AviReportWnd.cpp | 558 ++- src/filters/parser/AviSplitter/AviReportWnd.h | 45 +- src/filters/parser/AviSplitter/AviSplitter.cpp | 1296 ++++--- src/filters/parser/AviSplitter/AviSplitter.h | 62 +- src/filters/parser/AviSplitter/resource.h | 2 +- src/filters/parser/AviSplitter/stdafx.cpp | 8 +- src/filters/parser/AviSplitter/stdafx.h | 8 +- src/filters/parser/BaseSplitter/AsyncReader.cpp | 276 +- src/filters/parser/BaseSplitter/AsyncReader.h | 130 +- src/filters/parser/BaseSplitter/BaseSplitter.cpp | 1722 ++++----- src/filters/parser/BaseSplitter/BaseSplitter.h | 559 ++- .../parser/BaseSplitter/BaseSplitterFile.cpp | 319 +- src/filters/parser/BaseSplitter/BaseSplitterFile.h | 67 +- .../parser/BaseSplitter/BaseSplitterFileEx.cpp | 2894 +++++++------- .../parser/BaseSplitter/BaseSplitterFileEx.h | 699 ++-- src/filters/parser/BaseSplitter/MultiFiles.cpp | 251 +- src/filters/parser/BaseSplitter/MultiFiles.h | 102 +- src/filters/parser/BaseSplitter/stdafx.cpp | 8 +- src/filters/parser/BaseSplitter/stdafx.h | 8 +- src/filters/parser/DSMSplitter/DSMSplitter.cpp | 294 +- src/filters/parser/DSMSplitter/DSMSplitter.h | 30 +- src/filters/parser/DSMSplitter/DSMSplitterFile.cpp | 677 ++-- src/filters/parser/DSMSplitter/DSMSplitterFile.h | 52 +- src/filters/parser/DSMSplitter/resource.h | 2 +- src/filters/parser/DSMSplitter/stdafx.cpp | 8 +- src/filters/parser/DSMSplitter/stdafx.h | 8 +- src/filters/parser/DiracSplitter/DiracSplitter.cpp | 127 +- src/filters/parser/DiracSplitter/DiracSplitter.h | 56 +- .../parser/DiracSplitter/DiracSplitterFile.cpp | 38 +- .../parser/DiracSplitter/DiracSplitterFile.h | 26 +- .../libdirac/libdirac_byteio/accessunit_byteio.cpp | 88 +- .../libdirac/libdirac_byteio/accessunit_byteio.h | 243 +- .../libdirac/libdirac_byteio/byteio.cpp | 110 +- .../libdirac/libdirac_byteio/byteio.h | 687 ++-- .../libdirac_byteio/codingparams_byteio.cpp | 34 +- .../libdirac/libdirac_byteio/codingparams_byteio.h | 150 +- .../libdirac/libdirac_byteio/component_byteio.cpp | 16 +- .../libdirac/libdirac_byteio/component_byteio.h | 130 +- .../libdirac/libdirac_byteio/dirac_byte_stats.cpp | 22 +- .../libdirac/libdirac_byteio/dirac_byte_stats.h | 125 +- .../libdirac/libdirac_byteio/dirac_byte_stream.cpp | 54 +- .../libdirac/libdirac_byteio/dirac_byte_stream.h | 194 +- .../libdirac_byteio/displayparams_byteio.cpp | 210 +- .../libdirac_byteio/displayparams_byteio.h | 284 +- .../libdirac_byteio/endofsequence_byteio.cpp | 12 +- .../libdirac_byteio/endofsequence_byteio.h | 96 +- .../libdirac/libdirac_byteio/mvdata_byteio.cpp | 154 +- .../libdirac/libdirac_byteio/mvdata_byteio.h | 439 +-- .../libdirac_byteio/mvdataelement_byteio.cpp | 10 +- .../libdirac_byteio/mvdataelement_byteio.h | 132 +- .../libdirac_byteio/parseparams_byteio.cpp | 58 +- .../libdirac/libdirac_byteio/parseparams_byteio.h | 114 +- .../libdirac/libdirac_byteio/parseunit_byteio.cpp | 64 +- .../libdirac/libdirac_byteio/parseunit_byteio.h | 395 +- .../libdirac/libdirac_byteio/picture_byteio.cpp | 92 +- .../libdirac/libdirac_byteio/picture_byteio.h | 314 +- .../libdirac/libdirac_byteio/subband_byteio.cpp | 42 +- .../libdirac/libdirac_byteio/subband_byteio.h | 114 +- .../libdirac/libdirac_byteio/transform_byteio.cpp | 50 +- .../libdirac/libdirac_byteio/transform_byteio.h | 172 +- .../libdirac/libdirac_common/arith_codec.cpp | 226 +- .../libdirac/libdirac_common/arith_codec.h | 661 ++-- .../libdirac/libdirac_common/arrays.h | 885 ++--- .../libdirac/libdirac_common/band_codec.cpp | 30 +- .../libdirac/libdirac_common/band_codec.h | 324 +- .../libdirac/libdirac_common/band_codec_template.h | 354 +- .../libdirac/libdirac_common/band_vlc.cpp | 16 +- .../libdirac/libdirac_common/band_vlc.h | 156 +- .../libdirac/libdirac_common/bit_manager.cpp | 176 +- .../libdirac/libdirac_common/bit_manager.h | 848 ++--- .../libdirac/libdirac_common/cmd_line.cpp | 16 +- .../libdirac/libdirac_common/cmd_line.h | 72 +- .../libdirac/libdirac_common/common.cpp | 400 +- .../libdirac/libdirac_common/common.h | 3009 ++++++--------- .../libdirac/libdirac_common/common_types.h | 263 +- .../libdirac/libdirac_common/dirac_assertions.cpp | 14 +- .../libdirac/libdirac_common/dirac_assertions.h | 4 +- .../libdirac/libdirac_common/dirac_exception.cpp | 16 +- .../libdirac/libdirac_common/dirac_exception.h | 65 +- .../libdirac/libdirac_common/dirac_types.h | 244 +- .../libdirac/libdirac_common/mot_comp.cpp | 764 ++-- .../libdirac/libdirac_common/mot_comp.h | 468 +-- .../libdirac/libdirac_common/mot_comp_mmx.cpp | 432 ++- .../libdirac/libdirac_common/mot_comp_mmx.h | 14 +- .../libdirac/libdirac_common/motion.cpp | 624 ++- .../libdirac/libdirac_common/motion.h | 661 ++-- .../libdirac/libdirac_common/mv_codec.cpp | 532 +-- .../libdirac/libdirac_common/mv_codec.h | 434 +-- .../libdirac/libdirac_common/pic_io.cpp | 305 +- .../libdirac/libdirac_common/pic_io.h | 844 ++--- .../libdirac/libdirac_common/picture.cpp | 226 +- .../libdirac/libdirac_common/picture.h | 170 +- .../libdirac/libdirac_common/picture_buffer.cpp | 128 +- .../libdirac/libdirac_common/picture_buffer.h | 277 +- .../libdirac/libdirac_common/upconvert.cpp | 70 +- .../libdirac/libdirac_common/upconvert.h | 78 +- .../libdirac_common/video_format_defaults.cpp | 40 +- .../libdirac_common/video_format_defaults.h | 94 +- .../libdirac/libdirac_common/wavelet_utils.cpp | 1209 +++--- .../libdirac/libdirac_common/wavelet_utils.h | 1140 +++--- .../libdirac/libdirac_common/wavelet_utils_mmx.cpp | 1432 +++---- .../libdirac/libdirac_decoder/comp_decompress.cpp | 88 +- .../libdirac/libdirac_decoder/comp_decompress.h | 144 +- .../libdirac/libdirac_decoder/decoder_types.h | 21 +- .../libdirac/libdirac_decoder/dirac_cppparser.cpp | 116 +- .../libdirac/libdirac_decoder/dirac_cppparser.h | 248 +- .../libdirac/libdirac_decoder/dirac_parser.cpp | 578 +-- .../libdirac/libdirac_decoder/dirac_parser.h | 164 +- .../libdirac_decoder/picture_decompress.cpp | 300 +- .../libdirac/libdirac_decoder/picture_decompress.h | 200 +- .../libdirac/libdirac_decoder/seq_decompress.cpp | 68 +- .../libdirac/libdirac_decoder/seq_decompress.h | 264 +- .../libdirac/libdirac_encoder/comp_compress.cpp | 76 +- .../libdirac/libdirac_encoder/comp_compress.h | 112 +- .../libdirac/libdirac_encoder/dirac_encoder.cpp | 794 ++-- .../libdirac/libdirac_encoder/dirac_encoder.h | 627 ++- .../libdirac/libdirac_encoder/enc_picture.cpp | 309 +- .../libdirac/libdirac_encoder/enc_picture.h | 77 +- .../libdirac/libdirac_encoder/enc_queue.cpp | 145 +- .../libdirac/libdirac_encoder/enc_queue.h | 328 +- .../libdirac/libdirac_encoder/picture_compress.cpp | 600 ++- .../libdirac/libdirac_encoder/picture_compress.h | 286 +- .../libdirac/libdirac_encoder/prefilter.cpp | 847 ++--- .../libdirac/libdirac_encoder/prefilter.h | 10 +- .../libdirac/libdirac_encoder/quality_monitor.cpp | 146 +- .../libdirac/libdirac_encoder/quality_monitor.h | 108 +- .../libdirac/libdirac_encoder/quant_chooser.cpp | 252 +- .../libdirac/libdirac_encoder/quant_chooser.h | 123 +- .../libdirac/libdirac_encoder/rate_control.cpp | 280 +- .../libdirac/libdirac_encoder/rate_control.h | 243 +- .../libdirac/libdirac_encoder/seq_compress.cpp | 681 ++-- .../libdirac/libdirac_encoder/seq_compress.h | 570 ++- .../libdirac/libdirac_motionest/block_match.cpp | 386 +- .../libdirac/libdirac_motionest/block_match.h | 289 +- .../libdirac/libdirac_motionest/downconvert.cpp | 144 +- .../libdirac/libdirac_motionest/downconvert.h | 77 +- .../libdirac_motionest/downconvert_mmx.cpp | 148 +- .../libdirac/libdirac_motionest/me_mode_decn.cpp | 390 +- .../libdirac/libdirac_motionest/me_mode_decn.h | 178 +- .../libdirac/libdirac_motionest/me_subpel.cpp | 62 +- .../libdirac/libdirac_motionest/me_subpel.h | 100 +- .../libdirac/libdirac_motionest/me_utils.cpp | 1723 +++++---- .../libdirac/libdirac_motionest/me_utils.h | 1000 +++-- .../libdirac/libdirac_motionest/me_utils_mmx.cpp | 1913 +++++----- .../libdirac/libdirac_motionest/me_utils_mmx.h | 44 +- .../libdirac_motionest/motion_estimate.cpp | 152 +- .../libdirac/libdirac_motionest/motion_estimate.h | 113 +- .../libdirac/libdirac_motionest/pixel_match.cpp | 208 +- .../libdirac/libdirac_motionest/pixel_match.h | 142 +- src/filters/parser/DiracSplitter/resource.h | 2 +- src/filters/parser/DiracSplitter/stdafx.cpp | 8 +- src/filters/parser/DiracSplitter/stdafx.h | 36 +- src/filters/parser/FLVSplitter/FLVSplitter.cpp | 1278 +++---- src/filters/parser/FLVSplitter/FLVSplitter.h | 110 +- src/filters/parser/FLVSplitter/resource.h | 2 +- src/filters/parser/FLVSplitter/stdafx.cpp | 8 +- src/filters/parser/FLVSplitter/stdafx.h | 8 +- .../AP4/Source/Codecs/Ap4AdtsParser.cpp | 172 +- .../MP4Splitter/AP4/Source/Codecs/Ap4AdtsParser.h | 24 +- .../MP4Splitter/AP4/Source/Codecs/Ap4AvcParser.cpp | 266 +- .../MP4Splitter/AP4/Source/Codecs/Ap4AvcParser.h | 24 +- .../MP4Splitter/AP4/Source/Codecs/Ap4BitStream.cpp | 216 +- .../MP4Splitter/AP4/Source/Codecs/Ap4BitStream.h | 177 +- .../AP4/Source/Codecs/Ap4Mp4AudioInfo.cpp | 183 +- .../AP4/Source/Codecs/Ap4Mp4AudioInfo.h | 19 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4.h | 74 +- .../MP4Splitter/AP4/Source/Core/Ap48bdlAtom.cpp | 28 +- .../MP4Splitter/AP4/Source/Core/Ap48bdlAtom.h | 29 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Array.h | 93 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Atom.cpp | 374 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Atom.h | 476 +-- .../MP4Splitter/AP4/Source/Core/Ap4AtomFactory.cpp | 625 ++- .../MP4Splitter/AP4/Source/Core/Ap4AtomFactory.h | 27 +- .../AP4/Source/Core/Ap4AtomSampleTable.cpp | 264 +- .../AP4/Source/Core/Ap4AtomSampleTable.h | 14 +- .../MP4Splitter/AP4/Source/Core/Ap4AvcCAtom.cpp | 140 +- .../MP4Splitter/AP4/Source/Core/Ap4AvcCAtom.h | 46 +- .../MP4Splitter/AP4/Source/Core/Ap4ByteStream.cpp | 312 +- .../MP4Splitter/AP4/Source/Core/Ap4ByteStream.h | 94 +- .../MP4Splitter/AP4/Source/Core/Ap4ChplAtom.cpp | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4ChplAtom.h | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4CmvdAtom.cpp | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4CmvdAtom.h | 27 +- .../MP4Splitter/AP4/Source/Core/Ap4Co64Atom.cpp | 50 +- .../MP4Splitter/AP4/Source/Core/Ap4Co64Atom.h | 14 +- .../MP4Splitter/AP4/Source/Core/Ap4Command.cpp | 2 +- .../MP4Splitter/AP4/Source/Core/Ap4Command.h | 15 +- .../AP4/Source/Core/Ap4CommandFactory.cpp | 31 +- .../AP4/Source/Core/Ap4CommandFactory.h | 6 +- .../AP4/Source/Core/Ap4ContainerAtom.cpp | 75 +- .../MP4Splitter/AP4/Source/Core/Ap4ContainerAtom.h | 23 +- .../MP4Splitter/AP4/Source/Core/Ap4CttsAtom.cpp | 56 +- .../MP4Splitter/AP4/Source/Core/Ap4CttsAtom.h | 18 +- .../MP4Splitter/AP4/Source/Core/Ap4DataBuffer.cpp | 57 +- .../MP4Splitter/AP4/Source/Core/Ap4DataBuffer.h | 30 +- .../MP4Splitter/AP4/Source/Core/Ap4DcomAtom.cpp | 14 +- .../MP4Splitter/AP4/Source/Core/Ap4DcomAtom.h | 22 +- .../MP4Splitter/AP4/Source/Core/Ap4Debug.cpp | 2 +- .../AP4/Source/Core/Ap4DecoderConfigDescriptor.cpp | 39 +- .../AP4/Source/Core/Ap4DecoderConfigDescriptor.h | 39 +- .../Core/Ap4DecoderSpecificInfoDescriptor.cpp | 18 +- .../Source/Core/Ap4DecoderSpecificInfoDescriptor.h | 9 +- .../MP4Splitter/AP4/Source/Core/Ap4Descriptor.cpp | 8 +- .../MP4Splitter/AP4/Source/Core/Ap4Descriptor.h | 38 +- .../AP4/Source/Core/Ap4DescriptorFactory.cpp | 63 +- .../AP4/Source/Core/Ap4DescriptorFactory.h | 6 +- .../MP4Splitter/AP4/Source/Core/Ap4DrefAtom.cpp | 27 +- .../MP4Splitter/AP4/Source/Core/Ap4DrefAtom.h | 2 +- .../MP4Splitter/AP4/Source/Core/Ap4ElstAtom.cpp | 47 +- .../MP4Splitter/AP4/Source/Core/Ap4ElstAtom.h | 19 +- .../AP4/Source/Core/Ap4EsDescriptor.cpp | 108 +- .../MP4Splitter/AP4/Source/Core/Ap4EsDescriptor.h | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4EsdsAtom.cpp | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4EsdsAtom.h | 11 +- .../MP4Splitter/AP4/Source/Core/Ap4Expandable.cpp | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4Expandable.h | 38 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4File.cpp | 48 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4File.h | 77 +- .../AP4/Source/Core/Ap4FileByteStream.h | 56 +- .../MP4Splitter/AP4/Source/Core/Ap4FileCopier.cpp | 7 +- .../MP4Splitter/AP4/Source/Core/Ap4FileCopier.h | 3 +- .../MP4Splitter/AP4/Source/Core/Ap4FileWriter.cpp | 74 +- .../MP4Splitter/AP4/Source/Core/Ap4FileWriter.h | 14 +- .../AP4/Source/Core/Ap4FragmentSampleTable.cpp | 199 +- .../AP4/Source/Core/Ap4FragmentSampleTable.h | 37 +- .../MP4Splitter/AP4/Source/Core/Ap4FrmaAtom.cpp | 4 +- .../MP4Splitter/AP4/Source/Core/Ap4FrmaAtom.h | 12 +- .../MP4Splitter/AP4/Source/Core/Ap4FtabAtom.cpp | 28 +- .../MP4Splitter/AP4/Source/Core/Ap4FtabAtom.h | 50 +- .../MP4Splitter/AP4/Source/Core/Ap4FtypAtom.cpp | 26 +- .../MP4Splitter/AP4/Source/Core/Ap4FtypAtom.h | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4GrpiAtom.cpp | 22 +- .../MP4Splitter/AP4/Source/Core/Ap4GrpiAtom.h | 32 +- .../MP4Splitter/AP4/Source/Core/Ap4HdlrAtom.cpp | 49 +- .../MP4Splitter/AP4/Source/Core/Ap4HdlrAtom.h | 34 +- .../AP4/Source/Core/Ap4HintTrackReader.cpp | 128 +- .../AP4/Source/Core/Ap4HintTrackReader.h | 21 +- .../MP4Splitter/AP4/Source/Core/Ap4HmhdAtom.cpp | 18 +- .../MP4Splitter/AP4/Source/Core/Ap4HmhdAtom.h | 4 +- .../MP4Splitter/AP4/Source/Core/Ap4IkmsAtom.cpp | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4IkmsAtom.h | 17 +- .../MP4Splitter/AP4/Source/Core/Ap4Interfaces.h | 2 +- .../MP4Splitter/AP4/Source/Core/Ap4IodsAtom.cpp | 22 +- .../MP4Splitter/AP4/Source/Core/Ap4IodsAtom.h | 11 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Ipmp.cpp | 97 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Ipmp.h | 83 +- .../MP4Splitter/AP4/Source/Core/Ap4IproAtom.cpp | 26 +- .../MP4Splitter/AP4/Source/Core/Ap4IproAtom.h | 2 +- .../MP4Splitter/AP4/Source/Core/Ap4IsfmAtom.cpp | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4IsfmAtom.h | 17 +- .../MP4Splitter/AP4/Source/Core/Ap4IsltAtom.cpp | 7 +- .../MP4Splitter/AP4/Source/Core/Ap4IsltAtom.h | 10 +- .../MP4Splitter/AP4/Source/Core/Ap4IsmaCryp.cpp | 244 +- .../MP4Splitter/AP4/Source/Core/Ap4IsmaCryp.h | 38 +- .../AP4/Source/Core/Ap4LinearReader.cpp | 143 +- .../MP4Splitter/AP4/Source/Core/Ap4LinearReader.h | 50 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4List.h | 203 +- .../MP4Splitter/AP4/Source/Core/Ap4Marlin.cpp | 747 ++-- .../parser/MP4Splitter/AP4/Source/Core/Ap4Marlin.h | 61 +- .../MP4Splitter/AP4/Source/Core/Ap4MdhdAtom.cpp | 71 +- .../MP4Splitter/AP4/Source/Core/Ap4MdhdAtom.h | 29 +- .../MP4Splitter/AP4/Source/Core/Ap4MehdAtom.cpp | 27 +- .../MP4Splitter/AP4/Source/Core/Ap4MehdAtom.h | 16 +- .../MP4Splitter/AP4/Source/Core/Ap4MfhdAtom.cpp | 10 +- .../MP4Splitter/AP4/Source/Core/Ap4MfhdAtom.h | 14 +- .../MP4Splitter/AP4/Source/Core/Ap4MfroAtom.cpp | 18 +- .../MP4Splitter/AP4/Source/Core/Ap4MfroAtom.h | 13 +- .../MP4Splitter/AP4/Source/Core/Ap4MoovAtom.cpp | 192 +- .../MP4Splitter/AP4/Source/Core/Ap4MoovAtom.h | 13 +- .../MP4Splitter/AP4/Source/Core/Ap4Movie.cpp | 89 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Movie.h | 22 +- .../AP4/Source/Core/Ap4MovieFragment.cpp | 88 +- .../MP4Splitter/AP4/Source/Core/Ap4MovieFragment.h | 19 +- .../MP4Splitter/AP4/Source/Core/Ap4Mpeg2Ts.cpp | 545 ++- .../MP4Splitter/AP4/Source/Core/Ap4Mpeg2Ts.h | 59 +- .../MP4Splitter/AP4/Source/Core/Ap4MvhdAtom.cpp | 65 +- .../MP4Splitter/AP4/Source/Core/Ap4MvhdAtom.h | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4NmhdAtom.cpp | 8 +- .../MP4Splitter/AP4/Source/Core/Ap4NmhdAtom.h | 4 +- .../AP4/Source/Core/Ap4ObjectDescriptor.cpp | 204 +- .../AP4/Source/Core/Ap4ObjectDescriptor.h | 102 +- .../MP4Splitter/AP4/Source/Core/Ap4OdafAtom.cpp | 18 +- .../MP4Splitter/AP4/Source/Core/Ap4OdafAtom.h | 17 +- .../MP4Splitter/AP4/Source/Core/Ap4OddaAtom.cpp | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4OddaAtom.h | 18 +- .../MP4Splitter/AP4/Source/Core/Ap4OdheAtom.cpp | 21 +- .../MP4Splitter/AP4/Source/Core/Ap4OdheAtom.h | 19 +- .../MP4Splitter/AP4/Source/Core/Ap4OhdrAtom.cpp | 59 +- .../MP4Splitter/AP4/Source/Core/Ap4OhdrAtom.h | 50 +- .../MP4Splitter/AP4/Source/Core/Ap4OmaDcf.cpp | 716 ++-- .../parser/MP4Splitter/AP4/Source/Core/Ap4OmaDcf.h | 62 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Piff.cpp | 837 ++-- .../parser/MP4Splitter/AP4/Source/Core/Ap4Piff.h | 116 +- .../MP4Splitter/AP4/Source/Core/Ap4Processor.cpp | 305 +- .../MP4Splitter/AP4/Source/Core/Ap4Processor.h | 101 +- .../MP4Splitter/AP4/Source/Core/Ap4Protection.cpp | 890 ++--- .../MP4Splitter/AP4/Source/Core/Ap4Protection.h | 106 +- .../MP4Splitter/AP4/Source/Core/Ap4Results.cpp | 75 +- .../MP4Splitter/AP4/Source/Core/Ap4RtpAtom.cpp | 17 +- .../MP4Splitter/AP4/Source/Core/Ap4RtpAtom.h | 10 +- .../MP4Splitter/AP4/Source/Core/Ap4RtpHint.cpp | 212 +- .../MP4Splitter/AP4/Source/Core/Ap4RtpHint.h | 140 +- .../AP4/Source/Core/Ap4SLConfigDescriptor.cpp | 2 +- .../AP4/Source/Core/Ap4SLConfigDescriptor.h | 4 +- .../MP4Splitter/AP4/Source/Core/Ap4Sample.cpp | 12 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Sample.h | 100 +- .../AP4/Source/Core/Ap4SampleDescription.cpp | 505 +-- .../AP4/Source/Core/Ap4SampleDescription.h | 211 +- .../MP4Splitter/AP4/Source/Core/Ap4SampleEntry.cpp | 669 ++-- .../MP4Splitter/AP4/Source/Core/Ap4SampleEntry.h | 205 +- .../AP4/Source/Core/Ap4SampleSource.cpp | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4SampleSource.h | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4SampleTable.cpp | 97 +- .../MP4Splitter/AP4/Source/Core/Ap4SampleTable.h | 13 +- .../MP4Splitter/AP4/Source/Core/Ap4SchmAtom.cpp | 88 +- .../MP4Splitter/AP4/Source/Core/Ap4SchmAtom.h | 23 +- .../MP4Splitter/AP4/Source/Core/Ap4SdpAtom.cpp | 17 +- .../MP4Splitter/AP4/Source/Core/Ap4SdpAtom.h | 7 +- .../MP4Splitter/AP4/Source/Core/Ap4SmhdAtom.cpp | 14 +- .../MP4Splitter/AP4/Source/Core/Ap4SmhdAtom.h | 4 +- .../MP4Splitter/AP4/Source/Core/Ap4StcoAtom.cpp | 57 +- .../MP4Splitter/AP4/Source/Core/Ap4StcoAtom.h | 16 +- .../MP4Splitter/AP4/Source/Core/Ap4String.cpp | 60 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4String.h | 30 +- .../MP4Splitter/AP4/Source/Core/Ap4StscAtom.cpp | 119 +- .../MP4Splitter/AP4/Source/Core/Ap4StscAtom.h | 25 +- .../MP4Splitter/AP4/Source/Core/Ap4StsdAtom.cpp | 52 +- .../MP4Splitter/AP4/Source/Core/Ap4StsdAtom.h | 2 +- .../MP4Splitter/AP4/Source/Core/Ap4StssAtom.cpp | 42 +- .../MP4Splitter/AP4/Source/Core/Ap4StssAtom.h | 13 +- .../MP4Splitter/AP4/Source/Core/Ap4StszAtom.cpp | 79 +- .../MP4Splitter/AP4/Source/Core/Ap4StszAtom.h | 16 +- .../MP4Splitter/AP4/Source/Core/Ap4SttsAtom.cpp | 86 +- .../MP4Splitter/AP4/Source/Core/Ap4SttsAtom.h | 28 +- .../AP4/Source/Core/Ap4SyntheticSampleTable.cpp | 123 +- .../AP4/Source/Core/Ap4SyntheticSampleTable.h | 41 +- .../MP4Splitter/AP4/Source/Core/Ap4TfhdAtom.cpp | 89 +- .../MP4Splitter/AP4/Source/Core/Ap4TfhdAtom.h | 66 +- .../MP4Splitter/AP4/Source/Core/Ap4TfraAtom.cpp | 350 +- .../MP4Splitter/AP4/Source/Core/Ap4TfraAtom.h | 16 +- .../MP4Splitter/AP4/Source/Core/Ap4TimsAtom.cpp | 4 +- .../MP4Splitter/AP4/Source/Core/Ap4TimsAtom.h | 10 +- .../MP4Splitter/AP4/Source/Core/Ap4TkhdAtom.cpp | 70 +- .../MP4Splitter/AP4/Source/Core/Ap4TkhdAtom.h | 51 +- .../MP4Splitter/AP4/Source/Core/Ap4Track.cpp | 199 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Track.h | 58 +- .../MP4Splitter/AP4/Source/Core/Ap4TrakAtom.cpp | 166 +- .../MP4Splitter/AP4/Source/Core/Ap4TrakAtom.h | 22 +- .../AP4/Source/Core/Ap4TrefTypeAtom.cpp | 24 +- .../MP4Splitter/AP4/Source/Core/Ap4TrefTypeAtom.h | 18 +- .../MP4Splitter/AP4/Source/Core/Ap4TrexAtom.cpp | 10 +- .../MP4Splitter/AP4/Source/Core/Ap4TrexAtom.h | 41 +- .../MP4Splitter/AP4/Source/Core/Ap4TrunAtom.cpp | 132 +- .../MP4Splitter/AP4/Source/Core/Ap4TrunAtom.h | 28 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Types.h | 29 +- .../MP4Splitter/AP4/Source/Core/Ap4UrlAtom.cpp | 41 +- .../MP4Splitter/AP4/Source/Core/Ap4UrlAtom.h | 4 +- .../MP4Splitter/AP4/Source/Core/Ap4Utils.cpp | 177 +- .../parser/MP4Splitter/AP4/Source/Core/Ap4Utils.h | 61 +- .../MP4Splitter/AP4/Source/Core/Ap4UuidAtom.cpp | 82 +- .../MP4Splitter/AP4/Source/Core/Ap4UuidAtom.h | 21 +- .../MP4Splitter/AP4/Source/Core/Ap4VmhdAtom.cpp | 16 +- .../MP4Splitter/AP4/Source/Core/Ap4VmhdAtom.h | 4 +- .../AP4/Source/Crypto/Ap4AesBlockCipher.cpp | 614 ++- .../AP4/Source/Crypto/Ap4AesBlockCipher.h | 22 +- .../MP4Splitter/AP4/Source/Crypto/Ap4Hmac.cpp | 296 +- .../parser/MP4Splitter/AP4/Source/Crypto/Ap4Hmac.h | 9 +- .../MP4Splitter/AP4/Source/Crypto/Ap4KeyWrap.cpp | 78 +- .../MP4Splitter/AP4/Source/Crypto/Ap4KeyWrap.h | 6 +- .../AP4/Source/Crypto/Ap4StreamCipher.cpp | 232 +- .../AP4/Source/Crypto/Ap4StreamCipher.h | 49 +- .../AP4/Source/MetaData/Ap4MetaData.cpp | 1021 +++-- .../MP4Splitter/AP4/Source/MetaData/Ap4MetaData.h | 337 +- .../parser/MP4Splitter/Ap4AsyncReaderStream.cpp | 64 +- .../parser/MP4Splitter/Ap4AsyncReaderStream.h | 22 +- src/filters/parser/MP4Splitter/MP4Splitter.cpp | 2806 +++++++------- src/filters/parser/MP4Splitter/MP4Splitter.h | 60 +- src/filters/parser/MP4Splitter/MP4SplitterFile.cpp | 32 +- src/filters/parser/MP4Splitter/MP4SplitterFile.h | 10 +- src/filters/parser/MP4Splitter/resource.h | 2 +- src/filters/parser/MP4Splitter/stdafx.cpp | 8 +- src/filters/parser/MP4Splitter/stdafx.h | 8 +- .../parser/MatroskaSplitter/MatroskaFile.cpp | 1959 ++++------ src/filters/parser/MatroskaSplitter/MatroskaFile.h | 1013 +++-- .../parser/MatroskaSplitter/MatroskaSplitter.cpp | 2296 ++++++----- .../parser/MatroskaSplitter/MatroskaSplitter.h | 116 +- src/filters/parser/MatroskaSplitter/resource.h | 2 +- src/filters/parser/MatroskaSplitter/stdafx.cpp | 8 +- src/filters/parser/MatroskaSplitter/stdafx.h | 8 +- src/filters/parser/MpaSplitter/MpaSplitter.cpp | 172 +- src/filters/parser/MpaSplitter/MpaSplitter.h | 28 +- src/filters/parser/MpaSplitter/MpaSplitterFile.cpp | 598 +-- src/filters/parser/MpaSplitter/MpaSplitterFile.h | 56 +- src/filters/parser/MpaSplitter/resource.h | 2 +- src/filters/parser/MpaSplitter/stdafx.cpp | 8 +- src/filters/parser/MpaSplitter/stdafx.h | 8 +- src/filters/parser/MpegSplitter/MpegSplitter.cpp | 2790 +++++++------- src/filters/parser/MpegSplitter/MpegSplitter.h | 78 +- .../parser/MpegSplitter/MpegSplitterFile.cpp | 1400 ++++--- src/filters/parser/MpegSplitter/MpegSplitterFile.h | 215 +- src/filters/parser/MpegSplitter/resource.h | 2 +- src/filters/parser/MpegSplitter/stdafx.cpp | 8 +- src/filters/parser/MpegSplitter/stdafx.h | 8 +- src/filters/parser/NutSplitter/NutFile.cpp | 266 +- src/filters/parser/NutSplitter/NutFile.h | 210 +- src/filters/parser/NutSplitter/NutSplitter.cpp | 486 ++- src/filters/parser/NutSplitter/NutSplitter.h | 30 +- src/filters/parser/NutSplitter/resource.h | 2 +- src/filters/parser/NutSplitter/stdafx.cpp | 8 +- src/filters/parser/NutSplitter/stdafx.h | 8 +- src/filters/parser/OggSplitter/OggFile.cpp | 97 +- src/filters/parser/OggSplitter/OggFile.h | 80 +- src/filters/parser/OggSplitter/OggSplitter.cpp | 1960 +++++----- src/filters/parser/OggSplitter/OggSplitter.h | 179 +- src/filters/parser/OggSplitter/resource.h | 2 +- src/filters/parser/OggSplitter/stdafx.cpp | 8 +- src/filters/parser/OggSplitter/stdafx.h | 8 +- .../parser/RealMediaSplitter/RealMediaSplitter.cpp | 3980 ++++++++++---------- .../parser/RealMediaSplitter/RealMediaSplitter.h | 452 +-- src/filters/parser/RealMediaSplitter/resource.h | 2 +- src/filters/parser/RealMediaSplitter/stdafx.cpp | 8 +- src/filters/parser/RealMediaSplitter/stdafx.h | 8 +- src/filters/parser/RoQSplitter/RoQSplitter.cpp | 1546 ++++---- src/filters/parser/RoQSplitter/RoQSplitter.h | 122 +- src/filters/parser/RoQSplitter/resource.h | 2 +- src/filters/parser/RoQSplitter/stdafx.cpp | 8 +- src/filters/parser/RoQSplitter/stdafx.h | 8 +- src/filters/parser/SSFSplitter/SSFSplitter.cpp | 316 +- src/filters/parser/SSFSplitter/SSFSplitter.h | 34 +- src/filters/parser/SSFSplitter/resource.h | 2 +- src/filters/parser/SSFSplitter/stdafx.cpp | 8 +- src/filters/parser/SSFSplitter/stdafx.h | 8 +- .../parser/StreamDriveThru/StreamDriveThru.cpp | 534 ++- .../parser/StreamDriveThru/StreamDriveThru.h | 108 +- src/filters/parser/StreamDriveThru/resource.h | 2 +- src/filters/parser/StreamDriveThru/stdafx.cpp | 8 +- src/filters/parser/StreamDriveThru/stdafx.h | 8 +- 439 files changed, 44462 insertions(+), 51302 deletions(-) (limited to 'src/filters/parser') diff --git a/src/filters/parser/AviSplitter/AviFile.cpp b/src/filters/parser/AviSplitter/AviFile.cpp index 95bf6bea3..7b610a505 100644 --- a/src/filters/parser/AviSplitter/AviFile.cpp +++ b/src/filters/parser/AviSplitter/AviFile.cpp @@ -6,618 +6,607 @@ // CAviFile::CAviFile(IAsyncReader* pAsyncReader, HRESULT& hr) - : CBaseSplitterFile(pAsyncReader, hr) + : CBaseSplitterFile(pAsyncReader, hr) { - if(FAILED(hr)) return; - m_isamv = false; - hr = Init(); + if(FAILED(hr)) return; + m_isamv = false; + hr = Init(); } -template +template HRESULT CAviFile::Read(T& var, int offset) { - memset(&var, 0, sizeof(var)); - HRESULT hr = ByteRead((BYTE*)&var + offset, sizeof(var) - offset); - return hr; + memset(&var, 0, sizeof(var)); + HRESULT hr = ByteRead((BYTE*)&var + offset, sizeof(var) - offset); + return hr; } HRESULT CAviFile::Init() { - Seek(0); - DWORD dw[3]; - if(S_OK != Read(dw) || dw[0] != FCC('RIFF') || (dw[2] != FCC('AVI ') && dw[2] != FCC('AVIX') && dw[2] != FCC('AMV '))) - return E_FAIL; - - m_isamv = (dw[2] == FCC('AMV ')); - Seek(0); - HRESULT hr = Parse(0, GetLength()); - if(m_movis.GetCount() == 0) // FAILED(hr) is allowed as long as there was a movi chunk found - return E_FAIL; - - if(m_avih.dwStreams == 0 && m_strms.GetCount() > 0) - m_avih.dwStreams = m_strms.GetCount(); - - if(m_avih.dwStreams != m_strms.GetCount()) - return E_FAIL; - - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - strm_t* s = m_strms[i]; - if(s->strh.fccType != FCC('auds')) continue; - WAVEFORMATEX* wfe = (WAVEFORMATEX*)s->strf.GetData(); - if(wfe->wFormatTag == 0x55 && wfe->nBlockAlign == 1152 - && s->strh.dwScale == 1 && s->strh.dwRate != wfe->nSamplesPerSec) - { - // correcting encoder bugs... - s->strh.dwScale = 1152; - s->strh.dwRate = wfe->nSamplesPerSec; - } - } - - if(!m_isamv && (FAILED(BuildIndex()))) - EmptyIndex(); - - return S_OK; + Seek(0); + DWORD dw[3]; + if(S_OK != Read(dw) || dw[0] != FCC('RIFF') || (dw[2] != FCC('AVI ') && dw[2] != FCC('AVIX') && dw[2] != FCC('AMV '))) + return E_FAIL; + + m_isamv = (dw[2] == FCC('AMV ')); + Seek(0); + HRESULT hr = Parse(0, GetLength()); + if(m_movis.GetCount() == 0) // FAILED(hr) is allowed as long as there was a movi chunk found + return E_FAIL; + + if(m_avih.dwStreams == 0 && m_strms.GetCount() > 0) + m_avih.dwStreams = m_strms.GetCount(); + + if(m_avih.dwStreams != m_strms.GetCount()) + return E_FAIL; + + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + strm_t* s = m_strms[i]; + if(s->strh.fccType != FCC('auds')) continue; + WAVEFORMATEX* wfe = (WAVEFORMATEX*)s->strf.GetData(); + if(wfe->wFormatTag == 0x55 && wfe->nBlockAlign == 1152 + && s->strh.dwScale == 1 && s->strh.dwRate != wfe->nSamplesPerSec) + { + // correcting encoder bugs... + s->strh.dwScale = 1152; + s->strh.dwRate = wfe->nSamplesPerSec; + } + } + + if (!m_isamv && (FAILED(BuildIndex()))) + EmptyIndex(); + + return S_OK; } HRESULT CAviFile::BuildAMVIndex() { - strm_t::chunk NewChunk; - ULONG ulType; - ULONG ulSize; - - memset(&NewChunk, 0, sizeof(strm_t::chunk)); - while((Read(ulType) == S_OK) && (Read(ulSize) == S_OK)) - { - switch(ulType) - { - case FCC('00dc'): // 01bw : JPeg - NewChunk.size = ulSize; - NewChunk.filepos = GetPos(); - NewChunk.orgsize = ulSize; - NewChunk.fKeyFrame = true; - m_strms[0]->cs.Add(NewChunk); - break; - case FCC('01wb') : // 00dc : Audio - NewChunk.size = ulSize; - NewChunk.orgsize = ulSize; - NewChunk.fKeyFrame = true; - NewChunk.filepos = GetPos(); - m_strms[1]->cs.Add(NewChunk); - break; - } - Seek(GetPos() + ulSize); - } - - TRACE("Video packet : %d Audio packet :%d\n", m_strms[0]->cs.GetCount(), m_strms[1]->cs.GetCount()); - return S_OK; + strm_t::chunk NewChunk; + ULONG ulType; + ULONG ulSize; + + memset (&NewChunk, 0, sizeof(strm_t::chunk)); + while((Read(ulType) == S_OK) && (Read(ulSize) == S_OK)) + { + switch (ulType) + { + case FCC('00dc'): // 01bw : JPeg + NewChunk.size = ulSize; + NewChunk.filepos = GetPos(); + NewChunk.orgsize = ulSize; + NewChunk.fKeyFrame = true; + m_strms[0]->cs.Add (NewChunk); + break; + case FCC('01wb') : // 00dc : Audio + NewChunk.size = ulSize; + NewChunk.orgsize = ulSize; + NewChunk.fKeyFrame = true; + NewChunk.filepos = GetPos(); + m_strms[1]->cs.Add (NewChunk); + break; + } + Seek(GetPos() + ulSize); + } + + TRACE ("Video packet : %d Audio packet :%d\n", m_strms[0]->cs.GetCount(), m_strms[1]->cs.GetCount()); + return S_OK; } HRESULT CAviFile::Parse(DWORD parentid, __int64 end) { - HRESULT hr = S_OK; - - CAutoPtr strm; - - while(S_OK == hr && GetPos() < end) - { - UINT64 pos = GetPos(); - - DWORD id = 0, size; - if(S_OK != Read(id) || id == 0) - return E_FAIL; - - if(id == FCC('RIFF') || id == FCC('LIST')) - { - if(S_OK != Read(size) || S_OK != Read(id)) - return E_FAIL; - - if(m_isamv) size = end - GetPos() - 8; // No size set in AVM : guess end of file... - size += (size & 1) + 8; - - TRACE(_T("CAviFile::Parse(..): LIST '%c%c%c%c'\n"), - TCHAR((id >> 0) & 0xff), - TCHAR((id >> 8) & 0xff), - TCHAR((id >> 16) & 0xff), - TCHAR((id >> 24) & 0xff)); - - if(id == FCC('movi')) - { - m_movis.AddTail(pos); - if(m_isamv) BuildAMVIndex(); - } - else - { - hr = Parse(id, pos + size); - } - } - else - { - if(S_OK != Read(size)) - return E_FAIL; - - TRACE(_T("CAviFile::Parse(..): '%c%c%c%c'\n"), - TCHAR((id >> 0) & 0xff), - TCHAR((id >> 8) & 0xff), - TCHAR((id >> 16) & 0xff), - TCHAR((id >> 24) & 0xff)); - - if(parentid == FCC('INFO') && size > 0) - { - switch(id) - { - case FCC('IARL'): // Archival Location. Indicates where the subject of the file is archived. - case FCC('IART'): // Artist. Lists the artist of the original subject of the file; for example, “Michaelangelo.” - case FCC('ICMS'): // Commissioned. Lists the name of the person or organization that commissioned the subject of the file; for example, “Pope Julian II.” - case FCC('ICMT'): // Comments. Provides general comments about the file or the subject of the file. If the comment is several sentences long, end each sentence with a period. Do not include new-line characters. - case FCC('ICOP'): // Copyright. Records the copyright information for the file; for example, “Copyright Encyclopedia International 1991.” If there are multiple copyrights, separate them by a semicolon followed by a space. - case FCC('ICRD'): // Creation date. Specifies the date the subject of the file was created. List dates in year-month-day format, padding one-digit months and days with a zero on the left; for example, “1553-05-03” for May 3, 1553. - case FCC('ICRP'): // Cropped. Describes whether an image has been cropped and, if so, how it was cropped; for example, “lower-right corner.” - case FCC('IDIM'): // Dimensions. Specifies the size of the original subject of the file; for example, “8.5 in h, 11 in w.” - case FCC('IDPI'): // Dots Per Inch. Stores dots per inch setting of the digitizer used to produce the file, such as “300.” - case FCC('IENG'): // Engineer. Stores the name of the engineer who worked on the file. If there are multiple engineers, separate the names by a semicolon and a blank; for example, “Smith, John; Adams, Joe.” - case FCC('IGNR'): // Genre. Describes the original work, such as “landscape,” “portrait,” “still life,” etc. - case FCC('IKEY'): // Keywords. Provides a list of keywords that refer to the file or subject of the file. Separate multiple keywords with a semicolon and a blank; for example, “Seattle; aerial view; scenery.” - case FCC('ILGT'): // Lightness. Describes the changes in lightness settings on the digitizer required to produce the file. Note that the format of this information depends on hardware used. - case FCC('IMED'): // Medium. Describes the original subject of the file, such as “computer image,” “drawing,” “lithograph,” and so on. - case FCC('INAM'): // Name. Stores the title of the subject of the file, such as “Seattle From Above.” - case FCC('IPLT'): // Palette Setting. Specifies the number of colors requested when digitizing an image, such as “256.” - case FCC('IPRD'): // Product. Specifies the name of the title the file was originally intended for, such as “Encyclopedia of Pacific Northwest Geography.” - case FCC('ISBJ'): // Subject. Describes the contents of the file, such as “Aerial view of Seattle.” - case FCC('ISFT'): // Software. Identifies the name of the software package used to create the file, such as “Microsoft WaveEdit.” - case FCC('ISHP'): // Sharpness. Identifies the changes in sharpness for the digitizer required to produce the file (the format depends on the hardware used). - case FCC('ISRC'): // Source. Identifies the name of the person or organization who supplied the original subject of the file; for example, “Trey Research.” - case FCC('ISRF'): // Source Form. Identifies the original form of the material that was digitized, such as “slide,” “paper,” “map,” and so on. This is not necessarily the same as IMED. - case FCC('ITCH'): // Technician. Identifies the technician who digitized the subject file; for example, “Smith, John.” - { - CStringA str; - if(S_OK != ByteRead((BYTE*)str.GetBufferSetLength(size), size)) return E_FAIL; - m_info[id] = str; - break; - } - } - } - - switch(id) - { - case FCC('amvh'): - case FCC('avih'): - m_avih.fcc = id; - m_avih.cb = size; - if(S_OK != Read(m_avih, 8)) return E_FAIL; - break; - case FCC('strh'): - if(!strm) strm.Attach(DNew strm_t()); - strm->strh.fcc = FCC('strh'); - strm->strh.cb = size; - if(S_OK != Read(strm->strh, 8)) return E_FAIL; - if(m_isamv) - { - // First alway video, second always audio - strm->strh.fccType = m_strms.GetCount() == 0 ? FCC('vids') : FCC('amva'); - strm->strh.dwRate = m_avih.dwReserved[0] * 1000; // dwReserved[0] = fps! - strm->strh.dwScale = 1000; - } - break; - case FCC('strn'): - if(S_OK != ByteRead((BYTE*)strm->strn.GetBufferSetLength(size), size)) return E_FAIL; - break; - case FCC('strf'): - if(!strm) strm.Attach(DNew strm_t()); - strm->strf.SetCount(size); - if(S_OK != ByteRead(strm->strf.GetData(), size)) return E_FAIL; - if(m_isamv) - { - if(strm->strh.fccType == FCC('vids')) - { - strm->strf.SetCount(sizeof(BITMAPINFOHEADER)); - BITMAPINFOHEADER* pbmi = &((BITMAPINFO*)strm->strf.GetData())->bmiHeader; - pbmi->biSize = sizeof(BITMAPINFOHEADER); - pbmi->biHeight = m_avih.dwHeight; - pbmi->biWidth = m_avih.dwWidth; - pbmi->biCompression = FCC('AMVV'); - pbmi->biPlanes = 1; - pbmi->biBitCount = 24; - pbmi->biSizeImage = pbmi->biHeight * pbmi->biWidth * (pbmi->biBitCount / 8); - } - m_strms.Add(strm); - } - - break; - case FCC('indx'): - if(!strm) strm.Attach(DNew strm_t()); - ASSERT(strm->indx == NULL); - AVISUPERINDEX* pSuperIndex; - if(size < MAXDWORD - 8) - { - // Fix buffer overrun vulnerability : http://www.vulnhunt.com/advisories/CAL-20070912-1_Multiple_vendor_produce_handling_AVI_file_vulnerabilities.txt - TRY - { - pSuperIndex = (AVISUPERINDEX*)DNew unsigned char [(size_t)(size + 8)]; - } - CATCH(CMemoryException, e) - { - pSuperIndex = NULL; - } - END_CATCH - if(pSuperIndex) - { - strm->indx.Attach(pSuperIndex); - strm->indx->fcc = FCC('indx'); - strm->indx->cb = size; - if(S_OK != ByteRead((BYTE*)(AVISUPERINDEX*)strm->indx + 8, size)) return E_FAIL; - ASSERT(strm->indx->wLongsPerEntry == 4 && strm->indx->bIndexType == AVI_INDEX_OF_INDEXES); - } - } - break; - case FCC('dmlh'): - if(S_OK != Read(m_dmlh)) return E_FAIL; - break; - case FCC('vprp'): + HRESULT hr = S_OK; + + CAutoPtr strm; + + while(S_OK == hr && GetPos() < end) + { + UINT64 pos = GetPos(); + + DWORD id = 0, size; + if(S_OK != Read(id) || id == 0) + return E_FAIL; + + if(id == FCC('RIFF') || id == FCC('LIST')) + { + if(S_OK != Read(size) || S_OK != Read(id)) + return E_FAIL; + + if (m_isamv) size = end - GetPos() - 8; // No size set in AVM : guess end of file... + size += (size&1) + 8; + + TRACE(_T("CAviFile::Parse(..): LIST '%c%c%c%c'\n"), + TCHAR((id>>0)&0xff), + TCHAR((id>>8)&0xff), + TCHAR((id>>16)&0xff), + TCHAR((id>>24)&0xff)); + + if(id == FCC('movi')) + { + m_movis.AddTail(pos); + if (m_isamv) BuildAMVIndex(); + } + else + { + hr = Parse(id, pos + size); + } + } + else + { + if(S_OK != Read(size)) + return E_FAIL; + + TRACE(_T("CAviFile::Parse(..): '%c%c%c%c'\n"), + TCHAR((id>>0)&0xff), + TCHAR((id>>8)&0xff), + TCHAR((id>>16)&0xff), + TCHAR((id>>24)&0xff)); + + if(parentid == FCC('INFO') && size > 0) + { + switch(id) + { + case FCC('IARL'): // Archival Location. Indicates where the subject of the file is archived. + case FCC('IART'): // Artist. Lists the artist of the original subject of the file; for example, “Michaelangelo.” + case FCC('ICMS'): // Commissioned. Lists the name of the person or organization that commissioned the subject of the file; for example, “Pope Julian II.” + case FCC('ICMT'): // Comments. Provides general comments about the file or the subject of the file. If the comment is several sentences long, end each sentence with a period. Do not include new-line characters. + case FCC('ICOP'): // Copyright. Records the copyright information for the file; for example, “Copyright Encyclopedia International 1991.” If there are multiple copyrights, separate them by a semicolon followed by a space. + case FCC('ICRD'): // Creation date. Specifies the date the subject of the file was created. List dates in year-month-day format, padding one-digit months and days with a zero on the left; for example, “1553-05-03” for May 3, 1553. + case FCC('ICRP'): // Cropped. Describes whether an image has been cropped and, if so, how it was cropped; for example, “lower-right corner.” + case FCC('IDIM'): // Dimensions. Specifies the size of the original subject of the file; for example, “8.5 in h, 11 in w.” + case FCC('IDPI'): // Dots Per Inch. Stores dots per inch setting of the digitizer used to produce the file, such as “300.” + case FCC('IENG'): // Engineer. Stores the name of the engineer who worked on the file. If there are multiple engineers, separate the names by a semicolon and a blank; for example, “Smith, John; Adams, Joe.” + case FCC('IGNR'): // Genre. Describes the original work, such as “landscape,” “portrait,” “still life,” etc. + case FCC('IKEY'): // Keywords. Provides a list of keywords that refer to the file or subject of the file. Separate multiple keywords with a semicolon and a blank; for example, “Seattle; aerial view; scenery.” + case FCC('ILGT'): // Lightness. Describes the changes in lightness settings on the digitizer required to produce the file. Note that the format of this information depends on hardware used. + case FCC('IMED'): // Medium. Describes the original subject of the file, such as “computer image,” “drawing,” “lithograph,” and so on. + case FCC('INAM'): // Name. Stores the title of the subject of the file, such as “Seattle From Above.” + case FCC('IPLT'): // Palette Setting. Specifies the number of colors requested when digitizing an image, such as “256.” + case FCC('IPRD'): // Product. Specifies the name of the title the file was originally intended for, such as “Encyclopedia of Pacific Northwest Geography.” + case FCC('ISBJ'): // Subject. Describes the contents of the file, such as “Aerial view of Seattle.” + case FCC('ISFT'): // Software. Identifies the name of the software package used to create the file, such as “Microsoft WaveEdit.” + case FCC('ISHP'): // Sharpness. Identifies the changes in sharpness for the digitizer required to produce the file (the format depends on the hardware used). + case FCC('ISRC'): // Source. Identifies the name of the person or organization who supplied the original subject of the file; for example, “Trey Research.” + case FCC('ISRF'): // Source Form. Identifies the original form of the material that was digitized, such as “slide,” “paper,” “map,” and so on. This is not necessarily the same as IMED. + case FCC('ITCH'): // Technician. Identifies the technician who digitized the subject file; for example, “Smith, John.” + { + CStringA str; + if(S_OK != ByteRead((BYTE*)str.GetBufferSetLength(size), size)) return E_FAIL; + m_info[id] = str; + break; + } + } + } + + switch(id) + { + case FCC('amvh'): + case FCC('avih'): + m_avih.fcc = id; + m_avih.cb = size; + if(S_OK != Read(m_avih, 8)) return E_FAIL; + break; + case FCC('strh'): + if(!strm) strm.Attach(DNew strm_t()); + strm->strh.fcc = FCC('strh'); + strm->strh.cb = size; + if(S_OK != Read(strm->strh, 8)) return E_FAIL; + if (m_isamv) + { + // First alway video, second always audio + strm->strh.fccType = m_strms.GetCount() == 0 ? FCC('vids') : FCC('amva'); + strm->strh.dwRate = m_avih.dwReserved[0]*1000; // dwReserved[0] = fps! + strm->strh.dwScale = 1000; + } + break; + case FCC('strn'): + if(S_OK != ByteRead((BYTE*)strm->strn.GetBufferSetLength(size), size)) return E_FAIL; + break; + case FCC('strf'): + if(!strm) strm.Attach(DNew strm_t()); + strm->strf.SetCount(size); + if(S_OK != ByteRead(strm->strf.GetData(), size)) return E_FAIL; + if (m_isamv) + { + if (strm->strh.fccType == FCC('vids')) + { + strm->strf.SetCount(sizeof(BITMAPINFOHEADER)); + BITMAPINFOHEADER* pbmi = &((BITMAPINFO*)strm->strf.GetData())->bmiHeader; + pbmi->biSize = sizeof(BITMAPINFOHEADER); + pbmi->biHeight = m_avih.dwHeight; + pbmi->biWidth = m_avih.dwWidth; + pbmi->biCompression = FCC('AMVV'); + pbmi->biPlanes = 1; + pbmi->biBitCount = 24; + pbmi->biSizeImage = pbmi->biHeight * pbmi->biWidth * (pbmi->biBitCount/8); + } + m_strms.Add(strm); + } + + break; + case FCC('indx'): + if(!strm) strm.Attach(DNew strm_t()); + ASSERT(strm->indx == NULL); + AVISUPERINDEX* pSuperIndex; + if (size < MAXDWORD-8) + { + // Fix buffer overrun vulnerability : http://www.vulnhunt.com/advisories/CAL-20070912-1_Multiple_vendor_produce_handling_AVI_file_vulnerabilities.txt + TRY + { + pSuperIndex = (AVISUPERINDEX*)DNew unsigned char [(size_t)(size + 8)]; + } + CATCH (CMemoryException, e) + { + pSuperIndex = NULL; + } + END_CATCH + if (pSuperIndex) + { + strm->indx.Attach(pSuperIndex); + strm->indx->fcc = FCC('indx'); + strm->indx->cb = size; + if(S_OK != ByteRead((BYTE*)(AVISUPERINDEX*)strm->indx + 8, size)) return E_FAIL; + ASSERT(strm->indx->wLongsPerEntry == 4 && strm->indx->bIndexType == AVI_INDEX_OF_INDEXES); + } + } + break; + case FCC('dmlh'): + if(S_OK != Read(m_dmlh)) return E_FAIL; + break; + case FCC('vprp'): // if(S_OK != Read(m_vprp)) return E_FAIL; - break; - case FCC('idx1'): - ASSERT(m_idx1 == NULL); - m_idx1.Attach((AVIOLDINDEX*)DNew BYTE[size + 8]); - m_idx1->fcc = FCC('idx1'); - m_idx1->cb = size; - if(S_OK != ByteRead((BYTE*)(AVIOLDINDEX*)m_idx1 + 8, size)) return E_FAIL; - break; - default : - TRACE(_T("CAviFile::Parse(..): unknown tag '%c%c%c%c'\n"), - TCHAR((id >> 0) & 0xff), - TCHAR((id >> 8) & 0xff), - TCHAR((id >> 16) & 0xff), - TCHAR((id >> 24) & 0xff)); - break; - } - - size += (size & 1) + 8; - } - - Seek(pos + size); - } - - if(strm) m_strms.Add(strm); - - return hr; + break; + case FCC('idx1'): + ASSERT(m_idx1 == NULL); + m_idx1.Attach((AVIOLDINDEX*)DNew BYTE[size + 8]); + m_idx1->fcc = FCC('idx1'); + m_idx1->cb = size; + if(S_OK != ByteRead((BYTE*)(AVIOLDINDEX*)m_idx1 + 8, size)) return E_FAIL; + break; + default : + TRACE(_T("CAviFile::Parse(..): unknown tag '%c%c%c%c'\n"), + TCHAR((id>>0)&0xff), + TCHAR((id>>8)&0xff), + TCHAR((id>>16)&0xff), + TCHAR((id>>24)&0xff)); + break; + } + + size += (size&1) + 8; + } + + Seek(pos + size); + } + + if(strm) m_strms.Add(strm); + + return hr; } REFERENCE_TIME CAviFile::GetTotalTime() { - REFERENCE_TIME t = 0/*10i64*m_avih.dwMicroSecPerFrame*m_avih.dwTotalFrames*/; + REFERENCE_TIME t = 0/*10i64*m_avih.dwMicroSecPerFrame*m_avih.dwTotalFrames*/; - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - strm_t* s = m_strms[i]; - REFERENCE_TIME t2 = s->GetRefTime(s->cs.GetCount(), s->totalsize); - t = max(t, t2); - } + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + strm_t* s = m_strms[i]; + REFERENCE_TIME t2 = s->GetRefTime(s->cs.GetCount(), s->totalsize); + t = max(t, t2); + } - if(t == 0) t = 10i64 * m_avih.dwMicroSecPerFrame * m_avih.dwTotalFrames; + if(t == 0) t = 10i64*m_avih.dwMicroSecPerFrame*m_avih.dwTotalFrames; - return(t); + return(t); } HRESULT CAviFile::BuildIndex() { - EmptyIndex(); - - int nSuperIndexes = 0; - - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - strm_t* s = m_strms[i]; - if(s->indx && s->indx->nEntriesInUse > 0) nSuperIndexes++; - } - - if(nSuperIndexes == m_avih.dwStreams) - { - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - strm_t* s = m_strms[i]; - - AVISUPERINDEX* idx = (AVISUPERINDEX*)s->indx; - - DWORD nEntriesInUse = 0; - - for(int j = 0; j < (int)idx->nEntriesInUse; j++) - { - Seek(idx->aIndex[j].qwOffset); - - AVISTDINDEX stdidx; - if(S_OK != ByteRead((BYTE*)&stdidx, FIELD_OFFSET(AVISTDINDEX, aIndex))) - { - EmptyIndex(); - return E_FAIL; - } - - nEntriesInUse += stdidx.nEntriesInUse; - } - - s->cs.SetCount(nEntriesInUse); - - DWORD frame = 0; - UINT64 size = 0; - - for(int j = 0; j < (int)idx->nEntriesInUse; j++) - { - Seek(idx->aIndex[j].qwOffset); - - CAutoPtr p((AVISTDINDEX*)DNew BYTE[idx->aIndex[j].dwSize]); - if(!p || S_OK != ByteRead((BYTE*)(AVISTDINDEX*)p, idx->aIndex[j].dwSize)) - { - EmptyIndex(); - return E_FAIL; - } - - for(int k = 0, l = 0; k < (int)p->nEntriesInUse; k++) - { - s->cs[frame].size = size; - s->cs[frame].filepos = p->qwBaseOffset + p->aIndex[k].dwOffset; - s->cs[frame].fKeyFrame = !(p->aIndex[k].dwSize & AVISTDINDEX_DELTAFRAME) - || s->strh.fccType == FCC('auds'); - s->cs[frame].fChunkHdr = false; - s->cs[frame].orgsize = p->aIndex[k].dwSize & AVISTDINDEX_SIZEMASK; - - if(m_idx1) - { - s->cs[frame].filepos -= 8; - s->cs[frame].fChunkHdr = true; - } - - frame++; - size += s->GetChunkSize(p->aIndex[k].dwSize & AVISTDINDEX_SIZEMASK); - } - } - - s->totalsize = size; - } - } - else if(AVIOLDINDEX* idx = m_idx1) - { - int len = idx->cb / sizeof(idx->aIndex[0]); - - UINT64 offset = m_movis.GetHead() + 8; - - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - strm_t* s = m_strms[i]; - - int nFrames = 0; - - for(int j = 0; j < len; j++) - { - if(TRACKNUM(idx->aIndex[j].dwChunkId) == i) - nFrames++; - } - - s->cs.SetCount(nFrames); - - DWORD frame = 0; - UINT64 size = 0; - - for(int j = 0, k = 0; j < len; j++) - { - DWORD TrackNumber = TRACKNUM(idx->aIndex[j].dwChunkId); - - if(TrackNumber == i) - { - if(j == 0 && idx->aIndex[j].dwOffset > offset) - { - DWORD id; - Seek(offset + idx->aIndex[j].dwOffset); - Read(id); - if(id != idx->aIndex[j].dwChunkId) - { - TRACE(_T("WARNING: CAviFile::Init() detected absolute chunk addressing in \'idx1\'")); - offset = 0; - } - } - - s->cs[frame].size = size; - s->cs[frame].filepos = offset + idx->aIndex[j].dwOffset; - s->cs[frame].fKeyFrame = !!(idx->aIndex[j].dwFlags & AVIIF_KEYFRAME) - || s->strh.fccType == FCC('auds') // FIXME: some audio index is without any kf flag - || frame == 0; // grrr - s->cs[frame].fChunkHdr = j == len - 1 || idx->aIndex[j].dwOffset != idx->aIndex[j+1].dwOffset; - s->cs[frame].orgsize = idx->aIndex[j].dwSize; - - frame++; - size += s->GetChunkSize(idx->aIndex[j].dwSize); - } - } - - s->totalsize = size; - } - } - - m_idx1.Free(); - for(int i = 0; i < (int)m_avih.dwStreams; i++) - m_strms[i]->indx.Free(); - - return S_OK; + EmptyIndex(); + + int nSuperIndexes = 0; + + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + strm_t* s = m_strms[i]; + if(s->indx && s->indx->nEntriesInUse > 0) nSuperIndexes++; + } + + if(nSuperIndexes == m_avih.dwStreams) + { + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + strm_t* s = m_strms[i]; + + AVISUPERINDEX* idx = (AVISUPERINDEX*)s->indx; + + DWORD nEntriesInUse = 0; + + for(int j = 0; j < (int)idx->nEntriesInUse; j++) + { + Seek(idx->aIndex[j].qwOffset); + + AVISTDINDEX stdidx; + if(S_OK != ByteRead((BYTE*)&stdidx, FIELD_OFFSET(AVISTDINDEX, aIndex))) + { + EmptyIndex(); + return E_FAIL; + } + + nEntriesInUse += stdidx.nEntriesInUse; + } + + s->cs.SetCount(nEntriesInUse); + + DWORD frame = 0; + UINT64 size = 0; + + for(int j = 0; j < (int)idx->nEntriesInUse; j++) + { + Seek(idx->aIndex[j].qwOffset); + + CAutoPtr p((AVISTDINDEX*)DNew BYTE[idx->aIndex[j].dwSize]); + if(!p || S_OK != ByteRead((BYTE*)(AVISTDINDEX*)p, idx->aIndex[j].dwSize)) + { + EmptyIndex(); + return E_FAIL; + } + + for(int k = 0, l = 0; k < (int)p->nEntriesInUse; k++) + { + s->cs[frame].size = size; + s->cs[frame].filepos = p->qwBaseOffset + p->aIndex[k].dwOffset; + s->cs[frame].fKeyFrame = !(p->aIndex[k].dwSize&AVISTDINDEX_DELTAFRAME) + || s->strh.fccType == FCC('auds'); + s->cs[frame].fChunkHdr = false; + s->cs[frame].orgsize = p->aIndex[k].dwSize&AVISTDINDEX_SIZEMASK; + + if(m_idx1) + { + s->cs[frame].filepos -= 8; + s->cs[frame].fChunkHdr = true; + } + + frame++; + size += s->GetChunkSize(p->aIndex[k].dwSize&AVISTDINDEX_SIZEMASK); + } + } + + s->totalsize = size; + } + } + else if(AVIOLDINDEX* idx = m_idx1) + { + int len = idx->cb/sizeof(idx->aIndex[0]); + + UINT64 offset = m_movis.GetHead() + 8; + + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + strm_t* s = m_strms[i]; + + int nFrames = 0; + + for(int j = 0; j < len; j++) + { + if(TRACKNUM(idx->aIndex[j].dwChunkId) == i) + nFrames++; + } + + s->cs.SetCount(nFrames); + + DWORD frame = 0; + UINT64 size = 0; + + for(int j = 0, k = 0; j < len; j++) + { + DWORD TrackNumber = TRACKNUM(idx->aIndex[j].dwChunkId); + + if(TrackNumber == i) + { + if(j == 0 && idx->aIndex[j].dwOffset > offset) + { + DWORD id; + Seek(offset + idx->aIndex[j].dwOffset); + Read(id); + if(id != idx->aIndex[j].dwChunkId) + { + TRACE(_T("WARNING: CAviFile::Init() detected absolute chunk addressing in \'idx1\'")); + offset = 0; + } + } + + s->cs[frame].size = size; + s->cs[frame].filepos = offset + idx->aIndex[j].dwOffset; + s->cs[frame].fKeyFrame = !!(idx->aIndex[j].dwFlags&AVIIF_KEYFRAME) + || s->strh.fccType == FCC('auds') // FIXME: some audio index is without any kf flag + || frame == 0; // grrr + s->cs[frame].fChunkHdr = j == len-1 || idx->aIndex[j].dwOffset != idx->aIndex[j+1].dwOffset; + s->cs[frame].orgsize = idx->aIndex[j].dwSize; + + frame++; + size += s->GetChunkSize(idx->aIndex[j].dwSize); + } + } + + s->totalsize = size; + } + } + + m_idx1.Free(); + for(int i = 0; i < (int)m_avih.dwStreams; i++) + m_strms[i]->indx.Free(); + + return S_OK; } void CAviFile::EmptyIndex() { - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - strm_t* s = m_strms[i]; - s->cs.RemoveAll(); - s->totalsize = 0; - } + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + strm_t* s = m_strms[i]; + s->cs.RemoveAll(); + s->totalsize = 0; + } } bool CAviFile::IsInterleaved(bool fKeepInfo) { - if(m_strms.GetCount() < 2) - return(true); - /* - if(m_avih.dwFlags&AVIF_ISINTERLEAVED) // not reliable, nandub can write f*cked up files and still sets it - return(true); - */ - for(int i = 0; i < (int)m_avih.dwStreams; i++) - m_strms[i]->cs2.SetCount(m_strms[i]->cs.GetCount()); - - DWORD* curchunks = DNew DWORD[m_avih.dwStreams]; - UINT64* cursizes = DNew UINT64[m_avih.dwStreams]; - - memset(curchunks, 0, sizeof(DWORD)*m_avih.dwStreams); - memset(cursizes, 0, sizeof(UINT64)*m_avih.dwStreams); - - int end = 0; - - while(1) - { - UINT64 fpmin = _I64_MAX; - - DWORD n = -1; - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - int curchunk = curchunks[i]; - CAtlArray& cs = m_strms[i]->cs; - if(curchunk >= cs.GetCount()) continue; + if(m_strms.GetCount() < 2) + return(true); +/* + if(m_avih.dwFlags&AVIF_ISINTERLEAVED) // not reliable, nandub can write f*cked up files and still sets it + return(true); +*/ + for(int i = 0; i < (int)m_avih.dwStreams; i++) + m_strms[i]->cs2.SetCount(m_strms[i]->cs.GetCount()); + + DWORD* curchunks = DNew DWORD[m_avih.dwStreams]; + UINT64* cursizes = DNew UINT64[m_avih.dwStreams]; + + memset(curchunks, 0, sizeof(DWORD)*m_avih.dwStreams); + memset(cursizes, 0, sizeof(UINT64)*m_avih.dwStreams); + + int end = 0; + + while(1) + { + UINT64 fpmin = _I64_MAX; + + DWORD n = -1; + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + int curchunk = curchunks[i]; + CAtlArray& cs = m_strms[i]->cs; + if(curchunk >= cs.GetCount()) continue; UINT64 fp = cs[curchunk].filepos; - if(fp < fpmin) - { - fpmin = fp; - n = i; - } - } - if(n == -1) break; - - strm_t* s = m_strms[n]; - DWORD& curchunk = curchunks[n]; - UINT64& cursize = cursizes[n]; - - if(!s->IsRawSubtitleStream()) - { - strm_t::chunk2& cs2 = s->cs2[curchunk]; - cs2.t = (DWORD)(s->GetRefTime(curchunk, cursize) >> 13); // for comparing later it is just as good as /10000 to get a near [ms] accuracy + if(fp < fpmin) {fpmin = fp; n = i;} + } + if(n == -1) break; + + strm_t* s = m_strms[n]; + DWORD& curchunk = curchunks[n]; + UINT64& cursize = cursizes[n]; + + if(!s->IsRawSubtitleStream()) + { + strm_t::chunk2& cs2 = s->cs2[curchunk]; + cs2.t = (DWORD)(s->GetRefTime(curchunk, cursize)>>13); // for comparing later it is just as good as /10000 to get a near [ms] accuracy // cs2.t = (DWORD)(s->GetRefTime(curchunk, cursize)/10000); - cs2.n = end++; - } + cs2.n = end++; + } - cursize = s->cs[curchunk].size; - curchunk++; - } + cursize = s->cs[curchunk].size; + curchunk++; + } - memset(curchunks, 0, sizeof(DWORD)*m_avih.dwStreams); + memset(curchunks, 0, sizeof(DWORD)*m_avih.dwStreams); - strm_t::chunk2 cs2last = { -1, 0}; + strm_t::chunk2 cs2last = {-1, 0}; - bool fInterleaved = true; + bool fInterleaved = true; - while(fInterleaved) - { - strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX}; + while(fInterleaved) + { + strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX}; - int n = -1; - for(int i = 0; i < (int)m_avih.dwStreams; i++) - { - int curchunk = curchunks[i]; - if(curchunk >= m_strms[i]->cs2.GetCount()) continue; - strm_t::chunk2& cs2 = m_strms[i]->cs2[curchunk]; - if(cs2.t < cs2min.t) - { - cs2min = cs2; - n = i; - } - } - if(n == -1) break; + int n = -1; + for(int i = 0; i < (int)m_avih.dwStreams; i++) + { + int curchunk = curchunks[i]; + if(curchunk >= m_strms[i]->cs2.GetCount()) continue; + strm_t::chunk2& cs2 = m_strms[i]->cs2[curchunk]; + if(cs2.t < cs2min.t) {cs2min = cs2; n = i;} + } + if(n == -1) break; - curchunks[n]++; + curchunks[n]++; - if(cs2last.t >= 0 && abs((int)cs2min.n - (int)cs2last.n) >= 1000) - fInterleaved = false; + if(cs2last.t >= 0 && abs((int)cs2min.n - (int)cs2last.n) >= 1000) + fInterleaved = false; - cs2last = cs2min; - } + cs2last = cs2min; + } - delete [] curchunks; - delete [] cursizes; + delete [] curchunks; + delete [] cursizes; - if(fInterleaved && !fKeepInfo) - { - // this is not needed anymore, let's save a little memory then - for(int i = 0; i < (int)m_avih.dwStreams; i++) - m_strms[i]->cs2.RemoveAll(); - } + if(fInterleaved && !fKeepInfo) + { + // this is not needed anymore, let's save a little memory then + for(int i = 0; i < (int)m_avih.dwStreams; i++) + m_strms[i]->cs2.RemoveAll(); + } - return(fInterleaved); + return(fInterleaved); } REFERENCE_TIME CAviFile::strm_t::GetRefTime(DWORD frame, UINT64 size) { - float dframe = frame; + float dframe = frame; - if(strh.fccType == FCC('auds')) - { - WAVEFORMATEX* wfe = (WAVEFORMATEX*)strf.GetData(); + if(strh.fccType == FCC('auds')) + { + WAVEFORMATEX* wfe = (WAVEFORMATEX*)strf.GetData(); - dframe = wfe->nBlockAlign ? 1.0f * size / wfe->nBlockAlign : 0; - } + dframe = wfe->nBlockAlign ? 1.0f * size / wfe->nBlockAlign : 0; + } - float scale_per_rate = strh.dwRate ? 1.0f * strh.dwScale / strh.dwRate : 0; + float scale_per_rate = strh.dwRate ? 1.0f * strh.dwScale / strh.dwRate : 0; - return (REFERENCE_TIME)(scale_per_rate * dframe * 10000000 + 0.5f); + return (REFERENCE_TIME)(scale_per_rate * dframe * 10000000 + 0.5f); } int CAviFile::strm_t::GetFrame(REFERENCE_TIME rt) { - int frame = -1; + int frame = -1; - float rate_per_scale = strh.dwScale ? 1.0f * strh.dwRate / strh.dwScale : 0; + float rate_per_scale = strh.dwScale ? 1.0f * strh.dwRate / strh.dwScale : 0; - if(strh.fccType == FCC('auds')) - { - WAVEFORMATEX* wfe = (WAVEFORMATEX*)strf.GetData(); + if(strh.fccType == FCC('auds')) + { + WAVEFORMATEX* wfe = (WAVEFORMATEX*)strf.GetData(); - __int64 size = (__int64)(rate_per_scale * wfe->nBlockAlign * rt / 10000000 + 0.5f); + __int64 size = (__int64)(rate_per_scale * wfe->nBlockAlign * rt / 10000000 + 0.5f); - for(frame = 0; frame < cs.GetCount(); frame++) - { - if(cs[frame].size > size) - { - frame--; - break; - } - } - } - else - { - frame = (int)(rate_per_scale * rt / 10000000 + 0.5f); - } + for(frame = 0; frame < cs.GetCount(); frame++) + { + if(cs[frame].size > size) + { + frame--; + break; + } + } + } + else + { + frame = (int)(rate_per_scale * rt / 10000000 + 0.5f); + } - if(frame >= cs.GetCount()) frame = cs.GetCount() - 1; + if(frame >= cs.GetCount()) frame = cs.GetCount()-1; - return frame; + return frame; } int CAviFile::strm_t::GetKeyFrame(REFERENCE_TIME rt) { - int i = GetFrame(rt); - for(; i > 0; i--) - { - if(cs[i].fKeyFrame) break; - } - return(i); + int i = GetFrame(rt); + for(; i > 0; i--) {if(cs[i].fKeyFrame) break;} + return(i); } DWORD CAviFile::strm_t::GetChunkSize(DWORD size) { - if(strh.fccType == FCC('auds')) - { - WORD nBlockAlign = ((WAVEFORMATEX*)strf.GetData())->nBlockAlign; - size = nBlockAlign ? (size + (nBlockAlign - 1)) / nBlockAlign * nBlockAlign : 0; // round up for nando's vbr hack - } + if(strh.fccType == FCC('auds')) + { + WORD nBlockAlign = ((WAVEFORMATEX*)strf.GetData())->nBlockAlign; + size = nBlockAlign ? (size + (nBlockAlign-1)) / nBlockAlign * nBlockAlign : 0; // round up for nando's vbr hack + } - return size; + return size; } bool CAviFile::strm_t::IsRawSubtitleStream() { - return strh.fccType == FCC('txts') && cs.GetCount() == 1; + return strh.fccType == FCC('txts') && cs.GetCount() == 1; } diff --git a/src/filters/parser/AviSplitter/AviFile.h b/src/filters/parser/AviSplitter/AviFile.h index 5d7a8ddb0..6ef8cf9d3 100644 --- a/src/filters/parser/AviSplitter/AviFile.h +++ b/src/filters/parser/AviSplitter/AviFile.h @@ -5,62 +5,50 @@ class CAviFile : public CBaseSplitterFile { - HRESULT Init(); - HRESULT Parse(DWORD parentid, __int64 end); - HRESULT BuildAMVIndex(); + HRESULT Init(); + HRESULT Parse(DWORD parentid, __int64 end); + HRESULT BuildAMVIndex(); public: - CAviFile(IAsyncReader* pAsyncReader, HRESULT& hr); + CAviFile(IAsyncReader* pAsyncReader, HRESULT& hr); - //using CBaseSplitterFile::Read; - template HRESULT Read(T& var, int offset = 0); + //using CBaseSplitterFile::Read; + template HRESULT Read(T& var, int offset = 0); - AVIMAINHEADER m_avih; - struct ODMLExtendedAVIHeader - { - DWORD dwTotalFrames; - } m_dmlh; + AVIMAINHEADER m_avih; + struct ODMLExtendedAVIHeader {DWORD dwTotalFrames;} m_dmlh; // VideoPropHeader m_vprp; - struct strm_t - { - AVISTREAMHEADER strh; - CAtlArray strf; - CStringA strn; - CAutoPtr indx; - struct chunk - { - UINT64 fKeyFrame: 1, fChunkHdr: 1, size: 62; - UINT64 filepos; - DWORD orgsize; - }; - CAtlArray cs; - UINT64 totalsize; - REFERENCE_TIME GetRefTime(DWORD frame, UINT64 size); - int GetTime(DWORD frame, UINT64 size); - int GetFrame(REFERENCE_TIME rt); - int GetKeyFrame(REFERENCE_TIME rt); - DWORD GetChunkSize(DWORD size); - bool IsRawSubtitleStream(); - - // tmp - struct chunk2 - { - DWORD t; - DWORD n; - }; - CAtlArray cs2; - }; - CAutoPtrArray m_strms; - CAtlMap m_info; - CAutoPtr m_idx1; - - CAtlList m_movis; - bool m_isamv; - - REFERENCE_TIME GetTotalTime(); - HRESULT BuildIndex(); - void EmptyIndex(); - bool IsInterleaved(bool fKeepInfo = false); + struct strm_t + { + AVISTREAMHEADER strh; + CAtlArray strf; + CStringA strn; + CAutoPtr indx; + struct chunk {UINT64 fKeyFrame:1, fChunkHdr:1, size:62; UINT64 filepos; DWORD orgsize;}; + CAtlArray cs; + UINT64 totalsize; + REFERENCE_TIME GetRefTime(DWORD frame, UINT64 size); + int GetTime(DWORD frame, UINT64 size); + int GetFrame(REFERENCE_TIME rt); + int GetKeyFrame(REFERENCE_TIME rt); + DWORD GetChunkSize(DWORD size); + bool IsRawSubtitleStream(); + + // tmp + struct chunk2 {DWORD t; DWORD n;}; + CAtlArray cs2; + }; + CAutoPtrArray m_strms; + CAtlMap m_info; + CAutoPtr m_idx1; + + CAtlList m_movis; + bool m_isamv; + + REFERENCE_TIME GetTotalTime(); + HRESULT BuildIndex(); + void EmptyIndex(); + bool IsInterleaved(bool fKeepInfo = false); }; #define TRACKNUM(fcc) (10*((fcc&0xff)-0x30) + (((fcc>>8)&0xff)-0x30)) diff --git a/src/filters/parser/AviSplitter/AviReportWnd.cpp b/src/filters/parser/AviSplitter/AviReportWnd.cpp index 76e1a0ab4..95a20c668 100644 --- a/src/filters/parser/AviSplitter/AviReportWnd.cpp +++ b/src/filters/parser/AviSplitter/AviReportWnd.cpp @@ -7,165 +7,165 @@ CAviReportWnd::CAviReportWnd() { - m_font.CreateFont(12, 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 0, 0, _T("MS Shell Dlg")); + m_font.CreateFont(12, 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 0, 0, _T("MS Shell Dlg")); } bool CAviReportWnd::DoModal(CAviFile* pAF, bool fHideChecked, bool fShowWarningText) { - m_nChunks = 0; - m_rtDur = 0; + m_nChunks = 0; + m_rtDur = 0; - for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) - { - int cnt = pAF->m_strms[i]->cs2.GetCount(); - if(cnt <= 0) continue; - CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1]; - m_nChunks = max(m_nChunks, c2.n); - m_rtDur = max(m_rtDur, (REFERENCE_TIME)c2.t << 13); - } + for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) + { + int cnt = pAF->m_strms[i]->cs2.GetCount(); + if(cnt <= 0) continue; + CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1]; + m_nChunks = max(m_nChunks, c2.n); + m_rtDur = max(m_rtDur, (REFERENCE_TIME)c2.t<<13); + } - CRect r, r2; - GetDesktopWindow()->GetWindowRect(r); - r.DeflateRect(r.Width() / 4, r.Height() / 4); + CRect r, r2; + GetDesktopWindow()->GetWindowRect(r); + r.DeflateRect(r.Width()/4, r.Height()/4); - LPCTSTR wndclass = AfxRegisterWndClass( - CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS, - AfxGetApp()->LoadStandardCursor(IDC_ARROW), - (HBRUSH)(COLOR_BTNFACE + 1), 0); + LPCTSTR wndclass = AfxRegisterWndClass( + CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS, + AfxGetApp()->LoadStandardCursor(IDC_ARROW), + (HBRUSH)(COLOR_BTNFACE + 1), 0); - CreateEx(0, wndclass, TITLE, WS_POPUPWINDOW | WS_CAPTION | WS_CLIPCHILDREN, r, NULL, 0); + CreateEx(0, wndclass, TITLE, WS_POPUPWINDOW|WS_CAPTION|WS_CLIPCHILDREN, r, NULL, 0); - CRect cr; - GetClientRect(cr); - cr.DeflateRect(10, 10); + CRect cr; + GetClientRect(cr); + cr.DeflateRect(10, 10); - SetFont(&m_font, FALSE); + SetFont(&m_font, FALSE); - CDC* pDC = GetDC(); - CFont* pOldFont = pDC->SelectObject(&m_font); + CDC* pDC = GetDC(); + CFont* pOldFont = pDC->SelectObject(&m_font); - // + // - CString str( - _T("This AVI file was not prepared for sequential reading, the alternative ") - _T("'Avi Splitter' will now let the default one handle it. ") - _T("The complete reinterleaving of this file is strongly recommended before ") - _T("burning it onto a slow media like cd-rom.")); + CString str( + _T("This AVI file was not prepared for sequential reading, the alternative ") + _T("'Avi Splitter' will now let the default one handle it. ") + _T("The complete reinterleaving of this file is strongly recommended before ") + _T("burning it onto a slow media like cd-rom.")); - r = cr; + r = cr; - pDC->DrawText(str, r, DT_WORDBREAK | DT_CALCRECT); - r.right = cr.right; + pDC->DrawText(str, r, DT_WORDBREAK|DT_CALCRECT); + r.right = cr.right; - m_message.Create(str, WS_CHILD | WS_VISIBLE, r, this); - m_message.SetFont(&m_font, FALSE); + m_message.Create(str, WS_CHILD|WS_VISIBLE, r, this); + m_message.SetFont(&m_font, FALSE); - // + // - r.SetRect(cr.left, r.bottom + 10, cr.right, cr.bottom); + r.SetRect(cr.left, r.bottom + 10, cr.right, cr.bottom); - str = _T("Do not show this dialog again (hold Shift to re-enable it)"); + str = _T("Do not show this dialog again (hold Shift to re-enable it)"); - pDC->DrawText(str, r, DT_WORDBREAK | DT_CALCRECT); - r.right = cr.right; + pDC->DrawText(str, r, DT_WORDBREAK|DT_CALCRECT); + r.right = cr.right; - m_checkbox.Create(str, WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX, r, this, IDC_DONOTSHOWAGAINCHECK); - m_checkbox.SetFont(&m_font, FALSE); + m_checkbox.Create(str, WS_CHILD|WS_VISIBLE|BS_CHECKBOX|BS_AUTOCHECKBOX, r, this, IDC_DONOTSHOWAGAINCHECK); + m_checkbox.SetFont(&m_font, FALSE); - CheckDlgButton(IDC_DONOTSHOWAGAINCHECK, fHideChecked ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(IDC_DONOTSHOWAGAINCHECK, fHideChecked?BST_CHECKED:BST_UNCHECKED); - // + // - if(!fShowWarningText) - { - m_message.ShowWindow(SW_HIDE); - m_checkbox.ShowWindow(SW_HIDE); - r = cr; - } - else - { - r.SetRect(cr.left, r.bottom + 10, cr.right, cr.bottom); - } + if(!fShowWarningText) + { + m_message.ShowWindow(SW_HIDE); + m_checkbox.ShowWindow(SW_HIDE); + r = cr; + } + else + { + r.SetRect(cr.left, r.bottom + 10, cr.right, cr.bottom); + } - m_graph.Create(pAF, r, this); + m_graph.Create(pAF, r, this); - // + // - pDC->SelectObject(pOldFont); - ReleaseDC(pDC); + pDC->SelectObject(pOldFont); + ReleaseDC(pDC); - SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - SetForegroundWindow(); - ShowWindow(SW_SHOWNORMAL); + SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + SetForegroundWindow(); + ShowWindow(SW_SHOWNORMAL); - return !!RunModalLoop(); + return !!RunModalLoop(); } IMPLEMENT_DYNCREATE(CAviReportWnd, CWnd) BEGIN_MESSAGE_MAP(CAviReportWnd, CWnd) - ON_WM_CLOSE() - ON_WM_MOUSEMOVE() + ON_WM_CLOSE() + ON_WM_MOUSEMOVE() END_MESSAGE_MAP() void CAviReportWnd::OnClose() { - EndModalLoop(IsDlgButtonChecked(IDC_DONOTSHOWAGAINCHECK)); - __super::OnClose(); + EndModalLoop(IsDlgButtonChecked(IDC_DONOTSHOWAGAINCHECK)); + __super::OnClose(); } void CAviReportWnd::OnMouseMove(UINT nFlags, CPoint p) { - MapWindowPoints(&m_graph, &p, 1); - - CRect r, r2; - m_graph.GetClientRect(r); - r2 = r; - r.bottom -= GRAPHFOOTER; - r2.top = r.bottom; - - if(r.PtInRect(p)) - { - SetCapture(); - - int x = p.x - r.left; - int y = r.bottom - p.y; - - REFERENCE_TIME rt = m_rtDur * x / r.Width(); - int chunk = (int)(1.0 * m_nChunks * y / r.Height()); - - rt /= 10000; - int ms = (int)(rt % 1000); - rt /= 1000; - int s = (int)(rt % 60); - rt /= 60; - int m = (int)(rt % 60); - rt /= 60; - int h = (int)(rt); - - CString str; - str.Format(_T("%s (%d - %d:%02d:%02d.%03d)"), TITLE, chunk, h, m, s, ms); - SetWindowText(str); - } - else if(r2.PtInRect(p)) - { - SetCapture(); - - int dist = m_graph.GetChunkDist(p.x - r2.left); - CString str; - str.Format(_T("%s (chunk distance: %d"), TITLE, dist); - if(dist >= 1000) str += _T(" - over the limit!"); - str += ")"; - SetWindowText(str); - } - else if(GetCapture() == this) - { - SetWindowText(TITLE); - - ReleaseCapture(); - } - - __super::OnMouseMove(nFlags, p); + MapWindowPoints(&m_graph, &p, 1); + + CRect r, r2; + m_graph.GetClientRect(r); + r2 = r; + r.bottom -= GRAPHFOOTER; + r2.top = r.bottom; + + if(r.PtInRect(p)) + { + SetCapture(); + + int x = p.x - r.left; + int y = r.bottom - p.y; + + REFERENCE_TIME rt = m_rtDur * x / r.Width(); + int chunk = (int)(1.0 * m_nChunks * y / r.Height()); + + rt /= 10000; + int ms = (int)(rt%1000); + rt /= 1000; + int s = (int)(rt%60); + rt /= 60; + int m = (int)(rt%60); + rt /= 60; + int h = (int)(rt); + + CString str; + str.Format(_T("%s (%d - %d:%02d:%02d.%03d)"), TITLE, chunk, h, m, s, ms); + SetWindowText(str); + } + else if(r2.PtInRect(p)) + { + SetCapture(); + + int dist = m_graph.GetChunkDist(p.x - r2.left); + CString str; + str.Format(_T("%s (chunk distance: %d"), TITLE, dist); + if(dist >= 1000) str += _T(" - over the limit!"); + str += ")"; + SetWindowText(str); + } + else if(GetCapture() == this) + { + SetWindowText(TITLE); + + ReleaseCapture(); + } + + __super::OnMouseMove(nFlags, p); } ////////////// @@ -176,187 +176,169 @@ CAviPlotterWnd::CAviPlotterWnd() bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd) { - if(!CreateEx(WS_EX_CLIENTEDGE, _T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE, r, pParentWnd, 0)) - return(false); - - GetClientRect(r); - int w = r.Width(); - int h = r.Height() - GRAPHFOOTER; - - CDC* pDC = GetDC(); - m_dc.CreateCompatibleDC(pDC); - m_bm.CreateCompatibleBitmap(pDC, r.Width(), r.Height()); - ReleaseDC(pDC); - - CBitmap* pOldBitmap = m_dc.SelectObject(&m_bm); - - m_dc.FillSolidRect(r, 0); - - { - CPen pen(PS_DOT, 1, 0x008000); - CPen* pOldPen = m_dc.SelectObject(&pen); - for(int y = 0, dy = max(h / 10, 1); y < h; y += dy) - { - if(y == 0) continue; - m_dc.MoveTo(0, y); - m_dc.LineTo(w, y); - } - for(int x = 0, dx = max(w / 10, 1); x < w; x += dx) - { - if(x == 0) continue; - m_dc.MoveTo(x, 0); - m_dc.LineTo(x, w); - } - m_dc.SelectObject(pOldPen); - } - - { - CPen pen(PS_SOLID, 1, 0x00ff00); - CPen* pOldPen = m_dc.SelectObject(&pen); - m_dc.MoveTo(15, 30); - m_dc.LineTo(15, 2); - m_dc.LineTo(19, 10); - m_dc.LineTo(11, 10); - m_dc.LineTo(15, 2); - m_dc.MoveTo(w - 30 - 10, h - 15); - m_dc.LineTo(w - 2 - 10, h - 15); - m_dc.LineTo(w - 10 - 10, h - 19); - m_dc.LineTo(w - 10 - 10, h - 11); - m_dc.LineTo(w - 2 - 10, h - 15); - m_dc.SelectObject(pOldPen); - - m_dc.SetTextColor(0x008000); - m_dc.TextOut(20, 10, _T("Chunk")); - - CSize size = m_dc.GetTextExtent(_T("Time")); - m_dc.TextOut(w - size.cx - 10, h - size.cy - 20, _T("Time")); - } - - COLORREF clr[] = {0x0000ff, 0xff0000, 0x40ffff, 0xff40ff, 0xffff40, 0xffffff}; - - for(int i = 0, y = 40, dy = m_dc.GetTextExtent(_T("Stream N")).cy + 1; i < (int)pAF->m_avih.dwStreams; i++, y += dy) - { - m_dc.SetTextColor(clr[i%pAF->m_avih.dwStreams]); - m_dc.SetBkMode(TRANSPARENT); - CString str; - str.Format(_T("Stream %d"), i); - m_dc.TextOut(10, y, str); - } - - DWORD nmax = 0, tmax = 0; - - for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) - { - int cnt = pAF->m_strms[i]->cs2.GetCount(); - if(cnt <= 0) continue; - CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1]; - nmax = max(nmax, c2.n); - tmax = max(tmax, c2.t); - } - - if(nmax > 0 && tmax > 0) - { - CAtlArray pen; - pen.SetCount(pAF->m_avih.dwStreams); - for(int i = 0; i < pen.GetCount(); i++) - pen[i].CreatePen(PS_SOLID, 2, clr[i]); - - CAtlArray pp; - pp.SetCount(pAF->m_avih.dwStreams); - for(int i = 0; i < pen.GetCount(); i++) - pp[i].SetPoint(-1, -1); - - m_chunkdist.SetCount(w); - memset(m_chunkdist.GetData(), 0, sizeof(int)*w); - - DWORD* curchunks = DNew DWORD[pAF->m_avih.dwStreams]; - memset(curchunks, 0, sizeof(DWORD)*pAF->m_avih.dwStreams); - - CAviFile::strm_t::chunk2 cs2last = { -1, 0}; - - while(1) - { - CAviFile::strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX}; - - int n = -1; - for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) - { - int curchunk = curchunks[i]; - if(curchunk >= pAF->m_strms[i]->cs2.GetCount()) continue; - CAviFile::strm_t::chunk2& cs2 = pAF->m_strms[i]->cs2[curchunk]; - if(cs2.t < cs2min.t) - { - cs2min = cs2; - n = i; - } - } - if(n == -1) break; - - - CPoint p; - p.x = (int)(1.0 * w * cs2min.t / tmax); - p.y = (int)(h - 1.0 * h * cs2min.n / nmax); - if(pp[n] != p) - { - CPen* pOldPen = m_dc.SelectObject(&pen[n]); - if(pp[n] == CPoint(-1, -1)) m_dc.MoveTo(p); - else - { - m_dc.MoveTo(pp[n]); - m_dc.LineTo(p); - } - m_dc.SelectObject(pOldPen); - pp[n] = p; - } - - int dist = abs((int)cs2min.n - (int)cs2last.n); - - if(cs2last.t >= 0 /*&& dist >= 1000*/) - { - if(p.x >= 0 && p.x < w) - { - m_chunkdist[p.x] = max(m_chunkdist[p.x], dist); - } - } - - curchunks[n]++; - cs2last = cs2min; - } - - CPen red(PS_SOLID, 1, 0x0000ff); - CPen green(PS_SOLID, 1, 0x00ff00); - - for(int x = 0; x < w; x++) - { - CPen* pOldPen = m_dc.SelectObject(m_chunkdist[x] >= 1000 ? &red : &green); - m_dc.MoveTo(x, h); - m_dc.LineTo(x, h + GRAPHFOOTER); - m_dc.SelectObject(pOldPen); - } - - delete [] curchunks; - } - - m_dc.SelectObject(pOldBitmap); - - return(true); + if(!CreateEx(WS_EX_CLIENTEDGE, _T("STATIC"), _T(""), WS_CHILD|WS_VISIBLE, r, pParentWnd, 0)) + return(false); + + GetClientRect(r); + int w = r.Width(); + int h = r.Height() - GRAPHFOOTER; + + CDC* pDC = GetDC(); + m_dc.CreateCompatibleDC(pDC); + m_bm.CreateCompatibleBitmap(pDC, r.Width(), r.Height()); + ReleaseDC(pDC); + + CBitmap* pOldBitmap = m_dc.SelectObject(&m_bm); + + m_dc.FillSolidRect(r, 0); + + { + CPen pen(PS_DOT, 1, 0x008000); + CPen* pOldPen = m_dc.SelectObject(&pen); + for(int y = 0, dy = max(h/10,1); y < h; y += dy) {if(y == 0) continue; m_dc.MoveTo(0, y); m_dc.LineTo(w, y);} + for(int x = 0, dx = max(w/10,1); x < w; x += dx) {if(x == 0) continue; m_dc.MoveTo(x, 0); m_dc.LineTo(x, w);} + m_dc.SelectObject(pOldPen); + } + + { + CPen pen(PS_SOLID, 1, 0x00ff00); + CPen* pOldPen = m_dc.SelectObject(&pen); + m_dc.MoveTo(15, 30); + m_dc.LineTo(15, 2); + m_dc.LineTo(19, 10); + m_dc.LineTo(11, 10); + m_dc.LineTo(15, 2); + m_dc.MoveTo(w-30-10, h-15); + m_dc.LineTo(w-2-10, h-15); + m_dc.LineTo(w-10-10, h-19); + m_dc.LineTo(w-10-10, h-11); + m_dc.LineTo(w-2-10, h-15); + m_dc.SelectObject(pOldPen); + + m_dc.SetTextColor(0x008000); + m_dc.TextOut(20, 10, _T("Chunk")); + + CSize size = m_dc.GetTextExtent(_T("Time")); + m_dc.TextOut(w - size.cx - 10, h - size.cy - 20, _T("Time")); + } + + COLORREF clr[] = {0x0000ff,0xff0000,0x40ffff,0xff40ff,0xffff40,0xffffff}; + + for(int i = 0, y = 40, dy = m_dc.GetTextExtent(_T("Stream N")).cy + 1; i < (int)pAF->m_avih.dwStreams; i++, y += dy) + { + m_dc.SetTextColor(clr[i%pAF->m_avih.dwStreams]); + m_dc.SetBkMode(TRANSPARENT); + CString str; + str.Format(_T("Stream %d"), i); + m_dc.TextOut(10, y, str); + } + + DWORD nmax = 0, tmax = 0; + + for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) + { + int cnt = pAF->m_strms[i]->cs2.GetCount(); + if(cnt <= 0) continue; + CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1]; + nmax = max(nmax, c2.n); + tmax = max(tmax, c2.t); + } + + if(nmax > 0 && tmax > 0) + { + CAtlArray pen; + pen.SetCount(pAF->m_avih.dwStreams); + for(int i = 0; i < pen.GetCount(); i++) + pen[i].CreatePen(PS_SOLID, 2, clr[i]); + + CAtlArray pp; + pp.SetCount(pAF->m_avih.dwStreams); + for(int i = 0; i < pen.GetCount(); i++) + pp[i].SetPoint(-1, -1); + + m_chunkdist.SetCount(w); + memset(m_chunkdist.GetData(), 0, sizeof(int)*w); + + DWORD* curchunks = DNew DWORD[pAF->m_avih.dwStreams]; + memset(curchunks, 0, sizeof(DWORD)*pAF->m_avih.dwStreams); + + CAviFile::strm_t::chunk2 cs2last = {-1, 0}; + + while(1) + { + CAviFile::strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX}; + + int n = -1; + for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) + { + int curchunk = curchunks[i]; + if(curchunk >= pAF->m_strms[i]->cs2.GetCount()) continue; + CAviFile::strm_t::chunk2& cs2 = pAF->m_strms[i]->cs2[curchunk]; + if(cs2.t < cs2min.t) {cs2min = cs2; n = i;} + } + if(n == -1) break; + + + CPoint p; + p.x = (int)(1.0 * w * cs2min.t / tmax); + p.y = (int)(h - 1.0 * h * cs2min.n / nmax); + if(pp[n] != p) + { + CPen* pOldPen = m_dc.SelectObject(&pen[n]); + if(pp[n] == CPoint(-1, -1)) m_dc.MoveTo(p); + else {m_dc.MoveTo(pp[n]); m_dc.LineTo(p);} + m_dc.SelectObject(pOldPen); + pp[n] = p; + } + + int dist = abs((int)cs2min.n - (int)cs2last.n); + + if(cs2last.t >= 0 /*&& dist >= 1000*/) + { + if(p.x >= 0 && p.x < w) + { + m_chunkdist[p.x] = max(m_chunkdist[p.x], dist); + } + } + + curchunks[n]++; + cs2last = cs2min; + } + + CPen red(PS_SOLID, 1, 0x0000ff); + CPen green(PS_SOLID, 1, 0x00ff00); + + for(int x = 0; x < w; x++) + { + CPen* pOldPen = m_dc.SelectObject(m_chunkdist[x] >= 1000 ? &red : &green); + m_dc.MoveTo(x, h); + m_dc.LineTo(x, h + GRAPHFOOTER); + m_dc.SelectObject(pOldPen); + } + + delete [] curchunks; + } + + m_dc.SelectObject(pOldBitmap); + + return(true); } IMPLEMENT_DYNCREATE(CAviPlotterWnd, CWnd) BEGIN_MESSAGE_MAP(CAviPlotterWnd, CWnd) - ON_WM_PAINT() + ON_WM_PAINT() END_MESSAGE_MAP() void CAviPlotterWnd::OnPaint() { - CPaintDC dc(this); // device context for painting + CPaintDC dc(this); // device context for painting - CRect r; - GetClientRect(r); + CRect r; + GetClientRect(r); - CBitmap* pOld = m_dc.SelectObject(&m_bm); - dc.BitBlt(0, 0, r.Width(), r.Height(), &m_dc, 0, 0, SRCCOPY); - m_dc.SelectObject(pOld); + CBitmap* pOld = m_dc.SelectObject(&m_bm); + dc.BitBlt(0, 0, r.Width(), r.Height(), &m_dc, 0, 0, SRCCOPY); + m_dc.SelectObject(pOld); } diff --git a/src/filters/parser/AviSplitter/AviReportWnd.h b/src/filters/parser/AviSplitter/AviReportWnd.h index cd30807e0..cd5c3b331 100644 --- a/src/filters/parser/AviSplitter/AviReportWnd.h +++ b/src/filters/parser/AviSplitter/AviReportWnd.h @@ -4,47 +4,44 @@ class CAviPlotterWnd : public CStatic { - DECLARE_DYNCREATE(CAviPlotterWnd) + DECLARE_DYNCREATE(CAviPlotterWnd) private: - CDC m_dc; - CBitmap m_bm; + CDC m_dc; + CBitmap m_bm; - CAtlArray m_chunkdist; + CAtlArray m_chunkdist; public: - CAviPlotterWnd(); - bool Create(CAviFile* pAF, CRect r, CWnd* pParentWnd); + CAviPlotterWnd(); + bool Create(CAviFile* pAF, CRect r, CWnd* pParentWnd); - int GetChunkDist(int x) - { - return x >= 0 && x < m_chunkdist.GetCount() ? m_chunkdist[x] : 0; - } + int GetChunkDist(int x) {return x >= 0 && x < m_chunkdist.GetCount() ? m_chunkdist[x] : 0;} - DECLARE_MESSAGE_MAP() - afx_msg void OnPaint(); + DECLARE_MESSAGE_MAP() + afx_msg void OnPaint(); }; class CAviReportWnd : public CWnd { - DECLARE_DYNCREATE(CAviReportWnd) + DECLARE_DYNCREATE(CAviReportWnd) protected: - CFont m_font; - CStatic m_message; - CButton m_checkbox; - CAviPlotterWnd m_graph; + CFont m_font; + CStatic m_message; + CButton m_checkbox; + CAviPlotterWnd m_graph; - int m_nChunks; - REFERENCE_TIME m_rtDur; + int m_nChunks; + REFERENCE_TIME m_rtDur; public: - CAviReportWnd(); - bool DoModal(CAviFile* pAF, bool fHideChecked, bool fShowWarningText); + CAviReportWnd(); + bool DoModal(CAviFile* pAF, bool fHideChecked, bool fShowWarningText); - DECLARE_MESSAGE_MAP() - afx_msg void OnClose(); - afx_msg void OnMouseMove(UINT nFlags, CPoint point); + DECLARE_MESSAGE_MAP() + afx_msg void OnClose(); + afx_msg void OnMouseMove(UINT nFlags, CPoint point); }; diff --git a/src/filters/parser/AviSplitter/AviSplitter.cpp b/src/filters/parser/AviSplitter/AviSplitter.cpp index a34593187..d31561221 100644 --- a/src/filters/parser/AviSplitter/AviSplitter.cpp +++ b/src/filters/parser/AviSplitter/AviSplitter.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -29,8 +29,8 @@ const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = { - {&MEDIATYPE_Stream, &MEDIASUBTYPE_Avi}, - {&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}, + {&MEDIATYPE_Stream, &MEDIASUBTYPE_Avi}, + {&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}, }; const AMOVIESETUP_PIN sudpPins[] = @@ -41,39 +41,39 @@ const AMOVIESETUP_PIN sudpPins[] = const AMOVIESETUP_FILTER sudFilter[] = { - {&__uuidof(CAviSplitterFilter), L"MPC - Avi Splitter", MERIT_NORMAL + 1, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}, - {&__uuidof(CAviSourceFilter), L"MPC - Avi Source", MERIT_NORMAL + 1, 0, NULL, CLSID_LegacyAmFilterCategory}, + {&__uuidof(CAviSplitterFilter), L"MPC - Avi Splitter", MERIT_NORMAL+1, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}, + {&__uuidof(CAviSourceFilter), L"MPC - Avi Source", MERIT_NORMAL+1, 0, NULL, CLSID_LegacyAmFilterCategory}, }; CFactoryTemplate g_Templates[] = { - {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance, NULL, &sudFilter[0]}, - {sudFilter[1].strName, sudFilter[1].clsID, CreateInstance, NULL, &sudFilter[1]}, + {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance, NULL, &sudFilter[0]}, + {sudFilter[1].strName, sudFilter[1].clsID, CreateInstance, NULL, &sudFilter[1]}, }; int g_cTemplates = countof(g_Templates); STDAPI DllRegisterServer() { - CAtlList chkbytes; - chkbytes.AddTail(_T("0,4,,52494646,8,4,,41564920")); // 'RIFF' ... 'AVI ' - chkbytes.AddTail(_T("0,4,,52494646,8,4,,41564958")); // 'RIFF' ... 'AVIX' - chkbytes.AddTail(_T("0,4,,52494646,8,4,,414D5620")); // 'RIFF' ... 'AMV ' - - RegisterSourceFilter( - CLSID_AsyncReader, - MEDIASUBTYPE_Avi, - chkbytes, - _T(".avi"), _T(".divx"), _T(".vp6"), _T(".amv"), NULL); - - return AMovieDllRegisterServer2(TRUE); + CAtlList chkbytes; + chkbytes.AddTail(_T("0,4,,52494646,8,4,,41564920")); // 'RIFF' ... 'AVI ' + chkbytes.AddTail(_T("0,4,,52494646,8,4,,41564958")); // 'RIFF' ... 'AVIX' + chkbytes.AddTail(_T("0,4,,52494646,8,4,,414D5620")); // 'RIFF' ... 'AMV ' + + RegisterSourceFilter( + CLSID_AsyncReader, + MEDIASUBTYPE_Avi, + chkbytes, + _T(".avi"), _T(".divx"), _T(".vp6"), _T(".amv"), NULL); + + return AMovieDllRegisterServer2(TRUE); } STDAPI DllUnregisterServer() { // UnRegisterSourceFilter(MEDIASUBTYPE_Avi); - return AMovieDllRegisterServer2(FALSE); + return AMovieDllRegisterServer2(FALSE); } extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID); @@ -81,27 +81,27 @@ extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID); class CAviSplitterApp : public CWinApp { public: - CAviSplitterApp() {} - - BOOL InitInstance() - { - if(!__super::InitInstance()) return FALSE; - DllEntryPoint(m_hInstance, DLL_PROCESS_ATTACH, 0); - return TRUE; - } - - BOOL ExitInstance() - { - DllEntryPoint(m_hInstance, DLL_PROCESS_DETACH, 0); - return __super::ExitInstance(); - } - - void SetDefaultRegistryKey() - { - SetRegistryKey(_T("Gabest")); - } - - DECLARE_MESSAGE_MAP() + CAviSplitterApp() {} + + BOOL InitInstance() + { + if(!__super::InitInstance()) return FALSE; + DllEntryPoint(m_hInstance, DLL_PROCESS_ATTACH, 0); + return TRUE; + } + + BOOL ExitInstance() + { + DllEntryPoint(m_hInstance, DLL_PROCESS_DETACH, 0); + return __super::ExitInstance(); + } + + void SetDefaultRegistryKey() + { + SetRegistryKey(_T("Gabest")); + } + + DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(CAviSplitterApp, CWinApp) @@ -116,737 +116,709 @@ CAviSplitterApp theApp; // CAviSplitterFilter::CAviSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr) - : CBaseSplitterFilter(NAME("CAviSplitterFilter"), pUnk, phr, __uuidof(this)) - , m_timeformat(TIME_FORMAT_MEDIA_TIME) + : CBaseSplitterFilter(NAME("CAviSplitterFilter"), pUnk, phr, __uuidof(this)) + , m_timeformat(TIME_FORMAT_MEDIA_TIME) { } STDMETHODIMP CAviSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv) { - CheckPointer(ppv, E_POINTER); + CheckPointer(ppv, E_POINTER); - *ppv = NULL; + *ppv = NULL; - return - __super::NonDelegatingQueryInterface(riid, ppv); + return + __super::NonDelegatingQueryInterface(riid, ppv); } HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader) { - CheckPointer(pAsyncReader, E_POINTER); + CheckPointer(pAsyncReader, E_POINTER); - HRESULT hr = E_FAIL; + HRESULT hr = E_FAIL; - m_pFile.Free(); - m_tFrame.Free(); + m_pFile.Free(); + m_tFrame.Free(); - m_pFile.Attach(DNew CAviFile(pAsyncReader, hr)); - if(!m_pFile) return E_OUTOFMEMORY; + m_pFile.Attach(DNew CAviFile(pAsyncReader, hr)); + if(!m_pFile) return E_OUTOFMEMORY; - bool fShiftDown = !!(::GetKeyState(VK_SHIFT) & 0x8000); - bool fShowWarningText = !m_pFile->IsInterleaved(fShiftDown); + bool fShiftDown = !!(::GetKeyState(VK_SHIFT)&0x8000); + bool fShowWarningText = !m_pFile->IsInterleaved(fShiftDown); - if(SUCCEEDED(hr) && (fShowWarningText || fShiftDown)) - { + if(SUCCEEDED(hr) && (fShowWarningText || fShiftDown)) + { #ifdef REGISTER_FILTER - AFX_MANAGE_STATE(AfxGetStaticModuleState()); + AFX_MANAGE_STATE(AfxGetStaticModuleState()); #endif - bool fHideWarning = !!AfxGetApp()->GetProfileInt(_T("Settings"), _T("HideAviSplitterWarning"), 0); - - if(!fHideWarning && !dynamic_cast(this) || fShiftDown) - { - CAviReportWnd wnd; - fHideWarning = wnd.DoModal(m_pFile, fHideWarning, fShowWarningText); - AfxGetApp()->WriteProfileInt(_T("Settings"), _T("HideAviSplitterWarning"), fHideWarning); - } - - if(fShowWarningText) hr = E_FAIL; - } - - if(FAILED(hr)) - { - m_pFile.Free(); - return hr; - } - - m_rtNewStart = m_rtCurrent = 0; - m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->GetTotalTime(); - - bool fHasIndex = false; - - for(DWORD i = 0; !fHasIndex && i < m_pFile->m_strms.GetCount(); i++) - if(m_pFile->m_strms[i]->cs.GetCount() > 0) - fHasIndex = true; - - for(DWORD i = 0; i < m_pFile->m_strms.GetCount(); i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - - if(fHasIndex && s->cs.GetCount() == 0) continue; - - CMediaType mt; - CAtlArray mts; - - CStringW name, label; - - if(s->strh.fccType == FCC('vids')) - { - label = L"Video"; - - ASSERT(s->strf.GetCount() >= sizeof(BITMAPINFOHEADER)); - - BITMAPINFOHEADER* pbmi = &((BITMAPINFO*)s->strf.GetData())->bmiHeader; - - mt.majortype = MEDIATYPE_Video; - mt.subtype = FOURCCMap(pbmi->biCompression); - mt.formattype = FORMAT_VideoInfo; - VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + s->strf.GetCount() - sizeof(BITMAPINFOHEADER)); - memset(mt.Format(), 0, mt.FormatLength()); - memcpy(&pvih->bmiHeader, s->strf.GetData(), s->strf.GetCount()); - if(s->strh.dwRate > 0) pvih->AvgTimePerFrame = 10000000i64 * s->strh.dwScale / s->strh.dwRate; - switch(pbmi->biCompression) - { - case BI_RGB: - case BI_BITFIELDS: - mt.subtype = - pbmi->biBitCount == 1 ? MEDIASUBTYPE_RGB1 : - pbmi->biBitCount == 4 ? MEDIASUBTYPE_RGB4 : - pbmi->biBitCount == 8 ? MEDIASUBTYPE_RGB8 : - pbmi->biBitCount == 16 ? MEDIASUBTYPE_RGB565 : - pbmi->biBitCount == 24 ? MEDIASUBTYPE_RGB24 : - pbmi->biBitCount == 32 ? MEDIASUBTYPE_ARGB32 : - MEDIASUBTYPE_NULL; - break; + bool fHideWarning = !!AfxGetApp()->GetProfileInt(_T("Settings"), _T("HideAviSplitterWarning"), 0); + + if(!fHideWarning && !dynamic_cast(this) || fShiftDown) + { + CAviReportWnd wnd; + fHideWarning = wnd.DoModal(m_pFile, fHideWarning, fShowWarningText); + AfxGetApp()->WriteProfileInt(_T("Settings"), _T("HideAviSplitterWarning"), fHideWarning); + } + + if(fShowWarningText) hr = E_FAIL; + } + + if(FAILED(hr)) {m_pFile.Free(); return hr;} + + m_rtNewStart = m_rtCurrent = 0; + m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->GetTotalTime(); + + bool fHasIndex = false; + + for(DWORD i = 0; !fHasIndex && i < m_pFile->m_strms.GetCount(); i++) + if(m_pFile->m_strms[i]->cs.GetCount() > 0) + fHasIndex = true; + + for(DWORD i = 0; i < m_pFile->m_strms.GetCount(); i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + + if(fHasIndex && s->cs.GetCount() == 0) continue; + + CMediaType mt; + CAtlArray mts; + + CStringW name, label; + + if(s->strh.fccType == FCC('vids')) + { + label = L"Video"; + + ASSERT(s->strf.GetCount() >= sizeof(BITMAPINFOHEADER)); + + BITMAPINFOHEADER* pbmi = &((BITMAPINFO*)s->strf.GetData())->bmiHeader; + + mt.majortype = MEDIATYPE_Video; + mt.subtype = FOURCCMap(pbmi->biCompression); + mt.formattype = FORMAT_VideoInfo; + VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + s->strf.GetCount() - sizeof(BITMAPINFOHEADER)); + memset(mt.Format(), 0, mt.FormatLength()); + memcpy(&pvih->bmiHeader, s->strf.GetData(), s->strf.GetCount()); + if(s->strh.dwRate > 0) pvih->AvgTimePerFrame = 10000000i64 * s->strh.dwScale / s->strh.dwRate; + switch(pbmi->biCompression) + { + case BI_RGB: case BI_BITFIELDS: mt.subtype = + pbmi->biBitCount == 1 ? MEDIASUBTYPE_RGB1 : + pbmi->biBitCount == 4 ? MEDIASUBTYPE_RGB4 : + pbmi->biBitCount == 8 ? MEDIASUBTYPE_RGB8 : + pbmi->biBitCount == 16 ? MEDIASUBTYPE_RGB565 : + pbmi->biBitCount == 24 ? MEDIASUBTYPE_RGB24 : + pbmi->biBitCount == 32 ? MEDIASUBTYPE_ARGB32 : + MEDIASUBTYPE_NULL; + break; // case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break; // case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break; - } - - if(s->cs.GetCount() && pvih->AvgTimePerFrame > 0) - { - __int64 size = 0; - for(int i = 0; i < s->cs.GetCount(); i++) - size += s->cs[i].orgsize; - pvih->dwBitRate = size * 8 / s->cs.GetCount() * 10000000i64 / pvih->AvgTimePerFrame; - } - - mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 - ? s->strh.dwSuggestedBufferSize * 3 / 2 - : (pvih->bmiHeader.biWidth * pvih->bmiHeader.biHeight * 4)); - mts.Add(mt); - } - else if(s->strh.fccType == FCC('auds') || s->strh.fccType == FCC('amva')) - { - label = L"Audio"; - - ASSERT(s->strf.GetCount() >= sizeof(WAVEFORMATEX) - || s->strf.GetCount() == sizeof(PCMWAVEFORMAT)); + } + + if(s->cs.GetCount() && pvih->AvgTimePerFrame > 0) + { + __int64 size = 0; + for(int i = 0; i < s->cs.GetCount(); i++) + size += s->cs[i].orgsize; + pvih->dwBitRate = size*8 / s->cs.GetCount() * 10000000i64 / pvih->AvgTimePerFrame; + } + + mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 + ? s->strh.dwSuggestedBufferSize*3/2 + : (pvih->bmiHeader.biWidth*pvih->bmiHeader.biHeight*4)); + mts.Add(mt); + } + else if(s->strh.fccType == FCC('auds') || s->strh.fccType == FCC('amva')) + { + label = L"Audio"; + + ASSERT(s->strf.GetCount() >= sizeof(WAVEFORMATEX) + || s->strf.GetCount() == sizeof(PCMWAVEFORMAT)); WAVEFORMATEX* pwfe = (WAVEFORMATEX*)s->strf.GetData(); - if(pwfe->nBlockAlign == 0) continue; - - mt.majortype = MEDIATYPE_Audio; - if(m_pFile->m_isamv) - mt.subtype = FOURCCMap(MAKEFOURCC('A', 'M', 'V', 'A')); - else - mt.subtype = FOURCCMap(pwfe->wFormatTag); - mt.formattype = FORMAT_WaveFormatEx; - mt.SetFormat(s->strf.GetData(), max(s->strf.GetCount(), sizeof(WAVEFORMATEX))); - pwfe = (WAVEFORMATEX*)mt.Format(); - if(s->strf.GetCount() == sizeof(PCMWAVEFORMAT)) pwfe->cbSize = 0; - if(pwfe->wFormatTag == WAVE_FORMAT_PCM) pwfe->nBlockAlign = pwfe->nChannels * pwfe->wBitsPerSample >> 3; - if(pwfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) mt.subtype = FOURCCMap(WAVE_FORMAT_PCM); // audio renderer doesn't accept fffe in the subtype - mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 - ? s->strh.dwSuggestedBufferSize * 3 / 2 - : (pwfe->nChannels * pwfe->nSamplesPerSec * 32 >> 3)); - mts.Add(mt); - } - else if(s->strh.fccType == FCC('mids')) - { - label = L"Midi"; - - mt.majortype = MEDIATYPE_Midi; - mt.subtype = MEDIASUBTYPE_NULL; - mt.formattype = FORMAT_None; - mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 - ? s->strh.dwSuggestedBufferSize * 3 / 2 - : (1024 * 1024)); - mts.Add(mt); - } - else if(s->strh.fccType == FCC('txts')) - { - label = L"Text"; - - mt.majortype = MEDIATYPE_Text; - mt.subtype = MEDIASUBTYPE_NULL; - mt.formattype = FORMAT_None; - mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 - ? s->strh.dwSuggestedBufferSize * 3 / 2 - : (1024 * 1024)); - mts.Add(mt); - } - else if(s->strh.fccType == FCC('iavs')) - { - label = L"Interleaved"; - - ASSERT(s->strh.fccHandler == FCC('dvsd')); - - mt.majortype = MEDIATYPE_Interleaved; - mt.subtype = FOURCCMap(s->strh.fccHandler); - mt.formattype = FORMAT_DvInfo; - mt.SetFormat(s->strf.GetData(), max(s->strf.GetCount(), sizeof(DVINFO))); - mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 - ? s->strh.dwSuggestedBufferSize * 3 / 2 - : (1024 * 1024)); - mts.Add(mt); - } - - if(mts.IsEmpty()) - { - TRACE(_T("CAviSourceFilter: Unsupported stream (%d)\n"), i); - continue; - } - - //Put filename at front sometime(eg. ~temp.avi) will cause filter graph - //stop check this pin. Not sure the reason exactly. but it happens. - //If you know why, please emailto: tomasen@gmail.com - if(s->strn.IsEmpty()) - name.Format(L"%s %d", label , i); - else - name.Format(L"%s %d %s", label , i , CStringW(s->strn)); - - HRESULT hr; - - CAutoPtr pPinOut(DNew CAviSplitterOutputPin(mts, name, this, this, &hr)); - AddOutputPin(i, pPinOut); - } - - POSITION pos = m_pFile->m_info.GetStartPosition(); - while(pos) - { - DWORD fcc; - CStringA value; - m_pFile->m_info.GetNextAssoc(pos, fcc, value); + if(pwfe->nBlockAlign == 0) continue; + + mt.majortype = MEDIATYPE_Audio; + if (m_pFile->m_isamv) + mt.subtype = FOURCCMap(MAKEFOURCC('A','M','V','A')); + else + mt.subtype = FOURCCMap(pwfe->wFormatTag); + mt.formattype = FORMAT_WaveFormatEx; + mt.SetFormat(s->strf.GetData(), max(s->strf.GetCount(), sizeof(WAVEFORMATEX))); + pwfe = (WAVEFORMATEX*)mt.Format(); + if(s->strf.GetCount() == sizeof(PCMWAVEFORMAT)) pwfe->cbSize = 0; + if(pwfe->wFormatTag == WAVE_FORMAT_PCM) pwfe->nBlockAlign = pwfe->nChannels*pwfe->wBitsPerSample>>3; + if(pwfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) mt.subtype = FOURCCMap(WAVE_FORMAT_PCM); // audio renderer doesn't accept fffe in the subtype + mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 + ? s->strh.dwSuggestedBufferSize*3/2 + : (pwfe->nChannels*pwfe->nSamplesPerSec*32>>3)); + mts.Add(mt); + } + else if(s->strh.fccType == FCC('mids')) + { + label = L"Midi"; + + mt.majortype = MEDIATYPE_Midi; + mt.subtype = MEDIASUBTYPE_NULL; + mt.formattype = FORMAT_None; + mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 + ? s->strh.dwSuggestedBufferSize*3/2 + : (1024*1024)); + mts.Add(mt); + } + else if(s->strh.fccType == FCC('txts')) + { + label = L"Text"; + + mt.majortype = MEDIATYPE_Text; + mt.subtype = MEDIASUBTYPE_NULL; + mt.formattype = FORMAT_None; + mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 + ? s->strh.dwSuggestedBufferSize*3/2 + : (1024*1024)); + mts.Add(mt); + } + else if(s->strh.fccType == FCC('iavs')) + { + label = L"Interleaved"; + + ASSERT(s->strh.fccHandler == FCC('dvsd')); + + mt.majortype = MEDIATYPE_Interleaved; + mt.subtype = FOURCCMap(s->strh.fccHandler); + mt.formattype = FORMAT_DvInfo; + mt.SetFormat(s->strf.GetData(), max(s->strf.GetCount(), sizeof(DVINFO))); + mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0 + ? s->strh.dwSuggestedBufferSize*3/2 + : (1024*1024)); + mts.Add(mt); + } + + if(mts.IsEmpty()) + { + TRACE(_T("CAviSourceFilter: Unsupported stream (%d)\n"), i); + continue; + } + + //Put filename at front sometime(eg. ~temp.avi) will cause filter graph + //stop check this pin. Not sure the reason exactly. but it happens. + //If you know why, please emailto: tomasen@gmail.com + if(s->strn.IsEmpty()) + name.Format(L"%s %d", label , i); + else + name.Format(L"%s %d %s", label , i , CStringW(s->strn) ); + + HRESULT hr; + + CAutoPtr pPinOut(DNew CAviSplitterOutputPin(mts, name, this, this, &hr)); + AddOutputPin(i, pPinOut); + } + + POSITION pos = m_pFile->m_info.GetStartPosition(); + while(pos) + { + DWORD fcc; + CStringA value; + m_pFile->m_info.GetNextAssoc(pos, fcc, value); switch(fcc) - { - case FCC('INAM'): - SetProperty(L"TITL", CStringW(value)); - break; - case FCC('IART'): - SetProperty(L"AUTH", CStringW(value)); - break; - case FCC('ICOP'): - SetProperty(L"CPYR", CStringW(value)); - break; - case FCC('ISBJ'): - SetProperty(L"DESC", CStringW(value)); - break; - } - } - - m_tFrame.Attach(DNew DWORD[m_pFile->m_avih.dwStreams]); - - return m_pOutputs.GetCount() > 0 ? S_OK : E_FAIL; + { + case FCC('INAM'): SetProperty(L"TITL", CStringW(value)); break; + case FCC('IART'): SetProperty(L"AUTH", CStringW(value)); break; + case FCC('ICOP'): SetProperty(L"CPYR", CStringW(value)); break; + case FCC('ISBJ'): SetProperty(L"DESC", CStringW(value)); break; + } + } + + m_tFrame.Attach(DNew DWORD[m_pFile->m_avih.dwStreams]); + + return m_pOutputs.GetCount() > 0 ? S_OK : E_FAIL; } bool CAviSplitterFilter::DemuxInit() { - if(!m_pFile) return(false); + if(!m_pFile) return(false); - // reindex if needed + // reindex if needed - bool fReIndex = false; + bool fReIndex = false; - for(int i = 0; i < (int)m_pFile->m_avih.dwStreams && !fReIndex; i++) - { - if(m_pFile->m_strms[i]->cs.GetCount() == 0 && GetOutputPin(i)) - fReIndex = true; - } + for(int i = 0; i < (int)m_pFile->m_avih.dwStreams && !fReIndex; i++) + { + if(m_pFile->m_strms[i]->cs.GetCount() == 0 && GetOutputPin(i)) + fReIndex = true; + } - if(fReIndex) - { - m_pFile->EmptyIndex(); + if(fReIndex) + { + m_pFile->EmptyIndex(); - m_fAbort = false; - m_nOpenProgress = 0; + m_fAbort = false; + m_nOpenProgress = 0; - m_rtDuration = 0; + m_rtDuration = 0; - CAutoVectorPtr pSize; - pSize.Allocate(m_pFile->m_avih.dwStreams); - memset((UINT64*)pSize, 0, sizeof(UINT64)*m_pFile->m_avih.dwStreams); - m_pFile->Seek(0); + CAutoVectorPtr pSize; + pSize.Allocate(m_pFile->m_avih.dwStreams); + memset((UINT64*)pSize, 0, sizeof(UINT64)*m_pFile->m_avih.dwStreams); + m_pFile->Seek(0); ReIndex(m_pFile->GetLength(), pSize); - if(m_fAbort) m_pFile->EmptyIndex(); + if(m_fAbort) m_pFile->EmptyIndex(); - m_fAbort = false; - m_nOpenProgress = 100; - } + m_fAbort = false; + m_nOpenProgress = 100; + } - return(true); + return(true); } HRESULT CAviSplitterFilter::ReIndex(__int64 end, UINT64* pSize) { - HRESULT hr = S_OK; + HRESULT hr = S_OK; - while(S_OK == hr && m_pFile->GetPos() < end && SUCCEEDED(hr) && !m_fAbort) - { - __int64 pos = m_pFile->GetPos(); + while(S_OK == hr && m_pFile->GetPos() < end && SUCCEEDED(hr) && !m_fAbort) + { + __int64 pos = m_pFile->GetPos(); - DWORD id = 0, size; - if(S_OK != m_pFile->Read(id) || id == 0) - return E_FAIL; + DWORD id = 0, size; + if(S_OK != m_pFile->Read(id) || id == 0) + return E_FAIL; - if(id == FCC('RIFF') || id == FCC('LIST')) - { - if(S_OK != m_pFile->Read(size) || S_OK != m_pFile->Read(id)) - return E_FAIL; + if(id == FCC('RIFF') || id == FCC('LIST')) + { + if(S_OK != m_pFile->Read(size) || S_OK != m_pFile->Read(id)) + return E_FAIL; - size += (size & 1) + 8; + size += (size&1) + 8; - if(id == FCC('AVI ') || id == FCC('AVIX') || id == FCC('movi') || id == FCC('rec ')) - hr = ReIndex(pos + size, pSize); - } - else - { - if(S_OK != m_pFile->Read(size)) - return E_FAIL; + if(id == FCC('AVI ') || id == FCC('AVIX') || id == FCC('movi') || id == FCC('rec ')) + hr = ReIndex(pos + size, pSize); + } + else + { + if(S_OK != m_pFile->Read(size)) + return E_FAIL; - DWORD TrackNumber = TRACKNUM(id); + DWORD TrackNumber = TRACKNUM(id); - if(TrackNumber < m_pFile->m_strms.GetCount()) - { - CAviFile::strm_t* s = m_pFile->m_strms[TrackNumber]; + if(TrackNumber < m_pFile->m_strms.GetCount()) + { + CAviFile::strm_t* s = m_pFile->m_strms[TrackNumber]; - WORD type = TRACKTYPE(id); + WORD type = TRACKTYPE(id); - if(type == 'db' || type == 'dc' || /*type == 'pc' ||*/ type == 'wb' - || type == 'iv' || type == '__' || type == 'xx') - { - CAviFile::strm_t::chunk c; - c.filepos = pos; - c.size = pSize[TrackNumber]; - c.orgsize = size; - c.fKeyFrame = size > 0; // TODO: find a better way... - c.fChunkHdr = true; - s->cs.Add(c); + if(type == 'db' || type == 'dc' || /*type == 'pc' ||*/ type == 'wb' + || type == 'iv' || type == '__' || type == 'xx') + { + CAviFile::strm_t::chunk c; + c.filepos = pos; + c.size = pSize[TrackNumber]; + c.orgsize = size; + c.fKeyFrame = size > 0; // TODO: find a better way... + c.fChunkHdr = true; + s->cs.Add(c); - pSize[TrackNumber] += s->GetChunkSize(size); + pSize[TrackNumber] += s->GetChunkSize(size); - REFERENCE_TIME rt = s->GetRefTime(s->cs.GetCount() - 1, pSize[TrackNumber]); - m_rtDuration = max(rt, m_rtDuration); - } - } + REFERENCE_TIME rt = s->GetRefTime(s->cs.GetCount()-1, pSize[TrackNumber]); + m_rtDuration = max(rt, m_rtDuration); + } + } - size += (size & 1) + 8; - } + size += (size&1) + 8; + } - m_pFile->Seek(pos + size); + m_pFile->Seek(pos + size); - m_nOpenProgress = m_pFile->GetPos() * 100 / m_pFile->GetLength(); + m_nOpenProgress = m_pFile->GetPos()*100/m_pFile->GetLength(); - DWORD cmd; - if(CheckRequest(&cmd)) - { - if(cmd == CMD_EXIT) m_fAbort = true; - else Reply(S_OK); - } - } + DWORD cmd; + if(CheckRequest(&cmd)) + { + if(cmd == CMD_EXIT) m_fAbort = true; + else Reply(S_OK); + } + } - return hr; + return hr; } void CAviSplitterFilter::DemuxSeek(REFERENCE_TIME rt) { - memset((DWORD*)m_tFrame, 0, sizeof(DWORD)*m_pFile->m_avih.dwStreams); - m_pFile->Seek(0); - - DbgLog((LOG_TRACE, 0, _T("Seek: %I64d"), rt / 10000)); - - if(rt > 0) - { - UINT64 minfp = _I64_MAX; - - for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++) - { - CAviFile::strm_t* s = m_pFile->m_strms[j]; - - int f = s->GetKeyFrame(rt); - UINT64 fp = f >= 0 ? s->cs[f].filepos : m_pFile->GetLength(); - - if(!s->IsRawSubtitleStream()) - minfp = min(minfp, fp); - } - - for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++) - { - CAviFile::strm_t* s = m_pFile->m_strms[j]; - - for(int i = 0; i < s->cs.GetCount(); i++) - { - CAviFile::strm_t::chunk& c = s->cs[i]; - if(c.filepos >= minfp) - { - m_tFrame[j] = i; - break; - } - } - } - - DbgLog((LOG_TRACE, 0, _T("minfp: %I64d"), minfp)); - } + memset((DWORD*)m_tFrame, 0, sizeof(DWORD)*m_pFile->m_avih.dwStreams); + m_pFile->Seek(0); + + DbgLog((LOG_TRACE, 0, _T("Seek: %I64d"), rt/10000)); + + if(rt > 0) + { + UINT64 minfp = _I64_MAX; + + for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++) + { + CAviFile::strm_t* s = m_pFile->m_strms[j]; + + int f = s->GetKeyFrame(rt); + UINT64 fp = f >= 0 ? s->cs[f].filepos : m_pFile->GetLength(); + + if(!s->IsRawSubtitleStream()) + minfp = min(minfp, fp); + } + + for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++) + { + CAviFile::strm_t* s = m_pFile->m_strms[j]; + + for(int i = 0; i < s->cs.GetCount(); i++) + { + CAviFile::strm_t::chunk& c = s->cs[i]; + if(c.filepos >= minfp) + { + m_tFrame[j] = i; + break; + } + } + } + + DbgLog((LOG_TRACE, 0, _T("minfp: %I64d"), minfp)); + } } bool CAviSplitterFilter::DemuxLoop() { - HRESULT hr = S_OK; - - int nTracks = (int)m_pFile->m_strms.GetCount(); - - CAtlArray fDiscontinuity; - fDiscontinuity.SetCount(nTracks); - memset(fDiscontinuity.GetData(), 0, nTracks * sizeof(bool)); - - while(SUCCEEDED(hr) && !CheckRequest(NULL)) - { - int minTrack = nTracks; - UINT64 minFilePos = _I64_MAX; - - for(int i = 0; i < nTracks; i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - - DWORD f = m_tFrame[i]; - if(f >= (DWORD)s->cs.GetCount()) continue; - - bool fUrgent = s->IsRawSubtitleStream(); - - if(fUrgent || s->cs[f].filepos < minFilePos) - { - minTrack = i; - minFilePos = s->cs[f].filepos; - } - - if(fUrgent) break; - } - - if(minTrack == nTracks) - break; - - DWORD& f = m_tFrame[minTrack]; - - do - { - CAviFile::strm_t* s = m_pFile->m_strms[minTrack]; - - m_pFile->Seek(s->cs[f].filepos); - - DWORD size = 0; - - if(s->cs[f].fChunkHdr) - { - DWORD id = 0; - if(S_OK != m_pFile->Read(id) || id == 0 || minTrack != TRACKNUM(id) - || S_OK != m_pFile->Read(size)) - { - fDiscontinuity[minTrack] = true; - break; - } - - UINT64 expectedsize = -1; - expectedsize = f < (DWORD)s->cs.GetCount() - 1 - ? s->cs[f+1].size - s->cs[f].size - : s->totalsize - s->cs[f].size; - - if(expectedsize != s->GetChunkSize(size)) - { - fDiscontinuity[minTrack] = true; - // ASSERT(0); - break; - } - } - else - { - size = s->cs[f].orgsize; - } - - CAutoPtr p(DNew Packet()); - - p->TrackNumber = minTrack; - p->bSyncPoint = (BOOL)s->cs[f].fKeyFrame; - p->bDiscontinuity = fDiscontinuity[minTrack]; - p->rtStart = s->GetRefTime(f, s->cs[f].size); - p->rtStop = s->GetRefTime(f + 1, f + 1 < (DWORD)s->cs.GetCount() ? s->cs[f+1].size : s->totalsize); - - p->SetCount(size); - if(S_OK != (hr = m_pFile->ByteRead(p->GetData(), p->GetCount()))) - return(true); // break; - /* - DbgLog((LOG_TRACE, 0, _T("%d (%d): %I64d - %I64d, %I64d - %I64d (size = %d)"), - minTrack, (int)p->bSyncPoint, - (p->rtStart)/10000, (p->rtStop)/10000, - (p->rtStart-m_rtStart)/10000, (p->rtStop-m_rtStart)/10000, - size)); - */ - hr = DeliverPacket(p); - - fDiscontinuity[minTrack] = false; - } - while(0); - - f++; - } - - return(true); + HRESULT hr = S_OK; + + int nTracks = (int)m_pFile->m_strms.GetCount(); + + CAtlArray fDiscontinuity; + fDiscontinuity.SetCount(nTracks); + memset(fDiscontinuity.GetData(), 0, nTracks*sizeof(bool)); + + while(SUCCEEDED(hr) && !CheckRequest(NULL)) + { + int minTrack = nTracks; + UINT64 minFilePos = _I64_MAX; + + for(int i = 0; i < nTracks; i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + + DWORD f = m_tFrame[i]; + if(f >= (DWORD)s->cs.GetCount()) continue; + + bool fUrgent = s->IsRawSubtitleStream(); + + if(fUrgent || s->cs[f].filepos < minFilePos) + { + minTrack = i; + minFilePos = s->cs[f].filepos; + } + + if(fUrgent) break; + } + + if(minTrack == nTracks) + break; + + DWORD& f = m_tFrame[minTrack]; + + do + { + CAviFile::strm_t* s = m_pFile->m_strms[minTrack]; + + m_pFile->Seek(s->cs[f].filepos); + + DWORD size = 0; + + if(s->cs[f].fChunkHdr) + { + DWORD id = 0; + if(S_OK != m_pFile->Read(id) || id == 0 || minTrack != TRACKNUM(id) + || S_OK != m_pFile->Read(size)) + { + fDiscontinuity[minTrack] = true; + break; + } + + UINT64 expectedsize = -1; + expectedsize = f < (DWORD)s->cs.GetCount()-1 + ? s->cs[f+1].size - s->cs[f].size + : s->totalsize - s->cs[f].size; + + if(expectedsize != s->GetChunkSize(size)) + { + fDiscontinuity[minTrack] = true; + // ASSERT(0); + break; + } + } + else + { + size = s->cs[f].orgsize; + } + + CAutoPtr p(DNew Packet()); + + p->TrackNumber = minTrack; + p->bSyncPoint = (BOOL)s->cs[f].fKeyFrame; + p->bDiscontinuity = fDiscontinuity[minTrack]; + p->rtStart = s->GetRefTime(f, s->cs[f].size); + p->rtStop = s->GetRefTime(f+1, f+1 < (DWORD)s->cs.GetCount() ? s->cs[f+1].size : s->totalsize); + + p->SetCount(size); + if(S_OK != (hr = m_pFile->ByteRead(p->GetData(), p->GetCount()))) + return(true); // break; +/* + DbgLog((LOG_TRACE, 0, _T("%d (%d): %I64d - %I64d, %I64d - %I64d (size = %d)"), + minTrack, (int)p->bSyncPoint, + (p->rtStart)/10000, (p->rtStop)/10000, + (p->rtStart-m_rtStart)/10000, (p->rtStop-m_rtStart)/10000, + size)); +*/ + hr = DeliverPacket(p); + + fDiscontinuity[minTrack] = false; + } + while(0); + + f++; + } + + return(true); } // IMediaSeeking STDMETHODIMP CAviSplitterFilter::GetDuration(LONGLONG* pDuration) { - CheckPointer(pDuration, E_POINTER); - CheckPointer(m_pFile, VFW_E_NOT_CONNECTED); - - if(m_timeformat == TIME_FORMAT_FRAME) - { - for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - if(s->strh.fccType == FCC('vids')) - { - *pDuration = s->cs.GetCount(); - return S_OK; - } - } - - return E_UNEXPECTED; - } - - return __super::GetDuration(pDuration); + CheckPointer(pDuration, E_POINTER); + CheckPointer(m_pFile, VFW_E_NOT_CONNECTED); + + if(m_timeformat == TIME_FORMAT_FRAME) + { + for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + if(s->strh.fccType == FCC('vids')) + { + *pDuration = s->cs.GetCount(); + return S_OK; + } + } + + return E_UNEXPECTED; + } + + return __super::GetDuration(pDuration); } // STDMETHODIMP CAviSplitterFilter::IsFormatSupported(const GUID* pFormat) { - CheckPointer(pFormat, E_POINTER); - HRESULT hr = __super::IsFormatSupported(pFormat); - if(S_OK == hr) return hr; - return *pFormat == TIME_FORMAT_FRAME ? S_OK : S_FALSE; + CheckPointer(pFormat, E_POINTER); + HRESULT hr = __super::IsFormatSupported(pFormat); + if(S_OK == hr) return hr; + return *pFormat == TIME_FORMAT_FRAME ? S_OK : S_FALSE; } STDMETHODIMP CAviSplitterFilter::GetTimeFormat(GUID* pFormat) { - CheckPointer(pFormat, E_POINTER); - *pFormat = m_timeformat; - return S_OK; + CheckPointer(pFormat, E_POINTER); + *pFormat = m_timeformat; + return S_OK; } STDMETHODIMP CAviSplitterFilter::IsUsingTimeFormat(const GUID* pFormat) { - CheckPointer(pFormat, E_POINTER); - return *pFormat == m_timeformat ? S_OK : S_FALSE; + CheckPointer(pFormat, E_POINTER); + return *pFormat == m_timeformat ? S_OK : S_FALSE; } STDMETHODIMP CAviSplitterFilter::SetTimeFormat(const GUID* pFormat) { - CheckPointer(pFormat, E_POINTER); - if(S_OK != IsFormatSupported(pFormat)) return E_FAIL; - m_timeformat = *pFormat; - return S_OK; + CheckPointer(pFormat, E_POINTER); + if(S_OK != IsFormatSupported(pFormat)) return E_FAIL; + m_timeformat = *pFormat; + return S_OK; } STDMETHODIMP CAviSplitterFilter::GetStopPosition(LONGLONG* pStop) { - CheckPointer(pStop, E_POINTER); - if(FAILED(__super::GetStopPosition(pStop))) return E_FAIL; - if(m_timeformat == TIME_FORMAT_MEDIA_TIME) return S_OK; - LONGLONG rt = *pStop; - if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, rt, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL; - return S_OK; + CheckPointer(pStop, E_POINTER); + if(FAILED(__super::GetStopPosition(pStop))) return E_FAIL; + if(m_timeformat == TIME_FORMAT_MEDIA_TIME) return S_OK; + LONGLONG rt = *pStop; + if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, rt, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL; + return S_OK; } STDMETHODIMP CAviSplitterFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) { - CheckPointer(pTarget, E_POINTER); - - const GUID& SourceFormat = pSourceFormat ? *pSourceFormat : m_timeformat; - const GUID& TargetFormat = pTargetFormat ? *pTargetFormat : m_timeformat; - - if(TargetFormat == SourceFormat) - { - *pTarget = Source; - return S_OK; - } - else if(TargetFormat == TIME_FORMAT_FRAME && SourceFormat == TIME_FORMAT_MEDIA_TIME) - { - for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - if(s->strh.fccType == FCC('vids')) - { - *pTarget = s->GetFrame(Source); - return S_OK; - } - } - } - else if(TargetFormat == TIME_FORMAT_MEDIA_TIME && SourceFormat == TIME_FORMAT_FRAME) - { - for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - if(s->strh.fccType == FCC('vids')) - { - if(Source < 0 || Source >= s->cs.GetCount()) return E_FAIL; - CAviFile::strm_t::chunk& c = s->cs[(int)Source]; - *pTarget = s->GetRefTime((DWORD)Source, c.size); - return S_OK; - } - } - } - - return E_FAIL; + CheckPointer(pTarget, E_POINTER); + + const GUID& SourceFormat = pSourceFormat ? *pSourceFormat : m_timeformat; + const GUID& TargetFormat = pTargetFormat ? *pTargetFormat : m_timeformat; + + if(TargetFormat == SourceFormat) + { + *pTarget = Source; + return S_OK; + } + else if(TargetFormat == TIME_FORMAT_FRAME && SourceFormat == TIME_FORMAT_MEDIA_TIME) + { + for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + if(s->strh.fccType == FCC('vids')) + { + *pTarget = s->GetFrame(Source); + return S_OK; + } + } + } + else if(TargetFormat == TIME_FORMAT_MEDIA_TIME && SourceFormat == TIME_FORMAT_FRAME) + { + for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + if(s->strh.fccType == FCC('vids')) + { + if(Source < 0 || Source >= s->cs.GetCount()) return E_FAIL; + CAviFile::strm_t::chunk& c = s->cs[(int)Source]; + *pTarget = s->GetRefTime((DWORD)Source, c.size); + return S_OK; + } + } + } + + return E_FAIL; } STDMETHODIMP CAviSplitterFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) { - HRESULT hr; - if(FAILED(hr = __super::GetPositions(pCurrent, pStop)) || m_timeformat != TIME_FORMAT_FRAME) - return hr; + HRESULT hr; + if(FAILED(hr = __super::GetPositions(pCurrent, pStop)) || m_timeformat != TIME_FORMAT_FRAME) + return hr; - if(pCurrent) - if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_FRAME, *pCurrent, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL; - if(pStop) - if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, *pStop, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL; + if(pCurrent) + if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_FRAME, *pCurrent, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL; + if(pStop) + if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, *pStop, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL; - return S_OK; + return S_OK; } HRESULT CAviSplitterFilter::SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) { - if(m_timeformat != TIME_FORMAT_FRAME) - return __super::SetPositionsInternal(id, pCurrent, dwCurrentFlags, pStop, dwStopFlags); - - if(!pCurrent && !pStop - || (dwCurrentFlags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning - && (dwStopFlags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning) - return S_OK; - - REFERENCE_TIME - rtCurrent = m_rtCurrent, - rtStop = m_rtStop; - - if((dwCurrentFlags & AM_SEEKING_PositioningBitsMask) - && FAILED(ConvertTimeFormat(&rtCurrent, &TIME_FORMAT_FRAME, rtCurrent, &TIME_FORMAT_MEDIA_TIME))) - return E_FAIL; - if((dwStopFlags & AM_SEEKING_PositioningBitsMask) - && FAILED(ConvertTimeFormat(&rtStop, &TIME_FORMAT_FRAME, rtStop, &TIME_FORMAT_MEDIA_TIME))) - return E_FAIL; - - if(pCurrent) - switch(dwCurrentFlags & AM_SEEKING_PositioningBitsMask) - { - case AM_SEEKING_NoPositioning: - break; - case AM_SEEKING_AbsolutePositioning: - rtCurrent = *pCurrent; - break; - case AM_SEEKING_RelativePositioning: - rtCurrent = rtCurrent + *pCurrent; - break; - case AM_SEEKING_IncrementalPositioning: - rtCurrent = rtCurrent + *pCurrent; - break; - } - - if(pStop) - switch(dwStopFlags & AM_SEEKING_PositioningBitsMask) - { - case AM_SEEKING_NoPositioning: - break; - case AM_SEEKING_AbsolutePositioning: - rtStop = *pStop; - break; - case AM_SEEKING_RelativePositioning: - rtStop += *pStop; - break; - case AM_SEEKING_IncrementalPositioning: - rtStop = rtCurrent + *pStop; - break; - } - - if((dwCurrentFlags & AM_SEEKING_PositioningBitsMask) - && pCurrent) - if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_MEDIA_TIME, rtCurrent, &TIME_FORMAT_FRAME))) return E_FAIL; - if((dwStopFlags & AM_SEEKING_PositioningBitsMask) - && pStop) - if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_MEDIA_TIME, rtStop, &TIME_FORMAT_FRAME))) return E_FAIL; - - return __super::SetPositionsInternal(id, pCurrent, dwCurrentFlags, pStop, dwStopFlags); + if(m_timeformat != TIME_FORMAT_FRAME) + return __super::SetPositionsInternal(id, pCurrent, dwCurrentFlags, pStop, dwStopFlags); + + if(!pCurrent && !pStop + || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning + && (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning) + return S_OK; + + REFERENCE_TIME + rtCurrent = m_rtCurrent, + rtStop = m_rtStop; + + if((dwCurrentFlags&AM_SEEKING_PositioningBitsMask) + && FAILED(ConvertTimeFormat(&rtCurrent, &TIME_FORMAT_FRAME, rtCurrent, &TIME_FORMAT_MEDIA_TIME))) + return E_FAIL; + if((dwStopFlags&AM_SEEKING_PositioningBitsMask) + && FAILED(ConvertTimeFormat(&rtStop, &TIME_FORMAT_FRAME, rtStop, &TIME_FORMAT_MEDIA_TIME))) + return E_FAIL; + + if(pCurrent) + switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask) + { + case AM_SEEKING_NoPositioning: break; + case AM_SEEKING_AbsolutePositioning: rtCurrent = *pCurrent; break; + case AM_SEEKING_RelativePositioning: rtCurrent = rtCurrent + *pCurrent; break; + case AM_SEEKING_IncrementalPositioning: rtCurrent = rtCurrent + *pCurrent; break; + } + + if(pStop) + switch(dwStopFlags&AM_SEEKING_PositioningBitsMask) + { + case AM_SEEKING_NoPositioning: break; + case AM_SEEKING_AbsolutePositioning: rtStop = *pStop; break; + case AM_SEEKING_RelativePositioning: rtStop += *pStop; break; + case AM_SEEKING_IncrementalPositioning: rtStop = rtCurrent + *pStop; break; + } + + if((dwCurrentFlags&AM_SEEKING_PositioningBitsMask) + && pCurrent) + if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_MEDIA_TIME, rtCurrent, &TIME_FORMAT_FRAME))) return E_FAIL; + if((dwStopFlags&AM_SEEKING_PositioningBitsMask) + && pStop) + if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_MEDIA_TIME, rtStop, &TIME_FORMAT_FRAME))) return E_FAIL; + + return __super::SetPositionsInternal(id, pCurrent, dwCurrentFlags, pStop, dwStopFlags); } // IKeyFrameInfo STDMETHODIMP CAviSplitterFilter::GetKeyFrameCount(UINT& nKFs) { - if(!m_pFile) return E_UNEXPECTED; + if(!m_pFile) return E_UNEXPECTED; - HRESULT hr = S_OK; + HRESULT hr = S_OK; - nKFs = 0; + nKFs = 0; - for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - if(s->strh.fccType != FCC('vids')) continue; + for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + if(s->strh.fccType != FCC('vids')) continue; - for(int j = 0; j < s->cs.GetCount(); j++) - { - CAviFile::strm_t::chunk& c = s->cs[j]; - if(c.fKeyFrame) nKFs++; - } + for(int j = 0; j < s->cs.GetCount(); j++) + { + CAviFile::strm_t::chunk& c = s->cs[j]; + if(c.fKeyFrame) nKFs++; + } - if(nKFs == s->cs.GetCount()) - hr = S_FALSE; + if(nKFs == s->cs.GetCount()) + hr = S_FALSE; - break; - } + break; + } - return hr; + return hr; } STDMETHODIMP CAviSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs) { - CheckPointer(pFormat, E_POINTER); - CheckPointer(pKFs, E_POINTER); + CheckPointer(pFormat, E_POINTER); + CheckPointer(pKFs, E_POINTER); - if(!m_pFile) return E_UNEXPECTED; - if(*pFormat != TIME_FORMAT_MEDIA_TIME && *pFormat != TIME_FORMAT_FRAME) return E_INVALIDARG; + if(!m_pFile) return E_UNEXPECTED; + if(*pFormat != TIME_FORMAT_MEDIA_TIME && *pFormat != TIME_FORMAT_FRAME) return E_INVALIDARG; - UINT nKFsTmp = 0; + UINT nKFsTmp = 0; - for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) - { - CAviFile::strm_t* s = m_pFile->m_strms[i]; - if(s->strh.fccType != FCC('vids')) continue; + for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) + { + CAviFile::strm_t* s = m_pFile->m_strms[i]; + if(s->strh.fccType != FCC('vids')) continue; - bool fConvertToRefTime = !!(*pFormat == TIME_FORMAT_MEDIA_TIME); + bool fConvertToRefTime = !!(*pFormat == TIME_FORMAT_MEDIA_TIME); - for(int j = 0; j < s->cs.GetCount() && nKFsTmp < nKFs; j++) - { - if(s->cs[j].fKeyFrame) - pKFs[nKFsTmp++] = fConvertToRefTime ? s->GetRefTime(j, s->cs[j].size) : j; - } + for(int j = 0; j < s->cs.GetCount() && nKFsTmp < nKFs; j++) + { + if(s->cs[j].fKeyFrame) + pKFs[nKFsTmp++] = fConvertToRefTime ? s->GetRefTime(j, s->cs[j].size) : j; + } - break; - } + break; + } - nKFs = nKFsTmp; + nKFs = nKFsTmp; - return S_OK; + return S_OK; } // @@ -854,10 +826,10 @@ STDMETHODIMP CAviSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIM // CAviSourceFilter::CAviSourceFilter(LPUNKNOWN pUnk, HRESULT* phr) - : CAviSplitterFilter(pUnk, phr) + : CAviSplitterFilter(pUnk, phr) { - m_clsid = __uuidof(this); - m_pInput.Free(); + m_clsid = __uuidof(this); + m_pInput.Free(); } // @@ -865,29 +837,29 @@ CAviSourceFilter::CAviSourceFilter(LPUNKNOWN pUnk, HRESULT* phr) // CAviSplitterOutputPin::CAviSplitterOutputPin(CAtlArray& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr) - : CBaseSplitterOutputPin(mts, pName, pFilter, pLock, phr) + : CBaseSplitterOutputPin(mts, pName, pFilter, pLock, phr) { } HRESULT CAviSplitterOutputPin::CheckConnect(IPin* pPin) { - int iPosition = 0; - CMediaType mt; - while(S_OK == GetMediaType(iPosition++, &mt)) - { - if(mt.majortype == MEDIATYPE_Video - && (mt.subtype == FOURCCMap(FCC('IV32')) - || mt.subtype == FOURCCMap(FCC('IV31')) - || mt.subtype == FOURCCMap(FCC('IF09')))) - { - CLSID clsid = GetCLSID(GetFilterFromPin(pPin)); - if(clsid == CLSID_VideoMixingRenderer || clsid == CLSID_OverlayMixer) - return E_FAIL; - } - - mt.InitMediaType(); - } - - return __super::CheckConnect(pPin); + int iPosition = 0; + CMediaType mt; + while(S_OK == GetMediaType(iPosition++, &mt)) + { + if(mt.majortype == MEDIATYPE_Video + && (mt.subtype == FOURCCMap(FCC('IV32')) + || mt.subtype == FOURCCMap(FCC('IV31')) + || mt.subtype == FOURCCMap(FCC('IF09')))) + { + CLSID clsid = GetCLSID(GetFilterFromPin(pPin)); + if(clsid == CLSID_VideoMixingRenderer || clsid == CLSID_OverlayMixer) + return E_FAIL; + } + + mt.InitMediaType(); + } + + return __super::CheckConnect(pPin); } diff --git a/src/filters/parser/AviSplitter/AviSplitter.h b/src/filters/parser/AviSplitter/AviSplitter.h index d8e59040b..f3e0c50cf 100644 --- a/src/filters/parser/AviSplitter/AviSplitter.h +++ b/src/filters/parser/AviSplitter/AviSplitter.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -30,57 +30,57 @@ class CAviFile; class CAviSplitterOutputPin : public CBaseSplitterOutputPin { public: - CAviSplitterOutputPin(CAtlArray& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr); + CAviSplitterOutputPin(CAtlArray& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr); - HRESULT CheckConnect(IPin* pPin); + HRESULT CheckConnect(IPin* pPin); }; [uuid("9736D831-9D6C-4E72-B6E7-560EF9181001")] class CAviSplitterFilter : public CBaseSplitterFilter { - CAutoVectorPtr m_tFrame; + CAutoVectorPtr m_tFrame; protected: - CAutoPtr m_pFile; - HRESULT CreateOutputs(IAsyncReader* pAsyncReader); + CAutoPtr m_pFile; + HRESULT CreateOutputs(IAsyncReader* pAsyncReader); - bool DemuxInit(); - void DemuxSeek(REFERENCE_TIME rt); - bool DemuxLoop(); + bool DemuxInit(); + void DemuxSeek(REFERENCE_TIME rt); + bool DemuxLoop(); - HRESULT ReIndex(__int64 end, UINT64* pSize); + HRESULT ReIndex(__int64 end, UINT64* pSize); public: - CAviSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); + CAviSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); - DECLARE_IUNKNOWN; + DECLARE_IUNKNOWN; STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - // IMediaSeeking + // IMediaSeeking - STDMETHODIMP GetDuration(LONGLONG* pDuration); + STDMETHODIMP GetDuration(LONGLONG* pDuration); - // TODO: this is too ugly, integrate this with the baseclass somehow - GUID m_timeformat; - STDMETHODIMP IsFormatSupported(const GUID* pFormat); - STDMETHODIMP GetTimeFormat(GUID* pFormat); - STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat); - STDMETHODIMP SetTimeFormat(const GUID* pFormat); - STDMETHODIMP GetStopPosition(LONGLONG* pStop); - STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat); - STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop); + // TODO: this is too ugly, integrate this with the baseclass somehow + GUID m_timeformat; + STDMETHODIMP IsFormatSupported(const GUID* pFormat); + STDMETHODIMP GetTimeFormat(GUID* pFormat); + STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat); + STDMETHODIMP SetTimeFormat(const GUID* pFormat); + STDMETHODIMP GetStopPosition(LONGLONG* pStop); + STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat); + STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop); - HRESULT SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); + HRESULT SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); - // IKeyFrameInfo + // IKeyFrameInfo - STDMETHODIMP GetKeyFrameCount(UINT& nKFs); - STDMETHODIMP GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs); + STDMETHODIMP GetKeyFrameCount(UINT& nKFs); + STDMETHODIMP GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs); }; [uuid("CEA8DEFF-0AF7-4DB9-9A38-FB3C3AEFC0DE")] class CAviSourceFilter : public CAviSplitterFilter { public: - CAviSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); + CAviSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); }; diff --git a/src/filters/parser/AviSplitter/resource.h b/src/filters/parser/AviSplitter/resource.h index 80a8d5879..f29274003 100644 --- a/src/filters/parser/AviSplitter/resource.h +++ b/src/filters/parser/AviSplitter/resource.h @@ -3,7 +3,7 @@ // Used by AviSplitter.rc // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 diff --git a/src/filters/parser/AviSplitter/stdafx.cpp b/src/filters/parser/AviSplitter/stdafx.cpp index 793af597c..c356f5dba 100644 --- a/src/filters/parser/AviSplitter/stdafx.cpp +++ b/src/filters/parser/AviSplitter/stdafx.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ diff --git a/src/filters/parser/AviSplitter/stdafx.h b/src/filters/parser/AviSplitter/stdafx.h index ec6ed9d77..5f53f59b5 100644 --- a/src/filters/parser/AviSplitter/stdafx.h +++ b/src/filters/parser/AviSplitter/stdafx.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ diff --git a/src/filters/parser/BaseSplitter/AsyncReader.cpp b/src/filters/parser/BaseSplitter/AsyncReader.cpp index 99161206f..2231aa440 100644 --- a/src/filters/parser/BaseSplitter/AsyncReader.cpp +++ b/src/filters/parser/BaseSplitter/AsyncReader.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -30,205 +30,187 @@ // CAsyncFileReader // -CAsyncFileReader::CAsyncFileReader(CString fn, HRESULT& hr) - : CUnknown(NAME("CAsyncFileReader"), NULL, &hr) - , m_len(-1) - , m_hBreakEvent(NULL) - , m_lOsError(0) +CAsyncFileReader::CAsyncFileReader(CString fn, HRESULT& hr) + : CUnknown(NAME("CAsyncFileReader"), NULL, &hr) + , m_len(-1) + , m_hBreakEvent(NULL) + , m_lOsError(0) { - hr = Open(fn, modeRead | shareDenyNone | typeBinary | osSequentialScan) ? S_OK : E_FAIL; - if(SUCCEEDED(hr)) m_len = GetLength(); + hr = Open(fn, modeRead|shareDenyNone|typeBinary|osSequentialScan) ? S_OK : E_FAIL; + if(SUCCEEDED(hr)) m_len = GetLength(); } -CAsyncFileReader::CAsyncFileReader(CAtlList& Items, HRESULT& hr) - : CUnknown(NAME("CAsyncFileReader"), NULL, &hr) - , m_len(-1) - , m_hBreakEvent(NULL) - , m_lOsError(0) +CAsyncFileReader::CAsyncFileReader(CAtlList& Items, HRESULT& hr) + : CUnknown(NAME("CAsyncFileReader"), NULL, &hr) + , m_len(-1) + , m_hBreakEvent(NULL) + , m_lOsError(0) { - hr = OpenFiles(Items, modeRead | shareDenyNone | typeBinary | osSequentialScan) ? S_OK : E_FAIL; - if(SUCCEEDED(hr)) m_len = GetLength(); + hr = OpenFiles(Items, modeRead|shareDenyNone|typeBinary|osSequentialScan) ? S_OK : E_FAIL; + if(SUCCEEDED(hr)) m_len = GetLength(); } STDMETHODIMP CAsyncFileReader::NonDelegatingQueryInterface(REFIID riid, void** ppv) { - CheckPointer(ppv, E_POINTER); + CheckPointer(ppv, E_POINTER); - return - QI(IAsyncReader) - QI(ISyncReader) - QI(IFileHandle) - __super::NonDelegatingQueryInterface(riid, ppv); + return + QI(IAsyncReader) + QI(ISyncReader) + QI(IFileHandle) + __super::NonDelegatingQueryInterface(riid, ppv); } // IAsyncReader STDMETHODIMP CAsyncFileReader::SyncRead(LONGLONG llPosition, LONG lLength, BYTE* pBuffer) { - do - { - try - { - if(llPosition + lLength > GetLength()) return E_FAIL; // strange, but the Seek below can return llPosition even if the file is not that big (?) - if(llPosition != Seek(llPosition, begin)) return E_FAIL; - if((UINT)lLength < Read(pBuffer, lLength)) return E_FAIL; + do + { + try + { + if(llPosition+lLength > GetLength()) return E_FAIL; // strange, but the Seek below can return llPosition even if the file is not that big (?) + if(llPosition != Seek(llPosition, begin)) return E_FAIL; + if((UINT)lLength < Read(pBuffer, lLength)) return E_FAIL; #if 0 // def DEBUG - static __int64 s_total = 0, s_laststoppos = 0; - s_total += lLength; - if(s_laststoppos > llPosition) - TRACE(_T("[%I64d - %I64d] %d (%I64d)\n"), llPosition, llPosition + lLength, lLength, s_total); - s_laststoppos = llPosition + lLength; + static __int64 s_total = 0, s_laststoppos = 0; + s_total += lLength; + if(s_laststoppos > llPosition) + TRACE(_T("[%I64d - %I64d] %d (%I64d)\n"), llPosition, llPosition + lLength, lLength, s_total); + s_laststoppos = llPosition + lLength; #endif - return S_OK; - } - catch(CFileException* e) - { - m_lOsError = e->m_lOsError; - e->Delete(); - Sleep(1); - CString fn = m_strFileName; - try - { - Close(); - } - catch(CFileException* e) - { - e->Delete(); - } - try - { - Open(fn, modeRead | shareDenyNone | typeBinary | osSequentialScan); - } - catch(CFileException* e) - { - e->Delete(); - } - m_strFileName = fn; - } - } - while(m_hBreakEvent && WaitForSingleObject(m_hBreakEvent, 0) == WAIT_TIMEOUT); - - return E_FAIL; + return S_OK; + } + catch(CFileException* e) + { + m_lOsError = e->m_lOsError; + e->Delete(); + Sleep(1); + CString fn = m_strFileName; + try {Close();} catch(CFileException* e) {e->Delete();} + try {Open(fn, modeRead|shareDenyNone|typeBinary|osSequentialScan);} catch(CFileException* e) {e->Delete();} + m_strFileName = fn; + } + } + while(m_hBreakEvent && WaitForSingleObject(m_hBreakEvent, 0) == WAIT_TIMEOUT); + + return E_FAIL; } STDMETHODIMP CAsyncFileReader::Length(LONGLONG* pTotal, LONGLONG* pAvailable) { - LONGLONG len = m_len >= 0 ? m_len : GetLength(); - if(pTotal) *pTotal = len; - if(pAvailable) *pAvailable = len; - return S_OK; + LONGLONG len = m_len >= 0 ? m_len : GetLength(); + if(pTotal) *pTotal = len; + if(pAvailable) *pAvailable = len; + return S_OK; } // IFileHandle STDMETHODIMP_(HANDLE) CAsyncFileReader::GetFileHandle() { - return m_hFile; + return m_hFile; } STDMETHODIMP_(LPCTSTR) CAsyncFileReader::GetFileName() { - return m_nCurPart != -1 ? m_strFiles[m_nCurPart] : m_strFiles[0]; + return m_nCurPart != -1 ? m_strFiles[m_nCurPart] : m_strFiles[0]; } // // CAsyncUrlReader // -CAsyncUrlReader::CAsyncUrlReader(CString url, HRESULT& hr) - : CAsyncFileReader(url, hr) +CAsyncUrlReader::CAsyncUrlReader(CString url, HRESULT& hr) + : CAsyncFileReader(url, hr) { - if(SUCCEEDED(hr)) return; + if(SUCCEEDED(hr)) return; - m_url = url; + m_url = url; - if(CAMThread::Create()) - CallWorker(CMD_INIT); + if(CAMThread::Create()) + CallWorker(CMD_INIT); - hr = Open(m_fn, modeRead | shareDenyRead | typeBinary | osSequentialScan) ? S_OK : E_FAIL; - m_len = -1; // force GetLength() return actual length always + hr = Open(m_fn, modeRead|shareDenyRead|typeBinary|osSequentialScan) ? S_OK : E_FAIL; + m_len = -1; // force GetLength() return actual length always } CAsyncUrlReader::~CAsyncUrlReader() { - if(ThreadExists()) - CallWorker(CMD_EXIT); - - if(!m_fn.IsEmpty()) - { - CMultiFiles::Close(); - DeleteFile(m_fn); - } + if(ThreadExists()) + CallWorker(CMD_EXIT); + + if(!m_fn.IsEmpty()) + { + CMultiFiles::Close(); + DeleteFile(m_fn); + } } // IAsyncReader STDMETHODIMP CAsyncUrlReader::Length(LONGLONG* pTotal, LONGLONG* pAvailable) { - if(pTotal) *pTotal = 0; - return __super::Length(NULL, pAvailable); + if(pTotal) *pTotal = 0; + return __super::Length(NULL, pAvailable); } // CAMThread DWORD CAsyncUrlReader::ThreadProc() { - AfxSocketInit(NULL); - - DWORD cmd = GetRequest(); - if(cmd != CMD_INIT) - { - Reply(E_FAIL); - return E_FAIL; - } - - try - { - CInternetSession is; - CAutoPtr fin(is.OpenURL(m_url, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_CACHE_WRITE)); - - TCHAR path[_MAX_PATH], fn[_MAX_PATH]; - CFile fout; - if(GetTempPath(MAX_PATH, path) && GetTempFileName(path, _T("mpc_http"), 0, fn) - && fout.Open(fn, modeCreate | modeWrite | shareDenyWrite | typeBinary)) - { - m_fn = fn; - - char buff[1024]; - int len = fin->Read(buff, sizeof(buff)); - if(len > 0) fout.Write(buff, len); - - Reply(S_OK); - - while(!CheckRequest(&cmd)) - { - int len = fin->Read(buff, sizeof(buff)); - if(len > 0) fout.Write(buff, len); - } - } - else - { - Reply(E_FAIL); - } - - fin->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying - } - catch(CInternetException* ie) - { - ie->Delete(); - Reply(E_FAIL); - } - - // - - cmd = GetRequest(); - ASSERT(cmd == CMD_EXIT); - Reply(S_OK); - - // - - m_hThread = NULL; - - return S_OK; + AfxSocketInit(NULL); + + DWORD cmd = GetRequest(); + if(cmd != CMD_INIT) {Reply(E_FAIL); return E_FAIL;} + + try + { + CInternetSession is; + CAutoPtr fin(is.OpenURL(m_url, 1, INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_CACHE_WRITE)); + + TCHAR path[_MAX_PATH], fn[_MAX_PATH]; + CFile fout; + if(GetTempPath(MAX_PATH, path) && GetTempFileName(path, _T("mpc_http"), 0, fn) + && fout.Open(fn, modeCreate|modeWrite|shareDenyWrite|typeBinary)) + { + m_fn = fn; + + char buff[1024]; + int len = fin->Read(buff, sizeof(buff)); + if(len > 0) fout.Write(buff, len); + + Reply(S_OK); + + while(!CheckRequest(&cmd)) + { + int len = fin->Read(buff, sizeof(buff)); + if(len > 0) fout.Write(buff, len); + } + } + else + { + Reply(E_FAIL); + } + + fin->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying + } + catch(CInternetException* ie) + { + ie->Delete(); + Reply(E_FAIL); + } + + // + + cmd = GetRequest(); + ASSERT(cmd == CMD_EXIT); + Reply(S_OK); + + // + + m_hThread = NULL; + + return S_OK; } diff --git a/src/filters/parser/BaseSplitter/AsyncReader.h b/src/filters/parser/BaseSplitter/AsyncReader.h index 8f9cdfcf0..d26552f0e 100644 --- a/src/filters/parser/BaseSplitter/AsyncReader.h +++ b/src/filters/parser/BaseSplitter/AsyncReader.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -24,105 +24,73 @@ #include "MultiFiles.h" [uuid("6DDB4EE7-45A0-4459-A508-BD77B32C91B2")] -interface ISyncReader : -public IUnknown +interface ISyncReader : public IUnknown { - STDMETHOD_(void, SetBreakEvent)(HANDLE hBreakEvent) = 0; - STDMETHOD_(bool, HasErrors)() = 0; - STDMETHOD_(void, ClearErrors)() = 0; - STDMETHOD_(void, SetPTSOffset)(REFERENCE_TIME* rtPTSOffset) = 0; + STDMETHOD_(void, SetBreakEvent) (HANDLE hBreakEvent) = 0; + STDMETHOD_(bool, HasErrors) () = 0; + STDMETHOD_(void, ClearErrors) () = 0; + STDMETHOD_(void, SetPTSOffset) (REFERENCE_TIME* rtPTSOffset) = 0; }; [uuid("7D55F67A-826E-40B9-8A7D-3DF0CBBD272D")] -interface IFileHandle : -public IUnknown +interface IFileHandle : public IUnknown { - STDMETHOD_(HANDLE, GetFileHandle)() = 0; - STDMETHOD_(LPCTSTR, GetFileName)() = 0; + STDMETHOD_(HANDLE, GetFileHandle)() = 0; + STDMETHOD_(LPCTSTR, GetFileName)() = 0; }; class CAsyncFileReader : public CUnknown, public CMultiFiles, public IAsyncReader, public ISyncReader, public IFileHandle { protected: - ULONGLONG m_len; - HANDLE m_hBreakEvent; - LONG m_lOsError; // CFileException::m_lOsError + ULONGLONG m_len; + HANDLE m_hBreakEvent; + LONG m_lOsError; // CFileException::m_lOsError public: - CAsyncFileReader(CString fn, HRESULT& hr); - CAsyncFileReader(CAtlList& Items, HRESULT& hr); - - DECLARE_IUNKNOWN; - STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - - // IAsyncReader - - STDMETHODIMP RequestAllocator(IMemAllocator* pPreferred, ALLOCATOR_PROPERTIES* pProps, IMemAllocator** ppActual) - { - return E_NOTIMPL; - } - STDMETHODIMP Request(IMediaSample* pSample, DWORD_PTR dwUser) - { - return E_NOTIMPL; - } - STDMETHODIMP WaitForNext(DWORD dwTimeout, IMediaSample** ppSample, DWORD_PTR* pdwUser) - { - return E_NOTIMPL; - } - STDMETHODIMP SyncReadAligned(IMediaSample* pSample) - { - return E_NOTIMPL; - } - STDMETHODIMP SyncRead(LONGLONG llPosition, LONG lLength, BYTE* pBuffer); - STDMETHODIMP Length(LONGLONG* pTotal, LONGLONG* pAvailable); - STDMETHODIMP BeginFlush() - { - return E_NOTIMPL; - } - STDMETHODIMP EndFlush() - { - return E_NOTIMPL; - } - - // ISyncReader - - STDMETHODIMP_(void) SetBreakEvent(HANDLE hBreakEvent) - { - m_hBreakEvent = hBreakEvent; - } - STDMETHODIMP_(bool) HasErrors() - { - return m_lOsError != 0; - } - STDMETHODIMP_(void) ClearErrors() - { - m_lOsError = 0; - } - STDMETHODIMP_(void) SetPTSOffset(REFERENCE_TIME* rtPTSOffset) - { - m_pCurrentPTSOffset = rtPTSOffset; - }; - - // IFileHandle - - STDMETHODIMP_(HANDLE) GetFileHandle(); - STDMETHODIMP_(LPCTSTR) GetFileName(); + CAsyncFileReader(CString fn, HRESULT& hr); + CAsyncFileReader(CAtlList& Items, HRESULT& hr); + + DECLARE_IUNKNOWN; + STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); + + // IAsyncReader + + STDMETHODIMP RequestAllocator(IMemAllocator* pPreferred, ALLOCATOR_PROPERTIES* pProps, IMemAllocator** ppActual) {return E_NOTIMPL;} + STDMETHODIMP Request(IMediaSample* pSample, DWORD_PTR dwUser) {return E_NOTIMPL;} + STDMETHODIMP WaitForNext(DWORD dwTimeout, IMediaSample** ppSample, DWORD_PTR* pdwUser) {return E_NOTIMPL;} + STDMETHODIMP SyncReadAligned(IMediaSample* pSample) {return E_NOTIMPL;} + STDMETHODIMP SyncRead(LONGLONG llPosition, LONG lLength, BYTE* pBuffer); + STDMETHODIMP Length(LONGLONG* pTotal, LONGLONG* pAvailable); + STDMETHODIMP BeginFlush() {return E_NOTIMPL;} + STDMETHODIMP EndFlush() {return E_NOTIMPL;} + + // ISyncReader + + STDMETHODIMP_(void) SetBreakEvent(HANDLE hBreakEvent) {m_hBreakEvent = hBreakEvent;} + STDMETHODIMP_(bool) HasErrors() {return m_lOsError != 0;} + STDMETHODIMP_(void) ClearErrors() {m_lOsError = 0;} + STDMETHODIMP_(void) SetPTSOffset (REFERENCE_TIME* rtPTSOffset) { m_pCurrentPTSOffset = rtPTSOffset;}; + + // IFileHandle + + STDMETHODIMP_(HANDLE) GetFileHandle(); + STDMETHODIMP_(LPCTSTR) GetFileName(); }; class CAsyncUrlReader : public CAsyncFileReader, protected CAMThread { - CString m_url, m_fn; + CString m_url, m_fn; protected: - enum {CMD_EXIT, CMD_INIT}; + enum {CMD_EXIT, CMD_INIT}; DWORD ThreadProc(); public: - CAsyncUrlReader(CString url, HRESULT& hr); - virtual ~CAsyncUrlReader(); + CAsyncUrlReader(CString url, HRESULT& hr); + virtual ~CAsyncUrlReader(); - // IAsyncReader + // IAsyncReader - STDMETHODIMP Length(LONGLONG* pTotal, LONGLONG* pAvailable); + STDMETHODIMP Length(LONGLONG* pTotal, LONGLONG* pAvailable); }; diff --git a/src/filters/parser/BaseSplitter/BaseSplitter.cpp b/src/filters/parser/BaseSplitter/BaseSplitter.cpp index 783230bb6..1a57ed507 100644 --- a/src/filters/parser/BaseSplitter/BaseSplitter.cpp +++ b/src/filters/parser/BaseSplitter/BaseSplitter.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -43,57 +43,57 @@ CPacketQueue::CPacketQueue() : m_size(0) void CPacketQueue::Add(CAutoPtr p) { - CAutoLock cAutoLock(this); + CAutoLock cAutoLock(this); + + if(p) + { + m_size += p->GetDataSize(); - if(p) - { - m_size += p->GetDataSize(); - - if(p->bAppendable && !p->bDiscontinuity && !p->pmt - && p->rtStart == Packet::INVALID_TIME - && !IsEmpty() && GetTail()->rtStart != Packet::INVALID_TIME) - { - Packet* tail = GetTail(); - int oldsize = tail->GetCount(); - int newsize = tail->GetCount() + p->GetCount(); - tail->SetCount(newsize, max(1024, newsize)); // doubles the reserved buffer size - memcpy(tail->GetData() + oldsize, p->GetData(), p->GetCount()); - /* - GetTail()->Append(*p); // too slow - */ - return; - } - } - - AddTail(p); + if(p->bAppendable && !p->bDiscontinuity && !p->pmt + && p->rtStart == Packet::INVALID_TIME + && !IsEmpty() && GetTail()->rtStart != Packet::INVALID_TIME) + { + Packet* tail = GetTail(); + int oldsize = tail->GetCount(); + int newsize = tail->GetCount() + p->GetCount(); + tail->SetCount(newsize, max(1024, newsize)); // doubles the reserved buffer size + memcpy(tail->GetData() + oldsize, p->GetData(), p->GetCount()); + /* + GetTail()->Append(*p); // too slow + */ + return; + } + } + + AddTail(p); } CAutoPtr CPacketQueue::Remove() { - CAutoLock cAutoLock(this); - ASSERT(__super::GetCount() > 0); - CAutoPtr p = RemoveHead(); - if(p) m_size -= p->GetDataSize(); - return p; + CAutoLock cAutoLock(this); + ASSERT(__super::GetCount() > 0); + CAutoPtr p = RemoveHead(); + if(p) m_size -= p->GetDataSize(); + return p; } void CPacketQueue::RemoveAll() { - CAutoLock cAutoLock(this); - m_size = 0; - __super::RemoveAll(); + CAutoLock cAutoLock(this); + m_size = 0; + __super::RemoveAll(); } int CPacketQueue::GetCount() { - CAutoLock cAutoLock(this); - return __super::GetCount(); + CAutoLock cAutoLock(this); + return __super::GetCount(); } int CPacketQueue::GetSize() { - CAutoLock cAutoLock(this); - return m_size; + CAutoLock cAutoLock(this); + return m_size; } // @@ -101,7 +101,7 @@ int CPacketQueue::GetSize() // CBaseSplitterInputPin::CBaseSplitterInputPin(TCHAR* pName, CBaseSplitterFilter* pFilter, CCritSec* pLock, HRESULT* phr) - : CBasePin(pName, pFilter, pLock, phr, L"Input", PINDIR_INPUT) + : CBasePin(pName, pFilter, pLock, phr, L"Input", PINDIR_INPUT) { } @@ -111,80 +111,80 @@ CBaseSplitterInputPin::~CBaseSplitterInputPin() HRESULT CBaseSplitterInputPin::GetAsyncReader(IAsyncReader** ppAsyncReader) { - CheckPointer(ppAsyncReader, E_POINTER); - *ppAsyncReader = NULL; - CheckPointer(m_pAsyncReader, VFW_E_NOT_CONNECTED); - (*ppAsyncReader = m_pAsyncReader)->AddRef(); - return S_OK; + CheckPointer(ppAsyncReader, E_POINTER); + *ppAsyncReader = NULL; + CheckPointer(m_pAsyncReader, VFW_E_NOT_CONNECTED); + (*ppAsyncReader = m_pAsyncReader)->AddRef(); + return S_OK; } STDMETHODIMP CBaseSplitterInputPin::NonDelegatingQueryInterface(REFIID riid, void** ppv) { - CheckPointer(ppv, E_POINTER); + CheckPointer(ppv, E_POINTER); - return - __super::NonDelegatingQueryInterface(riid, ppv); + return + __super::NonDelegatingQueryInterface(riid, ppv); } HRESULT CBaseSplitterInputPin::CheckMediaType(const CMediaType* pmt) { - return S_OK; - /* - return pmt->majortype == MEDIATYPE_Stream - ? S_OK - : E_INVALIDARG; - */ + return S_OK; +/* + return pmt->majortype == MEDIATYPE_Stream + ? S_OK + : E_INVALIDARG; +*/ } HRESULT CBaseSplitterInputPin::CheckConnect(IPin* pPin) { - HRESULT hr; - if(FAILED(hr = __super::CheckConnect(pPin))) - return hr; + HRESULT hr; + if(FAILED(hr = __super::CheckConnect(pPin))) + return hr; - return CComQIPtr(pPin) ? S_OK : E_NOINTERFACE; + return CComQIPtr(pPin) ? S_OK : E_NOINTERFACE; } HRESULT CBaseSplitterInputPin::BreakConnect() { - HRESULT hr; + HRESULT hr; - if(FAILED(hr = __super::BreakConnect())) - return hr; + if(FAILED(hr = __super::BreakConnect())) + return hr; - if(FAILED(hr = (static_cast(m_pFilter))->BreakConnect(PINDIR_INPUT, this))) - return hr; + if(FAILED(hr = (static_cast(m_pFilter))->BreakConnect(PINDIR_INPUT, this))) + return hr; - m_pAsyncReader.Release(); + m_pAsyncReader.Release(); - return S_OK; + return S_OK; } HRESULT CBaseSplitterInputPin::CompleteConnect(IPin* pPin) { - HRESULT hr; + HRESULT hr; - if(FAILED(hr = __super::CompleteConnect(pPin))) - return hr; + if(FAILED(hr = __super::CompleteConnect(pPin))) + return hr; - CheckPointer(pPin, E_POINTER); - m_pAsyncReader = pPin; - CheckPointer(m_pAsyncReader, E_NOINTERFACE); + CheckPointer(pPin, E_POINTER); + m_pAsyncReader = pPin; + CheckPointer(m_pAsyncReader, E_NOINTERFACE); - if(FAILED(hr = (static_cast(m_pFilter))->CompleteConnect(PINDIR_INPUT, this))) - return hr; + if(FAILED(hr = (static_cast(m_pFilter))->CompleteConnect(PINDIR_INPUT, this))) + return hr; - return S_OK; + return S_OK; } STDMETHODIMP CBaseSplitterInputPin::BeginFlush() { - return E_UNEXPECTED; + return E_UNEXPECTED; } STDMETHODIMP CBaseSplitterInputPin::EndFlush() { - return E_UNEXPECTED; + return E_UNEXPECTED; } // @@ -192,26 +192,26 @@ STDMETHODIMP CBaseSplitterInputPin::EndFlush() // CBaseSplitterOutputPin::CBaseSplitterOutputPin(CAtlArray& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr, int nBuffers) - : CBaseOutputPin(NAME("CBaseSplitterOutputPin"), pFilter, pLock, phr, pName) - , m_hrDeliver(S_OK) // just in case it were asked before the worker thread could be created and reset it - , m_fFlushing(false) - , m_eEndFlush(TRUE) + : CBaseOutputPin(NAME("CBaseSplitterOutputPin"), pFilter, pLock, phr, pName) + , m_hrDeliver(S_OK) // just in case it were asked before the worker thread could be created and reset it + , m_fFlushing(false) + , m_eEndFlush(TRUE) { - m_mts.Copy(mts); - m_nBuffers = max(nBuffers, 1); - memset(&m_brs, 0, sizeof(m_brs)); - m_brs.rtLastDeliverTime = Packet::INVALID_TIME; + m_mts.Copy(mts); + m_nBuffers = max(nBuffers, 1); + memset(&m_brs, 0, sizeof(m_brs)); + m_brs.rtLastDeliverTime = Packet::INVALID_TIME; } CBaseSplitterOutputPin::CBaseSplitterOutputPin(LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr, int nBuffers) - : CBaseOutputPin(NAME("CBaseSplitterOutputPin"), pFilter, pLock, phr, pName) - , m_hrDeliver(S_OK) // just in case it were asked before the worker thread could be created and reset it - , m_fFlushing(false) - , m_eEndFlush(TRUE) + : CBaseOutputPin(NAME("CBaseSplitterOutputPin"), pFilter, pLock, phr, pName) + , m_hrDeliver(S_OK) // just in case it were asked before the worker thread could be created and reset it + , m_fFlushing(false) + , m_eEndFlush(TRUE) { - m_nBuffers = max(nBuffers, 1); - memset(&m_brs, 0, sizeof(m_brs)); - m_brs.rtLastDeliverTime = Packet::INVALID_TIME; + m_nBuffers = max(nBuffers, 1); + memset(&m_brs, 0, sizeof(m_brs)); + m_brs.rtLastDeliverTime = Packet::INVALID_TIME; } CBaseSplitterOutputPin::~CBaseSplitterOutputPin() @@ -220,26 +220,26 @@ CBaseSplitterOutputPin::~CBaseSplitterOutputPin() STDMETHODIMP CBaseSplitterOutputPin::NonDelegatingQueryInterface(REFIID riid, void** ppv) { - CheckPointer(ppv, E_POINTER); + CheckPointer(ppv, E_POINTER); - return -// riid == __uuidof(IMediaSeeking) ? m_pFilter->QueryInterface(riid, ppv) : - QI(IMediaSeeking) - QI(IPropertyBag) - QI(IPropertyBag2) - QI(IDSMPropertyBag) - QI(IBitRateInfo) - __super::NonDelegatingQueryInterface(riid, ppv); + return +// riid == __uuidof(IMediaSeeking) ? m_pFilter->QueryInterface(riid, ppv) : + QI(IMediaSeeking) + QI(IPropertyBag) + QI(IPropertyBag2) + QI(IDSMPropertyBag) + QI(IBitRateInfo) + __super::NonDelegatingQueryInterface(riid, ppv); } HRESULT CBaseSplitterOutputPin::SetName(LPCWSTR pName) { - CheckPointer(pName, E_POINTER); - if(m_pName) delete [] m_pName; - m_pName = DNew WCHAR[wcslen(pName)+1]; - CheckPointer(m_pName, E_OUTOFMEMORY); - wcscpy(m_pName, pName); - return S_OK; + CheckPointer(pName, E_POINTER); + if(m_pName) delete [] m_pName; + m_pName = DNew WCHAR[wcslen(pName)+1]; + CheckPointer(m_pName, E_OUTOFMEMORY); + wcscpy(m_pName, pName); + return S_OK; } HRESULT CBaseSplitterOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties) @@ -249,14 +249,14 @@ HRESULT CBaseSplitterOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATO HRESULT hr = NOERROR; - pProperties->cBuffers = m_nBuffers; - pProperties->cbBuffer = max(m_mt.lSampleSize, 1); + pProperties->cBuffers = m_nBuffers; + pProperties->cbBuffer = max(m_mt.lSampleSize, 1); - if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_mt.formattype == FORMAT_VorbisFormat) - { - // oh great, the oggds vorbis decoder assumes there will be two at least, stupid thing... - pProperties->cBuffers = max(pProperties->cBuffers, 2); - } + if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_mt.formattype == FORMAT_VorbisFormat) + { + // oh great, the oggds vorbis decoder assumes there will be two at least, stupid thing... + pProperties->cBuffers = max(pProperties->cBuffers, 2); + } ALLOCATOR_PROPERTIES Actual; if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr; @@ -269,30 +269,30 @@ HRESULT CBaseSplitterOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATO HRESULT CBaseSplitterOutputPin::CheckMediaType(const CMediaType* pmt) { - for(int i = 0; i < m_mts.GetCount(); i++) - { - if(*pmt == m_mts[i]) - return S_OK; - } + for(int i = 0; i < m_mts.GetCount(); i++) + { + if(*pmt == m_mts[i]) + return S_OK; + } - return E_INVALIDARG; + return E_INVALIDARG; } HRESULT CBaseSplitterOutputPin::GetMediaType(int iPosition, CMediaType* pmt) { CAutoLock cAutoLock(m_pLock); - if(iPosition < 0) return E_INVALIDARG; - if(iPosition >= m_mts.GetCount()) return VFW_S_NO_MORE_ITEMS; + if(iPosition < 0) return E_INVALIDARG; + if(iPosition >= m_mts.GetCount()) return VFW_S_NO_MORE_ITEMS; - *pmt = m_mts[iPosition]; + *pmt = m_mts[iPosition]; - return S_OK; + return S_OK; } STDMETHODIMP CBaseSplitterOutputPin::Notify(IBaseFilter* pSender, Quality q) { - return E_NOTIMPL; + return E_NOTIMPL; } // @@ -301,394 +301,393 @@ HRESULT CBaseSplitterOutputPin::Active() { CAutoLock cAutoLock(m_pLock); - if(m_Connected) - Create(); + if(m_Connected) + Create(); - return __super::Active(); + return __super::Active(); } HRESULT CBaseSplitterOutputPin::Inactive() { CAutoLock cAutoLock(m_pLock); - if(ThreadExists()) - CallWorker(CMD_EXIT); + if(ThreadExists()) + CallWorker(CMD_EXIT); - return __super::Inactive(); + return __super::Inactive(); } HRESULT CBaseSplitterOutputPin::DeliverBeginFlush() { - m_eEndFlush.Reset(); - m_fFlushed = false; - m_fFlushing = true; - m_hrDeliver = S_FALSE; - m_queue.RemoveAll(); - HRESULT hr = IsConnected() ? GetConnected()->BeginFlush() : S_OK; - if(S_OK != hr) m_eEndFlush.Set(); - return(hr); + m_eEndFlush.Reset(); + m_fFlushed = false; + m_fFlushing = true; + m_hrDeliver = S_FALSE; + m_queue.RemoveAll(); + HRESULT hr = IsConnected() ? GetConnected()->BeginFlush() : S_OK; + if(S_OK != hr) m_eEndFlush.Set(); + return(hr); } HRESULT CBaseSplitterOutputPin::DeliverEndFlush() { - if(!ThreadExists()) return S_FALSE; - HRESULT hr = IsConnected() ? GetConnected()->EndFlush() : S_OK; - m_hrDeliver = S_OK; - m_fFlushing = false; - m_fFlushed = true; - m_eEndFlush.Set(); - return hr; + if(!ThreadExists()) return S_FALSE; + HRESULT hr = IsConnected() ? GetConnected()->EndFlush() : S_OK; + m_hrDeliver = S_OK; + m_fFlushing = false; + m_fFlushed = true; + m_eEndFlush.Set(); + return hr; } HRESULT CBaseSplitterOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) { - m_brs.rtLastDeliverTime = Packet::INVALID_TIME; - if(m_fFlushing) return S_FALSE; - m_rtStart = tStart; - if(!ThreadExists()) return S_FALSE; - HRESULT hr = __super::DeliverNewSegment(tStart, tStop, dRate); - if(S_OK != hr) return hr; - MakeISCRHappy(); - return hr; + m_brs.rtLastDeliverTime = Packet::INVALID_TIME; + if(m_fFlushing) return S_FALSE; + m_rtStart = tStart; + if(!ThreadExists()) return S_FALSE; + HRESULT hr = __super::DeliverNewSegment(tStart, tStop, dRate); + if(S_OK != hr) return hr; + MakeISCRHappy(); + return hr; } int CBaseSplitterOutputPin::QueueCount() { - return m_queue.GetCount(); + return m_queue.GetCount(); } int CBaseSplitterOutputPin::QueueSize() { - return m_queue.GetSize(); + return m_queue.GetSize(); } HRESULT CBaseSplitterOutputPin::QueueEndOfStream() { - return QueuePacket(CAutoPtr()); // NULL means EndOfStream + return QueuePacket(CAutoPtr()); // NULL means EndOfStream } HRESULT CBaseSplitterOutputPin::QueuePacket(CAutoPtr p) { - if(!ThreadExists()) return S_FALSE; + if(!ThreadExists()) return S_FALSE; - while(S_OK == m_hrDeliver - && (!(static_cast(m_pFilter))->IsAnyPinDrying() - || m_queue.GetSize() > MAXPACKETSIZE * 100)) - Sleep(1); + while(S_OK == m_hrDeliver + && (!(static_cast(m_pFilter))->IsAnyPinDrying() + || m_queue.GetSize() > MAXPACKETSIZE*100)) + Sleep(1); - if(S_OK != m_hrDeliver) - return m_hrDeliver; + if(S_OK != m_hrDeliver) + return m_hrDeliver; - m_queue.Add(p); + m_queue.Add(p); - return m_hrDeliver; + return m_hrDeliver; } bool CBaseSplitterOutputPin::IsDiscontinuous() { - return m_mt.majortype == MEDIATYPE_Text - || m_mt.majortype == MEDIATYPE_ScriptCommand - || m_mt.majortype == MEDIATYPE_Subtitle - || m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE - || m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE - || m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE; + return m_mt.majortype == MEDIATYPE_Text + || m_mt.majortype == MEDIATYPE_ScriptCommand + || m_mt.majortype == MEDIATYPE_Subtitle + || m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE + || m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE + || m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE; } bool CBaseSplitterOutputPin::IsActive() { - CComPtr pPin = this; - do - { - CComPtr pPinTo; - CComQIPtr pSSIP; - if(S_OK == pPin->ConnectedTo(&pPinTo) && (pSSIP = pPinTo) && !pSSIP->IsActive()) - return(false); - pPin = GetFirstPin(GetFilterFromPin(pPinTo), PINDIR_OUTPUT); - } - while(pPin); + CComPtr pPin = this; + do + { + CComPtr pPinTo; + CComQIPtr pSSIP; + if(S_OK == pPin->ConnectedTo(&pPinTo) && (pSSIP = pPinTo) && !pSSIP->IsActive()) + return(false); + pPin = GetFirstPin(GetFilterFromPin(pPinTo), PINDIR_OUTPUT); + } + while(pPin); - return(true); + return(true); } DWORD CBaseSplitterOutputPin::ThreadProc() { - m_hrDeliver = S_OK; - m_fFlushing = m_fFlushed = false; - m_eEndFlush.Set(); - - while(1) - { - Sleep(1); - - DWORD cmd; - if(CheckRequest(&cmd)) - { - m_hThread = NULL; - cmd = GetRequest(); - Reply(S_OK); - ASSERT(cmd == CMD_EXIT); - return 0; - } - - int cnt = 0; - do - { - CAutoPtr p; - - { - CAutoLock cAutoLock(&m_queue); - if((cnt = m_queue.GetCount()) > 0) - p = m_queue.Remove(); - } - - if(S_OK == m_hrDeliver && cnt > 0) - { - ASSERT(!m_fFlushing); - - m_fFlushed = false; - - // flushing can still start here, to release a blocked deliver call - - HRESULT hr = p - ? DeliverPacket(p) - : DeliverEndOfStream(); - - m_eEndFlush.Wait(); // .. so we have to wait until it is done - - if(hr != S_OK && !m_fFlushed) // and only report the error in m_hrDeliver if we didn't flush the stream - { - // CAutoLock cAutoLock(&m_csQueueLock); - m_hrDeliver = hr; - break; - } - } - } - while(--cnt > 0); - } + m_hrDeliver = S_OK; + m_fFlushing = m_fFlushed = false; + m_eEndFlush.Set(); + + while(1) + { + Sleep(1); + + DWORD cmd; + if(CheckRequest(&cmd)) + { + m_hThread = NULL; + cmd = GetRequest(); + Reply(S_OK); + ASSERT(cmd == CMD_EXIT); + return 0; + } + + int cnt = 0; + do + { + CAutoPtr p; + + { + CAutoLock cAutoLock(&m_queue); + if((cnt = m_queue.GetCount()) > 0) + p = m_queue.Remove(); + } + + if(S_OK == m_hrDeliver && cnt > 0) + { + ASSERT(!m_fFlushing); + + m_fFlushed = false; + + // flushing can still start here, to release a blocked deliver call + + HRESULT hr = p + ? DeliverPacket(p) + : DeliverEndOfStream(); + + m_eEndFlush.Wait(); // .. so we have to wait until it is done + + if(hr != S_OK && !m_fFlushed) // and only report the error in m_hrDeliver if we didn't flush the stream + { + // CAutoLock cAutoLock(&m_csQueueLock); + m_hrDeliver = hr; + break; + } + } + } + while(--cnt > 0); + } } HRESULT CBaseSplitterOutputPin::DeliverPacket(CAutoPtr p) { - HRESULT hr; - - INT_PTR nBytes = p->GetCount(); - - if(nBytes == 0) - { - return S_OK; - } - - m_brs.nBytesSinceLastDeliverTime += nBytes; - - if(p->rtStart != Packet::INVALID_TIME) - { - if(m_brs.rtLastDeliverTime == Packet::INVALID_TIME) - { - m_brs.rtLastDeliverTime = p->rtStart; - m_brs.nBytesSinceLastDeliverTime = 0; - } - - if(m_brs.rtLastDeliverTime + 10000000 < p->rtStart) - { - REFERENCE_TIME rtDiff = p->rtStart - m_brs.rtLastDeliverTime; - - double secs, bits; - - secs = (double)rtDiff / 10000000; - bits = 8.0 * m_brs.nBytesSinceLastDeliverTime; - m_brs.nCurrentBitRate = (DWORD)(bits / secs); - - m_brs.rtTotalTimeDelivered += rtDiff; - m_brs.nTotalBytesDelivered += m_brs.nBytesSinceLastDeliverTime; - - secs = (double)m_brs.rtTotalTimeDelivered / 10000000; - bits = 8.0 * m_brs.nTotalBytesDelivered; - m_brs.nAverageBitRate = (DWORD)(bits / secs); - - m_brs.rtLastDeliverTime = p->rtStart; - m_brs.nBytesSinceLastDeliverTime = 0; - /* - TRACE(_T("[%d] c: %d kbps, a: %d kbps\n"), - p->TrackNumber, - (m_brs.nCurrentBitRate+500)/1000, - (m_brs.nAverageBitRate+500)/1000); - */ - } - - double dRate = 1.0; - if(SUCCEEDED((static_cast(m_pFilter))->GetRate(&dRate))) - { - p->rtStart = (REFERENCE_TIME)((double)p->rtStart / dRate); - p->rtStop = (REFERENCE_TIME)((double)p->rtStop / dRate); - } - } - - do - { - CComPtr pSample; - if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) break; - - if(nBytes > pSample->GetSize()) - { - pSample.Release(); - - ALLOCATOR_PROPERTIES props, actual; - if(S_OK != (hr = m_pAllocator->GetProperties(&props))) break; - props.cbBuffer = nBytes * 3 / 2; - - if(props.cBuffers > 1) - { - if(S_OK != (hr = __super::DeliverBeginFlush())) break; - if(S_OK != (hr = __super::DeliverEndFlush())) break; - } - - if(S_OK != (hr = m_pAllocator->Decommit())) break; - if(S_OK != (hr = m_pAllocator->SetProperties(&props, &actual))) break; - if(S_OK != (hr = m_pAllocator->Commit())) break; - if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) break; - } - - if(p->pmt) - { - pSample->SetMediaType(p->pmt); - p->bDiscontinuity = true; - - CAutoLock cAutoLock(m_pLock); - m_mts.RemoveAll(); - m_mts.Add(*p->pmt); - } - - bool fTimeValid = p->rtStart != Packet::INVALID_TIME; - /* - //if(p->TrackNumber == 1) - //if(p->rtStart != Packet::INVALID_TIME) - TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"), - p->TrackNumber, - p->bDiscontinuity, p->bSyncPoint, fTimeValid && p->rtStart < 0, - nBytes, p->rtStart, p->rtStop); - */ - ASSERT(!p->bSyncPoint || fTimeValid); - - BYTE* pData = NULL; - if(S_OK != (hr = pSample->GetPointer(&pData)) || !pData) break; - memcpy(pData, p->GetData(), nBytes); - if(S_OK != (hr = pSample->SetActualDataLength(nBytes))) break; - if(S_OK != (hr = pSample->SetTime(fTimeValid ? &p->rtStart : NULL, fTimeValid ? &p->rtStop : NULL))) break; - if(S_OK != (hr = pSample->SetMediaTime(NULL, NULL))) break; - if(S_OK != (hr = pSample->SetDiscontinuity(p->bDiscontinuity))) break; - if(S_OK != (hr = pSample->SetSyncPoint(p->bSyncPoint))) break; - if(S_OK != (hr = pSample->SetPreroll(fTimeValid && p->rtStart < 0))) break; - if(S_OK != (hr = Deliver(pSample))) break; - } - while(false); - - return hr; + HRESULT hr; + + INT_PTR nBytes = p->GetCount(); + + if(nBytes == 0) + { + return S_OK; + } + + m_brs.nBytesSinceLastDeliverTime += nBytes; + + if(p->rtStart != Packet::INVALID_TIME) + { + if(m_brs.rtLastDeliverTime == Packet::INVALID_TIME) + { + m_brs.rtLastDeliverTime = p->rtStart; + m_brs.nBytesSinceLastDeliverTime = 0; + } + + if(m_brs.rtLastDeliverTime + 10000000 < p->rtStart) + { + REFERENCE_TIME rtDiff = p->rtStart - m_brs.rtLastDeliverTime; + + double secs, bits; + + secs = (double)rtDiff / 10000000; + bits = 8.0 * m_brs.nBytesSinceLastDeliverTime; + m_brs.nCurrentBitRate = (DWORD)(bits / secs); + + m_brs.rtTotalTimeDelivered += rtDiff; + m_brs.nTotalBytesDelivered += m_brs.nBytesSinceLastDeliverTime; + + secs = (double)m_brs.rtTotalTimeDelivered / 10000000; + bits = 8.0 * m_brs.nTotalBytesDelivered; + m_brs.nAverageBitRate = (DWORD)(bits / secs); + + m_brs.rtLastDeliverTime = p->rtStart; + m_brs.nBytesSinceLastDeliverTime = 0; +/* + TRACE(_T("[%d] c: %d kbps, a: %d kbps\n"), + p->TrackNumber, + (m_brs.nCurrentBitRate+500)/1000, + (m_brs.nAverageBitRate+500)/1000); +*/ + } + + double dRate = 1.0; + if(SUCCEEDED((static_cast(m_pFilter))->GetRate(&dRate))) + { + p->rtStart = (REFERENCE_TIME)((double)p->rtStart / dRate); + p->rtStop = (REFERENCE_TIME)((double)p->rtStop / dRate); + } + } + + do + { + CComPtr pSample; + if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) break; + + if(nBytes > pSample->GetSize()) + { + pSample.Release(); + + ALLOCATOR_PROPERTIES props, actual; + if(S_OK != (hr = m_pAllocator->GetProperties(&props))) break; + props.cbBuffer = nBytes*3/2; + + if(props.cBuffers > 1) + { + if(S_OK != (hr = __super::DeliverBeginFlush())) break; + if(S_OK != (hr = __super::DeliverEndFlush())) break; + } + + if(S_OK != (hr = m_pAllocator->Decommit())) break; + if(S_OK != (hr = m_pAllocator->SetProperties(&props, &actual))) break; + if(S_OK != (hr = m_pAllocator->Commit())) break; + if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) break; + } + + if(p->pmt) + { + pSample->SetMediaType(p->pmt); + p->bDiscontinuity = true; + + CAutoLock cAutoLock(m_pLock); + m_mts.RemoveAll(); + m_mts.Add(*p->pmt); + } + + bool fTimeValid = p->rtStart != Packet::INVALID_TIME; +/* +//if(p->TrackNumber == 1) +//if(p->rtStart != Packet::INVALID_TIME) +TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"), + p->TrackNumber, + p->bDiscontinuity, p->bSyncPoint, fTimeValid && p->rtStart < 0, + nBytes, p->rtStart, p->rtStop); +*/ + ASSERT(!p->bSyncPoint || fTimeValid); + + BYTE* pData = NULL; + if(S_OK != (hr = pSample->GetPointer(&pData)) || !pData) break; + memcpy(pData, p->GetData(), nBytes); + if(S_OK != (hr = pSample->SetActualDataLength(nBytes))) break; + if(S_OK != (hr = pSample->SetTime(fTimeValid ? &p->rtStart : NULL, fTimeValid ? &p->rtStop : NULL))) break; + if(S_OK != (hr = pSample->SetMediaTime(NULL, NULL))) break; + if(S_OK != (hr = pSample->SetDiscontinuity(p->bDiscontinuity))) break; + if(S_OK != (hr = pSample->SetSyncPoint(p->bSyncPoint))) break; + if(S_OK != (hr = pSample->SetPreroll(fTimeValid && p->rtStart < 0))) break; + if(S_OK != (hr = Deliver(pSample))) break; + } + while(false); + + return hr; } void CBaseSplitterOutputPin::MakeISCRHappy() { - CComPtr pPinTo = this, pTmp; - while(pPinTo && SUCCEEDED(pPinTo->ConnectedTo(&pTmp)) && (pPinTo = pTmp)) - { - pTmp = NULL; + CComPtr pPinTo = this, pTmp; + while(pPinTo && SUCCEEDED(pPinTo->ConnectedTo(&pTmp)) && (pPinTo = pTmp)) + { + pTmp = NULL; - CComPtr pBF = GetFilterFromPin(pPinTo); + CComPtr pBF = GetFilterFromPin(pPinTo); - if(GetCLSID(pBF) == GUIDFromCString(_T("{48025243-2D39-11CE-875D-00608CB78066}"))) // ISCR - { - CAutoPtr p(DNew Packet()); - p->TrackNumber = (DWORD) - 1; - p->rtStart = -1; - p->rtStop = 0; - p->bSyncPoint = FALSE; - p->SetData(" ", 2); - QueuePacket(p); - break; - } + if(GetCLSID(pBF) == GUIDFromCString(_T("{48025243-2D39-11CE-875D-00608CB78066}"))) // ISCR + { + CAutoPtr p(DNew Packet()); + p->TrackNumber = (DWORD)-1; + p->rtStart = -1; p->rtStop = 0; + p->bSyncPoint = FALSE; + p->SetData(" ", 2); + QueuePacket(p); + break; + } - pPinTo = GetFirstPin(pBF, PINDIR_OUTPUT); - } + pPinTo = GetFirstPin(pBF, PINDIR_OUTPUT); + } } HRESULT CBaseSplitterOutputPin::GetDeliveryBuffer(IMediaSample** ppSample, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags) { - return __super::GetDeliveryBuffer(ppSample, pStartTime, pEndTime, dwFlags); + return __super::GetDeliveryBuffer(ppSample, pStartTime, pEndTime, dwFlags); } HRESULT CBaseSplitterOutputPin::Deliver(IMediaSample* pSample) { - return __super::Deliver(pSample); + return __super::Deliver(pSample); } // IMediaSeeking STDMETHODIMP CBaseSplitterOutputPin::GetCapabilities(DWORD* pCapabilities) { - return (static_cast(m_pFilter))->GetCapabilities(pCapabilities); + return (static_cast(m_pFilter))->GetCapabilities(pCapabilities); } STDMETHODIMP CBaseSplitterOutputPin::CheckCapabilities(DWORD* pCapabilities) { - return (static_cast(m_pFilter))->CheckCapabilities(pCapabilities); + return (static_cast(m_pFilter))->CheckCapabilities(pCapabilities); } STDMETHODIMP CBaseSplitterOutputPin::IsFormatSupported(const GUID* pFormat) { - return (static_cast(m_pFilter))->IsFormatSupported(pFormat); + return (static_cast(m_pFilter))->IsFormatSupported(pFormat); } STDMETHODIMP CBaseSplitterOutputPin::QueryPreferredFormat(GUID* pFormat) { - return (static_cast(m_pFilter))->QueryPreferredFormat(pFormat); + return (static_cast(m_pFilter))->QueryPreferredFormat(pFormat); } STDMETHODIMP CBaseSplitterOutputPin::GetTimeFormat(GUID* pFormat) { - return (static_cast(m_pFilter))->GetTimeFormat(pFormat); + return (static_cast(m_pFilter))->GetTimeFormat(pFormat); } STDMETHODIMP CBaseSplitterOutputPin::IsUsingTimeFormat(const GUID* pFormat) { - return (static_cast(m_pFilter))->IsUsingTimeFormat(pFormat); + return (static_cast(m_pFilter))->IsUsingTimeFormat(pFormat); } STDMETHODIMP CBaseSplitterOutputPin::SetTimeFormat(const GUID* pFormat) { - return (static_cast(m_pFilter))->SetTimeFormat(pFormat); + return (static_cast(m_pFilter))->SetTimeFormat(pFormat); } STDMETHODIMP CBaseSplitterOutputPin::GetDuration(LONGLONG* pDuration) { - return (static_cast(m_pFilter))->GetDuration(pDuration); + return (static_cast(m_pFilter))->GetDuration(pDuration); } STDMETHODIMP CBaseSplitterOutputPin::GetStopPosition(LONGLONG* pStop) { - return (static_cast(m_pFilter))->GetStopPosition(pStop); + return (static_cast(m_pFilter))->GetStopPosition(pStop); } STDMETHODIMP CBaseSplitterOutputPin::GetCurrentPosition(LONGLONG* pCurrent) { - return (static_cast(m_pFilter))->GetCurrentPosition(pCurrent); + return (static_cast(m_pFilter))->GetCurrentPosition(pCurrent); } STDMETHODIMP CBaseSplitterOutputPin::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) { - return (static_cast(m_pFilter))->ConvertTimeFormat(pTarget, pTargetFormat, Source, pSourceFormat); + return (static_cast(m_pFilter))->ConvertTimeFormat(pTarget, pTargetFormat, Source, pSourceFormat); } STDMETHODIMP CBaseSplitterOutputPin::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) { - return (static_cast(m_pFilter))->SetPositionsInternal(this, pCurrent, dwCurrentFlags, pStop, dwStopFlags); + return (static_cast(m_pFilter))->SetPositionsInternal(this, pCurrent, dwCurrentFlags, pStop, dwStopFlags); } STDMETHODIMP CBaseSplitterOutputPin::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) { - return (static_cast(m_pFilter))->GetPositions(pCurrent, pStop); + return (static_cast(m_pFilter))->GetPositions(pCurrent, pStop); } STDMETHODIMP CBaseSplitterOutputPin::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) { - return (static_cast(m_pFilter))->GetAvailable(pEarliest, pLatest); + return (static_cast(m_pFilter))->GetAvailable(pEarliest, pLatest); } STDMETHODIMP CBaseSplitterOutputPin::SetRate(double dRate) { - return (static_cast(m_pFilter))->SetRate(dRate); + return (static_cast(m_pFilter))->SetRate(dRate); } STDMETHODIMP CBaseSplitterOutputPin::GetRate(double* pdRate) { - return (static_cast(m_pFilter))->GetRate(pdRate); + return (static_cast(m_pFilter))->GetRate(pdRate); } STDMETHODIMP CBaseSplitterOutputPin::GetPreroll(LONGLONG* pllPreroll) { - return (static_cast(m_pFilter))->GetPreroll(pllPreroll); + return (static_cast(m_pFilter))->GetPreroll(pllPreroll); } // @@ -696,784 +695,729 @@ STDMETHODIMP CBaseSplitterOutputPin::GetPreroll(LONGLONG* pllPreroll) // CBaseSplitterFilter::CBaseSplitterFilter(LPCTSTR pName, LPUNKNOWN pUnk, HRESULT* phr, const CLSID& clsid) - : CBaseFilter(pName, pUnk, this, clsid) - , m_rtDuration(0), m_rtStart(0), m_rtStop(0), m_rtCurrent(0) - , m_dRate(1.0) - , m_nOpenProgress(100) - , m_fAbort(false) - , m_rtLastStart(_I64_MIN) - , m_rtLastStop(_I64_MIN) - , m_priority(THREAD_PRIORITY_NORMAL) + : CBaseFilter(pName, pUnk, this, clsid) + , m_rtDuration(0), m_rtStart(0), m_rtStop(0), m_rtCurrent(0) + , m_dRate(1.0) + , m_nOpenProgress(100) + , m_fAbort(false) + , m_rtLastStart(_I64_MIN) + , m_rtLastStop(_I64_MIN) + , m_priority(THREAD_PRIORITY_NORMAL) { - if(phr) *phr = S_OK; + if(phr) *phr = S_OK; - m_pInput.Attach(DNew CBaseSplitterInputPin(NAME("CBaseSplitterInputPin"), this, this, phr)); + m_pInput.Attach(DNew CBaseSplitterInputPin(NAME("CBaseSplitterInputPin"), this, this, phr)); } CBaseSplitterFilter::~CBaseSplitterFilter() { - CAutoLock cAutoLock(this); + CAutoLock cAutoLock(this); - CAMThread::CallWorker(CMD_EXIT); - CAMThread::Close(); + CAMThread::CallWorker(CMD_EXIT); + CAMThread::Close(); } STDMETHODIMP CBaseSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv) { - CheckPointer(ppv, E_POINTER); + CheckPointer(ppv, E_POINTER); - *ppv = NULL; + *ppv = NULL; - if(m_pInput && riid == __uuidof(IFileSourceFilter)) - return E_NOINTERFACE; + if(m_pInput && riid == __uuidof(IFileSourceFilter)) + return E_NOINTERFACE; - return - QI(IFileSourceFilter) - QI(IMediaSeeking) - QI(IAMOpenProgress) - QI2(IAMMediaContent) - QI2(IAMExtendedSeeking) - QI(IKeyFrameInfo) - QI(IBufferInfo) - QI(IPropertyBag) - QI(IPropertyBag2) - QI(IDSMPropertyBag) - QI(IDSMResourceBag) - QI(IDSMChapterBag) - __super::NonDelegatingQueryInterface(riid, ppv); + return + QI(IFileSourceFilter) + QI(IMediaSeeking) + QI(IAMOpenProgress) + QI2(IAMMediaContent) + QI2(IAMExtendedSeeking) + QI(IKeyFrameInfo) + QI(IBufferInfo) + QI(IPropertyBag) + QI(IPropertyBag2) + QI(IDSMPropertyBag) + QI(IDSMResourceBag) + QI(IDSMChapterBag) + __super::NonDelegatingQueryInterface(riid, ppv); } CBaseSplitterOutputPin* CBaseSplitterFilter::GetOutputPin(DWORD TrackNum) { - CAutoLock cAutoLock(&m_csPinMap); + CAutoLock cAutoLock(&m_csPinMap); CBaseSplitterOutputPin* pPin = NULL; - m_pPinMap.Lookup(TrackNum, pPin); - return pPin; + m_pPinMap.Lookup(TrackNum, pPin); + return pPin; } DWORD CBaseSplitterFilter::GetOutputTrackNum(CBaseSplitterOutputPin* pPin) { - CAutoLock cAutoLock(&m_csPinMap); + CAutoLock cAutoLock(&m_csPinMap); - POSITION pos = m_pPinMap.GetStartPosition(); - while(pos) - { - DWORD TrackNum; - CBaseSplitterOutputPin* pPinTmp; - m_pPinMap.GetNextAssoc(pos, TrackNum, pPinTmp); - if(pPinTmp == pPin) return TrackNum; - } + POSITION pos = m_pPinMap.GetStartPosition(); + while(pos) + { + DWORD TrackNum; + CBaseSplitterOutputPin* pPinTmp; + m_pPinMap.GetNextAssoc(pos, TrackNum, pPinTmp); + if(pPinTmp == pPin) return TrackNum; + } - return (DWORD) - 1; + return (DWORD)-1; } HRESULT CBaseSplitterFilter::RenameOutputPin(DWORD TrackNumSrc, DWORD TrackNumDst, const AM_MEDIA_TYPE* pmt) { - CAutoLock cAutoLock(&m_csPinMap); + CAutoLock cAutoLock(&m_csPinMap); - CBaseSplitterOutputPin* pPin; - if(m_pPinMap.Lookup(TrackNumSrc, pPin)) - { - if(CComQIPtr pPinTo = pPin->GetConnected()) - { - if(pmt && S_OK != pPinTo->QueryAccept(pmt)) - return VFW_E_TYPE_NOT_ACCEPTED; - } + CBaseSplitterOutputPin* pPin; + if(m_pPinMap.Lookup(TrackNumSrc, pPin)) + { + if(CComQIPtr pPinTo = pPin->GetConnected()) + { + if(pmt && S_OK != pPinTo->QueryAccept(pmt)) + return VFW_E_TYPE_NOT_ACCEPTED; + } - m_pPinMap.RemoveKey(TrackNumSrc); - m_pPinMap[TrackNumDst] = pPin; + m_pPinMap.RemoveKey(TrackNumSrc); + m_pPinMap[TrackNumDst] = pPin; - if(pmt) - { - CAutoLock cAutoLock(&m_csmtnew); - m_mtnew[TrackNumDst] = *pmt; - } + if(pmt) + { + CAutoLock cAutoLock(&m_csmtnew); + m_mtnew[TrackNumDst] = *pmt; + } - return S_OK; - } + return S_OK; + } - return E_FAIL; + return E_FAIL; } HRESULT CBaseSplitterFilter::AddOutputPin(DWORD TrackNum, CAutoPtr pPin) { - CAutoLock cAutoLock(&m_csPinMap); + CAutoLock cAutoLock(&m_csPinMap); - if(!pPin) return E_INVALIDARG; - m_pPinMap[TrackNum] = pPin; - m_pOutputs.AddTail(pPin); - return S_OK; + if(!pPin) return E_INVALIDARG; + m_pPinMap[TrackNum] = pPin; + m_pOutputs.AddTail(pPin); + return S_OK; } HRESULT CBaseSplitterFilter::DeleteOutputs() { - m_rtDuration = 0; + m_rtDuration = 0; - m_pRetiredOutputs.RemoveAll(); + m_pRetiredOutputs.RemoveAll(); - CAutoLock cAutoLockF(this); - if(m_State != State_Stopped) return VFW_E_NOT_STOPPED; + CAutoLock cAutoLockF(this); + if(m_State != State_Stopped) return VFW_E_NOT_STOPPED; - while(m_pOutputs.GetCount()) - { - CAutoPtr pPin = m_pOutputs.RemoveHead(); - if(IPin* pPinTo = pPin->GetConnected()) pPinTo->Disconnect(); - pPin->Disconnect(); - // we can't just let it be deleted now, something might have AddRefed on it (graphedit...) - m_pRetiredOutputs.AddTail(pPin); - } + while(m_pOutputs.GetCount()) + { + CAutoPtr pPin = m_pOutputs.RemoveHead(); + if(IPin* pPinTo = pPin->GetConnected()) pPinTo->Disconnect(); + pPin->Disconnect(); + // we can't just let it be deleted now, something might have AddRefed on it (graphedit...) + m_pRetiredOutputs.AddTail(pPin); + } - CAutoLock cAutoLockPM(&m_csPinMap); - m_pPinMap.RemoveAll(); + CAutoLock cAutoLockPM(&m_csPinMap); + m_pPinMap.RemoveAll(); - CAutoLock cAutoLockMT(&m_csmtnew); - m_mtnew.RemoveAll(); + CAutoLock cAutoLockMT(&m_csmtnew); + m_mtnew.RemoveAll(); - RemoveAll(); - ResRemoveAll(); - ChapRemoveAll(); + RemoveAll(); + ResRemoveAll(); + ChapRemoveAll(); - m_fontinst.UninstallFonts(); + m_fontinst.UninstallFonts(); - m_pSyncReader.Release(); + m_pSyncReader.Release(); - return S_OK; + return S_OK; } void CBaseSplitterFilter::DeliverBeginFlush() { - m_fFlushing = true; - POSITION pos = m_pOutputs.GetHeadPosition(); - while(pos) m_pOutputs.GetNext(pos)->DeliverBeginFlush(); + m_fFlushing = true; + POSITION pos = m_pOutputs.GetHeadPosition(); + while(pos) m_pOutputs.GetNext(pos)->DeliverBeginFlush(); } void CBaseSplitterFilter::DeliverEndFlush() { - POSITION pos = m_pOutputs.GetHeadPosition(); - while(pos) m_pOutputs.GetNext(pos)->DeliverEndFlush(); - m_fFlushing = false; - m_eEndFlush.Set(); + POSITION pos = m_pOutputs.GetHeadPosition(); + while(pos) m_pOutputs.GetNext(pos)->DeliverEndFlush(); + m_fFlushing = false; + m_eEndFlush.Set(); } DWORD CBaseSplitterFilter::ThreadProc() { - if(m_pSyncReader) - m_pSyncReader->SetBreakEvent(GetRequestHandle()); + if(m_pSyncReader) + m_pSyncReader->SetBreakEvent(GetRequestHandle()); - if(!DemuxInit()) - { - while(1) - { - DWORD cmd = GetRequest(); - if(cmd == CMD_EXIT) CAMThread::m_hThread = NULL; - Reply(S_OK); - if(cmd == CMD_EXIT) return 0; - } - } + if(!DemuxInit()) + { + while(1) + { + DWORD cmd = GetRequest(); + if(cmd == CMD_EXIT) CAMThread::m_hThread = NULL; + Reply(S_OK); + if(cmd == CMD_EXIT) return 0; + } + } - m_eEndFlush.Set(); - m_fFlushing = false; + m_eEndFlush.Set(); + m_fFlushing = false; - for(DWORD cmd = -1; ; cmd = GetRequest()) - { - if(cmd == CMD_EXIT) - { - m_hThread = NULL; - Reply(S_OK); - return 0; - } + for(DWORD cmd = -1; ; cmd = GetRequest()) + { + if(cmd == CMD_EXIT) + { + m_hThread = NULL; + Reply(S_OK); + return 0; + } - SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_NORMAL); + SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_NORMAL); - m_rtStart = m_rtNewStart; - m_rtStop = m_rtNewStop; + m_rtStart = m_rtNewStart; + m_rtStop = m_rtNewStop; - DemuxSeek(m_rtStart); + DemuxSeek(m_rtStart); - if(cmd != -1) - Reply(S_OK); + if(cmd != -1) + Reply(S_OK); - m_eEndFlush.Wait(); + m_eEndFlush.Wait(); - m_pActivePins.RemoveAll(); + m_pActivePins.RemoveAll(); - POSITION pos = m_pOutputs.GetHeadPosition(); - while(pos && !m_fFlushing) - { - CBaseSplitterOutputPin* pPin = m_pOutputs.GetNext(pos); - if(pPin->IsConnected() && pPin->IsActive()) - { - m_pActivePins.AddTail(pPin); - pPin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate); - } - } + POSITION pos = m_pOutputs.GetHeadPosition(); + while(pos && !m_fFlushing) + { + CBaseSplitterOutputPin* pPin = m_pOutputs.GetNext(pos); + if(pPin->IsConnected() && pPin->IsActive()) + { + m_pActivePins.AddTail(pPin); + pPin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate); + } + } - do - { - m_bDiscontinuitySent.RemoveAll(); - } - while(!DemuxLoop()); + do {m_bDiscontinuitySent.RemoveAll();} + while(!DemuxLoop()); - pos = m_pActivePins.GetHeadPosition(); - while(pos && !CheckRequest(&cmd)) - m_pActivePins.GetNext(pos)->QueueEndOfStream(); - } + pos = m_pActivePins.GetHeadPosition(); + while(pos && !CheckRequest(&cmd)) + m_pActivePins.GetNext(pos)->QueueEndOfStream(); + } - ASSERT(0); // we should only exit via CMD_EXIT + ASSERT(0); // we should only exit via CMD_EXIT - m_hThread = NULL; - return 0; + m_hThread = NULL; + return 0; } HRESULT CBaseSplitterFilter::DeliverPacket(CAutoPtr p) { - HRESULT hr = S_FALSE; + HRESULT hr = S_FALSE; - CBaseSplitterOutputPin* pPin = GetOutputPin(p->TrackNumber); - if(!pPin || !pPin->IsConnected() || !m_pActivePins.Find(pPin)) - return S_FALSE; + CBaseSplitterOutputPin* pPin = GetOutputPin(p->TrackNumber); + if(!pPin || !pPin->IsConnected() || !m_pActivePins.Find(pPin)) + return S_FALSE; - if(p->rtStart != Packet::INVALID_TIME) - { - m_rtCurrent = p->rtStart; + if(p->rtStart != Packet::INVALID_TIME) + { + m_rtCurrent = p->rtStart; - p->rtStart -= m_rtStart; - p->rtStop -= m_rtStart; + p->rtStart -= m_rtStart; + p->rtStop -= m_rtStart; - ASSERT(p->rtStart <= p->rtStop); - } + ASSERT(p->rtStart <= p->rtStop); + } - { - CAutoLock cAutoLock(&m_csmtnew); + { + CAutoLock cAutoLock(&m_csmtnew); - CMediaType mt; - if(m_mtnew.Lookup(p->TrackNumber, mt)) - { - p->pmt = CreateMediaType(&mt); - m_mtnew.RemoveKey(p->TrackNumber); - } - } + CMediaType mt; + if(m_mtnew.Lookup(p->TrackNumber, mt)) + { + p->pmt = CreateMediaType(&mt); + m_mtnew.RemoveKey(p->TrackNumber); + } + } - if(!m_bDiscontinuitySent.Find(p->TrackNumber)) - p->bDiscontinuity = TRUE; + if(!m_bDiscontinuitySent.Find(p->TrackNumber)) + p->bDiscontinuity = TRUE; - DWORD TrackNumber = p->TrackNumber; - BOOL bDiscontinuity = p->bDiscontinuity; - /* - //if(p->TrackNumber == 1) - //if(p->rtStart != Packet::INVALID_TIME) - TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"), - p->TrackNumber, - p->bDiscontinuity, p->bSyncPoint, p->rtStart != Packet::INVALID_TIME && p->rtStart < 0, - p->GetCount(), p->rtStart, p->rtStop); - */ + DWORD TrackNumber = p->TrackNumber; + BOOL bDiscontinuity = p->bDiscontinuity; +/* +//if(p->TrackNumber == 1) +//if(p->rtStart != Packet::INVALID_TIME) +TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"), + p->TrackNumber, + p->bDiscontinuity, p->bSyncPoint, p->rtStart != Packet::INVALID_TIME && p->rtStart < 0, + p->GetCount(), p->rtStart, p->rtStop); +*/ - hr = pPin->QueuePacket(p); + hr = pPin->QueuePacket(p); - if(S_OK != hr) - { - if(POSITION pos = m_pActivePins.Find(pPin)) - m_pActivePins.RemoveAt(pos); + if(S_OK != hr) + { + if(POSITION pos = m_pActivePins.Find(pPin)) + m_pActivePins.RemoveAt(pos); - if(!m_pActivePins.IsEmpty()) // only die when all pins are down - hr = S_OK; + if(!m_pActivePins.IsEmpty()) // only die when all pins are down + hr = S_OK; - return hr; - } + return hr; + } - if(bDiscontinuity) - m_bDiscontinuitySent.AddTail(TrackNumber); + if(bDiscontinuity) + m_bDiscontinuitySent.AddTail(TrackNumber); - return hr; + return hr; } bool CBaseSplitterFilter::IsAnyPinDrying() { - int totalcount = 0, totalsize = 0; + int totalcount = 0, totalsize = 0; - POSITION pos = m_pActivePins.GetHeadPosition(); - while(pos) - { - CBaseSplitterOutputPin* pPin = m_pActivePins.GetNext(pos); - int count = pPin->QueueCount(); - int size = pPin->QueueSize(); - if(!pPin->IsDiscontinuous() && (count < MINPACKETS || size < MINPACKETSIZE)) - { + POSITION pos = m_pActivePins.GetHeadPosition(); + while(pos) + { + CBaseSplitterOutputPin* pPin = m_pActivePins.GetNext(pos); + int count = pPin->QueueCount(); + int size = pPin->QueueSize(); + if(!pPin->IsDiscontinuous() && (count < MINPACKETS || size < MINPACKETSIZE)) + { // if(m_priority != THREAD_PRIORITY_ABOVE_NORMAL && (count < MINPACKETS/3 || size < MINPACKETSIZE/3)) - if(m_priority != THREAD_PRIORITY_BELOW_NORMAL && (count < MINPACKETS / 3 || size < MINPACKETSIZE / 3)) - { - // SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_ABOVE_NORMAL); - POSITION pos = m_pOutputs.GetHeadPosition(); - while(pos) m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); - m_priority = THREAD_PRIORITY_BELOW_NORMAL; - } - return(true); - } - totalcount += count; - totalsize += size; - } - - if(m_priority != THREAD_PRIORITY_NORMAL && (totalcount > MAXPACKETS * 2 / 3 || totalsize > MAXPACKETSIZE * 2 / 3)) - { + if(m_priority != THREAD_PRIORITY_BELOW_NORMAL && (count < MINPACKETS/3 || size < MINPACKETSIZE/3)) + { + // SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_ABOVE_NORMAL); + POSITION pos = m_pOutputs.GetHeadPosition(); + while(pos) m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); + m_priority = THREAD_PRIORITY_BELOW_NORMAL; + } + return(true); + } + totalcount += count; + totalsize += size; + } + + if(m_priority != THREAD_PRIORITY_NORMAL && (totalcount > MAXPACKETS*2/3 || totalsize > MAXPACKETSIZE*2/3)) + { // SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_NORMAL); - POSITION pos = m_pOutputs.GetHeadPosition(); - while(pos) m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_NORMAL); - m_priority = THREAD_PRIORITY_NORMAL; - } + POSITION pos = m_pOutputs.GetHeadPosition(); + while(pos) m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_NORMAL); + m_priority = THREAD_PRIORITY_NORMAL; + } - if(totalcount < MAXPACKETS && totalsize < MAXPACKETSIZE) - return(true); + if(totalcount < MAXPACKETS && totalsize < MAXPACKETSIZE) + return(true); - return(false); + return(false); } HRESULT CBaseSplitterFilter::BreakConnect(PIN_DIRECTION dir, CBasePin* pPin) { - CheckPointer(pPin, E_POINTER); + CheckPointer(pPin, E_POINTER); - if(dir == PINDIR_INPUT) - { - DeleteOutputs(); - } - else if(dir == PINDIR_OUTPUT) - { - } - else - { - return E_UNEXPECTED; - } + if(dir == PINDIR_INPUT) + { + DeleteOutputs(); + } + else if(dir == PINDIR_OUTPUT) + { + } + else + { + return E_UNEXPECTED; + } - return S_OK; + return S_OK; } HRESULT CBaseSplitterFilter::CompleteConnect(PIN_DIRECTION dir, CBasePin* pPin) { - CheckPointer(pPin, E_POINTER); + CheckPointer(pPin, E_POINTER); - if(dir == PINDIR_INPUT) - { - CBaseSplitterInputPin* pIn = static_cast(pPin); + if(dir == PINDIR_INPUT) + { + CBaseSplitterInputPin* pIn = static_cast(pPin); - HRESULT hr; + HRESULT hr; - CComPtr pAsyncReader; - if(FAILED(hr = pIn->GetAsyncReader(&pAsyncReader)) - || FAILED(hr = DeleteOutputs()) - || FAILED(hr = CreateOutputs(pAsyncReader))) - return hr; + CComPtr pAsyncReader; + if(FAILED(hr = pIn->GetAsyncReader(&pAsyncReader)) + || FAILED(hr = DeleteOutputs()) + || FAILED(hr = CreateOutputs(pAsyncReader))) + return hr; - ChapSort(); + ChapSort(); - m_pSyncReader = pAsyncReader; - } - else if(dir == PINDIR_OUTPUT) - { - m_pRetiredOutputs.RemoveAll(); - } - else - { - return E_UNEXPECTED; - } + m_pSyncReader = pAsyncReader; + } + else if(dir == PINDIR_OUTPUT) + { + m_pRetiredOutputs.RemoveAll(); + } + else + { + return E_UNEXPECTED; + } - return S_OK; + return S_OK; } int CBaseSplitterFilter::GetPinCount() { - return (m_pInput ? 1 : 0) + m_pOutputs.GetCount(); + return (m_pInput ? 1 : 0) + m_pOutputs.GetCount(); } CBasePin* CBaseSplitterFilter::GetPin(int n) { CAutoLock cAutoLock(this); - if(n >= 0 && n < (int)m_pOutputs.GetCount()) - { - if(POSITION pos = m_pOutputs.FindIndex(n)) - return m_pOutputs.GetAt(pos); - } + if(n >= 0 && n < (int)m_pOutputs.GetCount()) + { + if(POSITION pos = m_pOutputs.FindIndex(n)) + return m_pOutputs.GetAt(pos); + } - if(n == m_pOutputs.GetCount() && m_pInput) - { - return m_pInput; - } + if(n == m_pOutputs.GetCount() && m_pInput) + { + return m_pInput; + } - return NULL; + return NULL; } STDMETHODIMP CBaseSplitterFilter::Stop() { - CAutoLock cAutoLock(this); + CAutoLock cAutoLock(this); - DeliverBeginFlush(); - CallWorker(CMD_EXIT); - DeliverEndFlush(); + DeliverBeginFlush(); + CallWorker(CMD_EXIT); + DeliverEndFlush(); - HRESULT hr; - if(FAILED(hr = __super::Stop())) - return hr; + HRESULT hr; + if(FAILED(hr = __super::Stop())) + return hr; - return S_OK; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::Pause() { - CAutoLock cAutoLock(this); + CAutoLock cAutoLock(this); - FILTER_STATE fs = m_State; + FILTER_STATE fs = m_State; - HRESULT hr; - if(FAILED(hr = __super::Pause())) - return hr; + HRESULT hr; + if(FAILED(hr = __super::Pause())) + return hr; - if(fs == State_Stopped) - { - Create(); - } + if(fs == State_Stopped) + { + Create(); + } - return S_OK; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::Run(REFERENCE_TIME tStart) { - CAutoLock cAutoLock(this); + CAutoLock cAutoLock(this); - HRESULT hr; - if(FAILED(hr = __super::Run(tStart))) - return hr; + HRESULT hr; + if(FAILED(hr = __super::Run(tStart))) + return hr; - return S_OK; + return S_OK; } // IFileSourceFilter STDMETHODIMP CBaseSplitterFilter::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt) { - CheckPointer(pszFileName, E_POINTER); + CheckPointer(pszFileName, E_POINTER); - m_fn = pszFileName; - HRESULT hr = E_FAIL; - CComPtr pAsyncReader; - CAtlList Items; - if(BuildPlaylist(pszFileName, Items)) - pAsyncReader = (IAsyncReader*)DNew CAsyncFileReader(Items, hr); - else - pAsyncReader = (IAsyncReader*)DNew CAsyncFileReader(CString(pszFileName), hr); - if(FAILED(hr) - || FAILED(hr = DeleteOutputs()) - || FAILED(hr = CreateOutputs(pAsyncReader))) - { - m_fn = ""; - return hr; - } + m_fn = pszFileName; + HRESULT hr = E_FAIL; + CComPtr pAsyncReader; + CAtlList Items; + if (BuildPlaylist (pszFileName, Items)) + pAsyncReader = (IAsyncReader*)DNew CAsyncFileReader(Items, hr); + else + pAsyncReader = (IAsyncReader*)DNew CAsyncFileReader(CString(pszFileName), hr); + if(FAILED(hr) + || FAILED(hr = DeleteOutputs()) + || FAILED(hr = CreateOutputs(pAsyncReader))) + { + m_fn = ""; + return hr; + } - ChapSort(); + ChapSort(); - m_pSyncReader = pAsyncReader; + m_pSyncReader = pAsyncReader; - return S_OK; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt) { - CheckPointer(ppszFileName, E_POINTER); - if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength() + 1) * sizeof(WCHAR)))) - return E_OUTOFMEMORY; - wcscpy(*ppszFileName, m_fn); - return S_OK; + CheckPointer(ppszFileName, E_POINTER); + if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR)))) + return E_OUTOFMEMORY; + wcscpy(*ppszFileName, m_fn); + return S_OK; } LPCTSTR CBaseSplitterFilter::GetPartFilename(IAsyncReader* pAsyncReader) { - CComQIPtr pFH = pAsyncReader; - return pFH ? pFH->GetFileName() : m_fn; + CComQIPtr pFH = pAsyncReader; + return pFH ? pFH->GetFileName() : m_fn; } // IMediaSeeking STDMETHODIMP CBaseSplitterFilter::GetCapabilities(DWORD* pCapabilities) { - return pCapabilities ? *pCapabilities = - AM_SEEKING_CanGetStopPos | - AM_SEEKING_CanGetDuration | - AM_SEEKING_CanSeekAbsolute | - AM_SEEKING_CanSeekForwards | - AM_SEEKING_CanSeekBackwards, S_OK : E_POINTER; + return pCapabilities ? *pCapabilities = + AM_SEEKING_CanGetStopPos| + AM_SEEKING_CanGetDuration| + AM_SEEKING_CanSeekAbsolute| + AM_SEEKING_CanSeekForwards| + AM_SEEKING_CanSeekBackwards, S_OK : E_POINTER; } STDMETHODIMP CBaseSplitterFilter::CheckCapabilities(DWORD* pCapabilities) { - CheckPointer(pCapabilities, E_POINTER); - if(*pCapabilities == 0) return S_OK; - DWORD caps; - GetCapabilities(&caps); - if((caps&*pCapabilities) == 0) return E_FAIL; - if(caps == *pCapabilities) return S_OK; - return S_FALSE; -} -STDMETHODIMP CBaseSplitterFilter::IsFormatSupported(const GUID* pFormat) -{ - return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE; -} -STDMETHODIMP CBaseSplitterFilter::QueryPreferredFormat(GUID* pFormat) -{ - return GetTimeFormat(pFormat); -} -STDMETHODIMP CBaseSplitterFilter::GetTimeFormat(GUID* pFormat) -{ - return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER; -} -STDMETHODIMP CBaseSplitterFilter::IsUsingTimeFormat(const GUID* pFormat) -{ - return IsFormatSupported(pFormat); -} -STDMETHODIMP CBaseSplitterFilter::SetTimeFormat(const GUID* pFormat) -{ - return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG; -} -STDMETHODIMP CBaseSplitterFilter::GetDuration(LONGLONG* pDuration) -{ - CheckPointer(pDuration, E_POINTER); - *pDuration = m_rtDuration; - return S_OK; -} -STDMETHODIMP CBaseSplitterFilter::GetStopPosition(LONGLONG* pStop) -{ - return GetDuration(pStop); -} -STDMETHODIMP CBaseSplitterFilter::GetCurrentPosition(LONGLONG* pCurrent) -{ - return E_NOTIMPL; -} -STDMETHODIMP CBaseSplitterFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) -{ - return E_NOTIMPL; -} + CheckPointer(pCapabilities, E_POINTER); + if(*pCapabilities == 0) return S_OK; + DWORD caps; + GetCapabilities(&caps); + if((caps&*pCapabilities) == 0) return E_FAIL; + if(caps == *pCapabilities) return S_OK; + return S_FALSE; +} +STDMETHODIMP CBaseSplitterFilter::IsFormatSupported(const GUID* pFormat) {return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;} +STDMETHODIMP CBaseSplitterFilter::QueryPreferredFormat(GUID* pFormat) {return GetTimeFormat(pFormat);} +STDMETHODIMP CBaseSplitterFilter::GetTimeFormat(GUID* pFormat) {return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;} +STDMETHODIMP CBaseSplitterFilter::IsUsingTimeFormat(const GUID* pFormat) {return IsFormatSupported(pFormat);} +STDMETHODIMP CBaseSplitterFilter::SetTimeFormat(const GUID* pFormat) {return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;} +STDMETHODIMP CBaseSplitterFilter::GetDuration(LONGLONG* pDuration) {CheckPointer(pDuration, E_POINTER); *pDuration = m_rtDuration; return S_OK;} +STDMETHODIMP CBaseSplitterFilter::GetStopPosition(LONGLONG* pStop) {return GetDuration(pStop);} +STDMETHODIMP CBaseSplitterFilter::GetCurrentPosition(LONGLONG* pCurrent) {return E_NOTIMPL;} +STDMETHODIMP CBaseSplitterFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {return E_NOTIMPL;} STDMETHODIMP CBaseSplitterFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) { - return SetPositionsInternal(this, pCurrent, dwCurrentFlags, pStop, dwStopFlags); + return SetPositionsInternal(this, pCurrent, dwCurrentFlags, pStop, dwStopFlags); } STDMETHODIMP CBaseSplitterFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) { - if(pCurrent) *pCurrent = m_rtCurrent; - if(pStop) *pStop = m_rtStop; - return S_OK; + if(pCurrent) *pCurrent = m_rtCurrent; + if(pStop) *pStop = m_rtStop; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) { - if(pEarliest) *pEarliest = 0; - return GetDuration(pLatest); -} -STDMETHODIMP CBaseSplitterFilter::SetRate(double dRate) -{ - return dRate > 0 ? m_dRate = dRate, S_OK : E_INVALIDARG; -} -STDMETHODIMP CBaseSplitterFilter::GetRate(double* pdRate) -{ - return pdRate ? *pdRate = m_dRate, S_OK : E_POINTER; -} -STDMETHODIMP CBaseSplitterFilter::GetPreroll(LONGLONG* pllPreroll) -{ - return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER; + if(pEarliest) *pEarliest = 0; + return GetDuration(pLatest); } +STDMETHODIMP CBaseSplitterFilter::SetRate(double dRate) {return dRate > 0 ? m_dRate = dRate, S_OK : E_INVALIDARG;} +STDMETHODIMP CBaseSplitterFilter::GetRate(double* pdRate) {return pdRate ? *pdRate = m_dRate, S_OK : E_POINTER;} +STDMETHODIMP CBaseSplitterFilter::GetPreroll(LONGLONG* pllPreroll) {return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER;} HRESULT CBaseSplitterFilter::SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) { - CAutoLock cAutoLock(this); + CAutoLock cAutoLock(this); + + if(!pCurrent && !pStop + || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning + && (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning) + return S_OK; + + REFERENCE_TIME + rtCurrent = m_rtCurrent, + rtStop = m_rtStop; + + if(pCurrent) + switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask) + { + case AM_SEEKING_NoPositioning: break; + case AM_SEEKING_AbsolutePositioning: rtCurrent = *pCurrent; break; + case AM_SEEKING_RelativePositioning: rtCurrent = rtCurrent + *pCurrent; break; + case AM_SEEKING_IncrementalPositioning: rtCurrent = rtCurrent + *pCurrent; break; + } + + if(pStop) + switch(dwStopFlags&AM_SEEKING_PositioningBitsMask) + { + case AM_SEEKING_NoPositioning: break; + case AM_SEEKING_AbsolutePositioning: rtStop = *pStop; break; + case AM_SEEKING_RelativePositioning: rtStop += *pStop; break; + case AM_SEEKING_IncrementalPositioning: rtStop = rtCurrent + *pStop; break; + } + + if(m_rtCurrent == rtCurrent && m_rtStop == rtStop) + return S_OK; - if(!pCurrent && !pStop - || (dwCurrentFlags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning - && (dwStopFlags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning) - return S_OK; - - REFERENCE_TIME - rtCurrent = m_rtCurrent, - rtStop = m_rtStop; - - if(pCurrent) - switch(dwCurrentFlags & AM_SEEKING_PositioningBitsMask) - { - case AM_SEEKING_NoPositioning: - break; - case AM_SEEKING_AbsolutePositioning: - rtCurrent = *pCurrent; - break; - case AM_SEEKING_RelativePositioning: - rtCurrent = rtCurrent + *pCurrent; - break; - case AM_SEEKING_IncrementalPositioning: - rtCurrent = rtCurrent + *pCurrent; - break; - } - - if(pStop) - switch(dwStopFlags & AM_SEEKING_PositioningBitsMask) - { - case AM_SEEKING_NoPositioning: - break; - case AM_SEEKING_AbsolutePositioning: - rtStop = *pStop; - break; - case AM_SEEKING_RelativePositioning: - rtStop += *pStop; - break; - case AM_SEEKING_IncrementalPositioning: - rtStop = rtCurrent + *pStop; - break; - } - - if(m_rtCurrent == rtCurrent && m_rtStop == rtStop) - return S_OK; - - if(m_rtLastStart == rtCurrent && m_rtLastStop == rtStop && !m_LastSeekers.Find(id)) - { - m_LastSeekers.AddTail(id); - return S_OK; - } - - m_rtLastStart = rtCurrent; - m_rtLastStop = rtStop; - m_LastSeekers.RemoveAll(); - m_LastSeekers.AddTail(id); - - DbgLog((LOG_TRACE, 0, _T("Seek Started %I64d"), rtCurrent)); - - m_rtNewStart = m_rtCurrent = rtCurrent; - m_rtNewStop = rtStop; - - if(ThreadExists()) - { - DeliverBeginFlush(); - CallWorker(CMD_SEEK); - DeliverEndFlush(); - } - - DbgLog((LOG_TRACE, 0, _T("Seek Ended"))); - - return S_OK; + if(m_rtLastStart == rtCurrent && m_rtLastStop == rtStop && !m_LastSeekers.Find(id)) + { + m_LastSeekers.AddTail(id); + return S_OK; + } + + m_rtLastStart = rtCurrent; + m_rtLastStop = rtStop; + m_LastSeekers.RemoveAll(); + m_LastSeekers.AddTail(id); + +DbgLog((LOG_TRACE, 0, _T("Seek Started %I64d"), rtCurrent)); + + m_rtNewStart = m_rtCurrent = rtCurrent; + m_rtNewStop = rtStop; + + if(ThreadExists()) + { + DeliverBeginFlush(); + CallWorker(CMD_SEEK); + DeliverEndFlush(); + } + +DbgLog((LOG_TRACE, 0, _T("Seek Ended"))); + + return S_OK; } // IAMOpenProgress STDMETHODIMP CBaseSplitterFilter::QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent) { - CheckPointer(pllTotal, E_POINTER); - CheckPointer(pllCurrent, E_POINTER); + CheckPointer(pllTotal, E_POINTER); + CheckPointer(pllCurrent, E_POINTER); - *pllTotal = 100; - *pllCurrent = m_nOpenProgress; + *pllTotal = 100; + *pllCurrent = m_nOpenProgress; - return S_OK; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::AbortOperation() { - m_fAbort = true; - return S_OK; + m_fAbort = true; + return S_OK; } // IAMMediaContent STDMETHODIMP CBaseSplitterFilter::get_AuthorName(BSTR* pbstrAuthorName) { - return GetProperty(L"AUTH", pbstrAuthorName); + return GetProperty(L"AUTH", pbstrAuthorName); } STDMETHODIMP CBaseSplitterFilter::get_Title(BSTR* pbstrTitle) { - return GetProperty(L"TITL", pbstrTitle); + return GetProperty(L"TITL", pbstrTitle); } STDMETHODIMP CBaseSplitterFilter::get_Rating(BSTR* pbstrRating) { - return GetProperty(L"RTNG", pbstrRating); + return GetProperty(L"RTNG", pbstrRating); } STDMETHODIMP CBaseSplitterFilter::get_Description(BSTR* pbstrDescription) { - return GetProperty(L"DESC", pbstrDescription); + return GetProperty(L"DESC", pbstrDescription); } STDMETHODIMP CBaseSplitterFilter::get_Copyright(BSTR* pbstrCopyright) { - return GetProperty(L"CPYR", pbstrCopyright); + return GetProperty(L"CPYR", pbstrCopyright); } // IAMExtendedSeeking STDMETHODIMP CBaseSplitterFilter::get_ExSeekCapabilities(long* pExCapabilities) { - CheckPointer(pExCapabilities, E_POINTER); - *pExCapabilities = AM_EXSEEK_CANSEEK; - if(ChapGetCount()) *pExCapabilities |= AM_EXSEEK_MARKERSEEK; - return S_OK; + CheckPointer(pExCapabilities, E_POINTER); + *pExCapabilities = AM_EXSEEK_CANSEEK; + if(ChapGetCount()) *pExCapabilities |= AM_EXSEEK_MARKERSEEK; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::get_MarkerCount(long* pMarkerCount) { - CheckPointer(pMarkerCount, E_POINTER); - *pMarkerCount = (long)ChapGetCount(); - return S_OK; + CheckPointer(pMarkerCount, E_POINTER); + *pMarkerCount = (long)ChapGetCount(); + return S_OK; } STDMETHODIMP CBaseSplitterFilter::get_CurrentMarker(long* pCurrentMarker) { - CheckPointer(pCurrentMarker, E_POINTER); - REFERENCE_TIME rt = m_rtCurrent; - long i = ChapLookup(&rt); - if(i < 0) return E_FAIL; - *pCurrentMarker = i + 1; - return S_OK; + CheckPointer(pCurrentMarker, E_POINTER); + REFERENCE_TIME rt = m_rtCurrent; + long i = ChapLookup(&rt); + if(i < 0) return E_FAIL; + *pCurrentMarker = i+1; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::GetMarkerTime(long MarkerNum, double* pMarkerTime) { - CheckPointer(pMarkerTime, E_POINTER); - REFERENCE_TIME rt; - if(FAILED(ChapGet((int)MarkerNum - 1, &rt))) return E_FAIL; - *pMarkerTime = (double)rt / 10000000; - return S_OK; + CheckPointer(pMarkerTime, E_POINTER); + REFERENCE_TIME rt; + if(FAILED(ChapGet((int)MarkerNum-1, &rt))) return E_FAIL; + *pMarkerTime = (double)rt / 10000000; + return S_OK; } STDMETHODIMP CBaseSplitterFilter::GetMarkerName(long MarkerNum, BSTR* pbstrMarkerName) { - return ChapGet((int)MarkerNum - 1, NULL, pbstrMarkerName); + return ChapGet((int)MarkerNum-1, NULL, pbstrMarkerName); } // IKeyFrameInfo STDMETHODIMP CBaseSplitterFilter::GetKeyFrameCount(UINT& nKFs) { - return E_NOTIMPL; + return E_NOTIMPL; } STDMETHODIMP CBaseSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs) { - return E_NOTIMPL; + return E_NOTIMPL; } // IBufferInfo STDMETHODIMP_(int) CBaseSplitterFilter::GetCount() { - CAutoLock cAutoLock(m_pLock); + CAutoLock cAutoLock(m_pLock); - return m_pOutputs.GetCount(); + return m_pOutputs.GetCount(); } STDMETHODIMP CBaseSplitterFilter::GetStatus(int i, int& samples, int& size) { - CAutoLock cAutoLock(m_pLock); + CAutoLock cAutoLock(m_pLock); - if(POSITION pos = m_pOutputs.FindIndex(i)) - { - CBaseSplitterOutputPin* pPin = m_pOutputs.GetAt(pos); - samples = pPin->QueueCount(); - size = pPin->QueueSize(); - return pPin->IsConnected() ? S_OK : S_FALSE; - } + if(POSITION pos = m_pOutputs.FindIndex(i)) + { + CBaseSplitterOutputPin* pPin = m_pOutputs.GetAt(pos); + samples = pPin->QueueCount(); + size = pPin->QueueSize(); + return pPin->IsConnected() ? S_OK : S_FALSE; + } - return E_INVALIDARG; + return E_INVALIDARG; } STDMETHODIMP_(DWORD) CBaseSplitterFilter::GetPriority() diff --git a/src/filters/parser/BaseSplitter/BaseSplitter.h b/src/filters/parser/BaseSplitter/BaseSplitter.h index e8bb0d5f5..68114f7e7 100644 --- a/src/filters/parser/BaseSplitter/BaseSplitter.h +++ b/src/filters/parser/BaseSplitter/BaseSplitter.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -35,416 +35,341 @@ class Packet : public CAtlArray { public: - DWORD TrackNumber; - BOOL bDiscontinuity, bSyncPoint, bAppendable; - static const REFERENCE_TIME INVALID_TIME = _I64_MIN; - REFERENCE_TIME rtStart, rtStop; - AM_MEDIA_TYPE* pmt; - Packet() - { - pmt = NULL; - bDiscontinuity = bAppendable = FALSE; - } - virtual ~Packet() - { - if(pmt) DeleteMediaType(pmt); - } - virtual int GetDataSize() - { - return GetCount(); - } - void SetData(const void* ptr, DWORD len) - { - SetCount(len); - memcpy(GetData(), ptr, len); - } + DWORD TrackNumber; + BOOL bDiscontinuity, bSyncPoint, bAppendable; + static const REFERENCE_TIME INVALID_TIME = _I64_MIN; + REFERENCE_TIME rtStart, rtStop; + AM_MEDIA_TYPE* pmt; + Packet() {pmt = NULL; bDiscontinuity = bAppendable = FALSE;} + virtual ~Packet() {if(pmt) DeleteMediaType(pmt);} + virtual int GetDataSize() {return GetCount();} + void SetData(const void* ptr, DWORD len) {SetCount(len); memcpy(GetData(), ptr, len);} }; -class CPacketQueue - : public CCritSec - , protected CAutoPtrList +class CPacketQueue + : public CCritSec + , protected CAutoPtrList { - int m_size; + int m_size; public: - CPacketQueue(); - void Add(CAutoPtr p); - CAutoPtr Remove(); - void RemoveAll(); - int GetCount(), GetSize(); + CPacketQueue(); + void Add(CAutoPtr p); + CAutoPtr Remove(); + void RemoveAll(); + int GetCount(), GetSize(); }; class CBaseSplitterFilter; -class CBaseSplitterInputPin - : public CBasePin +class CBaseSplitterInputPin + : public CBasePin { protected: - CComQIPtr m_pAsyncReader; + CComQIPtr m_pAsyncReader; public: - CBaseSplitterInputPin(TCHAR* pName, CBaseSplitterFilter* pFilter, CCritSec* pLock, HRESULT* phr); - virtual ~CBaseSplitterInputPin(); + CBaseSplitterInputPin(TCHAR* pName, CBaseSplitterFilter* pFilter, CCritSec* pLock, HRESULT* phr); + virtual ~CBaseSplitterInputPin(); - HRESULT GetAsyncReader(IAsyncReader** ppAsyncReader); + HRESULT GetAsyncReader(IAsyncReader** ppAsyncReader); - DECLARE_IUNKNOWN; + DECLARE_IUNKNOWN; STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); HRESULT CheckMediaType(const CMediaType* pmt); HRESULT CheckConnect(IPin* pPin); HRESULT BreakConnect(); - HRESULT CompleteConnect(IPin* pPin); + HRESULT CompleteConnect(IPin* pPin); - STDMETHODIMP BeginFlush(); - STDMETHODIMP EndFlush(); + STDMETHODIMP BeginFlush(); + STDMETHODIMP EndFlush(); }; -class CBaseSplitterOutputPin - : public CBaseOutputPin - , public IDSMPropertyBagImpl - , protected CAMThread - , public IMediaSeeking - , public IBitRateInfo +class CBaseSplitterOutputPin + : public CBaseOutputPin + , public IDSMPropertyBagImpl + , protected CAMThread + , public IMediaSeeking + , public IBitRateInfo { protected: - CAtlArray m_mts; - int m_nBuffers; + CAtlArray m_mts; + int m_nBuffers; private: - CPacketQueue m_queue; + CPacketQueue m_queue; - HRESULT m_hrDeliver; + HRESULT m_hrDeliver; - bool m_fFlushing, m_fFlushed; - CAMEvent m_eEndFlush; + bool m_fFlushing, m_fFlushed; + CAMEvent m_eEndFlush; - enum {CMD_EXIT}; + enum {CMD_EXIT}; DWORD ThreadProc(); - void MakeISCRHappy(); + void MakeISCRHappy(); - // please only use DeliverPacket from the derived class + // please only use DeliverPacket from the derived class HRESULT GetDeliveryBuffer(IMediaSample** ppSample, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags); HRESULT Deliver(IMediaSample* pSample); - // bitrate stats + // bitrate stats - struct - { - UINT64 nTotalBytesDelivered; - REFERENCE_TIME rtTotalTimeDelivered; - UINT64 nBytesSinceLastDeliverTime; - REFERENCE_TIME rtLastDeliverTime; - DWORD nCurrentBitRate; - DWORD nAverageBitRate; - } m_brs; + struct + { + UINT64 nTotalBytesDelivered; + REFERENCE_TIME rtTotalTimeDelivered; + UINT64 nBytesSinceLastDeliverTime; + REFERENCE_TIME rtLastDeliverTime; + DWORD nCurrentBitRate; + DWORD nAverageBitRate; + } m_brs; protected: - REFERENCE_TIME m_rtStart; - - // override this if you need some second level stream specific demuxing (optional) - // the default implementation will send the sample as is - virtual HRESULT DeliverPacket(CAutoPtr p); - - // IMediaSeeking - - STDMETHODIMP GetCapabilities(DWORD* pCapabilities); - STDMETHODIMP CheckCapabilities(DWORD* pCapabilities); - STDMETHODIMP IsFormatSupported(const GUID* pFormat); - STDMETHODIMP QueryPreferredFormat(GUID* pFormat); - STDMETHODIMP GetTimeFormat(GUID* pFormat); - STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat); - STDMETHODIMP SetTimeFormat(const GUID* pFormat); - STDMETHODIMP GetDuration(LONGLONG* pDuration); - STDMETHODIMP GetStopPosition(LONGLONG* pStop); - STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent); - STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat); - STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); - STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop); - STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest); - STDMETHODIMP SetRate(double dRate); - STDMETHODIMP GetRate(double* pdRate); - STDMETHODIMP GetPreroll(LONGLONG* pllPreroll); + REFERENCE_TIME m_rtStart; + + // override this if you need some second level stream specific demuxing (optional) + // the default implementation will send the sample as is + virtual HRESULT DeliverPacket(CAutoPtr p); + + // IMediaSeeking + + STDMETHODIMP GetCapabilities(DWORD* pCapabilities); + STDMETHODIMP CheckCapabilities(DWORD* pCapabilities); + STDMETHODIMP IsFormatSupported(const GUID* pFormat); + STDMETHODIMP QueryPreferredFormat(GUID* pFormat); + STDMETHODIMP GetTimeFormat(GUID* pFormat); + STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat); + STDMETHODIMP SetTimeFormat(const GUID* pFormat); + STDMETHODIMP GetDuration(LONGLONG* pDuration); + STDMETHODIMP GetStopPosition(LONGLONG* pStop); + STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent); + STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat); + STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); + STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop); + STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest); + STDMETHODIMP SetRate(double dRate); + STDMETHODIMP GetRate(double* pdRate); + STDMETHODIMP GetPreroll(LONGLONG* pllPreroll); public: - CBaseSplitterOutputPin(CAtlArray& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr, int nBuffers = 0); - CBaseSplitterOutputPin(LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr, int nBuffers = 0); - virtual ~CBaseSplitterOutputPin(); + CBaseSplitterOutputPin(CAtlArray& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr, int nBuffers = 0); + CBaseSplitterOutputPin(LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr, int nBuffers = 0); + virtual ~CBaseSplitterOutputPin(); - DECLARE_IUNKNOWN; + DECLARE_IUNKNOWN; STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - HRESULT SetName(LPCWSTR pName); + HRESULT SetName(LPCWSTR pName); HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties); HRESULT CheckMediaType(const CMediaType* pmt); HRESULT GetMediaType(int iPosition, CMediaType* pmt); - CMediaType& CurrentMediaType() - { - return m_mt; - } - - STDMETHODIMP Notify(IBaseFilter* pSender, Quality q); - - // Queueing - - HANDLE GetThreadHandle() - { - ASSERT(m_hThread != NULL); - return m_hThread; - } - void SetThreadPriority(int nPriority) - { - if(m_hThread) ::SetThreadPriority(m_hThread, nPriority); - } - - HRESULT Active(); + CMediaType& CurrentMediaType() {return m_mt;} + + STDMETHODIMP Notify(IBaseFilter* pSender, Quality q); + + // Queueing + + HANDLE GetThreadHandle() {ASSERT(m_hThread != NULL); return m_hThread;} + void SetThreadPriority(int nPriority) {if(m_hThread) ::SetThreadPriority(m_hThread, nPriority);} + + HRESULT Active(); HRESULT Inactive(); HRESULT DeliverBeginFlush(); - HRESULT DeliverEndFlush(); + HRESULT DeliverEndFlush(); HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate); - int QueueCount(); - int QueueSize(); + int QueueCount(); + int QueueSize(); HRESULT QueueEndOfStream(); - HRESULT QueuePacket(CAutoPtr p); + HRESULT QueuePacket(CAutoPtr p); - // returns true for everything which (the lack of) would not block other streams (subtitle streams, basically) - virtual bool IsDiscontinuous(); + // returns true for everything which (the lack of) would not block other streams (subtitle streams, basically) + virtual bool IsDiscontinuous(); - // returns IStreamsSwitcherInputPin::IsActive(), when it can find one downstream - bool IsActive(); + // returns IStreamsSwitcherInputPin::IsActive(), when it can find one downstream + bool IsActive(); - // IBitRateInfo + // IBitRateInfo - STDMETHODIMP_(DWORD) GetCurrentBitRate() - { - return m_brs.nCurrentBitRate; - } - STDMETHODIMP_(DWORD) GetAverageBitRate() - { - return m_brs.nAverageBitRate; - } + STDMETHODIMP_(DWORD) GetCurrentBitRate() {return m_brs.nCurrentBitRate;} + STDMETHODIMP_(DWORD) GetAverageBitRate() {return m_brs.nAverageBitRate;} }; -class CBaseSplitterFilter - : public CBaseFilter - , public CCritSec - , public IDSMPropertyBagImpl - , public IDSMResourceBagImpl - , public IDSMChapterBagImpl - , protected CAMThread - , public IFileSourceFilter - , public IMediaSeeking - , public IAMOpenProgress - , public IAMMediaContent - , public IAMExtendedSeeking - , public IKeyFrameInfo - , public IBufferInfo +class CBaseSplitterFilter + : public CBaseFilter + , public CCritSec + , public IDSMPropertyBagImpl + , public IDSMResourceBagImpl + , public IDSMChapterBagImpl + , protected CAMThread + , public IFileSourceFilter + , public IMediaSeeking + , public IAMOpenProgress + , public IAMMediaContent + , public IAMExtendedSeeking + , public IKeyFrameInfo + , public IBufferInfo { - CCritSec m_csPinMap; - CAtlMap m_pPinMap; + CCritSec m_csPinMap; + CAtlMap m_pPinMap; - CCritSec m_csmtnew; - CAtlMap m_mtnew; + CCritSec m_csmtnew; + CAtlMap m_mtnew; - CAutoPtrList m_pRetiredOutputs; + CAutoPtrList m_pRetiredOutputs; - CComQIPtr m_pSyncReader; + CComQIPtr m_pSyncReader; protected: - CStringW m_fn; + CStringW m_fn; - CAutoPtr m_pInput; - CAutoPtrList m_pOutputs; + CAutoPtr m_pInput; + CAutoPtrList m_pOutputs; - CBaseSplitterOutputPin* GetOutputPin(DWORD TrackNum); - DWORD GetOutputTrackNum(CBaseSplitterOutputPin* pPin); - HRESULT AddOutputPin(DWORD TrackNum, CAutoPtr pPin); - HRESULT RenameOutputPin(DWORD TrackNumSrc, DWORD TrackNumDst, const AM_MEDIA_TYPE* pmt); - virtual HRESULT DeleteOutputs(); - virtual HRESULT CreateOutputs(IAsyncReader* pAsyncReader) = 0; // override this ... - virtual LPCTSTR GetPartFilename(IAsyncReader* pAsyncReader); + CBaseSplitterOutputPin* GetOutputPin(DWORD TrackNum); + DWORD GetOutputTrackNum(CBaseSplitterOutputPin* pPin); + HRESULT AddOutputPin(DWORD TrackNum, CAutoPtr pPin); + HRESULT RenameOutputPin(DWORD TrackNumSrc, DWORD TrackNumDst, const AM_MEDIA_TYPE* pmt); + virtual HRESULT DeleteOutputs(); + virtual HRESULT CreateOutputs(IAsyncReader* pAsyncReader) = 0; // override this ... + virtual LPCTSTR GetPartFilename(IAsyncReader* pAsyncReader); - LONGLONG m_nOpenProgress; - bool m_fAbort; + LONGLONG m_nOpenProgress; + bool m_fAbort; - REFERENCE_TIME m_rtDuration; // derived filter should set this at the end of CreateOutputs - REFERENCE_TIME m_rtStart, m_rtStop, m_rtCurrent, m_rtNewStart, m_rtNewStop; - double m_dRate; + REFERENCE_TIME m_rtDuration; // derived filter should set this at the end of CreateOutputs + REFERENCE_TIME m_rtStart, m_rtStop, m_rtCurrent, m_rtNewStart, m_rtNewStop; + double m_dRate; - CAtlList m_bDiscontinuitySent; - CAtlList m_pActivePins; + CAtlList m_bDiscontinuitySent; + CAtlList m_pActivePins; - CAMEvent m_eEndFlush; - bool m_fFlushing; + CAMEvent m_eEndFlush; + bool m_fFlushing; - void DeliverBeginFlush(); - void DeliverEndFlush(); - HRESULT DeliverPacket(CAutoPtr p); + void DeliverBeginFlush(); + void DeliverEndFlush(); + HRESULT DeliverPacket(CAutoPtr p); - DWORD m_priority; + DWORD m_priority; - CFontInstaller m_fontinst; + CFontInstaller m_fontinst; protected: - enum {CMD_EXIT, CMD_SEEK}; + enum {CMD_EXIT, CMD_SEEK}; DWORD ThreadProc(); - // ... and also override all these too - virtual bool DemuxInit() = 0; - virtual void DemuxSeek(REFERENCE_TIME rt) = 0; - virtual bool DemuxLoop() = 0; - virtual bool BuildPlaylist(LPCTSTR pszFileName, CAtlList& Items) - { - return false; - }; + // ... and also override all these too + virtual bool DemuxInit() = 0; + virtual void DemuxSeek(REFERENCE_TIME rt) = 0; + virtual bool DemuxLoop() = 0; + virtual bool BuildPlaylist(LPCTSTR pszFileName, CAtlList& Items) { return false; }; public: - CBaseSplitterFilter(LPCTSTR pName, LPUNKNOWN pUnk, HRESULT* phr, const CLSID& clsid); - virtual ~CBaseSplitterFilter(); + CBaseSplitterFilter(LPCTSTR pName, LPUNKNOWN pUnk, HRESULT* phr, const CLSID& clsid); + virtual ~CBaseSplitterFilter(); - DECLARE_IUNKNOWN; + DECLARE_IUNKNOWN; STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); - bool IsAnyPinDrying(); + bool IsAnyPinDrying(); - HRESULT BreakConnect(PIN_DIRECTION dir, CBasePin* pPin); - HRESULT CompleteConnect(PIN_DIRECTION dir, CBasePin* pPin); + HRESULT BreakConnect(PIN_DIRECTION dir, CBasePin* pPin); + HRESULT CompleteConnect(PIN_DIRECTION dir, CBasePin* pPin); - int GetPinCount(); - CBasePin* GetPin(int n); + int GetPinCount(); + CBasePin* GetPin(int n); - STDMETHODIMP Stop(); - STDMETHODIMP Pause(); - STDMETHODIMP Run(REFERENCE_TIME tStart); + STDMETHODIMP Stop(); + STDMETHODIMP Pause(); + STDMETHODIMP Run(REFERENCE_TIME tStart); - // IFileSourceFilter + // IFileSourceFilter - STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt); - STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt); + STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt); + STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt); - // IMediaSeeking + // IMediaSeeking - STDMETHODIMP GetCapabilities(DWORD* pCapabilities); - STDMETHODIMP CheckCapabilities(DWORD* pCapabilities); - STDMETHODIMP IsFormatSupported(const GUID* pFormat); - STDMETHODIMP QueryPreferredFormat(GUID* pFormat); - STDMETHODIMP GetTimeFormat(GUID* pFormat); - STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat); - STDMETHODIMP SetTimeFormat(const GUID* pFormat); - STDMETHODIMP GetDuration(LONGLONG* pDuration); - STDMETHODIMP GetStopPosition(LONGLONG* pStop); - STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent); - STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat); - STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); - STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop); - STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest); - STDMETHODIMP SetRate(double dRate); - STDMETHODIMP GetRate(double* pdRate); - STDMETHODIMP GetPreroll(LONGLONG* pllPreroll); + STDMETHODIMP GetCapabilities(DWORD* pCapabilities); + STDMETHODIMP CheckCapabilities(DWORD* pCapabilities); + STDMETHODIMP IsFormatSupported(const GUID* pFormat); + STDMETHODIMP QueryPreferredFormat(GUID* pFormat); + STDMETHODIMP GetTimeFormat(GUID* pFormat); + STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat); + STDMETHODIMP SetTimeFormat(const GUID* pFormat); + STDMETHODIMP GetDuration(LONGLONG* pDuration); + STDMETHODIMP GetStopPosition(LONGLONG* pStop); + STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent); + STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat); + STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); + STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop); + STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest); + STDMETHODIMP SetRate(double dRate); + STDMETHODIMP GetRate(double* pdRate); + STDMETHODIMP GetPreroll(LONGLONG* pllPreroll); protected: - friend class CBaseSplitterOutputPin; - virtual HRESULT SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); + friend class CBaseSplitterOutputPin; + virtual HRESULT SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags); private: - REFERENCE_TIME m_rtLastStart, m_rtLastStop; - CAtlList m_LastSeekers; + REFERENCE_TIME m_rtLastStart, m_rtLastStop; + CAtlList m_LastSeekers; public: - // IAMOpenProgress - - STDMETHODIMP QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent); - STDMETHODIMP AbortOperation(); - - // IDispatch - - STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) - { - return E_NOTIMPL; - } - STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) - { - return E_NOTIMPL; - } - STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) - { - return E_NOTIMPL; - } - STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) - { - return E_NOTIMPL; - } - - // IAMMediaContent - - STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName); - STDMETHODIMP get_Title(BSTR* pbstrTitle); - STDMETHODIMP get_Rating(BSTR* pbstrRating); - STDMETHODIMP get_Description(BSTR* pbstrDescription); - STDMETHODIMP get_Copyright(BSTR* pbstrCopyright); - STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) - { - return E_NOTIMPL; - } - STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) - { - return E_NOTIMPL; - } - STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) - { - return E_NOTIMPL; - } - STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) - { - return E_NOTIMPL; - } - STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) - { - return E_NOTIMPL; - } - STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) - { - return E_NOTIMPL; - } - STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) - { - return E_NOTIMPL; - } - STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) - { - return E_NOTIMPL; - } - - // IAMExtendedSeeking - - STDMETHODIMP get_ExSeekCapabilities(long* pExCapabilities); - STDMETHODIMP get_MarkerCount(long* pMarkerCount); - STDMETHODIMP get_CurrentMarker(long* pCurrentMarker); - STDMETHODIMP GetMarkerTime(long MarkerNum, double* pMarkerTime); - STDMETHODIMP GetMarkerName(long MarkerNum, BSTR* pbstrMarkerName); - STDMETHODIMP put_PlaybackSpeed(double Speed) - { - return E_NOTIMPL; - } - STDMETHODIMP get_PlaybackSpeed(double* pSpeed) - { - return E_NOTIMPL; - } - - // IKeyFrameInfo - - STDMETHODIMP_(HRESULT) GetKeyFrameCount(UINT& nKFs); - STDMETHODIMP_(HRESULT) GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs); - - // IBufferInfo - - STDMETHODIMP_(int) GetCount(); - STDMETHODIMP GetStatus(int i, int& samples, int& size); - STDMETHODIMP_(DWORD) GetPriority(); + // IAMOpenProgress + + STDMETHODIMP QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent); + STDMETHODIMP AbortOperation(); + + // IDispatch + + STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;} + STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {return E_NOTIMPL;} + STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {return E_NOTIMPL;} + STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {return E_NOTIMPL;} + + // IAMMediaContent + + STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName); + STDMETHODIMP get_Title(BSTR* pbstrTitle); + STDMETHODIMP get_Rating(BSTR* pbstrRating); + STDMETHODIMP get_Description(BSTR* pbstrDescription); + STDMETHODIMP get_Copyright(BSTR* pbstrCopyright); + STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {return E_NOTIMPL;} + STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;} + STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;} + STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {return E_NOTIMPL;} + STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {return E_NOTIMPL;} + STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {return E_NOTIMPL;} + STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {return E_NOTIMPL;} + STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {return E_NOTIMPL;} + + // IAMExtendedSeeking + + STDMETHODIMP get_ExSeekCapabilities(long* pExCapabilities); + STDMETHODIMP get_MarkerCount(long* pMarkerCount); + STDMETHODIMP get_CurrentMarker(long* pCurrentMarker); + STDMETHODIMP GetMarkerTime(long MarkerNum, double* pMarkerTime); + STDMETHODIMP GetMarkerName(long MarkerNum, BSTR* pbstrMarkerName); + STDMETHODIMP put_PlaybackSpeed(double Speed) {return E_NOTIMPL;} + STDMETHODIMP get_PlaybackSpeed(double* pSpeed) {return E_NOTIMPL;} + + // IKeyFrameInfo + + STDMETHODIMP_(HRESULT) GetKeyFrameCount(UINT& nKFs); + STDMETHODIMP_(HRESULT) GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs); + + // IBufferInfo + + STDMETHODIMP_(int) GetCount(); + STDMETHODIMP GetStatus(int i, int& samples, int& size); + STDMETHODIMP_(DWORD) GetPriority(); }; diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp b/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp index 577bafc8e..64571d736 100644 --- a/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp +++ b/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -28,228 +28,217 @@ // CBaseSplitterFile::CBaseSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr, int cachelen, bool fRandomAccess, bool fStreaming) - : m_pAsyncReader(pAsyncReader) - , m_fStreaming(false) - , m_fRandomAccess(false) - , m_pos(0), m_len(0) - , m_bitbuff(0), m_bitlen(0) - , m_cachepos(0), m_cachelen(0) + : m_pAsyncReader(pAsyncReader) + , m_fStreaming(false) + , m_fRandomAccess(false) + , m_pos(0), m_len(0) + , m_bitbuff(0), m_bitlen(0) + , m_cachepos(0), m_cachelen(0) { - if(!m_pAsyncReader) - { - hr = E_UNEXPECTED; - return; - } - - LONGLONG total = 0, available; - hr = m_pAsyncReader->Length(&total, &available); - - m_fStreaming = total == 0 && available > 0; - m_fRandomAccess = total > 0 && total == available; - m_len = total; - - if(FAILED(hr) || fRandomAccess && !m_fRandomAccess || !fStreaming && m_fStreaming || m_len < 0) - { - hr = E_FAIL; - return; - } - - if(!SetCacheSize(cachelen)) - { - hr = E_OUTOFMEMORY; - return; - } - - hr = S_OK; + if(!m_pAsyncReader) {hr = E_UNEXPECTED; return;} + + LONGLONG total = 0, available; + hr = m_pAsyncReader->Length(&total, &available); + + m_fStreaming = total == 0 && available > 0; + m_fRandomAccess = total > 0 && total == available; + m_len = total; + + if(FAILED(hr) || fRandomAccess && !m_fRandomAccess || !fStreaming && m_fStreaming || m_len < 0) + { + hr = E_FAIL; + return; + } + + if(!SetCacheSize(cachelen)) + { + hr = E_OUTOFMEMORY; + return; + } + + hr = S_OK; } bool CBaseSplitterFile::SetCacheSize(int cachelen) { - m_pCache.Free(); - m_cachetotal = 0; - m_pCache.Allocate((size_t)cachelen); - if(!m_pCache) return false; - m_cachetotal = cachelen; - m_cachelen = 0; - return true; + m_pCache.Free(); + m_cachetotal = 0; + m_pCache.Allocate((size_t)cachelen); + if(!m_pCache) return false; + m_cachetotal = cachelen; + m_cachelen = 0; + return true; } __int64 CBaseSplitterFile::GetPos() { - return m_pos - (m_bitlen >> 3); + return m_pos - (m_bitlen>>3); } __int64 CBaseSplitterFile::GetAvailable() { - LONGLONG total, available = 0; - m_pAsyncReader->Length(&total, &available); - return available; + LONGLONG total, available = 0; + m_pAsyncReader->Length(&total, &available); + return available; } __int64 CBaseSplitterFile::GetLength(bool fUpdate) { - if(m_fStreaming) - { - m_len = GetAvailable(); - } - else if(fUpdate) - { - LONGLONG total = 0, available; - m_pAsyncReader->Length(&total, &available); - m_len = total; - } - - return m_len; + if(m_fStreaming) + { + m_len = GetAvailable(); + } + else if(fUpdate) + { + LONGLONG total = 0, available; + m_pAsyncReader->Length(&total, &available); + m_len = total; + } + + return m_len; } void CBaseSplitterFile::Seek(__int64 pos) { - __int64 len = GetLength(); - m_pos = min(max(pos, 0), len); - BitFlush(); + __int64 len = GetLength(); + m_pos = min(max(pos, 0), len); + BitFlush(); } HRESULT CBaseSplitterFile::Read(BYTE* pData, __int64 len) { - CheckPointer(m_pAsyncReader, E_NOINTERFACE); - - HRESULT hr = S_OK; - - if(!m_fRandomAccess) - { - LONGLONG total = 0, available = -1; - m_pAsyncReader->Length(&total, &available); - if(total == available) - { - m_fRandomAccess = true; - OnComplete(); - } - } - - if(m_cachetotal == 0 || !m_pCache) - { - hr = m_pAsyncReader->SyncRead(m_pos, (long)len, pData); - m_pos += len; - return hr; - } - - BYTE* pCache = m_pCache; - - if(m_cachepos <= m_pos && m_pos < m_cachepos + m_cachelen) - { - __int64 minlen = min(len, m_cachelen - (m_pos - m_cachepos)); - - memcpy(pData, &pCache[m_pos - m_cachepos], (size_t)minlen); - - len -= minlen; - m_pos += minlen; - pData += minlen; - } - - while(len > m_cachetotal) - { - hr = m_pAsyncReader->SyncRead(m_pos, (long)m_cachetotal, pData); - if(S_OK != hr) return hr; - - len -= m_cachetotal; - m_pos += m_cachetotal; - pData += m_cachetotal; - } - - while(len > 0) - { - __int64 tmplen = GetLength(); - __int64 maxlen = min(tmplen - m_pos, m_cachetotal); - __int64 minlen = min(len, maxlen); - if(minlen <= 0) return S_FALSE; - - hr = m_pAsyncReader->SyncRead(m_pos, (long)maxlen, pCache); - if(S_OK != hr) return hr; - - m_cachepos = m_pos; - m_cachelen = maxlen; - - memcpy(pData, pCache, (size_t)minlen); - - len -= minlen; - m_pos += minlen; - pData += minlen; - } - - return hr; + CheckPointer(m_pAsyncReader, E_NOINTERFACE); + + HRESULT hr = S_OK; + + if(!m_fRandomAccess) + { + LONGLONG total = 0, available = -1; + m_pAsyncReader->Length(&total, &available); + if(total == available) {m_fRandomAccess = true; OnComplete();} + } + + if(m_cachetotal == 0 || !m_pCache) + { + hr = m_pAsyncReader->SyncRead(m_pos, (long)len, pData); + m_pos += len; + return hr; + } + + BYTE* pCache = m_pCache; + + if(m_cachepos <= m_pos && m_pos < m_cachepos + m_cachelen) + { + __int64 minlen = min(len, m_cachelen - (m_pos - m_cachepos)); + + memcpy(pData, &pCache[m_pos - m_cachepos], (size_t)minlen); + + len -= minlen; + m_pos += minlen; + pData += minlen; + } + + while(len > m_cachetotal) + { + hr = m_pAsyncReader->SyncRead(m_pos, (long)m_cachetotal, pData); + if(S_OK != hr) return hr; + + len -= m_cachetotal; + m_pos += m_cachetotal; + pData += m_cachetotal; + } + + while(len > 0) + { + __int64 tmplen = GetLength(); + __int64 maxlen = min(tmplen - m_pos, m_cachetotal); + __int64 minlen = min(len, maxlen); + if(minlen <= 0) return S_FALSE; + + hr = m_pAsyncReader->SyncRead(m_pos, (long)maxlen, pCache); + if(S_OK != hr) return hr; + + m_cachepos = m_pos; + m_cachelen = maxlen; + + memcpy(pData, pCache, (size_t)minlen); + + len -= minlen; + m_pos += minlen; + pData += minlen; + } + + return hr; } UINT64 CBaseSplitterFile::BitRead(int nBits, bool fPeek) { - ASSERT(nBits >= 0 && nBits <= 64); + ASSERT(nBits >= 0 && nBits <= 64); - while(m_bitlen < nBits) - { - m_bitbuff <<= 8; - if(S_OK != Read((BYTE*)&m_bitbuff, 1)) - { - return 0; // EOF? // ASSERT(0); - } - m_bitlen += 8; - } + while(m_bitlen < nBits) + { + m_bitbuff <<= 8; + if(S_OK != Read((BYTE*)&m_bitbuff, 1)) {return 0;} // EOF? // ASSERT(0); + m_bitlen += 8; + } - int bitlen = m_bitlen - nBits; + int bitlen = m_bitlen - nBits; - UINT64 ret = (m_bitbuff >> bitlen) & ((1ui64 << nBits) - 1); + UINT64 ret = (m_bitbuff >> bitlen) & ((1ui64 << nBits) - 1); - if(!fPeek) - { - m_bitbuff &= ((1ui64 << bitlen) - 1); - m_bitlen = bitlen; - } + if(!fPeek) + { + m_bitbuff &= ((1ui64 << bitlen) - 1); + m_bitlen = bitlen; + } - return ret; + return ret; } void CBaseSplitterFile::BitByteAlign() { - m_bitlen &= ~7; + m_bitlen &= ~7; } void CBaseSplitterFile::BitFlush() { - m_bitlen = 0; + m_bitlen = 0; } HRESULT CBaseSplitterFile::ByteRead(BYTE* pData, __int64 len) { Seek(GetPos()); - return Read(pData, len); + return Read(pData, len); } UINT64 CBaseSplitterFile::UExpGolombRead() { - int n = -1; - for(BYTE b = 0; !b; n++) b = BitRead(1); - return (1ui64 << n) - 1 + BitRead(n); + int n = -1; + for(BYTE b = 0; !b; n++) b = BitRead(1); + return (1ui64 << n) - 1 + BitRead(n); } INT64 CBaseSplitterFile::SExpGolombRead() { - UINT64 k = UExpGolombRead(); - return ((k & 1) ? 1 : -1) * ((k + 1) >> 1); + UINT64 k = UExpGolombRead(); + return ((k&1) ? 1 : -1) * ((k + 1) >> 1); } HRESULT CBaseSplitterFile::HasMoreData(__int64 len, DWORD ms) { - __int64 available = GetLength() - GetPos(); + __int64 available = GetLength() - GetPos(); - if(!m_fStreaming) - { - return available < 1 ? E_FAIL : S_OK; - } + if(!m_fStreaming) + { + return available < 1 ? E_FAIL : S_OK; + } - if(available < len) - { - if(ms > 0) Sleep(ms); - return S_FALSE; - } + if(available < len) + { + if(ms > 0) Sleep(ms); + return S_FALSE; + } - return S_OK; + return S_OK; } diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFile.h b/src/filters/parser/BaseSplitter/BaseSplitterFile.h index 88c544a6b..e7498223e 100644 --- a/src/filters/parser/BaseSplitter/BaseSplitterFile.h +++ b/src/filters/parser/BaseSplitter/BaseSplitterFile.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -27,51 +27,42 @@ class CBaseSplitterFile { - CComPtr m_pAsyncReader; - CAutoVectorPtr m_pCache; - __int64 m_cachepos, m_cachelen, m_cachetotal; + CComPtr m_pAsyncReader; + CAutoVectorPtr m_pCache; + __int64 m_cachepos, m_cachelen, m_cachetotal; - bool m_fStreaming, m_fRandomAccess; - __int64 m_pos, m_len; + bool m_fStreaming, m_fRandomAccess; + __int64 m_pos, m_len; - virtual HRESULT Read(BYTE* pData, __int64 len); // use ByteRead + virtual HRESULT Read(BYTE* pData, __int64 len); // use ByteRead protected: - UINT64 m_bitbuff; - int m_bitlen; + UINT64 m_bitbuff; + int m_bitlen; - virtual void OnComplete() {} + virtual void OnComplete() {} public: - CBaseSplitterFile(IAsyncReader* pReader, HRESULT& hr, int cachelen = DEFAULT_CACHE_LENGTH, bool fRandomAccess = true, bool fStreaming = false); - virtual ~CBaseSplitterFile() {} + CBaseSplitterFile(IAsyncReader* pReader, HRESULT& hr, int cachelen = DEFAULT_CACHE_LENGTH, bool fRandomAccess = true, bool fStreaming = false); + virtual ~CBaseSplitterFile() {} - bool SetCacheSize(int cachelen = DEFAULT_CACHE_LENGTH); + bool SetCacheSize(int cachelen = DEFAULT_CACHE_LENGTH); - __int64 GetPos(); - __int64 GetAvailable(); - __int64 GetLength(bool fUpdate = false); - __int64 GetRemaining() - { - return max(0, GetLength() - GetPos()); - } - virtual void Seek(__int64 pos); + __int64 GetPos(); + __int64 GetAvailable(); + __int64 GetLength(bool fUpdate = false); + __int64 GetRemaining() {return max(0, GetLength() - GetPos());} + virtual void Seek(__int64 pos); - UINT64 UExpGolombRead(); - INT64 SExpGolombRead(); + UINT64 UExpGolombRead(); + INT64 SExpGolombRead(); - UINT64 BitRead(int nBits, bool fPeek = false); - void BitByteAlign(), BitFlush(); - HRESULT ByteRead(BYTE* pData, __int64 len); + UINT64 BitRead(int nBits, bool fPeek = false); + void BitByteAlign(), BitFlush(); + HRESULT ByteRead(BYTE* pData, __int64 len); - bool IsStreaming() const - { - return m_fStreaming; - } - bool IsRandomAccess() const - { - return m_fRandomAccess; - } + bool IsStreaming() const {return m_fStreaming;} + bool IsRandomAccess() const {return m_fRandomAccess;} - HRESULT HasMoreData(__int64 len = 1, DWORD ms = 1); + HRESULT HasMoreData(__int64 len = 1, DWORD ms = 1); }; diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp index 16519f316..acb44acef 100644 --- a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp +++ b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -34,9 +34,9 @@ // CBaseSplitterFileEx::CBaseSplitterFileEx(IAsyncReader* pReader, HRESULT& hr, int cachelen, bool fRandomAccess, bool fStreaming) - : CBaseSplitterFile(pReader, hr, cachelen, fRandomAccess, fStreaming) - , m_tslen(0) - , m_rtPTSOffset(0) + : CBaseSplitterFile(pReader, hr, cachelen, fRandomAccess, fStreaming) + , m_tslen(0) + ,m_rtPTSOffset(0) { } @@ -48,16 +48,16 @@ CBaseSplitterFileEx::~CBaseSplitterFileEx() bool CBaseSplitterFileEx::NextMpegStartCode(BYTE& code, __int64 len) { - BitByteAlign(); - DWORD dw = -1; - do - { - if(len-- == 0 || !GetRemaining()) return(false); - dw = (dw << 8) | (BYTE)BitRead(8); - } - while((dw & 0xffffff00) != 0x00000100); - code = (BYTE)(dw & 0xff); - return(true); + BitByteAlign(); + DWORD dw = -1; + do + { + if(len-- == 0 || !GetRemaining()) return(false); + dw = (dw << 8) | (BYTE)BitRead(8); + } + while((dw&0xffffff00) != 0x00000100); + code = (BYTE)(dw&0xff); + return(true); } // @@ -66,651 +66,602 @@ bool CBaseSplitterFileEx::NextMpegStartCode(BYTE& code, __int64 len) bool CBaseSplitterFileEx::Read(pshdr& h) { - memset(&h, 0, sizeof(h)); - - BYTE b = (BYTE)BitRead(8, true); - - if((b & 0xf1) == 0x21) - { - h.type = mpeg1; - - EXECUTE_ASSERT(BitRead(4) == 2); - - h.scr = 0; - h.scr |= BitRead(3) << 30; - MARKER; // 32..30 - h.scr |= BitRead(15) << 15; - MARKER; // 29..15 - h.scr |= BitRead(15); - MARKER; - MARKER; // 14..0 - h.bitrate = BitRead(22); - MARKER; - } - else if((b & 0xc4) == 0x44) - { - h.type = mpeg2; - - EXECUTE_ASSERT(BitRead(2) == 1); - - h.scr = 0; - h.scr |= BitRead(3) << 30; - MARKER; // 32..30 - h.scr |= BitRead(15) << 15; - MARKER; // 29..15 - h.scr |= BitRead(15); - MARKER; // 14..0 - h.scr = (h.scr * 300 + BitRead(9)) * 10 / 27; - MARKER; - h.bitrate = BitRead(22); - MARKER; - MARKER; - BitRead(5); // reserved - UINT64 stuffing = BitRead(3); - while(stuffing-- > 0) EXECUTE_ASSERT(BitRead(8) == 0xff); - } - else - { - return(false); - } - - h.bitrate *= 400; - - return(true); + memset(&h, 0, sizeof(h)); + + BYTE b = (BYTE)BitRead(8, true); + + if((b&0xf1) == 0x21) + { + h.type = mpeg1; + + EXECUTE_ASSERT(BitRead(4) == 2); + + h.scr = 0; + h.scr |= BitRead(3) << 30; MARKER; // 32..30 + h.scr |= BitRead(15) << 15; MARKER; // 29..15 + h.scr |= BitRead(15); MARKER; MARKER; // 14..0 + h.bitrate = BitRead(22); MARKER; + } + else if((b&0xc4) == 0x44) + { + h.type = mpeg2; + + EXECUTE_ASSERT(BitRead(2) == 1); + + h.scr = 0; + h.scr |= BitRead(3) << 30; MARKER; // 32..30 + h.scr |= BitRead(15) << 15; MARKER; // 29..15 + h.scr |= BitRead(15); MARKER; // 14..0 + h.scr = (h.scr*300 + BitRead(9)) * 10 / 27; MARKER; + h.bitrate = BitRead(22); MARKER; MARKER; + BitRead(5); // reserved + UINT64 stuffing = BitRead(3); + while(stuffing-- > 0) EXECUTE_ASSERT(BitRead(8) == 0xff); + } + else + { + return(false); + } + + h.bitrate *= 400; + + return(true); } bool CBaseSplitterFileEx::Read(pssyshdr& h) { - memset(&h, 0, sizeof(h)); - - WORD len = (WORD)BitRead(16); - MARKER; - h.rate_bound = (DWORD)BitRead(22); - MARKER; - h.audio_bound = (BYTE)BitRead(6); - h.fixed_rate = !!BitRead(1); - h.csps = !!BitRead(1); - h.sys_audio_loc_flag = !!BitRead(1); - h.sys_video_loc_flag = !!BitRead(1); - MARKER; - h.video_bound = (BYTE)BitRead(5); - - EXECUTE_ASSERT((BitRead(8) & 0x7f) == 0x7f); // reserved (should be 0xff, but not in reality) - - for(len -= 6; len > 3; len -= 3) // TODO: also store these, somewhere, if needed - { - UINT64 stream_id = BitRead(8); - EXECUTE_ASSERT(BitRead(2) == 3); - UINT64 p_std_buff_size_bound = (BitRead(1) ? 1024 : 128) * BitRead(13); - } - - return(true); + memset(&h, 0, sizeof(h)); + + WORD len = (WORD)BitRead(16); MARKER; + h.rate_bound = (DWORD)BitRead(22); MARKER; + h.audio_bound = (BYTE)BitRead(6); + h.fixed_rate = !!BitRead(1); + h.csps = !!BitRead(1); + h.sys_audio_loc_flag = !!BitRead(1); + h.sys_video_loc_flag = !!BitRead(1); MARKER; + h.video_bound = (BYTE)BitRead(5); + + EXECUTE_ASSERT((BitRead(8)&0x7f) == 0x7f); // reserved (should be 0xff, but not in reality) + + for(len -= 6; len > 3; len -= 3) // TODO: also store these, somewhere, if needed + { + UINT64 stream_id = BitRead(8); + EXECUTE_ASSERT(BitRead(2) == 3); + UINT64 p_std_buff_size_bound = (BitRead(1)?1024:128)*BitRead(13); + } + + return(true); } bool CBaseSplitterFileEx::Read(peshdr& h, BYTE code) { - memset(&h, 0, sizeof(h)); - - if(!(code >= 0xbd && code < 0xf0 || code == 0xfd)) // 0xfd => blu-ray (.m2ts) - return(false); - - h.len = (WORD)BitRead(16); - - if(code == 0xbe || code == 0xbf) - return(true); - - // mpeg1 stuffing (ff ff .. , max 16x) - for(int i = 0; i < 16 && BitRead(8, true) == 0xff; i++) - { - BitRead(8); - if(h.len) h.len--; - } - - h.type = (BYTE)BitRead(2, true) == mpeg2 ? mpeg2 : mpeg1; - - if(h.type == mpeg1) - { - BYTE b = (BYTE)BitRead(2); - - if(b == 1) - { - h.std_buff_size = (BitRead(1) ? 1024 : 128) * BitRead(13); - if(h.len) h.len -= 2; - b = (BYTE)BitRead(2); - } - - if(b == 0) - { - h.fpts = (BYTE)BitRead(1); - h.fdts = (BYTE)BitRead(1); - } - } - else if(h.type == mpeg2) - { - EXECUTE_ASSERT(BitRead(2) == mpeg2); - h.scrambling = (BYTE)BitRead(2); - h.priority = (BYTE)BitRead(1); - h.alignment = (BYTE)BitRead(1); - h.copyright = (BYTE)BitRead(1); - h.original = (BYTE)BitRead(1); - h.fpts = (BYTE)BitRead(1); - h.fdts = (BYTE)BitRead(1); - h.escr = (BYTE)BitRead(1); - h.esrate = (BYTE)BitRead(1); - h.dsmtrickmode = (BYTE)BitRead(1); - h.morecopyright = (BYTE)BitRead(1); - h.crc = (BYTE)BitRead(1); - h.extension = (BYTE)BitRead(1); - h.hdrlen = (BYTE)BitRead(8); - } - else - { - if(h.len) while(h.len-- > 0) BitRead(8); - return(false); - } - - if(h.fpts) - { - if(h.type == mpeg2) - { - BYTE b = (BYTE)BitRead(4); - if(!(h.fdts && b == 3 || !h.fdts && b == 2)) - { - ASSERT(0); - return(false); - } - } - - h.pts = 0; - h.pts |= BitRead(3) << 30; - MARKER; // 32..30 - h.pts |= BitRead(15) << 15; - MARKER; // 29..15 - h.pts |= BitRead(15); - MARKER; // 14..0 - h.pts = 10000 * h.pts / 90 + m_rtPTSOffset; - } - - if(h.fdts) - { - if((BYTE)BitRead(4) != 1) - { - ASSERT(0); - return(false); - } - - h.dts = 0; - h.dts |= BitRead(3) << 30; - MARKER; // 32..30 - h.dts |= BitRead(15) << 15; - MARKER; // 29..15 - h.dts |= BitRead(15); - MARKER; // 14..0 - h.dts = 10000 * h.dts / 90 + m_rtPTSOffset; - } - - // skip to the end of header - - if(h.type == mpeg1) - { - if(!h.fpts && !h.fdts && BitRead(4) != 0xf) - { - /*ASSERT(0);*/ return(false); - } - - if(h.len) - { - h.len--; - if(h.pts) h.len -= 4; - if(h.dts) h.len -= 5; - } - } - - if(h.type == mpeg2) - { - if(h.len) h.len -= 3 + h.hdrlen; - - int left = h.hdrlen; - if(h.fpts) left -= 5; - if(h.fdts) left -= 5; - while(left-- > 0) BitRead(8); - /* - // mpeg2 stuffing (ff ff .. , max 32x) - while(BitRead(8, true) == 0xff) {BitRead(8); if(h.len) h.len--;} - Seek(GetPos()); // put last peeked byte back for Read() - - // FIXME: this doesn't seems to be here, - // infact there can be ff's as part of the data - // right at the beginning of the packet, which - // we should not skip... - */ - } + memset(&h, 0, sizeof(h)); + + if(!(code >= 0xbd && code < 0xf0 || code == 0xfd)) // 0xfd => blu-ray (.m2ts) + return(false); + + h.len = (WORD)BitRead(16); + + if(code == 0xbe || code == 0xbf) + return(true); + + // mpeg1 stuffing (ff ff .. , max 16x) + for(int i = 0; i < 16 && BitRead(8, true) == 0xff; i++) + { + BitRead(8); + if(h.len) h.len--; + } + + h.type = (BYTE)BitRead(2, true) == mpeg2 ? mpeg2 : mpeg1; + + if(h.type == mpeg1) + { + BYTE b = (BYTE)BitRead(2); + + if(b == 1) + { + h.std_buff_size = (BitRead(1)?1024:128)*BitRead(13); + if(h.len) h.len -= 2; + b = (BYTE)BitRead(2); + } + + if(b == 0) + { + h.fpts = (BYTE)BitRead(1); + h.fdts = (BYTE)BitRead(1); + } + } + else if(h.type == mpeg2) + { + EXECUTE_ASSERT(BitRead(2) == mpeg2); + h.scrambling = (BYTE)BitRead(2); + h.priority = (BYTE)BitRead(1); + h.alignment = (BYTE)BitRead(1); + h.copyright = (BYTE)BitRead(1); + h.original = (BYTE)BitRead(1); + h.fpts = (BYTE)BitRead(1); + h.fdts = (BYTE)BitRead(1); + h.escr = (BYTE)BitRead(1); + h.esrate = (BYTE)BitRead(1); + h.dsmtrickmode = (BYTE)BitRead(1); + h.morecopyright = (BYTE)BitRead(1); + h.crc = (BYTE)BitRead(1); + h.extension = (BYTE)BitRead(1); + h.hdrlen = (BYTE)BitRead(8); + } + else + { + if(h.len) while(h.len-- > 0) BitRead(8); + return(false); + } + + if(h.fpts) + { + if(h.type == mpeg2) + { + BYTE b = (BYTE)BitRead(4); + if(!(h.fdts && b == 3 || !h.fdts && b == 2)) {ASSERT(0); return(false);} + } + + h.pts = 0; + h.pts |= BitRead(3) << 30; MARKER; // 32..30 + h.pts |= BitRead(15) << 15; MARKER; // 29..15 + h.pts |= BitRead(15); MARKER; // 14..0 + h.pts = 10000*h.pts/90 + m_rtPTSOffset; + } + + if(h.fdts) + { + if((BYTE)BitRead(4) != 1) {ASSERT(0); return(false);} + + h.dts = 0; + h.dts |= BitRead(3) << 30; MARKER; // 32..30 + h.dts |= BitRead(15) << 15; MARKER; // 29..15 + h.dts |= BitRead(15); MARKER; // 14..0 + h.dts = 10000*h.dts/90 + m_rtPTSOffset; + } + + // skip to the end of header + + if(h.type == mpeg1) + { + if(!h.fpts && !h.fdts && BitRead(4) != 0xf) {/*ASSERT(0);*/ return(false);} + + if(h.len) + { + h.len--; + if(h.pts) h.len -= 4; + if(h.dts) h.len -= 5; + } + } + + if(h.type == mpeg2) + { + if(h.len) h.len -= 3+h.hdrlen; + + int left = h.hdrlen; + if(h.fpts) left -= 5; + if(h.fdts) left -= 5; + while(left-- > 0) BitRead(8); +/* + // mpeg2 stuffing (ff ff .. , max 32x) + while(BitRead(8, true) == 0xff) {BitRead(8); if(h.len) h.len--;} + Seek(GetPos()); // put last peeked byte back for Read() + + // FIXME: this doesn't seems to be here, + // infact there can be ff's as part of the data + // right at the beginning of the packet, which + // we should not skip... +*/ + } - return(true); + return(true); } bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt) { - __int64 endpos = GetPos() + len; // - sequence header length + __int64 endpos = GetPos() + len; // - sequence header length - BYTE id = 0; + BYTE id = 0; - while(GetPos() < endpos && id != 0xb3) - { - if(!NextMpegStartCode(id, len)) - return(false); - } + while(GetPos() < endpos && id != 0xb3) + { + if(!NextMpegStartCode(id, len)) + return(false); + } - if(id != 0xb3) - return(false); + if(id != 0xb3) + return(false); - __int64 shpos = GetPos() - 4; + __int64 shpos = GetPos() - 4; - h.width = (WORD)BitRead(12); - h.height = (WORD)BitRead(12); - h.ar = BitRead(4); + h.width = (WORD)BitRead(12); + h.height = (WORD)BitRead(12); + h.ar = BitRead(4); static int ifps[16] = {0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, 0, 0, 0, 0, 0, 0, 0}; - h.ifps = ifps[BitRead(4)]; - h.bitrate = (DWORD)BitRead(18); - MARKER; - h.vbv = (DWORD)BitRead(10); - h.constrained = BitRead(1); - - if(h.fiqm = BitRead(1)) - for(int i = 0; i < countof(h.iqm); i++) - h.iqm[i] = (BYTE)BitRead(8); - - if(h.fniqm = BitRead(1)) - for(int i = 0; i < countof(h.niqm); i++) - h.niqm[i] = (BYTE)BitRead(8); - - __int64 shlen = GetPos() - shpos; - - static float ar[] = - { - 1.0000f, 1.0000f, 0.6735f, 0.7031f, 0.7615f, 0.8055f, 0.8437f, 0.8935f, - 0.9157f, 0.9815f, 1.0255f, 1.0695f, 1.0950f, 1.1575f, 1.2015f, 1.0000f - }; - - h.arx = (int)((float)h.width / ar[h.ar] + 0.5); - h.ary = h.height; - - mpeg_t type = mpeg1; - - __int64 shextpos = 0, shextlen = 0; - - if(NextMpegStartCode(id, 8) && id == 0xb5) // sequence header ext - { - shextpos = GetPos() - 4; - - h.startcodeid = BitRead(4); - h.profile_levelescape = BitRead(1); // reserved, should be 0 - h.profile = BitRead(3); - h.level = BitRead(4); - h.progressive = BitRead(1); - h.chroma = BitRead(2); - h.width |= (BitRead(2) << 12); - h.height |= (BitRead(2) << 12); - h.bitrate |= (BitRead(12) << 18); - MARKER; - h.vbv |= (BitRead(8) << 10); - h.lowdelay = BitRead(1); - h.ifps = (DWORD)(h.ifps * (BitRead(2) + 1) / (BitRead(5) + 1)); - - shextlen = GetPos() - shextpos; - - struct - { - DWORD x, y; - } ar[] = {{h.width, h.height}, {4, 3}, {16, 9}, {221, 100}, {h.width, h.height}}; - int i = min(max(h.ar, 1), 5) - 1; - h.arx = ar[i].x; - h.ary = ar[i].y; - - type = mpeg2; - } - - h.ifps = 10 * h.ifps / 27; - h.bitrate = h.bitrate == (1 << 30) - 1 ? 0 : h.bitrate * 400; - - DWORD a = h.arx, b = h.ary; - while(a) - { - DWORD tmp = a; - a = b % tmp; - b = tmp; - } - if(b) h.arx /= b, h.ary /= b; - - if(!pmt) return(true); - - pmt->majortype = MEDIATYPE_Video; - - if(type == mpeg1) - { - pmt->subtype = MEDIASUBTYPE_MPEG1Payload; - pmt->formattype = FORMAT_MPEGVideo; - int len = FIELD_OFFSET(MPEG1VIDEOINFO, bSequenceHeader) + shlen + shextlen; - MPEG1VIDEOINFO* vi = (MPEG1VIDEOINFO*)DNew BYTE[len]; - memset(vi, 0, len); - vi->hdr.dwBitRate = h.bitrate; - vi->hdr.AvgTimePerFrame = h.ifps; - vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); - vi->hdr.bmiHeader.biWidth = h.width; - vi->hdr.bmiHeader.biHeight = h.height; - vi->hdr.bmiHeader.biXPelsPerMeter = h.width * h.ary; - vi->hdr.bmiHeader.biYPelsPerMeter = h.height * h.arx; - vi->cbSequenceHeader = shlen + shextlen; - Seek(shpos); - ByteRead((BYTE*)&vi->bSequenceHeader[0], shlen); - if(shextpos && shextlen) Seek(shextpos); - ByteRead((BYTE*)&vi->bSequenceHeader[0] + shlen, shextlen); - pmt->SetFormat((BYTE*)vi, len); - delete [] vi; - } - else if(type == mpeg2) - { - pmt->subtype = MEDIASUBTYPE_MPEG2_VIDEO; - pmt->formattype = FORMAT_MPEG2_VIDEO; - int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + shlen + shextlen; - MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len]; - memset(vi, 0, len); - vi->hdr.dwBitRate = h.bitrate; - vi->hdr.AvgTimePerFrame = h.ifps; - vi->hdr.dwPictAspectRatioX = h.arx; - vi->hdr.dwPictAspectRatioY = h.ary; - vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); - vi->hdr.bmiHeader.biWidth = h.width; - vi->hdr.bmiHeader.biHeight = h.height; - vi->dwProfile = h.profile; - vi->dwLevel = h.level; - vi->cbSequenceHeader = shlen + shextlen; - Seek(shpos); - ByteRead((BYTE*)&vi->dwSequenceHeader[0], shlen); - if(shextpos && shextlen) Seek(shextpos); - ByteRead((BYTE*)&vi->dwSequenceHeader[0] + shlen, shextlen); - pmt->SetFormat((BYTE*)vi, len); - delete [] vi; - } - else - { - return(false); - } - - return(true); + h.ifps = ifps[BitRead(4)]; + h.bitrate = (DWORD)BitRead(18); MARKER; + h.vbv = (DWORD)BitRead(10); + h.constrained = BitRead(1); + + if(h.fiqm = BitRead(1)) + for(int i = 0; i < countof(h.iqm); i++) + h.iqm[i] = (BYTE)BitRead(8); + + if(h.fniqm = BitRead(1)) + for(int i = 0; i < countof(h.niqm); i++) + h.niqm[i] = (BYTE)BitRead(8); + + __int64 shlen = GetPos() - shpos; + + static float ar[] = + { + 1.0000f,1.0000f,0.6735f,0.7031f,0.7615f,0.8055f,0.8437f,0.8935f, + 0.9157f,0.9815f,1.0255f,1.0695f,1.0950f,1.1575f,1.2015f,1.0000f + }; + + h.arx = (int)((float)h.width / ar[h.ar] + 0.5); + h.ary = h.height; + + mpeg_t type = mpeg1; + + __int64 shextpos = 0, shextlen = 0; + + if(NextMpegStartCode(id, 8) && id == 0xb5) // sequence header ext + { + shextpos = GetPos() - 4; + + h.startcodeid = BitRead(4); + h.profile_levelescape = BitRead(1); // reserved, should be 0 + h.profile = BitRead(3); + h.level = BitRead(4); + h.progressive = BitRead(1); + h.chroma = BitRead(2); + h.width |= (BitRead(2)<<12); + h.height |= (BitRead(2)<<12); + h.bitrate |= (BitRead(12)<<18); MARKER; + h.vbv |= (BitRead(8)<<10); + h.lowdelay = BitRead(1); + h.ifps = (DWORD)(h.ifps * (BitRead(2)+1) / (BitRead(5)+1)); + + shextlen = GetPos() - shextpos; + + struct {DWORD x, y;} ar[] = {{h.width,h.height},{4,3},{16,9},{221,100},{h.width,h.height}}; + int i = min(max(h.ar, 1), 5)-1; + h.arx = ar[i].x; + h.ary = ar[i].y; + + type = mpeg2; + } + + h.ifps = 10 * h.ifps / 27; + h.bitrate = h.bitrate == (1<<30)-1 ? 0 : h.bitrate * 400; + + DWORD a = h.arx, b = h.ary; + while(a) {DWORD tmp = a; a = b % tmp; b = tmp;} + if(b) h.arx /= b, h.ary /= b; + + if(!pmt) return(true); + + pmt->majortype = MEDIATYPE_Video; + + if(type == mpeg1) + { + pmt->subtype = MEDIASUBTYPE_MPEG1Payload; + pmt->formattype = FORMAT_MPEGVideo; + int len = FIELD_OFFSET(MPEG1VIDEOINFO, bSequenceHeader) + shlen + shextlen; + MPEG1VIDEOINFO* vi = (MPEG1VIDEOINFO*)DNew BYTE[len]; + memset(vi, 0, len); + vi->hdr.dwBitRate = h.bitrate; + vi->hdr.AvgTimePerFrame = h.ifps; + vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); + vi->hdr.bmiHeader.biWidth = h.width; + vi->hdr.bmiHeader.biHeight = h.height; + vi->hdr.bmiHeader.biXPelsPerMeter = h.width * h.ary; + vi->hdr.bmiHeader.biYPelsPerMeter = h.height * h.arx; + vi->cbSequenceHeader = shlen + shextlen; + Seek(shpos); + ByteRead((BYTE*)&vi->bSequenceHeader[0], shlen); + if(shextpos && shextlen) Seek(shextpos); + ByteRead((BYTE*)&vi->bSequenceHeader[0] + shlen, shextlen); + pmt->SetFormat((BYTE*)vi, len); + delete [] vi; + } + else if(type == mpeg2) + { + pmt->subtype = MEDIASUBTYPE_MPEG2_VIDEO; + pmt->formattype = FORMAT_MPEG2_VIDEO; + int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + shlen + shextlen; + MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len]; + memset(vi, 0, len); + vi->hdr.dwBitRate = h.bitrate; + vi->hdr.AvgTimePerFrame = h.ifps; + vi->hdr.dwPictAspectRatioX = h.arx; + vi->hdr.dwPictAspectRatioY = h.ary; + vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); + vi->hdr.bmiHeader.biWidth = h.width; + vi->hdr.bmiHeader.biHeight = h.height; + vi->dwProfile = h.profile; + vi->dwLevel = h.level; + vi->cbSequenceHeader = shlen + shextlen; + Seek(shpos); + ByteRead((BYTE*)&vi->dwSequenceHeader[0], shlen); + if(shextpos && shextlen) Seek(shextpos); + ByteRead((BYTE*)&vi->dwSequenceHeader[0] + shlen, shextlen); + pmt->SetFormat((BYTE*)vi, len); + delete [] vi; + } + else + { + return(false); + } + + return(true); } bool CBaseSplitterFileEx::Read(mpahdr& h, int len, bool fAllowV25, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); - - int syncbits = fAllowV25 ? 11 : 12; - - for(; len >= 4 && BitRead(syncbits, true) != (1 << syncbits) - 1; len--) - BitRead(8); - - if(len < 4) - return(false); - - h.sync = BitRead(11); - h.version = BitRead(2); - h.layer = BitRead(2); - h.crc = BitRead(1); - h.bitrate = BitRead(4); - h.freq = BitRead(2); - h.padding = BitRead(1); - h.privatebit = BitRead(1); - h.channels = BitRead(2); - h.modeext = BitRead(2); - h.copyright = BitRead(1); - h.original = BitRead(1); - h.emphasis = BitRead(2); - - if(h.version == 1 || h.layer == 0 || h.freq == 3 || h.bitrate == 15 || h.emphasis == 2) - return(false); - - if(h.version == 3 && h.layer == 2) - { - if((h.bitrate == 1 || h.bitrate == 2 || h.bitrate == 3 || h.bitrate == 5) && h.channels != 3 - && (h.bitrate >= 11 && h.bitrate <= 14) && h.channels == 3) - return(false); - } - - h.layer = 4 - h.layer; - - // - - static int brtbl[][5] = - { - {0, 0, 0, 0, 0}, - {32, 32, 32, 32, 8}, - {64, 48, 40, 48, 16}, - {96, 56, 48, 56, 24}, - {128, 64, 56, 64, 32}, - {160, 80, 64, 80, 40}, - {192, 96, 80, 96, 48}, - {224, 112, 96, 112, 56}, - {256, 128, 112, 128, 64}, - {288, 160, 128, 144, 80}, - {320, 192, 160, 160, 96}, - {352, 224, 192, 176, 112}, - {384, 256, 224, 192, 128}, - {416, 320, 256, 224, 144}, - {448, 384, 320, 256, 160}, - {0, 0, 0, 0, 0}, - }; - - static int brtblcol[][4] = {{0, 3, 4, 4}, {0, 0, 1, 2}}; - int bitrate = 1000 * brtbl[h.bitrate][brtblcol[h.version&1][h.layer]]; - if(bitrate == 0) return(false); - - static int freq[][4] = {{11025, 0, 22050, 44100}, {12000, 0, 24000, 48000}, {8000, 0, 16000, 32000}}; - - bool l3ext = h.layer == 3 && !(h.version & 1); - - h.nSamplesPerSec = freq[h.freq][h.version]; - h.FrameSize = h.layer == 1 - ? (12 * bitrate / h.nSamplesPerSec + h.padding) * 4 - : (l3ext ? 72 : 144) * bitrate / h.nSamplesPerSec + h.padding; - h.rtDuration = 10000000i64 * (h.layer == 1 ? 384 : l3ext ? 576 : 1152) / h.nSamplesPerSec;// / (h.channels == 3 ? 1 : 2); - h.nBytesPerSec = bitrate / 8; - - if(!pmt) return(true); - - /*int*/ - len = h.layer == 3 - ? sizeof(WAVEFORMATEX/*MPEGLAYER3WAVEFORMAT*/) // no need to overcomplicate this... - : sizeof(MPEG1WAVEFORMAT); - WAVEFORMATEX* wfe = (WAVEFORMATEX*)DNew BYTE[len]; - memset(wfe, 0, len); - wfe->cbSize = len - sizeof(WAVEFORMATEX); - - if(h.layer == 3) - { - wfe->wFormatTag = WAVE_FORMAT_MP3; - - /* MPEGLAYER3WAVEFORMAT* f = (MPEGLAYER3WAVEFORMAT*)wfe; - f->wfx.wFormatTag = WAVE_FORMAT_MP3; - f->wID = MPEGLAYER3_ID_UNKNOWN; - f->fdwFlags = h.padding ? MPEGLAYER3_FLAG_PADDING_ON : MPEGLAYER3_FLAG_PADDING_OFF; // _OFF or _ISO ? - */ - } - else - { - MPEG1WAVEFORMAT* f = (MPEG1WAVEFORMAT*)wfe; - f->wfx.wFormatTag = WAVE_FORMAT_MPEG; - f->fwHeadMode = 1 << h.channels; - f->fwHeadModeExt = 1 << h.modeext; - f->wHeadEmphasis = h.emphasis + 1; - if(h.privatebit) f->fwHeadFlags |= ACM_MPEG_PRIVATEBIT; - if(h.copyright) f->fwHeadFlags |= ACM_MPEG_COPYRIGHT; - if(h.original) f->fwHeadFlags |= ACM_MPEG_ORIGINALHOME; - if(h.crc == 0) f->fwHeadFlags |= ACM_MPEG_PROTECTIONBIT; - if(h.version == 3) f->fwHeadFlags |= ACM_MPEG_ID_MPEG1; - f->fwHeadLayer = 1 << (h.layer - 1); - f->dwHeadBitrate = bitrate; - } - - wfe->nChannels = h.channels == 3 ? 1 : 2; - wfe->nSamplesPerSec = h.nSamplesPerSec; - wfe->nBlockAlign = h.FrameSize; - wfe->nAvgBytesPerSec = h.nBytesPerSec; - - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = FOURCCMap(wfe->wFormatTag); - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)wfe, sizeof(WAVEFORMATEX) + wfe->cbSize); - - delete [] wfe; - - return(true); + memset(&h, 0, sizeof(h)); + + int syncbits = fAllowV25 ? 11 : 12; + + for(; len >= 4 && BitRead(syncbits, true) != (1<= 11 && h.bitrate <= 14) && h.channels == 3) + return(false); + } + + h.layer = 4 - h.layer; + + // + + static int brtbl[][5] = + { + {0,0,0,0,0}, + {32,32,32,32,8}, + {64,48,40,48,16}, + {96,56,48,56,24}, + {128,64,56,64,32}, + {160,80,64,80,40}, + {192,96,80,96,48}, + {224,112,96,112,56}, + {256,128,112,128,64}, + {288,160,128,144,80}, + {320,192,160,160,96}, + {352,224,192,176,112}, + {384,256,224,192,128}, + {416,320,256,224,144}, + {448,384,320,256,160}, + {0,0,0,0,0}, + }; + + static int brtblcol[][4] = {{0,3,4,4},{0,0,1,2}}; + int bitrate = 1000*brtbl[h.bitrate][brtblcol[h.version&1][h.layer]]; + if(bitrate == 0) return(false); + + static int freq[][4] = {{11025,0,22050,44100},{12000,0,24000,48000},{8000,0,16000,32000}}; + + bool l3ext = h.layer == 3 && !(h.version&1); + + h.nSamplesPerSec = freq[h.freq][h.version]; + h.FrameSize = h.layer == 1 + ? (12 * bitrate / h.nSamplesPerSec + h.padding) * 4 + : (l3ext ? 72 : 144) * bitrate / h.nSamplesPerSec + h.padding; + h.rtDuration = 10000000i64 * (h.layer == 1 ? 384 : l3ext ? 576 : 1152) / h.nSamplesPerSec;// / (h.channels == 3 ? 1 : 2); + h.nBytesPerSec = bitrate / 8; + + if(!pmt) return(true); + + /*int*/ len = h.layer == 3 + ? sizeof(WAVEFORMATEX/*MPEGLAYER3WAVEFORMAT*/) // no need to overcomplicate this... + : sizeof(MPEG1WAVEFORMAT); + WAVEFORMATEX* wfe = (WAVEFORMATEX*)DNew BYTE[len]; + memset(wfe, 0, len); + wfe->cbSize = len - sizeof(WAVEFORMATEX); + + if(h.layer == 3) + { + wfe->wFormatTag = WAVE_FORMAT_MP3; + +/* MPEGLAYER3WAVEFORMAT* f = (MPEGLAYER3WAVEFORMAT*)wfe; + f->wfx.wFormatTag = WAVE_FORMAT_MP3; + f->wID = MPEGLAYER3_ID_UNKNOWN; + f->fdwFlags = h.padding ? MPEGLAYER3_FLAG_PADDING_ON : MPEGLAYER3_FLAG_PADDING_OFF; // _OFF or _ISO ? +*/ + } + else + { + MPEG1WAVEFORMAT* f = (MPEG1WAVEFORMAT*)wfe; + f->wfx.wFormatTag = WAVE_FORMAT_MPEG; + f->fwHeadMode = 1 << h.channels; + f->fwHeadModeExt = 1 << h.modeext; + f->wHeadEmphasis = h.emphasis+1; + if(h.privatebit) f->fwHeadFlags |= ACM_MPEG_PRIVATEBIT; + if(h.copyright) f->fwHeadFlags |= ACM_MPEG_COPYRIGHT; + if(h.original) f->fwHeadFlags |= ACM_MPEG_ORIGINALHOME; + if(h.crc == 0) f->fwHeadFlags |= ACM_MPEG_PROTECTIONBIT; + if(h.version == 3) f->fwHeadFlags |= ACM_MPEG_ID_MPEG1; + f->fwHeadLayer = 1 << (h.layer-1); + f->dwHeadBitrate = bitrate; + } + + wfe->nChannels = h.channels == 3 ? 1 : 2; + wfe->nSamplesPerSec = h.nSamplesPerSec; + wfe->nBlockAlign = h.FrameSize; + wfe->nAvgBytesPerSec = h.nBytesPerSec; + + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = FOURCCMap(wfe->wFormatTag); + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)wfe, sizeof(WAVEFORMATEX) + wfe->cbSize); + + delete [] wfe; + + return(true); } bool CBaseSplitterFileEx::Read(aachdr& h, int len, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - for(; len >= 7 && BitRead(12, true) != 0xfff; len--) - BitRead(8); + for(; len >= 7 && BitRead(12, true) != 0xfff; len--) + BitRead(8); - if(len < 7) - return(false); + if(len < 7) + return(false); - h.sync = BitRead(12); - h.version = BitRead(1); - h.layer = BitRead(2); - h.fcrc = BitRead(1); - h.profile = BitRead(2); - h.freq = BitRead(4); - h.privatebit = BitRead(1); - h.channels = BitRead(3); - h.original = BitRead(1); - h.home = BitRead(1); + h.sync = BitRead(12); + h.version = BitRead(1); + h.layer = BitRead(2); + h.fcrc = BitRead(1); + h.profile = BitRead(2); + h.freq = BitRead(4); + h.privatebit = BitRead(1); + h.channels = BitRead(3); + h.original = BitRead(1); + h.home = BitRead(1); - h.copyright_id_bit = BitRead(1); - h.copyright_id_start = BitRead(1); - h.aac_frame_length = BitRead(13); - h.adts_buffer_fullness = BitRead(11); - h.no_raw_data_blocks_in_frame = BitRead(2); + h.copyright_id_bit = BitRead(1); + h.copyright_id_start = BitRead(1); + h.aac_frame_length = BitRead(13); + h.adts_buffer_fullness = BitRead(11); + h.no_raw_data_blocks_in_frame = BitRead(2); - if(h.fcrc == 0) h.crc = BitRead(16); + if(h.fcrc == 0) h.crc = BitRead(16); - if(h.layer != 0 || h.freq >= 12 || h.aac_frame_length <= (h.fcrc == 0 ? 9 : 7)) - return(false); + if(h.layer != 0 || h.freq >= 12 || h.aac_frame_length <= (h.fcrc == 0 ? 9 : 7)) + return(false); - h.FrameSize = h.aac_frame_length - (h.fcrc == 0 ? 9 : 7); + h.FrameSize = h.aac_frame_length - (h.fcrc == 0 ? 9 : 7); static int freq[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000}; - h.nBytesPerSec = h.aac_frame_length * freq[h.freq] / 1024; // ok? - h.rtDuration = 10000000i64 * 1024 / freq[h.freq]; // ok? + h.nBytesPerSec = h.aac_frame_length * freq[h.freq] / 1024; // ok? + h.rtDuration = 10000000i64 * 1024 / freq[h.freq]; // ok? - if(!pmt) return(true); + if(!pmt) return(true); - WAVEFORMATEX* wfe = (WAVEFORMATEX*)DNew BYTE[sizeof(WAVEFORMATEX)+5]; - memset(wfe, 0, sizeof(WAVEFORMATEX) + 5); - wfe->wFormatTag = WAVE_FORMAT_AAC; - wfe->nChannels = h.channels <= 6 ? h.channels : 2; - wfe->nSamplesPerSec = freq[h.freq]; - wfe->nBlockAlign = h.aac_frame_length; - wfe->nAvgBytesPerSec = h.nBytesPerSec; - wfe->cbSize = MakeAACInitData((BYTE*)(wfe + 1), h.profile, wfe->nSamplesPerSec, wfe->nChannels); + WAVEFORMATEX* wfe = (WAVEFORMATEX*)DNew BYTE[sizeof(WAVEFORMATEX)+5]; + memset(wfe, 0, sizeof(WAVEFORMATEX)+5); + wfe->wFormatTag = WAVE_FORMAT_AAC; + wfe->nChannels = h.channels <= 6 ? h.channels : 2; + wfe->nSamplesPerSec = freq[h.freq]; + wfe->nBlockAlign = h.aac_frame_length; + wfe->nAvgBytesPerSec = h.nBytesPerSec; + wfe->cbSize = MakeAACInitData((BYTE*)(wfe+1), h.profile, wfe->nSamplesPerSec, wfe->nChannels); - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = MEDIASUBTYPE_AAC; - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)wfe, sizeof(WAVEFORMATEX) + wfe->cbSize); + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = MEDIASUBTYPE_AAC; + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)wfe, sizeof(WAVEFORMATEX)+wfe->cbSize); - delete [] wfe; + delete [] wfe; - return(true); + return(true); } bool CBaseSplitterFileEx::Read(ac3hdr& h, int len, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); - - for(; len >= 7 && BitRead(16, true) != 0x0b77; len--) - BitRead(8); - - if(len < 7) - return(false); - - h.sync = (WORD)BitRead(16); - if(h.sync != 0x0B77) - return(false); - - h.crc1 = (WORD)BitRead(16); - h.fscod = BitRead(2); - h.frmsizecod = BitRead(6); - h.bsid = BitRead(5); - h.bsmod = BitRead(3); - h.acmod = BitRead(3); - if((h.acmod & 1) && h.acmod != 1) h.cmixlev = BitRead(2); - if(h.acmod & 4) h.surmixlev = BitRead(2); - if(h.acmod == 2) h.dsurmod = BitRead(2); - h.lfeon = BitRead(1); - - if(h.bsid >= 17 || h.fscod == 3 || h.frmsizecod >= 48) - return(false); - - if(!pmt) return(true); - - WAVEFORMATEX wfe; - memset(&wfe, 0, sizeof(wfe)); - wfe.wFormatTag = WAVE_FORMAT_DOLBY_AC3; - - static int channels[] = {2, 1, 2, 3, 3, 4, 4, 5}; - wfe.nChannels = channels[h.acmod] + h.lfeon; - - static int freq[] = {48000, 44100, 32000, 0}; - wfe.nSamplesPerSec = freq[h.fscod]; - - switch(h.bsid) - { - case 9: - wfe.nSamplesPerSec >>= 1; - break; - case 10: - wfe.nSamplesPerSec >>= 2; - break; - case 11: - wfe.nSamplesPerSec >>= 3; - break; - default: - break; - } + memset(&h, 0, sizeof(h)); + + for(; len >= 7 && BitRead(16, true) != 0x0b77; len--) + BitRead(8); + + if(len < 7) + return(false); + + h.sync = (WORD)BitRead(16); + if(h.sync != 0x0B77) + return(false); + + h.crc1 = (WORD)BitRead(16); + h.fscod = BitRead(2); + h.frmsizecod = BitRead(6); + h.bsid = BitRead(5); + h.bsmod = BitRead(3); + h.acmod = BitRead(3); + if((h.acmod & 1) && h.acmod != 1) h.cmixlev = BitRead(2); + if(h.acmod & 4) h.surmixlev = BitRead(2); + if(h.acmod == 2) h.dsurmod = BitRead(2); + h.lfeon = BitRead(1); + + if(h.bsid >= 17 || h.fscod == 3 || h.frmsizecod >= 48) + return(false); + + if(!pmt) return(true); + + WAVEFORMATEX wfe; + memset(&wfe, 0, sizeof(wfe)); + wfe.wFormatTag = WAVE_FORMAT_DOLBY_AC3; - static int rate[] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 576, 640, 768, 896, 1024, 1152, 1280}; + static int channels[] = {2, 1, 2, 3, 3, 4, 4, 5}; + wfe.nChannels = channels[h.acmod] + h.lfeon; - wfe.nAvgBytesPerSec = (rate[h.frmsizecod>>1] * 1000) / 8; - wfe.nBlockAlign = (WORD)(1536 * wfe.nAvgBytesPerSec / wfe.nSamplesPerSec); + static int freq[] = {48000, 44100, 32000, 0}; + wfe.nSamplesPerSec = freq[h.fscod]; - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = MEDIASUBTYPE_DOLBY_AC3; - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); + switch(h.bsid) + { + case 9: wfe.nSamplesPerSec >>= 1; break; + case 10: wfe.nSamplesPerSec >>= 2; break; + case 11: wfe.nSamplesPerSec >>= 3; break; + default: break; + } - return(true); + static int rate[] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 576, 640, 768, 896, 1024, 1152, 1280}; + + wfe.nAvgBytesPerSec = (rate[h.frmsizecod>>1] * 1000) / 8; + wfe.nBlockAlign = (WORD)(1536 * wfe.nAvgBytesPerSec / wfe.nSamplesPerSec); + + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = MEDIASUBTYPE_DOLBY_AC3; + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); + + return(true); } bool CBaseSplitterFileEx::Read(dtshdr& h, int len, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - for(; len >= 10 && BitRead(32, true) != 0x7ffe8001; len--) - BitRead(8); + for(; len >= 10 && BitRead(32, true) != 0x7ffe8001; len--) + BitRead(8); - if(len < 10) - return(false); + if(len < 10) + return(false); - h.sync = (DWORD)BitRead(32); - h.frametype = BitRead(1); - h.deficitsamplecount = BitRead(5); - h.fcrc = BitRead(1); - h.nblocks = BitRead(7); - h.framebytes = (WORD)BitRead(14) + 1; - h.amode = BitRead(6); - h.sfreq = BitRead(4); - h.rate = BitRead(5); + h.sync = (DWORD)BitRead(32); + h.frametype = BitRead(1); + h.deficitsamplecount = BitRead(5); + h.fcrc = BitRead(1); + h.nblocks = BitRead(7); + h.framebytes = (WORD)BitRead(14)+1; + h.amode = BitRead(6); + h.sfreq = BitRead(4); + h.rate = BitRead(5); h.downmix = BitRead(1); h.dynrange = BitRead(1); @@ -724,1006 +675,981 @@ bool CBaseSplitterFileEx::Read(dtshdr& h, int len, CMediaType* pmt) h.predictor_history = BitRead(1); - if(!pmt) return(true); + if(!pmt) return(true); - WAVEFORMATEX wfe; - memset(&wfe, 0, sizeof(wfe)); - wfe.wFormatTag = WAVE_FORMAT_DVD_DTS; + WAVEFORMATEX wfe; + memset(&wfe, 0, sizeof(wfe)); + wfe.wFormatTag = WAVE_FORMAT_DVD_DTS; - static int channels[] = {1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8}; + static int channels[] = {1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8}; - if(h.amode < countof(channels)) - { - wfe.nChannels = channels[h.amode]; - if(h.lfe > 0) - ++wfe.nChannels; - } + if(h.amode < countof(channels)) + { + wfe.nChannels = channels[h.amode]; + if (h.lfe > 0) + ++wfe.nChannels; + } - static int freq[] = {0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0, 12000, 24000, 48000, 0, 0}; - wfe.nSamplesPerSec = freq[h.sfreq]; + static int freq[] = {0,8000,16000,32000,0,0,11025,22050,44100,0,0,12000,24000,48000,0,0}; + wfe.nSamplesPerSec = freq[h.sfreq]; - static int rate[] = - { - 32000, 56000, 64000, 96000, 112000, 128000, 192000, 224000, - 256000, 320000, 384000, 448000, 512000, 576000, 640000, 754500, - 960000, 1024000, 1152000, 1280000, 1344000, 1408000, 1411200, 1472000, - 1509750, 1920000, 2048000, 3072000, 3840000, 0, 0, 0 - }; + static int rate[] = + { + 32000,56000,64000,96000,112000,128000,192000,224000, + 256000,320000,384000,448000,512000,576000,640000,754500, + 960000,1024000,1152000,1280000,1344000,1408000,1411200,1472000, + 1509750,1920000,2048000,3072000,3840000,0,0,0 + }; - wfe.nAvgBytesPerSec = (rate[h.rate] + 4) / 8; - wfe.nBlockAlign = h.framebytes; + wfe.nAvgBytesPerSec = (rate[h.rate] + 4) / 8; + wfe.nBlockAlign = h.framebytes; - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = MEDIASUBTYPE_DTS; - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = MEDIASUBTYPE_DTS; + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); - return(true); + return(true); } bool CBaseSplitterFileEx::Read(hdmvlpcmhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - h.size = BitRead(16); - h.channels = BitRead(4); - h.samplerate = BitRead(4); - h.bitpersample = BitRead(2); + h.size = BitRead(16); + h.channels = BitRead(4); + h.samplerate = BitRead(4); + h.bitpersample = BitRead(2); - if(h.channels == 0 || h.channels == 2 || - (h.samplerate != 1 && h.samplerate != 4 && h.samplerate != 5) || - h.bitpersample < 0 || h.bitpersample > 3) - return(false); + if (h.channels==0 || h.channels==2 || + (h.samplerate != 1 && h.samplerate!= 4 && h.samplerate!= 5) || + h.bitpersample<0 || h.bitpersample>3) + return(false); - if(!pmt) return(true); + if(!pmt) return(true); - WAVEFORMATEX_HDMV_LPCM wfe; - wfe.wFormatTag = WAVE_FORMAT_PCM; + WAVEFORMATEX_HDMV_LPCM wfe; + wfe.wFormatTag = WAVE_FORMAT_PCM; - static int channels[] = {0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8}; - wfe.nChannels = channels[h.channels]; - wfe.channel_conf = h.channels; + static int channels[] = {0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8}; + wfe.nChannels = channels[h.channels]; + wfe.channel_conf = h.channels; - static int freq[] = {0, 48000, 0, 0, 96000, 192000}; - wfe.nSamplesPerSec = freq[h.samplerate]; + static int freq[] = {0, 48000, 0, 0, 96000, 192000}; + wfe.nSamplesPerSec = freq[h.samplerate]; - static int bitspersample[] = {0, 16, 20, 24}; - wfe.wBitsPerSample = bitspersample[h.bitpersample]; + static int bitspersample[] = {0, 16, 20, 24}; + wfe.wBitsPerSample = bitspersample[h.bitpersample]; - wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample >> 3; - wfe.nAvgBytesPerSec = wfe.nBlockAlign * wfe.nSamplesPerSec; + wfe.nBlockAlign = wfe.nChannels*wfe.wBitsPerSample>>3; + wfe.nAvgBytesPerSec = wfe.nBlockAlign*wfe.nSamplesPerSec; - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = MEDIASUBTYPE_HDMV_LPCM_AUDIO; - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = MEDIASUBTYPE_HDMV_LPCM_AUDIO; + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); - return(true); + return(true); } bool CBaseSplitterFileEx::Read(lpcmhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); - - h.emphasis = BitRead(1); - h.mute = BitRead(1); - h.reserved1 = BitRead(1); - h.framenum = BitRead(5); - h.quantwordlen = BitRead(2); - h.freq = BitRead(2); - h.reserved2 = BitRead(1); - h.channels = BitRead(3); - h.drc = (BYTE)BitRead(8); - - if(h.quantwordlen == 3 || h.reserved1 || h.reserved2) - return(false); - - if(!pmt) return(true); - - WAVEFORMATEX wfe; - memset(&wfe, 0, sizeof(wfe)); - wfe.wFormatTag = WAVE_FORMAT_PCM; - wfe.nChannels = h.channels + 1; - static int freq[] = {48000, 96000, 44100, 32000}; - wfe.nSamplesPerSec = freq[h.freq]; - switch(h.quantwordlen) - { - case 0: - wfe.wBitsPerSample = 16; - break; - case 1: - wfe.wBitsPerSample = 20; - break; - case 2: - wfe.wBitsPerSample = 24; - break; - } - wfe.nBlockAlign = (wfe.nChannels * 2 * wfe.wBitsPerSample) / 8; - wfe.nAvgBytesPerSec = (wfe.nBlockAlign * wfe.nSamplesPerSec) / 2; - - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = MEDIASUBTYPE_DVD_LPCM_AUDIO; - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); - - // TODO: what to do with dvd-audio lpcm? - - return(true); + memset(&h, 0, sizeof(h)); + + h.emphasis = BitRead(1); + h.mute = BitRead(1); + h.reserved1 = BitRead(1); + h.framenum = BitRead(5); + h.quantwordlen = BitRead(2); + h.freq = BitRead(2); + h.reserved2 = BitRead(1); + h.channels = BitRead(3); + h.drc = (BYTE)BitRead(8); + + if(h.quantwordlen == 3 || h.reserved1 || h.reserved2) + return(false); + + if(!pmt) return(true); + + WAVEFORMATEX wfe; + memset(&wfe, 0, sizeof(wfe)); + wfe.wFormatTag = WAVE_FORMAT_PCM; + wfe.nChannels = h.channels+1; + static int freq[] = {48000, 96000, 44100, 32000}; + wfe.nSamplesPerSec = freq[h.freq]; + switch (h.quantwordlen) + { + case 0: + wfe.wBitsPerSample = 16; + break; + case 1: + wfe.wBitsPerSample = 20; + break; + case 2: + wfe.wBitsPerSample = 24; + break; + } + wfe.nBlockAlign = (wfe.nChannels*2*wfe.wBitsPerSample) / 8; + wfe.nAvgBytesPerSec = (wfe.nBlockAlign*wfe.nSamplesPerSec) / 2; + + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = MEDIASUBTYPE_DVD_LPCM_AUDIO; + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); + + // TODO: what to do with dvd-audio lpcm? + + return(true); } bool CBaseSplitterFileEx::Read(dvdspuhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - if(!pmt) return(true); + if(!pmt) return(true); - pmt->majortype = MEDIATYPE_Video; - pmt->subtype = MEDIASUBTYPE_DVD_SUBPICTURE; - pmt->formattype = FORMAT_None; + pmt->majortype = MEDIATYPE_Video; + pmt->subtype = MEDIASUBTYPE_DVD_SUBPICTURE; + pmt->formattype = FORMAT_None; - return(true); + return(true); } bool CBaseSplitterFileEx::Read(hdmvsubhdr& h, CMediaType* pmt, const char* language_code) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - if(!pmt) return(true); + if(!pmt) return(true); - pmt->majortype = MEDIATYPE_Subtitle; - pmt->subtype = MEDIASUBTYPE_HDMVSUB; - pmt->formattype = FORMAT_None; + pmt->majortype = MEDIATYPE_Subtitle; + pmt->subtype = MEDIASUBTYPE_HDMVSUB; + pmt->formattype = FORMAT_None; - SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO)); - if(psi) - { - memset(psi, 0, pmt->FormatLength()); - strcpy(psi->IsoLang, language_code ? language_code : "eng"); - } + SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO)); + if (psi) + { + memset(psi, 0, pmt->FormatLength()); + strcpy(psi->IsoLang, language_code ? language_code : "eng"); + } - return(true); + return(true); } bool CBaseSplitterFileEx::Read(svcdspuhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - if(!pmt) return(true); + if(!pmt) return(true); - pmt->majortype = MEDIATYPE_Video; - pmt->subtype = MEDIASUBTYPE_SVCD_SUBPICTURE; - pmt->formattype = FORMAT_None; + pmt->majortype = MEDIATYPE_Video; + pmt->subtype = MEDIASUBTYPE_SVCD_SUBPICTURE; + pmt->formattype = FORMAT_None; - return(true); + return(true); } bool CBaseSplitterFileEx::Read(cvdspuhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - if(!pmt) return(true); + if(!pmt) return(true); - pmt->majortype = MEDIATYPE_Video; - pmt->subtype = MEDIASUBTYPE_CVD_SUBPICTURE; - pmt->formattype = FORMAT_None; + pmt->majortype = MEDIATYPE_Video; + pmt->subtype = MEDIASUBTYPE_CVD_SUBPICTURE; + pmt->formattype = FORMAT_None; - return(true); + return(true); } bool CBaseSplitterFileEx::Read(ps2audhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); - - if(BitRead(16, true) != 'SS') - return(false); - - __int64 pos = GetPos(); - - while(BitRead(16, true) == 'SS') - { - DWORD tag = (DWORD)BitRead(32, true); - DWORD size = 0; - - if(tag == 'SShd') - { - BitRead(32); - ByteRead((BYTE*)&size, sizeof(size)); - ASSERT(size == 0x18); - Seek(GetPos()); - ByteRead((BYTE*)&h, sizeof(h)); - } - else if(tag == 'SSbd') - { - BitRead(32); - ByteRead((BYTE*)&size, sizeof(size)); - break; - } - } - - Seek(pos); - - if(!pmt) return(true); - - WAVEFORMATEXPS2 wfe; - wfe.wFormatTag = - h.unk1 == 0x01 ? WAVE_FORMAT_PS2_PCM : - h.unk1 == 0x10 ? WAVE_FORMAT_PS2_ADPCM : - WAVE_FORMAT_UNKNOWN; - wfe.nChannels = (WORD)h.channels; - wfe.nSamplesPerSec = h.freq; - wfe.wBitsPerSample = 16; // always? - wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample >> 3; - wfe.nAvgBytesPerSec = wfe.nBlockAlign * wfe.nSamplesPerSec; - wfe.dwInterleave = h.interleave; - - pmt->majortype = MEDIATYPE_Audio; - pmt->subtype = FOURCCMap(wfe.wFormatTag); - pmt->formattype = FORMAT_WaveFormatEx; - pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); - - return(true); + memset(&h, 0, sizeof(h)); + + if(BitRead(16, true) != 'SS') + return(false); + + __int64 pos = GetPos(); + + while(BitRead(16, true) == 'SS') + { + DWORD tag = (DWORD)BitRead(32, true); + DWORD size = 0; + + if(tag == 'SShd') + { + BitRead(32); + ByteRead((BYTE*)&size, sizeof(size)); + ASSERT(size == 0x18); + Seek(GetPos()); + ByteRead((BYTE*)&h, sizeof(h)); + } + else if(tag == 'SSbd') + { + BitRead(32); + ByteRead((BYTE*)&size, sizeof(size)); + break; + } + } + + Seek(pos); + + if(!pmt) return(true); + + WAVEFORMATEXPS2 wfe; + wfe.wFormatTag = + h.unk1 == 0x01 ? WAVE_FORMAT_PS2_PCM : + h.unk1 == 0x10 ? WAVE_FORMAT_PS2_ADPCM : + WAVE_FORMAT_UNKNOWN; + wfe.nChannels = (WORD)h.channels; + wfe.nSamplesPerSec = h.freq; + wfe.wBitsPerSample = 16; // always? + wfe.nBlockAlign = wfe.nChannels*wfe.wBitsPerSample>>3; + wfe.nAvgBytesPerSec = wfe.nBlockAlign*wfe.nSamplesPerSec; + wfe.dwInterleave = h.interleave; + + pmt->majortype = MEDIATYPE_Audio; + pmt->subtype = FOURCCMap(wfe.wFormatTag); + pmt->formattype = FORMAT_WaveFormatEx; + pmt->SetFormat((BYTE*)&wfe, sizeof(wfe)); + + return(true); } bool CBaseSplitterFileEx::Read(ps2subhdr& h, CMediaType* pmt) { - memset(&h, 0, sizeof(h)); + memset(&h, 0, sizeof(h)); - if(!pmt) return(true); + if(!pmt) return(true); - pmt->majortype = MEDIATYPE_Subtitle; - pmt->subtype = MEDIASUBTYPE_PS2_SUB; - pmt->formattype = FORMAT_None; + pmt->majortype = MEDIATYPE_Subtitle; + pmt->subtype = MEDIASUBTYPE_PS2_SUB; + pmt->formattype = FORMAT_None; - return(true); + return(true); } bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync) { - memset(&h, 0, sizeof(h)); - - BitByteAlign(); - - if(m_tslen == 0) - { - __int64 pos = GetPos(); - - for(int i = 0; i < 192; i++) - { - if(BitRead(8, true) == 0x47) - { - __int64 pos = GetPos(); - Seek(pos + 188); - if(BitRead(8, true) == 0x47) - { - m_tslen = 188; // TS stream - break; - } - Seek(pos + 192); - if(BitRead(8, true) == 0x47) - { - m_tslen = 192; // M2TS stream - break; - } - } - - BitRead(8); - } - - Seek(pos); - - if(m_tslen == 0) - { - return(false); - } - } - - if(fSync) - { - for(int i = 0; i < m_tslen; i++) - { - if(BitRead(8, true) == 0x47) - { - if(i == 0) break; - Seek(GetPos() + m_tslen); - if(BitRead(8, true) == 0x47) - { - Seek(GetPos() - m_tslen); - break; - } - } - - BitRead(8); - - if(i == m_tslen - 1) - return(false); - } - } - - if(BitRead(8, true) != 0x47) - return(false); - - h.next = GetPos() + m_tslen; - - h.sync = (BYTE)BitRead(8); - h.error = BitRead(1); - h.payloadstart = BitRead(1); - h.transportpriority = BitRead(1); - h.pid = BitRead(13); - h.scrambling = BitRead(2); - h.adapfield = BitRead(1); - h.payload = BitRead(1); - h.counter = BitRead(4); - - h.bytes = 188 - 4; - - if(h.adapfield) - { - h.length = (BYTE)BitRead(8); - - if(h.length > 0) - { - h.discontinuity = BitRead(1); - h.randomaccess = BitRead(1); - h.priority = BitRead(1); - h.fPCR = BitRead(1); - h.OPCR = BitRead(1); - h.splicingpoint = BitRead(1); - h.privatedata = BitRead(1); - h.extension = BitRead(1); - - int i = 1; - - if(h.fPCR) - { - h.PCR = BitRead(33); - BitRead(6); - UINT64 PCRExt = BitRead(9); - h.PCR = (h.PCR * 300 + PCRExt) * 10 / 27; - i += 6; - } - - ASSERT(i <= h.length); - - for(; i < h.length; i++) - BitRead(8); - } - - h.bytes -= h.length + 1; - - if(h.bytes < 0) - { - ASSERT(0); - return false; - } - } - - return true; + memset(&h, 0, sizeof(h)); + + BitByteAlign(); + + if(m_tslen == 0) + { + __int64 pos = GetPos(); + + for(int i = 0; i < 192; i++) + { + if(BitRead(8, true) == 0x47) + { + __int64 pos = GetPos(); + Seek(pos + 188); + if(BitRead(8, true) == 0x47) {m_tslen = 188; break;} // TS stream + Seek(pos + 192); + if(BitRead(8, true) == 0x47) {m_tslen = 192; break;} // M2TS stream + } + + BitRead(8); + } + + Seek(pos); + + if(m_tslen == 0) + { + return(false); + } + } + + if(fSync) + { + for(int i = 0; i < m_tslen; i++) + { + if(BitRead(8, true) == 0x47) + { + if(i == 0) break; + Seek(GetPos()+m_tslen); + if(BitRead(8, true) == 0x47) {Seek(GetPos()-m_tslen); break;} + } + + BitRead(8); + + if(i == m_tslen-1) + return(false); + } + } + + if(BitRead(8, true) != 0x47) + return(false); + + h.next = GetPos() + m_tslen; + + h.sync = (BYTE)BitRead(8); + h.error = BitRead(1); + h.payloadstart = BitRead(1); + h.transportpriority = BitRead(1); + h.pid = BitRead(13); + h.scrambling = BitRead(2); + h.adapfield = BitRead(1); + h.payload = BitRead(1); + h.counter = BitRead(4); + + h.bytes = 188 - 4; + + if(h.adapfield) + { + h.length = (BYTE)BitRead(8); + + if(h.length > 0) + { + h.discontinuity = BitRead(1); + h.randomaccess = BitRead(1); + h.priority = BitRead(1); + h.fPCR = BitRead(1); + h.OPCR = BitRead(1); + h.splicingpoint = BitRead(1); + h.privatedata = BitRead(1); + h.extension = BitRead(1); + + int i = 1; + + if(h.fPCR) + { + h.PCR = BitRead(33); + BitRead(6); + UINT64 PCRExt = BitRead(9); + h.PCR = (h.PCR*300 + PCRExt) * 10 / 27; + i += 6; + } + + ASSERT(i <= h.length); + + for(; i < h.length; i++) + BitRead(8); + } + + h.bytes -= h.length+1; + + if(h.bytes < 0) {ASSERT(0); return false;} + } + + return true; } bool CBaseSplitterFileEx::Read(trsechdr& h) { - BYTE pointer_field = BitRead(8); - while(pointer_field-- > 0) BitRead(8); - h.table_id = BitRead(8); - h.section_syntax_indicator = BitRead(1); - h.zero = BitRead(1); - h.reserved1 = BitRead(2); - h.section_length = BitRead(12); - h.transport_stream_id = BitRead(16); - h.reserved2 = BitRead(2); - h.version_number = BitRead(5); - h.current_next_indicator = BitRead(1); - h.section_number = BitRead(8); - h.last_section_number = BitRead(8); - return h.section_syntax_indicator == 1 && h.zero == 0; + BYTE pointer_field = BitRead(8); + while(pointer_field-- > 0) BitRead(8); + h.table_id = BitRead(8); + h.section_syntax_indicator = BitRead(1); + h.zero = BitRead(1); + h.reserved1 = BitRead(2); + h.section_length = BitRead(12); + h.transport_stream_id = BitRead(16); + h.reserved2 = BitRead(2); + h.version_number = BitRead(5); + h.current_next_indicator = BitRead(1); + h.section_number = BitRead(8); + h.last_section_number = BitRead(8); + return h.section_syntax_indicator == 1 && h.zero == 0; } bool CBaseSplitterFileEx::Read(pvahdr& h, bool fSync) { - memset(&h, 0, sizeof(h)); - - BitByteAlign(); - - if(fSync) - { - for(int i = 0; i < 65536; i++) - { - if((BitRead(64, true) & 0xfffffc00ffe00000i64) == 0x4156000055000000i64) - break; - BitRead(8); - } - } - - if((BitRead(64, true) & 0xfffffc00ffe00000i64) != 0x4156000055000000i64) - return(false); - - h.sync = (WORD)BitRead(16); - h.streamid = (BYTE)BitRead(8); - h.counter = (BYTE)BitRead(8); - h.res1 = (BYTE)BitRead(8); - h.res2 = BitRead(3); - h.fpts = BitRead(1); - h.postbytes = BitRead(2); - h.prebytes = BitRead(2); - h.length = (WORD)BitRead(16); - - if(h.length > 6136) - return(false); - - __int64 pos = GetPos(); - - if(h.streamid == 1 && h.fpts) - { - h.pts = 10000 * BitRead(32) / 90 + m_rtPTSOffset; - } - else if(h.streamid == 2 && (h.fpts || (BitRead(32, true) & 0xffffffe0) == 0x000001c0)) - { - BYTE b; - if(!NextMpegStartCode(b, 4)) return(false); - peshdr h2; - if(!Read(h2, b)) return(false); - if(h.fpts = h2.fpts) h.pts = h2.pts; - } - - BitRead(8 * h.prebytes); - - h.length -= GetPos() - pos; - - return(true); + memset(&h, 0, sizeof(h)); + + BitByteAlign(); + + if(fSync) + { + for(int i = 0; i < 65536; i++) + { + if((BitRead(64, true)&0xfffffc00ffe00000i64) == 0x4156000055000000i64) + break; + BitRead(8); + } + } + + if((BitRead(64, true)&0xfffffc00ffe00000i64) != 0x4156000055000000i64) + return(false); + + h.sync = (WORD)BitRead(16); + h.streamid = (BYTE)BitRead(8); + h.counter = (BYTE)BitRead(8); + h.res1 = (BYTE)BitRead(8); + h.res2 = BitRead(3); + h.fpts = BitRead(1); + h.postbytes = BitRead(2); + h.prebytes = BitRead(2); + h.length = (WORD)BitRead(16); + + if(h.length > 6136) + return(false); + + __int64 pos = GetPos(); + + if(h.streamid == 1 && h.fpts) + { + h.pts = 10000*BitRead(32)/90 + m_rtPTSOffset; + } + else if(h.streamid == 2 && (h.fpts || (BitRead(32, true)&0xffffffe0) == 0x000001c0)) + { + BYTE b; + if(!NextMpegStartCode(b, 4)) return(false); + peshdr h2; + if(!Read(h2, b)) return(false); + if(h.fpts = h2.fpts) h.pts = h2.pts; + } + + BitRead(8*h.prebytes); + + h.length -= GetPos() - pos; + + return(true); } void CBaseSplitterFileEx::RemoveMpegEscapeCode(BYTE* dst, BYTE* src, int length) -{ - int si = 0; - int di = 0; - while(si + 2 < length) - { +{ + int si=0; + int di=0; + while(si+2 3) - { - dst[di++] = src[si++]; - dst[di++] = src[si++]; - } - else if(src[si] == 0 && src[si+1] == 0) - { - if(src[si+2] == 3) //escape - { - dst[di++] = 0; - dst[di++] = 0; - si += 3; + if(src[si+2]>3){ + dst[di++]= src[si++]; + dst[di++]= src[si++]; + }else if(src[si]==0 && src[si+1]==0){ + if(src[si+2]==3){ //escape + dst[di++]= 0; + dst[di++]= 0; + si+=3; continue; - } - else //next start code + }else //next start code return; } - dst[di++] = src[si++]; + dst[di++]= src[si++]; } } bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt) { - __int64 endpos = GetPos() + len; // - sequence header length + __int64 endpos = GetPos() + len; // - sequence header length - DWORD dwStartCode; + DWORD dwStartCode; - while(GetPos() < endpos + 4 && BitRead(32, true) == 0x00000001 && (!h.spslen || !h.ppslen)) - { - __int64 pos = GetPos(); + while(GetPos() < endpos+4 && BitRead(32, true) == 0x00000001 && (!h.spslen || !h.ppslen)) + { + __int64 pos = GetPos(); - BitRead(32); - BYTE id = BitRead(8); - - if((id & 0x9f) == 0x07 && (id & 0x60) != 0) - { + BitRead(32); + BYTE id = BitRead(8); + + if((id&0x9f) == 0x07 && (id&0x60) != 0) + { #if 1 - BYTE SPSTemp[MAX_SPS]; - BYTE SPSBuff[MAX_SPS]; - CGolombBuffer gb(SPSBuff, MAX_SPS); - __int64 num_units_in_tick; - __int64 time_scale; - long fixed_frame_rate_flag; - - h.spspos = pos; - - // Manage H264 escape codes (see "remove escapes (very rare 1:2^22)" in ffmpeg h264.c file) - ByteRead((BYTE*)SPSTemp, MAX_SPS); - RemoveMpegEscapeCode(SPSBuff, SPSTemp, MAX_SPS); - - h.profile = (BYTE)gb.BitRead(8); - gb.BitRead(8); - h.level = (BYTE)gb.BitRead(8); - - gb.UExpGolombRead(); // seq_parameter_set_id - - if(h.profile >= 100) // high profile - { - if(gb.UExpGolombRead() == 3) // chroma_format_idc - { - gb.BitRead(1); // residue_transform_flag - } - - gb.UExpGolombRead(); // bit_depth_luma_minus8 - gb.UExpGolombRead(); // bit_depth_chroma_minus8 - - gb.BitRead(1); // qpprime_y_zero_transform_bypass_flag - - if(gb.BitRead(1)) // seq_scaling_matrix_present_flag - for(int i = 0; i < 8; i++) - if(gb.BitRead(1)) // seq_scaling_list_present_flag - for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) - next = (next + gb.SExpGolombRead() + 256) & 255; - } - - gb.UExpGolombRead(); // log2_max_frame_num_minus4 - - UINT64 pic_order_cnt_type = gb.UExpGolombRead(); - - if(pic_order_cnt_type == 0) - { - gb.UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4 - } - else if(pic_order_cnt_type == 1) - { - gb.BitRead(1); // delta_pic_order_always_zero_flag - gb.SExpGolombRead(); // offset_for_non_ref_pic - gb.SExpGolombRead(); // offset_for_top_to_bottom_field - UINT64 num_ref_frames_in_pic_order_cnt_cycle = gb.UExpGolombRead(); - for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) - gb.SExpGolombRead(); // offset_for_ref_frame[i] - } - - gb.UExpGolombRead(); // num_ref_frames - gb.BitRead(1); // gaps_in_frame_num_value_allowed_flag - - UINT64 pic_width_in_mbs_minus1 = gb.UExpGolombRead(); - UINT64 pic_height_in_map_units_minus1 = gb.UExpGolombRead(); - BYTE frame_mbs_only_flag = (BYTE)gb.BitRead(1); - - h.width = (pic_width_in_mbs_minus1 + 1) * 16; - h.height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16; - - if(h.height == 1088) h.height = 1080; // Prevent blur lines - - if(!frame_mbs_only_flag) - gb.BitRead(1); // mb_adaptive_frame_field_flag - gb.BitRead(1); // direct_8x8_inference_flag - if(gb.BitRead(1)) // frame_cropping_flag - { - gb.UExpGolombRead(); // frame_cropping_rect_left_offset - gb.UExpGolombRead(); // frame_cropping_rect_right_offset - gb.UExpGolombRead(); // frame_cropping_rect_top_offset - gb.UExpGolombRead(); // frame_cropping_rect_bottom_offset - } - - if(gb.BitRead(1)) // vui_parameters_present_flag - { - if(gb.BitRead(1)) // aspect_ratio_info_present_flag - { - if(255 == (BYTE)gb.BitRead(8)) // aspect_ratio_idc) - { - gb.BitRead(16); // sar_width - gb.BitRead(16); // sar_height - } - } - - if(gb.BitRead(1)) // overscan_info_present_flag - { - gb.BitRead(1); // overscan_appropriate_flag - } - - if(gb.BitRead(1)) // video_signal_type_present_flag - { - gb.BitRead(3); // video_format - gb.BitRead(1); // video_full_range_flag - if(gb.BitRead(1)) // colour_description_present_flag - { - gb.BitRead(8); // colour_primaries - gb.BitRead(8); // transfer_characteristics - gb.BitRead(8); // matrix_coefficients - } - } - if(gb.BitRead(1)) // chroma_location_info_present_flag - { - gb.UExpGolombRead(); // chroma_sample_loc_type_top_field - gb.UExpGolombRead(); // chroma_sample_loc_type_bottom_field - } - if(gb.BitRead(1)) // timing_info_present_flag - { - num_units_in_tick = gb.BitRead(32); - time_scale = gb.BitRead(32); - fixed_frame_rate_flag = gb.BitRead(1); - - // Trick for weird parameters (10x to Madshi)! - if((num_units_in_tick < 1000) || (num_units_in_tick > 1001)) - { - if((time_scale % num_units_in_tick != 0) && ((time_scale * 1001) % num_units_in_tick == 0)) - { - time_scale = (time_scale * 1001) / num_units_in_tick; - num_units_in_tick = 1001; - } - else - { - time_scale = (time_scale * 1000) / num_units_in_tick; - num_units_in_tick = 1000; - } - } - time_scale = time_scale / 2; // VUI consider fields even for progressive stream : divide by 2! - - if(time_scale) - h.AvgTimePerFrame = (10000000I64 * num_units_in_tick) / time_scale; - } - } - - Seek(h.spspos + gb.GetPos()); + BYTE SPSTemp[MAX_SPS]; + BYTE SPSBuff[MAX_SPS]; + CGolombBuffer gb (SPSBuff, MAX_SPS); + __int64 num_units_in_tick; + __int64 time_scale; + long fixed_frame_rate_flag; + + h.spspos = pos; + + // Manage H264 escape codes (see "remove escapes (very rare 1:2^22)" in ffmpeg h264.c file) + ByteRead((BYTE*)SPSTemp, MAX_SPS); + RemoveMpegEscapeCode (SPSBuff, SPSTemp, MAX_SPS); + + h.profile = (BYTE)gb.BitRead(8); + gb.BitRead(8); + h.level = (BYTE)gb.BitRead(8); + + gb.UExpGolombRead(); // seq_parameter_set_id + + if(h.profile >= 100) // high profile + { + if(gb.UExpGolombRead() == 3) // chroma_format_idc + { + gb.BitRead(1); // residue_transform_flag + } + + gb.UExpGolombRead(); // bit_depth_luma_minus8 + gb.UExpGolombRead(); // bit_depth_chroma_minus8 + + gb.BitRead(1); // qpprime_y_zero_transform_bypass_flag + + if(gb.BitRead(1)) // seq_scaling_matrix_present_flag + for(int i = 0; i < 8; i++) + if(gb.BitRead(1)) // seq_scaling_list_present_flag + for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) + next = (next + gb.SExpGolombRead() + 256) & 255; + } + + gb.UExpGolombRead(); // log2_max_frame_num_minus4 + + UINT64 pic_order_cnt_type = gb.UExpGolombRead(); + + if(pic_order_cnt_type == 0) + { + gb.UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4 + } + else if(pic_order_cnt_type == 1) + { + gb.BitRead(1); // delta_pic_order_always_zero_flag + gb.SExpGolombRead(); // offset_for_non_ref_pic + gb.SExpGolombRead(); // offset_for_top_to_bottom_field + UINT64 num_ref_frames_in_pic_order_cnt_cycle = gb.UExpGolombRead(); + for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) + gb.SExpGolombRead(); // offset_for_ref_frame[i] + } + + gb.UExpGolombRead(); // num_ref_frames + gb.BitRead(1); // gaps_in_frame_num_value_allowed_flag + + UINT64 pic_width_in_mbs_minus1 = gb.UExpGolombRead(); + UINT64 pic_height_in_map_units_minus1 = gb.UExpGolombRead(); + BYTE frame_mbs_only_flag = (BYTE)gb.BitRead(1); + + h.width = (pic_width_in_mbs_minus1 + 1) * 16; + h.height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16; + + if (h.height == 1088) h.height = 1080; // Prevent blur lines + + if (!frame_mbs_only_flag) + gb.BitRead(1); // mb_adaptive_frame_field_flag + gb.BitRead(1); // direct_8x8_inference_flag + if (gb.BitRead(1)) // frame_cropping_flag + { + gb.UExpGolombRead(); // frame_cropping_rect_left_offset + gb.UExpGolombRead(); // frame_cropping_rect_right_offset + gb.UExpGolombRead(); // frame_cropping_rect_top_offset + gb.UExpGolombRead(); // frame_cropping_rect_bottom_offset + } + + if (gb.BitRead(1)) // vui_parameters_present_flag + { + if (gb.BitRead(1)) // aspect_ratio_info_present_flag + { + if (255==(BYTE)gb.BitRead(8)) // aspect_ratio_idc) + { + gb.BitRead(16); // sar_width + gb.BitRead(16); // sar_height + } + } + + if (gb.BitRead(1)) // overscan_info_present_flag + { + gb.BitRead(1); // overscan_appropriate_flag + } + + if (gb.BitRead(1)) // video_signal_type_present_flag + { + gb.BitRead(3); // video_format + gb.BitRead(1); // video_full_range_flag + if(gb.BitRead(1)) // colour_description_present_flag + { + gb.BitRead(8); // colour_primaries + gb.BitRead(8); // transfer_characteristics + gb.BitRead(8); // matrix_coefficients + } + } + if(gb.BitRead(1)) // chroma_location_info_present_flag + { + gb.UExpGolombRead(); // chroma_sample_loc_type_top_field + gb.UExpGolombRead(); // chroma_sample_loc_type_bottom_field + } + if (gb.BitRead(1)) // timing_info_present_flag + { + num_units_in_tick = gb.BitRead(32); + time_scale = gb.BitRead(32); + fixed_frame_rate_flag = gb.BitRead(1); + + // Trick for weird parameters (10x to Madshi)! + if ((num_units_in_tick < 1000) || (num_units_in_tick > 1001)) + { + if ((time_scale % num_units_in_tick != 0) && ((time_scale*1001) % num_units_in_tick == 0)) + { + time_scale = (time_scale * 1001) / num_units_in_tick; + num_units_in_tick = 1001; + } + else + { + time_scale = (time_scale * 1000) / num_units_in_tick; + num_units_in_tick = 1000; + } + } + time_scale = time_scale / 2; // VUI consider fields even for progressive stream : divide by 2! + + if (time_scale) + h.AvgTimePerFrame = (10000000I64*num_units_in_tick)/time_scale; + } + } + + Seek(h.spspos+gb.GetPos()); #else - __int64 num_units_in_tick; - __int64 time_scale; - long fixed_frame_rate_flag; - - h.spspos = pos; - - h.profile = (BYTE)BitRead(8); - BitRead(8); - h.level = (BYTE)BitRead(8); - - UExpGolombRead(); // seq_parameter_set_id - - if(h.profile >= 100) // high profile - { - if(UExpGolombRead() == 3) // chroma_format_idc - { - BitRead(1); // residue_transform_flag - } - - UExpGolombRead(); // bit_depth_luma_minus8 - UExpGolombRead(); // bit_depth_chroma_minus8 - - BitRead(1); // qpprime_y_zero_transform_bypass_flag - - if(BitRead(1)) // seq_scaling_matrix_present_flag - for(int i = 0; i < 8; i++) - if(BitRead(1)) // seq_scaling_list_present_flag - for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) - next = (next + SExpGolombRead() + 256) & 255; - } - - UExpGolombRead(); // log2_max_frame_num_minus4 - - UINT64 pic_order_cnt_type = UExpGolombRead(); - - if(pic_order_cnt_type == 0) - { - UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4 - } - else if(pic_order_cnt_type == 1) - { - BitRead(1); // delta_pic_order_always_zero_flag - SExpGolombRead(); // offset_for_non_ref_pic - SExpGolombRead(); // offset_for_top_to_bottom_field - UINT64 num_ref_frames_in_pic_order_cnt_cycle = UExpGolombRead(); - for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) - SExpGolombRead(); // offset_for_ref_frame[i] - } - - UExpGolombRead(); // num_ref_frames - BitRead(1); // gaps_in_frame_num_value_allowed_flag - - UINT64 pic_width_in_mbs_minus1 = UExpGolombRead(); - UINT64 pic_height_in_map_units_minus1 = UExpGolombRead(); - BYTE frame_mbs_only_flag = (BYTE)BitRead(1); - - h.width = (pic_width_in_mbs_minus1 + 1) * 16; - h.height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16; - - if(h.height == 1088) h.height = 1080; // Prevent blur lines - - if(!frame_mbs_only_flag) - BitRead(1); // mb_adaptive_frame_field_flag - BitRead(1); // direct_8x8_inference_flag - if(BitRead(1)) // frame_cropping_flag - { - UExpGolombRead(); // frame_cropping_rect_left_offset - UExpGolombRead(); // frame_cropping_rect_right_offset - UExpGolombRead(); // frame_cropping_rect_top_offset - UExpGolombRead(); // frame_cropping_rect_bottom_offset - } - - if(BitRead(1)) // vui_parameters_present_flag - { - if(BitRead(1)) // aspect_ratio_info_present_flag - { - if(255 == (BYTE)BitRead(8)) // aspect_ratio_idc) - { - BitRead(16); // sar_width - BitRead(16); // sar_height - } - } - - if(BitRead(1)) // overscan_info_present_flag - { - BitRead(1); // overscan_appropriate_flag - } - - if(BitRead(1)) // video_signal_type_present_flag - { - BitRead(3); // video_format - BitRead(1); // video_full_range_flag - if(BitRead(1)) // colour_description_present_flag - { - BitRead(8); // colour_primaries - BitRead(8); // transfer_characteristics - BitRead(8); // matrix_coefficients - } - } - if(BitRead(1)) // chroma_location_info_present_flag - { - UExpGolombRead(); // chroma_sample_loc_type_top_field - UExpGolombRead(); // chroma_sample_loc_type_bottom_field - } - if(BitRead(1)) // timing_info_present_flag - { - num_units_in_tick = BitRead(32); - time_scale = BitRead(32); - fixed_frame_rate_flag = BitRead(1); - - // Trick for weird parameters (10x to Madshi)! - if((num_units_in_tick < 1000) || (num_units_in_tick > 1001)) - { - if((time_scale % num_units_in_tick != 0) && ((time_scale * 1001) % num_units_in_tick == 0)) - { - time_scale = (time_scale * 1001) / num_units_in_tick; - num_units_in_tick = 1001; - } - else - { - time_scale = (time_scale * 1000) / num_units_in_tick; - num_units_in_tick = 1000; - } - } - time_scale = time_scale / 2; // VUI consider fields even for progressive stream : divide by 2! - - if(time_scale) - h.AvgTimePerFrame = (10000000I64 * num_units_in_tick) / time_scale; - } - } + __int64 num_units_in_tick; + __int64 time_scale; + long fixed_frame_rate_flag; + + h.spspos = pos; + + h.profile = (BYTE)BitRead(8); + BitRead(8); + h.level = (BYTE)BitRead(8); + + UExpGolombRead(); // seq_parameter_set_id + + if(h.profile >= 100) // high profile + { + if(UExpGolombRead() == 3) // chroma_format_idc + { + BitRead(1); // residue_transform_flag + } + + UExpGolombRead(); // bit_depth_luma_minus8 + UExpGolombRead(); // bit_depth_chroma_minus8 + + BitRead(1); // qpprime_y_zero_transform_bypass_flag + + if(BitRead(1)) // seq_scaling_matrix_present_flag + for(int i = 0; i < 8; i++) + if(BitRead(1)) // seq_scaling_list_present_flag + for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) + next = (next + SExpGolombRead() + 256) & 255; + } + + UExpGolombRead(); // log2_max_frame_num_minus4 + + UINT64 pic_order_cnt_type = UExpGolombRead(); + + if(pic_order_cnt_type == 0) + { + UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4 + } + else if(pic_order_cnt_type == 1) + { + BitRead(1); // delta_pic_order_always_zero_flag + SExpGolombRead(); // offset_for_non_ref_pic + SExpGolombRead(); // offset_for_top_to_bottom_field + UINT64 num_ref_frames_in_pic_order_cnt_cycle = UExpGolombRead(); + for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) + SExpGolombRead(); // offset_for_ref_frame[i] + } + + UExpGolombRead(); // num_ref_frames + BitRead(1); // gaps_in_frame_num_value_allowed_flag + + UINT64 pic_width_in_mbs_minus1 = UExpGolombRead(); + UINT64 pic_height_in_map_units_minus1 = UExpGolombRead(); + BYTE frame_mbs_only_flag = (BYTE)BitRead(1); + + h.width = (pic_width_in_mbs_minus1 + 1) * 16; + h.height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16; + + if (h.height == 1088) h.height = 1080; // Prevent blur lines + + if (!frame_mbs_only_flag) + BitRead(1); // mb_adaptive_frame_field_flag + BitRead(1); // direct_8x8_inference_flag + if (BitRead(1)) // frame_cropping_flag + { + UExpGolombRead(); // frame_cropping_rect_left_offset + UExpGolombRead(); // frame_cropping_rect_right_offset + UExpGolombRead(); // frame_cropping_rect_top_offset + UExpGolombRead(); // frame_cropping_rect_bottom_offset + } + + if (BitRead(1)) // vui_parameters_present_flag + { + if (BitRead(1)) // aspect_ratio_info_present_flag + { + if (255==(BYTE)BitRead(8)) // aspect_ratio_idc) + { + BitRead(16); // sar_width + BitRead(16); // sar_height + } + } + + if (BitRead(1)) // overscan_info_present_flag + { + BitRead(1); // overscan_appropriate_flag + } + + if (BitRead(1)) // video_signal_type_present_flag + { + BitRead(3); // video_format + BitRead(1); // video_full_range_flag + if(BitRead(1)) // colour_description_present_flag + { + BitRead(8); // colour_primaries + BitRead(8); // transfer_characteristics + BitRead(8); // matrix_coefficients + } + } + if(BitRead(1)) // chroma_location_info_present_flag + { + UExpGolombRead(); // chroma_sample_loc_type_top_field + UExpGolombRead(); // chroma_sample_loc_type_bottom_field + } + if (BitRead(1)) // timing_info_present_flag + { + num_units_in_tick = BitRead(32); + time_scale = BitRead(32); + fixed_frame_rate_flag = BitRead(1); + + // Trick for weird parameters (10x to Madshi)! + if ((num_units_in_tick < 1000) || (num_units_in_tick > 1001)) + { + if ((time_scale % num_units_in_tick != 0) && ((time_scale*1001) % num_units_in_tick == 0)) + { + time_scale = (time_scale * 1001) / num_units_in_tick; + num_units_in_tick = 1001; + } + else + { + time_scale = (time_scale * 1000) / num_units_in_tick; + num_units_in_tick = 1000; + } + } + time_scale = time_scale / 2; // VUI consider fields even for progressive stream : divide by 2! + + if (time_scale) + h.AvgTimePerFrame = (10000000I64*num_units_in_tick)/time_scale; + } + } #endif - } - else if((id & 0x9f) == 0x08 && (id & 0x60) != 0) - { - h.ppspos = pos; - } + } + else if((id&0x9f) == 0x08 && (id&0x60) != 0) + { + h.ppspos = pos; + } - BitByteAlign(); + BitByteAlign(); - dwStartCode = BitRead(32, true); - while(GetPos() < endpos + 4 && (dwStartCode != 0x00000001) && (dwStartCode & 0xFFFFFF00) != 0x00000100) - { - BitRead(8); - dwStartCode = BitRead(32, true); - } + dwStartCode = BitRead(32, true); + while(GetPos() < endpos+4 && (dwStartCode != 0x00000001) && (dwStartCode & 0xFFFFFF00) != 0x00000100) + { + BitRead(8); + dwStartCode = BitRead(32, true); + } - if(h.spspos != 0 && h.spslen == 0) - h.spslen = GetPos() - h.spspos; - else if(h.ppspos != 0 && h.ppslen == 0) - h.ppslen = GetPos() - h.ppspos; + if(h.spspos != 0 && h.spslen == 0) + h.spslen = GetPos() - h.spspos; + else if(h.ppspos != 0 && h.ppslen == 0) + h.ppslen = GetPos() - h.ppspos; - } + } - if(!h.spspos || !h.spslen || !h.ppspos || !h.ppslen) - return(false); + if(!h.spspos || !h.spslen || !h.ppspos || !h.ppslen) + return(false); - if(!pmt) return(true); + if(!pmt) return(true); - { - int extra = 2 + h.spslen - 4 + 2 + h.ppslen - 4; + { + int extra = 2+h.spslen-4 + 2+h.ppslen-4; - pmt->majortype = MEDIATYPE_Video; - pmt->subtype = FOURCCMap('1CVA'); + pmt->majortype = MEDIATYPE_Video; + pmt->subtype = FOURCCMap('1CVA'); //pmt->subtype = MEDIASUBTYPE_H264; // TODO : put MEDIASUBTYPE_H264 to support Windows 7 decoder ! - pmt->formattype = FORMAT_MPEG2_VIDEO; - int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + extra; - MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len]; - memset(vi, 0, len); - // vi->hdr.dwBitRate = ; - vi->hdr.AvgTimePerFrame = h.AvgTimePerFrame; - vi->hdr.dwPictAspectRatioX = h.width; - vi->hdr.dwPictAspectRatioY = h.height; - vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); - vi->hdr.bmiHeader.biWidth = h.width; - vi->hdr.bmiHeader.biHeight = h.height; - vi->hdr.bmiHeader.biCompression = '1CVA'; - vi->dwProfile = h.profile; - vi->dwFlags = 4; // ? - vi->dwLevel = h.level; - vi->cbSequenceHeader = extra; - BYTE* p = (BYTE*)&vi->dwSequenceHeader[0]; - *p++ = (h.spslen - 4) >> 8; - *p++ = (h.spslen - 4) & 0xff; - Seek(h.spspos + 4); - ByteRead(p, h.spslen - 4); - p += h.spslen - 4; - *p++ = (h.ppslen - 4) >> 8; - *p++ = (h.ppslen - 4) & 0xff; - Seek(h.ppspos + 4); - ByteRead(p, h.ppslen - 4); - p += h.ppslen - 4; - pmt->SetFormat((BYTE*)vi, len); - delete [] vi; - } - - return(true); + pmt->formattype = FORMAT_MPEG2_VIDEO; + int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + extra; + MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len]; + memset(vi, 0, len); + // vi->hdr.dwBitRate = ; + vi->hdr.AvgTimePerFrame = h.AvgTimePerFrame; + vi->hdr.dwPictAspectRatioX = h.width; + vi->hdr.dwPictAspectRatioY = h.height; + vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); + vi->hdr.bmiHeader.biWidth = h.width; + vi->hdr.bmiHeader.biHeight = h.height; + vi->hdr.bmiHeader.biCompression = '1CVA'; + vi->dwProfile = h.profile; + vi->dwFlags = 4; // ? + vi->dwLevel = h.level; + vi->cbSequenceHeader = extra; + BYTE* p = (BYTE*)&vi->dwSequenceHeader[0]; + *p++ = (h.spslen-4) >> 8; + *p++ = (h.spslen-4) & 0xff; + Seek(h.spspos+4); + ByteRead(p, h.spslen-4); + p += h.spslen-4; + *p++ = (h.ppslen-4) >> 8; + *p++ = (h.ppslen-4) & 0xff; + Seek(h.ppspos+4); + ByteRead(p, h.ppslen-4); + p += h.ppslen-4; + pmt->SetFormat((BYTE*)vi, len); + delete [] vi; + } + + return(true); } bool CBaseSplitterFileEx::Read(vc1hdr& h, int len, CMediaType* pmt) { - __int64 endpos = GetPos() + len; // - sequence header length - __int64 extrapos = 0, extralen = 0; - int nFrameRateNum = 0, nFrameRateDen = 1; - - if(GetPos() < endpos + 4 && BitRead(32, true) == 0x0000010F) - { - extrapos = GetPos(); - - BitRead(32); - - h.profile = BitRead(2); - - // Check if advanced profile - if(h.profile != 3) return(false); - - h.level = BitRead(3); - h.chromaformat = BitRead(2); - - // (fps-2)/4 (->30) - h.frmrtq_postproc = BitRead(3); //common - // (bitrate-32kbps)/64kbps - h.bitrtq_postproc = BitRead(5); //common - h.postprocflag = BitRead(1); //common - - h.width = (BitRead(12) + 1) << 1; - h.height = (BitRead(12) + 1) << 1; - - h.broadcast = BitRead(1); - h.interlace = BitRead(1); - h.tfcntrflag = BitRead(1); - h.finterpflag = BitRead(1); - BitRead(1); // reserved - h.psf = BitRead(1); - if(BitRead(1)) - { - int ar = 0; - h.ArX = BitRead(14) + 1; - h.ArY = BitRead(14) + 1; - if(BitRead(1)) - ar = BitRead(4); - // TODO : next is not the true A/R! - if(ar && ar < 14) - { + __int64 endpos = GetPos() + len; // - sequence header length + __int64 extrapos = 0, extralen = 0; + int nFrameRateNum = 0, nFrameRateDen = 1; + + if (GetPos() < endpos+4 && BitRead(32, true) == 0x0000010F) + { + extrapos = GetPos(); + + BitRead(32); + + h.profile = BitRead(2); + + // Check if advanced profile + if (h.profile != 3) return(false); + + h.level = BitRead (3); + h.chromaformat = BitRead (2); + + // (fps-2)/4 (->30) + h.frmrtq_postproc = BitRead (3); //common + // (bitrate-32kbps)/64kbps + h.bitrtq_postproc = BitRead (5); //common + h.postprocflag = BitRead (1); //common + + h.width = (BitRead (12) + 1) << 1; + h.height = (BitRead (12) + 1) << 1; + + h.broadcast = BitRead (1); + h.interlace = BitRead (1); + h.tfcntrflag = BitRead (1); + h.finterpflag = BitRead (1); + BitRead (1); // reserved + h.psf = BitRead (1); + if(BitRead (1)) + { + int ar = 0; + h.ArX = BitRead (14) + 1; + h.ArY = BitRead (14) + 1; + if(BitRead (1)) + ar = BitRead (4); + // TODO : next is not the true A/R! + if(ar && ar < 14) + { // h.ArX = ff_vc1_pixel_aspect[ar].num; // h.ArY = ff_vc1_pixel_aspect[ar].den; - } - else if(ar == 15) - { - /*h.ArX =*/ BitRead(8); - /*h.ArY =*/ - BitRead(8); - } - - // Read framerate - const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 }, - ff_vc1_fps_dr[2] = { 1000, 1001 }; - - if(BitRead(1)) - { - if(BitRead(1)) - { - nFrameRateNum = 32; - nFrameRateDen = BitRead(16) + 1; - } - else - { - int nr, dr; - nr = BitRead(8); - dr = BitRead(4); - if(nr && nr < 8 && dr && dr < 3) - { - nFrameRateNum = ff_vc1_fps_dr[dr - 1]; - nFrameRateDen = ff_vc1_fps_nr[nr - 1] * 1000; - } - } - } - - } - - Seek(extrapos + 4); - extralen = 0; - long parse = 0; - - while(GetPos() < endpos + 4 && ((parse == 0x0000010E) || (parse & 0xFFFFFF00) != 0x00000100)) - { - parse = (parse << 8) | BitRead(8); - extralen++; - } - } - - if(!extrapos || !extralen) - return(false); - - if(!pmt) return(true); - - { - //pmt->majortype = MEDIATYPE_Video; - //pmt->subtype = FOURCCMap('1CVW'); - //pmt->formattype = FORMAT_MPEG2_VIDEO; - //int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + extralen + 1; - //MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len]; - //memset(vi, 0, len); - //// vi->hdr.dwBitRate = ; - //vi->hdr.AvgTimePerFrame = (10000000I64*nFrameRateNum)/nFrameRateDen; - //vi->hdr.dwPictAspectRatioX = h.width; - //vi->hdr.dwPictAspectRatioY = h.height; - //vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); - //vi->hdr.bmiHeader.biWidth = h.width; - //vi->hdr.bmiHeader.biHeight = h.height; - //vi->hdr.bmiHeader.biCompression = '1CVW'; - //vi->dwProfile = h.profile; - //vi->dwFlags = 4; // ? - //vi->dwLevel = h.level; - //vi->cbSequenceHeader = extralen+1; - //BYTE* p = (BYTE*)&vi->dwSequenceHeader[0]; - //*p++ = 0; - //Seek(extrapos); - //ByteRead(p, extralen); - //pmt->SetFormat((BYTE*)vi, len); - //delete [] vi; - - pmt->majortype = MEDIATYPE_Video; - pmt->subtype = FOURCCMap('1CVW'); - pmt->formattype = FORMAT_VIDEOINFO2; - int len = sizeof(VIDEOINFOHEADER2) + extralen + 1; - VIDEOINFOHEADER2* vi = (VIDEOINFOHEADER2*)DNew BYTE[len]; - memset(vi, 0, len); - vi->AvgTimePerFrame = (10000000I64 * nFrameRateNum) / nFrameRateDen; - vi->dwPictAspectRatioX = h.width; - vi->dwPictAspectRatioY = h.height; - vi->bmiHeader.biSize = sizeof(vi->bmiHeader); - vi->bmiHeader.biWidth = h.width; - vi->bmiHeader.biHeight = h.height; - vi->bmiHeader.biCompression = '1CVW'; - BYTE* p = (BYTE*)vi + sizeof(VIDEOINFOHEADER2); - *p++ = 0; - Seek(extrapos); - ByteRead(p, extralen); - pmt->SetFormat((BYTE*)vi, len); - delete [] vi; - } - - return(true); + } + else if(ar == 15) + { + /*h.ArX =*/ BitRead (8); + /*h.ArY =*/ BitRead (8); + } + + // Read framerate + const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 }, + ff_vc1_fps_dr[2] = { 1000, 1001 }; + + if(BitRead (1)) + { + if(BitRead (1)) + { + nFrameRateNum = 32; + nFrameRateDen = BitRead (16) + 1; + } else { + int nr, dr; + nr = BitRead (8); + dr = BitRead (4); + if(nr && nr < 8 && dr && dr < 3) + { + nFrameRateNum = ff_vc1_fps_dr[dr - 1]; + nFrameRateDen = ff_vc1_fps_nr[nr - 1] * 1000; + } + } + } + + } + + Seek(extrapos+4); + extralen = 0; + long parse = 0; + + while (GetPos() < endpos+4 && ((parse == 0x0000010E) || (parse & 0xFFFFFF00) != 0x00000100)) + { + parse = (parse<<8) | BitRead(8); + extralen++; + } + } + + if(!extrapos || !extralen) + return(false); + + if(!pmt) return(true); + + { + //pmt->majortype = MEDIATYPE_Video; + //pmt->subtype = FOURCCMap('1CVW'); + //pmt->formattype = FORMAT_MPEG2_VIDEO; + //int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + extralen + 1; + //MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len]; + //memset(vi, 0, len); + //// vi->hdr.dwBitRate = ; + //vi->hdr.AvgTimePerFrame = (10000000I64*nFrameRateNum)/nFrameRateDen; + //vi->hdr.dwPictAspectRatioX = h.width; + //vi->hdr.dwPictAspectRatioY = h.height; + //vi->hdr.bmiHeader.biSize = sizeof(vi->hdr.bmiHeader); + //vi->hdr.bmiHeader.biWidth = h.width; + //vi->hdr.bmiHeader.biHeight = h.height; + //vi->hdr.bmiHeader.biCompression = '1CVW'; + //vi->dwProfile = h.profile; + //vi->dwFlags = 4; // ? + //vi->dwLevel = h.level; + //vi->cbSequenceHeader = extralen+1; + //BYTE* p = (BYTE*)&vi->dwSequenceHeader[0]; + //*p++ = 0; + //Seek(extrapos); + //ByteRead(p, extralen); + //pmt->SetFormat((BYTE*)vi, len); + //delete [] vi; + + pmt->majortype = MEDIATYPE_Video; + pmt->subtype = FOURCCMap('1CVW'); + pmt->formattype = FORMAT_VIDEOINFO2; + int len = sizeof(VIDEOINFOHEADER2) + extralen + 1; + VIDEOINFOHEADER2* vi = (VIDEOINFOHEADER2*)DNew BYTE[len]; + memset(vi, 0, len); + vi->AvgTimePerFrame = (10000000I64*nFrameRateNum)/nFrameRateDen; + vi->dwPictAspectRatioX = h.width; + vi->dwPictAspectRatioY = h.height; + vi->bmiHeader.biSize = sizeof(vi->bmiHeader); + vi->bmiHeader.biWidth = h.width; + vi->bmiHeader.biHeight = h.height; + vi->bmiHeader.biCompression = '1CVW'; + BYTE* p = (BYTE*)vi + sizeof(VIDEOINFOHEADER2); + *p++ = 0; + Seek(extrapos); + ByteRead(p, extralen); + pmt->SetFormat((BYTE*)vi, len); + delete [] vi; + } + + return(true); } bool CBaseSplitterFileEx::Read(dvbsub& h, int len, CMediaType* pmt) { - __int64 endpos = GetPos() + len; // - sequence header length - __int64 extrapos = 0, extralen = 0; - int nFrameRateNum = 0, nFrameRateDen = 1; + __int64 endpos = GetPos() + len; // - sequence header length + __int64 extrapos = 0, extralen = 0; + int nFrameRateNum = 0, nFrameRateDen = 1; - if((BitRead(32, true) & 0xFFFFFF00) == 0x20000f00) - { - static const SUBTITLEINFO SubFormat = { 0, "", L"" }; + if ((BitRead(32, true) & 0xFFFFFF00) == 0x20000f00) + { + static const SUBTITLEINFO SubFormat = { 0, "", L"" }; - pmt->majortype = MEDIATYPE_Subtitle; - pmt->subtype = MEDIASUBTYPE_DVB_SUBTITLES; - pmt->formattype = FORMAT_None; - pmt->SetFormat((BYTE*)&SubFormat, sizeof(SUBTITLEINFO)); + pmt->majortype = MEDIATYPE_Subtitle; + pmt->subtype = MEDIASUBTYPE_DVB_SUBTITLES; + pmt->formattype = FORMAT_None; + pmt->SetFormat ((BYTE*)&SubFormat, sizeof(SUBTITLEINFO)); - return true; - } + return true; + } - return false; + return false; } /* diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h index 7cb0ae0d6..72f604c85 100644 --- a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h +++ b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -25,363 +25,360 @@ class CBaseSplitterFileEx : public CBaseSplitterFile { - int m_tslen; // transport stream packet length (188 or 192 bytes, auto-detected) + int m_tslen; // transport stream packet length (188 or 192 bytes, auto-detected) protected : - REFERENCE_TIME m_rtPTSOffset; + REFERENCE_TIME m_rtPTSOffset; public: - CBaseSplitterFileEx(IAsyncReader* pReader, HRESULT& hr, int cachelen = DEFAULT_CACHE_LENGTH, bool fRandomAccess = true, bool fStreaming = false); - virtual ~CBaseSplitterFileEx(); + CBaseSplitterFileEx(IAsyncReader* pReader, HRESULT& hr, int cachelen = DEFAULT_CACHE_LENGTH, bool fRandomAccess = true, bool fStreaming = false); + virtual ~CBaseSplitterFileEx(); - // using CBaseSplitterFile::Read; + // using CBaseSplitterFile::Read; - bool NextMpegStartCode(BYTE& b, __int64 len = 65536); + bool NextMpegStartCode(BYTE& b, __int64 len = 65536); #pragma pack(push, 1) - enum mpeg_t {mpegunk, mpeg1, mpeg2}; - - struct pshdr - { - mpeg_t type; - UINT64 scr, bitrate; - }; - - struct pssyshdr - { - DWORD rate_bound; - BYTE video_bound, audio_bound; - bool fixed_rate, csps; - bool sys_video_loc_flag, sys_audio_loc_flag; - }; - - struct peshdr - { - WORD len; - - BYTE type: 2, fpts: 1, fdts: 1; - REFERENCE_TIME pts, dts; - - // mpeg1 stuff - UINT64 std_buff_size; - - // mpeg2 stuff - BYTE scrambling: 2, priority: 1, alignment: 1, copyright: 1, original: 1; - BYTE escr: 1, esrate: 1, dsmtrickmode: 1, morecopyright: 1, crc: 1, extension: 1; - BYTE hdrlen; - - struct peshdr() - { - memset(this, 0, sizeof(*this)); - } - }; - - class seqhdr - { - public: - WORD width; - WORD height; - BYTE ar: 4; - DWORD ifps; - DWORD bitrate; - DWORD vbv; - BYTE constrained: 1; - BYTE fiqm: 1; - BYTE iqm[64]; - BYTE fniqm: 1; - BYTE niqm[64]; - // ext - BYTE startcodeid: 4; - BYTE profile_levelescape: 1; - BYTE profile: 3; - BYTE level: 4; - BYTE progressive: 1; - BYTE chroma: 2; - BYTE lowdelay: 1; - // misc - int arx, ary; - }; - - class mpahdr - { - public: - WORD sync: 11; - WORD version: 2; - WORD layer: 2; - WORD crc: 1; - WORD bitrate: 4; - WORD freq: 2; - WORD padding: 1; - WORD privatebit: 1; - WORD channels: 2; - WORD modeext: 2; - WORD copyright: 1; - WORD original: 1; - WORD emphasis: 2; - - int nSamplesPerSec, FrameSize, nBytesPerSec; - REFERENCE_TIME rtDuration; - }; - - class aachdr - { - public: - WORD sync: 12; - WORD version: 1; - WORD layer: 2; - WORD fcrc: 1; - WORD profile: 2; - WORD freq: 4; - WORD privatebit: 1; - WORD channels: 3; - WORD original: 1; - WORD home: 1; // ? - - WORD copyright_id_bit: 1; - WORD copyright_id_start: 1; - WORD aac_frame_length: 13; - WORD adts_buffer_fullness: 11; - WORD no_raw_data_blocks_in_frame: 2; - - WORD crc; - - int FrameSize, nBytesPerSec; - REFERENCE_TIME rtDuration; - }; - - class ac3hdr - { - public: - WORD sync; - WORD crc1; - BYTE fscod: 2; - BYTE frmsizecod: 6; - BYTE bsid: 5; - BYTE bsmod: 3; - BYTE acmod: 3; - BYTE cmixlev: 2; - BYTE surmixlev: 2; - BYTE dsurmod: 2; - BYTE lfeon: 1; - // the rest is unimportant for us - }; - - class dtshdr - { - public: - DWORD sync; - BYTE frametype: 1; - BYTE deficitsamplecount: 5; - BYTE fcrc: 1; - BYTE nblocks: 7; - WORD framebytes; - BYTE amode: 6; - BYTE sfreq: 4; - BYTE rate: 5; - - BYTE downmix: 1; - BYTE dynrange: 1; - BYTE timestamp: 1; - BYTE aux_data: 1; - BYTE hdcd: 1; - BYTE ext_descr: 3; - BYTE ext_coding: 1; - BYTE aspf: 1; - BYTE lfe: 2; - BYTE predictor_history: 1; - - }; - - class lpcmhdr - { - public: - BYTE emphasis: 1; - BYTE mute: 1; - BYTE reserved1: 1; - BYTE framenum: 5; - BYTE quantwordlen: 2; - BYTE freq: 2; // 48, 96, 44.1, 32 - BYTE reserved2: 1; - BYTE channels: 3; // +1 - BYTE drc; // 0x80: off - }; - - class hdmvlpcmhdr - { - public: - WORD size; - BYTE channels: 4; - BYTE samplerate: 4; - BYTE bitpersample: 2; - }; - - class dvdspuhdr - { - public: - // nothing ;) - }; - - class hdmvsubhdr - { - public: - // nothing ;) - }; - - class svcdspuhdr - { - public: - // nothing ;) - }; - - class cvdspuhdr - { - public: - // nothing ;) - }; - - class ps2audhdr - { - public: - // 'SShd' + len (0x18) - DWORD unk1; - DWORD freq; - DWORD channels; - DWORD interleave; // bytes per channel - // padding: FF .. FF - // 'SSbd' + len - // pcm or adpcm data - }; - - class ps2subhdr - { - public: - // nothing ;) - }; - - struct trhdr - { - BYTE sync; // 0x47 - BYTE error: 1; - BYTE payloadstart: 1; - BYTE transportpriority: 1; - WORD pid: 13; - BYTE scrambling: 2; - BYTE adapfield: 1; - BYTE payload: 1; - BYTE counter: 4; - // if adapfield set - BYTE length; - BYTE discontinuity: 1; - BYTE randomaccess: 1; - BYTE priority: 1; - BYTE fPCR: 1; - BYTE OPCR: 1; - BYTE splicingpoint: 1; - BYTE privatedata: 1; - BYTE extension: 1; - // TODO: add more fields here when the flags above are set (they aren't very interesting...) - __int64 PCR; - - int bytes; - __int64 next; - }; - - struct trsechdr - { - BYTE table_id; - WORD section_syntax_indicator: 1; - WORD zero: 1; - WORD reserved1: 2; - WORD section_length: 12; - WORD transport_stream_id; - BYTE reserved2: 2; - BYTE version_number: 5; - BYTE current_next_indicator: 1; - BYTE section_number; - BYTE last_section_number; - }; - - // http://www.technotrend.de/download/av_format_v1.pdf - - struct pvahdr - { - WORD sync; // 'VA' - BYTE streamid; // 1 - video, 2 - audio - BYTE counter; - BYTE res1; // 0x55 - BYTE res2: 3; - BYTE fpts: 1; - BYTE postbytes: 2; - BYTE prebytes: 2; - WORD length; - REFERENCE_TIME pts; - }; - - struct avchdr - { - BYTE profile, level; - unsigned int width, height; - __int64 spspos, spslen; - __int64 ppspos, ppslen; - __int64 AvgTimePerFrame; - - avchdr() - { - spspos = 0; - spslen = 0; - ppspos = 0; - ppslen = 0; - AvgTimePerFrame = 0; - } - }; - - struct vc1hdr - { - BYTE profile; - BYTE level; - BYTE chromaformat; - BYTE frmrtq_postproc; - BYTE bitrtq_postproc; - BYTE postprocflag; - BYTE broadcast; - BYTE interlace; - BYTE tfcntrflag; - BYTE finterpflag; - BYTE psf; - UINT ArX; - UINT ArY; - unsigned int width, height; - }; - - struct dvbsub - { - }; + enum mpeg_t {mpegunk, mpeg1, mpeg2}; + + struct pshdr + { + mpeg_t type; + UINT64 scr, bitrate; + }; + + struct pssyshdr + { + DWORD rate_bound; + BYTE video_bound, audio_bound; + bool fixed_rate, csps; + bool sys_video_loc_flag, sys_audio_loc_flag; + }; + + struct peshdr + { + WORD len; + + BYTE type:2, fpts:1, fdts:1; + REFERENCE_TIME pts, dts; + + // mpeg1 stuff + UINT64 std_buff_size; + + // mpeg2 stuff + BYTE scrambling:2, priority:1, alignment:1, copyright:1, original:1; + BYTE escr:1, esrate:1, dsmtrickmode:1, morecopyright:1, crc:1, extension:1; + BYTE hdrlen; + + struct peshdr() {memset(this, 0, sizeof(*this));} + }; + + class seqhdr + { + public: + WORD width; + WORD height; + BYTE ar:4; + DWORD ifps; + DWORD bitrate; + DWORD vbv; + BYTE constrained:1; + BYTE fiqm:1; + BYTE iqm[64]; + BYTE fniqm:1; + BYTE niqm[64]; + // ext + BYTE startcodeid:4; + BYTE profile_levelescape:1; + BYTE profile:3; + BYTE level:4; + BYTE progressive:1; + BYTE chroma:2; + BYTE lowdelay:1; + // misc + int arx, ary; + }; + + class mpahdr + { + public: + WORD sync:11; + WORD version:2; + WORD layer:2; + WORD crc:1; + WORD bitrate:4; + WORD freq:2; + WORD padding:1; + WORD privatebit:1; + WORD channels:2; + WORD modeext:2; + WORD copyright:1; + WORD original:1; + WORD emphasis:2; + + int nSamplesPerSec, FrameSize, nBytesPerSec; + REFERENCE_TIME rtDuration; + }; + + class aachdr + { + public: + WORD sync:12; + WORD version:1; + WORD layer:2; + WORD fcrc:1; + WORD profile:2; + WORD freq:4; + WORD privatebit:1; + WORD channels:3; + WORD original:1; + WORD home:1; // ? + + WORD copyright_id_bit:1; + WORD copyright_id_start:1; + WORD aac_frame_length:13; + WORD adts_buffer_fullness:11; + WORD no_raw_data_blocks_in_frame:2; + + WORD crc; + + int FrameSize, nBytesPerSec; + REFERENCE_TIME rtDuration; + }; + + class ac3hdr + { + public: + WORD sync; + WORD crc1; + BYTE fscod:2; + BYTE frmsizecod:6; + BYTE bsid:5; + BYTE bsmod:3; + BYTE acmod:3; + BYTE cmixlev:2; + BYTE surmixlev:2; + BYTE dsurmod:2; + BYTE lfeon:1; + // the rest is unimportant for us + }; + + class dtshdr + { + public: + DWORD sync; + BYTE frametype:1; + BYTE deficitsamplecount:5; + BYTE fcrc:1; + BYTE nblocks:7; + WORD framebytes; + BYTE amode:6; + BYTE sfreq:4; + BYTE rate:5; + + BYTE downmix:1; + BYTE dynrange:1; + BYTE timestamp:1; + BYTE aux_data:1; + BYTE hdcd:1; + BYTE ext_descr:3; + BYTE ext_coding:1; + BYTE aspf:1; + BYTE lfe:2; + BYTE predictor_history:1; + + }; + + class lpcmhdr + { + public: + BYTE emphasis:1; + BYTE mute:1; + BYTE reserved1:1; + BYTE framenum:5; + BYTE quantwordlen:2; + BYTE freq:2; // 48, 96, 44.1, 32 + BYTE reserved2:1; + BYTE channels:3; // +1 + BYTE drc; // 0x80: off + }; + + class hdmvlpcmhdr + { + public: + WORD size; + BYTE channels:4; + BYTE samplerate:4; + BYTE bitpersample:2; + }; + + class dvdspuhdr + { + public: + // nothing ;) + }; + + class hdmvsubhdr + { + public: + // nothing ;) + }; + + class svcdspuhdr + { + public: + // nothing ;) + }; + + class cvdspuhdr + { + public: + // nothing ;) + }; + + class ps2audhdr + { + public: + // 'SShd' + len (0x18) + DWORD unk1; + DWORD freq; + DWORD channels; + DWORD interleave; // bytes per channel + // padding: FF .. FF + // 'SSbd' + len + // pcm or adpcm data + }; + + class ps2subhdr + { + public: + // nothing ;) + }; + + struct trhdr + { + BYTE sync; // 0x47 + BYTE error:1; + BYTE payloadstart:1; + BYTE transportpriority:1; + WORD pid:13; + BYTE scrambling:2; + BYTE adapfield:1; + BYTE payload:1; + BYTE counter:4; + // if adapfield set + BYTE length; + BYTE discontinuity:1; + BYTE randomaccess:1; + BYTE priority:1; + BYTE fPCR:1; + BYTE OPCR:1; + BYTE splicingpoint:1; + BYTE privatedata:1; + BYTE extension:1; + // TODO: add more fields here when the flags above are set (they aren't very interesting...) + __int64 PCR; + + int bytes; + __int64 next; + }; + + struct trsechdr + { + BYTE table_id; + WORD section_syntax_indicator:1; + WORD zero:1; + WORD reserved1:2; + WORD section_length:12; + WORD transport_stream_id; + BYTE reserved2:2; + BYTE version_number:5; + BYTE current_next_indicator:1; + BYTE section_number; + BYTE last_section_number; + }; + + // http://www.technotrend.de/download/av_format_v1.pdf + + struct pvahdr + { + WORD sync; // 'VA' + BYTE streamid; // 1 - video, 2 - audio + BYTE counter; + BYTE res1; // 0x55 + BYTE res2:3; + BYTE fpts:1; + BYTE postbytes:2; + BYTE prebytes:2; + WORD length; + REFERENCE_TIME pts; + }; + + struct avchdr + { + BYTE profile, level; + unsigned int width, height; + __int64 spspos, spslen; + __int64 ppspos, ppslen; + __int64 AvgTimePerFrame; + + avchdr() + { + spspos = 0; + spslen = 0; + ppspos = 0; + ppslen = 0; + AvgTimePerFrame = 0; + } + }; + + struct vc1hdr + { + BYTE profile; + BYTE level; + BYTE chromaformat; + BYTE frmrtq_postproc; + BYTE bitrtq_postproc; + BYTE postprocflag; + BYTE broadcast; + BYTE interlace; + BYTE tfcntrflag; + BYTE finterpflag; + BYTE psf; + UINT ArX; + UINT ArY; + unsigned int width, height; + }; + + struct dvbsub + { + }; #pragma pack(pop) - bool Read(pshdr& h); - bool Read(pssyshdr& h); - bool Read(peshdr& h, BYTE code); - bool Read(seqhdr& h, int len, CMediaType* pmt = NULL); - bool Read(mpahdr& h, int len, bool fAllowV25, CMediaType* pmt = NULL); - bool Read(aachdr& h, int len, CMediaType* pmt = NULL); - bool Read(ac3hdr& h, int len, CMediaType* pmt = NULL); - bool Read(dtshdr& h, int len, CMediaType* pmt = NULL); - bool Read(lpcmhdr& h, CMediaType* pmt = NULL); - bool Read(hdmvlpcmhdr& h, CMediaType* pmt = NULL); - bool Read(dvdspuhdr& h, CMediaType* pmt = NULL); - bool Read(hdmvsubhdr& h, CMediaType* pmt = NULL, const char* language_code = NULL); - bool Read(svcdspuhdr& h, CMediaType* pmt = NULL); - bool Read(cvdspuhdr& h, CMediaType* pmt = NULL); - bool Read(ps2audhdr& h, CMediaType* pmt = NULL); - bool Read(ps2subhdr& h, CMediaType* pmt = NULL); - bool Read(trhdr& h, bool fSync = true); - bool Read(trsechdr& h); - bool Read(pvahdr& h, bool fSync = true); - bool Read(avchdr& h, int len, CMediaType* pmt = NULL); - bool Read(vc1hdr& h, int len, CMediaType* pmt = NULL); - bool Read(dvbsub& h, int len, CMediaType* pmt = NULL); - - void RemoveMpegEscapeCode(BYTE* dst, BYTE* src, int length); + bool Read(pshdr& h); + bool Read(pssyshdr& h); + bool Read(peshdr& h, BYTE code); + bool Read(seqhdr& h, int len, CMediaType* pmt = NULL); + bool Read(mpahdr& h, int len, bool fAllowV25, CMediaType* pmt = NULL); + bool Read(aachdr& h, int len, CMediaType* pmt = NULL); + bool Read(ac3hdr& h, int len, CMediaType* pmt = NULL); + bool Read(dtshdr& h, int len, CMediaType* pmt = NULL); + bool Read(lpcmhdr& h, CMediaType* pmt = NULL); + bool Read(hdmvlpcmhdr& h, CMediaType* pmt = NULL); + bool Read(dvdspuhdr& h, CMediaType* pmt = NULL); + bool Read(hdmvsubhdr& h, CMediaType* pmt = NULL, const char* language_code = NULL); + bool Read(svcdspuhdr& h, CMediaType* pmt = NULL); + bool Read(cvdspuhdr& h, CMediaType* pmt = NULL); + bool Read(ps2audhdr& h, CMediaType* pmt = NULL); + bool Read(ps2subhdr& h, CMediaType* pmt = NULL); + bool Read(trhdr& h, bool fSync = true); + bool Read(trsechdr& h); + bool Read(pvahdr& h, bool fSync = true); + bool Read(avchdr& h, int len, CMediaType* pmt = NULL); + bool Read(vc1hdr& h, int len, CMediaType* pmt = NULL); + bool Read(dvbsub& h, int len, CMediaType* pmt = NULL); + + void RemoveMpegEscapeCode(BYTE* dst, BYTE* src, int length); }; diff --git a/src/filters/parser/BaseSplitter/MultiFiles.cpp b/src/filters/parser/BaseSplitter/MultiFiles.cpp index 0e1443d89..c40610d85 100644 --- a/src/filters/parser/BaseSplitter/MultiFiles.cpp +++ b/src/filters/parser/BaseSplitter/MultiFiles.cpp @@ -28,182 +28,181 @@ IMPLEMENT_DYNAMIC(CMultiFiles, CObject) CMultiFiles::CMultiFiles() - : m_hFile(INVALID_HANDLE_VALUE) - , m_llTotalLength(0) - , m_nCurPart(-1) - , m_pCurrentPTSOffset(NULL) + : m_hFile(INVALID_HANDLE_VALUE) + , m_llTotalLength(0) + , m_nCurPart(-1) + , m_pCurrentPTSOffset(NULL) { } void CMultiFiles::Reset() { - m_strFiles.RemoveAll(); - m_FilesSize.RemoveAll(); - m_rtPtsOffsets.RemoveAll(); - m_llTotalLength = 0; + m_strFiles.RemoveAll(); + m_FilesSize.RemoveAll(); + m_rtPtsOffsets.RemoveAll(); + m_llTotalLength = 0; } BOOL CMultiFiles::Open(LPCTSTR lpszFileName, UINT nOpenFlags) { - Reset(); - m_strFiles.Add(lpszFileName); + Reset(); + m_strFiles.Add (lpszFileName); - return OpenPart(0); + return OpenPart(0); } BOOL CMultiFiles::OpenFiles(CAtlList& files, UINT nOpenFlags) { - POSITION pos = files.GetHeadPosition(); - LARGE_INTEGER llSize; - int nPos = 0; - REFERENCE_TIME rtDur = 0; - - Reset(); - while(pos) - { - CHdmvClipInfo::PlaylistItem& s = files.GetNext(pos); - m_strFiles.Add(s.m_strFileName); - if(!OpenPart(nPos)) return false; - - llSize.QuadPart = 0; - GetFileSizeEx(m_hFile, &llSize); - m_llTotalLength += llSize.QuadPart; - m_FilesSize.Add(llSize.QuadPart); - m_rtPtsOffsets.Add(rtDur); - rtDur += s.Duration(); - nPos++; - } - - if(files.GetCount() > 1) ClosePart(); - - return TRUE; + POSITION pos = files.GetHeadPosition(); + LARGE_INTEGER llSize; + int nPos = 0; + REFERENCE_TIME rtDur = 0; + + Reset(); + while(pos) + { + CHdmvClipInfo::PlaylistItem& s = files.GetNext(pos); + m_strFiles.Add(s.m_strFileName); + if (!OpenPart(nPos)) return false; + + llSize.QuadPart = 0; + GetFileSizeEx (m_hFile, &llSize); + m_llTotalLength += llSize.QuadPart; + m_FilesSize.Add (llSize.QuadPart); + m_rtPtsOffsets.Add (rtDur); + rtDur += s.Duration(); + nPos++; + } + + if (files.GetCount() > 1) ClosePart(); + + return TRUE; } ULONGLONG CMultiFiles::Seek(LONGLONG lOff, UINT nFrom) { - LARGE_INTEGER llNewPos; - LARGE_INTEGER llOff; - - if(m_strFiles.GetCount() == 1) - { - llOff.QuadPart = lOff; - SetFilePointerEx(m_hFile, llOff, &llNewPos, nFrom); - - return llNewPos.QuadPart; - } - else - { - LONGLONG lAbsolutePos = GetAbsolutePosition(lOff, nFrom); - int nNewPart = 0; - ULONGLONG llSum = 0; - - while(m_FilesSize[nNewPart] + llSum <= lAbsolutePos) - { - llSum += m_FilesSize[nNewPart]; - nNewPart++; - } - - OpenPart(nNewPart); - llOff.QuadPart = lAbsolutePos - llSum; - SetFilePointerEx(m_hFile, llOff, &llNewPos, FILE_BEGIN); - - return llSum + llNewPos.QuadPart; - } + LARGE_INTEGER llNewPos; + LARGE_INTEGER llOff; + + if (m_strFiles.GetCount() == 1) + { + llOff.QuadPart = lOff; + SetFilePointerEx (m_hFile, llOff, &llNewPos, nFrom); + + return llNewPos.QuadPart; + } + else + { + LONGLONG lAbsolutePos = GetAbsolutePosition(lOff, nFrom); + int nNewPart = 0; + ULONGLONG llSum = 0; + + while (m_FilesSize[nNewPart]+llSum <= lAbsolutePos) + { + llSum += m_FilesSize[nNewPart]; + nNewPart++; + } + + OpenPart (nNewPart); + llOff.QuadPart = lAbsolutePos - llSum; + SetFilePointerEx (m_hFile, llOff, &llNewPos, FILE_BEGIN); + + return llSum + llNewPos.QuadPart; + } } ULONGLONG CMultiFiles::GetAbsolutePosition(LONGLONG lOff, UINT nFrom) { - LARGE_INTEGER llNoMove = {0, 0}; - LARGE_INTEGER llCurPos; - - switch(nFrom) - { - case begin : - return lOff; - case current : - SetFilePointerEx(m_hFile, llNoMove, &llCurPos, FILE_CURRENT); - return llCurPos.QuadPart + lOff; - case end : - return m_llTotalLength - lOff; - default: - return 0; // just used to quash "not all control paths return a value" warning - } + LARGE_INTEGER llNoMove = {0, 0}; + LARGE_INTEGER llCurPos; + + switch (nFrom) + { + case begin : + return lOff; + case current : + SetFilePointerEx (m_hFile, llNoMove, &llCurPos, FILE_CURRENT); + return llCurPos.QuadPart + lOff; + case end : + return m_llTotalLength - lOff; + default: + return 0; // just used to quash "not all control paths return a value" warning + } } ULONGLONG CMultiFiles::GetLength() const { - if(m_strFiles.GetCount() == 1) - { - ULONGLONG llTotalSize = 0; - LARGE_INTEGER llSize; - GetFileSizeEx(m_hFile, &llSize); - return llSize.QuadPart; - } - else - return m_llTotalLength; + if (m_strFiles.GetCount() == 1) + { + ULONGLONG llTotalSize = 0; + LARGE_INTEGER llSize; + GetFileSizeEx (m_hFile, &llSize); + return llSize.QuadPart; + } + else + return m_llTotalLength; } UINT CMultiFiles::Read(void* lpBuf, UINT nCount) { - DWORD dwRead; - do - { - if(!ReadFile(m_hFile, lpBuf, nCount, &dwRead, NULL)) - break; - - if(dwRead != nCount && m_nCurPart < m_strFiles.GetCount() - 1) - { - OpenPart(m_nCurPart + 1); - lpBuf = (void*)((BYTE*)lpBuf + dwRead); - nCount -= dwRead; - } - } - while(nCount != dwRead && m_nCurPart < m_strFiles.GetCount() - 1); - return dwRead; + DWORD dwRead; + do + { + if (!ReadFile(m_hFile, lpBuf, nCount, &dwRead, NULL)) + break; + + if (dwRead != nCount && m_nCurPart < m_strFiles.GetCount()-1) + { + OpenPart (m_nCurPart+1); + lpBuf = (void*)((BYTE*)lpBuf + dwRead); + nCount -= dwRead; + } + } while (nCount != dwRead && m_nCurPart < m_strFiles.GetCount()-1); + return dwRead; } void CMultiFiles::Close() { - ClosePart(); - Reset(); + ClosePart(); + Reset(); } CMultiFiles::~CMultiFiles() { - Close(); + Close(); } BOOL CMultiFiles::OpenPart(int nPart) { - if(m_nCurPart == nPart) - return TRUE; - else - { - CString fn; + if (m_nCurPart == nPart) + return TRUE; + else + { + CString fn; - ClosePart(); + ClosePart(); - fn = m_strFiles.GetAt(nPart); - m_hFile = CreateFile(fn, GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + fn = m_strFiles.GetAt(nPart); + m_hFile = CreateFile (fn, GENERIC_READ, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if(m_hFile != INVALID_HANDLE_VALUE) - { - m_nCurPart = nPart; - if(m_pCurrentPTSOffset != NULL) *m_pCurrentPTSOffset = m_rtPtsOffsets[nPart]; - } + if (m_hFile != INVALID_HANDLE_VALUE) + { + m_nCurPart = nPart; + if (m_pCurrentPTSOffset != NULL) *m_pCurrentPTSOffset = m_rtPtsOffsets[nPart]; + } - return (m_hFile != INVALID_HANDLE_VALUE); - } + return (m_hFile != INVALID_HANDLE_VALUE); + } } void CMultiFiles::ClosePart() { - if(m_hFile != INVALID_HANDLE_VALUE) - { - CloseHandle(m_hFile); - m_hFile = INVALID_HANDLE_VALUE; - m_nCurPart = -1; - } + if (m_hFile != INVALID_HANDLE_VALUE) + { + CloseHandle (m_hFile); + m_hFile = INVALID_HANDLE_VALUE; + m_nCurPart = -1; + } } diff --git a/src/filters/parser/BaseSplitter/MultiFiles.h b/src/filters/parser/BaseSplitter/MultiFiles.h index 003601cd0..b07862a0a 100644 --- a/src/filters/parser/BaseSplitter/MultiFiles.h +++ b/src/filters/parser/BaseSplitter/MultiFiles.h @@ -28,75 +28,73 @@ class CMultiFiles : public CObject { - DECLARE_DYNAMIC(CMultiFiles) + DECLARE_DYNAMIC(CMultiFiles) public: // Flag values - enum OpenFlags - { - modeRead = (int) 0x00000, - modeWrite = (int) 0x00001, - modeReadWrite = (int) 0x00002, - shareCompat = (int) 0x00000, - shareExclusive = (int) 0x00010, - shareDenyWrite = (int) 0x00020, - shareDenyRead = (int) 0x00030, - shareDenyNone = (int) 0x00040, - modeNoInherit = (int) 0x00080, - modeCreate = (int) 0x01000, - modeNoTruncate = (int) 0x02000, - typeText = (int) 0x04000, // typeText and typeBinary are - typeBinary = (int) 0x08000, // used in derived classes only - osNoBuffer = (int) 0x10000, - osWriteThrough = (int) 0x20000, - osRandomAccess = (int) 0x40000, - osSequentialScan = (int) 0x80000, - }; + enum OpenFlags { + modeRead = (int) 0x00000, + modeWrite = (int) 0x00001, + modeReadWrite = (int) 0x00002, + shareCompat = (int) 0x00000, + shareExclusive = (int) 0x00010, + shareDenyWrite = (int) 0x00020, + shareDenyRead = (int) 0x00030, + shareDenyNone = (int) 0x00040, + modeNoInherit = (int) 0x00080, + modeCreate = (int) 0x01000, + modeNoTruncate = (int) 0x02000, + typeText = (int) 0x04000, // typeText and typeBinary are + typeBinary = (int) 0x08000, // used in derived classes only + osNoBuffer = (int) 0x10000, + osWriteThrough = (int) 0x20000, + osRandomAccess = (int) 0x40000, + osSequentialScan = (int) 0x80000, + }; - enum Attribute - { - normal = 0x00, - readOnly = 0x01, - hidden = 0x02, - system = 0x04, - volume = 0x08, - directory = 0x10, - archive = 0x20 - }; + enum Attribute { + normal = 0x00, + readOnly = 0x01, + hidden = 0x02, + system = 0x04, + volume = 0x08, + directory = 0x10, + archive = 0x20 + }; - enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 }; + enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 }; // Constructors - CMultiFiles(); + CMultiFiles(); - CString m_strFileName; + CString m_strFileName; // Operations - virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags); - virtual BOOL OpenFiles(CAtlList& files, UINT nOpenFlags); + virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags); + virtual BOOL OpenFiles(CAtlList& files, UINT nOpenFlags); - virtual ULONGLONG Seek(LONGLONG lOff, UINT nFrom); - virtual ULONGLONG GetLength() const; + virtual ULONGLONG Seek(LONGLONG lOff, UINT nFrom); + virtual ULONGLONG GetLength() const; - virtual UINT Read(void* lpBuf, UINT nCount); - virtual void Close(); + virtual UINT Read(void* lpBuf, UINT nCount); + virtual void Close(); // Implementation public: - virtual ~CMultiFiles(); + virtual ~CMultiFiles(); protected: - REFERENCE_TIME* m_pCurrentPTSOffset; - CAtlArray m_strFiles; - CAtlArray m_FilesSize; - CAtlArray m_rtPtsOffsets; - HANDLE m_hFile; - int m_nCurPart; - ULONGLONG m_llTotalLength; + REFERENCE_TIME* m_pCurrentPTSOffset; + CAtlArray m_strFiles; + CAtlArray m_FilesSize; + CAtlArray m_rtPtsOffsets; + HANDLE m_hFile; + int m_nCurPart; + ULONGLONG m_llTotalLength; - BOOL OpenPart(int nPart); - void ClosePart(); - ULONGLONG GetAbsolutePosition(LONGLONG lOff, UINT nFrom); - void Reset(); + BOOL OpenPart(int nPart); + void ClosePart(); + ULONGLONG GetAbsolutePosition(LONGLONG lOff, UINT nFrom); + void Reset(); }; diff --git a/src/filters/parser/BaseSplitter/stdafx.cpp b/src/filters/parser/BaseSplitter/stdafx.cpp index 0533f2b32..4c0a34f8e 100644 --- a/src/filters/parser/BaseSplitter/stdafx.cpp +++ b/src/filters/parser/BaseSplitter/stdafx.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ diff --git a/src/filters/parser/BaseSplitter/stdafx.h b/src/filters/parser/BaseSplitter/stdafx.h index 6fe7f24f9..f7ba733d1 100644 --- a/src/filters/parser/BaseSplitter/stdafx.h +++ b/src/filters/parser/BaseSplitter/stdafx.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ diff --git a/src/filters/parser/DSMSplitter/DSMSplitter.cpp b/src/filters/parser/DSMSplitter/DSMSplitter.cpp index 4e40972f8..300a3cf7a 100644 --- a/src/filters/parser/DSMSplitter/DSMSplitter.cpp +++ b/src/filters/parser/DSMSplitter/DSMSplitter.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -30,49 +30,49 @@ const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = { - {&MEDIATYPE_Stream, &MEDIASUBTYPE_DirectShowMedia}, - {&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}, + {&MEDIATYPE_Stream, &MEDIASUBTYPE_DirectShowMedia}, + {&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}, }; const AMOVIESETUP_PIN sudpPins[] = { - {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn}, - {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL} + {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn}, + {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL} }; const AMOVIESETUP_FILTER sudFilter[] = { - {&__uuidof(CDSMSplitterFilter), L"MPC - DSM Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}, - {&__uuidof(CDSMSourceFilter), L"MPC - DSM Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory}, + {&__uuidof(CDSMSplitterFilter), L"MPC - DSM Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}, + {&__uuidof(CDSMSourceFilter), L"MPC - DSM Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory}, }; CFactoryTemplate g_Templates[] = { - {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance, NULL, &sudFilter[0]}, - {sudFilter[1].strName, sudFilter[1].clsID, CreateInstance, NULL, &sudFilter[1]}, + {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance, NULL, &sudFilter[0]}, + {sudFilter[1].strName, sudFilter[1].clsID, CreateInstance, NULL, &sudFilter[1]}, }; int g_cTemplates = countof(g_Templates); STDAPI DllRegisterServer() { - CString str; - str.Format(_T("0,%d,,%%0%dI64x"), DSMSW_SIZE, DSMSW_SIZE * 2); - str.Format(CString(str), DSMSW); + CString str; + str.Format(_T("0,%d,,%%0%dI64x"), DSMSW_SIZE, DSMSW_SIZE*2); + str.Format(CString(str), DSMSW); - RegisterSourceFilter( - CLSID_AsyncReader, - MEDIASUBTYPE_DirectShowMedia, - str, NULL); + RegisterSourceFilter( + CLSID_AsyncReader, + MEDIASUBTYPE_DirectShowMedia, + str, NULL); - return AMovieDllRegisterServer2(TRUE); + return AMovieDllRegisterServer2(TRUE); } STDAPI DllUnregisterServer() { - UnRegisterSourceFilter(MEDIASUBTYPE_DirectShowMedia); + UnRegisterSourceFilter(MEDIASUBTYPE_DirectShowMedia); - return AMovieDllRegisterServer2(FALSE); + return AMovieDllRegisterServer2(FALSE); } #include "../../FilterApp.h" @@ -86,7 +86,7 @@ CFilterApp theApp; // CDSMSplitterFilter::CDSMSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr) - : CBaseSplitterFilter(NAME("CDSMSplitterFilter"), pUnk, phr, __uuidof(this)) + : CBaseSplitterFilter(NAME("CDSMSplitterFilter"), pUnk, phr, __uuidof(this)) { } @@ -94,168 +94,156 @@ CDSMSplitterFilter::~CDSMSplitterFilter() { } -static int compare_id(const void* id1, const void* id2) -{ - return (int) * (BYTE*)id1 - (int) * (BYTE*)id2; -} +static int compare_id(const void* id1, const void* id2) {return (int)*(BYTE*)id1 - (int)*(BYTE*)id2;} HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader) { - CheckPointer(pAsyncReader, E_POINTER); - - HRESULT hr = E_FAIL; - - m_pFile.Free(); - m_pFile.Attach(DNew CDSMSplitterFile(pAsyncReader, hr, *this, *this)); - if(!m_pFile) return E_OUTOFMEMORY; - if(FAILED(hr)) - { - m_pFile.Free(); - return hr; - } - - m_rtNewStart = m_rtCurrent = 0; - m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->m_rtDuration; - - CAtlArray ids; - - POSITION pos = m_pFile->m_mts.GetStartPosition(); - while(pos) - { - BYTE id; - CMediaType mt; - m_pFile->m_mts.GetNextAssoc(pos, id, mt); - ids.Add(id); - } - - qsort(ids.GetData(), ids.GetCount(), sizeof(BYTE), compare_id); - - for(int i = 0; i < ids.GetCount(); i++) - { - BYTE id = ids[i]; - CMediaType& mt = m_pFile->m_mts[id]; - - CStringW name, lang; - name.Format(L"Output %02d", id); - - CAtlArray mts; - mts.Add(mt); - - CAutoPtr pPinOut(DNew CBaseSplitterOutputPin(mts, name, this, this, &hr)); - - name.Empty(); - - pos = m_pFile->m_sim[id].GetStartPosition(); - while(pos) - { - CStringA key; - CStringW value; - m_pFile->m_sim[id].GetNextAssoc(pos, key, value); - pPinOut->SetProperty(CStringW(key), value); - - if(key == "NAME") name = value; - if(key == "LANG") if((lang = ISO6392ToLanguage(CStringA(CString(value)))).IsEmpty()) lang = value; - } - - if(!name.IsEmpty() || !lang.IsEmpty()) - { - if(!name.IsEmpty()) - { - if(!lang.IsEmpty()) name += L" (" + lang + L")"; - } - else if(!lang.IsEmpty()) name = lang; - pPinOut->SetName(name); - } - - EXECUTE_ASSERT(SUCCEEDED(AddOutputPin(id, pPinOut))); - } - - pos = m_pFile->m_fim.GetStartPosition(); - while(pos) - { - CStringA key; - CStringW value; - m_pFile->m_fim.GetNextAssoc(pos, key, value); - SetProperty(CStringW(key), value); - } - - for(int i = 0; i < m_resources.GetCount(); i++) - { - const CDSMResource& r = m_resources[i]; - if(r.mime == "application/x-truetype-font") - m_fontinst.InstallFont(r.data); - } - - return m_pOutputs.GetCount() > 0 ? S_OK : E_FAIL; + CheckPointer(pAsyncReader, E_POINTER); + + HRESULT hr = E_FAIL; + + m_pFile.Free(); + m_pFile.Attach(DNew CDSMSplitterFile(pAsyncReader, hr, *this, *this)); + if(!m_pFile) return E_OUTOFMEMORY; + if(FAILED(hr)) {m_pFile.Free(); return hr;} + + m_rtNewStart = m_rtCurrent = 0; + m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->m_rtDuration; + + CAtlArray ids; + + POSITION pos = m_pFile->m_mts.GetStartPosition(); + while(pos) + { + BYTE id; + CMediaType mt; + m_pFile->m_mts.GetNextAssoc(pos, id, mt); + ids.Add(id); + } + + qsort(ids.GetData(), ids.GetCount(), sizeof(BYTE), compare_id); + + for(int i = 0; i < ids.GetCount(); i++) + { + BYTE id = ids[i]; + CMediaType& mt = m_pFile->m_mts[id]; + + CStringW name, lang; + name.Format(L"Output %02d", id); + + CAtlArray mts; + mts.Add(mt); + + CAutoPtr pPinOut(DNew CBaseSplitterOutputPin(mts, name, this, this, &hr)); + + name.Empty(); + + pos = m_pFile->m_sim[id].GetStartPosition(); + while(pos) + { + CStringA key; CStringW value; + m_pFile->m_sim[id].GetNextAssoc(pos, key, value); + pPinOut->SetProperty(CStringW(key), value); + + if(key == "NAME") name = value; + if(key == "LANG") if((lang = ISO6392ToLanguage(CStringA(CString(value)))).IsEmpty()) lang = value; + } + + if(!name.IsEmpty() || !lang.IsEmpty()) + { + if(!name.IsEmpty()) {if(!lang.IsEmpty()) name += L" (" + lang + L")";} + else if(!lang.IsEmpty()) name = lang; + pPinOut->SetName(name); + } + + EXECUTE_ASSERT(SUCCEEDED(AddOutputPin(id, pPinOut))); + } + + pos = m_pFile->m_fim.GetStartPosition(); + while(pos) + { + CStringA key; CStringW value; + m_pFile->m_fim.GetNextAssoc(pos, key, value); + SetProperty(CStringW(key), value); + } + + for(int i = 0; i < m_resources.GetCount(); i++) + { + const CDSMResource& r = m_resources[i]; + if(r.mime == "application/x-truetype-font") + m_fontinst.InstallFont(r.data); + } + + return m_pOutputs.GetCount() > 0 ? S_OK : E_FAIL; } bool CDSMSplitterFilter::DemuxInit() { - return true; + return true; } void CDSMSplitterFilter::DemuxSeek(REFERENCE_TIME rt) { - m_pFile->Seek(m_pFile->FindSyncPoint(rt)); + m_pFile->Seek(m_pFile->FindSyncPoint(rt)); } bool CDSMSplitterFilter::DemuxLoop() { - HRESULT hr = S_OK; + HRESULT hr = S_OK; - while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining()) - { - dsmp_t type; - UINT64 len; + while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining()) + { + dsmp_t type; + UINT64 len; - if(!m_pFile->Sync(type, len)) - continue; + if(!m_pFile->Sync(type, len)) + continue; - __int64 pos = m_pFile->GetPos(); + __int64 pos = m_pFile->GetPos(); - if(type == DSMP_SAMPLE) - { - CAutoPtr p(DNew Packet()); - if(m_pFile->Read(len, p)) - { - if(p->rtStart != Packet::INVALID_TIME) - { - p->rtStart -= m_pFile->m_rtFirst; - p->rtStop -= m_pFile->m_rtFirst; - } + if(type == DSMP_SAMPLE) + { + CAutoPtr p(DNew Packet()); + if(m_pFile->Read(len, p)) + { + if(p->rtStart != Packet::INVALID_TIME) + { + p->rtStart -= m_pFile->m_rtFirst; + p->rtStop -= m_pFile->m_rtFirst; + } - hr = DeliverPacket(p); - } - } + hr = DeliverPacket(p); + } + } - m_pFile->Seek(pos + len); - } + m_pFile->Seek(pos + len); + } - return(true); + return(true); } // IKeyFrameInfo STDMETHODIMP CDSMSplitterFilter::GetKeyFrameCount(UINT& nKFs) { - CheckPointer(m_pFile, E_UNEXPECTED); - nKFs = m_pFile->m_sps.GetCount(); - return S_OK; + CheckPointer(m_pFile, E_UNEXPECTED); + nKFs = m_pFile->m_sps.GetCount(); + return S_OK; } STDMETHODIMP CDSMSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs) { - CheckPointer(pFormat, E_POINTER); - CheckPointer(pKFs, E_POINTER); - CheckPointer(m_pFile, E_UNEXPECTED); + CheckPointer(pFormat, E_POINTER); + CheckPointer(pKFs, E_POINTER); + CheckPointer(m_pFile, E_UNEXPECTED); - if(*pFormat != TIME_FORMAT_MEDIA_TIME) return E_INVALIDARG; + if(*pFormat != TIME_FORMAT_MEDIA_TIME) return E_INVALIDARG; - // these aren't really the keyframes, but quicky accessable points in the stream - for(nKFs = 0; nKFs < m_pFile->m_sps.GetCount(); nKFs++) - pKFs[nKFs] = m_pFile->m_sps[nKFs].rt; + // these aren't really the keyframes, but quicky accessable points in the stream + for(nKFs = 0; nKFs < m_pFile->m_sps.GetCount(); nKFs++) + pKFs[nKFs] = m_pFile->m_sps[nKFs].rt; - return S_OK; + return S_OK; } // @@ -263,8 +251,8 @@ STDMETHODIMP CDSMSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIM // CDSMSourceFilter::CDSMSourceFilter(LPUNKNOWN pUnk, HRESULT* phr) - : CDSMSplitterFilter(pUnk, phr) + : CDSMSplitterFilter(pUnk, phr) { - m_clsid = __uuidof(this); - m_pInput.Free(); + m_clsid = __uuidof(this); + m_pInput.Free(); } diff --git a/src/filters/parser/DSMSplitter/DSMSplitter.h b/src/filters/parser/DSMSplitter/DSMSplitter.h index 81469b232..77bc53cad 100644 --- a/src/filters/parser/DSMSplitter/DSMSplitter.h +++ b/src/filters/parser/DSMSplitter/DSMSplitter.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -30,26 +30,26 @@ class CDSMSplitterFilter : public CBaseSplitterFilter { protected: - CAutoPtr m_pFile; - HRESULT CreateOutputs(IAsyncReader* pAsyncReader); + CAutoPtr m_pFile; + HRESULT CreateOutputs(IAsyncReader* pAsyncReader); - bool DemuxInit(); - void DemuxSeek(REFERENCE_TIME rt); - bool DemuxLoop(); + bool DemuxInit(); + void DemuxSeek(REFERENCE_TIME rt); + bool DemuxLoop(); public: - CDSMSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); - virtual ~CDSMSplitterFilter(); + CDSMSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); + virtual ~CDSMSplitterFilter(); - // IKeyFrameInfo + // IKeyFrameInfo - STDMETHODIMP_(HRESULT) GetKeyFrameCount(UINT& nKFs); - STDMETHODIMP_(HRESULT) GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs); + STDMETHODIMP_(HRESULT) GetKeyFrameCount(UINT& nKFs); + STDMETHODIMP_(HRESULT) GetKeyFrames(const GUID* pFormat, REFERENCE_TIME* pKFs, UINT& nKFs); }; [uuid("803E8280-F3CE-4201-982C-8CD8FB512004")] class CDSMSourceFilter : public CDSMSplitterFilter { public: - CDSMSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); + CDSMSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); }; diff --git a/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp b/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp index 4d6f56e53..f4448f661 100644 --- a/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp +++ b/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp @@ -3,428 +3,395 @@ #include "../../../DSUtil/DSUtil.h" #include -CDSMSplitterFile::CDSMSplitterFile(IAsyncReader* pReader, HRESULT& hr, IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap) - : CBaseSplitterFile(pReader, hr, DEFAULT_CACHE_LENGTH, false) - , m_rtFirst(0) - , m_rtDuration(0) +CDSMSplitterFile::CDSMSplitterFile(IAsyncReader* pReader, HRESULT& hr, IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap) + : CBaseSplitterFile(pReader, hr, DEFAULT_CACHE_LENGTH, false) + , m_rtFirst(0) + , m_rtDuration(0) { - if(FAILED(hr)) return; + if(FAILED(hr)) return; - hr = Init(res, chap); + hr = Init(res, chap); } HRESULT CDSMSplitterFile::Init(IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap) { - Seek(0); - - if(BitRead(DSMSW_SIZE << 3) != DSMSW || BitRead(5) != DSMP_FILEINFO) - return E_FAIL; - - Seek(0); - - m_mts.RemoveAll(); - m_rtFirst = m_rtDuration = 0; - m_fim.RemoveAll(); - m_sim.RemoveAll(); - res.ResRemoveAll(); - chap.ChapRemoveAll(); - - dsmp_t type; - UINT64 len; - int limit = 65536; - - // examine the beginning of the file ... - - while(Sync(type, len, 0)) - { - __int64 pos = GetPos(); - - if(type == DSMP_MEDIATYPE) - { - BYTE id; - CMediaType mt; - if(Read(len, id, mt)) m_mts[id] = mt; - } - else if(type == DSMP_SAMPLE) - { - Packet p; - if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) - { - m_rtFirst = p.rtStart; - break; - } - } - else if(type == DSMP_FILEINFO) - { - if((BYTE)BitRead(8) > DSMF_VERSION) return E_FAIL; - Read(len - 1, m_fim); - } - else if(type == DSMP_STREAMINFO) - { - Read(len - 1, m_sim[(BYTE)BitRead(8)]); - } - else if(type == DSMP_SYNCPOINTS) - { - Read(len, m_sps); - } - else if(type == DSMP_RESOURCE) - { - Read(len, res); - } - else if(type == DSMP_CHAPTERS) - { - Read(len, chap); - } - - Seek(pos + len); - } - - if(type != DSMP_SAMPLE) - return E_FAIL; - - // ... and the end - - if(IsRandomAccess()) - for(int i = 1, j = (int)((GetLength() + limit / 2) / limit); i <= j; i++) - { - __int64 seekpos = max(0, (__int64)GetLength() - i * limit); - Seek(seekpos); - - while(Sync(type, len, limit) && GetPos() < seekpos + limit) - { - __int64 pos = GetPos(); - - if(type == DSMP_SAMPLE) - { - Packet p; - if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) - { - m_rtDuration = max(m_rtDuration, p.rtStop - m_rtFirst); // max isn't really needed, only for safety - i = j; - } - } - else if(type == DSMP_SYNCPOINTS) - { - Read(len, m_sps); - } - else if(type == DSMP_RESOURCE) - { - Read(len, res); - } - else if(type == DSMP_CHAPTERS) - { - Read(len, chap); - } - - Seek(pos + len); - } - } - - if(m_rtFirst < 0) - { - m_rtDuration += m_rtFirst; - m_rtFirst = 0; - } - - return m_mts.GetCount() > 0 ? S_OK : E_FAIL; + Seek(0); + + if(BitRead(DSMSW_SIZE<<3) != DSMSW || BitRead(5) != DSMP_FILEINFO) + return E_FAIL; + + Seek(0); + + m_mts.RemoveAll(); + m_rtFirst = m_rtDuration = 0; + m_fim.RemoveAll(); + m_sim.RemoveAll(); + res.ResRemoveAll(); + chap.ChapRemoveAll(); + + dsmp_t type; + UINT64 len; + int limit = 65536; + + // examine the beginning of the file ... + + while(Sync(type, len, 0)) + { + __int64 pos = GetPos(); + + if(type == DSMP_MEDIATYPE) + { + BYTE id; + CMediaType mt; + if(Read(len, id, mt)) m_mts[id] = mt; + } + else if(type == DSMP_SAMPLE) + { + Packet p; + if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) + { + m_rtFirst = p.rtStart; + break; + } + } + else if(type == DSMP_FILEINFO) {if((BYTE)BitRead(8) > DSMF_VERSION) return E_FAIL; Read(len-1, m_fim);} + else if(type == DSMP_STREAMINFO) {Read(len-1, m_sim[(BYTE)BitRead(8)]);} + else if(type == DSMP_SYNCPOINTS) {Read(len, m_sps);} + else if(type == DSMP_RESOURCE) {Read(len, res);} + else if(type == DSMP_CHAPTERS) {Read(len, chap);} + + Seek(pos + len); + } + + if(type != DSMP_SAMPLE) + return E_FAIL; + + // ... and the end + + if(IsRandomAccess()) + for(int i = 1, j = (int)((GetLength()+limit/2)/limit); i <= j; i++) + { + __int64 seekpos = max(0, (__int64)GetLength()-i*limit); + Seek(seekpos); + + while(Sync(type, len, limit) && GetPos() < seekpos+limit) + { + __int64 pos = GetPos(); + + if(type == DSMP_SAMPLE) + { + Packet p; + if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) + { + m_rtDuration = max(m_rtDuration, p.rtStop - m_rtFirst); // max isn't really needed, only for safety + i = j; + } + } + else if(type == DSMP_SYNCPOINTS) {Read(len, m_sps);} + else if(type == DSMP_RESOURCE) {Read(len, res);} + else if(type == DSMP_CHAPTERS) {Read(len, chap);} + + Seek(pos + len); + } + } + + if(m_rtFirst < 0) + { + m_rtDuration += m_rtFirst; + m_rtFirst = 0; + } + + return m_mts.GetCount() > 0 ? S_OK : E_FAIL; } bool CDSMSplitterFile::Sync(dsmp_t& type, UINT64& len, __int64 limit) { - UINT64 pos; - return Sync(pos, type, len, limit); + UINT64 pos; + return Sync(pos, type, len, limit); } bool CDSMSplitterFile::Sync(UINT64& syncpos, dsmp_t& type, UINT64& len, __int64 limit) { - BitByteAlign(); + BitByteAlign(); - limit += DSMSW_SIZE; + limit += DSMSW_SIZE; - for(UINT64 id = 0; (id&((1ui64 << (DSMSW_SIZE << 3)) - 1)) != DSMSW; id = (id << 8) | (BYTE)BitRead(8)) - { - if(limit-- <= 0 || GetRemaining() <= 2) - return(false); - } + for(UINT64 id = 0; (id&((1ui64<<(DSMSW_SIZE<<3))-1)) != DSMSW; id = (id << 8) | (BYTE)BitRead(8)) + { + if(limit-- <= 0 || GetRemaining() <= 2) + return(false); + } - syncpos = GetPos() - (DSMSW_SIZE << 3); - type = (dsmp_t)BitRead(5); - len = BitRead(((int)BitRead(3) + 1) << 3); + syncpos = GetPos() - (DSMSW_SIZE<<3); + type = (dsmp_t)BitRead(5); + len = BitRead(((int)BitRead(3)+1)<<3); - return(true); + return(true); } bool CDSMSplitterFile::Read(__int64 len, BYTE& id, CMediaType& mt) { - id = (BYTE)BitRead(8); - ByteRead((BYTE*)&mt.majortype, sizeof(mt.majortype)); - ByteRead((BYTE*)&mt.subtype, sizeof(mt.subtype)); - mt.bFixedSizeSamples = (BOOL)BitRead(1); - mt.bTemporalCompression = (BOOL)BitRead(1); - mt.lSampleSize = (ULONG)BitRead(30); - ByteRead((BYTE*)&mt.formattype, sizeof(mt.formattype)); - len -= 5 + sizeof(GUID) * 3; - ASSERT(len >= 0); - if(len > 0) - { - mt.AllocFormatBuffer((LONG)len); - ByteRead(mt.Format(), mt.FormatLength()); - } - else mt.ResetFormatBuffer(); - return true; + id = (BYTE)BitRead(8); + ByteRead((BYTE*)&mt.majortype, sizeof(mt.majortype)); + ByteRead((BYTE*)&mt.subtype, sizeof(mt.subtype)); + mt.bFixedSizeSamples = (BOOL)BitRead(1); + mt.bTemporalCompression = (BOOL)BitRead(1); + mt.lSampleSize = (ULONG)BitRead(30); + ByteRead((BYTE*)&mt.formattype, sizeof(mt.formattype)); + len -= 5 + sizeof(GUID)*3; + ASSERT(len >= 0); + if(len > 0) {mt.AllocFormatBuffer((LONG)len); ByteRead(mt.Format(), mt.FormatLength());} + else mt.ResetFormatBuffer(); + return true; } bool CDSMSplitterFile::Read(__int64 len, Packet* p, bool fData) { - if(!p) return false; - - p->TrackNumber = (DWORD)BitRead(8); - p->bSyncPoint = (BOOL)BitRead(1); - bool fSign = !!BitRead(1); - int iTimeStamp = (int)BitRead(3); - int iDuration = (int)BitRead(3); - - if(fSign && !iTimeStamp) - { - ASSERT(!iDuration); - p->rtStart = Packet::INVALID_TIME; - p->rtStop = Packet::INVALID_TIME + 1; - } - else - { - p->rtStart = (REFERENCE_TIME)BitRead(iTimeStamp << 3) * (fSign ? -1 : 1); - p->rtStop = p->rtStart + BitRead(iDuration << 3); - } - - if(fData) - { + if(!p) return false; + + p->TrackNumber = (DWORD)BitRead(8); + p->bSyncPoint = (BOOL)BitRead(1); + bool fSign = !!BitRead(1); + int iTimeStamp = (int)BitRead(3); + int iDuration = (int)BitRead(3); + + if(fSign && !iTimeStamp) + { + ASSERT(!iDuration); + p->rtStart = Packet::INVALID_TIME; + p->rtStop = Packet::INVALID_TIME + 1; + } + else + { + p->rtStart = (REFERENCE_TIME)BitRead(iTimeStamp<<3) * (fSign ? -1 : 1); + p->rtStop = p->rtStart + BitRead(iDuration<<3); + } + + if(fData) + { p->SetCount((INT_PTR)len - (2 + iTimeStamp + iDuration)); - ByteRead(p->GetData(), p->GetCount()); - } + ByteRead(p->GetData(), p->GetCount()); + } - return true; + return true; } bool CDSMSplitterFile::Read(__int64 len, CAtlArray& sps) { - SyncPoint sp = {0, 0}; - sps.RemoveAll(); + SyncPoint sp = {0, 0}; + sps.RemoveAll(); - while(len > 0) - { - bool fSign = !!BitRead(1); - int iTimeStamp = (int)BitRead(3); - int iFilePos = (int)BitRead(3); - BitRead(1); // reserved + while(len > 0) + { + bool fSign = !!BitRead(1); + int iTimeStamp = (int)BitRead(3); + int iFilePos = (int)BitRead(3); + BitRead(1); // reserved - sp.rt += (REFERENCE_TIME)BitRead(iTimeStamp << 3) * (fSign ? -1 : 1); - sp.fp += BitRead(iFilePos << 3); - sps.Add(sp); + sp.rt += (REFERENCE_TIME)BitRead(iTimeStamp<<3) * (fSign ? -1 : 1); + sp.fp += BitRead(iFilePos<<3); + sps.Add(sp); - len -= 1 + iTimeStamp + iFilePos; - } + len -= 1 + iTimeStamp + iFilePos; + } - if(len != 0) - { - sps.RemoveAll(); - return false; - } + if(len != 0) + { + sps.RemoveAll(); + return false; + } - // TODO: sort sps + // TODO: sort sps - return true; + return true; } bool CDSMSplitterFile::Read(__int64 len, CStreamInfoMap& im) { - while(len >= 5) - { - CStringA key; - ByteRead((BYTE*)key.GetBufferSetLength(4), 4); - len -= 4; - len -= Read(len, im[key]); - } - - return len == 0; + while(len >= 5) + { + CStringA key; + ByteRead((BYTE*)key.GetBufferSetLength(4), 4); + len -= 4; + len -= Read(len, im[key]); + } + + return len == 0; } bool CDSMSplitterFile::Read(__int64 len, IDSMResourceBagImpl& res) { - BYTE compression = (BYTE)BitRead(2); - BYTE reserved = (BYTE)BitRead(6); - len--; + BYTE compression = (BYTE)BitRead(2); + BYTE reserved = (BYTE)BitRead(6); + len--; - CDSMResource r; - len -= Read(len, r.name); - len -= Read(len, r.desc); - len -= Read(len, r.mime); + CDSMResource r; + len -= Read(len, r.name); + len -= Read(len, r.desc); + len -= Read(len, r.mime); - if(compression != 0) return false; // TODO + if(compression != 0) return false; // TODO - r.data.SetCount(len); - ByteRead(r.data.GetData(), r.data.GetCount()); + r.data.SetCount(len); + ByteRead(r.data.GetData(), r.data.GetCount()); - res += r; + res += r; - return true; + return true; } bool CDSMSplitterFile::Read(__int64 len, IDSMChapterBagImpl& chap) { - CDSMChapter c(0, L""); + CDSMChapter c(0, L""); - while(len > 0) - { - bool fSign = !!BitRead(1); - int iTimeStamp = (int)BitRead(3); - BitRead(4); // reserved - len--; + while(len > 0) + { + bool fSign = !!BitRead(1); + int iTimeStamp = (int)BitRead(3); + BitRead(4); // reserved + len--; - c.rt += (REFERENCE_TIME)BitRead(iTimeStamp << 3) * (fSign ? -1 : 1); - len -= iTimeStamp; - len -= Read(len, c.name); + c.rt += (REFERENCE_TIME)BitRead(iTimeStamp<<3) * (fSign ? -1 : 1); + len -= iTimeStamp; + len -= Read(len, c.name); - chap += c; - } + chap += c; + } - chap.ChapSort(); + chap.ChapSort(); - return len == 0; + return len == 0; } __int64 CDSMSplitterFile::Read(__int64 len, CStringW& str) { - char c; - CStringA s; - __int64 i = 0; - while(i++ < len && (c = (char)BitRead(8)) != 0) s += c; - str = UTF8To16(s); - return i; + char c; + CStringA s; + __int64 i = 0; + while(i++ < len && (c = (char)BitRead(8)) != 0) s += c; + str = UTF8To16(s); + return i; } __int64 CDSMSplitterFile::FindSyncPoint(REFERENCE_TIME rt) { - if(/*!m_sps.IsEmpty()*/ m_sps.GetCount() > 1) - { - int i = range_bsearch(m_sps, m_rtFirst + rt); - return i >= 0 ? m_sps[i].fp : 0; - } - - if(m_rtDuration <= 0 || rt <= m_rtFirst) - return 0; - - // ok, do the hard way then - - dsmp_t type; - UINT64 syncpos, len; - - // 1. find some boundaries close to rt's position (minpos, maxpos) - - __int64 minpos = 0, maxpos = GetLength(); - - for(int i = 0; i < 10 && (maxpos - minpos) >= 1024 * 1024; i++) - { - Seek((minpos + maxpos) / 2); - - while(GetPos() < maxpos) - { - if(!Sync(syncpos, type, len)) - continue; - - __int64 pos = GetPos(); - - if(type == DSMP_SAMPLE) - { - Packet p; - if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) - { - REFERENCE_TIME dt = (p.rtStart -= m_rtFirst) - rt; - if(dt >= 0) maxpos = max((__int64)syncpos - 65536, minpos); - else minpos = syncpos; - break; - } - } - - Seek(pos + len); - } - } - - // 2. find the first packet just after rt (maxpos) - - Seek(minpos); - - while(GetRemaining()) - { - if(!Sync(syncpos, type, len)) - continue; - - __int64 pos = GetPos(); - - if(type == DSMP_SAMPLE) - { - Packet p; - if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) - { - REFERENCE_TIME dt = (p.rtStart -= m_rtFirst) - rt; - if(dt >= 0) - { - maxpos = (__int64)syncpos; - break; - } - } - } - - Seek(pos + len); - } - - // 3. iterate backwards from maxpos and find at least one syncpoint for every stream, except for subtitle streams - - CAtlMap ids; - - { - POSITION pos = m_mts.GetStartPosition(); - while(pos) - { - BYTE id; - CMediaType mt; - m_mts.GetNextAssoc(pos, id, mt); - if(mt.majortype != MEDIATYPE_Text && mt.majortype != MEDIATYPE_Subtitle) - ids[id] = 0; - } - } - - __int64 ret = maxpos; - - while(maxpos > 0 && !ids.IsEmpty()) - { - minpos = max(0, maxpos - 65536); - - Seek(minpos); - - while(Sync(syncpos, type, len) && GetPos() < maxpos) - { - UINT64 pos = GetPos(); - - if(type == DSMP_SAMPLE) - { - Packet p; - if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME && p.bSyncPoint) - { - BYTE id = (BYTE)p.TrackNumber, tmp; - if(ids.Lookup(id, tmp)) - { - ids.RemoveKey((BYTE)p.TrackNumber); - ret = min(ret, (__int64)syncpos); - } - } - } - - Seek(pos + len); - } - - maxpos = minpos; - } - - return ret; + if(/*!m_sps.IsEmpty()*/ m_sps.GetCount() > 1) + { + int i = range_bsearch(m_sps, m_rtFirst + rt); + return i >= 0 ? m_sps[i].fp : 0; + } + + if(m_rtDuration <= 0 || rt <= m_rtFirst) + return 0; + + // ok, do the hard way then + + dsmp_t type; + UINT64 syncpos, len; + + // 1. find some boundaries close to rt's position (minpos, maxpos) + + __int64 minpos = 0, maxpos = GetLength(); + + for(int i = 0; i < 10 && (maxpos - minpos) >= 1024*1024; i++) + { + Seek((minpos + maxpos) / 2); + + while(GetPos() < maxpos) + { + if(!Sync(syncpos, type, len)) + continue; + + __int64 pos = GetPos(); + + if(type == DSMP_SAMPLE) + { + Packet p; + if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) + { + REFERENCE_TIME dt = (p.rtStart -= m_rtFirst) - rt; + if(dt >= 0) maxpos = max((__int64)syncpos - 65536, minpos); + else minpos = syncpos; + break; + } + } + + Seek(pos + len); + } + } + + // 2. find the first packet just after rt (maxpos) + + Seek(minpos); + + while(GetRemaining()) + { + if(!Sync(syncpos, type, len)) + continue; + + __int64 pos = GetPos(); + + if(type == DSMP_SAMPLE) + { + Packet p; + if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) + { + REFERENCE_TIME dt = (p.rtStart -= m_rtFirst) - rt; + if(dt >= 0) {maxpos = (__int64)syncpos; break;} + } + } + + Seek(pos + len); + } + + // 3. iterate backwards from maxpos and find at least one syncpoint for every stream, except for subtitle streams + + CAtlMap ids; + + { + POSITION pos = m_mts.GetStartPosition(); + while(pos) + { + BYTE id; + CMediaType mt; + m_mts.GetNextAssoc(pos, id, mt); + if(mt.majortype != MEDIATYPE_Text && mt.majortype != MEDIATYPE_Subtitle) + ids[id] = 0; + } + } + + __int64 ret = maxpos; + + while(maxpos > 0 && !ids.IsEmpty()) + { + minpos = max(0, maxpos - 65536); + + Seek(minpos); + + while(Sync(syncpos, type, len) && GetPos() < maxpos) + { + UINT64 pos = GetPos(); + + if(type == DSMP_SAMPLE) + { + Packet p; + if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME && p.bSyncPoint) + { + BYTE id = (BYTE)p.TrackNumber, tmp; + if(ids.Lookup(id, tmp)) + { + ids.RemoveKey((BYTE)p.TrackNumber); + ret = min(ret, (__int64)syncpos); + } + } + } + + Seek(pos + len); + } + + maxpos = minpos; + } + + return ret; } diff --git a/src/filters/parser/DSMSplitter/DSMSplitterFile.h b/src/filters/parser/DSMSplitter/DSMSplitterFile.h index 21fb2fde5..7c350db2f 100644 --- a/src/filters/parser/DSMSplitter/DSMSplitterFile.h +++ b/src/filters/parser/DSMSplitter/DSMSplitterFile.h @@ -6,34 +6,30 @@ class CDSMSplitterFile : public CBaseSplitterFile { - HRESULT Init(IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap); + HRESULT Init(IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap); public: - CDSMSplitterFile(IAsyncReader* pReader, HRESULT& hr, IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap); - - CAtlMap m_mts; - REFERENCE_TIME m_rtFirst, m_rtDuration; - - struct SyncPoint - { - REFERENCE_TIME rt; - __int64 fp; - }; - CAtlArray m_sps; - - typedef CAtlMap, CStringElementTraits > CStreamInfoMap; - CStreamInfoMap m_fim; - CAtlMap m_sim; - - bool Sync(dsmp_t& type, UINT64& len, __int64 limit = 65536); - bool Sync(UINT64& syncpos, dsmp_t& type, UINT64& len, __int64 limit = 65536); - bool Read(__int64 len, BYTE& id, CMediaType& mt); - bool Read(__int64 len, Packet* p, bool fData = true); - bool Read(__int64 len, CAtlArray& sps); - bool Read(__int64 len, CStreamInfoMap& im); - bool Read(__int64 len, IDSMResourceBagImpl& res); - bool Read(__int64 len, IDSMChapterBagImpl& chap); - __int64 Read(__int64 len, CStringW& str); - - __int64 FindSyncPoint(REFERENCE_TIME rt); + CDSMSplitterFile(IAsyncReader* pReader, HRESULT& hr, IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap); + + CAtlMap m_mts; + REFERENCE_TIME m_rtFirst, m_rtDuration; + + struct SyncPoint {REFERENCE_TIME rt; __int64 fp;}; + CAtlArray m_sps; + + typedef CAtlMap, CStringElementTraits > CStreamInfoMap; + CStreamInfoMap m_fim; + CAtlMap m_sim; + + bool Sync(dsmp_t& type, UINT64& len, __int64 limit = 65536); + bool Sync(UINT64& syncpos, dsmp_t& type, UINT64& len, __int64 limit = 65536); + bool Read(__int64 len, BYTE& id, CMediaType& mt); + bool Read(__int64 len, Packet* p, bool fData = true); + bool Read(__int64 len, CAtlArray& sps); + bool Read(__int64 len, CStreamInfoMap& im); + bool Read(__int64 len, IDSMResourceBagImpl& res); + bool Read(__int64 len, IDSMChapterBagImpl& chap); + __int64 Read(__int64 len, CStringW& str); + + __int64 FindSyncPoint(REFERENCE_TIME rt); }; diff --git a/src/filters/parser/DSMSplitter/resource.h b/src/filters/parser/DSMSplitter/resource.h index 003e79ee4..66d1331cb 100644 --- a/src/filters/parser/DSMSplitter/resource.h +++ b/src/filters/parser/DSMSplitter/resource.h @@ -3,7 +3,7 @@ // Used by DSMSplitter.rc // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 diff --git a/src/filters/parser/DSMSplitter/stdafx.cpp b/src/filters/parser/DSMSplitter/stdafx.cpp index 0046e7260..0a00e1846 100644 --- a/src/filters/parser/DSMSplitter/stdafx.cpp +++ b/src/filters/parser/DSMSplitter/stdafx.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ diff --git a/src/filters/parser/DSMSplitter/stdafx.h b/src/filters/parser/DSMSplitter/stdafx.h index 089cf8fa0..e8beccd47 100644 --- a/src/filters/parser/DSMSplitter/stdafx.h +++ b/src/filters/parser/DSMSplitter/stdafx.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ diff --git a/src/filters/parser/DiracSplitter/DiracSplitter.cpp b/src/filters/parser/DiracSplitter/DiracSplitter.cpp index b9e3cc8b7..db544603f 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitter.cpp +++ b/src/filters/parser/DiracSplitter/DiracSplitter.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2004 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -28,7 +28,7 @@ #ifdef REGISTER_FILTER const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = -{ +{ {&MEDIATYPE_Stream, &MEDIASUBTYPE_Dirac}, {&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL} }; @@ -74,8 +74,8 @@ int g_cTemplates = countof(g_Templates); STDAPI DllRegisterServer() { RegisterSourceFilter( - CLSID_AsyncReader, - MEDIASUBTYPE_Dirac, + CLSID_AsyncReader, + MEDIASUBTYPE_Dirac, _T("0,8,,4B572D4449524143"), // KW-DIRAC _T(".drc"), NULL); @@ -107,7 +107,7 @@ STDMETHODIMP CDiracSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void { CheckPointer(ppv, E_POINTER); - return + return __super::NonDelegatingQueryInterface(riid, ppv); } @@ -121,11 +121,7 @@ HRESULT CDiracSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader) m_pFile.Attach(DNew CDiracSplitterFile(pAsyncReader, hr)); if(!m_pFile) return E_OUTOFMEMORY; - if(FAILED(hr)) - { - m_pFile.Free(); - return hr; - } + if(FAILED(hr)) {m_pFile.Free(); return hr;} CAtlArray mts; mts.Add(m_pFile->GetMediaType()); @@ -162,7 +158,7 @@ void CDiracSplitterFilter::DemuxSeek(REFERENCE_TIME rt) // TODO __int64 len = m_pFile->GetLength(); - __int64 seekpos = (__int64)(1.0 * rt / m_rtDuration * len); + __int64 seekpos = (__int64)(1.0*rt/m_rtDuration*len); m_pFile->Seek(seekpos); seekpos = 0; @@ -176,11 +172,7 @@ void CDiracSplitterFilter::DemuxSeek(REFERENCE_TIME rt) for(int j = 0; j < 10; j++) { while(m_pFile->Next(code) && code != AU_START_CODE); - if(code != AU_START_CODE) - { - m_pFile->Seek(seekpos >>= 1); - continue; - } + if(code != AU_START_CODE) {m_pFile->Seek(seekpos >>= 1); continue;} __int64 pos = m_pFile->GetPos() - 5; @@ -194,7 +186,7 @@ void CDiracSplitterFilter::DemuxSeek(REFERENCE_TIME rt) break; } - m_pFile->Seek(pos - (__int64)(1.0 * dt / m_rtDuration * len)); + m_pFile->Seek(pos - (__int64)(1.0*dt/m_rtDuration*len)); pdt = dt; } @@ -222,7 +214,7 @@ bool CDiracSplitterFilter::DemuxLoop() memcpy(p->GetData(), pBuff, size); p->TrackNumber = 0; - p->rtStart = rtAvgTimePerFrame * fnum; + p->rtStart = rtAvgTimePerFrame*fnum; p->rtStop = p->rtStart + rtAvgTimePerFrame; p->bSyncPoint = code == AU_START_CODE; @@ -283,8 +275,7 @@ void CDiracVideoDecoder::FreeDecoder() { dirac_decoder_close((dirac_decoder_t*)m_decoder); m_decoder = NULL; - delete [] m_pYUV[0]; - m_pYUV[0] = NULL; + delete [] m_pYUV[0]; m_pYUV[0] = NULL; } } @@ -304,7 +295,7 @@ HRESULT CDiracVideoDecoder::Receive(IMediaSample* pIn) long len = pIn->GetActualDataLength(); if(len <= 0) return S_OK; // nothing to do - if(pIn->IsDiscontinuity() == S_OK) + if(pIn->IsDiscontinuity() == S_OK) InitDecoder(); dirac_decoder_t* decoder = (dirac_decoder_t*)m_decoder; @@ -326,7 +317,7 @@ HRESULT CDiracVideoDecoder::Receive(IMediaSample* pIn) { DIRACINFOHEADER* dvih = (DIRACINFOHEADER*)m_pInput->CurrentMediaType().Format(); if(dvih->hdr.bmiHeader.biWidth != decoder->src_params.width - || dvih->hdr.bmiHeader.biHeight != decoder->src_params.height) + || dvih->hdr.bmiHeader.biHeight != decoder->src_params.height) return E_FAIL; // hmm } @@ -335,14 +326,13 @@ HRESULT CDiracVideoDecoder::Receive(IMediaSample* pIn) int w = decoder->src_params.width; int h = decoder->src_params.height; int wc = decoder->src_params.chroma_width; - int hc = decoder->src_params.chroma_height; - delete [] m_pYUV[0]; - m_pYUV[0] = NULL; + int hc = decoder->src_params.chroma_height; + delete [] m_pYUV[0]; m_pYUV[0] = NULL; m_pYUV[0] = DNew BYTE[w*h + wc*hc*2 + w/2*h/2]; - m_pYUV[1] = m_pYUV[0] + w * h; - m_pYUV[2] = m_pYUV[1] + wc * hc; - m_pYUV[3] = m_pYUV[2] + wc * hc; - memset(m_pYUV[3], 0x80, w / 2 * h / 2); + m_pYUV[1] = m_pYUV[0] + w*h; + m_pYUV[2] = m_pYUV[1] + wc*hc; + m_pYUV[3] = m_pYUV[2] + wc*hc; + memset(m_pYUV[3], 0x80, w/2*h/2); m_rtAvgTimePerFrame = 10000000i64 * decoder->src_params.frame_rate.denominator / decoder->src_params.frame_rate.numerator; dirac_set_buf(decoder, m_pYUV, NULL); } @@ -379,7 +369,7 @@ HRESULT CDiracVideoDecoder::Deliver(IMediaSample* pIn, REFERENCE_TIME rtStart, R CComPtr pOut; BYTE* pDataOut = NULL; if(FAILED(hr = m_pOutput->GetDeliveryBuffer(&pOut, NULL, NULL, 0)) - || FAILED(hr = pOut->GetPointer(&pDataOut))) + || FAILED(hr = pOut->GetPointer(&pDataOut))) return hr; AM_MEDIA_TYPE* pmt; @@ -423,28 +413,28 @@ void CDiracVideoDecoder::Copy(BYTE* pOut) int pitchIn = w; BYTE* pY = m_pYUV[0]; - BYTE* pU = w / 2 == wc && h / 2 == hc ? m_pYUV[1] : m_pYUV[3]; // FIXME - BYTE* pV = w / 2 == wc && h / 2 == hc ? m_pYUV[2] : m_pYUV[3]; // FIXME + BYTE* pU = w/2 == wc && h/2 == hc ? m_pYUV[1] : m_pYUV[3]; // FIXME + BYTE* pV = w/2 == wc && h/2 == hc ? m_pYUV[2] : m_pYUV[3]; // FIXME if(bihOut.biCompression == '2YUY') { - BitBltFromI420ToYUY2(w, h, pOut, bihOut.biWidth * 2, pY, pU, pV, pitchIn); + BitBltFromI420ToYUY2(w, h, pOut, bihOut.biWidth*2, pY, pU, pV, pitchIn); } else if(bihOut.biCompression == 'I420' || bihOut.biCompression == 'VUYI') { - BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth * h, pOut + bihOut.biWidth * h * 5 / 4, bihOut.biWidth, pY, pU, pV, pitchIn); + BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth*h, pOut + bihOut.biWidth*h*5/4, bihOut.biWidth, pY, pU, pV, pitchIn); } else if(bihOut.biCompression == '21VY') { - BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth * h * 5 / 4, pOut + bihOut.biWidth * h, bihOut.biWidth, pY, pU, pV, pitchIn); + BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth*h*5/4, pOut + bihOut.biWidth*h, bihOut.biWidth, pY, pU, pV, pitchIn); } else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS) { - int pitchOut = bihOut.biWidth * bihOut.biBitCount >> 3; + int pitchOut = bihOut.biWidth*bihOut.biBitCount>>3; if(bihOut.biHeight > 0) { - pOut += pitchOut * (h - 1); + pOut += pitchOut*(h-1); pitchOut = -pitchOut; } @@ -460,10 +450,10 @@ HRESULT CDiracVideoDecoder::CheckInputType(const CMediaType* mtIn) { DIRACINFOHEADER* dvih = (DIRACINFOHEADER*)mtIn->Format(); - if(mtIn->majortype != MEDIATYPE_Video - || mtIn->subtype != MEDIASUBTYPE_DiracVideo - || mtIn->formattype != FORMAT_DiracVideoInfo - || (dvih->hdr.bmiHeader.biWidth & 1) || (dvih->hdr.bmiHeader.biHeight & 1)) + if(mtIn->majortype != MEDIATYPE_Video + || mtIn->subtype != MEDIASUBTYPE_DiracVideo + || mtIn->formattype != FORMAT_DiracVideoInfo + || (dvih->hdr.bmiHeader.biWidth&1) || (dvih->hdr.bmiHeader.biHeight&1)) return VFW_E_TYPE_NOT_ACCEPTED; return S_OK; @@ -475,22 +465,22 @@ HRESULT CDiracVideoDecoder::CheckTransform(const CMediaType* mtIn, const CMediaT { BITMAPINFOHEADER bih1, bih2; if(ExtractBIH(mtOut, &bih1) && ExtractBIH(&m_pOutput->CurrentMediaType(), &bih2) - && abs(bih1.biHeight) != abs(bih2.biHeight)) + && abs(bih1.biHeight) != abs(bih2.biHeight)) return VFW_E_TYPE_NOT_ACCEPTED; } return mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_DiracVideo - && mtOut->majortype == MEDIATYPE_Video && (mtOut->subtype == MEDIASUBTYPE_YUY2 - || mtOut->subtype == MEDIASUBTYPE_YV12 - || mtOut->subtype == MEDIASUBTYPE_I420 - || mtOut->subtype == MEDIASUBTYPE_IYUV - || mtOut->subtype == MEDIASUBTYPE_ARGB32 - || mtOut->subtype == MEDIASUBTYPE_RGB32 - || mtOut->subtype == MEDIASUBTYPE_RGB24 - || mtOut->subtype == MEDIASUBTYPE_RGB565 - || mtOut->subtype == MEDIASUBTYPE_RGB555) - ? S_OK - : VFW_E_TYPE_NOT_ACCEPTED; + && mtOut->majortype == MEDIATYPE_Video && (mtOut->subtype == MEDIASUBTYPE_YUY2 + || mtOut->subtype == MEDIASUBTYPE_YV12 + || mtOut->subtype == MEDIASUBTYPE_I420 + || mtOut->subtype == MEDIASUBTYPE_IYUV + || mtOut->subtype == MEDIASUBTYPE_ARGB32 + || mtOut->subtype == MEDIASUBTYPE_RGB32 + || mtOut->subtype == MEDIASUBTYPE_RGB24 + || mtOut->subtype == MEDIASUBTYPE_RGB565 + || mtOut->subtype == MEDIASUBTYPE_RGB555) + ? S_OK + : VFW_E_TYPE_NOT_ACCEPTED; } HRESULT CDiracVideoDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties) @@ -507,24 +497,19 @@ HRESULT CDiracVideoDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATO HRESULT hr; ALLOCATOR_PROPERTIES Actual; - if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) + if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) return hr; return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer - ? E_FAIL - : NOERROR); + ? E_FAIL + : NOERROR); } HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) { if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED; - struct - { - const GUID* subtype; - WORD biPlanes, biBitCount; - DWORD biCompression; - } fmts[] = + struct {const GUID* subtype; WORD biPlanes, biBitCount; DWORD biCompression;} fmts[] = { {&MEDIASUBTYPE_YV12, 3, 12, '21VY'}, {&MEDIASUBTYPE_I420, 3, 12, '024I'}, @@ -543,10 +528,10 @@ HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) }; if(m_pInput->CurrentMediaType().formattype == FORMAT_VideoInfo) - iPosition = iPosition * 2 + 1; + iPosition = iPosition*2 + 1; if(iPosition < 0) return E_INVALIDARG; - if(iPosition >= 2 * countof(fmts)) return VFW_S_NO_MORE_ITEMS; + if(iPosition >= 2*countof(fmts)) return VFW_S_NO_MORE_ITEMS; BITMAPINFOHEADER bih; ExtractBIH(&m_pInput->CurrentMediaType(), &bih); @@ -562,9 +547,9 @@ HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) bihOut.biPlanes = fmts[iPosition/2].biPlanes; bihOut.biBitCount = fmts[iPosition/2].biBitCount; bihOut.biCompression = fmts[iPosition/2].biCompression; - bihOut.biSizeImage = bih.biWidth * bih.biHeight * bihOut.biBitCount >> 3; + bihOut.biSizeImage = bih.biWidth*bih.biHeight*bihOut.biBitCount>>3; - if(iPosition & 1) + if(iPosition&1) { pmt->formattype = FORMAT_VideoInfo; VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER)); @@ -575,7 +560,7 @@ HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) { vih->bmiHeader.biWidth = ((VIDEOINFOHEADER2*)m_pInput->CurrentMediaType().Format())->dwPictAspectRatioX; vih->bmiHeader.biHeight = ((VIDEOINFOHEADER2*)m_pInput->CurrentMediaType().Format())->dwPictAspectRatioY; - vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth * vih->bmiHeader.biHeight * vih->bmiHeader.biBitCount >> 3; + vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth*vih->bmiHeader.biHeight*vih->bmiHeader.biBitCount>>3; } } else @@ -617,7 +602,7 @@ HRESULT CDiracVideoDecoder::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tSt HRESULT CDiracVideoDecoder::AlterQuality(Quality q) { - if(q.Late > 500 * 10000i64) m_fDropFrames = true; + if(q.Late > 500*10000i64) m_fDropFrames = true; if(q.Late <= 0) m_fDropFrames = false; return E_NOTIMPL; } diff --git a/src/filters/parser/DiracSplitter/DiracSplitter.h b/src/filters/parser/DiracSplitter/DiracSplitter.h index 4b3915ba2..0ed5d14cb 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitter.h +++ b/src/filters/parser/DiracSplitter/DiracSplitter.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -28,17 +28,17 @@ class CDiracSplitterFilter : public CBaseSplitterFilter { protected: - CAutoPtr m_pFile; - HRESULT CreateOutputs(IAsyncReader* pAsyncReader); + CAutoPtr m_pFile; + HRESULT CreateOutputs(IAsyncReader* pAsyncReader); - bool DemuxInit(); - void DemuxSeek(REFERENCE_TIME rt); - bool DemuxLoop(); + bool DemuxInit(); + void DemuxSeek(REFERENCE_TIME rt); + bool DemuxLoop(); public: - CDiracSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); + CDiracSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); - DECLARE_IUNKNOWN + DECLARE_IUNKNOWN STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); }; @@ -46,35 +46,35 @@ public: class CDiracSourceFilter : public CDiracSplitterFilter { public: - CDiracSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); + CDiracSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); }; [uuid("F78CF248-180E-4713-B107-B13F7B5C31E1")] class CDiracVideoDecoder : public CTransformFilter { void* m_decoder; // dirac_decoder_t* - void InitDecoder(), FreeDecoder(); - BYTE* m_pYUV[4]; - bool m_fDropFrames; - REFERENCE_TIME m_tStart, m_rtAvgTimePerFrame; + void InitDecoder(), FreeDecoder(); + BYTE* m_pYUV[4]; + bool m_fDropFrames; + REFERENCE_TIME m_tStart, m_rtAvgTimePerFrame; - HRESULT Deliver(IMediaSample* pIn, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop); - void Copy(BYTE* pOut); + HRESULT Deliver(IMediaSample* pIn, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop); + void Copy(BYTE* pOut); public: - CDiracVideoDecoder(LPUNKNOWN lpunk, HRESULT* phr); - virtual ~CDiracVideoDecoder(); + CDiracVideoDecoder(LPUNKNOWN lpunk, HRESULT* phr); + virtual ~CDiracVideoDecoder(); - HRESULT Receive(IMediaSample* pIn); - HRESULT CheckInputType(const CMediaType* mtIn); - HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut); - HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties); - HRESULT GetMediaType(int iPosition, CMediaType* pMediaType); + HRESULT Receive(IMediaSample* pIn); + HRESULT CheckInputType(const CMediaType* mtIn); + HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut); + HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties); + HRESULT GetMediaType(int iPosition, CMediaType* pMediaType); - HRESULT StartStreaming(); - HRESULT StopStreaming(); + HRESULT StartStreaming(); + HRESULT StopStreaming(); HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate); - HRESULT AlterQuality(Quality q); + HRESULT AlterQuality(Quality q); }; \ No newline at end of file diff --git a/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp b/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp index 7bae7f357..de3b42b45 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp +++ b/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp @@ -18,11 +18,11 @@ HRESULT CDiracSplitterFile::Init() HRESULT hr = E_FAIL; Seek(0); - + // Dirac streams are no longer preceded with KW-DIRAC //UINT64 hdr; //if(FAILED(Read((BYTE*)&hdr, sizeof(hdr))) || hdr != 0x43415249442D574Bui64) // KW-DIRAC - //return E_FAIL; + //return E_FAIL; dirac_decoder_t* decoder = dirac_decoder_init(0); @@ -31,20 +31,12 @@ HRESULT CDiracSplitterFile::Init() while(GetPos() < limit) { BYTE b; - if(!Next(b)) - { - ASSERT(0); - break; - } + if(!Next(b)) {ASSERT(0); break;} if(b == AU_START_CODE) { __int64 pos = GetPos() - 13; //Parse info size = 13 - if(!Next(b)) - { - ASSERT(0); - break; - } + if(!Next(b)) {ASSERT(0); break;} __int64 len = GetPos() - pos; Seek(pos); @@ -61,14 +53,10 @@ HRESULT CDiracSplitterFile::Init() dirac_buffer(decoder, (BYTE*)&dvih->dwSequenceHeader[0], (BYTE*)&dvih->dwSequenceHeader[0] + len); DecoderState dec_state = dirac_parse(decoder); - if(dec_state != STATE_SEQUENCE) - { - ASSERT(0); - break; - } + if(dec_state != STATE_SEQUENCE) {ASSERT(0); break;} if(decoder->src_params.frame_rate.denominator) - dvih->hdr.AvgTimePerFrame = 10000000i64 * decoder->src_params.frame_rate.denominator / decoder->src_params.frame_rate.numerator; + dvih->hdr.AvgTimePerFrame = 10000000i64 * decoder->src_params.frame_rate.denominator / decoder->src_params.frame_rate.numerator; dvih->hdr.bmiHeader.biSize = sizeof(dvih->hdr.bmiHeader); dvih->hdr.bmiHeader.biWidth = decoder->src_params.width; dvih->hdr.bmiHeader.biHeight = decoder->src_params.height; @@ -94,7 +82,7 @@ HRESULT CDiracSplitterFile::Init() } UINT64 CDiracSplitterFile::UnsignedGolombDecode() -{ +{ int M = 0; while(M < 64 && !BitRead(1)) M++; @@ -103,7 +91,7 @@ UINT64 CDiracSplitterFile::UnsignedGolombDecode() for(int i = 0; i < M; i++) info |= BitRead(1) << i; - return (1ui64 << M) - 1 + info; + return (1ui64<= GetLength()) return(false); qw = (qw << 8) | (BYTE)BitRead(8); } - while((qw & 0xffffffff00) != ((UINT64)START_CODE_PREFIX << 8)); + while((qw&0xffffffff00) != ((UINT64)START_CODE_PREFIX<<8)); int size_bytes = 0; // Read in the 6 bytes of next and previous parse unit offsets. - while(size_bytes < 6) + while (size_bytes < 6) { if(len-- == 0 || GetPos() >= GetLength()) return(false); BitRead(8); @@ -143,7 +131,7 @@ const BYTE* CDiracSplitterFile::NextBlock(BYTE& code, int& size, int& fnum) if(size == 0) { - if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX << 8)) + if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX<<8) ) code = (BYTE)(qw & 0xff); if(isFrameStartCode(code)) @@ -157,14 +145,14 @@ const BYTE* CDiracSplitterFile::NextBlock(BYTE& code, int& size, int& fnum) } else { - if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX << 8)) + if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX<<8)) break; } } if(size >= m_pBuff.GetSize()) { - int newsize = max(1024, size * 2); + int newsize = max(1024, size*2); m_pBuff.SetSize(newsize, newsize); pBuff = m_pBuff.GetData(); } diff --git a/src/filters/parser/DiracSplitter/DiracSplitterFile.h b/src/filters/parser/DiracSplitter/DiracSplitterFile.h index a69e61fb1..cc2ec185a 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitterFile.h +++ b/src/filters/parser/DiracSplitter/DiracSplitterFile.h @@ -7,27 +7,21 @@ class CDiracSplitterFile : public CBaseSplitterFile { - CMediaType m_mt; - REFERENCE_TIME m_rtDuration; - CArray m_pBuff; + CMediaType m_mt; + REFERENCE_TIME m_rtDuration; + CArray m_pBuff; - HRESULT Init(); + HRESULT Init(); public: - CDiracSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr); + CDiracSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr); // using CBaseSplitterFile::Read; - bool Next(BYTE& code, __int64 len = -1); - const BYTE* NextBlock(BYTE& code, int& size, int& fnum); - UINT64 UnsignedGolombDecode(); + bool Next(BYTE& code, __int64 len = -1); + const BYTE* NextBlock(BYTE& code, int& size, int& fnum); + UINT64 UnsignedGolombDecode(); - const CMediaType& GetMediaType() - { - return m_mt; - } - REFERENCE_TIME GetDuration() - { - return m_rtDuration; - } + const CMediaType& GetMediaType() {return m_mt;} + REFERENCE_TIME GetDuration() {return m_rtDuration;} }; diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp index 8248a0003..33bb8ff9f 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp @@ -42,40 +42,40 @@ using namespace dirac; // Constructor for encoding -SequenceHeaderByteIO::SequenceHeaderByteIO(SourceParams& src_params, - EncoderParams& enc_params): - ParseUnitByteIO(), - m_parseparams_byteio(*this, m_parse_params, enc_params), +SequenceHeaderByteIO::SequenceHeaderByteIO( SourceParams& src_params, + EncoderParams& enc_params): +ParseUnitByteIO(), +m_parseparams_byteio(*this, m_parse_params, enc_params), // create default source parameters for comparisions - m_default_src_params(src_params.GetVideoFormat()), - m_src_params(src_params), - m_sourceparams_byteio(m_src_params, - m_default_src_params, - *this), - m_codec_params(enc_params), - m_codingparams_byteio(m_src_params, - m_codec_params, - m_default_src_params, - *this) +m_default_src_params(src_params.GetVideoFormat()), +m_src_params(src_params), +m_sourceparams_byteio( m_src_params, + m_default_src_params, + *this), +m_codec_params(enc_params), +m_codingparams_byteio(m_src_params, + m_codec_params, + m_default_src_params, + *this) { } // Constructor for decoding SequenceHeaderByteIO::SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, - ParseParams& parse_params, - SourceParams& src_params, - CodecParams& codec_params) : - ParseUnitByteIO(parseunit_byteio), - m_parseparams_byteio(parseunit_byteio, parse_params), - m_src_params(src_params), - m_sourceparams_byteio(m_src_params, - m_default_src_params, - parseunit_byteio), - m_codec_params(codec_params), - m_codingparams_byteio(m_src_params, - m_codec_params, - m_default_src_params, - parseunit_byteio) + ParseParams& parse_params, + SourceParams& src_params, + CodecParams& codec_params) : +ParseUnitByteIO(parseunit_byteio), +m_parseparams_byteio( parseunit_byteio, parse_params), +m_src_params(src_params), +m_sourceparams_byteio( m_src_params, + m_default_src_params, + parseunit_byteio), +m_codec_params(codec_params), +m_codingparams_byteio( m_src_params, + m_codec_params, + m_default_src_params, + parseunit_byteio) { } @@ -84,7 +84,7 @@ SequenceHeaderByteIO::~SequenceHeaderByteIO() } //-----public------------------------------------------------------ -bool SequenceHeaderByteIO::Input() +bool SequenceHeaderByteIO::Input() { //int o=mp_stream->tellg(); InputParseParams(); @@ -92,22 +92,22 @@ bool SequenceHeaderByteIO::Input() // Inout Video format SetByteParams(m_parseparams_byteio); VideoFormat vf = IntToVideoFormat(ReadUint()); - if(vf == VIDEO_FORMAT_UNDEFINED) - DIRAC_THROW_EXCEPTION( - ERR_INVALID_VIDEO_FORMAT, - "Dirac does not recognise the specified video-format", - SEVERITY_ACCESSUNIT_ERROR); + if(vf==VIDEO_FORMAT_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_VIDEO_FORMAT, + "Dirac does not recognise the specified video-format", + SEVERITY_ACCESSUNIT_ERROR); SourceParams src_params(vf, true); m_src_params = src_params; - + InputSourceParams(); - + CodecParams codec_params(vf); m_codec_params = codec_params; - + InputCodingParams(); - + return true; } @@ -122,15 +122,15 @@ void SequenceHeaderByteIO::Output() OutputSourceParams(); OutputCodingParams(); - + } int SequenceHeaderByteIO::GetSize() const { - return ParseUnitByteIO::GetSize() + - m_parseparams_byteio.GetSize() + - ByteIO::GetSize() + - m_sourceparams_byteio.GetSize() + + return ParseUnitByteIO::GetSize()+ + m_parseparams_byteio.GetSize()+ + ByteIO::GetSize() + + m_sourceparams_byteio.GetSize()+ m_codingparams_byteio.GetSize(); } @@ -150,7 +150,7 @@ unsigned char SequenceHeaderByteIO::CalcParseCode() const void SequenceHeaderByteIO::InputSourceParams() { - // copy current input params + // copy current input params m_sourceparams_byteio.SetByteParams(*this); m_sourceparams_byteio.Input(); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h index 346bd4110..2c2966ed8 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h @@ -50,135 +50,132 @@ namespace dirac { -/** -* A random access point within a Dirac bytestream -*/ -class SequenceHeaderByteIO : public ParseUnitByteIO -{ -public: - /** - * Constructor (encoding) - *@param src_params Source parameters for current AccessUnit - *@param enc_params Encoder parameters for current AccessUnit + * A random access point within a Dirac bytestream */ - SequenceHeaderByteIO(SourceParams& src_params, - EncoderParams& enc_params); - - /** - * Constructor (decoding) - *@param parseunit_byteio Source of data - *@param parse_params Destination of parse paramters data - *@param src_params Destination of source paramters data - *@param codec_params Destination of coding paramters data - */ - SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, + class SequenceHeaderByteIO : public ParseUnitByteIO + { + public: + + /** + * Constructor (encoding) + *@param src_params Source parameters for current AccessUnit + *@param enc_params Encoder parameters for current AccessUnit + */ + SequenceHeaderByteIO( SourceParams& src_params, + EncoderParams& enc_params); + + /** + * Constructor (decoding) + *@param parseunit_byteio Source of data + *@param parse_params Destination of parse paramters data + *@param src_params Destination of source paramters data + *@param codec_params Destination of coding paramters data + */ + SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, ParseParams& parse_params, SourceParams& src_params, CodecParams& codec_params); - /** - * Destructor - */ - ~SequenceHeaderByteIO(); - - /** - * Parses data in Dirac-stream format (decoding) - */ - bool Input(); - - /** - * Writes access-unit info to Dirac stream-format (encoding) - */ - void Output(); - - /* - * Gets size of access-unit (in bytes) - */ - int GetSize() const; - - /** - * Gets parse-unit type - */ - ParseUnitType GetType() const - { - return PU_SEQ_HEADER; - } - -private: - - /** - * Calculates parse-code based on access-unit parameters (encoding) - *@return Char bit-set - */ - unsigned char CalcParseCode() const; - - /** - * Parse source attributes from bytestream-compatible input (decoding) - */ - void InputSourceParams(); - - /** - * Parse parse attributes from bytestream-compatible input (decoding) - */ - void InputParseParams(); - - /** - * Parse Coding attributes from bytestream-compatible input (decoding) - */ - void InputCodingParams(); - - /** - * Output source attributes for bytestream-compatible output (encoding) - */ - void OutputSourceParams(); - - /** - * Output parse attributes for bytestream-compatible output (encoding) - */ - void OutputParseParams(); - - /** - * Output coding attributes for bytestream-compatible output (encoding) - */ - void OutputCodingParams(); - - /** - * Current parse parameters - */ - ParseParams m_parse_params; - - - /** - * Parse-params byte input/output - */ - ParseParamsByteIO m_parseparams_byteio; - - /** - * Default source parameters - */ - SourceParams m_default_src_params; - - /** - * Current source parameters - */ - SourceParams& m_src_params; - - /** - * Source-params byte input/output - */ - SourceParamsByteIO m_sourceparams_byteio; - - /** - * Current codec parameters - */ - CodecParams& m_codec_params; - - /** - * Coding-params byte input/output - */ - CodingParamsByteIO m_codingparams_byteio; -}; + /** + * Destructor + */ + ~SequenceHeaderByteIO(); + + /** + * Parses data in Dirac-stream format (decoding) + */ + bool Input(); + + /** + * Writes access-unit info to Dirac stream-format (encoding) + */ + void Output(); + + /* + * Gets size of access-unit (in bytes) + */ + int GetSize() const; + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_SEQ_HEADER;} + + private: + + /** + * Calculates parse-code based on access-unit parameters (encoding) + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + /** + * Parse source attributes from bytestream-compatible input (decoding) + */ + void InputSourceParams(); + + /** + * Parse parse attributes from bytestream-compatible input (decoding) + */ + void InputParseParams(); + + /** + * Parse Coding attributes from bytestream-compatible input (decoding) + */ + void InputCodingParams(); + + /** + * Output source attributes for bytestream-compatible output (encoding) + */ + void OutputSourceParams(); + + /** + * Output parse attributes for bytestream-compatible output (encoding) + */ + void OutputParseParams(); + + /** + * Output coding attributes for bytestream-compatible output (encoding) + */ + void OutputCodingParams(); + + /** + * Current parse parameters + */ + ParseParams m_parse_params; + + + /** + * Parse-params byte input/output + */ + ParseParamsByteIO m_parseparams_byteio; + + /** + * Default source parameters + */ + SourceParams m_default_src_params; + + /** + * Current source parameters + */ + SourceParams& m_src_params; + + /** + * Source-params byte input/output + */ + SourceParamsByteIO m_sourceparams_byteio; + + /** + * Current codec parameters + */ + CodecParams& m_codec_params; + + /** + * Coding-params byte input/output + */ + CodingParamsByteIO m_codingparams_byteio; + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp index 724239e54..12b129953 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp @@ -42,37 +42,37 @@ using namespace dirac; using namespace std; ByteIO::ByteIO(bool new_stream): - m_current_byte(0), - m_current_pos(0), - m_num_bytes(0), - m_new_stream(true), - m_bits_left(0) +m_current_byte(0), +m_current_pos(0), +m_num_bytes(0), +m_new_stream(true), +m_bits_left(0) { if(new_stream) mp_stream = new stringstream(stringstream::in | stringstream::out | stringstream::binary); - + } ByteIO::ByteIO(const ByteIO& stream_data): - m_current_byte(0), - m_current_pos(0), - m_num_bytes(0), - m_new_stream(false), - m_bits_left(0) +m_current_byte(0), +m_current_pos(0), +m_num_bytes(0), +m_new_stream(false), +m_bits_left(0) { - mp_stream = stream_data.mp_stream; + mp_stream=stream_data.mp_stream; } ByteIO::~ByteIO() { - if(m_new_stream) + if (m_new_stream) delete mp_stream; } -const string ByteIO::GetBytes() +const string ByteIO::GetBytes() { return mp_stream->str(); } @@ -84,35 +84,35 @@ int ByteIO::GetSize() const void ByteIO::SetByteParams(const ByteIO& byte_io) { - mp_stream = byte_io.mp_stream; - m_current_byte = byte_io.m_current_byte; - m_current_pos = byte_io.m_current_pos; + mp_stream=byte_io.mp_stream; + m_current_byte=byte_io.m_current_byte; + m_current_pos=byte_io.m_current_pos; } //----------protected--------------------------------------------------------------- void ByteIO::ByteAlignInput() { - m_current_pos = 0; - m_current_byte = 0; + m_current_pos=0; + m_current_byte=0; } void ByteIO::ByteAlignOutput() { - if(m_current_pos != 0) + if(m_current_pos!=0) OutputCurrentByte(); } int ByteIO::ReadBit() { if(m_current_pos == CHAR_BIT) - m_current_pos = 0; + m_current_pos=0; - if(m_current_pos == 0) + if (m_current_pos == 0) m_current_byte = InputUnByte(); #if 1 // MSB to LSB - return GetBit(m_current_byte, (CHAR_BIT - 1 - m_current_pos++)); + return GetBit(m_current_byte, (CHAR_BIT-1-m_current_pos++)); #else // LSB to MSB return GetBit(m_current_byte, m_current_pos++); @@ -121,7 +121,7 @@ int ByteIO::ReadBit() int ByteIO::ReadBitB() { - if(m_bits_left) + if (m_bits_left) { --m_bits_left; return ReadBit(); @@ -143,7 +143,7 @@ bool ByteIO::ReadBoolB() unsigned int ByteIO::ReadNBits(int count) { unsigned int val = 0; - for(int i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { val <<= 1; val += ReadBit(); @@ -166,14 +166,14 @@ int ByteIO::ReadSint() int val = ReadUint(); bool bit; - //get the sign - if(val != 0) + //get the sign + if (val != 0) { bit = ReadBit(); - if(bit) + if (bit ) val = -val; } - return val; + return val; } int ByteIO::ReadSintB() @@ -182,24 +182,24 @@ int ByteIO::ReadSintB() int val = ReadUintB(); bool bit; - //get the sign - if(val != 0) + //get the sign + if (val != 0) { bit = ReadBitB(); - if(bit) + if (bit ) val = -val; } - return val; + return val; } unsigned int ByteIO::ReadUint() { unsigned int value = 1; - while(!ReadBit()) + while (!ReadBit()) { value <<= 1; - if(ReadBit()) - value += 1; + if (ReadBit()) + value +=1; } --value; return value; @@ -208,11 +208,11 @@ unsigned int ByteIO::ReadUint() unsigned int ByteIO::ReadUintB() { unsigned int value = 1; - while(!ReadBitB()) + while (!ReadBitB()) { value <<= 1; - if(ReadBitB()) - value += 1; + if (ReadBitB()) + value +=1; } --value; return value; @@ -223,21 +223,21 @@ void ByteIO::WriteBit(const bool& bit) if(bit) #if 1 // MSB to LSB - SetBit(m_current_byte, CHAR_BIT - 1 - m_current_pos); + SetBit(m_current_byte, CHAR_BIT-1-m_current_pos); #else // LSB to MSB SetBit(m_current_byte, m_current_pos); #endif - if(m_current_pos == CHAR_BIT - 1) - { + if ( m_current_pos == CHAR_BIT-1) + { // If a whole byte has been written, output to stream OutputCurrentByte(); m_current_byte = 0; m_current_pos = 0; - } + } else - // Shift mask to next bit in the output byte + // Shift mask to next bit in the output byte ++m_current_pos; } @@ -245,7 +245,7 @@ void ByteIO::WriteNBits(unsigned int val, int count) { do { - WriteBit(val & (1 << (count - 1))); + WriteBit(val & ( 1 << (count-1))); count--; } while(count > 0); @@ -253,7 +253,7 @@ void ByteIO::WriteNBits(unsigned int val, int count) int ByteIO::WriteNBits(unsigned int val) { - int nbits = static_cast(log(static_cast(val)) / log(2.0)) + 1; + int nbits = static_cast(log(static_cast(val))/log(2.0)) + 1; WriteNBits(val, nbits); return nbits; } @@ -265,24 +265,24 @@ void ByteIO::WriteSint(int val) WriteUint(value); //do sign - if(val < 0) WriteBit(1); - else if(val > 0) WriteBit(0); + if (val<0) WriteBit(1); + else if (val>0) WriteBit(0); } void ByteIO::WriteUint(unsigned int value) { - unsigned int val = value + 1; + unsigned int val = value+1; int num_follow_zeroes = 0; - while(val >= (1U << num_follow_zeroes)) + while (val >= (1U <= 0; --i) + for (int i=num_follow_zeroes-1; i>=0; --i) { WriteBit(BIT_ZERO); - WriteBit(val&(1 << i)); + WriteBit(val&(1<tellg(); - string data = mp_stream->str(); + string data=mp_stream->str(); data.erase(0, size); mp_stream->str(data); - m_num_bytes = data.size(); + m_num_bytes=data.size(); if(data.size()) - SeekGet(max(prev_pos - size, 0), ios_base::beg); + SeekGet(max(prev_pos-size, 0), ios_base::beg); } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h index 806d98a55..db885d658 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h @@ -53,371 +53,342 @@ namespace dirac { + + // BIT DEFS + #define BIT_ZERO 0 + #define BIT_ONE 1 + + // most significant bit in a character + #define MS_BIT (1 << (CHAR_BIT - 1)) + + /* array index for character containing bit */ + //#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT-1-bit)) + #define BIT_IN_CHAR(bit) (1 << bit) + + + /** + * Class ByteIO - top-level class for reading/writing bytes to a stream + */ + class ByteIO + { + public: + + /** + * Default constructor + *@param new_stream Has Creates & owns data buffer + */ + ByteIO(bool new_stream=true); + + /** + * Constructor + *@param stream_data Copies data buffer details + */ + ByteIO(const ByteIO& stream_data); + + /** + * Destructor + */ + virtual ~ByteIO(); + + /** + * Gathers byte-stream statistics + *@param dirac_byte_stats Collates byte information + */ + virtual void CollateByteStats(DiracByteStats& dirac_byte_stats) + { dirac_byte_stats.Clear(); } + + /** + * Get bytes in Dirac-bytestream format + */ + virtual const std::string GetBytes(); + + /** + * Get position of read stream pointer + */ + int GetReadBytePosition() const { return mp_stream->tellg();}; + + + /** + *Gets size (in bytes) + */ + virtual int GetSize() const; + + /** + * Copies stream source/destination info + *@param byte_io Byte source/destination + */ + void SetByteParams(const ByteIO& byte_io); + + /** + * Sync input for byte-alignment + */ + void ByteAlignOutput(); + + /** + * Ouputs an unsigned integer in interleaved exp Golomb format + *@param value Integer to be output + */ + //void OutputVarLengthUint(const unsigned int& value); + void WriteUint(unsigned int value); + + /** + * Sets input size in bits. Read is limited by this + */ + void SetBitsLeft(int left_bits) { m_bits_left = left_bits; } + + /** + * Sets input size in bits. Read is limited by this + */ + int BitsLeft(void) { return m_bits_left; } + + protected: + + inline bool CanRead() const { return(!mp_stream->eof()); } + + inline bool GetBit(unsigned char& c, int pos) const { return (c & BIT_IN_CHAR(pos)); } + + inline void SetBit(unsigned char& c, int pos) const { c |= BIT_IN_CHAR(pos); } + + inline void SetBits(unsigned char& c, unsigned char bits) const { c |= bits; } + + /** + * Sync input for byte-alignment + */ + void ByteAlignInput(); + + + /** + * Reads boolean value + */ + bool ReadBool(); + + /** + * Reads boolean value - bounded i/o + */ + bool ReadBoolB(); + + /** + * Reads next bit + */ + int ReadBit(); + + /** + * Reads next bit - bounded i/o + */ + int ReadBitB(); + + /** + * Reads next 'count' bits + *@param count number of bits to be read + *@return unsigned interger read + */ + unsigned int ReadNBits(int count); + + /** + * Reads from stream + *@param data Start of char buffer + *@param count Number of bytes to read + */ + void InputBytes(char* data, int count) + { + //int j=mp_stream->tellg(); + mp_stream->read(data, count); -// BIT DEFS -#define BIT_ZERO 0 -#define BIT_ONE 1 - -// most significant bit in a character -#define MS_BIT (1 << (CHAR_BIT - 1)) - -/* array index for character containing bit */ -//#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT-1-bit)) -#define BIT_IN_CHAR(bit) (1 << bit) - + //int h=mp_stream->tellg(); + } -/** -* Class ByteIO - top-level class for reading/writing bytes to a stream -*/ -class ByteIO -{ -public: - - /** - * Default constructor - *@param new_stream Has Creates & owns data buffer - */ - ByteIO(bool new_stream = true); - - /** - * Constructor - *@param stream_data Copies data buffer details - */ - ByteIO(const ByteIO& stream_data); - - /** - * Destructor - */ - virtual ~ByteIO(); - - /** - * Gathers byte-stream statistics - *@param dirac_byte_stats Collates byte information - */ - virtual void CollateByteStats(DiracByteStats& dirac_byte_stats) - { - dirac_byte_stats.Clear(); - } - - /** - * Get bytes in Dirac-bytestream format - */ - virtual const std::string GetBytes(); - - /** - * Get position of read stream pointer - */ - int GetReadBytePosition() const - { - return mp_stream->tellg(); - }; - - - /** - *Gets size (in bytes) - */ - virtual int GetSize() const; - - /** - * Copies stream source/destination info - *@param byte_io Byte source/destination - */ - void SetByteParams(const ByteIO& byte_io); - - /** - * Sync input for byte-alignment - */ - void ByteAlignOutput(); - - /** - * Ouputs an unsigned integer in interleaved exp Golomb format - *@param value Integer to be output - */ - //void OutputVarLengthUint(const unsigned int& value); - void WriteUint(unsigned int value); - - /** - * Sets input size in bits. Read is limited by this - */ - void SetBitsLeft(int left_bits) - { - m_bits_left = left_bits; - } - - /** - * Sets input size in bits. Read is limited by this - */ - int BitsLeft(void) - { - return m_bits_left; - } - -protected: - - inline bool CanRead() const - { - return(!mp_stream->eof()); - } - - inline bool GetBit(unsigned char& c, int pos) const - { - return (c & BIT_IN_CHAR(pos)); - } - - inline void SetBit(unsigned char& c, int pos) const - { - c |= BIT_IN_CHAR(pos); - } - - inline void SetBits(unsigned char& c, unsigned char bits) const - { - c |= bits; - } - - /** - * Sync input for byte-alignment - */ - void ByteAlignInput(); - - - /** - * Reads boolean value - */ - bool ReadBool(); - - /** - * Reads boolean value - bounded i/o - */ - bool ReadBoolB(); - - /** - * Reads next bit - */ - int ReadBit(); - - /** - * Reads next bit - bounded i/o - */ - int ReadBitB(); - - /** - * Reads next 'count' bits - *@param count number of bits to be read - *@return unsigned interger read - */ - unsigned int ReadNBits(int count); - - /** - * Reads from stream - *@param data Start of char buffer - *@param count Number of bytes to read - */ - void InputBytes(char* data, int count) - { - //int j=mp_stream->tellg(); - mp_stream->read(data, count); - - //int h=mp_stream->tellg(); - } - - /** - * Flushes the bounde input - */ - void FlushInputB(); - - /** - * Reads a signed integer in interleaved exp-Golomb format - *return Signed integer read - */ - //int InputVarLengthInt(); - int ReadSint(); - - /** - * Reads a signed integer in interleaved exp-Golomb format from bounded input - *return Signed integer read - */ - int ReadSintB(); - - /** - * Reads an unsigned integer in interleaved exp Golomb format - *@return Unsigned Integer read - */ - //unsigned int InputVarLengthUint(); - unsigned int ReadUint(); - - /** - * Reads an unsigned integer in interleaved exp Golomb format from bounded input - *@return Unsigned Integer read - */ - //unsigned int InputVarLengthUint(); - unsigned int ReadUintB(); - - /** - * Reads a fixed length unsigned integer from the stream in big endian - *@param byte_size Number of bytes in fixed length integer - *@return Unsigned Integer read - */ - //inline unsigned int InputFixedLengthUint(const int byte_size) { - inline unsigned int ReadUintLit(const int byte_size) - { - unsigned int val = 0; - for(int i = 0; i < byte_size; ++i) + /** + * Flushes the bounde input + */ + void FlushInputB(); + + /** + * Reads a signed integer in interleaved exp-Golomb format + *return Signed integer read + */ + //int InputVarLengthInt(); + int ReadSint(); + + /** + * Reads a signed integer in interleaved exp-Golomb format from bounded input + *return Signed integer read + */ + int ReadSintB(); + + /** + * Reads an unsigned integer in interleaved exp Golomb format + *@return Unsigned Integer read + */ + //unsigned int InputVarLengthUint(); + unsigned int ReadUint(); + + /** + * Reads an unsigned integer in interleaved exp Golomb format from bounded input + *@return Unsigned Integer read + */ + //unsigned int InputVarLengthUint(); + unsigned int ReadUintB(); + + /** + * Reads a fixed length unsigned integer from the stream in big endian + *@param byte_size Number of bytes in fixed length integer + *@return Unsigned Integer read + */ + //inline unsigned int InputFixedLengthUint(const int byte_size) { + inline unsigned int ReadUintLit(const int byte_size) { + unsigned int val=0; + for(int i=0; i < byte_size; ++i) + { + val <<= 8; + val += (unsigned char)mp_stream->get(); + } + m_num_bytes+=byte_size; + return val; + } + + /** + * Reads a byte from the stream + */ + inline unsigned char InputUnByte() {m_num_bytes++ ; return mp_stream->get(); } + + /** + * Reads a series of bytes from a stream + */ + inline std::string InputUnString(const int count) { - val <<= 8; - val += (unsigned char)mp_stream->get(); + std::string str; + for(int index=0; index < count; ++index) + str.push_back(InputUnByte()); + return str; } - m_num_bytes += byte_size; - return val; - } - - /** - * Reads a byte from the stream - */ - inline unsigned char InputUnByte() - { - m_num_bytes++ ; - return mp_stream->get(); - } - - /** - * Reads a series of bytes from a stream - */ - inline std::string InputUnString(const int count) - { - std::string str; - for(int index = 0; index < count; ++index) - str.push_back(InputUnByte()); - return str; - } - - /** - * Outputs a bit - *@param bit 1/0 Output - */ - void WriteBit(const bool& bit); - - /** - * Outputs an unsigned integer - *@param val Integer to be output - *@return number of bits written - */ - int WriteNBits(unsigned int val); - - /** - * Outputs an n bit integer - *@param val Unsigned Integer to be output - *@param count number of bits to be written - */ - void WriteNBits(unsigned int val, int count); - - - - /** - * Outputs a series of bytes - */ - void OutputBytes(const std::string& bytes) - { - int cur_pos = mp_stream->tellg(); - mp_stream->str(mp_stream->str() + bytes); - m_num_bytes += bytes.size(); + + /** + * Outputs a bit + *@param bit 1/0 Output + */ + void WriteBit(const bool& bit); + + /** + * Outputs an unsigned integer + *@param val Integer to be output + *@return number of bits written + */ + int WriteNBits(unsigned int val); + + /** + * Outputs an n bit integer + *@param val Unsigned Integer to be output + *@param count number of bits to be written + */ + void WriteNBits(unsigned int val, int count); + + + + /** + * Outputs a series of bytes + */ + void OutputBytes(const std::string& bytes) { + int cur_pos = mp_stream->tellg(); + mp_stream->str(mp_stream->str()+bytes); + m_num_bytes+=bytes.size(); // *mp_stream << bytes; - mp_stream->seekg(std::max(cur_pos, 0), std::ios_base::beg); - } - - /** - * Outputs current byte contents - */ - inline void OutputCurrentByte() - { - if(m_current_pos) - { - *mp_stream << (m_current_byte); - ++m_num_bytes; - m_current_pos = 0; - m_current_byte = 0; + mp_stream->seekg(std::max(cur_pos,0), std::ios_base::beg); } - }; - - /** - * Outputs an integer in Golomb signed integer format - *@param val Integer to be output - */ - //void OutputVarLengthInt(const int val); - void WriteSint(int val); - - /** - * Output unsigned int value in big endian format - * @param value Integer to be output - * @param length number of bytes in val to output - */ - //inline void OutputFixedLengthUint(const unsigned int& value, const int& length) - inline void WriteUintLit(const unsigned int& value, const int& length) - { - for(int i = length - 1; i >= 0 ; --i) + + /** + * Outputs current byte contents + */ + inline void OutputCurrentByte() { - unsigned char cp = (value >> (i * 8)) & 0xff; - *mp_stream << cp; - } - m_num_bytes += length; - } - - /** - * Removes portion of byte-stream no longer required - *@param count Number of bytes to be removed from beginning of stream - */ - void RemoveRedundantBytes(const int count); - - inline void SeekGet(const int offset, std::ios_base::seekdir dir) - { - mp_stream->seekg(offset, dir); - } - - /** - * Input/output steam - */ - std::stringstream* mp_stream; - - -private: - - /** - * ArithCodec can see internals for getting/setting bits - */ - friend class ArithCodecBase; - - /** - * VLC entropy coder can see internals for getting/setting bits - */ - friend class ArithCodecToVLCAdapter; - - /** - * Char used for temporary storage of op data bits - */ - unsigned char m_current_byte; - - /** - * Used to set individual bit within the current header byte - */ - int m_current_pos; - - /** - * Number of bytes processed - */ - int m_num_bytes; - - /** - * stream alloc flag - */ - bool m_new_stream; - - /** - * num bits left to read - */ - int m_bits_left; -protected: - - -}; + if (m_current_pos) + { + *mp_stream << (m_current_byte); + ++m_num_bytes; + m_current_pos = 0; + m_current_byte = 0; + } + }; + + /** + * Outputs an integer in Golomb signed integer format + *@param val Integer to be output + */ + //void OutputVarLengthInt(const int val); + void WriteSint(int val); + + /** + * Output unsigned int value in big endian format + * @param value Integer to be output + * @param length number of bytes in val to output + */ + //inline void OutputFixedLengthUint(const unsigned int& value, const int& length) + inline void WriteUintLit(const unsigned int& value, const int& length) + { + for(int i=length-1; i >=0 ; --i) + { + unsigned char cp = (value>>(i*8))&0xff; + *mp_stream << cp; + } + m_num_bytes+=length; + } + + /** + * Removes portion of byte-stream no longer required + *@param count Number of bytes to be removed from beginning of stream + */ + void RemoveRedundantBytes(const int count); + + inline void SeekGet(const int offset, std::ios_base::seekdir dir) + { + mp_stream->seekg(offset, dir); + } + + /** + * Input/output steam + */ + std::stringstream* mp_stream; + + + private: + + /** + * ArithCodec can see internals for getting/setting bits + */ + friend class ArithCodecBase; + + /** + * VLC entropy coder can see internals for getting/setting bits + */ + friend class ArithCodecToVLCAdapter; + + /** + * Char used for temporary storage of op data bits + */ + unsigned char m_current_byte; + + /** + * Used to set individual bit within the current header byte + */ + int m_current_pos; + + /** + * Number of bytes processed + */ + int m_num_bytes; + + /** + * stream alloc flag + */ + bool m_new_stream; + + /** + * num bits left to read + */ + int m_bits_left; + protected: + + + }; diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp index 69875e31b..7326b4562 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp @@ -42,13 +42,13 @@ using namespace dirac; CodingParamsByteIO::CodingParamsByteIO(const SourceParams& src_params, - CodecParams& codec_params, - const SourceParams& default_source_params, - const ByteIO& stream_data): - ByteIO(stream_data), - m_src_params(src_params), - m_codec_params(codec_params), - m_default_source_params(default_source_params) + CodecParams& codec_params, + const SourceParams& default_source_params, + const ByteIO& stream_data): +ByteIO(stream_data), +m_src_params(src_params), +m_codec_params(codec_params), +m_default_source_params(default_source_params) { } @@ -75,22 +75,22 @@ void CodingParamsByteIO::Input() // If source was coded as fields, halve the vertical dimensions // to set them to field dimensions - if(m_codec_params.FieldCoding()) + if (m_codec_params.FieldCoding()) { - m_codec_params.SetYl(m_codec_params.Yl() >> 1); - m_codec_params.SetChromaYl(m_codec_params.ChromaYl() >> 1); + m_codec_params.SetYl(m_codec_params.Yl()>>1); + m_codec_params.SetChromaYl(m_codec_params.ChromaYl()>>1); } unsigned int luma_depth = static_cast - ( - std::log((double)m_src_params.LumaExcursion()) / std::log(2.0) + 1 - ); + ( + std::log((double)m_src_params.LumaExcursion())/std::log(2.0) + 1 + ); m_codec_params.SetLumaDepth(luma_depth); unsigned int chroma_depth = static_cast - ( - std::log((double)m_src_params.ChromaExcursion()) / std::log(2.0) + 1 - ); + ( + std::log((double)m_src_params.ChromaExcursion())/std::log(2.0) + 1 + ); m_codec_params.SetChromaDepth(chroma_depth); // byte align @@ -112,7 +112,7 @@ void CodingParamsByteIO::Output() void CodingParamsByteIO::InputPictureCodingMode() { unsigned int coding_mode = ReadUint(); - if(coding_mode > 1) + if (coding_mode > 1) { std::ostringstream errstr; errstr << "Picture coding mode " << coding_mode diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h index 05b512df8..b96b037a0 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h @@ -51,83 +51,83 @@ namespace dirac { - -/** -* Represents compressed sequence-parameter data used in an AccessUnit -*/ -class CodingParamsByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param src_params Source parameters - *@param codec_params Coding parameters - *@param default_source_params Default source parameters - *@param stream_data Source/Destination of data - */ - CodingParamsByteIO(const SourceParams& src_params, - CodecParams& codec_params, - const SourceParams& default_source_params, - const ByteIO& stream_data); - - - /** - * Destructor - */ - ~CodingParamsByteIO(); - - /** - * Reads sequence information from Dirac byte-format - */ - void Input(); - - /** - * Outputs sequence information to Dirac byte-format - */ - void Output(); - -protected: - - -private: - - /** - * Reads number of bits used to compress input signal - */ - void InputVideoDepth(); - - /** - * Reads picture coding mode - 0 - frames, 1 - fields - */ - void InputPictureCodingMode(); - - /** - * Outputs number of bits used to compress input signal - */ - void OutputVideoDepth(); - + /** - * Outputs how input was coded - i.e. frames or fields + * Represents compressed sequence-parameter data used in an AccessUnit */ - void OutputPictureCodingMode(); - - /** - * Source paramters for intput/output - */ - const SourceParams& m_src_params; - - /** - * Coding paramters for intput/output - */ - CodecParams& m_codec_params; - - /** - * Default source parameters - */ - const SourceParams& m_default_source_params; - -}; + class CodingParamsByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param src_params Source parameters + *@param codec_params Coding parameters + *@param default_source_params Default source parameters + *@param stream_data Source/Destination of data + */ + CodingParamsByteIO(const SourceParams& src_params, + CodecParams& codec_params, + const SourceParams& default_source_params, + const ByteIO& stream_data); + + + /** + * Destructor + */ + ~CodingParamsByteIO(); + + /** + * Reads sequence information from Dirac byte-format + */ + void Input(); + + /** + * Outputs sequence information to Dirac byte-format + */ + void Output(); + + protected: + + + private: + + /** + * Reads number of bits used to compress input signal + */ + void InputVideoDepth(); + + /** + * Reads picture coding mode - 0 - frames, 1 - fields + */ + void InputPictureCodingMode(); + + /** + * Outputs number of bits used to compress input signal + */ + void OutputVideoDepth(); + + /** + * Outputs how input was coded - i.e. frames or fields + */ + void OutputPictureCodingMode(); + + /** + * Source paramters for intput/output + */ + const SourceParams& m_src_params; + + /** + * Coding paramters for intput/output + */ + CodecParams& m_codec_params; + + /** + * Default source parameters + */ + const SourceParams& m_default_source_params; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp index 88a63811a..07f5433d1 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp @@ -42,13 +42,13 @@ using namespace std; ComponentByteIO::ComponentByteIO(CompSort cs, const ByteIO& byteio): - ByteIO(byteio), - m_compsort(cs) +ByteIO(byteio), +m_compsort(cs) {} ComponentByteIO::ComponentByteIO(CompSort cs): - ByteIO(), - m_compsort(cs) +ByteIO(), +m_compsort(cs) {} ComponentByteIO::~ComponentByteIO() @@ -83,16 +83,16 @@ void ComponentByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) bool ComponentByteIO::Input() { - - return true; + + return true; } void ComponentByteIO::Output() { - + } //-------------private------------------------------------------------------- - + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h index 03ee2f1ea..e80b0877a 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h @@ -52,73 +52,73 @@ namespace dirac { -/** -* Picture component in Dirac bytestream format -*/ -class ComponentByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param cs Picture-component type - *@param byteIO Input/output Byte stream - */ - ComponentByteIO(CompSort cs, - const ByteIO& byteIO); - - /** - * Constructor - *@param cs Picture-component type - */ - ComponentByteIO(CompSort cs); - /** - * Destructor + * Picture component in Dirac bytestream format */ - ~ComponentByteIO(); - - /** - * Gathers byte stats on the component data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Add a subband byte-stream to this component - *@param p_subband_byteio Subband to be added - */ - void AddSubband(SubbandByteIO *p_subband_byteio); - - /** - * Inputs data from Dirac stream-format - */ - bool Input(); - - /** - * Outputs picture values to Dirac stream-format - */ - void Output(); - - - -protected: - - -private: - - /** - * Picture component type - */ - CompSort m_compsort; - - /** - * List of subbands in output/input order - */ - std::vector m_subband_list; - - -}; + class ComponentByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param cs Picture-component type + *@param byteIO Input/output Byte stream + */ + ComponentByteIO(CompSort cs, + const ByteIO& byteIO); + + /** + * Constructor + *@param cs Picture-component type + */ + ComponentByteIO(CompSort cs); + + /** + * Destructor + */ + ~ComponentByteIO(); + + /** + * Gathers byte stats on the component data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Add a subband byte-stream to this component + *@param p_subband_byteio Subband to be added + */ + void AddSubband(SubbandByteIO *p_subband_byteio); + + /** + * Inputs data from Dirac stream-format + */ + bool Input(); + + /** + * Outputs picture values to Dirac stream-format + */ + void Output(); + + + + protected: + + + private: + + /** + * Picture component type + */ + CompSort m_compsort; + + /** + * List of subbands in output/input order + */ + std::vector m_subband_list; + + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp index 883badb14..9c697bc3d 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp @@ -46,7 +46,7 @@ DiracByteStats::DiracByteStats() } DiracByteStats::DiracByteStats(const DiracByteStats& dirac_byte_stats): - m_byte_count(dirac_byte_stats.m_byte_count) +m_byte_count(dirac_byte_stats.m_byte_count) { } @@ -60,25 +60,25 @@ void DiracByteStats::Clear() m_byte_count.clear(); } -int64_t DiracByteStats::GetBitCount(const StatType& stat_type) const +int64_t DiracByteStats::GetBitCount(const StatType& stat_type) const { return GetByteCount(stat_type) * CHAR_BIT; } int64_t DiracByteStats::GetByteCount(const StatType& stat_type) const { - std::map::const_iterator it; - it = m_byte_count.find(stat_type); - if(it == m_byte_count.end()) - return 0; + std::map::const_iterator it; + it = m_byte_count.find(stat_type); + if(it==m_byte_count.end()) + return 0; - return it->second; + return it->second; } void DiracByteStats::SetByteCount(const StatType& stat_type, int64_t count) { - if(m_byte_count.find(stat_type) == m_byte_count.end()) - m_byte_count[stat_type] = 0; + if(m_byte_count.find(stat_type)==m_byte_count.end()) + m_byte_count[stat_type]=0; - m_byte_count[stat_type] += count; -} + m_byte_count[stat_type]+=count; + } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h index d32635a2a..0da273f0a 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h @@ -50,71 +50,70 @@ namespace dirac { -#ifdef _MSC_VER -// char length -#define CHAR_BIT 8 + #ifdef _MSC_VER + // char length + #define CHAR_BIT 8 #endif -typedef enum -{ - STAT_TOTAL_BYTE_COUNT = 0, - STAT_MV_BYTE_COUNT, - STAT_YCOMP_BYTE_COUNT, - STAT_UCOMP_BYTE_COUNT, - STAT_VCOMP_BYTE_COUNT -} StatType; - - -/** -* Class DiracByteStats - for collecting statistics on aspects of the Dirac byte-stream -*/ -class DiracByteStats -{ -public: - /** - * Constructor - */ - DiracByteStats(); - - /** - * Copy constructor - */ - DiracByteStats(const DiracByteStats& dirac_byte_stats); - - /** - * Destructor - */ - ~DiracByteStats(); - - /** - * Clears data - */ - void Clear(); - - /** - * Gets number of bits for a particular stat-type - */ - int64_t GetBitCount(const StatType& stat_type) const; - - /** - * Gets number of bytes for a particular stat-type - */ - int64_t GetByteCount(const StatType& stat_type) const; - - /** - * Sets number of bytes for a particular stat-type - */ - void SetByteCount(const StatType& stat_type, int64_t count); - - -private: - - /** - * Map of byte-counts - */ - std::map m_byte_count; - -}; + typedef enum { + STAT_TOTAL_BYTE_COUNT=0, + STAT_MV_BYTE_COUNT, + STAT_YCOMP_BYTE_COUNT, + STAT_UCOMP_BYTE_COUNT, + STAT_VCOMP_BYTE_COUNT + } StatType; + + + /** + * Class DiracByteStats - for collecting statistics on aspects of the Dirac byte-stream + */ + class DiracByteStats + { + public: + /** + * Constructor + */ + DiracByteStats(); + + /** + * Copy constructor + */ + DiracByteStats(const DiracByteStats& dirac_byte_stats); + + /** + * Destructor + */ + ~DiracByteStats(); + + /** + * Clears data + */ + void Clear(); + + /** + * Gets number of bits for a particular stat-type + */ + int64_t GetBitCount(const StatType& stat_type) const; + + /** + * Gets number of bytes for a particular stat-type + */ + int64_t GetByteCount(const StatType& stat_type) const; + + /** + * Sets number of bytes for a particular stat-type + */ + void SetByteCount(const StatType& stat_type, int64_t count); + + + private: + + /** + * Map of byte-counts + */ + std::map m_byte_count; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp index b31e8de47..a45e54706 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp @@ -44,8 +44,8 @@ using namespace dirac; using namespace std; DiracByteStream::DiracByteStream(): - ByteIO(), - mp_prev_parse_unit(NULL) +ByteIO(), +mp_prev_parse_unit(NULL) { } @@ -86,29 +86,29 @@ void DiracByteStream::Reset(ParseUnitByteIO* p_curr_unit, int pos) ParseUnitByteIO* DiracByteStream::GetNextParseUnit() { - if(GetSize() == 0) + if(GetSize()==0) return NULL; - int pos = 0; + int pos=0; if(mp_prev_parse_unit) { // remove the unwanted bytes associated with the previous parse-unit int prev_offset = mp_prev_parse_unit->GetNextParseOffset(); RemoveRedundantBytes(prev_offset ? prev_offset : mp_prev_parse_unit->GetSize()); delete mp_prev_parse_unit; - mp_prev_parse_unit = NULL; + mp_prev_parse_unit=NULL; if(!GetSize()) return NULL; } - ParseUnitByteIO* p_curr_unit = NULL; + ParseUnitByteIO* p_curr_unit=NULL; while(true) { pos = GetReadBytePosition(); p_curr_unit = new ParseUnitByteIO(*this); - if(!p_curr_unit->Input()) + if (!p_curr_unit->Input()) { Reset(p_curr_unit, pos); return NULL; @@ -121,7 +121,7 @@ ParseUnitByteIO* DiracByteStream::GetNextParseUnit() return NULL; } - if(p_curr_unit->IsEndOfSequence()) + if (p_curr_unit->IsEndOfSequence()) { break; } @@ -140,15 +140,15 @@ ParseUnitByteIO* DiracByteStream::GetNextParseUnit() } // while // Remove all redundant bytes that are not part of a parse unit - int remove_size = std::max(0, GetReadBytePosition() - p_curr_unit->GetSize()); - if(remove_size) + int remove_size = std::max (0, GetReadBytePosition()-p_curr_unit->GetSize()); + if (remove_size) { - //std::cerr << "Size="< 1) + if (source_sampling > 1) { std::ostringstream errstr; errstr << "Source Sampling " << source_sampling @@ -279,25 +279,25 @@ void SourceParamsByteIO::InputSignalRange() // read index value int signal_range_index = ReadUint(); SignalRangeType signal_range = IntToSignalRangeType(signal_range_index); - if(signal_range == SIGNAL_RANGE_UNDEFINED) + if(signal_range==SIGNAL_RANGE_UNDEFINED) DIRAC_THROW_EXCEPTION( - ERR_INVALID_SIGNAL_RANGE, - "Dirac does not recognise the specified signal-range", - SEVERITY_ACCESSUNIT_ERROR) + ERR_INVALID_SIGNAL_RANGE, + "Dirac does not recognise the specified signal-range", + SEVERITY_ACCESSUNIT_ERROR) - if(signal_range_index != SIGNAL_RANGE_CUSTOM) - { - m_src_params.SetSignalRange(signal_range); - } - else - { - // read luma values - m_src_params.SetLumaOffset(ReadUint()); - m_src_params.SetLumaExcursion(ReadUint()); - // read chroma values - m_src_params.SetChromaOffset(ReadUint()); - m_src_params.SetChromaExcursion(ReadUint()); - } + if(signal_range_index!=SIGNAL_RANGE_CUSTOM) + { + m_src_params.SetSignalRange(signal_range); + } + else + { + // read luma values + m_src_params.SetLumaOffset( ReadUint() ); + m_src_params.SetLumaExcursion( ReadUint() ); + // read chroma values + m_src_params.SetChromaOffset( ReadUint() ); + m_src_params.SetChromaExcursion( ReadUint() ); + } } void SourceParamsByteIO::InputTransferFunction() @@ -315,8 +315,8 @@ void SourceParamsByteIO::OutputFrameSize() { // output 'is custom' dimensions flag - bool is_custom = (m_src_params.Xl() != m_default_src_params.Xl() || - m_src_params.Yl() != m_default_src_params.Yl()); + bool is_custom = (m_src_params.Xl()!=m_default_src_params.Xl() || + m_src_params.Yl()!=m_default_src_params.Yl()); WriteBit(is_custom); @@ -332,8 +332,8 @@ void SourceParamsByteIO::OutputFrameSize() void SourceParamsByteIO::OutputChromaSamplingFormat() { // output 'is default' flag - bool not_default = m_src_params.CFormat() != m_default_src_params.CFormat(); - + bool not_default = m_src_params.CFormat()!=m_default_src_params.CFormat(); + WriteBit(not_default); if(!not_default) @@ -346,20 +346,20 @@ void SourceParamsByteIO::OutputChromaSamplingFormat() void SourceParamsByteIO::OutputPixelAspectRatio() { - if(m_src_params.PixelAspectRatioIndex() != PIXEL_ASPECT_RATIO_CUSTOM - && m_src_params.PixelAspectRatioIndex() == m_default_src_params.PixelAspectRatioIndex()) + if (m_src_params.PixelAspectRatioIndex()!= PIXEL_ASPECT_RATIO_CUSTOM + && m_src_params.PixelAspectRatioIndex() == m_default_src_params.PixelAspectRatioIndex()) { // default frame rate index WriteBit(0); return; } // Non-defaults - WriteBit(1); + WriteBit(1); // Picture rate index WriteUint(m_src_params.PixelAspectRatioIndex()); - - if(!m_src_params.PixelAspectRatioIndex()) // i,e. custom value + + if (!m_src_params.PixelAspectRatioIndex()) // i,e. custom value { WriteUint(m_src_params.PixelAspectRatio().m_num); WriteUint(m_src_params.PixelAspectRatio().m_denom); @@ -369,10 +369,10 @@ void SourceParamsByteIO::OutputPixelAspectRatio() void SourceParamsByteIO::OutputCleanArea() { - if(m_src_params.CleanWidth() != m_default_src_params.CleanWidth() || - m_src_params.CleanHeight() != m_default_src_params.CleanHeight() || - m_src_params.LeftOffset() != m_default_src_params.LeftOffset() || - m_src_params.TopOffset() != m_default_src_params.TopOffset()) + if (m_src_params.CleanWidth() != m_default_src_params.CleanWidth() || + m_src_params.CleanHeight() != m_default_src_params.CleanHeight() || + m_src_params.LeftOffset() != m_default_src_params.LeftOffset() || + m_src_params.TopOffset() != m_default_src_params.TopOffset()) { WriteBit(1); // non-default value WriteUint(m_src_params.CleanWidth()); @@ -386,9 +386,9 @@ void SourceParamsByteIO::OutputCleanArea() void SourceParamsByteIO::OutputColourSpecification() { - if(m_src_params.ColourSpecificationIndex() && - m_src_params.ColourSpecificationIndex() == - m_default_src_params.ColourSpecificationIndex()) + if (m_src_params.ColourSpecificationIndex() && + m_src_params.ColourSpecificationIndex() == + m_default_src_params.ColourSpecificationIndex()) { // default colour specification WriteBit(0); @@ -396,14 +396,14 @@ void SourceParamsByteIO::OutputColourSpecification() } // Non-defaults - WriteBit(1); + WriteBit(1); // Output Colour specification index WriteUint(m_src_params.ColourSpecificationIndex()); - if(!m_src_params.ColourSpecificationIndex()) // i,e, custom values + if (!m_src_params.ColourSpecificationIndex()) // i,e, custom values { // Output Colour Primaries - if(m_src_params.ColourPrimariesIndex() == m_default_src_params.ColourPrimariesIndex()) + if (m_src_params.ColourPrimariesIndex() == m_default_src_params.ColourPrimariesIndex()) { // default value WriteBit(0); @@ -415,7 +415,7 @@ void SourceParamsByteIO::OutputColourSpecification() } // Output Colour Matrix - if(m_src_params.ColourMatrixIndex() == m_default_src_params.ColourMatrixIndex()) + if (m_src_params.ColourMatrixIndex() == m_default_src_params.ColourMatrixIndex()) { // default value WriteBit(0); @@ -427,7 +427,7 @@ void SourceParamsByteIO::OutputColourSpecification() } // Output TransferFunction - if(m_src_params.TransferFunctionIndex() == m_default_src_params.TransferFunctionIndex()) + if (m_src_params.TransferFunctionIndex() == m_default_src_params.TransferFunctionIndex()) { // default value WriteBit(0); @@ -442,20 +442,20 @@ void SourceParamsByteIO::OutputColourSpecification() void SourceParamsByteIO::OutputFrameRate() { - if(m_src_params.FrameRateIndex() != FRAMERATE_CUSTOM - && m_src_params.FrameRateIndex() == m_default_src_params.FrameRateIndex()) + if (m_src_params.FrameRateIndex()!=FRAMERATE_CUSTOM + && m_src_params.FrameRateIndex() == m_default_src_params.FrameRateIndex()) { // default frame rate index WriteBit(0); return; } // Non-defaults - WriteBit(1); + WriteBit(1); // Picture rate index WriteUint(m_src_params.FrameRateIndex()); - - if(!m_src_params.FrameRateIndex()) // i,e. custom value + + if (!m_src_params.FrameRateIndex()) // i,e. custom value { WriteUint(m_src_params.FrameRate().m_num); WriteUint(m_src_params.FrameRate().m_denom); @@ -465,8 +465,8 @@ void SourceParamsByteIO::OutputFrameRate() void SourceParamsByteIO::OutputScanFormat() { // output 'is default' flag - bool not_interlace_default = m_src_params.SourceSampling() != m_default_src_params.SourceSampling(); - + bool not_interlace_default = m_src_params.SourceSampling()!=m_default_src_params.SourceSampling(); + WriteBit(not_interlace_default); if(!not_interlace_default) @@ -479,20 +479,20 @@ void SourceParamsByteIO::OutputScanFormat() void SourceParamsByteIO::OutputSignalRange() { - if(m_src_params.SignalRangeIndex() != SIGNAL_RANGE_CUSTOM && - m_src_params.SignalRangeIndex() == m_default_src_params.SignalRangeIndex()) + if (m_src_params.SignalRangeIndex()!=SIGNAL_RANGE_CUSTOM && + m_src_params.SignalRangeIndex() == m_default_src_params.SignalRangeIndex()) { // defaults WriteBit(0); return; } - + // Non-defaults - WriteBit(1); + WriteBit(1); // Output Signal Range Index WriteUint(m_src_params.SignalRangeIndex()); - if(!m_src_params.SignalRangeIndex()) // i.e. custom values + if (!m_src_params.SignalRangeIndex()) // i.e. custom values { WriteUint(m_src_params.LumaOffset()); WriteUint(m_src_params.LumaExcursion()); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h index 12cf7cec6..bc5fe823d 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h @@ -51,148 +51,148 @@ namespace dirac { - -/** -* Represents compressed source-parameter data contained in a sequence header -*/ -class SourceParamsByteIO : public ByteIO -{ -public: - - /** - * Constructor for Input/Output - *@param src_params Source parameters - *@param default_src_params Default Source parameters - *@param stream_data Source/Destination of data - */ - SourceParamsByteIO(SourceParams& src_params, - const SourceParams& default_src_params, - const ByteIO& stream_data); - /** - * Destructor - */ - ~SourceParamsByteIO(); - - /** - * Reads source params information from Dirac byte-format - */ - void Input(); - - /** - * Outputs source params information to Dirac byte-format - */ - void Output(); - -protected: - - -private: - - /** - * Reads frame dimensions - */ - void InputFrameSize(); - - /** - * Reads Chroma Sampling Format - */ - void InputChromaSamplingFormat(); - - /** - * Reads pixel aspect ratio info - */ - void InputPixelAspectRatio(); - - /** - * Reads clean-area info - */ - void InputCleanArea(); - - /** - * Reads colour-matrix info - */ - void InputColourMatrix(); - - /** - * Reads primary-colour info - */ - void InputColourPrimaries(); - - /** - * Reads colour spec info - */ - void InputColourSpecification(); - - /** - * Reads frame-rate info - */ - void InputFrameRate(); - - /** - * Reads Scan info - */ - void InputScanFormat(); - - /** - * Reads signal range info - */ - void InputSignalRange(); - - /** - * Reads transfer-function info - */ - void InputTransferFunction(); - - /** - * Outputs frame dimensions - */ - void OutputFrameSize(); - - /** - * Outputs Chroma Sampling Format - */ - void OutputChromaSamplingFormat(); - - /** - * Outputs pixel aspect ratio info - */ - void OutputPixelAspectRatio(); - - /** - * Outputs clean-area info - */ - void OutputCleanArea(); - - /** - * Outputs colour spec info - */ - void OutputColourSpecification(); - - /** - * Outputs frame-rate info - */ - void OutputFrameRate(); - - /** - * Outputs Scan info - */ - void OutputScanFormat(); - - /** - * Outputs signal range info - */ - void OutputSignalRange(); - - /** - * Source parameters for input/ouput - */ - SourceParams& m_src_params; - - /** - * Default source parameters - */ - const SourceParams& m_default_src_params; -}; + + /** + * Represents compressed source-parameter data contained in a sequence header + */ + class SourceParamsByteIO : public ByteIO + { + public: + + /** + * Constructor for Input/Output + *@param src_params Source parameters + *@param default_src_params Default Source parameters + *@param stream_data Source/Destination of data + */ + SourceParamsByteIO( SourceParams& src_params, + const SourceParams& default_src_params, + const ByteIO& stream_data); + /** + * Destructor + */ + ~SourceParamsByteIO(); + + /** + * Reads source params information from Dirac byte-format + */ + void Input(); + + /** + * Outputs source params information to Dirac byte-format + */ + void Output(); + + protected: + + + private: + + /** + * Reads frame dimensions + */ + void InputFrameSize(); + + /** + * Reads Chroma Sampling Format + */ + void InputChromaSamplingFormat(); + + /** + * Reads pixel aspect ratio info + */ + void InputPixelAspectRatio(); + + /** + * Reads clean-area info + */ + void InputCleanArea(); + + /** + * Reads colour-matrix info + */ + void InputColourMatrix(); + + /** + * Reads primary-colour info + */ + void InputColourPrimaries(); + + /** + * Reads colour spec info + */ + void InputColourSpecification(); + + /** + * Reads frame-rate info + */ + void InputFrameRate(); + + /** + * Reads Scan info + */ + void InputScanFormat(); + + /** + * Reads signal range info + */ + void InputSignalRange(); + + /** + * Reads transfer-function info + */ + void InputTransferFunction(); + + /** + * Outputs frame dimensions + */ + void OutputFrameSize(); + + /** + * Outputs Chroma Sampling Format + */ + void OutputChromaSamplingFormat(); + + /** + * Outputs pixel aspect ratio info + */ + void OutputPixelAspectRatio(); + + /** + * Outputs clean-area info + */ + void OutputCleanArea(); + + /** + * Outputs colour spec info + */ + void OutputColourSpecification(); + + /** + * Outputs frame-rate info + */ + void OutputFrameRate(); + + /** + * Outputs Scan info + */ + void OutputScanFormat(); + + /** + * Outputs signal range info + */ + void OutputSignalRange(); + + /** + * Source parameters for input/ouput + */ + SourceParams& m_src_params; + + /** + * Default source parameters + */ + const SourceParams& m_default_src_params; + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp index 58f74870a..ca0144e8e 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp @@ -46,9 +46,9 @@ using namespace std; EndOfSequenceByteIO::EndOfSequenceByteIO(const ByteIO& byte_io): - ParseUnitByteIO(byte_io) +ParseUnitByteIO(byte_io) { - + } @@ -65,14 +65,14 @@ void EndOfSequenceByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) //-------------private------------------------------------------------------- - + unsigned char EndOfSequenceByteIO::CalcParseCode() const { unsigned char code = 0; - // set end-of-sequence parse-code - SetBits(code, PARSE_CODE_END_OF_SEQUENCE); + // set end-of-sequence parse-code + SetBits(code, PARSE_CODE_END_OF_SEQUENCE); - return code; + return code; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h index f1b7bdb87..0bce3997f 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h @@ -50,60 +50,54 @@ namespace dirac { -/** -* Signals the end of a sequence in a Dirac-formatted bitstream. Current Accessunit parameters -* are no longer valid for subsequent frames -*/ -class EndOfSequenceByteIO : public ParseUnitByteIO -{ -public: - - /** - * Constructor - *@param stream_data Stream parameters - */ - EndOfSequenceByteIO(const ByteIO& stream_data); - - /** - * Destructor - */ - ~EndOfSequenceByteIO(); - - - /** - * Gets parse-unit type - */ - ParseUnitType GetType() const - { - return PU_END_OF_SEQUENCE; - } - - /** - * Gathers byte stats on the end of sequence data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); -protected: - /** - * Calculates number of bytes to start of next unit - *@return Zero(0) End of sequence does not specify a 'next'unit + * Signals the end of a sequence in a Dirac-formatted bitstream. Current Accessunit parameters + * are no longer valid for subsequent frames */ - int CalcNextUnitOffset() + class EndOfSequenceByteIO : public ParseUnitByteIO { - return 0; - } - -private: - - /** - * Calculates parse-code based on picture parameters - *@return Char bit-set - */ - unsigned char CalcParseCode() const; - - -}; + public: + + /** + * Constructor + *@param stream_data Stream parameters + */ + EndOfSequenceByteIO(const ByteIO& stream_data); + + /** + * Destructor + */ + ~EndOfSequenceByteIO(); + + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_END_OF_SEQUENCE;} + + /** + * Gathers byte stats on the end of sequence data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + protected: + + /** + * Calculates number of bytes to start of next unit + *@return Zero(0) End of sequence does not specify a 'next'unit + */ + int CalcNextUnitOffset() { return 0;} + + private: + + /** + * Calculates parse-code based on picture parameters + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp index 075fe0176..2ed0357aa 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp @@ -42,35 +42,35 @@ using namespace dirac; MvDataByteIO::MvDataByteIO(PictureParams& pparams, - PicturePredParams& picpredparams): - ByteIO(), - m_pparams(pparams), - m_picpredparams(picpredparams), - m_splitmode_data(), - m_predmode_data(), - m_mv1hblock_data(), - m_mv1vblock_data(), - m_mv2hblock_data(), - m_mv2vblock_data(), - m_ydcblock_data(), - m_udcblock_data(), - m_vdcblock_data() + PicturePredParams& picpredparams): +ByteIO(), +m_pparams(pparams), +m_picpredparams(picpredparams), +m_splitmode_data(), +m_predmode_data(), +m_mv1hblock_data(), +m_mv1vblock_data(), +m_mv2hblock_data(), +m_mv2vblock_data(), +m_ydcblock_data(), +m_udcblock_data(), +m_vdcblock_data() {} MvDataByteIO::MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, - PicturePredParams& picpredparams): - ByteIO(byte_io), - m_pparams(pparams), - m_picpredparams(picpredparams), - m_splitmode_data(byte_io), - m_predmode_data(byte_io), - m_mv1hblock_data(byte_io), - m_mv1vblock_data(byte_io), - m_mv2hblock_data(byte_io), - m_mv2vblock_data(byte_io), - m_ydcblock_data(byte_io), - m_udcblock_data(byte_io), - m_vdcblock_data(byte_io) + PicturePredParams& picpredparams): +ByteIO(byte_io), +m_pparams(pparams), +m_picpredparams(picpredparams), +m_splitmode_data(byte_io), +m_predmode_data(byte_io), +m_mv1hblock_data(byte_io), +m_mv1vblock_data(byte_io), +m_mv2hblock_data(byte_io), +m_mv2vblock_data(byte_io), +m_ydcblock_data(byte_io), +m_udcblock_data(byte_io), +m_vdcblock_data(byte_io) {} MvDataByteIO::~MvDataByteIO() @@ -85,50 +85,50 @@ void MvDataByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) int MvDataByteIO::GetSize() const { - if(m_pparams.NumRefs() == 2) + if (m_pparams.NumRefs()==2) return ByteIO::GetSize() + - m_splitmode_data.GetSize() + - m_predmode_data.GetSize() + - m_mv1hblock_data.GetSize() + - m_mv1vblock_data.GetSize() + - m_mv2hblock_data.GetSize() + - m_mv2vblock_data.GetSize() + - m_ydcblock_data.GetSize() + - m_udcblock_data.GetSize() + + m_splitmode_data.GetSize()+ + m_predmode_data.GetSize()+ + m_mv1hblock_data.GetSize()+ + m_mv1vblock_data.GetSize()+ + m_mv2hblock_data.GetSize()+ + m_mv2vblock_data.GetSize()+ + m_ydcblock_data.GetSize()+ + m_udcblock_data.GetSize()+ m_vdcblock_data.GetSize(); else return ByteIO::GetSize() + - m_splitmode_data.GetSize() + - m_predmode_data.GetSize() + - m_mv1hblock_data.GetSize() + - m_mv1vblock_data.GetSize() + - m_ydcblock_data.GetSize() + - m_udcblock_data.GetSize() + + m_splitmode_data.GetSize()+ + m_predmode_data.GetSize()+ + m_mv1hblock_data.GetSize()+ + m_mv1vblock_data.GetSize()+ + m_ydcblock_data.GetSize()+ + m_udcblock_data.GetSize()+ m_vdcblock_data.GetSize(); } const std::string MvDataByteIO::GetBytes() { //Output header and block data - if(m_pparams.NumRefs() == 2) + if (m_pparams.NumRefs()==2 ) return ByteIO::GetBytes() + - m_splitmode_data.GetBytes() + - m_predmode_data.GetBytes() + - m_mv1hblock_data.GetBytes() + - m_mv1vblock_data.GetBytes() + - m_mv2hblock_data.GetBytes() + - m_mv2vblock_data.GetBytes() + - m_ydcblock_data.GetBytes() + - m_udcblock_data.GetBytes() + + m_splitmode_data.GetBytes()+ + m_predmode_data.GetBytes()+ + m_mv1hblock_data.GetBytes()+ + m_mv1vblock_data.GetBytes()+ + m_mv2hblock_data.GetBytes()+ + m_mv2vblock_data.GetBytes()+ + m_ydcblock_data.GetBytes()+ + m_udcblock_data.GetBytes()+ m_vdcblock_data.GetBytes(); else return ByteIO::GetBytes() + - m_splitmode_data.GetBytes() + - m_predmode_data.GetBytes() + - m_mv1hblock_data.GetBytes() + - m_mv1vblock_data.GetBytes() + - m_ydcblock_data.GetBytes() + - m_udcblock_data.GetBytes() + + m_splitmode_data.GetBytes()+ + m_predmode_data.GetBytes()+ + m_mv1hblock_data.GetBytes()+ + m_mv1vblock_data.GetBytes()+ + m_ydcblock_data.GetBytes()+ + m_udcblock_data.GetBytes()+ m_vdcblock_data.GetBytes(); } @@ -186,7 +186,7 @@ void MvDataByteIO::OutputBlockParams() // output custom block params flag unsigned int pidx = BlockParametersIndex(olb_params); WriteUint(pidx); - if(pidx == 0) // custom block params + if (pidx == 0) // custom block params { // output Xblen WriteUint(olb_params.Xblen()); @@ -204,7 +204,7 @@ void MvDataByteIO::InputBlockParams() OLBParams olb_params; unsigned int p_idx = ReadUint(); - if(p_idx == 0) + if (p_idx == 0) { // Input Xblen olb_params.SetXblen(ReadUint()); @@ -216,7 +216,7 @@ void MvDataByteIO::InputBlockParams() olb_params.SetYbsep(ReadUint()); } else - SetDefaultBlockParameters(olb_params, p_idx); + SetDefaultBlockParameters (olb_params, p_idx); m_picpredparams.SetLumaBlockParams(olb_params); } @@ -231,13 +231,13 @@ void MvDataByteIO::InputMVPrecision() { // Input Motion vector precision MVPrecisionType mv_prec = IntToMVPrecisionType(ReadUint()); - if(mv_prec == MV_PRECISION_UNDEFINED) + if(mv_prec==MV_PRECISION_UNDEFINED) DIRAC_THROW_EXCEPTION( - ERR_INVALID_MOTION_VECTOR_PRECISION, - "Dirac does not recognise the specified MV precision", - SEVERITY_PICTURE_ERROR) + ERR_INVALID_MOTION_VECTOR_PRECISION, + "Dirac does not recognise the specified MV precision", + SEVERITY_PICTURE_ERROR) - m_picpredparams.SetMVPrecision(mv_prec); + m_picpredparams.SetMVPrecision(mv_prec); } void MvDataByteIO::OutputGlobalMotionParams() @@ -252,15 +252,15 @@ void MvDataByteIO::InputGlobalMotionParams() { // Always setting global motion to false // Using Global motion flag - if(ReadBool()) + if (ReadBool()) { m_picpredparams.SetUsingGlobalMotion(true); // NOTE: FIXME - input actual global motion params in future DIRAC_THROW_EXCEPTION( - ERR_UNSUPPORTED_STREAM_DATA, - "Cannot handle global motion parameters", - SEVERITY_PICTURE_ERROR) + ERR_UNSUPPORTED_STREAM_DATA, + "Cannot handle global motion parameters", + SEVERITY_PICTURE_ERROR) } else m_picpredparams.SetUsingGlobalMotion(false); @@ -278,7 +278,7 @@ void MvDataByteIO::InputFramePredictionMode() // TODO - need to process this field when alternative prediction modes // become available. unsigned int frame_pred_mode = ReadUint(); - if(frame_pred_mode != 0) + if (frame_pred_mode != 0) { DIRAC_THROW_EXCEPTION( ERR_UNSUPPORTED_STREAM_DATA, @@ -291,16 +291,16 @@ void MvDataByteIO::InputFramePredictionMode() void MvDataByteIO::OutputPictureWeights() { // Output default weights flags - if(m_picpredparams.PictureWeightsBits() != 1 || - m_picpredparams.Ref1Weight() != 1 || - (m_pparams.Refs().size() > 1 && m_picpredparams.Ref2Weight() != 1)) + if (m_picpredparams.PictureWeightsBits() != 1 || + m_picpredparams.Ref1Weight() != 1 || + (m_pparams.Refs().size() > 1 && m_picpredparams.Ref2Weight() != 1) ) { - WriteBit(true); + WriteBit(true); // Output weight precision bits WriteUint(m_picpredparams.PictureWeightsBits()); // Output Ref1 weight WriteSint(m_picpredparams.Ref1Weight()); - if(m_pparams.Refs().size() > 1) + if (m_pparams.Refs().size() > 1) { // Output Ref1 weight WriteSint(m_picpredparams.Ref2Weight()); @@ -308,17 +308,17 @@ void MvDataByteIO::OutputPictureWeights() } else { - WriteBit(false); + WriteBit(false); } } void MvDataByteIO::InputPictureWeights() { - if(ReadBool()) + if (ReadBool()) { m_picpredparams.SetPictureWeightsPrecision(ReadUint()); m_picpredparams.SetRef1Weight(ReadSint()); - if(m_pparams.Refs().size() > 1) + if (m_pparams.Refs().size() > 1) m_picpredparams.SetRef2Weight(ReadSint()); else m_picpredparams.SetRef2Weight(0); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h index ff809c3d5..578a3594e 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h @@ -53,244 +53,217 @@ namespace dirac { -/** -* Represents compressed sequence-parameter data used in an AccessUnit -*/ -class MvDataByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param pparams Picture Params - *@param picpredparams Picture prediction parameters - */ - MvDataByteIO(PictureParams& pparams, - PicturePredParams& picpredparams); - - /** - * Constructor - *@param byte_io Input/Output Byte stream - *@param pparams Picture Params - *@param picpredparams Picture prediction parameters - */ - MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, - PicturePredParams& picpredparams); - - /** - * Destructor - */ - virtual ~MvDataByteIO(); - - /** - * Gathers byte stats on the motion vector data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Outputs motion vector data Dirac byte-format - */ - void Output(); - - /** - * Inputs motion vector information - */ - void Input(); - - - /** - * Get string containing coded bytes - */ - virtual const std::string GetBytes(); - /** - * Return pointer to the superblock splitting modes ByteIO stream + * Represents compressed sequence-parameter data used in an AccessUnit */ - MvDataElementByteIO* SplitModeData() + class MvDataByteIO : public ByteIO { - return &m_splitmode_data; + public: + + /** + * Constructor + *@param pparams Picture Params + *@param picpredparams Picture prediction parameters + */ + MvDataByteIO(PictureParams& pparams, + PicturePredParams& picpredparams); + + /** + * Constructor + *@param byte_io Input/Output Byte stream + *@param pparams Picture Params + *@param picpredparams Picture prediction parameters + */ + MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, + PicturePredParams& picpredparams); + + /** + * Destructor + */ + virtual ~MvDataByteIO(); + + /** + * Gathers byte stats on the motion vector data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Outputs motion vector data Dirac byte-format + */ + void Output(); + + /** + * Inputs motion vector information + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return pointer to the superblock splitting modes ByteIO stream + */ + MvDataElementByteIO* SplitModeData() { return &m_splitmode_data; }; + + /** + * Return pointer to the superblock splitting modes ByteIO stream + */ + MvDataElementByteIO* PredModeData() { return &m_predmode_data; }; + + /** + * Return pointer to the block MVs reference 1 ByteIO stream + */ + MvDataElementByteIO* MV1HorizData() { return &m_mv1hblock_data; }; + + /** + * Return pointer to the block MVs reference 1 ByteIO stream + */ + MvDataElementByteIO* MV1VertData() { return &m_mv1vblock_data; }; + + /** + * Return pointer to the block MV reference 2 ByteIO stream + */ + MvDataElementByteIO* MV2HorizData() { return &m_mv2hblock_data; }; + + /** + * Return pointer to the block MV reference 2 ByteIO stream + */ + MvDataElementByteIO* MV2VertData() { return &m_mv2vblock_data; }; + + /** + * Return pointer to the block Y DC values ByteIO stream + */ + MvDataElementByteIO* YDCData() { return &m_ydcblock_data; }; + + /** + * Return pointer to the block U DC values ByteIO stream + */ + MvDataElementByteIO* UDCData() { return &m_udcblock_data; }; + + /** + * Return pointer to the block V DC values ByteIO stream + */ + MvDataElementByteIO* VDCData() { return &m_vdcblock_data; }; + + /** + * Return the size + */ + int GetSize() const; + + protected: + + + private: + /** + * Inputs block parameters + */ + void InputBlockParams(); + + /** + * Inputs Motion vector precision data + */ + void InputMVPrecision(); + + /** + * Inputs global motion parameters + */ + void InputGlobalMotionParams(); + + /** + * Inputs picture prediction mode + */ + void InputFramePredictionMode(); + + /** + * Inputs Picture Weights + */ + void InputPictureWeights(); + + /** + * Outputs block parameters + */ + void OutputBlockParams(); + + /** + * Outputs Motion vector precision data + */ + void OutputMVPrecision(); + + /** + * Outputs global motion parameters + */ + void OutputGlobalMotionParams(); + + /** + * Outputs picture prediction mode + */ + void OutputFramePredictionMode(); + + /** + * Outputs Picture Weights + */ + void OutputPictureWeights(); + + /** + * Sequence paramters for intput/output + */ + PictureParams& m_pparams; + + /** + * Codec params - EncParams for Output and DecParams for input + */ + PicturePredParams& m_picpredparams; + + /** + * block data containing split modes + */ + MvDataElementByteIO m_splitmode_data; + + /** + * block data containing prediction modes + */ + MvDataElementByteIO m_predmode_data; + + /** + * block data containing horizontal MV components for reference 1 + */ + MvDataElementByteIO m_mv1hblock_data; + + /** + * block data containing vertical MV components for reference 1 + */ + MvDataElementByteIO m_mv1vblock_data; + + /** + * block data containing horizontal MV components for reference 2 + */ + MvDataElementByteIO m_mv2hblock_data; + + /** + * block data containing vertical MV components for reference 2 + */ + MvDataElementByteIO m_mv2vblock_data; + + /** + * block data containing Y DC data + */ + MvDataElementByteIO m_ydcblock_data; + + /** + * block data containing U DC data + */ + MvDataElementByteIO m_udcblock_data; + + /** + * block data containing V DC data + */ + MvDataElementByteIO m_vdcblock_data; }; - /** - * Return pointer to the superblock splitting modes ByteIO stream - */ - MvDataElementByteIO* PredModeData() - { - return &m_predmode_data; - }; - - /** - * Return pointer to the block MVs reference 1 ByteIO stream - */ - MvDataElementByteIO* MV1HorizData() - { - return &m_mv1hblock_data; - }; - - /** - * Return pointer to the block MVs reference 1 ByteIO stream - */ - MvDataElementByteIO* MV1VertData() - { - return &m_mv1vblock_data; - }; - - /** - * Return pointer to the block MV reference 2 ByteIO stream - */ - MvDataElementByteIO* MV2HorizData() - { - return &m_mv2hblock_data; - }; - - /** - * Return pointer to the block MV reference 2 ByteIO stream - */ - MvDataElementByteIO* MV2VertData() - { - return &m_mv2vblock_data; - }; - - /** - * Return pointer to the block Y DC values ByteIO stream - */ - MvDataElementByteIO* YDCData() - { - return &m_ydcblock_data; - }; - - /** - * Return pointer to the block U DC values ByteIO stream - */ - MvDataElementByteIO* UDCData() - { - return &m_udcblock_data; - }; - - /** - * Return pointer to the block V DC values ByteIO stream - */ - MvDataElementByteIO* VDCData() - { - return &m_vdcblock_data; - }; - - /** - * Return the size - */ - int GetSize() const; - -protected: - - -private: - /** - * Inputs block parameters - */ - void InputBlockParams(); - - /** - * Inputs Motion vector precision data - */ - void InputMVPrecision(); - - /** - * Inputs global motion parameters - */ - void InputGlobalMotionParams(); - - /** - * Inputs picture prediction mode - */ - void InputFramePredictionMode(); - - /** - * Inputs Picture Weights - */ - void InputPictureWeights(); - - /** - * Outputs block parameters - */ - void OutputBlockParams(); - - /** - * Outputs Motion vector precision data - */ - void OutputMVPrecision(); - - /** - * Outputs global motion parameters - */ - void OutputGlobalMotionParams(); - - /** - * Outputs picture prediction mode - */ - void OutputFramePredictionMode(); - - /** - * Outputs Picture Weights - */ - void OutputPictureWeights(); - - /** - * Sequence paramters for intput/output - */ - PictureParams& m_pparams; - - /** - * Codec params - EncParams for Output and DecParams for input - */ - PicturePredParams& m_picpredparams; - - /** - * block data containing split modes - */ - MvDataElementByteIO m_splitmode_data; - - /** - * block data containing prediction modes - */ - MvDataElementByteIO m_predmode_data; - - /** - * block data containing horizontal MV components for reference 1 - */ - MvDataElementByteIO m_mv1hblock_data; - - /** - * block data containing vertical MV components for reference 1 - */ - MvDataElementByteIO m_mv1vblock_data; - - /** - * block data containing horizontal MV components for reference 2 - */ - MvDataElementByteIO m_mv2hblock_data; - - /** - * block data containing vertical MV components for reference 2 - */ - MvDataElementByteIO m_mv2vblock_data; - - /** - * block data containing Y DC data - */ - MvDataElementByteIO m_ydcblock_data; - - /** - * block data containing U DC data - */ - MvDataElementByteIO m_udcblock_data; - - /** - * block data containing V DC data - */ - MvDataElementByteIO m_vdcblock_data; -}; - } // namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp index 524845df4..f8785616d 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp @@ -44,14 +44,14 @@ using namespace dirac; MvDataElementByteIO::MvDataElementByteIO(): - ByteIO(), - m_block_data() +ByteIO(), +m_block_data() { } MvDataElementByteIO::MvDataElementByteIO(ByteIO &byte_io): - ByteIO(byte_io), - m_block_data(byte_io) +ByteIO(byte_io), +m_block_data(byte_io) { } @@ -88,7 +88,7 @@ void MvDataElementByteIO::Input() } void MvDataElementByteIO::Output() -{ +{ //Output size of block data WriteUint(m_block_data.GetSize()); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h index 6896ac7ea..2e0aa4211 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h @@ -53,80 +53,74 @@ namespace dirac { - -/** -* Represents compressed sequence-parameter data used in an AccessUnit -*/ -class MvDataElementByteIO : public ByteIO -{ -public: - - /** - * Constructor - */ - MvDataElementByteIO(); - - /** - * Constructor - *@param byte_io Input/Output Byte stream - */ - MvDataElementByteIO(ByteIO &byte_io); - - /** - * Destructor - */ - virtual ~MvDataElementByteIO(); - - /** - * Outputs motion vector data Dirac byte-format - */ - void Output(); - - /** - * Inputs motion vector information - */ - void Input(); - - - /** - * Get string containing coded bytes - */ - virtual const std::string GetBytes(); - + /** - * Return pointer to the block data ByteIO stream + * Represents compressed sequence-parameter data used in an AccessUnit */ - ByteIO* DataBlock() + class MvDataElementByteIO : public ByteIO { - return &m_block_data; + public: + + /** + * Constructor + */ + MvDataElementByteIO(); + + /** + * Constructor + *@param byte_io Input/Output Byte stream + */ + MvDataElementByteIO(ByteIO &byte_io); + + /** + * Destructor + */ + virtual ~MvDataElementByteIO(); + + /** + * Outputs motion vector data Dirac byte-format + */ + void Output(); + + /** + * Inputs motion vector information + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return pointer to the block data ByteIO stream + */ + ByteIO* DataBlock() { return &m_block_data; }; + + /** + * Return the input block data size + */ + unsigned int DataBlockSize() { return m_block_size; } + + /** + * Return the size + */ + int GetSize() const; + + protected: + + /** + * block data + */ + ByteIO m_block_data; + + /** + * In block data size + */ + unsigned int m_block_size; }; - /** - * Return the input block data size - */ - unsigned int DataBlockSize() - { - return m_block_size; - } - - /** - * Return the size - */ - int GetSize() const; - -protected: - - /** - * block data - */ - ByteIO m_block_data; - - /** - * In block data size - */ - unsigned int m_block_size; -}; - } // namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp index cd3691ee0..5034933bc 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp @@ -44,15 +44,15 @@ const unsigned int PP_AU_PICTURE_NUM_SIZE = 4; using namespace dirac; -ParseParamsByteIO::ParseParamsByteIO(const ByteIO& stream_data, - ParseParams &parse_params, - EncoderParams &enc_params): - ByteIO(stream_data), - m_parse_params(parse_params) +ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, + ParseParams &parse_params, + EncoderParams &enc_params): +ByteIO(stream_data), +m_parse_params(parse_params) { - if(enc_params.NumL1() == 0) + if (enc_params.NumL1() == 0) { - if(!enc_params.UsingAC()) + if (!enc_params.UsingAC()) { // Simple Profile m_parse_params.SetProfile(1); @@ -66,15 +66,15 @@ ParseParamsByteIO::ParseParamsByteIO(const ByteIO& stream_data, else { // Main (Long GOP) profile - m_parse_params.SetProfile(8); + m_parse_params.SetProfile(8); } // FIXME - no support for Low Delay Profile } -ParseParamsByteIO::ParseParamsByteIO(const ByteIO& stream_data, +ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, ParseParams &parse_params): - ByteIO(stream_data), - m_parse_params(parse_params) +ByteIO(stream_data), +m_parse_params(parse_params) { @@ -89,8 +89,8 @@ void ParseParamsByteIO::CheckVersion() std::ostringstream errstr; ParseParams def_parse_params; - if(m_parse_params.MajorVersion() > def_parse_params.MajorVersion() || - m_parse_params.MajorVersion() == 0 || + if (m_parse_params.MajorVersion() > def_parse_params.MajorVersion() || + m_parse_params.MajorVersion() == 0 || (m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && m_parse_params.MinorVersion() > def_parse_params.MinorVersion())) { @@ -103,7 +103,7 @@ void ParseParamsByteIO::CheckVersion() errstr << ". May not be able to decode bitstream correctly" << std::endl; } - if(errstr.str().size()) + if (errstr.str().size()) { DiracException err( ERR_UNSUPPORTED_STREAM_DATA, @@ -120,21 +120,21 @@ void ParseParamsByteIO::CheckProfile() // No profiles were specified in versions 1.0, 1.1, and 2.0 and 2.1. // So for these versions profile should be 0 in the bitstream - if(m_parse_params.MajorVersion() <= 2 && - m_parse_params.MinorVersion() < 2 && - m_parse_params.Profile() != 0) + if (m_parse_params.MajorVersion() <= 2 && + m_parse_params.MinorVersion() < 2 && + m_parse_params.Profile() != 0) { errstr << "Cannot handle profile " << m_parse_params.Profile() << " for bitstream version " << m_parse_params.MajorVersion() << "." << m_parse_params.MinorVersion(); errstr << ". May not be able to decode bitstream correctly" << std::endl; } - else if(m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && - m_parse_params.MinorVersion() == def_parse_params.MinorVersion() && - m_parse_params.Profile() != 1 /* Simple */ && - m_parse_params.Profile() != 2 /* Main (Intra) */ && - m_parse_params.Profile() != 8 /* Main (Long GOP) */ - ) + else if (m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && + m_parse_params.MinorVersion() == def_parse_params.MinorVersion() && + m_parse_params.Profile() != 1 /* Simple */ && + m_parse_params.Profile() != 2 /* Main (Intra) */ && + m_parse_params.Profile() != 8 /* Main (Long GOP) */ + ) { errstr << "Cannot handle profile " << m_parse_params.Profile() << " for bitstream version " << m_parse_params.MajorVersion() @@ -144,7 +144,7 @@ void ParseParamsByteIO::CheckProfile() errstr << ". May not be able to decode bitstream correctly" << std::endl; } - if(errstr.str().size()) + if (errstr.str().size()) { DiracException err( ERR_UNSUPPORTED_STREAM_DATA, @@ -160,15 +160,15 @@ void ParseParamsByteIO::CheckLevel() ParseParams def_parse_params; // No resources constraints for decoder - if(def_parse_params.Level() == 0) + if (def_parse_params.Level() == 0) return; // Constraints on Decoder. Can Handles level 1 for Simple and Main (Intra) // profiles, and level 128 for Main (Long GOP) Profile. - if(def_parse_params.Level() != 0) + if (def_parse_params.Level() != 0) { - if((m_parse_params.Profile() <= 2 && m_parse_params.Level() != 1) || - (m_parse_params.Profile() == 8 && m_parse_params.Level() != 128)) + if ((m_parse_params.Profile() <= 2 && m_parse_params.Level() != 1) || + (m_parse_params.Profile() ==8 && m_parse_params.Level() != 128)) { errstr << "Cannot handle Level " << m_parse_params.Level() << " for bitstream version " << m_parse_params.MajorVersion() @@ -180,7 +180,7 @@ void ParseParamsByteIO::CheckLevel() } } - if(errstr.str().size()) + if (errstr.str().size()) { DiracException err( ERR_UNSUPPORTED_STREAM_DATA, diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h index 04f040c2d..1e5423f31 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h @@ -51,65 +51,65 @@ namespace dirac { - -/** -* Represents compressed parse-parameter data used in an AccessUnit -*/ -class ParseParamsByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param stream_data Destination of data - *@param parse_params Parse parameters - *@param enc_params Encoder parameters - */ - ParseParamsByteIO(const ByteIO& stream_data, - ParseParams &parse_params, - EncoderParams &enc_params); - - /** - * Constructor - *@param stream_data Source of data - *@param parse_params Destination of parse params - */ - ParseParamsByteIO(const ByteIO& stream_data, - ParseParams &parse_params); - - /** - * Destructor - */ - ~ParseParamsByteIO(); - - /** - * Reads parse information from Dirac byte-format - */ - void Input(); - - /** - * Outputs parse information to Dirac byte-format - */ - void Output(); - - /** - * Get access-unit number - */ - int GetIdNumber() const; - -protected: - -private: - void CheckVersion(); - void CheckProfile(); - void CheckLevel(); - -private: + /** - * Reference to parse parameters + * Represents compressed parse-parameter data used in an AccessUnit */ - ParseParams& m_parse_params; -}; + class ParseParamsByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param stream_data Destination of data + *@param parse_params Parse parameters + *@param enc_params Encoder parameters + */ + ParseParamsByteIO(const ByteIO& stream_data, + ParseParams &parse_params, + EncoderParams &enc_params); + + /** + * Constructor + *@param stream_data Source of data + *@param parse_params Destination of parse params + */ + ParseParamsByteIO(const ByteIO& stream_data, + ParseParams &parse_params); + + /** + * Destructor + */ + ~ParseParamsByteIO(); + + /** + * Reads parse information from Dirac byte-format + */ + void Input(); + + /** + * Outputs parse information to Dirac byte-format + */ + void Output(); + + /** + * Get access-unit number + */ + int GetIdNumber() const; + + protected: + + private: + void CheckVersion(); + void CheckProfile(); + void CheckLevel(); + + private: + /** + * Reference to parse parameters + */ + ParseParams& m_parse_params; + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp index 9d4ac83de..56c0ebb8b 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp @@ -52,30 +52,30 @@ const int PU_NEXT_PARSE_OFFSET_SIZE = 4; const int PU_PREVIOUS_PARSE_OFFSET_SIZE = 4; const int PU_PREFIX_SIZE = 4; const int PU_PARSE_CODE_SIZE = 1; -const int PU_PARSEUNIT_SIZE = PU_NEXT_PARSE_OFFSET_SIZE + PU_PREVIOUS_PARSE_OFFSET_SIZE + +const int PU_PARSEUNIT_SIZE = PU_NEXT_PARSE_OFFSET_SIZE + PU_PREVIOUS_PARSE_OFFSET_SIZE+ PU_PREFIX_SIZE + PU_PARSE_CODE_SIZE; ParseUnitByteIO::ParseUnitByteIO(): - ByteIO(), - m_previous_parse_offset(0), - m_next_parse_offset(0) +ByteIO(), +m_previous_parse_offset(0), +m_next_parse_offset(0) { } ParseUnitByteIO::ParseUnitByteIO(const ByteIO& byte_io): - ByteIO(byte_io), - m_previous_parse_offset(0), - m_next_parse_offset(0) +ByteIO(byte_io), +m_previous_parse_offset(0), +m_next_parse_offset(0) { } ParseUnitByteIO::ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio): - ByteIO(parseunit_byteio), - m_previous_parse_offset(parseunit_byteio.m_previous_parse_offset), - m_next_parse_offset(parseunit_byteio.m_next_parse_offset), - m_parse_code(parseunit_byteio.m_parse_code) +ByteIO(parseunit_byteio), +m_previous_parse_offset(parseunit_byteio.m_previous_parse_offset), +m_next_parse_offset(parseunit_byteio.m_next_parse_offset), +m_parse_code(parseunit_byteio.m_parse_code) { } @@ -113,16 +113,16 @@ bool ParseUnitByteIO::Input() bool ParseUnitByteIO::IsValid() { - if(IsEndOfSequence()) + if (IsEndOfSequence()) return true; // Skip past the end of current parse unit - SeekGet(m_next_parse_offset - GetSize(), ios_base::cur); + SeekGet(m_next_parse_offset-GetSize(), ios_base::cur); // check the next series of bytes are the parse-info prefix string prefix = InputUnString(PU_PREFIX_SIZE); - if(prefix == PU_PREFIX) + if(prefix==PU_PREFIX) { unsigned char next_parse_code; @@ -133,28 +133,28 @@ bool ParseUnitByteIO::IsValid() int next_unit_previous_parse_offset; next_unit_previous_parse_offset = ReadUintLit(PU_PREVIOUS_PARSE_OFFSET_SIZE); - if(next_unit_previous_parse_offset == m_next_parse_offset) + if (next_unit_previous_parse_offset == m_next_parse_offset) { - SeekGet(-(m_next_parse_offset - GetSize() + PU_PARSEUNIT_SIZE), ios_base::cur); + SeekGet(-(m_next_parse_offset-GetSize()+PU_PARSEUNIT_SIZE), ios_base::cur); return true; } } - SeekGet(-(m_next_parse_offset - GetSize()), ios_base::cur); + SeekGet(-(m_next_parse_offset-GetSize()), ios_base::cur); return false; } bool ParseUnitByteIO::CanSkip() { - if(m_next_parse_offset == 0 || m_next_parse_offset == GetSize()) + if(m_next_parse_offset==0 || m_next_parse_offset == GetSize()) return true; // Skip past the end of current parse unit and past the header of the // next unit - SeekGet(m_next_parse_offset - GetSize() + GetSize(), ios_base::cur); + SeekGet(m_next_parse_offset-GetSize() + GetSize(), ios_base::cur); if(GetReadBytePosition() >= 0) { - SeekGet(-(m_next_parse_offset - GetSize() + GetSize()), ios_base::cur); - return true; // success + SeekGet(-(m_next_parse_offset-GetSize() + GetSize()), ios_base::cur); + return true; // success } // end of stream reached @@ -171,15 +171,15 @@ const string ParseUnitByteIO::GetBytes() //FIXME : Need to do this properly. // Write the parse offsets in Big Endian format - for(int i = PU_NEXT_PARSE_OFFSET_SIZE - 1; i >= 0; --i) + for(int i=PU_NEXT_PARSE_OFFSET_SIZE-1; i >= 0; --i) { - unsigned char cp = (m_next_parse_offset >> (i * 8)) & 0xff; + unsigned char cp = (m_next_parse_offset>>(i*8)) & 0xff; parse_string << cp; } - for(int i = PU_PREVIOUS_PARSE_OFFSET_SIZE - 1; i >= 0; --i) + for(int i=PU_PREVIOUS_PARSE_OFFSET_SIZE-1; i >= 0; --i) { - unsigned char cp = (m_previous_parse_offset >> (i * 8)) & 0xff; + unsigned char cp = (m_previous_parse_offset>>(i*8)) & 0xff; parse_string << cp; } @@ -251,32 +251,32 @@ int ParseUnitByteIO::CalcNextUnitOffset() bool ParseUnitByteIO::SyncToUnitStart() { - // locate parse-unit prefix + // locate parse-unit prefix string byte_buffer; - while(CanRead() == true && mp_stream->tellg() >= 0) + while(CanRead()==true && mp_stream->tellg() >= 0) { // ensure current buffer length if((int)byte_buffer.size() == PU_PREFIX_SIZE) { - byte_buffer.assign(byte_buffer.substr(1, PU_PREFIX_SIZE - 1)); + byte_buffer.assign(byte_buffer.substr(1,PU_PREFIX_SIZE-1)); } // read next byte byte_buffer.push_back(InputUnByte()); //look to see if we have prefix - if(byte_buffer == PU_PREFIX) + if(byte_buffer==PU_PREFIX) { // check we can read a parse-unit //int prev_pos = mp_stream->tellg(); - mp_stream->seekg(PU_PARSEUNIT_SIZE - PU_PREFIX_SIZE, ios_base::cur); + mp_stream->seekg (PU_PARSEUNIT_SIZE-PU_PREFIX_SIZE, ios_base::cur); int cur_pos = mp_stream->tellg(); - if(cur_pos < 0) // past end of stream + if (cur_pos < 0) // past end of stream { mp_stream->clear(); return false; } - mp_stream->seekg(-(PU_PARSEUNIT_SIZE - PU_PREFIX_SIZE), ios_base::cur); + mp_stream->seekg(-(PU_PARSEUNIT_SIZE-PU_PREFIX_SIZE), ios_base::cur); return true; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h index ab015d1fe..8d7742afa 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h @@ -53,216 +53,193 @@ namespace dirac { -/* Types of parse-unit */ -typedef enum -{ - PU_SEQ_HEADER = 0, - PU_PICTURE, - PU_END_OF_SEQUENCE, - PU_AUXILIARY_DATA, - PU_PADDING_DATA, - PU_CORE_PICTURE, - PU_LOW_DELAY_PICTURE, - PU_UNDEFINED -} ParseUnitType; - -/** -* Represents a collection of data in a Dirac bytestream that can be parsed as a -* self-contained unit -*/ -class ParseUnitByteIO : public ByteIO -{ -public: - - /** - * Constructor - */ - ParseUnitByteIO(); - - /** - * Constructor - *@param byte_io Stream parameters - */ - ParseUnitByteIO(const ByteIO& byte_io); - - /** - * Constructor - *@param parseunit_byteio Parse-unit parameters - */ - ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio); - - /** - * Destructor - */ - ~ParseUnitByteIO(); - - /** - * Gathers byte stats on the parse-unit data - *@param dirac_byte_stats Stat container - */ - virtual void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Reads from byte-stream to find parse data - *@return false if not enough data in stream - */ - bool Input(); // decoding - - /** - * Accesses validity of a unit by comparing it with an adjacent unit - */ - bool IsValid(); - - /** - * Can Skip past the entire parse-unit - *@return false Nothing to skip to - */ - bool CanSkip(); - - /** - * Gets string containing coded bytes - */ - virtual const std::string GetBytes(); // encoding - - /** - * Set next/previous parse-unit values - *@param p_prev_parseunit Previous parse-unit - */ - void SetAdjacentParseUnits(ParseUnitByteIO *p_prev_parseunit); // encoding - - /* - * Gets number of bytes input/output within unit - */ - virtual int GetSize() const; - - /** - * Gets expected number of bytes to start of next parse-unit - */ - int GetNextParseOffset() const; - - /** - * Gets number of bytes to start of previous parse-unit - */ - int GetPreviousParseOffset() const; - - /** - * Gets parse-unit type - */ - virtual ParseUnitType GetType() const; - - /** - * Returns true is parse unit is a Sequence Header - */ - bool IsSeqHeader() const - { - return m_parse_code == 0x00; - } - - /** - * Returns true is parse unit is an End of Sequence unit - */ - bool IsEndOfSequence() const - { - return m_parse_code == 0x10; - } - - /** - * Returns true is parse unit is Auxiliary Data - */ - bool IsAuxiliaryData() const - { - return (m_parse_code & 0xF8) == 0x20; - } - - /** - * Returns true is parse unit is Padding data - */ - bool IsPaddingData() const - { - return m_parse_code == 0x30; - } - - /** - * Returns true is parse unit is Picture data - */ - bool IsPicture() const - { - return ((m_parse_code & 0x08) == 0x08); - } - - /** - * Returns true is parse unit is Low Delay Sybtax unit - */ - bool IsLowDelay() const - { - return ((m_parse_code & 0x88) == 0x88); - } - - /** - * Returns true is parse unit is Core syntax unit - */ - bool IsCoreSyntax() const - { - return ((m_parse_code & 0x88) == 0x08); - } - - /** - * Returns true is parse unit uses Arithmetic coding - */ - bool IsUsingAC() const + /* Types of parse-unit */ + typedef enum { + PU_SEQ_HEADER=0, + PU_PICTURE, + PU_END_OF_SEQUENCE, + PU_AUXILIARY_DATA, + PU_PADDING_DATA, + PU_CORE_PICTURE, + PU_LOW_DELAY_PICTURE, + PU_UNDEFINED + } ParseUnitType; + + /** + * Represents a collection of data in a Dirac bytestream that can be parsed as a + * self-contained unit + */ + class ParseUnitByteIO : public ByteIO { - return ((m_parse_code & 0x48) == 0x08); - } - -protected: - - /** - * Calculates number of bytes to start of next unit - *@return Number of bytes to next unit - */ - virtual int CalcNextUnitOffset(); - - /** - * Pure virtual method for calculating parse-code - *@return Char containing bit-set for parse-unit parameters - */ - virtual unsigned char CalcParseCode() const - { - return 0; // encoding - } - - /** - * Locates start of parse-unit - *@return false if not enough data - */ - bool SyncToUnitStart(); // decoding - - /** - * Get parse code - */ - unsigned char GetParseCode() const - { - return m_parse_code; - } - -private: - - /** - * Number of bytes to next parse-unit - */ - int m_previous_parse_offset; - - /** - * Number of bytes to previous parse-unit - */ - int m_next_parse_offset; - - /** - * Parse-type-identifier - */ - unsigned char m_parse_code; - -}; + public: + + /** + * Constructor + */ + ParseUnitByteIO(); + + /** + * Constructor + *@param byte_io Stream parameters + */ + ParseUnitByteIO(const ByteIO& byte_io); + + /** + * Constructor + *@param parseunit_byteio Parse-unit parameters + */ + ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio); + + /** + * Destructor + */ + ~ParseUnitByteIO(); + + /** + * Gathers byte stats on the parse-unit data + *@param dirac_byte_stats Stat container + */ + virtual void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Reads from byte-stream to find parse data + *@return false if not enough data in stream + */ + bool Input(); // decoding + + /** + * Accesses validity of a unit by comparing it with an adjacent unit + */ + bool IsValid(); + + /** + * Can Skip past the entire parse-unit + *@return false Nothing to skip to + */ + bool CanSkip(); + + /** + * Gets string containing coded bytes + */ + virtual const std::string GetBytes(); // encoding + + /** + * Set next/previous parse-unit values + *@param p_prev_parseunit Previous parse-unit + */ + void SetAdjacentParseUnits(ParseUnitByteIO *p_prev_parseunit); // encoding + + /* + * Gets number of bytes input/output within unit + */ + virtual int GetSize() const; + + /** + * Gets expected number of bytes to start of next parse-unit + */ + int GetNextParseOffset() const; + + /** + * Gets number of bytes to start of previous parse-unit + */ + int GetPreviousParseOffset() const; + + /** + * Gets parse-unit type + */ + virtual ParseUnitType GetType() const; + + /** + * Returns true is parse unit is a Sequence Header + */ + bool IsSeqHeader() const + { return m_parse_code==0x00; } + + /** + * Returns true is parse unit is an End of Sequence unit + */ + bool IsEndOfSequence() const + { return m_parse_code==0x10; } + + /** + * Returns true is parse unit is Auxiliary Data + */ + bool IsAuxiliaryData() const + { return (m_parse_code&0xF8)==0x20; } + + /** + * Returns true is parse unit is Padding data + */ + bool IsPaddingData() const + { return m_parse_code==0x30; } + + /** + * Returns true is parse unit is Picture data + */ + bool IsPicture() const + { return ((m_parse_code&0x08)==0x08); } + + /** + * Returns true is parse unit is Low Delay Sybtax unit + */ + bool IsLowDelay() const + { return ((m_parse_code&0x88)==0x88); } + + /** + * Returns true is parse unit is Core syntax unit + */ + bool IsCoreSyntax() const + { return ((m_parse_code&0x88)==0x08); } + + /** + * Returns true is parse unit uses Arithmetic coding + */ + bool IsUsingAC() const + { return ((m_parse_code&0x48)==0x08); } + + protected: + + /** + * Calculates number of bytes to start of next unit + *@return Number of bytes to next unit + */ + virtual int CalcNextUnitOffset(); + + /** + * Pure virtual method for calculating parse-code + *@return Char containing bit-set for parse-unit parameters + */ + virtual unsigned char CalcParseCode() const { return 0;} // encoding + + /** + * Locates start of parse-unit + *@return false if not enough data + */ + bool SyncToUnitStart(); // decoding + + /** + * Get parse code + */ + unsigned char GetParseCode() const { return m_parse_code;} + + private: + + /** + * Number of bytes to next parse-unit + */ + int m_previous_parse_offset; + + /** + * Number of bytes to previous parse-unit + */ + int m_next_parse_offset; + + /** + * Parse-type-identifier + */ + unsigned char m_parse_code; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp index 06b52aa62..23231bea7 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp @@ -54,37 +54,37 @@ const int CODE_VLC_ENTROPY_CODING_BIT = 6; const unsigned int MAX_NUM_REFS = 2; PictureByteIO::PictureByteIO(PictureParams& frame_params, - int frame_num) : - ParseUnitByteIO(), - m_frame_params(frame_params), - m_frame_num(frame_num), - m_mv_data(0), - m_transform_data(0) + int frame_num) : +ParseUnitByteIO(), +m_frame_params(frame_params), +m_frame_num(frame_num), +m_mv_data(0), +m_transform_data(0) { - + } PictureByteIO::PictureByteIO(PictureParams& frame_params, - const ParseUnitByteIO& parseunit_byteio): - ParseUnitByteIO(parseunit_byteio), - m_frame_params(frame_params), - m_frame_num(0), - m_mv_data(0), - m_transform_data(0) + const ParseUnitByteIO& parseunit_byteio ): +ParseUnitByteIO(parseunit_byteio), +m_frame_params(frame_params), +m_frame_num(0), +m_mv_data(0), +m_transform_data(0) { - + } PictureByteIO::~PictureByteIO() { //delete block data - if(m_mv_data) + if (m_mv_data) { delete m_mv_data; m_mv_data = 0; } - if(m_transform_data) + if (m_transform_data) { delete m_transform_data; m_transform_data = 0; @@ -110,13 +110,13 @@ bool PictureByteIO::Input() // Use of VLC for entropy coding is supported for // intra frames only - if(m_frame_params.GetPictureType() == INTER_PICTURE && - m_frame_params.UsingAC() == false) + if (m_frame_params.GetPictureType() == INTER_PICTURE && + m_frame_params.UsingAC() == false) { DIRAC_THROW_EXCEPTION( - ERR_UNSUPPORTED_STREAM_DATA, - "VLC codes for entropy coding of coefficient data supported for Intra frames only", - SEVERITY_PICTURE_ERROR); + ERR_UNSUPPORTED_STREAM_DATA, + "VLC codes for entropy coding of coefficient data supported for Intra frames only", + SEVERITY_PICTURE_ERROR); } // input picture number @@ -125,10 +125,10 @@ bool PictureByteIO::Input() // input reference Picture numbers InputReferencePictures(); - + // input retired Picture numbers list m_frame_params.SetRetiredPictureNum(-1); - if(IsRef()) + if (IsRef()) InputRetiredPicture(); // byte align @@ -137,7 +137,7 @@ bool PictureByteIO::Input() return true; } -const string PictureByteIO::GetBytes() +const string PictureByteIO::GetBytes() { // Write mv data if(m_frame_params.PicSort().IsInter() && m_mv_data) @@ -146,7 +146,7 @@ const string PictureByteIO::GetBytes() } // Write transform header - if(m_transform_data) + if (m_transform_data) { OutputBytes(m_transform_data->GetBytes()); } @@ -156,15 +156,15 @@ const string PictureByteIO::GetBytes() int PictureByteIO::GetSize() const { int size = 0; - if(m_mv_data) + if (m_mv_data) size += m_mv_data->GetSize(); - if(m_transform_data) + if (m_transform_data) size += m_transform_data->GetSize(); //std::cerr << "Picture Header Size=" << ByteIO::GetSize(); //std::cerr << "Data Size=" << size << std::endl; - return size + ParseUnitByteIO::GetSize() + ByteIO::GetSize(); + return size+ParseUnitByteIO::GetSize()+ByteIO::GetSize(); } void PictureByteIO::Output() @@ -172,23 +172,23 @@ void PictureByteIO::Output() // output picture number WriteUintLit(m_frame_num, PP_PICTURE_NUM_SIZE); - if(m_frame_params.GetPictureType() == INTER_PICTURE) + if(m_frame_params.GetPictureType()==INTER_PICTURE) { // output reference picture numbers const std::vector& refs = m_frame_params.Refs(); - for(size_t i = 0; i < refs.size() && i < MAX_NUM_REFS; ++i) + for(size_t i=0; i < refs.size() && i < MAX_NUM_REFS; ++i) WriteSint(refs[i] - m_frame_num); } // output retired picture - ASSERTM(m_frame_params.GetReferenceType() == REFERENCE_PICTURE || m_frame_params.RetiredPictureNum() == -1, "Only Reference frames can retire frames"); + ASSERTM (m_frame_params.GetReferenceType() == REFERENCE_PICTURE || m_frame_params.RetiredPictureNum() == -1, "Only Reference frames can retire frames"); if(m_frame_params.GetReferenceType() == REFERENCE_PICTURE) { - if(m_frame_params.RetiredPictureNum() == -1) + if (m_frame_params.RetiredPictureNum() == -1) WriteSint(0); else { - WriteSint(m_frame_params.RetiredPictureNum() - m_frame_num); + WriteSint (m_frame_params.RetiredPictureNum() - m_frame_num); } } // byte align output @@ -198,14 +198,14 @@ void PictureByteIO::Output() //-------------private------------------------------------------------------- - + unsigned char PictureByteIO::CalcParseCode() const { unsigned char code = 0; int num_refs = m_frame_params.Refs().size(); - if(m_frame_params.GetPictureType() == INTER_PICTURE) + if(m_frame_params.GetPictureType()==INTER_PICTURE) { // set number of refs if(num_refs == 1) @@ -214,42 +214,42 @@ unsigned char PictureByteIO::CalcParseCode() const SetBit(code, CODE_TWO_REF_BIT); } // set ref type - if(m_frame_params.GetReferenceType() == REFERENCE_PICTURE) + if(m_frame_params.GetReferenceType()==REFERENCE_PICTURE) SetBit(code, CODE_REF_PICTURE_BIT); // Set parse unit type SetBit(code, CODE_PUTYPE_1_BIT); // Set Entropy Coding type - if(!m_frame_params.UsingAC()) + if (!m_frame_params.UsingAC()) { SetBit(code, CODE_VLC_ENTROPY_CODING_BIT); } return code; - + } -void PictureByteIO::InputReferencePictures() +void PictureByteIO::InputReferencePictures() { // get number of frames referred to - int ref_count = NumRefs(); + int ref_count = NumRefs(); - // get the number of these frames + // get the number of these frames vector& refs = m_frame_params.Refs(); refs.resize(ref_count); - for(int i = 0; i < ref_count; ++i) - refs[i] = m_frame_num + ReadSint(); + for(int i=0; i < ref_count; ++i) + refs[i]=m_frame_num+ReadSint(); } - -void PictureByteIO::InputRetiredPicture() + +void PictureByteIO::InputRetiredPicture() { TESTM(IsRef(), "Retired Picture offset only set for Reference Frames"); // input retired picture offset int offset = ReadSint(); // input retired frames - if(offset) + if (offset) { m_frame_params.SetRetiredPictureNum(m_frame_num + offset); } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h index 1fcd0cb9c..bdca76f40 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h @@ -54,178 +54,154 @@ namespace dirac { -/** -* A compressed picture in Dirac bytestream format -*/ -class PictureByteIO : public ParseUnitByteIO -{ -public: - - /** - * Constructor - *@param frame_params Picture parameters - *@param frame_num Picture number - */ - PictureByteIO(PictureParams& frame_params, - int frame_num); - - - /** - * Constructor - *@param frame_params Destination of data - *@param parseunit_byteio Source of data - */ - PictureByteIO(PictureParams& frame_params, - const ParseUnitByteIO& parseunit_byteio); - - /** - * Destructor - */ - virtual ~PictureByteIO(); - - /** - * Gathers byte stats on the picture data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Inputs data from Dirac stream-format - */ - bool Input(); - - /** - * Outputs picture values to Dirac stream-format - */ - void Output(); - - - - const std::string GetBytes(); - - int GetSize() const; - - /** - * Gets parse-unit type - */ - ParseUnitType GetType() const - { - return PU_PICTURE; - } - - /** - * Returns true is picture in Reference picture - */ - int IsRef() const - { - return (GetParseCode() & 0x0C) == 0x0C; - } - - /** - * Returns true is picture in Non-Reference picture - */ - int IsNonRef() const - { - return (GetParseCode() & 0x0C) == 0x08; - } - - /** - * Gets parse-unit type - */ - int NumRefs() const - { - return (GetParseCode() & 0x03); - } - - /** - * Returns true is picture is Intra picture - */ - bool IsIntra() const - { - return IsPicture() && (NumRefs() == 0) ; - } - /** - * Returns true is picture is Inter picture - */ - bool IsInter() const - { - return IsPicture() && (NumRefs() > 0) ; - } - - /*** - * Sets the MVDataIO + * A compressed picture in Dirac bytestream format */ - void SetMvData(MvDataByteIO *mv_data) + class PictureByteIO : public ParseUnitByteIO { - m_mv_data = mv_data; - } - - /*** - * Sets the TransformByteIo - */ - void SetTransformData(TransformByteIO *transform_data) - { - m_transform_data = transform_data; - } - -protected: - - -private: - - /** - * Calculates parse-code based on picture parameters - *@return Char bit-set - */ - unsigned char CalcParseCode() const; - - /** - * Reads reference-picture data - */ - void InputReferencePictures(); - - /** - * Reads retired picture number - */ - void InputRetiredPicture(); - - /** - * Calculates picture-type (eg INTRA/INTER) of picture - */ - void SetPictureType(); - - /** - * Calculates reference-type of picture - */ - void SetReferenceType(); - - /** - * Sets the entropy coding flag in the picture parameters - */ - void SetEntropyCodingFlag(); - - /** - * Picture parameters - */ - PictureParams& m_frame_params; - - /** - * Picture number - */ - int m_frame_num; - - /** - * MV data - */ - MvDataByteIO * m_mv_data; - - /** - * Transform data - */ - TransformByteIO * m_transform_data; - -}; + public: + + /** + * Constructor + *@param frame_params Picture parameters + *@param frame_num Picture number + */ + PictureByteIO(PictureParams& frame_params, + int frame_num); + + + /** + * Constructor + *@param frame_params Destination of data + *@param parseunit_byteio Source of data + */ + PictureByteIO(PictureParams& frame_params, + const ParseUnitByteIO& parseunit_byteio); + + /** + * Destructor + */ + virtual ~PictureByteIO(); + + /** + * Gathers byte stats on the picture data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Inputs data from Dirac stream-format + */ + bool Input(); + + /** + * Outputs picture values to Dirac stream-format + */ + void Output(); + + + + const std::string GetBytes(); + + int GetSize() const; + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_PICTURE;} + + /** + * Returns true is picture in Reference picture + */ + int IsRef() const { return (GetParseCode()&0x0C)==0x0C;} + + /** + * Returns true is picture in Non-Reference picture + */ + int IsNonRef() const { return (GetParseCode()&0x0C)==0x08;} + + /** + * Gets parse-unit type + */ + int NumRefs() const { return (GetParseCode()&0x03);} + + /** + * Returns true is picture is Intra picture + */ + bool IsIntra() const { return IsPicture() && (NumRefs()==0) ; } + + /** + * Returns true is picture is Inter picture + */ + bool IsInter() const { return IsPicture() && (NumRefs()>0) ; } + + /*** + * Sets the MVDataIO + */ + void SetMvData(MvDataByteIO *mv_data) {m_mv_data = mv_data; } + + /*** + * Sets the TransformByteIo + */ + void SetTransformData(TransformByteIO *transform_data) {m_transform_data = transform_data; } + + protected: + + + private: + + /** + * Calculates parse-code based on picture parameters + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + /** + * Reads reference-picture data + */ + void InputReferencePictures(); + + /** + * Reads retired picture number + */ + void InputRetiredPicture(); + + /** + * Calculates picture-type (eg INTRA/INTER) of picture + */ + void SetPictureType(); + + /** + * Calculates reference-type of picture + */ + void SetReferenceType(); + + /** + * Sets the entropy coding flag in the picture parameters + */ + void SetEntropyCodingFlag(); + + /** + * Picture parameters + */ + PictureParams& m_frame_params; + + /** + * Picture number + */ + int m_frame_num; + + /** + * MV data + */ + MvDataByteIO * m_mv_data; + + /** + * Transform data + */ + TransformByteIO * m_transform_data; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp index 41b6fcb66..63d0607b9 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp @@ -42,19 +42,19 @@ using namespace std; SubbandByteIO::SubbandByteIO(Subband& sub_band, const ByteIO& byteio): - ByteIO(byteio), - m_subband(sub_band), - m_band_data_length(0) +ByteIO(byteio), +m_subband(sub_band), +m_band_data_length(0) { - + } SubbandByteIO::SubbandByteIO(Subband& sub_band): - ByteIO(), - m_subband(sub_band), - m_band_data_length(0) +ByteIO(), +m_subband(sub_band), +m_band_data_length(0) { - + } SubbandByteIO::~SubbandByteIO() @@ -70,7 +70,7 @@ bool SubbandByteIO::Input() m_band_data_length = ReadUint(); // set skip flag if no data - m_subband.SetSkip(m_band_data_length == 0 ? true : false); + m_subband.SetSkip(m_band_data_length==0 ? true : false); // check for zero-length sub-band if(m_subband.Skipped()) @@ -79,16 +79,16 @@ bool SubbandByteIO::Input() return true; } - // If we're not skipped, we need a quantisation index for the subband - m_subband.SetQuantIndex(ReadUint()); + // If we're not skipped, we need a quantisation index for the subband + m_subband.SetQuantIndex(ReadUint() ); - if(!m_subband.UsingMultiQuants()) + if ( !m_subband.UsingMultiQuants() ) { - // Propogate the quantiser index to all the code blocks if we + // Propogate the quantiser index to all the code blocks if we // don't have multiquants - for(int j = 0 ; j < m_subband.GetCodeBlocks().LengthY() ; ++j) - for(int i = 0 ; i < m_subband.GetCodeBlocks().LengthX() ; ++i) - m_subband.GetCodeBlocks()[j][i].SetQuantIndex(m_subband.QuantIndex()); + for ( int j=0 ; j -std::istream & operator>> (std::istream & stream, TwoDArray & array) -{ - for(int j = 0 ; j < array.LengthY() ; ++j) + //! A function for inserting array data + template + std::istream & operator>> (std::istream & stream, TwoDArray & array) { - for(int i = 0 ; i < array.LengthX() ; ++i) + for (int j=0 ; j> array[j][i]; - }// i - }// j + for (int i=0 ; i> array[j][i]; + }// i + }// j - return stream; -} + return stream; + } } //namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp index bb751e1f0..fc0e42312 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp @@ -72,25 +72,25 @@ GenericIntraDCBandCodec >::GenericIntraDCBandCodec( void IntraDCBandCodec::DoWorkCode(CoeffArray& in_data) { // Residues after prediction, quantisation and inverse quantisation - m_dc_pred_res.Resize(m_node.Yl() , m_node.Xl()); - m_dc_pred_res.Fill(0); + m_dc_pred_res.Resize( m_node.Yl() , m_node.Xl() ); + m_dc_pred_res.Fill( 0 ); BandCodec::DoWorkCode(in_data); } -void IntraDCBandCodec::CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos) +void IntraDCBandCodec::CodeCoeff( CoeffArray& in_data, const int xpos, const int ypos) { m_nhood_nonzero = false; - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos][xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos-1]); - ValueType prediction = GetPrediction(in_data , xpos , ypos); + ValueType prediction = GetPrediction( in_data , xpos , ypos ); ValueType val = in_data[ypos][xpos] - prediction; - CodeVal(in_data , xpos , ypos , val); + CodeVal( in_data , xpos , ypos , val ); m_dc_pred_res[ypos][xpos] = in_data[ypos][xpos]; in_data[ypos][xpos] += prediction; } @@ -98,22 +98,22 @@ void IntraDCBandCodec::CodeCoeff(CoeffArray& in_data, const int xpos, const int void IntraDCBandCodec::DoWorkDecode(CoeffArray& out_data) { // Residues after prediction, quantisation and inverse quantisation - m_dc_pred_res.Resize(m_node.Yl() , m_node.Xl()); - m_dc_pred_res.Fill(0); + m_dc_pred_res.Resize( m_node.Yl() , m_node.Xl() ); + m_dc_pred_res.Fill( 0 ); BandCodec::DoWorkDecode(out_data); } -void IntraDCBandCodec::DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos) +void IntraDCBandCodec::DecodeCoeff( CoeffArray& out_data, const int xpos, const int ypos) { m_nhood_nonzero = false; - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos][xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos-1]); - DecodeVal(out_data , xpos , ypos); + DecodeVal( out_data , xpos , ypos ); m_dc_pred_res[ypos][xpos] = out_data[ypos][xpos]; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h index e03c75aaa..dfebb2e7f 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h @@ -48,201 +48,201 @@ namespace dirac { -class SubbandByteIO; + class SubbandByteIO; -//Subclasses the arithmetic codec to produce a coding/decoding tool for subbands + //Subclasses the arithmetic codec to produce a coding/decoding tool for subbands -//! A template class for coding and decoding wavelet subband data. -template -class GenericBandCodec: public EntropyCodec -{ -public: - - //! Constructor - /*! - Creates a BandCodec object to encode subband data - \param subband_byteio input/output for the encoded bits - \param number_of_contexts the number of contexts used in the encoding process - \param band_list the set of all the subbands - \param band_num the number of the subband being coded - \param is_intra Flag indicating whether the band comes from an intra picture - */ - GenericBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList& band_list, - int band_num, - const bool is_intra); + //! A template class for coding and decoding wavelet subband data. + template + class GenericBandCodec: public EntropyCodec + { + public: -protected: - //! Code an individual quantised value and perform inverse-quantisation - inline void CodeVal(CoeffArray& in_data , const int xpos , const int ypos , const CoeffType val); + //! Constructor + /*! + Creates a BandCodec object to encode subband data + \param subband_byteio input/output for the encoded bits + \param number_of_contexts the number of contexts used in the encoding process + \param band_list the set of all the subbands + \param band_num the number of the subband being coded + \param is_intra Flag indicating whether the band comes from an intra picture + */ + GenericBandCodec(SubbandByteIO* subband_byteio, + size_t number_of_contexts, + const SubbandList& band_list, + int band_num, + const bool is_intra); - //! Decode an individual quantised value and perform inverse-quantisation - inline void DecodeVal(CoeffArray& out_data , const int xpos , const int ypos); + protected: + //! Code an individual quantised value and perform inverse-quantisation + inline void CodeVal( CoeffArray& in_data , const int xpos , const int ypos , const CoeffType val); - //! Encode the offset for a code block quantiser - void CodeQuantIndexOffset(const int offset); + //! Decode an individual quantised value and perform inverse-quantisation + inline void DecodeVal(CoeffArray& out_data , const int xpos , const int ypos ); - //! Decode the offset for a code block quantiser - int DecodeQuantIndexOffset(); + //! Encode the offset for a code block quantiser + void CodeQuantIndexOffset( const int offset ); - //! Set a code block area to a given value - inline void SetToVal(const CodeBlock& code_block , CoeffArray& coeff_data , const CoeffType val); + //! Decode the offset for a code block quantiser + int DecodeQuantIndexOffset(); - //! Set all block values to 0 - virtual void ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data); + //! Set a code block area to a given value + inline void SetToVal( const CodeBlock& code_block , CoeffArray& coeff_data , const CoeffType val); -protected: - //functions - // Overridden from the base class - virtual void DoWorkCode(CoeffArray& in_data); - // Ditto - virtual void DoWorkDecode(CoeffArray& out_data); + //! Set all block values to 0 + virtual void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data); - virtual void CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data); - virtual void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); + protected: + //functions + // Overridden from the base class + virtual void DoWorkCode(CoeffArray& in_data); + // Ditto + virtual void DoWorkDecode(CoeffArray& out_data); - virtual void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + virtual void CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data); + virtual void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); - virtual void DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - //! A function for choosing the context for "follow bits" - inline int ChooseFollowContext(const int bin_number) const; + virtual void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - //! A function for choosing the context for "information bits" - inline int ChooseInfoContext() const; + virtual void DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + //! A function for choosing the context for "follow bits" + inline int ChooseFollowContext( const int bin_number ) const; - //! A function for choosing the context for sign bits - inline int ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos) const; + //! A function for choosing the context for "information bits" + inline int ChooseInfoContext() const; -private: - //! Private, bodyless copy constructor: class should not be copied - GenericBandCodec(const GenericBandCodec& cpy); - //! Private, bodyless copy operator=: class should not be assigned - GenericBandCodec& operator=(const GenericBandCodec& rhs); + //! A function for choosing the context for sign bits + inline int ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos ) const; -protected: + private: + //! Private, bodyless copy constructor: class should not be copied + GenericBandCodec(const GenericBandCodec& cpy); + //! Private, bodyless copy operator=: class should not be assigned + GenericBandCodec& operator=(const GenericBandCodec& rhs); - //! Flag indicating whether the band comes from an intra picture - bool m_is_intra; + protected: - //! variables - int m_bnum; + //! Flag indicating whether the band comes from an intra picture + bool m_is_intra; - //! the subband being coded - const Subband m_node; + //! variables + int m_bnum; - //! the quantisation index of the last codeblock - int m_last_qf_idx; + //! the subband being coded + const Subband m_node; - //! quantisation value - int m_qf; + //! the quantisation index of the last codeblock + int m_last_qf_idx; - //! reconstruction point - CoeffType m_offset; + //! quantisation value + int m_qf; - //! True if neighbours non-zero - bool m_nhood_nonzero; + //! reconstruction point + CoeffType m_offset; - //! the parent subband - Subband m_pnode; + //! True if neighbours non-zero + bool m_nhood_nonzero; - //! position of the parent coefficient - int m_pxpos, m_pypos; + //! the parent subband + Subband m_pnode; - //! True if the parent of a coeff is not zero - bool m_parent_notzero; + //! position of the parent coefficient + int m_pxpos, m_pypos; -}; + //! True if the parent of a coeff is not zero + bool m_parent_notzero; -//! A general class for coding and decoding wavelet subband data. -/*! - A general class for coding and decoding wavelet subband data, deriving from the abstract ArithCodec class. - */ -typedef GenericBandCodec > BandCodec; -typedef BandCodec LFBandCodec; + }; -////////////////////////////////////////////////////////////////////////////////// -//Finally,special class incorporating prediction for the DC band of intra frames// -////////////////////////////////////////////////////////////////////////////////// - -//! A template class specially for coding the DC subband of Intra frames -template -class GenericIntraDCBandCodec : public GenericBandCodec -{ -public: - //! Constructor + //! A general class for coding and decoding wavelet subband data. /*! - Creates a IntraDCBandCodec object to encode subband data - \param subband_byteio input/output for the encoded bits - \param number_of_contexts the number of contexts used in the encoding process - \param band_list the set of all the subbands + A general class for coding and decoding wavelet subband data, deriving from the abstract ArithCodec class. */ - GenericIntraDCBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList& band_list) - : GenericBandCodec(subband_byteio, number_of_contexts, - band_list, band_list.Length(), - true) {} - -protected: - //! When coding a skipped block, propegate the predicted values for future non skipped blocks - void ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data); - - //! Prediction of a DC value from its previously coded neighbours - CoeffType GetPrediction(const CoeffArray& data , const int xpos , const int ypos) const; - - //! Decode codeblock of coefficients and perform DC prediction - void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); -}; - - -//! A class specially for coding the DC subband of Intra frames -/*! - A class specially for coding the DC subband of Intra frames, using - intra-band prediction of coefficients. It uses the abstract ArithCodec - class -*/ -class IntraDCBandCodec: public GenericIntraDCBandCodec > -{ -public: - //! Constructor + typedef GenericBandCodec > BandCodec; + typedef BandCodec LFBandCodec; + + ////////////////////////////////////////////////////////////////////////////////// + //Finally,special class incorporating prediction for the DC band of intra frames// + ////////////////////////////////////////////////////////////////////////////////// + + //! A template class specially for coding the DC subband of Intra frames + template + class GenericIntraDCBandCodec : public GenericBandCodec + { + public: + //! Constructor + /*! + Creates a IntraDCBandCodec object to encode subband data + \param subband_byteio input/output for the encoded bits + \param number_of_contexts the number of contexts used in the encoding process + \param band_list the set of all the subbands + */ + GenericIntraDCBandCodec(SubbandByteIO* subband_byteio, + size_t number_of_contexts, + const SubbandList& band_list) + : GenericBandCodec(subband_byteio,number_of_contexts, + band_list, band_list.Length(), + true){} + + protected: + //! When coding a skipped block, propegate the predicted values for future non skipped blocks + void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data); + + //! Prediction of a DC value from its previously coded neighbours + CoeffType GetPrediction(const CoeffArray& data , const int xpos , const int ypos ) const; + + //! Decode codeblock of coefficients and perform DC prediction + void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); + }; + + + //! A class specially for coding the DC subband of Intra frames /*! - Creates a IntraDCBandCodec object to encode subband data, based on parameters - \param subband_byteio input/output for the encoded bits - \param number_of_contexts the number of contexts used in the encoding process - \param band_list the set of all the subbands - */ - IntraDCBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList& band_list) - : GenericIntraDCBandCodec >(subband_byteio, - number_of_contexts, - band_list) {} - - -private: - //! Initialize extra data required for error-feedback DC quantization - void DoWorkCode(CoeffArray& in_data); //overridden from the base class - - //! Ditto - void DoWorkDecode(CoeffArray& out_data); - - //! Encode a single coefficient using error-feedback DC quantization - void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - - //! Decode a single coefficient using error-feedback DC quantization - void DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos); - - //! Private, bodyless copy constructor: class should not be copied - IntraDCBandCodec(const IntraDCBandCodec& cpy); - - //! Private, bodyless copy operator=: class should not be assigned - IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs); - -private: - CoeffArray m_dc_pred_res; -}; + A class specially for coding the DC subband of Intra frames, using + intra-band prediction of coefficients. It uses the abstract ArithCodec + class + */ + class IntraDCBandCodec: public GenericIntraDCBandCodec > + { + public: + //! Constructor + /*! + Creates a IntraDCBandCodec object to encode subband data, based on parameters + \param subband_byteio input/output for the encoded bits + \param number_of_contexts the number of contexts used in the encoding process + \param band_list the set of all the subbands + */ + IntraDCBandCodec(SubbandByteIO* subband_byteio, + size_t number_of_contexts, + const SubbandList& band_list) + : GenericIntraDCBandCodec >(subband_byteio, + number_of_contexts, + band_list){} + + + private: + //! Initialize extra data required for error-feedback DC quantization + void DoWorkCode(CoeffArray& in_data); //overridden from the base class + + //! Ditto + void DoWorkDecode(CoeffArray& out_data); + + //! Encode a single coefficient using error-feedback DC quantization + void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + + //! Decode a single coefficient using error-feedback DC quantization + void DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos); + + //! Private, bodyless copy constructor: class should not be copied + IntraDCBandCodec(const IntraDCBandCodec& cpy); + + //! Private, bodyless copy operator=: class should not be assigned + IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs); + + private: + CoeffArray m_dc_pred_res; + }; }// end namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h index b1f924786..8ca94d089 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h @@ -7,18 +7,18 @@ using namespace dirac; //! Constructor for encoding. template GenericBandCodec::GenericBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList & band_list, - int band_num, - const bool is_intra): - EntropyCodec(subband_byteio, number_of_contexts), + size_t number_of_contexts, + const SubbandList & band_list, + int band_num, + const bool is_intra): + EntropyCodec(subband_byteio,number_of_contexts), m_is_intra(is_intra), m_bnum(band_num), m_node(band_list(band_num)), m_last_qf_idx(m_node.QuantIndex()) { - if(m_node.Parent() != 0) - m_pnode = band_list(m_node.Parent()); + if (m_node.Parent()!=0) + m_pnode=band_list(m_node.Parent()); } @@ -27,30 +27,30 @@ template void GenericBandCodec::DoWorkCode(CoeffArray& in_data) { - const TwoDArray& block_list(m_node.GetCodeBlocks()); + const TwoDArray& block_list( m_node.GetCodeBlocks() ); // coeff blocks can be skipped only if SpatialPartitioning is // enabled i.e. more than one code-block per subband bool code_skip = (block_list.LengthX() > 1 || block_list.LengthY() > 1); // Now loop over the blocks and code - for(int j = block_list.FirstY() ; j <= block_list.LastY() ; ++j) + for (int j=block_list.FirstY() ; j<=block_list.LastY() ; ++j) { CodeBlock *block = block_list[j]; - for(int i = block_list.FirstX() ; i <= block_list.LastX() ; ++i) + for (int i=block_list.FirstX() ; i<=block_list.LastX() ; ++i) { - if(code_skip) - EntropyCodec::EncodeSymbol(block[i].Skipped() , BLOCK_SKIP_CTX); - if(!block[i].Skipped()) - CodeCoeffBlock(block[i] , in_data); + if (code_skip) + EntropyCodec::EncodeSymbol(block[i].Skipped() , BLOCK_SKIP_CTX ); + if ( !block[i].Skipped() ) + CodeCoeffBlock( block[i] , in_data ); else - ClearBlock(block[i] , in_data); + ClearBlock (block[i] , in_data); }// i }// j } template -void GenericBandCodec::CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data) +void GenericBandCodec::CodeCoeffBlock( const CodeBlock& code_block , CoeffArray& in_data ) { //main coding function, using binarisation @@ -63,39 +63,39 @@ void GenericBandCodec::CodeCoeffBlock(const CodeBlock& code_block bool has_parent = m_node.Parent() != 0; - if(m_node.UsingMultiQuants()) + if ( m_node.UsingMultiQuants() ) { - CodeQuantIndexOffset(qf_idx - m_last_qf_idx); - m_last_qf_idx = qf_idx; + CodeQuantIndexOffset( qf_idx - m_last_qf_idx); + m_last_qf_idx = qf_idx; } - m_qf = dirac_quantiser_lists.QuantFactor4(qf_idx); - if(m_is_intra) - m_offset = dirac_quantiser_lists.IntraQuantOffset4(qf_idx); + m_qf = dirac_quantiser_lists.QuantFactor4( qf_idx ); + if (m_is_intra) + m_offset = dirac_quantiser_lists.IntraQuantOffset4( qf_idx ); else - m_offset = dirac_quantiser_lists.InterQuantOffset4(qf_idx); + m_offset = dirac_quantiser_lists.InterQuantOffset4( qf_idx ); - for(int ypos = ybeg; ypos < yend ; ++ypos) + for ( int ypos=ybeg; ypos> 1) + m_pnode.Yp(); - for(int xpos = xbeg; xpos < xend ; ++xpos) + m_pypos=(( ypos-m_node.Yp() )>>1)+m_pnode.Yp(); + for ( int xpos=xbeg; xpos> 1) + m_pnode.Xp(); + m_pxpos=(( xpos-m_node.Xp() )>>1)+m_pnode.Xp(); m_nhood_nonzero = false; - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(in_data[ypos-1][xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(in_data[ypos][xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(in_data[ypos-1][xpos-1]); - if(has_parent) - m_parent_notzero = static_cast(in_data[m_pypos][m_pxpos]); + if (has_parent) + m_parent_notzero = static_cast ( in_data[m_pypos][m_pxpos] ); else m_parent_notzero = false; - CodeCoeff(in_data , xpos , ypos); + CodeCoeff( in_data , xpos , ypos ); }// xpos }// ypos @@ -103,9 +103,9 @@ void GenericBandCodec::CodeCoeffBlock(const CodeBlock& code_block } template -void GenericBandCodec::CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos) +void GenericBandCodec::CodeCoeff( CoeffArray& in_data, const int xpos, const int ypos) { - CodeVal(in_data , xpos , ypos , in_data[ypos][xpos]); + CodeVal( in_data , xpos , ypos , in_data[ypos][xpos] ); } @@ -128,99 +128,99 @@ based on position, and have different contexts from the info bits. */ template -inline void GenericBandCodec::CodeVal(CoeffArray& in_data , - const int xpos , - const int ypos , - const CoeffType val) +inline void GenericBandCodec::CodeVal( CoeffArray& in_data , + const int xpos , + const int ypos , + const CoeffType val ) { - unsigned int abs_val(std::abs(val)); + unsigned int abs_val( std::abs(val) ); abs_val <<= 2; abs_val /= m_qf; - const int N = abs_val + 1; - int num_follow_zeroes = 0; + const int N = abs_val+1; + int num_follow_zeroes=0; - while(N >= (1 << num_follow_zeroes)) + while ( N >= (1<= 0; --i, ++c) + for ( int i=num_follow_zeroes-1, c=1; i>=0; --i, ++c ) { - EntropyCodec::EncodeSymbol(0, ChooseFollowContext(c)); - EntropyCodec::EncodeSymbol(N&(1 << i), ChooseInfoContext()); + EntropyCodec::EncodeSymbol( 0, ChooseFollowContext( c ) ); + EntropyCodec::EncodeSymbol( N&(1<(abs_val); + in_data[ypos][xpos] = static_cast( abs_val ); - if(abs_val) + if ( abs_val ) { // Must code sign bits and reconstruct in_data[ypos][xpos] *= m_qf; - in_data[ypos][xpos] += m_offset + 2; + in_data[ypos][xpos] += m_offset+2; in_data[ypos][xpos] >>= 2; - if(val > 0) + if ( val>0 ) { - EntropyCodec::EncodeSymbol(0 , ChooseSignContext(in_data , xpos , ypos)); + EntropyCodec::EncodeSymbol( 0 , ChooseSignContext( in_data , xpos , ypos ) ); } else { - EntropyCodec::EncodeSymbol(1 , ChooseSignContext(in_data , xpos , ypos)); + EntropyCodec::EncodeSymbol( 1 , ChooseSignContext( in_data , xpos , ypos ) ); in_data[ypos][xpos] = -in_data[ypos][xpos]; } } } template -void GenericBandCodec::CodeQuantIndexOffset(const int offset) +void GenericBandCodec::CodeQuantIndexOffset( const int offset ) { - const int abs_val = std::abs(offset); + const int abs_val = std::abs( offset ); - int N = abs_val + 1; - int num_follow_zeroes = 0; + int N = abs_val+1; + int num_follow_zeroes=0; - while(N >= (1 << num_follow_zeroes)) + while ( N>= (1<= 0; --i, ++c) + for ( int i=num_follow_zeroes-1, c=1; i>=0; --i, ++c ) { - EntropyCodec::EncodeSymbol(0 , Q_OFFSET_FOLLOW_CTX); - EntropyCodec::EncodeSymbol(N&(1 << i), Q_OFFSET_INFO_CTX); + EntropyCodec::EncodeSymbol( 0 , Q_OFFSET_FOLLOW_CTX ); + EntropyCodec::EncodeSymbol( N&(1< 0) - EntropyCodec::EncodeSymbol(0 , Q_OFFSET_SIGN_CTX); + if ( offset>0 ) + EntropyCodec::EncodeSymbol( 0 , Q_OFFSET_SIGN_CTX ); else - EntropyCodec::EncodeSymbol(1 , Q_OFFSET_SIGN_CTX); + EntropyCodec::EncodeSymbol( 1 , Q_OFFSET_SIGN_CTX ); } } template -void GenericBandCodec::DoWorkDecode(CoeffArray& out_data) +void GenericBandCodec::DoWorkDecode( CoeffArray& out_data ) { - const TwoDArray& block_list(m_node.GetCodeBlocks()); + const TwoDArray& block_list( m_node.GetCodeBlocks() ); // coeff blocks can be skipped only if SpatialPartitioning is // enabled i.e. more than one code-block per subband - bool decode_skip = (block_list.LengthX() > 1 || block_list.LengthY() > 1); + bool decode_skip= (block_list.LengthX() > 1 || block_list.LengthY() > 1); // Now loop over the blocks and decode - for(int j = block_list.FirstY() ; j <= block_list.LastY() ; ++j) + for (int j=block_list.FirstY() ; j<=block_list.LastY() ; ++j) { CodeBlock *block = block_list[j]; - for(int i = block_list.FirstX() ; i <= block_list.LastX() ; ++i) + for (int i=block_list.FirstX() ; i<=block_list.LastX() ; ++i) { - if(decode_skip) - block[i].SetSkip(EntropyCodec::DecodeSymbol(BLOCK_SKIP_CTX)); - if(!block[i].Skipped()) - DecodeCoeffBlock(block[i] , out_data); + if (decode_skip) + block[i].SetSkip( EntropyCodec::DecodeSymbol( BLOCK_SKIP_CTX ) ); + if ( !block[i].Skipped() ) + DecodeCoeffBlock( block[i] , out_data ); else - ClearBlock(block[i] , out_data); + ClearBlock (block[i] , out_data); }// i }// j @@ -228,7 +228,7 @@ void GenericBandCodec::DoWorkDecode(CoeffArray& out_data) } template -void GenericBandCodec::DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data) +void GenericBandCodec::DecodeCoeffBlock( const CodeBlock& code_block , CoeffArray& out_data ) { @@ -241,13 +241,13 @@ void GenericBandCodec::DecodeCoeffBlock(const CodeBlock& code_bloc bool has_parent = m_node.Parent() != 0; - if(m_node.UsingMultiQuants()) + if ( m_node.UsingMultiQuants() ) { - qf_idx = m_last_qf_idx + DecodeQuantIndexOffset(); + qf_idx = m_last_qf_idx+DecodeQuantIndexOffset(); m_last_qf_idx = qf_idx; } - if(qf_idx > (int)dirac_quantiser_lists.MaxQuantIndex()) + if (qf_idx > (int)dirac_quantiser_lists.MaxQuantIndex()) { std::ostringstream errstr; errstr << "Quantiser index out of range [0.." @@ -258,54 +258,54 @@ void GenericBandCodec::DecodeCoeffBlock(const CodeBlock& code_bloc SEVERITY_PICTURE_ERROR); } - m_qf = dirac_quantiser_lists.QuantFactor4(qf_idx); + m_qf = dirac_quantiser_lists.QuantFactor4( qf_idx ); - if(m_is_intra) - m_offset = dirac_quantiser_lists.IntraQuantOffset4(qf_idx); + if (m_is_intra) + m_offset = dirac_quantiser_lists.IntraQuantOffset4( qf_idx ); else - m_offset = dirac_quantiser_lists.InterQuantOffset4(qf_idx); + m_offset = dirac_quantiser_lists.InterQuantOffset4( qf_idx ); //Work - for(int ypos = ybeg; ypos < yend ; ++ypos) + for ( int ypos=ybeg; ypos> 1) + m_pnode.Yp(); + m_pypos=(( ypos-m_node.Yp() )>>1)+m_pnode.Yp(); CoeffType *p_out_data = NULL; - if(has_parent) + if (has_parent) p_out_data = out_data[m_pypos]; CoeffType *c_out_data_1 = NULL; - if(ypos != m_node.Yp()) + if (ypos!=m_node.Yp()) c_out_data_1 = out_data[ypos-1]; CoeffType *c_out_data_2 = out_data[ypos]; - for(int xpos = xbeg; xpos < xend ; ++xpos) + for ( int xpos=xbeg; xpos> 1) + m_pnode.Xp(); + m_pxpos=(( xpos-m_node.Xp() )>>1)+m_pnode.Xp(); m_nhood_nonzero = false; /* c_out_data_1 is the line above the current * c_out_data_2 is the current line */ - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(c_out_data_1[xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(c_out_data_2[xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(c_out_data_1[xpos-1]); - if(has_parent) - m_parent_notzero = (p_out_data[m_pxpos] != 0); + if (has_parent) + m_parent_notzero = ( p_out_data[m_pxpos] != 0 ); else m_parent_notzero = false; - DecodeCoeff(out_data , xpos , ypos); + DecodeCoeff( out_data , xpos , ypos ); }// xpos }// ypos } template -void GenericBandCodec::DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos) +void GenericBandCodec::DecodeCoeff( CoeffArray& in_data, const int xpos, const int ypos) { - DecodeVal(in_data , xpos , ypos); + DecodeVal( in_data , xpos , ypos ); } @@ -327,80 +327,80 @@ All bits are arithmetically coded. The follow bits have separate contexts based on position, and have different contexts from the info bits. */ template -inline void GenericBandCodec::DecodeVal(CoeffArray& out_data , const int xpos , const int ypos) +inline void GenericBandCodec::DecodeVal( CoeffArray& out_data , const int xpos , const int ypos ) { CoeffType& out_pixel = out_data[ypos][xpos]; out_pixel = 1; - int bit_count = 1; + int bit_count=1; - while(!EntropyCodec::DecodeSymbol(ChooseFollowContext(bit_count))) + while ( !EntropyCodec::DecodeSymbol( ChooseFollowContext( bit_count ) ) ) { out_pixel <<= 1; - out_pixel |= EntropyCodec::DecodeSymbol(ChooseInfoContext()); + out_pixel |= EntropyCodec::DecodeSymbol( ChooseInfoContext() ); bit_count++; }; --out_pixel; - if(out_pixel) + if ( out_pixel ) { out_pixel *= m_qf; - out_pixel += m_offset + 2; + out_pixel += m_offset+2; out_pixel >>= 2; - if(EntropyCodec::DecodeSymbol(ChooseSignContext(out_data, xpos, ypos))) + if ( EntropyCodec::DecodeSymbol( ChooseSignContext(out_data, xpos, ypos)) ) out_pixel = -out_pixel; } } template -inline int GenericBandCodec::ChooseFollowContext(const int bin_number) const +inline int GenericBandCodec::ChooseFollowContext( const int bin_number ) const { //condition on neighbouring values and parent values - if(!m_parent_notzero) + if (!m_parent_notzero) { - switch(bin_number) + switch ( bin_number ) { - case 1 : - if(m_nhood_nonzero == false) - return Z_FBIN1z_CTX; - - return Z_FBIN1nz_CTX; - - case 2 : - return Z_FBIN2_CTX; - case 3 : - return Z_FBIN3_CTX; - case 4 : - return Z_FBIN4_CTX; - case 5 : - return Z_FBIN5_CTX; - default : - return Z_FBIN6plus_CTX; + case 1 : + if(m_nhood_nonzero == false) + return Z_FBIN1z_CTX; + + return Z_FBIN1nz_CTX; + + case 2 : + return Z_FBIN2_CTX; + case 3 : + return Z_FBIN3_CTX; + case 4 : + return Z_FBIN4_CTX; + case 5 : + return Z_FBIN5_CTX; + default : + return Z_FBIN6plus_CTX; } } else { - switch(bin_number) + switch ( bin_number ) { - case 1 : - if(m_nhood_nonzero == false) - return NZ_FBIN1z_CTX; - - return NZ_FBIN1nz_CTX; - - case 2 : - return NZ_FBIN2_CTX; - case 3 : - return NZ_FBIN3_CTX; - case 4 : - return NZ_FBIN4_CTX; - case 5 : - return NZ_FBIN5_CTX; - default : - return NZ_FBIN6plus_CTX; + case 1 : + if(m_nhood_nonzero == false) + return NZ_FBIN1z_CTX; + + return NZ_FBIN1nz_CTX; + + case 2 : + return NZ_FBIN2_CTX; + case 3 : + return NZ_FBIN3_CTX; + case 4 : + return NZ_FBIN4_CTX; + case 5 : + return NZ_FBIN5_CTX; + default : + return NZ_FBIN6plus_CTX; } } @@ -416,33 +416,33 @@ inline int GenericBandCodec::ChooseInfoContext() const } template -inline int GenericBandCodec::ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos) const +inline int GenericBandCodec::ChooseSignContext( const CoeffArray& data , const int xpos , const int ypos ) const { - if(m_node.Yp() == 0 && m_node.Xp() != 0) + if ( m_node.Yp()==0 && m_node.Xp()!=0 ) { //we're in a vertically oriented subband - if(ypos == 0) + if (ypos == 0) return SIGN0_CTX; else { - if(data[ypos-1][xpos] > 0) + if (data[ypos-1][xpos]>0) return SIGN_POS_CTX; - else if(data[ypos-1][xpos] < 0) + else if (data[ypos-1][xpos]<0) return SIGN_NEG_CTX; else return SIGN0_CTX; } } - else if(m_node.Xp() == 0 && m_node.Yp() != 0) + else if ( m_node.Xp()==0 && m_node.Yp()!=0 ) { //we're in a horizontally oriented subband - if(xpos == 0) + if (xpos == 0) return SIGN0_CTX; else { - if(data[ypos][xpos-1] > 0) + if ( data[ypos][xpos-1] > 0 ) return SIGN_POS_CTX; - else if(data[ypos][xpos-1] < 0) + else if ( data[ypos][xpos-1] < 0 ) return SIGN_NEG_CTX; else return SIGN0_CTX; @@ -457,40 +457,40 @@ int GenericBandCodec::DecodeQuantIndexOffset() { int offset = 1; - while(!EntropyCodec::DecodeSymbol(Q_OFFSET_FOLLOW_CTX)) + while ( !EntropyCodec::DecodeSymbol( Q_OFFSET_FOLLOW_CTX ) ) { offset <<= 1; - offset |= EntropyCodec::DecodeSymbol(Q_OFFSET_INFO_CTX); + offset |= EntropyCodec::DecodeSymbol( Q_OFFSET_INFO_CTX ); } --offset; - if(offset) + if ( offset ) { - if(EntropyCodec::DecodeSymbol(Q_OFFSET_SIGN_CTX)) + if ( EntropyCodec::DecodeSymbol( Q_OFFSET_SIGN_CTX ) ) offset = -offset; } return offset; } template -void GenericBandCodec::SetToVal(const CodeBlock& code_block , CoeffArray& pic_data , const CoeffType val) +void GenericBandCodec::SetToVal( const CodeBlock& code_block , CoeffArray& pic_data , const CoeffType val) { - for(int j = code_block.Ystart() ; j < code_block.Yend() ; j++) + for (int j=code_block.Ystart() ; j -void GenericBandCodec::ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data) +void GenericBandCodec::ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data) { - for(int j = code_block.Ystart() ; j < code_block.Yend() ; j++) + for (int j=code_block.Ystart() ; j::DecodeCoeffBlock(const CodeBlock& co { GenericBandCodec::DecodeCoeffBlock(code_block, out_data); /* do prediction for this block */ - for(int ypos = code_block.Ystart() ; ypos < code_block.Yend() ; ++ypos) + for ( int ypos=code_block.Ystart() ; ypos::DecodeCoeffBlock(const CodeBlock& co * predict the values in the next codeblock */ template -void GenericIntraDCBandCodec::ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data) +void GenericIntraDCBandCodec::ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data) { - for(int ypos = code_block.Ystart() ; ypos < code_block.Yend() ; ++ypos) + for (int ypos=code_block.Ystart() ; ypos -CoeffType GenericIntraDCBandCodec::GetPrediction(const CoeffArray& data , const int xpos , const int ypos) const +CoeffType GenericIntraDCBandCodec::GetPrediction( const CoeffArray& data , const int xpos , const int ypos ) const { /* NB, 4.5.3 integer division * numbers are rounded down towards -ve infinity, differing from * C's convention that rounds towards 0 */ - if(ypos != 0) + if (ypos!=0) { - if(xpos != 0) + if (xpos!=0) { - int sum = data[ypos][xpos-1] + data[ypos-1][xpos-1] + data[ypos-1][xpos] + 3 / 2; - if(sum < 0) - return (sum - 2) / 3; + int sum = data[ypos][xpos-1] + data[ypos-1][xpos-1] + data[ypos-1][xpos] + 3/2; + if (sum<0) + return (sum-2)/3; else - return sum / 3; + return sum/3; } else return data[ypos - 1][0]; } else { - if(xpos != 0) + if(xpos!=0) return data[0][xpos - 1]; else return 0; diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp index 9ea1aa081..b6ddf5337 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp @@ -47,8 +47,8 @@ using namespace dirac; ArithCodecToVLCAdapter::ArithCodecToVLCAdapter( - SubbandByteIO* subband_byteio, - size_t /*number_of_contexts*/): + SubbandByteIO* subband_byteio, + size_t /*number_of_contexts*/): m_byteio(subband_byteio) {} @@ -82,19 +82,19 @@ GenericIntraDCBandCodec::GenericIntraDCBandCodec( const SubbandList & band_list); IntraDCBandVLC::IntraDCBandVLC(SubbandByteIO* subband_byteio, - const SubbandList& band_list): + const SubbandList& band_list): GenericIntraDCBandCodec(subband_byteio, 0, band_list) {} -void IntraDCBandVLC::CodeCoeff(CoeffArray& in_data , - const int xpos , - const int ypos) +void IntraDCBandVLC::CodeCoeff( CoeffArray& in_data , + const int xpos , + const int ypos ) { CoeffType val, prediction; - prediction = GetPrediction(in_data, xpos, ypos); + prediction = GetPrediction( in_data, xpos, ypos ); val = in_data[ypos][xpos] - prediction; - CodeVal(in_data , xpos , ypos , val); + CodeVal( in_data , xpos , ypos , val ); in_data[ypos][xpos] += prediction; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h index 4cde9849c..597802d26 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h @@ -48,92 +48,92 @@ namespace dirac { -class SubbandByteIO; -class ByteIO; + class SubbandByteIO; + class ByteIO; -/*! Abstract VLC entropy codec base class */ -class ArithCodecToVLCAdapter -{ -public: - /*! Constructor */ - ArithCodecToVLCAdapter(SubbandByteIO* subband_byteio, size_t number_of_contexts); + /*! Abstract VLC entropy codec base class */ + class ArithCodecToVLCAdapter + { + public: + /*! Constructor */ + ArithCodecToVLCAdapter(SubbandByteIO* subband_byteio, size_t number_of_contexts); - /*! Virtual Destructor */ - virtual ~ArithCodecToVLCAdapter() {} + /*! Virtual Destructor */ + virtual ~ArithCodecToVLCAdapter(){} - /* Compresses the input and returns the number of bits written */ - int Compress(CoeffArray &in_data); + /* Compresses the input and returns the number of bits written */ + int Compress (CoeffArray &in_data); - /* Decompresses the bitstream */ - void Decompress(CoeffArray& out_data, int num_bytes); + /* Decompresses the bitstream */ + void Decompress (CoeffArray& out_data, int num_bytes); - /* Encodes a symbol and writes to the output */ - void EncodeSymbol(bool val, int /*context_num*/) - { - m_byteio->WriteBit(val); - } + /* Encodes a symbol and writes to the output */ + void EncodeSymbol(bool val, int /*context_num*/) + { + m_byteio->WriteBit(val); + } - /* Decodes a symbol */ - bool DecodeSymbol(int /*context_num*/) - { - return m_byteio->ReadBoolB(); - } - - /*! Purely virtual function that does the actual encoding. Derived classes must define it */ - virtual void DoWorkCode(CoeffArray &in_data) = 0; - - /*! Purely virtual function that does the actual decoding. Derived classes must define it */ - virtual void DoWorkDecode(CoeffArray &out_data) = 0; - -protected: - /*! Input/output stream for Dirac-format bytes */ - ByteIO *m_byteio; - -private: - //! Private, bodyless copy constructor: class should not be copied - ArithCodecToVLCAdapter(const ArithCodecToVLCAdapter& cpy); - //! Private, bodyless copy operator=: class should not be assigned - ArithCodecToVLCAdapter& operator=(const ArithCodecToVLCAdapter& rhs); -}; - - -//! A general class for coding and decoding wavelet subband data using variable length coding. -/*! - A general class for coding and decoding wavelet subband data using variable length coding, - */ -typedef GenericBandCodec BandVLC; - -////////////////////////////////////////////////////////////////////////////////// -//Finally,special class incorporating prediction for the DC band of intra frames// -////////////////////////////////////////////////////////////////////////////////// - -//! A class specially for coding the DC subband of Intra frames -/*! - A class specially for coding the DC subband of Intra frames, using intra-band prediction - of coefficients. -*/ -class IntraDCBandVLC: public GenericIntraDCBandCodec -{ -public: - //! Constructor + /* Decodes a symbol */ + bool DecodeSymbol(int /*context_num*/) + { + return m_byteio->ReadBoolB(); + } + + /*! Purely virtual function that does the actual encoding. Derived classes must define it */ + virtual void DoWorkCode(CoeffArray &in_data) = 0; + + /*! Purely virtual function that does the actual decoding. Derived classes must define it */ + virtual void DoWorkDecode(CoeffArray &out_data) = 0; + + protected: + /*! Input/output stream for Dirac-format bytes */ + ByteIO *m_byteio; + + private: + //! Private, bodyless copy constructor: class should not be copied + ArithCodecToVLCAdapter(const ArithCodecToVLCAdapter& cpy); + //! Private, bodyless copy operator=: class should not be assigned + ArithCodecToVLCAdapter& operator=(const ArithCodecToVLCAdapter& rhs); + }; + + + //! A general class for coding and decoding wavelet subband data using variable length coding. /*! - Creates a IntraDCBandVLC object to encode subband data, based on parameters - \param subband_byteio input/output for the encoded bits - \param band_list the set of all the subbands + A general class for coding and decoding wavelet subband data using variable length coding, */ - IntraDCBandVLC(SubbandByteIO* subband_byteio, - const SubbandList& band_list); -private: - //! Encode a single coefficient using error-feedback DC quantization - void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - -private: - //! Private, bodyless copy constructor: class should not be copied - IntraDCBandVLC(const IntraDCBandVLC& cpy); - - //! Private, bodyless copy operator=: class should not be assigned - IntraDCBandVLC& operator=(const IntraDCBandVLC& rhs); -}; + typedef GenericBandCodec BandVLC; + + ////////////////////////////////////////////////////////////////////////////////// + //Finally,special class incorporating prediction for the DC band of intra frames// + ////////////////////////////////////////////////////////////////////////////////// + + //! A class specially for coding the DC subband of Intra frames + /*! + A class specially for coding the DC subband of Intra frames, using intra-band prediction + of coefficients. + */ + class IntraDCBandVLC: public GenericIntraDCBandCodec + { + public: + //! Constructor + /*! + Creates a IntraDCBandVLC object to encode subband data, based on parameters + \param subband_byteio input/output for the encoded bits + \param band_list the set of all the subbands + */ + IntraDCBandVLC(SubbandByteIO* subband_byteio, + const SubbandList& band_list); + private: + //! Encode a single coefficient using error-feedback DC quantization + void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + + private: + //! Private, bodyless copy constructor: class should not be copied + IntraDCBandVLC (const IntraDCBandVLC& cpy); + + //! Private, bodyless copy operator=: class should not be assigned + IntraDCBandVLC& operator=(const IntraDCBandVLC& rhs); + }; }// end namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp index 7a3470ad8..aed3d145c 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp @@ -49,7 +49,7 @@ using std::vector; //////////////// //Constructor -BasicOutputManager::BasicOutputManager(std::ostream* out_data): +BasicOutputManager::BasicOutputManager(std::ostream* out_data ): m_num_out_bytes(0), m_op_ptr(out_data) { @@ -59,9 +59,9 @@ BasicOutputManager::BasicOutputManager(std::ostream* out_data): void BasicOutputManager::InitOutputStream() { // Set byte pointer to start of buffer - m_current_byte = 0; - // Set output mask to MSB of byte - m_output_mask = 0x80; + m_current_byte = 0; + // Set output mask to MSB of byte + m_output_mask = 0x80; // Reset the output buffer m_buffer.clear(); } @@ -69,82 +69,82 @@ void BasicOutputManager::InitOutputStream() void BasicOutputManager::OutputSkipInterpretStartPrefixByte() { size_t buf_size = m_buffer.size(); - if(buf_size >= 4 && - m_buffer[buf_size-1] == (char)START_CODE_PREFIX_BYTE3 && - m_buffer[buf_size-2] == (char)START_CODE_PREFIX_BYTE2 && - m_buffer[buf_size-3] == (char)START_CODE_PREFIX_BYTE1 && - m_buffer[buf_size-4] == (char)START_CODE_PREFIX_BYTE0) + if (buf_size >=4 && + m_buffer[buf_size-1] == (char)START_CODE_PREFIX_BYTE3 && + m_buffer[buf_size-2] == (char)START_CODE_PREFIX_BYTE2 && + m_buffer[buf_size-3] == (char)START_CODE_PREFIX_BYTE1 && + m_buffer[buf_size-4] == (char)START_CODE_PREFIX_BYTE0) { m_buffer.push_back((char)NOT_START_CODE); std::cerr << "Wrote ignore code " << std::endl; } } -void BasicOutputManager::OutputBit(const bool& bit) +void BasicOutputManager::OutputBit(const bool& bit ) { - m_current_byte |= (bit ? (m_output_mask) : 0); + m_current_byte |= (bit ? (m_output_mask):0); // Shift mask to next bit in the output byte - m_output_mask >>= 1; + m_output_mask >>= 1; - if(m_output_mask == 0) - { + if ( m_output_mask == 0 ) + { // If a whole byte has been written, write out m_output_mask = 0x80; m_buffer.push_back(m_current_byte); OutputSkipInterpretStartPrefixByte(); m_current_byte = 0; - } + } } void BasicOutputManager::OutputBit(const bool& bit, int& count) { OutputBit(bit); - count++; + count++; } void BasicOutputManager::OutputByte(const char& byte) { FlushOutput(); - m_buffer.push_back(byte); + m_buffer.push_back( byte ); OutputSkipInterpretStartPrefixByte(); } -void BasicOutputManager::OutputBytes(char* str_array) +void BasicOutputManager::OutputBytes( char* str_array ) { FlushOutput(); - while(*str_array != 0) + while ( *str_array != 0 ) { - m_buffer.push_back(*str_array); + m_buffer.push_back( *str_array ); str_array++; } } -void BasicOutputManager::OutputBytes(char* str_array, int num) +void BasicOutputManager::OutputBytes(char* str_array,int num) { FlushOutput(); - for(int i = 0 ; i < num ; ++i) - m_buffer.push_back(str_array[i]); + for ( int i=0 ; i::iterator it = m_buffer.begin() ; it != m_buffer.end() ; ++it) + for ( vector::iterator it=m_buffer.begin() ; it!=m_buffer.end() ; ++it ) { - m_op_ptr->write(&(*it) , 1); + m_op_ptr->write( &( *it ) , 1 ); } m_num_out_bytes = m_buffer.size(); - InitOutputStream(); + InitOutputStream(); } void BasicOutputManager::FlushOutput() { // Flush the current byte to output buffer and reset - if(m_output_mask != 0x80) + if ( m_output_mask != 0x80 ) { - m_buffer.push_back(m_current_byte); + m_buffer.push_back( m_current_byte ); m_current_byte = 0; m_output_mask = 0x80; } @@ -152,27 +152,27 @@ void BasicOutputManager::FlushOutput() size_t BasicOutputManager::Size() const { - if(m_output_mask == 0x80) + if ( m_output_mask==0x80 ) return m_buffer.size(); else - return m_buffer.size() + 1; + return m_buffer.size()+1; } // Unit output - a subband or the MV data, for example // -UnitOutputManager::UnitOutputManager(std::ostream* out_data): +UnitOutputManager::UnitOutputManager(std::ostream* out_data ): m_header(out_data), m_data(out_data), m_unit_bytes(0), m_unit_data_bytes(0), m_unit_head_bytes(0) -{} + {} void UnitOutputManager::WriteToFile() { m_header.WriteToFile(); m_data.WriteToFile(); - + // after writing to file, get the number of unit bytes written m_unit_data_bytes = m_data.GetNumBytes(); m_unit_head_bytes = m_header.GetNumBytes(); @@ -182,16 +182,16 @@ void UnitOutputManager::WriteToFile() size_t UnitOutputManager::Size() const { - return m_data.Size() + m_header.Size(); + return m_data.Size()+m_header.Size(); } -FrameOutputManager::FrameOutputManager(std::ostream* out_data , int num_bands) : - m_data_array(3 , num_bands), - m_comp_bytes(3), - m_comp_hdr_bytes(3), - m_out_stream(out_data) +FrameOutputManager::FrameOutputManager( std::ostream* out_data , int num_bands ) : + m_data_array( 3 , num_bands ), + m_comp_bytes( 3 ), + m_comp_hdr_bytes( 3 ), + m_out_stream( out_data ) { - Init(num_bands); + Init( num_bands ); } FrameOutputManager::~FrameOutputManager() @@ -218,13 +218,13 @@ void FrameOutputManager::WriteToFile() m_header_bytes += m_mv_hdr_bytes; // Write out the component data - for(int c = 0 ; c < 3 ; ++c) + for ( int c=0 ; c<3 ; ++c) { m_comp_hdr_bytes[c] = 0; m_comp_bytes[c] = 0; - for(int b = m_data_array.LastX() ; b >= 0 ; --b) + for ( int b=m_data_array.LastX() ; b>=0 ; --b) { m_data_array[c][b]->WriteToFile(); // after writing to file, get the number of bytes written @@ -234,52 +234,52 @@ void FrameOutputManager::WriteToFile() }// c - for(int c = 0 ; c < m_data_array.LengthY() ; ++c) + for ( int c=0 ; cSize(); - for(int c = 0 ; c < 3 ; ++c) + for ( int c=0 ; c<3 ; ++c) { - for(int b = 0 ; b < m_data_array.LengthX() ; ++b) + for ( int b=0 ; bSize(); } @@ -306,17 +306,17 @@ size_t FrameOutputManager::Size() const size += m_mv_data->Size(); return size; -} +} // Sequence stuff // -SequenceOutputManager::SequenceOutputManager(std::ostream* out_data): - m_frame_op_mgr(out_data), - m_seq_header(out_data), - m_seq_end(out_data), - m_comp_bytes(3), - m_comp_hdr_bytes(3), +SequenceOutputManager::SequenceOutputManager( std::ostream* out_data ): + m_frame_op_mgr( out_data ), + m_seq_header( out_data ), + m_seq_end( out_data ), + m_comp_bytes( 3 ), + m_comp_hdr_bytes( 3 ), m_mv_hdr_bytes(0), m_mv_bytes(0), m_total_bytes(0), @@ -324,7 +324,7 @@ SequenceOutputManager::SequenceOutputManager(std::ostream* out_data): m_trailer_bytes(0) { - for(int c = 0 ; c < 3 ; ++c) + for (int c=0 ; c<3 ; ++c ) { m_comp_hdr_bytes[c] = 0; m_comp_bytes[c] = 0; @@ -334,12 +334,12 @@ SequenceOutputManager::SequenceOutputManager(std::ostream* out_data): void SequenceOutputManager::WriteFrameData() { m_frame_op_mgr.WriteToFile(); - + // Keep up with count of component bytes - for(int c = 0 ; c < m_comp_hdr_bytes.Length(); ++c) + for (int c=0 ; cread(&m_current_byte, 1); + m_ip_ptr->read(&m_current_byte,1); m_input_bits_left = 8; - if(m_shift == START_CODE_PREFIX && (unsigned char)m_current_byte == NOT_START_CODE) + if (m_shift == START_CODE_PREFIX && (unsigned char)m_current_byte == NOT_START_CODE) { std::cerr << "Ignoring byte " << std::endl; - m_ip_ptr->read(&m_current_byte, 1); + m_ip_ptr->read(&m_current_byte,1); m_shift = 0xffffffff; } m_shift = (m_shift << 8) | m_current_byte; @@ -403,7 +403,7 @@ bool BitInputManager::InputBit() m_input_bits_left--; - return bool((m_current_byte >> m_input_bits_left) & 1); + return bool( ( m_current_byte >> m_input_bits_left ) & 1 ); } @@ -415,7 +415,7 @@ bool BitInputManager::InputBit(int& count) bool BitInputManager::InputBit(int& count, const int max_count) { - if(count < max_count) + if ( countread(&byte, 1); + m_ip_ptr->read(&byte,1); - return byte; + return byte; } void BitInputManager::InputBytes(char* cptr, int num) { - // Forget about what's in the current byte + // Forget about what's in the current byte FlushInput(); - m_ip_ptr->read(cptr, num); + m_ip_ptr->read(cptr,num); } void BitInputManager::FlushInput() { - m_input_bits_left = 0; + m_input_bits_left = 0; } -bool BitInputManager::End() const +bool BitInputManager::End() const { - return m_ip_ptr->eof(); + return m_ip_ptr->eof(); } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h index 194fca1e0..6f75e8004 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h @@ -48,543 +48,477 @@ namespace dirac { -//! Prefix for all start codes -const unsigned int START_CODE_PREFIX = 0x42424344; //BBCD -const unsigned int START_CODE_PREFIX_BYTE0 = - (START_CODE_PREFIX >> 24) & 0xFF; -const unsigned int START_CODE_PREFIX_BYTE1 = - (START_CODE_PREFIX >> 16) & 0xFF; -const unsigned int START_CODE_PREFIX_BYTE2 = - (START_CODE_PREFIX >> 8) & 0xFF; -const unsigned int START_CODE_PREFIX_BYTE3 = - START_CODE_PREFIX & 0xFF; - -//! Random Access Point (RAP) Intra Picture start Code -const unsigned char RAP_START_CODE = 0xD7; -//! Non-RAP Intra Picture start code -const unsigned char IFRAME_START_CODE = 0xD6; -//! L1 Picture start code -const unsigned char L1FRAME_START_CODE = 0xD4; -//! L2 Picture start code -const unsigned char L2FRAME_START_CODE = 0xD5; -//! Sequence end code -const unsigned char SEQ_END_CODE = 0xD0; -//! Not a start code but part of data -const unsigned char NOT_START_CODE = 0xFF; -//! Bitstream version -const unsigned char BITSTREAM_VERSION = 0x05; //0.5 - - -//////////////////////////////////////////////// -//--------------Bit output stuff--------------// -//////////////////////////////////////////////// - -class UnitOutputManager; -class FrameOutputManager; -class SequenceOutputManager; - -//! Class for managing bit- and byte-oriented output. -/*! - A class for managing bit- and byte-oriented output. Wraps around - an ostream object but stores data in memory until told told to - write out in order to support data re-ordering - for example - writing a header once the subsequent data has been obtained. - Implementation to be reviewed in future. TJD 13 April 2004. -*/ -class BasicOutputManager -{ - // Data cannot be written to file directly, only by other o/p classes - friend class UnitOutputManager; - friend class FrameOutputManager; - friend class SequenceOutputManager; - -public: - //! Constructor + //! Prefix for all start codes + const unsigned int START_CODE_PREFIX = 0x42424344; //BBCD + const unsigned int START_CODE_PREFIX_BYTE0 = + (START_CODE_PREFIX >> 24) & 0xFF; + const unsigned int START_CODE_PREFIX_BYTE1 = + (START_CODE_PREFIX >> 16) & 0xFF; + const unsigned int START_CODE_PREFIX_BYTE2 = + (START_CODE_PREFIX >> 8) & 0xFF; + const unsigned int START_CODE_PREFIX_BYTE3 = + START_CODE_PREFIX & 0xFF; + + //! Random Access Point (RAP) Intra Picture start Code + const unsigned char RAP_START_CODE = 0xD7; + //! Non-RAP Intra Picture start code + const unsigned char IFRAME_START_CODE = 0xD6; + //! L1 Picture start code + const unsigned char L1FRAME_START_CODE = 0xD4; + //! L2 Picture start code + const unsigned char L2FRAME_START_CODE = 0xD5; + //! Sequence end code + const unsigned char SEQ_END_CODE = 0xD0; + //! Not a start code but part of data + const unsigned char NOT_START_CODE = 0xFF; + //! Bitstream version + const unsigned char BITSTREAM_VERSION = 0x05; //0.5 + + + //////////////////////////////////////////////// + //--------------Bit output stuff--------------// + //////////////////////////////////////////////// + + class UnitOutputManager; + class FrameOutputManager; + class SequenceOutputManager; + + //! Class for managing bit- and byte-oriented output. /*! - Constructor requires an ostream object pointer. - \param out_data the output stream object pointer + A class for managing bit- and byte-oriented output. Wraps around + an ostream object but stores data in memory until told told to + write out in order to support data re-ordering - for example + writing a header once the subsequent data has been obtained. + Implementation to be reviewed in future. TJD 13 April 2004. */ - BasicOutputManager(std::ostream* out_data); - - //Copy constructor is default shallow copy - - //Operator= is default shallow= - - //! Destructor - ~BasicOutputManager() {} - - //! Write a bit out. - /*! - Write a bit out to the internal data cache. - */ - void OutputBit(const bool& bit); - - //! Write a bit out and increment count - /*! - Write a bit out to the internal data cache and increment the - count of bits written. - */ - void OutputBit(const bool& bit, int& count); - - //! Write a byte out. - /*! - Write a byte out to the internal data cache. - */ - void OutputByte(const char& byte); - - //! Write a null-terminated set of bytes out. - /*! - Write a null-terminated set of bytes out to the internal data cache. - */ - void OutputBytes(char* str_array); - - //! Write a number of bytes out. - /*! - Write a number of bytes out to the internal data cache. - */ - void OutputBytes(char* str_array, int num); - - //! Return the number of bytes last output to file. - /*! - Return the number of bytes last output to file. - */ - size_t GetNumBytes() const + class BasicOutputManager { - return m_num_out_bytes; - } - - //! Current size of the internal data cache in bytes. + // Data cannot be written to file directly, only by other o/p classes + friend class UnitOutputManager; + friend class FrameOutputManager; + friend class SequenceOutputManager; + + public: + //! Constructor + /*! + Constructor requires an ostream object pointer. + \param out_data the output stream object pointer + */ + BasicOutputManager(std::ostream* out_data ); + + //Copy constructor is default shallow copy + + //Operator= is default shallow= + + //! Destructor + ~BasicOutputManager(){} + + //! Write a bit out. + /*! + Write a bit out to the internal data cache. + */ + void OutputBit(const bool& bit); + + //! Write a bit out and increment count + /*! + Write a bit out to the internal data cache and increment the + count of bits written. + */ + void OutputBit(const bool& bit,int& count); + + //! Write a byte out. + /*! + Write a byte out to the internal data cache. + */ + void OutputByte(const char& byte); + + //! Write a null-terminated set of bytes out. + /*! + Write a null-terminated set of bytes out to the internal data cache. + */ + void OutputBytes(char* str_array); + + //! Write a number of bytes out. + /*! + Write a number of bytes out to the internal data cache. + */ + void OutputBytes(char* str_array,int num); + + //! Return the number of bytes last output to file. + /*! + Return the number of bytes last output to file. + */ + size_t GetNumBytes() const {return m_num_out_bytes;} + + //! Current size of the internal data cache in bytes. + /*! + Current size of the internal data cache in bytes. + */ + size_t Size() const; + + private: + // Number of output bytes written + size_t m_num_out_bytes; + std::ostream* m_op_ptr; + // Buffer used to store output prior to saving to file + std::vector m_buffer; + // Char used for temporary storage of op data bits + char m_current_byte; + // Used to set individual bit within the current header byte + int m_output_mask; + + //functions + + //! Write all data to file. + /*! + Dump the internal data cache to the internal ostream object. + */ + void WriteToFile(); + + //Initialise the output stream. + void InitOutputStream(); + + //Clean out any remaining output bits to the buffer + void FlushOutput(); + + //! Write an ignore code + /*! + Write a skip interpret start prefix byte out to the internal data + cache. + */ + void OutputSkipInterpretStartPrefixByte(); + }; + + //! A class for handling data output, including headers. /*! - Current size of the internal data cache in bytes. + A class for handling data output, including headers and reordering. */ - size_t Size() const; - -private: - // Number of output bytes written - size_t m_num_out_bytes; - std::ostream* m_op_ptr; - // Buffer used to store output prior to saving to file - std::vector m_buffer; - // Char used for temporary storage of op data bits - char m_current_byte; - // Used to set individual bit within the current header byte - int m_output_mask; - - //functions - - //! Write all data to file. - /*! - Dump the internal data cache to the internal ostream object. - */ - void WriteToFile(); - - //Initialise the output stream. - void InitOutputStream(); - - //Clean out any remaining output bits to the buffer - void FlushOutput(); - - //! Write an ignore code - /*! - Write a skip interpret start prefix byte out to the internal data - cache. - */ - void OutputSkipInterpretStartPrefixByte(); -}; - -//! A class for handling data output, including headers. -/*! -A class for handling data output, including headers and reordering. -*/ -class UnitOutputManager -{ - // Only the FrameOutputManager can make this class write data to file - friend class FrameOutputManager; - -public: - //! Constructor. - /*! - Constructor wraps around a pointer to an ostream object, and - initialises two BasicOutputManager objects for header and data - */ - UnitOutputManager(std::ostream* out_data); - - //Copy constructor is default shallow copy - - //Operator= is default shallow= - - //! Destructor - ~UnitOutputManager() {} - - //! Handles the header bits. - /*! - A BasicOutputManager object for handling the header bits. - */ - BasicOutputManager& Header() + class UnitOutputManager { - return m_header; - } - - //! Handles the data bits. - /*! - A BasicOutputManager object for handling the data bits. - */ - BasicOutputManager& Data() + // Only the FrameOutputManager can make this class write data to file + friend class FrameOutputManager; + + public: + //! Constructor. + /*! + Constructor wraps around a pointer to an ostream object, and + initialises two BasicOutputManager objects for header and data + */ + UnitOutputManager(std::ostream* out_data ); + + //Copy constructor is default shallow copy + + //Operator= is default shallow= + + //! Destructor + ~UnitOutputManager(){} + + //! Handles the header bits. + /*! + A BasicOutputManager object for handling the header bits. + */ + BasicOutputManager& Header(){return m_header;} + + //! Handles the data bits. + /*! + A BasicOutputManager object for handling the data bits. + */ + BasicOutputManager& Data(){return m_data;} + + //! Returns the total number of bytes written in the last unit coded. + /*! + Returns the total number of bytes written in the last unit coded - header + data. + */ + const size_t GetUnitBytes() const {return m_unit_bytes;} + + //! Returns the total number of header bytes written in the last unit coded. + const size_t GetUnitHeaderBytes() const {return m_unit_head_bytes;} + + //! Current size of the internal data cache in bytes. + /*! + Current size of the internal data cache in bytes. + */ + size_t Size() const; + + private: + // basic output managers for the header and data + BasicOutputManager m_header,m_data; + + // total number of bytes written in the last unit coded + size_t m_unit_bytes; + + // number of data bytes for the last unit coded + size_t m_unit_data_bytes; + + // number of data bytes for the last unit coded + size_t m_unit_head_bytes; + + // functions + + //! Writes the bit caches to file. + /*! + Writes the header bits to the ostream, followed by the data bits. + */ + void WriteToFile(); + }; + + class FrameOutputManager { - return m_data; - } + public: - //! Returns the total number of bytes written in the last unit coded. - /*! - Returns the total number of bytes written in the last unit coded - header + data. - */ - const size_t GetUnitBytes() const - { - return m_unit_bytes; - } + // Only the SequenceOutputManager can make this class write data to file + friend class SequenceOutputManager; - //! Returns the total number of header bytes written in the last unit coded. - const size_t GetUnitHeaderBytes() const - { - return m_unit_head_bytes; - } + //! Constructor + /* + Constructs a class which manages output for an entire picture. + \param out_data pointer to the output stream + \param num_bands the number of subbands per component + */ + FrameOutputManager( std::ostream* out_data , const int num_bands=13 ); - //! Current size of the internal data cache in bytes. - /*! - Current size of the internal data cache in bytes. - */ - size_t Size() const; - -private: - // basic output managers for the header and data - BasicOutputManager m_header, m_data; - - // total number of bytes written in the last unit coded - size_t m_unit_bytes; - - // number of data bytes for the last unit coded - size_t m_unit_data_bytes; - - // number of data bytes for the last unit coded - size_t m_unit_head_bytes; - - // functions - - //! Writes the bit caches to file. - /*! - Writes the header bits to the ostream, followed by the data bits. - */ - void WriteToFile(); -}; - -class FrameOutputManager -{ -public: - - // Only the SequenceOutputManager can make this class write data to file - friend class SequenceOutputManager; + //! Destructor + ~FrameOutputManager(); - //! Constructor - /* - Constructs a class which manages output for an entire picture. - \param out_data pointer to the output stream - \param num_bands the number of subbands per component - */ - FrameOutputManager(std::ostream* out_data , const int num_bands = 13); - - //! Destructor - ~FrameOutputManager(); - - //! Set the number of bands there will be in a component - void SetNumBands(const int num_bands); - - //! Get an output manager for a subband - /*! - Get an output manager for a subband. - \param csort the component (Y, U or V) - \param band_num the number of the subband - */ - UnitOutputManager& BandOutput(const int csort , const int band_num); + //! Set the number of bands there will be in a component + void SetNumBands( const int num_bands ); - //! Get an output manager for a subband - /*! - Get an output manager for a subband. - \param csort the component (Y, U or V) - \param band_num the number of the subband - */ - const UnitOutputManager& BandOutput(const int csort , const int band_num) const; + //! Get an output manager for a subband + /*! + Get an output manager for a subband. + \param csort the component (Y, U or V) + \param band_num the number of the subband + */ + UnitOutputManager& BandOutput( const int csort , const int band_num ); - //! Get an output manager for MV data - /*! - Get an output manager for MV data - */ - UnitOutputManager& MVOutput() - { - return *m_mv_data; - } + //! Get an output manager for a subband + /*! + Get an output manager for a subband. + \param csort the component (Y, U or V) + \param band_num the number of the subband + */ + const UnitOutputManager& BandOutput( const int csort , const int band_num ) const; - //! Get an output manager for MV data - /*! - Get an output manager for MV data - */ - const UnitOutputManager& MVOutput() const - { - return *m_mv_data; - } + //! Get an output manager for MV data + /*! + Get an output manager for MV data + */ + UnitOutputManager& MVOutput(){ return *m_mv_data; } - //! Get an output manager for the picture header - BasicOutputManager& HeaderOutput() - { - return *m_frame_header; - } + //! Get an output manager for MV data + /*! + Get an output manager for MV data + */ + const UnitOutputManager& MVOutput() const { return *m_mv_data; } - //! Return the number of bytes used for each component - const size_t ComponentBytes(const int comp_num) const - { - return m_comp_bytes[comp_num]; - } + //! Get an output manager for the picture header + BasicOutputManager& HeaderOutput(){ return *m_frame_header; } - //! Return the number of header bytes used for each component - const size_t ComponentHeadBytes(const int comp_num) const - { - return m_comp_hdr_bytes[comp_num]; - } + //! Return the number of bytes used for each component + const size_t ComponentBytes( const int comp_num ) const { return m_comp_bytes[comp_num];} - //! Return the number of motion vector bytes used - const size_t MVBytes() const - { - return m_mv_bytes; - } + //! Return the number of header bytes used for each component + const size_t ComponentHeadBytes( const int comp_num ) const { return m_comp_hdr_bytes[comp_num];} - //! Return the number of motion vector header bytes used - const size_t MVHeadBytes() const - { - return m_mv_hdr_bytes; - } + //! Return the number of motion vector bytes used + const size_t MVBytes() const { return m_mv_bytes;} - //! Return the number of bytes used for the whole picture - const size_t FrameBytes() const - { - return m_total_bytes; - } + //! Return the number of motion vector header bytes used + const size_t MVHeadBytes() const { return m_mv_hdr_bytes;} - //! Return the number of header bytes used throughout the picture - const size_t FrameHeadBytes() const - { - return m_header_bytes; - } + //! Return the number of bytes used for the whole picture + const size_t FrameBytes() const { return m_total_bytes;} - //! Current size of the internal data cache in bytes. - /*! - Current size of the internal data cache in bytes. - */ - size_t Size() const; + //! Return the number of header bytes used throughout the picture + const size_t FrameHeadBytes() const { return m_header_bytes;} -private: + //! Current size of the internal data cache in bytes. + /*! + Current size of the internal data cache in bytes. + */ + size_t Size() const; - // Array of subband outputs, 1 for each component and subband - TwoDArray< UnitOutputManager* > m_data_array; + private: - // Motion vector output - UnitOutputManager* m_mv_data; + // Array of subband outputs, 1 for each component and subband + TwoDArray< UnitOutputManager* > m_data_array; - // Picture header output - BasicOutputManager* m_frame_header; + // Motion vector output + UnitOutputManager* m_mv_data; - // The total number of picture bytes - size_t m_total_bytes; + // Picture header output + BasicOutputManager* m_frame_header; - // The total number of header bytes - size_t m_header_bytes; + // The total number of picture bytes + size_t m_total_bytes; - // The total number of MV header bytes - size_t m_mv_hdr_bytes; + // The total number of header bytes + size_t m_header_bytes; - // The total number of MV bytes - size_t m_mv_bytes; + // The total number of MV header bytes + size_t m_mv_hdr_bytes; - // The total number of bytes in each component - OneDArray< size_t > m_comp_bytes; + // The total number of MV bytes + size_t m_mv_bytes; - // The total number of header bytes in each component - OneDArray< size_t > m_comp_hdr_bytes; + // The total number of bytes in each component + OneDArray< size_t > m_comp_bytes; - // A copy of a pointer to the output stream - std::ostream* m_out_stream; + // The total number of header bytes in each component + OneDArray< size_t > m_comp_hdr_bytes; - // Functions + // A copy of a pointer to the output stream + std::ostream* m_out_stream; - //! Initialise the band data - void Init(const int num_bands); + // Functions - //! Reset all the data - void Reset(); + //! Initialise the band data + void Init( const int num_bands ); - //! Delete all the data - void DeleteAll(); + //! Reset all the data + void Reset(); - //! Write all the picture data to file - void WriteToFile(); -}; + //! Delete all the data + void DeleteAll(); -class SequenceOutputManager -{ -public: - //! Constructor - SequenceOutputManager(std::ostream* out_data); + //! Write all the picture data to file + void WriteToFile(); + }; - //! Return a reference to the output for a single picture - FrameOutputManager& FrameOutput() + class SequenceOutputManager { - return m_frame_op_mgr; - } + public: + //! Constructor + SequenceOutputManager( std::ostream* out_data ); - //! Return a reference to the output for the sequence header - BasicOutputManager& HeaderOutput() - { - return m_seq_header; - } + //! Return a reference to the output for a single picture + FrameOutputManager& FrameOutput(){ return m_frame_op_mgr; } - //! Return a reference to the output for the sequence trailer - BasicOutputManager& TrailerOutput() - { - return m_seq_end; - } + //! Return a reference to the output for the sequence header + BasicOutputManager& HeaderOutput(){ return m_seq_header; } - //! Reset the picture data without outputting - void ResetFrame() - { - m_frame_op_mgr.Reset(); - } + //! Return a reference to the output for the sequence trailer + BasicOutputManager& TrailerOutput(){ return m_seq_end; } - //! Write the sequence header - void WriteSeqHeaderToFile(); + //! Reset the picture data without outputting + void ResetFrame(){ m_frame_op_mgr.Reset(); } - //! Write all the picture data to file - void WriteFrameData(); + //! Write the sequence header + void WriteSeqHeaderToFile(); - //! Write the sequence trailer - void WriteSeqTrailerToFile(); + //! Write all the picture data to file + void WriteFrameData(); - //! Return the total number of bytes used for the sequence - const size_t SequenceBytes() - { - return m_total_bytes; - } + //! Write the sequence trailer + void WriteSeqTrailerToFile(); - //! Return the total number of header bytes used throughout the sequence - const size_t SequenceHeadBytes() - { - return m_header_bytes; - } + //! Return the total number of bytes used for the sequence + const size_t SequenceBytes() { return m_total_bytes; } - //! Return the total number bytes used for MVs - const size_t MVBytes() - { - return m_mv_bytes; - } + //! Return the total number of header bytes used throughout the sequence + const size_t SequenceHeadBytes() { return m_header_bytes; } - //! Return the total number bytes used for a component - const size_t ComponentBytes(const int comp_num) - { - return m_comp_bytes[comp_num]; - } + //! Return the total number bytes used for MVs + const size_t MVBytes() { return m_mv_bytes; } - //! Reset the picture data - void ResetFrameData(); + //! Return the total number bytes used for a component + const size_t ComponentBytes( const int comp_num ) { return m_comp_bytes[comp_num]; } + //! Reset the picture data + void ResetFrameData(); -private: - // The picture output manager - FrameOutputManager m_frame_op_mgr; + private: - // Output manager for the sequence header - BasicOutputManager m_seq_header; + // The picture output manager + FrameOutputManager m_frame_op_mgr; - // Output manager for the sequence end - BasicOutputManager m_seq_end; + // Output manager for the sequence header + BasicOutputManager m_seq_header; - // The total number of bytes in each component - OneDArray< size_t > m_comp_bytes; + // Output manager for the sequence end + BasicOutputManager m_seq_end; - // The total number of header bits in each component - OneDArray< size_t > m_comp_hdr_bytes; + // The total number of bytes in each component + OneDArray< size_t > m_comp_bytes; - // The number of MV header bytes - size_t m_mv_hdr_bytes; + // The total number of header bits in each component + OneDArray< size_t > m_comp_hdr_bytes; - // The total number of MV bytes - size_t m_mv_bytes; + // The number of MV header bytes + size_t m_mv_hdr_bytes; - // The total number of bytes written so far - size_t m_total_bytes; + // The total number of MV bytes + size_t m_mv_bytes; - // The total number of header bytes written so far - size_t m_header_bytes; + // The total number of bytes written so far + size_t m_total_bytes; - // The total number of trailer bytes written so far - size_t m_trailer_bytes; -}; + // The total number of header bytes written so far + size_t m_header_bytes; -/////////////////////////////////////////////// -//--------------Bit input stuff--------------// -/////////////////////////////////////////////// + // The total number of trailer bytes written so far + size_t m_trailer_bytes; + }; -//! A class for managing bit-wise and byte-wise input. -class BitInputManager -{ + /////////////////////////////////////////////// + //--------------Bit input stuff--------------// + /////////////////////////////////////////////// -public: - //! Constructor. - /*! - Constructor. Wraps around an istream object. - */ - BitInputManager(std::istream* in_data); + //! A class for managing bit-wise and byte-wise input. + class BitInputManager + { + + public: + //! Constructor. + /*! + Constructor. Wraps around an istream object. + */ + BitInputManager(std::istream* in_data ); - //Copy constructor is default shallow copy + //Copy constructor is default shallow copy - //Operator= is default shallow= + //Operator= is default shallow= - //! Destructor - ~BitInputManager() {} + //! Destructor + ~BitInputManager(){} - //input functions - //! Obtain the next bit. - bool InputBit(); + //input functions + //! Obtain the next bit. + bool InputBit(); - //! Obtain the next bit, incrementing count. - bool InputBit(int& count); + //! Obtain the next bit, incrementing count. + bool InputBit(int& count); - //! Obtain the next bit, incrementing count, if count & bool_opts) - : m_options(), - m_inputs(), - m_bool_opts(bool_opts) + : m_options(), + m_inputs(), + m_bool_opts(bool_opts) { bool option_active = false; vector