diff --git a/media/event/vod_media_info_dump_muxer_listener.cc b/media/event/vod_media_info_dump_muxer_listener.cc index eb1e379656..604ce2543b 100644 --- a/media/event/vod_media_info_dump_muxer_listener.cc +++ b/media/event/vod_media_info_dump_muxer_listener.cc @@ -1,6 +1,7 @@ #include "media/event/vod_media_info_dump_muxer_listener.h" #include "base/logging.h" +#include "media/base/muxer_options.h" #include "media/base/stream_info.h" #include "media/event/vod_muxer_listener_internal.h" #include "media/file/file.h" @@ -25,7 +26,9 @@ bool IsAnyStreamEncrypted(const std::vector& stream_infos) { } // namespace VodMediaInfoDumpMuxerListener::VodMediaInfoDumpMuxerListener(File* output_file) - : file_(output_file) {} + : file_(output_file), + reference_time_scale_(0), + container_type_(kContainerUnknown) {} VodMediaInfoDumpMuxerListener::~VodMediaInfoDumpMuxerListener() {} @@ -39,8 +42,9 @@ void VodMediaInfoDumpMuxerListener::OnMediaStart( const std::vector& stream_infos, uint32 time_scale, ContainerType container_type) { - DLOG(INFO) - << "VodMediaInfoDumpMuxerListener does not care about OnMediaStart."; + muxer_options_ = muxer_options; + reference_time_scale_ = time_scale; + container_type_ = container_type; } void VodMediaInfoDumpMuxerListener::OnMediaEnd( @@ -54,7 +58,8 @@ void VodMediaInfoDumpMuxerListener::OnMediaEnd( float duration_seconds, uint64 file_size) { MediaInfo media_info; - if (!internal::GenerateMediaInfo(stream_infos, + if (!internal::GenerateMediaInfo(muxer_options_, + stream_infos, has_init_range, init_range_start, init_range_end, @@ -63,6 +68,8 @@ void VodMediaInfoDumpMuxerListener::OnMediaEnd( index_range_end, duration_seconds, file_size, + reference_time_scale_, + container_type_, &media_info)) { LOG(ERROR) << "Failed to generate MediaInfo from input."; return; diff --git a/media/event/vod_media_info_dump_muxer_listener.h b/media/event/vod_media_info_dump_muxer_listener.h index d5ea6fa02a..b527b58ac2 100644 --- a/media/event/vod_media_info_dump_muxer_listener.h +++ b/media/event/vod_media_info_dump_muxer_listener.h @@ -8,6 +8,7 @@ #include #include "base/compiler_specific.h" +#include "media/base/muxer_options.h" #include "media/event/muxer_listener.h" namespace dash_packager { @@ -17,7 +18,6 @@ class MediaInfo; namespace media { class File; -class MuxerOptions; namespace event { @@ -58,6 +58,9 @@ class VodMediaInfoDumpMuxerListener : public MuxerListener { File* file_; std::string scheme_id_uri_; + MuxerOptions muxer_options_; + uint32 reference_time_scale_; + ContainerType container_type_; DISALLOW_COPY_AND_ASSIGN(VodMediaInfoDumpMuxerListener); }; diff --git a/media/event/vod_mpd_notify_muxer_listener.cc b/media/event/vod_mpd_notify_muxer_listener.cc index a9708a5086..de91a7f1e8 100644 --- a/media/event/vod_mpd_notify_muxer_listener.cc +++ b/media/event/vod_mpd_notify_muxer_listener.cc @@ -14,7 +14,9 @@ namespace event { VodMpdNotifyMuxerListener::VodMpdNotifyMuxerListener( dash_packager::MpdNotifier* mpd_notifier) - : mpd_notifier_(mpd_notifier) { + : mpd_notifier_(mpd_notifier), + reference_time_scale_(0), + container_type_(kContainerUnknown) { DCHECK(mpd_notifier); } @@ -24,7 +26,11 @@ void VodMpdNotifyMuxerListener::OnMediaStart( const MuxerOptions& muxer_options, const std::vector& stream_infos, uint32 time_scale, - ContainerType container_type) {} + ContainerType container_type) { + muxer_options_ = muxer_options; + reference_time_scale_ = time_scale; + container_type_ = container_type; +} void VodMpdNotifyMuxerListener::OnMediaEnd( const std::vector& stream_infos, @@ -37,7 +43,8 @@ void VodMpdNotifyMuxerListener::OnMediaEnd( float duration_seconds, uint64 file_size) { dash_packager::MediaInfo media_info; - if (!internal::GenerateMediaInfo(stream_infos, + if (!internal::GenerateMediaInfo(muxer_options_, + stream_infos, has_init_range, init_range_start, init_range_end, @@ -46,6 +53,8 @@ void VodMpdNotifyMuxerListener::OnMediaEnd( index_range_end, duration_seconds, file_size, + reference_time_scale_, + container_type_, &media_info)) { LOG(ERROR) << "Failed to generate MediaInfo from input."; return; diff --git a/media/event/vod_mpd_notify_muxer_listener.h b/media/event/vod_mpd_notify_muxer_listener.h index bdb2e940c0..d5ee5bb9fd 100644 --- a/media/event/vod_mpd_notify_muxer_listener.h +++ b/media/event/vod_mpd_notify_muxer_listener.h @@ -5,6 +5,7 @@ #include #include "base/compiler_specific.h" +#include "media/base/muxer_options.h" #include "media/event/muxer_listener.h" namespace dash_packager { @@ -43,6 +44,9 @@ class VodMpdNotifyMuxerListener : public MuxerListener { private: dash_packager::MpdNotifier* const mpd_notifier_; + MuxerOptions muxer_options_; + uint32 reference_time_scale_; + ContainerType container_type_; DISALLOW_COPY_AND_ASSIGN(VodMpdNotifyMuxerListener); }; diff --git a/media/event/vod_muxer_listener_internal.cc b/media/event/vod_muxer_listener_internal.cc index bec8037551..110734e395 100644 --- a/media/event/vod_muxer_listener_internal.cc +++ b/media/event/vod_muxer_listener_internal.cc @@ -4,6 +4,7 @@ #include "base/logging.h" #include "media/base/audio_stream_info.h" +#include "media/base/muxer_options.h" #include "media/base/video_stream_info.h" #include "mpd/base/media_info.pb.h" #include "mpd/base/mpd_notifier.h" @@ -36,23 +37,13 @@ void SetRange(uint64 begin, uint64 end, Range* range) { range->set_end(end); } -void SetMediaInfoCommonInfo(bool has_init_range, - uint64 init_range_start, - uint64 init_range_end, - bool has_index_range, - uint64 index_range_start, - uint64 index_range_end, - float duration_seconds, - uint64 file_size, - MediaInfo* media_info) { - DCHECK(media_info); - DCHECK_GT(file_size, 0); - DCHECK_GT(duration_seconds, 0.0f); - - media_info->set_media_duration_seconds(duration_seconds); - media_info->set_bandwidth( - EstimateRequiredBandwidth(file_size, duration_seconds)); - +void SetMediaInfoRanges(bool has_init_range, + uint64 init_range_start, + uint64 init_range_end, + bool has_index_range, + uint64 index_range_start, + uint64 index_range_end, + MediaInfo* media_info) { if (has_init_range) { SetRange( init_range_start, init_range_end, media_info->mutable_init_range()); @@ -64,6 +55,44 @@ void SetMediaInfoCommonInfo(bool has_init_range, } } +void SetMediaInfoContainerType(MuxerListener::ContainerType container_type, + MediaInfo* media_info) { + DCHECK(media_info); + switch (container_type) { + case MuxerListener::kContainerUnknown: + media_info->set_container_type(MediaInfo::CONTAINER_UNKNOWN); + break; + case MuxerListener::kContainerMp4: + media_info->set_container_type(MediaInfo::CONTAINER_MP4); + break; + case MuxerListener::kContainerMpeg2ts: + media_info->set_container_type(MediaInfo::CONTAINER_MPEG2_TS); + break; + case MuxerListener::kContainerWebM: + media_info->set_container_type(MediaInfo::CONTAINER_WEBM); + break; + default: + NOTREACHED() << "Unknown container type " << container_type; + } +} + +void SetMediaInfoCommonInfo(float duration_seconds, + uint64 file_size, + uint32 reference_time_scale, + MuxerListener::ContainerType container_type, + MediaInfo* media_info) { + DCHECK(media_info); + DCHECK_GT(file_size, 0); + DCHECK_GT(duration_seconds, 0.0f); + + media_info->set_media_duration_seconds(duration_seconds); + media_info->set_bandwidth( + EstimateRequiredBandwidth(file_size, duration_seconds)); + + media_info->set_reference_time_scale(reference_time_scale); + SetMediaInfoContainerType(container_type, media_info); +} + void AddVideoInfo(const VideoStreamInfo* video_stream_info, MediaInfo* media_info) { DCHECK(video_stream_info); @@ -124,9 +153,16 @@ void SetMediaInfoStreamInfo(const std::vector& stream_infos, } } +void SetMediaInfoMuxerOptions(const MuxerOptions& muxer_options, + MediaInfo* media_info) { + DCHECK(media_info); + media_info->set_media_file_name(muxer_options.output_file_name); +} + } // namespace -bool GenerateMediaInfo(const std::vector& stream_infos, +bool GenerateMediaInfo(const MuxerOptions& muxer_options, + const std::vector& stream_infos, bool has_init_range, uint64 init_range_start, uint64 init_range_end, @@ -135,10 +171,12 @@ bool GenerateMediaInfo(const std::vector& stream_infos, uint64 index_range_end, float duration_seconds, uint64 file_size, + uint32 reference_time_scale, + MuxerListener::ContainerType container_type, MediaInfo* media_info) { DCHECK(media_info); if (file_size == 0) { - // TODO(rkurowia); bandwidth is a required field for MPD. But without the + // TODO(rkuroiwa): bandwidth is a required field for MPD. But without the // file size, AFAIK there's not much I can do. Fail silently? LOG(ERROR) << "File size not specified."; return false; @@ -150,14 +188,18 @@ bool GenerateMediaInfo(const std::vector& stream_infos, return false;; } - SetMediaInfoCommonInfo(has_init_range, - init_range_start, - init_range_end, - has_index_range, - index_range_start, - index_range_end, - duration_seconds, + SetMediaInfoMuxerOptions(muxer_options, media_info); + SetMediaInfoRanges(has_init_range, + init_range_start, + init_range_end, + has_index_range, + index_range_start, + index_range_end, + media_info); + SetMediaInfoCommonInfo(duration_seconds, file_size, + reference_time_scale, + container_type, media_info); SetMediaInfoStreamInfo(stream_infos, media_info); return true; diff --git a/media/event/vod_muxer_listener_internal.h b/media/event/vod_muxer_listener_internal.h index dc6ec49e38..5b85be2e0a 100644 --- a/media/event/vod_muxer_listener_internal.h +++ b/media/event/vod_muxer_listener_internal.h @@ -4,6 +4,7 @@ #include #include "base/basictypes.h" +#include "media/event/muxer_listener.h" namespace dash_packager { class MediaInfo; @@ -11,6 +12,7 @@ class MediaInfo; namespace media { +class MuxerOptions; class StreamInfo; namespace event { @@ -18,7 +20,8 @@ namespace internal { // On success fill |media_info| with input data and return true, otherwise // return false. -bool GenerateMediaInfo(const std::vector& stream_infos, +bool GenerateMediaInfo(const MuxerOptions& muxer_options, + const std::vector& stream_infos, bool has_init_range, uint64 init_range_start, uint64 init_range_end, @@ -27,6 +30,8 @@ bool GenerateMediaInfo(const std::vector& stream_infos, uint64 index_range_end, float duration_seconds, uint64 file_size, + uint32 reference_time_scale_, + MuxerListener::ContainerType container_type, dash_packager::MediaInfo* media_info); } // namespace internal