X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=aacdec_filter.c;h=a2459d82b31991a8e9ac578e0559a398c83f4e10;hp=5c1ea6d395347810ab9216707fd36aaf1b78a365;hb=HEAD;hpb=3013ef1f9e2dcd1426041837daf86f3d401acd94 diff --git a/aacdec_filter.c b/aacdec_filter.c index 5c1ea6d3..87a7900a 100644 --- a/aacdec_filter.c +++ b/aacdec_filter.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2006 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2006 Andre Noll , see file COPYING. */ /* * based in parts on libfaad, Copyright (C) 2003-2005 M. Bakker, * Ahead Software AG @@ -17,7 +13,6 @@ #include "portable_io.h" #include "list.h" #include "sched.h" -#include "ggo.h" #include "buffer_tree.h" #include "filter.h" #include "error.h" @@ -29,13 +24,13 @@ /** * data specific to the aacdec filter * - * \sa filter, filter_node + * \sa \ref filter, \ref filter_node. */ struct private_aacdec_data { /** the return value of aac_open */ NeAACDecHandle handle; /** whether this instance of the aac decoder is already initialized */ - int initialized; + bool initialized; /** number of times the decoder returned an error */ unsigned error_count; /** number of bytes already consumed from the imput stream */ @@ -46,23 +41,6 @@ struct private_aacdec_data { unsigned int sample_rate; }; -/* - * Get a new libfaad decoder handle. - * - * \return The handle returned by NeAACDecOpen(). - */ -static NeAACDecHandle aac_open(void) -{ - NeAACDecHandle h = NeAACDecOpen(); - NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h); - - c->defObjectType = LC; - c->outputFormat = FAAD_FMT_16BIT; - c->downMatrix = 0; - NeAACDecSetConfiguration(h, c); - return h; -} - static int aacdec_execute(struct btr_node *btrn, const char *cmd, char **result) { struct filter_node *fn = btr_context(btrn); @@ -73,11 +51,18 @@ static int aacdec_execute(struct btr_node *btrn, const char *cmd, char **result) static void aacdec_open(struct filter_node *fn) { - struct private_aacdec_data *padd = para_calloc(sizeof(*padd)); + NeAACDecConfigurationPtr c; + struct private_aacdec_data *padd = zalloc(sizeof(*padd)); + + padd->handle = NeAACDecOpen(); + c = NeAACDecGetCurrentConfiguration(padd->handle); + c->defObjectType = LC; + c->outputFormat = FAAD_FMT_16BIT; + c->downMatrix = 0; + NeAACDecSetConfiguration(padd->handle, c); fn->private_data = padd; fn->min_iqs = 2048; - padd->handle = aac_open(); } static void aacdec_close(struct filter_node *fn) @@ -89,14 +74,14 @@ static void aacdec_close(struct filter_node *fn) fn->private_data = NULL; } -static int aacdec_post_select(__a_unused struct sched *s, void *context) +static int aacdec_post_monitor(__a_unused struct sched *s, void *context) { struct filter_node *fn = context; struct btr_node *btrn = fn->btrn; struct private_aacdec_data *padd = fn->private_data; int i, ret; char *inbuf, *outbuf, *btrbuf; - size_t len, consumed, loaded; + size_t len, consumed, loaded = 0; NeAACDecFrameInfo frame_info; next_buffer: @@ -124,7 +109,7 @@ next_buffer: padd->channels = channels; PARA_INFO_LOG("rate: %u, channels: %u\n", padd->sample_rate, padd->channels); - padd->initialized = 1; + padd->initialized = true; } if (consumed >= len) goto success; @@ -151,8 +136,7 @@ next_buffer: consumed += frame_info.bytesconsumed; if (!frame_info.samples) goto success; - btrbuf = para_malloc(2 * frame_info.samples); - loaded = 0; + btrbuf = arr_alloc(2, frame_info.samples); for (i = 0; i < frame_info.samples; i++) { short sh = ((short *)outbuf)[i]; write_int16_host_endian(btrbuf + loaded, sh); @@ -162,25 +146,19 @@ next_buffer: success: btr_consume(btrn, consumed); padd->consumed_total += consumed; - goto next_buffer; + if (loaded == 0) + goto next_buffer; + return 1; err: assert(ret < 0); btr_remove_node(&fn->btrn); return ret; } -/** - * The init function of the aacdec filter. - * - * \param f Pointer to the filter struct to initialize. - * - * \sa filter::init - */ -void aacdec_filter_init(struct filter *f) -{ - f->open = aacdec_open; - f->close = aacdec_close; - f->pre_select = generic_filter_pre_select; - f->post_select = aacdec_post_select; - f->execute = aacdec_execute; -} +const struct filter lsg_filter_cmd_com_aacdec_user_data = { + .open = aacdec_open, + .close = aacdec_close, + .pre_monitor = generic_filter_pre_monitor, + .post_monitor = aacdec_post_monitor, + .execute = aacdec_execute +};