| 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 <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const NewMediaSegmentCB& new_segment_cb, | 35 const NewMediaSegmentCB& new_segment_cb, |
| 36 const base::Closure& end_of_segment_cb, | 36 const base::Closure& end_of_segment_cb, |
| 37 const LogCB& log_cb) OVERRIDE; | 37 const LogCB& log_cb) OVERRIDE; |
| 38 virtual void Flush() OVERRIDE; | 38 virtual void Flush() OVERRIDE; |
| 39 virtual bool Parse(const uint8* buf, int size) OVERRIDE; | 39 virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 enum State { | 42 enum State { |
| 43 kWaitingForInit, | 43 kWaitingForInit, |
| 44 kParsingBoxes, | 44 kParsingBoxes, |
| 45 kWaitingForSampleData, |
| 45 kEmittingSamples, | 46 kEmittingSamples, |
| 46 kError | 47 kError |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 bool ParseBox(bool* err); | 50 bool ParseBox(bool* err); |
| 50 bool ParseMoov(mp4::BoxReader* reader); | 51 bool ParseMoov(mp4::BoxReader* reader); |
| 51 bool ParseMoof(mp4::BoxReader* reader); | 52 bool ParseMoof(mp4::BoxReader* reader); |
| 52 | 53 |
| 53 void EmitNeedKeyIfNecessary( | 54 void EmitNeedKeyIfNecessary( |
| 54 const std::vector<ProtectionSystemSpecificHeader>& headers); | 55 const std::vector<ProtectionSystemSpecificHeader>& headers); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 std::vector<uint8>* frame_buf, | 72 std::vector<uint8>* frame_buf, |
| 72 std::vector<SubsampleEntry>* subsamples) const; | 73 std::vector<SubsampleEntry>* subsamples) const; |
| 73 bool EnqueueSample(BufferQueue* audio_buffers, | 74 bool EnqueueSample(BufferQueue* audio_buffers, |
| 74 BufferQueue* video_buffers, | 75 BufferQueue* video_buffers, |
| 75 bool* err); | 76 bool* err); |
| 76 bool SendAndFlushSamples(BufferQueue* audio_buffers, | 77 bool SendAndFlushSamples(BufferQueue* audio_buffers, |
| 77 BufferQueue* video_buffers); | 78 BufferQueue* video_buffers); |
| 78 | 79 |
| 79 void Reset(); | 80 void Reset(); |
| 80 | 81 |
| 82 // Checks to see if we have enough data in |queue_| to transition to |
| 83 // kEmittingSamples and start enqueuing samples. |
| 84 bool HaveEnoughDataToEnqueueSamples(); |
| 85 |
| 86 // Sets |highest_end_offset_| based on the data in |moov_| |
| 87 // and |moof|. Returns true if |highest_end_offset_| was successfully |
| 88 // computed. |
| 89 bool ComputeHighestEndOffset(const MovieFragment& moof); |
| 90 |
| 81 State state_; | 91 State state_; |
| 82 InitCB init_cb_; | 92 InitCB init_cb_; |
| 83 NewConfigCB config_cb_; | 93 NewConfigCB config_cb_; |
| 84 NewBuffersCB new_buffers_cb_; | 94 NewBuffersCB new_buffers_cb_; |
| 85 NeedKeyCB need_key_cb_; | 95 NeedKeyCB need_key_cb_; |
| 86 NewMediaSegmentCB new_segment_cb_; | 96 NewMediaSegmentCB new_segment_cb_; |
| 87 base::Closure end_of_segment_cb_; | 97 base::Closure end_of_segment_cb_; |
| 88 LogCB log_cb_; | 98 LogCB log_cb_; |
| 89 | 99 |
| 90 OffsetByteQueue queue_; | 100 OffsetByteQueue queue_; |
| 91 | 101 |
| 92 // These two parameters are only valid in the |kEmittingSegments| state. | 102 // These two parameters are only valid in the |kEmittingSegments| state. |
| 93 // | 103 // |
| 94 // |moof_head_| is the offset of the start of the most recently parsed moof | 104 // |moof_head_| is the offset of the start of the most recently parsed moof |
| 95 // block. All byte offsets in sample information are relative to this offset, | 105 // block. All byte offsets in sample information are relative to this offset, |
| 96 // as mandated by the Media Source spec. | 106 // as mandated by the Media Source spec. |
| 97 int64 moof_head_; | 107 int64 moof_head_; |
| 98 // |mdat_tail_| is the stream offset of the end of the current 'mdat' box. | 108 // |mdat_tail_| is the stream offset of the end of the current 'mdat' box. |
| 99 // Valid iff it is greater than the head of the queue. | 109 // Valid iff it is greater than the head of the queue. |
| 100 int64 mdat_tail_; | 110 int64 mdat_tail_; |
| 101 | 111 |
| 112 // 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 |
| 114 // enough bytes to parse all samples and aux_info in the current moof. |
| 115 int64 highest_end_offset_; |
| 116 |
| 102 scoped_ptr<mp4::Movie> moov_; | 117 scoped_ptr<mp4::Movie> moov_; |
| 103 scoped_ptr<mp4::TrackRunIterator> runs_; | 118 scoped_ptr<mp4::TrackRunIterator> runs_; |
| 104 | 119 |
| 105 bool has_audio_; | 120 bool has_audio_; |
| 106 bool has_video_; | 121 bool has_video_; |
| 107 uint32 audio_track_id_; | 122 uint32 audio_track_id_; |
| 108 uint32 video_track_id_; | 123 uint32 video_track_id_; |
| 109 // The object types allowed for audio tracks. | 124 // The object types allowed for audio tracks. |
| 110 std::set<int> audio_object_types_; | 125 std::set<int> audio_object_types_; |
| 111 bool has_sbr_; | 126 bool has_sbr_; |
| 112 bool is_audio_track_encrypted_; | 127 bool is_audio_track_encrypted_; |
| 113 bool is_video_track_encrypted_; | 128 bool is_video_track_encrypted_; |
| 114 | 129 |
| 115 DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); | 130 DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); |
| 116 }; | 131 }; |
| 117 | 132 |
| 118 } // namespace mp4 | 133 } // namespace mp4 |
| 119 } // namespace media | 134 } // namespace media |
| 120 | 135 |
| 121 #endif // MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ | 136 #endif // MEDIA_FORMATS_MP4_MP4_STREAM_PARSER_H_ |
| OLD | NEW |