From 0367d8e503ca5df1eae359929b8753050ccd9980 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期三, 17 七月 2019 13:37:26 +0800
Subject: [PATCH] 增加国标28181的处理

---
 csrc/wrapper.cpp |   61 +++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp
index ead51a0..9b4a88a 100644
--- a/csrc/wrapper.cpp
+++ b/csrc/wrapper.cpp
@@ -84,11 +84,13 @@
                 auto dec_ctx = in->getCodecContext();
                 if(bridge_)delete bridge_;
 
+                scale_w_ = scale_w_ == 0 || scale_w_ > dec_ctx->width ? dec_ctx->width : scale_w_;
+                scale_h_ = scale_h_ == 0 || scale_h_ > dec_ctx->height ? dec_ctx->height : scale_h_;
+
                 AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24;
                 bridge_ = new cvbridge(
                         dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
-                        scale_w_?scale_w_:dec_ctx->width, scale_h_?scale_h_:dec_ctx->height, pix_fmt,
-                        scale_f_);
+                        scale_w_, scale_h_, pix_fmt, scale_f_);
     
             }
             if (!flag){
@@ -100,6 +102,50 @@
 
         return nullptr;
     }
+
+    ffwrapper::FormatIn* Wrapper::init_reader_gb28181(const char* input){
+
+            VideoProp prop;
+            prop.url_ = input;
+            prop.rtsp_tcp_ = true;
+
+//        	std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl()));
+            ffwrapper::FormatIn* in(new FormatIn(prop.gpuAccl()));
+        	AVDictionary *avdic = prop.optsFormat();
+        	int flag = in->openGb28181(input, &avdic);
+        	if(avdic){
+                logIt("ERROR:in->openGb28181(input, &avdic):flag:%d\n",flag);
+        		av_dict_free(&avdic);
+        	}
+            if(flag == 0){
+                if(!in->findStreamInfo(NULL)){
+                    logIt("yolo can't find video stream\n");
+                    return nullptr;
+                }
+                bool flag = true;
+                if(map_workers_.find(WORKER_DECODER) != map_workers_.end()){
+                    flag = in->openCodec(AVMEDIA_TYPE_VIDEO, NULL);
+                    auto dec_ctx = in->getCodecContext();
+                    if(bridge_)delete bridge_;
+
+                    scale_w_ = scale_w_ == 0 || scale_w_ > dec_ctx->width ? dec_ctx->width : scale_w_;
+                    scale_h_ = scale_h_ == 0 || scale_h_ > dec_ctx->height ? dec_ctx->height : scale_h_;
+
+                    AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24;
+                    bridge_ = new cvbridge(
+                            dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
+                            scale_w_, scale_h_, pix_fmt, scale_f_);
+
+                }
+                if (!flag){
+                    logIt("FormatIn openCodec Failed!");
+                    return nullptr;
+                }
+                return in;
+            }
+
+            return nullptr;
+        }
 
     int Wrapper::init_recorder(FormatIn *in, std::string dir, const int mind, const int maxd){
         if(!in){
@@ -135,8 +181,10 @@
 
     void Wrapper::run_stream_thread(){
         while(!stop_stream_.load()){
-            auto in = init_reader(input_url_.c_str());
+            //auto in = init_reader(input_url_.c_str());
+            ffwrapper::FormatIn * in = init_reader_gb28181(input_url_.c_str());
             if (!in) {
+                logIt("ERROR: init_reader_gb28181!\n");
                 usleep(200000);
                 continue;
             }
@@ -235,11 +283,12 @@
         pic_bgr24 pic;
         if(bridge_){
             AVFrame *frm = frame->getAVFrame();
-            unsigned char *data = (unsigned char*)malloc(frm->width * frm->height * 3);
+            pic.w = scale_w_;
+            pic.h = scale_h_;
+
+            unsigned char *data = (unsigned char*)malloc(pic.w * pic.h * 3);
             bridge_->copyPicture(data, frm);
             pic.data = data;
-            pic.w = scale_w_ ? scale_w_ : frm->width;
-            pic.h = scale_h_ ? scale_h_ : frm->height;
         }
         if(func_dec_){
             func_dec_(pic.data, pic.w, pic.h);

--
Gitblit v1.8.0