From 1e570fed17a2cf3ecfbca3b04b33d5bf3fe30b47 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 3 Jul 2017 13:17:11 +0200 Subject: omxh264enc: move profile and level parsing functions to their own files Will allow to re-use them in the decoder element. https://bugzilla.gnome.org/show_bug.cgi?id=783114 --- omx/Makefile.am | 2 ++ omx/gstomxh264enc.c | 68 ++-------------------------------------- omx/gstomxh264utils.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ omx/gstomxh264utils.h | 34 ++++++++++++++++++++ omx/meson.build | 1 + 5 files changed, 127 insertions(+), 65 deletions(-) create mode 100644 omx/gstomxh264utils.c create mode 100644 omx/gstomxh264utils.h (limited to 'omx') diff --git a/omx/Makefile.am b/omx/Makefile.am index 9371e8b..da567f9 100644 --- a/omx/Makefile.am +++ b/omx/Makefile.am @@ -22,6 +22,7 @@ libgstomx_la_SOURCES = \ gstomxmpeg4videodec.c \ gstomxmpeg2videodec.c \ gstomxh264dec.c \ + gstomxh264utils.c \ gstomxh263dec.c \ gstomxwmvdec.c \ $(VP8_C_FILES) \ @@ -49,6 +50,7 @@ noinst_HEADERS = \ gstomxmpeg2videodec.h \ gstomxmpeg4videodec.h \ gstomxh264dec.h \ + gstomxh264utils.h \ gstomxh263dec.h \ gstomxwmvdec.h \ $(VP8_H_FILES) \ diff --git a/omx/gstomxh264enc.c b/omx/gstomxh264enc.c index 13acdcb..dc2cda0 100644 --- a/omx/gstomxh264enc.c +++ b/omx/gstomxh264enc.c @@ -25,6 +25,7 @@ #include #include "gstomxh264enc.h" +#include "gstomxh264utils.h" #ifdef USE_OMX_TARGET_RPI #include @@ -233,69 +234,6 @@ gst_omx_h264_enc_stop (GstVideoEncoder * enc) return GST_VIDEO_ENCODER_CLASS (parent_class)->stop (enc); } -static OMX_VIDEO_AVCPROFILETYPE -get_profile_from_str (const gchar * profile) -{ - if (g_str_equal (profile, "baseline")) { - return OMX_VIDEO_AVCProfileBaseline; - } else if (g_str_equal (profile, "main")) { - return OMX_VIDEO_AVCProfileMain; - } else if (g_str_equal (profile, "extended")) { - return OMX_VIDEO_AVCProfileExtended; - } else if (g_str_equal (profile, "high")) { - return OMX_VIDEO_AVCProfileHigh; - } else if (g_str_equal (profile, "high-10")) { - return OMX_VIDEO_AVCProfileHigh10; - } else if (g_str_equal (profile, "high-4:2:2")) { - return OMX_VIDEO_AVCProfileHigh422; - } else if (g_str_equal (profile, "high-4:4:4")) { - return OMX_VIDEO_AVCProfileHigh444; - } - - return OMX_VIDEO_AVCProfileMax; -} - - -static OMX_VIDEO_AVCLEVELTYPE -get_level_from_str (const gchar * level) -{ - if (g_str_equal (level, "1")) { - return OMX_VIDEO_AVCLevel1; - } else if (g_str_equal (level, "1b")) { - return OMX_VIDEO_AVCLevel1b; - } else if (g_str_equal (level, "1.1")) { - return OMX_VIDEO_AVCLevel11; - } else if (g_str_equal (level, "1.2")) { - return OMX_VIDEO_AVCLevel12; - } else if (g_str_equal (level, "1.3")) { - return OMX_VIDEO_AVCLevel13; - } else if (g_str_equal (level, "2")) { - return OMX_VIDEO_AVCLevel2; - } else if (g_str_equal (level, "2.1")) { - return OMX_VIDEO_AVCLevel21; - } else if (g_str_equal (level, "2.2")) { - return OMX_VIDEO_AVCLevel22; - } else if (g_str_equal (level, "3")) { - return OMX_VIDEO_AVCLevel3; - } else if (g_str_equal (level, "3.1")) { - return OMX_VIDEO_AVCLevel31; - } else if (g_str_equal (level, "3.2")) { - return OMX_VIDEO_AVCLevel32; - } else if (g_str_equal (level, "4")) { - return OMX_VIDEO_AVCLevel4; - } else if (g_str_equal (level, "4.1")) { - return OMX_VIDEO_AVCLevel41; - } else if (g_str_equal (level, "4.2")) { - return OMX_VIDEO_AVCLevel42; - } else if (g_str_equal (level, "5")) { - return OMX_VIDEO_AVCLevel5; - } else if (g_str_equal (level, "5.1")) { - return OMX_VIDEO_AVCLevel51; - } - - return OMX_VIDEO_AVCLevelMax; -} - /* Update OMX_VIDEO_PARAM_PROFILELEVELTYPE.{eProfile,eLevel} * * Returns TRUE if succeeded or if not supported, FALSE if failed */ @@ -607,13 +545,13 @@ gst_omx_h264_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port, s = gst_caps_get_structure (peercaps, 0); profile_string = gst_structure_get_string (s, "profile"); if (profile_string) { - profile = get_profile_from_str (profile_string); + profile = gst_omx_h264_utils_get_profile_from_str (profile_string); if (profile == OMX_VIDEO_AVCProfileMax) goto unsupported_profile; } level_string = gst_structure_get_string (s, "level"); if (level_string) { - level = get_level_from_str (level_string); + level = gst_omx_h264_utils_get_level_from_str (level_string); if (level == OMX_VIDEO_AVCLevelMax) goto unsupported_level; } diff --git a/omx/gstomxh264utils.c b/omx/gstomxh264utils.c new file mode 100644 index 0000000..6aeb088 --- /dev/null +++ b/omx/gstomxh264utils.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011, Hewlett-Packard Development Company, L.P. + * Author: Sebastian Dröge , 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 "gstomxh264utils.h" + +OMX_VIDEO_AVCPROFILETYPE +gst_omx_h264_utils_get_profile_from_str (const gchar * profile) +{ + if (g_str_equal (profile, "baseline")) { + return OMX_VIDEO_AVCProfileBaseline; + } else if (g_str_equal (profile, "main")) { + return OMX_VIDEO_AVCProfileMain; + } else if (g_str_equal (profile, "extended")) { + return OMX_VIDEO_AVCProfileExtended; + } else if (g_str_equal (profile, "high")) { + return OMX_VIDEO_AVCProfileHigh; + } else if (g_str_equal (profile, "high-10")) { + return OMX_VIDEO_AVCProfileHigh10; + } else if (g_str_equal (profile, "high-4:2:2")) { + return OMX_VIDEO_AVCProfileHigh422; + } else if (g_str_equal (profile, "high-4:4:4")) { + return OMX_VIDEO_AVCProfileHigh444; + } + + return OMX_VIDEO_AVCProfileMax; +} + +OMX_VIDEO_AVCLEVELTYPE +gst_omx_h264_utils_get_level_from_str (const gchar * level) +{ + if (g_str_equal (level, "1")) { + return OMX_VIDEO_AVCLevel1; + } else if (g_str_equal (level, "1b")) { + return OMX_VIDEO_AVCLevel1b; + } else if (g_str_equal (level, "1.1")) { + return OMX_VIDEO_AVCLevel11; + } else if (g_str_equal (level, "1.2")) { + return OMX_VIDEO_AVCLevel12; + } else if (g_str_equal (level, "1.3")) { + return OMX_VIDEO_AVCLevel13; + } else if (g_str_equal (level, "2")) { + return OMX_VIDEO_AVCLevel2; + } else if (g_str_equal (level, "2.1")) { + return OMX_VIDEO_AVCLevel21; + } else if (g_str_equal (level, "2.2")) { + return OMX_VIDEO_AVCLevel22; + } else if (g_str_equal (level, "3")) { + return OMX_VIDEO_AVCLevel3; + } else if (g_str_equal (level, "3.1")) { + return OMX_VIDEO_AVCLevel31; + } else if (g_str_equal (level, "3.2")) { + return OMX_VIDEO_AVCLevel32; + } else if (g_str_equal (level, "4")) { + return OMX_VIDEO_AVCLevel4; + } else if (g_str_equal (level, "4.1")) { + return OMX_VIDEO_AVCLevel41; + } else if (g_str_equal (level, "4.2")) { + return OMX_VIDEO_AVCLevel42; + } else if (g_str_equal (level, "5")) { + return OMX_VIDEO_AVCLevel5; + } else if (g_str_equal (level, "5.1")) { + return OMX_VIDEO_AVCLevel51; + } + + return OMX_VIDEO_AVCLevelMax; +} diff --git a/omx/gstomxh264utils.h b/omx/gstomxh264utils.h new file mode 100644 index 0000000..6300486 --- /dev/null +++ b/omx/gstomxh264utils.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2011, Hewlett-Packard Development Company, L.P. + * Author: Sebastian Dröge , 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_H264_UTILS_H__ +#define __GST_OMX_H264_UTILS_H__ + +#include "gstomx.h" + +G_BEGIN_DECLS + +OMX_VIDEO_AVCPROFILETYPE gst_omx_h264_utils_get_profile_from_str (const + gchar * profile); +OMX_VIDEO_AVCLEVELTYPE gst_omx_h264_utils_get_level_from_str (const gchar * + level); + +G_END_DECLS +#endif /* __GST_OMX_H264_UTILS_H__ */ diff --git a/omx/meson.build b/omx/meson.build index 6fe1ce2..68cce69 100644 --- a/omx/meson.build +++ b/omx/meson.build @@ -10,6 +10,7 @@ omx_sources = [ 'gstomxmpeg4videodec.c', 'gstomxmpeg2videodec.c', 'gstomxh264dec.c', + 'gstomxh264utils.c', 'gstomxh263dec.c', 'gstomxwmvdec.c', 'gstomxmpeg4videoenc.c', -- cgit v1.2.1