{
mlt_properties_set_int( properties, "image_count", mlt_properties_get_int( properties, "image_count" ) - 1 );
error = get_image( this, buffer, format, width, height, writable );
- mlt_properties_set_int( properties, "width", *width );
- mlt_properties_set_int( properties, "height", *height );
- mlt_properties_set_int( properties, "format", *format );
- if ( this->convert_image )
- this->convert_image( this, buffer, format, requested_format );
+ if ( !error )
+ {
+ mlt_properties_set_int( properties, "width", *width );
+ mlt_properties_set_int( properties, "height", *height );
+ mlt_properties_set_int( properties, "format", *format );
+ if ( this->convert_image )
+ this->convert_image( this, buffer, format, requested_format );
+ }
+ else
+ {
+ // Cause the image to be loaded from test card or fallback (white) below.
+ mlt_frame_get_image( this, buffer, format, width, height, writable );
+ }
}
else if ( mlt_properties_get_data( properties, "image", NULL ) )
{
int mlt_sample_calculator( float fps, int frequency, int64_t position )
{
- int samples = 0;
-
- if ( fps )
- {
- /* Compute the cumulative number of samples until the start of this frame and the
- cumulative number of samples until the start of the next frame. Round each to the
- nearest integer and take the difference to determine the number of samples in
- this frame.
-
- This approach should prevent rounding errors that can accumulate over a large number
- of frames causing A/V sync problems. */
-
- int64_t samples_at_this =
- (int64_t)( (double) position * (double) frequency / (double) fps +
- ( position < 0 ? -0.5 : 0.5 ) );
- int64_t samples_at_next =
- (int64_t)( (double) (position + 1) * (double) frequency / (double) fps +
- ( position < 0 ? -0.5 : 0.5 ) );
- samples = (int)( samples_at_next - samples_at_this );
- }
-
- return samples;
+ /* Compute the cumulative number of samples until the start of this frame and the
+ cumulative number of samples until the start of the next frame. Round each to the
+ nearest integer and take the difference to determine the number of samples in
+ this frame.
+
+ This approach should prevent rounding errors that can accumulate over a large number
+ of frames causing A/V sync problems. */
+ return mlt_sample_calculator_to_now( fps, frequency, position )
+ - mlt_sample_calculator_to_now( fps, frequency, position + 1 );
}
/** Determine the number of samples that belong before a time position.
* \bug Will this break when mlt_position is converted to double?
*/
-int64_t mlt_sample_calculator_to_now( float fps, int frequency, int64_t position )
+inline int64_t mlt_sample_calculator_to_now( float fps, int frequency, int64_t position )
{
int64_t samples = 0;