blob: 8b4cf704d11c71233180041ddd54711f2a0d9a90 (
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*!
* \file vdr_decoder.h
* \brief A generic decoder for a VDR media plugin (muggle)
*
* \version $Revision: 1.2 $
* \date $Date: 2004/05/28 15:29:18 $
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
* \author Responsible author: $Author: lvw $
*
* $Id: vdr_decoder.c,v 1.2 2004/05/28 15:29:18 lvw Exp $
*
* Adapted from:
* MP3/MPlayer plugin to VDR (C++)
* (C) 2001-2003 Stefan Huelswitt <huels@iname.com>
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <videodir.h>
#include <interface.h>
// #include "common.h"
// #include "data-mp3.h"
// #include "decoder-core.h"
// #include "decoder-mp3-stream.h"
// #include "decoder-snd.h"
// #include "decoder-ogg.h"
#include "vdr_decoder.h"
#include "vdr_decoder_mp3.h"
using namespace std;
// --- mgDecoders ---------------------------------------------------------------
mgMediaType mgDecoders::getMediaType( string s )
{
// TODO: currently handles only mp3. LVW
return MT_MP3;
}
mgDecoder *mgDecoders::findDecoder( string filename )
{
mgDecoder *decoder = 0;
switch( getMediaType( filename ) )
{
case MT_MP3:
{
// prepend filename with path to music library?? TODO
printf( "mp3 file detected, launching mgMP3Decoder\n" );
decoder = new mgMP3Decoder(filename);
} break;
/*
case MT_MP3_STREAM: decoder = new mgMP3StreamDecoder(full); break;
#ifdef HAVE_SNDFILE
case MT_SND: decoder = new cSndDecoder(full); break;
#endif
#ifdef HAVE_VORBISFILE
case MT_OGG: decoder = new mgOggDecoder(full); break;
#endif
*/
default:
{
esyslog("ERROR: unknown media type" );
} break;
}
if( decoder && !decoder->valid() )
{
// no decoder found or decoder doesn't match
delete decoder; // might be carried out on NULL pointer!
decoder = 0;
esyslog("ERROR: no valid decoder found for %s", filename.c_str() );
}
return decoder;
}
// --- mgDecoder ----------------------------------------------------------------
mgDecoder::mgDecoder(string filename)
{
m_filename = filename;
m_locked = 0;
m_urgentLock = false;
m_playing = false;
}
mgDecoder::~mgDecoder()
{
}
void mgDecoder::lock(bool urgent)
{
m_locklock.Lock();
if( urgent && m_locked )
{
m_urgentLock = true; // signal other locks to release quickly
}
m_locked ++;
m_locklock.Unlock(); // don't hold the "locklock" when locking "lock", may cause a deadlock
m_lock.Lock();
m_urgentLock = false;
}
void mgDecoder::unlock(void)
{
m_locklock.Lock();
m_locked--;
m_lock.Unlock();
m_locklock.Unlock();
}
bool mgDecoder::tryLock(void)
{
bool res = false;
m_locklock.Lock();
if( !m_locked && !m_playing )
{
lock();
res = true;
}
m_locklock.Unlock();
return res;
}
|