diff --git a/src/modules/video_render/main/source/Android/video_render_android_surface_view.cc b/src/modules/video_render/main/source/Android/video_render_android_surface_view.cc index 7e61260d5..253d831ee 100644 --- a/src/modules/video_render/main/source/Android/video_render_android_surface_view.cc +++ b/src/modules/video_render/main/source/Android/video_render_android_surface_view.cc @@ -365,102 +365,106 @@ WebRtc_Word32 AndroidSurfaceViewChannel::RenderFrame(const WebRtc_UWord32 /*stre /*Implements AndroidStream * Calls the Java object and render the buffer in _bufferToRender */ -void AndroidSurfaceViewChannel::DeliverFrame(JNIEnv* jniEnv) -{ - _renderCritSect.Enter(); -// TickTime timeNow=TickTime::Now(); - +void AndroidSurfaceViewChannel::DeliverFrame(JNIEnv* jniEnv) { + _renderCritSect.Enter(); #ifdef ANDROID_NDK_8_OR_ABOVE - if(_bitmapWidth!=_bufferToRender.Width() || _bitmapHeight!=_bufferToRender.Height()) - { - - // Create the bitmap to write to - WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: Creating bitmap %u %u", __FUNCTION__,_bufferToRender.Width(),_bufferToRender.Height()); - if(_javaBitmapObj) - { - jniEnv->DeleteGlobalRef(_javaBitmapObj); - _javaBitmapObj=NULL; - } - jobject javaBitmap=jniEnv->CallObjectMethod(_javaRenderObj,_createBitmapCid,videoFrame.Width(),videoFrame.Height()); - _javaBitmapObj = jniEnv->NewGlobalRef(javaBitmap); - if (!_javaBitmapObj) - { - WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not create Java Bitmap object reference", __FUNCTION__); - _renderCritSect.Leave(); - return; - } - else - { - _bitmapWidth=_bufferToRender.Width(); - _bitmapHeight=_bufferToRender.Height(); - } - } - void* pixels; - if (_javaBitmapObj && AndroidBitmap_lockPixels(jniEnv, _javaBitmapObj, &pixels) >= 0) - { - WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: Locked bitmap", __FUNCTION__); - // Convert I420 straight into the Java bitmap. - const int conversionResult=ConvertI420ToRGB565( (unsigned char* )_bufferToRender.Buffer(), (unsigned char* ) pixels, _bitmapWidth, _bitmapHeight); - if(conversionResult<0) - { - WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Color conversion failed.", __FUNCTION__); - } - - AndroidBitmap_unlockPixels(jniEnv, _javaBitmapObj); - - //Draw the Surface - jniEnv->CallVoidMethod(_javaRenderObj,_drawCid); - + if (_bitmapWidth != _bufferToRender.Width() || + _bitmapHeight != _bufferToRender.Height()) { + // Create the bitmap to write to + WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: Creating bitmap %u " + "%u", __FUNCTION__, _bufferToRender.Width(), + _bufferToRender.Height()); + if (_javaBitmapObj) { + jniEnv->DeleteGlobalRef(_javaBitmapObj); + _javaBitmapObj = NULL; } - else - { - WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Could not lock bitmap", __FUNCTION__); + jobject javaBitmap = jniEnv->CallObjectMethod(_javaRenderObj, + _createBitmapCid, + videoFrame.Width(), + videoFrame.Height()); + _javaBitmapObj = jniEnv->NewGlobalRef(javaBitmap); + if (!_javaBitmapObj) { + WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not " + "create Java Bitmap object reference", __FUNCTION__); + _renderCritSect.Leave(); + return; + } else { + _bitmapWidth=_bufferToRender.Width(); + _bitmapHeight=_bufferToRender.Height(); } - _renderCritSect.Leave(); + } + void* pixels; + if (_javaBitmapObj && + AndroidBitmap_lockPixels(jniEnv, _javaBitmapObj, &pixels) >= 0) { + WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: Locked bitmap", + __FUNCTION__); + // Convert I420 straight into the Java bitmap. + int ret = ConvertI420ToRGB565((unsigned char* )_bufferToRender.Buffer(), + (unsigned char* ) pixels, + _bitmapWidth, _bitmapHeight); + if (ret < 0) { + WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Color conversion " + "failed.", __FUNCTION__); + } + + AndroidBitmap_unlockPixels(jniEnv, _javaBitmapObj); + // Draw the Surface. + jniEnv->CallVoidMethod(_javaRenderObj,_drawCid); + + } else { + WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Could not lock " + "bitmap", __FUNCTION__); + } + _renderCritSect.Leave(); #else - if(_bitmapWidth!=_bufferToRender.Width() || _bitmapHeight!=_bufferToRender.Height()) - { - WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer,_id, "%s: New render size %d %d",__FUNCTION__, _bufferToRender.Width(), _bufferToRender.Height()); - if(_javaByteBufferObj) - { - jniEnv->DeleteGlobalRef(_javaByteBufferObj); - _javaByteBufferObj=NULL; - _directBuffer=NULL; - } - jobject javaByteBufferObj=jniEnv->CallObjectMethod(_javaRenderObj,_createByteBufferCid,_bufferToRender.Width(),_bufferToRender.Height()); - _javaByteBufferObj = jniEnv->NewGlobalRef(javaByteBufferObj); - if (!_javaByteBufferObj) - { - WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not create Java ByteBuffer object reference", __FUNCTION__); - _renderCritSect.Leave(); - return; - } - else - { - _directBuffer=(unsigned char*) jniEnv->GetDirectBufferAddress(_javaByteBufferObj); - _bitmapWidth=_bufferToRender.Width(); - _bitmapHeight=_bufferToRender.Height(); - } - } + if (_bitmapWidth != _bufferToRender.Width() || + _bitmapHeight != _bufferToRender.Height()) { + WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer, _id, "%s: New render size %d " + "%d",__FUNCTION__, + _bufferToRender.Width(), _bufferToRender.Height()); + if (_javaByteBufferObj) { + jniEnv->DeleteGlobalRef(_javaByteBufferObj); + _javaByteBufferObj = NULL; + _directBuffer = NULL; + } + jobject javaByteBufferObj = + jniEnv->CallObjectMethod(_javaRenderObj, _createByteBufferCid, + _bufferToRender.Width(), + _bufferToRender.Height()); + _javaByteBufferObj = jniEnv->NewGlobalRef(javaByteBufferObj); + if (!_javaByteBufferObj) { + WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: could not " + "create Java ByteBuffer object reference", __FUNCTION__); + _renderCritSect.Leave(); + return; + } else { + _directBuffer = static_cast + (jniEnv->GetDirectBufferAddress(_javaByteBufferObj)); + _bitmapWidth = _bufferToRender.Width(); + _bitmapHeight = _bufferToRender.Height(); + } + } - if(_javaByteBufferObj && _bitmapWidth && _bitmapHeight) - { - const int conversionResult=ConvertI420ToRGB565Android((unsigned char* )_bufferToRender.Buffer(), _directBuffer, _bitmapWidth, _bitmapHeight); - if(conversionResult<0) - { - WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Color conversion failed.", __FUNCTION__); - _renderCritSect.Leave(); - return; - } - } - _renderCritSect.Leave(); - //Draw the Surface - jniEnv->CallVoidMethod(_javaRenderObj,_drawByteBufferCid); + 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 = + ConvertI420ToRGB565((unsigned char* )_bufferToRender.Buffer(), + _directBuffer, _bitmapWidth, -_bitmapHeight); + if (conversionResult < 0) { + WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, _id, "%s: Color conversion" + " failed.", __FUNCTION__); + _renderCritSect.Leave(); + return; + } + } + _renderCritSect.Leave(); + // Draw the Surface + jniEnv->CallVoidMethod(_javaRenderObj, _drawByteBufferCid); #endif - //WEBRTC_TRACE(kTraceInfo, kTraceVideoRenderer,_id, "%s: time to deliver %lld" ,__FUNCTION__,(TickTime::Now()-timeNow).Milliseconds()); } -} //namespace webrtc +} // namespace webrtc diff --git a/src/modules/video_render/main/source/linux/video_x11_channel.cc b/src/modules/video_render/main/source/linux/video_x11_channel.cc index 84686f826..027275ce5 100644 --- a/src/modules/video_render/main/source/linux/video_x11_channel.cc +++ b/src/modules/video_render/main/source/linux/video_x11_channel.cc @@ -93,8 +93,8 @@ WebRtc_Word32 VideoX11Channel::DeliverFrame(unsigned char* buffer, } unsigned char *pBuf = buffer; - // convert to RGB32 - ConvertI420ToARGB(pBuf, _buffer, _width, _height, 0); + // convert to RGB32, setting stride = width. + ConvertFromI420(pBuf, _width, kARGB, 0, _width, _height, _buffer); // put image in window XShmPutImage(_display, _window, _gc, _image, 0, 0, _xPos, _yPos, _width, diff --git a/src/modules/video_render/main/source/mac/video_render_agl.cc b/src/modules/video_render/main/source/mac/video_render_agl.cc index 387cd238e..e968865ff 100644 --- a/src/modules/video_render/main/source/mac/video_render_agl.cc +++ b/src/modules/video_render/main/source/mac/video_render_agl.cc @@ -236,7 +236,9 @@ int VideoChannelAGL::DeliverFrame(unsigned char* buffer, int bufferSize, unsigne return -1; } - int rgbret = ConvertI420ToRGBAMac((WebRtc_UWord8*)buffer, (WebRtc_UWord8*)_buffer, (WebRtc_Word32)_width, (WebRtc_Word32)_height, 0); + // Setting stride = width. + int rgbret = ConvertFromYV12(buffer, _width, kBGRA, 0, _width, _height, + _buffer); if (rgbret < 0) { _owner->UnlockAGLCntx(); diff --git a/src/modules/video_render/main/source/mac/video_render_nsopengl.mm b/src/modules/video_render/main/source/mac/video_render_nsopengl.mm index 437bac5d2..5663010ee 100644 --- a/src/modules/video_render/main/source/mac/video_render_nsopengl.mm +++ b/src/modules/video_render/main/source/mac/video_render_nsopengl.mm @@ -232,8 +232,10 @@ int VideoChannelNSOpenGL::DeliverFrame(unsigned char* buffer, int bufferSize, un return -1; } - int rgbLength = ConvertI420ToRGBAMac(buffer, _buffer, _width, _height, 0); - if (rgbLength == -1) + int rgbRet = ConvertFromYV12(buffer, _width, + kBGRA, 0, _width, _height, + _buffer); + if (rgbRet < 0) { _owner->UnlockAGLCntx(); return -1; diff --git a/src/modules/video_render/main/source/windows/video_render_direct3d9.cc b/src/modules/video_render/main/source/windows/video_render_direct3d9.cc index e32b25703..00bc41b6b 100644 --- a/src/modules/video_render/main/source/windows/video_render_direct3d9.cc +++ b/src/modules/video_render/main/source/windows/video_render_direct3d9.cc @@ -200,7 +200,7 @@ int D3D9Channel::DeliverFrame(unsigned char* buffer, } UCHAR* pRect = (UCHAR*) lr.pBits; - ConvertI420ToARGB(buffer, pRect, _width, _height, 0); + ConvertFromI420(buffer, _width, kARGB, 0, _width, _height, pRect); if (FAILED(_pTexture->UnlockRect(0))) { diff --git a/src/modules/video_render/main/source/windows/video_render_directdraw.cc b/src/modules/video_render/main/source/windows/video_render_directdraw.cc index f1427e75a..854b58efe 100644 --- a/src/modules/video_render/main/source/windows/video_render_directdraw.cc +++ b/src/modules/video_render/main/source/windows/video_render_directdraw.cc @@ -996,26 +996,20 @@ int DirectDrawChannel::DeliverFrame(unsigned char* buffer, int bufferSize, switch (_blitVideoType) { case kYUY2: - ConvertI420ToYUY2(buffer, ptr, _width, _height, - ddsd.lPitch); - break; case kUYVY: - ConvertI420ToUYVY(buffer, ptr, _width, _height, - ddsd.lPitch); - break; - case kIYUV: // same as kYV12 + case kIYUV: // same as kYV12 case kYV12: - ConvertI420ToYV12(buffer, ptr, _width, _height, - ddsd.lPitch); + ConvertFromI420(buffer, _width, + _blitVideoType, 0, + _width, _height, + ptr); break; case kRGB24: { _tempRenderBuffer.VerifyAndAllocate(_width * _height * 3); - //unsigned char *ptrTempBuffer=_tempRenderBuffer.GetBuffer(); unsigned char *ptrTempBuffer = _tempRenderBuffer.Buffer(); - //ConvertI420ToRGB24(buffer ,(int*) ptrTempBuffer, _width, _height); - ConvertI420ToRGB24(buffer, ptrTempBuffer, _width, - _height); + ConvertFromI420(buffer, _width, kRGB24, 0, _width, _height, + ptrTempBuffer); for (int i = 0; i < _height; i++) { memcpy(ptr, ptrTempBuffer, _width * 3); @@ -1025,25 +1019,22 @@ int DirectDrawChannel::DeliverFrame(unsigned char* buffer, int bufferSize, break; } case kARGB: - ConvertI420ToARGB(buffer, ptr, _width, _height, - (ddsd.lPitch >> 2) - _width); + ConvertFromI420(buffer, ddsd.lPitch, kARGB, 0, + _width, _height, ptrTempBuffer); break; case kARGB4444: ConvertI420ToARGB4444(buffer, ptr, _width, _height, - (ddsd.lPitch >> 1) - _width); + (ddsd.lPitch >> 1) - _width); break; case kARGB1555: ConvertI420ToARGB1555(buffer, ptr, _width, _height, - (ddsd.lPitch >> 1) - _width); + (ddsd.lPitch >> 1) - _width); break; case kRGB565: { _tempRenderBuffer.VerifyAndAllocate(_width * _height * 2); - //unsigned char *ptrTempBuffer=_tempRenderBuffer.GetBuffer(); unsigned char *ptrTempBuffer = _tempRenderBuffer.Buffer(); - //ConvertI420ToRGB565(buffer ,(int*) ptrTempBuffer, _width, _height); - ConvertI420ToRGB565(buffer, ptrTempBuffer, _width, - _height); + ConvertI420ToRGB565(buffer, ptrTempBuffer, _width, _height); ptr += ddsd.lPitch * (_height - 1); for (int i = 0; i < _height; i++) {