2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 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 or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-04-10 21:42:38 +00:00
|
|
|
#ifndef MEDIA_FORMATS_MP4_SEGMENTER_H_
|
|
|
|
#define MEDIA_FORMATS_MP4_SEGMENTER_H_
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "media/base/status.h"
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-11-12 20:37:58 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
struct MuxerOptions;
|
|
|
|
|
|
|
|
class BufferWriter;
|
2014-08-20 23:51:15 +00:00
|
|
|
class KeySource;
|
2013-11-12 20:37:58 +00:00
|
|
|
class MediaSample;
|
|
|
|
class MediaStream;
|
|
|
|
|
2014-05-22 18:51:55 +00:00
|
|
|
namespace event {
|
|
|
|
class MuxerListener;
|
|
|
|
} // namespace event
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
namespace mp4 {
|
|
|
|
|
2014-04-08 20:21:07 +00:00
|
|
|
class Fragmenter;
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
struct FileType;
|
|
|
|
struct Movie;
|
|
|
|
struct MovieFragment;
|
|
|
|
struct SegmentIndex;
|
|
|
|
|
2014-04-08 20:21:07 +00:00
|
|
|
/// This class defines the Segmenter which is responsible for organizing
|
|
|
|
/// fragments into segments/subsegments and package them into a MP4 file.
|
|
|
|
/// Inherited by MultiSegmentSegmenter and SingleSegmentSegmenter.
|
|
|
|
/// SingleSegmentSegmenter defines the Segmenter for DASH Video-On-Demand with
|
|
|
|
/// a single segment for each media presentation while MultiSegmentSegmenter
|
|
|
|
/// handles all other cases including DASH live profile.
|
|
|
|
class Segmenter {
|
2013-11-12 20:37:58 +00:00
|
|
|
public:
|
2014-04-08 20:21:07 +00:00
|
|
|
Segmenter(const MuxerOptions& options,
|
|
|
|
scoped_ptr<FileType> ftyp,
|
|
|
|
scoped_ptr<Movie> moov);
|
|
|
|
virtual ~Segmenter();
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Initialize the segmenter.
|
|
|
|
/// Calling other public methods of this class without this method returning
|
2014-04-18 22:00:30 +00:00
|
|
|
/// Status::OK results in an undefined behavior.
|
2014-04-18 18:49:49 +00:00
|
|
|
/// @param streams contains the vector of MediaStreams to be segmented.
|
2014-04-16 01:09:32 +00:00
|
|
|
/// @param encryption_key_source points to the key source which contains
|
2014-04-18 22:00:30 +00:00
|
|
|
/// the encryption keys. It can be NULL to indicate that no encryption
|
|
|
|
/// is required.
|
2014-04-24 21:32:18 +00:00
|
|
|
/// @param max_sd_pixels specifies the threshold to determine whether a video
|
|
|
|
/// track should be considered as SD or HD. If the track has more
|
|
|
|
/// pixels per frame than max_sd_pixels, it is HD, SD otherwise.
|
2014-04-18 22:00:30 +00:00
|
|
|
/// @param clear_time specifies clear lead duration in seconds.
|
2014-04-18 18:49:49 +00:00
|
|
|
/// @param crypto_period_duration specifies crypto period duration in seconds.
|
2014-04-18 22:00:30 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
Status Initialize(const std::vector<MediaStream*>& streams,
|
2014-05-22 18:51:55 +00:00
|
|
|
event::MuxerListener* muxer_listener,
|
2014-08-20 23:51:15 +00:00
|
|
|
KeySource* encryption_key_source,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t max_sd_pixels,
|
2014-04-18 18:49:49 +00:00
|
|
|
double clear_lead_in_seconds,
|
|
|
|
double crypto_period_duration_in_seconds);
|
2014-04-18 22:00:30 +00:00
|
|
|
|
|
|
|
/// Finalize the segmenter.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
Status Finalize();
|
|
|
|
|
|
|
|
/// Add sample to the indicated stream.
|
|
|
|
/// @param stream points to the stream to which the sample belongs. It cannot
|
|
|
|
/// be NULL.
|
|
|
|
/// @param sample points to the sample to be added.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
|
|
|
Status AddSample(const MediaStream* stream,
|
|
|
|
scoped_refptr<MediaSample> sample);
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return true if there is an initialization range, while setting @a offset
|
|
|
|
/// and @a size; or false if initialization range does not apply.
|
2013-12-12 23:49:31 +00:00
|
|
|
virtual bool GetInitRange(size_t* offset, size_t* size) = 0;
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return true if there is an index byte range, while setting @a offset
|
|
|
|
/// and @a size; or false if index byte range does not apply.
|
2013-12-12 23:49:31 +00:00
|
|
|
virtual bool GetIndexRange(size_t* offset, size_t* size) = 0;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t GetReferenceTimeScale() const;
|
2013-12-12 23:49:31 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return The total length, in seconds, of segmented media files.
|
2013-12-12 23:49:31 +00:00
|
|
|
double GetDuration() const;
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
protected:
|
|
|
|
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(); }
|
2014-05-22 18:51:55 +00:00
|
|
|
event::MuxerListener* muxer_listener() { return muxer_listener_; }
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-18 22:00:30 +00:00
|
|
|
virtual Status DoInitialize() = 0;
|
|
|
|
virtual Status DoFinalize() = 0;
|
|
|
|
virtual Status DoFinalizeSegment() = 0;
|
|
|
|
|
|
|
|
void InitializeSegment();
|
|
|
|
Status FinalizeSegment();
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t GetReferenceStreamId();
|
2014-04-18 22:00:30 +00:00
|
|
|
|
2014-04-08 20:21:07 +00:00
|
|
|
Status FinalizeFragment(Fragmenter* fragment);
|
2013-11-12 20:37:58 +00:00
|
|
|
|
|
|
|
const MuxerOptions& options_;
|
|
|
|
scoped_ptr<FileType> ftyp_;
|
|
|
|
scoped_ptr<Movie> moov_;
|
|
|
|
scoped_ptr<MovieFragment> moof_;
|
|
|
|
scoped_ptr<BufferWriter> fragment_buffer_;
|
|
|
|
scoped_ptr<SegmentIndex> sidx_;
|
2014-04-08 20:21:07 +00:00
|
|
|
std::vector<Fragmenter*> fragmenters_;
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint64_t> segment_durations_;
|
|
|
|
std::map<const MediaStream*, uint32_t> stream_map_;
|
2013-11-12 20:37:58 +00:00
|
|
|
bool segment_initialized_;
|
|
|
|
bool end_of_segment_;
|
2014-05-22 18:51:55 +00:00
|
|
|
event::MuxerListener* muxer_listener_;
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-04-08 20:21:07 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Segmenter);
|
2013-11-12 20:37:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-11-12 20:37:58 +00:00
|
|
|
|
2014-04-10 21:42:38 +00:00
|
|
|
#endif // MEDIA_FORMATS_MP4_SEGMENTER_H_
|