annotate Plugins/Input/wma/libffwma/file.c @ 926:3d4af4890339 trunk

[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
author chainsaw
date Wed, 12 Apr 2006 13:35:24 -0700
parents d539e5c5f730
children a63e0fdb3d1e
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 file io for ffmpeg system
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
3 * Copyright (c) 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"
255
ad1e65c6a854 [svn] Create some proper headers and include them. No more implicit declarations.
chainsaw
parents: 218
diff changeset
20 #include "cutils.h"
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
21 #include <fcntl.h>
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
22 #include <unistd.h>
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
23 #include <sys/ioctl.h>
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
24 #include <sys/time.h>
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
25 #include "libaudacious/vfs.h"
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
26
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
27 /* standard file protocol */
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
28
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
29 static int file_open(URLContext *h, const char *filename, int flags)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
30 {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
31 VFSFile *file;
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
32
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
33 strstart(filename, "file:", &filename);
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
34
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
35 if (flags & URL_WRONLY) {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
36 file = vfs_fopen(filename, "wb");
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
37 } else {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
38 file = vfs_fopen(filename, "rb");
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
39 }
218
0bea7509d6ba [svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents: 210
diff changeset
40
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
41 if (file == NULL)
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
42 return -ENOENT;
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
43 h->priv_data = file;
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
44 return 0;
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
45 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
46
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
47 static int file_read(URLContext *h, unsigned char *buf, int size)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
48 {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
49 VFSFile *file;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
50 file = h->priv_data;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
51 return vfs_fread(buf, 1, size, file);
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
52 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
53
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
54 static int file_write(URLContext *h, unsigned char *buf, int size)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
55 {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
56 VFSFile *file;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
57 file = h->priv_data;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
58 return vfs_fwrite(buf, 1, size, file);
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
59 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
60
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
61 /* XXX: use llseek */
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
62 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
63 {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
64 int result = 0;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
65 VFSFile *file;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
66 file = h->priv_data;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
67 result = vfs_fseek(file, pos, whence);
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
68 if (result == 0)
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
69 result = vfs_ftell(file);
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
70 else
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
71 result = -1;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
72 return result;
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
73 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
74
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
75 static int file_close(URLContext *h)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
76 {
926
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
77 VFSFile *file;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
78 file = h->priv_data;
3d4af4890339 [svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents: 701
diff changeset
79 return vfs_fclose(file);
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
80 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
81
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
82 URLProtocol file_protocol = {
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
83 "file",
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
84 file_open,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
85 file_read,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
86 file_write,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
87 file_seek,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
88 file_close,
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 258
diff changeset
89 NULL
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
90 };
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
91
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
92 /* pipe protocol */
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
93
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
94 static int pipe_open(URLContext *h, const char *filename, int flags)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
95 {
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
96 int fd;
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
97
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
98 if (flags & URL_WRONLY) {
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
99 fd = 1;
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
100 } else {
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
101 fd = 0;
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
102 }
258
f4a57eac3ba3 [svn] Last bit of cast rework by Stephen Bennett.
chainsaw
parents: 255
diff changeset
103 h->priv_data = (void *)(long)fd;
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
104 return 0;
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
105 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
106
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
107 static int pipe_read(URLContext *h, unsigned char *buf, int size)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
108 {
258
f4a57eac3ba3 [svn] Last bit of cast rework by Stephen Bennett.
chainsaw
parents: 255
diff changeset
109 int fd = (int)(long)h->priv_data;
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
110 return read(fd, buf, size);
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
111 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
112
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
113 static int pipe_write(URLContext *h, unsigned char *buf, int size)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
114 {
258
f4a57eac3ba3 [svn] Last bit of cast rework by Stephen Bennett.
chainsaw
parents: 255
diff changeset
115 int fd = (int)(long)h->priv_data;
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
116 return write(fd, buf, size);
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
117 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
118
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
119 static int pipe_close(URLContext *h)
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
120 {
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
121 return 0;
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
122 }
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
123
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
124 URLProtocol pipe_protocol = {
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
125 "pipe",
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
126 pipe_open,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
127 pipe_read,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
128 pipe_write,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
129 NULL,
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
130 pipe_close,
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 258
diff changeset
131 NULL
137
b8d4c1faa6d7 [svn] Import WMA decoder into SVN.
nenolod
parents:
diff changeset
132 };