X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fdv%2Fproducer_libdv.c;h=dc675f72d9232260f111285eab56f612e1b734ba;hb=d7f9be0634acea4a311066054258d2b0f6b4b7a5;hp=f3d63a6c75c5a7af3c96383ada290f178474fc63;hpb=8bf137cd71aafb9c8f6a42c78ddb6bd0a8fe99db;p=melted diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index f3d63a6..dc675f7 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -70,10 +70,19 @@ mlt_producer producer_libdv_init( char *filename ) // Open the file if specified this->fd = open( filename, O_RDONLY ); - producer_collect_info( this ); - // Set the resource property (required for all producers) - mlt_properties_set( properties, "resource", filename ); + // Collect info + if ( this->fd != -1 && producer_collect_info( this ) ) + { + // Set the resource property (required for all producers) + mlt_properties_set( properties, "resource", filename ); + } + else + { + // Reject this file + mlt_producer_close( producer ); + producer = NULL; + } // Return the producer return producer; @@ -102,6 +111,7 @@ static int read_frame( int fd, uint8_t* frame_buf, int *isPAL ) static int producer_collect_info( producer_libdv this ) { int valid = 0; + // IRRIGATE ME uint8_t *dv_data = malloc( frame_size_625_50 ); if ( dv_data != NULL ) @@ -130,18 +140,20 @@ static int producer_collect_info( producer_libdv this ) // Calculate default in/out points double fps = this->is_pal ? 25 : 30000.0 / 1001.0; - mlt_timecode length = ( mlt_timecode )( this->frames_in_file ) / fps; - mlt_properties_set_double( properties, "fps", fps ); - mlt_properties_set_timecode( properties, "length", length ); - mlt_properties_set_timecode( properties, "in", 0.0 ); - mlt_properties_set_timecode( properties, "out", length ); + 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 ); + } + else + { + valid = 0; + } // Parse the header for meta info - dv_parse_header( this->dv_decoder, data ); + dv_parse_header( this->dv_decoder, dv_data ); mlt_properties_set_double( properties, "aspect_ratio", dv_format_wide( this->dv_decoder ) ? 16.0/9.0 : 4.0/3.0 ); - - // Set the speed to normal - mlt_properties_set_double( properties, "speed", 1 ); } free( dv_data ); @@ -165,7 +177,7 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma uint8_t *dv_data = mlt_properties_get_data( properties, "dv_data", NULL ); // Parse the header for meta info - dv_parse_header( this->dv_decoder, data ); + dv_parse_header( decoder, dv_data ); // Assign width and height from properties *width = mlt_properties_get_int( properties, "width" ); @@ -175,10 +187,11 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma if ( *format == mlt_image_yuv422 ) { // Allocate an image - uint8_t *image = malloc( *width * *height * 2 ); + // IRRIGATE ME + uint8_t *image = malloc( *width * ( *height + 1 ) * 2 ); // Pass to properties for clean up - mlt_properties_set_data( properties, "image", image, *width * *height * 2, free, NULL ); + mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 2, free, NULL ); // Decode the image pitches[ 0 ] = *width * 2; @@ -191,10 +204,11 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma else if ( *format == mlt_image_rgb24 ) { // Allocate an image - uint8_t *image = malloc( *width * *height * 3 ); + // IRRIGATE ME + uint8_t *image = malloc( *width * ( *height + 1 ) * 3 ); // Pass to properties for clean up - mlt_properties_set_data( properties, "image", image, *width * *height * 3, free, NULL ); + mlt_properties_set_data( properties, "image", image, *width * ( *height + 1 ) * 3, free, NULL ); // Decode the frame pitches[ 0 ] = 720 * 3; @@ -224,9 +238,10 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma uint8_t *dv_data = mlt_properties_get_data( properties, "dv_data", NULL ); // Parse the header for meta info - dv_parse_header( this->dv_decoder, data ); + dv_parse_header( decoder, dv_data ); // Obtain required values + //fprintf( stderr, "libdv: frequency %d\n", decoder->audio->frequency ); *frequency = decoder->audio->frequency; *samples = decoder->audio->samples_this_frame; *channels = decoder->audio->num_channels; @@ -307,7 +322,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i } // Update timecode on the frame we're creating - mlt_frame_set_timecode( *frame, mlt_producer_position( producer ) ); + mlt_frame_set_position( *frame, mlt_producer_position( producer ) ); // Calculate the next timecode mlt_producer_prepare_next( producer ); @@ -321,10 +336,10 @@ static void producer_close( mlt_producer parent ) producer_libdv this = parent->child; // Free the dv deconder - dv_decoder_free( this->dv_decoder ); + //dv_decoder_free( this->dv_decoder ); // Close the file - if ( this->fd != 0 ) + if ( this->fd > 0 ) close( this->fd ); // Close the parent