From 9e5babf9db52e64bdae60137be7696e56241fca6 Mon Sep 17 00:00:00 2001
From: xingzilong <xingzilong@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期五, 18 八月 2017 18:12:17 +0800
Subject: [PATCH] H264 NALU解析  并在RTSPServer判断

---
 RtspFace/PL_AndroidSurfaceViewRender.cpp |   90 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 70 insertions(+), 20 deletions(-)

diff --git a/RtspFace/PL_AndroidSurfaceViewRender.cpp b/RtspFace/PL_AndroidSurfaceViewRender.cpp
index 3336a15..16a453a 100644
--- a/RtspFace/PL_AndroidSurfaceViewRender.cpp
+++ b/RtspFace/PL_AndroidSurfaceViewRender.cpp
@@ -130,6 +130,9 @@
 
 bool convert_yuv420_origin_to_render(PL_ASVR_Internal* in)
 {
+	if (in->config.directlyDisplay)
+		return true;
+
     int src_width = in->lastMbfBuffOrigin.width;
     int src_height = in->lastMbfBuffOrigin.height;
     const uint8_t* src_y = (const uint8_t*)(in->lastMbfBuffOrigin.buffer);
@@ -251,6 +254,9 @@
 
 bool convert_nv12_origin_to_render(PL_ASVR_Internal* in)
 {
+	if (in->config.directlyDisplay)
+		return true;
+
     if (false)
     {//#test test nv12 on yuv420 frame
         const int src_width = in->lastMbfBuffOrigin.width;
@@ -310,10 +316,10 @@
                           dst_width, dst_height,
                           libyuv::kFilterNone);
 
-        libyuv::ScalePlane_16((uint16*)src_uv, MH_SUBSAMPLE1(src_width ,2),
-                              MH_SUBSAMPLE1(src_width ,2), src_height,
-                              (uint16*)dst_uv, MH_SUBSAMPLE1(dst_width ,2),
-                              MH_SUBSAMPLE1(dst_width, 2), dst_height,
+        libyuv::ScalePlane_16((uint16*)src_uv, MH_SUBSAMPLE1(src_width, 2),
+                              MH_SUBSAMPLE1(src_width, 2), MH_SUBSAMPLE1(src_height, 2),
+                              (uint16*)dst_uv, MH_SUBSAMPLE1(dst_width, 2),
+                              MH_SUBSAMPLE1(dst_width, 2), MH_SUBSAMPLE1(dst_height, 2),
                               libyuv::kFilterNone);
 
         in->buff1Size = dst_width * dst_height * 1.5;
@@ -382,6 +388,42 @@
     return true;
 }
 
+bool convert_rgb565_origin_to_render(PL_ASVR_Internal *in)
+{
+	if (in->config.directlyDisplay)
+		return true;
+
+	ANativeWindow* window = (ANativeWindow*)(in->config.windowSurface);
+	int src_width = in->lastMbfBuffOrigin.width;
+	int src_height = in->lastMbfBuffOrigin.height;
+
+	const int dst_width = (in->config.scaleToWidth <= 0 ? in->nativeWindowStride : in->config.scaleToWidth);
+	const int dst_height = (in->config.scaleToHeight <= 0 ? in->nativeWindowHeight : in->config.scaleToHeight);
+
+	if (src_width != dst_width || src_height != dst_height)
+	{
+		uint8_t* src = (uint8_t*)in->lastMbfBuffOrigin.buffer;
+		uint8_t* dst = (uint8_t*)in->buffer1;
+		libyuv::ScalePlane_16((uint16*)src, src_width,
+							  src_width, src_height,
+							  (uint16*)dst, dst_width,
+							  dst_width, dst_height,
+							  libyuv::kFilterNone);
+		in->buff1Size = dst_width * dst_height * 2;
+		memcpy(in->buffer, in->buffer1, in->buff1Size);
+		in->buffSize = in->buff1Size;
+	}
+	else
+	{
+		if (!in->config.directlyDisplay)
+		{
+			memcpy(in->buffer, in->lastMbfBuffOrigin.buffer, in->lastMbfBuffOrigin.buffSize);
+			in->buffSize = in->lastMbfBuffOrigin.buffSize;
+		}
+	}
+	return true;
+}
+
 bool render_surface(PL_ASVR_Internal* in)
 {
 	ANativeWindow* window = (ANativeWindow*)(in->config.windowSurface);
@@ -395,18 +437,23 @@
 			bitsSize = buffer.stride * buffer.height * 2;
 		else
 			bitsSize = buffer.stride * buffer.height;
-		
-		if (bitsSize > in->buffSize)
+
+		if (in->config.directlyDisplay)
+			memcpy(buffer.bits, in->lastMbfBuffOrigin.buffer,  bitsSize);
+		else
 		{
-			LOG_WARN << "surface buffer truncated" << LOG_ENDL;
-			bitsSize = in->buffSize;
-		}
-		else if (bitsSize < in->buffSize)
-		{
-			LOG_WARN << "in buffer truncated" << LOG_ENDL;
+			if (bitsSize > in->buffSize)
+			{
+				LOG_WARN << "surface buffer truncated" << LOG_ENDL;
+				bitsSize = in->buffSize;
+			}
+			else if (bitsSize < in->buffSize)
+			{
+				LOG_WARN << "in buffer truncated" << LOG_ENDL;
+			}
+			memcpy(buffer.bits, in->buffer, bitsSize);
 		}
 
-		memcpy(buffer.bits, in->buffer,  bitsSize);
 		ANativeWindow_unlockAndPost(window);
 	}
     else
@@ -432,9 +479,9 @@
 		return false;
 	
 	MB_Frame* frame = (MB_Frame*)pm->buffer;
-	if (frame->type != MB_Frame::MBFT_YUV420 && frame->type != MB_Frame::MBFT_NV12)
+	if (frame->type != MB_Frame::MBFT_YUV420 && frame->type != MB_Frame::MBFT_NV12 && frame->type != MB_Frame::MBFT_RGB565)
 	{
-		LOG_ERROR << "Only support MBFT_YUV420 and MBFT_NV12" << LOG_ENDL;
+		LOG_ERROR << "Only support MBFT_YUV420 銆丮BFT_NV12 and MBFT_RGB565" << LOG_ENDL;
 		in->payError = true;
 		return false;
 	}
@@ -456,7 +503,8 @@
         ret = convert_yuv420_origin_to_render(in);
     else if (in->lastMbfBuffOrigin.type == MB_Frame::MBFT_NV12)
         ret = convert_nv12_origin_to_render(in);
-
+	else if (in->lastMbfBuffOrigin.type == MB_Frame::MBFT_RGB565)
+		ret = convert_rgb565_origin_to_render(in);
     if (!ret)
 	{
 		LOG_ERROR << "convert yuv origin to render error" << LOG_ENDL;
@@ -484,12 +532,13 @@
     if (in->payError)
         pm.breake(PipeMaterial::PMT_FRAME_LIST, MB_Frame::MBFT_YUV420, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
     if (in->payError)
-        pm.breake(PipeMaterial::PMT_FRAME_LIST, MB_Frame::MBFT_NV12, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
-    if (in->payError)
-        pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_YUV420, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
+		pm.breake(PipeMaterial::PMT_FRAME_LIST, MB_Frame::MBFT_NV12, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
+	if (in->payError)
+		pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_YUV420, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
 	if (in->payError)
 		pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_NV12, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
-
+	if (in->payError)
+		pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_RGB565, PL_AndroidSurfaceViewRender::pay_breaker_MBFT_YUV, in);
 	return !(in->payError);
 }
 
@@ -528,3 +577,4 @@
 
 	return true;
 }
+

--
Gitblit v1.8.0