IQ.Pilot Release Commit @ e46d557
This commit is contained in:
@@ -6,6 +6,7 @@ common_libs = [
|
||||
'util.cc',
|
||||
'ratekeeper.cc',
|
||||
'clutil.cc',
|
||||
'yuv.cc',
|
||||
]
|
||||
|
||||
_common = env.Library('common', common_libs, LIBS="json11")
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import requests
|
||||
import unicodedata
|
||||
from datetime import datetime, timedelta, UTC
|
||||
from functools import lru_cache
|
||||
from openpilot.system.hardware.hw import Paths
|
||||
from openpilot.system.version import get_version
|
||||
|
||||
@@ -11,6 +12,16 @@ KEYS = {"id_rsa": "RS256",
|
||||
"id_ecdsa": "ES256"}
|
||||
|
||||
|
||||
@lru_cache(maxsize=4)
|
||||
def load_signing_key(private_key: str):
|
||||
# PyJWT re-parses a PEM string on every encode; an RSA parse is ~40ms, so cache the key object
|
||||
try:
|
||||
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||
return load_pem_private_key(private_key.encode(), password=None)
|
||||
except Exception:
|
||||
return private_key
|
||||
|
||||
|
||||
class BaseApi:
|
||||
def __init__(self, dongle_id, api_host, user_agent="openpilot-"):
|
||||
self.dongle_id = dongle_id
|
||||
@@ -38,7 +49,8 @@ class BaseApi:
|
||||
}
|
||||
if payload_extra is not None:
|
||||
payload.update(payload_extra)
|
||||
token = jwt.encode(payload, self.private_key, algorithm=self.jwt_algorithm)
|
||||
key = load_signing_key(self.private_key) if self.private_key else self.private_key
|
||||
token = jwt.encode(payload, key, algorithm=self.jwt_algorithm)
|
||||
if isinstance(token, bytes):
|
||||
token = token.decode('utf8')
|
||||
return token
|
||||
|
||||
@@ -21,6 +21,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"CalibrationParams", {PERSISTENT, BYTES}},
|
||||
{"CameraDebugExpGain", {CLEAR_ON_MANAGER_START, STRING}},
|
||||
{"CameraDebugExpTime", {CLEAR_ON_MANAGER_START, STRING}},
|
||||
{"CanLiveStreaming", {CLEAR_ON_MANAGER_START, BOOL}},
|
||||
{"CarBatteryCapacity", {PERSISTENT, INT}},
|
||||
{"CarParams", {CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION, BYTES}},
|
||||
{"CarParamsCache", {CLEAR_ON_MANAGER_START, BYTES}},
|
||||
@@ -199,6 +200,8 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"OSMapsHeadingUp", {PERSISTENT, BOOL, "1"}},
|
||||
{"OfflineTilesBaseUrl", {PERSISTENT, STRING}},
|
||||
{"OnroadUploads", {PERSISTENT, BOOL, "1"}},
|
||||
{"IQAutoUnits", {PERSISTENT, BOOL, "1"}},
|
||||
{"IQAutoUnitsRegion", {PERSISTENT, STRING}},
|
||||
{"IQAlertSilence", {PERSISTENT, BOOL, "0"}},
|
||||
{"IQAccelMeter", {PERSISTENT, BOOL, "0"}},
|
||||
{"IQBlinkerIndicators", {PERSISTENT, BOOL, "0"}},
|
||||
@@ -349,6 +352,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"ConstructionZoneAssist", {PERSISTENT, BOOL, "0"}},
|
||||
{"VisionVehicleTracks", {PERSISTENT, BOOL, "0"}},
|
||||
{"AmbientTrackDots", {PERSISTENT, BOOL, "1"}},
|
||||
{"EnvironmentView", {PERSISTENT, INT, "0"}},
|
||||
{"ConstructionZoneSpeed", {PERSISTENT, INT, "60"}},
|
||||
{"ShowSpeedLimits", {PERSISTENT, BOOL, "0"}},
|
||||
{"SLCPolicy", {PERSISTENT, INT, "1"}},
|
||||
|
||||
25
common/tests/native_test.h
Normal file
25
common/tests/native_test.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
inline void native_test_check(bool condition, const char *expression, const char *file, int line) {
|
||||
if (!condition) {
|
||||
throw std::runtime_error(std::string(file) + ":" + std::to_string(line) + ": check failed: " + expression);
|
||||
}
|
||||
}
|
||||
|
||||
#define CHECK(condition) native_test_check(static_cast<bool>(condition), #condition, __FILE__, __LINE__)
|
||||
#define REQUIRE(...) CHECK((__VA_ARGS__))
|
||||
|
||||
template <typename Function>
|
||||
int run_native_test(Function &&function) {
|
||||
try {
|
||||
function();
|
||||
return 0;
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
132
common/yuv.cc
Normal file
132
common/yuv.cc
Normal file
@@ -0,0 +1,132 @@
|
||||
#include "common/yuv.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace yuv {
|
||||
|
||||
namespace {
|
||||
|
||||
inline uint8_t clamp_u8(int v) {
|
||||
return static_cast<uint8_t>(std::clamp(v, 0, 255));
|
||||
}
|
||||
|
||||
void copy_plane(const uint8_t *src, int src_stride,
|
||||
uint8_t *dst, int dst_stride,
|
||||
int width, int height) {
|
||||
if (src_stride == width && dst_stride == width) {
|
||||
std::memcpy(dst, src, static_cast<size_t>(width) * height);
|
||||
return;
|
||||
}
|
||||
for (int y = 0; y < height; ++y) {
|
||||
std::memcpy(dst + y * dst_stride, src + y * src_stride, width);
|
||||
}
|
||||
}
|
||||
|
||||
void scale_plane_point(const uint8_t *src, int src_stride, int src_width, int src_height,
|
||||
uint8_t *dst, int dst_stride, int dst_width, int dst_height) {
|
||||
if (src_width == dst_width && src_height == dst_height) {
|
||||
copy_plane(src, src_stride, dst, dst_stride, dst_width, dst_height);
|
||||
return;
|
||||
}
|
||||
for (int y = 0; y < dst_height; ++y) {
|
||||
const int sy = y * src_height / dst_height;
|
||||
const uint8_t *src_row = src + sy * src_stride;
|
||||
uint8_t *dst_row = dst + y * dst_stride;
|
||||
for (int x = 0; x < dst_width; ++x) {
|
||||
dst_row[x] = src_row[x * src_width / dst_width];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BT.601 limited range → RGB (integer form used widely, incl. similar to libyuv).
|
||||
inline void yuv_to_rgb(int y, int u, int v, uint8_t *r, uint8_t *g, uint8_t *b) {
|
||||
const int c = (y - 16) * 298;
|
||||
const int d = u - 128;
|
||||
const int e = v - 128;
|
||||
*r = clamp_u8((c + 409 * e + 128) >> 8);
|
||||
*g = clamp_u8((c - 100 * d - 208 * e + 128) >> 8);
|
||||
*b = clamp_u8((c + 516 * d + 128) >> 8);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void nv12_to_i420(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_uv, int src_stride_uv,
|
||||
uint8_t *dst_y, int dst_stride_y,
|
||||
uint8_t *dst_u, int dst_stride_u,
|
||||
uint8_t *dst_v, int dst_stride_v,
|
||||
int width, int height) {
|
||||
copy_plane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
|
||||
|
||||
const int uv_width = width / 2;
|
||||
const int uv_height = height / 2;
|
||||
for (int y = 0; y < uv_height; ++y) {
|
||||
const uint8_t *uv = src_uv + y * src_stride_uv;
|
||||
uint8_t *u = dst_u + y * dst_stride_u;
|
||||
uint8_t *v = dst_v + y * dst_stride_v;
|
||||
for (int x = 0; x < uv_width; ++x) {
|
||||
u[x] = uv[2 * x];
|
||||
v[x] = uv[2 * x + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void i420_to_nv12(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_u, int src_stride_u,
|
||||
const uint8_t *src_v, int src_stride_v,
|
||||
uint8_t *dst_y, int dst_stride_y,
|
||||
uint8_t *dst_uv, int dst_stride_uv,
|
||||
int width, int height) {
|
||||
copy_plane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
|
||||
|
||||
const int uv_width = width / 2;
|
||||
const int uv_height = height / 2;
|
||||
for (int y = 0; y < uv_height; ++y) {
|
||||
const uint8_t *u = src_u + y * src_stride_u;
|
||||
const uint8_t *v = src_v + y * src_stride_v;
|
||||
uint8_t *uv = dst_uv + y * dst_stride_uv;
|
||||
for (int x = 0; x < uv_width; ++x) {
|
||||
uv[2 * x] = u[x];
|
||||
uv[2 * x + 1] = v[x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void i420_scale(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_u, int src_stride_u,
|
||||
const uint8_t *src_v, int src_stride_v,
|
||||
int src_width, int src_height,
|
||||
uint8_t *dst_y, int dst_stride_y,
|
||||
uint8_t *dst_u, int dst_stride_u,
|
||||
uint8_t *dst_v, int dst_stride_v,
|
||||
int dst_width, int dst_height) {
|
||||
scale_plane_point(src_y, src_stride_y, src_width, src_height,
|
||||
dst_y, dst_stride_y, dst_width, dst_height);
|
||||
scale_plane_point(src_u, src_stride_u, src_width / 2, src_height / 2,
|
||||
dst_u, dst_stride_u, dst_width / 2, dst_height / 2);
|
||||
scale_plane_point(src_v, src_stride_v, src_width / 2, src_height / 2,
|
||||
dst_v, dst_stride_v, dst_width / 2, dst_height / 2);
|
||||
}
|
||||
|
||||
void nv12_to_rgba(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_uv, int src_stride_uv,
|
||||
uint8_t *dst_rgba, int dst_stride_rgba,
|
||||
int width, int height) {
|
||||
for (int y = 0; y < height; ++y) {
|
||||
const uint8_t *y_row = src_y + y * src_stride_y;
|
||||
const uint8_t *uv_row = src_uv + (y / 2) * src_stride_uv;
|
||||
uint8_t *dst = dst_rgba + y * dst_stride_rgba;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
const int uv_x = (x & ~1);
|
||||
uint8_t r, g, b;
|
||||
yuv_to_rgb(y_row[x], uv_row[uv_x], uv_row[uv_x + 1], &r, &g, &b);
|
||||
dst[4 * x + 0] = r;
|
||||
dst[4 * x + 1] = g;
|
||||
dst[4 * x + 2] = b;
|
||||
dst[4 * x + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace yuv
|
||||
42
common/yuv.h
Normal file
42
common/yuv.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// NV12: Y plane + interleaved UV. I420: planar Y, U, V.
|
||||
|
||||
namespace yuv {
|
||||
|
||||
// Deinterleave NV12 UV into planar I420.
|
||||
void nv12_to_i420(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_uv, int src_stride_uv,
|
||||
uint8_t *dst_y, int dst_stride_y,
|
||||
uint8_t *dst_u, int dst_stride_u,
|
||||
uint8_t *dst_v, int dst_stride_v,
|
||||
int width, int height);
|
||||
|
||||
// Interleave planar I420 UV into NV12.
|
||||
void i420_to_nv12(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_u, int src_stride_u,
|
||||
const uint8_t *src_v, int src_stride_v,
|
||||
uint8_t *dst_y, int dst_stride_y,
|
||||
uint8_t *dst_uv, int dst_stride_uv,
|
||||
int width, int height);
|
||||
|
||||
// Point-sample scale I420 (equivalent to libyuv::I420Scale + kFilterNone).
|
||||
void i420_scale(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_u, int src_stride_u,
|
||||
const uint8_t *src_v, int src_stride_v,
|
||||
int src_width, int src_height,
|
||||
uint8_t *dst_y, int dst_stride_y,
|
||||
uint8_t *dst_u, int dst_stride_u,
|
||||
uint8_t *dst_v, int dst_stride_v,
|
||||
int dst_width, int dst_height);
|
||||
|
||||
// Convert NV12 to packed RGBA (R,G,B,A bytes — suitable for GL_RGBA).
|
||||
// BT.601 limited-range, matching common libyuv defaults.
|
||||
void nv12_to_rgba(const uint8_t *src_y, int src_stride_y,
|
||||
const uint8_t *src_uv, int src_stride_uv,
|
||||
uint8_t *dst_rgba, int dst_stride_rgba,
|
||||
int width, int height);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user