aboutsummaryrefslogtreecommitdiffstats
path: root/ffplay.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2016-06-11 12:11:11 +0200
committerMarton Balint <cus@passwd.hu>2016-06-19 23:35:22 +0200
commite32857f30eed011e6c49d578418692f54d8e9a5d (patch)
treefd0b2a49c86de03ac6885b9897cfb0e138233abf /ffplay.c
parent8594a8fbf9b0af99e5b5b149831a47478be4aff0 (diff)
downloadffmpeg-e32857f30eed011e6c49d578418692f54d8e9a5d.tar.gz
ffplay: ensure that we buffer at least 1 second of content
In order to do that, we keep track of the total duration of packets in a packet queue. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'ffplay.c')
-rw-r--r--ffplay.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ffplay.c b/ffplay.c
index 9f5b2a4934..d32b02323d 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -117,6 +117,7 @@ typedef struct PacketQueue {
MyAVPacketList *first_pkt, *last_pkt;
int nb_packets;
int size;
+ int64_t duration;
int abort_request;
int serial;
SDL_mutex *mutex;
@@ -417,6 +418,7 @@ static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
q->last_pkt = pkt1;
q->nb_packets++;
q->size += pkt1->pkt.size + sizeof(*pkt1);
+ q->duration += pkt1->pkt.duration;
/* XXX: should duplicate packet data in DV case */
SDL_CondSignal(q->cond);
return 0;
@@ -478,6 +480,7 @@ static void packet_queue_flush(PacketQueue *q)
q->first_pkt = NULL;
q->nb_packets = 0;
q->size = 0;
+ q->duration = 0;
SDL_UnlockMutex(q->mutex);
}
@@ -528,6 +531,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *seria
q->last_pkt = NULL;
q->nb_packets--;
q->size -= pkt1->pkt.size + sizeof(*pkt1);
+ q->duration -= pkt1->pkt.duration;
*pkt = pkt1->pkt;
if (serial)
*serial = pkt1->serial;
@@ -2800,7 +2804,7 @@ static int stream_has_enough_packets(AVStream *st, int stream_id, PacketQueue *q
return stream_id < 0 ||
queue->abort_request ||
(st->disposition & AV_DISPOSITION_ATTACHED_PIC) ||
- queue->nb_packets > MIN_FRAMES;
+ queue->nb_packets > MIN_FRAMES && (!queue->duration || av_q2d(st->time_base) * queue->duration > 1.0);
}
static int is_realtime(AVFormatContext *s)