]> git.vomp.tv Git - vompclient.git/blob - playerradio.h
Fix rounding error in radio playback navigation
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "audio.h"
32 #include "video.h"
33 #include "demuxervdr.h"
34 #include "demuxerts.h"
35 #include "afeed.h"
36 #include "remote.h"
37 #include "vdr.h"
38 #include "callback.h"
39 #include "message.h"
40 #include "messagequeue.h"
41
42 #ifdef WIN32
43 #include "threadwin.h"
44 #else
45 #include "threadp.h"
46 #endif
47
48 class PlayerRadio : public Thread_TYPE, public Callback
49 {
50   public:
51     PlayerRadio(MessageQueue* messageQueue, void* messageReceiver, bool isRecording);
52     virtual ~PlayerRadio();
53
54     int init(ULLONG lengthBytes, ULONG lengthPackets);
55     int shutdown();
56     void setStartBytes(ULLONG startBytes);
57
58     void play();
59     void play(ULONG apid);               // Live radio
60     void stop();
61     void pause();
62     void jumpToPercent(double percent);
63     void skipForward(UINT seconds);
64     void skipBackward(UINT seconds);
65
66     UCHAR getState() { return state; }
67     ULONG getCurrentSeconds();
68     ULONG getLengthSeconds();
69
70     void call(void*); // for callback interface
71
72     const static UCHAR S_PLAY = 1;
73     const static UCHAR S_PAUSE_P = 2;
74     const static UCHAR S_STOP = 6;
75     const static UCHAR S_JUMP = 7;
76
77     // Player events
78
79     const static UCHAR CONNECTION_LOST = 1;
80     const static UCHAR STOP_PLAYBACK = 2;
81     const static UCHAR STREAM_END = 3;
82
83   protected:
84     void threadMethod();
85     void threadPostStopCleanup();
86
87   private:
88     void switchState(UCHAR newState, ULONG jumpPacket=0);
89
90     void threadFeedLive();
91     void threadFeedPlay();
92     void threadFeedScan();
93
94     void doConnectionLost();
95     void restartAtPacket(ULONG newPacket);
96     bool setLengthSeconds();
97
98     MessageQueue* messageQueue;
99     void* messageReceiver;
100     Log* logger;
101     Audio* audio;
102     Demuxer* demuxer;
103     VDR* vdr;
104     AFeed afeed;
105
106     bool initted;
107     bool startup;
108     bool isRecording;
109     bool preBuffering;
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     ULLONG streamPos;
124     ULONG lengthPackets;
125     ULONG currentPacketNumber;
126     UINT blockSize;
127     UINT startupBlockSize;
128     UINT preBufferSize;
129     UCHAR* threadBuffer;
130     UCHAR state;
131 };
132
133 #endif
134
135
136 /*
137
138 Possible states:
139
140 Play, Pause, FFwd, FBwd, (Stop), [Jump]
141
142                     Possible  Working
143
144 Play   -> PauseP       *         *
145        -> Stop         *         *
146        -> Jump         *         *
147
148 PauseP -> Play         *         *
149        -> Stop         *         *
150        -> Jump         *         *
151
152 PauseI -> Play         *         *
153        -> PauseP
154        -> Stop         *         *
155        -> Jump         *         *
156
157 Stop   -> Play         *         *
158        -> PauseP
159        -> Jump
160
161 Jump   -> Play
162        -> PauseP
163        -> Stop
164
165 */