Skip to content

Commit 7eb25a5

Browse files
committed
Enforce non-zero TrackUid and SegmentUUID
1 parent 286bebf commit 7eb25a5

19 files changed

+313
-54
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ This library is licensed under the Amazon Software License.
4545
----
4646
### Release notes
4747

48+
#### Release 1.7.3 (12th Feb 2019)
49+
* Enforce non-zero TrackUid and SegmentUUID.
50+
4851
#### Release 1.7.2 (8th Feb 2019)
4952
* JNI free object logic fix used by Java KVS SDK.
5053

kinesis-video-gst-demo/kinesis_video_gstreamer_audio_video_sample_app.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ LOGGER_TAG("com.amazonaws.kinesis.video.gstreamer");
6464
#define DEFAULT_CREDENTIAL_EXPIRATION_SECONDS 180
6565
#define DEFAULT_AUDIO_VIDEO_DRIFT_TIMEOUT_SECOND 5
6666

67-
#define DEFAULT_VIDEO_TRACKID 0
67+
#define DEFAULT_VIDEO_TRACKID 1
6868
#define DEFAULT_AUDIO_TRACK_NAME "audio"
6969
#define DEFAULT_AUDIO_CODEC_ID "A_AAC"
70-
#define DEFAULT_AUDIO_TRACKID 1
70+
#define DEFAULT_AUDIO_TRACKID 2
7171

7272

7373
typedef struct _FileInfo {
@@ -703,7 +703,10 @@ void kinesis_video_stream_init(CustomData *data) {
703703
DEFAULT_CODEC_ID,
704704
DEFAULT_TRACKNAME,
705705
nullptr,
706-
0);
706+
0,
707+
MKV_TRACK_INFO_TYPE_VIDEO,
708+
vector<uint8_t>(),
709+
DEFAULT_VIDEO_TRACKID);
707710

708711
stream_definition->addTrack(DEFAULT_AUDIO_TRACKID, DEFAULT_AUDIO_TRACK_NAME, DEFAULT_AUDIO_CODEC_ID, MKV_TRACK_INFO_TYPE_AUDIO);
709712
data->kinesis_video_stream = data->kinesis_video_producer->createStreamSync(move(stream_definition));
@@ -751,8 +754,8 @@ int gstreamer_init(int argc, char *argv[], CustomData &data) {
751754
gst_caps_unref(caps);
752755

753756
// hardcoding appsink name and track id
754-
const string video_appsink_name = "appsink_0";
755-
const string audio_appsink_name = "appsink_1";
757+
const string video_appsink_name = "appsink_" + to_string(DEFAULT_VIDEO_TRACKID);
758+
const string audio_appsink_name = "appsink_" + to_string(DEFAULT_AUDIO_TRACKID);
756759

757760
appsink_video = gst_element_factory_make("appsink", (gchar *) video_appsink_name.c_str());
758761
appsink_audio = gst_element_factory_make("appsink", (gchar *) audio_appsink_name.c_str());

kinesis-video-gstreamer-plugin/plugin-src/gstkvssink.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_kvs_sink_debug);
130130

131131
#define DEFAULT_AUDIO_TRACK_NAME "audio"
132132
#define DEFAULT_AUDIO_CODEC_ID "A_AAC"
133-
#define DEFAULT_VIDEO_TRACKID 0
134-
#define DEFAULT_AUDIO_TRACKID 1
133+
#define KVS_SINK_DEFAULT_TRACKID 1
134+
#define KVS_SINK_DEFAULT_AUDIO_TRACKID 2
135135

136136
enum {
137137
PROP_0,
@@ -388,10 +388,12 @@ void create_kinesis_video_stream(GstKvsSink *kvssink) {
388388
kvssink->track_name,
389389
nullptr,
390390
0,
391-
kvssink->track_info_type);
391+
kvssink->track_info_type,
392+
vector<uint8_t>(),
393+
KVS_SINK_DEFAULT_TRACKID);
392394

393395
if (data->media_type == AUDIO_VIDEO) {
394-
stream_definition->addTrack(DEFAULT_AUDIO_TRACKID, DEFAULT_AUDIO_TRACK_NAME, DEFAULT_AUDIO_CODEC_ID, MKV_TRACK_INFO_TYPE_AUDIO);
396+
stream_definition->addTrack(KVS_SINK_DEFAULT_AUDIO_TRACKID, DEFAULT_AUDIO_TRACK_NAME, DEFAULT_AUDIO_CODEC_ID, MKV_TRACK_INFO_TYPE_AUDIO);
395397
}
396398

397399
data->kinesis_video_stream = data->kinesis_video_producer->createStreamSync(move(stream_definition));
@@ -1095,6 +1097,7 @@ gst_kvs_sink_handle_buffer (GstCollectPads * pads,
10951097
goto CleanUp;
10961098
}
10971099

1100+
//LOG_DEBUG("flags" << GST_BUFFER_FLAGS(buf));
10981101
isDroppable = GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_CORRUPTED) ||
10991102
GST_BUFFER_FLAG_IS_SET(buf, GST_BUFFER_FLAG_DECODE_ONLY) ||
11001103
(!GST_BUFFER_PTS_IS_VALID(buf)); //frame with invalid pts cannot be processed.
@@ -1134,13 +1137,10 @@ gst_kvs_sink_handle_buffer (GstCollectPads * pads,
11341137
}
11351138
break;
11361139
case AUDIO_VIDEO:
1137-
if(!delta) {
1138-
// Set key frame flag on first key frame. No matter audio or video.
1139-
// After that set key frame flag on video key frame only.
1140-
if (data->first_key_frame) {
1141-
data->first_key_frame = false;
1142-
kinesis_video_flags = FRAME_FLAG_KEY_FRAME;
1143-
} else if (kvs_sink_track_data->track_type == MKV_TRACK_INFO_TYPE_VIDEO) {
1140+
if(!delta && kvs_sink_track_data->track_type == MKV_TRACK_INFO_TYPE_VIDEO) {
1141+
if (data->first_video_frame) {
1142+
data->first_video_frame = false;
1143+
} else {
11441144
kinesis_video_flags = FRAME_FLAG_KEY_FRAME;
11451145
}
11461146
}
@@ -1267,7 +1267,7 @@ gst_kvs_sink_request_new_pad (GstElement * element, GstPadTemplate * templ,
12671267
NULL, locked);
12681268
kvs_sink_track_data->kvssink = kvssink;
12691269
kvs_sink_track_data->track_type = track_type;
1270-
kvs_sink_track_data->track_id = DEFAULT_TRACK_ID;
1270+
kvs_sink_track_data->track_id = KVS_SINK_DEFAULT_TRACKID;
12711271

12721272
if (!gst_element_add_pad (element, GST_PAD (newpad))) {
12731273
gst_object_unref (newpad);
@@ -1323,8 +1323,8 @@ assign_track_id(GstKvsSink *kvssink) {
13231323

13241324
// set up track id in kvs_sink_track_data
13251325
kvs_sink_track_data->track_id = kvs_sink_track_data->track_type == MKV_TRACK_INFO_TYPE_AUDIO ?
1326-
DEFAULT_AUDIO_TRACKID :
1327-
DEFAULT_VIDEO_TRACKID;
1326+
KVS_SINK_DEFAULT_AUDIO_TRACKID :
1327+
KVS_SINK_DEFAULT_TRACKID;
13281328
}
13291329
}
13301330
}

kinesis-video-gstreamer-plugin/plugin-src/gstkvssink.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ typedef struct _CustomData {
168168
last_dts(0),
169169
pts_base(0),
170170
media_type(VIDEO_ONLY),
171-
first_key_frame(true) {}
171+
first_video_frame(true) {}
172172
unique_ptr<KinesisVideoProducer> kinesis_video_producer;
173173
shared_ptr<KinesisVideoStream> kinesis_video_stream;
174174
shared_ptr<CallbackStateMachine> callback_state_machine;
175175
map<uint64_t, string> track_cpd;
176176
GstKvsSink *kvsSink;
177177
bool stream_created = false;
178178
MediaType media_type;
179-
bool first_key_frame;
179+
bool first_video_frame;
180180

181181
atomic_bool stream_ready;
182182
atomic_uint stream_status;

kinesis-video-pic/src/client/src/AuthIntegration.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ UINT64 getCurrentAuthExpiration(PKinesisVideoClient pKinesisVideoClient)
106106
return expiration;
107107
}
108108

109+
/**
110+
* Randomizing or adding a jitter to the auth info expiration.
111+
*
112+
* NOTE: The parameters are assumed to have been validated
113+
*/
114+
UINT64 randomizeAuthInfoExpiration(PKinesisVideoClient pKinesisVideoClient, UINT64 expiration, UINT64 currentTime)
115+
{
116+
UINT64 jitterInSec = (UINT64) ((expiration - currentTime) * AUTH_INFO_EXPIRATION_JITTER_RATIO / HUNDREDS_OF_NANOS_IN_A_SECOND);
117+
118+
// Quick check whether we need to do anything
119+
if (!ENABLE_AUTH_INFO_EXPIRATION_RANDOMIZATION ||
120+
jitterInSec == 0 ||
121+
currentTime + AUTH_INFO_EXPIRATION_RANDOMIZATION_DURATION_THRESHOLD > expiration) {
122+
return expiration;
123+
}
124+
125+
// Calculate the jitter and take random part.
126+
UINT64 randomizedJitter = pKinesisVideoClient->clientCallbacks.getRandomNumberFn(
127+
pKinesisVideoClient->clientCallbacks.customData) % jitterInSec;
128+
129+
// Ensure no more than max jitter is applied
130+
UINT64 jitter = MIN(randomizedJitter * HUNDREDS_OF_NANOS_IN_A_SECOND, MAX_AUTH_INFO_EXPIRATION_RANDOMIZATION);
131+
132+
return expiration - jitter;
133+
}
134+
109135
/**
110136
* Performs the producer client provisioning
111137
* NOTE: This is a long running operation

kinesis-video-pic/src/client/src/Include_i.h

+25
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,26 @@ typedef __KinesisVideoBase* PKinesisVideoBase;
199199
(x)->streamInfo.streamCaps.fragmentAcks && \
200200
(x)->streamInfo.retention != RETENTION_PERIOD_SENTINEL)
201201

202+
/**
203+
* Controls whether we enable auth info expiration randomization
204+
*/
205+
#define ENABLE_AUTH_INFO_EXPIRATION_RANDOMIZATION TRUE
206+
207+
/**
208+
* The threshold beyond which we won't do any auth info expiration randomization
209+
*/
210+
#define AUTH_INFO_EXPIRATION_RANDOMIZATION_DURATION_THRESHOLD 5 * HUNDREDS_OF_NANOS_IN_A_MINUTE
211+
212+
/**
213+
* Max randomization value to be added
214+
*/
215+
#define MAX_AUTH_INFO_EXPIRATION_RANDOMIZATION 3 * HUNDREDS_OF_NANOS_IN_A_MINUTE
216+
217+
/**
218+
* Ratio of the expiration to use for jitter
219+
*/
220+
#define AUTH_INFO_EXPIRATION_JITTER_RATIO 0.1L
221+
202222
/**
203223
* Kinesis Video client internal structure
204224
*/
@@ -278,6 +298,11 @@ STATUS provisionKinesisVideoProducer(PKinesisVideoClient);
278298
*/
279299
AUTH_INFO_TYPE getCurrentAuthType(PKinesisVideoClient);
280300

301+
/**
302+
* Randomizing or adding a jitter to the auth info expiration
303+
*/
304+
UINT64 randomizeAuthInfoExpiration(PKinesisVideoClient, UINT64, UINT64);
305+
281306
/**
282307
* Default implementations of some of the callbacks if the caller hasn't specified them
283308
*/

kinesis-video-pic/src/client/src/StreamEvent.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ STATUS getStreamingTokenResult(PKinesisVideoStream pKinesisVideoStream, SERVICE_
311311
// Ensure that we rotate before the max period is enforced
312312
pKinesisVideoStream->streamingAuthInfo.expiration = MIN(expiration, currentTime + MAX_ENFORCED_TOKEN_EXPIRATION_DURATION);
313313

314+
// Introduce jitter to the expiration time
315+
pKinesisVideoStream->streamingAuthInfo.expiration = randomizeAuthInfoExpiration(pKinesisVideoClient,
316+
pKinesisVideoStream->streamingAuthInfo.expiration,
317+
currentTime);
318+
314319
// If we don't have a token we assume there is no auth.
315320
if (pToken == NULL || tokenSize == 0) {
316321
pKinesisVideoStream->streamingAuthInfo.type = AUTH_INFO_NONE;

kinesis-video-pic/src/client/tst/ClientTestFixture.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ UINT64 ClientTestBase::getCurrentTimeFunc(UINT64 customData)
1717
return pClient->mTime;
1818
}
1919

20+
// Global variable which is used as a preset time
21+
UINT64 gPresetCurrentTime = 0;
22+
UINT64 ClientTestBase::getCurrentPresetTimeFunc(UINT64 customData)
23+
{
24+
DLOGV("TID 0x%016llx getCurrentPresetTimeFunc called.", GETTID());
25+
26+
ClientTestBase *pClient = (ClientTestBase*) customData;
27+
EXPECT_TRUE(pClient != NULL && pClient->mMagic == TEST_CLIENT_MAGIC_NUMBER);
28+
29+
pClient->mGetCurrentTimeFuncCount++;
30+
pClient->mTime = gPresetCurrentTime;
31+
32+
// Increment the preset time
33+
gPresetCurrentTime++;
34+
35+
return pClient->mTime;
36+
}
37+
2038
UINT32 ClientTestBase::getRandomNumberFunc(UINT64 customData)
2139
{
2240
DLOGV("TID 0x%016llx getRandomNumberFunc called.", GETTID());
@@ -29,6 +47,9 @@ UINT32 ClientTestBase::getRandomNumberFunc(UINT64 customData)
2947
return RAND();
3048
}
3149

50+
// Global variable which is used for the random function that returns constant value for testing
51+
UINT32 gConstReturnFromRandomFunction = TEST_CONST_RAND_FUNC_BYTE;
52+
3253
UINT32 ClientTestBase::getRandomNumberConstFunc(UINT64 customData)
3354
{
3455
DLOGV("TID 0x%016llx getRandomNumberConstFunc called.", GETTID());
@@ -38,7 +59,7 @@ UINT32 ClientTestBase::getRandomNumberConstFunc(UINT64 customData)
3859

3960
pClient->mGetRandomNumberFuncCount++;
4061

41-
return TEST_CONST_RAND_FUNC_BYTE;
62+
return gConstReturnFromRandomFunction;
4263
}
4364

4465
VOID ClientTestBase::logPrintFunc(UINT32 level, PCHAR tag, PCHAR fmt, ...)

kinesis-video-pic/src/client/tst/ClientTestFixture.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#define TEST_CONTENT_TYPE ((PCHAR) "TestContentType")
2424
#define TEST_CODEC_ID ((PCHAR) "TestCodec")
2525
#define TEST_TRACK_NAME ((PCHAR) "TestTrack")
26-
#define TEST_TRACKID 0
26+
#define TEST_TRACKID 1
27+
#define TEST_TRACK_INDEX 0
28+
#define TEST_INVALID_TRACK_ID 100
2729

2830
#define TEST_DEVICE_ARN ((PCHAR) "TestDeviceARN")
2931

@@ -578,6 +580,7 @@ class ClientTestBase : public ::testing::Test {
578580
// Static callbacks definitions
579581
//////////////////////////////////////////////////////////////////////////////////////
580582
static UINT64 getCurrentTimeFunc(UINT64);
583+
static UINT64 getCurrentPresetTimeFunc(UINT64);
581584
static UINT32 getRandomNumberFunc(UINT64);
582585
static UINT32 getRandomNumberConstFunc(UINT64);
583586
static VOID logPrintFunc(UINT32, PCHAR, PCHAR, ...);

0 commit comments

Comments
 (0)