2013-11-12 20:37:58 +00:00
|
|
|
// Copyright (c) 2013 Google Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
//
|
|
|
|
// This class defines the MP4 Segmenter which is responsible for organizing
|
|
|
|
// MP4 fragments into segments/subsegments and package into a MP4 file.
|
|
|
|
// Inherited by MP4GeneralSegmenter and MP4VODSegmenter. MP4VODSegmenter defines
|
|
|
|
// the segmenter for DASH Video-On-Demand with a single segment for each media
|
|
|
|
// presentation while MP4GeneralSegmenter handles all other cases including
|
|
|
|
// DASH live profile.
|
|
|
|
|
|
|
|
#ifndef MEDIA_MP4_MP4_SEGMENTER_H_
|
|
|
|
#define MEDIA_MP4_MP4_SEGMENTER_H_
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "media/base/status.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
struct MuxerOptions;
|
|
|
|
|
|
|
|
class BufferWriter;
|
|
|
|
class EncryptorSource;
|
|
|
|
class MediaSample;
|
|
|
|
class MediaStream;
|
|
|
|
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
class MP4Fragmenter;
|
|
|
|
|
|
|
|
struct FileType;
|
|
|
|
struct Movie;
|
|
|
|
struct MovieFragment;
|
|
|
|
struct SegmentIndex;
|
|
|
|
|
|
|
|
class MP4Segmenter {
|
|
|
|
public:
|
|
|
|
// Caller transfers the ownership of |ftyp| and |moov| to this class.
|
2014-01-08 19:56:59 +00:00
|
|
|
MP4Segmenter(const MuxerOptions& options,
|
|
|
|
scoped_ptr<FileType> ftyp,
|
|
|
|
scoped_ptr<Movie> moov);
|
2013-11-12 20:37:58 +00:00
|
|
|
virtual ~MP4Segmenter();
|
|
|
|
|
|
|
|
// Initialize the segmenter. Caller retains the ownership of
|
|
|
|
// |encryptor_source|. |encryptor_source| can be NULL.
|
2013-12-12 23:49:31 +00:00
|
|
|
// Calling other public methods of this class without this method returning
|
|
|
|
// Status::OK, results in an undefined behavior.
|
2013-11-12 20:37:58 +00:00
|
|
|
virtual Status Initialize(EncryptorSource* encryptor_source,
|
2014-01-14 01:38:34 +00:00
|
|
|
double clear_lead_in_seconds,
|
2013-11-12 20:37:58 +00:00
|
|
|
const std::vector<MediaStream*>& streams);
|
|
|
|
|
|
|
|
virtual Status Finalize();
|
|
|
|
|
|
|
|
virtual Status AddSample(const MediaStream* stream,
|
|
|
|
scoped_refptr<MediaSample> sample);
|
|
|
|
|
2013-12-12 23:49:31 +00:00
|
|
|
// Returns false if it does not apply.
|
|
|
|
// If it has an initialization byte range this returns true and set |offset|
|
|
|
|
// and |size|, otherwise returns false.
|
|
|
|
virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
|
|
|
|
|
|
|
|
// Returns false if it does not apply.
|
|
|
|
// If it has an index byte range this returns true and set |offset| and
|
|
|
|
// |size|, otherwise returns false.
|
|
|
|
virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
|
|
|
|
|
|
|
|
uint32 GetReferenceTimeScale() const;
|
|
|
|
|
|
|
|
// Returns the total length, in seconds, of segmented media files.
|
|
|
|
double GetDuration() const;
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
protected:
|
|
|
|
void InitializeSegment();
|
|
|
|
virtual Status FinalizeSegment();
|
|
|
|
|
|
|
|
uint32 GetReferenceStreamId();
|
|
|
|
|
|
|
|
const MuxerOptions& options() const { return options_; }
|
|
|
|
FileType* ftyp() { return ftyp_.get(); }
|
|
|
|
Movie* moov() { return moov_.get(); }
|
|
|
|
BufferWriter* fragment_buffer() { return fragment_buffer_.get(); }
|
|
|
|
SegmentIndex* sidx() { return sidx_.get(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void InitializeFragments();
|
|
|
|
Status FinalizeFragment(MP4Fragmenter* fragment);
|
|
|
|
|
|
|
|
const MuxerOptions& options_;
|
|
|
|
scoped_ptr<FileType> ftyp_;
|
|
|
|
scoped_ptr<Movie> moov_;
|
|
|
|
scoped_ptr<MovieFragment> moof_;
|
|
|
|
scoped_ptr<BufferWriter> fragment_buffer_;
|
|
|
|
scoped_ptr<SegmentIndex> sidx_;
|
|
|
|
std::vector<MP4Fragmenter*> fragmenters_;
|
|
|
|
std::vector<uint64> segment_durations_;
|
|
|
|
std::map<const MediaStream*, uint32> stream_map_;
|
|
|
|
bool segment_initialized_;
|
|
|
|
bool end_of_segment_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MP4Segmenter);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif // MEDIA_MP4_MP4_SEGMENTER_H_
|