| | |
| | | ${CMAKE_SOURCE_DIR}/csrc/thirdparty |
| | | ${CMAKE_SOURCE_DIR}/csrc/thirdparty/whereami |
| | | ${CMAKE_SOURCE_DIR}/csrc/thirdparty/ffmpeg/include |
| | | ${CMAKE_SOURCE_DIR}/csrc/thirdparty/gb28181/include |
| | | ) |
| | | |
| | | link_directories(/usr/local/cuda/lib64) |
| | | link_directories(/usr/local/cuda/lib64 ${CMAKE_SOURCE_DIR}/csrc/thirdparty/gb28181/lib) |
| | | |
| | | set(CMAKE_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/csrc/thirdparty/ffmpeg/lib ${CMAKE_LIBRARY_PATH}) |
| | | find_library(avutil NAMES libavutil.a ) |
| | |
| | | |
| | | add_library(${BIN} SHARED ${FFMPEG_LIST} ${CMAKE_SOURCE_DIR}/csrc/cffmpeg.cpp) |
| | | |
| | | target_link_libraries(${BIN} ${LINK_LIB} numa nppig nppicc nppc -lz pthread dl) |
| | | target_link_libraries(${BIN} ${LINK_LIB} numa nppig nppicc nppc -lz pthread dl rtspclient StreamParse) |
| | |
| | | #include <libavutil/opt.h> |
| | | #include <libavcodec/avcodec.h> |
| | | #include <libavfilter/avfilter.h> |
| | | #include <libavfilter/avfiltergraph.h> |
| | | //#include <libavfilter/avfiltergraph.h> |
| | | #include <libavfilter/buffersink.h> |
| | | #include <libavfilter/buffersrc.h> |
| | | } |
| | |
| | | #include "../data/FrameData.hpp" |
| | | |
| | | #include "../../common/gpu/info.h" |
| | | #include "PsToEs.hpp" |
| | | |
| | | using namespace logif; |
| | | |
| | |
| | | } |
| | | |
| | | //////////////////////////////////////////////////////////////////////// |
| | | 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"); |
| | |
| | | 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; |
| | | addCamera(fn); |
| | | |
| | | int ret = openWithCustomIO(NULL, 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){ |
| | | |
| | |
| | | ~FormatIn(); |
| | | |
| | | public: |
| | | int openWithCustomIO(read_packet fn, AVDictionary **options=NULL); |
| | | int openWithCustomIO(void *opaque, read_packet fn, AVDictionary **options=NULL); |
| | | int openGb28181(const char *filename, AVDictionary **options); |
| | | |
| | | int open(const char *filename, AVDictionary **options); |
| | | bool findStreamInfo(AVDictionary **options); |
| | |
| | | return nullptr; |
| | | } |
| | | |
| | | ffwrapper::FormatIn* Wrapper::init_reader_gb28181(const char* input){ |
| | | |
| | | VideoProp prop; |
| | | prop.url_ = input; |
| | | prop.rtsp_tcp_ = true; |
| | | |
| | | // std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl())); |
| | | ffwrapper::FormatIn* in(new FormatIn(prop.gpuAccl())); |
| | | AVDictionary *avdic = prop.optsFormat(); |
| | | int flag = in->openGb28181(input, &avdic); |
| | | if(avdic){ |
| | | logIt("ERROR:in->openGb28181(input, &avdic):flag:%d\n",flag); |
| | | av_dict_free(&avdic); |
| | | } |
| | | if(flag == 0){ |
| | | if(!in->findStreamInfo(NULL)){ |
| | | logIt("yolo can't find video stream\n"); |
| | | return nullptr; |
| | | } |
| | | bool flag = true; |
| | | if(map_workers_.find(WORKER_DECODER) != map_workers_.end()){ |
| | | flag = in->openCodec(AVMEDIA_TYPE_VIDEO, NULL); |
| | | auto dec_ctx = in->getCodecContext(); |
| | | if(bridge_)delete bridge_; |
| | | |
| | | scale_w_ = scale_w_ == 0 || scale_w_ > dec_ctx->width ? dec_ctx->width : scale_w_; |
| | | scale_h_ = scale_h_ == 0 || scale_h_ > dec_ctx->height ? dec_ctx->height : scale_h_; |
| | | |
| | | AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24; |
| | | bridge_ = new cvbridge( |
| | | dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, |
| | | scale_w_, scale_h_, pix_fmt, scale_f_); |
| | | |
| | | } |
| | | if (!flag){ |
| | | logIt("FormatIn openCodec Failed!"); |
| | | return nullptr; |
| | | } |
| | | return in; |
| | | } |
| | | |
| | | return nullptr; |
| | | } |
| | | |
| | | int Wrapper::init_recorder(FormatIn *in, std::string dir, const int mind, const int maxd){ |
| | | if(!in){ |
| | | logIt("Init wrapper first"); |
| | |
| | | |
| | | void Wrapper::run_stream_thread(){ |
| | | while(!stop_stream_.load()){ |
| | | auto in = init_reader(input_url_.c_str()); |
| | | //auto in = init_reader(input_url_.c_str()); |
| | | ffwrapper::FormatIn * in = init_reader_gb28181(input_url_.c_str()); |
| | | if (!in) { |
| | | logIt("ERROR: init_reader_gb28181!\n"); |
| | | usleep(200000); |
| | | continue; |
| | | } |
| | |
| | | |
| | | private: |
| | | std::unique_ptr<ffwrapper::FormatIn> init_reader(const char* input); |
| | | ffwrapper::FormatIn* init_reader_gb28181(const char* input); |
| | | void init_worker(ffwrapper::FormatIn *in); |
| | | int init_recorder(ffwrapper::FormatIn *in, std::string dir, const int mind, const int maxd); |
| | | void run_worker(ffwrapper::FormatIn *in, buz::avpacket &pkt); |