2 * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
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 "gstomxh264dec.h"
28 #include "gstomxh264utils.h"
30 GST_DEBUG_CATEGORY_STATIC (gst_omx_h264_dec_debug_category);
31 #define GST_CAT_DEFAULT gst_omx_h264_dec_debug_category
34 static gboolean gst_omx_h264_dec_is_format_change (GstOMXVideoDec * dec,
35 GstOMXPort * port, GstVideoCodecState * state);
36 static gboolean gst_omx_h264_dec_set_format (GstOMXVideoDec * dec,
37 GstOMXPort * port, GstVideoCodecState * state);
44 /* class initialization */
47 GST_DEBUG_CATEGORY_INIT (gst_omx_h264_dec_debug_category, "omxh264dec", 0, \
48 "debug category for gst-omx video decoder base class");
50 G_DEFINE_TYPE_WITH_CODE (GstOMXH264Dec, gst_omx_h264_dec,
51 GST_TYPE_OMX_VIDEO_DEC, DEBUG_INIT);
54 gst_omx_h264_dec_class_init (GstOMXH264DecClass * klass)
56 GstOMXVideoDecClass *videodec_class = GST_OMX_VIDEO_DEC_CLASS (klass);
57 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
59 videodec_class->is_format_change =
60 GST_DEBUG_FUNCPTR (gst_omx_h264_dec_is_format_change);
61 videodec_class->set_format = GST_DEBUG_FUNCPTR (gst_omx_h264_dec_set_format);
63 videodec_class->cdata.default_sink_template_caps = "video/x-h264, "
64 "alignment=(string) au, "
65 "stream-format=(string) byte-stream, "
66 "width=(int) [1,MAX], " "height=(int) [1,MAX]";
68 gst_element_class_set_static_metadata (element_class,
69 "OpenMAX H.264 Video Decoder",
70 "Codec/Decoder/Video/Hardware",
71 "Decode H.264 video streams",
72 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
74 gst_omx_set_default_role (&videodec_class->cdata, "video_decoder.avc");
78 gst_omx_h264_dec_init (GstOMXH264Dec * self)
83 gst_omx_h264_dec_is_format_change (GstOMXVideoDec * dec,
84 GstOMXPort * port, GstVideoCodecState * state)
86 GstCaps *old_caps = NULL;
87 GstCaps *new_caps = state->caps;
88 GstStructure *old_structure, *new_structure;
89 const gchar *old_profile, *old_level, *new_profile, *new_level;
91 if (dec->input_state) {
92 old_caps = dec->input_state->caps;
99 old_structure = gst_caps_get_structure (old_caps, 0);
100 new_structure = gst_caps_get_structure (new_caps, 0);
101 old_profile = gst_structure_get_string (old_structure, "profile");
102 old_level = gst_structure_get_string (old_structure, "level");
103 new_profile = gst_structure_get_string (new_structure, "profile");
104 new_level = gst_structure_get_string (new_structure, "level");
106 if (g_strcmp0 (old_profile, new_profile) != 0
107 || g_strcmp0 (old_level, new_level) != 0) {
115 set_profile_and_level (GstOMXH264Dec * self, GstVideoCodecState * state)
118 OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
119 const gchar *profile_string, *level_string;
122 GST_OMX_INIT_STRUCT (¶m);
123 param.nPortIndex = GST_OMX_VIDEO_DEC (self)->dec_in_port->index;
125 /* Pass profile and level to the decoder if we have both info from the
127 s = gst_caps_get_structure (state->caps, 0);
128 profile_string = gst_structure_get_string (s, "profile");
132 param.eProfile = gst_omx_h264_utils_get_profile_from_str (profile_string);
133 if (param.eProfile == OMX_VIDEO_AVCProfileMax)
134 goto unsupported_profile;
136 level_string = gst_structure_get_string (s, "level");
140 param.eLevel = gst_omx_h264_utils_get_level_from_str (level_string);
141 if (param.eLevel == OMX_VIDEO_AVCLevelMax)
142 goto unsupported_level;
144 GST_DEBUG_OBJECT (self, "Set profile (%s) and level (%s) on decoder",
145 profile_string, level_string);
148 gst_omx_component_set_parameter (GST_OMX_VIDEO_DEC (self)->dec,
149 OMX_IndexParamVideoProfileLevelCurrent, ¶m);
150 if (err == OMX_ErrorUnsupportedIndex) {
151 GST_WARNING_OBJECT (self,
152 "Setting profile/level not supported by component");
153 } else if (err != OMX_ErrorNone) {
154 GST_ERROR_OBJECT (self,
155 "Error setting profile %u and level %u: %s (0x%08x)",
156 (guint) param.eProfile, (guint) param.eLevel,
157 gst_omx_error_to_string (err), err);
164 GST_ERROR_OBJECT (self, "Unsupported profile %s", profile_string);
168 GST_ERROR_OBJECT (self, "Unsupported level %s", level_string);
173 gst_omx_h264_dec_set_format (GstOMXVideoDec * dec, GstOMXPort * port,
174 GstVideoCodecState * state)
176 GstOMXVideoDecClass *klass = GST_OMX_VIDEO_DEC_GET_CLASS (dec);
177 OMX_PARAM_PORTDEFINITIONTYPE port_def;
180 gst_omx_port_get_port_definition (port, &port_def);
181 port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
182 err = gst_omx_port_update_port_definition (port, &port_def);
183 if (err != OMX_ErrorNone)
186 if (klass->cdata.hacks & GST_OMX_HACK_PASS_PROFILE_TO_DECODER) {
187 if (!set_profile_and_level (GST_OMX_H264_DEC (dec), state))