kinesis_video_streamer_test_utils.h
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  */
15 #pragma once
16 
22 
23 using namespace com::amazonaws::kinesis::video;
24 using namespace Aws;
25 using namespace Aws::Client;
26 using namespace Aws::Kinesis;
27 
28 
29 struct TestData
30 {
31  uint32_t get_codec_private_data_call_count = 0;
32  KinesisManagerStatus get_codec_private_data_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
33  uint32_t get_stream_definition_call_count = 0;
34  StreamDefinition * get_stream_definition_return_value = nullptr;
35  uint32_t subscribe_call_count = 0;
37  uint32_t initialize_video_producer_call_count = 0;
38  KinesisManagerStatus initialize_video_producer_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
39  uint32_t initialize_video_stream_call_count = 0;
40  KinesisManagerStatus initialize_video_stream_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
41  uint32_t put_frame_call_count = 0;
43  uint32_t put_metadata_call_count = 0;
45  uint32_t free_stream_call_count = 0;
46  uint32_t kinesis_video_frame_callback_call_count = 0;
47  uint32_t rekognition_kinesis_video_frame_callback_call_count = 0;
48  uint32_t fetch_rekognition_results_call_count = 0;
49  uint32_t image_callback_call_count = 0;
50  uint32_t process_codec_private_data_call_count = 0;
51  KinesisManagerStatus process_codec_private_data_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
52 
53  void Reset()
54  {
55  get_codec_private_data_call_count = 0;
56  get_codec_private_data_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
57  get_stream_definition_call_count = 0;
58  get_stream_definition_return_value = nullptr;
59  subscribe_call_count = 0;
60  subscribe_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
61  initialize_video_producer_call_count = 0;
62  initialize_video_producer_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
63  initialize_video_stream_call_count = 0;
64  initialize_video_stream_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
65  put_frame_call_count = 0;
66  put_frame_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
67  put_metadata_call_count = 0;
68  put_metadata_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
69  free_stream_call_count = 0;
70  kinesis_video_frame_callback_call_count = 0;
71  rekognition_kinesis_video_frame_callback_call_count = 0;
72  fetch_rekognition_results_call_count = 0;
73  image_callback_call_count = 0;
74  process_codec_private_data_call_count = 0;
75  process_codec_private_data_return_value = KINESIS_MANAGER_STATUS_SUCCESS;
76  }
77 };
78 
80 {
82  MockStreamDefinitionProvider(TestData * data) { data_ = data; }
83 
85  const ParameterReaderInterface & reader,
86  PBYTE * out_codec_private_data,
87  uint32_t * out_codec_private_data_size) const override
88  {
91  }
92 
93  std::unique_ptr<StreamDefinition> GetStreamDefinition(const ParameterPath & prefix,
94  const ParameterReaderInterface & reader,
95  const PBYTE codec_private_data,
96  uint32_t codec_private_data_size) const override
97  {
99  return std::unique_ptr<StreamDefinition>(data_->get_stream_definition_return_value);
100  }
101 };
102 
104 {
108  ros::NodeHandle & handle)
109  : data_(data), RosStreamSubscriptionInstaller(handle)
110  {
111  }
112 
113  KinesisManagerStatus Install(const StreamSubscriptionDescriptor & descriptor) const override
114  {
115  data_->subscribe_call_count++;
116  return data_->subscribe_return_value;
117  }
118  void Uninstall(std::string & topic_name) {}
119 };
120 
122 {
123 public:
125 
126  TestParameterReader(std::string test_prefix)
127  {
128  int_map_ = {
129  {test_prefix + "retention_period", 2},
130  {test_prefix + "streaming_type", 0},
131  {test_prefix + "max_latency", 0},
132  {test_prefix + "fragment_duration", 2},
133  {test_prefix + "timecode_scale", 1},
134  {test_prefix + "nal_adaptation_flags",
135  NAL_ADAPTATION_ANNEXB_NALS | NAL_ADAPTATION_ANNEXB_CPD_NALS},
136  {test_prefix + "frame_rate", 24},
137  {test_prefix + "avg_bandwidth_bps", 4 * 1024 * 1024},
138  {test_prefix + "buffer_duration", 120},
139  {test_prefix + "replay_duration", 40},
140  {test_prefix + "connection_staleness", 30},
141  };
142  bool_map_ = {
143  {test_prefix + "key_frame_fragmentation", true}, {test_prefix + "frame_timecodes", true},
144  {test_prefix + "absolute_fragment_time", true}, {test_prefix + "fragment_acks", true},
145  {test_prefix + "restart_on_error", true}, {test_prefix + "recalculate_metrics", true},
146  };
147  string_map_ = {
148  {test_prefix + "stream_name", "testStream"}, {test_prefix + "kms_key_id", ""},
149  {test_prefix + "content_type", "video/h264"}, {test_prefix + "codec_id", "V_MPEG4/ISO/AVC"},
150  {test_prefix + "track_name", "kinesis_video"},
151  };
152  map_map_ = {
153  {test_prefix + "tags", {{"someKey", "someValue"}}},
154  };
155  }
156 
157  TestParameterReader(std::map<std::string, int> int_map, std::map<std::string, bool> bool_map,
158  std::map<std::string, std::string> string_map, std::map<std::string, std::map<std::string, std::string>> map_map)
159  : int_map_(int_map), bool_map_(bool_map), string_map_(string_map), map_map_(map_map)
160  {
161  }
162 
163  AwsError ReadParam(const ParameterPath & param_path, int & out) const override
164  {
165  std::string name = FormatParameterPath(param_path);
166  if (int_map_.count(name) > 0) {
167  out = int_map_.at(name);
168  return AWS_ERR_OK;
169  }
170  return AWS_ERR_NOT_FOUND;
171  }
172 
173  AwsError ReadParam(const ParameterPath & param_path, bool & out) const
174  {
175  std::string name = FormatParameterPath(param_path);
176  if (bool_map_.count(name) > 0) {
177  out = bool_map_.at(name);
178  return AWS_ERR_OK;
179  }
180  return AWS_ERR_NOT_FOUND;
181  }
182 
183  AwsError ReadParam(const ParameterPath & param_path, std::string & out) const
184  {
185  std::string name = FormatParameterPath(param_path);
186  if (string_map_.count(name) > 0) {
187  out = string_map_.at(name);
188  return AWS_ERR_OK;
189  }
190  return AWS_ERR_NOT_FOUND;
191  }
192 
193  AwsError ReadParam(const ParameterPath & param_path, Aws::String & out) const
194  {
195  return AWS_ERR_EMPTY;
196  }
197 
198  AwsError ReadParam(const ParameterPath & param_path, std::map<std::string, std::string> & out) const
199  {
200  std::string name = FormatParameterPath(param_path);
201  if (map_map_.count(name) > 0) {
202  out = map_map_.at(name);
203  return AWS_ERR_OK;
204  }
205  return AWS_ERR_NOT_FOUND;
206  }
207 
208  AwsError ReadParam(const ParameterPath & param_path, std::vector<std::string> & out) const
209  {
210  return AWS_ERR_EMPTY;
211  }
212 
213  AwsError ReadParam(const ParameterPath & param_path, double & out) const
214  {
215  return AWS_ERR_EMPTY;
216  }
217 
218  std::map<std::string, int> int_map_;
219  std::map<std::string, bool> bool_map_;
220  std::map<std::string, std::string> string_map_;
221  std::map<std::string, std::map<std::string, std::string>> map_map_;
222 
223 private:
224  std::string FormatParameterPath(const ParameterPath & param_path) const
225  {
226  return param_path.get_resolved_path('/', '/');
227  }
228 };
229 
231 {
233  MockStreamManager(TestData * data) { data_ = data; }
234 
235  MockStreamManager(TestData * data, TestParameterReader * parameter_reader,
236  StreamDefinitionProvider * stream_definition_provider,
237  StreamSubscriptionInstaller * subscription_installer)
238  : KinesisStreamManagerInterface(parameter_reader, stream_definition_provider,
239  subscription_installer)
240  {
241  data_ = data;
242  }
243 
245  std::string region, std::unique_ptr<DeviceInfoProvider> device_info_provider,
246  std::unique_ptr<ClientCallbackProvider> client_callback_provider,
247  std::unique_ptr<StreamCallbackProvider> stream_callback_provider,
248  std::unique_ptr<CredentialProvider> credential_provider,
249  VideoProducerFactory video_producer_factory) override
250  {
253  }
254 
256  VideoProducerFactory video_producer_factory) override
257  {
260  }
261 
263  std::unique_ptr<StreamDefinition> stream_definition) override
264  {
267  }
268 
269  KinesisManagerStatus PutFrame(std::string stream_name, Frame & frame) const override
270  {
271  data_->put_frame_call_count++;
272  return data_->put_frame_return_value;
273  }
274 
275  KinesisManagerStatus PutMetadata(std::string stream_name, const std::string & name,
276  const std::string & value) const
277  {
278  data_->put_metadata_call_count++;
279  return data_->put_metadata_return_value;
280  }
281 
282  void FreeStream(std::string stream_name) override { data_->free_stream_call_count++; }
283 
285  {
286  return KinesisStreamManagerInterface::KinesisVideoStreamerSetup();
287  }
288 
290  const std::string & stream_name, std::vector<uint8_t> codec_private_data) override
291  {
294  }
295 
296  KinesisManagerStatus FetchRekognitionResults(const std::string & stream_name,
297  Aws::Vector<Model::Record> * records) override
298  {
301  }
302 
304  int stream_idx, StreamSubscriptionDescriptor & descriptor) override
305  {
306  return KinesisStreamManagerInterface::GenerateStreamSubscriptionDescriptor(stream_idx,
307  descriptor);
308  }
309 
311  const StreamSubscriptionDescriptor & descriptor) override
312  {
313  return subscription_installer_->Install(descriptor);
314  }
315 };
KinesisManagerStatus GenerateStreamSubscriptionDescriptor(int stream_idx, StreamSubscriptionDescriptor &descriptor) override
KINESIS_MANAGER_STATUS_SUCCESS
uint32_t initialize_video_stream_call_count
StreamDefinition * get_stream_definition_return_value
KinesisManagerStatus PutMetadata(std::string stream_name, const std::string &name, const std::string &value) const
KinesisManagerStatus GetCodecPrivateData(const ParameterPath &prefix, const ParameterReaderInterface &reader, PBYTE *out_codec_private_data, uint32_t *out_codec_private_data_size) const override
KinesisManagerStatus subscribe_return_value
enum Aws::Kinesis::kinesis_manager_status_e KinesisManagerStatus
KinesisManagerStatus KinesisVideoStreamerSetup() override
MockStreamSubscriptionInstaller(TestData *data, Aws::Kinesis::KinesisStreamManagerInterface &stream_manager, ros::NodeHandle &handle)
KinesisManagerStatus InitializeVideoStream(std::unique_ptr< StreamDefinition > stream_definition) override
KinesisManagerStatus put_metadata_return_value
MockStreamManager(TestData *data, TestParameterReader *parameter_reader, StreamDefinitionProvider *stream_definition_provider, StreamSubscriptionInstaller *subscription_installer)
std::function< std::unique_ptr< KinesisVideoProducerInterface >(std::string, std::unique_ptr< com::amazonaws::kinesis::video::DeviceInfoProvider >, std::unique_ptr< com::amazonaws::kinesis::video::ClientCallbackProvider >, std::unique_ptr< com::amazonaws::kinesis::video::StreamCallbackProvider >, std::unique_ptr< com::amazonaws::kinesis::video::CredentialProvider >)> VideoProducerFactory
KinesisManagerStatus PutFrame(std::string stream_name, Frame &frame) const override
KinesisManagerStatus InitializeVideoProducer(std::string region, VideoProducerFactory video_producer_factory) override
AwsError
uint32_t process_codec_private_data_call_count
KinesisManagerStatus FetchRekognitionResults(const std::string &stream_name, Aws::Vector< Model::Record > *records) override
KinesisManagerStatus get_codec_private_data_return_value
uint32_t initialize_video_producer_call_count
std::string get_resolved_path(char node_namespace_separator, char parameter_namespace_separator) const
AWS_ERR_EMPTY
KinesisManagerStatus put_frame_return_value
uint32_t fetch_rekognition_results_call_count
KinesisManagerStatus initialize_video_producer_return_value
KinesisManagerStatus Install(const StreamSubscriptionDescriptor &descriptor) const override
AWS_ERR_NOT_FOUND
KinesisManagerStatus InitializeVideoProducer(std::string region, std::unique_ptr< DeviceInfoProvider > device_info_provider, std::unique_ptr< ClientCallbackProvider > client_callback_provider, std::unique_ptr< StreamCallbackProvider > stream_callback_provider, std::unique_ptr< CredentialProvider > credential_provider, VideoProducerFactory video_producer_factory) override
void FreeStream(std::string stream_name) override
KinesisManagerStatus initialize_video_stream_return_value
KinesisManagerStatus InitializeStreamSubscription(const StreamSubscriptionDescriptor &descriptor) override
std::unique_ptr< StreamDefinition > GetStreamDefinition(const ParameterPath &prefix, const ParameterReaderInterface &reader, const PBYTE codec_private_data, uint32_t codec_private_data_size) const override
KinesisManagerStatus ProcessCodecPrivateDataForStream(const std::string &stream_name, std::vector< uint8_t > codec_private_data) override
KinesisManagerStatus process_codec_private_data_return_value
AWS_ERR_OK
uint32_t get_codec_private_data_call_count


kinesis_video_streamer
Author(s): AWS RoboMaker
autogenerated on Fri Mar 5 2021 03:29:15