Browse Source

change driver_h264_enc. for change frame bitrate.

yuchuli 2 months ago
parent
commit
69d429ef47

+ 4 - 2
src/driver/driver_h264_enc/driver_h264_enc.pro

@@ -32,7 +32,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
 
 
 SOURCES += main.cpp \
-    ../../include/msgtype/rawpic.pb.cc
+    ../../include/msgtype/rawpic.pb.cc \
+    ../../include/msgtype/remotectrl.pb.cc
 
 
 #DEFINES += USE_QSV
@@ -61,4 +62,5 @@ LIBS +=  -lavcodec -lavformat -lavutil
 
 
 HEADERS += \
-    ../../include/msgtype/rawpic.pb.h
+    ../../include/msgtype/rawpic.pb.h \
+    ../../include/msgtype/remotectrl.pb.h

+ 3 - 1
src/driver/driver_h264_enc/driver_h264_enc.xml

@@ -1,9 +1,11 @@
 <xml>	
 	<node name="driver_camera_ioctl">
-		<param name="picname" value="picfront" />
+		<param name="picname" value="image00" />
 		<param name="h264name" value="h264front" />
 		<param name="width" value = "1920" />
 		<param name="height" value="1080" />
 		<param name="framerate" value="4000000" />
+		<param name="campos" value="front" />
+		<param name="remotectrlframerate" value="true" />
 	</node>
 </xml>

+ 55 - 6
src/driver/driver_h264_enc/main.cpp

@@ -35,6 +35,7 @@ extern "C"
 #include <opencv2/imgproc/types_c.h>
 
 #include "rawpic.pb.h"
+#include "remotectrl.pb.h"
 
 bool gbNewData = false;
 #include <QWaitCondition>
@@ -59,6 +60,12 @@ static char * gstrwidth ="1280";
 static char * gstrheight = "720";
 int gnwidth,gnheight;
 int gnframerate = 4000000;
+int gnframeratenow = 4000000;
+bool gbremotectrlframerate = true;
+int gnremotestate = 900;  //if 30 seconds no  remote message,gnframerate_percent = 1
+
+int gnframerate_percent = 100;
+std::string gstr_campos = "front";
 
 void * gpaout;
 
@@ -185,7 +192,7 @@ RESTART:
 
 
          /* put sample parameters */
-         c->bit_rate = gnframerate;
+         c->bit_rate = gnframeratenow;
          /* resolution must be a multiple of two */
          c->width = gnwidth;
          c->height = gnheight;
@@ -269,17 +276,24 @@ RESTART:
         }
         else
         {
-            static int ntest = 0;  //test  change framerate.
- //           ntest++;
-            int64_t new_bitrate = 4000000;
-            if(ntest > 300)
+
+            if(gbremotectrlframerate)
+            {
+                if(gnremotestate>0)gnremotestate--;
+            }
+            if(gnremotestate == 0)
             {
+                gnframerate_percent = 1;
+            }
+
+            if((gnframerate * gnframerate_percent/100 )  != gnframeratenow)
+            {
+                gnframeratenow = gnframerate * gnframerate_percent /100;
                 av_frame_free(&frame);
                 avcodec_free_context(&c);
                 av_packet_free(&pkt);
                 // 关闭原编码器
                 avcodec_close(c);
-                gnframerate = new_bitrate;
                 goto RESTART;
             }
 
@@ -385,6 +399,41 @@ int main(int argc, char *argv[])
     std::string strwidth = xp.GetParam("width",std::string("1920"));
     std::string strheight = xp.GetParam("height",std::string("1080"));
     gnframerate = xp.GetParam("framerate",4000000);
+    gnframeratenow = gnframerate;
+
+    bool bremotectrlframerate = xp.GetParam("remotectrlframerate",true);
+    gbremotectrlframerate = bremotectrlframerate;
+    std::string strcampos = xp.GetParam("campos","unknown");
+    gstr_campos =  strcampos;
+    if(bremotectrlframerate)
+    {
+
+        void * premote = iv::modulecomm::RegisterRecv("remotectrl",[](const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname){
+            (void)strdata;(void)nSize;(void)index;(void)dt;(void)strmemname;
+            gnremotestate = 900;
+            iv::remotectrl xremotectrl;
+            if(xremotectrl.ParseFromArray(strdata,nSize))
+            {
+                if(xremotectrl.has_frame_percent_separate())
+                {
+                    if(xremotectrl.frame_percent_separate())
+                    {
+                        if(gstr_campos == std::string("front"))gnframerate_percent = xremotectrl.frame_percent_front();
+                        if(gstr_campos == std::string("rear"))gnframerate_percent = xremotectrl.frame_percent_rear();
+                        if(gstr_campos == std::string("left"))gnframerate_percent = xremotectrl.frame_percent_left();
+                        if(gstr_campos == std::string("right"))gnframerate_percent = xremotectrl.frame_percent_right();
+                    }
+                    else
+                    {
+                        gnframerate_percent = xremotectrl.frame_percent();
+                    }
+                }
+            }
+        });
+
+        (void)premote;
+
+    }
 
     gstrbuffer = new char[30000000];
     gstrout = new char[10000000];