[844/906] mixer: give access to the pads at render time

allows us to move the video frame mapping somewhere else
This commit is contained in:
Matthew Waters 2013-11-14 15:08:47 +11:00
parent 4322266b97
commit 63ccd94d1a
6 changed files with 52 additions and 42 deletions

View file

@ -1476,6 +1476,11 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
GstSegment *seg; GstSegment *seg;
guint in_tex; guint in_tex;
GstVideoFrame *in_frame; GstVideoFrame *in_frame;
GstGLMixerFrameData *frame;
frame = g_ptr_array_index (mix->frames, array_index);
frame->pad = pad;
frame->texture = 0;
seg = &mixcol->collect.segment; seg = &mixcol->collect.segment;
@ -1537,13 +1542,12 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
pad->mapped = TRUE; pad->mapped = TRUE;
} }
g_array_index (mix->array_textures, guint, array_index) = in_tex; frame->texture = in_tex;
} }
++array_index; ++array_index;
} }
mix_class->process_textures (mix, mix->array_textures, mix->in_frames, mix_class->process_textures (mix, mix->frames, out_tex);
out_tex);
if (out_gl_wrapped) { if (out_gl_wrapped) {
if (gst_gl_download_perform_with_data (mix->download, out_tex, if (gst_gl_download_perform_with_data (mix->download, out_tex,
@ -2127,15 +2131,18 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
mix->array_buffers = g_ptr_array_new_full (mix->numpads, NULL); mix->array_buffers = g_ptr_array_new_full (mix->numpads, NULL);
mix->in_frames = g_ptr_array_new_full (mix->numpads, NULL); mix->in_frames = g_ptr_array_new_full (mix->numpads, NULL);
mix->array_textures = mix->frames = g_ptr_array_new_full (mix->numpads, NULL);
g_array_sized_new (FALSE, TRUE, sizeof (guint), mix->numpads);
g_ptr_array_set_size (mix->array_buffers, mix->numpads); g_ptr_array_set_size (mix->array_buffers, mix->numpads);
g_ptr_array_set_size (mix->in_frames, mix->numpads); g_ptr_array_set_size (mix->in_frames, mix->numpads);
g_array_set_size (mix->array_textures, mix->numpads); g_ptr_array_set_size (mix->frames, mix->numpads);
for (i = 0; i < mix->numpads; i++) { for (i = 0; i < mix->numpads; i++) {
mix->in_frames->pdata[i] = g_slice_alloc (sizeof (GstVideoFrame)); mix->in_frames->pdata[i] = g_slice_new0 (GstVideoFrame);
}
for (i = 0; i < mix->numpads; i++) {
mix->frames->pdata[i] = g_slice_new0 (GstGLMixerFrameData);
} }
GST_LOG_OBJECT (mix, "starting collectpads"); GST_LOG_OBJECT (mix, "starting collectpads");
@ -2154,9 +2161,13 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
g_slice_free1 (sizeof (GstVideoFrame), mix->in_frames->pdata[i]); g_slice_free1 (sizeof (GstVideoFrame), mix->in_frames->pdata[i]);
} }
for (i = 0; i < mix->numpads; i++) {
g_slice_free1 (sizeof (GstGLMixerFrameData), mix->in_frames->pdata[i]);
}
g_ptr_array_free (mix->array_buffers, TRUE); g_ptr_array_free (mix->array_buffers, TRUE);
g_ptr_array_free (mix->in_frames, TRUE); g_ptr_array_free (mix->in_frames, TRUE);
g_array_free (mix->array_textures, TRUE); g_ptr_array_free (mix->frames, TRUE);
if (mixer_class->reset) if (mixer_class->reset)
mixer_class->reset (mix); mixer_class->reset (mix);

View file

@ -43,6 +43,7 @@ G_BEGIN_DECLS
typedef struct _GstGLMixer GstGLMixer; typedef struct _GstGLMixer GstGLMixer;
typedef struct _GstGLMixerClass GstGLMixerClass; typedef struct _GstGLMixerClass GstGLMixerClass;
typedef struct _GstGLMixerPrivate GstGLMixerPrivate; typedef struct _GstGLMixerPrivate GstGLMixerPrivate;
typedef struct _GstGLMixerFrameData GstGLMixerFrameData;
typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer, typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer,
GstCaps* outcaps); GstCaps* outcaps);
@ -50,7 +51,7 @@ typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix, typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix,
GPtrArray *buffers, GstBuffer *outbuf); GPtrArray *buffers, GstBuffer *outbuf);
typedef gboolean (*GstGLMixerProcessTextures) (GstGLMixer *mix, typedef gboolean (*GstGLMixerProcessTextures) (GstGLMixer *mix,
GArray *in_textures, GPtrArray *in_frames, guint out_tex); GPtrArray *frames, guint out_tex);
struct _GstGLMixer struct _GstGLMixer
{ {
@ -73,8 +74,8 @@ struct _GstGLMixer
gint next_sinkpad; gint next_sinkpad;
GPtrArray *array_buffers; GPtrArray *array_buffers;
GArray *array_textures;
GPtrArray *in_frames; GPtrArray *in_frames;
GPtrArray *frames;
GstVideoInfo out_info; GstVideoInfo out_info;
GLuint out_tex_id; GLuint out_tex_id;
@ -108,6 +109,12 @@ struct _GstGLMixerClass
GstGLMixerProcessTextures process_textures; GstGLMixerProcessTextures process_textures;
}; };
struct _GstGLMixerFrameData
{
GstGLMixerPad *pad;
guint texture;
};
GType gst_gl_mixer_get_type(void); GType gst_gl_mixer_get_type(void);
gboolean gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf); gboolean gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf);

View file

@ -65,7 +65,7 @@ static gboolean gst_gl_mosaic_init_shader (GstGLMixer * mixer,
GstCaps * outcaps); GstCaps * outcaps);
static gboolean gst_gl_mosaic_process_textures (GstGLMixer * mixer, static gboolean gst_gl_mosaic_process_textures (GstGLMixer * mixer,
GArray * in_textures, GPtrArray * in_frames, guint out_tex); GPtrArray * frames, guint out_tex);
static void gst_gl_mosaic_callback (gpointer stuff); static void gst_gl_mosaic_callback (gpointer stuff);
//vertex source //vertex source
@ -135,7 +135,6 @@ static void
gst_gl_mosaic_init (GstGLMosaic * mosaic) gst_gl_mosaic_init (GstGLMosaic * mosaic)
{ {
mosaic->shader = NULL; mosaic->shader = NULL;
mosaic->input_textures = NULL;
mosaic->input_frames = NULL; mosaic->input_frames = NULL;
} }
@ -170,7 +169,6 @@ gst_gl_mosaic_reset (GstGLMixer * mixer)
{ {
GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer); GstGLMosaic *mosaic = GST_GL_MOSAIC (mixer);
mosaic->input_textures = NULL;
mosaic->input_frames = NULL; mosaic->input_frames = NULL;
//blocking call, wait the opengl thread has destroyed the shader //blocking call, wait the opengl thread has destroyed the shader
@ -190,13 +188,12 @@ gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
} }
static gboolean static gboolean
gst_gl_mosaic_process_textures (GstGLMixer * mix, GArray * in_textures, gst_gl_mosaic_process_textures (GstGLMixer * mix, GPtrArray * frames,
GPtrArray * in_frames, guint out_tex) guint out_tex)
{ {
GstGLMosaic *mosaic = GST_GL_MOSAIC (mix); GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
mosaic->input_textures = in_textures; mosaic->input_frames = frames;
mosaic->input_frames = in_frames;
//blocking call, use a FBO //blocking call, use a FBO
gst_gl_context_use_fbo_v2 (mix->context, gst_gl_context_use_fbo_v2 (mix->context,
@ -251,20 +248,20 @@ gst_gl_mosaic_callback (gpointer stuff)
attr_texture_loc = attr_texture_loc =
gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord"); gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");
while (count < mosaic->input_textures->len && count < 6) { while (count < mosaic->input_frames->len && count < 6) {
GstVideoFrame *in_frame; GstGLMixerFrameData *frame;
GLfloat *v_vertices; GLfloat *v_vertices;
guint in_tex; guint in_tex;
guint width, height; guint width, height;
in_frame = g_ptr_array_index (mosaic->input_frames, count); frame = g_ptr_array_index (mosaic->input_frames, count);
in_tex = g_array_index (mosaic->input_textures, guint, count); in_tex = frame->texture;
width = GST_VIDEO_FRAME_WIDTH (in_frame); width = GST_VIDEO_INFO_WIDTH (&frame->pad->in_info);
height = GST_VIDEO_FRAME_HEIGHT (in_frame); height = GST_VIDEO_INFO_HEIGHT (&frame->pad->in_info);
if (!in_frame || !in_tex || width <= 0 || height <= 0) { if (!frame || !in_tex || width <= 0 || height <= 0) {
GST_DEBUG ("skipping texture:%u frame:%p width:%u height %u", GST_DEBUG ("skipping texture:%u frame:%p width:%u height %u",
in_tex, in_frame, width, height); in_tex, frame, width, height);
count++; count++;
continue; continue;
} }

View file

@ -40,7 +40,6 @@ struct _GstGLMosaic
GstGLMixer mixer; GstGLMixer mixer;
GstGLShader *shader; GstGLShader *shader;
GArray *input_textures;
GPtrArray *input_frames; GPtrArray *input_frames;
}; };

View file

@ -65,7 +65,7 @@ static gboolean gst_gl_video_mixer_init_shader (GstGLMixer * mixer,
GstCaps * outcaps); GstCaps * outcaps);
static gboolean gst_gl_video_mixer_process_textures (GstGLMixer * mixer, static gboolean gst_gl_video_mixer_process_textures (GstGLMixer * mixer,
GArray * in_textures, GPtrArray * in_frames, guint out_tex); GPtrArray * in_frames, guint out_tex);
static void gst_gl_video_mixer_callback (gpointer stuff); static void gst_gl_video_mixer_callback (gpointer stuff);
/* vertex source */ /* vertex source */
@ -116,7 +116,6 @@ static void
gst_gl_video_mixer_init (GstGLVideoMixer * video_mixer) gst_gl_video_mixer_init (GstGLVideoMixer * video_mixer)
{ {
video_mixer->shader = NULL; video_mixer->shader = NULL;
video_mixer->input_textures = NULL;
video_mixer->input_frames = NULL; video_mixer->input_frames = NULL;
} }
@ -147,7 +146,6 @@ gst_gl_video_mixer_reset (GstGLMixer * mixer)
{ {
GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mixer); GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mixer);
video_mixer->input_textures = NULL;
video_mixer->input_frames = NULL; video_mixer->input_frames = NULL;
if (video_mixer->shader) if (video_mixer->shader)
@ -165,13 +163,12 @@ gst_gl_video_mixer_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
} }
static gboolean static gboolean
gst_gl_video_mixer_process_textures (GstGLMixer * mix, GArray * in_textures, gst_gl_video_mixer_process_textures (GstGLMixer * mix, GPtrArray * frames,
GPtrArray * in_frames, guint out_tex) guint out_tex)
{ {
GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mix); GstGLVideoMixer *video_mixer = GST_GL_VIDEO_MIXER (mix);
video_mixer->input_textures = in_textures; video_mixer->input_frames = frames;
video_mixer->input_frames = in_frames;
gst_gl_context_use_fbo_v2 (mix->context, gst_gl_context_use_fbo_v2 (mix->context,
GST_VIDEO_INFO_WIDTH (&mix->out_info), GST_VIDEO_INFO_WIDTH (&mix->out_info),
@ -222,21 +219,21 @@ gst_gl_video_mixer_callback (gpointer stuff)
gl->Enable (GL_BLEND); gl->Enable (GL_BLEND);
while (count < video_mixer->input_textures->len) { while (count < video_mixer->input_frames->len) {
GstVideoFrame *in_frame; GstGLMixerFrameData *frame;
GLfloat *v_vertices; GLfloat *v_vertices;
guint in_tex; guint in_tex;
guint in_width, in_height; guint in_width, in_height;
gfloat w, h; gfloat w, h;
in_frame = g_ptr_array_index (video_mixer->input_frames, count); frame = g_ptr_array_index (video_mixer->input_frames, count);
in_tex = g_array_index (video_mixer->input_textures, guint, count); in_tex = frame->texture;
in_width = GST_VIDEO_FRAME_WIDTH (in_frame); in_width = GST_VIDEO_INFO_WIDTH (&frame->pad->in_info);
in_height = GST_VIDEO_FRAME_HEIGHT (in_frame); in_height = GST_VIDEO_INFO_HEIGHT (&frame->pad->in_info);
if (!in_frame || !in_tex || in_width <= 0 || in_height <= 0) { if (!frame || !in_tex || in_width <= 0 || in_height <= 0) {
GST_DEBUG ("skipping texture:%u frame:%p width:%u height %u", GST_DEBUG ("skipping texture:%u frame:%p width:%u height %u",
in_tex, in_frame, in_width, in_height); in_tex, frame, in_width, in_height);
count++; count++;
continue; continue;
} }

View file

@ -40,7 +40,6 @@ struct _GstGLVideoMixer
GstGLMixer mixer; GstGLMixer mixer;
GstGLShader *shader; GstGLShader *shader;
GArray *input_textures;
GPtrArray *input_frames; GPtrArray *input_frames;
}; };