7 #include "packager/app/stream_descriptor.h"
9 #include "packager/base/logging.h"
10 #include "packager/base/strings/string_number_conversions.h"
11 #include "packager/base/strings/string_split.h"
12 #include "packager/media/base/language_utils.h"
23 kSegmentTemplateField,
29 kHlsPlaylistNameField,
30 kTrickPlayFactorField,
34 struct FieldNameToTypeMapping {
35 const char* field_name;
39 const FieldNameToTypeMapping kFieldNameTypeMappings[] = {
40 {
"stream_selector", kStreamSelectorField},
41 {
"stream", kStreamSelectorField},
42 {
"input", kInputField},
44 {
"output", kOutputField},
45 {
"out", kOutputField},
46 {
"init_segment", kOutputField},
47 {
"segment_template", kSegmentTemplateField},
48 {
"template", kSegmentTemplateField},
49 {
"bandwidth", kBandwidthField},
50 {
"bw", kBandwidthField},
51 {
"bitrate", kBandwidthField},
52 {
"language", kLanguageField},
53 {
"lang", kLanguageField},
54 {
"output_format", kOutputFormatField},
55 {
"format", kOutputFormatField},
56 {
"hls_name", kHlsNameField},
57 {
"hls_group_id", kHlsGroupIdField},
58 {
"playlist_name", kHlsPlaylistNameField},
59 {
"trick_play_factor", kTrickPlayFactorField},
60 {
"tpf", kTrickPlayFactorField},
61 {
"skip_encryption", kSkipEncryptionField},
64 FieldType GetFieldType(
const std::string& field_name) {
65 for (
size_t idx = 0; idx < arraysize(kFieldNameTypeMappings); ++idx) {
66 if (field_name == kFieldNameTypeMappings[idx].field_name)
67 return kFieldNameTypeMappings[idx].field_type;
75 const std::string& descriptor_string) {
79 base::StringPairs pairs;
80 if (!base::SplitStringIntoKeyValuePairs(descriptor_string,
'=',
',',
82 LOG(ERROR) <<
"Invalid stream descriptors name/value pairs.";
85 for (base::StringPairs::const_iterator iter = pairs.begin();
86 iter != pairs.end(); ++iter) {
87 switch (GetFieldType(iter->first)) {
88 case kStreamSelectorField:
92 descriptor.
input = iter->second;
95 descriptor.
output = iter->second;
97 case kSegmentTemplateField:
100 case kBandwidthField: {
102 if (!base::StringToUint(iter->second, &bw)) {
103 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
104 return base::nullopt;
109 case kLanguageField: {
112 if (language ==
"und") {
113 LOG(ERROR) <<
"Unknown/invalid language specified: " << iter->second;
114 return base::nullopt;
119 case kOutputFormatField: {
123 case kHlsNameField: {
127 case kHlsGroupIdField: {
131 case kHlsPlaylistNameField: {
135 case kTrickPlayFactorField: {
137 if (!base::StringToUint(iter->second, &factor)) {
138 LOG(ERROR) <<
"Non-numeric trick play factor " << iter->second
140 return base::nullopt;
143 LOG(ERROR) <<
"Stream trick_play_factor should be > 0.";
144 return base::nullopt;
149 case kSkipEncryptionField: {
150 unsigned skip_encryption_value;
151 if (!base::StringToUint(iter->second, &skip_encryption_value)) {
152 LOG(ERROR) <<
"Non-numeric option for skip encryption field "
153 "specified (" << iter->second <<
").";
154 return base::nullopt;
156 if (skip_encryption_value > 1) {
157 LOG(ERROR) <<
"skip_encryption should be either 0 or 1.";
158 return base::nullopt;
165 LOG(ERROR) <<
"Unknown field in stream descriptor (\"" << iter->first
167 return base::nullopt;
std::string stream_selector
Defines a single input/output stream.
std::string input
Input/source media file path or network stream URL. Required.
std::string hls_playlist_name
base::Optional< StreamDescriptor > ParseStreamDescriptor(const std::string &descriptor_string)
std::string segment_template
Specifies segment template. Can be empty.
std::string output_format
std::string LanguageToISO_639_2(const std::string &language)
uint32_t trick_play_factor