avcodec_open2() fails with error "Operation not permitted"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

avcodec_open2() fails with error "Operation not permitted"

FFmpeg-users mailing list
I'm trying to use h264_mediacodec decoder in my Android app. The decoder
is included in my ffmpeg build from master:

Enabled decoders:
h264 rawvideo vp8_mediacodec vp9_mediacodec h264_mediacodec vp8 vp9

I have followed the examples, e.g.,

https://ffmpeg.org/doxygen/trunk/decode__video_8c_source.html

and accordingly written this piece of code:

if (av_jni_set_java_vm(g_ctx.javaVM, NULL) != 0)
    LOGW("av_jni_set_java_vm failed!");

AVCodec *av_codec;
AVCodecContext *av_ctx;

av_codec = avcodec_find_decoder_by_name("h264_mediacodec");
if (av_codec != NULL)
    LOGW("found h264_mediacodec\n");

av_ctx = avcodec_alloc_context3(av_codec);
if (av_ctx != NULL)
    LOGW("allocated context\n");

int ret = avcodec_open2(av_ctx, av_codec, NULL);
if (ret < 0) {
        char str[AV_ERROR_MAX_STRING_SIZE];
        memset(str, 0, sizeof(str));
        av_strerror(ret, str, sizeof(str));
        LOGW("avcodec_open2 error: %d \"%s\"\n", ret, str);
    } else {
        LOGW("avcodec_open2 success\n");
    }

When it is executed, I get to log:

05-20 15:27:56.638 13664 13664 D Baresip Lib: found h264_mediacodec
05-20 15:27:56.638 13664 13664 D Baresip Lib: allocated context
05-20 15:27:56.638 13664 13664 D Baresip Lib: avcodec_open2 error: -1 "Operation not permitted"

Any ideas why avcodec_open2() fails?

-- Juha
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

avcodec_open2() fails with error "Operation not permitted"

FFmpeg-users mailing list
Juha Heinanen via ffmpeg-user writes:

> When it is executed, I get to log:
>
> 05-20 15:27:56.638 13664 13664 D Baresip Lib: found h264_mediacodec
> 05-20 15:27:56.638 13664 13664 D Baresip Lib: allocated context
> 05-20 15:27:56.638 13664 13664 D Baresip Lib: avcodec_open2 error: -1 "Operation not permitted"
>
> Any ideas why avcodec_open2() fails?

I traced this further and found that avcodec_open2() calls
mediacodec_decode_init() defined in libavcodec/mediacodecdec.c and there
the failing call is h264_set_extradata(), which returns -1:

    switch (avctx->codec_id) {
#if CONFIG_H264_MEDIACODEC_DECODER
    case AV_CODEC_ID_H264:
        codec_mime = "video/avc";
        ret = h264_set_extradata(avctx, format);
        /* ret is -1 */

And in h264_set_extradata(), the failing call is the first one:

    ret = ff_h264_decode_extradata(avctx->extradata, avctx->extradata_size,
        &ps, &is_avc, &nal_length_size, 0, avctx);

Finally, ff_h264_decode_extradata() fails in the first test:

    if (!data || size <= 0)
        return -1;

because data, i.e, avctx->extradata is NULL and its size is 0.

I haven't yet figured out why there is no extradata in avctx. Perhaps I
have missed some API call in my code?

-- Juha
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

avcodec_open2() fails with error "Operation not permitted"

FFmpeg-users mailing list
Juha Heinanen via ffmpeg-user writes:

> And in h264_set_extradata(), the failing call is the first one:
>
>     ret = ff_h264_decode_extradata(avctx->extradata, avctx->extradata_size,
>         &ps, &is_avc, &nal_length_size, 0, avctx);

Since decode with standard h264 decoder works, I checked why and found
in h264_decode_init() this:

    if (avctx->extradata_size > 0 && avctx->extradata) {
        ret = ff_h264_decode_extradata(avctx->extradata, avctx->extradata_size,
                                       &h->ps, &h->is_avc, &h->nal_length_size,
                                       avctx->err_recognition, avctx);
        if (ret < 0) {
            h264_decode_end(avctx);
            return ret;
        }
    }

So it works, because it decodes extradata only if extradata exists.
mediacodec_decode_init(), on the other hand, always tries to decode
extradata no matter if it exists or not.

-- Juha
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".