Beispiel #1
0
/*****************************************************************************
 * Demux:
 *****************************************************************************/
static block_t *GrabVideo( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    block_t     *p_block = NULL;
    int result = 0;

    if( p_sys->dma_capture )
    {
        result = dc1394_dma_single_capture( &p_sys->camera );
        if( result != DC1394_SUCCESS )
        {
            msg_Err( p_demux, "unable to capture a frame" );
            return NULL;
        }
    }
    else
    {
        result = dc1394_single_capture( p_sys->camera_info.handle,
                                        &p_sys->camera );
        if( result != DC1394_SUCCESS )
        {
            msg_Err( p_demux, "unable to capture a frame" );
            return NULL;
        }
    }

    p_block = block_New( p_demux, p_sys->camera.frame_width *
                                  p_sys->camera.frame_height * 2 );
    if( !p_block )
    {
        msg_Err( p_demux, "cannot get block" );
        return NULL;
    }

    if( !p_sys->camera.capture_buffer )
    {
        msg_Err (p_demux, "caputer buffer empty");
        block_Release( p_block );
        return NULL;
    }

    memcpy( p_block->p_buffer, (const char *)p_sys->camera.capture_buffer,
            p_sys->camera.frame_width * p_sys->camera.frame_height * 2 );

    p_block->i_pts = p_block->i_dts = mdate();
    if( p_sys->dma_capture )
        dc1394_dma_done_with_buffer( &p_sys->camera );
    return p_block;
}
unsigned char* linuxfwCamera::getFrame()  {

	if (handle==NULL) return NULL;
	
	if (use_dma) {
		if (dc1394_dma_single_capture(&camera)!=DC1394_SUCCESS) 
		{
			fprintf( stderr, "unable to capture a frame\n");
			dc1394_dma_release_camera(handle,&camera);
			dc1394_destroy_handle(handle);
			return NULL;
		} dc1394_dma_done_with_buffer(&camera);
	} else {
		if (dc1394_single_capture(handle,&camera)!=DC1394_SUCCESS) 
		{
			fprintf( stderr, "unable to capture a frame\n");
			dc1394_dma_release_camera(handle,&camera);
			dc1394_destroy_handle(handle);
			return NULL;
		}
	}
	
	switch (colour) {
		case false: {
			if (image_mode_==MODE_640x480_YUV411) {
				unsigned char *src = (unsigned char*)camera.capture_buffer;
				unsigned char *dest = buffer;
				for(int y=0;y<height;y++) {
					for(int x=0;x<width/4;++x) {
						src++;
						*dest++ = *src++;
						*dest++ = *src++;
						src++;
						*dest++ = *src++;
						*dest++ = *src++;
					}
				}
			} else {
				if (buffer!=NULL)
					memcpy(buffer,(unsigned char*)camera.capture_buffer,width*height*bytes);
			}
			break;
		}
		case true: {
			if (image_mode_==MODE_640x480_YUV411) {
				int R,G,B;
				int Y[4];
				int U,V;
				
				unsigned char *src = (unsigned char*)camera.capture_buffer;
				unsigned char *dest = buffer;
				for(int y=0;y<height;y++) {
					for(int x=0;x<width/4;++x) {
						U    = *src++;
						Y[0] = *src++;
						Y[1] = *src++;
						V    = *src++;
						Y[2] = *src++;
						Y[3] = *src++;
	
						// U and V are +-0.5
						U -= 128;
						V -= 128;
						
						// conversion
						for (int i=0;i<4;i++) {
							R = (int)(Y[i] + 1.370705f * V); 			//R
							G = (int)(Y[i] - 0.698001f * V - 0.337633f * U);	//G
							B = (int)(Y[i] + 1.732446f * U); 			//B
							
							if (R < 0) R=0;
							if (G < 0) G=0;
							if (B < 0) B=0;
							if (R > 255) R=255;
							if (G > 255) G=255;
							if (B > 255) B=255;
		
							*dest++ = B;
							*dest++ = G;
							*dest++ = R;
						}
					}
				}			
			} else {
				if (buffer!=NULL)
					memcpy(buffer,(unsigned char*)camera.capture_buffer,width*height*bytes);
			}
			break;
		}
		
	}
	
	return buffer;
}