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 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},
62 {
"drm_stream_label", kDrmStreamLabelField},
63 {
"drm_label", kDrmStreamLabelField},
66 FieldType GetFieldType(
const std::string& field_name) {
67 for (
size_t idx = 0; idx < arraysize(kFieldNameTypeMappings); ++idx) {
68 if (field_name == kFieldNameTypeMappings[idx].field_name)
69 return kFieldNameTypeMappings[idx].field_type;
77 const std::string& descriptor_string) {
81 base::StringPairs pairs;
82 if (!base::SplitStringIntoKeyValuePairs(descriptor_string,
'=',
',',
84 LOG(ERROR) <<
"Invalid stream descriptors name/value pairs.";
87 for (base::StringPairs::const_iterator iter = pairs.begin();
88 iter != pairs.end(); ++iter) {
89 switch (GetFieldType(iter->first)) {
90 case kStreamSelectorField:
94 descriptor.
input = iter->second;
97 descriptor.
output = iter->second;
99 case kSegmentTemplateField:
102 case kBandwidthField: {
104 if (!base::StringToUint(iter->second, &bw)) {
105 LOG(ERROR) <<
"Non-numeric bandwidth specified.";
106 return base::nullopt;
111 case kLanguageField: {
115 case kOutputFormatField: {
119 case kHlsNameField: {
123 case kHlsGroupIdField: {
127 case kHlsPlaylistNameField: {
131 case kTrickPlayFactorField: {
133 if (!base::StringToUint(iter->second, &factor)) {
134 LOG(ERROR) <<
"Non-numeric trick play factor " << iter->second
136 return base::nullopt;
139 LOG(ERROR) <<
"Stream trick_play_factor should be > 0.";
140 return base::nullopt;
145 case kSkipEncryptionField: {
146 unsigned skip_encryption_value;
147 if (!base::StringToUint(iter->second, &skip_encryption_value)) {
148 LOG(ERROR) <<
"Non-numeric option for skip encryption field "
149 "specified (" << iter->second <<
").";
150 return base::nullopt;
152 if (skip_encryption_value > 1) {
153 LOG(ERROR) <<
"skip_encryption should be either 0 or 1.";
154 return base::nullopt;
160 case kDrmStreamLabelField: {
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
uint32_t trick_play_factor