annotate src/ffmpeg/libavformat/aviobuf.c @ 841:9b50e71f7307 trunk

[svn] - implement shorten support more correctly.
author nenolod
date Mon, 12 Mar 2007 17:37:02 -0700
parents 52c45849841e
children e00028eb356c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1 /*
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
2 * Buffered I/O for ffmpeg system
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
3 * Copyright (c) 2000,2001 Fabrice Bellard
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
4 *
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
5 * This library is free software; you can redistribute it and/or
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
8 * version 2 of the License, or (at your option) any later version.
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
9 *
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
10 * This library is distributed in the hope that it will be useful,
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
13 * Lesser General Public License for more details.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
14 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
16 * License along with this library; if not, write to the Free Software
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
18 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
19 #include "avformat.h"
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
20 #include "avio.h"
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
21 #include <stdarg.h>
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
22
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
23 #define IO_BUFFER_SIZE 32768
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
24
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
25 int init_put_byte(ByteIOContext *s,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
26 unsigned char *buffer,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
27 int buffer_size,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
28 int write_flag,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
29 void *opaque,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
30 int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
31 void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
32 int (*seek)(void *opaque, offset_t offset, int whence))
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
33 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
34 s->buffer = buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
35 s->buffer_size = buffer_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
36 s->buf_ptr = buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
37 s->write_flag = write_flag;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
38 if (!s->write_flag)
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
39 s->buf_end = buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
40 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
41 s->buf_end = buffer + buffer_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
42 s->opaque = opaque;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
43 s->write_packet = write_packet;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
44 s->read_packet = read_packet;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
45 s->seek = seek;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
46 s->pos = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
47 s->must_flush = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
48 s->eof_reached = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
49 s->is_streamed = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
50 s->max_packet_size = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
51 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
52 }
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
53
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
54 offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
55 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
56 offset_t offset1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
57
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
58 if (whence != SEEK_CUR && whence != SEEK_SET)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
59 return -EINVAL;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
60
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
61 {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
62 if (whence == SEEK_CUR) {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
63 offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
64 if (offset == 0)
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
65 return offset1;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
66 offset += offset1;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
67 }
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
68 offset1 = offset - (s->pos - (s->buf_end - s->buffer));
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
69 if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
70 /* can do the seek inside the buffer */
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
71 s->buf_ptr = s->buffer + offset1;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
72 } else {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
73 if (!s->seek)
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
74 return -EPIPE;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
75 s->buf_ptr = s->buffer;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
76 s->buf_end = s->buffer;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
77 s->seek(s->opaque, offset, SEEK_SET);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
78 s->pos = offset;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
79 }
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
80 s->eof_reached = 0;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
81 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
82 return offset;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
83 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
84
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
85 void url_fskip(ByteIOContext *s, offset_t offset)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
86 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
87 url_fseek(s, offset, SEEK_CUR);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
88 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
89
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
90 offset_t url_ftell(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
91 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
92 return url_fseek(s, 0, SEEK_CUR);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
93 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
94
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
95 int url_feof(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
96 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
97 return s->eof_reached;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
98 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
99
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
100 /* Input stream */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
101
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
102 static void fill_buffer(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
103 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
104 int len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
105
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
106 /* no need to do anything if EOF already reached */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
107 if (s->eof_reached)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
108 return;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
109 len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
110 if (len <= 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
111 /* do not modify buffer if EOF reached so that a seek back can
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
112 be done without rereading data */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
113 s->eof_reached = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
114 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
115 s->pos += len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
116 s->buf_ptr = s->buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
117 s->buf_end = s->buffer + len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
118 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
119 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
120
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
121 /* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
122 necessary */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
123 /* XXX: put an inline version */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
124 int get_byte(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
125 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
126 if (s->buf_ptr < s->buf_end) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
127 return *s->buf_ptr++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
128 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
129 fill_buffer(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
130 if (s->buf_ptr < s->buf_end)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
131 return *s->buf_ptr++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
132 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
133 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
134 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
135 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
136
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
137 /* NOTE: return URL_EOF (-1) if EOF */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
138 int url_fgetc(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
139 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
140 if (s->buf_ptr < s->buf_end) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
141 return *s->buf_ptr++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
142 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
143 fill_buffer(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
144 if (s->buf_ptr < s->buf_end)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
145 return *s->buf_ptr++;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
146 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
147 return URL_EOF;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
148 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
149 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
150
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
151 int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
152 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
153 int len, size1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
154
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
155 size1 = size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
156 while (size > 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
157 len = s->buf_end - s->buf_ptr;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
158 if (len > size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
159 len = size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
160 if (len == 0) {
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
161 fill_buffer(s);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
162 len = s->buf_end - s->buf_ptr;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
163 if (len == 0)
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
164 break;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
165 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
166 memcpy(buf, s->buf_ptr, len);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
167 buf += len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
168 s->buf_ptr += len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
169 size -= len;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
170 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
171 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
172 return size1 - size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
173 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
174
828
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
175 int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
176 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
177 int len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
178
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
179 if(size<0)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
180 return -1;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
181
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
182 len = s->buf_end - s->buf_ptr;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
183 if (len == 0) {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
184 fill_buffer(s);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
185 len = s->buf_end - s->buf_ptr;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
186 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
187 if (len > size)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
188 len = size;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
189 memcpy(buf, s->buf_ptr, len);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
190 s->buf_ptr += len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
191 return len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
192 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
193
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
194 unsigned int get_le16(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
195 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
196 unsigned int val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
197 val = get_byte(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
198 val |= get_byte(s) << 8;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
199 return val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
200 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
201
828
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
202 unsigned int get_le24(ByteIOContext *s)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
203 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
204 unsigned int val;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
205 val = get_le16(s);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
206 val |= get_byte(s) << 16;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
207 return val;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
208 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
209
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
210 unsigned int get_le32(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
211 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
212 unsigned int val;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
213 val = get_byte(s);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
214 val |= get_byte(s) << 8;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
215 val |= get_byte(s) << 16;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
216 val |= get_byte(s) << 24;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
217 return val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
218 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
219
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
220 uint64_t get_le64(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
221 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
222 uint64_t val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
223 val = (uint64_t)get_le32(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
224 val |= (uint64_t)get_le32(s) << 32;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
225 return val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
226 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
227
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
228 unsigned int get_be16(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
229 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
230 unsigned int val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
231 val = get_byte(s) << 8;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
232 val |= get_byte(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
233 return val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
234 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
235
828
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
236 unsigned int get_be24(ByteIOContext *s)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
237 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
238 unsigned int val;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
239 val = get_be16(s) << 8;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
240 val |= get_byte(s);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
241 return val;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
242 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
243
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
244 unsigned int get_be32(ByteIOContext *s)
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
245 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
246 unsigned int val;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
247 val = get_byte(s) << 24;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
248 val |= get_byte(s) << 16;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
249 val |= get_byte(s) << 8;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
250 val |= get_byte(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
251 return val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
252 }
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
253
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
254 double get_be64_double(ByteIOContext *s)
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
255 {
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
256 union {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
257 double d;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
258 uint64_t ull;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
259 } u;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
260
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
261 u.ull = get_be64(s);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
262 return u.d;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
263 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
264
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
265 char *get_strz(ByteIOContext *s, char *buf, int maxlen)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
266 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
267 int i = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
268 char c;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
269
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
270 while ((c = get_byte(s))) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
271 if (i < maxlen-1)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
272 buf[i++] = c;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
273 }
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
274
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
275 buf[i] = 0; /* Ensure null terminated, but may be truncated */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
276
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
277 return buf;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
278 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
279
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
280 uint64_t get_be64(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
281 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
282 uint64_t val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
283 val = (uint64_t)get_be32(s) << 32;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
284 val |= (uint64_t)get_be32(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
285 return val;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
286 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
287
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
288 /* link with avio functions */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
289
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
290 #define url_write_packet NULL
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
291
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
292 static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
293 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
294 URLContext *h = opaque;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
295 return url_read(h, buf, buf_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
296 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
297
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
298 static int url_seek_packet(void *opaque, int64_t offset, int whence)
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
299 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
300 URLContext *h = opaque;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
301 url_seek(h, offset, whence);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
302 return 0;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
303 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
304
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
305 int url_fdopen(ByteIOContext *s, URLContext *h)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
306 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
307 uint8_t *buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
308 int buffer_size, max_packet_size;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
309
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
310 max_packet_size = url_get_max_packet_size(h);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
311 if (max_packet_size) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
312 buffer_size = max_packet_size; /* no need to bufferize more than one packet */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
313 } else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
314 buffer_size = IO_BUFFER_SIZE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
315 }
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
316 buffer = av_mallocz(buffer_size);
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
317 if (!buffer)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
318 return -ENOMEM;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
319
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
320 if (init_put_byte(s, buffer, buffer_size,
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
321 (h->flags & URL_WRONLY) != 0, h,
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
322 url_read_packet, url_write_packet, url_seek_packet) < 0) {
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
323 free(buffer);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
324 return -EIO;
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
325 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
326 s->is_streamed = h->is_streamed;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
327 s->max_packet_size = max_packet_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
328 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
329 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
330
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
331 /* XXX: must be called before any I/O */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
332 int url_setbufsize(ByteIOContext *s, int buf_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
333 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
334 uint8_t *buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
335 buffer = av_malloc(buf_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
336 if (!buffer)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
337 return -ENOMEM;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
338
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
339 free(s->buffer);
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
340 s->buffer = buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
341 s->buffer_size = buf_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
342 s->buf_ptr = buffer;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
343 if (!s->write_flag)
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
344 s->buf_end = buffer;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
345 else
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
346 s->buf_end = buffer + buf_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
347 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
348 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
349
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
350 /* NOTE: when opened as read/write, the buffers are only used for
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
351 reading */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
352 int url_fopen(ByteIOContext *s, const char *filename, int flags)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
353 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
354 URLContext *h;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
355 int err;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
356
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
357 err = url_open(&h, filename, flags);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
358 if (err < 0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
359 return err;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
360 err = url_fdopen(s, h);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
361 if (err < 0) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
362 url_close(h);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
363 return err;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
364 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
365 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
366 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
367
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
368 int url_vfdopen(ByteIOContext *s, VFSFile *fd)
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
369 {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
370 URLContext *h;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
371 int err;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
372
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
373 err = url_vopen(&h, fd);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
374 if (err < 0)
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
375 return err;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
376 err = url_fdopen(s, h);
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
377 if (err < 0) {
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
378 return err;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
379 }
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
380 return 0;
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
381 }
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
382
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
383 int url_fclose(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
384 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
385 URLContext *h = s->opaque;
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
386
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
387 free(s->buffer);
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
388 memset(s, 0, sizeof(ByteIOContext));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
389 return url_close(h);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
390 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
391
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
392 URLContext *url_fileno(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
393 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
394 return s->opaque;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
395 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
396
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
397 /* note: unlike fgets, the EOL character is not returned and a whole
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
398 line is parsed. return NULL if first char read was EOF */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
399 char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
400 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
401 int c;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
402 char *q;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
403
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
404 c = url_fgetc(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
405 if (c == EOF)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
406 return NULL;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
407 q = buf;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
408 for(;;) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
409 if (c == EOF || c == '\n')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
410 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
411 if ((q - buf) < buf_size - 1)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
412 *q++ = c;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
413 c = url_fgetc(s);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
414 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
415 if (buf_size > 0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
416 *q = '\0';
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
417 return buf;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
418 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
419
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
420 /*
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
421 * Return the maximum packet size associated to packetized buffered file
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
422 * handle. If the file is not packetized (stream like http or file on
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
423 * disk), then 0 is returned.
823
a195f1259a6b [svn] - merge VFS support from wma plugin.
nenolod
parents: 808
diff changeset
424 *
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
425 * @param h buffered file handle
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
426 * @return maximum packet size in bytes
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
427 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
428 int url_fget_max_packet_size(ByteIOContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
429 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
430 return s->max_packet_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
431 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
432
824
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
433 offset_t url_fsize(ByteIOContext *s)
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
434 {
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
435 offset_t size;
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
436
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
437 if (!s->seek)
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
438 return -EPIPE;
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
439 size = s->seek(s->opaque, -1, SEEK_END) + 1;
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
440 s->seek(s->opaque, s->pos, SEEK_SET);
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
441 return size;
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
442 }
420eb823b2d4 [svn] - url_fsize support.
nenolod
parents: 823
diff changeset
443
828
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
444 static void flush_buffer(ByteIOContext *s)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
445 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
446 if (s->buf_ptr > s->buffer) {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
447 if (s->write_packet){
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
448 s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
449 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
450 s->pos += s->buf_ptr - s->buffer;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
451 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
452 s->buf_ptr = s->buffer;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
453 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
454
832
52c45849841e [svn] - works
nenolod
parents: 830
diff changeset
455 void put_flush_packet(ByteIOContext *s)
52c45849841e [svn] - works
nenolod
parents: 830
diff changeset
456 {
52c45849841e [svn] - works
nenolod
parents: 830
diff changeset
457 flush_buffer(s);
52c45849841e [svn] - works
nenolod
parents: 830
diff changeset
458 s->must_flush = 0;
52c45849841e [svn] - works
nenolod
parents: 830
diff changeset
459 }
52c45849841e [svn] - works
nenolod
parents: 830
diff changeset
460
828
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
461 void put_byte(ByteIOContext *s, int b)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
462 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
463 *(s->buf_ptr)++ = b;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
464 if (s->buf_ptr >= s->buf_end)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
465 flush_buffer(s);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
466 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
467
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
468 void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
469 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
470 int len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
471
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
472 while (size > 0) {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
473 len = (s->buf_end - s->buf_ptr);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
474 if (len > size)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
475 len = size;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
476 memcpy(s->buf_ptr, buf, len);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
477 s->buf_ptr += len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
478
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
479 if (s->buf_ptr >= s->buf_end)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
480 flush_buffer(s);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
481
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
482 buf += len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
483 size -= len;
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
484 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
485 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
486
830
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
487 void put_le32(ByteIOContext *s, unsigned int val)
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
488 {
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
489 put_byte(s, val);
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
490 put_byte(s, val >> 8);
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
491 put_byte(s, val >> 16);
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
492 put_byte(s, val >> 24);
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
493 }
68562d99230f [svn] - more symbol cleanups.
nenolod
parents: 828
diff changeset
494
828
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
495 void put_be32(ByteIOContext *s, unsigned int val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
496 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
497 put_byte(s, val >> 24);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
498 put_byte(s, val >> 16);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
499 put_byte(s, val >> 8);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
500 put_byte(s, val);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
501 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
502
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
503 void put_strz(ByteIOContext *s, const char *str)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
504 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
505 if (str)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
506 put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
507 else
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
508 put_byte(s, 0);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
509 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
510
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
511 void put_le64(ByteIOContext *s, uint64_t val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
512 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
513 put_le32(s, (uint32_t)(val & 0xffffffff));
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
514 put_le32(s, (uint32_t)(val >> 32));
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
515 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
516
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
517 void put_be64(ByteIOContext *s, uint64_t val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
518 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
519 put_be32(s, (uint32_t)(val >> 32));
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
520 put_be32(s, (uint32_t)(val & 0xffffffff));
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
521 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
522
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
523 void put_le16(ByteIOContext *s, unsigned int val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
524 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
525 put_byte(s, val);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
526 put_byte(s, val >> 8);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
527 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
528
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
529 void put_be16(ByteIOContext *s, unsigned int val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
530 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
531 put_byte(s, val >> 8);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
532 put_byte(s, val);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
533 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
534
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
535 void put_le24(ByteIOContext *s, unsigned int val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
536 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
537 put_le16(s, val & 0xffff);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
538 put_byte(s, val >> 16);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
539 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
540
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
541 void put_be24(ByteIOContext *s, unsigned int val)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
542 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
543 put_be16(s, val >> 8);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
544 put_byte(s, val);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
545 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
546
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
547 void put_tag(ByteIOContext *s, const char *tag)
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
548 {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
549 while (*tag) {
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
550 put_byte(s, *tag++);
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
551 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
552 }
c294c4700937 [svn] - more stuff to kill
nenolod
parents: 824
diff changeset
553