// 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 #include #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. MP4Segmenter(const MuxerOptions& options, scoped_ptr ftyp, scoped_ptr moov); 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& streams); virtual Status Finalize(); virtual Status AddSample(const MediaStream* stream, scoped_refptr 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 ftyp_; scoped_ptr moov_; scoped_ptr moof_; scoped_ptr fragment_buffer_; scoped_ptr sidx_; std::vector fragmenters_; std::vector segment_durations_; std::map stream_map_; bool segment_initialized_; bool end_of_segment_; DISALLOW_COPY_AND_ASSIGN(MP4Segmenter); }; } // namespace mp4 } // namespace media #endif // MEDIA_MP4_MP4_SEGMENTER_H_