video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-08-05 2d4b871401ace5a54eaff1cbfacd008c586ad928
fix thread quit
2个文件已修改
37 ■■■■■ 已修改文件
csrc/buz/recorder.cpp 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/buz/recorder.hpp 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/buz/recorder.cpp
@@ -31,22 +31,32 @@
        ,file_frame_index_(-1)
        ,file_path_("")
        ,func_rec_info_(nullptr)
        ,thrd_(nullptr)
        {
            // logIt("RECODER ID: %s", id_.c_str());
        }
        Recorder::~Recorder(){
            if (out_ && !stop_recorder_.load()){
                stop_recorder_.store(true);
                cv_.notify_one();
                while(stop_recorder_.load()){
                    logIt("REC WAIT TO QUIT ID %s", id_.c_str());
                    sleep(1);
                }
            }else if (stop_recorder_.load()){
                logIt("REC NORMAL QUIT");
            }
            // if (out_){
            //     stop_recorder_.store(true);
            //     cv_.notify_one();
            //     int try_cnt = 0;
            //     while(stop_recorder_.load()){
            //         logIt("REC WAIT TO QUIT ID %s", id_.c_str());
            //         if (try_cnt > 100){
            //             logIt("REC TRY %d TIMES TO QUIT..., BREAK!!!", try_cnt);
            //             break;
            //         }
            //         try_cnt++;
            //         sleep(1);
            //     }
            // }else if (stop_recorder_.load()){
            //     logIt("REC NORMAL QUIT");
            // }
            
            stop_recorder_.store(true);
            thrd_->join();
            logIt("REC THREAD JOINED, QUIT!!!");
        }
        int Recorder::init_writer(){
@@ -190,9 +200,10 @@
            logIt("minduration %d maxduration %d curduration %d", minduration, maxduration, end_frame);    
            std::thread([&]{
            thrd_.reset(new std::thread([&]{
                run_thread();
            }).detach();
            }));
            //.detach();
            return 0;
        }
csrc/buz/recorder.hpp
@@ -64,6 +64,8 @@
                std::mutex              mutex_pkt_;
                 std::condition_variable cv_;
                std::unique_ptr<std::thread> thrd_;
                std::string             dir_;
                std::string             id_;