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 {
38 int64_t start_time = 0;
43 enum class CueEventType { kCueIn, kCueOut, kCuePoint };
48 int64_t timestamp = 0;
49 CueEventType type = CueEventType::kCuePoint;
54 bool is_subsegment =
false;
55 bool is_encrypted =
false;
56 int64_t start_timestamp = -1;
61 std::shared_ptr<EncryptionConfig> key_rotation_encryption_config;
66 size_t stream_index =
static_cast<size_t>(-1);
67 StreamDataType stream_data_type = StreamDataType::kUnknown;
69 std::shared_ptr<const StreamInfo> stream_info;
70 std::shared_ptr<const MediaSample> media_sample;
71 std::shared_ptr<const TextSample> text_sample;
72 std::shared_ptr<const SegmentInfo> segment_info;
73 std::shared_ptr<const Scte35Event> scte35_event;
74 std::shared_ptr<const CueEvent> cue_event;
76 static std::unique_ptr<StreamData> FromStreamInfo(
77 size_t stream_index, std::shared_ptr<const StreamInfo> stream_info) {
78 std::unique_ptr<StreamData> stream_data(
new StreamData);
79 stream_data->stream_index = stream_index;
80 stream_data->stream_data_type = StreamDataType::kStreamInfo;
81 stream_data->stream_info = std::move(stream_info);
85 static std::unique_ptr<StreamData> FromMediaSample(
86 size_t stream_index, std::shared_ptr<const MediaSample> media_sample) {
87 std::unique_ptr<StreamData> stream_data(
new StreamData);
88 stream_data->stream_index = stream_index;
89 stream_data->stream_data_type = StreamDataType::kMediaSample;
90 stream_data->media_sample = std::move(media_sample);
94 static std::unique_ptr<StreamData> FromTextSample(
95 size_t stream_index, std::shared_ptr<const TextSample> text_sample) {
96 std::unique_ptr<StreamData> stream_data(
new StreamData);
97 stream_data->stream_index = stream_index;
98 stream_data->stream_data_type = StreamDataType::kTextSample;
99 stream_data->text_sample = std::move(text_sample);
103 static std::unique_ptr<StreamData> FromSegmentInfo(
104 size_t stream_index, std::shared_ptr<const SegmentInfo> segment_info) {
105 std::unique_ptr<StreamData> stream_data(
new StreamData);
106 stream_data->stream_index = stream_index;
107 stream_data->stream_data_type = StreamDataType::kSegmentInfo;
108 stream_data->segment_info = std::move(segment_info);
112 static std::unique_ptr<StreamData> FromScte35Event(
114 std::shared_ptr<const Scte35Event> scte35_event) {
115 std::unique_ptr<StreamData> stream_data(
new StreamData);
116 stream_data->stream_index = stream_index;
117 stream_data->stream_data_type = StreamDataType::kScte35Event;
118 stream_data->scte35_event = std::move(scte35_event);
122 static std::unique_ptr<StreamData> FromCueEvent(
124 std::shared_ptr<const CueEvent> cue_event) {
125 std::unique_ptr<StreamData> stream_data(
new StreamData);
126 stream_data->stream_index = stream_index;
127 stream_data->stream_data_type = StreamDataType::kCueEvent;
128 stream_data->cue_event = std::move(cue_event);
154 Status SetHandler(
size_t output_stream_index,
155 std::shared_ptr<MediaHandler> handler);
159 return SetHandler(next_output_stream_index_, handler);
172 virtual Status InitializeInternal() = 0;
178 virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
181 virtual Status OnFlushRequest(
size_t input_stream_index);
184 virtual bool ValidateOutputStreamIndex(
size_t stream_index)
const;
188 Status Dispatch(std::unique_ptr<StreamData> stream_data);
192 size_t stream_index, std::shared_ptr<const StreamInfo> stream_info) {
193 return Dispatch(StreamData::FromStreamInfo(stream_index, stream_info));
198 size_t stream_index, std::shared_ptr<const MediaSample> media_sample) {
199 return Dispatch(StreamData::FromMediaSample(stream_index, media_sample));
205 size_t stream_index, std::shared_ptr<const TextSample> text_sample) {
206 return Dispatch(StreamData::FromTextSample(stream_index, text_sample));
211 size_t stream_index, std::shared_ptr<const SegmentInfo> segment_info) {
212 return Dispatch(StreamData::FromSegmentInfo(stream_index, segment_info));
217 std::shared_ptr<const Scte35Event> scte35_event) {
218 return Dispatch(StreamData::FromScte35Event(stream_index, scte35_event));
223 std::shared_ptr<const CueEvent> cue_event) {
224 return Dispatch(StreamData::FromCueEvent(stream_index, cue_event));
228 Status FlushDownstream(
size_t output_stream_index);
231 Status FlushAllDownstreams();
233 bool initialized() {
return initialized_; }
234 size_t num_input_streams()
const {
return num_input_streams_; }
235 size_t next_output_stream_index()
const {
return next_output_stream_index_; }
236 const std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>&
238 return output_handlers_;
245 bool initialized_ =
false;
247 size_t num_input_streams_ = 0;
249 size_t next_output_stream_index_ = 0;
252 std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>
259 #endif // PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_
All the methods that are virtual are virtual for mocking.