From 51e5858dda6fb386024df0dce2bc38270f1bff02 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期五, 26 七月 2019 10:59:28 +0800 Subject: [PATCH] remove log --- csrc/ffmpeg/format/FormatIn.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 42 insertions(+), 6 deletions(-) diff --git a/csrc/ffmpeg/format/FormatIn.cpp b/csrc/ffmpeg/format/FormatIn.cpp index 9ebdb3d..4df2c0f 100644 --- a/csrc/ffmpeg/format/FormatIn.cpp +++ b/csrc/ffmpeg/format/FormatIn.cpp @@ -33,13 +33,18 @@ ,io_ctx_(NULL) ,read_io_buff_(NULL) ,read_io_buff_size_(32768) + ,handle_gb28181(NULL) {} FormatIn::~FormatIn() { if(io_ctx_){ - free(read_io_buff_); - avio_close(io_ctx_); + if(read_io_buff_){ + // av_free(read_io_buff_); + read_io_buff_ = NULL; + } + avio_context_free(&io_ctx_); + io_ctx_ = NULL; } if(ctx_){ avformat_close_input(&ctx_); @@ -47,12 +52,16 @@ ctx_ = NULL; if(dec_ctx_){ avcodec_close(dec_ctx_); + dec_ctx_ = NULL; } + } + if (handle_gb28181){ + delete handle_gb28181; } } //////////////////////////////////////////////////////////////////////// - int FormatIn::openWithCustomIO(read_packet fn, AVDictionary **options/*=NULL*/){ + int FormatIn::openWithCustomIO(void *opaque, read_packet fn, AVDictionary **options/*=NULL*/){ ctx_ = avformat_alloc_context(); if(!ctx_){ logIt("open with custom io create format error"); @@ -64,21 +73,48 @@ return -1; } - io_ctx_ = avio_alloc_context(read_io_buff_, read_io_buff_size_, 0, NULL, fn, NULL, NULL); + io_ctx_ = avio_alloc_context(read_io_buff_, read_io_buff_size_, 0, opaque, fn, NULL, NULL);//opaque if(!io_ctx_){ logIt("open with custom io create custom avio error"); return -1; } ctx_->pb = io_ctx_; - auto err = av_probe_input_buffer(io_ctx_, &ctx_->iformat, NULL, NULL, 0, read_io_buff_size_); + 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"); + logIt("open with custom io prob input buffer error:%d", err); + logIt("failed:%s", getAVErrorDesc(err).c_str()); return -1; } + return 0; } + int FormatIn::openGb28181(const char *filename, AVDictionary **options){ + + std::string fn = filename; + //GB28181API gb28181(fn); + if (handle_gb28181){ + delete handle_gb28181; + } + handle_gb28181 = new GB28181API; + handle_gb28181->addCamera(fn); + + int ret = openWithCustomIO((void *)&handle_gb28181, handle_gb28181->readData, options); + if(ret < 0){ + logIt("do openWithCustomIO failed:%d",ret); + } + + ret = avformat_open_input(&ctx_, "", NULL, options); + if(ret < 0){ + logIt("open %s failed:%s",filename, + getAVErrorDesc(ret).c_str()); + + } + + return ret; + } + ///////////////////////////////////////////////////////////////////////// int FormatIn::open(const char *filename, AVDictionary **options){ -- Gitblit v1.8.0