From 815d1c5cbbfbcd81199089c0f216f4fbdff2b571 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 25 Nov 2006 16:10:24 +0000 Subject: [PATCH] Reworked players --- player.cc | 27 ++++++------------- player.h | 3 +-- playerradio.cc | 71 +++++++++++++++++++++++++++++++++----------------- playerradio.h | 1 + vvideolive.cc | 46 ++++++++++++++++++++++++++------ vvideolive.h | 3 ++- vvideorec.cc | 2 +- 7 files changed, 98 insertions(+), 55 deletions(-) diff --git a/player.cc b/player.cc index 76cda34..f35a8a2 100644 --- a/player.cc +++ b/player.cc @@ -22,7 +22,7 @@ // ----------------------------------- Called from outside, one offs or info funcs -Player::Player(MessageQueue* tmessageQueue, void* tmessageReceiver, bool tIsRecording, bool tIsRadio) +Player::Player(MessageQueue* tmessageQueue, void* tmessageReceiver, bool tIsRecording) : vfeed(this), afeed(this) { messageQueue = tmessageQueue; @@ -41,24 +41,13 @@ Player::Player(MessageQueue* tmessageQueue, void* tmessageReceiver, bool tIsReco videoStartup = false; preBuffering = false; isRecording = tIsRecording; - isRadio = tIsRadio; threadBuffer = NULL; - if (isRadio) - { - blockSize = 10000; - startupBlockSize = 20000; - preBufferSize = 20000; - video->turnVideoOff(); - } - else - { - blockSize = 100000; - startupBlockSize = 250000; - preBufferSize = 500000; - video->turnVideoOn(); - } + blockSize = 100000; + startupBlockSize = 250000; + preBufferSize = 500000; + video->turnVideoOn(); } Player::~Player() @@ -604,7 +593,7 @@ void Player::switchState(UCHAR toState, ULONG jumpFrame) if (currentFrameNumber > lengthFrames) currentFrameNumber = 0; demuxer->setFrameNum(currentFrameNumber); } - if (!isRadio) demuxer->seek(); + demuxer->seek(); videoStartup = true; state = S_PLAY; @@ -689,7 +678,7 @@ void Player::restartAtFrame(ULONG newFrame) video->reset(); audio->reset(); demuxer->flush(); - if (!isRadio) demuxer->seek(); + demuxer->seek(); currentFrameNumber = newFrame; demuxer->setFrameNum(newFrame); videoStartup = true; @@ -806,7 +795,7 @@ void Player::threadMethod() state = S_PLAY; audio->reset(); demuxer->flush(); - if (!isRadio) demuxer->seek(); + demuxer->seek(); demuxer->setFrameNum(currentFrameNumber); videoStartup = true; afeed.start(); diff --git a/player.h b/player.h index 2b5578d..3de7e5a 100644 --- a/player.h +++ b/player.h @@ -48,7 +48,7 @@ class Player : public Thread_TYPE, public Callback { public: - Player(MessageQueue* messageQueue, void* messageReceiver, bool isRecording, bool isRadio); + Player(MessageQueue* messageQueue, void* messageReceiver, bool isRecording); virtual ~Player(); int init(); @@ -127,7 +127,6 @@ class Player : public Thread_TYPE, public Callback bool startup; bool videoStartup; bool isRecording; - bool isRadio; bool preBuffering; #ifndef WIN32 diff --git a/playerradio.cc b/playerradio.cc index dcf18ea..23462a4 100644 --- a/playerradio.cc +++ b/playerradio.cc @@ -81,43 +81,61 @@ int PlayerRadio::init(ULLONG tlengthBytes, ULONG tlengthPackets) logger->log("PlayerRadio", Log::DEBUG, "PlayerRadio has received length bytes of %llu", lengthBytes); UINT thisRead = 0; - ULLONG endPTS = 0; int success; - threadBuffer = vdr->getBlock(0, 10000, &thisRead); - if (!threadBuffer) + if (isRecording) { - logger->log("PlayerRadio", Log::ERR, "Failed to get start block"); - shutdown(); - return 0; - } + UCHAR* buffer = vdr->getBlock(0, 10000, &thisRead); + if (!buffer) + { + logger->log("PlayerRadio", Log::ERR, "Failed to get start block"); + shutdown(); + return 0; + } - success = demuxer->findPTS(threadBuffer, thisRead, &startPTS); - if (!success) - { - logger->log("PlayerRadio", Log::ERR, "Failed to get start PTS"); - shutdown(); - return 0; + success = demuxer->findPTS(buffer, thisRead, &startPTS); + if (!success) + { + logger->log("PlayerRadio", Log::ERR, "Failed to get start PTS"); + free(buffer); + shutdown(); + return 0; + } + + free(buffer); + + if (!setLengthSeconds()) + { + logger->log("PlayerRadio", Log::ERR, "Failed to setLengthSeconds"); + shutdown(); + return 0; + } } - threadBuffer = vdr->getBlock(tlengthBytes - 10000, 10000, &thisRead); - if (!threadBuffer) + initted = true; + return 1; +} + +bool PlayerRadio::setLengthSeconds() +{ + int success; + ULLONG endPTS = 0; + UINT thisRead = 0; + UCHAR* buffer = vdr->getBlock(lengthBytes - 10000, 10000, &thisRead); + if (!buffer) { logger->log("PlayerRadio", Log::ERR, "Failed to get end block"); - shutdown(); - return 0; + return false; } - success = demuxer->findPTS(threadBuffer, thisRead, &endPTS); + success = demuxer->findPTS(buffer, thisRead, &endPTS); if (!success) { logger->log("PlayerRadio", Log::ERR, "Failed to get end PTS"); - shutdown(); - return 0; + free(buffer); + return false; } - logger->log("PlayerRadio", Log::DEBUG, "Start: %llu, End: %llu", startPTS, endPTS); - if (startPTS < endPTS) { lengthSeconds = (endPTS - startPTS) / 90000; @@ -127,8 +145,7 @@ int PlayerRadio::init(ULLONG tlengthBytes, ULONG tlengthPackets) lengthSeconds = (startPTS - endPTS) / 90000; } - initted = true; - return 1; + return true; } int PlayerRadio::shutdown() @@ -569,6 +586,12 @@ void PlayerRadio::threadFeedPlay() if (!vdr->isConnected()) { doConnectionLost(); return; } logger->log("PlayerRadio", Log::DEBUG, "Rescanned and reset length: %llu", lengthBytes); lastRescan = time(NULL); + + if (!setLengthSeconds()) + { + logger->log("PlayerRadio", Log::ERR, "Failed to setLengthSeconds in thread"); + return; + } } if (feedPosition >= lengthBytes) break; // finished playback diff --git a/playerradio.h b/playerradio.h index 67e5e4c..8100821 100644 --- a/playerradio.h +++ b/playerradio.h @@ -90,6 +90,7 @@ class PlayerRadio : public Thread_TYPE, public Callback void doConnectionLost(); void restartAtPacket(ULONG newPacket); + bool setLengthSeconds(); MessageQueue* messageQueue; void* messageReceiver; diff --git a/vvideolive.cc b/vvideolive.cc index e2ab989..919f164 100644 --- a/vvideolive.cc +++ b/vvideolive.cc @@ -38,10 +38,18 @@ VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType, VChannelList* unavailableView = NULL; streamType = tstreamType; videoMode = video->getMode(); - if (streamType == VDR::RADIO) player = new Player(Command::getInstance(), this, false, true); - else player = new Player(Command::getInstance(), this, false, false); - player->init(); + if (streamType == VDR::RADIO) + { + (PlayerRadio*)player = new PlayerRadio(Command::getInstance(), this, false); + ((PlayerRadio*)player)->init(0, 0); + } + else + { + (Player*)player = new Player(Command::getInstance(), this, false); + ((Player*)player)->init(); + } + create(video->getScreenWidth(), video->getScreenHeight()); Colour transparent(0, 0, 0, 0); setBackgroundColour(transparent); @@ -67,7 +75,15 @@ VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType, VChannelList* VVideoLive::~VVideoLive() { - delete player; + if (streamType == VDR::RADIO) + { + delete (PlayerRadio*)player; + } + else + { + delete (Player*)player; + } + instance = NULL; video->setDefaultAspect(); } @@ -164,12 +180,10 @@ int VVideoLive::handleCommand(int command) #ifdef DEV case Remote::YELLOW: { - player->test1(); break; } case Remote::BLUE: { - player->test2(); break; } #endif @@ -377,7 +391,15 @@ void VVideoLive::play(int noShowVLB) else { if (!noShowVLB) doBanner(false); - player->play(); + + if (streamType == VDR::RADIO) + { + ((PlayerRadio*)player)->play(); + } + else + { + ((Player*)player)->play(); + } } } @@ -386,7 +408,15 @@ void VVideoLive::stop(int noRemoveVLB) if (unavailable) return; if (!noRemoveVLB && VLiveBanner::getInstance()) viewman->removeView(VLiveBanner::getInstance()); // if live banner is present, remove it. won't cause damage if its not present - player->stop(); + if (streamType == VDR::RADIO) + { + ((PlayerRadio*)player)->stop(); + } + else + { + ((Player*)player)->stop(); + } + Log::getInstance()->log("VVideoLive", Log::DEBUG, "Delay starts here due to time taken by plugin to stop"); vdr->stopStreaming(); if (!vdr->isConnected()) { Command::getInstance()->connectionLost(); return; } diff --git a/vvideolive.h b/vvideolive.h index efb4e94..768fa5f 100644 --- a/vvideolive.h +++ b/vvideolive.h @@ -26,6 +26,7 @@ #include "view.h" #include "player.h" +#include "playerradio.h" #include "vdr.h" #include "channel.h" #include "vlivebanner.h" @@ -75,7 +76,7 @@ class VVideoLive : public View ViewMan* viewman; VDR* vdr; Video* video; - Player* player; + void* player; // HA HA FIXME ChannelList* chanList; VChannelList* vchannelList; UINT currentChannel; // index in list diff --git a/vvideorec.cc b/vvideorec.cc index 09beac4..47aa832 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -28,7 +28,7 @@ VVideoRec::VVideoRec(Recording* rec) timers = Timers::getInstance(); vas = NULL; - player = new Player(Command::getInstance(), this, true, false); + player = new Player(Command::getInstance(), this, true); player->init(); videoMode = video->getMode(); -- 2.39.5