From e878e92811a2dbfb6b4d3f7b2c357435f56e28db Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期日, 29 九月 2019 10:27:21 +0800
Subject: [PATCH] add trytime

---
 csrc/ffmpeg/format/FormatIn.cpp  |    3 +--
 csrc/ffmpeg/format/FormatOut.cpp |    2 +-
 csrc/buz/recorder.cpp            |   31 ++++++++++++++++++++-----------
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index cf2fa1f..00611c2 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -225,15 +225,22 @@
 
             int ret = mux_hevc(fp, file_path_.c_str());
             fclose(fp);
-            if (remove(hevc_file.c_str()) != 0){
-                logIt("mux hevc remove file %s failed", hevc_file.c_str());
+            if (ret == 0){
+                if (remove(hevc_file.c_str()) != 0){
+                    logIt("mux hevc remove file %s failed", hevc_file.c_str());
+                }
+            }else{
+                logIt("mux hevc to mp4 error, use raw hevc");
+                file_path_ = hevc_file;
             }
 
-            return ret;
+            return 0;
         }
 
         static int read_buffer(void *opaque, uint8_t *buf, int buf_size){
             FILE *fp_open = (FILE*)opaque;
+            if (!fp_open) logIt("mux hevc open file error");
+
         	if(!feof(fp_open)){
         		int true_size=fread(buf,1,buf_size,fp_open);
         		return true_size;
@@ -250,8 +257,14 @@
                 return -1;
             }
 
-            if (in->openWithCustomIO(fp, read_buffer) < 0) {
-                logIt("mux hevc open custom io error");
+            int tryTime = 0;
+            while (in->openWithCustomIO(fp, read_buffer) < 0) {
+                usleep(10000);
+                if (tryTime++ < 100){
+                    logIt("mux hevc mux: %d failed open custom io %s, try again", tryTime, outfile);
+                    continue;
+                }
+                logIt("mux hevc try %d time to open custom io, failed", tryTime);
                 return -2;
             }
             if (in->open(NULL, NULL) < 0){
@@ -293,14 +306,10 @@
 
         void Recorder::end_writer(){
 
-            int ret = -1;
             if (in_->IsHEVC()){
-                ret = end_write_hevc();
+                end_write_hevc();
             }else{
-                ret = end_write_h264();
-            }
-            if (ret < 0){
-                logIt("end write file : %s, h265: %d, failed", file_path_.c_str(), in_->IsHEVC());
+                end_write_h264();
             }
 
             logIt("finished record : %s frames: %d", file_path_.c_str(), cur_frame);
diff --git a/csrc/ffmpeg/format/FormatIn.cpp b/csrc/ffmpeg/format/FormatIn.cpp
index 25d9e3a..9f743f8 100644
--- a/csrc/ffmpeg/format/FormatIn.cpp
+++ b/csrc/ffmpeg/format/FormatIn.cpp
@@ -86,8 +86,7 @@
 
 		auto err = av_probe_input_buffer(ctx_->pb, &ctx_->iformat, NULL, NULL, 0, read_io_buff_size_);
 		if(err != 0){
-			logIt("open with custom io prob input buffer error:%d\n", err);
-            logIt("custom io failed:%s", getAVErrorDesc(err).c_str());
+			logIt("open with custom io prob input buffer error:%d err: %s\n", err, getAVErrorDesc(err).c_str());
 			return -1;
 		}
 
diff --git a/csrc/ffmpeg/format/FormatOut.cpp b/csrc/ffmpeg/format/FormatOut.cpp
index 6bc43df..60efd59 100644
--- a/csrc/ffmpeg/format/FormatOut.cpp
+++ b/csrc/ffmpeg/format/FormatOut.cpp
@@ -293,7 +293,7 @@
             logIt("Failed to copy context from input to output stream codec context\n");
             return false;
         }
-        out_stream->codecpar->codec_tag = out_stream->codec->codec_tag = 0;
+        out_stream->codecpar->codec_tag = 0;
         
         if(ctx_->oformat->flags & AVFMT_GLOBALHEADER)
             out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

--
Gitblit v1.8.0