]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Fix text corruption in channel number display on live tv
[vompclient.git] / playerradio.h
1 /*
2     Copyright 2004-2006 Chris Tallon
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 PLAYERRADIO_H
22 #define PLAYERRADIO_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 "threadsystem.h"
32
33 #include "callback.h"
34 #include "defines.h"
35 #include "afeed.h"
36
37 class Log;
38 class Audio;
39 class Video;
40 class Demuxer;
41 class VDR;
42 class MessageQueue;
43
44 /*
45  * Frames...
46  *
47  * VDR tells me there are around 8.3 "frames" per second in radio recordings.
48  * I don't know where this comes from but things seem to work.
49  */
50
51 class PlayerRadio : public Thread_TYPE, public Callback
52 {
53   public:
54     PlayerRadio(MessageQueue* messageQueue, void* messageReceiver);
55     virtual ~PlayerRadio();
56
57     int init(ULLONG lengthBytes, ULONG lengthFrames, bool IsPesRecording);
58     int shutdown();
59     void setCurrentFrameNumber(ULONG num);
60
61     void play();
62     void stop();
63     void pause();
64     void playpause();
65     void jumpToPercent(double percent);
66     void skipForward(UINT seconds);
67     void skipBackward(UINT seconds);
68
69     UCHAR getState() { return state; }
70     ULONG getCurrentSeconds();
71     ULONG getLengthSeconds();
72
73     void call(void*); // for callback interface
74
75     const static UCHAR S_PLAY = 1;
76     const static UCHAR S_PAUSE_P = 2;
77     const static UCHAR S_STOP = 6;
78     const static UCHAR S_JUMP = 7;
79
80     // Player events
81
82     const static UCHAR CONNECTION_LOST = 1;
83     const static UCHAR STOP_PLAYBACK = 2;
84     const static UCHAR STREAM_END = 3;
85
86   protected:
87     void threadMethod();
88     void threadPostStopCleanup();
89
90   private:
91     void switchState(UCHAR newState, ULONG jumpToFrame=0);
92
93     void threadFeedPlay();
94     void threadFeedScan();
95
96     void doConnectionLost();
97     void restartAtFrame(ULONG newFrame);
98     bool setLengthSeconds();
99
100     MessageQueue* messageQueue;
101     void* messageReceiver;
102     Log* logger;
103     Audio* audio;
104     Demuxer* demuxer;
105     VDR* vdr;
106     AFeed afeed;
107
108     bool initted;
109     bool startup;
110
111     ULLONG startPTS;
112     ULONG lengthSeconds;
113
114 #ifndef WIN32
115     pthread_mutex_t mutex;
116 #else
117     HANDLE mutex;
118 #endif
119     void lock();
120     void unLock();
121
122     ULLONG lengthBytes;
123     ULONG lengthFrames;
124     ULONG currentFrameNumber;
125     UINT blockSize;
126     UINT startupBlockSize;
127     UCHAR* threadBuffer;
128     UCHAR state;
129 };
130
131 #endif
132
133
134 /*
135
136 Possible states:
137
138 Play, Pause, FFwd, FBwd, (Stop), [Jump]
139
140                     Possible  Working
141
142 Play   -> PauseP       *         *
143        -> Stop         *         *
144        -> Jump         *         *
145
146 PauseP -> Play         *         *
147        -> Stop         *         *
148        -> Jump         *         *
149
150 PauseI -> Play         *         *
151        -> PauseP
152        -> Stop         *         *
153        -> Jump         *         *
154
155 Stop   -> Play         *         *
156        -> PauseP
157        -> Jump
158
159 Jump   -> Play
160        -> PauseP
161        -> Stop
162
163 */