Skip to content

Commit

Permalink
opus: allow per feature registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Cerveau authored and GStreamer Marge Bot committed Mar 16, 2021
1 parent cd5d4b0 commit 5e728ee
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 14 deletions.
19 changes: 5 additions & 14 deletions ext/opus/gstopus.c
Expand Up @@ -21,26 +21,17 @@
#include <config.h>
#endif

#include "gstopusdec.h"
#include "gstopusenc.h"

#include <gst/tag/tag.h>
#include "gstopuselements.h"

static gboolean
plugin_init (GstPlugin * plugin)
{
gboolean ret = FALSE;

if (!gst_element_register (plugin, "opusenc", GST_RANK_PRIMARY,
GST_TYPE_OPUS_ENC))
return FALSE;

if (!gst_element_register (plugin, "opusdec", GST_RANK_PRIMARY,
GST_TYPE_OPUS_DEC))
return FALSE;

gst_tag_register_musicbrainz_tags ();
ret |= GST_ELEMENT_REGISTER (opusenc, plugin);
ret |= GST_ELEMENT_REGISTER (opusdec, plugin);

return TRUE;
return ret;
}

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
Expand Down
3 changes: 3 additions & 0 deletions ext/opus/gstopusdec.c
Expand Up @@ -46,6 +46,7 @@
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "gstopuselements.h"
#include "gstopusheader.h"
#include "gstopuscommon.h"
#include "gstopusdec.h"
Expand Down Expand Up @@ -78,6 +79,8 @@ static GstStaticPadTemplate opus_dec_sink_factory =
);

G_DEFINE_TYPE (GstOpusDec, gst_opus_dec, GST_TYPE_AUDIO_DECODER);
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (opusdec, "opusdec",
GST_RANK_PRIMARY, GST_TYPE_OPUS_DEC, opus_element_init (plugin));

#define DB_TO_LINEAR(x) pow (10., (x) / 20.)

Expand Down
39 changes: 39 additions & 0 deletions ext/opus/gstopuselement.c
@@ -0,0 +1,39 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2008> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) 2020 Huawei Technologies Co., Ltd.
* @Author: Julian Bouzas <julian.bouzas@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "gstopuselements.h"

#include <gst/tag/tag.h>

void
opus_element_init (GstPlugin * plugin)
{
static gsize res = FALSE;

if (g_once_init_enter (&res)) {
gst_tag_register_musicbrainz_tags ();
g_once_init_leave (&res, TRUE);
}
}
37 changes: 37 additions & 0 deletions ext/opus/gstopuselements.h
@@ -0,0 +1,37 @@
/*
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2008> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) 2020 Huawei Technologies Co., Ltd.
* @Author: Julian Bouzas <julian.bouzas@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef __GST_OPUS_ELEMENTS_H__
#define __GST_OPUS_ELEMENTS_H__

#include <gst/gst.h>

G_BEGIN_DECLS


G_GNUC_INTERNAL void opus_element_init (GstPlugin * plugin);

GST_ELEMENT_REGISTER_DECLARE (opusenc);
GST_ELEMENT_REGISTER_DECLARE (opusdec);

G_END_DECLS

#endif /* __GST_OPUS_ELEMENTS_H__ */
4 changes: 4 additions & 0 deletions ext/opus/gstopusenc.c
Expand Up @@ -52,6 +52,8 @@
#include <gst/pbutils/pbutils.h>
#include <gst/tag/tag.h>
#include <gst/glib-compat-private.h>

#include "gstopuselements.h"
#include "gstopusheader.h"
#include "gstopuscommon.h"
#include "gstopusenc.h"
Expand Down Expand Up @@ -243,6 +245,8 @@ static GstFlowReturn gst_opus_enc_encode (GstOpusEnc * enc, GstBuffer * buffer);
G_DEFINE_TYPE_WITH_CODE (GstOpusEnc, gst_opus_enc, GST_TYPE_AUDIO_ENCODER,
G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL);
G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL));
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (opusenc, "opusenc",
GST_RANK_PRIMARY, GST_TYPE_OPUS_ENC, opus_element_init (plugin));

static void
gst_opus_enc_set_tags (GstOpusEnc * enc)
Expand Down
1 change: 1 addition & 0 deletions ext/opus/meson.build
@@ -1,5 +1,6 @@
opus_sources = [
'gstopus.c',
'gstopuselement.c',
'gstopuscommon.c',
'gstopusdec.c',
'gstopusenc.c',
Expand Down

0 comments on commit 5e728ee

Please sign in to comment.