another big glob of changes/fixes
[platform/upstream/flac.git] / src / plugin_winamp3 / flacpcm.h
1 /* FLAC input plugin for Winamp3\r
2  * Copyright (C) 2000,2001,2002  Josh Coalson\r
3  *\r
4  * This program is free software; you can redistribute it and/or\r
5  * modify it under the terms of the GNU General Public License\r
6  * as published by the Free Software Foundation; either version 2\r
7  * of the License, or (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License\r
15  * along with this program; if not, write to the Free Software\r
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
17  *\r
18  * NOTE: this code is derived from the 'rawpcm' example by\r
19  * Nullsoft; the original license for the 'rawpcm' example follows.\r
20  */\r
21 /*\r
22 \r
23   Nullsoft WASABI Source File License\r
24 \r
25   Copyright 1999-2001 Nullsoft, Inc.\r
26 \r
27     This software is provided 'as-is', without any express or implied\r
28     warranty.  In no event will the authors be held liable for any damages\r
29     arising from the use of this software.\r
30 \r
31     Permission is granted to anyone to use this software for any purpose,\r
32     including commercial applications, and to alter it and redistribute it\r
33     freely, subject to the following restrictions:\r
34 \r
35     1. The origin of this software must not be misrepresented; you must not\r
36        claim that you wrote the original software. If you use this software\r
37        in a product, an acknowledgment in the product documentation would be\r
38        appreciated but is not required.\r
39     2. Altered source versions must be plainly marked as such, and must not be\r
40        misrepresented as being the original software.\r
41     3. This notice may not be removed or altered from any source distribution.\r
42 \r
43 \r
44   Brennan Underwood\r
45   brennan@nullsoft.com\r
46 \r
47 */\r
48 \r
49 #ifndef _FLACPCM_H\r
50 #define _FLACPCM_H\r
51 \r
52 #include "studio/services/svc_mediaconverter.h"\r
53 #include "studio/services/servicei.h"\r
54 #include "studio/corecb.h"\r
55 #include "studio/wac.h"\r
56 #include "attribs/cfgitemi.h"\r
57 #include "attribs/attrint.h"\r
58 extern "C" {\r
59 #include "FLAC/seekable_stream_decoder.h"\r
60 };\r
61 \r
62 class FlacPcm : public svc_mediaConverterI {\r
63 public:\r
64         FlacPcm();\r
65         virtual ~FlacPcm();\r
66 \r
67         // service\r
68         static const char *getServiceName() { return "FLAC to PCM converter service"; }\r
69 \r
70         virtual int canConvertFrom(svc_fileReader *reader, const char *name, const char *chunktype)\r
71         { return name && !STRICMP(Std::extension(name), "flac"); } // only accepts *.flac files\r
72 \r
73         virtual const char *getConverterTo() { return "PCM"; }\r
74 \r
75         virtual int getInfos(MediaInfo *infos);\r
76 \r
77         virtual int processData(MediaInfo *infos, ChunkList *chunk_list, bool *killswitch);\r
78 \r
79         virtual int getLatency(void) { return 0; }\r
80 \r
81         // callbacks\r
82         virtual int corecb_onSeeked(int newpos);\r
83 \r
84 protected:\r
85         bool needs_seek;\r
86         FLAC__uint64 seek_sample;\r
87         unsigned samples_in_reservoir;\r
88         bool abort_flag;\r
89         svc_fileReader *reader;\r
90         FLAC__SeekableStreamDecoder *decoder;\r
91         FLAC__StreamMetadata_StreamInfo stream_info;\r
92         FLAC__int16 reservoir[FLAC__MAX_BLOCK_SIZE * 2 * 2]; // *2 for max channels, another *2 for overflow\r
93         unsigned char output[576 * 2 * (16/8)]; // *2 for max channels, (16/8) for max bytes per sample\r
94 \r
95         unsigned lengthInMsec() { return (unsigned)((FLAC__uint64)1000 * stream_info.total_samples / stream_info.sample_rate); }\r
96 private:\r
97         void cleanup();\r
98         static FLAC__SeekableStreamDecoderReadStatus readCallback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);\r
99         static FLAC__SeekableStreamDecoderSeekStatus seekCallback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);\r
100         static FLAC__SeekableStreamDecoderTellStatus tellCallback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);\r
101         static FLAC__SeekableStreamDecoderLengthStatus lengthCallback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);\r
102         static FLAC__bool eofCallback_(const FLAC__SeekableStreamDecoder *decoder, void *client_data);\r
103         static FLAC__StreamDecoderWriteStatus writeCallback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data);\r
104         static void metadataCallback_(const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);\r
105         static void errorCallback_(const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);\r
106 };\r
107 #endif\r