]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Rename Player class to PlayerVideoRec. Switch to std::mutex
[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_PAUSE_I = 3;
78     const static UCHAR S_STOP = 6;
79     const static UCHAR S_JUMP = 7;
80
81     // Player events
82
83     const static UCHAR CONNECTION_LOST = 1;
84     const static UCHAR STOP_PLAYBACK = 2;
85     const static UCHAR STREAM_END = 3;
86
87   protected:
88     void threadMethod();
89     void threadPostStopCleanup();
90
91   private:
92     void switchState(UCHAR newState, ULONG jumpToFrame=0);
93
94     void threadFeedPlay();
95     void threadFeedScan();
96
97     void doConnectionLost();
98     void restartAtFrame(ULONG newFrame);
99     bool setLengthSeconds();
100
101     MessageQueue* messageQueue;
102     void* messageReceiver;
103     Log* logger;
104     Audio* audio;
105     Demuxer* demuxer;
106     VDR* vdr;
107     AFeed afeed;
108
109     bool initted;
110     bool startup;
111
112     ULLONG startPTS;
113     ULONG lengthSeconds;
114
115 #ifndef WIN32
116     pthread_mutex_t mutex;
117 #else
118     HANDLE mutex;
119 #endif
120     void lock();
121     void unLock();
122
123     ULLONG lengthBytes;
124     ULONG lengthFrames;
125     ULONG currentFrameNumber;
126     UINT blockSize;
127     UINT startupBlockSize;
128     UCHAR* threadBuffer;
129     UCHAR state;
130 };
131
132 #endif
133
134
135 /*
136
137 Possible states:
138
139 Play, Pause, FFwd, FBwd, (Stop), [Jump]
140
141                     Possible  Working
142
143 Play   -> PauseP       *         *
144        -> Stop         *         *
145        -> Jump         *         *
146
147 PauseP -> Play         *         *
148        -> Stop         *         *
149        -> Jump         *         *
150
151 PauseI -> Play         *         *
152        -> PauseP
153        -> Stop         *         *
154        -> Jump         *         *
155
156 Stop   -> Play         *         *
157        -> PauseP
158        -> Jump
159
160 Jump   -> Play
161        -> PauseP
162        -> Stop
163
164 */