stream_definition_provider.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
16 #include <com/amazonaws/kinesis/video/utils/Include.h>
18 
19 using namespace com::amazonaws::kinesis::video;
20 using namespace Aws::Client;
21 
22 
23 #define STREAM_DEFINITION_MAX_CODEC_PRIVATE_DATA_SIZE (1024)
24 
25 
26 namespace Aws {
27 namespace Kinesis {
28 
29 using namespace std;
30 using namespace std::chrono;
31 
32 KinesisManagerStatus StreamDefinitionProvider::GetCodecPrivateData(
33  const ParameterPath & prefix, const ParameterReaderInterface & reader,
34  PBYTE * out_codec_private_data, uint32_t * out_codec_private_data_size) const
35 {
36  if (nullptr == out_codec_private_data ||
37  nullptr == out_codec_private_data_size) {
39  }
40  std::string b64_encoded_codec_private_data;
41  reader.ReadParam(prefix + "codecPrivateData", b64_encoded_codec_private_data);
42  if (!b64_encoded_codec_private_data.empty()) {
43  uint8_t temp_codec_data[STREAM_DEFINITION_MAX_CODEC_PRIVATE_DATA_SIZE] = {0};
44  uint32_t decoded_buffer_size = sizeof(temp_codec_data);
45  if (STATUS_SUCCESS != base64Decode(const_cast<char *>(b64_encoded_codec_private_data.c_str()),
46  temp_codec_data, &decoded_buffer_size)) {
48  }
49  PBYTE codec_private_data = (PBYTE)malloc(decoded_buffer_size);
50  if (nullptr == codec_private_data) {
52  }
53  memset(codec_private_data, 0, decoded_buffer_size);
54  memcpy(codec_private_data, temp_codec_data, decoded_buffer_size);
55  *out_codec_private_data = codec_private_data;
56  *out_codec_private_data_size = decoded_buffer_size;
57  }
59 }
60 
61 unique_ptr<StreamDefinition> StreamDefinitionProvider::GetStreamDefinition(
62  const ParameterPath & prefix, const ParameterReaderInterface & reader,
63  const PBYTE codec_private_data, uint32_t codec_private_data_size) const
64 {
65  if (nullptr == codec_private_data && 0 != codec_private_data_size) {
66  return unique_ptr<StreamDefinition>{};
67  }
68 
69  std::string stream_name = "default";
70  reader.ReadParam(prefix + "stream_name", stream_name);
71 
72  map<string, string> tags;
73  reader.ReadParam(prefix + "tags", tags);
74 
75  int retention_period = 2;
76  reader.ReadParam(prefix + "retention_period", retention_period);
77 
78  std::string kms_key_id;
79  reader.ReadParam(prefix + "kms_key_id", kms_key_id);
80 
81  int streaming_type_id = 0;
82  reader.ReadParam(prefix + "streaming_type", streaming_type_id);
83  STREAMING_TYPE streaming_type = static_cast<STREAMING_TYPE>(streaming_type_id);
84 
85  std::string content_type = "video/h264";
86  reader.ReadParam(prefix + "content_type", content_type);
87 
88 
89  int max_latency = 0;
90  reader.ReadParam(prefix + "max_latency", max_latency);
91 
92  int fragment_duration = 2;
93  reader.ReadParam(prefix + "fragment_duration", fragment_duration);
94 
95  int timecode_scale = 1;
96  reader.ReadParam(prefix + "timecode_scale", timecode_scale);
97 
98  bool key_frame_fragmentation = true;
99  reader.ReadParam(prefix + "key_frame_fragmentation", key_frame_fragmentation);
100 
101  bool frame_timecodes = true;
102  reader.ReadParam(prefix + "frame_timecodes", frame_timecodes);
103 
104  bool absolute_fragment_time = true;
105  reader.ReadParam(prefix + "absolute_fragment_time", absolute_fragment_time);
106 
107  bool fragment_acks = true;
108  reader.ReadParam(prefix + "fragment_acks", fragment_acks);
109 
110  bool restart_on_error = true;
111  reader.ReadParam(prefix + "restart_on_error", restart_on_error);
112 
113  bool recalculate_metrics = true;
114  reader.ReadParam(prefix + "recalculate_metrics", recalculate_metrics);
115 
116  int nal_adaptation_flag_id = NAL_ADAPTATION_ANNEXB_NALS | NAL_ADAPTATION_ANNEXB_CPD_NALS;
117  reader.ReadParam(prefix + "nal_adaptation_flags", nal_adaptation_flag_id);
118  NAL_ADAPTATION_FLAGS nal_adaptation_flags =
119  static_cast<NAL_ADAPTATION_FLAGS>(nal_adaptation_flag_id);
120 
121  int frame_rate = 24;
122  reader.ReadParam(prefix + "frame_rate", frame_rate);
123 
124  int avg_bandwidth_bps = 4 * 1024 * 1024;
125  reader.ReadParam(prefix + "avg_bandwidth_bps", avg_bandwidth_bps);
126 
127  int buffer_duration = 120;
128  reader.ReadParam(prefix + "buffer_duration", buffer_duration);
129 
130  int replay_duration = 40;
131  reader.ReadParam(prefix + "replay_duration", replay_duration);
132 
133  int connection_staleness = 30;
134  reader.ReadParam(prefix + "connection_staleness", connection_staleness);
135 
136  std::string codec_id = "V_MPEG4/ISO/AVC";
137  reader.ReadParam(prefix + "codec_id", codec_id);
138 
139  std::string track_name = "kinesis_video";
140  reader.ReadParam(prefix + "track_name", track_name);
141 
142 
143  auto stream_definition = make_unique<StreamDefinition>(
144  stream_name, hours(retention_period), &tags, kms_key_id, streaming_type, content_type,
145  milliseconds(max_latency), seconds(fragment_duration), milliseconds(timecode_scale),
146  key_frame_fragmentation, frame_timecodes, absolute_fragment_time, fragment_acks,
147  restart_on_error, recalculate_metrics, nal_adaptation_flags, frame_rate, avg_bandwidth_bps,
148  seconds(buffer_duration), seconds(replay_duration), seconds(connection_staleness), codec_id,
149  track_name, codec_private_data, codec_private_data_size);
150  return stream_definition;
151 }
152 } // namespace Kinesis
153 } // namespace Aws
enum Aws::Kinesis::kinesis_manager_status_e KinesisManagerStatus
#define STREAM_DEFINITION_MAX_CODEC_PRIVATE_DATA_SIZE
virtual AwsError ReadParam(const ParameterPath &param_path, std::vector< std::string > &out) const =0
const char * stream_name
Definition: common.h:80
const char * prefix
Definition: common.h:73


kinesis_manager
Author(s): AWS RoboMaker
autogenerated on Thu Mar 4 2021 03:28:41