]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/fifo.c
slightly improve *_TIMER
[ffmpeg] / libavutil / fifo.c
index 635df2dbf896247586d7579ef1830697d79e927f..8ac3a0cb55ca4c3a1eb35f2368ff07b51ad9e2be 100644 (file)
@@ -26,9 +26,9 @@ int av_fifo_init(AVFifoBuffer *f, int size)
 {
     f->wptr = f->rptr =
     f->buffer = av_malloc(size);
+    f->end = f->buffer + size;
     if (!f->buffer)
         return -1;
-    f->end = f->buffer + size;
     return 0;
 }
 
@@ -73,7 +73,7 @@ void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
 
 void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
 {
-    while (size > 0) {
+    do {
         int len = FFMIN(f->end - f->wptr, size);
         memcpy(f->wptr, buf, len);
         f->wptr += len;
@@ -81,18 +81,18 @@ void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
             f->wptr = f->buffer;
         buf += len;
         size -= len;
-    }
+    } while (size > 0);
 }
 
 
-/* get data from the fifo (return -1 if not enough data) */
+/** 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;
-    while (buf_size > 0) {
+    do {
         int len = FFMIN(f->end - f->rptr, buf_size);
         if(func) func(dest, f->rptr, len);
         else{
@@ -101,11 +101,11 @@ int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void
         }
         av_fifo_drain(f, len);
         buf_size -= len;
-    }
+    } while (buf_size > 0);
     return 0;
 }
 
-/* discard data from the fifo */
+/** discard data from the fifo */
 void av_fifo_drain(AVFifoBuffer *f, int size)
 {
     f->rptr += size;