]> git.vomp.tv Git - vompclient.git/blob - playermedia.h
Fix text corruption in channel number display on live tv
[vompclient.git] / playermedia.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 PLAYERMEDIA_H
22 #define PLAYERMEDIA_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 "vfeed.h"
40 #include "timerreceiver.h"
41 #include "video.h"
42
43 #ifdef WIN32
44 #include "threadwin.h"
45 #else
46 #include "threadp.h"
47 #endif
48
49
50
51 class Boxx;
52 class MediaURI;
53 class Video;
54 class DemuxerMedia;
55
56
57 class PlayerMedia : public Thread_TYPE, public Callback, public TimerReceiver
58 {
59   public:
60     PlayerMedia(Boxx *frontend);
61     virtual ~PlayerMedia();
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 playNew(ULONG mediaChannel,ULLONG lengthBytes, ULLONG lengthFrames=0);
74     //stop the player without shutting it down
75     int stop();
76     int play();
77     int pause();
78     int unpause();
79                 int fastForward();
80                 int fastBackward();
81                 int jumpToPercent(double percent);
82                 int skipForward(int sec);
83                 int skipBackward(int sec);
84
85     //wait for a particular sequence to be handled
86     //timeout in s, returnes current sequence, -1 on timeout
87     int waitForSequence(int timeout, int sequence);
88     int getSequence();
89
90                 //info functions
91
92                 //get current position in s
93                 ULONG getCurrentTimes();
94                 //get song len in s
95                 ULONG getSonglen();
96                 
97     ULLONG getLengthFrames();
98     ULLONG getLengthBytes();
99     
100     virtual void call(void * caller);
101
102     UCHAR getState() ;
103
104     const static UCHAR S_PLAY = 1;
105     const static UCHAR S_PAUSE = 2;
106     const static UCHAR S_POSITION = 3;
107     const static UCHAR S_DONE=5;
108     const static UCHAR S_STOP = 6;
109     const static UCHAR S_ERROR = 8;
110     const static UCHAR S_FF = 9;
111     const static UCHAR S_BACK = 10;
112     const static UCHAR S_SEEK = 11;
113
114
115     //message parameters for frontend messages
116     const static ULONG CONNECTION_LOST=1;
117     const static ULONG STREAM_END=2;
118     const static ULONG STREAM_ERR=3;
119                 const static ULONG STATUS_CHANGE=4; //some info has been changed
120                 const static ULONG SHORT_UPDATE=6; //timer info update
121     const static ULONG ASPECT43 = 7;
122     const static ULONG ASPECT169 = 8;
123
124     virtual void timercall(int reference);
125     void setAudioChannel(int channel);
126     bool * getDemuxerMpegAudioChannels();
127     bool * getDemuxerAc3AudioChannels();
128     int    getCurrentAudioChannel();
129     ULLONG getCurrentPTS();
130     ULLONG getLenPTS();
131     char * getInfo(); //return some info about the played file,caller has to destroy buffer
132
133   protected:
134     void threadMethod();
135     void threadPostStopCleanup();
136
137   private:
138     bool playerRunnig;
139     Audio* audio;
140     Video* video;
141     VDR* vdr;
142     Log* logger;
143
144     DemuxerMedia *demuxer;
145     AFeed afeed;
146     VFeed vfeed;
147
148     //feeder control
149     const static int FEEDER_START=1;
150     const static int FEEDER_STOP=2;
151     const static int FEEDER_PAUSE=3;
152     const static int FEEDER_UNPAUSE=4;
153     void controlFeeder(int action) ;
154     int feederState;
155
156     //synchronized get/set methods for states
157     int setRequestedState(UCHAR st);
158     void setState(UCHAR st);
159
160     //to be called from within the thread
161     UCHAR checkState();
162
163                 //variables used by the thread
164                 ULONG thisWrite;
165           ULONG thisRead;
166     bool running;
167     bool onStartup;  //set for the firts chunk to find the audio channel
168
169     UCHAR *threadBuffer;
170     UCHAR state;
171     UCHAR requestState;
172     ULLONG streampos;
173                 ULLONG bytesWritten;
174                 ULLONG requestedStreampos;
175
176     //the buffer len in bytes
177     const static int BUFLEN=100000;
178     const static int STARTBUFLEN=250000;
179     Boxx *frontend;
180     //requested sequence
181     int requestedSequence;
182     //handled sequence
183     int sequence;
184
185     void sendFrontendMessage(ULONG para);
186     void gotoSeek();
187
188     void waitTimed(int ms);
189
190     //get the current average bitrate by using PTS compared to streampos
191     ULLONG getBytesPerSecond();
192
193     ULONG mediaChannel;
194     ULLONG lengthBytes;
195     ULLONG lengthFrames;
196     ULLONG appDestinationPTS; //if we are moving set the PTS to the destination
197                               //for display at the bar, take this if !=0
198     bool playingStarted; //did we ever start to play?
199     bool canPosition;
200
201
202 };
203
204 #endif
205