]> git.vomp.tv Git - vompclient.git/blob - audioplayer.h
Compile fix for MVP re: location change of hmsf
[vompclient.git] / audioplayer.h
1 /*
2     Copyright 2004-2006 Chris Tallon, Andreas Vogel
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef AUDIOPLAYER_H
22 #define AUDIOPLAYER_H
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifndef WIN32
27 #include <sys/time.h>
28 #endif
29 #include <time.h>
30
31 #include "audio.h"
32 #include "remote.h"
33 #include "vdr.h"
34 #include "callback.h"
35 #include "message.h"
36 #include "messagequeue.h"
37 #include "thread.h"
38 #include "afeed.h"
39 #include "timerreceiver.h"
40
41 #ifdef WIN32
42 #include "threadwin.h"
43 #else
44 #include "threadp.h"
45 #endif
46
47
48
49 class Boxx;
50 class DemuxerAudio;
51 class MediaURI;
52
53
54 class AudioPlayer : public Thread_TYPE, public Callback, public TimerReceiver
55 {
56   public:
57     //the instance method to create the
58     //player instance - only call thie for
59     //the first time in the main thread (no lock!)
60     //later you can change the view the player is connect with
61                 //a view that "goes" should call getInstance(NULL,false) to detach
62                 //the last media view should shutdown the player
63     static AudioPlayer * getInstance(Boxx * frontend, bool create=true);
64     //start the player thread
65     void run();
66
67     //is the player still running?
68     bool isPlayerRunning();
69
70     void shutdown();
71
72     //each of the commands works as a request
73     //only after getSequence returned the same sequence as those commands this is
74     //handled by the player and getError is valid
75     int play(const MediaURI *uri);
76     //stop the player without shutting it down
77     int stop();
78     int pause();
79     int unpause();
80                 int fastForward();
81                 int fastBackward();
82                 int jumpToPercent(double percent);
83                 int skipForward(int sec);
84                 int skipBackward(int sec);
85
86                 //info functions for frontend
87                 //delete provided String afterwards
88                 //get the played title from ID3 Tag  - or NULL
89                 char * getTitle();
90                 //get info
91                 //multi line String containing ID3 infos
92                 char * getID3Info();
93
94     //wait for a particular sequence to be handled
95     //timeout in s, returnes current sequence, -1 on timeout
96     int waitForSequence(int timeout, int sequence);
97     int getSequence();
98
99                 //info functions
100
101                 //get current position in s
102                 ULONG getCurrentTimes();
103                 //get song len in s
104                 ULONG getSonglen();
105                 //current bitrate
106                 int getCurrentBitrate();
107                 
108     
109     virtual void call(void * caller);
110
111     UCHAR getState() ;
112
113     const static UCHAR S_PLAY = 1;
114     const static UCHAR S_PAUSE = 2;
115     const static UCHAR S_POSITION = 3;
116                 //player finished a song - no reset, next will follow
117     const static UCHAR S_DONE=5;
118     const static UCHAR S_STOP = 6;
119     const static UCHAR S_ERROR = 8;
120     const static UCHAR S_FF = 9;
121     const static UCHAR S_BACK = 10;
122
123     //message parameters for frontend messages
124     const static ULONG CONNECTION_LOST=1;
125     const static ULONG STREAM_END=2;
126     const static ULONG STREAM_ERR=3;
127                 const static ULONG STATUS_CHANGE=4; //some info has been changed
128                 const static ULONG NEW_SONG=5; //some info has been changed
129                 const static ULONG SHORT_UPDATE=6; //timer info update
130                 const static ULONG EXTERN1=7; //for other users as parameter to player event
131
132     virtual void timercall(int reference);
133
134   protected:
135     void threadMethod();
136     void threadPostStopCleanup();
137
138   private:
139                 //to guess lengthes if the demux does not know
140                 const static ULONG DEFAULT_BITRATE=128000;
141     AudioPlayer(Boxx *frontend);
142     virtual ~AudioPlayer();
143     static AudioPlayer * instance;
144     bool playerRunnig;
145     Audio* audio;
146     VDR* vdr;
147     Log* logger;
148
149     DemuxerAudio *demuxer;
150     AFeed afeed;
151
152     //feeder control
153     const static int FEEDER_START=1;
154     const static int FEEDER_STOP=2;
155     const static int FEEDER_PAUSE=3;
156     const static int FEEDER_UNPAUSE=4;
157     void controlFeeder(int action) ;
158     int feederState;
159
160     //synchronized get/set methods for states
161     int setRequestedState(UCHAR st);
162     void setState(UCHAR st);
163
164     //to be called from within the thread
165     UCHAR checkState();
166
167                 //variables used by the thread
168                 ULONG thisWrite;
169           ULONG thisRead;
170     bool running;
171
172     UCHAR *threadBuffer;
173     UCHAR state;
174     UCHAR requestState;
175     ULLONG streampos;
176     ULLONG lenInBytes;
177                 ULLONG bytesWritten;
178                 ULLONG requestedStreampos;
179
180                 int skipfactor;
181     //the buffer len in bytes
182     const static int BUFLEN=50*1024;
183     Boxx *frontend;
184     //requested sequence
185     int requestedSequence;
186     //handled sequence
187     int sequence;
188     //startplay sequence
189     int currentPlaySequence;
190     //sequence that is changed for each new filename
191     int playSequence;
192     //can we position?
193     bool canPosition;
194
195
196     MediaURI *uri;
197     int openFile();
198
199     void sendFrontendMessage(ULONG para);
200
201     void waitTimed(int ms);
202
203
204 };
205
206 #endif
207