~ubuntu-branches/ubuntu/utopic/libav/utopic

« back to all changes in this revision

Viewing changes to libavcodec/apedec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler, Reinhard Tartler, Rico Tzschichholz
  • Date: 2014-08-30 11:02:45 UTC
  • mfrom: (1.3.47 sid)
  • Revision ID: package-import@ubuntu.com-20140830110245-io3dg7q85wfr7125
Tags: 6:11~beta1-2
[ Reinhard Tartler ]
* Make libavcodec-dev depend on libavresample-dev

[ Rico Tzschichholz ]
* Some fixes and leftovers from soname bumps

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
 */
22
22
 
 
23
#include <inttypes.h>
 
24
 
23
25
#include "libavutil/avassert.h"
24
26
#include "libavutil/channel_layout.h"
25
27
#include "libavutil/opt.h"
 
28
#include "apedsp.h"
26
29
#include "avcodec.h"
27
 
#include "dsputil.h"
 
30
#include "bswapdsp.h"
28
31
#include "bytestream.h"
29
32
#include "internal.h"
30
33
#include "get_bits.h"
133
136
typedef struct APEContext {
134
137
    AVClass *class;                          ///< class for AVOptions
135
138
    AVCodecContext *avctx;
136
 
    DSPContext dsp;
 
139
    BswapDSPContext bdsp;
 
140
    APEDSPContext adsp;
137
141
    int channels;
138
142
    int samples;                             ///< samples left to decode in current frame
139
143
    int bps;
193
197
static void predictor_decode_mono_3950(APEContext *ctx, int count);
194
198
static void predictor_decode_stereo_3950(APEContext *ctx, int count);
195
199
 
196
 
// TODO: dsputilize
197
 
 
198
200
static av_cold int ape_decode_close(AVCodecContext *avctx)
199
201
{
200
202
    APEContext *s = avctx->priv_data;
210
212
    return 0;
211
213
}
212
214
 
 
215
static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, const int16_t *v2,
 
216
                                              const int16_t *v3,
 
217
                                              int order, int mul)
 
218
{
 
219
    int res = 0;
 
220
 
 
221
    while (order--) {
 
222
        res   += *v1 * *v2++;
 
223
        *v1++ += mul * *v3++;
 
224
    }
 
225
    return res;
 
226
}
 
227
 
213
228
static av_cold int ape_decode_init(AVCodecContext *avctx)
214
229
{
215
230
    APEContext *s = avctx->priv_data;
290
305
        s->predictor_decode_stereo = predictor_decode_stereo_3950;
291
306
    }
292
307
 
293
 
    ff_dsputil_init(&s->dsp, avctx);
 
308
    s->adsp.scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
 
309
 
 
310
    if (ARCH_ARM)
 
311
        ff_apedsp_init_arm(&s->adsp);
 
312
    if (ARCH_PPC)
 
313
        ff_apedsp_init_ppc(&s->adsp);
 
314
    if (ARCH_X86)
 
315
        ff_apedsp_init_x86(&s->adsp);
 
316
 
 
317
    ff_bswapdsp_init(&s->bdsp);
294
318
    avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
295
319
 
296
320
    return 0;
911
935
{
912
936
    int i, j;
913
937
    int32_t dotprod, sign;
914
 
    int32_t coeffs[8], delay[8];
 
938
    int32_t coeffs[8] = { 0 }, delay[8] = { 0 };
915
939
 
916
 
    memset(coeffs, 0, sizeof(coeffs));
917
 
    memset(delay,  0, sizeof(delay));
918
940
    for (i = 0; i < length; i++) {
919
941
        dotprod = 0;
920
942
        sign = APESIGN(buffer[i]);
1261
1283
 
1262
1284
    while (count--) {
1263
1285
        /* round fixedpoint scalar product */
1264
 
        res = ctx->dsp.scalarproduct_and_madd_int16(f->coeffs, f->delay - order,
1265
 
                                                    f->adaptcoeffs - order,
1266
 
                                                    order, APESIGN(*data));
 
1286
        res = ctx->adsp.scalarproduct_and_madd_int16(f->coeffs,
 
1287
                                                     f->delay - order,
 
1288
                                                     f->adaptcoeffs - order,
 
1289
                                                     order, APESIGN(*data));
1267
1290
        res = (res + (1 << (fracbits - 1))) >> fracbits;
1268
1291
        res += *data;
1269
1292
        *data++ = res;
1429
1452
        av_fast_malloc(&s->data, &s->data_size, buf_size);
1430
1453
        if (!s->data)
1431
1454
            return AVERROR(ENOMEM);
1432
 
        s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2);
 
1455
        s->bdsp.bswap_buf((uint32_t *) s->data, (const uint32_t *) buf,
 
1456
                          buf_size >> 2);
1433
1457
        memset(s->data + (buf_size & ~3), 0, buf_size & 3);
1434
1458
        s->ptr = s->data;
1435
1459
        s->data_end = s->data + buf_size;
1456
1480
        }
1457
1481
 
1458
1482
        if (!nblocks || nblocks > INT_MAX) {
1459
 
            av_log(avctx, AV_LOG_ERROR, "Invalid sample count: %u.\n", nblocks);
 
1483
            av_log(avctx, AV_LOG_ERROR, "Invalid sample count: %"PRIu32".\n",
 
1484
                   nblocks);
1460
1485
            return AVERROR_INVALIDDATA;
1461
1486
        }
1462
1487
        s->samples = nblocks;