0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00

audio/decode: remove macro crap

Declare decoders directly, instead of using the LIBAD_EXTERN macro. This
is simpler (no weird magic) and more extensible.
This commit is contained in:
wm4 2013-07-22 14:41:56 +02:00
parent 0b160e1257
commit f86b94f9b4
8 changed files with 61 additions and 116 deletions

View File

@ -126,7 +126,6 @@ SOURCES = talloc.c \
audio/format.c \
audio/mixer.c \
audio/reorder_ch.c \
audio/decode/ad.c \
audio/decode/ad_lavc.c \
audio/decode/ad_spdif.c \
audio/decode/dec_audio.c \

View File

@ -1,46 +0,0 @@
/*
* audio decoder interface
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "stream/stream.h"
#include "demux/demux.h"
#include "demux/stheader.h"
#include "ad.h"
/* Missed vorbis, mad, dshow */
extern const ad_functions_t mpcodecs_ad_mpg123;
extern const ad_functions_t mpcodecs_ad_lavc;
extern const ad_functions_t mpcodecs_ad_spdif;
const ad_functions_t * const mpcodecs_ad_drivers[] =
{
#ifdef CONFIG_MPG123
&mpcodecs_ad_mpg123,
#endif
&mpcodecs_ad_lavc,
&mpcodecs_ad_spdif,
NULL
};

View File

@ -21,14 +21,14 @@
#include "core/codecs.h"
#include "demux/stheader.h"
#include "demux/demux.h"
typedef struct mp_codec_info ad_info_t;
#include "audio/format.h"
struct mp_decoder_list;
/* interface of video decoder drivers */
typedef struct ad_functions
{
struct ad_functions {
const char *name;
void (*add_decoders)(struct mp_decoder_list *list);
int (*preinit)(sh_audio_t *sh);
@ -37,10 +37,7 @@ typedef struct ad_functions
int (*control)(sh_audio_t *sh, int cmd, void *arg);
int (*decode_audio)(sh_audio_t *sh, unsigned char *buffer, int minlen,
int maxlen);
} ad_functions_t;
// NULL terminated array of all drivers
extern const ad_functions_t * const mpcodecs_ad_drivers[];
};
#define ADCTRL_RESYNC_STREAM 1 // resync, called after seeking

View File

@ -1,48 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AD_INTERNAL_H
#define MPLAYER_AD_INTERNAL_H
#include "core/codecs.h"
#include "audio/format.h"
#include "stream/stream.h"
#include "demux/demux.h"
#include "demux/stheader.h"
#include "ad.h"
static void add_decoders(struct mp_decoder_list *list);
static int init(sh_audio_t *sh, const char *decoder);
static int preinit(sh_audio_t *sh);
static void uninit(sh_audio_t *sh);
static int control(sh_audio_t *sh, int cmd, void *arg);
static int decode_audio(sh_audio_t *sh,unsigned char *buffer,int minlen,int maxlen);
#define LIBAD_EXTERN(x) const ad_functions_t mpcodecs_ad_##x = {\
#x, \
add_decoders, \
preinit,\
init,\
uninit,\
control,\
decode_audio\
};
#endif /* MPLAYER_AD_INTERNAL_H */

View File

@ -35,15 +35,13 @@
#include "core/options.h"
#include "core/av_opts.h"
#include "ad_internal.h"
#include "ad.h"
#include "audio/reorder_ch.h"
#include "audio/fmt-conversion.h"
#include "compat/mpbswap.h"
#include "compat/libav.h"
LIBAD_EXTERN(lavc)
struct priv {
AVCodecContext *avctx;
AVFrame *avframe;
@ -55,6 +53,9 @@ struct priv {
struct demux_packet *packet;
};
static void uninit(sh_audio_t *sh);
static int decode_audio(sh_audio_t *sh,unsigned char *buffer,int minlen,int maxlen);
#define OPT_BASE_STRUCT struct MPOpts
const m_option_t ad_lavc_decode_opts_conf[] = {
@ -467,3 +468,13 @@ static void add_decoders(struct mp_decoder_list *list)
mp_add_decoder(list, "lavc", "pcm", "pcm", "Raw PCM");
mp_add_decoder(list, "lavc", "mp-pcm", "mp-pcm", "Raw PCM");
}
const struct ad_functions ad_lavc = {
.name = "lavc",
.add_decoders = add_decoders,
.preinit = preinit,
.init = init,
.uninit = uninit,
.control = control,
.decode_audio = decode_audio,
};

View File

@ -24,9 +24,8 @@
#include "config.h"
#include "ad_internal.h"
LIBAD_EXTERN(mpg123)
#include "ad.h"
#include "core/mp_msg.h"
/* Reducing the ifdeffery to two main variants:
* 1. most compatible to any libmpg123 version
@ -472,3 +471,13 @@ static void add_decoders(struct mp_decoder_list *list)
mp_add_decoder(list, "mpg123", "mp3", "mp3",
"High-performance decoder using libmpg123");
}
const struct ad_functions ad_mpg123 = {
.name = "mpg123",
.add_decoders = add_decoders,
.preinit = preinit,
.init = init,
.uninit = uninit,
.control = control,
.decode_audio = decode_audio,
};

View File

@ -28,9 +28,7 @@
#include "core/mp_msg.h"
#include "core/av_common.h"
#include "core/options.h"
#include "ad_internal.h"
LIBAD_EXTERN(spdif)
#include "ad.h"
#define FILENAME_SPDIFENC "spdif"
#define OUTBUF_SIZE 65536
@ -43,6 +41,8 @@ struct spdifContext {
uint8_t pb_buffer[OUTBUF_SIZE];
};
static void uninit(sh_audio_t *sh);
static int read_packet(void *p, uint8_t *buf, int buf_size)
{
// spdifenc does not use read callback.
@ -267,3 +267,13 @@ static void add_decoders(struct mp_decoder_list *list)
}
}
}
const struct ad_functions ad_spdif = {
.name = "spdif",
.add_decoders = add_decoders,
.preinit = preinit,
.init = init,
.uninit = uninit,
.control = control,
.decode_audio = decode_audio,
};

View File

@ -41,6 +41,19 @@
#include "audio/filter/af.h"
extern const struct ad_functions ad_mpg123;
extern const struct ad_functions ad_lavc;
extern const struct ad_functions ad_spdif;
static const struct ad_functions * const ad_drivers[] = {
#ifdef CONFIG_MPG123
&ad_mpg123,
#endif
&ad_lavc,
&ad_spdif,
NULL
};
struct af_cfg af_cfg = {0}; // Configuration for audio filters
static int init_audio_codec(sh_audio_t *sh_audio, const char *decoder)
@ -90,8 +103,8 @@ static int init_audio_codec(sh_audio_t *sh_audio, const char *decoder)
struct mp_decoder_list *mp_audio_decoder_list(void)
{
struct mp_decoder_list *list = talloc_zero(NULL, struct mp_decoder_list);
for (int i = 0; mpcodecs_ad_drivers[i] != NULL; i++)
mpcodecs_ad_drivers[i]->add_decoders(list);
for (int i = 0; ad_drivers[i] != NULL; i++)
ad_drivers[i]->add_decoders(list);
return list;
}
@ -106,9 +119,9 @@ static struct mp_decoder_list *mp_select_audio_decoders(const char *codec,
static const struct ad_functions *find_driver(const char *name)
{
for (int i = 0; mpcodecs_ad_drivers[i] != NULL; i++) {
if (strcmp(mpcodecs_ad_drivers[i]->name, name) == 0)
return mpcodecs_ad_drivers[i];
for (int i = 0; ad_drivers[i] != NULL; i++) {
if (strcmp(ad_drivers[i]->name, name) == 0)
return ad_drivers[i];
}
return NULL;
}