From 109ffe9a777658936a38d0c146579a67c60a0d17 Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期四, 11 五月 2017 17:48:48 +0800
Subject: [PATCH] 

---
 RtspFace/main.cpp |  150 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 114 insertions(+), 36 deletions(-)

diff --git a/RtspFace/main.cpp b/RtspFace/main.cpp
index 2e9ae59..6e8260a 100644
--- a/RtspFace/main.cpp
+++ b/RtspFace/main.cpp
@@ -6,29 +6,41 @@
 #include "PL_AVFrameYUV420.h"
 #include "PL_AVFrameBGRA.h"
 #include "PL_Queue.h"
+#include "PL_Scale.h"
+#include "PL_Fork.h"
 
-#include "PL_SensetimeFaceDetect.h"
+#include "PL_SensetimeFaceTrack.h"
+
+#include "PL_DlibFaceTrack.h"
 
 #include "logger.h"
+#include <iostream>
+
+Logger g_logger(std::cout);
 
 int main(int argc, char** argv)
 {
-	initLogger(2);
+	g_logger.set_level(VERBOSE);
 
 	PipeLine pipeLine;
 	
-	pipeLine.register_elem_creator("PL_RTSPClient", create_PL_RTSPClient);
-	pipeLine.register_elem_creator("PL_RTSPServer", create_PL_RTSPServer);
-	pipeLine.register_elem_creator("PL_H264Decoder", create_PL_H264Decoder);
-	pipeLine.register_elem_creator("PL_AVFrameYUV420", create_PL_AVFrameYUV420);
-	pipeLine.register_elem_creator("PL_H264Encoder", create_PL_H264Encoder);
-	pipeLine.register_elem_creator("PL_Queue", create_PL_Queue);
+	PipeLine::register_global_elem_creator("PL_RTSPClient", create_PL_RTSPClient);
+	PipeLine::register_global_elem_creator("PL_RTSPServer", create_PL_RTSPServer);
+	PipeLine::register_global_elem_creator("PL_H264Decoder", create_PL_H264Decoder);
+	PipeLine::register_global_elem_creator("PL_AVFrameYUV420", create_PL_AVFrameYUV420);
+	PipeLine::register_global_elem_creator("PL_AVFrameBGRA", create_PL_AVFrameBGRA);
+	PipeLine::register_global_elem_creator("PL_H264Encoder", create_PL_H264Encoder);
+	PipeLine::register_global_elem_creator("PL_Queue", create_PL_Queue);
+	PipeLine::register_global_elem_creator("PL_Scale", create_PL_Scale);
+	PipeLine::register_global_elem_creator("PL_Fork", create_PL_Scale);
 	
-	pipeLine.register_elem_creator("PL_SensetimeFaceDetect", create_PL_SensetimeFaceDetect);
+	pipeLine.register_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack);
+	
+	pipeLine.register_elem_creator("PL_DlibFaceTrack", create_PL_DlibFaceTrack);
 	
 	{
 		PL_RTSPClient* rtspClient = (PL_RTSPClient*)pipeLine.push_elem("PL_RTSPClient");
-		RTSPConfig rtspConfig;
+		PL_RTSPClient_Config rtspConfig;
 		rtspConfig.progName = argv[0];
 		rtspConfig.rtspURL = argv[1];
 		rtspConfig.aux = true; // ffmpeg need aux, but live555 not
@@ -38,26 +50,84 @@
 		bool ret = rtspClient->init(&rtspConfig);
 		if (!ret)
 		{
-			LOG(ERROR) << "rtspClient.init error";
+			LOG_ERROR << "rtspClient.init error" << std::endl;
 			exit(EXIT_FAILURE);
 		}
 	}
 
 	{
 		PL_H264Decoder* h264Decoder = (PL_H264Decoder*)pipeLine.push_elem("PL_H264Decoder");
-		h264Decoder->init(nullptr);
+		bool ret = h264Decoder->init(nullptr);
+		if (!ret)
+		{
+			LOG_ERROR << "PL_H264Decoder.init error" << std::endl;
+			exit(EXIT_FAILURE);
+		}
 	}
 
 	{
 		PL_AVFrameYUV420* avFrameYUV420 = (PL_AVFrameYUV420*)pipeLine.push_elem("PL_AVFrameYUV420");
-		avFrameYUV420->init(nullptr);
+		bool ret = avFrameYUV420->init(nullptr);
+		if (!ret)
+		{
+			LOG_ERROR << "PL_AVFrameYUV420.init error" << std::endl;
+			exit(EXIT_FAILURE);
+		}
+	}
+	
+	{
+		PL_Scale_Config config;
+		config.toWidth = 480;
+		config.toHeight = 360;
+		PL_Scale* ple = (PL_Scale*)pipeLine.push_elem("PL_Scale");
+		bool ret = ple->init(&config);
+		if (!ret)
+		{
+			LOG_ERROR << "PL_Scale.init error" << std::endl;
+			exit(EXIT_FAILURE);
+		}
+	}
+	
+	{
+		PL_AVFrameBGRA_Config config;
+		config.convertTo = PL_AVFrameBGRA_Config::I420_TO_RGBA8888;
+		PL_AVFrameBGRA* ple = (PL_AVFrameBGRA*)pipeLine.push_elem("PL_AVFrameBGRA");
+		bool ret = ple->init(&config);
+		if (!ret)
+		{
+			LOG_ERROR << "PL_AVFrameBGRA.init error" << std::endl;
+			exit(EXIT_FAILURE);
+		}
 	}
 
-	{
-		SensetimeFaceDetectConfig config;
-		PL_SensetimeFaceDetect* stFaceDetect = (PL_SensetimeFaceDetect*)pipeLine.push_elem("PL_SensetimeFaceDetect");
-		stFaceDetect->init(&config);
-	}
+	//{
+	//	SensetimeFaceTrackConfig config;
+	//	//config.generate_face_feature = true;
+	//	PL_SensetimeFaceTrack* ple = (PL_SensetimeFaceTrack*)pipeLine.push_elem("PL_SensetimeFaceTrack");
+	//	ple->init(&config);
+	//}
+	
+	//PipeLine pipeLine2;
+	//{
+	//	PL_Fork_Config config;
+	//	config.forkBy = PL_Fork::FB_MB_TYPE;
+	//	config.forkSync = PL_Fork::FS_PARALLEL;
+	//	PL_Fork* ple = (PL_Fork*)pipeLine.push_elem("PL_Fork");
+	//	ple->init(&config);
+	//	ple->attach_pipe_line(&pipeLine2);
+	//	
+	//	{
+	//		//pipeLine2.push_elem();
+	//	}
+	//}
+	
+	//{
+	//	PL_DlibFaceTrack_Config config;
+	//	config.pyramid_down_layers = 2;
+	//	config.pyramid_down_n = 1;
+	//	PL_DlibFaceTrack* ple = (PL_DlibFaceTrack*)pipeLine.push_elem("PL_DlibFaceTrack");
+	//	ple->init(&config);
+	//}
 
 	//{//#todo queue should support deep copy
 	//	PL_Queue_Config config;
@@ -65,31 +135,39 @@
 	//	bool ret = queue1->init(&config);
 	//	if (!ret)
 	//	{
-	//		LOG(ERROR) << "queue1.init error";
+	//		LOG_ERROR << "queue1.init error" << std::endl;
 	//		exit(EXIT_FAILURE);
 	//	}
 	//}
 
-	{
-		PL_H264Encoder* h264Encoder = (PL_H264Encoder*)pipeLine.push_elem("PL_H264Encoder");
-		h264Encoder->init(nullptr);
-	}
-	
-	{
-		RTSPServerConfig config;
-		PL_RTSPServer* rtspServer = (PL_RTSPServer*)pipeLine.push_elem("PL_RTSPServer");
-		bool ret = rtspServer->init(&config);
-		if (!ret)
-		{
-			LOG(ERROR) << "rtspServer.init error";
-			exit(EXIT_FAILURE);
-		}
-	}
+	//{
+	//	PL_H264Encoder_Config config;
+	//	config.av_opt_preset = "superfast";
+	//	config.av_opt_tune = "zerolatency";
+	//	config.avc_profile_str = "baseline";
+	//	PL_H264Encoder* h264Encoder = (PL_H264Encoder*)pipeLine.push_elem("PL_H264Encoder");
+	//	bool ret = h264Encoder->init(&config);
+	//	if (!ret)
+	//	{
+	//		LOG_ERROR << "PL_H264Encoder.init error" << std::endl;
+	//		exit(EXIT_FAILURE);
+	//	}
+	//}
+    //
+	//{
+	//	PL_RTSPServer* rtspServer = (PL_RTSPServer*)pipeLine.push_elem("PL_RTSPServer");
+	//	bool ret = rtspServer->init(nullptr);
+	//	if (!ret)
+	//	{
+	//		LOG_ERROR << "rtspServer.init error" << std::endl;
+	//		exit(EXIT_FAILURE);
+	//	}
+	//}
 	
 	while(true)
 	{
-		//LOG(ERROR) << "begin pipe";
+		//LOG_ERROR << "begin pipe" << std::endl;
 		pipeLine.pipe();
-		//LOG(ERROR) << "end pipe";
+		//LOG_ERROR << "end pipe" << std::endl;
 	}
 }

--
Gitblit v1.8.0