Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2010-05-25 23:13:28 +0400
committerMartin Storsjö <martin@martin.st>2010-05-25 23:13:28 +0400
commit11f6181af18a7deab3dc97caf864a00a2a017961 (patch)
treea8156da12eafdc51321d1ebf6d8b2d28908748b3 /libavcodec/api-example.c
parent0ecfa7b7c7fe26cfd34795068c9880ed84df16a0 (diff)
api-example: Try to avoid decoding incomplete frames
Use a larger input audio buffer, refill it when it has less than 4 KB data left. Originally committed as revision 23323 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/api-example.c')
-rw-r--r--libavcodec/api-example.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/libavcodec/api-example.c b/libavcodec/api-example.c
index fb48b1f6d6..cde8dc3524 100644
--- a/libavcodec/api-example.c
+++ b/libavcodec/api-example.c
@@ -39,6 +39,8 @@
#include "libavutil/mathematics.h"
#define INBUF_SIZE 4096
+#define AUDIO_INBUF_SIZE 20480
+#define AUDIO_REFILL_THRESH 4096
/*
* Audio encoding example
@@ -118,7 +120,7 @@ static void audio_decode_example(const char *outfilename, const char *filename)
int out_size, len;
FILE *f, *outfile;
uint8_t *outbuf;
- uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
+ uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
av_init_packet(&avpkt);
@@ -155,12 +157,8 @@ static void audio_decode_example(const char *outfilename, const char *filename)
/* decode until eof */
avpkt.data = inbuf;
- for(;;) {
- avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
- if (avpkt.size == 0)
- break;
+ avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
- avpkt.data = inbuf;
while (avpkt.size > 0) {
out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);
@@ -174,8 +172,19 @@ static void audio_decode_example(const char *outfilename, const char *filename)
}
avpkt.size -= len;
avpkt.data += len;
+ if (avpkt.size < AUDIO_REFILL_THRESH) {
+ /* Refill the input buffer, to avoid trying to decode
+ * incomplete frames. Instead of this, one could also use
+ * a parser, or use a proper container format through
+ * libavformat. */
+ memmove(inbuf, avpkt.data, avpkt.size);
+ avpkt.data = inbuf;
+ len = fread(avpkt.data + avpkt.size, 1,
+ AUDIO_INBUF_SIZE - avpkt.size, f);
+ if (len > 0)
+ avpkt.size += len;
+ }
}
- }
fclose(outfile);
fclose(f);