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" 22 kSegmentTemplateField,
28 kHlsPlaylistNameField,
29 kHlsIframePlaylistNameField,
30 kTrickPlayFactorField,
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},
60 {
"iframe_playlist_name", kHlsIframePlaylistNameField},
61 {
"trick_play_factor", kTrickPlayFactorField},
62 {
"tpf", kTrickPlayFactorField},
63 {
"skip_encryption", kSkipEncryptionField},
64 {
"drm_stream_label", kDrmStreamLabelField},
65 {
"drm_label", kDrmStreamLabelField},
68 FieldType GetFieldType(
const std::string& field_name) {
69 for (
size_t idx = 0; idx < arraysize(kFieldNameTypeMappings); ++idx) {
70 if (field_name == kFieldNameTypeMappings[idx].field_name)
71 return kFieldNameTypeMappings[idx].field_type;
79 const std::string& descriptor_string) {
83 base::StringPairs pairs;
84 if (!base::SplitStringIntoKeyValuePairs(descriptor_string,
'=',
',',
86 LOG(ERROR) <<
"Invalid stream descriptors name/value pairs.";
89 for (base::StringPairs::const_iterator iter = pairs.begin();
90 iter != pairs.end(); ++iter) {
91 switch (GetFieldType(iter->first)) {
92 case kStreamSelectorField:
96 descriptor.
input = iter->second;
99 descriptor.
output = iter->second;
101 case kSegmentTemplateField:
104 case kBandwidthField: {
106 if (!base::StringToUint(iter->second, &bw)) {
107 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
108 return base::nullopt;
113 case kLanguageField: {
117 case kOutputFormatField: {
121 case kHlsNameField: {
125 case kHlsGroupIdField: {
129 case kHlsPlaylistNameField: {
133 case kHlsIframePlaylistNameField: {
137 case kTrickPlayFactorField: {
139 if (!base::StringToUint(iter->second, &factor)) {
140 LOG(ERROR) <<
"Non-numeric trick play factor " << iter->second
142 return base::nullopt;
145 LOG(ERROR) <<
"Stream trick_play_factor should be > 0.";
146 return base::nullopt;
151 case kSkipEncryptionField: {
152 unsigned skip_encryption_value;
153 if (!base::StringToUint(iter->second, &skip_encryption_value)) {
154 LOG(ERROR) <<
"Non-numeric option for skip encryption field " 155 "specified (" << iter->second <<
").";
156 return base::nullopt;
158 if (skip_encryption_value > 1) {
159 LOG(ERROR) <<
"skip_encryption should be either 0 or 1.";
160 return base::nullopt;
166 case kDrmStreamLabelField: {
171 LOG(ERROR) <<
"Unknown field in stream descriptor (\"" << iter->first
173 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
All the methods that are virtual are virtual for mocking.
uint32_t trick_play_factor
std::string hls_iframe_playlist_name