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/buz/recorder.cpp | 31 ++++++++++++++++++++----------- 1 files changed, 20 insertions(+), 11 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); -- Gitblit v1.8.0