Chromium Code Reviews| 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/callback_forward.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "media/base/audio_decoder_config.h" | |
| 11 #include "media/base/buffers.h" | |
| 12 #include "media/base/byte_queue.h" | |
| 13 #include "media/base/stream_parser.h" | |
| 14 #include "media/base/video_decoder_config.h" | |
| 15 #include "media/mp4/box_definitions.h" | |
| 16 #include "media/mp4/track_run_iterator.h" | |
| 17 | |
| 18 namespace media { | |
| 19 | |
| 20 namespace mp4 { | |
| 21 class BoxReader; | |
| 22 } | |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Remove }. Lets keep the MP4StreamParser in the mp4
strobe_
2012/06/07 16:33:54
Done.
| |
| 23 | |
| 24 using mp4::BoxReader; | |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
remove since everything is in the mp4 namespace no
strobe_
2012/06/07 16:33:54
Done.
| |
| 25 | |
| 26 // A wrapper around a ByteQueue which maintains a notion of a | |
| 27 // monotonically-increasing offset. All buffer access is done by passing these | |
| 28 // offsets into this class, going some way towards preventing the proliferation | |
| 29 // of many different meanings of "offset", "head", etc. | |
| 30 class OffsetByteQueue { | |
| 31 public: | |
| 32 OffsetByteQueue(); | |
| 33 ~OffsetByteQueue(); | |
| 34 | |
| 35 // These work like their underlying ByteQueue counterparts. | |
| 36 void Reset(); | |
| 37 void Push(const uint8* buf, size_t size); | |
| 38 void Peek(const uint8** buf, size_t* size); | |
| 39 void Pop(size_t count); | |
| 40 | |
| 41 // Sets 'buf' to point at the first buffered byte corresponding to 'offset', | |
| 42 // and 'size' to the number of bytes available starting from that offset. | |
| 43 // | |
| 44 // It is an error if the offset is before the current head. It's not an error | |
| 45 // if the current offset is beyond tail(), but you will of course get back | |
| 46 // '*buf==NULL' and '*size==0'. | |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Use || when referring to parameters. ie |buf| == N
strobe_
2012/06/07 16:33:54
Done.
| |
| 47 void PeekAt(size_t offset, const uint8** buf, size_t* size); | |
| 48 | |
| 49 // Marks the bytes up to 'max_offset' as ready for deletion. This is | |
| 50 // relatively inexpensive, but will not necessarily reduce the resident | |
| 51 // buffer size right away (or ever). | |
| 52 // | |
| 53 // Returns 'true' if the full range of bytes were successfully trimmed; | |
| 54 // 'false' if the max offset was greater than the end of the buffer. | |
| 55 // | |
| 56 // It is OK if 'max_offset' is less than the current head; the request will be | |
| 57 // ignored. | |
| 58 bool Trim(size_t max_offset); | |
| 59 | |
| 60 // The head and tail positions | |
| 61 size_t head() { return head_; } | |
| 62 size_t tail() { return head_ + size_; } | |
| 63 | |
| 64 private: | |
| 65 // Synchronize buf_ and size_ with queue_. | |
| 66 void Sync(); | |
| 67 | |
| 68 ByteQueue queue_; | |
| 69 const uint8* buf_; | |
| 70 size_t size_; | |
| 71 size_t head_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(OffsetByteQueue); | |
| 74 }; | |
| 75 | |
| 76 // This class is essentially identical in structure to the WebM parser and | |
| 77 // the common bits should be factored before it lands. | |
| 78 class MP4StreamParser : public StreamParser { | |
| 79 public: | |
| 80 MP4StreamParser(); | |
| 81 virtual ~MP4StreamParser(); | |
| 82 | |
| 83 virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, | |
| 84 const NewBuffersCB& audio_cb, | |
| 85 const NewBuffersCB& video_cb, | |
| 86 const KeyNeededCB& key_needed_cb) OVERRIDE; | |
| 87 virtual void Flush() OVERRIDE; | |
| 88 virtual bool Parse(const uint8* buf, int size) OVERRIDE; | |
| 89 | |
| 90 private: | |
| 91 enum State { | |
| 92 kWaitingForInit, | |
| 93 kParsingBoxes, | |
| 94 kEmittingSamples, | |
| 95 kError | |
| 96 }; | |
| 97 | |
| 98 bool ParseBox(bool* err); | |
| 99 bool ParseMoov(BoxReader* r); | |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
r -> reader here and elsewhere
strobe_
2012/06/07 16:33:54
Done.
| |
| 100 bool ParseMoof(BoxReader* r); | |
| 101 | |
| 102 bool ReadMDATsUntil(const size_t tgt_tail); | |
| 103 | |
| 104 void ChangeState(State new_state); | |
| 105 | |
| 106 bool EmitConfigs(); | |
| 107 bool EnqueueSample(BufferQueue* audio_buffers, | |
| 108 BufferQueue* video_buffers, | |
| 109 bool* err); | |
| 110 | |
| 111 State state_; | |
| 112 InitCB init_cb_; | |
| 113 NewConfigCB config_cb_; | |
| 114 NewBuffersCB audio_cb_; | |
| 115 NewBuffersCB video_cb_; | |
| 116 KeyNeededCB key_needed_cb_; | |
| 117 | |
| 118 OffsetByteQueue queue_; | |
| 119 | |
| 120 // These two parameters are only valid in the 'kEmittingSegments' state. | |
| 121 // | |
| 122 // 'moof_head_' is the offset of the start of the most recently parsed moof | |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Use ||
strobe_
2012/06/07 16:33:54
Done.
| |
| 123 // block. All byte offsets in sample information are relative to this offset, | |
| 124 // as mandated by the Media Source spec. | |
| 125 size_t moof_head_; | |
| 126 // 'mdat_tail_' is the offset of the end of the | |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Use ||
strobe_
2012/06/07 16:33:54
Done.
| |
| 127 size_t mdat_tail_; | |
| 128 | |
| 129 mp4::TrackRunIterator runs_; | |
| 130 | |
| 131 scoped_ptr<mp4::Movie> moov_; | |
| 132 | |
| 133 bool has_audio_; | |
| 134 bool has_video_; | |
| 135 uint32 audio_track_id_; | |
| 136 uint32 video_track_id_; | |
| 137 | |
| 138 // We keep this around to avoid having to go digging through the moov with | |
| 139 // every frame. | |
| 140 uint8 size_of_nalu_length_; | |
| 141 | |
| 142 DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); | |
| 143 }; | |
| 144 | |
| 145 } // namespace media | |
| 146 | |
| 147 #endif // MEDIA_MP4_MP4_STREAM_PARSER_H_ | |
| OLD | NEW |