diff --git a/sdk/android/src/jni/androidmediacodeccommon.h b/sdk/android/src/jni/androidmediacodeccommon.h index cc418eef137..b4bdf08031f 100644 --- a/sdk/android/src/jni/androidmediacodeccommon.h +++ b/sdk/android/src/jni/androidmediacodeccommon.h @@ -58,6 +58,9 @@ enum { kMaxPendingFramesVp8 = 1 }; enum { kMaxPendingFramesVp9 = 1 }; // Maximum amount of pending frames for H.264 decoder. enum { kMaxPendingFramesH264 = 4 }; +// TODO(zhanghe): update the value after checking more devices if needed. +// Maximum amount of pending frames for H.265 decoder. +enum { kMaxPendingFramesH265 = 4 }; // Maximum amount of decoded frames for which per-frame logging is enabled. enum { kMaxDecodedLogFrames = 10 }; // Maximum amount of encoded frames for which per-frame logging is enabled. diff --git a/sdk/android/src/jni/androidmediaencoder.cc b/sdk/android/src/jni/androidmediaencoder.cc index 463409df7f1..0e4a6cf7edc 100644 --- a/sdk/android/src/jni/androidmediaencoder.cc +++ b/sdk/android/src/jni/androidmediaencoder.cc @@ -1039,27 +1039,6 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { info.codecSpecific.VP9.gof.CopyGofInfoVP9(gof_); } } -#ifndef DISABLE_H265 - else if (codec_type == kVideoCodecH265) { - const std::vector nalu_idxs = - H265::FindNaluIndices(payload, payload_size); - if (nalu_idxs.empty()) { - ALOGE << "Start code is not found!"; - ALOGE << "Data:" << image->_buffer[0] << " " << image->_buffer[1] - << " " << image->_buffer[2] << " " << image->_buffer[3] - << " " << image->_buffer[4] << " " << image->_buffer[5]; - ProcessHWError(true /* reset_if_fallback_unavailable */); - return false; - } - header.VerifyAndAllocateFragmentationHeader(nalu_idxs.size()); - for (size_t i = 0; i < nalu_idxs.size(); i++) { - header.fragmentationOffset[i] = nalu_idxs[i].payload_start_offset; - header.fragmentationLength[i] = nalu_idxs[i].payload_size; - header.fragmentationPlType[i] = 0; - header.fragmentationTimeDiff[i] = 0; - } - } -#endif // Generate a header describing a single fragment. RTPFragmentationHeader header; memset(&header, 0, sizeof(header)); @@ -1108,6 +1087,27 @@ bool MediaCodecVideoEncoder::DeliverPendingOutputs(JNIEnv* jni) { header.fragmentationTimeDiff[i] = 0; } } +#ifndef DISABLE_H265 + else if (codec_type == kVideoCodecH265) { + const std::vector nalu_idxs = + H265::FindNaluIndices(payload, payload_size); + if (nalu_idxs.empty()) { + ALOGE << "Start code is not found!"; + ALOGE << "Data:" << image->_buffer[0] << " " << image->_buffer[1] + << " " << image->_buffer[2] << " " << image->_buffer[3] + << " " << image->_buffer[4] << " " << image->_buffer[5]; + ProcessHWError(true /* reset_if_fallback_unavailable */); + return false; + } + header.VerifyAndAllocateFragmentationHeader(nalu_idxs.size()); + for (size_t i = 0; i < nalu_idxs.size(); i++) { + header.fragmentationOffset[i] = nalu_idxs[i].payload_start_offset; + header.fragmentationLength[i] = nalu_idxs[i].payload_size; + header.fragmentationPlType[i] = 0; + header.fragmentationTimeDiff[i] = 0; + } + } +#endif callback_result = callback_->OnEncodedImage(*image, &info, &header); }