Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 477780 | Differences between
and this patch

Collapse All | Expand All

(-)src/native/ffmpeg/org_jitsi_impl_neomedia_codec_FFmpeg.c.orig (-219 lines)
Lines 18-28 Link Here
18
#include <libavfilter/avfiltergraph.h>
18
#include <libavfilter/avfiltergraph.h>
19
#include <libavfilter/buffersrc.h>
19
#include <libavfilter/buffersrc.h>
20
20
21
#ifndef _JITSI_LIBAV_
22
#include <libavfilter/formats.h> /* ff_default_query_formats, ff_make_format_list, ff_set_common_formats */
23
#include <libavfilter/internal.h> /* ff_request_frame */
24
#endif
25
26
#include <libswscale/swscale.h>
21
#include <libswscale/swscale.h>
27
22
28
#define DEFINE_AVCODECCONTEXT_F_PROPERTY_SETTER(name, property) \
23
#define DEFINE_AVCODECCONTEXT_F_PROPERTY_SETTER(name, property) \
Lines 454-621 Link Here
454
DEFINE_AVCODECCONTEXT_I_PROPERTY_SETTER(trellis, trellis)
449
DEFINE_AVCODECCONTEXT_I_PROPERTY_SETTER(trellis, trellis)
455
DEFINE_AVCODECCONTEXT_I_PROPERTY_SETTER(workaround_1bugs, workaround_bugs)
450
DEFINE_AVCODECCONTEXT_I_PROPERTY_SETTER(workaround_1bugs, workaround_bugs)
456
451
457
JNIEXPORT jlong JNICALL
458
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1graph_1alloc
459
    (JNIEnv *env, jclass clazz)
460
{
461
    return (jlong) (intptr_t) avfilter_graph_alloc();
462
}
463
464
JNIEXPORT jint JNICALL
465
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1graph_1config
466
    (JNIEnv *env, jclass clazz, jlong graph, jlong log_ctx)
467
{
468
    return
469
        (jint)
470
            avfilter_graph_config(
471
                    (AVFilterGraph *) (intptr_t) graph,
472
                    (AVClass *) (intptr_t) log_ctx);
473
}
474
475
JNIEXPORT void JNICALL
476
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1graph_1free
477
    (JNIEnv *env, jclass clazz, jlong graph)
478
{
479
    AVFilterGraph *graph_ = (AVFilterGraph *) (intptr_t) graph;
480
481
    avfilter_graph_free(&graph_);
482
}
483
484
JNIEXPORT jlong JNICALL
485
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1graph_1get_1filter
486
    (JNIEnv *env, jclass clazz, jlong graph, jstring name)
487
{
488
    const char *name_ = (*env)->GetStringUTFChars(env, name, NULL);
489
    AVFilterContext *filter;
490
491
    if (name_)
492
    {
493
        filter
494
            = avfilter_graph_get_filter(
495
                    (AVFilterGraph *) (intptr_t) graph,
496
                    (char *) name_);
497
        (*env)->ReleaseStringUTFChars(env, name, name_);
498
    }
499
    else
500
        filter = NULL;
501
    return (jlong) (intptr_t) filter;
502
}
503
504
static int
505
ffsink_end_frame(AVFilterLink *link)
506
{
507
    if (link->cur_buf)
508
        link->dst->priv = avfilter_ref_buffer(link->cur_buf, ~0);
509
    return 0;
510
}
511
512
static int
513
ffsink_query_formats(AVFilterContext *ctx)
514
{
515
    AVFilterContext *src = ctx;
516
    int err;
517
518
    /* Find buffer. */
519
#ifdef _JITSI_LIBAV_
520
    while (src && src->input_count && src->inputs)
521
#else
522
    while (src && src->nb_inputs && src->inputs)
523
#endif
524
    {
525
        AVFilterLink *link = src->inputs[0];
526
527
        if (link)
528
            src = link->src;
529
        else
530
            break;
531
    }
532
533
    /* Make ffsink output in the format in which buffer inputs. */
534
    if (src)
535
    {
536
        const int pix_fmts[] = { src->outputs[0]->in_formats->formats[0], -1 };
537
538
#ifdef _JITSI_LIBAV_
539
        avfilter_set_common_formats(ctx, ff_make_format_list(pix_fmts));
540
#else
541
        ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
542
#endif
543
544
        err = 0;
545
    }
546
    else
547
#ifdef _JITSI_LIBAV_
548
        err = query_formats(ctx);
549
#else
550
        err = ff_default_query_formats(ctx);
551
#endif
552
553
    return err;
554
}
555
556
static void
557
ffsink_uninit(AVFilterContext *ctx)
558
{
559
    ctx->priv = NULL;
560
}
561
562
JNIEXPORT jint JNICALL
563
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1graph_1parse
564
    (JNIEnv *env, jclass clazz,
565
    jlong graph, jstring filters, jlong inputs, jlong outputs, jlong log_ctx)
566
{
567
    const char *filters_ = (*env)->GetStringUTFChars(env, filters, NULL);
568
    int ret;
569
570
    if (filters_)
571
    {
572
        AVFilterGraph *graph_ = (AVFilterGraph *) (intptr_t) graph;
573
574
        ret
575
            = avfilter_graph_parse(
576
                    graph_,
577
                    filters_,
578
                    (AVFilterInOut **) (intptr_t) inputs,
579
                    (AVFilterInOut **) (intptr_t) outputs,
580
                    (AVClass *) (intptr_t) log_ctx);
581
582
        /*
583
         * FIXME The implementation at the time of this writing presumes that
584
         * the first filter is buffer, the last filter is nullsink meant to be
585
         * ffsink and the ffsink is expected to output in the format in which
586
         * the buffer inputs.
587
         */
588
        if (0 == ret)
589
        {
590
            /* Turn nullsink into ffsink. */
591
            unsigned filterCount = graph_->filter_count;
592
593
            if (filterCount)
594
            {
595
                AVFilterContext *ffsink = graph_->filters[filterCount - 1];
596
597
                /*
598
                 * Make sure query_format of ffsink outputs in the format in
599
                 * which buffer inputs. Otherwise, the output format may end up
600
                 * different on the C and Java sides.
601
                 */
602
                ffsink->filter->uninit = ffsink_uninit;
603
                ffsink->priv = NULL;
604
                ffsink->filter->query_formats = ffsink_query_formats;
605
606
                ffsink->input_pads->end_frame = ffsink_end_frame;
607
                ffsink->input_pads->min_perms = AV_PERM_READ;
608
                ffsink->input_pads->start_frame = NULL;
609
            }
610
        }
611
612
        (*env)->ReleaseStringUTFChars(env, filters, filters_);
613
    }
614
    else
615
        ret = AVERROR(ENOMEM);
616
    return (jint) ret;
617
}
618
619
JNIEXPORT void JNICALL
452
JNIEXPORT void JNICALL
620
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1register_1all
453
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1register_1all
621
    (JNIEnv *env, jclass clazz)
454
    (JNIEnv *env, jclass clazz)
Lines 623-635 Link Here
623
    avfilter_register_all();
456
    avfilter_register_all();
624
}
457
}
625
458
626
JNIEXPORT void JNICALL
627
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avfilter_1unref_1buffer
628
    (JNIEnv *env, jclass clazz, jlong ref)
629
{
630
    avfilter_unref_buffer((AVFilterBufferRef *) (intptr_t) ref);
631
}
632
633
JNIEXPORT jlong JNICALL
459
JNIEXPORT jlong JNICALL
634
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avframe_1get_1pts
460
Java_org_jitsi_impl_neomedia_codec_FFmpeg_avframe_1get_1pts
635
    (JNIEnv *env, jclass clazz, jlong frame)
461
    (JNIEnv *env, jclass clazz, jlong frame)
Lines 693-743 Link Here
693
                    (int) width, (int) height);
519
                    (int) width, (int) height);
694
}
520
}
695
521
696
JNIEXPORT jlong JNICALL
697
Java_org_jitsi_impl_neomedia_codec_FFmpeg_get_1filtered_1video_1frame
698
    (JNIEnv *env, jclass clazz,
699
    jlong input, jint width, jint height, jint pixFmt,
700
    jlong buffer, jlong ffsink, jlong output)
701
{
702
    AVFrame *input_ = (AVFrame *) (intptr_t) input;
703
    AVFilterContext *buffer_ = (AVFilterContext *) (intptr_t) buffer;
704
    AVFilterBufferRef *ref = NULL;
705
706
    input_->width = width;
707
    input_->height = height;
708
    input_->format = pixFmt;
709
    if (av_buffersrc_write_frame(buffer_, input_) == 0)
710
    {
711
        AVFilterContext *ffsink_ = (AVFilterContext *) (intptr_t) ffsink;
712
713
        if (ff_request_frame(ffsink_->inputs[0]) == 0)
714
        {
715
            ref = (AVFilterBufferRef *) (ffsink_->priv);
716
            if (ref)
717
            {
718
                AVFrame *output_ = (AVFrame *) (intptr_t) output;
719
720
                /*
721
                 * The data of cur_buf will be returned into output so it needs
722
                 * to exist at least while output needs it. So take ownership of
723
                 * cur_buf and the user of output will unref it when they are
724
                 * done with output.
725
                 */
726
                ffsink_->priv = NULL;
727
728
                memcpy(output_->data, ref->data, sizeof(output_->data));
729
                memcpy(
730
                    output_->linesize,
731
                    ref->linesize,
732
                    sizeof(output_->linesize));
733
                output_->interlaced_frame = ref->video->interlaced;
734
                output_->top_field_first = ref->video->top_field_first;
735
            }
736
        }
737
    }
738
    return (jlong) (intptr_t) ref;
739
}
740
741
JNIEXPORT void JNICALL
522
JNIEXPORT void JNICALL
742
Java_org_jitsi_impl_neomedia_codec_FFmpeg_memcpy___3IIIJ
523
Java_org_jitsi_impl_neomedia_codec_FFmpeg_memcpy___3IIIJ
743
    (JNIEnv *env, jclass clazz,
524
    (JNIEnv *env, jclass clazz,

Return to bug 477780