#ifndef _cffmpeg_buz_recorder_hpp_ #define _cffmpeg_buz_recorder_hpp_ #include #include #include #include #include #include #include #include #include "../common/callback.hpp" namespace ffwrapper{ class FormatIn; class FormatOut; class CodedData; } namespace cffmpeg_wrap{ namespace buz{ struct avpacket{ std::shared_ptr data; int64_t id; }; class Recorder{ public: explicit Recorder(ffwrapper::FormatIn *in); ~Recorder(); public: int Run(const char* output, const int mind, const int maxd); int CachePacket(const avpacket &pkt); int FireRecorder(const int64_t &id); void SetCallback(FUNC_REC_INFO cb){ func_rec_info_ = cb; } private: void run_thread(); int init_writer(); void start_writer(); int write_correctly(const avpacket &pkt); void end_writer(); void maybe_dump_gop(); private: ffwrapper::FormatIn *in_; ffwrapper::FormatOut *out_; int maxduration; int minduration; int end_frame; int cur_frame; std::list list_pkt_; std::unique_ptr thread_; std::atomic_bool stop_recorder_; std::mutex mutex_pkt_; std::condition_variable cv_; std::string dir_; int64_t id_frame_; int file_frame_index_; std::string file_path_; FUNC_REC_INFO func_rec_info_; }; } } #endif