[873/906] upload: use GstVideoInfo for choosing the format

This commit is contained in:
Matthew Waters 2014-01-29 19:14:54 +11:00
parent a2abc0d3b6
commit 4386cc1c6b
6 changed files with 73 additions and 99 deletions

View file

@ -901,9 +901,8 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
if (!filter->upload) { if (!filter->upload) {
filter->upload = gst_gl_upload_new (filter->context); filter->upload = gst_gl_upload_new (filter->context);
gst_gl_upload_init_format (filter->upload, gst_gl_upload_init_format (filter->upload, filter->in_info,
GST_VIDEO_INFO_FORMAT (&filter->in_info), in_width, in_height, filter->out_info);
out_width, out_height);
} }
//blocking call, generate a FBO //blocking call, generate a FBO
if (!gst_gl_context_gen_fbo (filter->context, out_width, out_height, if (!gst_gl_context_gen_fbo (filter->context, out_width, out_height,

View file

@ -130,9 +130,14 @@ _gl_mem_map (GstGLMemory * gl_mem, gsize maxsize, GstMapFlags flags)
if (GST_GL_MEMORY_FLAG_IS_SET (gl_mem, GST_GL_MEMORY_FLAG_NEED_UPLOAD)) { if (GST_GL_MEMORY_FLAG_IS_SET (gl_mem, GST_GL_MEMORY_FLAG_NEED_UPLOAD)) {
if (!GST_GL_MEMORY_FLAG_IS_SET (gl_mem, if (!GST_GL_MEMORY_FLAG_IS_SET (gl_mem,
GST_GL_MEMORY_FLAG_UPLOAD_INITTED)) { GST_GL_MEMORY_FLAG_UPLOAD_INITTED)) {
if (!gst_gl_upload_init_format (gl_mem->upload, gl_mem->v_format, GstVideoInfo in_info, out_info;
gl_mem->width, gl_mem->height, gl_mem->width,
gl_mem->height)) { gst_video_info_set_format (&in_info, gl_mem->v_format, gl_mem->width,
gl_mem->height);
gst_video_info_set_format (&out_info, GST_VIDEO_FORMAT_RGBA,
gl_mem->width, gl_mem->height);
if (!gst_gl_upload_init_format (gl_mem->upload, in_info, out_info)) {
goto error; goto error;
} }
GST_GL_MEMORY_FLAG_SET (gl_mem, GST_GL_MEMORY_FLAG_UPLOAD_INITTED); GST_GL_MEMORY_FLAG_SET (gl_mem, GST_GL_MEMORY_FLAG_UPLOAD_INITTED);

View file

@ -1576,9 +1576,6 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
GstSegment *seg; GstSegment *seg;
guint in_tex; guint in_tex;
GstGLMixerFrameData *frame; GstGLMixerFrameData *frame;
GstVideoFormat in_format;
guint in_width, in_height, out_width, out_height;
frame = g_ptr_array_index (mix->frames, array_index); frame = g_ptr_array_index (mix->frames, array_index);
frame->pad = pad; frame->pad = pad;
@ -1595,19 +1592,13 @@ gst_gl_mixer_process_textures (GstGLMixer * mix, GstBuffer * outbuf)
if (GST_CLOCK_TIME_IS_VALID (stream_time)) if (GST_CLOCK_TIME_IS_VALID (stream_time))
gst_object_sync_values (GST_OBJECT (pad), stream_time); gst_object_sync_values (GST_OBJECT (pad), stream_time);
in_format = GST_VIDEO_INFO_FORMAT (&pad->in_info);
in_width = GST_VIDEO_INFO_WIDTH (&pad->in_info);
in_height = GST_VIDEO_INFO_HEIGHT (&pad->in_info);
out_width = GST_VIDEO_INFO_WIDTH (&mix->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&mix->out_info);
if (!pad->upload) { if (!pad->upload) {
pad->upload = gst_gl_upload_new (mix->context); pad->upload = gst_gl_upload_new (mix->context);
if (!gst_gl_upload_init_format (pad->upload, in_format, if (!gst_gl_upload_init_format (pad->upload, pad->in_info,
in_width, in_height, out_width, out_height)) { mix->out_info)) {
GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND, GST_ELEMENT_ERROR (mix, RESOURCE, NOT_FOUND, ("%s",
("%s", "Failed to init upload format"), (NULL)); "Failed to init upload format"), (NULL));
res = FALSE; res = FALSE;
goto out; goto out;
} }

View file

@ -365,6 +365,8 @@ static const gchar *text_vertex_shader_gles2 =
struct TexData struct TexData
{ {
guint internal_format, format, type, width, height; guint internal_format, format, type, width, height;
guint tex_scaling[2];
const gchar *name;
}; };
struct _GstGLUploadPrivate struct _GstGLUploadPrivate
@ -428,8 +430,6 @@ gst_gl_upload_init (GstGLUpload * upload)
upload->shader_attr_position_loc = 0; upload->shader_attr_position_loc = 0;
upload->shader_attr_texture_loc = 0; upload->shader_attr_texture_loc = 0;
gst_video_info_init (&upload->info);
} }
/** /**
@ -523,16 +523,13 @@ gst_gl_upload_finalize (GObject * object)
static gboolean static gboolean
_gst_gl_upload_init_format_unlocked (GstGLUpload * upload, _gst_gl_upload_init_format_unlocked (GstGLUpload * upload,
GstVideoFormat v_format, guint in_width, guint in_height, guint out_width, GstVideoInfo in_info, GstVideoInfo out_info)
guint out_height)
{ {
GstVideoInfo info;
g_return_val_if_fail (upload != NULL, FALSE); g_return_val_if_fail (upload != NULL, FALSE);
g_return_val_if_fail (v_format != GST_VIDEO_FORMAT_UNKNOWN, FALSE); g_return_val_if_fail (GST_VIDEO_INFO_FORMAT (&in_info) !=
g_return_val_if_fail (v_format != GST_VIDEO_FORMAT_ENCODED, FALSE); GST_VIDEO_FORMAT_UNKNOWN, FALSE);
g_return_val_if_fail (in_width > 0 && in_height > 0, FALSE); g_return_val_if_fail (GST_VIDEO_INFO_FORMAT (&in_info) !=
g_return_val_if_fail (out_width > 0 && out_height > 0, FALSE); GST_VIDEO_FORMAT_ENCODED, FALSE);
if (upload->initted) { if (upload->initted) {
return FALSE; return FALSE;
@ -540,11 +537,8 @@ _gst_gl_upload_init_format_unlocked (GstGLUpload * upload,
upload->initted = TRUE; upload->initted = TRUE;
} }
gst_video_info_set_format (&info, v_format, out_width, out_height); upload->in_info = in_info;
upload->out_info = out_info;
upload->info = info;
upload->in_width = in_width;
upload->in_height = in_height;
gst_gl_context_thread_add (upload->context, gst_gl_context_thread_add (upload->context,
(GstGLContextThreadFunc) _init_upload, upload); (GstGLContextThreadFunc) _init_upload, upload);
@ -556,26 +550,22 @@ _gst_gl_upload_init_format_unlocked (GstGLUpload * upload,
/** /**
* gst_gl_upload_init_format: * gst_gl_upload_init_format:
* @upload: a #GstGLUpload * @upload: a #GstGLUpload
* @v_format: a #GstVideoFormat * @in_info: input #GstVideoInfo
* @in_width: the width of the data to upload * @out_info: output #GstVideoInfo
* @in_height: the height of the data to upload
* @out_width: the width to upload to
* @out_height: the height to upload to
* *
* Initializes @upload with the information required for upload. * Initializes @upload with the information required for upload.
* *
* Returns: whether the initialization was successful * Returns: whether the initialization was successful
*/ */
gboolean gboolean
gst_gl_upload_init_format (GstGLUpload * upload, GstVideoFormat v_format, gst_gl_upload_init_format (GstGLUpload * upload, GstVideoInfo in_info,
guint in_width, guint in_height, guint out_width, guint out_height) GstVideoInfo out_info)
{ {
gboolean ret; gboolean ret;
g_mutex_lock (&upload->lock); g_mutex_lock (&upload->lock);
ret = _gst_gl_upload_init_format_unlocked (upload, v_format, in_width, ret = _gst_gl_upload_init_format_unlocked (upload, in_info, out_info);
in_height, out_width, out_height);
g_mutex_unlock (&upload->lock); g_mutex_unlock (&upload->lock);
@ -611,7 +601,7 @@ gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer,
if (gst_is_gl_memory (mem)) { if (gst_is_gl_memory (mem)) {
GST_LOG_OBJECT (upload, "Attempting upload with GstGLMemory"); GST_LOG_OBJECT (upload, "Attempting upload with GstGLMemory");
/* Assuming only one memory */ /* Assuming only one memory */
if (!gst_video_frame_map (&upload->priv->frame, &upload->info, buffer, if (!gst_video_frame_map (&upload->priv->frame, &upload->in_info, buffer,
GST_MAP_READ | GST_MAP_GL)) { GST_MAP_READ | GST_MAP_GL)) {
GST_ERROR_OBJECT (upload, "Failed to map memory"); GST_ERROR_OBJECT (upload, "Failed to map memory");
return FALSE; return FALSE;
@ -625,9 +615,9 @@ gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer,
if (!upload->priv->tex_id) if (!upload->priv->tex_id)
gst_gl_context_gen_texture (upload->context, &upload->priv->tex_id, gst_gl_context_gen_texture (upload->context, &upload->priv->tex_id,
GST_VIDEO_INFO_FORMAT (&upload->info), GST_VIDEO_INFO_FORMAT (&upload->in_info),
GST_VIDEO_INFO_WIDTH (&upload->info), GST_VIDEO_INFO_WIDTH (&upload->in_info),
GST_VIDEO_INFO_HEIGHT (&upload->info)); GST_VIDEO_INFO_HEIGHT (&upload->in_info));
/* GstVideoGLTextureUploadMeta */ /* GstVideoGLTextureUploadMeta */
gl_tex_upload_meta = gst_buffer_get_video_gl_texture_upload_meta (buffer); gl_tex_upload_meta = gst_buffer_get_video_gl_texture_upload_meta (buffer);
@ -635,11 +625,6 @@ gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer,
guint texture_ids[] = { 0, 0, 0, 0 }; guint texture_ids[] = { 0, 0, 0, 0 };
GST_LOG_OBJECT (upload, "Attempting upload with " GST_LOG_OBJECT (upload, "Attempting upload with "
"GstVideoGLTextureUploadMeta"); "GstVideoGLTextureUploadMeta");
if (!upload->priv->tex_id)
gst_gl_context_gen_texture (upload->context, &upload->priv->tex_id,
GST_VIDEO_FORMAT_RGBA, GST_VIDEO_INFO_WIDTH (&upload->info),
GST_VIDEO_INFO_HEIGHT (&upload->info));
texture_ids[0] = upload->priv->tex_id; texture_ids[0] = upload->priv->tex_id;
if (!gst_gl_upload_perform_with_gl_texture_upload_meta (upload, if (!gst_gl_upload_perform_with_gl_texture_upload_meta (upload,
@ -655,7 +640,7 @@ gst_gl_upload_perform_with_buffer (GstGLUpload * upload, GstBuffer * buffer,
GST_LOG_OBJECT (upload, "Attempting upload with raw data"); GST_LOG_OBJECT (upload, "Attempting upload with raw data");
/* GstVideoMeta map */ /* GstVideoMeta map */
if (!gst_video_frame_map (&upload->priv->frame, &upload->info, buffer, if (!gst_video_frame_map (&upload->priv->frame, &upload->in_info, buffer,
GST_MAP_READ)) { GST_MAP_READ)) {
GST_ERROR_OBJECT (upload, "Failed to map memory"); GST_ERROR_OBJECT (upload, "Failed to map memory");
return FALSE; return FALSE;
@ -688,12 +673,9 @@ _upload_memory_unlocked (GstGLUpload * upload, GstGLMemory * gl_mem,
guint i; guint i;
gboolean ret; gboolean ret;
upload->in_width = GST_VIDEO_INFO_WIDTH (&upload->info); for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->in_info); i++) {
upload->in_height = GST_VIDEO_INFO_HEIGHT (&upload->info);
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->info); i++) {
data[i] = (guint8 *) gl_mem->data + data[i] = (guint8 *) gl_mem->data +
GST_VIDEO_INFO_PLANE_OFFSET (&upload->info, i); GST_VIDEO_INFO_PLANE_OFFSET (&upload->in_info, i);
} }
ret = _gst_gl_upload_perform_with_data_unlocked (upload, tex_id, data); ret = _gst_gl_upload_perform_with_data_unlocked (upload, tex_id, data);
@ -749,7 +731,7 @@ static gboolean
_do_upload_for_meta (GstGLUpload * upload, GstVideoGLTextureUploadMeta * meta) _do_upload_for_meta (GstGLUpload * upload, GstVideoGLTextureUploadMeta * meta)
{ {
GstVideoMeta *v_meta; GstVideoMeta *v_meta;
GstVideoInfo info; GstVideoInfo in_info, out_info;
GstVideoFrame frame; GstVideoFrame frame;
GstMemory *mem; GstMemory *mem;
gboolean ret; gboolean ret;
@ -770,8 +752,10 @@ _do_upload_for_meta (GstGLUpload * upload, GstVideoGLTextureUploadMeta * meta)
width = v_meta->width; width = v_meta->width;
height = v_meta->height; height = v_meta->height;
if (!_gst_gl_upload_init_format_unlocked (upload, v_format, width, height, gst_video_info_set_format (&in_info, v_format, width, height);
width, height)) gst_video_info_set_format (&out_info, GST_VIDEO_FORMAT_RGBA, width, height);
if (!_gst_gl_upload_init_format_unlocked (upload, in_info, out_info))
return FALSE; return FALSE;
} }
@ -791,10 +775,14 @@ _do_upload_for_meta (GstGLUpload * upload, GstVideoGLTextureUploadMeta * meta)
return TRUE; return TRUE;
} }
gst_video_info_set_format (&info, v_meta->format, v_meta->width, if (v_meta == NULL)
return FALSE;
gst_video_info_set_format (&in_info, v_meta->format, v_meta->width,
v_meta->height); v_meta->height);
if (!gst_video_frame_map (&frame, &info, upload->priv->buffer, GST_MAP_READ)) { if (!gst_video_frame_map (&frame, &in_info, upload->priv->buffer,
GST_MAP_READ)) {
GST_ERROR ("failed to map video frame"); GST_ERROR ("failed to map video frame");
return FALSE; return FALSE;
} }
@ -939,7 +927,7 @@ gst_gl_upload_add_video_gl_texture_upload_meta (GstGLUpload * upload,
* @data: where the downloaded data should go * @data: where the downloaded data should go
* *
* Uploads @data into @texture_id. data size and format is specified by * Uploads @data into @texture_id. data size and format is specified by
* the #GstVideoFormat passed to gst_gl_upload_init_format() * the #GstVideoInfo<!-- -->s passed to gst_gl_upload_init_format()
* *
* Returns: whether the upload was successful * Returns: whether the upload was successful
*/ */
@ -968,13 +956,9 @@ _gst_gl_upload_perform_with_data_unlocked (GstGLUpload * upload,
g_return_val_if_fail (upload != NULL, FALSE); g_return_val_if_fail (upload != NULL, FALSE);
g_return_val_if_fail (texture_id > 0, FALSE); g_return_val_if_fail (texture_id > 0, FALSE);
g_return_val_if_fail (GST_VIDEO_INFO_FORMAT (&upload->info) !=
GST_VIDEO_FORMAT_UNKNOWN
&& GST_VIDEO_INFO_FORMAT (&upload->info) != GST_VIDEO_FORMAT_ENCODED,
FALSE);
upload->out_texture = texture_id; upload->out_texture = texture_id;
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->info); i++) { for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&upload->in_info); i++) {
upload->data[i] = data[i]; upload->data[i] = data[i];
} }
@ -1025,7 +1009,7 @@ _init_upload (GstGLContext * context, GstGLUpload * upload)
gl = context->gl_vtable; gl = context->gl_vtable;
v_format = GST_VIDEO_INFO_FORMAT (&upload->info); v_format = GST_VIDEO_INFO_FORMAT (&upload->in_info);
GST_INFO ("Initializing texture upload for format:%s", GST_INFO ("Initializing texture upload for format:%s",
gst_video_format_to_string (v_format)); gst_video_format_to_string (v_format));
@ -1036,7 +1020,9 @@ _init_upload (GstGLContext * context, GstGLUpload * upload)
goto error; goto error;
} }
_init_upload_fbo (context, upload); if (!_init_upload_fbo (context, upload)) {
goto error;
}
switch (v_format) { switch (v_format) {
case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_AYUV:
@ -1153,8 +1139,8 @@ _init_upload_fbo (GstGLContext * context, GstGLUpload * upload)
gl = context->gl_vtable; gl = context->gl_vtable;
out_width = GST_VIDEO_INFO_WIDTH (&upload->info); out_width = GST_VIDEO_INFO_WIDTH (&upload->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&upload->info); out_height = GST_VIDEO_INFO_HEIGHT (&upload->out_info);
if (!gl->GenFramebuffers) { if (!gl->GenFramebuffers) {
/* turn off the pipeline because Frame buffer object is a not present */ /* turn off the pipeline because Frame buffer object is a not present */
@ -1225,10 +1211,10 @@ _do_upload (GstGLContext * context, GstGLUpload * upload)
{ {
guint in_width, in_height, out_width, out_height; guint in_width, in_height, out_width, out_height;
out_width = GST_VIDEO_INFO_WIDTH (&upload->info); out_width = GST_VIDEO_INFO_WIDTH (&upload->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&upload->info); out_height = GST_VIDEO_INFO_HEIGHT (&upload->out_info);
in_width = upload->in_width; in_width = GST_VIDEO_INFO_WIDTH (&upload->in_info);
in_height = upload->in_height; in_height = GST_VIDEO_INFO_HEIGHT (&upload->in_info);
GST_TRACE ("uploading to texture:%u dimensions:%ux%u, " GST_TRACE ("uploading to texture:%u dimensions:%ux%u, "
"from textures:%u,%u,%u dimensions:%ux%u", upload->out_texture, "from textures:%u,%u,%u dimensions:%ux%u", upload->out_texture,
@ -1263,9 +1249,9 @@ _do_upload_make (GstGLContext * context, GstGLUpload * upload)
gl = context->gl_vtable; gl = context->gl_vtable;
in_width = upload->in_width; in_width = GST_VIDEO_INFO_WIDTH (&upload->in_info);
in_height = upload->in_height; in_height = GST_VIDEO_INFO_HEIGHT (&upload->in_info);
v_format = GST_VIDEO_INFO_FORMAT (&upload->info); v_format = GST_VIDEO_INFO_FORMAT (&upload->in_info);
switch (v_format) { switch (v_format) {
case GST_VIDEO_FORMAT_RGBx: case GST_VIDEO_FORMAT_RGBx:
@ -1429,7 +1415,7 @@ _do_upload_fill (GstGLContext * context, GstGLUpload * upload)
struct TexData *tex = upload->priv->texture_info; struct TexData *tex = upload->priv->texture_info;
const GstGLFuncs *gl = context->gl_vtable; const GstGLFuncs *gl = context->gl_vtable;
v_format = GST_VIDEO_INFO_FORMAT (&upload->info); v_format = GST_VIDEO_INFO_FORMAT (&upload->in_info);
for (i = 0; i < upload->priv->n_textures; i++) { for (i = 0; i < upload->priv->n_textures; i++) {
guint data_i = i; guint data_i = i;
@ -1486,9 +1472,9 @@ _do_upload_draw_opengl (GstGLContext * context, GstGLUpload * upload)
gl = context->gl_vtable; gl = context->gl_vtable;
out_width = GST_VIDEO_INFO_WIDTH (&upload->info); out_width = GST_VIDEO_INFO_WIDTH (&upload->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&upload->info); out_height = GST_VIDEO_INFO_HEIGHT (&upload->out_info);
v_format = GST_VIDEO_INFO_FORMAT (&upload->info); v_format = GST_VIDEO_INFO_FORMAT (&upload->in_info);
gl->BindFramebuffer (GL_FRAMEBUFFER, upload->fbo); gl->BindFramebuffer (GL_FRAMEBUFFER, upload->fbo);
@ -1648,9 +1634,9 @@ _do_upload_draw_gles2 (GstGLContext * context, GstGLUpload * upload)
gl = context->gl_vtable; gl = context->gl_vtable;
out_width = GST_VIDEO_INFO_WIDTH (&upload->info); out_width = GST_VIDEO_INFO_WIDTH (&upload->out_info);
out_height = GST_VIDEO_INFO_HEIGHT (&upload->info); out_height = GST_VIDEO_INFO_HEIGHT (&upload->out_info);
v_format = GST_VIDEO_INFO_FORMAT (&upload->info); v_format = GST_VIDEO_INFO_FORMAT (&upload->in_info);
gl->BindFramebuffer (GL_FRAMEBUFFER, upload->fbo); gl->BindFramebuffer (GL_FRAMEBUFFER, upload->fbo);

View file

@ -51,7 +51,8 @@ struct _GstGLUpload
GstGLContext *context; GstGLContext *context;
/* input data */ /* input data */
GstVideoInfo info; GstVideoInfo in_info;
GstVideoInfo out_info;
gpointer data[GST_VIDEO_MAX_PLANES]; gpointer data[GST_VIDEO_MAX_PLANES];
gboolean initted; gboolean initted;
@ -61,8 +62,6 @@ struct _GstGLUpload
GLuint depth_buffer; GLuint depth_buffer;
GLuint out_texture; GLuint out_texture;
GLuint in_texture[GST_VIDEO_MAX_PLANES]; GLuint in_texture[GST_VIDEO_MAX_PLANES];
guint in_width;
guint in_height;
GstGLShader *shader; GstGLShader *shader;
GLint shader_attr_position_loc; GLint shader_attr_position_loc;
GLint shader_attr_texture_loc; GLint shader_attr_texture_loc;
@ -102,9 +101,7 @@ struct _GstGLUploadClass
GstGLUpload * gst_gl_upload_new (GstGLContext * context); GstGLUpload * gst_gl_upload_new (GstGLContext * context);
gboolean gst_gl_upload_init_format (GstGLUpload * upload, GstVideoFormat v_format, gboolean gst_gl_upload_init_format (GstGLUpload * upload, GstVideoInfo in_info, GstVideoInfo out_info);
guint in_width, guint in_height,
guint out_width, guint out_height);
gboolean gst_gl_upload_add_video_gl_texture_upload_meta (GstGLUpload * upload, GstBuffer * buffer); gboolean gst_gl_upload_add_video_gl_texture_upload_meta (GstGLUpload * upload, GstBuffer * buffer);

View file

@ -387,12 +387,8 @@ _ensure_gl_setup (GstGLImageSink * gl_sink)
if (!gl_sink->upload) { if (!gl_sink->upload) {
gl_sink->upload = gst_gl_upload_new (gl_sink->context); gl_sink->upload = gst_gl_upload_new (gl_sink->context);
if (!gst_gl_upload_init_format (gl_sink->upload, if (!gst_gl_upload_init_format (gl_sink->upload, gl_sink->info,
GST_VIDEO_INFO_FORMAT (&gl_sink->info), gl_sink->info))
GST_VIDEO_INFO_WIDTH (&gl_sink->info),
GST_VIDEO_INFO_HEIGHT (&gl_sink->info),
GST_VIDEO_INFO_WIDTH (&gl_sink->info),
GST_VIDEO_INFO_HEIGHT (&gl_sink->info)))
goto upload_error; goto upload_error;
} }