コード例 #1
0
static int rawdv_check_file(demuxer_t *demuxer)
{
   unsigned char tmp_buffer[DV_PAL_FRAME_SIZE];
   int bytes_read=0;
   int result=0;
   dv_decoder_t *td;

   mp_msg(MSGT_DEMUX,MSGL_V,"Checking for DV\n");

   bytes_read=stream_read(demuxer->stream,tmp_buffer,DV_PAL_FRAME_SIZE);
   if ((bytes_read!=DV_PAL_FRAME_SIZE) && (bytes_read!=DV_NTSC_FRAME_SIZE))
      return 0;

   td=dv_decoder_new(TRUE,TRUE,FALSE);
   if (!td)
      return 0;

   td->quality=DV_QUALITY_BEST;
   result=dv_parse_header(td, tmp_buffer);
   if (result<0)
      return 0;

   if ((( td->num_dif_seqs==10) || (td->num_dif_seqs==12))
       && (td->width==720)
       && ((td->height==576) || (td->height==480)))
      result=1;
   dv_decoder_free(td);
   if (result)
      return DEMUXER_TYPE_RAWDV;
   else
      return 0;
}
コード例 #2
0
ファイル: libdv.c プロジェクト: Cuchulain/cinelerra
int dv_delete(dv_t *dv)
{
	int i;
	if(dv->decoder)
	{
		dv_decoder_free( dv->decoder );
	}

	if(dv->temp_video)
		free(dv->temp_video);

	if(dv->temp_audio[0])
	{
		for(i = 0; i < 4; i++)
			free(dv->temp_audio[i]);
	}

	if(dv->encoder)
	{
		dv_encoder_free( dv->encoder );
	}

	free(dv);
	return 0;
}
コード例 #3
0
ファイル: pdp_ieee1394l.c プロジェクト: Angeldude/pd
static void pdp_ieee1394_free(t_pdp_ieee1394 *x)
{
  //pdp_ieee1394_close(x);
  if(x->x_haveVideo)stopTransfer(x);
  //if(x->decodedbuf)delete[]decodedbuf;
  if(x->x_decoder!=NULL)dv_decoder_free(x->x_decoder);
}
コード例 #4
0
lp_libdv_in::~lp_libdv_in()
{
	int i;
	if(pv_decoder != 0){
		dv_decoder_free(pv_decoder);
	}
	if(pv_file_buffer != 0){
		free(pv_file_buffer);
	}
	for(i=0; i<4; i++){
		if(pv_dv_audio_buffers[i] != 0){
			free(pv_dv_audio_buffers[i]);
		}
	}
	if(pv_audio_ready_buffer != 0){
		delete[] pv_audio_ready_buffer;
	}
/*	if(pv_pixels[0] != 0){
		free(pv_pixels);
	}
*/
	if(pv_sdl_out != 0){
		delete pv_sdl_out;
	}
}
コード例 #5
0
ファイル: pdp_ieee1394l.c プロジェクト: Angeldude/pd
static int
startTransfer (t_pdp_ieee1394 *x)
{
  //if ((x->dvfd=openDevice(format))<0){
  //  verbose(1, "DV4L: closed");
  //  return(0);
  //}
  //x->x_image.newimage=0;
  //x->x_image.image.data=0;
  //x->x_image.image.xsize=720;
  //x->x_image.image.ysize=576;
  //x->x_image.image.setCsizeByFormat(x->x_reqFormat);
  //x->x_image.image.reallocate();
  x->videobuf=NULL;

  x->x_frame_ready = false; 

  if(x->x_decoder!=NULL)dv_decoder_free(x->x_decoder);
  if (!(x->x_decoder=dv_decoder_new(1, 1, 1))){
    //error("DV4L: unable to create DV-decoder...closing");
    close_device(x);
    return(0);
  }
  //x->x_decoder->quality=x->x_quality;
  x->x_decoder->quality = DV_QUALITY_BEST;
  verbose(1, "DV4L: DV decoding quality %d ", x->x_decoder->quality);
  //fprintf(stderr,"before");
  x->x_continue_thread = true;
  pthread_create(&x->x_thread_id, 0, pdp_ieee1394_thread, x);
  return 1;
}
コード例 #6
0
ファイル: dvframe.cpp プロジェクト: 6301158/ofx-dev
DVFrame::~DVFrame()
{
//#ifdef HAVE_LIBDV
	dv_decoder_free( decoder );
//#endif

	for ( int n = 0; n < 4; n++ )
		free( audio_buffers[ n ] );
}
コード例 #7
0
ファイル: gstdvdec.c プロジェクト: slkwyy/gst-plugins-good
static GstStateChangeReturn
gst_dvdec_change_state (GstElement * element, GstStateChange transition)
{
  GstDVDec *dvdec = GST_DVDEC (element);
  GstStateChangeReturn ret;


  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      break;
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      dvdec->decoder =
          dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
      dvdec->decoder->quality = qualities[dvdec->quality];
      dv_set_error_log (dvdec->decoder, NULL);
      gst_video_info_init (&dvdec->vinfo);
      gst_segment_init (&dvdec->segment, GST_FORMAT_UNDEFINED);
      dvdec->src_negotiated = FALSE;
      dvdec->sink_negotiated = FALSE;
      dvdec->need_segment = FALSE;
      /* 
       * Enable this function call when libdv2 0.100 or higher is more
       * common
       */
      /* dv_set_quality (dvdec->decoder, qualities [dvdec->quality]); */
      break;
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);

  switch (transition) {
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
      break;
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      dv_decoder_free (dvdec->decoder);
      dvdec->decoder = NULL;
      if (dvdec->pool) {
        gst_buffer_pool_set_active (dvdec->pool, FALSE);
        gst_object_unref (dvdec->pool);
        dvdec->pool = NULL;
      }
      break;
    case GST_STATE_CHANGE_READY_TO_NULL:
      break;
    default:
      break;
  }
  return ret;
}
コード例 #8
0
ファイル: qtdv.c プロジェクト: knutj/cinelerra
static void delete_codec(quicktime_video_map_t *vtrack)
{
    quicktime_dv_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;

    if(codec->dv_decoder)
    {
        dv_decoder_free( codec->dv_decoder );
        codec->dv_decoder = NULL;
    }

    if(codec->dv_encoder)
    {
        dv_encoder_free( codec->dv_encoder );
        codec->dv_encoder = NULL;
    }

    if(codec->temp_frame) free(codec->temp_frame);
    if(codec->temp_rows) free(codec->temp_rows);
    free(codec->data);
    free(codec);
}
コード例 #9
0
static demuxer_t* demux_open_rawdv(demuxer_t* demuxer)
{
   unsigned char dv_frame[DV_PAL_FRAME_SIZE];
   sh_video_t *sh_video = NULL;
   rawdv_frames_t *frames = malloc(sizeof(rawdv_frames_t));
   dv_decoder_t *dv_decoder=NULL;

   mp_msg(MSGT_DEMUXER,MSGL_V,"demux_open_rawdv() end_pos %"PRId64"\n",(int64_t)demuxer->stream->end_pos);

   // go back to the beginning
   stream_reset(demuxer->stream);
   stream_seek(demuxer->stream, 0);

   //get the first frame
   stream_read(demuxer->stream, dv_frame, DV_PAL_FRAME_SIZE);

   //read params from this frame
   dv_decoder=dv_decoder_new(TRUE,TRUE,FALSE);
   dv_decoder->quality=DV_QUALITY_BEST;

   if (dv_parse_header(dv_decoder, dv_frame) == -1)
	   return NULL;

   // create a new video stream header
   sh_video = new_sh_video(demuxer, 0);
   if (!sh_video)
	   return NULL;

   // make sure the demuxer knows about the new video stream header
   // (even though new_sh_video() ought to take care of it)
   demuxer->seekable = 1;
   demuxer->video->sh = sh_video;

   // make sure that the video demuxer stream header knows about its
   // parent video demuxer stream (this is getting wacky), or else
   // video_read_properties() will choke
   sh_video->ds = demuxer->video;

   // custom fourcc for internal MPlayer use
//   sh_video->format = mmioFOURCC('R', 'A', 'D', 'V');
   sh_video->format = mmioFOURCC('D', 'V', 'S', 'D');

   sh_video->disp_w = dv_decoder->width;
   sh_video->disp_h = dv_decoder->height;
   mp_msg(MSGT_DEMUXER,MSGL_V,"demux_open_rawdv() frame_size: %d w: %d h: %d dif_seq: %d system: %d\n",dv_decoder->frame_size,dv_decoder->width, dv_decoder->height,dv_decoder->num_dif_seqs,dv_decoder->system);

   sh_video->fps= (dv_decoder->system==e_dv_system_525_60?29.97:25);
   sh_video->frametime = 1.0/sh_video->fps;

  // emulate BITMAPINFOHEADER for win32 decoders:
  sh_video->bih=malloc(sizeof(BITMAPINFOHEADER));
  memset(sh_video->bih,0,sizeof(BITMAPINFOHEADER));
  sh_video->bih->biSize=40;
  sh_video->bih->biWidth = dv_decoder->width;
  sh_video->bih->biHeight = dv_decoder->height;
  sh_video->bih->biPlanes=1;
  sh_video->bih->biBitCount=24;
  sh_video->bih->biCompression=sh_video->format; // "DVSD"
  sh_video->bih->biSizeImage=sh_video->bih->biWidth*sh_video->bih->biHeight*3;


   frames->current_filepos=0;
   frames->current_frame=0;
   frames->frame_size=dv_decoder->frame_size;
   frames->frame_number=demuxer->stream->end_pos/frames->frame_size;

   mp_msg(MSGT_DEMUXER,MSGL_V,"demux_open_rawdv() seek to %qu, size: %d, dv_dec->frame_size: %d\n",frames->current_filepos,frames->frame_size, dv_decoder->frame_size);
    if (dv_decoder->audio != NULL && demuxer->audio->id>=-1){
       sh_audio_t *sh_audio =  new_sh_audio(demuxer, 0);
	    demuxer->audio->sh = sh_audio;
	    sh_audio->ds = demuxer->audio;
       mp_msg(MSGT_DEMUXER,MSGL_V,"demux_open_rawdv() chan: %d samplerate: %d\n",dv_decoder->audio->num_channels,dv_decoder->audio->frequency );
       // custom fourcc for internal MPlayer use
       sh_audio->format = mmioFOURCC('R', 'A', 'D', 'V');

	sh_audio->wf = malloc(sizeof(WAVEFORMATEX));
	memset(sh_audio->wf, 0, sizeof(WAVEFORMATEX));
	sh_audio->wf->wFormatTag = sh_audio->format;
	sh_audio->wf->nChannels = dv_decoder->audio->num_channels;
	sh_audio->wf->wBitsPerSample = 16;
	sh_audio->wf->nSamplesPerSec = dv_decoder->audio->frequency;
	// info about the input stream:
	sh_audio->wf->nAvgBytesPerSec = sh_video->fps*dv_decoder->frame_size;
	sh_audio->wf->nBlockAlign = dv_decoder->frame_size;

//       sh_audio->context=(void*)dv_decoder;
    }
   stream_reset(demuxer->stream);
   stream_seek(demuxer->stream, 0);
   dv_decoder_free(dv_decoder);  //we keep this in the context of both stream headers
   demuxer->priv=frames;
   return demuxer;
}
コード例 #10
0
int main( int argc, char **argv)
{
    int infile = 0;
    unsigned char dv_buffer[144000];
    unsigned char video_buffer[720 * 576 * 3];
    int16_t *audio_bufs[4];
    dv_decoder_t *decoder = NULL;
    dv_encoder_t *encoder = NULL;
    int pitches[3];
    unsigned char *pixels[3];
    int i = 0, j;
    int isPAL = FALSE;

    pitches[0] = 720 * 2;
    pixels[0] = video_buffer;

    for(i = 0; i < 4; i++) {
        audio_bufs[i] = malloc(DV_AUDIO_MAX_SAMPLES*sizeof(int16_t));
    }

    /* assume NTSC for now, switch to PAL later if needed */
    decoder = dv_decoder_new(FALSE, FALSE, FALSE);
    encoder = dv_encoder_new(FALSE, FALSE, FALSE);

    decoder->quality = DV_QUALITY_BEST;
    encoder->vlc_encode_passes = 3;
    encoder->static_qno = 0;
    encoder->force_dct = DV_DCT_AUTO;

    i = 0;
    while (read_frame(stdin, dv_buffer, &isPAL)) {
        dv_parse_header(decoder, dv_buffer);
        if (isPAL != encoder->isPAL && isPAL == TRUE) {
            decoder->clamp_luma = FALSE;
            decoder->clamp_chroma = FALSE;
            encoder->clamp_luma = FALSE;
            encoder->clamp_chroma = FALSE;
            dv_reconfigure(FALSE, FALSE);
        } else if (isPAL != encoder->isPAL) {
            decoder->clamp_luma = TRUE;
            decoder->clamp_chroma = TRUE;
            decoder->add_ntsc_setup = TRUE;
            encoder->clamp_luma = TRUE;
            encoder->clamp_chroma = TRUE;
            encoder->rem_ntsc_setup = TRUE;
            dv_reconfigure(TRUE, TRUE);
        }
        encoder->isPAL = isPAL;
        encoder->is16x9 = (dv_format_wide(decoder)>0);
        dv_decode_full_audio(decoder, dv_buffer, audio_bufs);
        for (j = 0; j < TIMES; j++) {
            dv_decode_full_frame(decoder, dv_buffer, e_dv_color_yuv,
                                 pixels, pitches);

            dv_encode_full_frame(encoder, pixels, e_dv_color_yuv, dv_buffer);
        }
        dv_encode_full_audio(encoder, audio_bufs, 2, 48000, dv_buffer);
        fwrite(dv_buffer, 1, (isPAL ? 144000 : 120000), stdout);
    }

    close(infile);

    for(i=0; i < 4; i++) free(audio_bufs[i]);
    dv_decoder_free(decoder);
    dv_encoder_free(encoder);

    return 0;
}
コード例 #11
0
ファイル: qtdv.c プロジェクト: knutj/cinelerra
static int decode(quicktime_t *file, unsigned char **row_pointers, int track)
{
    long bytes;
    quicktime_video_map_t *vtrack = &(file->vtracks[track]);
    quicktime_dv_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
    int width = vtrack->track->tkhd.track_width;
    int height = vtrack->track->tkhd.track_height;
    int result = 0;
    int i;
    int decode_colormodel = 0;
    int pitches[3] = { 720 * 2, 0, 0 };


    quicktime_set_video_position(file, vtrack->current_position, track);
    bytes = quicktime_frame_size(file, vtrack->current_position, track);
    result = !quicktime_read_data(file, (char*)codec->data, bytes);

    if( codec->dv_decoder && codec->parameters_changed )
    {
        dv_decoder_free( codec->dv_decoder );
        codec->dv_decoder = NULL;
        codec->parameters_changed = 0;
    }

    if( ! codec->dv_decoder )
    {
        pthread_mutex_lock( &libdv_init_mutex );


        codec->dv_decoder = dv_decoder_new( codec->add_ntsc_setup,
                                            codec->clamp_luma,
                                            codec->clamp_chroma );
        codec->dv_decoder->prev_frame_decoded = 0;

        codec->parameters_changed = 0;
        pthread_mutex_unlock( &libdv_init_mutex );
    }

    if(codec->dv_decoder)
    {
        int is_sequential =
            check_sequentiality( row_pointers,
                                 720 * cmodel_calculate_pixelsize(file->color_model),
                                 file->out_h );

        codec->dv_decoder->quality = codec->decode_quality;

        dv_parse_header( codec->dv_decoder, codec->data );

// Libdv improperly decodes RGB colormodels.
        if((file->color_model == BC_YUV422 ||
                file->color_model == BC_RGB888) &&
                file->in_x == 0 &&
                file->in_y == 0 &&
                file->in_w == width &&
                file->in_h == height &&
                file->out_w == width &&
                file->out_h == height &&
                is_sequential)
        {
            if( file->color_model == BC_YUV422 )
            {
                pitches[0] = 720 * 2;
                dv_decode_full_frame( codec->dv_decoder, codec->data,
                                      e_dv_color_yuv, row_pointers,
                                      pitches );
            }
            else if( file->color_model == BC_RGB888)
            {
                pitches[0] = 720 * 3;
                dv_decode_full_frame( codec->dv_decoder, codec->data,
                                      e_dv_color_rgb, row_pointers,
                                      pitches );
            }
        }
        else
        {
            if(!codec->temp_frame)
            {
                codec->temp_frame = malloc(720 * 576 * 2);
                codec->temp_rows = malloc(sizeof(unsigned char*) * 576);
                for(i = 0; i < 576; i++)
                    codec->temp_rows[i] = codec->temp_frame + 720 * 2 * i;
            }

            decode_colormodel = BC_YUV422;
            pitches[0] = 720 * 2;
            dv_decode_full_frame( codec->dv_decoder, codec->data,
                                  e_dv_color_yuv, codec->temp_rows,
                                  pitches );




            cmodel_transfer(row_pointers,
                            codec->temp_rows,
                            row_pointers[0],
                            row_pointers[1],
                            row_pointers[2],
                            codec->temp_rows[0],
                            codec->temp_rows[1],
                            codec->temp_rows[2],
                            file->in_x,
                            file->in_y,
                            file->in_w,
                            file->in_h,
                            0,
                            0,
                            file->out_w,
                            file->out_h,
                            decode_colormodel,
                            file->color_model,
                            0,
                            width,
                            file->out_w);
        }
    }

//printf(__FUNCTION__ " 2\n");
    return result;
}
コード例 #12
0
ファイル: rawdv.c プロジェクト: d-j-a-y/veejay-dyne-outdated
dv_t	*rawdv_open_input_file(const char *filename, int mmap_size)
{
	dv_t *dv = (dv_t*) vj_malloc(sizeof(dv_t));
	if(!dv) return NULL;
	memset(dv, 0, sizeof(dv_t));
	dv_decoder_t *decoder = NULL;

	uint8_t *tmp = (uint8_t*) vj_malloc(sizeof(uint8_t) * DV_HEADER_SIZE);
	memset( tmp, 0, sizeof(uint8_t) * DV_HEADER_SIZE);
	off_t file_size = 0;
	int n = 0;

	decoder = dv_decoder_new( 1,0,0);
	dv->fd = open( filename, O_RDONLY );
	
	if(!dv->fd)
	{
		dv_decoder_free(decoder); 
		rawdv_free(dv);
		veejay_msg(VEEJAY_MSG_ERROR, "Unable to open file '%s'",filename);
		if(tmp)free(tmp);
		return NULL;
	}
	/* fseek sometimes lies about filesize - seek to end (lseek returns file offset from start)*/
	file_size = lseek( dv->fd, 0, SEEK_END );
	if( file_size < DV_HEADER_SIZE)
	{
		dv_decoder_free(decoder);
		veejay_msg(VEEJAY_MSG_ERROR, "File %s is not a DV file", filename);
		rawdv_free(dv);
		if(tmp) free(tmp);
		return NULL;
	}
	/* And back to start offset */
	if( lseek(dv->fd,0, SEEK_SET ) < 0)
	{
		dv_decoder_free(decoder);
		veejay_msg(VEEJAY_MSG_ERROR, "Seek error in %s", filename);
		rawdv_free(dv);
		if(tmp) free(tmp);
		return NULL;
	}

	dv->mmap_region = NULL;
	if( mmap_size > 0 ) // user wants mmap
	{
		dv->mmap_region = mmap_file( dv->fd, 0, (mmap_size * 720 * 576 * 3),
			file_size );
	}

	if( dv->mmap_region == NULL )
	{
		if(mmap_size>0)
			veejay_msg(VEEJAY_MSG_DEBUG, "Mmap of DV file failed - fallback to read");
		n = read( dv->fd, tmp, DV_HEADER_SIZE );
	}
	else
	{
		n = mmap_read( dv->mmap_region, 0, DV_HEADER_SIZE, tmp );
	}

	if( n <= 0 )
	{
		dv_decoder_free(decoder);
		rawdv_free(dv);
		if(tmp) free(tmp);
		veejay_msg(VEEJAY_MSG_ERROR, "Cannot read from '%s'", filename);
		return NULL;
	}

	if( dv_parse_header( decoder, tmp) < 0 )
	{
		dv_decoder_free( decoder );
		rawdv_free(dv);
		if(tmp) free(tmp);
		veejay_msg(VEEJAY_MSG_ERROR, "Cannot parse header of file %s", filename);
		return NULL;
	}
/*	if(decoder->sampling == e_dv_sample_411)
	{
		dv_decoder_free( decoder );
		rawdv_free(dv);
		if(tmp) free(tmp);
		return NULL;
	}*/


	if(dv_is_PAL( decoder ) )
		dv->chunk_size = DV_PAL_SIZE;
	else
		dv->chunk_size = DV_NTSC_SIZE;

	dv->width = decoder->width;
	dv->height = decoder->height;
	dv->audio_rate = decoder->audio->frequency;
	dv->audio_chans = decoder->audio->num_channels;
	dv->audio_qbytes = decoder->audio->quantization;
	dv->fps = ( dv_is_PAL( decoder) ? 25.0 : 29.97 );
	dv->size = decoder->frame_size;
	dv->num_frames = (file_size - DV_HEADER_SIZE) / dv->size;
	dv->fmt = decoder->sampling;	
//	dv->fmt = ( decoder->sampling == e_dv_sample_422 ? 1 : 0);
	dv->buf = (uint8_t*) vj_malloc(sizeof(uint8_t*) * dv->size);
	dv->offset = 0;

	veejay_msg(VEEJAY_MSG_DEBUG,
			"DV properties %d x %d, %f, %d frames, %d sampling",
			dv->width,dv->height, dv->fps, dv->num_frames,
			dv->fmt );
	
	dv_decoder_free( decoder );

	if(tmp)
		free(tmp);

/*	if(dv->audio_rate)
	{
		int i;
		for( i = 0; i < 4; i ++ )
		dv->audio_buffers[i] = (int16_t*) vj_malloc(sizeof(int16_t) * 2 * DV_AUDIO_MAX_SAMPLES);
	}*/

/*
	veejay_msg(VEEJAY_MSG_DEBUG,
		"rawDV: num frames %ld, dimensions %d x %d, at %2.2f in %s",
		dv->num_frames,
		dv->width,
		dv->height,
		dv->fps,
		(dv->fmt==1?"422":"420"));
	veejay_msg(VEEJAY_MSG_DEBUG,
		"rawDV: frame size %d, rate %d, channels %d, bits %d",
		dv->size,
		dv->audio_rate,
		dv->audio_chans,
		dv->audio_qbytes);*/

	return dv;
}