vdr
1.7.27
|
00001 /* 00002 * player.c: The basic player interface 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * $Id: player.c 2.0 2007/07/20 15:25:24 kls Exp $ 00008 */ 00009 00010 #include "player.h" 00011 #include "i18n.h" 00012 00013 // --- cPlayer --------------------------------------------------------------- 00014 00015 cPlayer::cPlayer(ePlayMode PlayMode) 00016 { 00017 device = NULL; 00018 playMode = PlayMode; 00019 } 00020 00021 cPlayer::~cPlayer() 00022 { 00023 Detach(); 00024 } 00025 00026 int cPlayer::PlayPes(const uchar *Data, int Length, bool VideoOnly) 00027 { 00028 if (device) 00029 return device->PlayPes(Data, Length, VideoOnly); 00030 esyslog("ERROR: attempt to use cPlayer::PlayPes() without attaching to a cDevice!"); 00031 return -1; 00032 } 00033 00034 void cPlayer::Detach(void) 00035 { 00036 if (device) 00037 device->Detach(this); 00038 } 00039 00040 // --- cControl -------------------------------------------------------------- 00041 00042 cControl *cControl::control = NULL; 00043 cMutex cControl::mutex; 00044 00045 cControl::cControl(cPlayer *Player, bool Hidden) 00046 { 00047 attached = false; 00048 hidden = Hidden; 00049 player = Player; 00050 } 00051 00052 cControl::~cControl() 00053 { 00054 if (this == control) 00055 control = NULL; 00056 } 00057 00058 cOsdObject *cControl::GetInfo(void) 00059 { 00060 return NULL; 00061 } 00062 00063 cControl *cControl::Control(void) 00064 { 00065 cMutexLock MutexLock(&mutex); 00066 return (control && !control->hidden) ? control : NULL; 00067 } 00068 00069 void cControl::Launch(cControl *Control) 00070 { 00071 cMutexLock MutexLock(&mutex); 00072 cControl *c = control; // keeps control from pointing to uninitialized memory 00073 control = Control; 00074 delete c; 00075 } 00076 00077 void cControl::Attach(void) 00078 { 00079 cMutexLock MutexLock(&mutex); 00080 if (control && !control->attached && control->player && !control->player->IsAttached()) { 00081 if (cDevice::PrimaryDevice()->AttachPlayer(control->player)) 00082 control->attached = true; 00083 else { 00084 Skins.Message(mtError, tr("Channel locked (recording)!")); 00085 Shutdown(); 00086 } 00087 } 00088 } 00089 00090 void cControl::Shutdown(void) 00091 { 00092 cMutexLock MutexLock(&mutex); 00093 cControl *c = control; // avoids recursions 00094 control = NULL; 00095 delete c; 00096 }