diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 424ad78ab3..b313f74e7e 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -19,6 +19,7 @@ #include "selfdrive/hardware/hw.h" #ifdef QCOM +#include "CL/cl_ext_qcom.h" #include "selfdrive/camerad/cameras/camera_qcom.h" #elif QCOM2 #include "selfdrive/camerad/cameras/camera_qcom2.h" @@ -28,6 +29,8 @@ #include "selfdrive/camerad/cameras/camera_replay.h" #endif +ExitHandler do_exit; + class Debayer { public: Debayer(cl_device_id device_id, cl_context context, const CameraBuf *b, const CameraState *s) { @@ -339,8 +342,6 @@ float set_exposure_target(const CameraBuf *b, int x_start, int x_end, int x_skip return lum_med / 256.0; } -extern ExitHandler do_exit; - void *processing_thread(MultiCameraState *cameras, CameraState *cs, process_thread_cb callback) { const char *thread_name = nullptr; if (cs == &cameras->road_cam) { @@ -422,3 +423,27 @@ void common_process_driver_camera(MultiCameraState *s, CameraState *c, int cnt) } s->pm->send("driverCameraState", msg); } + + +void camerad_thread() { + cl_device_id device_id = cl_get_device_id(CL_DEVICE_TYPE_DEFAULT); + // TODO: do this for QCOM2 too +#if defined(QCOM) + const cl_context_properties props[] = {CL_CONTEXT_PRIORITY_HINT_QCOM, CL_PRIORITY_HINT_HIGH_QCOM, 0}; + cl_context context = CL_CHECK_ERR(clCreateContext(props, 1, &device_id, NULL, NULL, &err)); +#else + cl_context context = CL_CHECK_ERR(clCreateContext(NULL, 1, &device_id, NULL, NULL, &err)); +#endif + + MultiCameraState cameras = {}; + VisionIpcServer vipc_server("camerad", device_id, context); + + cameras_init(&vipc_server, &cameras, device_id, context); + cameras_open(&cameras); + + vipc_server.start_listener(); + + cameras_run(&cameras); + + CL_CHECK(clReleaseContext(context)); +} diff --git a/selfdrive/camerad/cameras/camera_common.h b/selfdrive/camerad/cameras/camera_common.h index 75bd79bfdf..f9269ebfe3 100644 --- a/selfdrive/camerad/cameras/camera_common.h +++ b/selfdrive/camerad/cameras/camera_common.h @@ -129,3 +129,4 @@ void cameras_open(MultiCameraState *s); void cameras_run(MultiCameraState *s); void cameras_close(MultiCameraState *s); void camera_autoexposure(CameraState *s, float grey_frac); +void camerad_thread(); diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index cf639264c0..668410d6f7 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -1,48 +1,11 @@ -#include -#include -#include +#include "selfdrive/camerad/cameras/camera_common.h" #include -#include -#include -#include "libyuv.h" - -#include "cereal/visionipc/visionipc_server.h" -#include "selfdrive/common/clutil.h" #include "selfdrive/common/params.h" -#include "selfdrive/common/swaglog.h" #include "selfdrive/common/util.h" #include "selfdrive/hardware/hw.h" -#ifdef QCOM -#include "selfdrive/camerad/cameras/camera_qcom.h" -#elif QCOM2 -#include "selfdrive/camerad/cameras/camera_qcom2.h" -#elif WEBCAM -#include "selfdrive/camerad/cameras/camera_webcam.h" -#else -#include "selfdrive/camerad/cameras/camera_replay.h" -#endif - -ExitHandler do_exit; - -void party(cl_device_id device_id, cl_context context) { - MultiCameraState cameras = {}; - VisionIpcServer vipc_server("camerad", device_id, context); - - cameras_init(&vipc_server, &cameras, device_id, context); - cameras_open(&cameras); - - vipc_server.start_listener(); - - cameras_run(&cameras); -} - -#ifdef QCOM -#include "CL/cl_ext_qcom.h" -#endif - int main(int argc, char *argv[]) { if (!Hardware::PC()) { int ret; @@ -52,18 +15,6 @@ int main(int argc, char *argv[]) { assert(ret == 0 || Params().getBool("IsOffroad")); // failure ok while offroad due to offlining cores } - cl_device_id device_id = cl_get_device_id(CL_DEVICE_TYPE_DEFAULT); - - // TODO: do this for QCOM2 too -#if defined(QCOM) - const cl_context_properties props[] = {CL_CONTEXT_PRIORITY_HINT_QCOM, CL_PRIORITY_HINT_HIGH_QCOM, 0}; - cl_context context = CL_CHECK_ERR(clCreateContext(props, 1, &device_id, NULL, NULL, &err)); -#else - cl_context context = CL_CHECK_ERR(clCreateContext(NULL, 1, &device_id, NULL, NULL, &err)); -#endif - - party(device_id, context); - - CL_CHECK(clReleaseContext(context)); + camerad_thread(); return 0; } diff --git a/selfdrive/camerad/test/ae_gray_test.cc b/selfdrive/camerad/test/ae_gray_test.cc index 0f14a23794..358d93d759 100644 --- a/selfdrive/camerad/test/ae_gray_test.cc +++ b/selfdrive/camerad/test/ae_gray_test.cc @@ -11,9 +11,10 @@ #include "selfdrive/camerad/cameras/camera_common.h" // needed by camera_common.cc -ExitHandler do_exit; - void camera_autoexposure(CameraState *s, float grey_frac) {} +void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx) {} +void cameras_open(MultiCameraState *s) {} +void cameras_run(MultiCameraState *s) {} int main() { // set up fake camerabuf