X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fdevice1394input.C;h=88aae8a638372323a3785c2f88219a0239bc8a43;hb=7fa4ccc2c91d37f20f3618261e4cbaa9d5d3c740;hp=2fa7c6f0badd73bec5c08aa098b27d61c34213db;hpb=3ec3a9cc6afc6561311686b3ec597ee3c1d80d6f;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/cinelerra/device1394input.C b/cinelerra-5.1/cinelerra/device1394input.C index 2fa7c6f0..88aae8a6 100644 --- a/cinelerra-5.1/cinelerra/device1394input.C +++ b/cinelerra-5.1/cinelerra/device1394input.C @@ -19,6 +19,8 @@ * */ +#ifdef HAVE_FIREWIRE + #include "condition.h" #include "device1394input.h" #include "ieee1394-ioctl.h" @@ -124,59 +126,53 @@ int Device1394Input::open(const char *path, // Initialize grabbing - if(fd < 0) - { - if((fd = ::open(path, O_RDWR)) < 0) - { - printf("Device1394Input::open %s: %s\n", path, strerror(errno)); - } - else - { + if(fd < 0 && (fd = ::open(path, O_RDWR)) < 0) { + printf("Device1394Input::open %s: %s\n", path, strerror(errno)); + result = 1; + } + if( !result ) { #define CIP_N_NTSC 68000000 #define CIP_D_NTSC 1068000000 - #define CIP_N_PAL 1 #define CIP_D_PAL 16 - - struct dv1394_init init = - { - api_version: DV1394_API_VERSION, - channel: (unsigned int)channel, - n_frames: (unsigned int)length, - format: is_pal ? DV1394_PAL: DV1394_NTSC, - cip_n: 0, - cip_d: 0, - syt_offset: 0 - }; - if(ioctl(fd, DV1394_IOC_INIT, &init) < 0) - { - printf("Device1394Input::open DV1394_IOC_INIT: %s\n", strerror(errno)); - } - - input_buffer = (unsigned char*)mmap(0, - length * buffer_size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fd, - 0); - - if(ioctl(fd, DV1394_IOC_START_RECEIVE, 0) < 0) - { - perror("Device1394Input::open DV1394_START_RECEIVE"); - } + struct dv1394_init init = { + api_version: DV1394_API_VERSION, + channel: (unsigned int)channel, + n_frames: (unsigned int)length, + format: is_pal ? DV1394_PAL: DV1394_NTSC, + cip_n: 0, + cip_d: 0, + syt_offset: 0 + }; + if(ioctl(fd, DV1394_IOC_INIT, &init) < 0) { + printf("Device1394Input::open DV1394_IOC_INIT: %s\n", strerror(errno)); + result = 1; } + } + if( !result ) { + input_buffer = (unsigned char*)mmap(0, length * buffer_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if( input_buffer == MAP_FAILED ) { + perror("Device1394Input::open mmap"); + input_buffer = 0; + result = 1; + } + } + if( !result ) { + if(ioctl(fd, DV1394_IOC_START_RECEIVE, 0) < 0) { + perror("Device1394Input::open DV1394_START_RECEIVE"); + result = 1; + } + } - - + if( !result ) { buffer = new char*[total_buffers]; buffer_valid = new int[total_buffers]; bzero(buffer_valid, sizeof(int) * total_buffers); - for(int i = 0; i < total_buffers; i++) - { + for(int i = 0; i < total_buffers; i++) { buffer[i] = new char[DV_PAL_SIZE]; } - audio_buffer = new char[INPUT_SAMPLES * 2 * channels]; audio_lock = new Condition(0, "Device1394Input::audio_lock"); video_lock = new Condition(0, "Device1394Input::video_lock"); @@ -193,24 +189,28 @@ void Device1394Input::run() { while(!done) { + int ret = 0; // Wait for frame to arrive struct dv1394_status status; printf("Device1394Input::run %d done=%d\n", __LINE__, done); Thread::enable_cancel(); - if(ioctl(fd, DV1394_IOC_WAIT_FRAMES, 1)) - { + if(ioctl(fd, DV1394_IOC_WAIT_FRAMES, 1)) { perror("Device1394Input::run DV1394_IOC_WAIT_FRAMES"); - sleep(1); + ret = 1; } - else - if(ioctl(fd, DV1394_IOC_GET_STATUS, &status)) - { + else if(ioctl(fd, DV1394_IOC_GET_STATUS, &status)) { perror("Device1394Input::run DV1394_IOC_GET_STATUS"); + ret = 1; + } + else if( !input_buffer ) { + fprintf(stderr, "Device1394Input::run !input_buffer"); + ret = 1; } + if( ret ) + sleep(1); Thread::disable_cancel(); - - + if( ret ) continue; buffer_lock->lock("Device1394Input::run 1"); @@ -370,7 +370,4 @@ int Device1394Input::read_audio(char *data, int samples) return result; } - - - - +#endif