/*
 * Copyright (C) 2025 Fraunhofer Institute for Integrated Circuits IIS
 *
 * 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 __GSTMPEGHDEC_H__
#define __GSTMPEGHDEC_H__

#include <gst/gst.h>
#include <gst/audio/gstaudiodecoder.h>

#include "mpeghdec/mpeghdecoder.h"

G_BEGIN_DECLS
#define GST_TYPE_MPEGHDEC (gst_mpeghdec_get_type())
#define GST_MPEGHDEC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_MPEGHDEC, GstMpeghDec))
#define GST_MPEGHDEC_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_MPEGHDEC, GstMpeghDecClass))
#define GST_IS_MPEGHDEC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_MPEGHDEC))
#define GST_IS_MPEGHDEC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_MPEGHDEC))
typedef struct _GstMpeghDec GstMpeghDec;
typedef struct _GstMpeghDecClass GstMpeghDecClass;

typedef enum
{
  /* Off */
  GST_MPEGH_DRC_EFFECT_TYPE_OFF = -1,
  /* None */
  GST_MPEGH_DRC_EFFECT_TYPE_NONE = 0,
  /* Late night */
  GST_MPEGH_DRC_EFFECT_TYPE_NIGHT = 1,
  /* Noisy environment */
  GST_MPEGH_DRC_EFFECT_TYPE_NOISY = 2,
  /* Limited playback range */
  GST_MPEGH_DRC_EFFECT_TYPE_LIMITED = 3,
  /* Low playback level */
  GST_MPEGH_DRC_EFFECT_TYPE_LOWLEVEL = 4,
  /* Dialog enhancement */
  GST_MPEGH_DRC_EFFECT_TYPE_DIALOG = 5,
  /* General compression */
  GST_MPEGH_DRC_EFFECT_TYPE_GENERAL = 6
} GstMpeghEffectType;

struct _GstMpeghDec
{
  GstAudioDecoder element;

  HANDLE_MPEGH_DECODER_CONTEXT dec;

  gint target_layout;
  gfloat target_reference_level;
  GstMpeghEffectType drc_effect_type;
  gfloat drc_attenuation_factor;
  gfloat drc_boost_factor;
  gboolean album_mode;

  gint channels;
  gint samplerate;

  gboolean need_reorder;
  GstAudioChannelPosition positions[64];
  GstAudioChannelPosition mapped_positions[64];

  GstAudioInfo info;
};

struct _GstMpeghDecClass
{
  GstAudioDecoderClass parent_class;
};

GType gst_mpeghdec_get_type (void);

GST_ELEMENT_REGISTER_DECLARE (mpeghdec);

G_END_DECLS
#endif /* __GSTMPEGHDEC_H__ */
