~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavfilter/af_pan.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    double gain[MAX_CHANNELS][MAX_CHANNELS];
47
47
    int64_t need_renorm;
48
48
    int need_renumber;
49
 
    int nb_input_channels;
50
49
    int nb_output_channels;
51
50
 
52
51
    int pure_gains;
116
115
    if (!args)
117
116
        return AVERROR(ENOMEM);
118
117
    arg = av_strtok(args, "|", &tokenizer);
119
 
    ret = ff_parse_channel_layout(&pan->out_channel_layout, arg, ctx);
 
118
    ret = ff_parse_channel_layout(&pan->out_channel_layout,
 
119
                                  &pan->nb_output_channels, arg, ctx);
120
120
    if (ret < 0)
121
121
        goto fail;
122
 
    pan->nb_output_channels = av_get_channel_layout_nb_channels(pan->out_channel_layout);
123
122
 
124
123
    /* parse channel specifications */
125
124
    while ((arg = arg0 = av_strtok(NULL, "|", &tokenizer))) {
239
238
    ff_set_common_samplerates(ctx, formats);
240
239
 
241
240
    // inlink supports any channel layout
242
 
    layouts = ff_all_channel_layouts();
 
241
    layouts = ff_all_channel_counts();
243
242
    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
244
243
 
245
244
    // outlink supports only requested output channel layout
246
245
    layouts = NULL;
247
 
    ff_add_channel_layout(&layouts, pan->out_channel_layout);
 
246
    ff_add_channel_layout(&layouts,
 
247
                          pan->out_channel_layout ? pan->out_channel_layout :
 
248
                          FF_COUNT2LAYOUT(pan->nb_output_channels));
248
249
    ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
249
250
    return 0;
250
251
}
257
258
    int i, j, k, r;
258
259
    double t;
259
260
 
260
 
    pan->nb_input_channels = av_get_channel_layout_nb_channels(link->channel_layout);
261
261
    if (pan->need_renumber) {
262
262
        // input channels were given by their name: renumber them
263
263
        for (i = j = 0; i < MAX_CHANNELS; i++) {
271
271
 
272
272
    // sanity check; can't be done in query_formats since the inlink
273
273
    // channel layout is unknown at that time
274
 
    if (pan->nb_input_channels > SWR_CH_MAX ||
 
274
    if (link->channels > SWR_CH_MAX ||
275
275
        pan->nb_output_channels > SWR_CH_MAX) {
276
276
        av_log(ctx, AV_LOG_ERROR,
277
277
               "libswresample support a maximum of %d channels. "
286
286
                                  0, ctx);
287
287
    if (!pan->swr)
288
288
        return AVERROR(ENOMEM);
 
289
    if (!link->channel_layout)
 
290
        av_opt_set_int(pan->swr, "ich", link->channels, 0);
 
291
    if (!pan->out_channel_layout)
 
292
        av_opt_set_int(pan->swr, "och", pan->nb_output_channels, 0);
289
293
 
290
294
    // gains are pure, init the channel mapping
291
295
    if (pan->pure_gains) {
293
297
        // get channel map from the pure gains
294
298
        for (i = 0; i < pan->nb_output_channels; i++) {
295
299
            int ch_id = -1;
296
 
            for (j = 0; j < pan->nb_input_channels; j++) {
 
300
            for (j = 0; j < link->channels; j++) {
297
301
                if (pan->gain[i][j]) {
298
302
                    ch_id = j;
299
303
                    break;
311
315
            if (!((pan->need_renorm >> i) & 1))
312
316
                continue;
313
317
            t = 0;
314
 
            for (j = 0; j < pan->nb_input_channels; j++)
 
318
            for (j = 0; j < link->channels; j++)
315
319
                t += pan->gain[i][j];
316
320
            if (t > -1E-5 && t < 1E-5) {
317
321
                // t is almost 0 but not exactly, this is probably a mistake
320
324
                           "Degenerate coefficients while renormalizing\n");
321
325
                continue;
322
326
            }
323
 
            for (j = 0; j < pan->nb_input_channels; j++)
 
327
            for (j = 0; j < link->channels; j++)
324
328
                pan->gain[i][j] /= t;
325
329
        }
326
330
        av_opt_set_int(pan->swr, "icl", link->channel_layout, 0);
335
339
    // summary
336
340
    for (i = 0; i < pan->nb_output_channels; i++) {
337
341
        cur = buf;
338
 
        for (j = 0; j < pan->nb_input_channels; j++) {
 
342
        for (j = 0; j < link->channels; j++) {
339
343
            r = snprintf(cur, buf + sizeof(buf) - cur, "%s%.3g i%d",
340
344
                         j ? " + " : "", pan->gain[i][j], j);
341
345
            cur += FFMIN(buf + sizeof(buf) - cur, r);
409
413
    { NULL }
410
414
};
411
415
 
412
 
AVFilter avfilter_af_pan = {
 
416
AVFilter ff_af_pan = {
413
417
    .name          = "pan",
414
418
    .description   = NULL_IF_CONFIG_SMALL("Remix channels with coefficients (panning)."),
415
419
    .priv_size     = sizeof(PanContext),