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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_OMX_H__
|
|
|
|
#define __GST_OMX_H__
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2011-07-28 07:54:53 +00:00
|
|
|
#include <string.h>
|
2011-06-28 06:51:23 +00:00
|
|
|
#include <OMX_Core.h>
|
|
|
|
#include <OMX_Component.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2011-07-28 07:54:53 +00:00
|
|
|
#define GST_OMX_INIT_STRUCT(st) G_STMT_START { \
|
2011-08-08 11:04:30 +00:00
|
|
|
memset ((st), 0, sizeof (*(st))); \
|
|
|
|
(st)->nSize = sizeof (*(st)); \
|
2011-07-28 07:54:53 +00:00
|
|
|
(st)->nVersion.s.nVersionMajor = 1; \
|
|
|
|
(st)->nVersion.s.nVersionMinor = 1; \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2011-07-19 08:33:15 +00:00
|
|
|
/* Different hacks that are required to work around
|
|
|
|
* bugs in different OpenMAX implementations
|
|
|
|
*/
|
|
|
|
/* In the EventSettingsChanged callback use nData2 instead of nData1 for
|
|
|
|
* the port index. Happens with Bellagio.
|
|
|
|
*/
|
|
|
|
#define GST_OMX_HACK_EVENT_PORT_SETTINGS_CHANGED_NDATA_PARAMETER_SWAP G_GUINT64_CONSTANT (0x0000000000000001)
|
|
|
|
/* In the EventSettingsChanged callback assume that port index 0 really
|
|
|
|
* means port index 1. Happens with the Bellagio ffmpegdist video decoder.
|
|
|
|
*/
|
2011-07-20 06:34:33 +00:00
|
|
|
#define GST_OMX_HACK_EVENT_PORT_SETTINGS_CHANGED_PORT_0_TO_1 G_GUINT64_CONSTANT (0x0000000000000002)
|
|
|
|
/* If the video framerate is not specified as fraction (Q.16) but as
|
|
|
|
* integer number. Happens with the Bellagio ffmpegdist video encoder.
|
|
|
|
*/
|
|
|
|
#define GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER G_GUINT64_CONSTANT (0x0000000000000004)
|
|
|
|
/* If the SYNCFRAME flag on encoder output buffers is not used and we
|
|
|
|
* have to assume that all frames are sync frames.
|
|
|
|
* Happens with the Bellagio ffmpegdist video encoder.
|
|
|
|
*/
|
|
|
|
#define GST_OMX_HACK_SYNCFRAME_FLAG_NOT_USED G_GUINT64_CONSTANT (0x0000000000000008)
|
2011-09-27 12:15:06 +00:00
|
|
|
/* If the component needs to be re-created if the caps change.
|
|
|
|
* Happens with Qualcomm's OpenMAX implementation.
|
|
|
|
*/
|
2011-10-14 08:27:47 +00:00
|
|
|
#define GST_OMX_HACK_NO_COMPONENT_RECONFIGURE G_GUINT64_CONSTANT (0x0000000000000010)
|
2011-09-26 11:04:18 +00:00
|
|
|
|
2011-07-19 08:33:15 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
typedef struct _GstOMXCore GstOMXCore;
|
|
|
|
typedef struct _GstOMXPort GstOMXPort;
|
|
|
|
typedef enum _GstOMXPortDirection GstOMXPortDirection;
|
|
|
|
typedef struct _GstOMXComponent GstOMXComponent;
|
|
|
|
typedef struct _GstOMXBuffer GstOMXBuffer;
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
typedef enum {
|
2011-07-08 13:25:07 +00:00
|
|
|
/* Everything good and the buffer is valid */
|
2011-07-07 10:23:24 +00:00
|
|
|
GST_OMX_ACQUIRE_BUFFER_OK = 0,
|
2011-07-08 13:25:07 +00:00
|
|
|
/* The port is flushing, exit ASAP */
|
2011-07-07 10:23:24 +00:00
|
|
|
GST_OMX_ACQUIRE_BUFFER_FLUSHING,
|
2011-07-08 13:25:07 +00:00
|
|
|
/* The port must be reconfigured */
|
2011-07-07 10:23:24 +00:00
|
|
|
GST_OMX_ACQUIRE_BUFFER_RECONFIGURE,
|
2011-07-08 13:25:07 +00:00
|
|
|
/* The port was reconfigured and the caps might have changed
|
|
|
|
* NOTE: This is only returned a single time! */
|
|
|
|
GST_OMX_ACQUIRE_BUFFER_RECONFIGURED,
|
|
|
|
/* A fatal error happened */
|
2011-07-07 10:23:24 +00:00
|
|
|
GST_OMX_ACQUIRE_BUFFER_ERROR
|
|
|
|
} GstOMXAcquireBufferReturn;
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
struct _GstOMXCore {
|
|
|
|
/* Handle to the OpenMAX IL core shared library */
|
|
|
|
GModule *module;
|
|
|
|
|
|
|
|
/* Current number of users, transitions from/to 0
|
|
|
|
* call init/deinit */
|
|
|
|
GMutex *lock;
|
|
|
|
gint user_count; /* LOCK */
|
|
|
|
|
|
|
|
/* OpenMAX core library functions, protected with LOCK */
|
|
|
|
/* FIXME: OpenMAX spec does not specify that this is required
|
|
|
|
* but gst-openmax does it */
|
|
|
|
OMX_ERRORTYPE (*init) (void);
|
|
|
|
OMX_ERRORTYPE (*deinit) (void);
|
|
|
|
OMX_ERRORTYPE (*get_handle) (OMX_HANDLETYPE * handle,
|
|
|
|
OMX_STRING name, OMX_PTR data, OMX_CALLBACKTYPE * callbacks);
|
|
|
|
OMX_ERRORTYPE (*free_handle) (OMX_HANDLETYPE handle);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstOMXPort {
|
|
|
|
GstOMXComponent *comp;
|
2011-07-06 08:29:54 +00:00
|
|
|
guint32 index;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
/* Protects port_def, buffers, pending_buffers,
|
2011-07-08 13:25:07 +00:00
|
|
|
* settings_changed, flushing, flushed, enabled_changed
|
|
|
|
* and settings_cookie.
|
2011-06-28 06:51:23 +00:00
|
|
|
*
|
|
|
|
* Signalled if pending_buffers gets a
|
|
|
|
* new buffer or flushing/flushed is set
|
2011-07-08 13:25:07 +00:00
|
|
|
* to TRUE or the port is enabled/disabled
|
|
|
|
* or the settings change or an error happens.
|
|
|
|
*
|
|
|
|
* Note: Always check comp->last_error before
|
|
|
|
* waiting and after being signalled!
|
2011-06-28 06:51:23 +00:00
|
|
|
*
|
|
|
|
* Note: flushed==TRUE implies flushing==TRUE!
|
|
|
|
*
|
|
|
|
* Note: This lock must always be taken before
|
|
|
|
* the component's state lock if both are needed!
|
|
|
|
*/
|
|
|
|
GMutex *port_lock;
|
|
|
|
GCond *port_cond;
|
|
|
|
OMX_PARAM_PORTDEFINITIONTYPE port_def;
|
2011-07-07 10:51:03 +00:00
|
|
|
GPtrArray *buffers; /* Contains GstOMXBuffer* */
|
|
|
|
GQueue *pending_buffers; /* Contains GstOMXBuffer* */
|
2011-07-08 13:25:07 +00:00
|
|
|
/* If TRUE we need to get the new caps of this port */
|
2011-06-28 06:51:23 +00:00
|
|
|
gboolean settings_changed;
|
|
|
|
gboolean flushing;
|
|
|
|
gboolean flushed; /* TRUE after OMX_CommandFlush was done */
|
2011-07-06 08:40:13 +00:00
|
|
|
gboolean enabled_changed; /* TRUE after OMX_Command{En,Dis}able was done */
|
2011-07-08 13:25:07 +00:00
|
|
|
|
2011-07-19 08:33:54 +00:00
|
|
|
/* Increased whenever the settings of these port change.
|
|
|
|
* If settings_cookie != configured_settings_cookie
|
|
|
|
* the port has to be reconfigured.
|
|
|
|
*/
|
2011-07-08 13:25:07 +00:00
|
|
|
gint settings_cookie;
|
2011-07-19 08:33:54 +00:00
|
|
|
gint configured_settings_cookie;
|
2011-06-28 06:51:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstOMXComponent {
|
|
|
|
GstObject *parent;
|
|
|
|
OMX_HANDLETYPE handle;
|
|
|
|
GstOMXCore *core;
|
|
|
|
|
2011-07-19 08:33:15 +00:00
|
|
|
guint64 hacks; /* Flags, GST_OMX_HACK_* */
|
|
|
|
|
2011-07-07 10:51:03 +00:00
|
|
|
GPtrArray *ports; /* Contains GstOMXPort* */
|
2011-07-08 13:25:07 +00:00
|
|
|
gint n_in_ports, n_out_ports;
|
2011-06-28 06:51:23 +00:00
|
|
|
|
2011-07-19 08:33:54 +00:00
|
|
|
/* Protecting state, pending_state, last_error,
|
|
|
|
* pending_reconfigure_outports.
|
2011-06-28 06:51:23 +00:00
|
|
|
* Signalled if one of them changes
|
|
|
|
*/
|
|
|
|
GMutex *state_lock;
|
|
|
|
GCond *state_cond;
|
|
|
|
OMX_STATETYPE state;
|
|
|
|
/* OMX_StateInvalid if no pending state */
|
|
|
|
OMX_STATETYPE pending_state;
|
|
|
|
/* OMX_ErrorNone usually, if different nothing will work */
|
|
|
|
OMX_ERRORTYPE last_error;
|
2011-07-19 08:33:54 +00:00
|
|
|
|
|
|
|
gint have_pending_reconfigure_outports; /* atomic */
|
|
|
|
GList *pending_reconfigure_outports;
|
2011-06-28 06:51:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstOMXBuffer {
|
|
|
|
GstOMXPort *port;
|
|
|
|
OMX_BUFFERHEADERTYPE *omx_buf;
|
|
|
|
|
|
|
|
/* TRUE if the buffer is used by the port, i.e.
|
|
|
|
* between {Empty,Fill}ThisBuffer and the callback
|
|
|
|
*/
|
|
|
|
gboolean used;
|
2011-07-08 13:25:07 +00:00
|
|
|
|
|
|
|
/* Cookie of the settings when this buffer was allocated */
|
|
|
|
gint settings_cookie;
|
2011-06-28 06:51:23 +00:00
|
|
|
};
|
|
|
|
|
2011-07-12 08:05:31 +00:00
|
|
|
extern GQuark gst_omx_element_name_quark;
|
|
|
|
|
|
|
|
GKeyFile * gst_omx_get_configuration (void);
|
|
|
|
|
2011-07-13 18:22:51 +00:00
|
|
|
const gchar * gst_omx_error_to_string (OMX_ERRORTYPE err);
|
2011-07-19 08:33:15 +00:00
|
|
|
guint64 gst_omx_parse_hacks (gchar ** hacks);
|
2011-07-13 18:22:51 +00:00
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
GstOMXCore * gst_omx_core_acquire (const gchar * filename);
|
|
|
|
void gst_omx_core_release (GstOMXCore * core);
|
|
|
|
|
|
|
|
|
2011-07-19 08:33:15 +00:00
|
|
|
GstOMXComponent * gst_omx_component_new (GstObject *parent, const gchar * core_name, const gchar * component_name, const gchar *component_role, guint64 hacks);
|
2011-06-28 06:51:23 +00:00
|
|
|
void gst_omx_component_free (GstOMXComponent * comp);
|
|
|
|
|
|
|
|
OMX_ERRORTYPE gst_omx_component_set_state (GstOMXComponent * comp, OMX_STATETYPE state);
|
|
|
|
OMX_STATETYPE gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout);
|
|
|
|
|
2011-07-06 08:29:54 +00:00
|
|
|
void gst_omx_component_set_last_error (GstOMXComponent * comp, OMX_ERRORTYPE err);
|
2011-06-28 06:51:23 +00:00
|
|
|
OMX_ERRORTYPE gst_omx_component_get_last_error (GstOMXComponent * comp);
|
2011-07-13 18:22:51 +00:00
|
|
|
const gchar * gst_omx_component_get_last_error_string (GstOMXComponent * comp);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
GstOMXPort * gst_omx_component_add_port (GstOMXComponent * comp, guint32 index);
|
|
|
|
GstOMXPort * gst_omx_component_get_port (GstOMXComponent * comp, guint32 index);
|
|
|
|
|
2011-07-19 08:33:54 +00:00
|
|
|
void gst_omx_component_trigger_settings_changed (GstOMXComponent * comp, guint32 port_index);
|
2011-07-08 13:25:07 +00:00
|
|
|
|
2011-07-28 08:23:08 +00:00
|
|
|
OMX_ERRORTYPE gst_omx_component_get_parameter (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer param);
|
|
|
|
OMX_ERRORTYPE gst_omx_component_set_parameter (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer param);
|
|
|
|
|
|
|
|
OMX_ERRORTYPE gst_omx_component_get_config (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer config);
|
|
|
|
OMX_ERRORTYPE gst_omx_component_set_config (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer config);
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
void gst_omx_port_get_port_definition (GstOMXPort * port, OMX_PARAM_PORTDEFINITIONTYPE * port_def);
|
|
|
|
gboolean gst_omx_port_update_port_definition (GstOMXPort *port, OMX_PARAM_PORTDEFINITIONTYPE *port_definition);
|
|
|
|
|
2011-07-07 10:23:24 +00:00
|
|
|
GstOMXAcquireBufferReturn gst_omx_port_acquire_buffer (GstOMXPort *port, GstOMXBuffer **buf);
|
2011-07-06 08:29:54 +00:00
|
|
|
OMX_ERRORTYPE gst_omx_port_release_buffer (GstOMXPort *port, GstOMXBuffer *buf);
|
2011-06-28 06:51:23 +00:00
|
|
|
|
|
|
|
OMX_ERRORTYPE gst_omx_port_set_flushing (GstOMXPort *port, gboolean flush);
|
|
|
|
gboolean gst_omx_port_is_flushing (GstOMXPort *port);
|
|
|
|
|
|
|
|
OMX_ERRORTYPE gst_omx_port_allocate_buffers (GstOMXPort *port);
|
|
|
|
OMX_ERRORTYPE gst_omx_port_deallocate_buffers (GstOMXPort *port);
|
|
|
|
|
|
|
|
OMX_ERRORTYPE gst_omx_port_reconfigure (GstOMXPort * port);
|
|
|
|
|
|
|
|
OMX_ERRORTYPE gst_omx_port_set_enabled (GstOMXPort * port, gboolean enabled);
|
|
|
|
gboolean gst_omx_port_is_enabled (GstOMXPort * port);
|
|
|
|
|
2011-07-19 08:33:54 +00:00
|
|
|
OMX_ERRORTYPE gst_omx_port_manual_reconfigure (GstOMXPort * port, gboolean start);
|
|
|
|
|
2011-06-28 06:51:23 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_OMX_H__ */
|