annotate src/wma/libffwma/aviobuf.c @ 878:aa044d71838f trunk

[svn] Goodbye ffmpeg, welcome back WMA.
author chainsaw
date Mon, 19 Mar 2007 13:15:52 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
878
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
1 /*
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
2 * Buffered I/O for ffmpeg system
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
3 * Copyright (c) 2000,2001 Fabrice Bellard
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
4 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
9 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
13 * Lesser General Public License for more details.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
14 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
18 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
19 #include "avformat.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
20 #include "avio.h"
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
21 #include <stdarg.h>
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
22
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
23 #define IO_BUFFER_SIZE 32768
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
24
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
25 int init_put_byte(ByteIOContext *s,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
26 unsigned char *buffer,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
27 int buffer_size,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
28 int write_flag,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
29 void *opaque,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
30 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
31 void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
32 int (*seek)(void *opaque, offset_t offset, int whence))
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
33 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
34 s->buffer = buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
35 s->buffer_size = buffer_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
36 s->buf_ptr = buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
37 s->write_flag = write_flag;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
38 if (!s->write_flag)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
39 s->buf_end = buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
40 else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
41 s->buf_end = buffer + buffer_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
42 s->opaque = opaque;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
43 s->write_packet = write_packet;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
44 s->read_packet = read_packet;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
45 s->seek = seek;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
46 s->pos = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
47 s->must_flush = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
48 s->eof_reached = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
49 s->is_streamed = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
50 s->max_packet_size = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
51 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
52 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
53
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
54 offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
55 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
56 offset_t offset1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
57
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
58 if (whence != SEEK_CUR && whence != SEEK_SET)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
59 return -EINVAL;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
60
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
61 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
62 if (whence == SEEK_CUR) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
63 offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
64 if (offset == 0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
65 return offset1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
66 offset += offset1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
67 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
68 offset1 = offset - (s->pos - (s->buf_end - s->buffer));
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
69 if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
70 /* can do the seek inside the buffer */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
71 s->buf_ptr = s->buffer + offset1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
72 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
73 if (!s->seek)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
74 return -EPIPE;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
75 s->buf_ptr = s->buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
76 s->buf_end = s->buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
77 s->seek(s->opaque, offset, SEEK_SET);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
78 s->pos = offset;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
79 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
80 s->eof_reached = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
81 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
82 return offset;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
83 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
84
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
85 void url_fskip(ByteIOContext *s, offset_t offset)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
86 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
87 url_fseek(s, offset, SEEK_CUR);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
88 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
89
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
90 offset_t url_ftell(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
91 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
92 return url_fseek(s, 0, SEEK_CUR);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
93 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
94
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
95 int url_feof(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
96 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
97 return s->eof_reached;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
98 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
99
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
100 /* Input stream */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
101
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
102 static void fill_buffer(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
103 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
104 int len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
105
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
106 /* no need to do anything if EOF already reached */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
107 if (s->eof_reached)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
108 return;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
109 len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
110 if (len <= 0) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
111 /* do not modify buffer if EOF reached so that a seek back can
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
112 be done without rereading data */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
113 s->eof_reached = 1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
114 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
115 s->pos += len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
116 s->buf_ptr = s->buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
117 s->buf_end = s->buffer + len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
118 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
119 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
120
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
121 /* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
122 necessary */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
123 /* XXX: put an inline version */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
124 int get_byte(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
125 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
126 if (s->buf_ptr < s->buf_end) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
127 return *s->buf_ptr++;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
128 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
129 fill_buffer(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
130 if (s->buf_ptr < s->buf_end)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
131 return *s->buf_ptr++;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
132 else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
133 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
134 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
135 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
136
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
137 /* NOTE: return URL_EOF (-1) if EOF */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
138 int url_fgetc(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
139 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
140 if (s->buf_ptr < s->buf_end) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
141 return *s->buf_ptr++;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
142 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
143 fill_buffer(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
144 if (s->buf_ptr < s->buf_end)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
145 return *s->buf_ptr++;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
146 else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
147 return URL_EOF;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
148 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
149 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
150
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
151 int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
152 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
153 int len, size1;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
154
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
155 size1 = size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
156 while (size > 0) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
157 len = s->buf_end - s->buf_ptr;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
158 if (len > size)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
159 len = size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
160 if (len == 0) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
161 fill_buffer(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
162 len = s->buf_end - s->buf_ptr;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
163 if (len == 0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
164 break;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
165 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
166 memcpy(buf, s->buf_ptr, len);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
167 buf += len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
168 s->buf_ptr += len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
169 size -= len;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
170 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
171 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
172 return size1 - size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
173 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
174
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
175 unsigned int get_le16(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
176 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
177 unsigned int val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
178 val = get_byte(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
179 val |= get_byte(s) << 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
180 return val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
181 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
182
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
183 unsigned int get_le32(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
184 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
185 unsigned int val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
186 val = get_byte(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
187 val |= get_byte(s) << 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
188 val |= get_byte(s) << 16;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
189 val |= get_byte(s) << 24;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
190 return val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
191 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
192
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
193 uint64_t get_le64(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
194 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
195 uint64_t val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
196 val = (uint64_t)get_le32(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
197 val |= (uint64_t)get_le32(s) << 32;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
198 return val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
199 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
200
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
201 unsigned int get_be16(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
202 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
203 unsigned int val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
204 val = get_byte(s) << 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
205 val |= get_byte(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
206 return val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
207 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
208
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
209 unsigned int get_be32(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
210 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
211 unsigned int val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
212 val = get_byte(s) << 24;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
213 val |= get_byte(s) << 16;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
214 val |= get_byte(s) << 8;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
215 val |= get_byte(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
216 return val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
217 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
218
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
219 double get_be64_double(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
220 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
221 union {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
222 double d;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
223 uint64_t ull;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
224 } u;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
225
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
226 u.ull = get_be64(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
227 return u.d;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
228 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
229
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
230 char *get_strz(ByteIOContext *s, char *buf, int maxlen)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
231 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
232 int i = 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
233 char c;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
234
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
235 while ((c = get_byte(s))) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
236 if (i < maxlen-1)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
237 buf[i++] = c;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
238 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
239
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
240 buf[i] = 0; /* Ensure null terminated, but may be truncated */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
241
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
242 return buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
243 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
244
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
245 uint64_t get_be64(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
246 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
247 uint64_t val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
248 val = (uint64_t)get_be32(s) << 32;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
249 val |= (uint64_t)get_be32(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
250 return val;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
251 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
252
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
253 /* link with avio functions */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
254
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
255 #define url_write_packet NULL
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
256
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
257 static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
258 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
259 URLContext *h = opaque;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
260 return url_read(h, buf, buf_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
261 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
262
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
263 static int url_seek_packet(void *opaque, int64_t offset, int whence)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
264 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
265 URLContext *h = opaque;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
266 url_seek(h, offset, whence);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
267 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
268 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
269
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
270 int url_fdopen(ByteIOContext *s, URLContext *h)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
271 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
272 uint8_t *buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
273 int buffer_size, max_packet_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
274
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
275 max_packet_size = url_get_max_packet_size(h);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
276 if (max_packet_size) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
277 buffer_size = max_packet_size; /* no need to bufferize more than one packet */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
278 } else {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
279 buffer_size = IO_BUFFER_SIZE;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
280 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
281 buffer = av_mallocz(buffer_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
282 if (!buffer)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
283 return -ENOMEM;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
284
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
285 if (init_put_byte(s, buffer, buffer_size,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
286 (h->flags & URL_WRONLY) != 0, h,
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
287 url_read_packet, url_write_packet, url_seek_packet) < 0) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
288 free(buffer);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
289 return -EIO;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
290 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
291 s->is_streamed = h->is_streamed;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
292 s->max_packet_size = max_packet_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
293 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
294 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
295
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
296 /* XXX: must be called before any I/O */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
297 int url_setbufsize(ByteIOContext *s, int buf_size)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
298 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
299 uint8_t *buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
300 buffer = av_malloc(buf_size);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
301 if (!buffer)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
302 return -ENOMEM;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
303
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
304 free(s->buffer);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
305 s->buffer = buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
306 s->buffer_size = buf_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
307 s->buf_ptr = buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
308 if (!s->write_flag)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
309 s->buf_end = buffer;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
310 else
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
311 s->buf_end = buffer + buf_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
312 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
313 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
314
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
315 /* NOTE: when opened as read/write, the buffers are only used for
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
316 reading */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
317 int url_fopen(ByteIOContext *s, const char *filename, int flags)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
318 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
319 URLContext *h;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
320 int err;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
321
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
322 err = url_open(&h, filename, flags);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
323 if (err < 0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
324 return err;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
325 err = url_fdopen(s, h);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
326 if (err < 0) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
327 url_close(h);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
328 return err;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
329 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
330 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
331 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
332
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
333 int url_vfdopen(ByteIOContext *s, VFSFile *fd)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
334 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
335 URLContext *h;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
336 int err;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
337
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
338 err = url_vopen(&h, fd);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
339 if (err < 0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
340 return err;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
341 err = url_fdopen(s, h);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
342 if (err < 0) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
343 return err;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
344 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
345 return 0;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
346 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
347
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
348 int url_fclose(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
349 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
350 URLContext *h = s->opaque;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
351
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
352 free(s->buffer);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
353 memset(s, 0, sizeof(ByteIOContext));
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
354 return url_close(h);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
355 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
356
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
357 URLContext *url_fileno(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
358 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
359 return s->opaque;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
360 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
361
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
362 /* note: unlike fgets, the EOL character is not returned and a whole
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
363 line is parsed. return NULL if first char read was EOF */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
364 char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
365 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
366 int c;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
367 char *q;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
368
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
369 c = url_fgetc(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
370 if (c == EOF)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
371 return NULL;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
372 q = buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
373 for(;;) {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
374 if (c == EOF || c == '\n')
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
375 break;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
376 if ((q - buf) < buf_size - 1)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
377 *q++ = c;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
378 c = url_fgetc(s);
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
379 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
380 if (buf_size > 0)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
381 *q = '\0';
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
382 return buf;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
383 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
384
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
385 /*
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
386 * Return the maximum packet size associated to packetized buffered file
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
387 * handle. If the file is not packetized (stream like http or file on
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
388 * disk), then 0 is returned.
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
389 *
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
390 * @param h buffered file handle
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
391 * @return maximum packet size in bytes
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
392 */
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
393 int url_fget_max_packet_size(ByteIOContext *s)
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
394 {
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
395 return s->max_packet_size;
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
396 }
aa044d71838f [svn] Goodbye ffmpeg, welcome back WMA.
chainsaw
parents:
diff changeset
397