2 * Copyright (C) 2013, Collabora Ltd.
3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "gstomxtheoradec.h"
29 GST_DEBUG_CATEGORY_STATIC (gst_omx_theora_dec_debug_category);
30 #define GST_CAT_DEFAULT gst_omx_theora_dec_debug_category
33 static gboolean gst_omx_theora_dec_is_format_change (GstOMXVideoDec * dec,
34 GstOMXPort * port, GstVideoCodecState * state);
35 static gboolean gst_omx_theora_dec_set_format (GstOMXVideoDec * dec,
36 GstOMXPort * port, GstVideoCodecState * state);
37 static GstFlowReturn gst_omx_theora_dec_handle_frame (GstVideoDecoder * decoder,
38 GstVideoCodecFrame * frame);
39 static gboolean gst_omx_theora_dec_stop (GstVideoDecoder * decoder);
46 /* class initialization */
49 GST_DEBUG_CATEGORY_INIT (gst_omx_theora_dec_debug_category, "omxtheoradec", 0, \
50 "debug category for gst-omx video decoder base class");
52 G_DEFINE_TYPE_WITH_CODE (GstOMXTheoraDec, gst_omx_theora_dec,
53 GST_TYPE_OMX_VIDEO_DEC, DEBUG_INIT);
56 gst_omx_theora_dec_class_init (GstOMXTheoraDecClass * klass)
58 GstVideoDecoderClass *gstvideodec_class = GST_VIDEO_DECODER_CLASS (klass);
59 GstOMXVideoDecClass *videodec_class = GST_OMX_VIDEO_DEC_CLASS (klass);
60 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
62 videodec_class->is_format_change =
63 GST_DEBUG_FUNCPTR (gst_omx_theora_dec_is_format_change);
64 videodec_class->set_format =
65 GST_DEBUG_FUNCPTR (gst_omx_theora_dec_set_format);
67 videodec_class->cdata.default_sink_template_caps = "video/x-theora, "
68 "width=(int) [1,MAX], " "height=(int) [1,MAX]";
70 gstvideodec_class->handle_frame = gst_omx_theora_dec_handle_frame;
71 gstvideodec_class->stop = gst_omx_theora_dec_stop;
73 gst_element_class_set_static_metadata (element_class,
74 "OpenMAX Theora Video Decoder",
75 "Codec/Decoder/Video/Hardware",
76 "Decode Theora video streams",
77 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
79 gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.theora");
83 gst_omx_theora_dec_init (GstOMXTheoraDec * self)
88 gst_omx_theora_dec_is_format_change (GstOMXVideoDec * dec,
89 GstOMXPort * port, GstVideoCodecState * state)
95 gst_omx_theora_dec_set_format (GstOMXVideoDec * dec, GstOMXPort * port,
96 GstVideoCodecState * state)
99 OMX_PARAM_PORTDEFINITIONTYPE port_def;
101 gst_omx_port_get_port_definition (port, &port_def);
102 port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingTheora;
103 ret = gst_omx_port_update_port_definition (port, &port_def) == OMX_ErrorNone;
109 gst_omx_theora_dec_handle_frame (GstVideoDecoder * decoder,
110 GstVideoCodecFrame * frame)
112 GstOMXTheoraDec *self = GST_OMX_THEORA_DEC (decoder);
114 if (GST_BUFFER_FLAG_IS_SET (frame->input_buffer, GST_BUFFER_FLAG_HEADER)) {
119 self->header = gst_buffer_new ();
120 gst_buffer_copy_into (self->header, frame->input_buffer,
121 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
124 size = gst_buffer_get_size (frame->input_buffer);
125 size = GUINT16_TO_BE (size);
126 sbuf = gst_buffer_new_and_alloc (2);
127 gst_buffer_fill (sbuf, 0, &size, 2);
128 self->header = gst_buffer_append (self->header, sbuf);
131 gst_buffer_append (self->header, gst_buffer_ref (frame->input_buffer));
133 gst_video_decoder_drop_frame (GST_VIDEO_DECODER (self), frame);
139 gst_buffer_replace (&GST_OMX_VIDEO_DEC (self)->codec_data, self->header);
140 gst_buffer_unref (self->header);
145 GST_VIDEO_DECODER_CLASS (gst_omx_theora_dec_parent_class)->handle_frame
146 (GST_VIDEO_DECODER (self), frame);
150 gst_omx_theora_dec_stop (GstVideoDecoder * decoder)
152 GstOMXTheoraDec *self = GST_OMX_THEORA_DEC (decoder);
154 gst_buffer_replace (&self->header, NULL);