Hi,

data for overlay image converted from RGBA to YUV422 for each frame. attached patch save converted image of *pixbuf* producer to avoid converting it to profile format each time it require to produce resulting frame.

with that patch and previous SSE2 patches it possible to put full hd logo on video without dropped frame.

it is draft version with leak on exit but it could answer the question if it is a right approach for solving problem with image converted to desired format once per frame instead of once per load/format_change.

--
________________________________________
Maksym Veremeyenko
>From 94f0d6dbd3141ea1461e92b0055de3dddf686583 Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1stereo.tv>
Date: Tue, 14 Feb 2012 18:20:29 +0200
Subject: [PATCH 1/2] implement mlt_frame_get_image_data and
 mlt_frame_get_alpha_data

---
 src/framework/mlt_frame.c |   10 ++++++++++
 src/framework/mlt_frame.h |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c
index 6125929..d08c5cb 100644
--- a/src/framework/mlt_frame.c
+++ b/src/framework/mlt_frame.c
@@ -310,6 +310,11 @@ int mlt_frame_set_image( mlt_frame self, uint8_t *image, int size, mlt_destructo
 	return mlt_properties_set_data( MLT_FRAME_PROPERTIES( self ), "image", image, size, destroy, NULL );
 }
 
+void* mlt_frame_get_image_data( mlt_frame self, int *size )
+{
+	return mlt_properties_get_data( MLT_FRAME_PROPERTIES( self ), "image", size );
+}
+
 /** Set a new alpha channel on the frame.
   *
   * \public \memberof mlt_frame_s
@@ -325,6 +330,11 @@ int mlt_frame_set_alpha( mlt_frame self, uint8_t *alpha, int size, mlt_destructo
 	return mlt_properties_set_data( MLT_FRAME_PROPERTIES( self ), "alpha", alpha, size, destroy, NULL );
 }
 
+void* mlt_frame_get_alpha_data( mlt_frame self, int *size )
+{
+	return mlt_properties_get_data( MLT_FRAME_PROPERTIES( self ), "alpha", size );
+}
+
 /** Replace image stack with the information provided.
  *
  * This might prove to be unreliable and restrictive - the idea is that a transition
diff --git a/src/framework/mlt_frame.h b/src/framework/mlt_frame.h
index 144d867..4eaf0ce 100644
--- a/src/framework/mlt_frame.h
+++ b/src/framework/mlt_frame.h
@@ -118,8 +118,10 @@ extern mlt_position mlt_frame_get_position( mlt_frame self );
 extern int mlt_frame_set_position( mlt_frame self, mlt_position value );
 extern int mlt_frame_set_image( mlt_frame self, uint8_t *image, int size, mlt_destructor destroy );
 extern int mlt_frame_set_alpha( mlt_frame self, uint8_t *alpha, int size, mlt_destructor destroy );
+extern void* mlt_frame_get_alpha_data( mlt_frame self, int *size );
 extern void mlt_frame_replace_image( mlt_frame self, uint8_t *image, mlt_image_format format, int width, int height );
 extern int mlt_frame_get_image( mlt_frame self, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable );
+extern void* mlt_frame_get_image_data( mlt_frame self, int *size );
 extern uint8_t *mlt_frame_get_alpha_mask( mlt_frame self );
 extern int mlt_frame_get_audio( mlt_frame self, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples );
 extern int mlt_frame_set_audio( mlt_frame self, void *buffer, mlt_audio_format, int size, mlt_destructor );
-- 
1.7.7.6

>From 815d08b838e84afbbb4f74a08af394e2240c37b0 Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <ve...@m1stereo.tv>
Date: Tue, 14 Feb 2012 18:47:11 +0200
Subject: [PATCH 2/2] save converted image for next use

---
 src/modules/gtk2/producer_pixbuf.c |   80 +++++++++++++++++++++++++++++++----
 1 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/src/modules/gtk2/producer_pixbuf.c b/src/modules/gtk2/producer_pixbuf.c
index b7da50b..f2acc28 100644
--- a/src/modules/gtk2/producer_pixbuf.c
+++ b/src/modules/gtk2/producer_pixbuf.c
@@ -59,6 +59,13 @@ struct producer_pixbuf_s
 	uint8_t *image;
 	mlt_cache_item image_cache;
 	pthread_mutex_t mutex;
+	struct
+	{
+		uint8_t *image;
+		uint8_t *alpha;
+		mlt_image_format format;
+		int size[2];
+	} clone;
 };
 
 static void load_filenames( producer_pixbuf self, mlt_properties producer_properties );
@@ -391,6 +398,11 @@ static void refresh_image( producer_pixbuf self, mlt_frame frame, int width, int
 		int dst_stride = self->width * ( self->alpha ? 4 : 3 );
 		int image_size = dst_stride * ( height + 1 );
 		self->image = mlt_pool_alloc( image_size );
+		if( self->clone.image )
+		{
+			mlt_pool_release( self->clone.image );
+			self->clone.image = NULL;
+		};
 
 		if ( src_stride != dst_stride )
 		{
@@ -454,7 +466,8 @@ static void refresh_image( producer_pixbuf self, mlt_frame frame, int width, int
 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
 {
 	int error = 0;
-	
+	mlt_image_format format_origin;
+
 	// Obtain properties of frame
 	mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
 
@@ -472,20 +485,67 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
 	// Get width and height (may have changed during the refresh)
 	*width = self->width;
 	*height = self->height;
-	*format = self->alpha ? mlt_image_rgb24a : mlt_image_rgb24;
+	format_origin = self->alpha ? mlt_image_rgb24a : mlt_image_rgb24;
+	if ( mlt_image_none == *format)
+		*format = format_origin;
 
 	// NB: Cloning is necessary with this producer (due to processing of images ahead of use)
 	// The fault is not in the design of mlt, but in the implementation of the pixbuf producer...
 	if ( self->image )
 	{
-		// Clone the image
-		int image_size = self->width * self->height * ( self->alpha ? 4 :3 );
-		uint8_t *image_copy = mlt_pool_alloc( image_size );
-		memcpy( image_copy, self->image, image_size );
-		// Now update properties so we free the copy after
-		mlt_frame_set_image( frame, image_copy, image_size, mlt_pool_release );
-		// We're going to pass the copy on
-		*buffer = image_copy;
+		uint8_t* image;
+		int size;
+
+		if ( !self->clone.image || self->clone.format != *format )
+		{
+			if( self->clone.image )
+				mlt_pool_release( self->clone.image );
+			if( self->clone.alpha )
+				mlt_pool_release( self->clone.alpha );
+			self->clone.alpha = NULL;
+
+			// Clone the image
+			size = self->width * self->height * ( self->alpha ? 4 :3 );
+			image = mlt_pool_alloc( size );
+			memcpy( image, self->image, size );
+
+			// Now update properties so we free the copy after
+			mlt_frame_set_image( frame, image, size, mlt_pool_release );
+
+			// convert image
+			if(frame->convert_image && format_origin != *format)
+			{
+				frame->convert_image( frame, &image, &format_origin, *format );
+				*format = format_origin;
+			}
+
+			// request and save converted image
+			self->clone.format = *format;
+			image = mlt_frame_get_image_data( frame, &self->clone.size[0]);
+			*buffer = self->clone.image = mlt_pool_alloc( self->clone.size[0] );
+			memcpy( self->clone.image, image, self->clone.size[0] );
+			image = mlt_frame_get_alpha_data( frame, &self->clone.size[1]);
+			if ( image )
+			{
+				self->clone.alpha = mlt_pool_alloc( self->clone.size[1] );
+				memcpy( self->clone.alpha, image, self->clone.size[1] );
+			}
+		}
+		else
+		{
+			// clone again
+			*buffer = image = mlt_pool_alloc( self->clone.size[0] );
+			memcpy( image, self->clone.image, self->clone.size[0] );
+			// Now update properties so we free the copy after
+			mlt_frame_set_image( frame, image, self->clone.size[0], mlt_pool_release );
+			if ( self->clone.alpha )
+			{
+				image = mlt_pool_alloc( self->clone.size[1] );
+				memcpy( image, self->clone.alpha, self->clone.size[1] );
+				mlt_frame_set_alpha( frame, image, self->clone.size[1], mlt_pool_release );
+			};
+		};
+
 		mlt_log_debug( MLT_PRODUCER_SERVICE( &self->parent ), "%dx%d (%s)\n",
 			self->width, self->height, mlt_image_format_name( *format ) );
 	}
-- 
1.7.7.6

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Mlt-devel mailing list
Mlt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlt-devel

Reply via email to