DvppSnapshot.h 1.88 KB
#include<string>

#include "depend_headers.h"
#include "dvpp_headers.h"
#include "DvppDataMemory.hpp"

#include <queue>
#include <mutex>
#include <thread>
#include <chrono>
#include <atomic>
#include <memory>

using namespace std;

typedef void(*RECEIVER_FINISHED_CALLBACK)(const void* userPtr);


struct Vdec_CallBack_UserData;

class DvppSnapshot{
public:
    DvppSnapshot();
    ~DvppSnapshot();

    bool init(FFDecConfig cfg);

    DvppDataMemory* snapshot();

public:
    void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData);
    void doProcessReport();

private:
    AVCodecContext* init_FFmpeg(FFDecConfig config);
    bool init_vdpp(FFDecConfig cfg, AVCodecContext* avctx);
    void release_ffmpeg();
    
    int sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, unsigned long long frame_nb);
    bool sendVdecEos(aclvdecChannelDesc *vdecChannelDesc);
    void release_dvpp();

    int getVdecType(int videoType, int profile);

    void calcOutResolution(int w, int h);

private:
    FFDecConfig m_cfg;
    string m_dec_name;

    bool m_bFinished{false};
    bool m_bRunning{false};

    bool m_bExitReportThd{false};

    // 读取数据
    int video_index{-1};
    AVFormatContext *fmt_ctx{nullptr};
    AVPixelFormat pix_fmt;
    AVCodecContext *avctx{nullptr};
    AVBSFContext * h264bsfc{nullptr};

    int frame_width{0};
	int frame_height{0};
    int out_frame_width{0};
	int out_frame_height{0};
    bool m_bReal {false}; // 是否实时流
    float m_fps{0.0};

    bool m_bResize {false};

    // 解码
    int m_dvpp_deviceId {-1};
    int m_dvpp_channel {-1};
    aclrtContext m_context{nullptr};
    acldvppStreamFormat m_enType;

    int m_vdec_out_size {-1};

    queue<DvppDataMemory*> m_decoded_data_queue;
    mutex m_decoded_data_queue_mtx;

    uint64_t m_in_count {0};
    uint64_t m_out_count {0};

    std::atomic<int> m_DvppCacheCounter{0};
};