2011-06-28 06:51:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
|
|
|
|
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
|
2013-03-19 12:27:35 +00:00
|
|
|
* Copyright (C) 2013, Collabora Ltd.
|
|
|
|
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
2011-06-28 06:51:23 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation
|
|
|
|
* version 2.1 of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2013-04-18 10:03:31 +00:00
|
|
|
|
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined(__GNUC__)
|
|
|
|
#ifndef __VCCOREVER__
|
|
|
|
#define __VCCOREVER__ 0x04000000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wredundant-decls"
|
|
|
|
#pragma GCC optimize ("gnu89-inline")
|
|
|
|
#endif
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2014-04-15 16:11:08 +00:00
|
|
|
#include <gst/gl/gl.h>
|
2016-01-19 18:10:38 +00:00
|
|
|
#include <gst/gl/egl/gstglmemoryegl.h>
|
2013-04-08 16:26:16 +00:00
|
|
|
#endif
|
2013-04-18 10:03:31 +00:00
|
|
|
|
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined(__GNUC__)
|
|
|
|
#pragma GCC reset_options
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2014-03-05 10:41:02 +00:00
|
|
|
#include "gstomxbufferpool.h"
|
2014-03-03 15:15:24 +00:00
|
|
|
#include "gstomxvideo.h"
|
2011-06-28 06:51:23 +00:00
|
|
|
#include "gstomxvideodec.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_omx_video_dec_debug_category);
|
|
|
|
#define GST_CAT_DEFAULT gst_omx_video_dec_debug_category
|
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
static void gst_omx_video_dec_finalize (GObject * object);
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_omx_video_dec_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
|
2012-10-22 12:34:53 +00:00
|
|
|
static gboolean gst_omx_video_dec_open (GstVideoDecoder * decoder);
|
|
|
|
static gboolean gst_omx_video_dec_close (GstVideoDecoder * decoder);
|
2012-06-20 12:11:58 +00:00
|
|
|
static gboolean gst_omx_video_dec_start (GstVideoDecoder * decoder);
|
|
|
|
static gboolean gst_omx_video_dec_stop (GstVideoDecoder * decoder);
|
|
|
|
static gboolean gst_omx_video_dec_set_format (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecState * state);
|
2014-01-29 18:31:26 +00:00
|
|
|
static gboolean gst_omx_video_dec_flush (GstVideoDecoder * decoder);
|
2012-06-20 12:11:58 +00:00
|
|
|
static GstFlowReturn gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
static GstFlowReturn gst_omx_video_dec_finish (GstVideoDecoder * decoder);
|
2012-10-22 12:28:04 +00:00
|
|
|
static gboolean gst_omx_video_dec_decide_allocation (GstVideoDecoder * bdec,
|
|
|
|
GstQuery * query);
|
2012-06-20 12:11:58 +00:00
|
|
|
|
2016-06-17 07:59:45 +00:00
|
|
|
static GstFlowReturn gst_omx_video_dec_drain (GstVideoDecoder * decoder);
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2013-03-07 13:10:12 +00:00
|
|
|
static OMX_ERRORTYPE gst_omx_video_dec_allocate_output_buffers (GstOMXVideoDec *
|
|
|
|
self);
|
|
|
|
static OMX_ERRORTYPE gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec
|
|
|
|
* self);
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* class initialization */
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
#define DEBUG_INIT \
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_omx_video_dec_debug_category, "omxvideodec", 0, \
|
|
|
|
"debug category for gst-omx video decoder base class");
|
|
|
|
|
2011-07-13 18:37:02 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstOMXVideoDec, gst_omx_video_dec,
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_TYPE_VIDEO_DECODER, DEBUG_INIT);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_omx_video_dec_class_init (GstOMXVideoDecClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2012-06-20 12:11:58 +00:00
|
|
|
GstVideoDecoderClass *video_decoder_class = GST_VIDEO_DECODER_CLASS (klass);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_omx_video_dec_finalize;
|
|
|
|
|
|
|
|
element_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_video_dec_change_state);
|
|
|
|
|
2012-10-22 12:34:53 +00:00
|
|
|
video_decoder_class->open = GST_DEBUG_FUNCPTR (gst_omx_video_dec_open);
|
|
|
|
video_decoder_class->close = GST_DEBUG_FUNCPTR (gst_omx_video_dec_close);
|
2012-06-20 12:11:58 +00:00
|
|
|
video_decoder_class->start = GST_DEBUG_FUNCPTR (gst_omx_video_dec_start);
|
|
|
|
video_decoder_class->stop = GST_DEBUG_FUNCPTR (gst_omx_video_dec_stop);
|
2014-01-29 18:31:26 +00:00
|
|
|
video_decoder_class->flush = GST_DEBUG_FUNCPTR (gst_omx_video_dec_flush);
|
2012-06-20 12:11:58 +00:00
|
|
|
video_decoder_class->set_format =
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_video_dec_set_format);
|
2012-06-20 12:11:58 +00:00
|
|
|
video_decoder_class->handle_frame =
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_video_dec_handle_frame);
|
2012-06-20 12:11:58 +00:00
|
|
|
video_decoder_class->finish = GST_DEBUG_FUNCPTR (gst_omx_video_dec_finish);
|
2016-06-17 07:59:45 +00:00
|
|
|
video_decoder_class->drain = GST_DEBUG_FUNCPTR (gst_omx_video_dec_drain);
|
2012-10-22 12:28:04 +00:00
|
|
|
video_decoder_class->decide_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_video_dec_decide_allocation);
|
2011-08-10 08:11:37 +00:00
|
|
|
|
2013-05-06 13:33:59 +00:00
|
|
|
klass->cdata.type = GST_OMX_COMPONENT_TYPE_FILTER;
|
2014-04-29 14:16:16 +00:00
|
|
|
klass->cdata.default_src_template_caps =
|
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2016-01-19 18:10:38 +00:00
|
|
|
GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_GL_MEMORY,
|
2014-04-29 14:16:16 +00:00
|
|
|
"RGBA") "; "
|
|
|
|
#endif
|
|
|
|
"video/x-raw, "
|
2011-08-10 08:11:37 +00:00
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", "
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", " "framerate = " GST_VIDEO_FPS_RANGE;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-12 19:57:32 +00:00
|
|
|
gst_omx_video_dec_init (GstOMXVideoDec * self)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_video_decoder_set_packetized (GST_VIDEO_DECODER (self), TRUE);
|
2015-08-28 15:57:33 +00:00
|
|
|
gst_video_decoder_set_use_default_pad_acceptcaps (GST_VIDEO_DECODER_CAST
|
|
|
|
(self), TRUE);
|
|
|
|
GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_DECODER_SINK_PAD (self));
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_init (&self->drain_lock);
|
|
|
|
g_cond_init (&self->drain_cond);
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-10-22 12:34:53 +00:00
|
|
|
gst_omx_video_dec_open (GstVideoDecoder * decoder)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
2012-10-22 12:34:53 +00:00
|
|
|
GstOMXVideoDec *self = GST_OMX_VIDEO_DEC (decoder);
|
2011-06-28 06:51:23 +00:00
|
|
|
GstOMXVideoDecClass *klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
|
2013-02-25 11:38:27 +00:00
|
|
|
gint in_port_index, out_port_index;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-09-27 12:15:06 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Opening decoder");
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
self->dec =
|
2013-02-12 10:49:21 +00:00
|
|
|
gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name,
|
|
|
|
klass->cdata.component_name, klass->cdata.component_role,
|
|
|
|
klass->cdata.hacks);
|
2011-07-14 05:58:41 +00:00
|
|
|
self->started = FALSE;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (!self->dec)
|
2011-06-28 06:51:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_component_get_state (self->dec,
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateLoaded)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 11:38:27 +00:00
|
|
|
in_port_index = klass->cdata.in_port_index;
|
|
|
|
out_port_index = klass->cdata.out_port_index;
|
|
|
|
|
|
|
|
if (in_port_index == -1 || out_port_index == -1) {
|
|
|
|
OMX_PORT_PARAM_TYPE param;
|
|
|
|
OMX_ERRORTYPE err;
|
|
|
|
|
|
|
|
GST_OMX_INIT_STRUCT (¶m);
|
|
|
|
|
|
|
|
err =
|
|
|
|
gst_omx_component_get_parameter (self->dec, OMX_IndexParamVideoInit,
|
|
|
|
¶m);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_WARNING_OBJECT (self, "Couldn't get port information: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
/* Fallback */
|
|
|
|
in_port_index = 0;
|
|
|
|
out_port_index = 1;
|
|
|
|
} else {
|
2013-04-18 22:07:28 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Detected %u ports, starting at %u",
|
|
|
|
(guint) param.nPorts, (guint) param.nStartPortNumber);
|
2013-02-25 11:38:27 +00:00
|
|
|
in_port_index = param.nStartPortNumber + 0;
|
|
|
|
out_port_index = param.nStartPortNumber + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self->dec_in_port = gst_omx_component_add_port (self->dec, in_port_index);
|
|
|
|
self->dec_out_port = gst_omx_component_add_port (self->dec, out_port_index);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (!self->dec_in_port || !self->dec_out_port)
|
2011-06-28 06:51:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2011-09-27 12:15:06 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Opened decoder");
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Opening EGL renderer");
|
|
|
|
self->egl_render =
|
|
|
|
gst_omx_component_new (GST_OBJECT_CAST (self), klass->cdata.core_name,
|
|
|
|
"OMX.broadcom.egl_render", NULL, klass->cdata.hacks);
|
|
|
|
|
|
|
|
if (!self->egl_render)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_omx_component_get_state (self->egl_render,
|
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateLoaded)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
{
|
|
|
|
OMX_PORT_PARAM_TYPE param;
|
|
|
|
OMX_ERRORTYPE err;
|
|
|
|
|
|
|
|
GST_OMX_INIT_STRUCT (¶m);
|
|
|
|
|
|
|
|
err =
|
|
|
|
gst_omx_component_get_parameter (self->egl_render,
|
|
|
|
OMX_IndexParamVideoInit, ¶m);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_WARNING_OBJECT (self, "Couldn't get port information: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
/* Fallback */
|
|
|
|
in_port_index = 0;
|
|
|
|
out_port_index = 1;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (self, "Detected %u ports, starting at %u", param.nPorts,
|
|
|
|
param.nStartPortNumber);
|
|
|
|
in_port_index = param.nStartPortNumber + 0;
|
|
|
|
out_port_index = param.nStartPortNumber + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self->egl_in_port =
|
|
|
|
gst_omx_component_add_port (self->egl_render, in_port_index);
|
|
|
|
self->egl_out_port =
|
|
|
|
gst_omx_component_add_port (self->egl_render, out_port_index);
|
|
|
|
|
|
|
|
if (!self->egl_in_port || !self->egl_out_port)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Opened EGL renderer");
|
|
|
|
#endif
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 18:19:10 +00:00
|
|
|
gst_omx_video_dec_shutdown (GstOMXVideoDec * self)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
2011-07-25 08:48:58 +00:00
|
|
|
OMX_STATETYPE state;
|
|
|
|
|
2011-11-17 18:19:10 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Shutting down decoder");
|
2011-09-27 12:15:06 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
state = gst_omx_component_get_state (self->egl_render, 0);
|
|
|
|
if (state > OMX_StateLoaded || state == OMX_StateInvalid) {
|
|
|
|
if (state > OMX_StateIdle) {
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateIdle);
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateIdle);
|
|
|
|
gst_omx_component_get_state (self->egl_render, 5 * GST_SECOND);
|
|
|
|
gst_omx_component_get_state (self->dec, 1 * GST_SECOND);
|
|
|
|
}
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateLoaded);
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateLoaded);
|
|
|
|
|
|
|
|
gst_omx_port_deallocate_buffers (self->dec_in_port);
|
|
|
|
gst_omx_video_dec_deallocate_output_buffers (self);
|
2014-03-04 16:41:20 +00:00
|
|
|
gst_omx_close_tunnel (self->dec_out_port, self->egl_in_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
if (state > OMX_StateLoaded) {
|
|
|
|
gst_omx_component_get_state (self->egl_render, 5 * GST_SECOND);
|
|
|
|
gst_omx_component_get_state (self->dec, 1 * GST_SECOND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise we didn't use EGL and just fall back to
|
|
|
|
* shutting down the decoder */
|
|
|
|
#endif
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
state = gst_omx_component_get_state (self->dec, 0);
|
2011-07-25 08:48:58 +00:00
|
|
|
if (state > OMX_StateLoaded || state == OMX_StateInvalid) {
|
2011-09-27 13:05:19 +00:00
|
|
|
if (state > OMX_StateIdle) {
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateIdle);
|
|
|
|
gst_omx_component_get_state (self->dec, 5 * GST_SECOND);
|
2011-09-27 13:05:19 +00:00
|
|
|
}
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateLoaded);
|
|
|
|
gst_omx_port_deallocate_buffers (self->dec_in_port);
|
2013-03-07 13:10:12 +00:00
|
|
|
gst_omx_video_dec_deallocate_output_buffers (self);
|
2011-07-25 08:48:58 +00:00
|
|
|
if (state > OMX_StateLoaded)
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_get_state (self->dec, 5 * GST_SECOND);
|
2011-07-13 19:19:34 +00:00
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-11-17 18:19:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-10-22 12:34:53 +00:00
|
|
|
gst_omx_video_dec_close (GstVideoDecoder * decoder)
|
2011-11-17 18:19:10 +00:00
|
|
|
{
|
2012-10-22 12:34:53 +00:00
|
|
|
GstOMXVideoDec *self = GST_OMX_VIDEO_DEC (decoder);
|
|
|
|
|
2011-11-17 18:19:10 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Closing decoder");
|
|
|
|
|
|
|
|
if (!gst_omx_video_dec_shutdown (self))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
self->dec_in_port = NULL;
|
|
|
|
self->dec_out_port = NULL;
|
|
|
|
if (self->dec)
|
|
|
|
gst_omx_component_free (self->dec);
|
|
|
|
self->dec = NULL;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
self->egl_in_port = NULL;
|
|
|
|
self->egl_out_port = NULL;
|
|
|
|
if (self->egl_render)
|
|
|
|
gst_omx_component_free (self->egl_render);
|
|
|
|
self->egl_render = NULL;
|
|
|
|
#endif
|
|
|
|
|
2011-09-27 12:15:06 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Closed decoder");
|
|
|
|
|
2011-07-13 19:19:34 +00:00
|
|
|
return TRUE;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_omx_video_dec_finalize (GObject * object)
|
|
|
|
{
|
2011-11-01 15:08:59 +00:00
|
|
|
GstOMXVideoDec *self = GST_OMX_VIDEO_DEC (object);
|
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_clear (&self->drain_lock);
|
|
|
|
g_cond_clear (&self->drain_cond);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
G_OBJECT_CLASS (gst_omx_video_dec_parent_class)->finalize (object);
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_omx_video_dec_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstOMXVideoDec *self;
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_OMX_VIDEO_DEC (element),
|
|
|
|
GST_STATE_CHANGE_FAILURE);
|
|
|
|
self = GST_OMX_VIDEO_DEC (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2011-11-01 15:08:59 +00:00
|
|
|
self->draining = FALSE;
|
2011-11-09 14:42:13 +00:00
|
|
|
self->started = FALSE;
|
2011-06-28 06:51:23 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2013-02-25 08:12:22 +00:00
|
|
|
if (self->dec_in_port)
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_in_port, 5 * GST_SECOND, TRUE);
|
2013-02-25 08:12:22 +00:00
|
|
|
if (self->dec_out_port)
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, TRUE);
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
if (self->egl_in_port)
|
|
|
|
gst_omx_port_set_flushing (self->egl_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
if (self->egl_out_port)
|
|
|
|
gst_omx_port_set_flushing (self->egl_out_port, 5 * GST_SECOND, TRUE);
|
|
|
|
#endif
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
2011-11-01 15:08:59 +00:00
|
|
|
self->draining = FALSE;
|
2012-11-12 10:29:48 +00:00
|
|
|
g_cond_broadcast (&self->drain_cond);
|
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2011-06-28 06:51:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
ret =
|
2013-02-25 11:38:27 +00:00
|
|
|
GST_ELEMENT_CLASS (gst_omx_video_dec_parent_class)->change_state
|
|
|
|
(element, transition);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-04-12 19:57:32 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_FLUSHING;
|
2011-11-10 13:42:13 +00:00
|
|
|
self->started = FALSE;
|
2011-11-17 18:19:10 +00:00
|
|
|
|
|
|
|
if (!gst_omx_video_dec_shutdown (self))
|
|
|
|
ret = GST_STATE_CHANGE_FAILURE;
|
2011-06-28 06:51:23 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-18 06:41:20 +00:00
|
|
|
static gboolean
|
2013-02-25 11:38:27 +00:00
|
|
|
gst_omx_video_dec_fill_buffer (GstOMXVideoDec * self,
|
|
|
|
GstOMXBuffer * inbuf, GstBuffer * outbuf)
|
2011-07-18 06:41:20 +00:00
|
|
|
{
|
2012-06-20 12:11:58 +00:00
|
|
|
GstVideoCodecState *state =
|
|
|
|
gst_video_decoder_get_output_state (GST_VIDEO_DECODER (self));
|
|
|
|
GstVideoInfo *vinfo = &state->info;
|
2013-02-25 08:12:22 +00:00
|
|
|
OMX_PARAM_PORTDEFINITIONTYPE *port_def = &self->dec_out_port->port_def;
|
2011-07-18 06:41:20 +00:00
|
|
|
gboolean ret = FALSE;
|
2012-04-12 19:57:32 +00:00
|
|
|
GstVideoFrame frame;
|
2011-07-18 06:41:20 +00:00
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
if (vinfo->width != port_def->format.video.nFrameWidth ||
|
|
|
|
vinfo->height != port_def->format.video.nFrameHeight) {
|
2013-04-18 22:07:28 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Resolution do not match: port=%ux%u vinfo=%dx%d",
|
|
|
|
(guint) port_def->format.video.nFrameWidth,
|
|
|
|
(guint) port_def->format.video.nFrameHeight,
|
2013-03-09 12:07:59 +00:00
|
|
|
vinfo->width, vinfo->height);
|
2011-07-18 06:41:20 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same strides and everything */
|
2012-04-12 19:57:32 +00:00
|
|
|
if (gst_buffer_get_size (outbuf) == inbuf->omx_buf->nFilledLen) {
|
|
|
|
GstMapInfo map = GST_MAP_INFO_INIT;
|
|
|
|
|
2014-05-19 07:06:42 +00:00
|
|
|
if (!gst_buffer_map (outbuf, &map, GST_MAP_WRITE)) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to map output buffer");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
memcpy (map.data,
|
2011-07-18 06:41:20 +00:00
|
|
|
inbuf->omx_buf->pBuffer + inbuf->omx_buf->nOffset,
|
|
|
|
inbuf->omx_buf->nFilledLen);
|
2012-04-12 19:57:32 +00:00
|
|
|
gst_buffer_unmap (outbuf, &map);
|
2011-07-18 06:41:20 +00:00
|
|
|
ret = TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
2012-04-12 19:57:32 +00:00
|
|
|
|
2011-07-18 06:41:20 +00:00
|
|
|
/* Different strides */
|
2014-04-09 16:51:57 +00:00
|
|
|
if (gst_video_frame_map (&frame, vinfo, outbuf, GST_MAP_WRITE)) {
|
|
|
|
const guint nstride = port_def->format.video.nStride;
|
|
|
|
const guint nslice = port_def->format.video.nSliceHeight;
|
|
|
|
guint src_stride[GST_VIDEO_MAX_PLANES] = { nstride, 0, };
|
|
|
|
guint src_size[GST_VIDEO_MAX_PLANES] = { nstride * nslice, 0, };
|
|
|
|
gint dst_width[GST_VIDEO_MAX_PLANES] = { 0, };
|
|
|
|
gint dst_height[GST_VIDEO_MAX_PLANES] =
|
|
|
|
{ GST_VIDEO_INFO_HEIGHT (vinfo), 0, };
|
|
|
|
const guint8 *src;
|
|
|
|
guint p;
|
|
|
|
|
|
|
|
switch (GST_VIDEO_INFO_FORMAT (vinfo)) {
|
2014-04-09 16:52:16 +00:00
|
|
|
case GST_VIDEO_FORMAT_ABGR:
|
|
|
|
case GST_VIDEO_FORMAT_ARGB:
|
|
|
|
dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo) * 4;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_RGB16:
|
|
|
|
case GST_VIDEO_FORMAT_BGR16:
|
|
|
|
case GST_VIDEO_FORMAT_YUY2:
|
|
|
|
case GST_VIDEO_FORMAT_UYVY:
|
|
|
|
case GST_VIDEO_FORMAT_YVYU:
|
|
|
|
dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo) * 2;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY8:
|
|
|
|
dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
break;
|
2014-04-09 16:51:57 +00:00
|
|
|
case GST_VIDEO_FORMAT_I420:
|
|
|
|
dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
src_stride[1] = nstride / 2;
|
|
|
|
src_size[1] = (src_stride[1] * nslice) / 2;
|
|
|
|
dst_width[1] = GST_VIDEO_INFO_WIDTH (vinfo) / 2;
|
|
|
|
dst_height[1] = GST_VIDEO_INFO_HEIGHT (vinfo) / 2;
|
|
|
|
src_stride[2] = nstride / 2;
|
|
|
|
src_size[2] = (src_stride[1] * nslice) / 2;
|
|
|
|
dst_width[2] = GST_VIDEO_INFO_WIDTH (vinfo) / 2;
|
|
|
|
dst_height[2] = GST_VIDEO_INFO_HEIGHT (vinfo) / 2;
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_NV12:
|
|
|
|
dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
src_stride[1] = nstride;
|
|
|
|
src_size[1] = src_stride[1] * nslice / 2;
|
|
|
|
dst_width[1] = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
dst_height[1] = GST_VIDEO_INFO_HEIGHT (vinfo) / 2;
|
|
|
|
break;
|
2014-04-09 16:52:16 +00:00
|
|
|
case GST_VIDEO_FORMAT_NV16:
|
|
|
|
dst_width[0] = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
src_stride[1] = nstride;
|
|
|
|
src_size[1] = src_stride[1] * nslice;
|
|
|
|
dst_width[1] = GST_VIDEO_INFO_WIDTH (vinfo);
|
|
|
|
dst_height[1] = GST_VIDEO_INFO_HEIGHT (vinfo);
|
|
|
|
break;
|
2014-04-09 16:51:57 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2011-07-18 06:41:20 +00:00
|
|
|
}
|
2014-04-09 16:51:57 +00:00
|
|
|
|
|
|
|
src = inbuf->omx_buf->pBuffer + inbuf->omx_buf->nOffset;
|
|
|
|
for (p = 0; p < GST_VIDEO_INFO_N_PLANES (vinfo); p++) {
|
|
|
|
const guint8 *data;
|
|
|
|
guint8 *dst;
|
|
|
|
guint h;
|
|
|
|
|
|
|
|
dst = GST_VIDEO_FRAME_PLANE_DATA (&frame, p);
|
|
|
|
data = src;
|
|
|
|
for (h = 0; h < dst_height[p]; h++) {
|
|
|
|
memcpy (dst, data, dst_width[p]);
|
2016-06-29 07:37:43 +00:00
|
|
|
dst += GST_VIDEO_FRAME_PLANE_STRIDE (&frame, p);
|
2014-04-09 16:51:57 +00:00
|
|
|
data += src_stride[p];
|
2011-07-18 06:41:20 +00:00
|
|
|
}
|
2014-04-09 16:51:57 +00:00
|
|
|
src += src_size[p];
|
2011-07-18 06:41:20 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 16:51:57 +00:00
|
|
|
gst_video_frame_unmap (&frame);
|
|
|
|
ret = TRUE;
|
|
|
|
} else {
|
|
|
|
GST_ERROR_OBJECT (self, "Can't map output buffer to frame");
|
|
|
|
goto done;
|
|
|
|
}
|
2011-07-18 06:41:20 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (ret) {
|
2012-04-12 19:57:32 +00:00
|
|
|
GST_BUFFER_PTS (outbuf) =
|
2016-06-17 09:06:48 +00:00
|
|
|
gst_util_uint64_scale (GST_OMX_GET_TICKS (inbuf->omx_buf->nTimeStamp),
|
|
|
|
GST_SECOND, OMX_TICKS_PER_SECOND);
|
2011-07-18 06:41:20 +00:00
|
|
|
if (inbuf->omx_buf->nTickCount != 0)
|
|
|
|
GST_BUFFER_DURATION (outbuf) =
|
|
|
|
gst_util_uint64_scale (inbuf->omx_buf->nTickCount, GST_SECOND,
|
|
|
|
OMX_TICKS_PER_SECOND);
|
|
|
|
}
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
|
2011-07-18 06:41:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-07 13:10:12 +00:00
|
|
|
static OMX_ERRORTYPE
|
|
|
|
gst_omx_video_dec_allocate_output_buffers (GstOMXVideoDec * self)
|
|
|
|
{
|
|
|
|
OMX_ERRORTYPE err = OMX_ErrorNone;
|
|
|
|
GstOMXPort *port;
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
gboolean eglimage = FALSE, add_videometa = FALSE;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
guint min = 0, max = 0;
|
|
|
|
GstVideoCodecState *state =
|
|
|
|
gst_video_decoder_get_output_state (GST_VIDEO_DECODER (self));
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
port = self->eglimage ? self->egl_out_port : self->dec_out_port;
|
|
|
|
#else
|
2013-03-07 13:10:12 +00:00
|
|
|
port = self->dec_out_port;
|
2013-02-25 10:55:04 +00:00
|
|
|
#endif
|
2013-03-07 13:10:12 +00:00
|
|
|
|
|
|
|
pool = gst_video_decoder_get_buffer_pool (GST_VIDEO_DECODER (self));
|
2013-02-25 10:55:04 +00:00
|
|
|
if (pool) {
|
2013-03-07 13:10:12 +00:00
|
|
|
GstAllocator *allocator;
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2014-05-19 07:01:46 +00:00
|
|
|
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min, &max)) {
|
|
|
|
GST_ERROR_OBJECT (self, "Can't get buffer pool params");
|
2014-05-26 09:02:10 +00:00
|
|
|
gst_structure_free (config);
|
2014-05-19 07:01:46 +00:00
|
|
|
err = OMX_ErrorUndefined;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (!gst_buffer_pool_config_get_allocator (config, &allocator, NULL)) {
|
|
|
|
GST_ERROR_OBJECT (self, "Can't get buffer pool allocator");
|
2014-05-26 09:02:10 +00:00
|
|
|
gst_structure_free (config);
|
2014-05-19 07:01:46 +00:00
|
|
|
err = OMX_ErrorUndefined;
|
|
|
|
goto done;
|
|
|
|
}
|
2013-03-07 13:10:12 +00:00
|
|
|
|
|
|
|
/* Need at least 2 buffers for anything meaningful */
|
2013-03-13 12:23:35 +00:00
|
|
|
min = MAX (MAX (min, port->port_def.nBufferCountMin), 4);
|
|
|
|
if (max == 0) {
|
|
|
|
max = min;
|
|
|
|
} else if (max < port->port_def.nBufferCountMin || max < 2) {
|
|
|
|
/* Can't use pool because can't have enough buffers */
|
|
|
|
gst_caps_replace (&caps, NULL);
|
|
|
|
} else {
|
|
|
|
min = max;
|
|
|
|
}
|
2013-03-07 13:10:12 +00:00
|
|
|
|
|
|
|
add_videometa = gst_buffer_pool_config_has_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
2014-03-07 16:12:24 +00:00
|
|
|
gst_structure_free (config);
|
2013-03-07 13:10:12 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2016-01-19 18:10:38 +00:00
|
|
|
eglimage = self->eglimage
|
|
|
|
&& (allocator && GST_IS_GL_MEMORY_EGL_ALLOCATOR (allocator));
|
2013-02-25 10:55:04 +00:00
|
|
|
#else
|
|
|
|
/* TODO: Implement something that works for other targets too */
|
2013-03-07 13:10:12 +00:00
|
|
|
eglimage = FALSE;
|
2013-02-25 10:55:04 +00:00
|
|
|
#endif
|
2013-03-07 13:10:12 +00:00
|
|
|
caps = caps ? gst_caps_ref (caps) : NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Trying to use pool %p with caps %" GST_PTR_FORMAT
|
|
|
|
" and memory type %s", pool, caps,
|
|
|
|
(allocator ? allocator->mem_type : "(null)"));
|
|
|
|
} else {
|
|
|
|
gst_caps_replace (&caps, NULL);
|
|
|
|
min = max = port->port_def.nBufferCountMin;
|
|
|
|
GST_DEBUG_OBJECT (self, "No pool available, not negotiated yet");
|
|
|
|
}
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
/* Will retry without EGLImage */
|
|
|
|
if (self->eglimage && !eglimage) {
|
|
|
|
GST_DEBUG_OBJECT (self,
|
|
|
|
"Wanted to use EGLImage but downstream doesn't support it");
|
|
|
|
err = OMX_ErrorUndefined;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-07 13:10:12 +00:00
|
|
|
if (caps)
|
|
|
|
self->out_port_pool =
|
|
|
|
gst_omx_buffer_pool_new (GST_ELEMENT_CAST (self), self->dec, port);
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
if (eglimage) {
|
|
|
|
GList *buffers = NULL;
|
|
|
|
GList *images = NULL;
|
|
|
|
gint i;
|
|
|
|
GstBufferPoolAcquireParams params = { 0, };
|
2014-04-15 16:11:08 +00:00
|
|
|
EGLDisplay egl_display = EGL_NO_DISPLAY;
|
2013-02-25 10:55:04 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Trying to allocate %d EGLImages", min);
|
|
|
|
|
|
|
|
for (i = 0; i < min; i++) {
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMemory *mem;
|
2016-01-19 18:10:38 +00:00
|
|
|
GstGLMemoryEGL *gl_mem;
|
2013-02-25 10:55:04 +00:00
|
|
|
|
|
|
|
if (gst_buffer_pool_acquire_buffer (pool, &buffer, ¶ms) != GST_FLOW_OK
|
|
|
|
|| gst_buffer_n_memory (buffer) != 1
|
|
|
|
|| !(mem = gst_buffer_peek_memory (buffer, 0))
|
2016-01-19 18:10:38 +00:00
|
|
|
|| !GST_IS_GL_MEMORY_EGL_ALLOCATOR (mem->allocator)) {
|
2013-02-25 10:55:04 +00:00
|
|
|
GST_INFO_OBJECT (self, "Failed to allocated %d-th EGLImage", i);
|
|
|
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
g_list_free (images);
|
|
|
|
buffers = NULL;
|
|
|
|
images = NULL;
|
|
|
|
/* TODO: For non-RPi targets we want to use the normal memory code below */
|
|
|
|
/* Retry without EGLImage */
|
|
|
|
err = OMX_ErrorUndefined;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-01-19 18:10:38 +00:00
|
|
|
gl_mem = (GstGLMemoryEGL *) mem;
|
2013-02-25 10:55:04 +00:00
|
|
|
buffers = g_list_append (buffers, buffer);
|
2016-01-19 18:10:38 +00:00
|
|
|
images = g_list_append (images, gst_gl_memory_egl_get_image (gl_mem));
|
2014-04-15 16:11:08 +00:00
|
|
|
if (egl_display == EGL_NO_DISPLAY)
|
2016-01-19 18:10:38 +00:00
|
|
|
egl_display = gst_gl_memory_egl_get_display (gl_mem);
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Allocated %d EGLImages successfully", min);
|
|
|
|
|
|
|
|
/* Everything went fine? */
|
|
|
|
if (eglimage) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Setting EGLDisplay");
|
2014-04-15 16:11:08 +00:00
|
|
|
self->egl_out_port->port_def.format.video.pNativeWindow = egl_display;
|
2013-02-25 10:55:04 +00:00
|
|
|
err =
|
|
|
|
gst_omx_port_update_port_definition (self->egl_out_port,
|
|
|
|
&self->egl_out_port->port_def);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
|
|
|
"Failed to set EGLDisplay on port: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
g_list_free (images);
|
|
|
|
/* TODO: For non-RPi targets we want to use the normal memory code below */
|
|
|
|
/* Retry without EGLImage */
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
if (min != port->port_def.nBufferCountActual) {
|
|
|
|
err = gst_omx_port_update_port_definition (port, NULL);
|
|
|
|
if (err == OMX_ErrorNone) {
|
|
|
|
port->port_def.nBufferCountActual = min;
|
|
|
|
err = gst_omx_port_update_port_definition (port, &port->port_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
2013-04-08 14:52:19 +00:00
|
|
|
"Failed to configure %u output buffers: %s (0x%08x)", min,
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
g_list_free (images);
|
|
|
|
/* TODO: For non-RPi targets we want to use the normal memory code below */
|
|
|
|
/* Retry without EGLImage */
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_omx_port_is_enabled (port)) {
|
|
|
|
err = gst_omx_port_set_enabled (port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
|
|
|
"Failed to enable port: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
g_list_free (images);
|
|
|
|
/* TODO: For non-RPi targets we want to use the normal memory code below */
|
|
|
|
/* Retry without EGLImage */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_use_eglimages (port, images);
|
|
|
|
g_list_free (images);
|
|
|
|
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
|
|
|
"Failed to pass EGLImages to port: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
/* TODO: For non-RPi targets we want to use the normal memory code below */
|
|
|
|
/* Retry without EGLImage */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 2 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
|
|
|
"Failed to wait until port is enabled: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
/* TODO: For non-RPi targets we want to use the normal memory code below */
|
|
|
|
/* Retry without EGLImage */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Populating internal buffer pool");
|
|
|
|
GST_OMX_BUFFER_POOL (self->out_port_pool)->other_pool =
|
|
|
|
GST_BUFFER_POOL (gst_object_ref (pool));
|
|
|
|
for (l = buffers; l; l = l->next) {
|
|
|
|
g_ptr_array_add (GST_OMX_BUFFER_POOL (self->out_port_pool)->buffers,
|
|
|
|
l->data);
|
|
|
|
}
|
|
|
|
g_list_free (buffers);
|
|
|
|
/* All good and done, set caps below */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-07 13:10:12 +00:00
|
|
|
|
|
|
|
/* If not using EGLImage or trying to use EGLImage failed */
|
|
|
|
if (!eglimage) {
|
|
|
|
gboolean was_enabled = TRUE;
|
|
|
|
|
|
|
|
if (min != port->port_def.nBufferCountActual) {
|
|
|
|
err = gst_omx_port_update_port_definition (port, NULL);
|
|
|
|
if (err == OMX_ErrorNone) {
|
|
|
|
port->port_def.nBufferCountActual = min;
|
|
|
|
err = gst_omx_port_update_port_definition (port, &port->port_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self,
|
2013-03-09 12:27:08 +00:00
|
|
|
"Failed to configure %u output buffers: %s (0x%08x)", min,
|
2013-03-07 13:10:12 +00:00
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_omx_port_is_enabled (port)) {
|
|
|
|
err = gst_omx_port_set_enabled (port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
|
|
|
"Failed to enable port: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
was_enabled = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_allocate_buffers (port);
|
|
|
|
if (err != OMX_ErrorNone && min > port->port_def.nBufferCountMin) {
|
|
|
|
GST_ERROR_OBJECT (self,
|
|
|
|
"Failed to allocate required number of buffers %d, trying less and copying",
|
|
|
|
min);
|
|
|
|
min = port->port_def.nBufferCountMin;
|
|
|
|
|
2014-05-19 07:04:09 +00:00
|
|
|
if (!was_enabled) {
|
|
|
|
err = gst_omx_port_set_enabled (port, FALSE);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_INFO_OBJECT (self,
|
|
|
|
"Failed to disable port again: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2013-03-07 13:10:12 +00:00
|
|
|
|
|
|
|
if (min != port->port_def.nBufferCountActual) {
|
|
|
|
err = gst_omx_port_update_port_definition (port, NULL);
|
|
|
|
if (err == OMX_ErrorNone) {
|
|
|
|
port->port_def.nBufferCountActual = min;
|
|
|
|
err = gst_omx_port_update_port_definition (port, &port->port_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self,
|
2013-03-09 12:27:08 +00:00
|
|
|
"Failed to configure %u output buffers: %s (0x%08x)", min,
|
2013-03-07 13:10:12 +00:00
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_allocate_buffers (port);
|
|
|
|
|
|
|
|
/* Can't provide buffers downstream in this case */
|
|
|
|
gst_caps_replace (&caps, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to allocate %d buffers: %s (0x%08x)", min,
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!was_enabled) {
|
|
|
|
err = gst_omx_port_wait_enabled (port, 2 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self,
|
|
|
|
"Failed to wait until port is enabled: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err = OMX_ErrorNone;
|
|
|
|
|
|
|
|
if (caps) {
|
|
|
|
config = gst_buffer_pool_get_config (self->out_port_pool);
|
|
|
|
|
|
|
|
if (add_videometa)
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
|
|
|
|
gst_buffer_pool_config_set_params (config, caps,
|
|
|
|
self->dec_out_port->port_def.nBufferSize, min, max);
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_set_config (self->out_port_pool, config)) {
|
|
|
|
GST_INFO_OBJECT (self, "Failed to set config on internal pool");
|
|
|
|
gst_object_unref (self->out_port_pool);
|
|
|
|
self->out_port_pool = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OMX_BUFFER_POOL (self->out_port_pool)->allocating = TRUE;
|
|
|
|
/* This now allocates all the buffers */
|
|
|
|
if (!gst_buffer_pool_set_active (self->out_port_pool, TRUE)) {
|
|
|
|
GST_INFO_OBJECT (self, "Failed to activate internal pool");
|
|
|
|
gst_object_unref (self->out_port_pool);
|
|
|
|
self->out_port_pool = NULL;
|
|
|
|
} else {
|
|
|
|
GST_OMX_BUFFER_POOL (self->out_port_pool)->allocating = FALSE;
|
|
|
|
}
|
|
|
|
} else if (self->out_port_pool) {
|
|
|
|
gst_object_unref (self->out_port_pool);
|
|
|
|
self->out_port_pool = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!self->out_port_pool && err == OMX_ErrorNone)
|
|
|
|
GST_DEBUG_OBJECT (self,
|
|
|
|
"Not using our internal pool and copying buffers for downstream");
|
|
|
|
|
|
|
|
if (caps)
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
if (pool)
|
|
|
|
gst_object_unref (pool);
|
|
|
|
if (state)
|
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static OMX_ERRORTYPE
|
|
|
|
gst_omx_video_dec_deallocate_output_buffers (GstOMXVideoDec * self)
|
|
|
|
{
|
|
|
|
OMX_ERRORTYPE err;
|
|
|
|
|
|
|
|
if (self->out_port_pool) {
|
|
|
|
gst_buffer_pool_set_active (self->out_port_pool, FALSE);
|
2013-04-05 11:45:24 +00:00
|
|
|
#if 0
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_buffer_pool_wait_released (self->out_port_pool);
|
2013-04-05 11:45:24 +00:00
|
|
|
#endif
|
2013-03-07 13:10:12 +00:00
|
|
|
GST_OMX_BUFFER_POOL (self->out_port_pool)->deactivated = TRUE;
|
|
|
|
gst_object_unref (self->out_port_pool);
|
|
|
|
self->out_port_pool = NULL;
|
|
|
|
}
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
err =
|
2016-01-19 18:10:38 +00:00
|
|
|
gst_omx_port_deallocate_buffers (self->eglimage ? self->
|
|
|
|
egl_out_port : self->dec_out_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
#else
|
2013-03-07 13:10:12 +00:00
|
|
|
err = gst_omx_port_deallocate_buffers (self->dec_out_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static OMX_ERRORTYPE
|
|
|
|
gst_omx_video_dec_reconfigure_output_port (GstOMXVideoDec * self)
|
|
|
|
{
|
|
|
|
GstOMXPort *port;
|
|
|
|
OMX_ERRORTYPE err;
|
|
|
|
GstVideoCodecState *state;
|
|
|
|
OMX_PARAM_PORTDEFINITIONTYPE port_def;
|
|
|
|
GstVideoFormat format;
|
|
|
|
|
|
|
|
/* At this point the decoder output port is disabled */
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
{
|
|
|
|
OMX_STATETYPE egl_state;
|
|
|
|
|
|
|
|
if (self->eglimage) {
|
|
|
|
/* Nothing to do here, we could however fall back to non-EGLImage in theory */
|
2013-04-18 13:21:32 +00:00
|
|
|
port = self->egl_out_port;
|
2013-02-25 10:55:04 +00:00
|
|
|
err = OMX_ErrorNone;
|
|
|
|
goto enable_port;
|
|
|
|
} else {
|
|
|
|
/* Set up egl_render */
|
|
|
|
|
|
|
|
self->eglimage = TRUE;
|
|
|
|
|
|
|
|
gst_omx_port_get_port_definition (self->dec_out_port, &port_def);
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (self),
|
|
|
|
GST_VIDEO_FORMAT_RGBA, port_def.format.video.nFrameWidth,
|
|
|
|
port_def.format.video.nFrameHeight, self->input_state);
|
|
|
|
|
2014-04-29 14:16:16 +00:00
|
|
|
/* at this point state->caps is NULL */
|
|
|
|
if (state->caps)
|
|
|
|
gst_caps_unref (state->caps);
|
|
|
|
state->caps = gst_video_info_to_caps (&state->info);
|
|
|
|
gst_caps_set_features (state->caps, 0,
|
2016-01-19 18:10:38 +00:00
|
|
|
gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_GL_MEMORY, NULL));
|
2014-04-29 14:16:16 +00:00
|
|
|
|
|
|
|
/* try to negotiate with caps feature */
|
2013-02-25 10:55:04 +00:00
|
|
|
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
|
2014-04-29 14:16:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self,
|
|
|
|
"Failed to negotiate with feature %s",
|
2016-01-19 18:10:38 +00:00
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY);
|
2014-04-29 14:16:16 +00:00
|
|
|
|
|
|
|
if (state->caps)
|
|
|
|
gst_caps_replace (&state->caps, NULL);
|
|
|
|
|
|
|
|
/* fallback: try to use EGLImage even if it is not in the caps feature */
|
|
|
|
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
|
|
|
|
gst_video_codec_state_unref (state);
|
2017-03-13 15:34:36 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Failed to negotiate RGBA for EGLImage");
|
2014-04-29 14:16:16 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
goto no_egl;
|
|
|
|
}
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
|
|
|
|
/* Now link it all together */
|
|
|
|
|
|
|
|
err = gst_omx_port_set_enabled (self->egl_in_port, FALSE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (self->egl_in_port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_set_enabled (self->egl_out_port, FALSE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (self->egl_out_port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
{
|
2013-04-08 14:31:33 +00:00
|
|
|
#define OMX_IndexParamBrcmVideoEGLRenderDiscardMode 0x7f0000db
|
2013-02-25 10:55:04 +00:00
|
|
|
OMX_CONFIG_PORTBOOLEANTYPE discardMode;
|
|
|
|
memset (&discardMode, 0, sizeof (discardMode));
|
|
|
|
discardMode.nSize = sizeof (discardMode);
|
|
|
|
discardMode.nPortIndex = 220;
|
|
|
|
discardMode.nVersion.nVersion = OMX_VERSION;
|
|
|
|
discardMode.bEnabled = OMX_FALSE;
|
|
|
|
if (gst_omx_component_set_parameter (self->egl_render,
|
|
|
|
OMX_IndexParamBrcmVideoEGLRenderDiscardMode,
|
|
|
|
&discardMode) != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
#undef OMX_IndexParamBrcmVideoEGLRenderDiscardMode
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:41:20 +00:00
|
|
|
err = gst_omx_setup_tunnel (self->dec_out_port, self->egl_in_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_set_enabled (self->egl_in_port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_component_set_state (self->egl_render, OMX_StateIdle);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (self->egl_in_port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
if (gst_omx_component_get_state (self->egl_render,
|
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateIdle)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_video_dec_allocate_output_buffers (self);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
if (gst_omx_component_set_state (self->egl_render,
|
|
|
|
OMX_StateExecuting) != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
if (gst_omx_component_get_state (self->egl_render,
|
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateExecuting)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err =
|
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, FALSE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err =
|
|
|
|
gst_omx_port_set_flushing (self->egl_in_port, 5 * GST_SECOND, FALSE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err =
|
|
|
|
gst_omx_port_set_flushing (self->egl_out_port, 5 * GST_SECOND, FALSE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_populate (self->egl_out_port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_set_enabled (self->dec_out_port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (self->dec_out_port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
|
|
|
|
err = gst_omx_port_mark_reconfigured (self->dec_out_port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
err = gst_omx_port_mark_reconfigured (self->egl_out_port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto no_egl;
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
no_egl:
|
|
|
|
|
|
|
|
gst_omx_port_set_enabled (self->dec_out_port, FALSE);
|
|
|
|
gst_omx_port_wait_enabled (self->dec_out_port, 1 * GST_SECOND);
|
|
|
|
egl_state = gst_omx_component_get_state (self->egl_render, 0);
|
|
|
|
if (egl_state > OMX_StateLoaded || egl_state == OMX_StateInvalid) {
|
|
|
|
if (egl_state > OMX_StateIdle) {
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateIdle);
|
|
|
|
gst_omx_component_get_state (self->egl_render, 5 * GST_SECOND);
|
|
|
|
}
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateLoaded);
|
|
|
|
|
|
|
|
gst_omx_video_dec_deallocate_output_buffers (self);
|
2014-03-04 16:41:20 +00:00
|
|
|
gst_omx_close_tunnel (self->dec_out_port, self->egl_in_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
|
|
|
|
if (egl_state > OMX_StateLoaded) {
|
|
|
|
gst_omx_component_get_state (self->egl_render, 5 * GST_SECOND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* After this egl_render should be deactivated
|
|
|
|
* and the decoder's output port disabled */
|
|
|
|
self->eglimage = FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
port = self->dec_out_port;
|
|
|
|
|
|
|
|
/* Update caps */
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
|
|
|
|
gst_omx_port_get_port_definition (port, &port_def);
|
|
|
|
g_assert (port_def.format.video.eCompressionFormat == OMX_VIDEO_CodingUnused);
|
|
|
|
|
2014-04-09 16:51:12 +00:00
|
|
|
format =
|
|
|
|
gst_omx_video_get_format_from_omx (port_def.format.video.eColorFormat);
|
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
GST_ERROR_OBJECT (self, "Unsupported color format: %d",
|
|
|
|
port_def.format.video.eColorFormat);
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
err = OMX_ErrorUndefined;
|
|
|
|
goto done;
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self,
|
2014-04-09 16:51:12 +00:00
|
|
|
"Setting output state: format %s (%d), width %u, height %u",
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_video_format_to_string (format),
|
2014-04-09 16:51:12 +00:00
|
|
|
port_def.format.video.eColorFormat,
|
2013-04-18 22:07:28 +00:00
|
|
|
(guint) port_def.format.video.nFrameWidth,
|
|
|
|
(guint) port_def.format.video.nFrameHeight);
|
2013-02-25 10:55:04 +00:00
|
|
|
|
|
|
|
state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (self),
|
|
|
|
format, port_def.format.video.nFrameWidth,
|
|
|
|
port_def.format.video.nFrameHeight, self->input_state);
|
|
|
|
|
|
|
|
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
|
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to negotiate");
|
|
|
|
err = OMX_ErrorUndefined;
|
2014-06-02 13:34:09 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2013-02-25 10:55:04 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
enable_port:
|
|
|
|
#endif
|
|
|
|
err = gst_omx_video_dec_allocate_output_buffers (self);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
err = gst_omx_port_populate (port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
err = gst_omx_port_mark_reconfigured (port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
done:
|
2013-03-07 13:10:12 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-05-30 13:29:15 +00:00
|
|
|
static void
|
|
|
|
gst_omx_video_dec_clean_older_frames (GstOMXVideoDec * self,
|
|
|
|
GstOMXBuffer * buf, GList * frames)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
2016-06-17 09:06:48 +00:00
|
|
|
timestamp =
|
|
|
|
gst_util_uint64_scale (GST_OMX_GET_TICKS (buf->omx_buf->nTimeStamp),
|
|
|
|
GST_SECOND, OMX_TICKS_PER_SECOND);
|
2014-05-30 13:29:15 +00:00
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
|
|
|
/* We could release all frames stored with pts < timestamp since the
|
|
|
|
* decoder will likely output frames in display order */
|
|
|
|
for (l = frames; l; l = l->next) {
|
|
|
|
GstVideoCodecFrame *tmp = l->data;
|
|
|
|
|
|
|
|
if (tmp->pts < timestamp) {
|
|
|
|
gst_video_decoder_release_frame (GST_VIDEO_DECODER (self), tmp);
|
|
|
|
GST_LOG_OBJECT (self,
|
|
|
|
"discarding ghost frame %p (#%d) PTS:%" GST_TIME_FORMAT " DTS:%"
|
|
|
|
GST_TIME_FORMAT, tmp, tmp->system_frame_number,
|
|
|
|
GST_TIME_ARGS (tmp->pts), GST_TIME_ARGS (tmp->dts));
|
|
|
|
} else {
|
|
|
|
gst_video_codec_frame_unref (tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* We will release all frames with invalid timestamp because we don't even
|
|
|
|
* know if they will be output some day. */
|
|
|
|
for (l = frames; l; l = l->next) {
|
|
|
|
GstVideoCodecFrame *tmp = l->data;
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (tmp->pts)) {
|
|
|
|
gst_video_decoder_release_frame (GST_VIDEO_DECODER (self), tmp);
|
|
|
|
GST_LOG_OBJECT (self,
|
|
|
|
"discarding frame %p (#%d) with invalid PTS:%" GST_TIME_FORMAT
|
|
|
|
" DTS:%" GST_TIME_FORMAT, tmp, tmp->system_frame_number,
|
|
|
|
GST_TIME_ARGS (tmp->pts), GST_TIME_ARGS (tmp->dts));
|
|
|
|
} else {
|
|
|
|
gst_video_codec_frame_unref (tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (frames);
|
|
|
|
}
|
|
|
|
|
2014-06-24 12:52:58 +00:00
|
|
|
static GstBuffer *
|
|
|
|
copy_frame (const GstVideoInfo * info, GstBuffer * outbuf)
|
|
|
|
{
|
|
|
|
GstVideoInfo out_info, tmp_info;
|
|
|
|
GstBuffer *tmpbuf;
|
|
|
|
GstVideoFrame out_frame, tmp_frame;
|
|
|
|
|
|
|
|
out_info = *info;
|
|
|
|
tmp_info = *info;
|
|
|
|
|
|
|
|
tmpbuf = gst_buffer_new_and_alloc (out_info.size);
|
|
|
|
|
|
|
|
gst_video_frame_map (&out_frame, &out_info, outbuf, GST_MAP_READ);
|
|
|
|
gst_video_frame_map (&tmp_frame, &tmp_info, tmpbuf, GST_MAP_WRITE);
|
|
|
|
gst_video_frame_copy (&tmp_frame, &out_frame);
|
|
|
|
gst_video_frame_unmap (&out_frame);
|
|
|
|
gst_video_frame_unmap (&tmp_frame);
|
|
|
|
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
|
|
|
|
return tmpbuf;
|
|
|
|
}
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
static void
|
|
|
|
gst_omx_video_dec_loop (GstOMXVideoDec * self)
|
|
|
|
{
|
2013-02-25 10:55:04 +00:00
|
|
|
GstOMXPort *port;
|
2011-06-28 06:51:23 +00:00
|
|
|
GstOMXBuffer *buf = NULL;
|
2012-06-20 12:11:58 +00:00
|
|
|
GstVideoCodecFrame *frame;
|
2011-06-28 06:51:23 +00:00
|
|
|
GstFlowReturn flow_ret = GST_FLOW_OK;
|
2011-07-07 10:23:24 +00:00
|
|
|
GstOMXAcquireBufferReturn acq_return;
|
2011-11-09 08:00:57 +00:00
|
|
|
GstClockTimeDiff deadline;
|
2013-03-11 09:04:10 +00:00
|
|
|
OMX_ERRORTYPE err;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
port = self->eglimage ? self->egl_out_port : self->dec_out_port;
|
|
|
|
#else
|
|
|
|
port = self->dec_out_port;
|
|
|
|
#endif
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
acq_return = gst_omx_port_acquire_buffer (port, &buf);
|
|
|
|
if (acq_return == GST_OMX_ACQUIRE_BUFFER_ERROR) {
|
|
|
|
goto component_error;
|
|
|
|
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
|
|
|
|
goto flushing;
|
2013-03-14 11:49:42 +00:00
|
|
|
} else if (acq_return == GST_OMX_ACQUIRE_BUFFER_EOS) {
|
|
|
|
goto eos;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 15:55:16 +00:00
|
|
|
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (self)) ||
|
|
|
|
acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
|
2012-06-20 12:11:58 +00:00
|
|
|
GstVideoCodecState *state;
|
2011-06-28 06:51:23 +00:00
|
|
|
OMX_PARAM_PORTDEFINITIONTYPE port_def;
|
2012-06-20 12:11:58 +00:00
|
|
|
GstVideoFormat format;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-07-08 13:25:07 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
|
|
|
|
|
2013-02-27 15:55:16 +00:00
|
|
|
/* Reallocate all buffers */
|
2013-02-28 16:02:31 +00:00
|
|
|
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE
|
|
|
|
&& gst_omx_port_is_enabled (port)) {
|
2013-02-27 15:55:16 +00:00
|
|
|
err = gst_omx_port_set_enabled (port, FALSE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_buffers_released (port, 5 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
2013-03-07 13:10:12 +00:00
|
|
|
err = gst_omx_video_dec_deallocate_output_buffers (self);
|
2013-02-27 15:55:16 +00:00
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
|
|
|
|
/* We have the possibility to reconfigure everything now */
|
|
|
|
err = gst_omx_video_dec_reconfigure_output_port (self);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
} else {
|
|
|
|
/* Just update caps */
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2012-12-20 11:20:31 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_omx_port_get_port_definition (port, &port_def);
|
|
|
|
g_assert (port_def.format.video.eCompressionFormat ==
|
|
|
|
OMX_VIDEO_CodingUnused);
|
2011-07-18 06:41:20 +00:00
|
|
|
|
2014-04-09 16:51:12 +00:00
|
|
|
format =
|
2016-01-19 18:10:38 +00:00
|
|
|
gst_omx_video_get_format_from_omx (port_def.format.video.
|
|
|
|
eColorFormat);
|
2014-04-09 16:51:12 +00:00
|
|
|
|
|
|
|
if (format == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
GST_ERROR_OBJECT (self, "Unsupported color format: %d",
|
|
|
|
port_def.format.video.eColorFormat);
|
|
|
|
if (buf)
|
|
|
|
gst_omx_port_release_buffer (port, buf);
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
goto caps_failed;
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
GST_DEBUG_OBJECT (self,
|
2014-04-09 16:51:12 +00:00
|
|
|
"Setting output state: format %s (%d), width %u, height %u",
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_video_format_to_string (format),
|
2014-04-09 16:51:12 +00:00
|
|
|
port_def.format.video.eColorFormat,
|
2013-04-18 22:07:28 +00:00
|
|
|
(guint) port_def.format.video.nFrameWidth,
|
|
|
|
(guint) port_def.format.video.nFrameHeight);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
state = gst_video_decoder_set_output_state (GST_VIDEO_DECODER (self),
|
|
|
|
format, port_def.format.video.nFrameWidth,
|
|
|
|
port_def.format.video.nFrameHeight, self->input_state);
|
2011-11-10 14:17:41 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
/* Take framerate and pixel-aspect-ratio from sinkpad caps */
|
2013-02-27 15:55:16 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
|
|
|
|
if (buf)
|
2013-04-18 14:03:56 +00:00
|
|
|
gst_omx_port_release_buffer (port, buf);
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
goto caps_failed;
|
|
|
|
}
|
2013-02-27 15:55:16 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_video_codec_state_unref (state);
|
2013-03-08 14:56:40 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2013-02-27 15:55:16 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 13:25:07 +00:00
|
|
|
/* Now get a buffer */
|
2013-01-11 11:52:10 +00:00
|
|
|
if (acq_return != GST_OMX_ACQUIRE_BUFFER_OK) {
|
2011-06-28 06:51:23 +00:00
|
|
|
return;
|
2013-01-11 11:52:10 +00:00
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 23:20:24 +00:00
|
|
|
g_assert (acq_return == GST_OMX_ACQUIRE_BUFFER_OK);
|
2011-07-07 10:23:24 +00:00
|
|
|
|
2013-01-11 11:52:10 +00:00
|
|
|
/* This prevents a deadlock between the srcpad stream
|
|
|
|
* lock and the videocodec stream lock, if ::reset()
|
|
|
|
* is called at the wrong time
|
|
|
|
*/
|
2013-04-18 14:03:56 +00:00
|
|
|
if (gst_omx_port_is_flushing (port)) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Flushing");
|
2013-04-18 14:03:56 +00:00
|
|
|
gst_omx_port_release_buffer (port, buf);
|
2013-01-11 11:52:10 +00:00
|
|
|
goto flushing;
|
|
|
|
}
|
|
|
|
|
2013-04-18 22:07:28 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Handling buffer: 0x%08x %" G_GUINT64_FORMAT,
|
2016-06-17 09:06:48 +00:00
|
|
|
(guint) buf->omx_buf->nFlags,
|
|
|
|
(guint64) GST_OMX_GET_TICKS (buf->omx_buf->nTimeStamp));
|
2013-03-14 11:49:42 +00:00
|
|
|
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2014-03-03 15:15:24 +00:00
|
|
|
frame = gst_omx_video_find_nearest_frame (buf,
|
|
|
|
gst_video_decoder_get_frames (GST_VIDEO_DECODER (self)));
|
2014-05-30 13:29:15 +00:00
|
|
|
|
|
|
|
/* So we have a timestamped OMX buffer and get, or not, corresponding frame.
|
|
|
|
* Assuming decoder output frames in display order, frames preceding this
|
|
|
|
* frame could be discarded as they seems useless due to e.g interlaced
|
|
|
|
* stream, corrupted input data...
|
|
|
|
* In any cases, not likely to be seen again. so drop it before they pile up
|
|
|
|
* and use all the memory. */
|
|
|
|
gst_omx_video_dec_clean_older_frames (self, buf,
|
|
|
|
gst_video_decoder_get_frames (GST_VIDEO_DECODER (self)));
|
2013-03-14 11:49:42 +00:00
|
|
|
|
|
|
|
if (frame
|
|
|
|
&& (deadline = gst_video_decoder_get_max_decode_time
|
|
|
|
(GST_VIDEO_DECODER (self), frame)) < 0) {
|
|
|
|
GST_WARNING_OBJECT (self,
|
|
|
|
"Frame is too late, dropping (deadline %" GST_TIME_FORMAT ")",
|
|
|
|
GST_TIME_ARGS (-deadline));
|
|
|
|
flow_ret = gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
|
|
|
|
frame = NULL;
|
2013-02-25 10:55:04 +00:00
|
|
|
} else if (!frame && (buf->omx_buf->nFilledLen > 0 || buf->eglimage)) {
|
2014-05-19 07:08:33 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
2013-03-14 11:49:42 +00:00
|
|
|
|
|
|
|
/* This sometimes happens at EOS or if the input is not properly framed,
|
|
|
|
* let's handle it gracefully by allocating a new buffer for the current
|
|
|
|
* caps and filling it
|
|
|
|
*/
|
2012-04-30 23:20:24 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_ERROR_OBJECT (self, "No corresponding frame found");
|
2012-04-30 23:20:24 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
if (self->out_port_pool) {
|
|
|
|
gint i, n;
|
|
|
|
GstBufferPoolAcquireParams params = { 0, };
|
2013-03-07 13:10:12 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
n = port->buffers->len;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstOMXBuffer *tmp = g_ptr_array_index (port->buffers, i);
|
2013-03-07 13:10:12 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
if (tmp == buf)
|
|
|
|
break;
|
2011-07-06 11:19:15 +00:00
|
|
|
}
|
2013-03-14 11:49:42 +00:00
|
|
|
g_assert (i != n);
|
|
|
|
|
|
|
|
GST_OMX_BUFFER_POOL (self->out_port_pool)->current_buffer_index = i;
|
|
|
|
flow_ret =
|
|
|
|
gst_buffer_pool_acquire_buffer (self->out_port_pool, &outbuf,
|
|
|
|
¶ms);
|
|
|
|
if (flow_ret != GST_FLOW_OK) {
|
|
|
|
gst_omx_port_release_buffer (port, buf);
|
|
|
|
goto invalid_buffer;
|
|
|
|
}
|
2014-06-24 12:52:58 +00:00
|
|
|
|
|
|
|
if (GST_OMX_BUFFER_POOL (self->out_port_pool)->need_copy)
|
|
|
|
outbuf =
|
|
|
|
copy_frame (&GST_OMX_BUFFER_POOL (self->out_port_pool)->video_info,
|
|
|
|
outbuf);
|
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
buf = NULL;
|
|
|
|
} else {
|
|
|
|
outbuf =
|
|
|
|
gst_video_decoder_allocate_output_buffer (GST_VIDEO_DECODER (self));
|
|
|
|
if (!gst_omx_video_dec_fill_buffer (self, buf, outbuf)) {
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
gst_omx_port_release_buffer (port, buf);
|
|
|
|
goto invalid_buffer;
|
|
|
|
}
|
|
|
|
}
|
2012-04-30 23:20:24 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
flow_ret = gst_pad_push (GST_VIDEO_DECODER_SRC_PAD (self), outbuf);
|
2013-02-25 10:55:04 +00:00
|
|
|
} else if (buf->omx_buf->nFilledLen > 0 || buf->eglimage) {
|
2013-03-14 11:49:42 +00:00
|
|
|
if (self->out_port_pool) {
|
|
|
|
gint i, n;
|
2014-06-24 12:52:58 +00:00
|
|
|
GstBuffer *outbuf;
|
2013-03-14 11:49:42 +00:00
|
|
|
GstBufferPoolAcquireParams params = { 0, };
|
2013-03-07 13:10:12 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
n = port->buffers->len;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstOMXBuffer *tmp = g_ptr_array_index (port->buffers, i);
|
2013-03-07 13:10:12 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
if (tmp == buf)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_assert (i != n);
|
2013-03-07 13:10:12 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_OMX_BUFFER_POOL (self->out_port_pool)->current_buffer_index = i;
|
|
|
|
flow_ret =
|
|
|
|
gst_buffer_pool_acquire_buffer (self->out_port_pool,
|
2014-06-24 12:52:58 +00:00
|
|
|
&outbuf, ¶ms);
|
2013-03-14 11:49:42 +00:00
|
|
|
if (flow_ret != GST_FLOW_OK) {
|
2013-03-07 13:10:12 +00:00
|
|
|
flow_ret =
|
2013-03-14 11:49:42 +00:00
|
|
|
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
|
|
|
|
frame = NULL;
|
|
|
|
gst_omx_port_release_buffer (port, buf);
|
|
|
|
goto invalid_buffer;
|
|
|
|
}
|
2014-06-24 12:52:58 +00:00
|
|
|
|
|
|
|
if (GST_OMX_BUFFER_POOL (self->out_port_pool)->need_copy)
|
|
|
|
outbuf =
|
|
|
|
copy_frame (&GST_OMX_BUFFER_POOL (self->out_port_pool)->video_info,
|
|
|
|
outbuf);
|
|
|
|
|
|
|
|
frame->output_buffer = outbuf;
|
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
flow_ret =
|
|
|
|
gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame);
|
|
|
|
frame = NULL;
|
|
|
|
buf = NULL;
|
|
|
|
} else {
|
|
|
|
if ((flow_ret =
|
|
|
|
gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER
|
|
|
|
(self), frame)) == GST_FLOW_OK) {
|
|
|
|
/* FIXME: This currently happens because of a race condition too.
|
|
|
|
* We first need to reconfigure the output port and then the input
|
|
|
|
* port if both need reconfiguration.
|
|
|
|
*/
|
|
|
|
if (!gst_omx_video_dec_fill_buffer (self, buf, frame->output_buffer)) {
|
|
|
|
gst_buffer_replace (&frame->output_buffer, NULL);
|
2012-04-30 23:20:24 +00:00
|
|
|
flow_ret =
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
|
|
|
|
frame = NULL;
|
2013-03-12 18:16:46 +00:00
|
|
|
gst_omx_port_release_buffer (port, buf);
|
2012-04-30 23:20:24 +00:00
|
|
|
goto invalid_buffer;
|
|
|
|
}
|
2012-06-20 12:11:58 +00:00
|
|
|
flow_ret =
|
|
|
|
gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame);
|
2013-01-11 11:52:10 +00:00
|
|
|
frame = NULL;
|
2012-04-30 23:20:24 +00:00
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
2013-03-14 11:49:42 +00:00
|
|
|
} else if (frame != NULL) {
|
|
|
|
flow_ret = gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
|
|
|
|
frame = NULL;
|
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Read frame from component");
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Finished frame: %s", gst_flow_get_name (flow_ret));
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
if (buf) {
|
|
|
|
err = gst_omx_port_release_buffer (port, buf);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto release_error;
|
2012-04-30 23:20:24 +00:00
|
|
|
}
|
2011-11-01 12:58:38 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
self->downstream_flow_ret = flow_ret;
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
if (flow_ret != GST_FLOW_OK)
|
|
|
|
goto flow_error;
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2011-11-09 14:45:20 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
component_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, FAILED, (NULL),
|
2011-07-13 18:22:51 +00:00
|
|
|
("OpenMAX component in error state %s (0x%08x)",
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_get_last_error_string (self->dec),
|
|
|
|
gst_omx_component_get_last_error (self->dec)));
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_ERROR;
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
2011-06-28 06:51:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
flushing:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (self, "Flushing -- stopping task");
|
2015-11-18 12:59:59 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
|
|
|
if (self->draining) {
|
|
|
|
self->draining = FALSE;
|
|
|
|
g_cond_broadcast (&self->drain_cond);
|
|
|
|
}
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2012-04-12 19:57:32 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_FLUSHING;
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
2015-11-18 12:59:59 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2011-06-28 06:51:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
eos:
|
|
|
|
{
|
|
|
|
g_mutex_lock (&self->drain_lock);
|
|
|
|
if (self->draining) {
|
2014-06-18 21:04:33 +00:00
|
|
|
GstQuery *query = gst_query_new_drain ();
|
|
|
|
|
2014-03-10 16:43:50 +00:00
|
|
|
/* Drain the pipeline to reclaim all memories back to the pool */
|
2014-06-18 21:04:33 +00:00
|
|
|
if (!gst_pad_peer_query (GST_VIDEO_DECODER_SRC_PAD (self), query))
|
|
|
|
GST_DEBUG_OBJECT (self, "drain query failed");
|
|
|
|
gst_query_unref (query);
|
2014-03-10 16:43:50 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Drained");
|
|
|
|
self->draining = FALSE;
|
|
|
|
g_cond_broadcast (&self->drain_cond);
|
|
|
|
flow_ret = GST_FLOW_OK;
|
2013-03-15 10:46:34 +00:00
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2013-03-14 11:49:42 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (self, "Component signalled EOS");
|
|
|
|
flow_ret = GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2013-05-20 10:06:34 +00:00
|
|
|
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2013-03-14 11:49:42 +00:00
|
|
|
self->downstream_flow_ret = flow_ret;
|
|
|
|
|
2013-03-16 09:00:24 +00:00
|
|
|
/* Here we fallback and pause the task for the EOS case */
|
2013-03-14 11:49:42 +00:00
|
|
|
if (flow_ret != GST_FLOW_OK)
|
|
|
|
goto flow_error;
|
|
|
|
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
flow_error:
|
|
|
|
{
|
2012-04-12 19:57:32 +00:00
|
|
|
if (flow_ret == GST_FLOW_EOS) {
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "EOS");
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self),
|
2011-06-28 06:51:23 +00:00
|
|
|
gst_event_new_eos ());
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2014-01-25 16:44:14 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
} else if (flow_ret < GST_FLOW_EOS) {
|
2013-02-25 11:38:27 +00:00
|
|
|
GST_ELEMENT_ERROR (self, STREAM, FAILED,
|
|
|
|
("Internal data stream error."), ("stream stopped, reason %s",
|
|
|
|
gst_flow_get_name (flow_ret)));
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self),
|
2011-06-28 06:51:23 +00:00
|
|
|
gst_event_new_eos ());
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2014-01-25 16:44:14 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
} else if (flow_ret == GST_FLOW_FLUSHING) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Flushing -- stopping task");
|
2015-11-18 12:59:59 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
|
|
|
if (self->draining) {
|
|
|
|
self->draining = FALSE;
|
|
|
|
g_cond_broadcast (&self->drain_cond);
|
|
|
|
}
|
2014-01-25 16:44:14 +00:00
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
|
|
|
self->started = FALSE;
|
2015-11-18 12:59:59 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2011-06-28 06:51:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
reconfigure_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
|
|
|
|
("Unable to reconfigure output port"));
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_ERROR;
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
2011-07-06 11:19:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
|
2011-07-18 06:41:20 +00:00
|
|
|
invalid_buffer:
|
2011-07-06 11:19:15 +00:00
|
|
|
{
|
2011-07-18 06:41:20 +00:00
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
|
|
|
|
("Invalid sized input buffer"));
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_NOT_NEGOTIATED;
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2011-06-28 06:51:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
|
2011-07-08 13:25:07 +00:00
|
|
|
caps_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL), ("Failed to set caps"));
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_NOT_NEGOTIATED;
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
2011-07-08 13:25:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-11 09:04:10 +00:00
|
|
|
release_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
|
|
|
|
("Failed to relase output buffer to component: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err));
|
|
|
|
gst_pad_push_event (GST_VIDEO_DECODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_VIDEO_DECODER_SRC_PAD (self));
|
|
|
|
self->downstream_flow_ret = GST_FLOW_ERROR;
|
|
|
|
self->started = FALSE;
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_omx_video_dec_start (GstVideoDecoder * decoder)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
|
|
|
GstOMXVideoDec *self;
|
|
|
|
|
|
|
|
self = GST_OMX_VIDEO_DEC (decoder);
|
|
|
|
|
2011-12-06 11:47:12 +00:00
|
|
|
self->last_upstream_ts = 0;
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2012-12-20 11:30:05 +00:00
|
|
|
return TRUE;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_omx_video_dec_stop (GstVideoDecoder * decoder)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
|
|
|
GstOMXVideoDec *self;
|
|
|
|
|
|
|
|
self = GST_OMX_VIDEO_DEC (decoder);
|
|
|
|
|
2011-09-27 12:15:06 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Stopping decoder");
|
|
|
|
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, TRUE);
|
2011-11-18 17:58:58 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_omx_port_set_flushing (self->egl_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->egl_out_port, 5 * GST_SECOND, TRUE);
|
|
|
|
#endif
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_pad_stop_task (GST_VIDEO_DECODER_SRC_PAD (decoder));
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_component_get_state (self->dec, 0) > OMX_StateIdle)
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateIdle);
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
if (gst_omx_component_get_state (self->egl_render, 0) > OMX_StateIdle)
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateIdle);
|
|
|
|
#endif
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_FLUSHING;
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
2011-11-01 12:58:38 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
2011-11-01 15:08:59 +00:00
|
|
|
self->draining = FALSE;
|
2012-11-12 10:29:48 +00:00
|
|
|
g_cond_broadcast (&self->drain_cond);
|
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_get_state (self->dec, 5 * GST_SECOND);
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_omx_component_get_state (self->egl_render, 1 * GST_SECOND);
|
|
|
|
#endif
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
gst_buffer_replace (&self->codec_data, NULL);
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
if (self->input_state)
|
|
|
|
gst_video_codec_state_unref (self->input_state);
|
|
|
|
self->input_state = NULL;
|
|
|
|
|
2011-09-27 12:15:06 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Stopped decoder");
|
|
|
|
|
2011-07-13 19:19:34 +00:00
|
|
|
return TRUE;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 10:42:38 +00:00
|
|
|
static gboolean
|
|
|
|
gst_omx_video_dec_negotiate (GstOMXVideoDec * self)
|
|
|
|
{
|
|
|
|
OMX_VIDEO_PARAM_PORTFORMATTYPE param;
|
|
|
|
OMX_ERRORTYPE err;
|
|
|
|
GstCaps *comp_supported_caps;
|
|
|
|
GList *negotiation_map = NULL, *l;
|
2013-03-07 10:24:54 +00:00
|
|
|
GstCaps *templ_caps, *intersection;
|
2013-02-25 10:42:38 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
GstStructure *s;
|
|
|
|
const gchar *format_str;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Trying to negotiate a video format with downstream");
|
|
|
|
|
2013-03-07 10:24:54 +00:00
|
|
|
templ_caps = gst_pad_get_pad_template_caps (GST_VIDEO_DECODER_SRC_PAD (self));
|
|
|
|
intersection =
|
|
|
|
gst_pad_peer_query_caps (GST_VIDEO_DECODER_SRC_PAD (self), templ_caps);
|
|
|
|
gst_caps_unref (templ_caps);
|
2013-02-25 10:42:38 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Allowed downstream caps: %" GST_PTR_FORMAT,
|
|
|
|
intersection);
|
|
|
|
|
2014-03-03 15:15:24 +00:00
|
|
|
negotiation_map =
|
|
|
|
gst_omx_video_get_supported_colorformats (self->dec_out_port,
|
|
|
|
self->input_state);
|
2013-02-25 10:42:38 +00:00
|
|
|
|
2014-03-12 11:47:34 +00:00
|
|
|
comp_supported_caps = gst_omx_video_get_caps_for_map (negotiation_map);
|
2013-02-25 10:42:38 +00:00
|
|
|
|
2011-09-02 12:43:43 +00:00
|
|
|
if (!gst_caps_is_empty (comp_supported_caps)) {
|
|
|
|
GstCaps *tmp;
|
|
|
|
|
|
|
|
tmp = gst_caps_intersect (comp_supported_caps, intersection);
|
|
|
|
gst_caps_unref (intersection);
|
|
|
|
intersection = tmp;
|
|
|
|
}
|
2012-12-20 10:40:13 +00:00
|
|
|
gst_caps_unref (comp_supported_caps);
|
|
|
|
|
2011-09-02 12:43:43 +00:00
|
|
|
if (gst_caps_is_empty (intersection)) {
|
2012-04-12 19:57:32 +00:00
|
|
|
gst_caps_unref (intersection);
|
2011-09-02 12:43:43 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Empty caps");
|
2012-12-20 11:02:30 +00:00
|
|
|
g_list_free_full (negotiation_map,
|
2014-03-03 15:15:24 +00:00
|
|
|
(GDestroyNotify) gst_omx_video_negotiation_map_free);
|
2011-09-02 12:43:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
intersection = gst_caps_truncate (intersection);
|
2012-12-20 10:40:13 +00:00
|
|
|
intersection = gst_caps_fixate (intersection);
|
2011-09-02 12:43:43 +00:00
|
|
|
|
|
|
|
s = gst_caps_get_structure (intersection, 0);
|
2012-04-12 19:57:32 +00:00
|
|
|
format_str = gst_structure_get_string (s, "format");
|
|
|
|
if (!format_str ||
|
2011-09-02 12:43:43 +00:00
|
|
|
(format =
|
2012-04-12 19:57:32 +00:00
|
|
|
gst_video_format_from_string (format_str)) ==
|
|
|
|
GST_VIDEO_FORMAT_UNKNOWN) {
|
2011-09-02 12:43:43 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Invalid caps: %" GST_PTR_FORMAT, intersection);
|
2014-03-07 12:18:49 +00:00
|
|
|
gst_caps_unref (intersection);
|
2012-12-20 11:02:30 +00:00
|
|
|
g_list_free_full (negotiation_map,
|
2014-03-03 15:15:24 +00:00
|
|
|
(GDestroyNotify) gst_omx_video_negotiation_map_free);
|
2011-09-02 12:43:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-27 10:30:14 +00:00
|
|
|
GST_OMX_INIT_STRUCT (¶m);
|
|
|
|
param.nPortIndex = self->dec_out_port->index;
|
|
|
|
|
2012-12-20 10:55:36 +00:00
|
|
|
for (l = negotiation_map; l; l = l->next) {
|
2014-03-03 15:15:24 +00:00
|
|
|
GstOMXVideoNegotiationMap *m = l->data;
|
2012-12-20 10:55:36 +00:00
|
|
|
|
|
|
|
if (m->format == format) {
|
|
|
|
param.eColorFormat = m->type;
|
2011-09-02 12:43:43 +00:00
|
|
|
break;
|
2012-12-20 10:55:36 +00:00
|
|
|
}
|
2011-09-02 12:43:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Negotiating color format %s (%d)", format_str,
|
|
|
|
param.eColorFormat);
|
|
|
|
|
2012-12-20 10:55:36 +00:00
|
|
|
/* We must find something here */
|
|
|
|
g_assert (l != NULL);
|
2012-12-20 11:02:30 +00:00
|
|
|
g_list_free_full (negotiation_map,
|
2014-03-03 15:15:24 +00:00
|
|
|
(GDestroyNotify) gst_omx_video_negotiation_map_free);
|
2012-12-20 10:55:36 +00:00
|
|
|
|
2011-09-02 12:43:43 +00:00
|
|
|
err =
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_set_parameter (self->dec,
|
2011-09-02 12:43:43 +00:00
|
|
|
OMX_IndexParamVideoPortFormat, ¶m);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to set video port format: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
}
|
|
|
|
|
2014-04-16 09:00:55 +00:00
|
|
|
gst_caps_unref (intersection);
|
2011-09-02 12:43:43 +00:00
|
|
|
return (err == OMX_ErrorNone);
|
|
|
|
}
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
static gboolean
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_omx_video_dec_set_format (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecState * state)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
|
|
|
GstOMXVideoDec *self;
|
|
|
|
GstOMXVideoDecClass *klass;
|
2012-06-20 12:11:58 +00:00
|
|
|
GstVideoInfo *info = &state->info;
|
2011-06-28 06:51:23 +00:00
|
|
|
gboolean is_format_change = FALSE;
|
|
|
|
gboolean needs_disable = FALSE;
|
|
|
|
OMX_PARAM_PORTDEFINITIONTYPE port_def;
|
|
|
|
|
|
|
|
self = GST_OMX_VIDEO_DEC (decoder);
|
|
|
|
klass = GST_OMX_VIDEO_DEC_GET_CLASS (decoder);
|
|
|
|
|
2011-07-19 10:29:51 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting new caps %" GST_PTR_FORMAT, state->caps);
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_port_get_port_definition (self->dec_in_port, &port_def);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
/* Check if the caps change is a real format change or if only irrelevant
|
|
|
|
* parts of the caps have changed or nothing at all.
|
|
|
|
*/
|
2012-06-20 12:11:58 +00:00
|
|
|
is_format_change |= port_def.format.video.nFrameWidth != info->width;
|
|
|
|
is_format_change |= port_def.format.video.nFrameHeight != info->height;
|
2011-06-28 06:51:23 +00:00
|
|
|
is_format_change |= (port_def.format.video.xFramerate == 0
|
2012-06-20 12:11:58 +00:00
|
|
|
&& info->fps_n != 0)
|
2011-06-28 06:51:23 +00:00
|
|
|
|| (port_def.format.video.xFramerate !=
|
2012-06-20 12:11:58 +00:00
|
|
|
(info->fps_n << 16) / (info->fps_d));
|
2011-06-28 06:51:23 +00:00
|
|
|
is_format_change |= (self->codec_data != state->codec_data);
|
|
|
|
if (klass->is_format_change)
|
2013-02-25 08:12:22 +00:00
|
|
|
is_format_change |=
|
|
|
|
klass->is_format_change (self, self->dec_in_port, state);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
needs_disable =
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_get_state (self->dec,
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateLoaded;
|
|
|
|
/* If the component is not in Loaded state and a real format change happens
|
|
|
|
* we have to disable the port and re-allocate all buffers. If no real
|
|
|
|
* format change happened we can just exit here.
|
|
|
|
*/
|
|
|
|
if (needs_disable && !is_format_change) {
|
|
|
|
GST_DEBUG_OBJECT (self,
|
|
|
|
"Already running and caps did not change the format");
|
2012-06-20 12:11:58 +00:00
|
|
|
if (self->input_state)
|
|
|
|
gst_video_codec_state_unref (self->input_state);
|
|
|
|
self->input_state = gst_video_codec_state_ref (state);
|
2011-06-28 06:51:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-09-27 12:15:06 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
if (needs_disable && is_format_change) {
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
GstOMXPort *out_port =
|
|
|
|
self->eglimage ? self->egl_out_port : self->dec_out_port;
|
|
|
|
#else
|
|
|
|
GstOMXPort *out_port = self->dec_out_port;
|
|
|
|
#endif
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Need to disable and drain decoder");
|
|
|
|
|
2016-06-17 07:59:45 +00:00
|
|
|
gst_omx_video_dec_drain (decoder);
|
2014-03-10 16:43:50 +00:00
|
|
|
gst_omx_video_dec_flush (decoder);
|
2013-02-25 10:55:04 +00:00
|
|
|
gst_omx_port_set_flushing (out_port, 5 * GST_SECOND, TRUE);
|
2013-03-09 13:14:40 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
if (klass->cdata.hacks & GST_OMX_HACK_NO_COMPONENT_RECONFIGURE) {
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
gst_omx_video_dec_stop (GST_VIDEO_DECODER (self));
|
2012-10-22 12:34:53 +00:00
|
|
|
gst_omx_video_dec_close (GST_VIDEO_DECODER (self));
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-09-27 12:15:06 +00:00
|
|
|
|
2012-10-22 12:34:53 +00:00
|
|
|
if (!gst_omx_video_dec_open (GST_VIDEO_DECODER (self)))
|
2011-09-27 12:15:06 +00:00
|
|
|
return FALSE;
|
|
|
|
needs_disable = FALSE;
|
|
|
|
} else {
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
if (self->eglimage) {
|
2013-05-10 10:25:07 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->egl_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->egl_out_port, 5 * GST_SECOND, TRUE);
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-25 10:55:04 +00:00
|
|
|
|
2013-05-10 10:25:07 +00:00
|
|
|
if (gst_omx_port_set_enabled (self->dec_in_port, FALSE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_set_enabled (out_port, FALSE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_buffers_released (self->dec_in_port,
|
|
|
|
5 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_buffers_released (out_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_deallocate_buffers (self->dec_in_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_video_dec_deallocate_output_buffers (self) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_enabled (self->dec_in_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_enabled (out_port, 1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2013-02-25 10:55:04 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-05-10 10:25:07 +00:00
|
|
|
if (self->eglimage) {
|
|
|
|
OMX_STATETYPE egl_state;
|
2013-02-25 10:55:04 +00:00
|
|
|
|
|
|
|
egl_state = gst_omx_component_get_state (self->egl_render, 0);
|
|
|
|
if (egl_state > OMX_StateLoaded || egl_state == OMX_StateInvalid) {
|
2013-05-10 10:25:07 +00:00
|
|
|
|
2013-02-25 10:55:04 +00:00
|
|
|
if (egl_state > OMX_StateIdle) {
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateIdle);
|
2013-05-10 10:25:07 +00:00
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateIdle);
|
|
|
|
egl_state = gst_omx_component_get_state (self->egl_render,
|
|
|
|
5 * GST_SECOND);
|
|
|
|
gst_omx_component_get_state (self->dec, 1 * GST_SECOND);
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateLoaded);
|
2013-05-10 10:25:07 +00:00
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateLoaded);
|
2013-02-25 10:55:04 +00:00
|
|
|
|
2014-03-04 16:41:20 +00:00
|
|
|
gst_omx_close_tunnel (self->dec_out_port, self->egl_in_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
|
|
|
|
if (egl_state > OMX_StateLoaded) {
|
|
|
|
gst_omx_component_get_state (self->egl_render, 5 * GST_SECOND);
|
|
|
|
}
|
2013-05-10 10:25:07 +00:00
|
|
|
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateIdle);
|
|
|
|
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateExecuting);
|
|
|
|
gst_omx_component_get_state (self->dec, GST_CLOCK_TIME_NONE);
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
self->eglimage = FALSE;
|
|
|
|
}
|
2013-05-10 10:25:07 +00:00
|
|
|
#endif
|
2011-09-27 12:15:06 +00:00
|
|
|
}
|
2012-06-20 12:11:58 +00:00
|
|
|
if (self->input_state)
|
|
|
|
gst_video_codec_state_unref (self->input_state);
|
|
|
|
self->input_state = NULL;
|
2012-12-20 11:20:31 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Decoder drained and disabled");
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
port_def.format.video.nFrameWidth = info->width;
|
|
|
|
port_def.format.video.nFrameHeight = info->height;
|
|
|
|
if (info->fps_n == 0)
|
2011-06-28 06:51:23 +00:00
|
|
|
port_def.format.video.xFramerate = 0;
|
|
|
|
else
|
2012-06-20 12:11:58 +00:00
|
|
|
port_def.format.video.xFramerate = (info->fps_n << 16) / (info->fps_d);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting inport port definition");
|
|
|
|
|
2013-02-28 14:48:53 +00:00
|
|
|
if (gst_omx_port_update_port_definition (self->dec_in_port,
|
|
|
|
&port_def) != OMX_ErrorNone)
|
2011-06-28 06:51:23 +00:00
|
|
|
return FALSE;
|
2012-12-20 11:20:31 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
if (klass->set_format) {
|
2013-02-25 08:12:22 +00:00
|
|
|
if (!klass->set_format (self, self->dec_in_port, state)) {
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Subclass failed to set the new format");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-28 16:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Updating outport port definition");
|
|
|
|
if (gst_omx_port_update_port_definition (self->dec_out_port,
|
|
|
|
NULL) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
gst_buffer_replace (&self->codec_data, state->codec_data);
|
2012-06-20 12:11:58 +00:00
|
|
|
self->input_state = gst_video_codec_state_ref (state);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Enabling component");
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
if (needs_disable) {
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_port_set_enabled (self->dec_in_port, TRUE) != OMX_ErrorNone)
|
2011-06-28 06:51:23 +00:00
|
|
|
return FALSE;
|
2013-03-06 16:05:51 +00:00
|
|
|
if (gst_omx_port_allocate_buffers (self->dec_in_port) != OMX_ErrorNone)
|
2013-02-12 10:41:43 +00:00
|
|
|
return FALSE;
|
2014-05-15 08:58:34 +00:00
|
|
|
|
|
|
|
if ((klass->cdata.hacks & GST_OMX_HACK_NO_DISABLE_OUTPORT)) {
|
|
|
|
if (gst_omx_port_set_enabled (self->dec_out_port, TRUE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_allocate_buffers (self->dec_out_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_omx_port_wait_enabled (self->dec_out_port,
|
|
|
|
5 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_port_wait_enabled (self->dec_in_port,
|
2013-02-12 10:41:43 +00:00
|
|
|
5 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2013-02-27 14:49:56 +00:00
|
|
|
if (gst_omx_port_mark_reconfigured (self->dec_in_port) != OMX_ErrorNone)
|
2011-07-19 08:33:54 +00:00
|
|
|
return FALSE;
|
2011-06-28 06:51:23 +00:00
|
|
|
} else {
|
2013-03-07 16:38:40 +00:00
|
|
|
if (!gst_omx_video_dec_negotiate (self))
|
|
|
|
GST_LOG_OBJECT (self, "Negotiation failed, will get output format later");
|
|
|
|
|
2014-05-15 08:58:34 +00:00
|
|
|
if (!(klass->cdata.hacks & GST_OMX_HACK_NO_DISABLE_OUTPORT)) {
|
|
|
|
/* Disable output port */
|
|
|
|
if (gst_omx_port_set_enabled (self->dec_out_port, FALSE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-05-15 08:58:34 +00:00
|
|
|
if (gst_omx_port_wait_enabled (self->dec_out_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2013-02-28 16:02:31 +00:00
|
|
|
|
2014-05-15 08:58:34 +00:00
|
|
|
if (gst_omx_component_set_state (self->dec,
|
|
|
|
OMX_StateIdle) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2013-02-28 16:02:31 +00:00
|
|
|
|
2014-05-15 08:58:34 +00:00
|
|
|
/* Need to allocate buffers to reach Idle state */
|
|
|
|
if (gst_omx_port_allocate_buffers (self->dec_in_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (gst_omx_component_set_state (self->dec,
|
|
|
|
OMX_StateIdle) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Need to allocate buffers to reach Idle state */
|
|
|
|
if (gst_omx_port_allocate_buffers (self->dec_in_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_allocate_buffers (self->dec_out_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_component_get_state (self->dec,
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateIdle)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_component_set_state (self->dec,
|
2011-06-28 06:51:23 +00:00
|
|
|
OMX_StateExecuting) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2011-09-14 08:15:38 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_component_get_state (self->dec,
|
2011-09-14 08:15:38 +00:00
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateExecuting)
|
|
|
|
return FALSE;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unset flushing to allow ports to accept data again */
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_in_port, 5 * GST_SECOND, FALSE);
|
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, FALSE);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (gst_omx_component_get_last_error (self->dec) != OMX_ErrorNone) {
|
2011-07-13 18:22:51 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Component in error state: %s (0x%08x)",
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_get_last_error_string (self->dec),
|
|
|
|
gst_omx_component_get_last_error (self->dec));
|
2011-06-28 06:51:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2011-09-14 08:15:38 +00:00
|
|
|
return TRUE;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-01-29 18:31:26 +00:00
|
|
|
gst_omx_video_dec_flush (GstVideoDecoder * decoder)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
2014-01-29 18:31:26 +00:00
|
|
|
GstOMXVideoDec *self = GST_OMX_VIDEO_DEC (decoder);
|
2014-01-27 17:03:50 +00:00
|
|
|
OMX_ERRORTYPE err = OMX_ErrorNone;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-01-29 18:31:26 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Flushing decoder");
|
2011-11-07 13:00:47 +00:00
|
|
|
|
2014-03-01 17:48:17 +00:00
|
|
|
if (gst_omx_component_get_state (self->dec, 0) == OMX_StateLoaded)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-08-14 14:36:11 +00:00
|
|
|
/* 0) Pause the components */
|
2014-03-07 19:08:05 +00:00
|
|
|
if (gst_omx_component_get_state (self->dec, 0) == OMX_StateExecuting) {
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StatePause);
|
|
|
|
gst_omx_component_get_state (self->dec, GST_CLOCK_TIME_NONE);
|
|
|
|
}
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2014-03-07 19:08:05 +00:00
|
|
|
if (self->eglimage) {
|
|
|
|
if (gst_omx_component_get_state (self->egl_render, 0) == OMX_StateExecuting) {
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StatePause);
|
|
|
|
gst_omx_component_get_state (self->egl_render, GST_CLOCK_TIME_NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-18 19:46:55 +00:00
|
|
|
/* 1) Flush the ports */
|
2014-03-07 19:08:05 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "flushing ports");
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, TRUE);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2014-01-27 17:03:50 +00:00
|
|
|
if (self->eglimage) {
|
|
|
|
gst_omx_port_set_flushing (self->egl_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->egl_out_port, 5 * GST_SECOND, TRUE);
|
|
|
|
}
|
2013-02-25 10:55:04 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-18 19:46:55 +00:00
|
|
|
/* 2) Wait until the srcpad loop is stopped,
|
|
|
|
* unlock GST_VIDEO_DECODER_STREAM_LOCK to prevent deadlocks
|
|
|
|
* caused by using this lock from inside the loop function */
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
|
|
|
gst_pad_stop_task (GST_VIDEO_DECODER_SRC_PAD (decoder));
|
|
|
|
GST_DEBUG_OBJECT (self, "Flushing -- task stopped");
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
|
2014-03-07 19:08:05 +00:00
|
|
|
/* 3) Resume components */
|
|
|
|
gst_omx_component_set_state (self->dec, OMX_StateExecuting);
|
|
|
|
gst_omx_component_get_state (self->dec, GST_CLOCK_TIME_NONE);
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2014-03-07 19:08:05 +00:00
|
|
|
if (self->eglimage) {
|
|
|
|
gst_omx_component_set_state (self->egl_render, OMX_StateExecuting);
|
|
|
|
gst_omx_component_get_state (self->egl_render, GST_CLOCK_TIME_NONE);
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-03-07 19:08:05 +00:00
|
|
|
/* 4) Unset flushing to allow ports to accept data again */
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->dec_in_port, 5 * GST_SECOND, FALSE);
|
|
|
|
gst_omx_port_set_flushing (self->dec_out_port, 5 * GST_SECOND, FALSE);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2014-01-27 17:03:50 +00:00
|
|
|
if (self->eglimage) {
|
|
|
|
gst_omx_port_set_flushing (self->egl_in_port, 5 * GST_SECOND, FALSE);
|
|
|
|
gst_omx_port_set_flushing (self->egl_out_port, 5 * GST_SECOND, FALSE);
|
|
|
|
err = gst_omx_port_populate (self->egl_out_port);
|
2014-03-07 19:08:05 +00:00
|
|
|
gst_omx_port_mark_reconfigured (self->egl_out_port);
|
2014-01-27 17:03:50 +00:00
|
|
|
} else {
|
|
|
|
err = gst_omx_port_populate (self->dec_out_port);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
err = gst_omx_port_populate (self->dec_out_port);
|
2013-02-25 10:55:04 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-27 17:03:50 +00:00
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_WARNING_OBJECT (self, "Failed to populate output port: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
}
|
|
|
|
|
2014-03-07 19:08:05 +00:00
|
|
|
/* Reset our state */
|
2011-12-06 11:47:12 +00:00
|
|
|
self->last_upstream_ts = 0;
|
2011-11-01 12:58:38 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2014-03-07 19:08:05 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (self, "Flush finished");
|
2011-09-27 12:15:06 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_omx_video_dec_handle_frame (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
2011-07-07 10:23:24 +00:00
|
|
|
GstOMXAcquireBufferReturn acq_ret = GST_OMX_ACQUIRE_BUFFER_ERROR;
|
2011-06-28 06:51:23 +00:00
|
|
|
GstOMXVideoDec *self;
|
2011-09-29 08:37:32 +00:00
|
|
|
GstOMXVideoDecClass *klass;
|
2013-02-27 14:49:56 +00:00
|
|
|
GstOMXPort *port;
|
2011-06-28 06:51:23 +00:00
|
|
|
GstOMXBuffer *buf;
|
|
|
|
GstBuffer *codec_data = NULL;
|
2012-12-20 18:30:38 +00:00
|
|
|
guint offset = 0, size;
|
2013-03-15 08:51:42 +00:00
|
|
|
GstClockTime timestamp, duration;
|
2013-03-11 09:04:10 +00:00
|
|
|
OMX_ERRORTYPE err;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
self = GST_OMX_VIDEO_DEC (decoder);
|
2011-09-29 08:37:32 +00:00
|
|
|
klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Handling frame");
|
|
|
|
|
2014-03-07 19:08:05 +00:00
|
|
|
if (!self->started) {
|
|
|
|
if (!GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame)) {
|
|
|
|
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (self, "Starting task");
|
|
|
|
gst_pad_start_task (GST_VIDEO_DECODER_SRC_PAD (self),
|
|
|
|
(GstTaskFunction) gst_omx_video_dec_loop, decoder, NULL);
|
2013-03-15 13:09:45 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 12:11:58 +00:00
|
|
|
timestamp = frame->pts;
|
|
|
|
duration = frame->duration;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-11-01 12:58:38 +00:00
|
|
|
if (self->downstream_flow_ret != GST_FLOW_OK) {
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-11-01 12:58:38 +00:00
|
|
|
return self->downstream_flow_ret;
|
|
|
|
}
|
|
|
|
|
2011-09-29 08:37:32 +00:00
|
|
|
if (klass->prepare_frame) {
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
ret = klass->prepare_frame (self, frame);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (self, "Preparing frame failed: %s",
|
|
|
|
gst_flow_get_name (ret));
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-09-29 08:37:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 14:49:56 +00:00
|
|
|
port = self->dec_in_port;
|
|
|
|
|
2012-12-20 18:30:38 +00:00
|
|
|
size = gst_buffer_get_size (frame->input_buffer);
|
|
|
|
while (offset < size) {
|
2011-08-19 07:19:22 +00:00
|
|
|
/* Make sure to release the base class stream lock, otherwise
|
|
|
|
* _loop() can't call _finish_frame() and we might block forever
|
|
|
|
* because no input buffers are released */
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2013-02-27 14:49:56 +00:00
|
|
|
acq_ret = gst_omx_port_acquire_buffer (port, &buf);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-07-07 10:23:24 +00:00
|
|
|
goto component_error;
|
|
|
|
} else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-07-07 10:23:24 +00:00
|
|
|
goto flushing;
|
|
|
|
} else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
|
2013-02-27 14:49:56 +00:00
|
|
|
/* Reallocate all buffers */
|
|
|
|
err = gst_omx_port_set_enabled (port, FALSE);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_buffers_released (port, 5 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_deallocate_buffers (port);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_set_enabled (port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
2013-03-06 16:05:51 +00:00
|
|
|
err = gst_omx_port_allocate_buffers (port);
|
2013-02-27 14:49:56 +00:00
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_mark_reconfigured (port);
|
|
|
|
if (err != OMX_ErrorNone) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-07-07 10:23:24 +00:00
|
|
|
goto reconfigure_error;
|
2013-01-11 11:52:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
/* Now get a new buffer and fill it */
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-07-07 10:23:24 +00:00
|
|
|
continue;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
g_assert (acq_ret == GST_OMX_ACQUIRE_BUFFER_OK && buf != NULL);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-11-08 07:31:32 +00:00
|
|
|
if (buf->omx_buf->nAllocLen - buf->omx_buf->nOffset <= 0) {
|
2013-02-27 14:49:56 +00:00
|
|
|
gst_omx_port_release_buffer (port, buf);
|
2011-09-23 13:53:49 +00:00
|
|
|
goto full_buffer;
|
2011-11-08 07:31:32 +00:00
|
|
|
}
|
2011-09-23 13:53:49 +00:00
|
|
|
|
2011-11-01 12:58:38 +00:00
|
|
|
if (self->downstream_flow_ret != GST_FLOW_OK) {
|
2013-02-27 14:49:56 +00:00
|
|
|
gst_omx_port_release_buffer (port, buf);
|
2013-01-11 11:52:10 +00:00
|
|
|
goto flow_error;
|
2011-11-01 12:58:38 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
if (self->codec_data) {
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Passing codec data to the component");
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
codec_data = self->codec_data;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-09-23 13:53:49 +00:00
|
|
|
if (buf->omx_buf->nAllocLen - buf->omx_buf->nOffset <
|
2012-04-12 19:57:32 +00:00
|
|
|
gst_buffer_get_size (codec_data)) {
|
2013-02-27 14:49:56 +00:00
|
|
|
gst_omx_port_release_buffer (port, buf);
|
2011-07-07 10:23:24 +00:00
|
|
|
goto too_large_codec_data;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_CODECCONFIG;
|
2013-03-19 11:55:09 +00:00
|
|
|
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
|
2012-04-12 19:57:32 +00:00
|
|
|
buf->omx_buf->nFilledLen = gst_buffer_get_size (codec_data);;
|
|
|
|
gst_buffer_extract (codec_data, 0,
|
|
|
|
buf->omx_buf->pBuffer + buf->omx_buf->nOffset,
|
|
|
|
buf->omx_buf->nFilledLen);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-03-15 08:32:42 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp))
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp,
|
|
|
|
gst_util_uint64_scale (timestamp, OMX_TICKS_PER_SECOND,
|
|
|
|
GST_SECOND));
|
2013-03-15 08:32:42 +00:00
|
|
|
else
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp, G_GUINT64_CONSTANT (0));
|
2013-03-15 08:32:42 +00:00
|
|
|
buf->omx_buf->nTickCount = 0;
|
|
|
|
|
2011-07-14 05:58:41 +00:00
|
|
|
self->started = TRUE;
|
2013-03-11 09:04:10 +00:00
|
|
|
err = gst_omx_port_release_buffer (port, buf);
|
2011-07-07 10:23:24 +00:00
|
|
|
gst_buffer_replace (&self->codec_data, NULL);
|
2013-03-11 09:04:10 +00:00
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto release_error;
|
2011-07-07 10:23:24 +00:00
|
|
|
/* Acquire new buffer for the actual frame */
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
/* Now handle the frame */
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Passing frame offset %d to the component", offset);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
/* Copy the buffer content in chunks of size as requested
|
|
|
|
* by the port */
|
2012-12-20 18:30:38 +00:00
|
|
|
buf->omx_buf->nFilledLen =
|
|
|
|
MIN (size - offset, buf->omx_buf->nAllocLen - buf->omx_buf->nOffset);
|
2012-12-19 11:44:31 +00:00
|
|
|
gst_buffer_extract (frame->input_buffer, offset,
|
2012-04-12 19:57:32 +00:00
|
|
|
buf->omx_buf->pBuffer + buf->omx_buf->nOffset,
|
2011-07-07 10:23:24 +00:00
|
|
|
buf->omx_buf->nFilledLen);
|
|
|
|
|
|
|
|
if (timestamp != GST_CLOCK_TIME_NONE) {
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp,
|
|
|
|
gst_util_uint64_scale (timestamp, OMX_TICKS_PER_SECOND, GST_SECOND));
|
2013-03-15 08:51:42 +00:00
|
|
|
self->last_upstream_ts = timestamp;
|
|
|
|
} else {
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp, G_GUINT64_CONSTANT (0));
|
2011-07-07 10:23:24 +00:00
|
|
|
}
|
2013-03-15 08:51:42 +00:00
|
|
|
|
|
|
|
if (duration != GST_CLOCK_TIME_NONE && offset == 0) {
|
2011-07-07 10:23:24 +00:00
|
|
|
buf->omx_buf->nTickCount =
|
2014-05-10 20:47:56 +00:00
|
|
|
gst_util_uint64_scale (duration, OMX_TICKS_PER_SECOND, GST_SECOND);
|
2011-12-06 11:47:12 +00:00
|
|
|
self->last_upstream_ts += duration;
|
2013-03-15 08:51:42 +00:00
|
|
|
} else {
|
|
|
|
buf->omx_buf->nTickCount = 0;
|
2011-07-07 10:23:24 +00:00
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2013-09-05 08:23:39 +00:00
|
|
|
if (offset == 0 && GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT (frame))
|
|
|
|
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
|
2011-07-07 10:23:24 +00:00
|
|
|
|
|
|
|
/* TODO: Set flags
|
|
|
|
* - OMX_BUFFERFLAG_DECODEONLY for buffers that are outside
|
|
|
|
* the segment
|
|
|
|
*/
|
|
|
|
|
|
|
|
offset += buf->omx_buf->nFilledLen;
|
2013-03-19 11:55:09 +00:00
|
|
|
|
|
|
|
if (offset == size)
|
|
|
|
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
|
|
|
|
|
2011-07-14 05:58:41 +00:00
|
|
|
self->started = TRUE;
|
2013-03-11 09:04:10 +00:00
|
|
|
err = gst_omx_port_release_buffer (port, buf);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto release_error;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Passed frame to component");
|
|
|
|
|
2011-11-01 12:58:38 +00:00
|
|
|
return self->downstream_flow_ret;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-09-23 13:53:49 +00:00
|
|
|
full_buffer:
|
|
|
|
{
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-09-23 13:53:49 +00:00
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, FAILED, (NULL),
|
2013-04-18 22:07:28 +00:00
|
|
|
("Got OpenMAX buffer with no free space (%p, %u/%u)", buf,
|
|
|
|
(guint) buf->omx_buf->nOffset, (guint) buf->omx_buf->nAllocLen));
|
2011-09-23 13:53:49 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-01-11 11:52:10 +00:00
|
|
|
flow_error:
|
|
|
|
{
|
|
|
|
gst_video_codec_frame_unref (frame);
|
|
|
|
|
|
|
|
return self->downstream_flow_ret;
|
|
|
|
}
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
too_large_codec_data:
|
|
|
|
{
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL),
|
2013-08-20 15:00:07 +00:00
|
|
|
("codec_data larger than supported by OpenMAX port "
|
|
|
|
"(%" G_GSIZE_FORMAT " > %u)", gst_buffer_get_size (codec_data),
|
2013-04-18 22:07:28 +00:00
|
|
|
(guint) self->dec_in_port->port_def.nBufferSize));
|
2011-06-28 06:51:23 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
component_error:
|
|
|
|
{
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, FAILED, (NULL),
|
2011-07-13 18:22:51 +00:00
|
|
|
("OpenMAX component in error state %s (0x%08x)",
|
2013-02-25 08:12:22 +00:00
|
|
|
gst_omx_component_get_last_error_string (self->dec),
|
|
|
|
gst_omx_component_get_last_error (self->dec)));
|
2011-06-28 06:51:23 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
flushing:
|
|
|
|
{
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2012-04-12 19:57:32 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Flushing -- returning FLUSHING");
|
|
|
|
return GST_FLOW_FLUSHING;
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
reconfigure_error:
|
|
|
|
{
|
2013-01-11 11:52:10 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2011-06-28 06:51:23 +00:00
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
|
|
|
|
("Unable to reconfigure input port"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2013-03-11 09:04:10 +00:00
|
|
|
release_error:
|
|
|
|
{
|
|
|
|
gst_video_codec_frame_unref (frame);
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
|
|
|
|
("Failed to relase input buffer to component: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-06-20 12:11:58 +00:00
|
|
|
gst_omx_video_dec_finish (GstVideoDecoder * decoder)
|
2011-06-28 06:51:23 +00:00
|
|
|
{
|
2016-06-17 07:59:45 +00:00
|
|
|
return gst_omx_video_dec_drain (decoder);
|
2011-06-28 06:51:23 +00:00
|
|
|
}
|
2011-11-01 15:08:59 +00:00
|
|
|
|
|
|
|
static GstFlowReturn
|
2016-06-17 07:59:45 +00:00
|
|
|
gst_omx_video_dec_drain (GstVideoDecoder * decoder)
|
2011-11-01 15:08:59 +00:00
|
|
|
{
|
2016-06-17 07:59:45 +00:00
|
|
|
GstOMXVideoDec *self;
|
2012-04-30 23:20:24 +00:00
|
|
|
GstOMXVideoDecClass *klass;
|
2011-11-01 15:08:59 +00:00
|
|
|
GstOMXBuffer *buf;
|
|
|
|
GstOMXAcquireBufferReturn acq_ret;
|
2013-03-11 09:04:10 +00:00
|
|
|
OMX_ERRORTYPE err;
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2016-06-17 07:59:45 +00:00
|
|
|
self = GST_OMX_VIDEO_DEC (decoder);
|
|
|
|
|
2011-11-01 15:08:59 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Draining component");
|
|
|
|
|
2012-04-30 23:20:24 +00:00
|
|
|
klass = GST_OMX_VIDEO_DEC_GET_CLASS (self);
|
|
|
|
|
2011-11-09 14:43:32 +00:00
|
|
|
if (!self->started) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Component not started yet");
|
2011-11-08 09:46:36 +00:00
|
|
|
return GST_FLOW_OK;
|
2011-11-09 14:43:32 +00:00
|
|
|
}
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
|
2012-04-30 23:20:24 +00:00
|
|
|
if ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER)) {
|
|
|
|
GST_WARNING_OBJECT (self, "Component does not support empty EOS buffers");
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-08 11:42:58 +00:00
|
|
|
/* Make sure to release the base class stream lock, otherwise
|
|
|
|
* _loop() can't call _finish_frame() and we might block forever
|
|
|
|
* because no input buffers are released */
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (self);
|
2011-11-08 11:42:58 +00:00
|
|
|
|
2011-11-01 15:08:59 +00:00
|
|
|
/* Send an EOS buffer to the component and let the base
|
|
|
|
* class drop the EOS event. We will send it later when
|
|
|
|
* the EOS buffer arrives on the output port. */
|
2013-02-25 08:12:22 +00:00
|
|
|
acq_ret = gst_omx_port_acquire_buffer (self->dec_in_port, &buf);
|
2011-11-08 11:42:58 +00:00
|
|
|
if (acq_ret != GST_OMX_ACQUIRE_BUFFER_OK) {
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-11-09 14:43:32 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Failed to acquire buffer for draining: %d",
|
|
|
|
acq_ret);
|
2011-11-01 15:08:59 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2011-11-08 11:42:58 +00:00
|
|
|
}
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
2011-11-01 15:08:59 +00:00
|
|
|
self->draining = TRUE;
|
2011-12-06 11:47:12 +00:00
|
|
|
buf->omx_buf->nFilledLen = 0;
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp,
|
2011-12-06 11:47:12 +00:00
|
|
|
gst_util_uint64_scale (self->last_upstream_ts, OMX_TICKS_PER_SECOND,
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_SECOND));
|
2011-12-06 11:47:12 +00:00
|
|
|
buf->omx_buf->nTickCount = 0;
|
2011-11-01 15:08:59 +00:00
|
|
|
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS;
|
2013-03-11 09:04:10 +00:00
|
|
|
err = gst_omx_port_release_buffer (self->dec_in_port, buf);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to drain component: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
2014-03-19 11:12:49 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2013-03-11 09:04:10 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-11-01 15:08:59 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Waiting until component is drained");
|
2012-04-25 13:31:32 +00:00
|
|
|
|
2013-02-25 08:12:22 +00:00
|
|
|
if (G_UNLIKELY (self->dec->hacks & GST_OMX_HACK_DRAIN_MAY_NOT_RETURN)) {
|
2012-11-12 10:29:48 +00:00
|
|
|
gint64 wait_until = g_get_monotonic_time () + G_TIME_SPAN_SECOND / 2;
|
2012-04-25 13:31:32 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
if (!g_cond_wait_until (&self->drain_cond, &self->drain_lock, wait_until))
|
2012-04-25 13:31:32 +00:00
|
|
|
GST_WARNING_OBJECT (self, "Drain timed out");
|
|
|
|
else
|
|
|
|
GST_DEBUG_OBJECT (self, "Drained component");
|
|
|
|
|
|
|
|
} else {
|
2012-11-12 10:29:48 +00:00
|
|
|
g_cond_wait (&self->drain_cond, &self->drain_lock);
|
2012-04-25 13:31:32 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Drained component");
|
|
|
|
}
|
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2012-06-20 12:11:58 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (self);
|
2011-11-01 15:08:59 +00:00
|
|
|
|
2011-11-08 09:46:36 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
|
2011-11-01 15:08:59 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2012-10-22 12:28:04 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_omx_video_dec_decide_allocation (GstVideoDecoder * bdec, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstBufferPool *pool;
|
|
|
|
GstStructure *config;
|
|
|
|
|
2014-04-15 16:06:38 +00:00
|
|
|
#if defined (USE_OMX_TARGET_RPI) && defined (HAVE_GST_GL)
|
2013-02-25 10:55:04 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
gint i, n;
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
gst_query_parse_allocation (query, &caps, NULL);
|
|
|
|
if (caps && gst_video_info_from_caps (&info, caps)
|
|
|
|
&& info.finfo->format == GST_VIDEO_FORMAT_RGBA) {
|
2014-04-29 14:16:16 +00:00
|
|
|
gboolean found = FALSE;
|
|
|
|
GstCapsFeatures *feature = gst_caps_get_features (caps, 0);
|
2013-02-25 10:55:04 +00:00
|
|
|
/* Prefer an EGLImage allocator if available and we want to use it */
|
|
|
|
n = gst_query_get_n_allocation_params (query);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
|
|
|
|
|
|
|
gst_query_parse_nth_allocation_param (query, i, &allocator, ¶ms);
|
2015-07-02 22:26:48 +00:00
|
|
|
if (allocator) {
|
2016-01-19 18:10:38 +00:00
|
|
|
if (GST_IS_GL_MEMORY_EGL_ALLOCATOR (allocator)) {
|
2015-07-02 22:26:48 +00:00
|
|
|
found = TRUE;
|
|
|
|
gst_query_set_nth_allocation_param (query, 0, allocator, ¶ms);
|
|
|
|
while (gst_query_get_n_allocation_params (query) > 1)
|
|
|
|
gst_query_remove_nth_allocation_param (query, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
break;
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-29 14:16:16 +00:00
|
|
|
|
|
|
|
/* if try to negotiate with caps feature memory:EGLImage
|
|
|
|
* and if allocator is not of type memory EGLImage then fails */
|
|
|
|
if (feature
|
|
|
|
&& gst_caps_features_contains (feature,
|
2016-01-19 18:10:38 +00:00
|
|
|
GST_CAPS_FEATURE_MEMORY_GL_MEMORY) && !found) {
|
2014-04-29 14:16:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-02-25 10:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-22 12:28:04 +00:00
|
|
|
if (!GST_VIDEO_DECODER_CLASS
|
|
|
|
(gst_omx_video_dec_parent_class)->decide_allocation (bdec, query))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_assert (gst_query_get_n_allocation_pools (query) > 0);
|
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
|
|
|
|
g_assert (pool != NULL);
|
|
|
|
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
}
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
gst_object_unref (pool);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|