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>
old-commit-hash: 0ac35a656a
taco
George Hotz 3 years ago committed by GitHub
parent 5a9644261f
commit 6dde52671b
  1. 7
      selfdrive/loggerd/loggerd.cc
  2. 5
      selfdrive/loggerd/loggerd.h
  3. 9
      selfdrive/loggerd/omx_encoder.cc
  4. 3
      selfdrive/loggerd/omx_encoder.h
  5. 28
      selfdrive/loggerd/raw_logger.cc
  6. 5
      selfdrive/loggerd/raw_logger.h

@ -64,11 +64,12 @@ void encoder_thread(LoggerdState *s, const LogCameraInfo &cam_info) {
// main encoder // main encoder
encoders.push_back(new Encoder(cam_info.filename, cam_info.type, buf_info.width, buf_info.height, 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.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 // qcamera encoder
if (cam_info.has_qcamera) { if (cam_info.has_qcamera) {
encoders.push_back(new Encoder(qcam_info.filename, cam_info.type, qcam_info.frame_width, qcam_info.frame_height, 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.downscale)); 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 fps;
int bitrate; int bitrate;
bool is_h265; bool is_h265;
bool downscale;
bool has_qcamera; bool has_qcamera;
bool trigger_rotate; bool trigger_rotate;
bool enable; bool enable;
@ -64,7 +63,6 @@ const LogCameraInfo cameras_logged[] = {
.fps = MAIN_FPS, .fps = MAIN_FPS,
.bitrate = MAIN_BITRATE, .bitrate = MAIN_BITRATE,
.is_h265 = true, .is_h265 = true,
.downscale = false,
.has_qcamera = true, .has_qcamera = true,
.trigger_rotate = true, .trigger_rotate = true,
.enable = true, .enable = true,
@ -77,7 +75,6 @@ const LogCameraInfo cameras_logged[] = {
.fps = MAIN_FPS, .fps = MAIN_FPS,
.bitrate = DCAM_BITRATE, .bitrate = DCAM_BITRATE,
.is_h265 = true, .is_h265 = true,
.downscale = false,
.has_qcamera = false, .has_qcamera = false,
.trigger_rotate = true, .trigger_rotate = true,
.enable = true, .enable = true,
@ -90,7 +87,6 @@ const LogCameraInfo cameras_logged[] = {
.fps = MAIN_FPS, .fps = MAIN_FPS,
.bitrate = MAIN_BITRATE, .bitrate = MAIN_BITRATE,
.is_h265 = true, .is_h265 = true,
.downscale = false,
.has_qcamera = false, .has_qcamera = false,
.trigger_rotate = true, .trigger_rotate = true,
.enable = Hardware::TICI(), .enable = Hardware::TICI(),
@ -102,7 +98,6 @@ const LogCameraInfo qcam_info = {
.fps = MAIN_FPS, .fps = MAIN_FPS,
.bitrate = 256000, .bitrate = 256000,
.is_h265 = false, .is_h265 = false,
.downscale = true,
.frame_width = Hardware::TICI() ? 526 : 480, .frame_width = Hardware::TICI() ? 526 : 480,
.frame_height = Hardware::TICI() ? 330 : 360 // keep pixel count the same? .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 ***** // ***** 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->filename = filename;
this->type = type; this->type = type;
this->write = write; this->write = write;
this->width = width;
this->height = height;
this->fps = fps; this->fps = fps;
this->remuxing = !h265; this->remuxing = !h265;
this->downscale = downscale; this->downscale = in_width != out_width || in_height != out_height;
if (this->downscale) { if (this->downscale) {
this->y_ptr2 = (uint8_t *)malloc(this->width*this->height); this->y_ptr2 = (uint8_t *)malloc(this->width*this->height);
this->u_ptr2 = (uint8_t *)malloc(this->width*this->height/4); 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 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) { int in_width, int in_height, uint64_t ts) {
assert(in_width == this->in_width_);
assert(in_height == this->in_height_);
int err; int err;
if (!this->is_open) { if (!this->is_open) {
return -1; return -1;

@ -22,7 +22,7 @@ struct OmxBuffer {
// OmxEncoder, lossey codec using hardware hevc // OmxEncoder, lossey codec using hardware hevc
class OmxEncoder : public VideoEncoder { class OmxEncoder : public VideoEncoder {
public: 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(); ~OmxEncoder();
int encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, 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); int in_width, int in_height, uint64_t ts);
@ -43,6 +43,7 @@ private:
static void write_and_broadcast_handler(OmxEncoder *e); static void write_and_broadcast_handler(OmxEncoder *e);
static void handle_out_buf(OmxEncoder *e, OmxBuffer *out_buf); static void handle_out_buf(OmxEncoder *e, OmxBuffer *out_buf);
int in_width_, in_height_;
int width, height, fps; int width, height, fps;
char vid_path[1024]; char vid_path[1024];
char lock_path[1024]; char lock_path[1024];

@ -22,9 +22,9 @@ extern "C" {
#include "selfdrive/common/swaglog.h" #include "selfdrive/common/swaglog.h"
#include "selfdrive/common/util.h" #include "selfdrive/common/util.h"
RawLogger::RawLogger(const char* filename, CameraType type, int width, int height, int fps, RawLogger::RawLogger(const char* filename, CameraType type, int in_width, int in_height, int fps,
int bitrate, bool h265, bool downscale, bool write) int bitrate, bool h265, int out_width, int out_height, bool write)
: filename(filename), fps(fps) { : in_width_(in_width), in_height_(in_height), filename(filename), fps(fps) {
// TODO: respect write arg // 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); codec_ctx = avcodec_alloc_context3(codec);
assert(codec_ctx); assert(codec_ctx);
codec_ctx->width = width; codec_ctx->width = out_width;
codec_ctx->height = height; codec_ctx->height = out_height;
codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
// codec_ctx->thread_count = 2; // codec_ctx->thread_count = 2;
@ -51,14 +51,14 @@ RawLogger::RawLogger(const char* filename, CameraType type, int width, int heigh
frame = av_frame_alloc(); frame = av_frame_alloc();
assert(frame); assert(frame);
frame->format = codec_ctx->pix_fmt; frame->format = codec_ctx->pix_fmt;
frame->width = width; frame->width = out_width;
frame->height = height; frame->height = out_height;
frame->linesize[0] = width; frame->linesize[0] = out_width;
frame->linesize[1] = width/2; frame->linesize[1] = out_width/2;
frame->linesize[2] = width/2; frame->linesize[2] = out_width/2;
if (downscale) { if (in_width != out_width || in_height != out_height) {
downscale_buf.resize(width * height * 3 / 2); 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 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) { int in_width, int in_height, uint64_t ts) {
assert(in_width == this->in_width_);
assert(in_height == this->in_height_);
AVPacket pkt; AVPacket pkt;
av_init_packet(&pkt); av_init_packet(&pkt);
pkt.data = NULL; pkt.data = NULL;

@ -15,8 +15,8 @@ extern "C" {
class RawLogger : public VideoEncoder { class RawLogger : public VideoEncoder {
public: public:
RawLogger(const char* filename, CameraType type, int width, int height, int fps, RawLogger(const char* filename, CameraType type, int in_width, int in_height, int fps,
int bitrate, bool h265, bool downscale, bool write = true); int bitrate, bool h265, int out_width, int out_height, bool write = true);
~RawLogger(); ~RawLogger();
int encode_frame(const uint8_t *y_ptr, const uint8_t *u_ptr, const uint8_t *v_ptr, 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); int in_width, int in_height, uint64_t ts);
@ -30,6 +30,7 @@ private:
int counter = 0; int counter = 0;
bool is_open = false; bool is_open = false;
int in_width_, in_height_;
std::string vid_path, lock_path; std::string vid_path, lock_path;
const AVCodec *codec = NULL; const AVCodec *codec = NULL;

Loading…
Cancel
Save