gml_Bitmap_shared.h

00001 /*
00002  * gml_Bitmap_shared.h --
00003  *
00004  *    Manage a shared-memory ring of bitmaps.
00005  *
00006  *  Copyright (c) 2004 CLIPS-IMAG
00007  *
00008  *  See the file "gml_LicenseTerms.txt" for information on usage and redistribution
00009  *  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  *
00011  *  Created on December 13, 2004 (JL).
00012  */
00013 #ifndef __GML_BITMAP_SHARED__
00014 #define __GML_BITMAP_SHARED__
00015 
00016 #include "gml/base/gml_GlobalMutex.h"
00017 #include "gml/image/gml_Bitmap.h"
00018 #include "gml/image/gml_Bitmap_base.h"
00019 
00020 class gml_TSDRegistrator;
00021 
00022 #define GML_BITMAP_SHARED_SD_REGTYPE    "_grabber._tcp"
00023 #define GML_BITMAP_SHARED_SD_NAME_KEY   "segment-name"
00024 
00025 
00026 /// gml_TSharedBitmapInfos --
00027 ///
00028 
00029 class gml_TSharedBitmapInfos
00030 {
00031 public:
00032 
00033   UInt32      fMutexKey;
00034   UInt32      fFrameCount;
00035   UInt32      fLatestFrameOffset;
00036   gml_TBitmap fFrameInfo;
00037   
00038 };
00039 
00040 
00041 /// gml_TSharedBitmapRing --
00042 ///
00043 /// @todo separate publication from sharing subsystems
00044 
00045 class gml_TSharedBitmapRing
00046 {
00047 public:
00048   ///
00049   /// Init --
00050   ///
00051   ///   Setup the ring, allocate all bitmaps, create shared memory segments.
00052   ///
00053   gml_TError Init (
00054       UInt32              width,                            ///< see gml_BitmapInit
00055       UInt32              height,                           ///< see gml_BitmapInit
00056       gml_TPixelEncoding  encoding,                         ///< see gml_BitmapInit
00057       int                 offset = GML_BITMAP_PADDING_AUTO, ///< see gml_BitmapInit
00058       char*               name   = NULL,                    ///< name to be published, or NULL
00059       UInt8               count  = 5                        ///< number of bitmaps in the ring
00060   );
00061   
00062   ///
00063   /// Dispose --
00064   ///
00065   ///   Release all resources, including locks and shared memory files.
00066   ///
00067   void Dispose ();
00068   
00069   ///
00070   /// NextBitmap --
00071   ///
00072   ///   Return in <bitmap> the next available buffer.
00073   ///   Its buffer MUST NOT be freed by the caller.
00074   ///
00075   ///   If <index> is not <NULL>, set it to the ring index of the returned 
00076   ///   bitmap.
00077   ///
00078   gml_TError NextBitmap (gml_TBitmap* bitmap, UInt8* index = (UInt8*)NULL);
00079   
00080   ///
00081   /// Release --
00082   ///
00083   ///   Signal that the buffer acquired by <NextBitmap> is ready.
00084   ///   Should be called once for each call to <NextBitmap>.
00085   ///
00086   void Release ();
00087   
00088   ///
00089   /// SegmentName --
00090   ///
00091   UInt32 SegmentName () { return fSegmentName; }
00092   
00093   
00094 private:
00095 
00096   UInt8                   fRingSize;
00097   UInt8                   fCurrentBitmap;
00098   UInt32                  fLastFrameCount;
00099   gml_TGlobalMutex        fMutex;
00100   gml_TSharedBitmapInfos* fSharedMemory;
00101   gml_TSDRegistrator*     fRegistrator;
00102   UInt32                  fBitmapSize;
00103   UInt32                  fSegmentName;
00104   UInt32                  fSegmentSize;
00105   
00106 };
00107 
00108 #endif /* __GML_BITMAP_SHARED__ */
00109 
Generated on Tue Jun 12 14:03:27 2007 for gml by Doxygen 1.5.2.