| 381 | } |
| 382 | |
| 383 | int MediaCodec_Decoder::getOutput(int index, mc_out *out, bool readBuffer) { |
| 384 | JniEnv jniEnv{}; |
| 385 | |
| 386 | JNIEnv *env = jniEnv.getEnv(); |
| 387 | if (env == nullptr) { |
| 388 | return MC_ERROR; |
| 389 | } |
| 390 | |
| 391 | if (mMediaCodec == nullptr) { |
| 392 | return MC_ERROR; |
| 393 | } |
| 394 | |
| 395 | OutputBufferInfo outputBufferInfo{}; |
| 396 | |
| 397 | jobject outputInfo = env->CallObjectMethod(mMediaCodec, jMediaCodec_getOutputBufferInfo, |
| 398 | (jint) index); |
| 399 | if (outputInfo != nullptr) { |
| 400 | OutputBufferInfo::convert(env, &outputBufferInfo, outputInfo); |
| 401 | env->DeleteLocalRef(outputInfo); |
| 402 | } |
| 403 | |
| 404 | if (index >= 0) { |
| 405 | out->type = outputBufferInfo.type; |
| 406 | out->b_eos = outputBufferInfo.eos; |
| 407 | out->buf.index = outputBufferInfo.index; |
| 408 | out->buf.pts = outputBufferInfo.pts; |
| 409 | |
| 410 | if (readBuffer) { |
| 411 | jobject bufferInfo = env->CallObjectMethod(mMediaCodec, jMediaCodec_getOutBuffer, |
| 412 | (jint) index); |
| 413 | if (bufferInfo != nullptr) { |
| 414 | auto *ptr = (uint8_t *) env->GetDirectBufferAddress(bufferInfo); |
| 415 | int offset = outputBufferInfo.bufferOffset; |
| 416 | out->buf.p_ptr = ptr + offset; |
| 417 | out->buf.size = outputBufferInfo.bufferSize; |
| 418 | |
| 419 | env->DeleteLocalRef(bufferInfo); |
| 420 | } |
| 421 | } else { |
| 422 | out->buf.p_ptr = nullptr; |
| 423 | out->buf.size = 0; |
| 424 | } |
| 425 | |
| 426 | } else if (index == MC_INFO_OUTPUT_FORMAT_CHANGED) { |
| 427 | out->type = outputBufferInfo.type; |
| 428 | out->b_eos = outputBufferInfo.eos; |
| 429 | |
| 430 | if (mCodecCategory == CATEGORY_VIDEO) { |
| 431 | out->conf.video.width = outputBufferInfo.videoWidth; |
| 432 | out->conf.video.height = outputBufferInfo.videoHeight; |
| 433 | out->conf.video.stride = outputBufferInfo.videoStride; |
| 434 | out->conf.video.slice_height = outputBufferInfo.videoSliceHeight; |
| 435 | out->conf.video.pixel_format = outputBufferInfo.videoPixelFormat; |
| 436 | out->conf.video.crop_left = outputBufferInfo.videoCropLeft; |
| 437 | out->conf.video.crop_top = outputBufferInfo.videoCropTop; |
| 438 | out->conf.video.crop_right = outputBufferInfo.videoCropRight; |
| 439 | out->conf.video.crop_bottom = outputBufferInfo.videoCropBottom; |
| 440 | } else { |
no test coverage detected