|
SASC
DVBSoftCAM
|
00001 /* 00002 * device.c: The basic device interface 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * $Id: device.c 1.56 2004/06/19 08:51:05 kls Exp $ 00008 */ 00009 00010 #include "include/vdr/device.h" 00011 #include <errno.h> 00012 #include <sys/ioctl.h> 00013 #include <sys/mman.h> 00014 #include "include/vdr/channels.h" 00015 #include "include/vdr/i18n.h" 00016 00017 // --- cDevice --------------------------------------------------------------- 00018 00019 // The default priority for non-primary devices: 00020 #define DEFAULTPRIORITY -1 00021 00022 int cDevice::numDevices = 0; 00023 int cDevice::useDevice = 0; 00024 int cDevice::nextCardIndex = 0; 00025 int cDevice::currentChannel = 1; 00026 cDevice *cDevice::device[MAXDEVICES] = { NULL }; 00027 cDevice *cDevice::primaryDevice = NULL; 00028 00029 cDevice::cDevice(void) 00030 { 00031 cardIndex = nextCardIndex++; 00032 00033 SetDescription("receiver on device %d", CardIndex() + 1); 00034 00035 mute = false; 00036 00037 sectionHandler = NULL; 00038 eitFilter = NULL; 00039 patFilter = NULL; 00040 sdtFilter = NULL; 00041 nitFilter = NULL; 00042 00043 player = NULL; 00044 00045 for (int i = 0; i < MAXRECEIVERS; i++) 00046 receiver[i] = NULL; 00047 00048 if (numDevices < MAXDEVICES) 00049 device[numDevices++] = this; 00050 else 00051 esyslog("ERROR: too many devices!"); 00052 } 00053 00054 cDevice::~cDevice() 00055 { 00056 } 00057 00058 void cDevice::SetUseDevice(int n) 00059 { 00060 if (n < MAXDEVICES) 00061 useDevice |= (1 << n); 00062 } 00063 00064 int cDevice::NextCardIndex(int n) 00065 { 00066 if (n > 0) { 00067 nextCardIndex += n; 00068 if (nextCardIndex >= MAXDEVICES) 00069 esyslog("ERROR: nextCardIndex too big (%d)", nextCardIndex); 00070 } 00071 else if (n < 0) 00072 esyslog("ERROR: illegal value in IncCardIndex(%d)", n); 00073 return nextCardIndex; 00074 } 00075 00076 int cDevice::DeviceNumber(void) const 00077 { 00078 for (int i = 0; i < numDevices; i++) { 00079 if (device[i] == this) 00080 return i; 00081 } 00082 return -1; 00083 } 00084 00085 void cDevice::MakePrimaryDevice(bool On) 00086 { 00087 } 00088 00089 bool cDevice::SetPrimaryDevice(int n) 00090 { 00091 n--; 00092 if (0 <= n && n < numDevices && device[n]) { 00093 isyslog("setting primary device to %d", n + 1); 00094 if (primaryDevice) 00095 primaryDevice->MakePrimaryDevice(false); 00096 primaryDevice = device[n]; 00097 primaryDevice->MakePrimaryDevice(true); 00098 return true; 00099 } 00100 esyslog("ERROR: invalid primary device number: %d", n + 1); 00101 return false; 00102 } 00103 00104 bool cDevice::HasDecoder(void) const 00105 { 00106 return false; 00107 } 00108 00109 cSpuDecoder *cDevice::GetSpuDecoder(void) 00110 { 00111 return NULL; 00112 } 00113 00114 cDevice *cDevice::ActualDevice(void) 00115 { 00116 return NULL; 00117 } 00118 00119 cDevice *cDevice::GetDevice(int Index) 00120 { 00121 int i; 00122 for (i = 0; i < numDevices; i++) 00123 if (device[i]->CardIndex() == Index) 00124 return device[i]; 00125 return NULL; 00126 } 00127 00128 cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool LiveView) 00129 { 00130 return NULL; 00131 } 00132 00133 bool cDevice::HasCi(void) 00134 { 00135 return false; 00136 } 00137 00138 void cDevice::SetCamSlot(cCamSlot *CamSlot) 00139 { 00140 } 00141 00142 void cDevice::Shutdown(void) 00143 { 00144 } 00145 00146 uchar *cDevice::GrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int SizeY) 00147 { 00148 return false; 00149 } 00150 00151 void cDevice::SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat) 00152 { 00153 } 00154 00155 void cDevice::SetVideoFormat(bool VideoFormat16_9) 00156 { 00157 } 00158 00159 eVideoSystem cDevice::GetVideoSystem(void) 00160 { 00161 return vsNTSC; 00162 } 00163 00164 #define PRINTPIDS(s) 00165 00166 bool cDevice::HasPid(int Pid) const 00167 { 00168 for (int i = 0; i < MAXPIDHANDLES; i++) { 00169 if (pidHandles[i].pid == Pid) 00170 return true; 00171 } 00172 return false; 00173 } 00174 00175 bool cDevice::AddPid(int Pid, ePidType PidType) 00176 { 00177 if (Pid || PidType == ptPcr) { 00178 int n = -1; 00179 int a = -1; 00180 if (PidType != ptPcr) { // PPID always has to be explicit 00181 for (int i = 0; i < MAXPIDHANDLES; i++) { 00182 if (i != ptPcr) { 00183 if (pidHandles[i].pid == Pid) 00184 n = i; 00185 else if (a < 0 && i >= ptOther && !pidHandles[i].used) 00186 a = i; 00187 } 00188 } 00189 } 00190 if (n >= 0) { 00191 // The Pid is already in use 00192 if (++pidHandles[n].used == 2 && n <= ptTeletext) { 00193 // It's a special PID that may have to be switched into "tap" mode 00194 PRINTPIDS("A"); 00195 return SetPid(&pidHandles[n], n, true); 00196 } 00197 PRINTPIDS("a"); 00198 return true; 00199 } 00200 else if (PidType < ptOther) { 00201 // The Pid is not yet in use and it is a special one 00202 n = PidType; 00203 } 00204 else if (a >= 0) { 00205 // The Pid is not yet in use and we have a free slot 00206 n = a; 00207 } 00208 else 00209 esyslog("ERROR: no free slot for PID %d", Pid); 00210 if (n >= 0) { 00211 pidHandles[n].pid = Pid; 00212 pidHandles[n].used = 1; 00213 PRINTPIDS("C"); 00214 return SetPid(&pidHandles[n], n, true); 00215 } 00216 } 00217 return true; 00218 } 00219 00220 void cDevice::DelPid(int Pid, ePidType PidType) 00221 { 00222 if (Pid || PidType == ptPcr) { 00223 int n = -1; 00224 if (PidType == ptPcr) 00225 n = PidType; // PPID always has to be explicit 00226 else { 00227 for (int i = 0; i < MAXPIDHANDLES; i++) { 00228 if (pidHandles[i].pid == Pid) { 00229 n = i; 00230 break; 00231 } 00232 } 00233 } 00234 if (n >= 0 && pidHandles[n].used) { 00235 PRINTPIDS("D"); 00236 if (--pidHandles[n].used < 2) { 00237 SetPid(&pidHandles[n], n, false); 00238 if (pidHandles[n].used == 0) { 00239 pidHandles[n].handle = -1; 00240 pidHandles[n].pid = 0; 00241 } 00242 } 00243 PRINTPIDS("E"); 00244 } 00245 } 00246 } 00247 00248 bool cDevice::SetPid(cPidHandle *Handle, int Type, bool On) 00249 { 00250 return false; 00251 } 00252 00253 void cDevice::StartSectionHandler(void) 00254 { 00255 } 00256 00257 int cDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask) 00258 { 00259 return -1; 00260 } 00261 00262 void cDevice::CloseFilter(int Handle) 00263 { 00264 close(Handle); 00265 } 00266 00267 void cDevice::AttachFilter(cFilter *Filter) 00268 { 00269 } 00270 00271 void cDevice::Detach(cFilter *Filter) 00272 { 00273 } 00274 00275 bool cDevice::ProvidesSource(int Source) const 00276 { 00277 return false; 00278 } 00279 00280 bool cDevice::ProvidesTransponder(const cChannel *Channel) const 00281 { 00282 return false; 00283 } 00284 00285 bool cDevice::ProvidesTransponderExclusively(const cChannel *Channel) const 00286 { 00287 for (int i = 0; i < numDevices; i++) { 00288 if (device[i] && device[i] != this && device[i]->ProvidesTransponder(Channel)) 00289 return false; 00290 } 00291 return true; 00292 } 00293 00294 bool cDevice::ProvidesChannel(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) const 00295 { 00296 return false; 00297 } 00298 00299 bool cDevice::IsTunedToTransponder(const cChannel *Channel) 00300 { 00301 return false; 00302 } 00303 00304 bool cDevice::MaySwitchTransponder(void) 00305 { 00306 return !Receiving(true) && !(pidHandles[ptAudio].pid || pidHandles[ptVideo].pid || pidHandles[ptDolby].pid); 00307 } 00308 00309 bool cDevice::SwitchChannel(const cChannel *Channel, bool LiveView) 00310 { 00311 return false; 00312 } 00313 00314 bool cDevice::SwitchChannel(int Direction) 00315 { 00316 return false; 00317 } 00318 00319 eSetChannelResult cDevice::SetChannel(const cChannel *Channel, bool LiveView) 00320 { 00321 return scrOk; 00322 } 00323 00324 bool cDevice::SetChannelDevice(const cChannel *Channel, bool LiveView) 00325 { 00326 return false; 00327 } 00328 00329 bool cDevice::HasLock(int TimeoutMs) 00330 { 00331 return true; 00332 } 00333 00334 bool cDevice::HasProgramme(void) 00335 { 00336 return false; 00337 } 00338 00339 int cDevice::GetAudioChannelDevice(void) 00340 { 00341 return 0; 00342 } 00343 00344 void cDevice::SetAudioChannelDevice(int AudioChannel) 00345 { 00346 } 00347 00348 void cDevice::SetVolumeDevice(int Volume) 00349 { 00350 } 00351 00352 void cDevice::SetDigitalAudioDevice(bool On) 00353 { 00354 } 00355 00356 void cDevice::SetAudioTrackDevice(eTrackType Type) 00357 { 00358 } 00359 00360 bool cDevice::ToggleMute(void) 00361 { 00362 return true; 00363 } 00364 00365 void cDevice::SetVolume(int Volume, bool Absolute) 00366 { 00367 } 00368 00369 int cDevice::NumAudioTracks(void) const 00370 { 00371 return 0; 00372 } 00373 00374 00375 bool cDevice::CanReplay(void) const 00376 { 00377 return HasDecoder(); 00378 } 00379 00380 bool cDevice::SetPlayMode(ePlayMode PlayMode) 00381 { 00382 return false; 00383 } 00384 00385 int64_t cDevice::GetSTC(void) 00386 { 00387 return -1; 00388 } 00389 00390 void cDevice::TrickSpeed(int Speed) 00391 { 00392 } 00393 00394 void cDevice::Clear(void) 00395 { 00396 } 00397 00398 void cDevice::Play(void) 00399 { 00400 } 00401 00402 void cDevice::Freeze(void) 00403 { 00404 } 00405 00406 void cDevice::Mute(void) 00407 { 00408 } 00409 00410 void cDevice::StillPicture(const uchar *Data, int Length) 00411 { 00412 } 00413 00414 bool cDevice::Replaying(void) const 00415 { 00416 return player != NULL; 00417 } 00418 00419 bool cDevice::AttachPlayer(cPlayer *Player) 00420 { 00421 return false; 00422 } 00423 00424 void cDevice::Detach(cPlayer *Player) 00425 { 00426 } 00427 00428 void cDevice::StopReplay(void) 00429 { 00430 } 00431 00432 bool cDevice::Poll(cPoller &Poller, int TimeoutMs) 00433 { 00434 return false; 00435 } 00436 00437 bool cDevice::Flush(int TimeoutMs) 00438 { 00439 return true; 00440 } 00441 00442 int cDevice::PlayVideo(const uchar *Data, int Length) 00443 { 00444 return -1; 00445 } 00446 00447 int cDevice::PlayAudio(const uchar *Data, int Length, uchar Id) 00448 { 00449 return -1; 00450 } 00451 00452 int cDevice::PlayPesPacket(const uchar *Data, int Length, bool VideoOnly) 00453 { 00454 return Length; 00455 } 00456 00457 int cDevice::PlayPes(const uchar *Data, int Length, bool VideoOnly) 00458 { 00459 return Length; 00460 } 00461 00462 int cDevice::Priority(void) const 00463 { 00464 return 0; 00465 } 00466 00467 bool cDevice::Ready(void) 00468 { 00469 return true; 00470 } 00471 00472 bool cDevice::Receiving(bool CheckAny) const 00473 { 00474 return false; 00475 } 00476 00477 void cDevice::Action(void) 00478 { 00479 } 00480 00481 bool cDevice::OpenDvr(void) 00482 { 00483 return false; 00484 } 00485 00486 void cDevice::CloseDvr(void) 00487 { 00488 } 00489 00490 bool cDevice::GetTSPacket(uchar *&Data) 00491 { 00492 return false; 00493 } 00494 00495 bool cDevice::AttachReceiver(cReceiver *Receiver) 00496 { 00497 return false; 00498 } 00499 00500 void cDevice::Detach(cReceiver *Receiver) 00501 { 00502 } 00503 00504 void cDevice::DetachAllReceivers(void) 00505 { 00506 } 00507 // --- cTSBuffer ------------------------------------------------------------- 00508 cTSBuffer::cTSBuffer(int File, int Size, int CardIndex) 00509 { 00510 } 00511 00512 cTSBuffer::~cTSBuffer() 00513 { 00514 } 00515 00516 void cTSBuffer::Action(void) 00517 { 00518 } 00519 00520 uchar *cTSBuffer::Get(void) 00521 { 00522 return NULL; 00523 } 00524