Guest
Public paste!

Untitled

By: a guest | Mar 14th, 2010 | Syntax: C | Size: 14.32 KB | Hits: 89 | Expires: Never
Copy text to clipboard
  1.  
  2. #include "xineCommon.h"
  3.  
  4. #include "xineOsd.h"
  5. #include "xineDevice.h"
  6. #include "xineLib.h"
  7.  
  8.  
  9.  
  10. namespace PluginXine
  11. {
  12.  
  13. #if APIVERSNUM < 10307
  14.  
  15.   bool cXineOsd::OpenWindow(cWindow *Window)
  16.   {
  17.     cMutexLock osdLock(&m_osdMutex);
  18.    
  19.     m_windowVisible[ Window->Handle() ] = false;
  20.    
  21.     int maxOsdWidth, maxOsdHeight;
  22.     GetMaxOsdSize(maxOsdWidth, maxOsdHeight);
  23.  
  24.     return m_xineLib.OpenWindow(this, Window, maxOsdWidth, maxOsdHeight);
  25.   }
  26.  
  27.   void cXineOsd::CommitWindow(cWindow *Window)
  28.   {
  29.     cMutexLock osdLock(&m_osdMutex);
  30.    
  31.     m_xineLib.CommitWindow(this, Window);
  32.   }
  33.  
  34.   void cXineOsd::ShowWindow(cWindow *Window)
  35.   {
  36.     cMutexLock osdLock(&m_osdMutex);
  37.    
  38.     m_windowVisible[ Window->Handle() ] = true;
  39.    
  40.     m_xineLib.ShowWindow(this, Window);
  41.   }
  42.  
  43.   void cXineOsd::HideWindow(cWindow *Window, bool Hide)
  44.   {
  45.     cMutexLock osdLock(&m_osdMutex);
  46.    
  47.     m_windowVisible[ Window->Handle() ] = !Hide;
  48.    
  49.     m_xineLib.HideWindow(this, Window, Hide);
  50.   }
  51.  
  52.   void cXineOsd::MoveWindow(cWindow *Window, int x, int y)
  53.   {
  54.     cMutexLock osdLock(&m_osdMutex);
  55.    
  56.     m_xineLib.MoveWindow(this, Window, x, y);
  57.   }
  58.  
  59.   void cXineOsd::CloseWindow(cWindow *Window)
  60.   {
  61.     cMutexLock osdLock(&m_osdMutex);
  62.    
  63.     m_windowVisible[ Window->Handle() ] = false;
  64.    
  65.     m_xineLib.CloseWindow(this, Window);
  66.   }
  67.  
  68. #endif
  69.  
  70.  
  71.   static int vl = -1, vt = -1, vw = -1, vh = -1, zx = -1, zy = -1;
  72.  
  73.  
  74.   void cXineOsd::ReshowCurrentOsd(const bool dontOptimize, const int frameLeft /* = -1 */, const int frameTop /* = -1 */, const int frameWidth /* = -1 */, const int frameHeight /* = -1 */, const int frameZoomX /* = -1 */, const int frameZoomY /* = -1 */)
  75.   {
  76.     cMutexLock osdLock(&m_osdMutex);
  77.    
  78.     int maxOsdWidth, maxOsdHeight;
  79.     GetMaxOsdSize(maxOsdWidth, maxOsdHeight);
  80.  
  81. #if APIVERSNUM < 10307    
  82.  
  83.     (void)vl;
  84.     (void)vt;
  85.     (void)vw;
  86.     (void)vh;
  87.     (void)zx;
  88.     (void)zy;
  89.  
  90.     for (int i = 0; i < NumWindows(); i++)
  91.     {
  92.       cWindow *const window = GetWindowNr(i);
  93.       if (!window)
  94.         continue;
  95.      
  96.       if (dontOptimize)
  97.         m_xineLib.OpenWindow(this, window, maxOsdWidth, maxOsdHeight);
  98.      
  99.       m_xineLib.CommitWindow(this, window, !dontOptimize);
  100.  
  101.       if (m_windowVisible[ i ])
  102.         Show(window->Handle());
  103.       else
  104.         Hide(window->Handle());
  105.     }
  106.  
  107. #else
  108.  
  109. #ifdef SET_VIDEO_WINDOW
  110.    
  111.     m_xineLib.SetVideoWindow(maxOsdWidth, maxOsdHeight, vidWin, dontOptimize);
  112.    
  113. #endif    
  114.    
  115.     int videoLeft   = frameLeft;
  116.     int videoTop    = frameTop;
  117.     int videoWidth  = frameWidth;
  118.     int videoHeight = frameHeight;
  119.     int videoZoomX  = frameZoomX;
  120.     int videoZoomY  = frameZoomY;
  121.  
  122.     if (frameLeft < 0
  123.         || frameTop < 0
  124.         || frameWidth < 0
  125.         || frameHeight < 0
  126.         || frameZoomX < 0
  127.         || frameZoomY < 0)
  128.     {
  129.       m_xineLib.execFuncVideoSize(videoLeft, videoTop, videoWidth, videoHeight, videoZoomX, videoZoomY);
  130.     }
  131.  
  132. //    ::fprintf(stderr, "frame: %d x %d, %d x %d\n", videoLeft, videoTop, videoWidth, videoHeight, videoZoomX, videoZoomY);
  133.  
  134.     vl = videoLeft;
  135.     vt = videoTop;
  136.     vw = videoWidth;
  137.     vh = videoHeight;
  138.     zx = videoZoomX;
  139.     zy = videoZoomY;
  140.    
  141.     for (int i = 0; i < MAXNUMWINDOWS; i++)
  142.       m_xineLib.SendWindow(maxOsdWidth, maxOsdHeight, this, i, GetBitmap(i), videoLeft, videoTop, videoWidth, videoHeight, videoZoomX, videoZoomY, dontOptimize);
  143.  
  144. #endif
  145.  
  146.     m_xineLib.execFuncOsdFlush();
  147.   }
  148.  
  149. #if APIVERSNUM < 10509
  150.   cXineOsd::cXineOsd(cXineDevice &xineDevice, int x, int y)
  151. #else
  152.   cXineOsd::cXineOsd(cXineDevice &xineDevice, int x, int y, uint Level)
  153. #endif
  154. #if APIVERSNUM < 10307    
  155.     : cOsdBase(x, y)
  156. #elif APIVERSNUM < 10509
  157.     : cOsd(x, y)
  158. #else
  159.     : cOsd(x, y, Level)
  160. #endif
  161.     , m_xineDevice(xineDevice)
  162.     , m_xineLib(xineDevice.m_xineLib)
  163.     , m_osdMutex(xineDevice.m_osdMutex)
  164.   {
  165. //static int cnt = 0;
  166. //fprintf(stderr, "x: %d, y: %d, cnt: %d\n", x, y, cnt);
  167. //    if (x == 58 && y == 46 && cnt++ == 5) { char cmd[500]; sprintf(cmd, "ddd /soft/vdr-" APIVERSION "/bin/vdr %d", getpid()); system(cmd); sleep(10); } //should never happen!
  168.  
  169. #if APIVERSNUM < 10307    
  170.  
  171.     ::memset(m_windowVisible, 0, sizeof (m_windowVisible));
  172.  
  173. #endif
  174.   }
  175.  
  176.   cXineOsd::~cXineOsd()
  177.   {
  178. #if APIVERSNUM < 10509
  179.     HideOsd();
  180. #else
  181.     cMutexLock osdLock(&m_osdMutex);
  182.    
  183.     if (Active())
  184.       SetActive(false);
  185. #endif
  186.   }
  187.  
  188.   void cXineOsd::HideOsd()
  189.   {
  190.     cMutexLock osdLock(&m_osdMutex);
  191.    
  192. #if APIVERSNUM < 10307    
  193.  
  194.     for (int i = 0; i < MAXNUMWINDOWS; i++)
  195.       m_xineLib.CloseWindow(this, i);
  196.  
  197. #else
  198.  
  199.     int maxOsdWidth, maxOsdHeight;
  200.     GetMaxOsdSize(maxOsdWidth, maxOsdHeight);
  201.  
  202.     tArea defaultWindow;
  203.     defaultWindow.x1 = 0;
  204.     defaultWindow.y1 = 0;
  205.     defaultWindow.x2 = 0;
  206.     defaultWindow.y2 = 0;
  207.     defaultWindow.bpp = 0;
  208.  
  209.     m_xineLib.SetVideoWindow(maxOsdWidth, maxOsdHeight, defaultWindow);
  210.    
  211.     for (int i = 0; i < MAXNUMWINDOWS; i++)
  212.       m_xineLib.SendWindow(maxOsdWidth, maxOsdHeight, this, i);
  213.    
  214. #endif    
  215.  
  216.     m_xineDevice.OnFreeOsd(this);
  217.  
  218.     m_xineLib.execFuncOsdFlush();
  219.  
  220. //    m_xineLib.execFuncGrabImage("/tmp/grab.jpg", true, 50, 1000, 1000);
  221.   }
  222.  
  223.  
  224.  
  225. #if APIVERSNUM >= 10307
  226.  
  227.   eOsdError cXineOsd::CanHandleAreas(const tArea *Areas, int NumAreas)
  228.   {
  229. //    fprintf(stderr, "cXineOsd::CanHandleAreas(%p, %d)\n", Areas, NumAreas);
  230.  
  231.     const eOsdError retVal = cOsd::CanHandleAreas(Areas, NumAreas);
  232.     if (oeOk != retVal)
  233.       return retVal;
  234.  
  235.     for (int i = 0; i < NumAreas; i++)
  236.     {
  237.       const tArea &a = Areas[ i ];
  238. /*      
  239.       fprintf(stderr, "Areas[ %d ]: (%d,%d)-(%d,%d)@%d\n"
  240.               , i
  241.               , a.x1
  242.               , a.y1
  243.               , a.x2
  244.               , a.y2
  245.               , a.bpp);
  246. */      
  247.       assert(a.x1 <= a.x2);
  248.       assert(a.y1 <= a.y2);
  249.  
  250.       if (1 != a.bpp
  251.           && 2 != a.bpp
  252.           && 4 != a.bpp
  253.           && 8 != a.bpp
  254.           && 16 != a.bpp)
  255.       {
  256.         return oeBppNotSupported;
  257.       }
  258.     }
  259.  
  260.     return oeOk;
  261.   }
  262.  
  263.   eOsdError cXineOsd::SetAreas(const tArea *Areas, int NumAreas)
  264.   {
  265.     cMutexLock osdLock(&m_osdMutex);
  266.     return cOsd::SetAreas(Areas, NumAreas);
  267.   }
  268.  
  269.   void cXineOsd::SaveRegion(int x1, int y1, int x2, int y2)
  270.   {
  271.     cMutexLock osdLock(&m_osdMutex);
  272.     cOsd::SaveRegion(x1, y1, x2, y2);
  273.   }
  274.  
  275.   void cXineOsd::RestoreRegion(void)
  276.   {
  277.     cMutexLock osdLock(&m_osdMutex);
  278.     cOsd::RestoreRegion();
  279.   }
  280.  
  281.   eOsdError cXineOsd::SetPalette(const cPalette &Palette, int Area)
  282.   {
  283.     cMutexLock osdLock(&m_osdMutex);
  284.     return cOsd::SetPalette(Palette, Area);
  285.   }
  286.  
  287.   void cXineOsd::DrawPixel(int x, int y, tColor Color)
  288.   {
  289.     cMutexLock osdLock(&m_osdMutex);
  290.     cOsd::DrawPixel(x, y, Color);
  291.   }
  292.  
  293. #if APIVERSNUM < 10327    
  294.   void cXineOsd::DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg /* = 0 */, tColor ColorBg /* = 0 */)
  295.   {
  296.     cMutexLock osdLock(&m_osdMutex);
  297.     cOsd::DrawBitmap(x, y, Bitmap, ColorFg, ColorBg);
  298. //    fprintf(stderr, "drawbitmap\n");
  299.   }
  300. #elif APIVERSNUM < 10344
  301.   void cXineOsd::DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg /* = 0 */, tColor ColorBg /* = 0 */, bool ReplacePalette /* = false */)
  302.   {
  303.     cMutexLock osdLock(&m_osdMutex);
  304.     cOsd::DrawBitmap(x, y, Bitmap, ColorFg, ColorBg, ReplacePalette);
  305. //    fprintf(stderr, "drawbitmap\n");
  306.   }
  307. #else  
  308.   void cXineOsd::DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg /* = 0 */, tColor ColorBg /* = 0 */, bool ReplacePalette /* = false */, bool Overlay /* = false */)
  309.   {
  310.     cMutexLock osdLock(&m_osdMutex);
  311.     cOsd::DrawBitmap(x, y, Bitmap, ColorFg, ColorBg, ReplacePalette, Overlay);
  312. //    fprintf(stderr, "drawbitmap: (%d x %d) at (%d, %d) in (%d x %d)\n", Bitmap.Width(), Bitmap.Height(), x, y, Width(), Height());
  313.   }
  314. #endif
  315.  
  316.   void cXineOsd::DrawBitmapHor(int x, int y, int w, const cBitmap &Bitmap)
  317.   {
  318. #ifdef VDR_HAS_TRUECOLOR_OSD
  319.     cMutexLock osdLock(&m_osdMutex);
  320.     cOsd::DrawBitmapHor(x, y, w, Bitmap);
  321. #endif
  322.   }
  323.  
  324.   void cXineOsd::DrawBitmapVert(int x, int y, int h, const cBitmap &Bitmap)
  325.   {
  326. #ifdef VDR_HAS_TRUECOLOR_OSD
  327.     cMutexLock osdLock(&m_osdMutex);
  328.     cOsd::DrawBitmapVert(x, y, h, Bitmap);
  329. #endif
  330.   }
  331.  
  332.   void cXineOsd::DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font, int Width /* = 0 */, int Height /* = 0 */, int Alignment /* = taDefault */)
  333.   {
  334.     cMutexLock osdLock(&m_osdMutex);
  335.     cOsd::DrawText(x, y, s, ColorFg, ColorBg, Font, Width, Height, Alignment);
  336.   }
  337.  
  338.   void cXineOsd::DrawImage(u_int imageId, int x, int y, bool blend, int horRepeat /* = 1 */, int vertRepeat /* = 1 */)
  339.   {
  340. #ifdef VDR_HAS_TRUECOLOR_OSD
  341.     cMutexLock osdLock(&m_osdMutex);
  342.     cOsd::DrawImage(imageId, x, y, blend, horRepeat, vertRepeat);
  343. #endif
  344.   }
  345.  
  346.   void cXineOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color)
  347.   {
  348.     cMutexLock osdLock(&m_osdMutex);
  349.     cOsd::DrawRectangle(x1, y1, x2, y2, Color);
  350.   }
  351.  
  352.   void cXineOsd::DrawRectangle(int x1, int y1, int x2, int y2, tColor Color, int alphaGradH, int alphaGradV, int alphaGradStepH, int alphaGradStepV)
  353.   {
  354. #ifdef VDR_HAS_TRUECOLOR_OSD
  355.     cMutexLock osdLock(&m_osdMutex);
  356.     cOsd::DrawRectangle(x1, y1, x2, y2, Color, alphaGradH, alphaGradV, alphaGradStepH, alphaGradStepV);
  357. #endif
  358.   }
  359.  
  360.   void cXineOsd::DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants /* = 0 */)
  361.   {
  362.     cMutexLock osdLock(&m_osdMutex);
  363.     cOsd::DrawEllipse(x1, y1, x2, y2, Color, Quadrants);
  364.   }
  365.  
  366.   void cXineOsd::DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type)
  367.   {
  368.     cMutexLock osdLock(&m_osdMutex);
  369.     cOsd::DrawSlope(x1, y1, x2, y2, Color, Type);
  370.   }
  371.  
  372.   void cXineOsd::SetImagePath(u_int imageId, char const *path)
  373.   {
  374. #ifdef VDR_HAS_TRUECOLOR_OSD
  375.     cMutexLock osdLock(&m_osdMutex);
  376.     cOsd::SetImagePath(imageId, path);
  377. #endif
  378.   }
  379.  
  380.   void cXineOsd::Flush(void)
  381.   {
  382. //    ::fprintf(stderr, "Flush ---: %s\n", ::ctime(&(const time_t &)::time(0)));
  383.     cMutexLock osdLock(&m_osdMutex);
  384. //    ::fprintf(stderr, "Flush +++: %s\n", ::ctime(&(const time_t &)::time(0)));
  385. #if APIVERSNUM >= 10509
  386.     if (!Active())
  387.       return;
  388. #endif
  389. //    static int cnt = 0;
  390. //    fprintf(stderr, "cXineOsd::Flush() %d\n", cnt++);
  391.  
  392.     int maxOsdWidth, maxOsdHeight;
  393.     GetMaxOsdSize(maxOsdWidth, maxOsdHeight);
  394.  
  395. #ifdef SET_VIDEO_WINDOW
  396.    
  397.     m_xineLib.SetVideoWindow(maxOsdWidth, maxOsdHeight, vidWin);
  398.  
  399. #endif    
  400.    
  401.     int videoLeft   = -1;
  402.     int videoTop    = -1;
  403.     int videoWidth  = -1;
  404.     int videoHeight = -1;
  405.     int videoZoomX  = -1;
  406.     int videoZoomY  = -1;
  407.  
  408.     m_xineLib.execFuncVideoSize(videoLeft, videoTop, videoWidth, videoHeight, videoZoomX, videoZoomY);
  409.  
  410.     if (videoLeft  < 0) videoLeft  = 0;
  411.     if (videoTop   < 0) videoTop   = 0;
  412.     if (videoZoomX < 0) videoZoomX = 100;
  413.     if (videoZoomY < 0) videoZoomY = 100;
  414.  
  415.     if (vl != videoLeft
  416.         || vt != videoTop
  417.         || vw != videoWidth
  418.         || vh != videoHeight
  419.         || zx != videoZoomX
  420.         || zy != videoZoomY)
  421.     {
  422.       xfprintf(stderr, "frame: (%d, %d)-(%d, %d), zoom: (%.2lf, %.2lf)\n", videoLeft, videoTop, videoWidth, videoHeight, videoZoomX / 100.0, videoZoomY / 100.0);
  423. //      ::fprintf(stderr, "video: %d x %d, %d x %d @ %d %% x %d %%\n", videoLeft, videoTop, videoWidth, videoHeight, videoZoomX, videoZoomY);
  424.  
  425.       vl = videoLeft;
  426.       vt = videoTop;
  427.       vw = videoWidth;
  428.       vh = videoHeight;
  429.       zx = videoZoomX;
  430.       zy = videoZoomY;
  431.     }
  432.    
  433.     for (int i = 0; i < MAXNUMWINDOWS; i++)
  434.       m_xineLib.SendWindow(maxOsdWidth, maxOsdHeight, this, i, GetBitmap(i), videoLeft, videoTop, videoWidth, videoHeight, videoZoomX, videoZoomY);
  435.  
  436.     m_xineLib.execFuncOsdFlush();
  437.   }
  438.  
  439.   void cXineOsd::GetMaxOsdSize(int &maxOsdWidth, int &maxOsdHeight)
  440.   {
  441.     maxOsdWidth  = 0;
  442.     maxOsdHeight = 0;
  443.  
  444.     for (int i = 0; i < MAXNUMWINDOWS; i++)
  445.     {
  446.       cBitmap *const p = GetBitmap(i);
  447.       if (!p)
  448.         continue;
  449.  
  450.       int w = Left() + p->X0() + p->Width();
  451.       int h = Top()  + p->Y0() + p->Height();
  452.  
  453.       if (maxOsdWidth < w)
  454.         maxOsdWidth = w;
  455.  
  456.       if (maxOsdHeight < h)
  457.         maxOsdHeight = h;
  458.     }
  459. //fprintf(stderr, "GetMaxOsdSize(%d, %d)\n", maxOsdWidth, maxOsdHeight);
  460. #if APIVERSNUM >= 10707
  461.     if (maxOsdWidth <= m_xineDevice.Settings().OsdExtentParams().GetOsdExtentWidth()
  462.       && maxOsdHeight <= m_xineDevice.Settings().OsdExtentParams().GetOsdExtentHeight())
  463.     {
  464.       maxOsdWidth  = m_xineDevice.Settings().OsdExtentParams().GetOsdExtentWidth();
  465.       maxOsdHeight = m_xineDevice.Settings().OsdExtentParams().GetOsdExtentHeight();
  466.     }
  467.     else
  468. #endif
  469.     if (maxOsdWidth > 1920 || maxOsdHeight > 1080)
  470.     {
  471.       if (maxOsdWidth < 1920)
  472.         maxOsdWidth  = 1920;
  473.  
  474.       if (maxOsdHeight < 1080)
  475.         maxOsdHeight = 1080;
  476.     }
  477.     else if (maxOsdWidth > 1280 || maxOsdHeight > 720)
  478.     {
  479.       maxOsdWidth  = 1920;
  480.       maxOsdHeight = 1080;
  481.     }
  482.     else if (maxOsdWidth > 720 || maxOsdHeight > 576)
  483.     {
  484.       maxOsdWidth  = 1280;
  485.       maxOsdHeight = 720;
  486.     }
  487.     else
  488.     {
  489.       maxOsdWidth  = 720;
  490.       maxOsdHeight = 576;
  491.     }
  492.   }
  493.  
  494.   void cXineOsd::SetActive(bool On)
  495.   {
  496. #if APIVERSNUM >= 10509
  497.     cMutexLock osdLock(&m_osdMutex);
  498.    
  499.     if (On == Active())
  500.       return;
  501.  
  502.     cOsd::SetActive(On);
  503.  
  504.     if (!m_xineDevice.ChangeCurrentOsd(this, On))
  505.       return;
  506.  
  507.     if (On)
  508.       m_xineLib.ReshowCurrentOSD();
  509.     else
  510.       HideOsd();
  511. #endif    
  512.   }
  513.  
  514.  
  515.  
  516.   cXineOsdProvider::cXineOsdProvider(cXineDevice &xineDevice)
  517.     : cOsdProvider()
  518.     , m_xineDevice(xineDevice)
  519.   {
  520.   }
  521.  
  522. #if APIVERSNUM < 10509  
  523.   cOsd *cXineOsdProvider::CreateOsd(int Left, int Top)
  524.   {
  525.     return m_xineDevice.NewOsd(Left, Top);
  526.   }
  527. #else
  528.   cOsd *cXineOsdProvider::CreateOsd(int Left, int Top, uint Level)
  529.   {
  530.      if (Level == 10) { Left += (1920 - 720) / 2; Top += (1080 - 576); }
  531.  
  532.     return m_xineDevice.NewOsd(Left, Top, Level);
  533.   }
  534.  
  535.   cOsd *cXineOsdProvider::CreateTrueColorOsd(int Left, int Top, uint Level)
  536.   {
  537.     if (Level == 10) { Left += (1920 - 720) / 2; Top += (1080 - 576); }
  538.  
  539.     return m_xineDevice.NewOsd(Left, Top, Level, true);
  540.   }
  541. #endif
  542.  
  543. #endif
  544.  
  545.  
  546.  
  547. };