X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fdv%2Fproducer_libdv.c;h=3d4f2439d063845544fac85c2941a51ec581b5ac;hb=edfb53ebb1ce5b141e34b7feb7df7448cbc5be96;hp=5d2c768e7e926a2da4591ff38308941f60d4c471;hpb=661165812e3410fe2f6f49d7af882b36a0efcf82;p=melted diff --git a/src/modules/dv/producer_libdv.c b/src/modules/dv/producer_libdv.c index 5d2c768..3d4f243 100644 --- a/src/modules/dv/producer_libdv.c +++ b/src/modules/dv/producer_libdv.c @@ -51,9 +51,10 @@ mlt_producer producer_libdv_init( char *filename ) { producer_libdv this = calloc( sizeof( struct producer_libdv_s ), 1 ); - if ( this != NULL && mlt_producer_init( &this->parent, this ) == 0 ) + if ( filename != NULL && this != NULL && mlt_producer_init( &this->parent, this ) == 0 ) { mlt_producer producer = &this->parent; + mlt_properties properties = mlt_producer_properties( producer ); // Register transport implementation with the producer producer->close = producer_close; @@ -63,15 +64,24 @@ mlt_producer producer_libdv_init( char *filename ) // Create the dv_decoder this->dv_decoder = dv_decoder_new( FALSE, FALSE, FALSE ); - this->dv_decoder->quality = DV_QUALITY_BEST; + this->dv_decoder->quality = DV_QUALITY_COLOR | DV_QUALITY_AC_1; this->dv_decoder->audio->arg_audio_emphasis = 2; dv_set_audio_correction( this->dv_decoder, DV_AUDIO_CORRECT_AVERAGE ); // Open the file if specified - if ( filename != NULL ) + this->fd = open( filename, O_RDONLY ); + + // 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 { - this->fd = open( filename, O_RDONLY ); - producer_collect_info( this ); + // Reject this file + mlt_producer_close( producer ); + producer = NULL; } // Return the producer @@ -101,7 +111,8 @@ static int read_frame( int fd, uint8_t* frame_buf, int *isPAL ) static int producer_collect_info( producer_libdv this ) { int valid = 0; - uint8_t *dv_data = malloc( frame_size_625_50 ); + + uint8_t *dv_data = mlt_pool_alloc( frame_size_625_50 ); if ( dv_data != NULL ) { @@ -128,67 +139,30 @@ static int producer_collect_info( producer_libdv this ) this->frames_in_file = this->file_size / this->frame_size; // Calculate default in/out points - double fps = this->is_pal ? 25 : 30000 / 1001; - mlt_timecode length = ( mlt_timecode )( this->frames_in_file ) / fps; - mlt_properties_set_double( properties, "fps", fps ); - mlt_properties_set_timecode( properties, "playtime", length ); - mlt_properties_set_timecode( properties, "length", length ); - mlt_properties_set_timecode( properties, "in", 0.0 ); - mlt_properties_set_timecode( properties, "out", length ); - - // Set the speed to normal - mlt_properties_set_double( properties, "speed", 1 ); + 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 ); + } + else + { + valid = 0; + } + + // Parse the header for meta info + dv_parse_header( this->dv_decoder, dv_data ); + mlt_properties_set_double( properties, "aspect_ratio", + dv_format_wide( this->dv_decoder ) ? ( this->is_pal ? 512/351 : 96/79 ) : ( this->is_pal ? 128/117 : 72/79 ) ); } - free( dv_data ); + mlt_pool_release( dv_data ); } return valid; } -#if 0 -static int mc_producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable ) -{ - // Get the frames properties - mlt_properties properties = mlt_frame_properties( this ); - - // Get the dv data - uint8_t *dv_data = mlt_properties_get_data( properties, "dv_data", NULL ); - - // Determine bytes in frame - int bytes_in_frame = dv_data[ 3 ] & 0x80 ? frame_size_625_50 : frame_size_525_60; - - // Assign width and height from properties - *width = mlt_properties_get_int( properties, "width" ); - *height = mlt_properties_get_int( properties, "height" ); - - if ( *format == mlt_image_yuv422 ) - { - // Allocate image - *buffer = malloc( *width * *height * 2 ); - - // Decompress - DecompressBuffer_DV( dv_data, bytes_in_frame, *buffer, *width * 2, *width, *height, 0, FOURCC_YUYV, 0, NULL ); - - // Set the image on the properties - mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, free, NULL ); - } - else - { - // Allocate image - *buffer = malloc( *width * *height * 3 ); - - // Decompress - DecompressBuffer_DV( dv_data, bytes_in_frame, *buffer, *width * 3, *width, *height, 0, FOURCC_R24C, 0, NULL ); - - // Set the image on the properties - mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, free, NULL ); - } - - return 0; -} -#endif - static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable ) { int pitches[3] = { 0, 0, 0 }; @@ -203,21 +177,21 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma // Get the dv data uint8_t *dv_data = mlt_properties_get_data( properties, "dv_data", NULL ); + // 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" ); - // Parse the header - dv_parse_header( decoder, dv_data ); - // Extract an image of the format requested if ( *format == mlt_image_yuv422 ) { // Allocate an image - uint8_t *image = malloc( *width * *height * 2 ); + uint8_t *image = mlt_pool_alloc( *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, ( mlt_destructor )mlt_pool_release, NULL ); // Decode the image pitches[ 0 ] = *width * 2; @@ -230,10 +204,10 @@ 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 ); + uint8_t *image = mlt_pool_alloc( *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, ( mlt_destructor )mlt_pool_release, NULL ); // Decode the frame pitches[ 0 ] = 720 * 3; @@ -272,13 +246,13 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma // Create a temporary workspace for ( i = 0; i < 4; i++ ) - audio_channels[ i ] = malloc( DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) ); + audio_channels[ i ] = mlt_pool_alloc( DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) ); // Create a workspace for the result - *buffer = malloc( *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) ); + *buffer = mlt_pool_alloc( *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ) ); // Pass the allocated audio buffer as a property - mlt_properties_set_data( properties, "audio", *buffer, *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), free, NULL ); + mlt_properties_set_data( properties, "audio", *buffer, *channels * DV_AUDIO_MAX_SAMPLES * sizeof( int16_t ), ( mlt_destructor )mlt_pool_release, NULL ); // Decode the audio dv_decode_full_audio( decoder, dv_data, audio_channels ); @@ -291,7 +265,7 @@ static int producer_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_forma // Free the temporary work space for ( i = 0; i < 4; i++ ) - free( audio_channels[ i ] ); + mlt_pool_release( audio_channels[ i ] ); return 0; } @@ -299,7 +273,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 = malloc( 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 ); @@ -322,11 +296,29 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i mlt_properties_set_data( properties, "dv_decoder", this->dv_decoder, 0, NULL, NULL ); // Pass the dv data - mlt_properties_set_data( properties, "dv_data", data, frame_size_625_50, free, 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 ); + + char *quality = mlt_properties_get( mlt_producer_properties( producer ), "quality" ); + if ( quality != NULL ) + { + if ( strncmp( quality, "fast", 4 ) == 0 ) + this->dv_decoder->quality = ( DV_QUALITY_COLOR | DV_QUALITY_DC ); + else if ( strncmp( quality, "best", 4 ) == 0 ) + this->dv_decoder->quality = ( DV_QUALITY_COLOR | DV_QUALITY_AC_2 ); + else + this->dv_decoder->quality = ( DV_QUALITY_COLOR | DV_QUALITY_AC_1 ); + } + + // Parse the header for meta info + dv_parse_header( this->dv_decoder, data ); + mlt_properties_set_int( properties, "progressive", dv_is_progressive( this->dv_decoder ) ); + mlt_properties_set_double( properties, "aspect_ratio", + dv_format_wide( this->dv_decoder ) ? ( this->is_pal ? 512.0/351.0 : 96.0/79.0 ) : ( this->is_pal ? 128.0/117.0 : 72.0/79.0 ) ); // Hmm - register audio callback ( *frame )->get_audio = producer_get_audio; @@ -336,11 +328,11 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i } else { - free( data ); + mlt_pool_release( data ); } // 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 ); @@ -354,10 +346,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 @@ -367,4 +359,3 @@ static void producer_close( mlt_producer parent ) // Free the memory free( this ); } -