2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2018-10-31 17:54:59 +01:00
|
|
|
* Copyright 2003-2018 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2006-03-16 07:52:46 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common data structures and functions used by FLAC and OggFLAC
|
2006-03-16 07:52:46 +01:00
|
|
|
*/
|
|
|
|
|
2012-10-02 10:56:44 +02:00
|
|
|
#ifndef MPD_FLAC_COMMON_HXX
|
|
|
|
#define MPD_FLAC_COMMON_HXX
|
2006-03-16 07:52:46 +01:00
|
|
|
|
2013-05-05 14:19:04 +02:00
|
|
|
#include "FlacInput.hxx"
|
2016-07-11 23:12:14 +02:00
|
|
|
#include "FlacPcm.hxx"
|
2014-01-24 00:02:24 +01:00
|
|
|
#include "../DecoderAPI.hxx"
|
2018-02-17 13:10:04 +01:00
|
|
|
#include "util/ConstBuffer.hxx"
|
2006-03-16 07:52:46 +01:00
|
|
|
|
2009-11-11 16:43:34 +01:00
|
|
|
#include <FLAC/stream_decoder.h>
|
2006-03-16 07:52:46 +01:00
|
|
|
|
2016-07-10 21:50:38 +02:00
|
|
|
struct FlacDecoder : public FlacInput {
|
2009-11-11 19:25:15 +01:00
|
|
|
/**
|
2016-11-18 07:59:01 +01:00
|
|
|
* Has DecoderClient::Ready() been called yet?
|
2009-11-11 19:25:15 +01:00
|
|
|
*/
|
2016-07-11 22:44:39 +02:00
|
|
|
bool initialized = false;
|
2009-11-11 19:25:15 +01:00
|
|
|
|
|
|
|
/**
|
2010-01-06 09:00:32 +01:00
|
|
|
* Does the FLAC file contain an unsupported audio format?
|
|
|
|
*/
|
2016-07-11 22:44:39 +02:00
|
|
|
bool unsupported = false;
|
2010-01-06 09:00:32 +01:00
|
|
|
|
2018-02-17 13:10:04 +01:00
|
|
|
/**
|
|
|
|
* The kbit_rate parameter for the next
|
|
|
|
* DecoderBridge::SubmitData() call.
|
|
|
|
*/
|
|
|
|
uint16_t kbit_rate;
|
|
|
|
|
2016-07-11 23:12:14 +02:00
|
|
|
FlacPcmImport pcm_import;
|
2010-01-06 09:00:32 +01:00
|
|
|
|
|
|
|
/**
|
2016-07-08 22:20:16 +02:00
|
|
|
* End of last frame's position within the stream. This is
|
|
|
|
* used for bit rate calculations.
|
2009-11-11 19:25:15 +01:00
|
|
|
*/
|
2016-07-11 22:44:39 +02:00
|
|
|
FLAC__uint64 position = 0;
|
2012-10-02 19:47:31 +02:00
|
|
|
|
2013-07-31 00:26:55 +02:00
|
|
|
Tag tag;
|
2009-01-15 19:50:28 +01:00
|
|
|
|
2018-02-17 13:10:04 +01:00
|
|
|
/**
|
|
|
|
* Decoded PCM data obtained by our libFLAC write callback.
|
|
|
|
* If this is non-empty, then DecoderBridge::SubmitData()
|
|
|
|
* should be called.
|
|
|
|
*/
|
|
|
|
ConstBuffer<void> chunk = nullptr;
|
|
|
|
|
2016-11-18 07:13:35 +01:00
|
|
|
FlacDecoder(DecoderClient &_client, InputStream &_input_stream)
|
|
|
|
:FlacInput(_input_stream, &_client) {}
|
2016-07-08 22:44:23 +02:00
|
|
|
|
|
|
|
/**
|
2016-11-18 07:59:01 +01:00
|
|
|
* Wrapper for DecoderClient::Ready().
|
2016-07-08 22:44:23 +02:00
|
|
|
*/
|
|
|
|
bool Initialize(unsigned sample_rate, unsigned bits_per_sample,
|
|
|
|
unsigned channels, FLAC__uint64 total_frames);
|
2016-07-10 21:47:17 +02:00
|
|
|
|
2016-07-11 22:45:29 +02:00
|
|
|
void OnMetadata(const FLAC__StreamMetadata &metadata);
|
|
|
|
|
|
|
|
FLAC__StreamDecoderWriteStatus OnWrite(const FLAC__Frame &frame,
|
|
|
|
const FLAC__int32 *const buf[],
|
|
|
|
FLAC__uint64 nbytes);
|
|
|
|
|
2016-07-10 21:47:17 +02:00
|
|
|
/**
|
|
|
|
* Calculate the delta (in bytes) between the last frame and
|
|
|
|
* the current frame.
|
|
|
|
*/
|
|
|
|
FLAC__uint64 GetDeltaPosition(const FLAC__StreamDecoder &sd);
|
2009-11-10 21:42:15 +01:00
|
|
|
|
2016-07-11 22:45:29 +02:00
|
|
|
private:
|
|
|
|
void OnStreamInfo(const FLAC__StreamMetadata_StreamInfo &stream_info);
|
|
|
|
void OnVorbisComment(const FLAC__StreamMetadata_VorbisComment &vc);
|
2009-01-15 19:50:28 +01:00
|
|
|
|
2016-07-11 22:45:29 +02:00
|
|
|
/**
|
2016-11-18 07:59:01 +01:00
|
|
|
* This function attempts to call DecoderClient::Ready() in case there
|
2016-07-11 22:45:29 +02:00
|
|
|
* was no STREAMINFO block. This is allowed for nonseekable streams,
|
|
|
|
* where the server sends us only a part of the file, without
|
|
|
|
* providing the STREAMINFO block from the beginning of the file
|
|
|
|
* (e.g. when seeking with SqueezeBox Server).
|
|
|
|
*/
|
|
|
|
bool OnFirstFrame(const FLAC__FrameHeader &header);
|
|
|
|
};
|
2006-03-16 07:52:46 +01:00
|
|
|
|
2006-07-20 20:53:56 +02:00
|
|
|
#endif /* _FLAC_COMMON_H */
|