2 Copyright 2004-2006 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
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.
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.
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.
36 #include "messagequeue.h"
39 #include "timerreceiver.h"
42 #include "threadwin.h"
54 class AudioPlayer : public Thread_TYPE, public Callback, public TimerReceiver
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
67 //is the player still running?
68 bool isPlayerRunning();
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
82 int jumpToPercent(double percent);
83 int skipForward(int sec);
84 int skipBackward(int sec);
86 //info functions for frontend
87 //delete provided String afterwards
88 //get the played title from ID3 Tag - or NULL
91 //multi line String containing ID3 infos
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);
101 //get current position in s
102 ULONG getCurrentTimes();
106 int getCurrentBitrate();
109 virtual void call(void * caller);
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;
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
132 virtual void timercall(int reference);
136 void threadPostStopCleanup();
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;
149 DemuxerAudio *demuxer;
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) ;
160 //synchronized get/set methods for states
161 int setRequestedState(UCHAR st);
162 void setState(UCHAR st);
164 //to be called from within the thread
167 //variables used by the thread
178 ULLONG requestedStreampos;
181 //the buffer len in bytes
182 const static int BUFLEN=50*1024;
185 int requestedSequence;
189 int currentPlaySequence;
190 //sequence that is changed for each new filename
199 void sendFrontendMessage(ULONG para);
201 void waitTimed(int ms);