Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

xdvshow-shm.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <assert.h>
#include <time.h>
#include <sys/shm.h>
#include <errno.h>
#include <pthread.h>
#include "xdvshow-const.h"
#include "xdvshow-shm.h"
#include "xdvshow-flags.h"
#include "xdvshow-defs.h"

Include dependency graph for xdvshow-shm.c:

Include dependency graph

Go to the source code of this file.

Functions

int xdvshow_semaphore_init ()
 xdvshow_semaphore_init() initializes video_ready, video_empty, audio_ready, and audio_empty semaphores.

void xdvshow_close_shm ()
 xdvshow_close_shm() detaches shared memory _xdvshow_shm.shm_buf.

int xdvshow_read_unlock ()
 xdvshow_read_unlock() decrements (unlocks) video_empty semaphore

int xdvshow_read_audio_unlock ()
 xdvshow_read_audio_unlock() decrements (unlocks) audio_empty semaphore

int xdvshow_read_shm (u_char **dvframe)
 returns the video data of the DV frame.

int xdvshow_read_audio_shm (u_char **audioframe)
 returns the audio data of the DV frame.

int _xdvshow_alloc_shm ()
 allocates a shared memory segment for video frame buffers list.

int _xdvshow_attach_shm ()
 allocates the video and audio buffers within the frame buffers list.


Variables

u_int32_t flags
u_int32_t dv_format_type
__xdvshow_shm _xdvshow_shm
sem_t video_ready
sem_t video_empty
sem_t audio_ready
sem_t audio_empty


Function Documentation

int _xdvshow_alloc_shm  ) 
 

allocates a shared memory segment for video frame buffers list.

Private function.

Returns:
1 on success (XXX), -1 on failure

Definition at line 216 of file xdvshow-shm.c.

References _xdvshow_shm, __xdvshow_shm::framebufs, SHM_FRAME_BUF_NUM, and __xdvshow_shm::shmid.

Referenced by xdvshow_capture_raw(), xdvshow_prepare_file(), and xdvshow_prepare_rtp().

00217 { 00218 int shmid; 00219 00220 shmid = shmget(IPC_PRIVATE, 00221 SHM_FRAME_BUF_NUM*sizeof(struct shm_frame_buf)*2, /* audio and video */ 00222 0600); 00223 if (shmid < 0) { 00224 perror("shmget"); 00225 return(-1); 00226 } 00227 00228 _xdvshow_shm.shmid = shmid; 00229 _xdvshow_shm.framebufs = SHM_FRAME_BUF_NUM; 00230 00231 return(1); 00232 }

int _xdvshow_attach_shm  ) 
 

allocates the video and audio buffers within the frame buffers list.

Private function. The number of buffers depends on SHM_FRAME_BUF_NUM.

Returns:
1 on success (XXX), -1 on failure

Definition at line 243 of file xdvshow-shm.c.

References _xdvshow_shm, __xdvshow_shm::audio_shm_frame, DVFRAME_READY, __xdvshow_shm::framebufs, shm_frame::next, __xdvshow_shm::read_frame, __xdvshow_shm::shm_buf, __xdvshow_shm::shm_frame, and __xdvshow_shm::shmid.

Referenced by xdvshow_capture_raw(), xdvshow_prepare_file(), and xdvshow_prepare_rtp().

00244 { 00245 u_long *shm_buf; 00246 00247 int i; 00248 struct shm_frame *shm_frame = NULL; 00249 struct shm_frame *shm_frame_last = NULL; 00250 00251 if ((shm_buf = shmat(_xdvshow_shm.shmid, 0, 0)) == (void *)-1) { 00252 perror("shmat"); 00253 return(-1); 00254 } 00255 00256 _xdvshow_shm.shm_buf = shm_buf; 00257 00258 for (i=0; i<_xdvshow_shm.framebufs; i++) { 00259 shm_frame = (struct shm_frame *)malloc(sizeof(struct shm_frame)); 00260 memset(shm_frame, 0, sizeof(struct shm_frame)); 00261 00262 shm_frame->frame_buf = (struct shm_frame_buf *)(shm_buf + (i * sizeof(struct shm_frame_buf))/4); 00263 shm_frame->frame_buf->lock = DVFRAME_READY; 00264 00265 if (shm_frame_last == NULL) { 00266 _xdvshow_shm.shm_frame = shm_frame; 00267 } 00268 else { 00269 shm_frame_last->next = shm_frame; 00270 } 00271 shm_frame_last = shm_frame; 00272 } 00273 shm_frame->next = _xdvshow_shm.shm_frame; 00274 _xdvshow_shm.read_frame = _xdvshow_shm.shm_frame; 00275 00276 shm_frame = NULL; 00277 shm_frame_last = NULL; 00278 for (i=0; i<_xdvshow_shm.framebufs; i++) { 00279 shm_frame = (struct shm_frame *)malloc(sizeof(struct shm_frame)); 00280 memset(shm_frame, 0, sizeof(struct shm_frame)); 00281 00282 shm_frame->frame_buf = (struct shm_frame_buf *)(shm_buf + ((_xdvshow_shm.framebufs + i) * sizeof(struct shm_frame_buf))/4); 00283 shm_frame->frame_buf->lock = DVFRAME_READY; 00284 00285 if (shm_frame_last == NULL) { 00286 _xdvshow_shm.audio_shm_frame = shm_frame; 00287 } 00288 else { 00289 shm_frame_last->next = shm_frame; 00290 } 00291 shm_frame_last = shm_frame; 00292 } 00293 shm_frame->next = _xdvshow_shm.audio_shm_frame; 00294 00295 return(1); 00296 }

void xdvshow_close_shm  ) 
 

xdvshow_close_shm() detaches shared memory _xdvshow_shm.shm_buf.

Definition at line 98 of file xdvshow-shm.c.

References _xdvshow_shm, and __xdvshow_shm::shm_buf.

Referenced by main().

00099 { 00100 if(shmdt(_xdvshow_shm.shm_buf)) { 00101 perror("detaching shared memory _xdvshow_shm.shm_buf"); 00102 assert(0); 00103 } 00104 }

int xdvshow_read_audio_shm u_char **  audioframe  ) 
 

returns the audio data of the DV frame.

Waits for the audio_ready semaphore and then points the audioframe pointer to the audio data in the shared memory segment.

Parameters:
**audioframe (unsigned char) is the curently processedaudio buffer.
Returns:
1 after finishing without any problems.

Definition at line 185 of file xdvshow-shm.c.

References _xdvshow_shm, audio_ready, __xdvshow_shm::audio_shm_frame, audioframe, shm_frame_buf::data, DPRINT, DVFRAME_COPYING, shm_frame::frame_buf, shm_frame_buf::lock, __xdvshow_shm::locked_audio_shm_framebuf, shm_frame::next, and ts_sem_wait.

Referenced by main().

00186 { 00187 #ifdef DEBUG 00188 int iDebugSemVal; 00189 if(sem_getvalue(&audio_ready, &iDebugSemVal)) { 00190 perror("Unable to get value of audio_ready semaphore!"); 00191 exit(EXIT_FAILURE); 00192 } 00193 DPRINT("semaphore audio_ready value: %d\n", iDebugSemVal); 00194 #endif /* DEBUG */ 00195 00196 ts_sem_wait(&audio_ready); 00197 00198 _xdvshow_shm.audio_shm_frame->next->frame_buf->lock = DVFRAME_COPYING; 00199 00200 *audioframe = _xdvshow_shm.audio_shm_frame->frame_buf->data; 00201 _xdvshow_shm.locked_audio_shm_framebuf = _xdvshow_shm.audio_shm_frame->frame_buf; 00202 00203 _xdvshow_shm.audio_shm_frame = _xdvshow_shm.audio_shm_frame->next; 00204 00205 return(1); 00206 }

int xdvshow_read_audio_unlock  ) 
 

xdvshow_read_audio_unlock() decrements (unlocks) audio_empty semaphore

Returns:
always 1

Definition at line 129 of file xdvshow-shm.c.

References _xdvshow_shm, audio_empty, DVFRAME_READY, shm_frame_buf::lock, and __xdvshow_shm::locked_audio_shm_framebuf.

Referenced by main().

00130 { 00131 _xdvshow_shm.locked_audio_shm_framebuf->lock = DVFRAME_READY; 00132 00133 if (sem_post(&audio_empty) < 0) { 00134 perror("audio_empty sem_post"); 00135 assert(0); 00136 } 00137 00138 return(1); 00139 }

int xdvshow_read_shm u_char **  dvframe  ) 
 

returns the video data of the DV frame.

Waits for the video_ready semaphore and then points the dvframe pointer to the DV video buffer in the shared memory segment.

Parameters:
**dvframe (unsigned char) is the curently processed frame buffer.
Returns:
1 after finishing without any problems.

Definition at line 151 of file xdvshow-shm.c.

References _xdvshow_shm, shm_frame_buf::data, DPRINT, DVFRAME_COPYING, shm_frame::frame_buf, shm_frame_buf::lock, __xdvshow_shm::locked_shm_framebuf, shm_frame::next, __xdvshow_shm::read_frame, ts_sem_wait, and video_ready.

Referenced by main().

00152 { 00153 #ifdef DEBUG 00154 int iDebugSemVal; 00155 if(sem_getvalue(&video_ready, &iDebugSemVal)) { 00156 perror("Unable to get value of video_ready semaphore!"); 00157 exit(EXIT_FAILURE); 00158 } 00159 DPRINT("semaphore video_ready value: %d\n", iDebugSemVal); 00160 #endif /* DEBUG */ 00161 00162 ts_sem_wait(&video_ready); 00163 00164 00165 _xdvshow_shm.read_frame->frame_buf->lock = DVFRAME_COPYING; 00166 00167 *dvframe = _xdvshow_shm.read_frame->frame_buf->data; 00168 _xdvshow_shm.locked_shm_framebuf = _xdvshow_shm.read_frame->frame_buf; 00169 00170 _xdvshow_shm.read_frame = _xdvshow_shm.read_frame->next; 00171 00172 return(1); 00173 }

int xdvshow_read_unlock  ) 
 

xdvshow_read_unlock() decrements (unlocks) video_empty semaphore

Returns:
always 1

Definition at line 111 of file xdvshow-shm.c.

References _xdvshow_shm, DVFRAME_READY, shm_frame_buf::lock, __xdvshow_shm::locked_shm_framebuf, and video_empty.

Referenced by main().

00112 { 00113 _xdvshow_shm.locked_shm_framebuf->lock = DVFRAME_READY; 00114 00115 if (sem_post(&video_empty) < 0) { 00116 perror("video_empty sem_post"); 00117 assert(0); 00118 } 00119 00120 return(1); 00121 }

int xdvshow_semaphore_init  ) 
 

xdvshow_semaphore_init() initializes video_ready, video_empty, audio_ready, and audio_empty semaphores.

xdvshow_semaphore_init() initializes video_ready, video_empty, audio_ready, and audio_empty semaphores. *_ready semaphores are initialized to 0. *_empty semaphores are initialized to _xdvshow_shm.framebufs value.

Returns:
0 on success, -1 on failure

Definition at line 74 of file xdvshow-shm.c.

References _xdvshow_shm, audio_empty, audio_ready, flags_use_audio, __xdvshow_shm::framebufs, video_empty, and video_ready.

Referenced by main().

00075 { 00076 if ((sem_init(&video_ready, 0, 0) != 0) || 00077 (sem_init(&video_empty, 0, _xdvshow_shm.framebufs) != 0)) { 00078 00079 perror("sem_init"); 00080 return (-1); 00081 } 00082 00083 if (flags_use_audio) { 00084 if ((sem_init(&audio_ready, 0 , 0) != 0) || 00085 (sem_init(&audio_empty, 0, _xdvshow_shm.framebufs) != 0)) { 00086 00087 perror("audio sem_init"); 00088 return (-1); 00089 } 00090 } 00091 00092 return(0); 00093 }


Variable Documentation

struct __xdvshow_shm _xdvshow_shm
 

Definition at line 60 of file xdvshow-shm.c.

Referenced by _multicast_join(), _xdvshow_alloc_shm(), _xdvshow_attach_shm(), _xdvshow_prepare_socket(), _xdvshow_read_file(), _xdvshow_recv_dvrtp(), sigint_signal(), xdvshow_capture_raw(), xdvshow_close_shm(), xdvshow_prepare_rtp(), xdvshow_read_audio_shm(), xdvshow_read_audio_unlock(), xdvshow_read_shm(), xdvshow_read_unlock(), xdvshow_SDL_handle_events(), and xdvshow_semaphore_init().

sem_t audio_empty
 

Definition at line 63 of file xdvshow-shm.c.

Referenced by _xdvshow_read_file(), _xdvshow_recv_dvrtp(), xdvshow_read_audio_unlock(), and xdvshow_semaphore_init().

sem_t audio_ready
 

Definition at line 63 of file xdvshow-shm.c.

Referenced by _xdvshow_read_file(), _xdvshow_recv_dvrtp(), xdvshow_read_audio_shm(), and xdvshow_semaphore_init().

u_int32_t dv_format_type
 

Definition at line 58 of file xdvshow-shm.c.

u_int32_t flags
 

Definition at line 57 of file xdvshow-shm.c.

sem_t video_empty
 

Definition at line 62 of file xdvshow-shm.c.

Referenced by _xdvshow_read_file(), _xdvshow_recv_dvrtp(), xdvshow_capture_raw(), xdvshow_read_unlock(), and xdvshow_semaphore_init().

sem_t video_ready
 

Definition at line 62 of file xdvshow-shm.c.

Referenced by _xdvshow_read_file(), _xdvshow_recv_dvrtp(), xdvshow_capture_raw(), xdvshow_read_shm(), and xdvshow_semaphore_init().


Generated on Wed Nov 3 19:19:02 2004 for xdvshow by doxygen 1.3.7