mlt_producer producer;
mlt_consumer consumer;
mlt_profile profile;
- int is_close_profile;
+ int64_t audio_counter;
+ mlt_position audio_position;
};
typedef struct context_s *context;
int result = mlt_frame_get_image( nested_frame, image, format, width, height, writable );
// Allocate the image
- int size = *width * *height * ( *format == mlt_image_yuv422 ? 2 : *format == mlt_image_rgb24 ? 3 :
- ( *format == mlt_image_rgb24a || *format == mlt_image_opengl ) ? 4 : ( 3 / 2 ) );
+ int size = mlt_image_format_size( *format, *width, *height, NULL );
uint8_t *new_image = mlt_pool_alloc( size );
// Update the frame
static int get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
+ context cx = mlt_frame_pop_audio( frame );
mlt_frame nested_frame = mlt_frame_pop_audio( frame );
- int result = mlt_frame_get_audio( nested_frame, buffer, format, frequency, channels, samples );
- int size = mlt_audio_format_size( *format, *samples, *channels );
- int16_t *new_buffer = mlt_pool_alloc( size );
+ int result = 0;
- mlt_properties_set_data( MLT_FRAME_PROPERTIES( frame ), "audio", new_buffer, size, mlt_pool_release, NULL );
- memcpy( new_buffer, *buffer, size );
- *buffer = new_buffer;
+ // if not repeating last frame
+ if ( mlt_frame_get_position( nested_frame ) != cx->audio_position )
+ {
+ double fps = mlt_profile_fps( cx->profile );
+ if ( mlt_producer_get_fps( cx->this ) < fps )
+ fps = mlt_producer_get_fps( cx->this );
+ *samples = mlt_sample_calculator( fps, *frequency, cx->audio_counter++ );
+ result = mlt_frame_get_audio( nested_frame, buffer, format, frequency, channels, samples );
+ int size = mlt_audio_format_size( *format, *samples, *channels );
+ int16_t *new_buffer = mlt_pool_alloc( size );
+
+ mlt_frame_set_audio( frame, new_buffer, *format, size, mlt_pool_release );
+ memcpy( new_buffer, *buffer, size );
+ *buffer = new_buffer;
+ cx->audio_position = mlt_frame_get_position( nested_frame );
+ }
+ else
+ {
+ // otherwise return no samples
+ *samples = 0;
+ *buffer = NULL;
+ }
return result;
}
{
// Allocate and initialize our context
cx = mlt_pool_alloc( sizeof( struct context_s ) );
+ memset( cx, 0, sizeof( *cx ) );
mlt_properties_set_data( properties, "context", cx, 0, mlt_pool_release, NULL );
cx->this = this;
char *profile_name = mlt_properties_get( properties, "profile" );
+ if ( !profile_name )
+ profile_name = mlt_properties_get( properties, "mlt_profile" );
mlt_profile profile = mlt_service_profile( MLT_PRODUCER_SERVICE( this ) );
if ( profile_name )
{
cx->profile = mlt_profile_init( profile_name );
- cx->is_close_profile = 1;
cx->profile->is_explicit = 1;
}
else
{
- cx->profile = profile;
- cx->is_close_profile = 0;
+ cx->profile = mlt_profile_clone( profile );
cx->profile->is_explicit = 0;
}
- // For now, we must conform the nested network's frame rate to the parent network's
- // framerate.
- cx->profile->frame_rate_num = profile->frame_rate_num;
- cx->profile->frame_rate_den = profile->frame_rate_den;
-
// Encapsulate a real producer for the resource
cx->producer = mlt_factory_producer( cx->profile, NULL,
mlt_properties_get( properties, "resource" ) );
- mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( cx->producer ),
- "out, length" );
+ if ( ( profile_name && !strcmp( profile_name, "auto" ) ) ||
+ mlt_properties_get_int( properties, "autoprofile" ) )
+ {
+ mlt_profile_from_producer( cx->profile, cx->producer );
+ mlt_producer_close( cx->producer );
+ cx->producer = mlt_factory_producer( cx->profile, NULL, mlt_properties_get( properties, "resource" ) );
+ }
// Since we control the seeking, prevent it from seeking on its own
mlt_producer_set_speed( cx->producer, 0 );
+ cx->audio_position = -1;
// We will encapsulate a consumer
cx->consumer = mlt_consumer_new( cx->profile );
// Generate a frame
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) );
- if ( frame )
+ if ( *frame )
{
- // Our "in" needs to be the same, keep it so
- mlt_properties_pass_list( MLT_PRODUCER_PROPERTIES( cx->producer ), properties, "in, out" );
-
// Seek the producer to the correct place
// Calculate our positions
- double actual_position = (double)mlt_producer_position( this );
+ double actual_position = (double) mlt_producer_frame( this );
if ( mlt_producer_get_speed( this ) != 0 )
actual_position *= mlt_producer_get_speed( this );
mlt_position need_first = floor( actual_position );
- mlt_producer_seek( cx->producer, need_first );
-
+ mlt_producer_seek( cx->producer,
+ lrint( need_first * mlt_profile_fps( cx->profile ) / mlt_producer_get_fps( this ) ) );
+
// Get the nested frame
mlt_frame nested_frame = mlt_consumer_rt_frame( cx->consumer );
mlt_frame_push_service( *frame, cx );
mlt_frame_push_get_image( *frame, get_image );
mlt_frame_push_audio( *frame, nested_frame );
+ mlt_frame_push_audio( *frame, cx );
mlt_frame_push_audio( *frame, get_audio );
// Give the returned frame temporal identity
mlt_properties_set_double( frame_props, "aspect_ratio", mlt_profile_sar( cx->profile ) );
mlt_properties_set_int( frame_props, "width", cx->profile->width );
mlt_properties_set_int( frame_props, "height", cx->profile->height );
- mlt_properties_set_int( frame_props, "real_width", cx->profile->width );
- mlt_properties_set_int( frame_props, "real_height", cx->profile->height );
+ mlt_properties_set_int( frame_props, "meta.media.width", cx->profile->width );
+ mlt_properties_set_int( frame_props, "meta.media.height", cx->profile->height );
mlt_properties_set_int( frame_props, "progressive", cx->profile->progressive );
}
mlt_consumer_stop( cx->consumer );
mlt_consumer_close( cx->consumer );
mlt_producer_close( cx->producer );
- if ( cx->is_close_profile )
- mlt_profile_close( cx->profile );
+ mlt_profile_close( cx->profile );
}
this->close = NULL;
mlt_producer this = mlt_producer_new( profile );
// Encapsulate the real producer
- mlt_profile temp_profile = mlt_profile_init( NULL );
+ mlt_profile temp_profile = mlt_profile_clone( profile );
+ temp_profile->is_explicit = 0;
mlt_producer real_producer = mlt_factory_producer( temp_profile, NULL, arg );
if ( this && real_producer )