mlt_producer producer;
mlt_consumer consumer;
mlt_profile 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_frame_set_audio( frame, new_buffer, *format, size, mlt_pool_release );
- 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;
+ }
+ else
+ {
+ // otherwise return no samples
+ *samples = 0;
+ }
+ cx->audio_position = mlt_frame_get_position( nested_frame );
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" );
cx->profile->is_explicit = 0;
}
- if ( ! mlt_properties_get_int( properties, "autoprofile" ) )
- {
- // 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" ) );
- if ( mlt_properties_get_int( properties, "autoprofile" ) )
+ 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" ) );
}
- mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( cx->producer ),
- "out, length" );
// Since we control the seeking, prevent it from seeking on its own
mlt_producer_set_speed( cx->producer, 0 );
*frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) );
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, 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_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 );
mlt_producer real_producer = mlt_factory_producer( temp_profile, NULL, arg );
if ( this && real_producer )