/* * Copyright (C) 2006-2009 Alex Lasnier * * This file is part of Radio Info * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "radioinfo.h" #include "filter.h" #include "tools.h" #include "config.h" #include "menu.h" #if VDRVERSNUM < 10510 #error This version of RadioInfo only works with VDR 1.5.10 or above. #endif /////////////////////////////////////////////////////////////////////////////// static const char* VERSION = "0.2.0"; static const char* DESCRIPTION = "Provides extra information for radio channels"; static const char* MAINMENUENTRY = NULL; cPluginRadioinfo* cPluginRadioinfo::currentRadioInfo = NULL; sRadioInfoConfig config; /////////////////////////////////////////////////////////////////////////////// cPluginRadioinfo::cPluginRadioinfo(void) { // Initialize any member variables here. // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! SetLogType(L_ALL); radioInfoOsd = NULL; radioInfoReceiver = NULL; currentChannel = NULL; currentDevice = NULL; currentRadioInfo = this; config.maxRetries = 100; config.quickDetect = true; config.osdDelay = 2; } //----------------------------------------------------------------------------- cPluginRadioinfo::~cPluginRadioinfo() { // Clean up after yourself! delete radioInfoOsd; delete radioInfoReceiver; cRadioInfoFilter::Destroy(); } //----------------------------------------------------------------------------- const char* cPluginRadioinfo::Version(void) { return VERSION; } const char* cPluginRadioinfo::Description(void) { return DESCRIPTION; } const char* cPluginRadioinfo::MainMenuEntry(void) { return MAINMENUENTRY; } //----------------------------------------------------------------------------- const char* cPluginRadioinfo::CommandLineHelp(void) { // Return a string that describes all known command line options. return NULL; } //----------------------------------------------------------------------------- bool cPluginRadioinfo::ProcessArgs(int argc, char* argv[]) { // Implement command line argument processing here if applicable. return true; } //----------------------------------------------------------------------------- bool cPluginRadioinfo::Initialize(void) { pidCache.Load(); return true; } //----------------------------------------------------------------------------- bool cPluginRadioinfo::Start(void) { // Start any background activities the plugin shall perform. // Initialize any background activities the plugin shall perform. return true; } //----------------------------------------------------------------------------- void cPluginRadioinfo::Stop(void) { // Stop any background activities the plugin shall perform. if (radioInfoOsd) radioInfoOsd->Stop(); if (radioInfoReceiver) radioInfoReceiver->Detach(); } //----------------------------------------------------------------------------- void cPluginRadioinfo::Housekeeping(void) { // Perform any cleanup or other regular tasks. } //----------------------------------------------------------------------------- cOsdObject* cPluginRadioinfo::MainMenuAction(void) { return NULL; } //----------------------------------------------------------------------------- cMenuSetupPage* cPluginRadioinfo::SetupMenu(void) { // Return a setup menu in case the plugin supports one. return new cRadioInfoSetupMenu; } //----------------------------------------------------------------------------- bool cPluginRadioinfo::SetupParse(const char* Name, const char* Value) { // Parse your own setup parameters and store their values. if (!strcasecmp(Name, "maxRetries")) config.maxRetries = atoi(Value); else if (!strcasecmp(Name, "quickDetect")) config.quickDetect = atoi(Value); else if (!strcasecmp(Name, "osdDelay")) config.osdDelay = atoi(Value); else return false; return true; } //----------------------------------------------------------------------------- bool cPluginRadioinfo::Service(const char* Id, void* Data) { // Handle custom service requests from other plugins return false; } //----------------------------------------------------------------------------- const char** cPluginRadioinfo::SVDRPHelpPages(void) { // Return help text for SVDRP commands this plugin implements return NULL; } //----------------------------------------------------------------------------- cString cPluginRadioinfo::SVDRPCommand(const char* Command, const char* Option, int& ReplyCode) { // Process SVDRP commands this plugin implements return NULL; } //----------------------------------------------------------------------------- void cPluginRadioinfo::ChannelSwitch(const cDevice* Device, int ChannelNumber, bool LiveView) { if (Device != cDevice::PrimaryDevice()) return; if (ChannelNumber) { if (ChannelNumber == cDevice::PrimaryDevice()->CurrentChannel()) { cRadioInfoFilter::Instance()->Detach(); delete radioInfoReceiver; radioInfoReceiver = NULL; if (radioInfoOsd) { //radioInfoOsd->Stop(); delete radioInfoOsd; radioInfoOsd = NULL; } currentChannel = NULL; currentDevice = NULL; const cChannel* chan = Channels.GetByNumber(ChannelNumber); // Is it a radio channel? if (chan && chan->Vpid() == 0 && chan->Apid(0) != 0) { currentChannel = (cChannel*) chan; currentDevice = (cDevice*) cDevice::ActualDevice(); radioInfoData.Reset(); FindPid(); radioInfoOsd = new cRadioInfoOsd(&radioInfoData); } else // Not a radio channel { } } } else // About to switch channel { } } //----------------------------------------------------------------------------- void cPluginRadioinfo::FindPid(void) { int pid = pidCache.Pid(currentChannel->Nid(), currentChannel->Tid(), currentChannel->Sid()); if (pid != -1) { dprint(L_DBG, "Info PID found in cache"); FoundInfoPid(pid); } else { dprint(L_DBG, "Info PID not cached, searching..."); cRadioInfoFilter::Instance()->Attach(currentDevice); } } //----------------------------------------------------------------------------- void cPluginRadioinfo::FoundInfoPid(int Pid) { if (Pid != -1) { dprint(L_DBG, "Found Info PID %d", Pid); // Add pid to cache pidCache.SetPid(currentChannel->Nid(), currentChannel->Tid(), currentChannel->Sid(), Pid); if (radioInfoReceiver) { dprint(L_ERR, "Receiver already exits; this shoudn't happen!"); delete radioInfoReceiver; radioInfoReceiver = NULL; } // Start receiving data from info PID radioInfoReceiver = new cRadioInfoReceiver(Pid, currentChannel, &radioInfoData); radioInfoReceiver->Attach(currentDevice); } else // No PID found { //TODO: If no PID is found perhaps the program should periodically retry to find one. dprint(L_DBG, "Unable to find info PID"); } } /////////////////////////////////////////////////////////////////////////////// VDRPLUGINCREATOR(cPluginRadioinfo); // Don't touch this! ///////////////////////////////////////////////////////////////////////////////