diff --git a/lib/libDtChat/dc_internal.h b/lib/libDtChat/dc_internal.h index 96dcf4de..82fa6882 100644 --- a/lib/libDtChat/dc_internal.h +++ b/lib/libDtChat/dc_internal.h @@ -490,6 +490,11 @@ int dc_call_audio_out(DcMediaCall *call, int16_t *pcm); /* one encoded frame out (fragmented) and the completed frames in */ int dc_call_send_video(DcMediaCall *call, uint16_t frame_id, const unsigned char *frame, size_t len, int keyframe); +/* the same with a caller-chosen timestamp (the send path uses the elapsed + * time since the call began; a test or a recording can say when the frame + * belongs) */ +int dc_call_send_video_at(DcMediaCall *call, uint32_t ts, uint16_t frame_id, + const unsigned char *frame, size_t len, int keyframe); /* 1: a decoded I420 frame to render (DC_VIDEO_W x DC_VIDEO_H), 0: nothing * complete or not decodable yet, -1: a frame was dropped because it was more * than DC_SYNC_LATE_MS behind the audio (or OUT is too small) */ diff --git a/lib/libDtChat/media_call.c b/lib/libDtChat/media_call.c index 856b2bff..e33a0abf 100644 --- a/lib/libDtChat/media_call.c +++ b/lib/libDtChat/media_call.c @@ -547,6 +547,17 @@ dc_call_audio_out(DcMediaCall *call, int16_t *pcm) int dc_call_send_video(DcMediaCall *call, uint16_t frame_id, const unsigned char *frame, size_t len, int keyframe) +{ + if (call == NULL) + return -1; + return dc_call_send_video_at(call, + (uint32_t)(dc_loop_now_ms() - call->video_start), frame_id, frame, + len, keyframe); +} + +int +dc_call_send_video_at(DcMediaCall *call, uint32_t ts, uint16_t frame_id, + const unsigned char *frame, size_t len, int keyframe) { unsigned char fragment[DC_MEDIA_MAX_PAYLOAD]; unsigned char packet[DC_MEDIA_MAX_PAYLOAD + 64]; @@ -569,8 +580,7 @@ dc_call_send_video(DcMediaCall *call, uint16_t frame_id, * timestamp is when the frame is sent, not a frame count: a pump * that runs slower than the nominal frame rate must not make the * stream drift behind the sound */ - plen = dc_media_seal(&call->snd, DC_MEDIA_VIDEO, - (uint32_t)(dc_loop_now_ms() - call->video_start), fragment, + plen = dc_media_seal(&call->snd, DC_MEDIA_VIDEO, ts, fragment, flen, packet, sizeof(packet)); if (plen == 0) return -1; diff --git a/lib/libDtChat/test_video_packet.c b/lib/libDtChat/test_video_packet.c index 9a79be93..5c96c2e8 100644 --- a/lib/libDtChat/test_video_packet.c +++ b/lib/libDtChat/test_video_packet.c @@ -262,15 +262,15 @@ main(void) for (i = 0; i < 10; i++) { CHECK(dc_call_audio_out(d, pcm) == 1); } - CHECK(dc_call_send_video(c, 1, frame, 1000, 0) == 0); + CHECK(dc_call_send_video_at(c, 0, 1, frame, 1000, 0) == 0); (void)dc_call_drain(d); CHECK(dc_call_video_packet(d, got, sizeof(got), &len, &keyframe, &frame_id) == -1); - CHECK(dc_call_send_video(c, 2, frame, 1000, 0) == 0); + CHECK(dc_call_send_video_at(c, 66, 2, frame, 1000, 0) == 0); (void)dc_call_drain(d); CHECK(dc_call_video_packet(d, got, sizeof(got), &len, &keyframe, &frame_id) == -1); - CHECK(dc_call_send_video(c, 3, frame, 1000, 0) == 0); + CHECK(dc_call_send_video_at(c, 132, 3, frame, 1000, 0) == 0); (void)dc_call_drain(d); CHECK(dc_call_video_packet(d, got, sizeof(got), &len, &keyframe, &frame_id) == 1);