1 /*
2   Copyright (c) 2005-2009, The Musepack Development Team
3   All rights reserved.
4 
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions are
7   met:
8 
9   * Redistributions of source code must retain the above copyright
10   notice, this list of conditions and the following disclaimer.
11 
12   * Redistributions in binary form must reproduce the above
13   copyright notice, this list of conditions and the following
14   disclaimer in the documentation and/or other materials provided
15   with the distribution.
16 
17   * Neither the name of the The Musepack Development Team nor the
18   names of its contributors may be used to endorse or promote
19   products derived from this software without specific prior
20   written permission.
21 
22   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 /// \file reader.h
35 #ifndef _MPCDEC_READER_H_
36 #define _MPCDEC_READER_H_
37 #ifdef WIN32
38 #pragma once
39 #endif
40 
41 #include "mpc_types.h"
42 #include <stdio.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 
49 /// \brief Stream reader interface structure.
50 ///
51 /// This is the structure you must supply to the musepack decoding library
52 /// to feed it with raw data.  Implement the five member functions to provide
53 /// a functional reader.
54 typedef struct mpc_reader_t mpc_reader;
55 struct mpc_reader_t {
56     /// Reads size bytes of data into buffer at ptr.
57     mpc_int32_t (*read)(mpc_reader *p_reader, void *ptr, mpc_int32_t size);
58 
59     /// Seeks to byte position offset.
60     mpc_bool_t (*seek)(mpc_reader *p_reader, mpc_int32_t offset);
61 
62     /// Returns the current byte offset in the stream.
63     mpc_int32_t (*tell)(mpc_reader *p_reader);
64 
65     /// Returns the total length of the source stream, in bytes.
66     mpc_int32_t (*get_size)(mpc_reader *p_reader);
67 
68     /// True if the stream is a seekable stream.
69     mpc_bool_t (*canseek)(mpc_reader *p_reader);
70 
71     /// Field that can be used to identify a particular instance of
72     /// reader or carry along data associated with that reader.
73     void *data;
74 };
75 
76 /// Initializes reader with default stdio file reader implementation.  Use
77 /// this if you're just reading from a plain file.
78 ///
79 /// \param r p_reader handle to initialize
80 /// \param filename input filename to attach to the reader
81 MPC_API mpc_status mpc_reader_init_stdio(mpc_reader *p_reader, const char *filename);
82 
83 /// Initializes reader with default stdio file reader implementation.  Use
84 /// this if you prefer to open the file yourself.
85 ///
86 /// \param r p_reader handle to initialize
87 /// \param p_file input file handle (already open)
88 MPC_API mpc_status mpc_reader_init_stdio_stream(mpc_reader * p_reader, FILE * p_file);
89 
90 /// Release reader with default stdio file reader implementation.
91 ///
92 /// \param r reader handle to release
93 MPC_API void mpc_reader_exit_stdio(mpc_reader *p_reader);
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 #endif
99