Two bug fixs in android surface render
Descritption: This CL addresses two issues in android surface view render, 1. Uninitlized class members _javaByteBufferObj and _directBuffer which could cause crash. 2. Using ConvertI420ToRGB565. We should use high level libyuv apis to help libyuv maintainer. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/566005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2185 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
ba0f9fe10b
commit
d46fe7034b
@ -12,6 +12,7 @@
|
|||||||
#include "critical_section_wrapper.h"
|
#include "critical_section_wrapper.h"
|
||||||
#include "common_video/libyuv/include/libyuv.h"
|
#include "common_video/libyuv/include/libyuv.h"
|
||||||
#include "tick_util.h"
|
#include "tick_util.h"
|
||||||
|
|
||||||
#ifdef ANDROID_NDK_8_OR_ABOVE
|
#ifdef ANDROID_NDK_8_OR_ABOVE
|
||||||
#include <android/bitmap.h>
|
#include <android/bitmap.h>
|
||||||
#endif
|
#endif
|
||||||
@ -235,6 +236,10 @@ AndroidSurfaceViewChannel::AndroidSurfaceViewChannel(
|
|||||||
_renderer(renderer),
|
_renderer(renderer),
|
||||||
_jvm(jvm),
|
_jvm(jvm),
|
||||||
_javaRenderObj(javaRenderObj),
|
_javaRenderObj(javaRenderObj),
|
||||||
|
#ifndef ANDROID_NDK_8_OR_ABOVE
|
||||||
|
_javaByteBufferObj(NULL),
|
||||||
|
_directBuffer(NULL),
|
||||||
|
#endif
|
||||||
_bitmapWidth(0),
|
_bitmapWidth(0),
|
||||||
_bitmapHeight(0) {
|
_bitmapHeight(0) {
|
||||||
}
|
}
|
||||||
@ -469,8 +474,8 @@ void AndroidSurfaceViewChannel::DeliverFrame(JNIEnv* jniEnv) {
|
|||||||
}
|
}
|
||||||
jobject javaBitmap = jniEnv->CallObjectMethod(_javaRenderObj,
|
jobject javaBitmap = jniEnv->CallObjectMethod(_javaRenderObj,
|
||||||
_createBitmapCid,
|
_createBitmapCid,
|
||||||
videoFrame.Width(),
|
_bufferToRender.Width(),
|
||||||
videoFrame.Height());
|
_bufferToRender.Height());
|
||||||
_javaBitmapObj = jniEnv->NewGlobalRef(javaBitmap);
|
_javaBitmapObj = jniEnv->NewGlobalRef(javaBitmap);
|
||||||
if (!_javaBitmapObj) {
|
if (!_javaBitmapObj) {
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not "
|
WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not "
|
||||||
@ -488,9 +493,10 @@ void AndroidSurfaceViewChannel::DeliverFrame(JNIEnv* jniEnv) {
|
|||||||
WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: Locked bitmap",
|
WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: Locked bitmap",
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
// Convert I420 straight into the Java bitmap.
|
// Convert I420 straight into the Java bitmap.
|
||||||
int ret = ConvertI420ToRGB565((unsigned char*)_bufferToRender.Buffer(),
|
int ret = ConvertFromI420((unsigned char*)_bufferToRender.Buffer(),
|
||||||
(unsigned char*) pixels,
|
_bitmapWidth, KRGB565, 0,
|
||||||
_bitmapWidth, _bitmapHeight);
|
_bitmapWidth, _bitmapHeight,
|
||||||
|
(unsigned char*) pixels);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
WEBRTC_TRACE(kTraceError,
|
WEBRTC_TRACE(kTraceError,
|
||||||
kTraceVideoRenderer,
|
kTraceVideoRenderer,
|
||||||
@ -520,6 +526,7 @@ void AndroidSurfaceViewChannel::DeliverFrame(JNIEnv* jniEnv) {
|
|||||||
_javaByteBufferObj = NULL;
|
_javaByteBufferObj = NULL;
|
||||||
_directBuffer = NULL;
|
_directBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
jobject javaByteBufferObj =
|
jobject javaByteBufferObj =
|
||||||
jniEnv->CallObjectMethod(_javaRenderObj, _createByteBufferCid,
|
jniEnv->CallObjectMethod(_javaRenderObj, _createByteBufferCid,
|
||||||
_bufferToRender.Width(),
|
_bufferToRender.Width(),
|
||||||
@ -539,11 +546,10 @@ void AndroidSurfaceViewChannel::DeliverFrame(JNIEnv* jniEnv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(_javaByteBufferObj && _bitmapWidth && _bitmapHeight) {
|
if(_javaByteBufferObj && _bitmapWidth && _bitmapHeight) {
|
||||||
// Android requires a vertically flipped image compared to std convert.
|
|
||||||
// This is done by giving a negative height input.
|
|
||||||
const int conversionResult =
|
const int conversionResult =
|
||||||
ConvertI420ToRGB565((unsigned char* )_bufferToRender.Buffer(),
|
ConvertFromI420((unsigned char* )_bufferToRender.Buffer(), _bitmapWidth,
|
||||||
_directBuffer, _bitmapWidth, -_bitmapHeight);
|
kRGB565, 0, _bitmapWidth, _bitmapHeight, _directBuffer);
|
||||||
|
|
||||||
if (conversionResult < 0) {
|
if (conversionResult < 0) {
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Color conversion"
|
WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Color conversion"
|
||||||
" failed.", __FUNCTION__);
|
" failed.", __FUNCTION__);
|
||||||
|
Loading…
Reference in New Issue
Block a user