7 #include "packager/media/base/media_handler.h"
9 #include "packager/status_macros.h"
14 std::string StreamDataTypeToString(StreamDataType type) {
16 case StreamDataType::kStreamInfo:
18 case StreamDataType::kMediaSample:
19 return "media sample";
20 case StreamDataType::kTextSample:
22 case StreamDataType::kSegmentInfo:
23 return "segment info";
24 case StreamDataType::kScte35Event:
25 return "scte35 event";
26 case StreamDataType::kCueEvent:
28 case StreamDataType::kUnknown:
35 std::shared_ptr<MediaHandler> handler) {
36 if (output_handlers_.find(output_stream_index) != output_handlers_.end()) {
37 return Status(error::ALREADY_EXISTS,
38 "The handler at the specified index already exists.");
40 output_handlers_[output_stream_index] =
41 std::make_pair(handler, handler->num_input_streams_++);
42 next_output_stream_index_ = output_stream_index + 1;
52 for (
auto& pair : output_handlers_) {
54 return Status(error::INVALID_ARGUMENT,
"Invalid output stream index");
55 status = pair.second.first->Initialize();
63 Status MediaHandler::Chain(
64 const std::vector<std::shared_ptr<MediaHandler>>& list) {
65 std::shared_ptr<MediaHandler> previous;
67 for (
const auto& next : list) {
74 RETURN_IF_ERROR(previous->AddHandler(next));
77 previous = std::move(next);
86 const size_t output_stream_index = input_stream_index;
91 return stream_index < num_input_streams_;
95 size_t output_stream_index = stream_data->stream_index;
96 auto handler_it = output_handlers_.find(output_stream_index);
97 if (handler_it == output_handlers_.end()) {
98 return Status(error::NOT_FOUND,
99 "No output handler exist at the specified index.");
101 stream_data->stream_index = handler_it->second.second;
102 return handler_it->second.first->Process(std::move(stream_data));
106 auto handler_it = output_handlers_.find(output_stream_index);
107 if (handler_it == output_handlers_.end()) {
108 return Status(error::NOT_FOUND,
109 "No output handler exist at the specified index.");
111 return handler_it->second.first->OnFlushRequest(handler_it->second.second);
115 for (
const auto& pair : output_handlers_) {
116 Status status = pair.second.first->OnFlushRequest(pair.second.second);