if (s->use_ndk_codec < 0)
s->use_ndk_codec = !av_jni_get_java_vm(avctx);
format = ff_AMediaFormat_new(s->use_ndk_codec); if (!format) {
av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
ret = AVERROR_EXTERNAL; goto done;
}
switch (avctx->codec_id) { #if CONFIG_AV1_MEDIACODEC_DECODER case AV_CODEC_ID_AV1:
codec_mime = "video/av01";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_H264_MEDIACODEC_DECODER case AV_CODEC_ID_H264:
codec_mime = "video/avc";
ret = h264_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_HEVC_MEDIACODEC_DECODER case AV_CODEC_ID_HEVC:
codec_mime = "video/hevc";
#if CONFIG_HEVC_MEDIACODEC_DECODER_EXTRADATA
ret = hevc_set_extradata(avctx, format); #else
ret = common_set_extradata(avctx, format); #endif if (ret < 0) goto done; break; #endif #if CONFIG_MPEG2_MEDIACODEC_DECODER case AV_CODEC_ID_MPEG2VIDEO:
codec_mime = "video/mpeg2";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_MPEG4_MEDIACODEC_DECODER case AV_CODEC_ID_MPEG4:
codec_mime = "video/mp4v-es",
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_VP8_MEDIACODEC_DECODER case AV_CODEC_ID_VP8:
codec_mime = "video/x-vnd.on2.vp8";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_VP9_MEDIACODEC_DECODER case AV_CODEC_ID_VP9:
codec_mime = "video/x-vnd.on2.vp9";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_AAC_MEDIACODEC_DECODER case AV_CODEC_ID_AAC:
codec_mime = "audio/mp4a-latm";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_AMRNB_MEDIACODEC_DECODER case AV_CODEC_ID_AMR_NB:
codec_mime = "audio/3gpp";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_AMRWB_MEDIACODEC_DECODER case AV_CODEC_ID_AMR_WB:
codec_mime = "audio/amr-wb";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif #if CONFIG_MP3_MEDIACODEC_DECODER case AV_CODEC_ID_MP3:
codec_mime = "audio/mpeg";
ret = common_set_extradata(avctx, format); if (ret < 0) goto done; break; #endif default:
av_assert0(0);
}
/* In delay_flush mode, wait until the user has released or rendered
all retained frames. */ if (s->delay_flush && ff_mediacodec_dec_is_flushing(avctx, s->ctx)) { if (!ff_mediacodec_dec_flush(avctx, s->ctx)) { return AVERROR(EAGAIN);
}
}
/* poll for new frame */
ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, false); if (ret != AVERROR(EAGAIN)) return ret;
/* feed decoder */ while (1) { if (s->ctx->current_input_buffer < 0 && !s->ctx->draining) { /* poll for input space */
index = ff_AMediaCodec_dequeueInputBuffer(s->ctx->codec, 0); if (index < 0) { /* no space, block for an output frame to appear */
ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, true); /* Try again if both input port and output port return EAGAIN. *Ifnodataisconsumedandnoframeinoutput,itcanmake *bothavcodec_send_packet()andavcodec_receive_frame() *returnEAGAIN,whichviolatethedesign.
*/ if (ff_AMediaCodec_infoTryAgainLater(s->ctx->codec, index) &&
ret == AVERROR(EAGAIN)) continue; return ret;
}
s->ctx->current_input_buffer = index;
}
/* try to flush any buffered packet data */ if (s->buffered_pkt.size > 0) {
ret = ff_mediacodec_dec_send(avctx, s->ctx, &s->buffered_pkt, false); if (ret >= 0) {
s->buffered_pkt.size -= ret;
s->buffered_pkt.data += ret; if (s->buffered_pkt.size <= 0) {
av_packet_unref(&s->buffered_pkt);
} else {
av_log(avctx, AV_LOG_WARNING, "could not send entire packet in single input buffer (%d < %d)\n",
ret, s->buffered_pkt.size+ret);
}
} elseif (ret < 0 && ret != AVERROR(EAGAIN)) { return ret;
}
if (s->amlogic_mpeg2_api23_workaround && s->buffered_pkt.size <= 0) { /* fallthrough to fetch next packet regardless of input buffer space */
} else { /* poll for space again */ continue;
}
}
#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM staticconst AVOption ff_mediacodec_adec_options[] = {
{ "ndk_codec", "Use MediaCodec from NDK",
OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AD },
{ "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AD },
{ NULL }
};
int moz_avcodec_mediacodec_is_eos(AVCodecContext* avctx) { // Note that MediaCodecH264DecContext is used by all codec types.
MediaCodecH264DecContext *s = avctx->priv_data; return s->ctx->eos;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.