Kaynağa Gözat

add rtspclientup class in driver_h264_rtspclient.

yuchuli 3 yıl önce
ebeveyn
işleme
703276c533

BIN
src/driver/driver_h264_rtspclient/codepar


+ 11 - 1
src/driver/driver_h264_rtspclient/driver_h264_rtspclient.pro

@@ -19,7 +19,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
-SOURCES += main.cpp
+SOURCES += main.cpp \
+    rtspclientup.cpp
 
 
 #DEFINES += USE_QSV
@@ -51,3 +52,12 @@ INCLUDEPATH += $$PWD/Include
 #INCLUDEPATH += $$PWD/libEasyRTSPClient/Include
 
 LIBS += -L$$PWD -leasypusher -leasyrtspclient
+
+RESOURCES += \
+    rtspclient.qrc
+
+#DEFINES += SAVECODEPAR
+
+HEADERS += \
+    rtspclientup.h \
+    ffmpeg_outputer.h

+ 224 - 0
src/driver/driver_h264_rtspclient/ffmpeg_outputer.h

@@ -0,0 +1,224 @@
+#pragma once
+
+#include <iostream>
+#include <thread>
+#include <chrono>
+#include <assert.h>
+#include <list>
+#include <mutex>
+
+#ifdef __cplusplus 
+extern "C" {
+
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+#include "libavutil/avutil.h"
+#include "libavutil/time.h"
+
+}
+#endif
+
+class FfmpegOutputer {
+    enum State {INIT=0, SERVICE, DOWN};
+    AVFormatContext *m_ofmt_ctx {nullptr};
+    std::string m_url;
+
+    std::thread *m_thread_output {nullptr};
+    bool m_thread_output_is_running {false};
+
+    State m_output_state;
+    std::mutex m_list_packets_lock;
+    std::list<AVPacket*> m_list_packets;
+    bool m_repeat {true};
+
+    bool string_start_with(const std::string& s, const std::string& prefix){
+        return (s.compare(0, prefix.size(), prefix) == 0);
+    }
+
+    int output_initialize(){
+        int ret = 0;
+        if (!(m_ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
+            ret = avio_open(&m_ofmt_ctx->pb, m_url.c_str(), AVIO_FLAG_WRITE);
+            if (ret < 0) {
+                printf("Could not open output URL '%s'", m_url.c_str());
+                return -1;
+            }
+        }
+
+        AVDictionary *opts = NULL;
+        if (string_start_with(m_url, "rtsp://")) {
+            av_dict_set(&opts, "rtsp_transport", "tcp", 0);
+            av_dict_set(&opts, "muxdelay", "0.1", 0);
+ //           av_dict_set(&opts, "fps", "30", 0);
+        }
+
+        //Write file header
+        ret = avformat_write_header(m_ofmt_ctx, &opts);
+        if (ret < 0) {
+            printf("Error occurred when opening output URL\n");
+            return -1;
+        }
+
+        m_output_state = SERVICE;
+        return 0;
+    }
+
+    void output_service() {
+        int ret = 0;
+        if(m_list_packets.size() == 0)
+        {
+            std::this_thread::sleep_for(std::chrono::microseconds(100));
+            return;
+        }
+        while(m_list_packets.size() > 0) {
+            AVPacket *pkt = m_list_packets.front();
+ //           std::cout<<"send "<<std::endl;
+            m_list_packets.pop_front();
+            ret = av_interleaved_write_frame(m_ofmt_ctx, pkt);
+            av_packet_free(&pkt);
+            if (ret != 0) {
+                std::cout << "av_interleaved_write_frame err" << ret << std::endl;
+                m_output_state = DOWN;
+                break;
+            }
+        }
+
+    }
+
+    void output_down() {
+        if (m_repeat) {
+            m_output_state = INIT;
+        }else{
+            av_write_trailer(m_ofmt_ctx);
+            if (!(m_ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
+                avio_closep(&m_ofmt_ctx->pb);
+            }
+
+            // Set exit flag
+            m_thread_output_is_running = false;
+        }
+    }
+
+    void output_process_thread_proc() {
+        m_thread_output_is_running = true;
+        while(m_thread_output_is_running) {
+            switch(m_output_state) {
+                case INIT:
+                    if (output_initialize() < 0) m_output_state = DOWN;
+                    break;
+                case SERVICE:
+                    output_service();
+                    break;
+                case DOWN:
+                    output_down();
+                    break;
+            }
+        }
+
+        std::cout << "output thread exit!" << std::endl;
+    }
+
+public:
+    FfmpegOutputer():m_ofmt_ctx(NULL){
+        
+    }
+    virtual ~FfmpegOutputer()
+    {
+        CloseOutputStream();
+    }
+
+    int OpenOutputStream(const std::string& url, AVFormatContext *ifmt_ctx)
+    {
+        int ret = 0;
+        const char* format_name = NULL;
+        m_url = url;
+        if (string_start_with(m_url, "rtsp://")) {
+            format_name = "rtsp";
+        }else if(string_start_with(m_url, "udp://") || string_start_with(m_url, "tcp://")) {
+            format_name = "h264";
+        }else if(string_start_with(m_url, "rtp://")) {
+            format_name = "rtp";
+        }else if(string_start_with(m_url, "rtmp://")) {
+            format_name = "flv";
+        }
+        else{
+            std::cout << "Not support this Url:" << m_url << std::endl;
+            return -1;
+        }
+
+        if (nullptr == m_ofmt_ctx) {
+            ret = avformat_alloc_output_context2(&m_ofmt_ctx, NULL, format_name, m_url.c_str());
+            if (ret < 0 || m_ofmt_ctx == NULL) {
+                std::cout << "avformat_alloc_output_context2() err=" << ret << std::endl;
+                return -1;
+            }
+
+            for(int i = 0;i < ifmt_ctx->nb_streams; ++i) {
+                AVStream *ostream = avformat_new_stream(m_ofmt_ctx, NULL);
+                if (NULL == ostream) {
+                    std::cout << "Can't create new stream!" << std::endl;
+                    return -1;
+                }
+#if LIBAVCODEC_VERSION_MAJOR > 56
+                ret = avcodec_parameters_copy(ostream->codecpar, ifmt_ctx->streams[i]->codecpar);
+                if (ret < 0) {
+                    std::cout << "avcodec_parameters_copy() err=" << ret << std::endl;
+                    return -1;
+                }
+
+#else
+                ret = avcodec_copy_context(ostream->codec, ifmt_ctx->streams[i]->codec);
+                if (ret < 0){
+                    flog(LOG_ERROR, "avcodec_copy_context() err=%d", ret);
+                    return -1;
+                }
+#endif
+                m_ofmt_ctx->oformat->flags |= AVFMT_TS_NONSTRICT;
+                if (m_ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {
+                    ostream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
+                }
+            }
+        }
+
+        if (!m_ofmt_ctx) {
+            printf("Could not create output context\n");
+            return -1;
+        }
+
+        av_dump_format(m_ofmt_ctx, 0, m_url.c_str(), 1);
+        ret = output_initialize();
+        if (ret != 0) {
+            return -1;
+        }
+
+        m_thread_output = new std::thread(&FfmpegOutputer::output_process_thread_proc, this);
+        return 0;
+    }
+
+
+
+    int InputPacket(AVPacket *pkt) {
+        AVPacket *pkt1 = av_packet_alloc();
+        av_packet_ref(pkt1, pkt);
+        m_list_packets.push_back(pkt1);
+        return 0;
+    }
+
+    int CloseOutputStream() {
+        std::cout << "call CloseOutputStream()" << std::endl;
+        m_repeat = false;
+        m_output_state = DOWN;
+        if (m_thread_output) {
+            m_thread_output->join();
+            delete m_thread_output;
+            m_thread_output = nullptr;
+        }
+
+        if (m_ofmt_ctx) {
+            avformat_free_context(m_ofmt_ctx);
+            m_ofmt_ctx = NULL;
+        }
+
+        return 0;
+    }
+};

+ 109 - 17
src/driver/driver_h264_rtspclient/main.cpp

@@ -196,7 +196,9 @@ int test2()
 
 
 #include "modulecomm.h"
+#include "rtspclientup.h"
 
+rtspclientup * gup1 = NULL;
 
 std::shared_ptr<char> gpstr_data;
 bool gbUpdate = false;
@@ -214,7 +216,14 @@ void Listenframe(const char * strdata,const unsigned int nSize,const unsigned in
     gbUpdate = true;
     gmutex.unlock();
 //    qDebug(" %02x %02x %02x %02x %02x %02x",strdata[0],strdata[1],strdata[2],strdata[3],strdata[4],strdata[5]);
-
+    iv::framedata xframe;
+    xframe.mframe_ptr = std::shared_ptr<char>(new char[nSize]);
+    mempcpy(xframe.mframe_ptr.get(),strdata,nSize);
+    xframe.mndatasize = nSize;
+    if(gup1 != NULL)
+    {
+        gup1->AddData(xframe);
+    }
 
 
 }
@@ -231,6 +240,7 @@ std::vector<iv::datapac> gvectorsend;
 
 void threadrecv()
 {
+//    return;
     static AVFormatContext *i_fmt_ctx;
     static AVStream *i_video_stream;
 
@@ -245,11 +255,15 @@ void threadrecv()
     /* should set to NULL so that avformat_open_input() allocate a new one */
         i_fmt_ctx = NULL;
         //这是我用ONVIF协议得到的摄像头RTSP流媒体地址
-        char rtspUrl[] = "rtsp://111.33.136.149:9554/mystream";
+        char rtspUrl[] = "rtsp://111.33.136.149:9554/testhello2";
 
 
+        AVDictionary *avdic=NULL;
+        char option_key[]="rtsp_transport";
+        char option_value[]="tcp";
+        av_dict_set(&avdic,option_key,option_value,0);
 
-        if (avformat_open_input(&i_fmt_ctx, rtspUrl, NULL, NULL)!=0)
+        if (avformat_open_input(&i_fmt_ctx, rtspUrl, NULL, &avdic)!=0)
         {
             fprintf(stderr, " = could not open input file\n");
             return ;
@@ -262,7 +276,7 @@ void threadrecv()
 //            av_dict_set(&opts, "muxdelay", "0.1", 0);
 
 
-        if (avformat_find_stream_info(i_fmt_ctx, &opts)<0)
+        if (avformat_find_stream_info(i_fmt_ctx,NULL)<0)
         {
             fprintf(stderr, " = could not find stream info\n");
             return ;
@@ -284,6 +298,8 @@ void threadrecv()
                if (av_read_frame(i_fmt_ctx, &i_pkt) <0 )
                    break;
 
+
+
                int sizedata = i_pkt.size;
                int i;;
                gmutexlat.lock();
@@ -297,16 +313,30 @@ void threadrecv()
                }
                gmutexlat.unlock();
                 std::cout<<"    time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" read packet size:"<<i_pkt.size<<std::endl;
+                av_packet_unref(&i_pkt);
            }
 
 
 }
+#include <QFile>
+
+
 
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
+    av_register_all();         //初始化FFMPEG  调用了这个才能正常适用编码器和解码器
+
+    //Network
+    avformat_network_init();
+
+    rtspclientup * pup = new rtspclientup("rtsp://111.33.136.149:9554/test",1920,1080);
+    gup1 = pup;
     void * pa = iv::modulecomm::RegisterRecv("h264front",Listenframe);
+    return a.exec();
+
+
     AVFormatContext *ifmt_ctx = NULL;
        AVPacket pkt;
        const char *in_filename, *out_filename;
@@ -314,21 +344,20 @@ int main(int argc, char *argv[])
        int ret;
        int frame_index = 0;
 
-       in_filename = "/home/yuchuli/imx291.h264";
+       in_filename = "./imx291.h264";
 
        out_filename = "rtsp://111.33.136.149:9554/testhello2";
        //out_filename = "rtp://233.233.233.233:6666";
        //out_filename = "tcp://127.0.0.1:9000";
        //out_filename = "udp://127.0.0.1:9000";
 
-       av_register_all();         //初始化FFMPEG  调用了这个才能正常适用编码器和解码器
 
-       //Network
-       avformat_network_init();
 
 
        std::thread * precvthread = new std::thread(threadrecv);
 
+
+
        if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
            printf("Could not open input file.");
           return -1;
@@ -341,14 +370,71 @@ int main(int argc, char *argv[])
        }
 
 
-       ifmt_ctx->streams[0]->avg_frame_rate.num = 30;
-       ifmt_ctx->streams[0]->codecpar->sample_aspect_ratio.num = 30;
-       ifmt_ctx->streams[0]->time_base.den = 30;
+       ifmt_ctx->streams[0]->codecpar->width = 1920;
+       ifmt_ctx->streams[0]->codecpar->height = 1080;
+
+
+       AVFormatContext * fmtctx = NULL;
+       int nrtn = avformat_alloc_output_context2(&fmtctx,NULL,"rtsp","rtsp://127.0.0.1:9554/test2.sdp");
+
+
+
+       fmtctx->bit_rate = 2000000;
+       fmtctx->fps_probe_size = 30;
+
+       int err = 0;
+
+       AVStream *out_stream = avformat_new_stream(fmtctx, NULL);
+
+       QFile xFile;
+
+#ifdef SAVECODEPAR
+       xFile.setFileName("./codepar");
+       if(xFile.open(QIODevice::ReadWrite))
+       {
+           xFile.write((char*)ifmt_ctx->streams[0]->codecpar,sizeof(AVCodecParameters));
+           if(ifmt_ctx->streams[0]->codecpar->extradata_size>0)
+           {
+               xFile.write((char*)ifmt_ctx->streams[0]->codecpar->extradata,ifmt_ctx->streams[0]->codecpar->extradata_size);
+           }
+           xFile.close();
+           return 0;
+       }
+
+#endif
+
+       xFile.setFileName(":/codepar");
+       if(xFile.open(QIODevice::ReadOnly))
+       {
+           int n = sizeof(AVCodecParameters);
+           xFile.read((char *)out_stream->codecpar,sizeof(AVCodecParameters));
+           if(out_stream->codecpar->extradata_size>0)
+           {
+               out_stream->codecpar->extradata = new uint8_t[out_stream->codecpar->extradata_size];
+               xFile.read((char*)out_stream->codecpar->extradata,out_stream->codecpar->extradata_size);
+           }
+           xFile.close();
+       }
+       else
+       {
+           std::cout<<"can't get codepar from file."<<std::endl;
+           return -1;
+       }
+
+
+
+       out_stream->codecpar->bit_rate = 2000000;
+       out_stream->codecpar->width = 1280;
+       out_stream->codecpar->height = 720;
+
+//       avcodec_parameters_copy(fmtctx->streams[0]->codecpar, ifmt_ctx->streams[0]->codecpar);
+
+//       memcpy(fmtctx->streams[0]->codecpar, ifmt_ctx->streams[0]->codecpar,sizeof(AVCodecParameters));
 
-       ifmt_ctx->bit_rate = 2000000;
        if (NULL == pusher) {
            pusher = new FfmpegOutputer();
-           ret = pusher->OpenOutputStream(out_filename, ifmt_ctx);
+ //          ret = pusher->OpenOutputStream(out_filename, ifmt_ctx);
+           ret = pusher->OpenOutputStream(out_filename, fmtctx);
            if (ret != 0){
                return -3;
            }
@@ -358,7 +444,9 @@ int main(int argc, char *argv[])
        av_dump_format(ifmt_ctx, 0, in_filename, 0);
 
        int pos = 0;
-       av_read_frame(ifmt_ctx, &pkt);
+//       av_read_frame(ifmt_ctx, &pkt);
+
+ //      pkt = av_packet_alloc();
        while (true) {
 
            if(gbUpdate == false)
@@ -377,6 +465,9 @@ int main(int argc, char *argv[])
            //           pkt.buf->data = pkt.data;
            memcpy(pkt.data, gpstr_data.get(),gndatasize);
            pkt.size = gndatasize;
+           pkt.stream_index = 0;
+           pkt.side_data = 0;
+           pkt.side_data_elems = 0;
   //         std::cout<<" size : "<<gndatasize<<std::endl;
            //           std::cout<<" buf size: "<<pkt.buf->size<<std::endl;
            //           pkt.buf->size = gndatasize;
@@ -400,11 +491,11 @@ int main(int argc, char *argv[])
            std::cout<<"    time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<" pos: "<<pkt.pos<<" size: "<<pkt.size<<" flats: "<<pkt.flags<< std::endl;
  //          if (ret < 0) break;
 
-           pkt.duration = 3;
+           pkt.duration = 3*1000;
 
 //           std::cout<<" pts: "<<pkt.pts<<" dts: "<<pkt.dts<<std::endl;
            if (pkt.pts == AV_NOPTS_VALUE) {
-               pkt.dts = pkt.pts = (1.0/30)*90*frame_index;
+               pkt.dts = pkt.pts = 1000* (1.0/30)*90*frame_index;
  //              pkt.dts = pkt.pts = frame_index * 1;
  //              frame_index++;
 
@@ -412,8 +503,9 @@ int main(int argc, char *argv[])
  //          std::cout<<" pts: "<<pkt.pts<<" dts: "<<pkt.dts<<std::endl;
 
            pusher->InputPacket(&pkt);
+           delete pkt.data;
            av_packet_unref(&pkt);
-//           delete pkt.data;
+
            frame_index++;
 //           av_usleep(40000);
        }

+ 5 - 0
src/driver/driver_h264_rtspclient/rtspclient.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>codepar</file>
+    </qresource>
+</RCC>

+ 140 - 0
src/driver/driver_h264_rtspclient/rtspclientup.cpp

@@ -0,0 +1,140 @@
+#include "rtspclientup.h"
+
+#include <QFile>
+
+#include "ffmpeg_outputer.h"
+
+rtspclientup::rtspclientup(const char * strrtsp, int nwidth,int nheight)
+{
+    strncpy(mstrrtsp,strrtsp,256);
+    mnwidth = nwidth;
+    mnheight = nheight;
+
+    mpthreadrstp = new std::thread(&rtspclientup::threadrstp,this,strrtsp,nwidth,nheight);
+}
+
+rtspclientup::~rtspclientup()
+{
+    mbthreadrun = false;
+    mpthreadrstp->join();
+}
+
+
+void rtspclientup::threadrstp(const char *strrtsp, int nwidth, int nheight)
+{
+
+    AVPacket pkt;
+    FfmpegOutputer *pusher = NULL;
+    AVFormatContext * fmtctx = NULL;
+    int nrtn = avformat_alloc_output_context2(&fmtctx,NULL,"rtsp",strrtsp);
+    if(nrtn<0)
+    {
+        std::cout<<" avformat_alloc_output_context2 fail."<<std::endl;
+        return;
+    }
+    AVStream *out_stream = avformat_new_stream(fmtctx, NULL);
+
+    QFile xFile;
+    int ret;
+    int frame_index = 0;
+
+    xFile.setFileName(":/codepar");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+//        int n = sizeof(AVCodecParameters);
+        xFile.read((char *)out_stream->codecpar,sizeof(AVCodecParameters));
+        if(out_stream->codecpar->extradata_size>0)
+        {
+            out_stream->codecpar->extradata = new uint8_t[out_stream->codecpar->extradata_size];
+            xFile.read((char*)out_stream->codecpar->extradata,out_stream->codecpar->extradata_size);
+        }
+        xFile.close();
+    }
+    else
+    {
+        std::cout<<"can't get codepar from file."<<std::endl;
+        return ;
+    }
+    out_stream->codecpar->bit_rate = 2000000;
+    out_stream->codecpar->width = nwidth;
+    out_stream->codecpar->height = nheight;
+
+    if (NULL == pusher) {
+        pusher = new FfmpegOutputer();
+//          ret = pusher->OpenOutputStream(out_filename, ifmt_ctx);
+        ret = pusher->OpenOutputStream(strrtsp, fmtctx);
+        while ((ret != 0)&&mbthreadrun) {
+            std::cout<<"OpenOutputStream Fail. "<<std::endl;
+            std::this_thread::sleep_for(std::chrono::seconds(1));
+            ret = pusher->OpenOutputStream(strrtsp, fmtctx);
+
+        }
+    }
+
+
+    frame_index = 0;
+    int pos = 0;
+    while(mbthreadrun)
+    {
+        if(mvectorframe.size() == 0)
+        {
+            std::unique_lock<std::mutex> lk(mmutexcv);
+            if(mcv.wait_for(lk, std::chrono::milliseconds(30000)) == std::cv_status::timeout)
+            {
+                lk.unlock();
+                continue;
+            }
+            else
+            {
+                lk.unlock();
+            }
+        }
+        iv::framedata xframe;
+        bool bsend = false;
+        mmutexdata.lock();
+        if(mvectorframe.size()>0)
+        {
+            xframe = mvectorframe[0];
+            mvectorframe.erase(mvectorframe.begin());
+            bsend = true;
+        }
+        mmutexdata.unlock();
+        if(bsend)
+        {
+            pkt.buf = NULL;
+            pkt.duration = 0;
+            pkt.data = new unsigned char[xframe.mndatasize];
+            memcpy(pkt.data, xframe.mframe_ptr.get(),xframe.mndatasize);
+            pkt.size = xframe.mndatasize;
+            pkt.stream_index = 0;
+            pkt.side_data = 0;
+            pkt.side_data_elems = 0;
+            pkt.pos =  pos;
+            pkt.pts = AV_NOPTS_VALUE;
+            pkt.dts = AV_NOPTS_VALUE;
+            pos = pos + xframe.mndatasize;
+            pkt.flags = 0;
+            pkt.duration = 3*1000;
+            if (pkt.pts == AV_NOPTS_VALUE) {
+                pkt.dts = pkt.pts = 1000* (1.0/30)*90*frame_index;
+            }
+            pusher->InputPacket(&pkt);
+            delete pkt.data;
+            av_packet_unref(&pkt);
+            frame_index++;
+        }
+    }
+}
+
+void rtspclientup::AddData(iv::framedata xframedata)
+{
+    mmutexdata.lock();
+    while(mvectorframe.size()>1000)
+    {
+        mvectorframe.erase(mvectorframe.begin());
+        std::cout<<"rtspclientup erase data."<<std::endl;
+    }
+    mvectorframe.push_back(xframedata);
+    mmutexdata.unlock();
+    mcv.notify_all();
+}

+ 59 - 0
src/driver/driver_h264_rtspclient/rtspclientup.h

@@ -0,0 +1,59 @@
+#ifndef RTSPCLIENTUP_H
+#define RTSPCLIENTUP_H
+
+extern "C"
+{
+#include <libavcodec/avcodec.h>
+#include <libavutil/opt.h>
+#include <libavutil/imgutils.h>
+#include <libavutil/common.h>
+#include "libavutil/error.h"
+#include "libavutil/hwcontext.h"
+#include "libavformat/avformat.h"
+#include "libavformat/avio.h"
+}
+
+#include <iostream>
+#include <thread>
+#include <memory>
+#include <mutex>
+#include <vector>
+#include <condition_variable>
+
+namespace iv {
+struct framedata
+{
+    std::shared_ptr<char> mframe_ptr;
+    int mndatasize;
+};
+
+}
+
+class rtspclientup
+{
+public:
+    rtspclientup(const char * strrtsp, int nwidth,int nheight);
+    ~rtspclientup();
+
+private:
+    char mstrrtsp[256];
+    int mnwidth;
+    int mnheight;
+
+    bool mbthreadrun = true;
+    std::thread * mpthreadrstp;
+    std::mutex mmutexdata;
+    std::vector<iv::framedata> mvectorframe;
+
+    std::condition_variable mcv;
+    std::mutex mmutexcv;
+
+private:
+    void threadrstp(const char * strrtsp,int nwidth,int nheight);
+
+
+public:
+    void AddData(iv::framedata xframedata);
+};
+
+#endif // RTSPCLIENTUP_H

+ 5 - 0
src/driver/driver_h264_usbimx291/main.cpp

@@ -35,8 +35,13 @@ void ThreadGetData()
             frecvtime = frecvtime/1000000.0;
 
 #ifdef  TEST_SAVEH264
+            static int ncount = 0;
+            if(ncount<50)
+            {
             gFile.write(xframe.mpstr_ptr.get(),xframe.mdatalen);
             gFile.flush();
+            }
+//            ncount++;
 #endif
 //            qDebug(" recvtime : %13.6f  datatime:%13.6f",frecvtime,xframe.mfrecvtime);
             iv::modulecomm::ModuleSendMsg(gpa,xframe.mpstr_ptr.get(),xframe.mdatalen);

+ 1 - 0
src/tool/testmpegts/ffmpegcmd

@@ -0,0 +1 @@
+ffmpeg -rtsp_transport tcp -i "rtsp://111.33.136.149:9554/testhello2" -f mpegts -codec:v mpeg1video -s 1920x1080 "http://127.0.0.1:6122/testhello2

+ 23 - 0
src/tool/testmpegts/index.html

@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<title>JSMpeg Stream Client</title>
+	<style type="text/css">
+		html, body {
+			background-color: #111;
+			text-align: center;
+		}
+	</style>
+	
+</head>
+<body>
+	<canvas id="video-canvas"></canvas>
+	<script type="text/javascript" src="jsmpeg.min.js"></script>
+	<script type="text/javascript">
+		var canvas = document.getElementById('video-canvas');
+		var url = 'ws://'+document.location.hostname+':6123/ts';
+		var player = new JSMpeg.Player(url, {canvas: canvas});
+	</script>
+</body>
+</html>
+