mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
ffplay: switch to new FIFO API
This commit is contained in:
parent
c65c2ed01d
commit
bdf9ed41fe
@ -115,7 +115,7 @@ typedef struct MyAVPacketList {
|
|||||||
} MyAVPacketList;
|
} MyAVPacketList;
|
||||||
|
|
||||||
typedef struct PacketQueue {
|
typedef struct PacketQueue {
|
||||||
AVFifoBuffer *pkt_list;
|
AVFifo *pkt_list;
|
||||||
int nb_packets;
|
int nb_packets;
|
||||||
int size;
|
int size;
|
||||||
int64_t duration;
|
int64_t duration;
|
||||||
@ -424,19 +424,18 @@ int64_t get_valid_channel_layout(int64_t channel_layout, int channels)
|
|||||||
static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
|
static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
MyAVPacketList pkt1;
|
MyAVPacketList pkt1;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (q->abort_request)
|
if (q->abort_request)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (av_fifo_space(q->pkt_list) < sizeof(pkt1)) {
|
|
||||||
if (av_fifo_grow(q->pkt_list, sizeof(pkt1)) < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkt1.pkt = pkt;
|
pkt1.pkt = pkt;
|
||||||
pkt1.serial = q->serial;
|
pkt1.serial = q->serial;
|
||||||
|
|
||||||
av_fifo_generic_write(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
|
ret = av_fifo_write(q->pkt_list, &pkt1, 1);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
q->nb_packets++;
|
q->nb_packets++;
|
||||||
q->size += pkt1.pkt->size + sizeof(pkt1);
|
q->size += pkt1.pkt->size + sizeof(pkt1);
|
||||||
q->duration += pkt1.pkt->duration;
|
q->duration += pkt1.pkt->duration;
|
||||||
@ -477,7 +476,7 @@ static int packet_queue_put_nullpacket(PacketQueue *q, AVPacket *pkt, int stream
|
|||||||
static int packet_queue_init(PacketQueue *q)
|
static int packet_queue_init(PacketQueue *q)
|
||||||
{
|
{
|
||||||
memset(q, 0, sizeof(PacketQueue));
|
memset(q, 0, sizeof(PacketQueue));
|
||||||
q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList));
|
q->pkt_list = av_fifo_alloc2(1, sizeof(MyAVPacketList), AV_FIFO_FLAG_AUTO_GROW);
|
||||||
if (!q->pkt_list)
|
if (!q->pkt_list)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
q->mutex = SDL_CreateMutex();
|
q->mutex = SDL_CreateMutex();
|
||||||
@ -499,10 +498,8 @@ static void packet_queue_flush(PacketQueue *q)
|
|||||||
MyAVPacketList pkt1;
|
MyAVPacketList pkt1;
|
||||||
|
|
||||||
SDL_LockMutex(q->mutex);
|
SDL_LockMutex(q->mutex);
|
||||||
while (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
|
while (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0)
|
||||||
av_fifo_generic_read(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
|
|
||||||
av_packet_free(&pkt1.pkt);
|
av_packet_free(&pkt1.pkt);
|
||||||
}
|
|
||||||
q->nb_packets = 0;
|
q->nb_packets = 0;
|
||||||
q->size = 0;
|
q->size = 0;
|
||||||
q->duration = 0;
|
q->duration = 0;
|
||||||
@ -513,7 +510,7 @@ static void packet_queue_flush(PacketQueue *q)
|
|||||||
static void packet_queue_destroy(PacketQueue *q)
|
static void packet_queue_destroy(PacketQueue *q)
|
||||||
{
|
{
|
||||||
packet_queue_flush(q);
|
packet_queue_flush(q);
|
||||||
av_fifo_freep(&q->pkt_list);
|
av_fifo_freep2(&q->pkt_list);
|
||||||
SDL_DestroyMutex(q->mutex);
|
SDL_DestroyMutex(q->mutex);
|
||||||
SDL_DestroyCond(q->cond);
|
SDL_DestroyCond(q->cond);
|
||||||
}
|
}
|
||||||
@ -551,8 +548,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *seria
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (av_fifo_size(q->pkt_list) >= sizeof(pkt1)) {
|
if (av_fifo_read(q->pkt_list, &pkt1, 1) >= 0) {
|
||||||
av_fifo_generic_read(q->pkt_list, &pkt1, sizeof(pkt1), NULL);
|
|
||||||
q->nb_packets--;
|
q->nb_packets--;
|
||||||
q->size -= pkt1.pkt->size + sizeof(pkt1);
|
q->size -= pkt1.pkt->size + sizeof(pkt1);
|
||||||
q->duration -= pkt1.pkt->duration;
|
q->duration -= pkt1.pkt->duration;
|
||||||
|
Loading…
Reference in New Issue
Block a user