ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
[libav.git] / libavformat / aviobuf.c
CommitLineData
de6d9b64
FB
1/*
2 * Buffered I/O for ffmpeg system
19720f15 3 * Copyright (c) 2000,2001 Fabrice Bellard
de6d9b64 4 *
19720f15
FB
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
de6d9b64 9 *
19720f15 10 * This library is distributed in the hope that it will be useful,
de6d9b64 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19720f15
FB
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
de6d9b64 14 *
19720f15
FB
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
de6d9b64 18 */
de6d9b64 19#include "avformat.h"
5c91a675 20#include "avio.h"
abba3dd1 21#include <stdarg.h>
de6d9b64
FB
22
23#define IO_BUFFER_SIZE 32768
24
25int init_put_byte(ByteIOContext *s,
26 unsigned char *buffer,
27 int buffer_size,
28 int write_flag,
29 void *opaque,
0c1a9eda
ZK
30 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
31 void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
de6d9b64
FB
32 int (*seek)(void *opaque, offset_t offset, int whence))
33{
34 s->buffer = buffer;
35 s->buffer_size = buffer_size;
36 s->buf_ptr = buffer;
37 s->write_flag = write_flag;
38 if (!s->write_flag)
39 s->buf_end = buffer;
40 else
41 s->buf_end = buffer + buffer_size;
42 s->opaque = opaque;
43 s->write_packet = write_packet;
44 s->read_packet = read_packet;
45 s->seek = seek;
46 s->pos = 0;
47 s->must_flush = 0;
48 s->eof_reached = 0;
49 s->is_streamed = 0;
abba3dd1 50 s->max_packet_size = 0;
ee9f36a8 51 s->update_checksum= NULL;
de6d9b64
FB
52 return 0;
53}
54
55
764ef400 56#ifdef CONFIG_ENCODERS
de6d9b64
FB
57static void flush_buffer(ByteIOContext *s)
58{
59 if (s->buf_ptr > s->buffer) {
60 if (s->write_packet)
61 s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
465e1dad 62 if(s->update_checksum){
ee9f36a8
MN
63 s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
64 s->checksum_ptr= s->buffer;
65 }
de6d9b64
FB
66 s->pos += s->buf_ptr - s->buffer;
67 }
68 s->buf_ptr = s->buffer;
69}
70
71void put_byte(ByteIOContext *s, int b)
72{
73 *(s->buf_ptr)++ = b;
74 if (s->buf_ptr >= s->buf_end)
75 flush_buffer(s);
76}
77
75bdb984 78void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
de6d9b64
FB
79{
80 int len;
81
82 while (size > 0) {
83 len = (s->buf_end - s->buf_ptr);
84 if (len > size)
85 len = size;
86 memcpy(s->buf_ptr, buf, len);
87 s->buf_ptr += len;
88
89 if (s->buf_ptr >= s->buf_end)
90 flush_buffer(s);
91
92 buf += len;
93 size -= len;
94 }
95}
96
97void put_flush_packet(ByteIOContext *s)
98{
99 flush_buffer(s);
100 s->must_flush = 0;
101}
764ef400 102#endif //CONFIG_ENCODERS
de6d9b64
FB
103
104offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
105{
106 offset_t offset1;
107
108 if (whence != SEEK_CUR && whence != SEEK_SET)
109 return -EINVAL;
110
764ef400 111#ifdef CONFIG_ENCODERS
de6d9b64
FB
112 if (s->write_flag) {
113 if (whence == SEEK_CUR) {
4606ac8d 114 offset1 = s->pos + (s->buf_ptr - s->buffer);
de6d9b64
FB
115 if (offset == 0)
116 return offset1;
117 offset += offset1;
118 }
119 offset1 = offset - s->pos;
120 if (!s->must_flush &&
121 offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
122 /* can do the seek inside the buffer */
123 s->buf_ptr = s->buffer + offset1;
124 } else {
125 if (!s->seek)
126 return -EPIPE;
127 flush_buffer(s);
128 s->must_flush = 1;
129 s->buf_ptr = s->buffer;
130 s->seek(s->opaque, offset, SEEK_SET);
131 s->pos = offset;
132 }
764ef400
MM
133 } else
134#endif //CONFIG_ENCODERS
135 {
de6d9b64
FB
136 if (whence == SEEK_CUR) {
137 offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer);
138 if (offset == 0)
139 return offset1;
140 offset += offset1;
141 }
142 offset1 = offset - (s->pos - (s->buf_end - s->buffer));
143 if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
144 /* can do the seek inside the buffer */
145 s->buf_ptr = s->buffer + offset1;
146 } else {
147 if (!s->seek)
148 return -EPIPE;
149 s->buf_ptr = s->buffer;
150 s->buf_end = s->buffer;
53e2f9ca
MN
151 if (s->seek(s->opaque, offset, SEEK_SET) == (offset_t)-EPIPE)
152 return -EPIPE;
de6d9b64
FB
153 s->pos = offset;
154 }
abba3dd1 155 s->eof_reached = 0;
de6d9b64
FB
156 }
157 return offset;
158}
159
160void url_fskip(ByteIOContext *s, offset_t offset)
161{
162 url_fseek(s, offset, SEEK_CUR);
163}
164
165offset_t url_ftell(ByteIOContext *s)
166{
167 return url_fseek(s, 0, SEEK_CUR);
168}
169
170int url_feof(ByteIOContext *s)
171{
172 return s->eof_reached;
173}
174
764ef400 175#ifdef CONFIG_ENCODERS
de6d9b64
FB
176void put_le32(ByteIOContext *s, unsigned int val)
177{
178 put_byte(s, val);
179 put_byte(s, val >> 8);
180 put_byte(s, val >> 16);
181 put_byte(s, val >> 24);
182}
183
184void put_be32(ByteIOContext *s, unsigned int val)
185{
186 put_byte(s, val >> 24);
187 put_byte(s, val >> 16);
188 put_byte(s, val >> 8);
189 put_byte(s, val);
190}
191
3b4b29dc
FB
192/* IEEE format is assumed */
193void put_be64_double(ByteIOContext *s, double val)
194{
195 union {
196 double d;
0c1a9eda 197 uint64_t ull;
3b4b29dc
FB
198 } u;
199 u.d = val;
200 put_be64(s, u.ull);
75bdb984
PG
201}
202
3b4b29dc 203void put_strz(ByteIOContext *s, const char *str)
75bdb984
PG
204{
205 if (str)
206 put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
207 else
208 put_byte(s, 0);
209}
210
0c1a9eda 211void put_le64(ByteIOContext *s, uint64_t val)
de6d9b64 212{
0c1a9eda
ZK
213 put_le32(s, (uint32_t)(val & 0xffffffff));
214 put_le32(s, (uint32_t)(val >> 32));
de6d9b64
FB
215}
216
0c1a9eda 217void put_be64(ByteIOContext *s, uint64_t val)
de6d9b64 218{
0c1a9eda
ZK
219 put_be32(s, (uint32_t)(val >> 32));
220 put_be32(s, (uint32_t)(val & 0xffffffff));
de6d9b64
FB
221}
222
223void put_le16(ByteIOContext *s, unsigned int val)
224{
225 put_byte(s, val);
226 put_byte(s, val >> 8);
227}
228
229void put_be16(ByteIOContext *s, unsigned int val)
230{
231 put_byte(s, val >> 8);
232 put_byte(s, val);
233}
234
0570bf06 235void put_tag(ByteIOContext *s, const char *tag)
de6d9b64
FB
236{
237 while (*tag) {
238 put_byte(s, *tag++);
239 }
240}
764ef400 241#endif //CONFIG_ENCODERS
de6d9b64
FB
242
243/* Input stream */
244
245static void fill_buffer(ByteIOContext *s)
246{
247 int len;
248
abba3dd1
FB
249 /* no need to do anything if EOF already reached */
250 if (s->eof_reached)
251 return;
ee9f36a8 252
465e1dad 253 if(s->update_checksum){
ee9f36a8
MN
254 s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_end - s->checksum_ptr);
255 s->checksum_ptr= s->buffer;
256 }
257
de6d9b64 258 len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
abba3dd1
FB
259 if (len <= 0) {
260 /* do not modify buffer if EOF reached so that a seek back can
261 be done without rereading data */
de6d9b64 262 s->eof_reached = 1;
abba3dd1
FB
263 } else {
264 s->pos += len;
265 s->buf_ptr = s->buffer;
266 s->buf_end = s->buffer + len;
de6d9b64
FB
267 }
268}
269
ee9f36a8
MN
270unsigned long get_checksum(ByteIOContext *s){
271 s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr);
465e1dad 272 s->update_checksum= NULL;
ee9f36a8
MN
273 return s->checksum;
274}
275
276void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum){
277 s->update_checksum= update_checksum;
465e1dad
MN
278 if(s->update_checksum){
279 s->checksum= s->update_checksum(checksum, NULL, 0);
280 s->checksum_ptr= s->buf_ptr;
281 }
ee9f36a8
MN
282}
283
abba3dd1
FB
284/* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
285 necessary */
286/* XXX: put an inline version */
de6d9b64
FB
287int get_byte(ByteIOContext *s)
288{
289 if (s->buf_ptr < s->buf_end) {
290 return *s->buf_ptr++;
291 } else {
292 fill_buffer(s);
293 if (s->buf_ptr < s->buf_end)
294 return *s->buf_ptr++;
295 else
296 return 0;
297 }
298}
299
abba3dd1
FB
300/* NOTE: return URL_EOF (-1) if EOF */
301int url_fgetc(ByteIOContext *s)
302{
303 if (s->buf_ptr < s->buf_end) {
304 return *s->buf_ptr++;
305 } else {
306 fill_buffer(s);
307 if (s->buf_ptr < s->buf_end)
308 return *s->buf_ptr++;
309 else
310 return URL_EOF;
311 }
312}
313
de6d9b64
FB
314int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
315{
316 int len, size1;
317
318 size1 = size;
319 while (size > 0) {
320 len = s->buf_end - s->buf_ptr;
321 if (len > size)
322 len = size;
323 if (len == 0) {
324 fill_buffer(s);
325 len = s->buf_end - s->buf_ptr;
326 if (len == 0)
327 break;
328 } else {
329 memcpy(buf, s->buf_ptr, len);
330 buf += len;
331 s->buf_ptr += len;
332 size -= len;
333 }
334 }
335 return size1 - size;
336}
337
e15dec10
LS
338int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size)
339{
340 int len;
341
342 len = s->buf_end - s->buf_ptr;
343 if (len == 0) {
344 fill_buffer(s);
345 len = s->buf_end - s->buf_ptr;
346 }
347 if (len > size)
348 len = size;
349 memcpy(buf, s->buf_ptr, len);
350 s->buf_ptr += len;
351 return len;
352}
353
de6d9b64
FB
354unsigned int get_le16(ByteIOContext *s)
355{
356 unsigned int val;
357 val = get_byte(s);
358 val |= get_byte(s) << 8;
359 return val;
360}
361
362unsigned int get_le32(ByteIOContext *s)
363{
364 unsigned int val;
365 val = get_byte(s);
366 val |= get_byte(s) << 8;
367 val |= get_byte(s) << 16;
368 val |= get_byte(s) << 24;
369 return val;
370}
371
0c1a9eda 372uint64_t get_le64(ByteIOContext *s)
de6d9b64 373{
0c1a9eda
ZK
374 uint64_t val;
375 val = (uint64_t)get_le32(s);
376 val |= (uint64_t)get_le32(s) << 32;
de6d9b64
FB
377 return val;
378}
379
380unsigned int get_be16(ByteIOContext *s)
381{
382 unsigned int val;
383 val = get_byte(s) << 8;
384 val |= get_byte(s);
385 return val;
386}
387
388unsigned int get_be32(ByteIOContext *s)
389{
390 unsigned int val;
391 val = get_byte(s) << 24;
392 val |= get_byte(s) << 16;
393 val |= get_byte(s) << 8;
394 val |= get_byte(s);
395 return val;
396}
397
3b4b29dc 398double get_be64_double(ByteIOContext *s)
75bdb984 399{
3b4b29dc
FB
400 union {
401 double d;
0c1a9eda 402 uint64_t ull;
3b4b29dc 403 } u;
75bdb984 404
3b4b29dc
FB
405 u.ull = get_be64(s);
406 return u.d;
75bdb984
PG
407}
408
3b4b29dc 409char *get_strz(ByteIOContext *s, char *buf, int maxlen)
75bdb984
PG
410{
411 int i = 0;
412 char c;
413
414 while ((c = get_byte(s))) {
415 if (i < maxlen-1)
416 buf[i++] = c;
417 }
418
419 buf[i] = 0; /* Ensure null terminated, but may be truncated */
420
421 return buf;
422}
423
0c1a9eda 424uint64_t get_be64(ByteIOContext *s)
de6d9b64 425{
0c1a9eda
ZK
426 uint64_t val;
427 val = (uint64_t)get_be32(s) << 32;
428 val |= (uint64_t)get_be32(s);
de6d9b64
FB
429 return val;
430}
431
432/* link with avio functions */
433
764ef400 434#ifdef CONFIG_ENCODERS
0c1a9eda 435static void url_write_packet(void *opaque, uint8_t *buf, int buf_size)
de6d9b64
FB
436{
437 URLContext *h = opaque;
438 url_write(h, buf, buf_size);
439}
764ef400
MM
440#else
441#define url_write_packet NULL
442#endif //CONFIG_ENCODERS
de6d9b64 443
0c1a9eda 444static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
de6d9b64
FB
445{
446 URLContext *h = opaque;
447 return url_read(h, buf, buf_size);
448}
449
0c1a9eda 450static int url_seek_packet(void *opaque, int64_t offset, int whence)
de6d9b64
FB
451{
452 URLContext *h = opaque;
53e2f9ca
MN
453 return url_seek(h, offset, whence);
454 //return 0;
de6d9b64
FB
455}
456
457int url_fdopen(ByteIOContext *s, URLContext *h)
458{
0c1a9eda 459 uint8_t *buffer;
abba3dd1 460 int buffer_size, max_packet_size;
de6d9b64 461
abba3dd1
FB
462
463 max_packet_size = url_get_max_packet_size(h);
464 if (max_packet_size) {
465 buffer_size = max_packet_size; /* no need to bufferize more than one packet */
466 } else {
467 buffer_size = IO_BUFFER_SIZE;
468 }
1ea4f593 469 buffer = av_malloc(buffer_size);
de6d9b64
FB
470 if (!buffer)
471 return -ENOMEM;
472
473 if (init_put_byte(s, buffer, buffer_size,
ac9fe33d 474 (h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
de6d9b64 475 url_read_packet, url_write_packet, url_seek_packet) < 0) {
1ea4f593 476 av_free(buffer);
0bd586c5 477 return AVERROR_IO;
de6d9b64
FB
478 }
479 s->is_streamed = h->is_streamed;
abba3dd1 480 s->max_packet_size = max_packet_size;
de6d9b64
FB
481 return 0;
482}
483
484/* XXX: must be called before any I/O */
485int url_setbufsize(ByteIOContext *s, int buf_size)
486{
0c1a9eda 487 uint8_t *buffer;
1ea4f593 488 buffer = av_malloc(buf_size);
de6d9b64
FB
489 if (!buffer)
490 return -ENOMEM;
491
1ea4f593 492 av_free(s->buffer);
de6d9b64
FB
493 s->buffer = buffer;
494 s->buffer_size = buf_size;
495 s->buf_ptr = buffer;
496 if (!s->write_flag)
497 s->buf_end = buffer;
498 else
499 s->buf_end = buffer + buf_size;
500 return 0;
501}
502
abba3dd1
FB
503/* NOTE: when opened as read/write, the buffers are only used for
504 reading */
de6d9b64
FB
505int url_fopen(ByteIOContext *s, const char *filename, int flags)
506{
507 URLContext *h;
508 int err;
509
510 err = url_open(&h, filename, flags);
511 if (err < 0)
512 return err;
513 err = url_fdopen(s, h);
514 if (err < 0) {
515 url_close(h);
516 return err;
517 }
518 return 0;
519}
520
521int url_fclose(ByteIOContext *s)
522{
523 URLContext *h = s->opaque;
524
1ea4f593 525 av_free(s->buffer);
de6d9b64
FB
526 memset(s, 0, sizeof(ByteIOContext));
527 return url_close(h);
528}
529
530URLContext *url_fileno(ByteIOContext *s)
531{
532 return s->opaque;
533}
534
764ef400 535#ifdef CONFIG_ENCODERS
abba3dd1
FB
536/* XXX: currently size is limited */
537int url_fprintf(ByteIOContext *s, const char *fmt, ...)
538{
539 va_list ap;
540 char buf[4096];
541 int ret;
542
543 va_start(ap, fmt);
544 ret = vsnprintf(buf, sizeof(buf), fmt, ap);
545 va_end(ap);
546 put_buffer(s, buf, strlen(buf));
547 return ret;
548}
764ef400 549#endif //CONFIG_ENCODERS
abba3dd1
FB
550
551/* note: unlike fgets, the EOL character is not returned and a whole
552 line is parsed. return NULL if first char read was EOF */
553char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
554{
555 int c;
556 char *q;
557
558 c = url_fgetc(s);
559 if (c == EOF)
560 return NULL;
561 q = buf;
562 for(;;) {
563 if (c == EOF || c == '\n')
564 break;
565 if ((q - buf) < buf_size - 1)
566 *q++ = c;
567 c = url_fgetc(s);
568 }
569 if (buf_size > 0)
570 *q = '\0';
571 return buf;
572}
573
574/*
575 * Return the maximum packet size associated to packetized buffered file
576 * handle. If the file is not packetized (stream like http or file on
577 * disk), then 0 is returned.
578 *
579 * @param h buffered file handle
580 * @return maximum packet size in bytes
581 */
582int url_fget_max_packet_size(ByteIOContext *s)
583{
584 return s->max_packet_size;
585}
586
764ef400 587#ifdef CONFIG_ENCODERS
de6d9b64 588/* buffer handling */
0c1a9eda 589int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
de6d9b64
FB
590{
591 return init_put_byte(s, buf, buf_size,
ac9fe33d
GB
592 (flags & URL_WRONLY || flags & URL_RDWR),
593 NULL, NULL, NULL, NULL);
de6d9b64
FB
594}
595
596/* return the written or read size */
597int url_close_buf(ByteIOContext *s)
598{
abba3dd1 599 put_flush_packet(s);
de6d9b64
FB
600 return s->buf_ptr - s->buffer;
601}
abba3dd1
FB
602
603/* output in a dynamic buffer */
604
605typedef struct DynBuffer {
606 int pos, size, allocated_size;
0c1a9eda 607 uint8_t *buffer;
abba3dd1 608 int io_buffer_size;
0c1a9eda 609 uint8_t io_buffer[1];
abba3dd1
FB
610} DynBuffer;
611
0c1a9eda 612static void dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
abba3dd1
FB
613{
614 DynBuffer *d = opaque;
615 int new_size, new_allocated_size;
abba3dd1
FB
616
617 /* reallocate buffer if needed */
618 new_size = d->pos + buf_size;
619 new_allocated_size = d->allocated_size;
620 while (new_size > new_allocated_size) {
621 if (!new_allocated_size)
622 new_allocated_size = new_size;
623 else
64e105e0 624 new_allocated_size = (new_allocated_size * 3) / 2 + 1;
abba3dd1
FB
625 }
626
627 if (new_allocated_size > d->allocated_size) {
b88ba823
MH
628 d->buffer = av_realloc(d->buffer, new_allocated_size);
629 if(d->buffer == NULL)
630 return ;
abba3dd1
FB
631 d->allocated_size = new_allocated_size;
632 }
633 memcpy(d->buffer + d->pos, buf, buf_size);
634 d->pos = new_size;
635 if (d->pos > d->size)
636 d->size = d->pos;
637}
638
0c1a9eda 639static void dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
abba3dd1
FB
640{
641 unsigned char buf1[4];
642
643 /* packetized write: output the header */
644 buf1[0] = (buf_size >> 24);
645 buf1[1] = (buf_size >> 16);
646 buf1[2] = (buf_size >> 8);
647 buf1[3] = (buf_size);
648 dyn_buf_write(opaque, buf1, 4);
649
650 /* then the data */
651 dyn_buf_write(opaque, buf, buf_size);
652}
653
654static int dyn_buf_seek(void *opaque, offset_t offset, int whence)
655{
656 DynBuffer *d = opaque;
657
658 if (whence == SEEK_CUR)
659 offset += d->pos;
660 else if (whence == SEEK_END)
661 offset += d->size;
662 if (offset < 0 || offset > 0x7fffffffLL)
663 return -1;
664 d->pos = offset;
665 return 0;
666}
667
668static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
669{
670 DynBuffer *d;
671 int io_buffer_size, ret;
672
673 if (max_packet_size)
674 io_buffer_size = max_packet_size;
675 else
676 io_buffer_size = 1024;
677
678 d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
679 if (!d)
680 return -1;
681 d->io_buffer_size = io_buffer_size;
682 d->buffer = NULL;
683 d->pos = 0;
684 d->size = 0;
685 d->allocated_size = 0;
686 ret = init_put_byte(s, d->io_buffer, io_buffer_size,
687 1, d, NULL,
688 max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
689 max_packet_size ? NULL : dyn_buf_seek);
690 if (ret == 0) {
691 s->max_packet_size = max_packet_size;
692 }
693 return ret;
694}
695
696/*
697 * Open a write only memory stream.
698 *
699 * @param s new IO context
700 * @return zero if no error.
701 */
702int url_open_dyn_buf(ByteIOContext *s)
703{
704 return url_open_dyn_buf_internal(s, 0);
705}
706
707/*
708 * Open a write only packetized memory stream with a maximum packet
709 * size of 'max_packet_size'. The stream is stored in a memory buffer
710 * with a big endian 4 byte header giving the packet size in bytes.
711 *
712 * @param s new IO context
713 * @param max_packet_size maximum packet size (must be > 0)
714 * @return zero if no error.
715 */
716int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
717{
718 if (max_packet_size <= 0)
719 return -1;
720 return url_open_dyn_buf_internal(s, max_packet_size);
721}
722
723/*
724 * Return the written size and a pointer to the buffer. The buffer
725 * must be freed with av_free().
726 * @param s IO context
727 * @param pointer to a byte buffer
728 * @return the length of the byte buffer
729 */
0c1a9eda 730int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
abba3dd1
FB
731{
732 DynBuffer *d = s->opaque;
733 int size;
734
735 put_flush_packet(s);
736
737 *pbuffer = d->buffer;
738 size = d->size;
739 av_free(d);
740 return size;
741}
764ef400 742#endif //CONFIG_ENCODERS