Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r599 - in branches/itanium2: Core Core/Shm Engine/Control Engine/Display StandAlone
- Date: Thu, 6 Oct 2005 04:01:03 -0600 (MDT)
Author: abe
Date: Thu Oct 6 04:01:02 2005
New Revision: 599
Added:
branches/itanium2/Core/Shm/
branches/itanium2/Core/Shm/MFStreamData.cc
branches/itanium2/Core/Shm/MFStreamData.h
branches/itanium2/Core/Shm/ShmSemaphore.cc
branches/itanium2/Core/Shm/ShmSemaphore.h
Modified:
branches/itanium2/Core/CMakeLists.txt
branches/itanium2/Engine/Control/RTRT_register.cc
branches/itanium2/Engine/Display/CMakeLists.txt
branches/itanium2/Engine/Display/SHMImageDisplay.cc
branches/itanium2/Engine/Display/SHMImageDisplay.h
branches/itanium2/StandAlone/manta_path_plot.pl
Log:
Added a shm semaphore and stream data format classes.
Implementation of the SHM interface is complete, now I just have to get it to
work.
A Core/Shm
A Core/Shm/ShmSemaphore.cc
A Core/Shm/ShmSemaphore.h
A Core/Shm/MFStreamData.cc
A Core/Shm/MFStreamData.h
M Core/CMakeLists.txt
M StandAlone/manta_path_plot.pl
M Engine/Control/RTRT_register.cc
M Engine/Display/SHMImageDisplay.cc
M Engine/Display/SHMImageDisplay.h
M Engine/Display/CMakeLists.txt
Modified: branches/itanium2/Core/CMakeLists.txt
==============================================================================
--- branches/itanium2/Core/CMakeLists.txt (original)
+++ branches/itanium2/Core/CMakeLists.txt Thu Oct 6 04:01:02 2005
@@ -35,6 +35,16 @@
Geometry/AffineTransform.cc
)
+
+IF(SGI_LINUX)
+ SET (CORE_SOURCES ${CORE_SOURCES}
+ Shm/ShmSemaphore.h
+ Shm/ShmSemaphore.cc
+ Shm/MFStreamData.h
+ Shm/MFStreamData.cc
+ )
+ENDIF(SGI_LINUX)
+
ADD_LIBRARY (Manta_Core ${CORE_SOURCES})
TARGET_LINK_LIBRARIES(Manta_Core SCIRun_Core)
Added: branches/itanium2/Core/Shm/MFStreamData.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Core/Shm/MFStreamData.cc Thu Oct 6 04:01:02 2005
@@ -0,0 +1,162 @@
+#ifdef __ia64__
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <Core/Shm/MFStreamData.h>
+
+#include <SCIRun/Core/Exceptions/ErrnoException.h>
+#include <SCIRun/Core/Thread/Time.h>
+#include <SCIRun/Core/Math/MinMax.h>
+
+#include <Image/SimpleImage.h>
+#include <Image/Pixel.h>
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <time.h>
+
+#include <errno.h>
+
+using namespace Manta;
+using namespace SCIRun;
+
+void *MFStreamData::operator new( size_t bytes, int key_, int flag ) {
+
+ int id;
+
+ // Lookup the shm key.
+ if ((id = shmget( key_, sizeof(MFStreamData), 0 /*PERM_FILE*/ )) == -1) {
+
+ // Check to see if we should create a new segment.
+ if ((errno == ENOENT) && (flag == STRM_SHM_CREATE)) {
+
+ // Try to create again.
+ if ((id = shmget( key_, sizeof(MFStreamData), IPC_CREAT/*|PERM_FILE*/
)) == -1) {
+ throw new ErrnoException( "Cannot create shm: ", errno, __FILE__,
__LINE__ );
+ }
+ }
+ else {
+ throw new ErrnoException( "Cannot get shm, key invalid: ", errno,
__FILE__, __LINE__ );
+ }
+ }
+
+ // Attach pointer to the memory.
+ void *this_ptr;
+
+ if ((int)(this_ptr = shmat( id, 0, 0 )) == -1) {
+ throw new ErrnoException( "Cannot attach pointer to shm: ", errno,
__FILE__, __LINE__ );
+ }
+
+ // Cast the pointer and set the shmID and key fields.
+ MFStreamData *stream_data = (MFStreamData *)this_ptr;
+ stream_data->shmID = id;
+ stream_data->key = key_;
+
+ // Check to see if we should increment the reference count.
+ if (flag == STRM_SHM_ATTACH) {
+ stream_data->refCount++;
+ }
+
+ return this_ptr;
+}
+
+MFStreamData::MFStreamData( int xres_, int yres_ ) :
+ xres( xres_ ),
+ yres( yres_ ),
+ zres( 4 ),
+ semaphore( key, LOCK_OPEN )
+{
+}
+
+MFStreamData::~MFStreamData() {
+
+ int id = shmID;
+
+ // Detach shm
+ if (shmdt( this ) == -1) {
+ throw new ErrnoException("Could not detach shm", errno, __FILE__,
__LINE__);
+ }
+
+ // Remove shm
+ if (shmctl( id, IPC_RMID, 0 ) == -1) {
+ throw new ErrnoException("Could not detach shm", errno, __FILE__,
__LINE__);
+ }
+}
+
+void MFStreamData::swap_buffers() {
+
+ // Wait for the memory to be open for writting and then lock it.
+ int val = semaphore.get_value();
+ while (val != LOCK_OPEN) {
+ SCIRun::Time::waitFor( 0.0001 );
+ val = semaphore.get_value();
+ }
+
+ // Decrement the semaphore to 0.
+ semaphore.try_wait();
+
+ // Switch the back and front buffers.
+ backBuffer = !backBuffer;
+ frontBuffer = !frontBuffer;
+
+ // Increment the semaphore to 1, unlock the shm.
+ semaphore.post();
+}
+
+void MFStreamData::draw_pixels( const Image *image ) {
+
+ bool stereo;
+ int image_xres, image_yres;
+
+ // Determine image resolution.
+ image->getResolution( stereo, image_xres, image_yres );
+
+ int copy_xres = SCIRun::Min( image_xres, TEXTURE_X_RES );
+ int copy_yres = SCIRun::Min( image_yres, TEXTURE_Y_RES );
+ int total = copy_xres * copy_yres;
+
+ RGBA8Pixel *dest = (RGBA8Pixel *)pixelPool[backBuffer];
+
+ // Copy the pixels from the image on to the back buffer.
+ if (typeid(*image) == typeid(SimpleImage<RGBA8Pixel>)) {
+
+ RGBA8Pixel *src = ((SimpleImage<RGBA8Pixel> *)image)->getRaw( 0 );
+
+ // Naive copy
+ for (int i=0;i<total;++i) {
+ dest[i] = src[i];
+ }
+ }
+
+ // If we don't have an RGBA8 Pixel frame buffer do nothing.
+}
+
+
+#endif
Added: branches/itanium2/Core/Shm/MFStreamData.h
==============================================================================
--- (empty file)
+++ branches/itanium2/Core/Shm/MFStreamData.h Thu Oct 6 04:01:02 2005
@@ -0,0 +1,116 @@
+
+#ifdef __ia64__
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#include <sys/types.h>
+
+#define STRM_SHM_CREATE 0x1
+#define STRM_SHM_ATTACH 0x0
+
+#include <Core/Shm/ShmSemaphore.h>
+#include <Interface/Image.h>
+
+namespace Manta {
+
+ class MFStreamData {
+ public:
+
+
/////////////////////////////////////////////////////////////////////////////
+
+ enum { TEXTURE_X_RES = 2560, // Maximum image size.
+ TEXTURE_Y_RES = 2048,
+ TEXTURE_Z_RES = 4,
+ MAX_NUM_UPDATES = 16,
+ MAX_NUM_SSCMD = 16, // Specific stream commands.
+
+ LOCK_WRITING = 0,
+ LOCK_OPEN = 1,
+ LOCK_READING = 2
+ };
+
+
/////////////////////////////////////////////////////////////////////////////
+
+ long heartbeat;
+ long counter;
+
+ int shmID;
+
+ int key;
+ ShmSemaphore semaphore;
+
+ int refCount;
+ int exitFlag;
+
+ int pixelFlipHorz;
+ int pixelFlipVert;
+
+ int pID;
+
+ int lock;
+
+ int xres, yres, zres;
+
+ unsigned char pixelPool[2][TEXTURE_X_RES*TEXTURE_Y_RES*TEXTURE_Z_RES];
+
+ int frontBuffer;
+ int backBuffer;
+
+ int numRects;
+ int rectDef[MAX_NUM_UPDATES][5];
+
+ int ssCMD [MAX_NUM_SSCMD];
+ int ssDATA[MAX_NUM_SSCMD];
+ int numSSCMD;
+
+
/////////////////////////////////////////////////////////////////////////////
+
+ // Allocates a new Media Fusion Stream Data struct using the specified
shm key.
+ void *operator new( size_t bytes, int key_, int flag );
+
+ // Constructor specific actual image size.
+ MFStreamData( int xres_, int yres_ );
+ ~MFStreamData();
+
+ // Swap buffers method.
+ void swap_buffers();
+ void draw_pixels( const Image *image );
+
+ private:
+ // Inaccessible operators.
+ MFStreamData( const MFStreamData & );
+ MFStreamData &operator= ( const MFStreamData & );
+ void *operator new( size_t bytes );
+ };
+
+};
+#endif
+
+
+
Added: branches/itanium2/Core/Shm/ShmSemaphore.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Core/Shm/ShmSemaphore.cc Thu Oct 6 04:01:02 2005
@@ -0,0 +1,113 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifdef __ia64__
+
+#include <Core/Shm/ShmSemaphore.h>
+
+#include <SCIRun/Core/Exceptions/ErrnoException.h>
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#include <errno.h>
+
+using namespace Manta;
+using namespace SCIRun;
+
+ShmSemaphore::ShmSemaphore( int key_, int init_val_ ) {
+
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short *array;
+ }
+ arg;
+
+ // Create the semaphore.
+ id = semget( key_, 1, /*PERM_FILE|*/IPC_CREAT );
+ if (id == -1) {
+ throw new ErrnoException( "Cannot create shm semaphore ", errno,
__FILE__, __LINE__ );
+ }
+
+ // Set the semaphore value.
+ arg.val = init_val_;
+ if (semctl( id, 0, SETVAL, arg ) == -1) {
+ throw new ErrnoException( "Cannot set shm semaphore value ", errno,
__FILE__, __LINE__ );
+ }
+}
+
+ShmSemaphore::~ShmSemaphore() {
+
+ // Destroy the semaphore.
+ if (semctl( id, 0, IPC_RMID ) == -1) {
+ throw new ErrnoException( "Cannot destroy shm semaphore ", errno,
__FILE__, __LINE__ );
+ }
+}
+
+
+void ShmSemaphore::post() {
+
+ struct sembuf sbuf = { 0, 1, 0 };
+
+ if (semop( id, &sbuf, 1 ) == -1) {
+ throw new ErrnoException( "Cannot post shm semaphore ", errno, __FILE__,
__LINE__ );
+ }
+}
+
+void ShmSemaphore::wait() {
+
+ struct sembuf sbuf = { 0, -1, 0 };
+
+ if (semop( id, &sbuf, 1 ) == -1) {
+ throw new ErrnoException( "Cannot wait on shm semaphore ", errno,
__FILE__, __LINE__ );
+ }
+}
+
+bool ShmSemaphore::try_wait() {
+
+ struct sembuf sbuf = { 0, -1, IPC_NOWAIT };
+
+ if (semop( id, &sbuf, 1 ) == -1) {
+ if (errno != EAGAIN)
+ throw new ErrnoException( "Cannot post shm semaphore ", errno,
__FILE__, __LINE__ );
+ else
+ return false;
+ }
+ return true;
+}
+
+int ShmSemaphore::get_value() {
+
+ return semctl( id, 0, GETVAL, 0 );
+}
+
+
+#endif
Added: branches/itanium2/Core/Shm/ShmSemaphore.h
==============================================================================
--- (empty file)
+++ branches/itanium2/Core/Shm/ShmSemaphore.h Thu Oct 6 04:01:02 2005
@@ -0,0 +1,61 @@
+
+#ifdef __ia64__
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef _SHMSEMAPHORE__H_
+#define _SHMSEMAPHORE__H_
+
+namespace Manta {
+
+
/////////////////////////////////////////////////////////////////////////////
+ // This class implements a SysV SHM semaphore.
+ // Abe Stephens -- October 2005
+
/////////////////////////////////////////////////////////////////////////////
+ class ShmSemaphore {
+ private:
+ int id;
+
+ public:
+ ShmSemaphore( int key_, int init_val_ );
+ ~ShmSemaphore();
+
+ void post();
+ void wait();
+ bool try_wait();
+ int get_value();
+
+ };
+
+};
+
+#endif
+
+#endif
+
Modified: branches/itanium2/Engine/Control/RTRT_register.cc
==============================================================================
--- branches/itanium2/Engine/Control/RTRT_register.cc (original)
+++ branches/itanium2/Engine/Control/RTRT_register.cc Thu Oct 6 04:01:02
2005
@@ -2,6 +2,7 @@
#include <Engine/Display/NullDisplay.h>
#include <Engine/Display/OpenGLDisplay.h>
#include <Engine/Display/FileDisplay.h>
+#include <Engine/Display/SHMImageDisplay.h>
#include <Engine/IdleModes/ZoomIdleMode.h>
#include <Engine/ImageTraversers/NullImageTraverser.h>
#include <Engine/ImageTraversers/TiledImageTraverser.h>
@@ -52,6 +53,7 @@
rtrt->registerComponent("null", &NullDisplay::create);
rtrt->registerComponent("opengl", &OpenGLDisplay::create);
rtrt->registerComponent("file", &FileDisplay::create);
+ rtrt->registerComponent("mf", &SHMImageDisplay::create);
// Register image traversers
rtrt->registerComponent("null", &NullImageTraverser::create);
Modified: branches/itanium2/Engine/Display/CMakeLists.txt
==============================================================================
--- branches/itanium2/Engine/Display/CMakeLists.txt (original)
+++ branches/itanium2/Engine/Display/CMakeLists.txt Thu Oct 6 04:01:02
2005
@@ -12,5 +12,11 @@
Display/GLXImageDisplay.cc
# Display/GLXMultipipeImageDisplay.h
# Display/GLXMultipipeImageDisplay.cc
+)
- )
+IF(SGI_LINUX)
+ SET(Manta_Display_SRCS ${Manta_Display_SRCS}
+ Display/SHMImageDisplay.h
+ Display/SHMImageDisplay.cc
+ )
+ENDIF(SGI_LINUX)
Modified: branches/itanium2/Engine/Display/SHMImageDisplay.cc
==============================================================================
--- branches/itanium2/Engine/Display/SHMImageDisplay.cc (original)
+++ branches/itanium2/Engine/Display/SHMImageDisplay.cc Thu Oct 6 04:01:02
2005
@@ -35,98 +35,40 @@
#include <Image/Pixel.h>
#include <Interface/Image.h>
#include <Interface/Context.h>
+#include <Core/Util/Args.h>
+
+#include <Core/Exceptions/IllegalArgument.h>
#include <iostream>
using namespace Manta;
-// Includes for shm methods.
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/sem.h>
-#include <unistd.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <termios.h>
-#include <pthread.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// SHM Structure.
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-struct SHM_STREAM_DATA {
- longheartbeat;
- long counter;
-
- int shmID;
-
- int key;
- int semID;
-
- int refCount;
- int exitFlag;
-
- int pixelFlipHorz;
- int pixelFlipVert;
-
- int pID;
-
- int lock;
-
- int xres, yres, zres;
-
- unsigned char *pixelPool[2];
-
- int frontBuffer;
- int backBuffer;
-
- int numRects;
- int rectDef[MAX_NUM_UPDATES][5];
-
- intssCMD [MAX_NUM_SSCMD];
- intssDATA[MAX_NUM_SSCMD];
- intnumSSCMD;
-
-};
-
-// SHM Library functions.
-int shmCreate( int key, SHM_STREAM_DATA ** _strmSHM, int createFlag );
-int shmDestroy( SHM_STREAM_DATA ** _strmSHM );
-int semCreate( int key, int *semID, int initVal );
-int semDestroy( int semID );
-int semPost( int semID );
-int semWait( int semID );
-int semTryWait( int semID );
-int semGetValue( int semID );
-void strmSwapBuffers( SHM_STREAM_DATA * strmSHM );
-
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP
SETUP
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-SHMImageDisplay::SHMImageDisplay( const vector<string> &args ) {
+SHMImageDisplay::SHMImageDisplay( const vector<string> &args ) :
+ stream_data( 0 ),
+ shm_key( 0 )
+{
-
+ // Parse args.
+ for (int i=0;i<args.size();++i) {
+ if (args[i] == "-key") {
+ if (!getArg(i,args,shm_key)) {
+ throw new IllegalArgument("-key <n>", i, args );
+ }
+ }
+ }
}
-GLXImageDisplay::~GLXImageDisplay() {
+SHMImageDisplay::~SHMImageDisplay() {
+
+ // Delete the shared mem if allocated.
+ if (stream_data) {
+ delete stream_data;
+ }
}
// Manta ImageDisplay interface.
@@ -137,21 +79,12 @@
return;
// Determine the resolution.
+ bool stereo;
+ int xres, yres;
+ context.getResolution( stereo, xres, yres );
- // Allocate a SHM Stream structure.
-
- // Initialize shared memory segment
- if( !shmCreate( key, &strmSHM, true ) ) {
- printf( "Cannot create shm for stream\n" );
- exit( 1 );
- }
-
- // Initialize semaphore
- if( !semCreate( key, &strmSHM->semID, LOCK_OPEN ) ) {
- printf( "Cannot create semaphore for shm\n" );
- exit( 1 );
- }
-
+ // Acquire shm segment.
+ stream_data = new( shm_key, true ) MFStreamData( xres, yres );
}
@@ -164,308 +97,15 @@
// Check to see if this processor should display the image.
if (context.proc == 0) {
-
- // Determine the image resolution.
- int xres, yres;
- bool stereo;
-
- image->getResolution( stereo, xres, yres );
-
-
- // ...
- }
-
-}
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// SHM FUNCTIONS SHM FUNCTIONS SHM FUNCTIONS SHM FUNCTIONS SHM FUNCTIONS
S
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-int shmCreate( int key, SHM_STREAM_DATA ** _strmSHM, int createFlag )
-{
- int shm_id;
-
- /*--- ICD SHARED MEMORY CREATION ---*/
-
- printf("\n***********************************************************\n" );
- printf("* \n" );
- printf("* Initializing Shared Memory Area \n" );
- printf("* \n" );
- fflush( stdout );
-
- printf( "* Shared Memory area size: %i\n", sizeof( SHM_STREAM_DATA ) );
-
- /* get shared memory now */
- shm_id = shmget( key, sizeof( SHM_STREAM_DATA ), PERM_FILE );
-
- /* we have an error try to debug */
- if( shm_id == -1 )
- {
- /* print error */
- if( errno == ENOENT )
- {
- /* test is creation flag is set (only used by modules for opening
new segments */
- if( createFlag == STRM_SHM_CREATE )
- {
- printf( "* INFO: SHM memory for stream has not been
initialized - initializing now \n" );
-
- /* couldn't get the shared memory so create instead */
- shm_id = shmget( key, sizeof( SHM_STREAM_DATA ),
IPC_CREAT|PERM_FILE );
-
- if( shm_id == -1 )
- {
- /* print error */
- printf( " Error code %i\n", errno );
- printf( "*\n" );
- printf( "* Possible Error Codes:\n" );
- printf( "* Error code EINVAL = %i\n", EINVAL );
- printf( "* Error code EEXIST = %i\n", EEXIST );
- printf( "* Error code EIDRM = %i\n", EIDRM );
- printf( "* Error code ENOSPC = %i\n", ENOSPC );
- printf( "* Error code ENOENT = %i\n", ENOENT );
- printf( "* Error code EACCES = %i\n", EACCES );
- printf( "* Error code ENOMEM = %i\n", ENOMEM );
-
- /* couldn't create shm so die badly */
- printf("couldn't create shm so die badly\n");
- return( FALSE );
- }
-
- } else {
-
- printf( "* INFO: SHM memory for stream has not been
initialized - Stream key is invalid \n" );
- printf("* \n" );
-
printf("***********************************************************\n\n" );
- return( FALSE );
-
- }
-
- } else {
-
- printf( "* Actual Error code %i\n", errno );
- printf( "*\n" );
- printf( "* Possible Error Codes:\n" );
- printf( "* Error code EINVAL = %i\n", EINVAL );
- printf( "* Error code EEXIST = %i\n", EEXIST );
- printf( "* Error code EIDRM = %i\n", EIDRM );
- printf( "* Error code ENOSPC = %i\n", ENOSPC );
- printf( "* Error code ENOENT = %i\n", ENOENT );
- printf( "* Error code EACCES = %i\n", EACCES );
- printf( "* Error code ENOMEM = %i\n", ENOMEM );
- }
-
-
- }
-
- /* attach pointer to shm memory */
- *_strmSHM = shmat( shm_id, 0, 0 );
-
- if( (int)*_strmSHM == -1 )
- {
- /* couldn't attach pointer to shm space */
- printf("couldn't attach pointer to shm space \n");
- exit( 1 );
- }
-
- printf("* Shared Memory ID = %i Address = %X Size of %i\n",
- shm_id, (int) *_strmSHM, sizeof( SHM_STREAM_DATA ) );
- printf("* \n" );
- printf("***********************************************************\n\n" );
-
- /* set shm_id internally in shm's structure */
- (*_strmSHM)->shmID = shm_id;
-
-
- /* if createFlag is FALSE this means this is a view trying to attach to
the stream module
- therfore we should increment the reference count */
- if( createFlag == STRM_SHM_ATTACH )
- {
- (*_strmSHM)->refCount++;
- } else {
- /* just viewing strmSHM (used by the stream_manager) don't increment
refCount */ ;
- }
-
-
- return( TRUE );
-
-}
-
-int shmDestroy( SHM_STREAM_DATA ** _strmSHM )
-{
- int shmID;
-
- shmID = (*_strmSHM)->shmID;
-
- /* detach shm */
- shmdt( *_strmSHM );
- printf( "Detatched SHM\n" );
+ // Copy the image to shared memory.
+ stream_data->draw_pixels( image );
- /* remove shm */
- shmctl( shmID, IPC_RMID, NULL );
- printf( "Deleted SHM\n" );
-
- return( TRUE );
-
-}
-
-void strmSwapBuffers( SHM_STREAM_DATA * strmSHM )
-{
- int semVAL;
-
- /* WAIT FOR OTHER APPS THAT MAY BE READING SHM TO FINISHED AND UNLOCK IT */
-
- /* wait for memory to be open for writing, then attempt to lock it */
- semVAL = semGetValue( strmSHM->semID );
- while( semVAL != LOCK_OPEN )
- {
- nano_sleep( 100000 );
- semVAL = semGetValue( strmSHM->semID );
- //printf("waiting to strmSwapBuffers #%i \n", semVAL-1 );
fflush(stdout);
- }
-
- /* decrement semaphore to 0 -> LOCK_WRITING */
- semTryWait( strmSHM->semID );
-
-
- /* do the swap..... */
- if( strmSHM->backBuffer == 0 )
- {
- strmSHM->backBuffer = 1;
- strmSHM->frontBuffer = 0;
- } else {
- strmSHM->backBuffer = 0;
- strmSHM->frontBuffer = 1;
- }
-
- /* UNLOCK THE SHM FOR OTHER APPS TO READ FROM IT */
-
- /* writing is finished open memory up for reading */
- /* increment semaphore to 1 -> LOCK_OPEN */
- semPost( strmSHM->semID );
-
-
-}
-
-int semCreate( int key, int *semID, int initVal )
-{
- int val;
- union semun {
- int val;
- struct semid_ds *buf;
- unsigned short *array;
- } arg;
-
- *semID = semget( key, 1, PERM_FILE|IPC_CREAT );
- if( *semID == -1 )
- {
- printf( "Couldn't get semaphore reason %i\n", errno );
- return FALSE;
- } else {
- printf( "semaphore ID %d\n", (unsigned int)*semID );
- }
-
- arg.val = initVal;
- val = semctl( *semID, 0, SETVAL, arg );
-
- if( val == -1 )
- {
- printf( "Couldn't set semaphore val to 1 error#:%i\n", errno );
- return FALSE;
- } else {
- printf( "semaphore val |%i|\n", arg.val );
- }
-
- return TRUE;
-
-}
-
-int semDestroy( int semID )
-{
- if( semctl( semID, 0, IPC_RMID ) == -1 )
- {
- printf( "Couldn't remove semaphore reason %i\n", errno );
- return FALSE;
-
- } else {
-
- printf( "semaphore ID %d removed \n", (unsigned int)semID );
- return TRUE;
- }
-}
-
-int semPost( int semID )
-{
- int val;
- struct sembuf sbuf;
-
- sbuf.sem_num = 0;
- sbuf.sem_op = 1;
- sbuf.sem_flg = 0;
-
- val = semop( semID, &sbuf, 1 );
- if( val == -1 )
- {
- printf( "Couldn't perform Post operation on semaphore error#:%i\n",
errno );
- return FALSE;
- }
-
- return TRUE;
-
-}
-
-int semWait( int semID )
-{
- int val;
- struct sembuf sbuf;
-
- sbuf.sem_num = 0;
- sbuf.sem_op = -1;
- sbuf.sem_flg = 0;
-
- val = semop( semID, &sbuf, 1 );
- if( val == -1 )
- {
- printf( "Couldn't perform Wait operation on semaphore error#:%i\n",
errno );
- return FALSE;
- }
-
- return TRUE;
-
-}
-
-int semTryWait( int semID )
-{
- int val;
- struct sembuf sbuf;
-
- sbuf.sem_num = 0;
- sbuf.sem_op = -1;
- sbuf.sem_flg = IPC_NOWAIT;
-
- val = semop( semID, &sbuf, 1 );
- if( val == -1 )
- {
- if( errno != EAGAIN ) /* EAGAIN is a note to say that the semaphore is
already at zero... */
- {
- printf( "\nCouldn't perform TryWait operation on semaphore
error#:%i\n", errno );
- return FALSE;
- }
- }
-
- return TRUE;
-
-}
-
-int semGetValue( int semID )
-{
- int value = -1;
- value = semctl( semID, 0, GETVAL, NULL );
- return( value );
+ // Swap the shm buffer.
+ stream_data->swap_buffers();
+ }
+
}
-
-
Modified: branches/itanium2/Engine/Display/SHMImageDisplay.h
==============================================================================
--- branches/itanium2/Engine/Display/SHMImageDisplay.h (original)
+++ branches/itanium2/Engine/Display/SHMImageDisplay.h Thu Oct 6 04:01:02
2005
@@ -35,6 +35,10 @@
#define Manta_Engine_SHMImageDisplay_h
#include <Interface/ImageDisplay.h>
+#include <Core/Shm/MFStreamData.h>
+
+#include <vector>
+#include <string>
namespace Manta {
@@ -42,14 +46,17 @@
class DisplayContext;
class Image;
+ using std::vector;
+ using std::string;
+
// Abe Stephens -- abe@sgi.com
// Nigel Jenkins -- njenkins@sgi.com
// Tom Fuke -- tom@sgi.com
class SHMImageDisplay : public ImageDisplay {
private:
-
- int manta_channel; // The last channel number to call
setupDisplayChannel.
+ MFStreamData *stream_data;
+ int shm_key;
public:
// Note that the GLXImage display must be passed a GLX context by the
Modified: branches/itanium2/StandAlone/manta_path_plot.pl
==============================================================================
--- branches/itanium2/StandAlone/manta_path_plot.pl (original)
+++ branches/itanium2/StandAlone/manta_path_plot.pl Thu Oct 6 04:01:02
2005
@@ -175,8 +175,8 @@
print HTML "<img src=\"$png_file\" /><br><pre>\n";
print HTML "Min fps: $min_fps\n";
print HTML "Max fps: $max_fps\n";
- print HTML "Mean fps: " . (($min_fps+$max_fps)/2) . "\n";
- print HTML "Avg fps: " . ($total_fps / $total_samples) . "</pre>\n";
+ print HTML "Median fps: " . (($min_fps+$max_fps)/2) . "\n";
+ print HTML "Mean fps: " . ($total_fps / $total_samples) . "</pre>\n";
print HTML "<hr width=100%><p>\n";
push(@out_array,$out_file);
- [MANTA] r599 - in branches/itanium2: Core Core/Shm Engine/Control Engine/Display StandAlone, abe, 10/06/2005
Archive powered by MHonArc 2.6.16.