mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-27 13:10:37 +00:00
avformat/udp: do not accumulate packet_gap delay errors
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
8b7b52c863
commit
0a06569487
@ -552,6 +552,7 @@ static void *circular_buffer_task_tx( void *_URLContext)
|
|||||||
URLContext *h = _URLContext;
|
URLContext *h = _URLContext;
|
||||||
UDPContext *s = h->priv_data;
|
UDPContext *s = h->priv_data;
|
||||||
int old_cancelstate;
|
int old_cancelstate;
|
||||||
|
int64_t target_timestamp = 0;
|
||||||
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
|
||||||
pthread_mutex_lock(&s->mutex);
|
pthread_mutex_lock(&s->mutex);
|
||||||
@ -566,6 +567,7 @@ static void *circular_buffer_task_tx( void *_URLContext)
|
|||||||
int len;
|
int len;
|
||||||
const uint8_t *p;
|
const uint8_t *p;
|
||||||
uint8_t tmp[4];
|
uint8_t tmp[4];
|
||||||
|
int64_t timestamp;
|
||||||
|
|
||||||
len=av_fifo_size(s->fifo);
|
len=av_fifo_size(s->fifo);
|
||||||
|
|
||||||
@ -589,6 +591,17 @@ static void *circular_buffer_task_tx( void *_URLContext)
|
|||||||
pthread_mutex_unlock(&s->mutex);
|
pthread_mutex_unlock(&s->mutex);
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelstate);
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelstate);
|
||||||
|
|
||||||
|
if (s->packet_gap) {
|
||||||
|
timestamp = av_gettime_relative();
|
||||||
|
if (timestamp < target_timestamp) {
|
||||||
|
target_timestamp = FFMIN(target_timestamp, timestamp + s->packet_gap);
|
||||||
|
av_usleep(target_timestamp - timestamp);
|
||||||
|
} else {
|
||||||
|
target_timestamp = timestamp;
|
||||||
|
}
|
||||||
|
target_timestamp += s->packet_gap;
|
||||||
|
}
|
||||||
|
|
||||||
p = s->tmp;
|
p = s->tmp;
|
||||||
while (len) {
|
while (len) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -613,8 +626,6 @@ static void *circular_buffer_task_tx( void *_URLContext)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av_usleep(s->packet_gap);
|
|
||||||
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
|
||||||
pthread_mutex_lock(&s->mutex);
|
pthread_mutex_lock(&s->mutex);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user