From 1bebac2618de5d1a1aeada427ef7930ff5425082 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 31 Oct 2005 14:29:08 +0000 Subject: [PATCH] New options code, enable radio, other stuff for dongle 15 --- command.cc | 8 +-- playervideo.cc | 13 +++- playervideo.h | 6 +- tcp.cc | 5 +- vchannellist.cc | 2 +- voptions.cc | 180 ++++++++++++++++-------------------------------- voptions.h | 33 ++++++++- vvideolive.cc | 11 +-- vvideorec.cc | 2 +- woptionbox.cc | 10 ++- woptionbox.h | 4 +- 11 files changed, 128 insertions(+), 146 deletions(-) diff --git a/command.cc b/command.cc index 18633ba..f440396 100644 --- a/command.cc +++ b/command.cc @@ -331,18 +331,18 @@ void Command::doJustConnected(VConnect* vconnect) // Go S-Video if config says so - config = vdr->configLoad("TV", "S-Video"); + config = vdr->configLoad("TV", "Connection"); if (config) { - if (!strcasecmp(config, "Yes")) + if (!strcasecmp(config, "S-Video")) { - logger->log("Command", Log::INFO, "Switching to S-Video as S-Video=%s", config); + logger->log("Command", Log::INFO, "Switching to S-Video as Connection=%s", config); video->setConnection(Video::SVIDEO); } else { - logger->log("Command", Log::INFO, "Leaving video output as S-Video=%s", config); + logger->log("Command", Log::INFO, "Switching to RGB/Composite as Connection=%s", config); video->setConnection(Video::COMPOSITERGB); } delete[] config; diff --git a/playervideo.cc b/playervideo.cc index 71764b6..82ff847 100644 --- a/playervideo.cc +++ b/playervideo.cc @@ -20,7 +20,7 @@ #include "playervideo.h" -PlayerVideo::PlayerVideo(MessageQueue* messageQueue, UCHAR tIsRecording) +PlayerVideo::PlayerVideo(MessageQueue* messageQueue, UCHAR tIsRecording, UCHAR isRadio) : vfeed(this), afeed(this) { commandMessageQueue = messageQueue; @@ -35,6 +35,17 @@ PlayerVideo::PlayerVideo(MessageQueue* messageQueue, UCHAR tIsRecording) isRecording = tIsRecording; lastRescan = 0; threadBuffer = NULL; + + if (isRadio) + { + blockSize = 20000; + startupBlockSize = 60000; + } + else + { + blockSize = 100000; + startupBlockSize = 250000; + } } PlayerVideo::~PlayerVideo() diff --git a/playervideo.h b/playervideo.h index c1422ff..ce8bff7 100644 --- a/playervideo.h +++ b/playervideo.h @@ -39,7 +39,7 @@ class PlayerVideo : public Player { public: - PlayerVideo(MessageQueue* messageQueue, UCHAR isRecording); + PlayerVideo(MessageQueue* messageQueue, UCHAR isRecording, UCHAR isRadio); virtual ~PlayerVideo(); int init(); @@ -76,10 +76,10 @@ class PlayerVideo : public Player UCHAR feedMode; UCHAR isRecording; time_t lastRescan; + UINT blockSize; + UINT startupBlockSize; const static UCHAR MODE_NORMAL = 1; const static UCHAR MODE_BACKWARDS = 2; - const static UINT blockSize = 100000; - const static UINT startupBlockSize = 250000; UCHAR* threadBuffer; UCHAR playing; // As in not stopped, (playing && paused) can == TRUE diff --git a/tcp.cc b/tcp.cc index f71f0e4..f6a4edf 100644 --- a/tcp.cc +++ b/tcp.cc @@ -242,6 +242,7 @@ int TCP::readData(UCHAR* buffer, int totalBytes) } thisRead = read(sock, &buffer[bytesRead], totalBytes - bytesRead); +// printf("read %i\n", thisRead); if (!thisRead) { // if read returns 0 then connection is closed @@ -261,8 +262,8 @@ int TCP::readData(UCHAR* buffer, int totalBytes) { if (++readTries == 100) { - Log::getInstance()->log("TCP", Log::ERR, "Too many reads"); - return 0; +// Log::getInstance()->log("TCP", Log::ERR, "Too many reads"); +// return 0; } } } diff --git a/vchannellist.cc b/vchannellist.cc index 4f66b0b..2e1a476 100644 --- a/vchannellist.cc +++ b/vchannellist.cc @@ -198,7 +198,7 @@ int VChannelList::handleCommand(int command) if (chan == NULL) return 2; - if (chan->type == VDR::RADIO) return 2; + // if (chan->type == VDR::RADIO) return 2; VVideoLive* v = new VVideoLive(chanList, chan->type); v->setChannel(chan->number); diff --git a/voptions.cc b/voptions.cc index dc3bc28..a18aa25 100644 --- a/voptions.cc +++ b/voptions.cc @@ -22,7 +22,7 @@ VOptions::VOptions() { - create(500, 250); + create(500, 285); if (Video::getInstance()->getFormat() == Video::PAL) { setScreenPos(120, 140); @@ -39,92 +39,40 @@ VOptions::VOptions() int fontHeight = surface->getFontHeight(); - optionBox[0].setSurface(surface); - optionBox[0].setSurfaceOffset(330, 45); - optionBox[0].setDimensions(150, fontHeight); - optionBox[0].addOption("Old"); - optionBox[0].addOption("New"); - - optionBox[1].setSurface(surface); - optionBox[1].setSurfaceOffset(330, 75); - optionBox[1].setDimensions(150, fontHeight); - optionBox[1].addOption("RGB+composite"); - optionBox[1].addOption("S-Video"); - - optionBox[2].setSurface(surface); - optionBox[2].setSurfaceOffset(330, 105); - optionBox[2].setDimensions(150, fontHeight); - optionBox[2].addOption("4:3"); - optionBox[2].addOption("16:9"); - - optionBox[3].setSurface(surface); - optionBox[3].setSurfaceOffset(330, 135); - optionBox[3].setDimensions(150, fontHeight); - optionBox[3].addOption("Chop sides"); - optionBox[3].addOption("Letterbox"); - - optionBox[4].setSurface(surface); - optionBox[4].setSurfaceOffset(330, 165); - optionBox[4].setDimensions(150, fontHeight); - optionBox[4].addOption("On"); - optionBox[4].addOption("Off"); - optionBox[4].addOption("Last state"); - - optionBox[5].setSurface(surface); - optionBox[5].setSurfaceOffset(330, 195); - optionBox[5].setDimensions(150, fontHeight); - optionBox[5].addOption("All"); - optionBox[5].addOption("FTA only"); + UINT i; + for (i = 0; i < numOptions; i++) + { + optionBox[i].setSurface(surface); + optionBox[i].setSurfaceOffset(330, 45 + (i * 30)); + optionBox[i].setDimensions(150, fontHeight); + for (UINT j = 0; j < optionData[i].optionCount; j++) + { + Log::getInstance()->log("Options", Log::DEBUG, "Add option"); + Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", optionData[i].options[j]); + optionBox[i].addOption(optionData[i].options[j]); + Log::getInstance()->log("Options", Log::DEBUG, "Done add option"); + } + } char* config; vdr = VDR::getInstance(); - - config = vdr->configLoad("General", "Remote type"); - if (!config || strcasecmp(config, "New")) - optionBox[0].setSelected("Old"); - else - optionBox[0].setSelected("New"); - if (config) delete[] config; - - config = vdr->configLoad("TV", "S-Video"); - if (!config || strcasecmp(config, "Yes")) - optionBox[1].setSelected("RGB+composite"); - else - optionBox[1].setSelected("S-Video"); - if (config) delete[] config; - - config = vdr->configLoad("TV", "Aspect"); - if (!config || strcasecmp(config, "16:9")) - optionBox[2].setSelected("4:3"); - else - optionBox[2].setSelected("16:9"); - if (config) delete[] config; - - config = vdr->configLoad("TV", "Widemode"); - if (!config || strcasecmp(config, "Letterbox")) - optionBox[3].setSelected("Chop sides"); - else - optionBox[3].setSelected("Letterbox"); - if (config) delete[] config; - - config = vdr->configLoad("General", "Power After Boot"); - if (!config) - optionBox[4].setSelected("On"); - else if (!strcasecmp(config, "Off")) - optionBox[4].setSelected("Off"); - else if (!strcasecmp(config, "Last state")) - optionBox[4].setSelected("Last state"); - else - optionBox[4].setSelected("On"); - if (config) delete[] config; - - config = vdr->configLoad("General", "Channels"); - if (!config || strcasecmp(config, "FTA only")) - optionBox[5].setSelected("All"); - else - optionBox[5].setSelected("FTA only"); - if (config) delete[] config; + for (i = 0; i < numOptions; i++) + { + optionBox[i].setSelected(optionData[i].options[optionData[i].defaultOption]); + config = vdr->configLoad(optionData[i].configSection, optionData[i].configParam); + if (config) + { + for (UINT j = 0; j < optionData[i].optionCount; j++) + { + if (!strcasecmp(config, optionData[i].options[j])) + { + optionBox[i].setSelected(optionData[i].options[j]); + } + } + delete[] config; + } + } selectedOption = 0; optionBox[0].setActive(1); @@ -141,19 +89,14 @@ void VOptions::draw() WSymbol wsy; Colour cl; - drawText("Remote control type", 10, 45, Colour::LIGHTTEXT); - drawText("TV connection type", 10, 75, Colour::LIGHTTEXT); - drawText("TV aspect ratio", 10, 105, Colour::LIGHTTEXT); - drawText("16:9 on 4:3 display mode", 10, 135, Colour::LIGHTTEXT); - drawText("Power state after bootup", 10, 165, Colour::LIGHTTEXT); - drawText("Display channels", 10, 195, Colour::LIGHTTEXT); - - drawText("Press back to exit, <, > or [ok] to change", 10, 220, Colour::LIGHTTEXT); + drawText("Press back to exit, <, > or [ok] to change", 10, 255, Colour::LIGHTTEXT); wsy.setSurface(surface); for (UINT i = 0; i < numOptions; i++) { + drawText(optionData[i].title, 10, 45+i*30, Colour::LIGHTTEXT); + if (i == selectedOption) cl = Colour::SELECTHIGHLIGHT; else cl = Colour::BUTTONBACKGROUND; @@ -168,7 +111,6 @@ void VOptions::draw() optionBox[i].draw(); optionBox[i].show(); } - } int VOptions::handleCommand(int command) @@ -235,53 +177,51 @@ int VOptions::handleCommand(int command) void VOptions::doSave() { - char* remoteType = optionBox[0].getSelected(); - vdr->configSave("General", "Remote type", remoteType); - - char* tvconnection = optionBox[1].getSelected(); - if (!strcmp(tvconnection, "S-Video")) - vdr->configSave("TV", "S-Video", "Yes"); - else - vdr->configSave("TV", "S-Video", "No"); - - char* aspect = optionBox[2].getSelected(); - vdr->configSave("TV", "Aspect", aspect); - - char* widemode = optionBox[3].getSelected(); - vdr->configSave("TV", "Widemode", widemode); - - char* powerState = optionBox[4].getSelected(); - vdr->configSave("General", "Power After Boot", powerState); + char* result[numOptions]; - char* channels = optionBox[5].getSelected(); - vdr->configSave("General", "Channels", channels); + for (UINT i = 0; i < numOptions; i++) + { + result[i] = optionBox[i].getSelected(); + vdr->configSave(optionData[i].configSection, optionData[i].configParam, result[i]); + } // Apply changes + Video* video = Video::getInstance(); - if (!strcmp(remoteType, "New")) + if (!strcmp(result[0], optionData[0].options[1])) + { + Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote"); Remote::getInstance()->setRemoteType(Remote::NEWREMOTE); + } else + { + Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote"); Remote::getInstance()->setRemoteType(Remote::OLDREMOTE); + } - Video* video = Video::getInstance(); - - if (!strcmp(tvconnection, "S-Video")) + if (!strcmp(result[1], optionData[1].options[1])) + { + Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video"); video->setConnection(Video::SVIDEO); + } else + { + Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite"); video->setConnection(Video::COMPOSITERGB); + } - if (!strcmp(aspect, "16:9")) + if (!strcmp(result[2], optionData[2].options[1])) { - Log::getInstance()->log("Options", Log::DEBUG, "Setting widescreen"); + Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV"); video->setTVsize(Video::ASPECT16X9); } else { - Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 screen"); + Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV"); video->setTVsize(Video::ASPECT4X3); } - if (!strcmp(widemode, "Letterbox")) + if (!strcmp(result[3], optionData[3].options[1])) { Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox"); video->setMode(Video::LETTERBOX); @@ -291,4 +231,6 @@ void VOptions::doSave() Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides"); video->setMode(Video::NORMAL); } + } + diff --git a/voptions.h b/voptions.h index 8237af1..96d2db7 100644 --- a/voptions.h +++ b/voptions.h @@ -30,6 +30,36 @@ #include "woptionbox.h" #include "wsymbol.h" +#define NUM_OPTIONS 7 +typedef struct +{ + char *title; // Name of the option + char *configSection; // Which section of the config file + char *configParam; // Parameter name in the config file + UINT optionCount; // How many choices? + UINT defaultOption; // Serial of the default choice (base 0) + const char **options; // Text for the options +} OPTIONDATA; + +const static char* options0[] = {"Old", "New"}; +const static char* options1[] = {"RGB+composite", "S-Video"}; +const static char* options2[] = {"4:3", "16:9"}; +const static char* options3[] = {"Chop sides", "Letterbox"}; +const static char* options4[] = {"On", "Off", "Last state"}; +const static char* options5[] = {"All", "FTA only"}; +const static char* options6[] = {"0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "99"}; + +const static OPTIONDATA optionData[NUM_OPTIONS] = +{ + {"Remote control type", "General", "Remote type", 2, 0, options0 }, + {"TV connection type", "TV", "Connection", 2, 0, options1 }, + {"TV aspect ratio", "TV", "Aspect", 2, 0, options2 }, + {"16:9 on 4:3 display mode", "TV", "Widemode", 2, 0, options3 }, + {"Power state after bootup", "General", "Power After Boot", 3, 0, options4 }, + {"Display channels", "General", "Channels", 2, 0, options5 }, + {"VDR-Pri 0=OK !See forums!","General", "Live priority", 21, 0, options6 } +}; + class VOptions : public View { public: @@ -42,11 +72,10 @@ class VOptions : public View private: void doSave(); - const static UINT numOptions = 6; + const static UINT numOptions = NUM_OPTIONS; UINT selectedOption; WOptionBox optionBox[numOptions]; VDR* vdr; - }; #endif diff --git a/vvideolive.cc b/vvideolive.cc index aab8f08..05f0fed 100644 --- a/vvideolive.cc +++ b/vvideolive.cc @@ -32,14 +32,9 @@ VVideoLive::VVideoLive(ChannelList* tchanList, ULONG tstreamType) unavailable = 0; unavailableView = NULL; streamType = tstreamType; - if (streamType == VDR::VIDEO) - { - player = new PlayerVideo(Command::getInstance(), 0); - } - else - { - player = new PlayerRadio(); - } + if (streamType == VDR::RADIO) player = new PlayerVideo(Command::getInstance(), 0, 1); + else player = new PlayerVideo(Command::getInstance(), 0, 0); + player->init(); Video* video = Video::getInstance(); diff --git a/vvideorec.cc b/vvideorec.cc index 113a853..5622e18 100644 --- a/vvideorec.cc +++ b/vvideorec.cc @@ -22,7 +22,7 @@ VVideoRec::VVideoRec(Recording* rec) { - player = new PlayerVideo(Command::getInstance(), 1); + player = new PlayerVideo(Command::getInstance(), 1, 0); // say 0 for radio because buffering will work anyway player->init(); vdr = VDR::getInstance(); diff --git a/woptionbox.cc b/woptionbox.cc index cd2cafe..ca56e27 100644 --- a/woptionbox.cc +++ b/woptionbox.cc @@ -36,13 +36,17 @@ WOptionBox::~WOptionBox() free(options); } -void WOptionBox::addOption(char* takeText) +void WOptionBox::addOption(const char* takeText) { int length = strlen(takeText); char* newOption = new char[length + 1]; strcpy(newOption, takeText); - options = (char**)realloc(options, numOptions * sizeof(char*)); + Log::getInstance()->log("Temp", Log::DEBUG, "About to realloc, num Options=%i, current options = %p, new text = %s", numOptions, options, newOption); + + options = (char**)realloc(options, (numOptions+1) * sizeof(char*)); + Log::getInstance()->log("Temp", Log::DEBUG, ""); + options[numOptions] = newOption; numOptions++; @@ -91,7 +95,7 @@ void WOptionBox::cycle() } } -void WOptionBox::setSelected(char* toSelect) +void WOptionBox::setSelected(const char* toSelect) { for(UINT i = 0; i < numOptions; i++) { diff --git a/woptionbox.h b/woptionbox.h index c9e8def..b840b13 100644 --- a/woptionbox.h +++ b/woptionbox.h @@ -32,8 +32,8 @@ class WOptionBox : public Widget public: WOptionBox(); ~WOptionBox(); - void addOption(char* newOption); - void setSelected(char* selectedOption); + void addOption(const char* newOption); + void setSelected(const char* selectedOption); char* getSelected(); void setActive(UCHAR tactive); void left(); -- 2.39.2