FlacCommon.hxx 2.59 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * 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.
14 15 16 17 18 19 20 21
 *
 * 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
22 23
 */

24 25
#ifndef MPD_FLAC_COMMON_HXX
#define MPD_FLAC_COMMON_HXX
26

27
#include "FlacInput.hxx"
28
#include "FlacPcm.hxx"
29
#include "../DecoderAPI.hxx"
30

31
#include <FLAC/stream_decoder.h>
32

33
struct FlacDecoder : public FlacInput {
34
	/**
35
	 * Has DecoderClient::Ready() been called yet?
36
	 */
37
	bool initialized = false;
38 39

	/**
40 41
	 * Does the FLAC file contain an unsupported audio format?
	 */
42
	bool unsupported = false;
43

44
	FlacPcmImport pcm_import;
45 46

	/**
47 48
	 * End of last frame's position within the stream.  This is
	 * used for bit rate calculations.
49
	 */
50
	FLAC__uint64 position = 0;
51

Max Kellermann's avatar
Max Kellermann committed
52
	Tag tag;
Max Kellermann's avatar
Max Kellermann committed
53

54 55
	FlacDecoder(DecoderClient &_client, InputStream &_input_stream)
		:FlacInput(_input_stream, &_client) {}
56 57

	/**
58
	 * Wrapper for DecoderClient::Ready().
59 60 61
	 */
	bool Initialize(unsigned sample_rate, unsigned bits_per_sample,
			unsigned channels, FLAC__uint64 total_frames);
62

63 64 65 66 67 68
	void OnMetadata(const FLAC__StreamMetadata &metadata);

	FLAC__StreamDecoderWriteStatus OnWrite(const FLAC__Frame &frame,
					       const FLAC__int32 *const buf[],
					       FLAC__uint64 nbytes);

69 70 71 72 73
	/**
	 * Calculate the delta (in bytes) between the last frame and
	 * the current frame.
	 */
	FLAC__uint64 GetDeltaPosition(const FLAC__StreamDecoder &sd);
74

75 76 77
private:
	void OnStreamInfo(const FLAC__StreamMetadata_StreamInfo &stream_info);
	void OnVorbisComment(const FLAC__StreamMetadata_VorbisComment &vc);
Max Kellermann's avatar
Max Kellermann committed
78

79
	/**
80
	 * This function attempts to call DecoderClient::Ready() in case there
81 82 83 84 85 86 87
	 * 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);
};
88

Avuton Olrich's avatar
Avuton Olrich committed
89
#endif /* _FLAC_COMMON_H */