Files
dragonpilot/selfdrive/ui/replay/framereader.h
Dean Lee 0189a19b8e replay: refactor FrameReader (#22438)
* decode from the previous keyframe after seek

* less memory

* some stream seems to contian no keyframes

* test random seek

* merge master

* continue

update test_cases

use fr

* merge master
2021-10-18 14:19:23 -07:00

41 lines
976 B
C++

#pragma once
#include <string>
#include <vector>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
class FrameReader {
public:
FrameReader();
~FrameReader();
bool load(const std::string &url);
bool get(int idx, uint8_t *rgb, uint8_t *yuv);
int getRGBSize() const { return width * height * 3; }
int getYUVSize() const { return width * height * 3 / 2; }
size_t getFrameCount() const { return frames_.size(); }
bool valid() const { return valid_; }
int width = 0, height = 0;
private:
bool decode(int idx, uint8_t *rgb, uint8_t *yuv);
bool decodeFrame(AVFrame *f, uint8_t *rgb, uint8_t *yuv);
struct Frame {
AVPacket pkt = {};
int decoded = false;
bool failed = false;
};
std::vector<Frame> frames_;
AVFrame *av_frame_ = nullptr;
AVFormatContext *pFormatCtx_ = nullptr;
AVCodecContext *pCodecCtx_ = nullptr;
int key_frames_count_ = 0;
std::vector<uint8_t> yuv_buf_;
bool valid_ = false;
};