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"
15 namespace edash_packager {
25 kSegmentTemplateField,
30 struct FieldNameToTypeMapping {
31 const char* field_name;
35 const FieldNameToTypeMapping kFieldNameTypeMappings[] = {
36 {
"stream_selector", kStreamSelectorField },
37 {
"stream", kStreamSelectorField },
38 {
"input", kInputField },
39 {
"in", kInputField },
40 {
"output", kOutputField },
41 {
"out", kOutputField },
42 {
"init_segment", kOutputField },
43 {
"segment_template", kSegmentTemplateField },
44 {
"template", kSegmentTemplateField },
45 {
"bandwidth", kBandwidthField },
46 {
"bw", kBandwidthField },
47 {
"bitrate", kBandwidthField },
48 {
"language", kLanguageField },
49 {
"lang", kLanguageField },
52 FieldType GetFieldType(
const std::string& field_name) {
53 for (
size_t idx = 0; idx < arraysize(kFieldNameTypeMappings); ++idx) {
54 if (field_name == kFieldNameTypeMappings[idx].field_name)
55 return kFieldNameTypeMappings[idx].field_type;
62 StreamDescriptor::StreamDescriptor() : bandwidth(0) {}
64 StreamDescriptor::~StreamDescriptor() {}
66 bool InsertStreamDescriptor(
const std::string& descriptor_string,
67 StreamDescriptorList* descriptor_list) {
68 StreamDescriptor descriptor;
71 base::StringPairs pairs;
72 if (!base::SplitStringIntoKeyValuePairs(descriptor_string,
76 LOG(ERROR) <<
"Invalid stream descriptors name/value pairs.";
79 for (base::StringPairs::const_iterator iter = pairs.begin();
80 iter != pairs.end(); ++iter) {
81 switch (GetFieldType(iter->first)) {
82 case kStreamSelectorField:
83 descriptor.stream_selector = iter->second;
86 descriptor.input = iter->second;
89 descriptor.output = iter->second;
91 case kSegmentTemplateField:
92 descriptor.segment_template = iter->second;
94 case kBandwidthField: {
96 if (!base::StringToUint(iter->second, &bw)) {
97 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
100 descriptor.bandwidth = bw;
103 case kLanguageField: {
105 if (language ==
"und") {
106 LOG(ERROR) <<
"Unknown/invalid language specified: " << iter->second;
109 DCHECK_EQ(3u, language.size());
110 descriptor.language = language;
114 LOG(ERROR) <<
"Unknown field in stream descriptor (\"" << iter->first
121 if (descriptor.input.empty()) {
122 LOG(ERROR) <<
"Stream input not specified.";
125 if (!FLAGS_dump_stream_info && descriptor.stream_selector.empty()) {
126 LOG(ERROR) <<
"Stream stream_selector not specified.";
129 if (!FLAGS_dump_stream_info && descriptor.output.empty()) {
130 LOG(ERROR) <<
"Stream output not specified.";
133 descriptor_list->insert(descriptor);
std::string LanguageToISO_639_2(const std::string &language)