| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_MP4_MP4_STREAM_PARSER_H_ |
| 6 #define MEDIA_MP4_MP4_STREAM_PARSER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "media/base/media_export.h" |
| 13 #include "media/base/stream_parser.h" |
| 14 #include "media/mp4/offset_byte_queue.h" |
| 15 #include "media/mp4/track_run_iterator.h" |
| 16 |
| 17 namespace media { |
| 18 namespace mp4 { |
| 19 |
| 20 struct Movie; |
| 21 class BoxReader; |
| 22 |
| 23 class MEDIA_EXPORT MP4StreamParser : public StreamParser { |
| 24 public: |
| 25 MP4StreamParser(); |
| 26 virtual ~MP4StreamParser(); |
| 27 |
| 28 virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, |
| 29 const NewBuffersCB& audio_cb, |
| 30 const NewBuffersCB& video_cb, |
| 31 const KeyNeededCB& key_needed_cb, |
| 32 const NewMediaSegmentCB& new_segment_cb) OVERRIDE; |
| 33 virtual void Flush() OVERRIDE; |
| 34 virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| 35 |
| 36 private: |
| 37 enum State { |
| 38 kWaitingForInit, |
| 39 kParsingBoxes, |
| 40 kEmittingSamples, |
| 41 kError |
| 42 }; |
| 43 |
| 44 bool ParseBox(bool* err); |
| 45 bool ParseMoov(mp4::BoxReader* reader); |
| 46 bool ParseMoof(mp4::BoxReader* reader); |
| 47 |
| 48 bool ReadMDATsUntil(const int64 tgt_tail); |
| 49 |
| 50 void ChangeState(State new_state); |
| 51 |
| 52 bool EmitConfigs(); |
| 53 bool EnqueueSample(BufferQueue* audio_buffers, |
| 54 BufferQueue* video_buffers, |
| 55 bool* err); |
| 56 |
| 57 State state_; |
| 58 InitCB init_cb_; |
| 59 NewConfigCB config_cb_; |
| 60 NewBuffersCB audio_cb_; |
| 61 NewBuffersCB video_cb_; |
| 62 KeyNeededCB key_needed_cb_; |
| 63 NewMediaSegmentCB new_segment_cb_; |
| 64 |
| 65 OffsetByteQueue queue_; |
| 66 |
| 67 // These two parameters are only valid in the |kEmittingSegments| state. |
| 68 // |
| 69 // |moof_head_| is the offset of the start of the most recently parsed moof |
| 70 // block. All byte offsets in sample information are relative to this offset, |
| 71 // as mandated by the Media Source spec. |
| 72 int64 moof_head_; |
| 73 // |mdat_tail_| is the stream offset of the end of the current 'mdat' box. |
| 74 // Valid iff it is greater than the head of the queue. |
| 75 int64 mdat_tail_; |
| 76 |
| 77 mp4::TrackRunIterator runs_; |
| 78 |
| 79 scoped_ptr<mp4::Movie> moov_; |
| 80 |
| 81 bool has_audio_; |
| 82 bool has_video_; |
| 83 uint32 audio_track_id_; |
| 84 uint32 video_track_id_; |
| 85 bool parameter_sets_inserted_; |
| 86 |
| 87 // We keep this around to avoid having to go digging through the moov with |
| 88 // every frame. |
| 89 uint8 size_of_nalu_length_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); |
| 92 }; |
| 93 |
| 94 } // namespace mp4 |
| 95 } // namespace media |
| 96 |
| 97 #endif // MEDIA_MP4_MP4_STREAM_PARSER_H_ |
| OLD | NEW |