omx: Add Theora decoder

This commit is contained in:
Sebastian Dröge 2013-03-19 09:36:18 +01:00
parent 29a348efac
commit 8460cabd13
5 changed files with 245 additions and 3 deletions

View file

@ -165,6 +165,15 @@ AC_CHECK_DECLS([OMX_VIDEO_CodingVP8],
], [[#include <OMX_Video.h>]])
AM_CONDITIONAL(HAVE_VP8, test "x$HAVE_VP8" = "xyes")
AC_CHECK_DECLS([OMX_VIDEO_CodingTheora],
[
AC_DEFINE(HAVE_THEORA, 1, [OpenMAX IL has Theora support])
HAVE_THEORA=yes
], [
HAVE_THEORA=no
], [[#include <OMX_Video.h>]])
AM_CONDITIONAL(HAVE_THEORA, test "x$HAVE_THEORA" = "xyes")
dnl Check for -Bsymbolic-functions linker flag used to avoid
dnl intra-library PLT jumps, if available.
AC_ARG_ENABLE(Bsymbolic,

View file

@ -5,6 +5,11 @@ VP8_C_FILES=gstomxvp8dec.c
VP8_H_FILES=gstomxvp8dec.h
endif
if HAVE_THEORA
THEORA_C_FILES=gstomxtheoradec.c
THEORA_H_FILES=gstomxtheoradec.h
endif
libgstomx_la_SOURCES = \
gstomx.c \
gstomxvideodec.c \
@ -15,8 +20,9 @@ libgstomx_la_SOURCES = \
gstomxmpeg2videodec.c \
gstomxh264dec.c \
gstomxh263dec.c \
$(VP8_C_FILES) \
gstomxwmvdec.c \
$(VP8_C_FILES) \
$(THEORA_C_FILES) \
gstomxmpeg4videoenc.c \
gstomxh264enc.c \
gstomxh263enc.c \
@ -32,8 +38,9 @@ noinst_HEADERS = \
gstomxmpeg4videodec.h \
gstomxh264dec.h \
gstomxh263dec.h \
$(VP8_H_FILES) \
gstomxwmvdec.h \
$(VP8_H_FILES) \
$(THEORA_H_FILES) \
gstomxmpeg4videoenc.h \
gstomxh264enc.h \
gstomxh263enc.h \
@ -58,7 +65,12 @@ libgstomx_la_LIBADD = \
$(GST_LIBS)
libgstomx_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
EXTRA_DIST = openmax
EXTRA_DIST = \
openmax \
gstomxvp8dec.c \
gstomxvp8dec.h \
gstomxtheoradec.c \
gstomxtheoradec.h
Android.mk: Makefile.am $(BUILT_SOURCES)
androgenizer \

View file

@ -34,6 +34,7 @@
#include "gstomxh264dec.h"
#include "gstomxh263dec.h"
#include "gstomxvp8dec.h"
#include "gstomxtheoradec.h"
#include "gstomxwmvdec.h"
#include "gstomxmpeg4videoenc.h"
#include "gstomxh264enc.h"
@ -2331,6 +2332,9 @@ static const GGetTypeFunction types[] = {
#ifdef HAVE_VP8
, gst_omx_vp8_dec_get_type
#endif
#ifdef HAVE_THEORA
, gst_omx_theora_dec_get_type
#endif
};
struct TypeOffest

156
omx/gstomxtheoradec.c Normal file
View file

@ -0,0 +1,156 @@
/*
* 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 "gstomxtheoradec.h"
GST_DEBUG_CATEGORY_STATIC (gst_omx_theora_dec_debug_category);
#define GST_CAT_DEFAULT gst_omx_theora_dec_debug_category
/* prototypes */
static gboolean gst_omx_theora_dec_is_format_change (GstOMXVideoDec * dec,
GstOMXPort * port, GstVideoCodecState * state);
static gboolean gst_omx_theora_dec_set_format (GstOMXVideoDec * dec,
GstOMXPort * port, GstVideoCodecState * state);
static GstFlowReturn gst_omx_theora_dec_handle_frame (GstVideoDecoder * decoder,
GstVideoCodecFrame * frame);
static gboolean gst_omx_theora_dec_stop (GstVideoDecoder * decoder);
enum
{
PROP_0
};
/* class initialization */
#define DEBUG_INIT \
GST_DEBUG_CATEGORY_INIT (gst_omx_theora_dec_debug_category, "omxtheoradec", 0, \
"debug category for gst-omx video decoder base class");
G_DEFINE_TYPE_WITH_CODE (GstOMXTheoraDec, gst_omx_theora_dec,
GST_TYPE_OMX_VIDEO_DEC, DEBUG_INIT);
static void
gst_omx_theora_dec_class_init (GstOMXTheoraDecClass * klass)
{
GstVideoDecoderClass *gstvideodec_class = GST_VIDEO_DECODER_CLASS (klass);
GstOMXVideoDecClass *videodec_class = GST_OMX_VIDEO_DEC_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
videodec_class->is_format_change =
GST_DEBUG_FUNCPTR (gst_omx_theora_dec_is_format_change);
videodec_class->set_format =
GST_DEBUG_FUNCPTR (gst_omx_theora_dec_set_format);
videodec_class->cdata.default_sink_template_caps = "video/x-theora";
gstvideodec_class->handle_frame = gst_omx_theora_dec_handle_frame;
gstvideodec_class->stop = gst_omx_theora_dec_stop;
gst_element_class_set_static_metadata (element_class,
"OpenMAX THEORA Video Decoder",
"Codec/Decoder/Video",
"Decode THEORA video streams",
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.theora");
}
static void
gst_omx_theora_dec_init (GstOMXTheoraDec * self)
{
}
static gboolean
gst_omx_theora_dec_is_format_change (GstOMXVideoDec * dec,
GstOMXPort * port, GstVideoCodecState * state)
{
return FALSE;
}
static gboolean
gst_omx_theora_dec_set_format (GstOMXVideoDec * dec, GstOMXPort * port,
GstVideoCodecState * state)
{
gboolean ret;
OMX_PARAM_PORTDEFINITIONTYPE port_def;
gst_omx_port_get_port_definition (port, &port_def);
port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingTheora;
ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone;
return ret;
}
static GstFlowReturn
gst_omx_theora_dec_handle_frame (GstVideoDecoder * decoder,
GstVideoCodecFrame * frame)
{
GstOMXTheoraDec *self = GST_OMX_THEORA_DEC (decoder);
if (GST_BUFFER_FLAG_IS_SET (frame->input_buffer, GST_BUFFER_FLAG_HEADER)) {
guint16 size;
GstBuffer *sbuf;
if (!self->header) {
self->header = gst_buffer_new ();
gst_buffer_copy_into (self->header, frame->input_buffer,
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
}
size = gst_buffer_get_size (frame->input_buffer);
size = GUINT16_TO_BE (size);
sbuf = gst_buffer_new_and_alloc (2);
gst_buffer_fill (sbuf, 0, &size, 2);
self->header = gst_buffer_append (self->header, sbuf);
self->header =
gst_buffer_append (self->header, gst_buffer_ref (frame->input_buffer));
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
return GST_FLOW_OK;
}
if (self->header) {
gst_buffer_replace (&GST_OMX_VIDEO_DEC (self)->codec_data, self->header);
gst_buffer_unref (self->header);
self->header = NULL;
}
return
GST_VIDEO_DECODER_CLASS (gst_omx_theora_dec_parent_class)->handle_frame
(GST_VIDEO_DECODER (self), frame);
}
static gboolean
gst_omx_theora_dec_stop (GstVideoDecoder * decoder)
{
GstOMXTheoraDec *self = GST_OMX_THEORA_DEC (decoder);
gst_buffer_replace (&self->header, NULL);
return TRUE;
}

61
omx/gstomxtheoradec.h Normal file
View file

@ -0,0 +1,61 @@
/*
* Copyright (C) 2013, Collabota Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* 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_THEORA_DEC_H__
#define __GST_OMX_THEORA_DEC_H__
#include <gst/gst.h>
#include "gstomxvideodec.h"
G_BEGIN_DECLS
#define GST_TYPE_OMX_THEORA_DEC \
(gst_omx_theora_dec_get_type())
#define GST_OMX_THEORA_DEC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OMX_THEORA_DEC,GstOMXTheoraDec))
#define GST_OMX_THEORA_DEC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OMX_THEORA_DEC,GstOMXTheoraDecClass))
#define GST_OMX_THEORA_DEC_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_OMX_THEORA_DEC,GstOMXTheoraDecClass))
#define GST_IS_OMX_THEORA_DEC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OMX_THEORA_DEC))
#define GST_IS_OMX_THEORA_DEC_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OMX_THEORA_DEC))
typedef struct _GstOMXTheoraDec GstOMXTheoraDec;
typedef struct _GstOMXTheoraDecClass GstOMXTheoraDecClass;
struct _GstOMXTheoraDec
{
GstOMXVideoDec parent;
GstBuffer *header;
};
struct _GstOMXTheoraDecClass
{
GstOMXVideoDecClass parent_class;
};
GType gst_omx_theora_dec_get_type (void);
G_END_DECLS
#endif /* __GST_OMX_THEORA_DEC_H__ */