|
a |
|
b/sc2src/flacdecoder.h |
|
|
1 |
/* Copyright (C) 2015-2018 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#ifndef _FLACDECODER_H_INCLUDED_
|
|
|
19 |
#define _FLACDECODER_H_INCLUDED_
|
|
|
20 |
|
|
|
21 |
#include <FLAC/stream_decoder.h>
|
|
|
22 |
|
|
|
23 |
#ifdef WITH_OHBUILD
|
|
|
24 |
#include "OhmReceiver.h"
|
|
|
25 |
#else
|
|
|
26 |
#include <OpenHome/OhmReceiver.h>
|
|
|
27 |
#endif
|
|
|
28 |
|
|
|
29 |
#include "audiodecoder.h"
|
|
|
30 |
|
|
|
31 |
using namespace OpenHome;
|
|
|
32 |
using namespace OpenHome::Av;
|
|
|
33 |
|
|
|
34 |
class FlacDecoder : public AudioDecoder {
|
|
|
35 |
static const int SAMPLES_BUF_SIZE = 16 * 1024;
|
|
|
36 |
public:
|
|
|
37 |
FlacDecoder();
|
|
|
38 |
~FlacDecoder();
|
|
|
39 |
|
|
|
40 |
void start();
|
|
|
41 |
int decode(OhmMsgAudio& aMsg);
|
|
|
42 |
void finish();
|
|
|
43 |
private:
|
|
|
44 |
void putAudioMessage(
|
|
|
45 |
unsigned int bits_per_sample,
|
|
|
46 |
unsigned int channels,
|
|
|
47 |
unsigned int frames,
|
|
|
48 |
unsigned int sample_rate,
|
|
|
49 |
bool halt);
|
|
|
50 |
static FLAC__StreamDecoderReadStatus readCallback(
|
|
|
51 |
const FLAC__StreamDecoder *decoder,
|
|
|
52 |
FLAC__byte buffer[],
|
|
|
53 |
size_t *bytes,
|
|
|
54 |
void *client_data);
|
|
|
55 |
static FLAC__StreamDecoderWriteStatus writeCallback(
|
|
|
56 |
const FLAC__StreamDecoder *decoder,
|
|
|
57 |
const FLAC__Frame *frame,
|
|
|
58 |
const FLAC__int32 * const buffer[],
|
|
|
59 |
void *client_data);
|
|
|
60 |
static void metadataCallback(
|
|
|
61 |
const FLAC__StreamDecoder *decoder,
|
|
|
62 |
const FLAC__StreamMetadata *metadata,
|
|
|
63 |
void *client_data);
|
|
|
64 |
static void errorCallback(
|
|
|
65 |
const FLAC__StreamDecoder *decoder,
|
|
|
66 |
FLAC__StreamDecoderErrorStatus status,
|
|
|
67 |
void *client_data);
|
|
|
68 |
|
|
|
69 |
FLAC__StreamDecoder* m_decoder;
|
|
|
70 |
|
|
|
71 |
const unsigned char *m_buffer;
|
|
|
72 |
unsigned int m_bytes;
|
|
|
73 |
bool m_halt;
|
|
|
74 |
|
|
|
75 |
char m_pBuffer[SAMPLES_BUF_SIZE];
|
|
|
76 |
#ifdef DEBUG_DECODER
|
|
|
77 |
int dumpfd;
|
|
|
78 |
#endif
|
|
|
79 |
};
|
|
|
80 |
|
|
|
81 |
#endif /* _FLACDECODER_H_INCLUDED_ */
|