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