X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fdv%2Fproducer_libdv.c;h=0ab10e08e665bbc8c6b65fc85c6701673d6f2d09;hb=eae86b6ff2d11421e4839ffbe79c4c547d15751a;hp=9ed89780d7eb0e53bfbdbd378111f15f5a68fa34;hpb=2c0cf75e5da5906e48c5a6398bd48d04501283b9;p=melted diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index 9ed8978..0ab10e0 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -76,15 +76,14 @@ dv_decoder_t *dv_decoder_alloc( ) // Configure the decoder this = dv_decoder_new( FALSE, FALSE, FALSE ); - this->quality = DV_QUALITY_COLOR | DV_QUALITY_AC_1; + this->quality = DV_QUALITY_COLOR | DV_QUALITY_AC_2; this->audio->arg_audio_emphasis = 2; dv_set_audio_correction( this, DV_AUDIO_CORRECT_AVERAGE ); + dv_set_error_log( this, NULL ); // Register it with the properties to ensure clean up - // BUG: dv_decoder_free core dumps here sprintf( label, "%p", this ); - //mlt_properties_set_data( dv_decoders, label, this, 0, ( mlt_destructor )dv_decoder_free, NULL ); - mlt_properties_set_data( dv_decoders, label, this, 0, NULL, NULL ); + mlt_properties_set_data( dv_decoders, label, this, 0, ( mlt_destructor )dv_decoder_free, NULL ); } } @@ -138,10 +137,10 @@ mlt_producer producer_libdv_init( char *filename ) if ( filename != NULL && this != NULL && mlt_producer_init( &this->parent, this ) == 0 ) { mlt_producer producer = &this->parent; - mlt_properties properties = mlt_producer_properties( producer ); + mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer ); // Register transport implementation with the producer - producer->close = producer_close; + producer->close = ( mlt_destructor )producer_close; // Register our get_frame implementation with the producer producer->get_frame = producer_get_frame; @@ -171,15 +170,15 @@ mlt_producer producer_libdv_init( char *filename ) static int read_frame( int fd, uint8_t* frame_buf, int *isPAL ) { - int result = read( fd, frame_buf, frame_size_525_60 ) == frame_size_525_60; + int result = read( fd, frame_buf, FRAME_SIZE_525_60 ) == FRAME_SIZE_525_60; if ( result ) { *isPAL = ( frame_buf[3] & 0x80 ); if ( *isPAL ) { - int diff = frame_size_625_50 - frame_size_525_60; - result = read( fd, frame_buf + frame_size_525_60, diff ) == diff; + int diff = FRAME_SIZE_625_50 - FRAME_SIZE_525_60; + result = read( fd, frame_buf + FRAME_SIZE_525_60, diff ) == diff; } } @@ -190,7 +189,7 @@ static int producer_collect_info( producer_libdv this ) { int valid = 0; - uint8_t *dv_data = mlt_pool_alloc( frame_size_625_50 ); + uint8_t *dv_data = mlt_pool_alloc( FRAME_SIZE_625_50 ); if ( dv_data != NULL ) { @@ -201,7 +200,7 @@ static int producer_collect_info( producer_libdv this ) if ( valid ) { // Get the properties - mlt_properties properties = mlt_producer_properties( &this->parent ); + mlt_properties properties = MLT_PRODUCER_PROPERTIES( &this->parent ); // Get a dv_decoder dv_decoder_t *dv_decoder = dv_decoder_alloc( ); @@ -214,7 +213,7 @@ static int producer_collect_info( producer_libdv this ) this->file_size = buf.st_size; // Determine the frame size - this->frame_size = this->is_pal ? frame_size_625_50 : frame_size_525_60; + this->frame_size = this->is_pal ? FRAME_SIZE_625_50 : FRAME_SIZE_525_60; // Determine the number of frames in the file this->frames_in_file = this->file_size / this->frame_size; @@ -223,9 +222,12 @@ static int producer_collect_info( producer_libdv this ) double fps = this->is_pal ? 25 : 30000.0 / 1001.0; if ( mlt_properties_get_double( properties, "fps" ) == fps ) { - mlt_properties_set_position( properties, "length", this->frames_in_file ); - mlt_properties_set_position( properties, "in", 0 ); - mlt_properties_set_position( properties, "out", this->frames_in_file - 1 ); + if ( this->frames_in_file > 0 ) + { + mlt_properties_set_position( properties, "length", this->frames_in_file ); + mlt_properties_set_position( properties, "in", 0 ); + mlt_properties_set_position( properties, "out", this->frames_in_file - 1 ); + } } else { @@ -235,7 +237,7 @@ static int producer_collect_info( producer_libdv this ) // Parse the header for meta info dv_parse_header( dv_decoder, dv_data ); mlt_properties_set_double( properties, "aspect_ratio", - dv_format_wide( dv_decoder ) ? ( this->is_pal ? 512.0/351.0 : 96.0/79.0 ) : ( this->is_pal ? 128.0/117.0 : 72.0/79.0 ) ); + dv_format_wide( dv_decoder ) ? ( this->is_pal ? 118.0/81.0 : 40.0/33.0 ) : ( this->is_pal ? 59.0/54.0 : 10.0/11.0 ) ); // Return the decoder dv_decoder_return( dv_decoder ); @@ -253,7 +255,7 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma uint8_t *pixels[3] = { NULL, NULL, NULL }; // Get the frames properties - mlt_properties properties = mlt_frame_properties( this ); + mlt_properties properties = MLT_FRAME_PROPERTIES( this ); // Get a dv_decoder dv_decoder_t *decoder = dv_decoder_alloc( ); @@ -328,7 +330,7 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma int16_t *audio_channels[ 4 ]; // Get the frames properties - mlt_properties properties = mlt_frame_properties( this ); + mlt_properties properties = MLT_FRAME_PROPERTIES( this ); // Get a dv_decoder dv_decoder_t *decoder = dv_decoder_alloc( ); @@ -373,7 +375,6 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma else { // No audio available on the frame, so get test audio (silence) - this->get_audio = NULL; mlt_frame_get_audio( this, buffer, format, frequency, channels, samples ); } @@ -386,7 +387,7 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index ) { producer_libdv this = producer->child; - uint8_t *data = mlt_pool_alloc( frame_size_625_50 ); + uint8_t *data = mlt_pool_alloc( FRAME_SIZE_625_50 ); // Obtain the current frame number uint64_t position = mlt_producer_frame( producer ); @@ -403,30 +404,30 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i read_frame( this->fd, data, &this->is_pal ) ) { // Get the frames properties - mlt_properties properties = mlt_frame_properties( *frame ); + mlt_properties properties = MLT_FRAME_PROPERTIES( *frame ); // Get a dv_decoder dv_decoder_t *dv_decoder = dv_decoder_alloc( ); // Pass the dv data - mlt_properties_set_data( properties, "dv_data", data, frame_size_625_50, ( mlt_destructor )mlt_pool_release, NULL ); + mlt_properties_set_data( properties, "dv_data", data, FRAME_SIZE_625_50, ( mlt_destructor )mlt_pool_release, NULL ); // Update other info on the frame mlt_properties_set_int( properties, "width", 720 ); mlt_properties_set_int( properties, "height", this->is_pal ? 576 : 480 ); - mlt_properties_set_int( properties, "top_field_first", 0 ); + mlt_properties_set_int( properties, "top_field_first", !this->is_pal ? 0 : ( data[ 5 ] & 0x07 ) == 0 ? 0 : 1 ); // Parse the header for meta info dv_parse_header( dv_decoder, data ); - mlt_properties_set_int( properties, "progressive", dv_is_progressive( dv_decoder ) ); + //mlt_properties_set_int( properties, "progressive", dv_is_progressive( dv_decoder ) ); mlt_properties_set_double( properties, "aspect_ratio", - dv_format_wide( dv_decoder ) ? ( this->is_pal ? 512.0/351.0 : 96.0/79.0 ) : ( this->is_pal ? 128.0/117.0 : 72.0/79.0 ) ); + dv_format_wide( dv_decoder ) ? ( this->is_pal ? 118.0/81.0 : 40.0/33.0 ) : ( this->is_pal ? 59.0/54.0 : 10.0/11.0 ) ); // Hmm - register audio callback - ( *frame )->get_audio = producer_get_audio; + mlt_frame_push_audio( *frame, producer_get_audio ); // Push the quality string - mlt_frame_push_service( *frame, mlt_properties_get( mlt_producer_properties( producer ), "quality" ) ); + mlt_frame_push_service( *frame, mlt_properties_get( MLT_PRODUCER_PROPERTIES( producer ), "quality" ) ); // Push the get_image method on to the stack mlt_frame_push_get_image( *frame, producer_get_image );