7 #ifndef PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_ 8 #define PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_ 14 #include "packager/media/base/media_sample.h" 15 #include "packager/media/base/stream_info.h" 16 #include "packager/media/base/text_sample.h" 17 #include "packager/status.h" 22 enum class StreamDataType {
32 std::string StreamDataTypeToString(StreamDataType type);
40 double start_time_in_seconds = 0;
41 double duration_in_seconds = 0;
45 enum class CueEventType { kCueIn, kCueOut, kCuePoint };
50 CueEventType type = CueEventType::kCuePoint;
51 double time_in_seconds;
56 bool is_subsegment =
false;
57 bool is_encrypted =
false;
58 int64_t start_timestamp = -1;
63 std::shared_ptr<EncryptionConfig> key_rotation_encryption_config;
68 size_t stream_index =
static_cast<size_t>(-1);
69 StreamDataType stream_data_type = StreamDataType::kUnknown;
71 std::shared_ptr<const StreamInfo> stream_info;
72 std::shared_ptr<const MediaSample> media_sample;
73 std::shared_ptr<const TextSample> text_sample;
74 std::shared_ptr<const SegmentInfo> segment_info;
75 std::shared_ptr<const Scte35Event> scte35_event;
76 std::shared_ptr<const CueEvent> cue_event;
78 static std::unique_ptr<StreamData> FromStreamInfo(
80 std::shared_ptr<const StreamInfo> stream_info) {
81 std::unique_ptr<StreamData> stream_data(
new StreamData);
82 stream_data->stream_index = stream_index;
83 stream_data->stream_data_type = StreamDataType::kStreamInfo;
84 stream_data->stream_info = std::move(stream_info);
88 static std::unique_ptr<StreamData> FromMediaSample(
90 std::shared_ptr<const MediaSample> media_sample) {
91 std::unique_ptr<StreamData> stream_data(
new StreamData);
92 stream_data->stream_index = stream_index;
93 stream_data->stream_data_type = StreamDataType::kMediaSample;
94 stream_data->media_sample = std::move(media_sample);
98 static std::unique_ptr<StreamData> FromTextSample(
100 std::shared_ptr<const TextSample> text_sample) {
101 std::unique_ptr<StreamData> stream_data(
new StreamData);
102 stream_data->stream_index = stream_index;
103 stream_data->stream_data_type = StreamDataType::kTextSample;
104 stream_data->text_sample = std::move(text_sample);
108 static std::unique_ptr<StreamData> FromSegmentInfo(
110 std::shared_ptr<const SegmentInfo> segment_info) {
111 std::unique_ptr<StreamData> stream_data(
new StreamData);
112 stream_data->stream_index = stream_index;
113 stream_data->stream_data_type = StreamDataType::kSegmentInfo;
114 stream_data->segment_info = std::move(segment_info);
118 static std::unique_ptr<StreamData> FromScte35Event(
120 std::shared_ptr<const Scte35Event> scte35_event) {
121 std::unique_ptr<StreamData> stream_data(
new StreamData);
122 stream_data->stream_index = stream_index;
123 stream_data->stream_data_type = StreamDataType::kScte35Event;
124 stream_data->scte35_event = std::move(scte35_event);
128 static std::unique_ptr<StreamData> FromCueEvent(
130 std::shared_ptr<const CueEvent> cue_event) {
131 std::unique_ptr<StreamData> stream_data(
new StreamData);
132 stream_data->stream_index = stream_index;
133 stream_data->stream_data_type = StreamDataType::kCueEvent;
134 stream_data->cue_event = std::move(cue_event);
160 Status SetHandler(
size_t output_stream_index,
161 std::shared_ptr<MediaHandler> handler);
165 return SetHandler(next_output_stream_index_, handler);
176 std::initializer_list<std::shared_ptr<MediaHandler>> list);
181 virtual Status InitializeInternal() = 0;
187 virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
190 virtual Status OnFlushRequest(
size_t input_stream_index);
193 virtual bool ValidateOutputStreamIndex(
size_t stream_index)
const;
197 Status Dispatch(std::unique_ptr<StreamData> stream_data)
const;
202 std::shared_ptr<const StreamInfo> stream_info)
const {
204 StreamData::FromStreamInfo(stream_index, std::move(stream_info)));
210 std::shared_ptr<const MediaSample> media_sample)
const {
212 StreamData::FromMediaSample(stream_index, std::move(media_sample)));
219 std::shared_ptr<const TextSample> text_sample)
const {
221 StreamData::FromTextSample(stream_index, std::move(text_sample)));
227 std::shared_ptr<const SegmentInfo> segment_info)
const {
229 StreamData::FromSegmentInfo(stream_index, std::move(segment_info)));
235 std::shared_ptr<const Scte35Event> scte35_event)
const {
237 StreamData::FromScte35Event(stream_index, std::move(scte35_event)));
242 std::shared_ptr<const CueEvent> cue_event)
const {
244 StreamData::FromCueEvent(stream_index, std::move(cue_event)));
248 Status FlushDownstream(
size_t output_stream_index);
251 Status FlushAllDownstreams();
253 bool initialized() {
return initialized_; }
254 size_t num_input_streams()
const {
return num_input_streams_; }
255 size_t next_output_stream_index()
const {
return next_output_stream_index_; }
256 const std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>&
258 return output_handlers_;
265 bool initialized_ =
false;
267 size_t num_input_streams_ = 0;
269 size_t next_output_stream_index_ = 0;
272 std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>
279 #endif // PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_
All the methods that are virtual are virtual for mocking.