| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ | 5 #ifndef MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ |
| 6 #define MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ | 6 #define MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <set> | 10 #include <set> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 15 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
| 16 #include "media/base/stream_parser.h" | 18 #include "media/base/stream_parser.h" |
| 17 #include "media/formats/common/offset_byte_queue.h" | 19 #include "media/formats/common/offset_byte_queue.h" |
| 18 #include "media/formats/mp4/track_run_iterator.h" | 20 #include "media/formats/mp4/track_run_iterator.h" |
| 19 | 21 |
| 20 namespace media { | 22 namespace media { |
| 21 namespace mp4 { | 23 namespace mp4 { |
| 22 | 24 |
| 23 struct Movie; | 25 struct Movie; |
| 24 class BoxReader; | 26 class BoxReader; |
| 25 | 27 |
| 26 class MEDIA_EXPORT MP4StreamParser : public StreamParser { | 28 class MEDIA_EXPORT MP4StreamParser : public StreamParser { |
| 27 public: | 29 public: |
| 28 MP4StreamParser(const std::set<int>& audio_object_types, bool has_sbr); | 30 MP4StreamParser(const std::set<int>& audio_object_types, bool has_sbr); |
| 29 ~MP4StreamParser() override; | 31 ~MP4StreamParser() override; |
| 30 | 32 |
| 31 void Init(const InitCB& init_cb, | 33 void Init(const InitCB& init_cb, |
| 32 const NewConfigCB& config_cb, | 34 const NewConfigCB& config_cb, |
| 33 const NewBuffersCB& new_buffers_cb, | 35 const NewBuffersCB& new_buffers_cb, |
| 34 bool ignore_text_tracks, | 36 bool ignore_text_tracks, |
| 35 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 37 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
| 36 const NewMediaSegmentCB& new_segment_cb, | 38 const NewMediaSegmentCB& new_segment_cb, |
| 37 const base::Closure& end_of_segment_cb, | 39 const base::Closure& end_of_segment_cb, |
| 38 const scoped_refptr<MediaLog>& media_log) override; | 40 const scoped_refptr<MediaLog>& media_log) override; |
| 39 void Flush() override; | 41 void Flush() override; |
| 40 bool Parse(const uint8* buf, int size) override; | 42 bool Parse(const uint8_t* buf, int size) override; |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 enum State { | 45 enum State { |
| 44 kWaitingForInit, | 46 kWaitingForInit, |
| 45 kParsingBoxes, | 47 kParsingBoxes, |
| 46 kWaitingForSampleData, | 48 kWaitingForSampleData, |
| 47 kEmittingSamples, | 49 kEmittingSamples, |
| 48 kError | 50 kError |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 bool ParseBox(bool* err); | 53 bool ParseBox(bool* err); |
| 52 bool ParseMoov(mp4::BoxReader* reader); | 54 bool ParseMoov(mp4::BoxReader* reader); |
| 53 bool ParseMoof(mp4::BoxReader* reader); | 55 bool ParseMoof(mp4::BoxReader* reader); |
| 54 | 56 |
| 55 void OnEncryptedMediaInitData( | 57 void OnEncryptedMediaInitData( |
| 56 const std::vector<ProtectionSystemSpecificHeader>& headers); | 58 const std::vector<ProtectionSystemSpecificHeader>& headers); |
| 57 | 59 |
| 58 // To retain proper framing, each 'mdat' atom must be read; to limit memory | 60 // To retain proper framing, each 'mdat' atom must be read; to limit memory |
| 59 // usage, the atom's data needs to be discarded incrementally as frames are | 61 // usage, the atom's data needs to be discarded incrementally as frames are |
| 60 // extracted from the stream. This function discards data from the stream up | 62 // extracted from the stream. This function discards data from the stream up |
| 61 // to |max_clear_offset|, updating the |mdat_tail_| value so that framing can | 63 // to |max_clear_offset|, updating the |mdat_tail_| value so that framing can |
| 62 // be retained after all 'mdat' information has been read. |max_clear_offset| | 64 // be retained after all 'mdat' information has been read. |max_clear_offset| |
| 63 // is the upper bound on what can be removed from |queue_|. Anything below | 65 // is the upper bound on what can be removed from |queue_|. Anything below |
| 64 // this offset is no longer needed by the parser. | 66 // this offset is no longer needed by the parser. |
| 65 // Returns 'true' on success, 'false' if there was an error. | 67 // Returns 'true' on success, 'false' if there was an error. |
| 66 bool ReadAndDiscardMDATsUntil(int64 max_clear_offset); | 68 bool ReadAndDiscardMDATsUntil(int64_t max_clear_offset); |
| 67 | 69 |
| 68 void ChangeState(State new_state); | 70 void ChangeState(State new_state); |
| 69 | 71 |
| 70 bool EmitConfigs(); | 72 bool EmitConfigs(); |
| 71 bool PrepareAACBuffer(const AAC& aac_config, | 73 bool PrepareAACBuffer(const AAC& aac_config, |
| 72 std::vector<uint8>* frame_buf, | 74 std::vector<uint8_t>* frame_buf, |
| 73 std::vector<SubsampleEntry>* subsamples) const; | 75 std::vector<SubsampleEntry>* subsamples) const; |
| 74 bool EnqueueSample(BufferQueue* audio_buffers, | 76 bool EnqueueSample(BufferQueue* audio_buffers, |
| 75 BufferQueue* video_buffers, | 77 BufferQueue* video_buffers, |
| 76 bool* err); | 78 bool* err); |
| 77 bool SendAndFlushSamples(BufferQueue* audio_buffers, | 79 bool SendAndFlushSamples(BufferQueue* audio_buffers, |
| 78 BufferQueue* video_buffers); | 80 BufferQueue* video_buffers); |
| 79 | 81 |
| 80 void Reset(); | 82 void Reset(); |
| 81 | 83 |
| 82 // Checks to see if we have enough data in |queue_| to transition to | 84 // Checks to see if we have enough data in |queue_| to transition to |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 base::Closure end_of_segment_cb_; | 99 base::Closure end_of_segment_cb_; |
| 98 scoped_refptr<MediaLog> media_log_; | 100 scoped_refptr<MediaLog> media_log_; |
| 99 | 101 |
| 100 OffsetByteQueue queue_; | 102 OffsetByteQueue queue_; |
| 101 | 103 |
| 102 // These two parameters are only valid in the |kEmittingSegments| state. | 104 // These two parameters are only valid in the |kEmittingSegments| state. |
| 103 // | 105 // |
| 104 // |moof_head_| is the offset of the start of the most recently parsed moof | 106 // |moof_head_| is the offset of the start of the most recently parsed moof |
| 105 // block. All byte offsets in sample information are relative to this offset, | 107 // block. All byte offsets in sample information are relative to this offset, |
| 106 // as mandated by the Media Source spec. | 108 // as mandated by the Media Source spec. |
| 107 int64 moof_head_; | 109 int64_t moof_head_; |
| 108 // |mdat_tail_| is the stream offset of the end of the current 'mdat' box. | 110 // |mdat_tail_| is the stream offset of the end of the current 'mdat' box. |
| 109 // Valid iff it is greater than the head of the queue. | 111 // Valid iff it is greater than the head of the queue. |
| 110 int64 mdat_tail_; | 112 int64_t mdat_tail_; |
| 111 | 113 |
| 112 // The highest end offset in the current moof. This offset is | 114 // The highest end offset in the current moof. This offset is |
| 113 // relative to |moof_head_|. This value is used to make sure we have collected | 115 // relative to |moof_head_|. This value is used to make sure we have collected |
| 114 // enough bytes to parse all samples and aux_info in the current moof. | 116 // enough bytes to parse all samples and aux_info in the current moof. |
| 115 int64 highest_end_offset_; | 117 int64_t highest_end_offset_; |
| 116 | 118 |
| 117 scoped_ptr<mp4::Movie> moov_; | 119 scoped_ptr<mp4::Movie> moov_; |
| 118 scoped_ptr<mp4::TrackRunIterator> runs_; | 120 scoped_ptr<mp4::TrackRunIterator> runs_; |
| 119 | 121 |
| 120 bool has_audio_; | 122 bool has_audio_; |
| 121 bool has_video_; | 123 bool has_video_; |
| 122 uint32 audio_track_id_; | 124 uint32_t audio_track_id_; |
| 123 uint32 video_track_id_; | 125 uint32_t video_track_id_; |
| 124 // The object types allowed for audio tracks. | 126 // The object types allowed for audio tracks. |
| 125 std::set<int> audio_object_types_; | 127 std::set<int> audio_object_types_; |
| 126 bool has_sbr_; | 128 bool has_sbr_; |
| 127 bool is_audio_track_encrypted_; | 129 bool is_audio_track_encrypted_; |
| 128 bool is_video_track_encrypted_; | 130 bool is_video_track_encrypted_; |
| 129 | 131 |
| 130 // Tracks the number of MEDIA_LOGs for skipping top level boxes. Useful to | 132 // Tracks the number of MEDIA_LOGs for skipping top level boxes. Useful to |
| 131 // prevent log spam. | 133 // prevent log spam. |
| 132 int num_top_level_box_skipped_; | 134 int num_top_level_box_skipped_; |
| 133 | 135 |
| 134 DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); | 136 DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); |
| 135 }; | 137 }; |
| 136 | 138 |
| 137 } // namespace mp4 | 139 } // namespace mp4 |
| 138 } // namespace media | 140 } // namespace media |
| 139 | 141 |
| 140 #endif // MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ | 142 #endif // MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ |
| OLD | NEW |