2 * mlt_frame.c -- interface for all frame classes
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "mlt_frame.h"
23 #include "mlt_producer.h"
24 #include "mlt_factory.h"
29 /** Constructor for a frame.
32 mlt_frame
mlt_frame_init( )
35 mlt_frame
this = calloc( sizeof( struct mlt_frame_s
), 1 );
39 // Get the normalisation
40 char *normalisation
= mlt_environment( "MLT_NORMALISATION" );
42 // Initialise the properties
43 mlt_properties properties
= &this->parent
;
44 mlt_properties_init( properties
, this );
46 // Set default properties on the frame
47 mlt_properties_set_position( properties
, "_position", 0.0 );
48 mlt_properties_set_data( properties
, "image", NULL
, 0, NULL
, NULL
);
50 if ( normalisation
== NULL
|| strcmp( normalisation
, "NTSC" ) )
52 mlt_properties_set_int( properties
, "width", 720 );
53 mlt_properties_set_int( properties
, "height", 576 );
54 mlt_properties_set_int( properties
, "normalised_width", 720 );
55 mlt_properties_set_int( properties
, "normalised_height", 576 );
56 mlt_properties_set_double( properties
, "aspect_ratio", 59.0/54.0 );
60 mlt_properties_set_int( properties
, "width", 720 );
61 mlt_properties_set_int( properties
, "height", 480 );
62 mlt_properties_set_int( properties
, "normalised_width", 720 );
63 mlt_properties_set_int( properties
, "normalised_height", 480 );
64 mlt_properties_set_double( properties
, "aspect_ratio", 10.0/11.0 );
67 mlt_properties_set_data( properties
, "audio", NULL
, 0, NULL
, NULL
);
68 mlt_properties_set_data( properties
, "alpha", NULL
, 0, NULL
, NULL
);
70 // Construct stacks for frames and methods
71 this->stack_image
= mlt_deque_init( );
72 this->stack_audio
= mlt_deque_init( );
73 this->stack_service
= mlt_deque_init( );
79 /** Fetch the frames properties.
82 mlt_properties
mlt_frame_properties( mlt_frame
this )
84 return this != NULL ?
&this->parent
: NULL
;
87 /** Check if we have a way to derive something other than a test card.
90 int mlt_frame_is_test_card( mlt_frame
this )
92 return mlt_deque_count( this->stack_image
) == 0 || mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "test_image" );
95 /** Check if we have a way to derive something other than test audio.
98 int mlt_frame_is_test_audio( mlt_frame
this )
100 return mlt_deque_count( this->stack_audio
) == 0 || mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "test_audio" );
103 /** Get the aspect ratio of the frame.
106 double mlt_frame_get_aspect_ratio( mlt_frame
this )
108 return mlt_properties_get_double( MLT_FRAME_PROPERTIES( this ), "aspect_ratio" );
111 /** Set the aspect ratio of the frame.
114 int mlt_frame_set_aspect_ratio( mlt_frame
this, double value
)
116 return mlt_properties_set_double( MLT_FRAME_PROPERTIES( this ), "aspect_ratio", value
);
119 /** Get the position of this frame.
122 mlt_position
mlt_frame_get_position( mlt_frame
this )
124 int pos
= mlt_properties_get_position( MLT_FRAME_PROPERTIES( this ), "_position" );
125 return pos
< 0 ?
0 : pos
;
128 /** Set the position of this frame.
131 int mlt_frame_set_position( mlt_frame
this, mlt_position value
)
133 return mlt_properties_set_position( MLT_FRAME_PROPERTIES( this ), "_position", value
);
136 /** Stack a get_image callback.
139 int mlt_frame_push_get_image( mlt_frame
this, mlt_get_image get_image
)
141 return mlt_deque_push_back( this->stack_image
, get_image
);
144 /** Pop a get_image callback.
147 mlt_get_image
mlt_frame_pop_get_image( mlt_frame
this )
149 return mlt_deque_pop_back( this->stack_image
);
155 int mlt_frame_push_frame( mlt_frame
this, mlt_frame that
)
157 return mlt_deque_push_back( this->stack_image
, that
);
163 mlt_frame
mlt_frame_pop_frame( mlt_frame
this )
165 return mlt_deque_pop_back( this->stack_image
);
171 int mlt_frame_push_service( mlt_frame
this, void *that
)
173 return mlt_deque_push_back( this->stack_image
, that
);
179 void *mlt_frame_pop_service( mlt_frame
this )
181 return mlt_deque_pop_back( this->stack_image
);
187 int mlt_frame_push_service_int( mlt_frame
this, int that
)
189 return mlt_deque_push_back_int( this->stack_image
, that
);
195 int mlt_frame_pop_service_int( mlt_frame
this )
197 return mlt_deque_pop_back_int( this->stack_image
);
200 /** Push an audio item on the stack.
203 int mlt_frame_push_audio( mlt_frame
this, void *that
)
205 return mlt_deque_push_back( this->stack_audio
, that
);
208 /** Pop an audio item from the stack
211 void *mlt_frame_pop_audio( mlt_frame
this )
213 return mlt_deque_pop_back( this->stack_audio
);
216 /** Return the service stack
219 mlt_deque
mlt_frame_service_stack( mlt_frame
this )
221 return this->stack_service
;
224 /** Replace image stack with the information provided.
226 This might prove to be unreliable and restrictive - the idea is that a transition
227 which normally uses two images may decide to only use the b frame (ie: in the case
228 of a composite where the b frame completely obscures the a frame).
230 The image must be writable and the destructor for the image itself must be taken
231 care of on another frame and that frame cannot have a replace applied to it...
232 Further it assumes that no alpha mask is in use.
234 For these reasons, it can only be used in a specific situation - when you have
235 multiple tracks each with their own transition and these transitions are applied
236 in a strictly reversed order (ie: highest numbered [lowest track] is processed
239 More reliable approach - the cases should be detected during the process phase
240 and the upper tracks should simply not be invited to stack...
243 void mlt_frame_replace_image( mlt_frame
this, uint8_t *image
, mlt_image_format format
, int width
, int height
)
245 // Remove all items from the stack
246 while( mlt_deque_pop_back( this->stack_image
) ) ;
248 // Update the information
249 mlt_properties_set_data( MLT_FRAME_PROPERTIES( this ), "image", image
, 0, NULL
, NULL
);
250 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "width", width
);
251 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "height", height
);
252 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "format", format
);
253 this->get_alpha_mask
= NULL
;
256 /** Get the image associated to the frame.
259 int mlt_frame_get_image( mlt_frame
this, uint8_t **buffer
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
261 mlt_properties properties
= MLT_FRAME_PROPERTIES( this );
262 mlt_get_image get_image
= mlt_frame_pop_get_image( this );
263 mlt_producer producer
= mlt_properties_get_data( properties
, "test_card_producer", NULL
);
266 if ( get_image
!= NULL
)
268 mlt_properties_set_int( properties
, "image_count", mlt_properties_get_int( properties
, "image_count" ) - 1 );
269 mlt_position position
= mlt_frame_get_position( this );
270 error
= get_image( this, buffer
, format
, width
, height
, writable
);
271 mlt_properties_set_int( properties
, "width", *width
);
272 mlt_properties_set_int( properties
, "height", *height
);
273 mlt_properties_set_int( properties
, "format", *format
);
274 mlt_frame_set_position( this, position
);
276 else if ( mlt_properties_get_data( properties
, "image", NULL
) != NULL
)
278 *format
= mlt_properties_get_int( properties
, "format" );
279 *buffer
= mlt_properties_get_data( properties
, "image", NULL
);
280 *width
= mlt_properties_get_int( properties
, "width" );
281 *height
= mlt_properties_get_int( properties
, "height" );
283 else if ( producer
!= NULL
)
285 mlt_frame test_frame
= NULL
;
286 mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer
), &test_frame
, 0 );
287 if ( test_frame
!= NULL
)
289 mlt_properties test_properties
= MLT_FRAME_PROPERTIES( test_frame
);
290 mlt_properties_set_double( test_properties
, "consumer_aspect_ratio", mlt_properties_get_double( properties
, "consumer_aspect_ratio" ) );
291 mlt_properties_set( test_properties
, "rescale.interp", mlt_properties_get( properties
, "rescale.interp" ) );
292 mlt_frame_get_image( test_frame
, buffer
, format
, width
, height
, writable
);
293 mlt_properties_set_data( properties
, "test_card_frame", test_frame
, 0, ( mlt_destructor
)mlt_frame_close
, NULL
);
294 mlt_properties_set_data( properties
, "image", *buffer
, *width
* *height
* 2, NULL
, NULL
);
295 mlt_properties_set_int( properties
, "width", *width
);
296 mlt_properties_set_int( properties
, "height", *height
);
297 mlt_properties_set_int( properties
, "format", *format
);
298 mlt_properties_set_double( properties
, "aspect_ratio", mlt_frame_get_aspect_ratio( test_frame
) );
302 mlt_properties_set_data( properties
, "test_card_producer", NULL
, 0, NULL
, NULL
);
303 mlt_frame_get_image( this, buffer
, format
, width
, height
, writable
);
312 *width
= *width
== 0 ?
720 : *width
;
313 *height
= *height
== 0 ?
576 : *height
;
314 size
= *width
* *height
;
316 mlt_properties_set_int( properties
, "format", *format
);
317 mlt_properties_set_int( properties
, "width", *width
);
318 mlt_properties_set_int( properties
, "height", *height
);
319 mlt_properties_set_int( properties
, "aspect_ratio", 0 );
327 case mlt_image_rgb24
:
330 *buffer
= mlt_pool_alloc( size
);
332 memset( *buffer
, 255, size
);
334 case mlt_image_rgb24a
:
335 case mlt_image_opengl
:
338 *buffer
= mlt_pool_alloc( size
);
340 memset( *buffer
, 255, size
);
342 case mlt_image_yuv422
:
345 *buffer
= mlt_pool_alloc( size
);
348 while ( p
!= NULL
&& p
!= q
)
354 case mlt_image_yuv420p
:
356 *buffer
= mlt_pool_alloc( size
);
358 memset( *buffer
, 255, size
);
362 mlt_properties_set_data( properties
, "image", *buffer
, size
, ( mlt_destructor
)mlt_pool_release
, NULL
);
363 mlt_properties_set_int( properties
, "test_image", 1 );
366 mlt_properties_set_int( properties
, "scaled_width", *width
);
367 mlt_properties_set_int( properties
, "scaled_height", *height
);
372 uint8_t *mlt_frame_get_alpha_mask( mlt_frame
this )
374 uint8_t *alpha
= NULL
;
377 if ( this->get_alpha_mask
!= NULL
)
378 alpha
= this->get_alpha_mask( this );
380 alpha
= mlt_properties_get_data( &this->parent
, "alpha", NULL
);
383 int size
= mlt_properties_get_int( &this->parent
, "scaled_width" ) * mlt_properties_get_int( &this->parent
, "scaled_height" );
384 alpha
= mlt_pool_alloc( size
);
385 memset( alpha
, 255, size
);
386 mlt_properties_set_data( &this->parent
, "alpha", alpha
, size
, mlt_pool_release
, NULL
);
392 int mlt_frame_get_audio( mlt_frame
this, int16_t **buffer
, mlt_audio_format
*format
, int *frequency
, int *channels
, int *samples
)
394 mlt_get_audio get_audio
= mlt_frame_pop_audio( this );
395 mlt_properties properties
= MLT_FRAME_PROPERTIES( this );
396 int hide
= mlt_properties_get_int( properties
, "test_audio" );
398 if ( hide
== 0 && get_audio
!= NULL
)
400 mlt_position position
= mlt_frame_get_position( this );
401 get_audio( this, buffer
, format
, frequency
, channels
, samples
);
402 mlt_frame_set_position( this, position
);
404 else if ( mlt_properties_get_data( properties
, "audio", NULL
) )
406 *buffer
= mlt_properties_get_data( properties
, "audio", NULL
);
407 *frequency
= mlt_properties_get_int( properties
, "audio_frequency" );
408 *channels
= mlt_properties_get_int( properties
, "audio_channels" );
409 *samples
= mlt_properties_get_int( properties
, "audio_samples" );
414 *samples
= *samples
<= 0 ?
1920 : *samples
;
415 *channels
= *channels
<= 0 ?
2 : *channels
;
416 *frequency
= *frequency
<= 0 ?
48000 : *frequency
;
417 size
= *samples
* *channels
* sizeof( int16_t );
418 *buffer
= mlt_pool_alloc( size
);
419 if ( *buffer
!= NULL
)
420 memset( *buffer
, 0, size
);
421 mlt_properties_set_data( properties
, "audio", *buffer
, size
, ( mlt_destructor
)mlt_pool_release
, NULL
);
422 mlt_properties_set_int( properties
, "test_audio", 1 );
425 mlt_properties_set_int( properties
, "audio_frequency", *frequency
);
426 mlt_properties_set_int( properties
, "audio_channels", *channels
);
427 mlt_properties_set_int( properties
, "audio_samples", *samples
);
429 if ( mlt_properties_get( properties
, "meta.volume" ) )
431 double value
= mlt_properties_get_double( properties
, "meta.volume" );
434 memset( *buffer
, 0, *samples
* *channels
* 2 );
435 mlt_properties_set_double( properties
, "meta.volume", 1.0 );
437 else if ( value
!= 1.0 )
439 int total
= *samples
* *channels
;
440 int16_t *p
= *buffer
;
446 mlt_properties_set_double( properties
, "meta.volume", 1.0 );
453 unsigned char *mlt_frame_get_waveform( mlt_frame
this, int w
, int h
)
456 mlt_properties properties
= MLT_FRAME_PROPERTIES( this );
457 mlt_audio_format format
= mlt_audio_pcm
;
458 int frequency
= 32000; // lower frequency available?
460 double fps
= mlt_properties_get_double( properties
, "fps" );
461 int samples
= mlt_sample_calculator( fps
, frequency
, mlt_frame_get_position( this ) );
464 mlt_frame_get_audio( this, &pcm
, &format
, &frequency
, &channels
, &samples
);
466 // Make an 8-bit buffer large enough to hold rendering
468 unsigned char *bitmap
= ( unsigned char* )mlt_pool_alloc( size
);
469 if ( bitmap
!= NULL
)
470 memset( bitmap
, 0, size
);
471 mlt_properties_set_data( properties
, "waveform", bitmap
, size
, ( mlt_destructor
)mlt_pool_release
, NULL
);
473 // Render vertical lines
474 int16_t *ubound
= pcm
+ samples
* channels
;
475 int skip
= samples
/ w
- 1;
478 // Iterate sample stream and along x coordinate
479 for ( i
= 0; i
< w
&& pcm
< ubound
; i
++ )
481 // pcm data has channels interleaved
482 for ( j
= 0; j
< channels
; j
++ )
484 // Determine sample's magnitude from 2s complement;
485 int pcm_magnitude
= *pcm
< 0 ?
~(*pcm
) + 1 : *pcm
;
486 // The height of a line is the ratio of the magnitude multiplied by
487 // half the vertical resolution
488 int height
= ( int )( ( double )( pcm_magnitude
) / 32768 * h
/ 2 );
489 // Determine the starting y coordinate - left channel above center,
490 // right channel below - currently assumes 2 channels
491 int displacement
= ( h
/ 2 ) - ( 1 - j
) * height
;
492 // Position buffer pointer using y coordinate, stride, and x coordinate
493 unsigned char *p
= &bitmap
[ i
+ displacement
* w
];
495 // Draw vertical line
496 for ( k
= 0; k
< height
; k
++ )
501 pcm
+= skip
* channels
;
507 mlt_producer
mlt_frame_get_original_producer( mlt_frame
this )
510 return mlt_properties_get_data( MLT_FRAME_PROPERTIES( this ), "_producer", NULL
);
514 void mlt_frame_close( mlt_frame
this )
516 if ( this != NULL
&& mlt_properties_dec_ref( MLT_FRAME_PROPERTIES( this ) ) <= 0 )
518 mlt_deque_close( this->stack_image
);
519 mlt_deque_close( this->stack_audio
);
520 while( mlt_deque_peek_back( this->stack_service
) )
521 mlt_service_close( mlt_deque_pop_back( this->stack_service
) );
522 mlt_deque_close( this->stack_service
);
523 mlt_properties_close( &this->parent
);
528 /***** convenience functions *****/
530 int mlt_convert_rgb24a_to_yuv422( uint8_t *rgba
, int width
, int height
, int stride
, uint8_t *yuv
, uint8_t *alpha
)
533 register int y0
, y1
, u0
, u1
, v0
, v1
;
534 register int r
, g
, b
;
535 register uint8_t *d
= yuv
;
538 for ( i
= 0; i
< height
; i
++ )
540 register uint8_t *s
= rgba
+ ( stride
* i
);
541 for ( j
= 0; j
< ( width
/ 2 ); j
++ )
547 RGB2YUV (r
, g
, b
, y0
, u0
, v0
);
552 RGB2YUV (r
, g
, b
, y1
, u1
, v1
);
564 RGB2YUV (r
, g
, b
, y0
, u0
, v0
);
572 int mlt_convert_rgb24_to_yuv422( uint8_t *rgb
, int width
, int height
, int stride
, uint8_t *yuv
)
575 register int y0
, y1
, u0
, u1
, v0
, v1
;
576 register int r
, g
, b
;
577 register uint8_t *d
= yuv
;
580 for ( i
= 0; i
< height
; i
++ )
582 register uint8_t *s
= rgb
+ ( stride
* i
);
583 for ( j
= 0; j
< ( width
/ 2 ); j
++ )
588 RGB2YUV (r
, g
, b
, y0
, u0
, v0
);
592 RGB2YUV (r
, g
, b
, y1
, u1
, v1
);
603 RGB2YUV (r
, g
, b
, y0
, u0
, v0
);
611 int mlt_convert_yuv420p_to_yuv422( uint8_t *yuv420p
, int width
, int height
, int stride
, uint8_t *yuv
)
616 int half
= width
>> 1;
618 uint8_t *Y
= yuv420p
;
619 uint8_t *U
= Y
+ width
* height
;
620 uint8_t *V
= U
+ width
* height
/ 4;
622 register uint8_t *d
= yuv
;
624 for ( i
= 0; i
< height
; i
++ )
626 register uint8_t *u
= U
+ ( i
/ 2 ) * ( half
);
627 register uint8_t *v
= V
+ ( i
/ 2 ) * ( half
);
629 for ( j
= 0; j
< half
; j
++ )
640 uint8_t *mlt_resize_alpha( uint8_t *input
, int owidth
, int oheight
, int iwidth
, int iheight
)
642 uint8_t *output
= NULL
;
644 if ( input
!= NULL
&& ( iwidth
!= owidth
|| iheight
!= oheight
) && ( owidth
> 6 && oheight
> 6 ) )
646 uint8_t *in_line
= input
;
649 output
= mlt_pool_alloc( owidth
* oheight
);
650 memset( output
, 0, owidth
* oheight
);
652 out_line
= output
+ ( ( oheight
- iheight
) / 2 ) * owidth
;
653 out_line
+= 2 * ( int )( ( owidth
- iwidth
) / 2 );
655 // Loop for the entirety of our output height.
658 // We're in the input range for this row.
659 memcpy( out_line
, input
, iwidth
);
661 // Move to next input line
664 // Move to next output line
672 void mlt_resize_yuv422( uint8_t *output
, int owidth
, int oheight
, uint8_t *input
, int iwidth
, int iheight
)
675 int istride
= iwidth
* 2;
676 int ostride
= owidth
* 2;
678 // Optimisation point
679 if ( output
== NULL
|| input
== NULL
|| ( owidth
<= 6 || oheight
<= 6 || iwidth
<= 6 || oheight
<= 6 ) )
683 else if ( iwidth
== owidth
&& iheight
== oheight
)
685 memcpy( output
, input
, iheight
* istride
);
689 uint8_t *in_line
= input
;
692 int size
= owidth
* oheight
;
701 out_line
= output
+ ( ( oheight
- iheight
) / 2 ) * ostride
;
702 out_line
+= 4 * ( int )( ( owidth
- iwidth
) / 4 );
704 // Loop for the entirety of our output height.
707 // We're in the input range for this row.
708 memcpy( out_line
, in_line
, istride
);
710 // Move to next input line
713 // Move to next output line
718 /** A resizing function for yuv422 frames - this does not rescale, but simply
719 resizes. It assumes yuv422 images available on the frame so use with care.
722 uint8_t *mlt_frame_resize_yuv422( mlt_frame
this, int owidth
, int oheight
)
725 mlt_properties properties
= MLT_FRAME_PROPERTIES( this );
727 // Get the input image, width and height
728 uint8_t *input
= mlt_properties_get_data( properties
, "image", NULL
);
729 uint8_t *alpha
= mlt_frame_get_alpha_mask( this );
731 int iwidth
= mlt_properties_get_int( properties
, "width" );
732 int iheight
= mlt_properties_get_int( properties
, "height" );
734 // If width and height are correct, don't do anything
735 if ( iwidth
!= owidth
|| iheight
!= oheight
)
737 // Create the output image
738 uint8_t *output
= mlt_pool_alloc( owidth
* ( oheight
+ 1 ) * 2 );
740 // Call the generic resize
741 mlt_resize_yuv422( output
, owidth
, oheight
, input
, iwidth
, iheight
);
743 // Now update the frame
744 mlt_properties_set_data( properties
, "image", output
, owidth
* ( oheight
+ 1 ) * 2, ( mlt_destructor
)mlt_pool_release
, NULL
);
745 mlt_properties_set_int( properties
, "width", owidth
);
746 mlt_properties_set_int( properties
, "height", oheight
);
748 // We should resize the alpha too
749 alpha
= mlt_resize_alpha( alpha
, owidth
, oheight
, iwidth
, iheight
);
752 mlt_properties_set_data( properties
, "alpha", alpha
, owidth
* ( oheight
+ 1 ), ( mlt_destructor
)mlt_pool_release
, NULL
);
753 this->get_alpha_mask
= NULL
;
759 // No change, return input
763 /** A rescaling function for yuv422 frames - low quality, and provided for testing
764 only. It assumes yuv422 images available on the frame so use with care.
767 uint8_t *mlt_frame_rescale_yuv422( mlt_frame
this, int owidth
, int oheight
)
770 mlt_properties properties
= MLT_FRAME_PROPERTIES( this );
772 // Get the input image, width and height
773 uint8_t *input
= mlt_properties_get_data( properties
, "image", NULL
);
774 int iwidth
= mlt_properties_get_int( properties
, "width" );
775 int iheight
= mlt_properties_get_int( properties
, "height" );
777 // If width and height are correct, don't do anything
778 if ( iwidth
!= owidth
|| iheight
!= oheight
)
780 // Create the output image
781 uint8_t *output
= mlt_pool_alloc( owidth
* ( oheight
+ 1 ) * 2 );
784 int istride
= iwidth
* 2;
785 int ostride
= owidth
* 2;
787 iwidth
= iwidth
- ( iwidth
% 4 );
789 // Derived coordinates
793 int out_x_range
= owidth
/ 2;
794 int out_y_range
= oheight
/ 2;
795 int in_x_range
= iwidth
/ 2;
796 int in_y_range
= iheight
/ 2;
799 register uint8_t *out_line
= output
;
800 register uint8_t *out_ptr
;
802 // Calculate a middle pointer
803 uint8_t *in_middle
= input
+ istride
* in_y_range
+ in_x_range
* 2;
806 // Generate the affine transform scaling values
807 register int scale_width
= ( iwidth
<< 16 ) / owidth
;
808 register int scale_height
= ( iheight
<< 16 ) / oheight
;
809 register int base
= 0;
811 int outer
= out_x_range
* scale_width
;
812 int bottom
= out_y_range
* scale_height
;
814 // Loop for the entirety of our output height.
815 for ( dy
= - bottom
; dy
< bottom
; dy
+= scale_height
)
817 // Start at the beginning of the line
820 // Pointer to the middle of the input line
821 in_line
= in_middle
+ ( dy
>> 16 ) * istride
;
823 // Loop for the entirety of our output row.
824 for ( dx
= - outer
; dx
< outer
; dx
+= scale_width
)
828 *out_ptr
++ = *( in_line
+ base
);
830 *out_ptr
++ = *( in_line
+ base
+ 1 );
834 *out_ptr
++ = *( in_line
+ base
);
836 *out_ptr
++ = *( in_line
+ base
+ 3 );
839 // Move to next output line
843 // Now update the frame
844 mlt_properties_set_data( properties
, "image", output
, owidth
* ( oheight
+ 1 ) * 2, ( mlt_destructor
)mlt_pool_release
, NULL
);
845 mlt_properties_set_int( properties
, "width", owidth
);
846 mlt_properties_set_int( properties
, "height", oheight
);
852 // No change, return input
856 int mlt_frame_mix_audio( mlt_frame
this, mlt_frame that
, float weight_start
, float weight_end
, int16_t **buffer
, mlt_audio_format
*format
, int *frequency
, int *channels
, int *samples
)
860 int frequency_src
= *frequency
, frequency_dest
= *frequency
;
861 int channels_src
= *channels
, channels_dest
= *channels
;
862 int samples_src
= *samples
, samples_dest
= *samples
;
866 mlt_frame_get_audio( that
, &src
, format
, &frequency_src
, &channels_src
, &samples_src
);
867 mlt_frame_get_audio( this, &dest
, format
, &frequency_dest
, &channels_dest
, &samples_dest
);
869 int silent
= mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "silent_audio" );
870 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "silent_audio", 0 );
872 memset( dest
, 0, samples_dest
* channels_dest
* sizeof( int16_t ) );
874 silent
= mlt_properties_get_int( MLT_FRAME_PROPERTIES( that
), "silent_audio" );
875 mlt_properties_set_int( MLT_FRAME_PROPERTIES( that
), "silent_audio", 0 );
877 memset( src
, 0, samples_src
* channels_src
* sizeof( int16_t ) );
879 if ( channels_src
> 6 )
881 if ( channels_dest
> 6 )
883 if ( samples_src
> 4000 )
885 if ( samples_dest
> 4000 )
888 // determine number of samples to process
889 *samples
= samples_src
< samples_dest ? samples_src
: samples_dest
;
890 *channels
= channels_src
< channels_dest ? channels_src
: channels_dest
;
892 *frequency
= frequency_dest
;
894 // Compute a smooth ramp over start to end
895 float weight
= weight_start
;
896 float weight_step
= ( weight_end
- weight_start
) / *samples
;
899 for ( i
= 0; i
< *samples
; i
++ )
901 for ( j
= 0; j
< *channels
; j
++ )
903 if ( j
< channels_dest
)
904 d
= (double) dest
[ i
* channels_dest
+ j
];
905 if ( j
< channels_src
)
906 s
= (double) src
[ i
* channels_src
+ j
];
907 dest
[ i
* channels_dest
+ j
] = s
* weight
+ d
* ( 1.0 - weight
);
909 weight
+= weight_step
;
915 /* Will this break when mlt_position is converted to double? -Zach */
916 int mlt_sample_calculator( float fps
, int frequency
, int64_t position
)
920 if ( ( int )( fps
* 100 ) == 2997 )
922 samples
= frequency
/ 30;
927 if ( position
% 5 != 0 )
931 if ( position
% 300 == 0 )
933 else if ( position
% 30 == 0 )
935 else if ( position
% 2 == 0 )
941 if ( position
% 30 == 0 )
943 else if ( position
% 29 == 0 )
945 else if ( position
% 4 == 2 )
956 samples
= frequency
/ fps
;
962 int64_t mlt_sample_calculator_to_now( float fps
, int frequency
, int64_t frame
)
966 // TODO: Correct rules for NTSC and drop the * 100 hack
967 if ( ( int )( fps
* 100 ) == 2997 )
969 samples
= ( ( double )( frame
* frequency
) / 30 );
973 samples
+= 2 * ( frame
/ 5 );
976 samples
+= frame
+ ( frame
/ 2 ) - ( frame
/ 30 ) + ( frame
/ 300 );
979 samples
+= ( 2 * frame
) - ( frame
/ 4 ) - ( frame
/ 29 );
985 samples
= ( ( frame
* frequency
) / ( int )fps
);