annotate Plugins/Input/wma/libffwma/aviobuf.c @ 210:12004b385a96 trunk

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