Remove size parameter in OnMediaEnd
Derive file size from media ranges instead. Also fix subsegment range reporting for WebM (internal variable, no output affected). Change-Id: I5f8152dff4c2cd5fbae5550992b86a669e278f7b
This commit is contained in:
parent
8d2b87c773
commit
61c58724ec
|
@ -116,8 +116,7 @@ void HlsNotifyMuxerListener::OnMediaStart(const MuxerOptions& muxer_options,
|
|||
void HlsNotifyMuxerListener::OnSampleDurationReady(uint32_t sample_duration) {}
|
||||
|
||||
void HlsNotifyMuxerListener::OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) {
|
||||
float duration_seconds) {
|
||||
// TODO(kqyang): Should we just Flush here to avoid calling Flush explicitly?
|
||||
// Don't flush the notifier here. Flushing here would write all the playlists
|
||||
// before all Media Playlists are read. Which could cause problems
|
||||
|
|
|
@ -54,8 +54,7 @@ class HlsNotifyMuxerListener : public MuxerListener {
|
|||
ContainerType container_type) override;
|
||||
void OnSampleDurationReady(uint32_t sample_duration) override;
|
||||
void OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) override;
|
||||
float duration_seconds) override;
|
||||
void OnNewSegment(const std::string& file_name,
|
||||
uint64_t start_time,
|
||||
uint64_t duration,
|
||||
|
|
|
@ -319,7 +319,7 @@ TEST_F(HlsNotifyMuxerListenerTest, OnSampleDurationReady) {
|
|||
// Make sure it doesn't crash.
|
||||
TEST_F(HlsNotifyMuxerListenerTest, OnMediaEnd) {
|
||||
// None of these values matter, they are not used.
|
||||
listener_.OnMediaEnd(MuxerListener::MediaRanges(), 0, 0);
|
||||
listener_.OnMediaEnd(MuxerListener::MediaRanges(), 0);
|
||||
}
|
||||
|
||||
TEST_F(HlsNotifyMuxerListenerTest, OnNewSegment) {
|
||||
|
@ -383,7 +383,7 @@ TEST_F(HlsNotifyMuxerListenerTest, NoSegmentTemplateOnMediaEnd) {
|
|||
EXPECT_CALL(mock_notifier_,
|
||||
NotifyNewSegment(_, StrEq("filename.mp4"), kStartTime,
|
||||
kDuration, kSegmentStartOffset, kFileSize));
|
||||
listener_.OnMediaEnd(ranges, 200000, 98234328);
|
||||
listener_.OnMediaEnd(ranges, 200000);
|
||||
}
|
||||
|
||||
// Verify that when there is a mismatch in the number of calls to
|
||||
|
@ -435,7 +435,7 @@ TEST_F(HlsNotifyMuxerListenerTest,
|
|||
EXPECT_CALL(mock_notifier_,
|
||||
NotifyNewSegment(_, StrEq("filename.mp4"), kStartTime,
|
||||
kDuration, kSegmentStartOffset, kFileSize));
|
||||
listener_.OnMediaEnd(ranges, 200000, 98234328);
|
||||
listener_.OnMediaEnd(ranges, 200000);
|
||||
}
|
||||
|
||||
} // namespace media
|
||||
|
|
|
@ -13,8 +13,7 @@ MockMuxerListener::MockMuxerListener() {}
|
|||
MockMuxerListener::~MockMuxerListener() {}
|
||||
|
||||
void MockMuxerListener::OnMediaEnd(const MediaRanges& range,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) {
|
||||
float duration_seconds) {
|
||||
const bool has_init_range = static_cast<bool>(range.init_range);
|
||||
Range init_range = {};
|
||||
if (has_init_range) {
|
||||
|
@ -29,7 +28,7 @@ void MockMuxerListener::OnMediaEnd(const MediaRanges& range,
|
|||
OnMediaEndMock(has_init_range, init_range.start, init_range.end,
|
||||
has_index_range, index_range.start, index_range.end,
|
||||
!range.subsegment_ranges.empty(), range.subsegment_ranges,
|
||||
duration_seconds, file_size);
|
||||
duration_seconds);
|
||||
}
|
||||
|
||||
} // namespace media
|
||||
|
|
|
@ -40,7 +40,7 @@ class MockMuxerListener : public MuxerListener {
|
|||
|
||||
MOCK_METHOD1(OnSampleDurationReady, void(uint32_t sample_duration));
|
||||
|
||||
MOCK_METHOD10(OnMediaEndMock,
|
||||
MOCK_METHOD9(OnMediaEndMock,
|
||||
void(bool has_init_range,
|
||||
uint64_t init_range_start,
|
||||
uint64_t init_range_end,
|
||||
|
@ -49,14 +49,12 @@ class MockMuxerListener : public MuxerListener {
|
|||
uint64_t index_range_end,
|
||||
bool has_subsegment_ranges,
|
||||
const std::vector<Range> subsegment_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size));
|
||||
float duration_seconds));
|
||||
|
||||
// Windows 32 bit cannot mock MediaRanges because it has Optionals that use
|
||||
// memory alignment of 8 bytes. The compiler fails if it is mocked.
|
||||
void OnMediaEnd(const MediaRanges& range,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) override;
|
||||
float duration_seconds) override;
|
||||
|
||||
MOCK_METHOD4(OnNewSegment,
|
||||
void(const std::string& segment_name,
|
||||
|
|
|
@ -110,8 +110,7 @@ void MpdNotifyMuxerListener::OnSampleDurationReady(
|
|||
}
|
||||
|
||||
void MpdNotifyMuxerListener::OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) {
|
||||
float duration_seconds) {
|
||||
if (mpd_notifier_->dash_profile() == DashProfile::kLive) {
|
||||
DCHECK(subsegments_.empty());
|
||||
// TODO(kqyang): Set mpd duration to |duration_seconds|, which is more
|
||||
|
@ -122,7 +121,7 @@ void MpdNotifyMuxerListener::OnMediaEnd(const MediaRanges& media_ranges,
|
|||
}
|
||||
|
||||
DCHECK(media_info_);
|
||||
if (!internal::SetVodInformation(media_ranges, duration_seconds, file_size,
|
||||
if (!internal::SetVodInformation(media_ranges, duration_seconds,
|
||||
media_info_.get())) {
|
||||
LOG(ERROR) << "Failed to generate VOD information from input.";
|
||||
return;
|
||||
|
|
|
@ -46,8 +46,7 @@ class MpdNotifyMuxerListener : public MuxerListener {
|
|||
ContainerType container_type) override;
|
||||
void OnSampleDurationReady(uint32_t sample_duration) override;
|
||||
void OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) override;
|
||||
float duration_seconds) override;
|
||||
void OnNewSegment(const std::string& file_name,
|
||||
uint64_t start_time,
|
||||
uint64_t duration,
|
||||
|
|
|
@ -83,8 +83,7 @@ class MpdNotifyMuxerListenerTest : public ::testing::TestWithParam<MpdType> {
|
|||
|
||||
void FireOnMediaEndWithParams(const OnMediaEndParameters& params) {
|
||||
// On success, this writes the result to |temp_file_path_|.
|
||||
listener_->OnMediaEnd(params.media_ranges, params.duration_seconds,
|
||||
params.file_size);
|
||||
listener_->OnMediaEnd(params.media_ranges, params.duration_seconds);
|
||||
}
|
||||
|
||||
std::unique_ptr<MpdNotifyMuxerListener> listener_;
|
||||
|
|
|
@ -105,12 +105,11 @@ class MuxerListener {
|
|||
/// Called when all files are written out and the muxer object does not output
|
||||
/// any more files.
|
||||
/// Note: This event might not be very interesting to MPEG DASH Live profile.
|
||||
/// @param media_ranges is the ranges of the media file.
|
||||
/// @param media_ranges is the ranges of the media file. It should have ranges
|
||||
/// for the entire file, using which the file size can be calculated.
|
||||
/// @param duration_seconds is the length of the media in seconds.
|
||||
/// @param file_size is the size of the file in bytes.
|
||||
virtual void OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) = 0;
|
||||
float duration_seconds) = 0;
|
||||
|
||||
/// Called when a segment has been muxed and the file has been written.
|
||||
/// Note: For some implementations, this is used to signal new subsegments.
|
||||
|
|
|
@ -192,13 +192,8 @@ bool GenerateMediaInfo(const MuxerOptions& muxer_options,
|
|||
|
||||
bool SetVodInformation(const MuxerListener::MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size,
|
||||
MediaInfo* media_info) {
|
||||
DCHECK(media_info);
|
||||
if (file_size == 0) {
|
||||
LOG(ERROR) << "File size not specified.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (duration_seconds <= 0.0f) {
|
||||
// Non positive second media must be invalid media.
|
||||
|
@ -220,6 +215,17 @@ bool SetVodInformation(const MuxerListener::MediaRanges& media_ranges,
|
|||
media_info->set_media_duration_seconds(duration_seconds);
|
||||
|
||||
if (!media_info->has_bandwidth()) {
|
||||
// Calculate file size from media_ranges.
|
||||
uint64_t file_size = 0;
|
||||
if (media_ranges.init_range)
|
||||
file_size = std::max(file_size, media_ranges.init_range->end + 1);
|
||||
if (media_ranges.index_range)
|
||||
file_size = std::max(file_size, media_ranges.index_range->end + 1);
|
||||
if (!media_ranges.subsegment_ranges.empty()) {
|
||||
file_size =
|
||||
std::max(file_size, media_ranges.subsegment_ranges.back().end + 1);
|
||||
}
|
||||
|
||||
media_info->set_bandwidth(
|
||||
EstimateRequiredBandwidth(file_size, duration_seconds));
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ bool GenerateMediaInfo(const MuxerOptions& muxer_options,
|
|||
/// @return true on success, false otherwise.
|
||||
bool SetVodInformation(const MuxerListener::MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size,
|
||||
MediaInfo* media_info);
|
||||
|
||||
/// @param protection_scheme specifies the protection scheme: 'cenc', 'cens',
|
||||
|
|
|
@ -64,8 +64,9 @@ OnMediaEndParameters GetDefaultOnMediaEndParams() {
|
|||
const uint64_t kInitRangeEnd = kInitRangeStart + 120;
|
||||
const uint64_t kIndexRangeStart = kInitRangeEnd + 1;
|
||||
const uint64_t kIndexRangeEnd = kIndexRangeStart + 100;
|
||||
const uint64_t kMediaSegmentRangeStart = kIndexRangeEnd + 1;
|
||||
const uint64_t kMediaSegmentRangeEnd = 9999;
|
||||
const float kMediaDuration = 10.5f;
|
||||
const uint64_t kFileSize = 10000;
|
||||
MuxerListener::MediaRanges media_ranges;
|
||||
Range init_range;
|
||||
init_range.start = kInitRangeStart;
|
||||
|
@ -76,7 +77,12 @@ OnMediaEndParameters GetDefaultOnMediaEndParams() {
|
|||
index_range.end = kIndexRangeEnd;
|
||||
media_ranges.index_range =index_range;
|
||||
|
||||
OnMediaEndParameters param = {media_ranges, kMediaDuration, kFileSize};
|
||||
Range media_segment_range;
|
||||
media_segment_range.start = kMediaSegmentRangeStart;
|
||||
media_segment_range.end = kMediaSegmentRangeEnd;
|
||||
media_ranges.subsegment_ranges.push_back(media_segment_range);
|
||||
|
||||
OnMediaEndParameters param = {media_ranges, kMediaDuration};
|
||||
return param;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ struct VideoStreamInfoParameters {
|
|||
struct OnMediaEndParameters {
|
||||
MuxerListener::MediaRanges media_ranges;
|
||||
float duration_seconds;
|
||||
uint64_t file_size;
|
||||
};
|
||||
|
||||
// Creates StreamInfo instance from VideoStreamInfoParameters.
|
||||
|
|
|
@ -73,10 +73,9 @@ void VodMediaInfoDumpMuxerListener::OnSampleDurationReady(
|
|||
}
|
||||
|
||||
void VodMediaInfoDumpMuxerListener::OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) {
|
||||
float duration_seconds) {
|
||||
DCHECK(media_info_);
|
||||
if (!internal::SetVodInformation(media_ranges, duration_seconds, file_size,
|
||||
if (!internal::SetVodInformation(media_ranges, duration_seconds,
|
||||
media_info_.get())) {
|
||||
LOG(ERROR) << "Failed to generate VOD information from input.";
|
||||
return;
|
||||
|
|
|
@ -45,8 +45,7 @@ class VodMediaInfoDumpMuxerListener : public MuxerListener {
|
|||
ContainerType container_type) override;
|
||||
void OnSampleDurationReady(uint32_t sample_duration) override;
|
||||
void OnMediaEnd(const MediaRanges& media_ranges,
|
||||
float duration_seconds,
|
||||
uint64_t file_size) override;
|
||||
float duration_seconds) override;
|
||||
void OnNewSegment(const std::string& file_name,
|
||||
uint64_t start_time,
|
||||
uint64_t duration,
|
||||
|
|
|
@ -95,9 +95,7 @@ class VodMediaInfoDumpMuxerListenerTest : public ::testing::Test {
|
|||
|
||||
void FireOnMediaEndWithParams(const OnMediaEndParameters& params) {
|
||||
// On success, this writes the result to |temp_file_path_|.
|
||||
listener_->OnMediaEnd(params.media_ranges,
|
||||
params.duration_seconds,
|
||||
params.file_size);
|
||||
listener_->OnMediaEnd(params.media_ranges, params.duration_seconds);
|
||||
}
|
||||
|
||||
void ExpectTempFileToEqual(const std::string& expected_protobuf) {
|
||||
|
|
|
@ -61,7 +61,7 @@ void TsMuxer::FireOnMediaEndEvent() {
|
|||
// For now, there is no single file TS segmenter. So all the values passed
|
||||
// here are left empty.
|
||||
MuxerListener::MediaRanges range;
|
||||
muxer_listener()->OnMediaEnd(range, 0, 0);
|
||||
muxer_listener()->OnMediaEnd(range, 0);
|
||||
}
|
||||
|
||||
} // namespace mp2t
|
||||
|
|
|
@ -469,15 +469,7 @@ void MP4Muxer::FireOnMediaEndEvent() {
|
|||
media_range.subsegment_ranges = segmenter_->GetSegmentRanges();
|
||||
|
||||
const float duration_seconds = static_cast<float>(segmenter_->GetDuration());
|
||||
|
||||
const int64_t file_size =
|
||||
File::GetFileSize(options().output_file_name.c_str());
|
||||
if (file_size <= 0) {
|
||||
LOG(ERROR) << "Invalid file size: " << file_size;
|
||||
return;
|
||||
}
|
||||
|
||||
muxer_listener()->OnMediaEnd(media_range, duration_seconds, file_size);
|
||||
muxer_listener()->OnMediaEnd(media_range, duration_seconds);
|
||||
}
|
||||
|
||||
uint64_t MP4Muxer::IsoTimeNow() {
|
||||
|
|
|
@ -56,15 +56,17 @@ std::vector<Range> SingleSegmentSegmenter::GetSegmentRanges() {
|
|||
for (int32_t i = 0; i < cues()->cue_entries_size() - 1; ++i) {
|
||||
const mkvmuxer::CuePoint* cue_point = cues()->GetCueByIndex(i);
|
||||
Range r;
|
||||
r.start = cue_point->cluster_pos();
|
||||
r.end = cues()->GetCueByIndex(i + 1)->cluster_pos() - 1;
|
||||
// Cue point cluster position is relative to segment payload pos.
|
||||
r.start = segment_payload_pos() + cue_point->cluster_pos();
|
||||
r.end =
|
||||
segment_payload_pos() + cues()->GetCueByIndex(i + 1)->cluster_pos() - 1;
|
||||
ranges.push_back(r);
|
||||
}
|
||||
|
||||
Range last_range;
|
||||
const mkvmuxer::CuePoint* last_cue_point =
|
||||
cues()->GetCueByIndex(cues()->cue_entries_size() - 1);
|
||||
last_range.start = last_cue_point->cluster_pos();
|
||||
last_range.start = segment_payload_pos() + last_cue_point->cluster_pos();
|
||||
last_range.end = last_range.start + cluster()->Size() - 1;
|
||||
ranges.push_back(last_range);
|
||||
return ranges;
|
||||
|
|
|
@ -122,15 +122,7 @@ void WebMMuxer::FireOnMediaEndEvent() {
|
|||
media_range.subsegment_ranges = segmenter_->GetSegmentRanges();
|
||||
|
||||
const float duration_seconds = segmenter_->GetDurationInSeconds();
|
||||
|
||||
const int64_t file_size =
|
||||
File::GetFileSize(options().output_file_name.c_str());
|
||||
if (file_size <= 0) {
|
||||
LOG(ERROR) << "Invalid file size: " << file_size;
|
||||
return;
|
||||
}
|
||||
|
||||
muxer_listener()->OnMediaEnd(media_range, duration_seconds, file_size);
|
||||
muxer_listener()->OnMediaEnd(media_range, duration_seconds);
|
||||
}
|
||||
|
||||
} // namespace webm
|
||||
|
|
Loading…
Reference in New Issue