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/mpd/base/language_utils.h"
25 kSegmentTemplateField,
31 struct FieldNameToTypeMapping {
32 const char* field_name;
36 const FieldNameToTypeMapping kFieldNameTypeMappings[] = {
37 {
"stream_selector", kStreamSelectorField },
38 {
"stream", kStreamSelectorField },
39 {
"input", kInputField },
40 {
"in", kInputField },
41 {
"output", kOutputField },
42 {
"out", kOutputField },
43 {
"init_segment", kOutputField },
44 {
"segment_template", kSegmentTemplateField },
45 {
"template", kSegmentTemplateField },
46 {
"bandwidth", kBandwidthField },
47 {
"bw", kBandwidthField },
48 {
"bitrate", kBandwidthField },
49 {
"language", kLanguageField },
50 {
"lang", kLanguageField },
51 {
"output_format", kOutputFormatField },
52 {
"format", kOutputFormatField },
55 FieldType GetFieldType(
const std::string& field_name) {
56 for (
size_t idx = 0; idx < arraysize(kFieldNameTypeMappings); ++idx) {
57 if (field_name == kFieldNameTypeMappings[idx].field_name)
58 return kFieldNameTypeMappings[idx].field_type;
65 StreamDescriptor::StreamDescriptor()
66 : bandwidth(0), output_format(CONTAINER_UNKNOWN) {}
68 StreamDescriptor::~StreamDescriptor() {}
70 bool InsertStreamDescriptor(
const std::string& descriptor_string,
71 StreamDescriptorList* descriptor_list) {
72 StreamDescriptor descriptor;
75 base::StringPairs pairs;
76 if (!base::SplitStringIntoKeyValuePairs(descriptor_string,
80 LOG(ERROR) <<
"Invalid stream descriptors name/value pairs.";
83 for (base::StringPairs::const_iterator iter = pairs.begin();
84 iter != pairs.end(); ++iter) {
85 switch (GetFieldType(iter->first)) {
86 case kStreamSelectorField:
87 descriptor.stream_selector = iter->second;
90 descriptor.input = iter->second;
93 descriptor.output = iter->second;
95 case kSegmentTemplateField:
96 descriptor.segment_template = iter->second;
98 case kBandwidthField: {
100 if (!base::StringToUint(iter->second, &bw)) {
101 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
104 descriptor.bandwidth = bw;
107 case kLanguageField: {
109 if (language ==
"und") {
110 LOG(ERROR) <<
"Unknown/invalid language specified: " << iter->second;
113 DCHECK_EQ(3u, language.size());
114 descriptor.language = language;
117 case kOutputFormatField: {
118 MediaContainerName output_format =
119 DetermineContainerFromFormatName(iter->second);
120 if (output_format == CONTAINER_UNKNOWN) {
121 LOG(ERROR) <<
"Unrecognized output format " << iter->second;
124 descriptor.output_format = output_format;
128 LOG(ERROR) <<
"Unknown field in stream descriptor (\"" << iter->first
135 if (descriptor.input.empty()) {
136 LOG(ERROR) <<
"Stream input not specified.";
139 if (!FLAGS_dump_stream_info && descriptor.stream_selector.empty()) {
140 LOG(ERROR) <<
"Stream stream_selector not specified.";
143 if (!FLAGS_dump_stream_info && descriptor.output.empty()) {
144 LOG(ERROR) <<
"Stream output not specified.";
147 descriptor_list->insert(descriptor);
std::string LanguageToISO_639_2(const std::string &language)