comparison fifo.c @ 492:75f096258d14 libavutil

Add a generic write function to av_fifo. Patch by Bj«Órn Axelsson: bjorn axelsson intinor se Original thread: [FFmpeg-devel] [RFC][PATCH] av_fifo_write_from_bytestream() Date: 04/03/2008 12:14 PM
author benoit
date Wed, 09 Apr 2008 11:35:16 +0000
parents 4c85ac99ab37
children 97dd9756349c
comparison
equal deleted inserted replaced
491:34640f2e3060 492:75f096258d14
71 } 71 }
72 } 72 }
73 73
74 void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size) 74 void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)
75 { 75 {
76 av_fifo_generic_write(f, (void *)buf, size, NULL);
77 }
78
79 int av_fifo_generic_write(AVFifoBuffer *f, void *buf, int size, int (*func)(void*, void*, int))
80 {
81 int total = size;
76 do { 82 do {
77 int len = FFMIN(f->end - f->wptr, size); 83 int len = FFMIN(f->end - f->wptr, size);
84 if(func) {
85 if(func(buf, f->wptr, len) <= 0)
86 break;
87 } else {
78 memcpy(f->wptr, buf, len); 88 memcpy(f->wptr, buf, len);
89 buf = (uint8_t*)buf + len;
90 }
79 f->wptr += len; 91 f->wptr += len;
80 if (f->wptr >= f->end) 92 if (f->wptr >= f->end)
81 f->wptr = f->buffer; 93 f->wptr = f->buffer;
82 buf += len;
83 size -= len; 94 size -= len;
84 } while (size > 0); 95 } while (size > 0);
96 return total - size;
85 } 97 }
86 98
87 99
88 /** get data from the fifo (return -1 if not enough data) */ 100 /** get data from the fifo (return -1 if not enough data) */
89 int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest) 101 int av_fifo_generic_read(AVFifoBuffer *f, int buf_size, void (*func)(void*, void*, int), void* dest)