Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

vsdl.h

Go to the documentation of this file.
00001 /*
00002  * vsdl.h
00003  *
00004  * Classes to support video output via SDL
00005  *
00006  * Copyright (c) 1999-2000 Equivalence Pty. Ltd.
00007  *
00008  * The contents of this file are subject to the Mozilla Public License
00009  * Version 1.0 (the "License"); you may not use this file except in
00010  * compliance with the License. You may obtain a copy of the License at
00011  * http://www.mozilla.org/MPL/
00012  *
00013  * Software distributed under the License is distributed on an "AS IS"
00014  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00015  * the License for the specific language governing rights and limitations
00016  * under the License.
00017  *
00018  * The Original Code is Open H323 Library.
00019  *
00020  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00021  *
00022  * Contributor(s): Derek J Smithies (derek@indranet.co.nz)
00023  *
00024  * $Log: vsdl.h,v $
00025  * Revision 1.7  2004/05/31 01:26:58  dereksmithies
00026  * Fix the "no newline at end of file" warning.
00027  *
00028  * Revision 1.6  2004/05/27 04:47:05  csoutheren
00029  * Added include guard to file
00030  *
00031  * Revision 1.5  2003/12/12 05:11:56  rogerhardiman
00032  * Add SDL support on FreeBSD. Header files live in SDL11 directory
00033  *
00034  * Revision 1.4  2003/05/17 03:20:48  rjongbloed
00035  * Removed need to do strange things with main() function.
00036  *
00037  * Revision 1.3  2003/04/28 14:29:45  craigs
00038  * Started rearranging code
00039  *
00040  * Revision 1.2  2003/04/28 08:44:42  craigs
00041  * Fixed problem with include on linux
00042  *
00043  * Revision 1.1  2003/04/28 07:04:20  craigs
00044  * Initial version from ohphone
00045  *
00046  * Revision 1.8  2003/03/21 00:47:47  dereks
00047  * Remove surplus PTRACE statements.
00048  *
00049  * Revision 1.7  2003/03/20 23:50:41  dereks
00050  * Fixups resulting from the new PVideoOutputDevice class code.
00051  *
00052  * Revision 1.6  2002/12/03 21:45:05  dereks
00053  * Fixes from Walter Whitlock to cure warnings about u_chars. Thanks!
00054  *
00055  * Revision 1.5  2002/06/27 02:17:40  robertj
00056  * Renamed video format 411 to the correct 420P, thanks Mark Cooke
00057  *
00058  * Revision 1.4  2002/04/29 03:51:55  dereks
00059  * Documentation tidy up. Thanks to Walter Whitlock.
00060  *
00061  * Revision 1.3  2002/04/26 03:33:32  dereks
00062  * Major upgrade. All calls to SDL library are now done by one thread.
00063  *
00064  * Revision 1.2  2001/05/25 01:14:44  dereks
00065  * Alter SetFrameSize & OpenWindo to use unsigned variables. Change type of
00066  * other variables to eliminate compiler warnings.
00067  *
00068  * Revision 1.1  2001/03/07 01:47:45  dereks
00069  * Initial release of SDL (Simple DirectMedia Layer, a cross-platform multimedia library),
00070  * a video library code.
00071  *
00072  *
00073  */
00074 
00075 #ifndef _PVSDL
00076 #define _PVSDL
00077 
00078 #if P_SDL
00079 
00080 #include <ptlib.h>
00081 #if defined(P_FREEBSD)
00082 #include <SDL11/SDL.h>
00083 #else
00084 #include <SDL/SDL.h>
00085 #endif
00086 
00087 #undef main
00088 
00089 class PSDLVideoFrame : public PObject
00090 {
00091     PCLASSINFO(PSDLVideoFrame, PObject);
00092   public:
00093     PSDLVideoFrame(
00094       unsigned newWidth,
00095       unsigned newHeight,
00096       Uint8 *data
00097     );
00098     PSDLVideoFrame(
00099       unsigned newWidth,
00100       unsigned newHeight,
00101       const void *_data
00102     );
00103   
00104     ~PSDLVideoFrame();
00105   
00106     unsigned GetWidth() { return width; }
00107     unsigned GetHeight() { return height; }
00108   
00109     Uint8 *GetDataPointer() { return data; }
00110   
00111     void PrintOn(ostream & str) const;
00112   
00113   protected:
00114     void Initialise(unsigned newWidth, unsigned newHeight, Uint8 *_data);
00115   
00116     unsigned width;
00117     unsigned height;
00118   
00119     Uint8 *data;
00120 };
00121 
00122 
00123 class PSDLDisplayThread : public PThread
00124 {
00125     PCLASSINFO(PSDLDisplayThread, PThread);
00126   public:
00127     PSDLDisplayThread(
00128       BOOL _videoPIP
00129     );
00130     ~PSDLDisplayThread();
00131   
00132     void Main();
00133   
00136     BOOL AddFrame(PSDLVideoFrame *newFrame, BOOL isEncoding);
00137   
00138     BOOL IsOpen();
00139   
00140     virtual void Terminate();
00141     void RequestOpenWindow(BOOL isEncoding);
00142     void RequestCloseWindow(BOOL isEncoding);
00143   
00144   protected:
00145     BOOL ScreenIsOpen();
00146     BOOL DisplayIsShutDown();
00147     void CloseWindow(BOOL isEncoding);
00148   
00149     PSDLVideoFrame *GetNextFrame(BOOL isEncoding);
00150   
00151     BOOL ResizeScreen(unsigned newWidth, unsigned newHeight);
00152     void InitDisplayPosn();
00153     void InitDisplayPosn(unsigned w, unsigned h);
00154     void CloseScreen();
00155     BOOL CreateOverlay(BOOL isEncoding);
00156     BOOL SetOverlaySize (BOOL isEncoding, unsigned _width, unsigned _height);
00157   
00158     void WriteOutDisplay();
00159   
00160     unsigned GetDisplayIndex(BOOL isEncoding);
00161   
00164     BOOL SetFrameSize(BOOL isEncoding, unsigned _width, unsigned _height);
00165   
00168     void ProcessSDLEvents(void);
00169   
00170     BOOL Redraw(BOOL isEncoding, PSDLVideoFrame *frame);
00171   
00172     enum { RemoteIndex = 0 };
00173     enum { EncodeIndex = 1 };
00174   
00175     const char * GetDirName(BOOL isEncoding) 
00176       { return (isEncoding ? "local" : "remote"); }
00177   
00178     PMutex     mutex;  
00179     PSyncPoint commandSync;
00180     BOOL       threadRunning;
00181   
00182     SDL_Surface  *screen;
00183     SDL_Overlay  *overlay[2];
00184     SDL_Rect      displayPosn[2];
00185   
00186     unsigned   width[2];
00187     unsigned   height[2];
00188     unsigned   oldScreenWidth, oldScreenHeight;
00189   
00190     PString  remoteName;
00191     BOOL   displayIsShutDown;
00192     BOOL   videoPIP;
00193   
00194     BOOL  closeEncWindow;
00195     BOOL  closeRecWindow;
00196   
00197     PSDLVideoFrame *nextEncFrame;
00198     PSDLVideoFrame *nextRcvFrame;
00199 };
00200 
00201 
00204 class PSDLVideoDevice : public PVideoOutputDevice
00205 {
00206     PCLASSINFO(PSDLVideoDevice, PVideoOutputDevice);
00207   
00208   public:
00211     PSDLVideoDevice(
00212       const PString & _remoteName,
00213       BOOL _isEncoding, 
00214       PSDLDisplayThread *_sdlThread
00215     );
00216   
00219     ~PSDLVideoDevice();
00220   
00223     virtual BOOL Open(
00224       const PString & /*deviceName*/,   
00225       BOOL /*startImmediate*/ = TRUE    
00226       ) { return TRUE; }
00227   
00230     BOOL Close();
00231   
00234     BOOL IsOpen();
00235   
00236     unsigned GetFrameWidth() const { return width; }
00237   
00238     unsigned GetFrameHeight() const { return height; }
00239   
00243     BOOL Redraw (const void *frame);
00244   
00247     virtual PStringList GetDeviceNames() const;
00248   
00254     virtual PINDEX GetMaxFrameBytes()
00255       { return 352 * 288 * 3 * 2; }
00256   
00259     BOOL SetFrameSize (unsigned _width ,unsigned _height);
00260   
00261     virtual PString GetRemoteName() const
00262       { return remoteName ; }
00263   
00266     virtual void SetRemoteName(
00267       const PString & _remoteName
00268     ) { remoteName = _remoteName; }
00269   
00272     void ForceDepth(int /*d*/) { }
00273   
00274   
00275     BOOL SetFrameData(
00276       unsigned x,
00277       unsigned y,
00278       unsigned width,
00279       unsigned height,
00280       const BYTE * data,
00281       BOOL endFrame = TRUE
00282     ) ;
00283   
00286     BOOL EndFrame();
00287   
00288   private:
00289     BOOL     isEncoding;
00290     PString  remoteName;
00291     PSDLDisplayThread *sdlThread;
00292     unsigned     width, height;
00293 };
00294 
00295 #endif    // P_SDL
00296 
00297 #endif
00298 

Generated on Wed Sep 28 10:27:34 2005 for PWLib by  doxygen 1.4.4