summaryrefslogtreecommitdiff
path: root/vdr_decoder_sndfile.h
blob: fc020768924d2efe919450ba679484ce5b43555e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Muggle plugin to VDR (C++)
 *
 * (C) 2005 Lars von Wedel, Wolfgang Rohdewald, mainly copied from
 * (C) 2001-2005 Stefan Huelswitt <s.huelswitt@gmx.de>
 *
 * This code 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 code 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.
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
 */

#ifndef ___DECODER_SND_H
#define ___DECODER_SND_H

#define DEC_SND     DEC_ID('S','N','D',' ')
#define DEC_SND_STR "SND"

#ifdef HAVE_SNDFILE

#include <string>

#include <time.h>
#include <mad.h>
#include <sndfile.h>

#include <vdr/thread.h>

#include "vdr_decoder.h"

#define CDFS_MAGIC 0xCDDA		 // cdfs filesystem-ID

// ----------------------------------------------------------------

class mgSndfile
{
	private:
		SNDFILE *m_sf;
		std::string m_filename;

		void Error(const char *action);

		SF_INFO m_sfi;
	public:

		mgSndfile( mgItemGd *item );
		~mgSndfile();

		SF_INFO* SoundfileInfo();
		bool Open( bool log = true );
		void Close();
		sf_count_t Seek( sf_count_t frames = 0, bool relative = false );
		sf_count_t Stream( int *buffer, sf_count_t frames );
};

// ----------------------------------------------------------------

class mgSndfileDecoder : public mgDecoder, public cThread
{
	private:
		mgSndfile m_file;

		struct mgDecode m_ds;
		struct mad_pcm *m_pcm;
		unsigned long long m_index;
		//
		cMutex m_buffMutex;
		cCondVar m_fgCond, m_bgCond;
		bool m_run, m_ready;
		int *m_framebuff, m_deferedN, m_softCount;
		//
		void init();
		bool clean();
		struct mgDecode *done( eDecodeStatus status );

	protected:
		virtual void Action(void);

	public:
		mgSndfileDecoder( mgItemGd *item );
		~mgSndfileDecoder();

		virtual bool valid(void);
		virtual bool start(void);
		virtual bool stop(void);
		virtual bool skip(int seconds, int avail, int rate);
		virtual struct mgDecode *decode();
		virtual mgPlayInfo *playInfo();
};

// ----------------------------------------------------------------
#endif							 //HAVE_SNDFILE
#endif							 //___DECODER_SND_H