浏览代码

change h264.

yuchuli 3 年之前
父节点
当前提交
138e506674

+ 73 - 0
src/driver/driver_h264_dev/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 40 - 0
src/driver/driver_h264_dev/driver_h264_dev.pro

@@ -0,0 +1,40 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# You can make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+
+!include(../../../include/ivboost.pri ) {
+    error( "Couldn't find the ivboost.pri file!" )
+}
+
+!include(../../../include/ivopencv.pri ) {
+    error( "Couldn't find the ivopencv.pri file!" )
+}
+
+
+SOURCES += \
+        main.cpp \
+        ../../include/msgtype/rawpic.pb.cc
+
+LIBS += -lavcodec -lavformat -lavutil
+
+HEADERS += \
+        ../../include/msgtype/rawpic.pb.h
+
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target

+ 8 - 0
src/driver/driver_h264_dev/main.cpp

@@ -0,0 +1,8 @@
+#include <QCoreApplication>
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    return a.exec();
+}

+ 18 - 4
src/driver/driver_h264_enc/main.cpp

@@ -26,6 +26,7 @@ extern "C"
 bool gbNewData = false;
 #include <QWaitCondition>
 #include <QMutex>
+#include <chrono>
 
 QWaitCondition gwc;
 static QMutex gWaitMutex;
@@ -45,6 +46,8 @@ static char * gstrwidth ="1920";
 static char * gstrheight = "1080";
 int gnwidth,gnheight;
 
+void * gpaout;
+
 static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
                    FILE *outfile)
 {
@@ -69,10 +72,13 @@ static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
             exit(1);
         }
 
+        std::cout<<"time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
         printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
+        iv::modulecomm::ModuleSendMsg(gpaout,(char *)pkt->data,pkt->size);
 //        fwrite(pkt->data, 1, pkt->size, outfile);
         av_packet_unref(pkt);
     }
+
 }
 
 
@@ -86,7 +92,9 @@ void ThreadEnc()
 
     char * strbuf = new char[30000000];
 
+
     avcodec_register_all();
+
      codec = avcodec_find_encoder(AV_CODEC_ID_H264);// avcodec_find_encoder_by_name("h264");
 
      if(codec == NULL)
@@ -108,7 +116,7 @@ void ThreadEnc()
              exit(1);
 
          /* put sample parameters */
-         c->bit_rate = 4000000;
+         c->bit_rate = 1000000;
          /* resolution must be a multiple of two */
          c->width = 1920;
          c->height = 1080;
@@ -128,7 +136,10 @@ void ThreadEnc()
          c->pix_fmt = AV_PIX_FMT_YUV420P;
 
          if (codec->id == AV_CODEC_ID_H264)
-              av_opt_set(c->priv_data, "preset", "slow", 0);
+         {
+              av_opt_set(c->priv_data, "preset", "fast", 0);
+              av_opt_set(c->priv_data, "tune", "zerolatency", 0);
+         }
 
           /* open it */
           int ret = avcodec_open2(c, codec, NULL);
@@ -188,6 +199,8 @@ void ThreadEnc()
 
         }
     }
+    encode(c, NULL, pkt,NULL);
+
 
 }
 
@@ -196,7 +209,7 @@ void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int
 {
     if(nSize<1000)return;
     iv::vision::rawpic pic;
-    std::cout<<"rec. "<<std::endl;
+ //   std::cout<<"rec. "<<std::endl;
     if(false == pic.ParseFromArray(strdata,nSize))
     {
         std::cout<<"picview Listenpic fail."<<std::endl;
@@ -219,7 +232,7 @@ void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int
     QTime xTime;
     xTime.start();
     cv::cvtColor(mat, dstYuvImage, CV_BGR2YUV_I420);
-    std::cout<<" cvt time: "<<xTime.elapsed()<<std::endl;
+//    std::cout<<" cvt time: "<<xTime.elapsed()<<std::endl;
     gMutexLock.lock();
     memcpy(gstrbuffer,(char *)dstYuvImage.data,gnwidth*gnheight*3/2);
     gbNewData = true;
@@ -242,6 +255,7 @@ int main(int argc, char *argv[])
     gnheight = atoi(gstrheight);
 
     void * pa = iv::modulecomm::RegisterRecv("picfront",Listenpic);
+    gpaout = iv::modulecomm::RegisterSend("frame",1000000,1);
     std::thread * pthreadenc = new std::thread(ThreadEnc);
     return a.exec();
 }