Home

Dokumentation

Impressum

Dokumentation VDR
 

Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

dvbosd.c

Go to the documentation of this file.
00001 /*
00002  * dvbosd.c: Implementation of the DVB On Screen Display
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: dvbosd.c 1.19 2002/08/25 09:53:51 kls Exp $
00008  */
00009 
00010 #include "dvbosd.h"
00011 #include <signal.h>
00012 #include <sys/ioctl.h>
00013 #include <sys/unistd.h>
00014 #include "tools.h"
00015 
00016 const cDvbDevice *cDvbOsd::dvbDevice = NULL;
00017 
00018 cDvbOsd::cDvbOsd(int x, int y)
00019 :cOsdBase(x, y)
00020 {
00021   osdDev = dvbDevice ? dvbDevice->OsdDeviceHandle() : -1;
00022   if (osdDev < 0)
00023      esyslog("ERROR: illegal OSD device handle (%d)!", osdDev);
00024 }
00025 
00026 cDvbOsd::~cDvbOsd()
00027 {
00028   for (int i = 0; i < NumWindows(); i++)
00029       CloseWindow(GetWindowNr(i));
00030 }
00031 
00032 void cDvbOsd::SetDvbDevice(const cDvbDevice *DvbDevice)
00033 {
00034   dvbDevice = DvbDevice;
00035 }
00036 
00037 bool cDvbOsd::SetWindow(cWindow *Window)
00038 {
00039   if (Window) {
00040      // Window handles are counted 0...(MAXNUMWINDOWS - 1), but the actual window
00041      // numbers in the driver are used from 1...MAXNUMWINDOWS.
00042      int Handle = Window->Handle();
00043      if (0 <= Handle && Handle < MAXNUMWINDOWS) {
00044         Cmd(OSD_SetWindow, 0, Handle + 1);
00045         return true;
00046         }
00047      esyslog("ERROR: illegal window handle: %d", Handle);
00048      }
00049   return false;
00050 }
00051 
00052 void cDvbOsd::Cmd(OSD_Command cmd, int color, int x0, int y0, int x1, int y1, const void *data)
00053 {
00054   if (osdDev >= 0) {
00055      osd_cmd_t dc;
00056      dc.cmd   = cmd;
00057      dc.color = color;
00058      dc.x0    = x0;
00059      dc.y0    = y0;
00060      dc.x1    = x1;
00061      dc.y1    = y1;
00062      dc.data  = (void *)data;
00063      // must block all signals, otherwise the command might not be fully executed
00064      sigset_t set, oldset;
00065      sigfillset(&set);
00066      sigdelset(&set, SIGALRM);
00067      sigprocmask(SIG_BLOCK, &set, &oldset);
00068      ioctl(osdDev, OSD_SEND_CMD, &dc);
00069      if (cmd == OSD_SetBlock) // XXX this is the only command that takes longer
00070         usleep(5000); // XXX Workaround for a driver bug (cInterface::DisplayChannel() displayed texts at wrong places
00071                       // XXX and sometimes the OSD was no longer displayed).
00072                       // XXX Increase the value if the problem still persists on your particular system.
00073                       // TODO Check if this is still necessary with driver versions after 0.7.
00074      sigprocmask(SIG_SETMASK, &oldset, NULL);
00075      }
00076 }
00077 
00078 bool cDvbOsd::OpenWindow(cWindow *Window)
00079 {
00080   if (SetWindow(Window)) {
00081      Cmd(OSD_Open, Window->Bpp(), X0() + Window->X0(), Y0() + Window->Y0(), X0() + Window->X0() + Window->Width() - 1, Y0() + Window->Y0() + Window->Height() - 1, (void *)1); // initially hidden!
00082      return true;
00083      }
00084   return false;
00085 }
00086 
00087 void cDvbOsd::CommitWindow(cWindow *Window)
00088 {
00089   if (SetWindow(Window)) {
00090      int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
00091      if (Window->Dirty(x1, y1, x2, y2)) {
00092         // commit colors:
00093         int FirstColor = 0, LastColor = 0;
00094         const eDvbColor *pal;
00095         while ((pal = Window->NewColors(FirstColor, LastColor)) != NULL)
00096               Cmd(OSD_SetPalette, FirstColor, LastColor, 0, 0, 0, pal);
00097         // commit modified data:
00098         Cmd(OSD_SetBlock, Window->Width(), x1, y1, x2, y2, Window->Data(x1, y1));
00099         }
00100      }
00101 }
00102 
00103 void cDvbOsd::ShowWindow(cWindow *Window)
00104 {
00105   if (SetWindow(Window))
00106      Cmd(OSD_MoveWindow, 0, X0() + Window->X0(), Y0() + Window->Y0());
00107 }
00108 
00109 void cDvbOsd::HideWindow(cWindow *Window, bool Hide)
00110 {
00111   if (SetWindow(Window))
00112      Cmd(Hide ? OSD_Hide : OSD_Show, 0);
00113 }
00114 
00115 void cDvbOsd::MoveWindow(cWindow *Window, int x, int y)
00116 {
00117   if (SetWindow(Window))
00118      Cmd(OSD_MoveWindow, 0, X0() + x, Y0() + y);
00119 }
00120 
00121 void cDvbOsd::CloseWindow(cWindow *Window)
00122 {
00123   if (SetWindow(Window))
00124      Cmd(OSD_Close);
00125 }

Generated on Wed Feb 5 23:30:08 2003 for VDR by doxygen1.3-rc2