7#include <packager/media/chunking/segment_coordinator.h>
13#include <absl/log/log.h>
15#include <packager/macros/status.h>
16#include <packager/media/base/media_handler.h>
17#include <packager/status.h>
22SegmentCoordinator::SegmentCoordinator() =
default;
25 DVLOG(2) <<
"SegmentCoordinator: Marking stream " << input_stream_index
27 teletext_stream_indices_.insert(input_stream_index);
37 const size_t input_stream_index = stream_data->stream_index;
38 const StreamDataType stream_data_type = stream_data->stream_data_type;
40 DVLOG(3) <<
"SegmentCoordinator::Process stream_index=" << input_stream_index
41 <<
" type=" << StreamDataTypeToString(stream_data_type);
44 if (stream_data_type == StreamDataType::kSegmentInfo) {
45 auto info = std::move(stream_data->segment_info);
52 if (!IsTeletextStream(input_stream_index)) {
53 RETURN_IF_ERROR(OnSegmentInfo(input_stream_index, std::move(info)));
60 return Dispatch(std::move(stream_data));
63Status SegmentCoordinator::OnSegmentInfo(
64 size_t input_stream_index,
65 std::shared_ptr<const SegmentInfo> info) {
67 if (info->is_subsegment) {
68 DVLOG(3) <<
"SegmentCoordinator: Skipping subsegment replication";
73 if (teletext_stream_indices_.empty()) {
74 DVLOG(3) <<
"SegmentCoordinator: No teletext streams registered, "
75 <<
"skipping replication";
83 if (!sync_source_stream_index_.has_value()) {
84 sync_source_stream_index_ = input_stream_index;
85 DVLOG(2) <<
"SegmentCoordinator: Set sync source to stream "
86 << input_stream_index;
90 if (input_stream_index != sync_source_stream_index_.value()) {
91 DVLOG(3) <<
"SegmentCoordinator: Ignoring SegmentInfo from stream "
92 << input_stream_index <<
" (sync source is stream "
93 << sync_source_stream_index_.value() <<
")";
98 latest_segment_boundary_ = info->start_timestamp;
101 <<
"SegmentCoordinator: Received SegmentInfo from sync source stream "
102 << input_stream_index <<
" boundary=" << info->start_timestamp
103 <<
" duration=" << info->duration
104 <<
" segment_number=" << info->segment_number;
106 DVLOG(2) <<
"SegmentCoordinator: Replicating segment boundary "
107 << info->start_timestamp <<
" to " << teletext_stream_indices_.size()
108 <<
" teletext stream(s)";
111 for (
size_t teletext_stream_index : teletext_stream_indices_) {
112 DVLOG(3) <<
"SegmentCoordinator: Replicating to teletext stream "
113 << teletext_stream_index;
120bool SegmentCoordinator::IsTeletextStream(
size_t input_stream_index)
const {
121 return teletext_stream_indices_.count(input_stream_index) > 0;
All the methods that are virtual are virtual for mocking.