video analysis2.0拆分,ffmpeg封装go接口库
chenshijun
2019-10-29 8c95c6857542b3fe82cd614e45755902884358af
修改视频获取不到流的死等问题
1个文件已修改
19 ■■■■ 已修改文件
csrc/thirdparty/gb28181/include/PsToEs.hpp 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/thirdparty/gb28181/include/PsToEs.hpp
@@ -5,6 +5,7 @@
#include <pthread.h>
#include "librtsp.h"
#include <sys/time.h>
using namespace std;
@@ -14,7 +15,7 @@
public:
    MyQueue():mtx(PTHREAD_MUTEX_INITIALIZER), cond(PTHREAD_COND_INITIALIZER){
        t.tv_sec = 0;
        t.tv_nsec = 20000000;
        t.tv_nsec = 0;
    }
    ~MyQueue() {
@@ -39,9 +40,16 @@
    T pop() {
        pthread_mutex_lock(&mtx);
        while (q.empty()) {
            pthread_cond_wait(&cond, &mtx);
        if (q.empty()) {
            gettimeofday(&now, NULL);
            t.tv_sec = now.tv_sec + 5;
            t.tv_nsec = now.tv_usec * 1000;
//            pthread_cond_wait(&cond, &mtx);
            pthread_cond_timedwait(&cond, &mtx, &t);
        }
        if (q.empty()) {
            pthread_mutex_unlock(&mtx);
            return 0;
        }
        T value = q.front();
        q.pop_front();
@@ -72,6 +80,7 @@
    pthread_mutex_t mtx;
    pthread_cond_t cond;
    timespec t;
    struct timeval now;
};
typedef struct _buffInfo {
@@ -115,7 +124,11 @@
            //从缓存中获取buffinfo
            frameBuffInfo *buffinfo = _this->m_rtpQueue.pop();
//            printf(" m_rtpQueue.pop after \n");
            if(buffinfo != nullptr){
            diff = len - buffinfo->buffLen;
            }else{
                return 0;
            }
            //帧长大于bufsize
            if (diff < 0) {