2011-08-15 13:10:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
|
|
|
|
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstomxaudioenc.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_omx_audio_enc_debug_category);
|
|
|
|
#define GST_CAT_DEFAULT gst_omx_audio_enc_debug_category
|
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
static void gst_omx_audio_enc_finalize (GObject * object);
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_omx_audio_enc_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
|
2014-08-28 07:43:22 +00:00
|
|
|
static gboolean gst_omx_audio_enc_open (GstAudioEncoder * encoder);
|
|
|
|
static gboolean gst_omx_audio_enc_close (GstAudioEncoder * encoder);
|
2011-11-25 10:31:58 +00:00
|
|
|
static gboolean gst_omx_audio_enc_start (GstAudioEncoder * encoder);
|
|
|
|
static gboolean gst_omx_audio_enc_stop (GstAudioEncoder * encoder);
|
|
|
|
static gboolean gst_omx_audio_enc_set_format (GstAudioEncoder * encoder,
|
|
|
|
GstAudioInfo * info);
|
|
|
|
static GstFlowReturn gst_omx_audio_enc_handle_frame (GstAudioEncoder *
|
2011-08-15 13:10:04 +00:00
|
|
|
encoder, GstBuffer * buffer);
|
2011-11-25 10:31:58 +00:00
|
|
|
static void gst_omx_audio_enc_flush (GstAudioEncoder * encoder);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2011-11-01 15:46:09 +00:00
|
|
|
static GstFlowReturn gst_omx_audio_enc_drain (GstOMXAudioEnc * self);
|
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* class initialization */
|
2016-06-21 09:43:13 +00:00
|
|
|
#define do_init \
|
|
|
|
{ \
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_omx_audio_enc_debug_category, "omxaudioenc", 0, \
|
2016-06-21 09:43:13 +00:00
|
|
|
"debug category for gst-omx audio encoder base class"); \
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL); \
|
|
|
|
}
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstOMXAudioEnc, gst_omx_audio_enc,
|
2016-06-21 09:43:13 +00:00
|
|
|
GST_TYPE_AUDIO_ENCODER, do_init);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_omx_audio_enc_class_init (GstOMXAudioEncClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2011-11-25 10:31:58 +00:00
|
|
|
GstAudioEncoderClass *audio_encoder_class = GST_AUDIO_ENCODER_CLASS (klass);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_omx_audio_enc_finalize;
|
|
|
|
|
|
|
|
element_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_audio_enc_change_state);
|
|
|
|
|
2014-08-28 07:43:22 +00:00
|
|
|
audio_encoder_class->open = GST_DEBUG_FUNCPTR (gst_omx_audio_enc_open);
|
|
|
|
audio_encoder_class->close = GST_DEBUG_FUNCPTR (gst_omx_audio_enc_close);
|
2011-11-25 10:31:58 +00:00
|
|
|
audio_encoder_class->start = GST_DEBUG_FUNCPTR (gst_omx_audio_enc_start);
|
|
|
|
audio_encoder_class->stop = GST_DEBUG_FUNCPTR (gst_omx_audio_enc_stop);
|
|
|
|
audio_encoder_class->flush = GST_DEBUG_FUNCPTR (gst_omx_audio_enc_flush);
|
|
|
|
audio_encoder_class->set_format =
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_audio_enc_set_format);
|
2011-11-25 10:31:58 +00:00
|
|
|
audio_encoder_class->handle_frame =
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_omx_audio_enc_handle_frame);
|
|
|
|
|
2013-05-06 13:33:59 +00:00
|
|
|
klass->cdata.type = GST_OMX_COMPONENT_TYPE_FILTER;
|
2012-04-12 19:57:32 +00:00
|
|
|
klass->cdata.default_sink_template_caps = "audio/x-raw, "
|
2011-08-15 13:10:04 +00:00
|
|
|
"rate = (int) [ 1, MAX ], "
|
|
|
|
"channels = (int) [ 1, " G_STRINGIFY (OMX_AUDIO_MAXCHANNELS) " ], "
|
2012-04-12 19:57:32 +00:00
|
|
|
"format = (string) { S8, U8, S16LE, S16BE, U16LE, U16BE, "
|
|
|
|
"S24LE, S24BE, U24LE, U24BE, S32LE, S32BE, U32LE, U32BE }";
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-12 19:57:32 +00:00
|
|
|
gst_omx_audio_enc_init (GstOMXAudioEnc * self)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_init (&self->drain_lock);
|
|
|
|
g_cond_init (&self->drain_cond);
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-28 07:43:22 +00:00
|
|
|
gst_omx_audio_enc_open (GstAudioEncoder * encoder)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
2014-08-28 07:43:22 +00:00
|
|
|
GstOMXAudioEnc *self = GST_OMX_AUDIO_ENC (encoder);
|
2011-08-15 13:10:04 +00:00
|
|
|
GstOMXAudioEncClass *klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
|
2013-02-25 11:38:27 +00:00
|
|
|
gint in_port_index, out_port_index;
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
self->enc =
|
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-08-15 13:10:04 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (!self->enc)
|
2011-08-15 13:10:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_component_get_state (self->enc,
|
2011-08-15 13:10:04 +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->enc, OMX_IndexParamAudioInit,
|
|
|
|
¶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->enc_in_port = gst_omx_component_add_port (self->enc, in_port_index);
|
|
|
|
self->enc_out_port = gst_omx_component_add_port (self->enc, out_port_index);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (!self->enc_in_port || !self->enc_out_port)
|
2011-08-15 13:10:04 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-17 18:19:35 +00:00
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
static gboolean
|
2011-11-17 18:19:35 +00:00
|
|
|
gst_omx_audio_enc_shutdown (GstOMXAudioEnc * self)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
|
|
|
OMX_STATETYPE state;
|
|
|
|
|
2011-11-17 18:19:35 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Shutting down encoder");
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
state = gst_omx_component_get_state (self->enc, 0);
|
2011-08-15 13:10:04 +00:00
|
|
|
if (state > OMX_StateLoaded || state == OMX_StateInvalid) {
|
2011-09-27 13:08:54 +00:00
|
|
|
if (state > OMX_StateIdle) {
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_set_state (self->enc, OMX_StateIdle);
|
|
|
|
gst_omx_component_get_state (self->enc, 5 * GST_SECOND);
|
2011-09-27 13:08:54 +00:00
|
|
|
}
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_set_state (self->enc, OMX_StateLoaded);
|
|
|
|
gst_omx_port_deallocate_buffers (self->enc_in_port);
|
|
|
|
gst_omx_port_deallocate_buffers (self->enc_out_port);
|
2011-08-15 13:10:04 +00:00
|
|
|
if (state > OMX_StateLoaded)
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_get_state (self->enc, 5 * GST_SECOND);
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 18:19:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-28 07:43:22 +00:00
|
|
|
gst_omx_audio_enc_close (GstAudioEncoder * encoder)
|
2011-11-17 18:19:35 +00:00
|
|
|
{
|
2014-08-28 07:43:22 +00:00
|
|
|
GstOMXAudioEnc *self = GST_OMX_AUDIO_ENC (encoder);
|
|
|
|
|
2011-11-17 18:19:35 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Closing encoder");
|
|
|
|
|
|
|
|
if (!gst_omx_audio_enc_shutdown (self))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
self->enc_in_port = NULL;
|
|
|
|
self->enc_out_port = NULL;
|
|
|
|
if (self->enc)
|
2018-07-24 13:06:01 +00:00
|
|
|
gst_omx_component_unref (self->enc);
|
2013-02-25 08:15:53 +00:00
|
|
|
self->enc = NULL;
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_omx_audio_enc_finalize (GObject * object)
|
|
|
|
{
|
2011-11-01 15:46:09 +00:00
|
|
|
GstOMXAudioEnc *self = GST_OMX_AUDIO_ENC (object);
|
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_clear (&self->drain_lock);
|
|
|
|
g_cond_clear (&self->drain_cond);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
G_OBJECT_CLASS (gst_omx_audio_enc_parent_class)->finalize (object);
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_omx_audio_enc_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstOMXAudioEnc *self;
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_OMX_AUDIO_ENC (element),
|
|
|
|
GST_STATE_CHANGE_FAILURE);
|
|
|
|
self = GST_OMX_AUDIO_ENC (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2011-11-01 15:46:09 +00:00
|
|
|
|
|
|
|
self->draining = FALSE;
|
2011-11-10 13:39:40 +00:00
|
|
|
self->started = FALSE;
|
2011-08-15 13:10:04 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2013-02-25 08:15:53 +00:00
|
|
|
if (self->enc_in_port)
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->enc_in_port, 5 * GST_SECOND, TRUE);
|
2013-02-25 08:15:53 +00:00
|
|
|
if (self->enc_out_port)
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, TRUE);
|
2011-11-01 15:46:09 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
2011-11-01 15:46:09 +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-08-15 13:10:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
ret =
|
|
|
|
GST_ELEMENT_CLASS (gst_omx_audio_enc_parent_class)->change_state (element,
|
|
|
|
transition);
|
2011-08-15 13:10:04 +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:39:40 +00:00
|
|
|
self->started = FALSE;
|
2011-11-17 18:19:35 +00:00
|
|
|
|
|
|
|
if (!gst_omx_audio_enc_shutdown (self))
|
|
|
|
ret = GST_STATE_CHANGE_FAILURE;
|
2011-08-15 13:10:04 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_omx_audio_enc_loop (GstOMXAudioEnc * self)
|
|
|
|
{
|
|
|
|
GstOMXAudioEncClass *klass;
|
2013-02-25 08:15:53 +00:00
|
|
|
GstOMXPort *port = self->enc_out_port;
|
2011-08-15 13:10:04 +00:00
|
|
|
GstOMXBuffer *buf = NULL;
|
|
|
|
GstFlowReturn flow_ret = GST_FLOW_OK;
|
|
|
|
GstOMXAcquireBufferReturn acq_return;
|
2013-03-11 09:04:10 +00:00
|
|
|
OMX_ERRORTYPE err;
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
|
|
|
|
|
2018-08-13 13:10:37 +00:00
|
|
|
acq_return = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
|
2011-08-15 13:10:04 +00:00
|
|
|
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-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
if (!gst_pad_has_current_caps (GST_AUDIO_ENCODER_SRC_PAD (self))
|
2013-02-27 14:49:56 +00:00
|
|
|
|| acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
|
2011-11-25 10:31:58 +00:00
|
|
|
GstAudioInfo *info =
|
|
|
|
gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (self));
|
2011-08-15 13:10:04 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Port settings have changed, updating caps");
|
|
|
|
|
2013-02-27 15:55:16 +00:00
|
|
|
/* Reallocate all buffers */
|
|
|
|
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
err = gst_omx_port_deallocate_buffers (port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
caps = klass->get_caps (self, self->enc_out_port, info);
|
2011-08-15 13:10:04 +00:00
|
|
|
if (!caps) {
|
|
|
|
if (buf)
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_port_release_buffer (self->enc_out_port, buf);
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
goto caps_failed;
|
|
|
|
}
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting output caps: %" GST_PTR_FORMAT, caps);
|
|
|
|
|
2017-01-10 15:29:08 +00:00
|
|
|
if (!gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (self), caps)) {
|
2011-08-15 13:10:04 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
if (buf)
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_port_release_buffer (self->enc_out_port, buf);
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
goto caps_failed;
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2013-02-27 15:55:16 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
|
|
|
|
|
|
|
if (acq_return == GST_OMX_ACQUIRE_BUFFER_RECONFIGURE) {
|
|
|
|
err = gst_omx_port_set_enabled (port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
2013-03-06 16:05:51 +00:00
|
|
|
err = gst_omx_port_allocate_buffers (port);
|
2013-02-27 15:55:16 +00:00
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
2013-03-07 10:11:58 +00:00
|
|
|
err = gst_omx_port_populate (port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
|
2013-02-27 15:55:16 +00:00
|
|
|
err = gst_omx_port_mark_reconfigured (port);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
/* Now get a buffer */
|
2013-01-11 11:52:10 +00:00
|
|
|
if (acq_return != GST_OMX_ACQUIRE_BUFFER_OK) {
|
2011-08-15 13:10:04 +00:00
|
|
|
return;
|
2013-01-11 11:52:10 +00:00
|
|
|
}
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 09:09:34 +00:00
|
|
|
g_assert (acq_return == GST_OMX_ACQUIRE_BUFFER_OK);
|
2013-03-14 11:49:42 +00:00
|
|
|
if (!buf) {
|
|
|
|
g_assert ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER));
|
2011-12-14 09:09:34 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2013-03-14 11:49:42 +00:00
|
|
|
goto eos;
|
|
|
|
}
|
2011-08-15 13:10:04 +00:00
|
|
|
|
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));
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
/* This prevents a deadlock between the srcpad stream
|
|
|
|
* lock and the videocodec stream lock, if ::reset()
|
|
|
|
* is called at the wrong time
|
|
|
|
*/
|
|
|
|
if (gst_omx_port_is_flushing (self->enc_out_port)) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Flushing");
|
|
|
|
gst_omx_port_release_buffer (self->enc_out_port, buf);
|
|
|
|
goto flushing;
|
|
|
|
}
|
2012-04-12 19:57:32 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
|
|
|
|
if ((buf->omx_buf->nFlags & OMX_BUFFERFLAG_CODECCONFIG)
|
|
|
|
&& buf->omx_buf->nFilledLen > 0) {
|
|
|
|
GstCaps *caps;
|
|
|
|
GstBuffer *codec_data;
|
|
|
|
GstMapInfo map = GST_MAP_INFO_INIT;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Handling codec data");
|
|
|
|
caps =
|
|
|
|
gst_caps_copy (gst_pad_get_current_caps (GST_AUDIO_ENCODER_SRC_PAD
|
|
|
|
(self)));
|
|
|
|
codec_data = gst_buffer_new_and_alloc (buf->omx_buf->nFilledLen);
|
|
|
|
|
|
|
|
gst_buffer_map (codec_data, &map, GST_MAP_WRITE);
|
|
|
|
memcpy (map.data,
|
|
|
|
buf->omx_buf->pBuffer + buf->omx_buf->nOffset,
|
|
|
|
buf->omx_buf->nFilledLen);
|
|
|
|
gst_buffer_unmap (codec_data, &map);
|
|
|
|
|
|
|
|
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, codec_data, NULL);
|
|
|
|
if (!gst_pad_set_caps (GST_AUDIO_ENCODER_SRC_PAD (self), caps)) {
|
2011-12-14 09:09:34 +00:00
|
|
|
gst_caps_unref (caps);
|
2013-03-14 11:49:42 +00:00
|
|
|
if (buf)
|
|
|
|
gst_omx_port_release_buffer (self->enc_out_port, buf);
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
|
|
|
goto caps_failed;
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
flow_ret = GST_FLOW_OK;
|
|
|
|
} else if (buf->omx_buf->nFilledLen > 0) {
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
guint n_samples;
|
2011-12-14 09:09:34 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Handling output data");
|
2012-12-20 11:20:31 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
n_samples =
|
|
|
|
klass->get_num_samples (self, self->enc_out_port,
|
|
|
|
gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (self)), buf);
|
2011-12-14 09:09:34 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
if (buf->omx_buf->nFilledLen > 0) {
|
|
|
|
GstMapInfo map = GST_MAP_INFO_INIT;
|
|
|
|
outbuf = gst_buffer_new_and_alloc (buf->omx_buf->nFilledLen);
|
2011-12-14 09:09:34 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
|
2012-04-12 19:57:32 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
memcpy (map.data,
|
|
|
|
buf->omx_buf->pBuffer + buf->omx_buf->nOffset,
|
|
|
|
buf->omx_buf->nFilledLen);
|
|
|
|
gst_buffer_unmap (outbuf, &map);
|
2012-04-12 19:57:32 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
} else {
|
|
|
|
outbuf = gst_buffer_new ();
|
|
|
|
}
|
2011-12-14 09:09:34 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) =
|
2016-06-17 09:06:48 +00:00
|
|
|
gst_util_uint64_scale (GST_OMX_GET_TICKS (buf->omx_buf->nTimeStamp),
|
|
|
|
GST_SECOND, OMX_TICKS_PER_SECOND);
|
2013-03-14 11:49:42 +00:00
|
|
|
if (buf->omx_buf->nTickCount != 0)
|
|
|
|
GST_BUFFER_DURATION (outbuf) =
|
|
|
|
gst_util_uint64_scale (buf->omx_buf->nTickCount, GST_SECOND,
|
2011-08-15 13:10:04 +00:00
|
|
|
OMX_TICKS_PER_SECOND);
|
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
flow_ret =
|
|
|
|
gst_audio_encoder_finish_frame (GST_AUDIO_ENCODER (self),
|
|
|
|
outbuf, n_samples);
|
|
|
|
}
|
2012-12-20 11:20:31 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Handled output data");
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Finished frame: %s", gst_flow_get_name (flow_ret));
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-03-14 11:49:42 +00:00
|
|
|
err = gst_omx_port_release_buffer (port, buf);
|
|
|
|
if (err != OMX_ErrorNone)
|
|
|
|
goto release_error;
|
|
|
|
|
|
|
|
self->downstream_flow_ret = flow_ret;
|
2011-11-01 14:10:12 +00:00
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
if (flow_ret != GST_FLOW_OK)
|
|
|
|
goto flow_error;
|
|
|
|
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2011-11-10 14:10:14 +00:00
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
component_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, FAILED, (NULL),
|
|
|
|
("OpenMAX component in error state %s (0x%08x)",
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_get_last_error_string (self->enc),
|
|
|
|
gst_omx_component_get_last_error (self->enc)));
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_ERROR;
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
2011-08-15 13:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
2012-04-12 19:57:32 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_FLUSHING;
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
2015-11-18 12:59:59 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2013-03-14 11:49:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
eos:
|
|
|
|
{
|
|
|
|
g_mutex_lock (&self->drain_lock);
|
|
|
|
if (self->draining) {
|
|
|
|
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_AUDIO_ENCODER_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_AUDIO_ENCODER_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_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
flow_error:
|
|
|
|
{
|
2012-04-12 19:57:32 +00:00
|
|
|
if (flow_ret == GST_FLOW_EOS) {
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "EOS");
|
|
|
|
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (self),
|
2011-08-15 13:10:04 +00:00
|
|
|
gst_event_new_eos ());
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
2014-01-25 16:44:14 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
} else if (flow_ret < GST_FLOW_EOS) {
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_ELEMENT_ERROR (self, STREAM, FAILED, ("Internal data stream error."),
|
|
|
|
("stream stopped, reason %s", gst_flow_get_name (flow_ret)));
|
|
|
|
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (self),
|
2011-08-15 13:10:04 +00:00
|
|
|
gst_event_new_eos ());
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_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_AUDIO_ENCODER_SRC_PAD (self));
|
|
|
|
self->started = FALSE;
|
2015-11-18 12:59:59 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
reconfigure_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL),
|
|
|
|
("Unable to reconfigure output port"));
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_NOT_NEGOTIATED;
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
2011-08-15 13:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
caps_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, SETTINGS, (NULL), ("Failed to set caps"));
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_NOT_NEGOTIATED;
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
2011-08-15 13:10:04 +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_AUDIO_ENCODER_SRC_PAD (self), gst_event_new_eos ());
|
|
|
|
gst_pad_pause_task (GST_AUDIO_ENCODER_SRC_PAD (self));
|
|
|
|
self->downstream_flow_ret = GST_FLOW_ERROR;
|
|
|
|
self->started = FALSE;
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_omx_audio_enc_start (GstAudioEncoder * encoder)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
|
|
|
GstOMXAudioEnc *self;
|
|
|
|
|
|
|
|
self = GST_OMX_AUDIO_ENC (encoder);
|
|
|
|
|
2011-12-06 11:47:25 +00:00
|
|
|
self->last_upstream_ts = 0;
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2012-12-20 11:30:05 +00:00
|
|
|
return TRUE;
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_omx_audio_enc_stop (GstAudioEncoder * encoder)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
|
|
|
GstOMXAudioEnc *self;
|
|
|
|
|
|
|
|
self = GST_OMX_AUDIO_ENC (encoder);
|
|
|
|
|
2011-11-18 18:00:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Stopping encoder");
|
|
|
|
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->enc_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, TRUE);
|
2011-11-18 18:00:31 +00:00
|
|
|
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_stop_task (GST_AUDIO_ENCODER_SRC_PAD (encoder));
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_component_get_state (self->enc, 0) > OMX_StateIdle)
|
|
|
|
gst_omx_component_set_state (self->enc, OMX_StateIdle);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_FLUSHING;
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
2011-11-01 15:46:09 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
2011-11-01 15:46:09 +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:46:09 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_get_state (self->enc, 5 * GST_SECOND);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_omx_audio_enc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
|
|
|
GstOMXAudioEnc *self;
|
|
|
|
GstOMXAudioEncClass *klass;
|
|
|
|
gboolean needs_disable = FALSE;
|
|
|
|
OMX_PARAM_PORTDEFINITIONTYPE port_def;
|
|
|
|
OMX_AUDIO_PARAM_PCMMODETYPE pcm_param;
|
|
|
|
gint i;
|
|
|
|
OMX_ERRORTYPE err;
|
|
|
|
|
|
|
|
self = GST_OMX_AUDIO_ENC (encoder);
|
|
|
|
klass = GST_OMX_AUDIO_ENC_GET_CLASS (encoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Setting new caps");
|
|
|
|
|
2011-08-17 12:33:31 +00:00
|
|
|
/* Set audio encoder base class properties */
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_audio_encoder_set_frame_samples_min (encoder,
|
2011-08-17 12:33:31 +00:00
|
|
|
gst_util_uint64_scale_ceil (OMX_MIN_PCMPAYLOAD_MSEC,
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_MSECOND * info->rate, GST_SECOND));
|
|
|
|
gst_audio_encoder_set_frame_samples_max (encoder, 0);
|
2011-08-17 12:33:31 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_port_get_port_definition (self->enc_in_port, &port_def);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
needs_disable =
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_get_state (self->enc,
|
2011-08-15 13:10:04 +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) {
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Need to disable and drain encoder");
|
2011-11-08 10:07:01 +00:00
|
|
|
gst_omx_audio_enc_drain (self);
|
2013-03-08 14:11:27 +00:00
|
|
|
gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, TRUE);
|
2013-03-09 13:14:40 +00:00
|
|
|
|
|
|
|
/* Wait until the srcpad loop is finished,
|
|
|
|
* unlock GST_AUDIO_ENCODER_STREAM_LOCK to prevent deadlocks
|
|
|
|
* caused by using this lock from inside the loop function */
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2013-03-08 14:11:27 +00:00
|
|
|
gst_pad_stop_task (GST_AUDIO_ENCODER_SRC_PAD (encoder));
|
2013-03-09 13:14:40 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-11-04 08:43:48 +00:00
|
|
|
|
2014-08-28 07:44:31 +00:00
|
|
|
if (klass->cdata.hacks & GST_OMX_HACK_NO_COMPONENT_RECONFIGURE) {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
|
|
|
gst_omx_audio_enc_stop (GST_AUDIO_ENCODER (self));
|
|
|
|
gst_omx_audio_enc_close (GST_AUDIO_ENCODER (self));
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
|
|
|
|
if (!gst_omx_audio_enc_open (GST_AUDIO_ENCODER (self)))
|
|
|
|
return FALSE;
|
|
|
|
needs_disable = FALSE;
|
2017-07-05 09:47:41 +00:00
|
|
|
|
|
|
|
/* The local port_def is now obsolete so get it again. */
|
|
|
|
gst_omx_port_get_port_definition (self->enc_in_port, &port_def);
|
2014-08-28 07:44:31 +00:00
|
|
|
} else {
|
2017-07-20 08:43:19 +00:00
|
|
|
/* Disabling at the same time input port and output port is only
|
|
|
|
* required when a buffer is shared between the ports. This cannot
|
|
|
|
* be the case for a encoder because its input and output buffers
|
|
|
|
* are of different nature. So let's disable ports sequencially.
|
|
|
|
* Starting from IL 1.2.0, this point has been clarified.
|
|
|
|
* OMX_SendCommand will return an error if the IL client attempts to
|
|
|
|
* call it when there is already an on-going command being processed.
|
|
|
|
* The exception is for buffer sharing above and the event
|
|
|
|
* OMX_EventPortNeedsDisable will be sent to request disabling the
|
|
|
|
* other port at the same time. */
|
2014-08-28 07:44:31 +00:00
|
|
|
if (gst_omx_port_set_enabled (self->enc_in_port, FALSE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_buffers_released (self->enc_in_port,
|
|
|
|
5 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_deallocate_buffers (self->enc_in_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_enabled (self->enc_in_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2017-07-20 08:43:19 +00:00
|
|
|
|
|
|
|
if (gst_omx_port_set_enabled (self->enc_out_port, FALSE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_wait_buffers_released (self->enc_out_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_deallocate_buffers (self->enc_out_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2014-08-28 07:44:31 +00:00
|
|
|
if (gst_omx_port_wait_enabled (self->enc_out_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-12-20 11:20:31 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Encoder drained and disabled");
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
port_def.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
|
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->enc_in_port,
|
|
|
|
&port_def) != OMX_ErrorNone)
|
2011-08-15 13:10:04 +00:00
|
|
|
return FALSE;
|
2012-12-20 11:20:31 +00:00
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_OMX_INIT_STRUCT (&pcm_param);
|
2013-02-25 08:15:53 +00:00
|
|
|
pcm_param.nPortIndex = self->enc_in_port->index;
|
2011-11-25 10:31:58 +00:00
|
|
|
pcm_param.nChannels = info->channels;
|
2011-08-15 13:10:04 +00:00
|
|
|
pcm_param.eNumData =
|
2011-11-25 10:31:58 +00:00
|
|
|
((info->finfo->flags & GST_AUDIO_FORMAT_FLAG_SIGNED) ?
|
|
|
|
OMX_NumericalDataSigned : OMX_NumericalDataUnsigned);
|
2011-08-15 13:10:04 +00:00
|
|
|
pcm_param.eEndian =
|
2011-11-25 10:31:58 +00:00
|
|
|
((info->finfo->endianness == G_LITTLE_ENDIAN) ?
|
|
|
|
OMX_EndianLittle : OMX_EndianBig);
|
2011-08-15 13:10:04 +00:00
|
|
|
pcm_param.bInterleaved = OMX_TRUE;
|
2011-11-25 10:31:58 +00:00
|
|
|
pcm_param.nBitPerSample = info->finfo->width;
|
|
|
|
pcm_param.nSamplingRate = info->rate;
|
2011-08-15 13:10:04 +00:00
|
|
|
pcm_param.ePCMMode = OMX_AUDIO_PCMModeLinear;
|
|
|
|
|
|
|
|
for (i = 0; i < pcm_param.nChannels; i++) {
|
|
|
|
OMX_AUDIO_CHANNELTYPE pos;
|
|
|
|
|
2011-11-25 10:31:58 +00:00
|
|
|
switch (info->position[i]) {
|
2012-04-12 19:57:32 +00:00
|
|
|
case GST_AUDIO_CHANNEL_POSITION_MONO:
|
2011-08-15 13:10:04 +00:00
|
|
|
case GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER:
|
|
|
|
pos = OMX_AUDIO_ChannelCF;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT:
|
|
|
|
pos = OMX_AUDIO_ChannelLF;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT:
|
|
|
|
pos = OMX_AUDIO_ChannelRF;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT:
|
|
|
|
pos = OMX_AUDIO_ChannelLS;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT:
|
|
|
|
pos = OMX_AUDIO_ChannelRS;
|
|
|
|
break;
|
2012-04-12 19:57:32 +00:00
|
|
|
case GST_AUDIO_CHANNEL_POSITION_LFE1:
|
2011-08-15 13:10:04 +00:00
|
|
|
pos = OMX_AUDIO_ChannelLFE;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_REAR_CENTER:
|
|
|
|
pos = OMX_AUDIO_ChannelCS;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_REAR_LEFT:
|
|
|
|
pos = OMX_AUDIO_ChannelLR;
|
|
|
|
break;
|
|
|
|
case GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT:
|
|
|
|
pos = OMX_AUDIO_ChannelRR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pos = OMX_AUDIO_ChannelNone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pcm_param.eChannelMapping[i] = pos;
|
|
|
|
}
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Setting PCM parameters");
|
2011-08-15 13:10:04 +00:00
|
|
|
err =
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_set_parameter (self->enc, OMX_IndexParamAudioPcm,
|
2011-08-15 13:10:04 +00:00
|
|
|
&pcm_param);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to set PCM parameters: %s (0x%08x)",
|
|
|
|
gst_omx_error_to_string (err), err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (klass->set_format) {
|
2013-02-25 08:15:53 +00:00
|
|
|
if (!klass->set_format (self, self->enc_in_port, info)) {
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Subclass failed to set the new format");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 10:25:04 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Updating outport port definition");
|
|
|
|
if (gst_omx_port_update_port_definition (self->enc_out_port,
|
|
|
|
NULL) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Enabling component");
|
2011-08-15 13:10:04 +00:00
|
|
|
if (needs_disable) {
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_port_set_enabled (self->enc_in_port, TRUE) != OMX_ErrorNone)
|
2011-08-15 13:10:04 +00:00
|
|
|
return FALSE;
|
2013-03-06 16:05:51 +00:00
|
|
|
if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
|
2013-02-12 10:41:43 +00:00
|
|
|
return FALSE;
|
2014-05-15 11:22:56 +00:00
|
|
|
|
|
|
|
if ((klass->cdata.hacks & GST_OMX_HACK_NO_DISABLE_OUTPORT)) {
|
|
|
|
if (gst_omx_port_set_enabled (self->enc_out_port, TRUE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_allocate_buffers (self->enc_out_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_omx_port_wait_enabled (self->enc_out_port,
|
|
|
|
5 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_port_wait_enabled (self->enc_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->enc_in_port) != OMX_ErrorNone)
|
2011-08-15 13:10:04 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2014-05-15 11:22:56 +00:00
|
|
|
if (!(klass->cdata.hacks & GST_OMX_HACK_NO_DISABLE_OUTPORT)) {
|
|
|
|
/* Disable output port */
|
|
|
|
if (gst_omx_port_set_enabled (self->enc_out_port, FALSE) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_omx_port_wait_enabled (self->enc_out_port,
|
|
|
|
1 * GST_SECOND) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (gst_omx_component_set_state (self->enc,
|
|
|
|
OMX_StateIdle) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Need to allocate buffers to reach Idle state */
|
|
|
|
if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (gst_omx_component_set_state (self->enc,
|
|
|
|
OMX_StateIdle) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Need to allocate buffers to reach Idle state */
|
|
|
|
if (gst_omx_port_allocate_buffers (self->enc_in_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
if (gst_omx_port_allocate_buffers (self->enc_out_port) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_component_get_state (self->enc,
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateIdle)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_component_set_state (self->enc,
|
2011-08-15 13:10:04 +00:00
|
|
|
OMX_StateExecuting) != OMX_ErrorNone)
|
|
|
|
return FALSE;
|
2011-09-14 08:15:38 +00:00
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_component_get_state (self->enc,
|
2011-09-14 08:15:38 +00:00
|
|
|
GST_CLOCK_TIME_NONE) != OMX_StateExecuting)
|
|
|
|
return FALSE;
|
2011-08-15 13:10:04 +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->enc_in_port, 5 * GST_SECOND, FALSE);
|
|
|
|
gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, FALSE);
|
|
|
|
|
2013-02-25 08:15:53 +00:00
|
|
|
if (gst_omx_component_get_last_error (self->enc) != OMX_ErrorNone) {
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Component in error state: %s (0x%08x)",
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_get_last_error_string (self->enc),
|
|
|
|
gst_omx_component_get_last_error (self->enc));
|
2011-08-15 13:10:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the srcpad loop again */
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Starting task again");
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_start_task (GST_AUDIO_ENCODER_SRC_PAD (self),
|
2012-06-20 10:09:13 +00:00
|
|
|
(GstTaskFunction) gst_omx_audio_enc_loop, encoder, NULL);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2011-09-14 08:15:38 +00:00
|
|
|
return TRUE;
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_omx_audio_enc_flush (GstAudioEncoder * encoder)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
|
|
|
GstOMXAudioEnc *self;
|
|
|
|
|
|
|
|
self = GST_OMX_AUDIO_ENC (encoder);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Resetting encoder");
|
|
|
|
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->enc_in_port, 5 * GST_SECOND, TRUE);
|
|
|
|
gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, TRUE);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2011-11-10 14:03:05 +00:00
|
|
|
/* Wait until the srcpad loop is finished */
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
|
|
|
GST_PAD_STREAM_LOCK (GST_AUDIO_ENCODER_SRC_PAD (self));
|
|
|
|
GST_PAD_STREAM_UNLOCK (GST_AUDIO_ENCODER_SRC_PAD (self));
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2013-03-07 10:11:58 +00:00
|
|
|
gst_omx_port_set_flushing (self->enc_in_port, 5 * GST_SECOND, FALSE);
|
|
|
|
gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, FALSE);
|
|
|
|
gst_omx_port_populate (self->enc_out_port);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
/* Start the srcpad loop again */
|
2011-12-06 11:47:25 +00:00
|
|
|
self->last_upstream_ts = 0;
|
2011-11-01 14:10:12 +00:00
|
|
|
self->downstream_flow_ret = GST_FLOW_OK;
|
2014-08-14 14:36:11 +00:00
|
|
|
self->started = FALSE;
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_pad_start_task (GST_AUDIO_ENCODER_SRC_PAD (self),
|
2012-06-20 10:09:13 +00:00
|
|
|
(GstTaskFunction) gst_omx_audio_enc_loop, encoder, NULL);
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-11-25 10:31:58 +00:00
|
|
|
gst_omx_audio_enc_handle_frame (GstAudioEncoder * encoder, GstBuffer * inbuf)
|
2011-08-15 13:10:04 +00:00
|
|
|
{
|
|
|
|
GstOMXAcquireBufferReturn acq_ret = GST_OMX_ACQUIRE_BUFFER_ERROR;
|
|
|
|
GstOMXAudioEnc *self;
|
2013-02-27 14:49:56 +00:00
|
|
|
GstOMXPort *port;
|
2011-08-15 13:10:04 +00:00
|
|
|
GstOMXBuffer *buf;
|
2012-04-16 06:34:56 +00:00
|
|
|
gsize size;
|
2011-08-15 13:10:04 +00:00
|
|
|
guint offset = 0;
|
|
|
|
GstClockTime timestamp, duration, timestamp_offset = 0;
|
2013-03-11 09:04:10 +00:00
|
|
|
OMX_ERRORTYPE err;
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
self = GST_OMX_AUDIO_ENC (encoder);
|
|
|
|
|
2011-11-01 14:10:12 +00:00
|
|
|
if (self->downstream_flow_ret != GST_FLOW_OK) {
|
|
|
|
return self->downstream_flow_ret;
|
|
|
|
}
|
|
|
|
|
2011-08-17 12:17:18 +00:00
|
|
|
if (inbuf == NULL)
|
2014-05-10 20:48:23 +00:00
|
|
|
return gst_omx_audio_enc_drain (self);
|
2011-08-17 12:17:18 +00:00
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Handling frame");
|
|
|
|
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (inbuf);
|
|
|
|
duration = GST_BUFFER_DURATION (inbuf);
|
|
|
|
|
2013-02-27 14:49:56 +00:00
|
|
|
port = self->enc_in_port;
|
|
|
|
|
2012-04-16 06:34:56 +00:00
|
|
|
size = gst_buffer_get_size (inbuf);
|
|
|
|
while (offset < size) {
|
2011-08-17 09:34:31 +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 */
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2018-08-13 13:10:37 +00:00
|
|
|
acq_ret = gst_omx_port_acquire_buffer (port, &buf, GST_OMX_WAIT);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
if (acq_ret == GST_OMX_ACQUIRE_BUFFER_ERROR) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
goto component_error;
|
|
|
|
} else if (acq_ret == GST_OMX_ACQUIRE_BUFFER_FLUSHING) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-08-15 13:10:04 +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) {
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
goto reconfigure_error;
|
2013-01-11 11:52:10 +00:00
|
|
|
}
|
2013-02-27 14:49:56 +00:00
|
|
|
|
|
|
|
err = gst_omx_port_wait_buffers_released (port, 5 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_deallocate_buffers (port);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 1 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_set_enabled (port, TRUE);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_AUDIO_ENCODER_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_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_wait_enabled (port, 5 * GST_SECOND);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gst_omx_port_mark_reconfigured (port);
|
|
|
|
if (err != OMX_ErrorNone) {
|
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
goto reconfigure_error;
|
|
|
|
}
|
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
/* Now get a new buffer and fill it */
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-01-11 11:52:10 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
g_assert (acq_ret == GST_OMX_ACQUIRE_BUFFER_OK && buf != NULL);
|
|
|
|
|
2011-11-01 14:10:12 +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);
|
2011-11-01 14:10:12 +00:00
|
|
|
return self->downstream_flow_ret;
|
|
|
|
}
|
|
|
|
|
2011-11-08 07:31:58 +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 15:02:49 +00:00
|
|
|
goto full_buffer;
|
2011-11-08 07:31:58 +00:00
|
|
|
}
|
2011-09-23 15:02:49 +00:00
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Handling frame at offset %d", offset);
|
|
|
|
|
2011-08-15 13:10:04 +00:00
|
|
|
/* Copy the buffer content in chunks of size as requested
|
|
|
|
* by the port */
|
|
|
|
buf->omx_buf->nFilledLen =
|
2012-04-16 06:34:56 +00:00
|
|
|
MIN (size - offset, buf->omx_buf->nAllocLen - buf->omx_buf->nOffset);
|
|
|
|
gst_buffer_extract (inbuf, offset,
|
|
|
|
buf->omx_buf->pBuffer + buf->omx_buf->nOffset,
|
|
|
|
buf->omx_buf->nFilledLen);
|
2011-08-15 13:10:04 +00:00
|
|
|
|
|
|
|
/* Interpolate timestamps if we're passing the buffer
|
|
|
|
* in multiple chunks */
|
|
|
|
if (offset != 0 && duration != GST_CLOCK_TIME_NONE) {
|
2012-04-16 06:34:56 +00:00
|
|
|
timestamp_offset = gst_util_uint64_scale (offset, duration, size);
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (timestamp != GST_CLOCK_TIME_NONE) {
|
2016-06-17 09:06:48 +00:00
|
|
|
GST_OMX_SET_TICKS (buf->omx_buf->nTimeStamp,
|
2011-08-15 13:10:04 +00:00
|
|
|
gst_util_uint64_scale (timestamp + timestamp_offset,
|
2016-06-17 09:06:48 +00:00
|
|
|
OMX_TICKS_PER_SECOND, GST_SECOND));
|
2011-12-06 11:47:25 +00:00
|
|
|
self->last_upstream_ts = timestamp + timestamp_offset;
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
if (duration != GST_CLOCK_TIME_NONE) {
|
|
|
|
buf->omx_buf->nTickCount =
|
2012-04-16 06:34:56 +00:00
|
|
|
gst_util_uint64_scale (buf->omx_buf->nFilledLen, duration, size);
|
2014-05-12 06:56:15 +00:00
|
|
|
buf->omx_buf->nTickCount =
|
|
|
|
gst_util_uint64_scale (buf->omx_buf->nTickCount,
|
|
|
|
OMX_TICKS_PER_SECOND, GST_SECOND);
|
2011-12-06 11:47:25 +00:00
|
|
|
self->last_upstream_ts += duration;
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offset += buf->omx_buf->nFilledLen;
|
|
|
|
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-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-20 11:20:31 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Passed frame to component");
|
|
|
|
|
2011-11-01 14:10:12 +00:00
|
|
|
return self->downstream_flow_ret;
|
2011-08-15 13:10:04 +00:00
|
|
|
|
2011-09-23 15:02:49 +00:00
|
|
|
full_buffer:
|
|
|
|
{
|
|
|
|
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 15:02:49 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2011-08-15 13:10:04 +00:00
|
|
|
component_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (self, LIBRARY, FAILED, (NULL),
|
|
|
|
("OpenMAX component in error state %s (0x%08x)",
|
2013-02-25 08:15:53 +00:00
|
|
|
gst_omx_component_get_last_error_string (self->enc),
|
|
|
|
gst_omx_component_get_last_error (self->enc)));
|
2011-08-15 13:10:04 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
flushing:
|
|
|
|
{
|
2012-04-12 19:57:32 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Flushing -- returning FLUSHING");
|
|
|
|
return GST_FLOW_FLUSHING;
|
2011-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
reconfigure_error:
|
|
|
|
{
|
|
|
|
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_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-08-15 13:10:04 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 15:46:09 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_omx_audio_enc_drain (GstOMXAudioEnc * self)
|
|
|
|
{
|
2011-12-14 09:09:34 +00:00
|
|
|
GstOMXAudioEncClass *klass;
|
2011-11-01 15:46:09 +00:00
|
|
|
GstOMXBuffer *buf;
|
|
|
|
GstOMXAcquireBufferReturn acq_ret;
|
2013-03-11 09:04:10 +00:00
|
|
|
OMX_ERRORTYPE err;
|
2011-11-01 15:46:09 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (self, "Draining component");
|
|
|
|
|
2011-12-14 09:09:34 +00:00
|
|
|
klass = GST_OMX_AUDIO_ENC_GET_CLASS (self);
|
|
|
|
|
2011-11-10 13:54:33 +00:00
|
|
|
if (!self->started) {
|
|
|
|
GST_DEBUG_OBJECT (self, "Component not started yet");
|
2011-11-08 10:07:01 +00:00
|
|
|
return GST_FLOW_OK;
|
2011-11-10 13:54:33 +00:00
|
|
|
}
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
|
2012-04-12 19:57:32 +00:00
|
|
|
if ((klass->cdata.hacks & GST_OMX_HACK_NO_EMPTY_EOS_BUFFER)) {
|
2011-12-14 09:09:34 +00:00
|
|
|
GST_WARNING_OBJECT (self, "Component does not support empty EOS buffers");
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-08 11:45:16 +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 */
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_UNLOCK (self);
|
2011-11-08 11:45:16 +00:00
|
|
|
|
2011-11-01 15:46:09 +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. */
|
2018-08-13 13:10:37 +00:00
|
|
|
acq_ret = gst_omx_port_acquire_buffer (self->enc_in_port, &buf, GST_OMX_WAIT);
|
2011-11-08 11:45:16 +00:00
|
|
|
if (acq_ret != GST_OMX_ACQUIRE_BUFFER_OK) {
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-11-10 13:54:33 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Failed to acquire buffer for draining: %d",
|
|
|
|
acq_ret);
|
2011-11-01 15:46:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2011-11-08 11:45:16 +00:00
|
|
|
}
|
2011-11-01 15:46:09 +00:00
|
|
|
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_lock (&self->drain_lock);
|
2011-11-01 15:46:09 +00:00
|
|
|
self->draining = TRUE;
|
2011-12-06 11:47:25 +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:25 +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:25 +00:00
|
|
|
buf->omx_buf->nTickCount = 0;
|
2011-11-01 15:46:09 +00:00
|
|
|
buf->omx_buf->nFlags |= OMX_BUFFERFLAG_EOS;
|
2013-03-11 09:04:10 +00:00
|
|
|
err = gst_omx_port_release_buffer (self->enc_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);
|
2017-07-17 08:14:54 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2013-03-11 09:04:10 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2011-11-01 15:46:09 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Waiting until component is drained");
|
2012-11-12 10:29:48 +00:00
|
|
|
g_cond_wait (&self->drain_cond, &self->drain_lock);
|
2011-11-01 15:46:09 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "Drained component");
|
2012-11-12 10:29:48 +00:00
|
|
|
g_mutex_unlock (&self->drain_lock);
|
2011-11-25 10:31:58 +00:00
|
|
|
GST_AUDIO_ENCODER_STREAM_LOCK (self);
|
2011-11-01 15:46:09 +00:00
|
|
|
|
2011-11-08 10:07:01 +00:00
|
|
|
self->started = FALSE;
|
|
|
|
|
2011-11-01 15:46:09 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|