2021-05-25 08:01:15 +08:00
|
|
|
#pragma once
|
2020-01-18 02:07:22 +08:00
|
|
|
|
2021-05-25 08:01:15 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-11-14 03:55:04 +08:00
|
|
|
|
2024-06-07 05:31:56 +08:00
|
|
|
#include "msgq/visionipc/visionbuf.h"
|
2022-06-28 22:12:42 +08:00
|
|
|
#include "tools/replay/filereader.h"
|
2024-09-20 01:33:24 +08:00
|
|
|
#include "tools/replay/util.h"
|
2020-01-18 02:07:22 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
}
|
|
|
|
|
2024-04-25 10:44:18 +08:00
|
|
|
class VideoDecoder;
|
2021-11-17 18:17:59 +08:00
|
|
|
|
2021-11-29 21:10:24 +08:00
|
|
|
class FrameReader {
|
2020-01-18 02:07:22 +08:00
|
|
|
public:
|
2021-11-29 21:10:24 +08:00
|
|
|
FrameReader();
|
2021-05-25 08:01:15 +08:00
|
|
|
~FrameReader();
|
2024-04-25 10:44:18 +08:00
|
|
|
bool load(CameraType type, const std::string &url, bool no_hw_decoder = false, std::atomic<bool> *abort = nullptr, bool local_cache = false,
|
2022-05-15 10:55:12 +08:00
|
|
|
int chunk_size = -1, int retries = 0);
|
2024-04-25 10:44:18 +08:00
|
|
|
bool loadFromFile(CameraType type, const std::string &file, bool no_hw_decoder = false, std::atomic<bool> *abort = nullptr);
|
2023-08-24 15:03:16 +08:00
|
|
|
bool get(int idx, VisionBuf *buf);
|
2024-04-18 01:05:32 +08:00
|
|
|
size_t getFrameCount() const { return packets_info.size(); }
|
2021-04-24 15:59:09 +08:00
|
|
|
|
2021-05-25 08:01:15 +08:00
|
|
|
int width = 0, height = 0;
|
2021-04-24 15:59:09 +08:00
|
|
|
|
2024-04-25 10:44:18 +08:00
|
|
|
VideoDecoder *decoder_ = nullptr;
|
2021-11-17 18:17:59 +08:00
|
|
|
AVFormatContext *input_ctx = nullptr;
|
2021-11-29 19:09:14 +08:00
|
|
|
int prev_idx = -1;
|
2024-04-18 01:05:32 +08:00
|
|
|
struct PacketInfo {
|
|
|
|
int flags;
|
|
|
|
int64_t pos;
|
|
|
|
};
|
|
|
|
std::vector<PacketInfo> packets_info;
|
2024-04-25 10:44:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class VideoDecoder {
|
|
|
|
public:
|
|
|
|
VideoDecoder();
|
|
|
|
~VideoDecoder();
|
|
|
|
bool open(AVCodecParameters *codecpar, bool hw_decoder);
|
|
|
|
bool decode(FrameReader *reader, int idx, VisionBuf *buf);
|
|
|
|
int width = 0, height = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool initHardwareDecoder(AVHWDeviceType hw_device_type);
|
|
|
|
AVFrame *decodeFrame(AVPacket *pkt);
|
|
|
|
bool copyBuffer(AVFrame *f, VisionBuf *buf);
|
|
|
|
|
|
|
|
AVFrame *av_frame_, *hw_frame_;
|
|
|
|
AVCodecContext *decoder_ctx = nullptr;
|
|
|
|
AVPixelFormat hw_pix_fmt = AV_PIX_FMT_NONE;
|
|
|
|
AVBufferRef *hw_device_ctx = nullptr;
|
2020-01-18 02:07:22 +08:00
|
|
|
};
|