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 {
36 bool is_subsegment =
false;
37 bool is_encrypted =
false;
38 int64_t start_timestamp = -1;
43 std::shared_ptr<EncryptionConfig> key_rotation_encryption_config;
48 size_t stream_index =
static_cast<size_t>(-1);
49 StreamDataType stream_data_type = StreamDataType::kUnknown;
51 std::shared_ptr<const PeriodInfo> period_info;
52 std::shared_ptr<const StreamInfo> stream_info;
53 std::shared_ptr<const MediaSample> media_sample;
54 std::shared_ptr<const TextSample> text_sample;
55 std::shared_ptr<const MediaEvent> media_event;
56 std::shared_ptr<const SegmentInfo> segment_info;
58 static std::unique_ptr<StreamData> FromPeriodInfo(
59 size_t stream_index, std::shared_ptr<const PeriodInfo> period_info) {
60 std::unique_ptr<StreamData> stream_data(
new StreamData);
61 stream_data->stream_index = stream_index;
62 stream_data->stream_data_type = StreamDataType::kPeriodInfo;
63 stream_data->period_info = std::move(period_info);
67 static std::unique_ptr<StreamData> FromStreamInfo(
68 size_t stream_index, std::shared_ptr<const StreamInfo> stream_info) {
69 std::unique_ptr<StreamData> stream_data(
new StreamData);
70 stream_data->stream_index = stream_index;
71 stream_data->stream_data_type = StreamDataType::kStreamInfo;
72 stream_data->stream_info = std::move(stream_info);
76 static std::unique_ptr<StreamData> FromMediaSample(
77 size_t stream_index, std::shared_ptr<const MediaSample> media_sample) {
78 std::unique_ptr<StreamData> stream_data(
new StreamData);
79 stream_data->stream_index = stream_index;
80 stream_data->stream_data_type = StreamDataType::kMediaSample;
81 stream_data->media_sample = std::move(media_sample);
85 static std::unique_ptr<StreamData> FromTextSample(
86 size_t stream_index, std::shared_ptr<const TextSample> text_sample) {
87 std::unique_ptr<StreamData> stream_data(
new StreamData);
88 stream_data->stream_index = stream_index;
89 stream_data->stream_data_type = StreamDataType::kTextSample;
90 stream_data->text_sample = std::move(text_sample);
94 static std::unique_ptr<StreamData> FromMediaEvent(
95 size_t stream_index, std::shared_ptr<const MediaEvent> media_event) {
96 std::unique_ptr<StreamData> stream_data(
new StreamData);
97 stream_data->stream_index = stream_index;
98 stream_data->stream_data_type = StreamDataType::kMediaEvent;
99 stream_data->media_event = std::move(media_event);
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);
135 std::shared_ptr<MediaHandler> handler);
139 return SetHandler(next_output_stream_index_, handler);
158 virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
172 size_t stream_index, std::shared_ptr<const PeriodInfo> period_info) {
173 return Dispatch(StreamData::FromPeriodInfo(stream_index, period_info));
178 size_t stream_index, std::shared_ptr<const StreamInfo> stream_info) {
179 return Dispatch(StreamData::FromStreamInfo(stream_index, stream_info));
184 size_t stream_index, std::shared_ptr<const MediaSample> media_sample) {
185 return Dispatch(StreamData::FromMediaSample(stream_index, media_sample));
191 size_t stream_index, std::shared_ptr<const TextSample> text_sample) {
192 return Dispatch(StreamData::FromTextSample(stream_index, text_sample));
197 size_t stream_index, std::shared_ptr<const MediaEvent> media_event) {
198 return Dispatch(StreamData::FromMediaEvent(stream_index, media_event));
203 size_t stream_index, std::shared_ptr<const SegmentInfo> segment_info) {
204 return Dispatch(StreamData::FromSegmentInfo(stream_index, segment_info));
213 bool initialized() {
return initialized_; }
214 size_t num_input_streams()
const {
return num_input_streams_; }
215 size_t next_output_stream_index()
const {
return next_output_stream_index_; }
216 const std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>&
218 return output_handlers_;
222 MediaHandler(
const MediaHandler&) =
delete;
223 MediaHandler& operator=(
const MediaHandler&) =
delete;
225 bool initialized_ =
false;
227 size_t num_input_streams_ = 0;
229 size_t next_output_stream_index_ = 0;
232 std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>
239 #endif // PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_