Chromium Code Reviews| Index: media/mp4/mp4_stream_parser.h |
| diff --git a/media/mp4/mp4_stream_parser.h b/media/mp4/mp4_stream_parser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f24b1e5f8d2e52ef204290b4742ee488746cf49c |
| --- /dev/null |
| +++ b/media/mp4/mp4_stream_parser.h |
| @@ -0,0 +1,147 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_MP4_MP4_STREAM_PARSER_H_ |
| +#define MEDIA_MP4_MP4_STREAM_PARSER_H_ |
| + |
| +#include "base/callback_forward.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "media/base/audio_decoder_config.h" |
| +#include "media/base/buffers.h" |
| +#include "media/base/byte_queue.h" |
| +#include "media/base/stream_parser.h" |
| +#include "media/base/video_decoder_config.h" |
| +#include "media/mp4/box_definitions.h" |
| +#include "media/mp4/track_run_iterator.h" |
| + |
| +namespace media { |
| + |
| +namespace mp4 { |
| +class BoxReader; |
| +} |
|
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.
|
| + |
| +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.
|
| + |
| +// A wrapper around a ByteQueue which maintains a notion of a |
| +// monotonically-increasing offset. All buffer access is done by passing these |
| +// offsets into this class, going some way towards preventing the proliferation |
| +// of many different meanings of "offset", "head", etc. |
| +class OffsetByteQueue { |
| + public: |
| + OffsetByteQueue(); |
| + ~OffsetByteQueue(); |
| + |
| + // These work like their underlying ByteQueue counterparts. |
| + void Reset(); |
| + void Push(const uint8* buf, size_t size); |
| + void Peek(const uint8** buf, size_t* size); |
| + void Pop(size_t count); |
| + |
| + // Sets 'buf' to point at the first buffered byte corresponding to 'offset', |
| + // and 'size' to the number of bytes available starting from that offset. |
| + // |
| + // It is an error if the offset is before the current head. It's not an error |
| + // if the current offset is beyond tail(), but you will of course get back |
| + // '*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.
|
| + void PeekAt(size_t offset, const uint8** buf, size_t* size); |
| + |
| + // Marks the bytes up to 'max_offset' as ready for deletion. This is |
| + // relatively inexpensive, but will not necessarily reduce the resident |
| + // buffer size right away (or ever). |
| + // |
| + // Returns 'true' if the full range of bytes were successfully trimmed; |
| + // 'false' if the max offset was greater than the end of the buffer. |
| + // |
| + // It is OK if 'max_offset' is less than the current head; the request will be |
| + // ignored. |
| + bool Trim(size_t max_offset); |
| + |
| + // The head and tail positions |
| + size_t head() { return head_; } |
| + size_t tail() { return head_ + size_; } |
| + |
| + private: |
| + // Synchronize buf_ and size_ with queue_. |
| + void Sync(); |
| + |
| + ByteQueue queue_; |
| + const uint8* buf_; |
| + size_t size_; |
| + size_t head_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OffsetByteQueue); |
| +}; |
| + |
| +// This class is essentially identical in structure to the WebM parser and |
| +// the common bits should be factored before it lands. |
| +class MP4StreamParser : public StreamParser { |
| + public: |
| + MP4StreamParser(); |
| + virtual ~MP4StreamParser(); |
| + |
| + virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, |
| + const NewBuffersCB& audio_cb, |
| + const NewBuffersCB& video_cb, |
| + const KeyNeededCB& key_needed_cb) OVERRIDE; |
| + virtual void Flush() OVERRIDE; |
| + virtual bool Parse(const uint8* buf, int size) OVERRIDE; |
| + |
| + private: |
| + enum State { |
| + kWaitingForInit, |
| + kParsingBoxes, |
| + kEmittingSamples, |
| + kError |
| + }; |
| + |
| + bool ParseBox(bool* err); |
| + 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.
|
| + bool ParseMoof(BoxReader* r); |
| + |
| + bool ReadMDATsUntil(const size_t tgt_tail); |
| + |
| + void ChangeState(State new_state); |
| + |
| + bool EmitConfigs(); |
| + bool EnqueueSample(BufferQueue* audio_buffers, |
| + BufferQueue* video_buffers, |
| + bool* err); |
| + |
| + State state_; |
| + InitCB init_cb_; |
| + NewConfigCB config_cb_; |
| + NewBuffersCB audio_cb_; |
| + NewBuffersCB video_cb_; |
| + KeyNeededCB key_needed_cb_; |
| + |
| + OffsetByteQueue queue_; |
| + |
| + // These two parameters are only valid in the 'kEmittingSegments' state. |
| + // |
| + // '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.
|
| + // block. All byte offsets in sample information are relative to this offset, |
| + // as mandated by the Media Source spec. |
| + size_t moof_head_; |
| + // '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.
|
| + size_t mdat_tail_; |
| + |
| + mp4::TrackRunIterator runs_; |
| + |
| + scoped_ptr<mp4::Movie> moov_; |
| + |
| + bool has_audio_; |
| + bool has_video_; |
| + uint32 audio_track_id_; |
| + uint32 video_track_id_; |
| + |
| + // We keep this around to avoid having to go digging through the moov with |
| + // every frame. |
| + uint8 size_of_nalu_length_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MP4StreamParser); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_MP4_MP4_STREAM_PARSER_H_ |