From 2498da675aed4d79da46d80c419885a7e286226a Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Tue, 8 Apr 2014 13:21:07 -0700 Subject: [PATCH] Rename MP4GeneralSegmenter and MP4VODSegmenter Rename MP4GeneralSegmenter to MultiSegmentSegmenter and MP4VODSegmenter to SingleSegmentSegmenter. Also drop MP4 from MP4Fragmenter and MP4Segmenter. Change-Id: I5cefb88164516ec3588e0e3333a16f05b6277e7b --- app/packager_main.cc | 2 +- media/file/local_file.h | 2 +- .../mp4/{mp4_fragmenter.cc => fragmenter.cc} | 28 +++++----- media/mp4/{mp4_fragmenter.h => fragmenter.h} | 24 ++++----- media/mp4/mp4.gyp | 16 +++--- media/mp4/mp4_muxer.cc | 9 ++-- media/mp4/mp4_muxer.h | 4 +- ...egmenter.cc => multi_segment_segmenter.cc} | 36 ++++++------- ..._segmenter.h => multi_segment_segmenter.h} | 24 ++++----- media/mp4/{mp4_segmenter.cc => segmenter.cc} | 52 +++++++++---------- media/mp4/{mp4_segmenter.h => segmenter.h} | 36 ++++++------- ...gmenter.cc => single_segment_segmenter.cc} | 35 +++++++------ ...segmenter.h => single_segment_segmenter.h} | 26 +++++----- media/test/packager_test.cc | 2 +- 14 files changed, 149 insertions(+), 147 deletions(-) rename media/mp4/{mp4_fragmenter.cc => fragmenter.cc} (91%) rename media/mp4/{mp4_fragmenter.h => fragmenter.h} (85%) rename media/mp4/{mp4_general_segmenter.cc => multi_segment_segmenter.cc} (83%) rename media/mp4/{mp4_general_segmenter.h => multi_segment_segmenter.h} (75%) rename media/mp4/{mp4_segmenter.cc => segmenter.cc} (83%) rename media/mp4/{mp4_segmenter.h => segmenter.h} (74%) rename media/mp4/{mp4_vod_segmenter.cc => single_segment_segmenter.cc} (83%) rename media/mp4/{mp4_vod_segmenter.h => single_segment_segmenter.h} (70%) diff --git a/app/packager_main.cc b/app/packager_main.cc index 7415c444e2..056ce61a72 100644 --- a/app/packager_main.cc +++ b/app/packager_main.cc @@ -16,11 +16,11 @@ #include "base/strings/stringprintf.h" #include "media/base/demuxer.h" #include "media/base/fixed_encryptor_source.h" -#include "media/base/widevine_encryptor_source.h" #include "media/base/media_stream.h" #include "media/base/muxer_options.h" #include "media/base/request_signer.h" #include "media/base/stream_info.h" +#include "media/base/widevine_encryptor_source.h" #include "media/event/vod_media_info_dump_muxer_listener.h" #include "media/file/file.h" #include "media/file/file_closer.h" diff --git a/media/file/local_file.h b/media/file/local_file.h index 7baf587035..9ca744aee5 100644 --- a/media/file/local_file.h +++ b/media/file/local_file.h @@ -34,7 +34,7 @@ class LocalFile : public File { /// @} protected: - ~LocalFile(); + virtual ~LocalFile(); virtual bool Open() OVERRIDE; diff --git a/media/mp4/mp4_fragmenter.cc b/media/mp4/fragmenter.cc similarity index 91% rename from media/mp4/mp4_fragmenter.cc rename to media/mp4/fragmenter.cc index a1b9f9c879..440a4fdac1 100644 --- a/media/mp4/mp4_fragmenter.cc +++ b/media/mp4/fragmenter.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "media/mp4/mp4_fragmenter.h" +#include "media/mp4/fragmenter.h" #include "media/base/aes_encryptor.h" #include "media/base/buffer_reader.h" @@ -41,11 +41,11 @@ bool OptimizeSampleEntries(std::vector* entries, T* default_value) { namespace media { namespace mp4 { -MP4Fragmenter::MP4Fragmenter(TrackFragment* traf, - scoped_ptr encryptor, - int64 clear_time, - uint8 nalu_length_size, - bool normalize_presentation_timestamp) +Fragmenter::Fragmenter(TrackFragment* traf, + scoped_ptr encryptor, + int64 clear_time, + uint8 nalu_length_size, + bool normalize_presentation_timestamp) : encryptor_(encryptor.Pass()), nalu_length_size_(nalu_length_size), traf_(traf), @@ -57,9 +57,9 @@ MP4Fragmenter::MP4Fragmenter(TrackFragment* traf, first_sap_time_(kInvalidTime), clear_time_(clear_time) {} -MP4Fragmenter::~MP4Fragmenter() {} +Fragmenter::~Fragmenter() {} -Status MP4Fragmenter::AddSample(scoped_refptr sample) { +Status Fragmenter::AddSample(scoped_refptr sample) { CHECK_GT(sample->duration(), 0); if (ShouldEncryptFragment()) { @@ -112,7 +112,7 @@ Status MP4Fragmenter::AddSample(scoped_refptr sample) { return Status::OK; } -void MP4Fragmenter::InitializeFragment() { +void Fragmenter::InitializeFragment() { fragment_finalized_ = false; traf_->decode_time.decode_time += fragment_duration_; traf_->auxiliary_size.sample_info_sizes.clear(); @@ -135,7 +135,7 @@ void MP4Fragmenter::InitializeFragment() { } } -void MP4Fragmenter::FinalizeFragment() { +void Fragmenter::FinalizeFragment() { if (ShouldEncryptFragment()) { DCHECK(encryptor_); @@ -188,7 +188,7 @@ void MP4Fragmenter::FinalizeFragment() { fragment_finalized_ = true; } -void MP4Fragmenter::GenerateSegmentReference(SegmentReference* reference) { +void Fragmenter::GenerateSegmentReference(SegmentReference* reference) { // NOTE: Daisy chain is not supported currently. reference->reference_type = false; reference->subsegment_duration = fragment_duration_; @@ -203,12 +203,12 @@ void MP4Fragmenter::GenerateSegmentReference(SegmentReference* reference) { reference->earliest_presentation_time = earliest_presentation_time_; } -void MP4Fragmenter::EncryptBytes(uint8* data, uint32 size) { +void Fragmenter::EncryptBytes(uint8* data, uint32 size) { DCHECK(encryptor_); CHECK(encryptor_->Encrypt(data, size, data)); } -Status MP4Fragmenter::EncryptSample(scoped_refptr sample) { +Status Fragmenter::EncryptSample(scoped_refptr sample) { DCHECK(encryptor_); FrameCENCInfo cenc_info(encryptor_->iv()); @@ -244,7 +244,7 @@ Status MP4Fragmenter::EncryptSample(scoped_refptr sample) { return Status::OK; } -bool MP4Fragmenter::StartsWithSAP() { +bool Fragmenter::StartsWithSAP() { DCHECK(!traf_->runs.empty()); uint32 start_sample_flag; if (traf_->runs[0].flags & TrackFragmentRun::kSampleFlagsPresentMask) { diff --git a/media/mp4/mp4_fragmenter.h b/media/mp4/fragmenter.h similarity index 85% rename from media/mp4/mp4_fragmenter.h rename to media/mp4/fragmenter.h index 528e2772b3..da19aa61eb 100644 --- a/media/mp4/mp4_fragmenter.h +++ b/media/mp4/fragmenter.h @@ -4,8 +4,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef MEDIA_MP4_MP4_FRAGMENTER_H_ -#define MEDIA_MP4_MP4_FRAGMENTER_H_ +#ifndef MEDIA_MP4_FRAGMENTER_H_ +#define MEDIA_MP4_FRAGMENTER_H_ #include @@ -24,10 +24,10 @@ namespace mp4 { struct SegmentReference; struct TrackFragment; -/// MP4Fragmenter is responsible for the generation of MP4 fragments, i.e. traf +/// Fragmenter is responsible for the generation of MP4 fragments, i.e. traf /// box and corresponding mdat box. The samples are also encrypted if encryption /// is requested. -class MP4Fragmenter { +class Fragmenter { public: /// @param traf points to a TrackFragment box. /// @param encryptor handles encryption of the samples. It can be NULL, which @@ -38,12 +38,12 @@ class MP4Fragmenter { /// encryption. /// @param normalize_presentation_timestamp defines whether PTS should be /// normalized to start from zero. - MP4Fragmenter(TrackFragment* traf, - scoped_ptr encryptor, - int64 clear_time, - uint8 nalu_length_size, - bool normalize_presentation_timestamp); - ~MP4Fragmenter(); + Fragmenter(TrackFragment* traf, + scoped_ptr encryptor, + int64 clear_time, + uint8 nalu_length_size, + bool normalize_presentation_timestamp); + ~Fragmenter(); /// Add a sample to the fragmenter. Status AddSample(scoped_refptr sample); @@ -97,10 +97,10 @@ class MP4Fragmenter { scoped_ptr data_; scoped_ptr aux_data_; - DISALLOW_COPY_AND_ASSIGN(MP4Fragmenter); + DISALLOW_COPY_AND_ASSIGN(Fragmenter); }; } // namespace mp4 } // namespace media -#endif // MEDIA_MP4_MP4_FRAGMENTER_H_ +#endif // MEDIA_MP4_FRAGMENTER_H_ diff --git a/media/mp4/mp4.gyp b/media/mp4/mp4.gyp index f6b211a0ce..a7206e9f6a 100644 --- a/media/mp4/mp4.gyp +++ b/media/mp4/mp4.gyp @@ -40,21 +40,21 @@ 'es_descriptor.cc', 'es_descriptor.h', 'fourccs.h', - 'mp4_fragmenter.cc', - 'mp4_fragmenter.h', - 'mp4_general_segmenter.cc', - 'mp4_general_segmenter.h', + 'fragmenter.cc', + 'fragmenter.h', 'mp4_media_parser.cc', 'mp4_media_parser.h', 'mp4_muxer.cc', 'mp4_muxer.h', - 'mp4_segmenter.cc', - 'mp4_segmenter.h', - 'mp4_vod_segmenter.cc', - 'mp4_vod_segmenter.h', + 'multi_segment_segmenter.cc', + 'multi_segment_segmenter.h', 'offset_byte_queue.cc', 'offset_byte_queue.h', 'rcheck.h', + 'segmenter.cc', + 'segmenter.h', + 'single_segment_segmenter.cc', + 'single_segment_segmenter.h', 'sync_sample_iterator.cc', 'sync_sample_iterator.h', 'track_run_iterator.cc', diff --git a/media/mp4/mp4_muxer.cc b/media/mp4/mp4_muxer.cc index 4c90907b80..f02bc930ae 100644 --- a/media/mp4/mp4_muxer.cc +++ b/media/mp4/mp4_muxer.cc @@ -19,8 +19,8 @@ #include "media/mp4/box_definitions.h" #include "media/mp4/es_descriptor.h" #include "media/mp4/fourccs.h" -#include "media/mp4/mp4_general_segmenter.h" -#include "media/mp4/mp4_vod_segmenter.h" +#include "media/mp4/multi_segment_segmenter.h" +#include "media/mp4/single_segment_segmenter.h" namespace { // The version of cenc implemented here. CENC 4. @@ -99,10 +99,11 @@ Status MP4Muxer::Initialize() { } if (options().single_segment) { - segmenter_.reset(new MP4VODSegmenter(options(), ftyp.Pass(), moov.Pass())); + segmenter_.reset( + new SingleSegmentSegmenter(options(), ftyp.Pass(), moov.Pass())); } else { segmenter_.reset( - new MP4GeneralSegmenter(options(), ftyp.Pass(), moov.Pass())); + new MultiSegmentSegmenter(options(), ftyp.Pass(), moov.Pass())); } Status segmenter_initialized = segmenter_->Initialize( diff --git a/media/mp4/mp4_muxer.h b/media/mp4/mp4_muxer.h index 22542912e8..b7db99ff66 100644 --- a/media/mp4/mp4_muxer.h +++ b/media/mp4/mp4_muxer.h @@ -20,7 +20,7 @@ class VideoStreamInfo; namespace mp4 { -class MP4Segmenter; +class Segmenter; struct ProtectionSchemeInfo; struct ProtectionSystemSpecificHeader; @@ -79,7 +79,7 @@ class MP4Muxer : public Muxer { // Get time in seconds since midnight, Jan. 1, 1904, in UTC Time. uint64 IsoTimeNow(); - scoped_ptr segmenter_; + scoped_ptr segmenter_; DISALLOW_COPY_AND_ASSIGN(MP4Muxer); }; diff --git a/media/mp4/mp4_general_segmenter.cc b/media/mp4/multi_segment_segmenter.cc similarity index 83% rename from media/mp4/mp4_general_segmenter.cc rename to media/mp4/multi_segment_segmenter.cc index cfd7d62c3c..74179937f5 100644 --- a/media/mp4/mp4_general_segmenter.cc +++ b/media/mp4/multi_segment_segmenter.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "media/mp4/mp4_general_segmenter.h" +#include "media/mp4/multi_segment_segmenter.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" @@ -17,25 +17,25 @@ namespace media { namespace mp4 { -MP4GeneralSegmenter::MP4GeneralSegmenter(const MuxerOptions& options, - scoped_ptr ftyp, - scoped_ptr moov) - : MP4Segmenter(options, ftyp.Pass(), moov.Pass()), +MultiSegmentSegmenter::MultiSegmentSegmenter(const MuxerOptions& options, + scoped_ptr ftyp, + scoped_ptr moov) + : Segmenter(options, ftyp.Pass(), moov.Pass()), styp_(new SegmentType), num_segments_(0) { // Use the same brands for styp as ftyp. - styp_->major_brand = MP4Segmenter::ftyp()->major_brand; - styp_->compatible_brands = MP4Segmenter::ftyp()->compatible_brands; + styp_->major_brand = Segmenter::ftyp()->major_brand; + styp_->compatible_brands = Segmenter::ftyp()->compatible_brands; } -MP4GeneralSegmenter::~MP4GeneralSegmenter() {} +MultiSegmentSegmenter::~MultiSegmentSegmenter() {} -Status MP4GeneralSegmenter::Initialize( +Status MultiSegmentSegmenter::Initialize( EncryptorSource* encryptor_source, double clear_lead_in_seconds, const std::vector& streams) { - Status status = MP4Segmenter::Initialize( - encryptor_source, clear_lead_in_seconds, streams); + Status status = + Segmenter::Initialize(encryptor_source, clear_lead_in_seconds, streams); if (!status.ok()) return status; @@ -58,19 +58,19 @@ Status MP4GeneralSegmenter::Initialize( return status; } -bool MP4GeneralSegmenter::GetInitRange(size_t* offset, size_t* size) { - DLOG(INFO) << "MP4GeneralSegmenter outputs init segment: " +bool MultiSegmentSegmenter::GetInitRange(size_t* offset, size_t* size) { + DLOG(INFO) << "MultiSegmentSegmenter outputs init segment: " << options().output_file_name; return false; } -bool MP4GeneralSegmenter::GetIndexRange(size_t* offset, size_t* size) { - DLOG(INFO) << "MP4GeneralSegmenter does not have index range."; +bool MultiSegmentSegmenter::GetIndexRange(size_t* offset, size_t* size) { + DLOG(INFO) << "MultiSegmentSegmenter does not have index range."; return false; } -Status MP4GeneralSegmenter::FinalizeSegment() { - Status status = MP4Segmenter::FinalizeSegment(); +Status MultiSegmentSegmenter::FinalizeSegment() { + Status status = Segmenter::FinalizeSegment(); if (!status.ok()) return status; @@ -134,7 +134,7 @@ Status MP4GeneralSegmenter::FinalizeSegment() { return WriteSegment(); } -Status MP4GeneralSegmenter::WriteSegment() { +Status MultiSegmentSegmenter::WriteSegment() { DCHECK(sidx()); DCHECK(fragment_buffer()); DCHECK(styp_); diff --git a/media/mp4/mp4_general_segmenter.h b/media/mp4/multi_segment_segmenter.h similarity index 75% rename from media/mp4/mp4_general_segmenter.h rename to media/mp4/multi_segment_segmenter.h index af8c0843d9..bdb2ac8656 100644 --- a/media/mp4/mp4_general_segmenter.h +++ b/media/mp4/multi_segment_segmenter.h @@ -4,10 +4,10 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef MEDIA_MP4_MP4_GENERAL_SEGMENTER_H_ -#define MEDIA_MP4_MP4_GENERAL_SEGMENTER_H_ +#ifndef MEDIA_MP4_MULTI_SEGMENT_SEGMENTER_H_ +#define MEDIA_MP4_MULTI_SEGMENT_SEGMENTER_H_ -#include "media/mp4/mp4_segmenter.h" +#include "media/mp4/segmenter.h" namespace media { namespace mp4 { @@ -21,20 +21,20 @@ struct SegmentType; /// contain one or many fragments with fragment duration defined by @b /// MuxerOptions.fragment_duration. The actual segment or fragment duration /// may not match the requested duration exactly, but will be approximated. -/// That is, the segmenter tries to end segment/fragment at the first sample +/// That is, the Segmenter tries to end segment/fragment at the first sample /// with overall segment/fragment duration not smaller than defined duration /// and yet meet SAP requirements. The generated segments are written to files /// defined by @b MuxerOptions.segment_template if specified; otherwise, /// the segments are appended to the main output file specified by @b /// MuxerOptions.output_file_name. -class MP4GeneralSegmenter : public MP4Segmenter { +class MultiSegmentSegmenter : public Segmenter { public: - MP4GeneralSegmenter(const MuxerOptions& options, - scoped_ptr ftyp, - scoped_ptr moov); - virtual ~MP4GeneralSegmenter(); + MultiSegmentSegmenter(const MuxerOptions& options, + scoped_ptr ftyp, + scoped_ptr moov); + virtual ~MultiSegmentSegmenter(); - /// @name MP4Segmenter implementation overrides. + /// @name Segmenter implementation overrides. /// @{ virtual Status Initialize(EncryptorSource* encryptor_source, double clear_lead_in_seconds, @@ -54,10 +54,10 @@ class MP4GeneralSegmenter : public MP4Segmenter { scoped_ptr styp_; uint32 num_segments_; - DISALLOW_COPY_AND_ASSIGN(MP4GeneralSegmenter); + DISALLOW_COPY_AND_ASSIGN(MultiSegmentSegmenter); }; } // namespace mp4 } // namespace media -#endif // MEDIA_MP4_MP4_GENERAL_SEGMENTER_H_ +#endif // MEDIA_MP4_MULTI_SEGMENT_SEGMENTER_H_ diff --git a/media/mp4/mp4_segmenter.cc b/media/mp4/segmenter.cc similarity index 83% rename from media/mp4/mp4_segmenter.cc rename to media/mp4/segmenter.cc index edadcf9f0a..807fb16ad2 100644 --- a/media/mp4/mp4_segmenter.cc +++ b/media/mp4/segmenter.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "media/mp4/mp4_segmenter.h" +#include "media/mp4/segmenter.h" #include @@ -16,7 +16,7 @@ #include "media/base/muxer_options.h" #include "media/base/video_stream_info.h" #include "media/mp4/box_definitions.h" -#include "media/mp4/mp4_fragmenter.h" +#include "media/mp4/fragmenter.h" namespace { uint64 Rescale(uint64 time_in_old_scale, uint32 old_scale, uint32 new_scale) { @@ -27,9 +27,9 @@ uint64 Rescale(uint64 time_in_old_scale, uint32 old_scale, uint32 new_scale) { namespace media { namespace mp4 { -MP4Segmenter::MP4Segmenter(const MuxerOptions& options, - scoped_ptr ftyp, - scoped_ptr moov) +Segmenter::Segmenter(const MuxerOptions& options, + scoped_ptr ftyp, + scoped_ptr moov) : options_(options), ftyp_(ftyp.Pass()), moov_(moov.Pass()), @@ -39,11 +39,11 @@ MP4Segmenter::MP4Segmenter(const MuxerOptions& options, segment_initialized_(false), end_of_segment_(false) {} -MP4Segmenter::~MP4Segmenter() { STLDeleteElements(&fragmenters_); } +Segmenter::~Segmenter() { STLDeleteElements(&fragmenters_); } -Status MP4Segmenter::Initialize(EncryptorSource* encryptor_source, - double clear_lead_in_seconds, - const std::vector& streams) { +Status Segmenter::Initialize(EncryptorSource* encryptor_source, + double clear_lead_in_seconds, + const std::vector& streams) { DCHECK_LT(0u, streams.size()); moof_->header.sequence_number = 0; @@ -68,7 +68,7 @@ Status MP4Segmenter::Initialize(EncryptorSource* encryptor_source, if (!encryptor) return Status(error::MUXER_FAILURE, "Failed to create the encryptor."); } - fragmenters_[i] = new MP4Fragmenter( + fragmenters_[i] = new Fragmenter( &moof_->tracks[i], encryptor.Pass(), clear_lead_in_seconds * streams[i]->info()->time_scale(), @@ -87,9 +87,9 @@ Status MP4Segmenter::Initialize(EncryptorSource* encryptor_source, return Status::OK; } -Status MP4Segmenter::Finalize() { +Status Segmenter::Finalize() { end_of_segment_ = true; - for (std::vector::iterator it = fragmenters_.begin(); + for (std::vector::iterator it = fragmenters_.begin(); it != fragmenters_.end(); ++it) { Status status = FinalizeFragment(*it); @@ -113,13 +113,13 @@ Status MP4Segmenter::Finalize() { return Status::OK; } -Status MP4Segmenter::AddSample(const MediaStream* stream, - scoped_refptr sample) { +Status Segmenter::AddSample(const MediaStream* stream, + scoped_refptr sample) { // Find the fragmenter for this stream. DCHECK(stream); DCHECK(stream_map_.find(stream) != stream_map_.end()); uint32 stream_id = stream_map_[stream]; - MP4Fragmenter* fragmenter = fragmenters_[stream_id]; + Fragmenter* fragmenter = fragmenters_[stream_id]; // Set default sample duration if it has not been set yet. if (moov_->extends.tracks[stream_id].default_sample_duration == 0) { @@ -168,11 +168,11 @@ Status MP4Segmenter::AddSample(const MediaStream* stream, return Status::OK; } -uint32 MP4Segmenter::GetReferenceTimeScale() const { +uint32 Segmenter::GetReferenceTimeScale() const { return moov_->header.timescale; } -double MP4Segmenter::GetDuration() const { +double Segmenter::GetDuration() const { if (moov_->header.timescale == 0) { // Handling the case where this is not properly initialized. return 0.0; @@ -181,7 +181,7 @@ double MP4Segmenter::GetDuration() const { return static_cast(moov_->header.duration) / moov_->header.timescale; } -void MP4Segmenter::InitializeSegment() { +void Segmenter::InitializeSegment() { sidx_->references.clear(); end_of_segment_ = false; std::vector::iterator it = segment_durations_.begin(); @@ -189,30 +189,30 @@ void MP4Segmenter::InitializeSegment() { *it = 0; } -Status MP4Segmenter::FinalizeSegment() { +Status Segmenter::FinalizeSegment() { segment_initialized_ = false; return Status::OK; } -uint32 MP4Segmenter::GetReferenceStreamId() { +uint32 Segmenter::GetReferenceStreamId() { DCHECK(sidx_); return sidx_->reference_id - 1; } -void MP4Segmenter::InitializeFragments() { +void Segmenter::InitializeFragments() { ++moof_->header.sequence_number; - for (std::vector::iterator it = fragmenters_.begin(); + for (std::vector::iterator it = fragmenters_.begin(); it != fragmenters_.end(); ++it) { (*it)->InitializeFragment(); } } -Status MP4Segmenter::FinalizeFragment(MP4Fragmenter* fragmenter) { +Status Segmenter::FinalizeFragment(Fragmenter* fragmenter) { fragmenter->FinalizeFragment(); // Check if all tracks are ready for fragmentation. - for (std::vector::iterator it = fragmenters_.begin(); + for (std::vector::iterator it = fragmenters_.begin(); it != fragmenters_.end(); ++it) { if (!(*it)->fragment_finalized()) @@ -225,7 +225,7 @@ Status MP4Segmenter::FinalizeFragment(MP4Fragmenter* fragmenter) { uint64 base = moof_->ComputeSize() + mdat.ComputeSize(); for (uint i = 0; i < moof_->tracks.size(); ++i) { TrackFragment& traf = moof_->tracks[i]; - MP4Fragmenter* fragmenter = fragmenters_[i]; + Fragmenter* fragmenter = fragmenters_[i]; if (fragmenter->aux_data()->Size() > 0) { traf.auxiliary_offset.offsets[0] += base; base += fragmenter->aux_data()->Size(); @@ -244,7 +244,7 @@ Status MP4Segmenter::FinalizeFragment(MP4Fragmenter* fragmenter) { moof_->Write(fragment_buffer_.get()); for (uint i = 0; i < moof_->tracks.size(); ++i) { - MP4Fragmenter* fragmenter = fragmenters_[i]; + Fragmenter* fragmenter = fragmenters_[i]; mdat.data_size = fragmenter->aux_data()->Size() + fragmenter->data()->Size(); mdat.Write(fragment_buffer_.get()); diff --git a/media/mp4/mp4_segmenter.h b/media/mp4/segmenter.h similarity index 74% rename from media/mp4/mp4_segmenter.h rename to media/mp4/segmenter.h index f82a0a91bf..5089f5c46a 100644 --- a/media/mp4/mp4_segmenter.h +++ b/media/mp4/segmenter.h @@ -4,8 +4,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef MEDIA_MP4_MP4_SEGMENTER_H_ -#define MEDIA_MP4_MP4_SEGMENTER_H_ +#ifndef MEDIA_MP4_SEGMENTER_H_ +#define MEDIA_MP4_SEGMENTER_H_ #include #include @@ -25,25 +25,25 @@ class MediaStream; namespace mp4 { -class MP4Fragmenter; +class Fragmenter; struct FileType; struct Movie; struct MovieFragment; struct SegmentIndex; -/// This class defines the MP4 Segmenter which is responsible for organizing -/// MP4 fragments into segments/subsegments and package them 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. -class MP4Segmenter { +/// 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 { public: - MP4Segmenter(const MuxerOptions& options, - scoped_ptr ftyp, - scoped_ptr moov); - virtual ~MP4Segmenter(); + Segmenter(const MuxerOptions& options, + scoped_ptr ftyp, + scoped_ptr moov); + virtual ~Segmenter(); /// Initialize the segmenter. /// Calling other public methods of this class without this method returning @@ -86,7 +86,7 @@ class MP4Segmenter { private: void InitializeFragments(); - Status FinalizeFragment(MP4Fragmenter* fragment); + Status FinalizeFragment(Fragmenter* fragment); const MuxerOptions& options_; scoped_ptr ftyp_; @@ -94,16 +94,16 @@ class MP4Segmenter { scoped_ptr moof_; scoped_ptr fragment_buffer_; scoped_ptr sidx_; - std::vector fragmenters_; + std::vector fragmenters_; std::vector segment_durations_; std::map stream_map_; bool segment_initialized_; bool end_of_segment_; - DISALLOW_COPY_AND_ASSIGN(MP4Segmenter); + DISALLOW_COPY_AND_ASSIGN(Segmenter); }; } // namespace mp4 } // namespace media -#endif // MEDIA_MP4_MP4_SEGMENTER_H_ +#endif // MEDIA_MP4_SEGMENTER_H_ diff --git a/media/mp4/mp4_vod_segmenter.cc b/media/mp4/single_segment_segmenter.cc similarity index 83% rename from media/mp4/mp4_vod_segmenter.cc rename to media/mp4/single_segment_segmenter.cc index 39e06fb84e..21176e8264 100644 --- a/media/mp4/mp4_vod_segmenter.cc +++ b/media/mp4/single_segment_segmenter.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "media/mp4/mp4_vod_segmenter.h" +#include "media/mp4/single_segment_segmenter.h" #include "media/base/buffer_writer.h" #include "media/base/media_stream.h" @@ -15,17 +15,18 @@ namespace media { namespace mp4 { -MP4VODSegmenter::MP4VODSegmenter(const MuxerOptions& options, - scoped_ptr ftyp, - scoped_ptr moov) - : MP4Segmenter(options, ftyp.Pass(), moov.Pass()) {} -MP4VODSegmenter::~MP4VODSegmenter() {} +SingleSegmentSegmenter::SingleSegmentSegmenter(const MuxerOptions& options, + scoped_ptr ftyp, + scoped_ptr moov) + : Segmenter(options, ftyp.Pass(), moov.Pass()) {} +SingleSegmentSegmenter::~SingleSegmentSegmenter() {} -Status MP4VODSegmenter::Initialize(EncryptorSource* encryptor_source, - double clear_lead_in_seconds, - const std::vector& streams) { - Status status = MP4Segmenter::Initialize( - encryptor_source, clear_lead_in_seconds, streams); +Status SingleSegmentSegmenter::Initialize( + EncryptorSource* encryptor_source, + double clear_lead_in_seconds, + const std::vector& streams) { + Status status = + Segmenter::Initialize(encryptor_source, clear_lead_in_seconds, streams); if (!status.ok()) return status; temp_file_.reset(File::Open(options().temp_file_name.c_str(), "w")); @@ -36,8 +37,8 @@ Status MP4VODSegmenter::Initialize(EncryptorSource* encryptor_source, return Status::OK; } -Status MP4VODSegmenter::Finalize() { - Status status = MP4Segmenter::Finalize(); +Status SingleSegmentSegmenter::Finalize() { + Status status = Segmenter::Finalize(); if (!status.ok()) return status; @@ -93,14 +94,14 @@ Status MP4VODSegmenter::Finalize() { return Status::OK; } -bool MP4VODSegmenter::GetInitRange(size_t* offset, size_t* size) { +bool SingleSegmentSegmenter::GetInitRange(size_t* offset, size_t* size) { // In Finalize, ftyp and moov gets written first so offset must be 0. *offset = 0; *size = ftyp()->ComputeSize() + moov()->ComputeSize(); return true; } -bool MP4VODSegmenter::GetIndexRange(size_t* offset, size_t* size) { +bool SingleSegmentSegmenter::GetIndexRange(size_t* offset, size_t* size) { // Index range is right after init range so the offset must be the size of // ftyp and moov. *offset = ftyp()->ComputeSize() + moov()->ComputeSize(); @@ -108,8 +109,8 @@ bool MP4VODSegmenter::GetIndexRange(size_t* offset, size_t* size) { return true; } -Status MP4VODSegmenter::FinalizeSegment() { - Status status = MP4Segmenter::FinalizeSegment(); +Status SingleSegmentSegmenter::FinalizeSegment() { + Status status = Segmenter::FinalizeSegment(); if (!status.ok()) return status; diff --git a/media/mp4/mp4_vod_segmenter.h b/media/mp4/single_segment_segmenter.h similarity index 70% rename from media/mp4/mp4_vod_segmenter.h rename to media/mp4/single_segment_segmenter.h index 3150185f1f..03dc578835 100644 --- a/media/mp4/mp4_vod_segmenter.h +++ b/media/mp4/single_segment_segmenter.h @@ -4,11 +4,11 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef MEDIA_MP4_MP4_VOD_SEGMENTER_H_ -#define MEDIA_MP4_MP4_VOD_SEGMENTER_H_ +#ifndef MEDIA_MP4_SINGLE_SEGMENT_SEGMENTER_H_ +#define MEDIA_MP4_SINGLE_SEGMENT_SEGMENTER_H_ #include "media/file/file_closer.h" -#include "media/mp4/mp4_segmenter.h" +#include "media/mp4/segmenter.h" namespace media { namespace mp4 { @@ -20,18 +20,18 @@ namespace mp4 { /// or many fragments with fragment duration defined by @b /// MuxerOptions.fragment_duration. The actual subsegment or fragment duration /// may not match the requested duration exactly, but will be approximated. That -/// is, the segmenter tries to end subsegment/fragment at the first sample with +/// is, the Segmenter tries to end subsegment/fragment at the first sample with /// overall subsegment/fragment duration not smaller than defined duration and -/// yet meet SAP requirements. VOD segmenter ignores @b +/// yet meet SAP requirements. SingleSegmentSegmenter ignores @b /// MuxerOptions.num_subsegments_per_sidx. -class MP4VODSegmenter : public MP4Segmenter { +class SingleSegmentSegmenter : public Segmenter { public: - MP4VODSegmenter(const MuxerOptions& options, - scoped_ptr ftyp, - scoped_ptr moov); - virtual ~MP4VODSegmenter(); + SingleSegmentSegmenter(const MuxerOptions& options, + scoped_ptr ftyp, + scoped_ptr moov); + virtual ~SingleSegmentSegmenter(); - /// @name MP4Segmenter implementation overrides. + /// @name Segmenter implementation overrides. /// @{ virtual Status Initialize(EncryptorSource* encryptor_source, double clear_lead_in_seconds, @@ -49,10 +49,10 @@ class MP4VODSegmenter : public MP4Segmenter { scoped_ptr vod_sidx_; scoped_ptr temp_file_; - DISALLOW_COPY_AND_ASSIGN(MP4VODSegmenter); + DISALLOW_COPY_AND_ASSIGN(SingleSegmentSegmenter); }; } // namespace mp4 } // namespace media -#endif // MEDIA_MP4_MP4_VOD_SEGMENTER_H_ +#endif // MEDIA_MP4_SINGLE_SEGMENT_SEGMENTER_H_ diff --git a/media/test/packager_test.cc b/media/test/packager_test.cc index 6171dd41b0..958db235be 100644 --- a/media/test/packager_test.cc +++ b/media/test/packager_test.cc @@ -252,7 +252,7 @@ TEST_P(PackagerTest, MP4MuxerSingleSegmentUnencryptedSeparateAudioVideo) { EXPECT_TRUE(ContentsEqual(kOutputAudio, kOutputAudio2)); } -TEST_P(PackagerTest, MP4MuxerMultipleSegmentsUnencrypted) { +TEST_P(PackagerTest, MP4MuxerMultiSegmentsUnencrypted) { ASSERT_NO_FATAL_FAILURE(Remux(GetParam(), kOutputVideo2, kOutputNone,