From 81d49a435bc67fa0be45056c743f2a5b46bad264 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期四, 14 三月 2019 20:05:20 +0800
Subject: [PATCH] 解决ffmpeg打开国标流失败导致段错误的问题

---
 QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
index b4b7f3c..9e8fd7e 100644
--- a/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
+++ b/QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
@@ -143,7 +143,7 @@
  */
 void BASICGB28181::FFmpegDecoderJPG::BareFlowDecoderThd(FFmpegDecoderJPG *p_this) {
     DBG(p_this->m_camIdx << "  BareFlowDecoderThd ok ... gpuIdx is " << p_this->m_gpuIdx);
-//    while(!p_this->m_running) {
+    while(!p_this->m_running) {
 
         p_this->m_running = true;
 //    av_register_all();
@@ -154,14 +154,14 @@
         if (!p_this->iobuffer) {
             ERR("av_malloc: err======" << p_this->m_camIdx);
             p_this->m_running = false;
-            return;
+            continue;
         }
         p_this->avio = avio_alloc_context(p_this->iobuffer, p_this->m_buf_size, 0, p_this, p_this->read_data, NULL,
                                           NULL);
         if (!p_this->avio) {
             ERR("avio_alloc_context: err======" << p_this->m_camIdx);
             p_this->m_running = false;
-            return;
+            continue;
         }
         p_this->ic->pb = p_this->avio;
 
@@ -169,13 +169,13 @@
         if (err) {
             ERR("av_probe_input_buffer: err======" << err  << p_this->m_camIdx);
             p_this->m_running = false;
-            return;
+            continue;
         }
         err = avformat_open_input(&p_this->ic, "", NULL, NULL);
         if (err) {
             ERR("avformat_open_input: err======" << err  << p_this->m_camIdx);
             p_this->m_running = false;
-            return;
+            continue;
         }
 //    int err2 = avformat_find_stream_info(ic, nullptr);
         err = avformat_find_stream_info(p_this->ic, NULL);
@@ -184,7 +184,7 @@
 //        avformat_close_input(&p_this->ic);
 //        DBG("avformat_close_input(&p_this->ic);");
             p_this->m_running = false;
-            return;
+            continue;
         }
         int vi = -1;
         for (int i = 0; i < p_this->ic->nb_streams; ++i) {
@@ -202,7 +202,7 @@
 //        avformat_close_input(&p_this->ic);
 //        DBG("avformat_close_input(&p_this->ic);");
             p_this->m_running = false;
-            return;
+            continue;
         }
 
         p_this->codec = avcodec_find_decoder(p_this->ctx->codec_id);
@@ -231,7 +231,7 @@
 //        avcodec_free_context(&p_this->ctx);
 //        DBG("avcodec_free_context(&p_this->ctx);");
             p_this->m_running = false;
-            return;
+            continue;
         }
 
         av_init_packet(&p_this->pkt);
@@ -239,7 +239,7 @@
         p_this->frame = av_frame_alloc();
         unsigned int usleepTime = (1000 / p_this->m_fps) - 12;
         usleepTime *= 1000;
-        DBG(" before while <<usleepTime is " << usleepTime);
+        DBG("===open ok, camid: " << p_this->m_camIdx );
         while (p_this->m_running) {
 #ifdef TestCode
             ClockTimer Test("while time");
@@ -322,7 +322,7 @@
         }
         DBG(" after while ");
         av_frame_free(&p_this->frame);
-//    }
+    }
 }
 
 bool BASICGB28181::FFmpegDecoderJPG::startThd(const std::string &camIdx, const int &fps, const int &gpuIdx) {

--
Gitblit v1.8.0