[FFmpeg-devel] [PATCH v2 3/3] ffplay: fix memory calculation
Muhammad Faiz
mfcc64 at gmail.com
Sun Nov 15 09:57:51 CET 2015
approximately compute memory size on wrapped_avframe packet
patch attached
-------------- next part --------------
From 148239aa55382bc68d888826764a778fb7982d6d Mon Sep 17 00:00:00 2001
From: Muhammad Faiz <mfcc64 at gmail.com>
Date: Sun, 15 Nov 2015 09:21:29 +0700
Subject: [PATCH v2 3/3] ffplay: fix memory calculation
approximately compute memory size on wrapped_avframe packet
---
ffplay.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/ffplay.c b/ffplay.c
index 2c1817e..a3e2c25 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -395,6 +395,24 @@ int64_t get_valid_channel_layout(int64_t channel_layout, int channels)
static void free_picture(Frame *vp);
+static int get_packet_memory_size(AVPacket *pkt)
+{
+ const AVFrame *frame = av_packet_get_frame(pkt);
+ int k, size = pkt->size;
+
+ if (frame) {
+ for (k = 0; k < AV_NUM_DATA_POINTERS; k++) {
+ if (frame->buf[k])
+ size += frame->buf[k]->size;
+ }
+
+ for (k = 0; k < frame->nb_extended_buf; k++)
+ size += frame->extended_buf[k]->size;
+ }
+
+ return size;
+}
+
static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
{
MyAVPacketList *pkt1;
@@ -417,7 +435,7 @@ static int packet_queue_put_private(PacketQueue *q, AVPacket *pkt)
q->last_pkt->next = pkt1;
q->last_pkt = pkt1;
q->nb_packets++;
- q->size += pkt1->pkt.size + sizeof(*pkt1);
+ q->size += get_packet_memory_size(&pkt1->pkt) + sizeof(*pkt1);
/* XXX: should duplicate packet data in DV case */
SDL_CondSignal(q->cond);
return 0;
@@ -528,7 +546,7 @@ static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block, int *seria
if (!q->first_pkt)
q->last_pkt = NULL;
q->nb_packets--;
- q->size -= pkt1->pkt.size + sizeof(*pkt1);
+ q->size -= get_packet_memory_size(&pkt1->pkt) + sizeof(*pkt1);
*pkt = pkt1->pkt;
if (serial)
*serial = pkt1->serial;
--
1.8.3.1
More information about the ffmpeg-devel
mailing list