7#include <packager/media/chunking/segment_coordinator.h>
9#include <absl/log/log.h>
11#include <packager/macros/status.h>
16SegmentCoordinator::SegmentCoordinator() =
default;
19 DVLOG(2) <<
"SegmentCoordinator: Marking stream " << input_stream_index
21 teletext_stream_indices_.insert(input_stream_index);
31 const size_t input_stream_index = stream_data->stream_index;
32 const StreamDataType stream_data_type = stream_data->stream_data_type;
34 DVLOG(3) <<
"SegmentCoordinator::Process stream_index=" << input_stream_index
35 <<
" type=" << StreamDataTypeToString(stream_data_type);
38 if (stream_data_type == StreamDataType::kSegmentInfo) {
39 auto info = std::move(stream_data->segment_info);
46 if (!IsTeletextStream(input_stream_index)) {
47 RETURN_IF_ERROR(OnSegmentInfo(input_stream_index, std::move(info)));
54 return Dispatch(std::move(stream_data));
57Status SegmentCoordinator::OnSegmentInfo(
58 size_t input_stream_index,
59 std::shared_ptr<const SegmentInfo> info) {
61 if (info->is_subsegment) {
62 DVLOG(3) <<
"SegmentCoordinator: Skipping subsegment replication";
67 if (teletext_stream_indices_.empty()) {
68 DVLOG(3) <<
"SegmentCoordinator: No teletext streams registered, "
69 <<
"skipping replication";
77 if (!sync_source_stream_index_.has_value()) {
78 sync_source_stream_index_ = input_stream_index;
79 DVLOG(2) <<
"SegmentCoordinator: Set sync source to stream "
80 << input_stream_index;
84 if (input_stream_index != sync_source_stream_index_.value()) {
85 DVLOG(3) <<
"SegmentCoordinator: Ignoring SegmentInfo from stream "
86 << input_stream_index <<
" (sync source is stream "
87 << sync_source_stream_index_.value() <<
")";
92 latest_segment_boundary_ = info->start_timestamp;
95 <<
"SegmentCoordinator: Received SegmentInfo from sync source stream "
96 << input_stream_index <<
" boundary=" << info->start_timestamp
97 <<
" duration=" << info->duration
98 <<
" segment_number=" << info->segment_number;
100 DVLOG(2) <<
"SegmentCoordinator: Replicating segment boundary "
101 << info->start_timestamp <<
" to " << teletext_stream_indices_.size()
102 <<
" teletext stream(s)";
105 for (
size_t teletext_stream_index : teletext_stream_indices_) {
106 DVLOG(3) <<
"SegmentCoordinator: Replicating to teletext stream "
107 << teletext_stream_index;
114bool SegmentCoordinator::IsTeletextStream(
size_t input_stream_index)
const {
115 return teletext_stream_indices_.count(input_stream_index) > 0;
All the methods that are virtual are virtual for mocking.