2013-09-24 01:35:40 +00:00
|
|
|
// 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_TRACK_RUN_ITERATOR_H_
|
|
|
|
#define MEDIA_MP4_TRACK_RUN_ITERATOR_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "media/mp4/box_definitions.h"
|
|
|
|
#include "media/mp4/cenc.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class DecryptConfig;
|
|
|
|
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
struct SampleInfo;
|
|
|
|
struct TrackRunInfo;
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
class TrackRunIterator {
|
2013-09-24 01:35:40 +00:00
|
|
|
public:
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Create a new TrackRunIterator from movie box.
|
|
|
|
/// @param moov should not be NULL.
|
2013-09-24 04:17:12 +00:00
|
|
|
explicit TrackRunIterator(const Movie* moov);
|
2013-09-24 01:35:40 +00:00
|
|
|
~TrackRunIterator();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// For non-fragmented mp4, moov contains all the chunk information; This
|
|
|
|
/// function sets up the iterator to access all the chunks.
|
|
|
|
/// For fragmented mp4, chunk and sample information are generally contained
|
|
|
|
/// in moof. This function is a no-op in this case. Init(moof) will be called
|
|
|
|
/// later after parsing moof.
|
|
|
|
/// @return true on success, false otherwise.
|
2013-10-08 17:37:58 +00:00
|
|
|
bool Init();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Set up the iterator to handle all the runs from the current fragment.
|
|
|
|
/// @return true on success, false otherwise.
|
2013-09-24 01:35:40 +00:00
|
|
|
bool Init(const MovieFragment& moof);
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return true if the iterator points to a valid run, false if past the
|
|
|
|
/// last run.
|
2013-09-24 01:35:40 +00:00
|
|
|
bool IsRunValid() const;
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return true if the iterator points to a valid sample, false if past the
|
|
|
|
/// last sample.
|
2013-09-24 01:35:40 +00:00
|
|
|
bool IsSampleValid() const;
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Advance iterator to the next run. Require that the iterator point to a
|
|
|
|
/// valid run.
|
2013-09-24 01:35:40 +00:00
|
|
|
void AdvanceRun();
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Advance iterator to the next sample. Require that the iterator point to a
|
|
|
|
/// valid sample.
|
2013-09-24 01:35:40 +00:00
|
|
|
void AdvanceSample();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return true if this track run has auxiliary information and has not yet
|
|
|
|
/// been cached. Only valid if IsRunValid().
|
2013-09-24 01:35:40 +00:00
|
|
|
bool AuxInfoNeedsToBeCached();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Caches the CENC data from the given buffer.
|
|
|
|
/// @param buf must be a buffer starting at the offset given by cenc_offset().
|
|
|
|
/// @param size must be at least cenc_size().
|
|
|
|
/// @return true on success, false on error.
|
2013-09-24 01:35:40 +00:00
|
|
|
bool CacheAuxInfo(const uint8* buf, int size);
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return the maximum buffer location at which no data earlier in the
|
|
|
|
/// stream will be required in order to read the current or any
|
|
|
|
/// subsequent sample. You may clear all data up to this offset
|
|
|
|
/// before reading the current sample safely. Result is in the same
|
|
|
|
/// units as offset() (for Media Source this is in bytes past the
|
|
|
|
/// head of the MOOF box).
|
2013-09-24 01:35:40 +00:00
|
|
|
int64 GetMaxClearOffset();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @name Properties of the current run. Only valid if IsRunValid().
|
|
|
|
/// @{
|
2013-09-24 01:35:40 +00:00
|
|
|
uint32 track_id() const;
|
|
|
|
int64 aux_info_offset() const;
|
|
|
|
int aux_info_size() const;
|
|
|
|
bool is_encrypted() const;
|
|
|
|
bool is_audio() const;
|
2014-03-17 18:36:41 +00:00
|
|
|
bool is_video() const;
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @}
|
|
|
|
|
2014-03-17 18:36:41 +00:00
|
|
|
/// Only valid if is_audio() is true.
|
2013-09-24 01:35:40 +00:00
|
|
|
const AudioSampleEntry& audio_description() const;
|
2014-03-17 18:36:41 +00:00
|
|
|
/// Only valid if is_video() is true.
|
2013-09-24 01:35:40 +00:00
|
|
|
const VideoSampleEntry& video_description() const;
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @name Properties of the current sample. Only valid if IsSampleValid().
|
|
|
|
/// @{
|
2013-09-24 01:35:40 +00:00
|
|
|
int64 sample_offset() const;
|
|
|
|
int sample_size() const;
|
2013-09-24 04:17:12 +00:00
|
|
|
int64 dts() const;
|
|
|
|
int64 cts() const;
|
|
|
|
int64 duration() const;
|
2013-09-24 01:35:40 +00:00
|
|
|
bool is_keyframe() const;
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Only call when is_encrypted() is true and AuxInfoNeedsToBeCached() is
|
|
|
|
/// false. Result is owned by caller.
|
2013-09-24 01:35:40 +00:00
|
|
|
scoped_ptr<DecryptConfig> GetDecryptConfig();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ResetRun();
|
|
|
|
const TrackEncryption& track_encryption() const;
|
|
|
|
|
|
|
|
const Movie* moov_;
|
|
|
|
|
|
|
|
std::vector<TrackRunInfo> runs_;
|
|
|
|
std::vector<TrackRunInfo>::const_iterator run_itr_;
|
|
|
|
std::vector<SampleInfo>::const_iterator sample_itr_;
|
|
|
|
|
|
|
|
std::vector<FrameCENCInfo> cenc_info_;
|
|
|
|
|
|
|
|
int64 sample_dts_;
|
|
|
|
int64 sample_offset_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TrackRunIterator);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif // MEDIA_MP4_TRACK_RUN_ITERATOR_H_
|