You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
4 years ago
|
#pragma once
|
||
5 years ago
|
|
||
3 years ago
|
#include <memory>
|
||
4 years ago
|
#include <string>
|
||
|
#include <vector>
|
||
4 years ago
|
|
||
3 years ago
|
#include "tools/replay/filereader.h"
|
||
5 years ago
|
|
||
|
extern "C" {
|
||
|
#include <libavcodec/avcodec.h>
|
||
|
#include <libavformat/avformat.h>
|
||
|
}
|
||
|
|
||
3 years ago
|
struct AVFrameDeleter {
|
||
|
void operator()(AVFrame* frame) const { av_frame_free(&frame); }
|
||
|
};
|
||
|
|
||
3 years ago
|
class FrameReader {
|
||
5 years ago
|
public:
|
||
3 years ago
|
FrameReader();
|
||
4 years ago
|
~FrameReader();
|
||
3 years ago
|
bool load(const std::string &url, bool no_hw_decoder = false, std::atomic<bool> *abort = nullptr, bool local_cache = false,
|
||
|
int chunk_size = -1, int retries = 0);
|
||
3 years ago
|
bool load(const std::byte *data, size_t size, bool no_hw_decoder = false, std::atomic<bool> *abort = nullptr);
|
||
3 years ago
|
bool get(int idx, uint8_t *yuv);
|
||
4 years ago
|
int getYUVSize() const { return width * height * 3 / 2; }
|
||
3 years ago
|
size_t getFrameCount() const { return packets.size(); }
|
||
4 years ago
|
bool valid() const { return valid_; }
|
||
4 years ago
|
|
||
4 years ago
|
int width = 0, height = 0;
|
||
3 years ago
|
int aligned_width = 0, aligned_height = 0;
|
||
4 years ago
|
|
||
5 years ago
|
private:
|
||
3 years ago
|
bool initHardwareDecoder(AVHWDeviceType hw_device_type);
|
||
3 years ago
|
bool decode(int idx, uint8_t *yuv);
|
||
3 years ago
|
AVFrame * decodeFrame(AVPacket *pkt);
|
||
3 years ago
|
bool copyBuffers(AVFrame *f, uint8_t *yuv);
|
||
4 years ago
|
|
||
3 years ago
|
std::vector<AVPacket*> packets;
|
||
3 years ago
|
std::unique_ptr<AVFrame, AVFrameDeleter>av_frame_, hw_frame;
|
||
3 years ago
|
AVFormatContext *input_ctx = nullptr;
|
||
|
AVCodecContext *decoder_ctx = nullptr;
|
||
4 years ago
|
int key_frames_count_ = 0;
|
||
4 years ago
|
bool valid_ = false;
|
||
4 years ago
|
AVIOContext *avio_ctx_ = nullptr;
|
||
3 years ago
|
|
||
|
AVPixelFormat hw_pix_fmt = AV_PIX_FMT_NONE;
|
||
|
AVBufferRef *hw_device_ctx = nullptr;
|
||
3 years ago
|
int prev_idx = -1;
|
||
3 years ago
|
inline static std::atomic<bool> has_hw_decoder = true;
|
||
5 years ago
|
};
|