X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fdv%2Fproducer_libdv.c;h=f2cc38975a112802e04880bcc431054929850cf3;hb=b6232c93db568b3becc00019ca18e31bd92e54b5;hp=7a0c16bc1e258efc7145997f822471a9ebccd4b6;hpb=363d095af9149cc181e92a35d2e34e583d061747;p=mlt diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index 7a0c16bc..f2cc3897 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -76,9 +76,10 @@ 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 sprintf( label, "%p", this ); @@ -122,6 +123,7 @@ struct producer_libdv_s uint64_t file_size; int frame_size; long frames_in_file; + mlt_producer alternative; }; static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index ); @@ -135,8 +137,12 @@ mlt_producer producer_libdv_init( char *filename ) if ( filename != NULL && this != NULL && mlt_producer_init( &this->parent, this ) == 0 ) { + int destroy = 0; mlt_producer producer = &this->parent; - mlt_properties properties = mlt_producer_properties( producer ); + mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer ); + + // Set the resource property (required for all producers) + mlt_properties_set( properties, "resource", filename ); // Register transport implementation with the producer producer->close = ( mlt_destructor )producer_close; @@ -144,18 +150,34 @@ mlt_producer producer_libdv_init( char *filename ) // Register our get_frame implementation with the producer producer->get_frame = producer_get_frame; - // Open the file if specified - this->fd = open( filename, O_RDONLY ); - - // Collect info - if ( this->fd != -1 && producer_collect_info( this ) ) + // If we have mov or dv, then we'll use an alternative producer + if ( strchr( filename, '.' ) != NULL && ( + strncasecmp( strrchr( filename, '.' ), ".avi", 4 ) == 0 || + strncasecmp( strrchr( filename, '.' ), ".mov", 4 ) == 0 ) ) { - // Set the resource property (required for all producers) - mlt_properties_set( properties, "resource", filename ); + // Load via an alternative mechanism + this->alternative = mlt_factory_producer( "kino", filename ); + + // If it's unavailable, then clean up + if ( this->alternative == NULL ) + destroy = 1; + else + mlt_properties_pass( properties, MLT_PRODUCER_PROPERTIES( this->alternative ), "" ); + this->is_pal = mlt_properties_get_int( properties, "fps" ) == 25; } else { - // Reject this file + // Open the file if specified + this->fd = open( filename, O_RDONLY ); + + // Collect info + if ( this->fd == -1 || !producer_collect_info( this ) ) + destroy = 1; + } + + // If we couldn't open the file, then destroy it now + if ( destroy ) + { mlt_producer_close( producer ); producer = NULL; } @@ -199,7 +221,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( ); @@ -236,7 +258,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 ); @@ -254,7 +276,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( ); @@ -278,9 +300,10 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma // Parse the header for meta info dv_parse_header( decoder, dv_data ); - // Assign width and height from properties - *width = mlt_properties_get_int( properties, "width" ); - *height = mlt_properties_get_int( properties, "height" ); + // Assign width and height according to the frame + *width = 720; + *height = dv_data[ 3 ] & 0x80 ? 576 : 480; + // Extract an image of the format requested if ( *format == mlt_image_yuv422 ) @@ -329,7 +352,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( ); @@ -374,7 +397,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,59 +408,88 @@ 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 ) { + // Access the private data producer_libdv this = producer->child; - uint8_t *data = mlt_pool_alloc( FRAME_SIZE_625_50 ); - + + // Will carry the frame data + uint8_t *data = NULL; + // Obtain the current frame number uint64_t position = mlt_producer_frame( producer ); - // Convert timecode to a file position (ensuring that we're on a frame boundary) - uint64_t offset = position * this->frame_size; + if ( this->alternative == NULL ) + { + // Convert timecode to a file position (ensuring that we're on a frame boundary) + uint64_t offset = position * this->frame_size; + + // Allocate space + data = mlt_pool_alloc( FRAME_SIZE_625_50 ); + + // Create an empty frame + *frame = mlt_frame_init( ); + + // Seek and fetch + if ( this->fd != 0 && + lseek( this->fd, offset, SEEK_SET ) == offset && + read_frame( this->fd, data, &this->is_pal ) ) + { + // Pass the dv data + mlt_properties_set_data( MLT_FRAME_PROPERTIES( *frame ), "dv_data", data, FRAME_SIZE_625_50, ( mlt_destructor )mlt_pool_release, NULL ); + } + else + { + mlt_pool_release( data ); + data = NULL; + } + } + else + { + // Seek + mlt_producer_seek( this->alternative, position ); + + // Fetch + mlt_service_get_frame( MLT_PRODUCER_SERVICE( this->alternative ), frame, 0 ); - // Create an empty frame - *frame = mlt_frame_init( ); + // Verify + if ( *frame != NULL ) + data = mlt_properties_get_data( MLT_FRAME_PROPERTIES( *frame ), "dv_data", NULL ); + } - // Seek and fetch - if ( this->fd != 0 && - lseek( this->fd, offset, SEEK_SET ) == offset && - read_frame( this->fd, data, &this->is_pal ) ) + if ( data != NULL ) { // 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_int( properties, "test_image", 0 ); + mlt_properties_set_int( properties, "test_audio", 0 ); // 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 ) ); + mlt_properties_set_double( properties, "dv_aspect_ratio", mlt_properties_get_double( properties, "aspect_ratio" ) ); + // 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 ); - + // Return the decoder dv_decoder_return( dv_decoder ); } - else - { - mlt_pool_release( data ); - } // Update timecode on the frame we're creating mlt_frame_set_position( *frame, mlt_producer_position( producer ) ); @@ -458,6 +509,9 @@ static void producer_close( mlt_producer parent ) if ( this->fd > 0 ) close( this->fd ); + if ( this->alternative ) + mlt_producer_close( this->alternative ); + // Close the parent parent->close = NULL; mlt_producer_close( parent );