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

xdvshow-ieee1394.c File Reference

#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include <semaphore.h>
#include <libraw1394/raw1394.h>
#include <libraw1394/csr.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <err.h>
#include <dev/firewire/firewire.h>
#include "iec68113.h"
#include "xdvshow-shm.h"
#include "xdvshow-flags.h"
#include "xdvshow-ieee1394.h"
#include "xdvshow-const.h"
#include "xdvshow-defs.h"

Include dependency graph for xdvshow-ieee1394.c:

Include dependency graph

Go to the source code of this file.

Defines

#define RAW_BUF_SIZE   (10240)
#define PSIZE   512
#define DSIZE   480
#define NCHUNK   8
#define NPACKET_R   256
#define NPACKET_T   255
#define NPKT   50
#define NVEC   50
#define BLOCKSIZE   80
#define TNBUF   100 /* XXX too large value causes block noise */
#define NEMPTY   10 /* depends on TNBUF */
#define RBUFSIZE   (PSIZE * NPACKET_R)
#define MAXBLOCKS   (300)
#define CYCLE_FRAC   0xc00

Functions

raw1394handle_t open_1394_driver (int channel, iso_handler_t handler)
void close_1394_driver (int channel, raw1394handle_t handle)
 Internal function used for closing the device via libraw1394 linux library.

int raw_iso_handler (raw1394handle_t handle, int channel, size_t length, quadlet_t *data)
void * xdvshow_capture_raw (void *data)
 xdvshow_capture_raw is called as the DV stream capturing thread under FreeBSD.

int my_reset_handler (raw1394handle_t handle, unsigned int generation)

Variables

int g_card = 0
int g_channel = 63
int g_frame_count = 100000
volatile int g_alldone = 0
volatile int g_reader_active
unsigned char * g_frame
char * system_name [] = {"NTSC", "PAL"}
int frame_rate [] = {30, 25}


Define Documentation

#define BLOCKSIZE   80
 

Definition at line 69 of file xdvshow-ieee1394.c.

#define CYCLE_FRAC   0xc00
 

Definition at line 76 of file xdvshow-ieee1394.c.

#define DSIZE   480
 

Definition at line 61 of file xdvshow-ieee1394.c.

#define MAXBLOCKS   (300)
 

Definition at line 75 of file xdvshow-ieee1394.c.

#define NCHUNK   8
 

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

#define NEMPTY   10 /* depends on TNBUF */
 

Definition at line 72 of file xdvshow-ieee1394.c.

#define NPACKET_R   256
 

Definition at line 64 of file xdvshow-ieee1394.c.

#define NPACKET_T   255
 

Definition at line 65 of file xdvshow-ieee1394.c.

#define NPKT   50
 

Definition at line 67 of file xdvshow-ieee1394.c.

#define NVEC   50
 

Definition at line 68 of file xdvshow-ieee1394.c.

#define PSIZE   512
 

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

#define RAW_BUF_SIZE   (10240)
 

Definition at line 40 of file xdvshow-ieee1394.c.

Referenced by raw_iso_handler(), and xdvshow_capture_raw().

#define RBUFSIZE   (PSIZE * NPACKET_R)
 

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

#define TNBUF   100 /* XXX too large value causes block noise */
 

Definition at line 71 of file xdvshow-ieee1394.c.


Function Documentation

void close_1394_driver int  channel,
raw1394handle_t  handle
 

Internal function used for closing the device via libraw1394 linux library.

Definition at line 241 of file xdvshow-ieee1394.c.

Referenced by xdvshow_capture_raw().

00242 { 00243 raw1394_stop_iso_rcv(handle, channel); 00244 raw1394_destroy_handle(handle); 00245 }

int my_reset_handler raw1394handle_t  handle,
unsigned int  generation
 

Definition at line 190 of file xdvshow-ieee1394.c.

References g_reader_active.

Referenced by open_1394_driver().

00191 { 00192 static int i = 0; 00193 00194 printf("reset %d\n", i++); 00195 if (i == 100) 00196 g_reader_active = 0; 00197 return 0; 00198 }

raw1394handle_t open_1394_driver int  channel,
iso_handler_t  handler
 

Definition at line 201 of file xdvshow-ieee1394.c.

References g_card, g_channel, and my_reset_handler().

Referenced by xdvshow_capture_raw().

00202 { 00203 int numcards; 00204 struct raw1394_portinfo g_pinf[16]; 00205 raw1394handle_t handle; 00206 00207 if (!(handle = raw1394_new_handle())) { 00208 perror("raw1394 - couldn't get handle"); 00209 printf("This error usually means that the ieee1394 driver is not ready\n"); 00210 exit( -1); 00211 } 00212 00213 if ((numcards = raw1394_get_port_info(handle, g_pinf, 16)) < 0) { 00214 perror("raw1394 - couldn't get card info"); 00215 exit( -1); 00216 } 00217 00218 if (raw1394_set_port(handle, g_card) < 0) { 00219 perror("raw1394 - couldn't set port"); 00220 exit( -1); 00221 } 00222 raw1394_set_iso_handler(handle, g_channel, handler); 00223 /* raw1394_set_tag_handler(handle, my_tag_handler); */ 00224 raw1394_set_bus_reset_handler(handle, my_reset_handler); 00225 00226 /* Starting iso receive */ 00227 00228 if (raw1394_start_iso_rcv(handle, channel) < 0) { 00229 perror("raw1394 - couldn't start iso receive"); 00230 exit( -1); 00231 } 00232 printf("raw1394 - driver opened\n"); 00233 return handle; 00234 }

Here is the call graph for this function:

int raw_iso_handler raw1394handle_t  handle,
int  channel,
size_t  length,
quadlet_t *  data
 

Definition at line 83 of file xdvshow-ieee1394.c.

References g_frame, and RAW_BUF_SIZE.

Referenced by xdvshow_capture_raw().

00085 { 00086 if (length < RAW_BUF_SIZE) { 00087 *(int*)g_frame = length; 00088 memcpy(g_frame + 4, data, length); 00089 } 00090 return 0; 00091 }

void * xdvshow_capture_raw void *  data  ) 
 

xdvshow_capture_raw is called as the DV stream capturing thread under FreeBSD.

Definition at line 94 of file xdvshow-ieee1394.c.

References _xdvshow_alloc_shm(), _xdvshow_attach_shm(), _xdvshow_shm, __xdvshow_shm::audio_shm_frame, close_1394_driver(), shm_frame_buf::data, DPRINT, DVFRAME_DATA_READY, shm_frame::frame_buf, g_alldone, g_channel, g_frame, g_frame_count, shm_frame_buf::lock, shm_frame::next, open_1394_driver(), RAW_BUF_SIZE, raw_iso_handler(), __xdvshow_shm::shm_frame, ts_sem_wait, video_empty, and video_ready.

Referenced by main().

00095 { 00096 int frames_read; 00097 int length; 00098 raw1394handle_t handle; 00099 int found_first_frame; 00100 int skipped = 0; 00101 00102 int offset = 0; 00103 int ret; 00104 00105 u_char *dvdata; 00106 u_char *audio_dvdata; 00107 00108 #ifdef DEBUG 00109 int sem_value = 0; 00110 int iDebugSemVal; 00111 #endif /* DEBUG */ 00112 00113 ret = _xdvshow_alloc_shm(); 00114 if (ret < 0) { 00115 return((void *)1); 00116 } 00117 00118 ret = _xdvshow_attach_shm(); 00119 00120 dvdata = _xdvshow_shm.shm_frame->frame_buf->data; 00121 audio_dvdata = _xdvshow_shm.audio_shm_frame->frame_buf->data; 00122 00123 g_frame = (unsigned char*)malloc(RAW_BUF_SIZE); 00124 00125 handle = open_1394_driver(g_channel, raw_iso_handler); 00126 00127 frames_read = 0; 00128 found_first_frame = 0; 00129 00130 printf("raw1394 - start capture\n"); 00131 while (!g_alldone) { 00132 raw1394_loop_iterate(handle); 00133 length = *(int*)g_frame; 00134 if (length >= 492) { 00135 if (!found_first_frame) { 00136 if (g_frame[16] == 0x1f && g_frame[17] == 0x07) 00137 found_first_frame = 1; 00138 else skipped++; 00139 } 00140 if (skipped > 500) { 00141 printf("skipped too many without finding frame\n"); 00142 break; 00143 } 00144 if (found_first_frame) { 00145 if (g_frame[16] == 0x1f && g_frame[17] == 0x07) 00146 frames_read++; 00147 if (frames_read > g_frame_count) 00148 break; 00149 if (offset < 144000){ 00150 memcpy(&dvdata[offset], (g_frame + 16), 480); 00151 offset += 480; 00152 } 00153 if (offset == 144000){ 00154 offset = 0; 00155 00156 _xdvshow_shm.shm_frame->frame_buf->lock = DVFRAME_DATA_READY; 00157 00158 #ifdef DEBUG 00159 DPRINT("RECEIVED frame no. %d\n", sem_value++); 00160 if(sem_getvalue(&video_ready, &iDebugSemVal)) { 00161 perror("Unable to get value of video_ready semaphore!"); 00162 exit(EXIT_FAILURE); 00163 } 00164 DPRINT("semaphore video_ready value: %d\n", iDebugSemVal); 00165 00166 if(sem_getvalue(&video_empty, &iDebugSemVal)) { 00167 perror("Unable to get value of video_empty semaphore!"); 00168 exit(EXIT_FAILURE); 00169 } 00170 DPRINT("semaphore video_empty value: %d\n", iDebugSemVal); 00171 #endif /* DEBUG */ 00172 00173 if (sem_post(&video_ready) < 0) 00174 perror("sem_post"); 00175 ts_sem_wait(&video_empty); 00176 00177 _xdvshow_shm.shm_frame = _xdvshow_shm.shm_frame->next; 00178 dvdata = _xdvshow_shm.shm_frame->frame_buf->data; 00179 } 00180 } 00181 } 00182 } 00183 close_1394_driver(g_channel, handle); 00184 free(g_frame); 00185 00186 return 0; 00187 }

Here is the call graph for this function:


Variable Documentation

int frame_rate[] = {30, 25}
 

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

volatile int g_alldone = 0
 

Definition at line 45 of file xdvshow-ieee1394.c.

Referenced by xdvshow_capture_raw().

int g_card = 0
 

Definition at line 42 of file xdvshow-ieee1394.c.

Referenced by open_1394_driver().

int g_channel = 63
 

Definition at line 43 of file xdvshow-ieee1394.c.

Referenced by open_1394_driver(), and xdvshow_capture_raw().

unsigned char* g_frame
 

Definition at line 48 of file xdvshow-ieee1394.c.

Referenced by raw_iso_handler(), and xdvshow_capture_raw().

int g_frame_count = 100000
 

Definition at line 44 of file xdvshow-ieee1394.c.

Referenced by xdvshow_capture_raw().

volatile int g_reader_active
 

Definition at line 46 of file xdvshow-ieee1394.c.

Referenced by my_reset_handler().

char* system_name[] = {"NTSC", "PAL"}
 

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


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