From 91870f6d34bd7a3bbe2e257c268a0645d5daf681 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Wed, 13 Aug 2008 17:59:09 +0200 Subject: [PATCH] [157/906] move thread_do_upload_make from thread_do_upload to thread_init_upload --- gst-libs/gst/gl/gstgldisplay.c | 220 ++++++++++++++++----------------- gst-libs/gst/gl/gstgldisplay.h | 5 +- 2 files changed, 113 insertions(+), 112 deletions(-) diff --git a/gst-libs/gst/gl/gstgldisplay.c b/gst-libs/gst/gl/gstgldisplay.c index 5a4267a020..a1de98ebda 100644 --- a/gst-libs/gst/gl/gstgldisplay.c +++ b/gst-libs/gst/gl/gstgldisplay.c @@ -170,7 +170,7 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass) display->upload_height = 0; display->upload_video_format = 0; display->colorspace_conversion = GST_GL_DISPLAY_CONVERSION_MESA; - display->upload_data_with = 0; + display->upload_data_width = 0; display->upload_data_height = 0; display->upload_data = NULL; @@ -1139,6 +1139,9 @@ gst_gl_display_thread_init_upload (GstGLDisplay *display) g_assert_not_reached (); } + //alloc texture (related to upload) memory only on time + gst_gl_display_thread_do_upload_make (display); + g_cond_signal (display->cond_init_upload); } @@ -1149,8 +1152,6 @@ gst_gl_display_thread_do_upload (GstGLDisplay *display) { glutSetWindow (display->glutWinId); - //FIXME:call upload_make function in thread_init_upload instead of calling it here - gst_gl_display_thread_do_upload_make (display); gst_gl_display_thread_do_upload_fill (display); gst_gl_display_thread_do_upload_draw (display); @@ -2001,12 +2002,15 @@ gst_gl_display_del_texture (GstGLDisplay* display, GLuint texture, GLint width, /* Called by the first gl element of a video/x-raw-gl flow */ void gst_gl_display_init_upload (GstGLDisplay* display, GstVideoFormat video_format, - guint gl_width, guint gl_height) + guint gl_width, guint gl_height, + gint video_width, gint video_height) { gst_gl_display_lock (display); display->upload_video_format = video_format; display->upload_width = gl_width; display->upload_height = gl_height; + display->upload_data_width = video_width; + display->upload_data_height = video_height; gst_gl_display_post_message (GST_GL_DISPLAY_ACTION_INIT_UPLOAD, display); g_cond_wait (display->cond_init_upload, display->mutex); gst_gl_display_unlock (display); @@ -2026,7 +2030,7 @@ gst_gl_display_do_upload (GstGLDisplay *display, GLuint texture, if (isAlive) { display->upload_outtex = texture; - display->upload_data_with = data_width; + display->upload_data_width = data_width; display->upload_data_height = data_height; display->upload_data = data; gst_gl_display_post_message (GST_GL_DISPLAY_ACTION_DO_UPLOAD, display); @@ -2225,116 +2229,112 @@ gst_gl_display_set_client_draw_callback (GstGLDisplay * display, CDCB cb) /* called by gst_gl_display_thread_do_upload (in the gl thread) */ void gst_gl_display_thread_do_upload_make (GstGLDisplay *display) { - gint width = display->upload_data_with; + gint width = display->upload_data_width; gint height = display->upload_data_height; - //FIXME:remove the next check then call this function in thread_init_upload - if (display->upload_intex == 0) + glGenTextures (1, &display->upload_intex); + + glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex); + switch (display->upload_video_format) { - glGenTextures (1, &display->upload_intex); + case GST_VIDEO_FORMAT_RGBx: + case GST_VIDEO_FORMAT_BGRx: + case GST_VIDEO_FORMAT_xRGB: + case GST_VIDEO_FORMAT_xBGR: + case GST_VIDEO_FORMAT_RGBA: + case GST_VIDEO_FORMAT_BGRA: + case GST_VIDEO_FORMAT_ARGB: + case GST_VIDEO_FORMAT_ABGR: + case GST_VIDEO_FORMAT_AYUV: + glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, + width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + break; - glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex); - switch (display->upload_video_format) + case GST_VIDEO_FORMAT_RGB: + case GST_VIDEO_FORMAT_BGR: + glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, + width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + break; + + case GST_VIDEO_FORMAT_YUY2: + switch (display->colorspace_conversion) { - case GST_VIDEO_FORMAT_RGBx: - case GST_VIDEO_FORMAT_BGRx: - case GST_VIDEO_FORMAT_xRGB: - case GST_VIDEO_FORMAT_xBGR: - case GST_VIDEO_FORMAT_RGBA: - case GST_VIDEO_FORMAT_BGRA: - case GST_VIDEO_FORMAT_ARGB: - case GST_VIDEO_FORMAT_ABGR: - case GST_VIDEO_FORMAT_AYUV: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, - width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - break; - - case GST_VIDEO_FORMAT_RGB: - case GST_VIDEO_FORMAT_BGR: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, - width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - break; - - case GST_VIDEO_FORMAT_YUY2: - switch (display->colorspace_conversion) - { - case GST_GL_DISPLAY_CONVERSION_GLSL: - case GST_GL_DISPLAY_CONVERSION_MATRIX: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA, - width, height, - 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); - - if (display->upload_intex_u == 0) { - glGenTextures (1, &display->upload_intex_u); - glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u); - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, - width, height, - 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); - } - break; - case GST_GL_DISPLAY_CONVERSION_MESA: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, - width, height, - 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL); - break; - default: - g_assert_not_reached (); - } - break; - case GST_VIDEO_FORMAT_UYVY: - switch (display->colorspace_conversion) - { - case GST_GL_DISPLAY_CONVERSION_GLSL: - case GST_GL_DISPLAY_CONVERSION_MATRIX: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA, - width, height, - 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); - if (display->upload_intex_u == 0) { - glGenTextures (1, &display->upload_intex_u); - glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u); - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, - width, height, - 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); - break; - } - case GST_GL_DISPLAY_CONVERSION_MESA: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, - width, height, - 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL); - break; - default: - g_assert_not_reached (); - } - break; - - case GST_VIDEO_FORMAT_I420: - case GST_VIDEO_FORMAT_YV12: - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE, - width, height, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); - - if (display->upload_intex_u == 0) { - glGenTextures (1, &display->upload_intex_u); - glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u); - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE, - GST_ROUND_UP_2 (width) / 2, - GST_ROUND_UP_2 (height) / 2, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); - } - - if (display->upload_intex_v == 0) { - glGenTextures (1, &display->upload_intex_v); - glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v); - glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE, - GST_ROUND_UP_2 (width) / 2, - GST_ROUND_UP_2 (height) / 2, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); - } - break; + case GST_GL_DISPLAY_CONVERSION_GLSL: + case GST_GL_DISPLAY_CONVERSION_MATRIX: +glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA, + width, height, + 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); +if (display->upload_intex_u == 0) { + glGenTextures (1, &display->upload_intex_u); + glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u); + glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, + width, height, + 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); +} +break; + case GST_GL_DISPLAY_CONVERSION_MESA: +glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, + width, height, + 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL); +break; default: - g_assert_not_reached (); +g_assert_not_reached (); } + break; + case GST_VIDEO_FORMAT_UYVY: + switch (display->colorspace_conversion) + { + case GST_GL_DISPLAY_CONVERSION_GLSL: + case GST_GL_DISPLAY_CONVERSION_MATRIX: +glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE_ALPHA, + width, height, + 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); +if (display->upload_intex_u == 0) { + glGenTextures (1, &display->upload_intex_u); + glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u); + glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, + width, height, + 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); + break; +} + case GST_GL_DISPLAY_CONVERSION_MESA: +glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, + width, height, + 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL); +break; + default: +g_assert_not_reached (); + } + break; + + case GST_VIDEO_FORMAT_I420: + case GST_VIDEO_FORMAT_YV12: + glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE, + width, height, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); + + if (display->upload_intex_u == 0) { +glGenTextures (1, &display->upload_intex_u); +glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_u); +glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE, + GST_ROUND_UP_2 (width) / 2, + GST_ROUND_UP_2 (height) / 2, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); + } + + if (display->upload_intex_v == 0) { +glGenTextures (1, &display->upload_intex_v); +glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->upload_intex_v); +glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_LUMINANCE, + GST_ROUND_UP_2 (width) / 2, + GST_ROUND_UP_2 (height) / 2, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL); + } + break; + + default: + g_assert_not_reached (); } } @@ -2343,7 +2343,7 @@ void gst_gl_display_thread_do_upload_make (GstGLDisplay *display) void gst_gl_display_thread_do_upload_fill (GstGLDisplay *display) { - gint width = display->upload_data_with; + gint width = display->upload_data_width; gint height = display->upload_data_height; gpointer data = display->upload_data; @@ -2615,13 +2615,13 @@ gst_gl_display_thread_do_upload_draw (GstGLDisplay *display) }//end switch display->currentVideo_format glBegin (GL_QUADS); - glTexCoord2i (display->upload_data_with, 0); + glTexCoord2i (display->upload_data_width, 0); glVertex2f (1.0f, -1.0f); glTexCoord2i (0, 0); glVertex2f (-1.0f, -1.0f); glTexCoord2i (0, display->upload_data_height); glVertex2f (-1.0f, 1.0f); - glTexCoord2i (display->upload_data_with, display->upload_data_height); + glTexCoord2i (display->upload_data_width, display->upload_data_height); glVertex2f (1.0f, 1.0f); glEnd (); diff --git a/gst-libs/gst/gl/gstgldisplay.h b/gst-libs/gst/gl/gstgldisplay.h index bc364dc314..cd65dcf858 100644 --- a/gst-libs/gst/gl/gstgldisplay.h +++ b/gst-libs/gst/gl/gstgldisplay.h @@ -175,7 +175,7 @@ struct _GstGLDisplay { GLuint upload_height; GstVideoFormat upload_video_format; GstGLDisplayConversion colorspace_conversion; - gint upload_data_with; + gint upload_data_width; gint upload_data_height; gpointer upload_data; @@ -278,7 +278,8 @@ void gst_gl_display_gen_texture (GstGLDisplay* display, GLuint* pTexture, GLint void gst_gl_display_del_texture (GstGLDisplay* display, GLuint texture, GLint width, GLint height); void gst_gl_display_init_upload (GstGLDisplay* display, GstVideoFormat video_format, - guint gl_width, guint gl_height); + guint gl_width, guint gl_height, + gint video_width, gint video_height); gboolean gst_gl_display_do_upload (GstGLDisplay* display, GLuint texture, gint data_width, gint data_height, gpointer data);