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: " 90 for (base::StringPairs::const_iterator iter = pairs.begin();
91 iter != pairs.end(); ++iter) {
92 switch (GetFieldType(iter->first)) {
93 case kStreamSelectorField:
97 descriptor.
input = iter->second;
100 descriptor.
output = iter->second;
102 case kSegmentTemplateField:
105 case kBandwidthField: {
107 if (!base::StringToUint(iter->second, &bw)) {
108 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
109 return base::nullopt;
114 case kLanguageField: {
118 case kOutputFormatField: {
122 case kHlsNameField: {
126 case kHlsGroupIdField: {
130 case kHlsPlaylistNameField: {
134 case kHlsIframePlaylistNameField: {
138 case kTrickPlayFactorField: {
140 if (!base::StringToUint(iter->second, &factor)) {
141 LOG(ERROR) <<
"Non-numeric trick play factor " << iter->second
143 return base::nullopt;
146 LOG(ERROR) <<
"Stream trick_play_factor should be > 0.";
147 return base::nullopt;
152 case kSkipEncryptionField: {
153 unsigned skip_encryption_value;
154 if (!base::StringToUint(iter->second, &skip_encryption_value)) {
155 LOG(ERROR) <<
"Non-numeric option for skip encryption field " 156 "specified (" << iter->second <<
").";
157 return base::nullopt;
159 if (skip_encryption_value > 1) {
160 LOG(ERROR) <<
"skip_encryption should be either 0 or 1.";
161 return base::nullopt;
167 case kDrmStreamLabelField: {
172 LOG(ERROR) <<
"Unknown field in stream descriptor (\"" << iter->first
174 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