7 #include <packager/media/formats/webm/multi_segment_segmenter.h>
9 #include <absl/log/check.h>
10 #include <mkvmuxer/mkvmuxer.h>
12 #include <packager/macros/logging.h>
13 #include <packager/macros/status.h>
14 #include <packager/media/base/muxer_options.h>
15 #include <packager/media/base/muxer_util.h>
16 #include <packager/media/base/stream_info.h>
17 #include <packager/media/event/muxer_listener.h>
23 MultiSegmentSegmenter::MultiSegmentSegmenter(
const MuxerOptions& options)
24 : Segmenter(options), num_segment_(0) {}
26 MultiSegmentSegmenter::~MultiSegmentSegmenter() {}
28 Status MultiSegmentSegmenter::FinalizeSegment(int64_t start_timestamp,
29 int64_t duration_timestamp,
31 int64_t segment_number) {
33 RETURN_IF_ERROR(Segmenter::FinalizeSegment(
34 start_timestamp, duration_timestamp, is_subsegment, segment_number));
35 if (!cluster()->Finalize())
36 return Status(error::FILE_FAILURE,
"Error finalizing segment.");
39 std::string segment_name =
40 GetSegmentName(options().segment_template, start_timestamp,
41 segment_number, options().bandwidth);
45 RETURN_IF_ERROR(writer_->Close());
47 if (!File::Copy(temp_file_name_.c_str(), segment_name.c_str()))
48 return Status(error::FILE_FAILURE,
"Failure to copy memory file.");
50 if (!File::Delete(temp_file_name_.c_str()))
51 return Status(error::FILE_FAILURE,
"Failure to delete memory file.");
55 if (muxer_listener()) {
56 const uint64_t size = cluster()->Size();
57 muxer_listener()->OnNewSegment(segment_name, start_timestamp,
58 duration_timestamp, size, segment_number);
60 VLOG(1) <<
"WEBM file '" << segment_name <<
"' finalized.";
65 bool MultiSegmentSegmenter::GetInitRangeStartAndEnd(uint64_t* ,
70 bool MultiSegmentSegmenter::GetIndexRangeStartAndEnd(uint64_t* ,
75 std::vector<Range> MultiSegmentSegmenter::GetSegmentRanges() {
76 return std::vector<Range>();
79 Status MultiSegmentSegmenter::DoInitialize() {
80 std::unique_ptr<MkvWriter> writer(
new MkvWriter);
81 Status status = writer->Open(options().output_file_name);
84 writer_ = std::move(writer);
85 return WriteSegmentHeader(0, writer_.get());
88 Status MultiSegmentSegmenter::DoFinalize() {
92 Status MultiSegmentSegmenter::NewSegment(int64_t start_timestamp,
96 "memory://" + GetSegmentName(options().segment_template,
97 start_timestamp, num_segment_,
100 writer_.reset(
new MkvWriter);
101 Status status = writer_->Open(temp_file_name_);
107 const int64_t start_timecode = FromBmffTimestamp(start_timestamp);
108 return SetCluster(start_timecode, 0, writer_.get());
All the methods that are virtual are virtual for mocking.