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/status.h"
16 #include "packager/media/base/stream_info.h"
17 #include "packager/media/base/text_sample.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<PeriodInfo> period_info;
52 std::shared_ptr<StreamInfo> stream_info;
53 std::shared_ptr<MediaSample> media_sample;
54 std::shared_ptr<TextSample> text_sample;
55 std::shared_ptr<MediaEvent> media_event;
56 std::shared_ptr<SegmentInfo> segment_info;
81 std::shared_ptr<MediaHandler> handler);
85 return SetHandler(next_output_stream_index_, handler);
104 virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
118 std::shared_ptr<PeriodInfo> period_info) {
119 std::unique_ptr<StreamData> stream_data(
new StreamData);
120 stream_data->stream_index = stream_index;
121 stream_data->stream_data_type = StreamDataType::kPeriodInfo;
122 stream_data->period_info = std::move(period_info);
123 return Dispatch(std::move(stream_data));
128 std::shared_ptr<StreamInfo> stream_info) {
129 std::unique_ptr<StreamData> stream_data(
new StreamData);
130 stream_data->stream_index = stream_index;
131 stream_data->stream_data_type = StreamDataType::kStreamInfo;
132 stream_data->stream_info = std::move(stream_info);
133 return Dispatch(std::move(stream_data));
138 std::shared_ptr<MediaSample> media_sample) {
139 std::unique_ptr<StreamData> stream_data(
new StreamData);
140 stream_data->stream_index = stream_index;
141 stream_data->stream_data_type = StreamDataType::kMediaSample;
142 stream_data->media_sample = std::move(media_sample);
143 return Dispatch(std::move(stream_data));
149 std::shared_ptr<TextSample> text_sample) {
150 std::unique_ptr<StreamData> stream_data(
new StreamData);
151 stream_data->stream_index = stream_index;
152 stream_data->stream_data_type = StreamDataType::kTextSample;
153 stream_data->text_sample = std::move(text_sample);
154 return Dispatch(std::move(stream_data));
159 std::shared_ptr<MediaEvent> media_event) {
160 std::unique_ptr<StreamData> stream_data(
new StreamData);
161 stream_data->stream_index = stream_index;
162 stream_data->stream_data_type = StreamDataType::kMediaEvent;
163 stream_data->media_event = std::move(media_event);
164 return Dispatch(std::move(stream_data));
169 std::shared_ptr<SegmentInfo> segment_info) {
170 std::unique_ptr<StreamData> stream_data(
new StreamData);
171 stream_data->stream_index = stream_index;
172 stream_data->stream_data_type = StreamDataType::kSegmentInfo;
173 stream_data->segment_info = std::move(segment_info);
174 return Dispatch(std::move(stream_data));
183 bool initialized() {
return initialized_; }
184 size_t num_input_streams()
const {
return num_input_streams_; }
185 size_t next_output_stream_index()
const {
return next_output_stream_index_; }
186 const std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>&
188 return output_handlers_;
192 MediaHandler(
const MediaHandler&) =
delete;
193 MediaHandler& operator=(
const MediaHandler&) =
delete;
195 bool initialized_ =
false;
197 size_t num_input_streams_ = 0;
199 size_t next_output_stream_index_ = 0;
202 std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>
209 #endif // PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_