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"
21 enum class StreamDataType {
36 bool is_subsegment =
false;
37 bool is_encrypted =
false;
38 int64_t start_timestamp = -1;
44 size_t stream_index =
static_cast<size_t>(-1);
45 StreamDataType stream_data_type = StreamDataType::kUnknown;
47 std::shared_ptr<PeriodInfo> period_info;
48 std::shared_ptr<StreamInfo> stream_info;
49 std::shared_ptr<EncryptionConfig> encryption_config;
50 std::shared_ptr<MediaSample> media_sample;
51 std::shared_ptr<MediaEvent> media_event;
52 std::shared_ptr<SegmentInfo> segment_info;
77 std::shared_ptr<MediaHandler> handler);
81 return SetHandler(next_output_stream_index_, handler);
97 virtual Status Process(std::unique_ptr<StreamData> stream_data) = 0;
105 bool initialized() {
return initialized_; }
106 size_t num_input_streams() {
return num_input_streams_; }
110 Status
Dispatch(std::unique_ptr<StreamData> stream_data);
114 std::shared_ptr<PeriodInfo> period_info) {
115 std::unique_ptr<StreamData> stream_data(
new StreamData);
116 stream_data->stream_index = stream_index;
117 stream_data->stream_data_type = StreamDataType::kPeriodInfo;
118 stream_data->period_info = std::move(period_info);
119 return Dispatch(std::move(stream_data));
124 std::shared_ptr<StreamInfo> stream_info) {
125 std::unique_ptr<StreamData> stream_data(
new StreamData);
126 stream_data->stream_index = stream_index;
127 stream_data->stream_data_type = StreamDataType::kStreamInfo;
128 stream_data->stream_info = std::move(stream_info);
129 return Dispatch(std::move(stream_data));
135 std::unique_ptr<EncryptionConfig> encryption_config) {
136 std::unique_ptr<StreamData> stream_data(
new StreamData);
137 stream_data->stream_index = stream_index;
138 stream_data->stream_data_type = StreamDataType::kEncryptionConfig;
139 stream_data->encryption_config = std::move(encryption_config);
140 return Dispatch(std::move(stream_data));
145 std::shared_ptr<MediaSample> media_sample) {
146 std::unique_ptr<StreamData> stream_data(
new StreamData);
147 stream_data->stream_index = stream_index;
148 stream_data->stream_data_type = StreamDataType::kMediaSample;
149 stream_data->media_sample = std::move(media_sample);
150 return Dispatch(std::move(stream_data));
155 std::shared_ptr<MediaEvent> media_event) {
156 std::unique_ptr<StreamData> stream_data(
new StreamData);
157 stream_data->stream_index = stream_index;
158 stream_data->stream_data_type = StreamDataType::kMediaEvent;
159 stream_data->media_event = std::move(media_event);
160 return Dispatch(std::move(stream_data));
165 std::shared_ptr<SegmentInfo> segment_info) {
166 std::unique_ptr<StreamData> stream_data(
new StreamData);
167 stream_data->stream_index = stream_index;
168 stream_data->stream_data_type = StreamDataType::kSegmentInfo;
169 stream_data->segment_info = std::move(segment_info);
170 return Dispatch(std::move(stream_data));
176 size_t num_input_streams()
const {
return num_input_streams_; }
177 size_t next_output_stream_index()
const {
return next_output_stream_index_; }
178 const std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>&
180 return output_handlers_;
184 MediaHandler(
const MediaHandler&) =
delete;
185 MediaHandler& operator=(
const MediaHandler&) =
delete;
187 bool initialized_ =
false;
189 size_t num_input_streams_ = 0;
191 size_t next_output_stream_index_ = 0;
194 std::map<size_t, std::pair<std::shared_ptr<MediaHandler>,
size_t>>
201 #endif // PACKAGER_MEDIA_BASE_MEDIA_HANDLER_H_