aws-samples / amazon-kinesis-video-streams-producer-embedded-c

Light-wight Amazon Kinesis Video Streams Producer SDK For FreeRTOS/Embedded Linux
Apache License 2.0
29 stars 18 forks source link

Fix audio and video out of order in timestamp #19

Closed weichihl closed 2 years ago

weichihl commented 2 years ago

KVS requires cluster's timestamp should larger than previous timestamp.

If we have these frames in stream buffer:

video frame, type=cluster,      absolute timestamp = 100, delta timestamp = 0
......
audio frame, type=simple block, absolute timestamp = 200, delta timestamp = 100
audio frame, type=simple block, absolute timestamp = 220, delta timestamp = 120

Now we want to add a video frame, type=cluster, absolute timestamp = 200, current solution would insert it into stream buffer as:

video frame 1, type=cluster,      absolute timestamp = 100, delta timestamp = 0
......
audio frame 8, type=simple block, absolute timestamp = 200, delta timestamp = 100
video frame 2, type=cluster,      absolute timestamp = 200, delta timestamp = 0
audio frame 9, type=simple block, absolute timestamp = 220, delta timestamp = 120

There will be 2 issues in this orders. KVS would return 4004 error if we send these frames out.

This fix would make the stream buffer as:

video frame 1, type=cluster,      absolute timestamp = 100, delta timestamp = 0
......
video frame 2, type=cluster,      absolute timestamp = 200, delta timestamp = 0
audio frame 8, type=simple block, absolute timestamp = 200, delta timestamp = 0
audio frame 9, type=simple block, absolute timestamp = 220, delta timestamp = 20

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.