summaryrefslogtreecommitdiff
path: root/libavdevice
diff options
context:
space:
mode:
authorrogerdpack <rogerpack2005@gmail.com>2014-03-21 16:27:01 -0600
committerMichael Niedermayer <michaelni@gmx.at>2014-03-22 03:46:10 +0100
commit6abc56e892c2c2500d1fc2698fa6d580b72f721b (patch)
treeebfc055ca90bebe59fc8275d06b88fb5b2a404a0 /libavdevice
parent87ecefdab0097537c5c30014e57b19113ab05eee (diff)
dshow: use distinct buffers per stream.
Basically sometimes if you start dropping video packets, you also drop audio packets. Now they each have separate buffers to avoid this unexpected behavior. Signed-off-by: rogerdpack <rogerpack2005@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavdevice')
-rw-r--r--libavdevice/dshow.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 96ca813a47..51693be5e5 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -53,7 +53,7 @@ struct dshow_ctx {
int eof;
- int64_t curbufsize;
+ int64_t curbufsize[2];
unsigned int video_frame_num;
IMediaControl *control;
@@ -180,16 +180,16 @@ static char *dup_wchar_to_utf8(wchar_t *w)
return s;
}
-static int shall_we_drop(AVFormatContext *s)
+static int shall_we_drop(AVFormatContext *s, int index)
{
struct dshow_ctx *ctx = s->priv_data;
static const uint8_t dropscore[] = {62, 75, 87, 100};
const int ndropscores = FF_ARRAY_ELEMS(dropscore);
- unsigned int buffer_fullness = (ctx->curbufsize*100)/s->max_picture_buffer;
+ unsigned int buffer_fullness = (ctx->curbufsize[index]*100)/s->max_picture_buffer;
if(dropscore[++ctx->video_frame_num%ndropscores] <= buffer_fullness) {
av_log(s, AV_LOG_ERROR,
- "real-time buffer %d%% full! frame dropped!\n", buffer_fullness);
+ "real-time buffer[%d] too full (%d%% of size: %d)! frame dropped!\n", index, buffer_fullness, s->max_picture_buffer);
return 1;
}
@@ -207,7 +207,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)
WaitForSingleObject(ctx->mutex, INFINITE);
- if(shall_we_drop(s))
+ if(shall_we_drop(s, index))
goto fail;
pktl_next = av_mallocz(sizeof(AVPacketList));
@@ -225,8 +225,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)
for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next);
*ppktl = pktl_next;
-
- ctx->curbufsize += buf_size;
+ ctx->curbufsize[index] += buf_size;
SetEvent(ctx->event[1]);
ReleaseMutex(ctx->mutex);
@@ -944,7 +943,8 @@ static int dshow_read_header(AVFormatContext *avctx)
goto error;
}
}
-
+ ctx->curbufsize[0] = 0;
+ ctx->curbufsize[1] = 0;
ctx->mutex = CreateMutex(NULL, 0, NULL);
if (!ctx->mutex) {
av_log(avctx, AV_LOG_ERROR, "Could not create Mutex\n");
@@ -1038,7 +1038,7 @@ static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
*pkt = pktl->pkt;
ctx->pktl = ctx->pktl->next;
av_free(pktl);
- ctx->curbufsize -= pkt->size;
+ ctx->curbufsize[pkt->stream_index] -= pkt->size;
}
ResetEvent(ctx->event[1]);
ReleaseMutex(ctx->mutex);