]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_frame.c
fix possible crash in mlt_frame_get_waveform
[mlt] / src / framework / mlt_frame.c
index d1e0373654ec8d70d6ae68ad3031237203354712..677a51610527f97ba6d94025d43c187a64ccc013 100644 (file)
@@ -41,7 +41,7 @@
 mlt_frame mlt_frame_init( mlt_service service )
 {
        // Allocate a frame
-       mlt_frame self = calloc( sizeof( struct mlt_frame_s ), 1 );
+       mlt_frame self = calloc( 1, sizeof( struct mlt_frame_s ) );
 
        if ( self != NULL )
        {
@@ -131,10 +131,15 @@ int mlt_frame_set_aspect_ratio( mlt_frame self, double value )
 }
 
 /** Get the time position of this frame.
+ *
+ * This position is not necessarily the position as the original
+ * producer knows it. It could be the position that the playlist,
+ * multitrack, or tractor producer set.
  *
  * \public \memberof mlt_frame_s
  * \param self a frame
  * \return the position
+ * \see mlt_frame_original_position
  */
 
 mlt_position mlt_frame_get_position( mlt_frame self )
@@ -143,6 +148,21 @@ mlt_position mlt_frame_get_position( mlt_frame self )
        return pos < 0 ? 0 : pos;
 }
 
+/** Get the original time position of this frame.
+ *
+ * This is the position that the original producer set on the frame.
+ *
+ * \public \memberof mlt_frame_s
+ * \param self a frame
+ * \return the position
+ */
+
+mlt_position mlt_frame_original_position( mlt_frame self )
+{
+       int pos = mlt_properties_get_position( MLT_FRAME_PROPERTIES( self ), "original_position" );
+       return pos < 0 ? 0 : pos;
+}
+
 /** Set the time position of this frame.
  *
  * \public \memberof mlt_frame_s
@@ -153,6 +173,9 @@ mlt_position mlt_frame_get_position( mlt_frame self )
 
 int mlt_frame_set_position( mlt_frame self, mlt_position value )
 {
+       // Only set the original_position the first time.
+       if ( ! mlt_properties_get( MLT_FRAME_PROPERTIES( self ), "original_position" ) )
+               mlt_properties_set_position( MLT_FRAME_PROPERTIES( self ), "original_position", value );
        return mlt_properties_set_position( MLT_FRAME_PROPERTIES( self ), "_position", value );
 }
 
@@ -798,6 +821,8 @@ unsigned char *mlt_frame_get_waveform( mlt_frame self, int w, int h )
 
        // Make an 8-bit buffer large enough to hold rendering
        int size = w * h;
+       if ( size <= 0 )
+               return NULL;
        unsigned char *bitmap = ( unsigned char* )mlt_pool_alloc( size );
        if ( bitmap != NULL )
                memset( bitmap, 0, size );