]> git.sesse.net Git - mlt/commitdiff
enhance mlt_frame_clone with a deep/shallow parameter
authorDan Dennedy <dan@dennedy.org>
Sun, 20 Nov 2011 00:39:00 +0000 (16:39 -0800)
committerDan Dennedy <dan@dennedy.org>
Sun, 20 Nov 2011 00:39:00 +0000 (16:39 -0800)
src/framework/mlt_frame.c
src/framework/mlt_frame.h
src/modules/core/consumer_multi.c

index fec200edd40969aa95c698f24376a91d58c76dfb..d0d8e0a438291e3af84eeae17d97bfdd1b7ce988 100644 (file)
@@ -985,11 +985,13 @@ mlt_properties mlt_frame_unique_properties( mlt_frame self, mlt_service service
  *
  * \public \memberof mlt_frame_s
  * \param self the frame to clone
+ * \param is_deep a boolean to indicate whether to make a deep copy of the audio
+ * and video data chunks or to make a shallow copy by pointing to the supplied frame
  * \return a almost-complete copy of the frame
  * \todo copy the processing deques
  */
 
-mlt_frame mlt_frame_clone( mlt_frame self )
+mlt_frame mlt_frame_clone( mlt_frame self, int is_deep )
 {
        mlt_frame new_frame = mlt_frame_init( NULL );
        mlt_properties properties = MLT_FRAME_PROPERTIES( self );
@@ -997,17 +999,31 @@ mlt_frame mlt_frame_clone( mlt_frame self )
        void *data;
        int size;
 
-       // This frame takes a reference on the original frame since the data is a shallow copy.
-       mlt_properties_inc_ref( properties );
-       mlt_properties_set_data( new_props, "_cloned_frame", self, 0,
-               (mlt_destructor) mlt_frame_close, NULL );
-
-       // Copy properties
        mlt_properties_inherit( new_props, properties );
-       data = mlt_properties_get_data( properties, "audio", &size );
-       mlt_properties_set_data( new_props, "audio", data, size, NULL, NULL );
-       data = mlt_properties_get_data( properties, "image", &size );
-       mlt_properties_set_data( new_props, "image", data, size, NULL, NULL );
+       if ( is_deep )
+       {
+               data = mlt_properties_get_data( properties, "audio", &size );
+               void *copy = mlt_pool_alloc( size );
+               memcpy( copy, data, size );
+               mlt_properties_set_data( new_props, "audio", copy, size, mlt_pool_release, NULL );
+               data = mlt_properties_get_data( properties, "image", &size );
+               copy = mlt_pool_alloc( size );
+               memcpy( copy, data, size );
+               mlt_properties_set_data( new_props, "image", copy, size, mlt_pool_release, NULL );
+       }
+       else
+       {
+               // This frame takes a reference on the original frame since the data is a shallow copy.
+               mlt_properties_inc_ref( properties );
+               mlt_properties_set_data( new_props, "_cloned_frame", self, 0,
+                       (mlt_destructor) mlt_frame_close, NULL );
+
+               // Copy properties
+               data = mlt_properties_get_data( properties, "audio", &size );
+               mlt_properties_set_data( new_props, "audio", data, size, NULL, NULL );
+               data = mlt_properties_get_data( properties, "image", &size );
+               mlt_properties_set_data( new_props, "image", data, size, NULL, NULL );
+       }
 
        return new_frame;
 }
index 226f6148604045b84256693261ee66d605bc1793..144d867d0a2fd529e293a96c00eeba4a1b81cef8 100644 (file)
@@ -138,7 +138,7 @@ extern mlt_deque mlt_frame_service_stack( mlt_frame self );
 extern mlt_producer mlt_frame_get_original_producer( mlt_frame self );
 extern void mlt_frame_close( mlt_frame self );
 extern mlt_properties mlt_frame_unique_properties( mlt_frame self, mlt_service service );
-extern mlt_frame mlt_frame_clone( mlt_frame self );
+extern mlt_frame mlt_frame_clone( mlt_frame self, int is_deep );
 
 /* convenience functions */
 extern int mlt_sample_calculator( float fps, int frequency, int64_t position );
index da629784652f1a28a5ab20995e187fd1878ed2b1..86e17d08d73e9c8916113e65591075a285b9af6a 100644 (file)
@@ -261,7 +261,7 @@ static void foreach_consumer_put( mlt_consumer consumer, mlt_frame frame )
        do {
                snprintf( key, sizeof(key), "%d.consumer", index++ );
                nested = mlt_properties_get_data( properties, key, NULL );
-               if ( nested ) mlt_consumer_put_frame( nested, mlt_frame_clone( frame ) );
+               if ( nested ) mlt_consumer_put_frame( nested, mlt_frame_clone( frame, 0 ) );
        } while ( nested );
 }