| | |
| | | |
| | | project(${BIN}) |
| | | |
| | | # set(CMAKE_C_VISIBILITY_PRESET hidden) |
| | | # set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
| | | if(NOT CMAKE_BUILD_TYPE) |
| | | set(CMAKE_BUILD_TYPE "Release") |
| | | endif() |
| | | |
| | | set(CMAKE_CXX_FLAGS "-DLIB_CFFMPEG -fPIC -Wl,-Bsymbolic ${CMAKE_CXX_FLAGS}") |
| | | set(CMAKE_C_FLAGS "-DLIB_CFFMPEG -fPIC -Wl,-Bsymbolic ${CMAKE_C_FLAGS}") |
| | |
| | | void* c_ffmpeg_get_avpacket(const cffmpeg h, int *size, int *key); |
| | | int c_ffmpeg_get_avpacket2(const cffmpeg h, unsigned char **data, int *size, int *key); |
| | | |
| | | void c_ffmpeg_release_buf(void* buf); |
| | | |
| | | // pic encoder |
| | | void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi); |
| | | void c_ffmpeg_destroy_encoder(void *h); |
| | |
| | | return s->GetPacket(data, size, key); |
| | | } |
| | | |
| | | void c_ffmpeg_release_buf(void* buf){ |
| | | if (buf){ |
| | | free(buf); |
| | | } |
| | | } |
| | | |
| | | // pic encoder |
| | | void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi){ |
| | | return CreateEncoder(w, h, fps, br, pix_fmt, scale_flag, gi); |
| | |
| | | |
| | | if(io_ctx_){ |
| | | av_freep(&io_ctx_->buffer); |
| | | avio_context_free(&io_ctx_); |
| | | av_freep(&io_ctx_); |
| | | io_ctx_ = NULL; |
| | | } |
| | | |
| | |
| | | list_recInfo_.emplace_back(info); |
| | | } |
| | | |
| | | void rec::findRecFramesIndex(const int64_t &fired_id, const int duration, int &start, int &end){ |
| | | void rec::findRecFramesIndex(int64_t &fired_id, const int duration, int &start, int &end){ |
| | | |
| | | start = end = -1; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | // 如果fired_id在startid之前,将其放入start_id之后 |
| | | if (start_id > fired_id) fired_id = start_id + duration / 2; |
| | | |
| | | if (end < 0) end = index; |
| | | } |
| | | |
| | |
| | | std::lock_guard<std::mutex> locker(mtx_pkt_); |
| | | logIt("cache size: %ld", list_pkt_.size()); |
| | | // 首次获取录像信息,先存一个最短时长 |
| | | findRecFramesIndex(frameID, duration, start, end); |
| | | rec->StartWritePacket(list_pkt_, frameID, start, end); |
| | | // maybe fired_id changed by findRecFramesIndex |
| | | int64_t fired_id = frameID; |
| | | findRecFramesIndex(fired_id, duration, start, end); |
| | | rec->StartWritePacket(list_pkt_, fired_id, start, end); |
| | | |
| | | return rec; |
| | | } |
| | |
| | | |
| | | private: |
| | | // 查找缓存中的录制帧 |
| | | void findRecFramesIndex(const int64_t &fired_id, const int duration, int &start, int &end); |
| | | void findRecFramesIndex(int64_t &fired_id, const int duration, int &start, int &end); |
| | | |
| | | // 录像实例的回调函数,录像完成后设置录像文件路径,id和帧id |
| | | void setRecInfo(std::string &id, int &index, std::string &path); |
| | |
| | | } |
| | | return fn_get_avpacket2(h, data, size, key); |
| | | } |
| | | |
| | | void wrap_fn_release_buf(void *lib, void *buf){ |
| | | if (!fn_release_buf){ |
| | | fn_release_buf = (lib_cffmpeg_release_buf)dlsym(lib, "c_ffmpeg_release_buf"); |
| | | } |
| | | if (fn_release_buf) fn_release_buf(buf); |
| | | } |
| | | // for encoder |
| | | cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi){ |
| | | if (!fn_create_encoder){ |
| | |
| | | typedef void (*lib_cffmpeg_close_stream)(const cffmpeg); |
| | | typedef void*(*lib_cffmpeg_avpacket)(const cffmpeg, int*, int*); |
| | | typedef int (*lib_cffmpeg_avpacket2)(const cffmpeg, unsigned char**, int*, int*); |
| | | typedef void(*lib_cffmpeg_release_buf) (void*); |
| | | |
| | | static lib_cffmpeg_create fn_create = NULL; |
| | | static lib_cffmpeg_create2 fn_create2 = NULL; |
| | |
| | | static lib_cffmpeg_close_stream fn_close_stream = NULL; |
| | | static lib_cffmpeg_avpacket fn_get_avpacket = NULL; |
| | | static lib_cffmpeg_avpacket2 fn_get_avpacket2 = NULL; |
| | | static lib_cffmpeg_release_buf fn_release_buf = NULL; |
| | | |
| | | typedef void* libcffmpeg; |
| | | libcffmpeg init_libcffmpeg(const char *so_file); |
| | |
| | | void wrap_fn_close_stream(void *lib, const cffmpeg h); |
| | | void* wrap_fn_get_avpacket(void *lib, const cffmpeg h, int* size, int* key); |
| | | int wrap_fn_get_avpacket2(void *lib, const cffmpeg h, unsigned char **data, int* size, int* key); |
| | | void wrap_fn_release_buf(void *lib, void *buf); |
| | | |
| | | // for encoder |
| | | typedef void* cencoder; |
| | | typedef cencoder (*lib_cffmpeg_create_encoder)(const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi); |