/* * 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 #include #include "filter.h" #include "radioinfo.h" #include "tools.h" #include "config.h" /////////////////////////////////////////////////////////////////////////////// cRadioInfoFilter* cRadioInfoFilter::instance = NULL; /////////////////////////////////////////////////////////////////////////////// cRadioInfoFilter::cRadioInfoFilter() { dprint(L_FIL, "RadioInfoFilter Created"); numOfRetries = 0; attachedDevice = NULL; if (config.quickDetect) { dprint(L_FIL, "RadioInfoFilter Fast PID Detection Enabled."); Set(0x20, 0x02); Set(0x21, 0x02); } else { dprint(L_FIL, "RadioInfoFilter Thorough PID Detection Enabled."); Set(0x00, 0x00); } } //----------------------------------------------------------------------------- cRadioInfoFilter* cRadioInfoFilter::Instance(void) { if (!instance) instance = new cRadioInfoFilter(); return instance; } //----------------------------------------------------------------------------- void cRadioInfoFilter::Destroy(void) { delete instance; instance = NULL; } //----------------------------------------------------------------------------- void cRadioInfoFilter::Attach(cDevice* device) { if (!attachedDevice) { attachedDevice = device; if (attachedDevice) { attachedDevice->AttachFilter(this); dprint(L_FIL, "RadioInfoFilter Attached."); } } } //----------------------------------------------------------------------------- void cRadioInfoFilter::Detach(void) { if (attachedDevice) { attachedDevice->Detach(this); attachedDevice = NULL; dprint(L_FIL, "RadioInfoFilter Detached."); } } //----------------------------------------------------------------------------- void cRadioInfoFilter::SetStatus(bool On) { numOfRetries = 0; cFilter::SetStatus(On); } //----------------------------------------------------------------------------- void cRadioInfoFilter::Process(u_short Pid, u_char Tid, const u_char* Data, int Length) { if (!numOfRetries) dprint(L_FIL, "radioInfoFilter Receiving Data."); numOfRetries++; if (numOfRetries > config.maxRetries) { SetStatus(false); cPluginRadioinfo::currentRadioInfo->FoundInfoPid(-1); return; } if (Pid == 0x00 && Tid == 0x00) { SI::PAT pat(Data, false); if (!pat.CheckCRCAndParse()) return; SI::PAT::Association assoc; for (SI::Loop::Iterator it; pat.associationLoop.getNext(assoc, it); ) { if (!assoc.isNITPid()) { if (Channels.GetByServiceID(Source(), Transponder(), assoc.getServiceId())) { Add(assoc.getPid(), 0x02); break; } } } } else { SI::PMT pmt(Data, false); if (!pmt.CheckCRCAndParse()) return; cChannel* Channel = Channels.GetByServiceID(Source(), Transponder(), pmt.getServiceId()); if (Channel && Channel == Channels.GetByNumber(cDevice::CurrentChannel()) ) { SI::PMT::Stream stream; for (SI::Loop::Iterator it; pmt.streamLoop.getNext(stream, it); ) { if (stream.getStreamType() == 5) { cPluginRadioinfo::currentRadioInfo->FoundInfoPid(stream.getPid()); SetStatus(false); Detach(); } } } } } ///////////////////////////////////////////////////////////////////////////////