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.
|
|
|
|
virtual Status Initialize(EncryptorSource* encryptor_source,
|
|
|
|
const std::vector<MediaStream*>& streams);
|
|
|
|
|
|
|
|
virtual Status Finalize();
|
|
|
|
|
|
|
|
virtual Status AddSample(const MediaStream* stream,
|
|
|
|
scoped_refptr<MediaSample> sample);
|
|
|
|
|
|
|
|
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_
|