mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 20:03:53 +08:00
loggerd: prereqs for deanlee loggerd omx encoder (try 2) (#24252)
* refactor encoders * fix pc build * buf_info Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -64,11 +64,12 @@ void encoder_thread(LoggerdState *s, const LogCameraInfo &cam_info) {
|
||||
// main encoder
|
||||
encoders.push_back(new Encoder(cam_info.filename, cam_info.type, buf_info.width, buf_info.height,
|
||||
cam_info.fps, cam_info.bitrate, cam_info.is_h265,
|
||||
cam_info.downscale, cam_info.record));
|
||||
buf_info.width, buf_info.height, cam_info.record));
|
||||
// qcamera encoder
|
||||
if (cam_info.has_qcamera) {
|
||||
encoders.push_back(new Encoder(qcam_info.filename, cam_info.type, qcam_info.frame_width, qcam_info.frame_height,
|
||||
qcam_info.fps, qcam_info.bitrate, qcam_info.is_h265, qcam_info.downscale));
|
||||
encoders.push_back(new Encoder(qcam_info.filename, cam_info.type, buf_info.width, buf_info.height,
|
||||
qcam_info.fps, qcam_info.bitrate, qcam_info.is_h265,
|
||||
qcam_info.frame_width, qcam_info.frame_height));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ struct LogCameraInfo {
|
||||
int fps;
|
||||
int bitrate;
|
||||
bool is_h265;
|
||||
bool downscale;
|
||||
bool has_qcamera;
|
||||
bool trigger_rotate;
|
||||
bool enable;
|
||||
@@ -64,7 +63,6 @@ const LogCameraInfo cameras_logged[] = {
|
||||
.fps = MAIN_FPS,
|
||||
.bitrate = MAIN_BITRATE,
|
||||
.is_h265 = true,
|
||||
.downscale = false,
|
||||
.has_qcamera = true,
|
||||
.trigger_rotate = true,
|
||||
.enable = true,
|
||||
@@ -77,7 +75,6 @@ const LogCameraInfo cameras_logged[] = {
|
||||
.fps = MAIN_FPS,
|
||||
.bitrate = DCAM_BITRATE,
|
||||
.is_h265 = true,
|
||||
.downscale = false,
|
||||
.has_qcamera = false,
|
||||
.trigger_rotate = true,
|
||||
.enable = true,
|
||||
@@ -90,7 +87,6 @@ const LogCameraInfo cameras_logged[] = {
|
||||
.fps = MAIN_FPS,
|
||||
.bitrate = MAIN_BITRATE,
|
||||
.is_h265 = true,
|
||||
.downscale = false,
|
||||
.has_qcamera = false,
|
||||
.trigger_rotate = true,
|
||||
.enable = Hardware::TICI(),
|
||||
@@ -102,7 +98,6 @@ const LogCameraInfo qcam_info = {
|
||||
.fps = MAIN_FPS,
|
||||
.bitrate = 256000,
|
||||
.is_h265 = false,
|
||||
.downscale = true,
|
||||
.frame_width = Hardware::TICI() ? 526 : 480,
|
||||
.frame_height = Hardware::TICI() ? 330 : 360 // keep pixel count the same?
|
||||
};
|
||||
|
||||
@@ -154,16 +154,15 @@ static const char* omx_color_fomat_name(uint32_t format) {
|
||||
|
||||
|
||||
// ***** encoder functions *****
|
||||
OmxEncoder::OmxEncoder(const char* filename, CameraType type, int width, int height, int fps, int bitrate, bool h265, bool downscale, bool write) {
|
||||
OmxEncoder::OmxEncoder(const char* filename, CameraType type, int in_width, int in_height, int fps, int bitrate, bool h265, int out_width, int out_height, bool write)
|
||||
: in_width_(in_width), in_height_(in_height), width(out_width), height(out_height) {
|
||||
this->filename = filename;
|
||||
this->type = type;
|
||||
this->write = write;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->fps = fps;
|
||||
this->remuxing = !h265;
|
||||
|
||||
this->downscale = downscale;
|
||||
this->downscale = in_width != out_width || in_height != out_height;
|
||||
if (this->downscale) {
|
||||
this->y_ptr2 = (uint8_t *)malloc(this->width*this->height);
|
||||
this->u_ptr2 = (uint8_t *)malloc(this->width*this->height/4);
|
||||
@@ -464,6 +463,8 @@ void OmxEncoder::handle_out_buf(OmxEncoder *e, OmxBuffer *out_buf) {
|
||||
|
||||
int OmxEncoder::encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr,
|
||||
int in_width, int in_height, uint64_t ts) {
|
||||
assert(in_width == this->in_width_);
|
||||
assert(in_height == this->in_height_);
|
||||
int err;
|
||||
if (!this->is_open) {
|
||||
return -1;
|
||||
|
||||
@@ -22,7 +22,7 @@ struct OmxBuffer {
|
||||
// OmxEncoder, lossey codec using hardware hevc
|
||||
class OmxEncoder : public VideoEncoder {
|
||||
public:
|
||||
OmxEncoder(const char* filename, CameraType type, int width, int height, int fps, int bitrate, bool h265, bool downscale, bool write = true);
|
||||
OmxEncoder(const char* filename, CameraType type, int width, int height, int fps, int bitrate, bool h265, int out_width, int out_height, bool write = true);
|
||||
~OmxEncoder();
|
||||
int encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr,
|
||||
int in_width, int in_height, uint64_t ts);
|
||||
@@ -43,6 +43,7 @@ private:
|
||||
static void write_and_broadcast_handler(OmxEncoder *e);
|
||||
static void handle_out_buf(OmxEncoder *e, OmxBuffer *out_buf);
|
||||
|
||||
int in_width_, in_height_;
|
||||
int width, height, fps;
|
||||
char vid_path[1024];
|
||||
char lock_path[1024];
|
||||
|
||||
@@ -22,9 +22,9 @@ extern "C" {
|
||||
#include "selfdrive/common/swaglog.h"
|
||||
#include "selfdrive/common/util.h"
|
||||
|
||||
RawLogger::RawLogger(const char* filename, CameraType type, int width, int height, int fps,
|
||||
int bitrate, bool h265, bool downscale, bool write)
|
||||
: filename(filename), fps(fps) {
|
||||
RawLogger::RawLogger(const char* filename, CameraType type, int in_width, int in_height, int fps,
|
||||
int bitrate, bool h265, int out_width, int out_height, bool write)
|
||||
: in_width_(in_width), in_height_(in_height), filename(filename), fps(fps) {
|
||||
|
||||
// TODO: respect write arg
|
||||
|
||||
@@ -34,8 +34,8 @@ RawLogger::RawLogger(const char* filename, CameraType type, int width, int heigh
|
||||
|
||||
codec_ctx = avcodec_alloc_context3(codec);
|
||||
assert(codec_ctx);
|
||||
codec_ctx->width = width;
|
||||
codec_ctx->height = height;
|
||||
codec_ctx->width = out_width;
|
||||
codec_ctx->height = out_height;
|
||||
codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||
|
||||
// codec_ctx->thread_count = 2;
|
||||
@@ -51,14 +51,14 @@ RawLogger::RawLogger(const char* filename, CameraType type, int width, int heigh
|
||||
frame = av_frame_alloc();
|
||||
assert(frame);
|
||||
frame->format = codec_ctx->pix_fmt;
|
||||
frame->width = width;
|
||||
frame->height = height;
|
||||
frame->linesize[0] = width;
|
||||
frame->linesize[1] = width/2;
|
||||
frame->linesize[2] = width/2;
|
||||
frame->width = out_width;
|
||||
frame->height = out_height;
|
||||
frame->linesize[0] = out_width;
|
||||
frame->linesize[1] = out_width/2;
|
||||
frame->linesize[2] = out_width/2;
|
||||
|
||||
if (downscale) {
|
||||
downscale_buf.resize(width * height * 3 / 2);
|
||||
if (in_width != out_width || in_height != out_height) {
|
||||
downscale_buf.resize(out_width * out_height * 3 / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,8 @@ void RawLogger::encoder_close() {
|
||||
|
||||
int RawLogger::encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr,
|
||||
int in_width, int in_height, uint64_t ts) {
|
||||
assert(in_width == this->in_width_);
|
||||
assert(in_height == this->in_height_);
|
||||
AVPacket pkt;
|
||||
av_init_packet(&pkt);
|
||||
pkt.data = NULL;
|
||||
|
||||
@@ -15,8 +15,8 @@ extern "C" {
|
||||
|
||||
class RawLogger : public VideoEncoder {
|
||||
public:
|
||||
RawLogger(const char* filename, CameraType type, int width, int height, int fps,
|
||||
int bitrate, bool h265, bool downscale, bool write = true);
|
||||
RawLogger(const char* filename, CameraType type, int in_width, int in_height, int fps,
|
||||
int bitrate, bool h265, int out_width, int out_height, bool write = true);
|
||||
~RawLogger();
|
||||
int encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr,
|
||||
int in_width, int in_height, uint64_t ts);
|
||||
@@ -30,6 +30,7 @@ private:
|
||||
int counter = 0;
|
||||
bool is_open = false;
|
||||
|
||||
int in_width_, in_height_;
|
||||
std::string vid_path, lock_path;
|
||||
|
||||
const AVCodec *codec = NULL;
|
||||
|
||||
Reference in New Issue
Block a user