]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Make av_fifo*_read() ignore the available amount of data.
authormichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sun, 25 May 2008 22:20:39 +0000 (22:20 +0000)
committermichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sun, 25 May 2008 22:20:39 +0000 (22:20 +0000)
This is more efficient as in practice the check is redundant most of the
time. Callers which do not know if enough data is available have to check
it with av_fifo_size(). Doing the check in *read() means the caller has
no choice to skip the check when its known to be redundant.
Also the return value was never documented in a public header so
changing it should not break the API. Besides this fixes the case where
read() failed on a 100% full fifo.

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@13404 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

ffmpeg.c
libavformat/mpegenc.c
libavutil/fifo.c

index dc53f34c34698068d838f5577bffebc711b16b7b..544927956fb520db0d42b4063e0e5d19380c6f3f 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -592,10 +592,12 @@ static void do_audio_out(AVFormatContext *s,
 
         frame_bytes = enc->frame_size * 2 * enc->channels;
 
-        while (av_fifo_read(&ost->fifo, audio_buf, frame_bytes) == 0) {
+        while (av_fifo_size(&ost->fifo) >= frame_bytes) {
             AVPacket pkt;
             av_init_packet(&pkt);
 
+            av_fifo_read(&ost->fifo, audio_buf, frame_bytes);
+
             //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
 
             ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
@@ -1385,9 +1387,8 @@ static int output_packet(AVInputStream *ist, int ist_index,
                             if(fifo_bytes > 0 && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
                                 int fs_tmp = enc->frame_size;
                                 enc->frame_size = fifo_bytes / (2 * enc->channels);
-                                if(av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes) == 0) {
+                                av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes);
                                     ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples);
-                                }
                                 enc->frame_size = fs_tmp;
                             }
                             if(ret <= 0) {
index 05c72cd1e7c40f8d0f7bac12c7466363e4f7e311..c96ffd1684b533506ebe247ba31d3d700ec828eb 100644 (file)
@@ -913,8 +913,8 @@ static int flush_packet(AVFormatContext *ctx, int stream_index,
         }
 
         /* output data */
-        if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, ctx->pb) < 0)
-            return -1;
+        assert(payload_size - stuffing_size <= av_fifo_size(&stream->fifo));
+        av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, ctx->pb);
         stream->bytes_to_iframe -= payload_size - stuffing_size;
     }else{
         payload_size=
index 19ec13e63d0716e7515fbe86c0d82f08ce2e7ff9..f2ace514bdb6023094dfd8ad995fd28c8126fdd7 100644 (file)
@@ -45,9 +45,6 @@ int av_fifo_size(AVFifoBuffer *f)
     return size;
 }
 
-/**
- * Get data from the fifo (returns -1 if not enough data).
- */
 int av_fifo_read(AVFifoBuffer *f, uint8_t *buf, int buf_size)
 {
     return av_fifo_generic_read(f, buf_size, NULL, buf);
@@ -97,13 +94,8 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
 }
 
 
-/** get data from the fifo (return -1 if not enough data) */
 int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest)
 {
-    int size = av_fifo_size(f);
-
-    if (size < buf_size)
-        return -1;
     do {
         int len = FFMIN(f->end - f->rptr, buf_size);
         if(func) func(dest, f->rptr, len);