Skip to content

Commit 1be6d28

Browse files
committed
give video frame PTS to client, if callback is registered per API
1 parent 5f648f8 commit 1be6d28

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

toxav/codecs/h264/codec.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,12 +1686,32 @@ void decode_frame_h264(VCSession *vc, Tox *tox, uint8_t skip_video_flag, uint64_
16861686
// -------- DEBUG:AUDIO/VIDEO DELAY/LATENCY --------
16871687
// -------- DEBUG:AUDIO/VIDEO DELAY/LATENCY --------
16881688

1689-
vc->vcb(vc->av, vc->friend_number, frame->width, frame->height,
1690-
(const uint8_t *)frame->data[0],
1691-
(const uint8_t *)frame->data[1],
1692-
(const uint8_t *)frame->data[2],
1693-
frame->linesize[0], frame->linesize[1],
1694-
frame->linesize[2], vc->vcb_user_data);
1689+
if (vc->vcb_pts)
1690+
{
1691+
uint64_t pts_for_client = h_frame_record_timestamp;
1692+
int32_t delta_check = (int32_t)(h_frame_record_timestamp - frame->pkt_pts);
1693+
if ((delta_check >= 0) && (delta_check <= 100))
1694+
{
1695+
pts_for_client = frame->pkt_pts;
1696+
}
1697+
1698+
vc->vcb_pts(vc->av, vc->friend_number, frame->width, frame->height,
1699+
(const uint8_t *)frame->data[0],
1700+
(const uint8_t *)frame->data[1],
1701+
(const uint8_t *)frame->data[2],
1702+
frame->linesize[0], frame->linesize[1],
1703+
frame->linesize[2], vc->vcb_pts_user_data,
1704+
pts_for_client);
1705+
}
1706+
else
1707+
{
1708+
vc->vcb(vc->av, vc->friend_number, frame->width, frame->height,
1709+
(const uint8_t *)frame->data[0],
1710+
(const uint8_t *)frame->data[1],
1711+
(const uint8_t *)frame->data[2],
1712+
frame->linesize[0], frame->linesize[1],
1713+
frame->linesize[2], vc->vcb_user_data);
1714+
}
16951715
}
16961716

16971717
// end_time_ms = current_time_monotonic(vc->av->toxav_mono_time);

toxav/tox_generic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ struct ToxAV {
160160
/* Video frame receive callback */
161161
toxav_video_receive_frame_cb *vcb;
162162
void *vcb_user_data;
163+
toxav_video_receive_frame_pts_cb *vcb_pts;
164+
void *vcb_pts_user_data;
163165
toxav_video_receive_frame_h264_cb *vcb_h264;
164166
void *vcb_h264_user_data;
165167
/* Bit rate control callback */

toxav/toxav.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,14 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb
19981998
pthread_mutex_unlock(av->mutex);
19991999
}
20002000

2001+
void toxav_callback_video_receive_frame_pts(ToxAV *av, toxav_video_receive_frame_pts_cb *callback, void *user_data)
2002+
{
2003+
pthread_mutex_lock(av->mutex);
2004+
av->vcb_pts = callback;
2005+
av->vcb_pts_user_data = user_data;
2006+
pthread_mutex_unlock(av->mutex);
2007+
}
2008+
20012009
void toxav_callback_video_receive_frame_h264(ToxAV *av, toxav_video_receive_frame_h264_cb *callback, void *user_data)
20022010
{
20032011
pthread_mutex_lock(av->mutex);

toxav/toxav.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,14 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb
826826

827827

828828

829+
typedef void toxav_video_receive_frame_pts_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
830+
const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride,
831+
void *user_data, uint64_t pts);
832+
833+
void toxav_callback_video_receive_frame_pts(ToxAV *av, toxav_video_receive_frame_pts_cb *callback, void *user_data);
834+
835+
836+
829837

830838

831839
typedef void toxav_video_receive_frame_h264_cb(ToxAV *av, uint32_t friend_number,
@@ -839,8 +847,6 @@ typedef void toxav_video_receive_frame_h264_cb(ToxAV *av, uint32_t friend_number
839847
void toxav_callback_video_receive_frame_h264(ToxAV *av, toxav_video_receive_frame_h264_cb *callback, void *user_data);
840848

841849

842-
843-
844850
/**
845851
* NOTE Compatibility with old toxav group calls. TODO(iphydf): remove
846852
*

toxav/video.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f
179179
vc->vcb_h264 = av->vcb_h264;
180180
vc->vcb_h264_user_data = av->vcb_h264_user_data;
181181

182+
// set pts callback
183+
vc->vcb_pts = av->vcb_pts;
184+
vc->vcb_pts_user_data = av->vcb_pts_user_data;
185+
186+
182187
for (int i = 0; i < VIDEO_INCOMING_FRAMES_GAP_MS_ENTRIES; i++) {
183188
vc->incoming_video_frames_gap_ms[i] = 0;
184189
}

toxav/video.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ typedef struct VCSession_s {
287287
/* Video frame receive callback */
288288
toxav_video_receive_frame_cb *vcb;
289289
void *vcb_user_data;
290+
toxav_video_receive_frame_pts_cb *vcb_pts;
291+
void *vcb_pts_user_data;
290292
toxav_video_receive_frame_h264_cb *vcb_h264;
291293
void *vcb_h264_user_data;
292294

0 commit comments

Comments
 (0)