2013-09-24 04:17:12 +00:00
|
|
|
// Copyright (c) 2013 Google Inc. All rights reserved.
|
2013-09-24 01:35:40 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
#ifndef MEDIA_MP4_MP4_MEDIA_PARSER_H_
|
|
|
|
#define MEDIA_MP4_MP4_MEDIA_PARSER_H_
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
2013-09-24 04:17:12 +00:00
|
|
|
#include "base/callback_forward.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
2013-09-24 04:17:12 +00:00
|
|
|
#include "media/base/media_parser.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
#include "media/mp4/offset_byte_queue.h"
|
|
|
|
|
|
|
|
namespace media {
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
struct Movie;
|
|
|
|
class BoxReader;
|
2013-09-24 04:17:12 +00:00
|
|
|
class ProtectionSystemSpecificHeader;
|
|
|
|
class TrackRunIterator;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
class MP4MediaParser : public MediaParser {
|
2013-09-24 01:35:40 +00:00
|
|
|
public:
|
2013-09-24 04:17:12 +00:00
|
|
|
MP4MediaParser();
|
|
|
|
virtual ~MP4MediaParser();
|
|
|
|
|
|
|
|
virtual void Init(const InitCB& init_cb,
|
|
|
|
const NewSampleCB& new_sample_cb,
|
|
|
|
const NeedKeyCB& need_key_cb) OVERRIDE;
|
2013-09-24 01:35:40 +00:00
|
|
|
virtual bool Parse(const uint8* buf, int size) OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum State {
|
|
|
|
kWaitingForInit,
|
|
|
|
kParsingBoxes,
|
|
|
|
kEmittingSamples,
|
|
|
|
kError
|
|
|
|
};
|
|
|
|
|
|
|
|
bool ParseBox(bool* err);
|
|
|
|
bool ParseMoov(mp4::BoxReader* reader);
|
|
|
|
bool ParseMoof(mp4::BoxReader* reader);
|
|
|
|
|
|
|
|
void EmitNeedKeyIfNecessary(
|
|
|
|
const std::vector<ProtectionSystemSpecificHeader>& headers);
|
|
|
|
|
|
|
|
// To retain proper framing, each 'mdat' atom must be read; to limit memory
|
|
|
|
// usage, the atom's data needs to be discarded incrementally as frames are
|
|
|
|
// extracted from the stream. This function discards data from the stream up
|
|
|
|
// to |offset|, updating the |mdat_tail_| value so that framing can be
|
|
|
|
// retained after all 'mdat' information has been read.
|
|
|
|
// Returns 'true' on success, 'false' if there was an error.
|
|
|
|
bool ReadAndDiscardMDATsUntil(const int64 offset);
|
|
|
|
|
|
|
|
void ChangeState(State new_state);
|
|
|
|
|
|
|
|
bool EmitConfigs();
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
bool EnqueueSample(bool* err);
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
State state_;
|
|
|
|
InitCB init_cb_;
|
2013-09-24 04:17:12 +00:00
|
|
|
NewSampleCB new_sample_cb_;
|
2013-09-24 01:35:40 +00:00
|
|
|
NeedKeyCB need_key_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
|
|
|
|
// block. All byte offsets in sample information are relative to this offset,
|
|
|
|
// as mandated by the Media Source spec.
|
|
|
|
int64 moof_head_;
|
|
|
|
// |mdat_tail_| is the stream offset of the end of the current 'mdat' box.
|
|
|
|
// Valid iff it is greater than the head of the queue.
|
|
|
|
int64 mdat_tail_;
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
scoped_ptr<Movie> moov_;
|
|
|
|
scoped_ptr<TrackRunIterator> runs_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
bool has_audio_;
|
|
|
|
bool has_video_;
|
|
|
|
uint32 audio_track_id_;
|
|
|
|
uint32 video_track_id_;
|
|
|
|
bool is_audio_track_encrypted_;
|
|
|
|
bool is_video_track_encrypted_;
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(MP4MediaParser);
|
2013-09-24 01:35:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
#endif // MEDIA_MP4_MP4_MEDIA_PARSER_H_
|