2 Copyright 2004-2005 Chris Tallon
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 // this is a total copy from player but with video stuff taken out
22 // most of this isn't used because it's designed for recording playback
25 #include "playerradio.h"
27 PlayerRadio::PlayerRadio()
28 : afeedr(this, &stream)
35 feedMode = MODE_NORMAL;
38 PlayerRadio::~PlayerRadio()
40 if (initted) shutdown();
43 int PlayerRadio::init()
45 if (initted) return 0;
48 afeedr.init(audio->getFD());
57 int PlayerRadio::shutdown()
59 if (!initted) return 0;
62 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "PlayerRadio shutdown...");
77 int PlayerRadio::play()
79 if (!initted) return 0;
81 // If we are just paused, unpause!
88 // If we are fast forwarding, set to normal
95 // If we are fast backwarding, set to normal
102 // If we are already playing, bail // FIXME - resync?
105 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "DOING RESYNC");
118 // Standard play start
124 // ------------------------ This one works, but doesn't allow any pre-buffering.
130 // ------------------------ This one doesn't work, but it should, and would allow for prebuffering.
137 // struct timespec delay;
139 // delay.tv_nsec = 500000000;
140 // nanosleep(&delay, NULL);
146 // ------------------------------------------------------------------------------------------------
152 void PlayerRadio::stop()
154 if (!initted) return;
155 if (!playing) return;
165 void PlayerRadio::togglePause()
167 if (!initted) return;
168 if (!playing) return;
170 if (ffwd) toggleFastForward();
171 if (fbwd) toggleFastBackward();
185 void PlayerRadio::setPosition(ULLONG position)
187 feedPosition = position;
190 void PlayerRadio::setLength(ULLONG length)
192 streamLength = length;
193 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Player has received length of %llu", streamLength);
196 void PlayerRadio::skipForward()
198 // skip forward 1 minute
199 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "SKIP FORWARD 1 MINUTE");
201 if (paused) togglePause();
207 audio->doMuting(); // ???
208 feedPosition += 30000000;
214 void PlayerRadio::skipBackward()
216 // skip forward 1 minute
217 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "SKIP BACKWARD 1 MINUTE");
219 if (paused) togglePause();
225 audio->doMuting(); // ???
226 if (feedPosition > 30000000) feedPosition -= 30000000;
232 void PlayerRadio::toggleFastForward()
234 if (!initted) return;
235 if (!playing) return;
237 if (paused) togglePause();
238 if (fbwd) toggleFastBackward();
245 audio->systemMuteOff();
251 audio->systemMuteOn();
255 void PlayerRadio::toggleFastBackward()
257 if (!initted) return;
258 if (!playing) return;
260 if (paused) togglePause();
261 if (ffwd) toggleFastForward();
267 audio->systemMuteOff();
270 feedMode = MODE_NORMAL;
277 audio->systemMuteOn();
280 feedMode = MODE_BACKWARDS;
285 void PlayerRadio::jumpToPercent(int percent)
291 feedPosition = streamLength * percent / 100;
299 void PlayerRadio::call()
301 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "playerradio called\n");
302 // threadSignalNoLock();
307 void PlayerRadio::threadMethod()
314 VDR* vdr = VDR::getInstance();
325 // a bit hackey. this needs to be split to live and rec players
326 if (streamLength && (feedPosition >= streamLength)) break;
328 if (streamLength && ((feedPosition + blockSize) > streamLength))
330 askFor = streamLength - feedPosition;
332 buf = vdr->getBlock(feedPosition, askFor, &thisRead);
336 printf("Written direct: %i\n", write(audio->getFD(), buf, thisRead));
340 if (feedMode == MODE_NORMAL)
342 feedPosition += thisRead;
344 else if (feedMode == MODE_BACKWARDS)
346 if (feedPosition >= blockSize)
348 feedPosition -= blockSize;
352 // got to the start of the recording.. revert to play mode? how?
353 feedPosition += thisRead;
361 /* while(writeLength < thisRead)
363 thisWrite = stream.put(buf + writeLength, thisRead - writeLength);
364 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Just put %i to stream", thisWrite);
366 writeLength += thisWrite;
370 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "RADIO OUTPUT STREAM FULL!!!");
371 // stream is full and cant take anymore
372 threadWaitForSignal();
373 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "BACK FROM WAIT");
379 Log::getInstance()->log("PlayerRadio", Log::DEBUG, "Written audio");