OLD | NEW |
1 /* | 1 /* |
2 * a very simple circular buffer FIFO implementation | 2 * a very simple circular buffer FIFO implementation |
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | 3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard |
4 * Copyright (c) 2006 Roman Shaposhnik | 4 * Copyright (c) 2006 Roman Shaposhnik |
5 * | 5 * |
6 * This file is part of FFmpeg. | 6 * This file is part of FFmpeg. |
7 * | 7 * |
8 * FFmpeg is free software; you can redistribute it and/or | 8 * FFmpeg is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 av_fifo_generic_read(f, f2->buffer, len, NULL); | 71 av_fifo_generic_read(f, f2->buffer, len, NULL); |
72 f2->wptr += len; | 72 f2->wptr += len; |
73 f2->wndx += len; | 73 f2->wndx += len; |
74 av_free(f->buffer); | 74 av_free(f->buffer); |
75 *f= *f2; | 75 *f= *f2; |
76 av_free(f2); | 76 av_free(f2); |
77 } | 77 } |
78 return 0; | 78 return 0; |
79 } | 79 } |
80 | 80 |
| 81 // src must NOT be const as it can be a context for func that may need updating
(like a pointer or byte counter) |
81 int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
*, void*, int)) | 82 int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void
*, void*, int)) |
82 { | 83 { |
83 int total = size; | 84 int total = size; |
84 do { | 85 do { |
85 int len = FFMIN(f->end - f->wptr, size); | 86 int len = FFMIN(f->end - f->wptr, size); |
86 if(func) { | 87 if(func) { |
87 if(func(src, f->wptr, len) <= 0) | 88 if(func(src, f->wptr, len) <= 0) |
88 break; | 89 break; |
89 } else { | 90 } else { |
90 memcpy(f->wptr, src, len); | 91 memcpy(f->wptr, src, len); |
(...skipping 28 matching lines...) Expand all Loading... |
119 } | 120 } |
120 | 121 |
121 /** Discard data from the FIFO. */ | 122 /** Discard data from the FIFO. */ |
122 void av_fifo_drain(AVFifoBuffer *f, int size) | 123 void av_fifo_drain(AVFifoBuffer *f, int size) |
123 { | 124 { |
124 f->rptr += size; | 125 f->rptr += size; |
125 if (f->rptr >= f->end) | 126 if (f->rptr >= f->end) |
126 f->rptr -= f->end - f->buffer; | 127 f->rptr -= f->end - f->buffer; |
127 f->rndx += size; | 128 f->rndx += size; |
128 } | 129 } |
OLD | NEW |