2 Copyright (C) 2003 Commonwealth Scientific and Industrial Research
3 Organisation (CSIRO) Australia
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 - Neither the name of CSIRO Australia nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
24 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * oggplay_file_reader.c
36 * Shane Stephens <shane.stephens@annodex.net>
40 #include "oggplay_private.h"
41 #include "oggplay_file_reader.h"
47 oggplay_file_reader_initialise(OggPlayReader
* opr
, int block
) {
49 OggPlayFileReader
* me
= (OggPlayFileReader
*)opr
;
50 (void)block
; /* unused for file readers */
53 return E_OGGPLAY_BAD_READER
;
56 me
->file
= fopen(me
->file_name
, "rb");
58 if (me
->file
== NULL
) {
59 return E_OGGPLAY_BAD_INPUT
;
62 fseek(me
->file
, 0L, SEEK_END
);
63 me
->size
= ftell(me
->file
);
64 fseek(me
->file
, 0L, SEEK_SET
);
66 me
->current_position
= 0;
72 oggplay_file_reader_destroy(OggPlayReader
* opr
) {
74 OggPlayFileReader
* me
;
77 return E_OGGPLAY_BAD_READER
;
80 me
= (OggPlayFileReader
*)opr
;
82 if (me
->file
!= NULL
) {
92 oggplay_file_reader_available(OggPlayReader
* opr
, ogg_int64_t current_bytes
,
93 ogg_int64_t current_time
) {
95 OggPlayFileReader
*me
= (OggPlayFileReader
*)opr
;
106 oggplay_file_reader_finished_retrieving(OggPlayReader
*opr
) {
114 oggplay_file_reader_io_read(void * user_handle
, void * buf
, size_t n
) {
116 OggPlayFileReader
*me
= (OggPlayFileReader
*)user_handle
;
123 r
= fread(buf
, 1, n
, me
->file
);
125 me
->current_position
+= r
;
132 oggplay_file_reader_io_seek(void * user_handle
, long offset
, int whence
) {
134 OggPlayFileReader
* me
= (OggPlayFileReader
*)user_handle
;
141 r
= fseek(me
->file
, offset
, whence
);
142 me
->current_position
= ftell(me
->file
);
148 oggplay_file_reader_io_tell(void * user_handle
) {
150 OggPlayFileReader
* me
= (OggPlayFileReader
*)user_handle
;
156 return ftell(me
->file
);
161 oggplay_file_reader_new(const char *file_name
) {
163 OggPlayFileReader
* me
= oggplay_malloc (sizeof (OggPlayFileReader
));
168 me
->current_position
= 0;
169 me
->file_name
= file_name
;
172 me
->functions
.initialise
= &oggplay_file_reader_initialise
;
173 me
->functions
.destroy
= &oggplay_file_reader_destroy
;
174 me
->functions
.available
= &oggplay_file_reader_available
;
175 me
->functions
.finished_retrieving
= &oggplay_file_reader_finished_retrieving
;
176 me
->functions
.seek
= NULL
;
177 me
->functions
.duration
= NULL
;
178 me
->functions
.io_read
= &oggplay_file_reader_io_read
;
179 me
->functions
.io_seek
= &oggplay_file_reader_io_seek
;
180 me
->functions
.io_tell
= &oggplay_file_reader_io_tell
;
181 me
->functions
.duration
= NULL
;
183 return (OggPlayReader
*)me
;