7 #include "packager/app/stream_descriptor.h"
9 #include "packager/app/packager_util.h"
10 #include "packager/base/logging.h"
11 #include "packager/base/strings/string_number_conversions.h"
12 #include "packager/base/strings/string_split.h"
13 #include "packager/media/base/container_names.h"
14 #include "packager/mpd/base/language_utils.h"
26 kSegmentTemplateField,
32 kHlsPlaylistNameField,
35 struct FieldNameToTypeMapping {
36 const char* field_name;
40 const FieldNameToTypeMapping kFieldNameTypeMappings[] = {
41 {
"stream_selector", kStreamSelectorField},
42 {
"stream", kStreamSelectorField},
43 {
"input", kInputField},
45 {
"output", kOutputField},
46 {
"out", kOutputField},
47 {
"init_segment", kOutputField},
48 {
"segment_template", kSegmentTemplateField},
49 {
"template", kSegmentTemplateField},
50 {
"bandwidth", kBandwidthField},
51 {
"bw", kBandwidthField},
52 {
"bitrate", kBandwidthField},
53 {
"language", kLanguageField},
54 {
"lang", kLanguageField},
55 {
"output_format", kOutputFormatField},
56 {
"format", kOutputFormatField},
57 {
"hls_name", kHlsNameField},
58 {
"hls_group_id", kHlsGroupIdField},
59 {
"playlist_name", kHlsPlaylistNameField},
62 FieldType GetFieldType(
const std::string& field_name) {
63 for (
size_t idx = 0; idx < arraysize(kFieldNameTypeMappings); ++idx) {
64 if (field_name == kFieldNameTypeMappings[idx].field_name)
65 return kFieldNameTypeMappings[idx].field_type;
72 StreamDescriptor::StreamDescriptor()
73 : bandwidth(0), output_format(CONTAINER_UNKNOWN) {}
75 StreamDescriptor::~StreamDescriptor() {}
77 bool InsertStreamDescriptor(
const std::string& descriptor_string,
78 StreamDescriptorList* descriptor_list) {
79 StreamDescriptor descriptor;
82 base::StringPairs pairs;
83 if (!base::SplitStringIntoKeyValuePairs(descriptor_string,
87 LOG(ERROR) <<
"Invalid stream descriptors name/value pairs.";
90 for (base::StringPairs::const_iterator iter = pairs.begin();
91 iter != pairs.end(); ++iter) {
92 switch (GetFieldType(iter->first)) {
93 case kStreamSelectorField:
94 descriptor.stream_selector = iter->second;
97 descriptor.input = iter->second;
100 descriptor.output = iter->second;
102 case kSegmentTemplateField:
103 descriptor.segment_template = iter->second;
105 case kBandwidthField: {
107 if (!base::StringToUint(iter->second, &bw)) {
108 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
111 descriptor.bandwidth = bw;
114 case kLanguageField: {
116 if (language ==
"und") {
117 LOG(ERROR) <<
"Unknown/invalid language specified: " << iter->second;
120 DCHECK_EQ(3u, language.size());
121 descriptor.language = language;
124 case kOutputFormatField: {
125 MediaContainerName output_format =
126 DetermineContainerFromFormatName(iter->second);
127 if (output_format == CONTAINER_UNKNOWN) {
128 LOG(ERROR) <<
"Unrecognized output format " << iter->second;
131 descriptor.output_format = output_format;
134 case kHlsNameField: {
135 descriptor.hls_name = iter->second;
138 case kHlsGroupIdField: {
139 descriptor.hls_group_id = iter->second;
142 case kHlsPlaylistNameField: {
143 descriptor.hls_playlist_name = iter->second;
147 LOG(ERROR) <<
"Unknown field in stream descriptor (\"" << iter->first
154 if (descriptor.input.empty()) {
155 LOG(ERROR) <<
"Stream input not specified.";
158 if (!FLAGS_dump_stream_info && descriptor.stream_selector.empty()) {
159 LOG(ERROR) <<
"Stream stream_selector not specified.";
163 if (descriptor.output_format == CONTAINER_UNKNOWN) {
164 const std::string& output_name = descriptor.output.empty()
165 ? descriptor.segment_template
167 if (!output_name.empty()) {
168 descriptor.output_format = DetermineContainerFromFileName(output_name);
169 if (descriptor.output_format == CONTAINER_UNKNOWN) {
170 LOG(ERROR) <<
"Unable to determine output format for file "
177 if (descriptor.output_format == MediaContainerName::CONTAINER_MPEG2TS) {
178 if (descriptor.segment_template.empty()) {
179 LOG(ERROR) <<
"Please specify segment_template. Single file TS output is "
185 if (!descriptor.output.empty()) {
186 LOG(WARNING) <<
"TS output '" << descriptor.output
187 <<
"' ignored. TS muxer does not support initialization "
188 "segment generation.";
192 descriptor.output = descriptor.segment_template;
195 if (!FLAGS_dump_stream_info && descriptor.output.empty()) {
196 LOG(ERROR) <<
"Stream output not specified.";
199 descriptor_list->insert(descriptor);
std::string LanguageToISO_639_2(const std::string &language)