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-01 18:55:56 +08:00
|
|
|
#include "selfdrive/ui/replay/filereader.h"
|
2020-01-18 02:07:22 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2021-10-29 18:14:14 +08:00
|
|
|
#include <libswscale/swscale.h>
|
|
|
|
#include <libavutil/imgutils.h>
|
2020-01-18 02:07:22 +08:00
|
|
|
}
|
|
|
|
|
2021-11-01 18:55:56 +08:00
|
|
|
class FrameReader : protected FileReader {
|
2020-01-18 02:07:22 +08:00
|
|
|
public:
|
2021-11-01 18:55:56 +08:00
|
|
|
FrameReader(bool local_cache = false, int chunk_size = -1, int retries = 0);
|
2021-05-25 08:01:15 +08:00
|
|
|
~FrameReader();
|
2021-11-01 18:55:56 +08:00
|
|
|
bool load(const std::string &url, std::atomic<bool> *abort = nullptr);
|
2021-10-19 05:19:23 +08:00
|
|
|
bool get(int idx, uint8_t *rgb, uint8_t *yuv);
|
2021-09-10 04:40:12 +08:00
|
|
|
int getRGBSize() const { return width * height * 3; }
|
2021-10-04 22:45:28 +08:00
|
|
|
int getYUVSize() const { return width * height * 3 / 2; }
|
2021-09-10 04:40:12 +08:00
|
|
|
size_t getFrameCount() const { return frames_.size(); }
|
2021-06-08 14:31:59 +08:00
|
|
|
bool valid() const { return valid_; }
|
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
|
|
|
|
2020-01-18 02:07:22 +08:00
|
|
|
private:
|
2021-10-19 05:19:23 +08:00
|
|
|
bool decode(int idx, uint8_t *rgb, uint8_t *yuv);
|
|
|
|
bool decodeFrame(AVFrame *f, uint8_t *rgb, uint8_t *yuv);
|
|
|
|
|
2021-06-08 14:31:59 +08:00
|
|
|
struct Frame {
|
|
|
|
AVPacket pkt = {};
|
2021-10-19 05:19:23 +08:00
|
|
|
int decoded = false;
|
2021-06-08 14:31:59 +08:00
|
|
|
bool failed = false;
|
2021-05-25 08:01:15 +08:00
|
|
|
};
|
2021-06-08 14:31:59 +08:00
|
|
|
std::vector<Frame> frames_;
|
2021-11-01 18:06:00 +08:00
|
|
|
SwsContext *rgb_sws_ctx_ = nullptr, *yuv_sws_ctx_ = nullptr;
|
|
|
|
AVFrame *av_frame_, *rgb_frame_, *yuv_frame_ = nullptr;
|
2021-09-10 04:40:12 +08:00
|
|
|
AVFormatContext *pFormatCtx_ = nullptr;
|
|
|
|
AVCodecContext *pCodecCtx_ = nullptr;
|
2021-10-19 05:19:23 +08:00
|
|
|
int key_frames_count_ = 0;
|
2021-06-08 14:31:59 +08:00
|
|
|
bool valid_ = false;
|
2021-11-01 18:55:56 +08:00
|
|
|
AVIOContext *avio_ctx_ = nullptr;
|
2020-01-18 02:07:22 +08:00
|
|
|
};
|