From b1d89fcc223ad80a0c0a29fc43ea7d81908a18a2 Mon Sep 17 00:00:00 2001 From: guoshaobing Date: Sat, 22 Jan 2022 16:26:04 +0800 Subject: [PATCH] =?UTF-8?q?Android=20=E7=A1=AC=E8=A7=A3=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=20sps/pps=E5=8F=98=E5=8C=96=E6=97=B6=E9=87=8D?= =?UTF-8?q?=E5=90=AF=E8=A7=A3=E7=A0=81=E5=99=A8=E7=BB=A7=E7=BB=AD=E6=92=AD?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.解决播放一个流(例如flv),相同分辨率,不同视频源,切换推流时,播放器绿屏问题 2.分辨率变化后,通知上层view进行适配 --- .../ffpipenode_android_mediacodec_vdec.c | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/ijkmedia/ijkplayer/android/pipeline/ffpipenode_android_mediacodec_vdec.c b/ijkmedia/ijkplayer/android/pipeline/ffpipenode_android_mediacodec_vdec.c index 4c6a53510b..ac821cb98f 100755 --- a/ijkmedia/ijkplayer/android/pipeline/ffpipenode_android_mediacodec_vdec.c +++ b/ijkmedia/ijkplayer/android/pipeline/ffpipenode_android_mediacodec_vdec.c @@ -552,9 +552,15 @@ static int feed_input_buffer2(JNIEnv *env, IJKFF_Pipenode *node, int64_t timeUs, avcodec_free_context(&new_avctx); return change_ret; } else { - if (opaque->codecpar->width != new_avctx->width && - opaque->codecpar->height != new_avctx->height) { + AVCodecContext *ic = opaque->decoder->avctx; + // resolution change or extradata change(eg.same resolution video. extradata change contain extradata size change and extradata content change) + if ((opaque->codecpar->width != new_avctx->width && opaque->codecpar->height != new_avctx->height) + || size_data_size != ic->extradata_size + || memcmp(ic->extradata, new_avctx->extradata, size_data_size) != 0) { ALOGW("AV_PKT_DATA_NEW_EXTRADATA: %d x %d\n", new_avctx->width, new_avctx->height); + //update extradata and extradata_size for next extradata change + ic->extradata_size = size_data_size; + ic->extradata = new_avctx->extradata; avcodec_parameters_from_context(opaque->codecpar, new_avctx); opaque->aformat_need_recreate = true; ffpipeline_set_surface_need_reconfigure_l(pipeline, true); @@ -799,9 +805,15 @@ static int feed_input_buffer(JNIEnv *env, IJKFF_Pipenode *node, int64_t timeUs, avcodec_free_context(&new_avctx); return change_ret; } else { - if (opaque->codecpar->width != new_avctx->width && - opaque->codecpar->height != new_avctx->height) { + AVCodecContext *ic = opaque->decoder->avctx; + // resolution change or extradata change(eg.same resolution video. extradata change contain extradata size change and extradata content change) + if ((opaque->codecpar->width != new_avctx->width && opaque->codecpar->height != new_avctx->height) + || size_data_size != ic->extradata_size + || memcmp(ic->extradata, new_avctx->extradata, size_data_size) != 0) { ALOGW("AV_PKT_DATA_NEW_EXTRADATA: %d x %d\n", new_avctx->width, new_avctx->height); + //update extradata and extradata_size for next extradata change + ic->extradata_size = size_data_size; + ic->extradata = new_avctx->extradata; avcodec_parameters_from_context(opaque->codecpar, new_avctx); opaque->aformat_need_recreate = true; ffpipeline_set_surface_need_reconfigure_l(pipeline, true); @@ -1126,6 +1138,12 @@ static int drain_output_buffer_l(JNIEnv *env, IJKFF_Pipenode *node, int64_t time // ffp_notify_msg3(ffp, FFP_MSG_VIDEO_SIZE_CHANGED, width, height); // opaque->frame_width = width; // opaque->frame_height = height; + + // update frame width and height for send FFP_MSG_VIDEO_SIZE_CHANGED msg on queue_picture method. + if(opaque->ffp->mediacodec_handle_resolution_change && opaque->codecpar->codec_id == AV_CODEC_ID_H264){ + opaque->frame_width = width; + opaque->frame_height = height; + } ALOGI( "AMEDIACODEC__INFO_OUTPUT_FORMAT_CHANGED\n" " width-height: (%d x %d)\n"