7#include <packager/media/base/media_handler.h>
15#include <packager/macros/status.h>
16#include <packager/status.h>
21std::string StreamDataTypeToString(StreamDataType type) {
23 case StreamDataType::kStreamInfo:
25 case StreamDataType::kMediaSample:
26 return "media sample";
27 case StreamDataType::kTextSample:
29 case StreamDataType::kSegmentInfo:
30 return "segment info";
31 case StreamDataType::kScte35Event:
32 return "scte35 event";
33 case StreamDataType::kCueEvent:
35 case StreamDataType::kUnknown:
42 std::shared_ptr<MediaHandler> handler) {
43 if (output_handlers_.find(output_stream_index) != output_handlers_.end()) {
44 return Status(error::ALREADY_EXISTS,
45 "The handler at the specified index already exists.");
47 output_handlers_[output_stream_index] =
48 std::make_pair(handler, handler->num_input_streams_++);
49 next_output_stream_index_ = output_stream_index + 1;
59 for (
auto& pair : output_handlers_) {
61 return Status(error::INVALID_ARGUMENT,
"Invalid output stream index");
62 status = pair.second.first->Initialize();
70Status MediaHandler::Chain(
71 const std::vector<std::shared_ptr<MediaHandler>>& list) {
72 std::shared_ptr<MediaHandler> previous;
74 for (
const auto& next : list) {
81 RETURN_IF_ERROR(previous->AddHandler(next));
84 previous = std::move(next);
93 const size_t output_stream_index = input_stream_index;
98 return stream_index < num_input_streams_;
102 size_t output_stream_index = stream_data->stream_index;
103 auto handler_it = output_handlers_.find(output_stream_index);
104 if (handler_it == output_handlers_.end()) {
105 return Status(error::NOT_FOUND,
106 "No output handler exist at the specified index.");
108 stream_data->stream_index = handler_it->second.second;
109 return handler_it->second.first->Process(std::move(stream_data));
113 auto handler_it = output_handlers_.find(output_stream_index);
114 if (handler_it == output_handlers_.end()) {
115 return Status(error::NOT_FOUND,
116 "No output handler exist at the specified index.");
118 return handler_it->second.first->OnFlushRequest(handler_it->second.second);
122 for (
const auto& pair : output_handlers_) {
123 Status status = pair.second.first->OnFlushRequest(pair.second.second);
All the methods that are virtual are virtual for mocking.