Skip to content

Commit

Permalink
* optimize camera
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed Aug 13, 2024
1 parent a661491 commit a597e16
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
43 changes: 43 additions & 0 deletions components/maixcam_lib/include/sophgo_middleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define __SOPHGO_MIDDLEWARE_HPP__

#include "stdint.h"
#include "signal.h"
#include "maix_basic.hpp"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -267,4 +270,44 @@ static inline int mmf_add_vdec_channel_v2(int ch, void *cfg) {
return mmf_add_vdec_channel0(MMF_FUNC_SET_PARAM(0, 2), ch, cfg);
}

static void try_deinit_mmf()
{
static uint8_t is_called = 0;
if (!is_called) {
mmf_deinit_v2(true);
is_called = 1;
}
}

static void signal_handle(int signal)
{
const char *signal_msg = NULL;
switch (signal) {
case SIGILL: signal_msg = "SIGILL"; break;
case SIGTRAP: signal_msg = "SIGTRAP"; break;
case SIGABRT: signal_msg = "SIGABRT"; break;
case SIGBUS: signal_msg = "SIGBUS"; break;
case SIGFPE: signal_msg = "SIGFPE"; break;
case SIGKILL: signal_msg = "SIGKILL"; break;
case SIGSEGV: signal_msg = "SIGSEGV"; break;
default: signal_msg = "UNKNOWN"; break;
}

printf("Trigger signal, code:%s(%d)!\r\n", signal_msg, signal);
try_deinit_mmf();
exit(1);
}

static __attribute__((constructor)) void maix_vision_register_signal(void)
{
signal(SIGILL, signal_handle);
signal(SIGTRAP, signal_handle);
signal(SIGABRT, signal_handle);
signal(SIGBUS, signal_handle);
signal(SIGFPE, signal_handle);
signal(SIGKILL, signal_handle);
signal(SIGSEGV, signal_handle);

maix::util::register_exit_function(try_deinit_mmf);
}
#endif // __SOPHGO_MIDDLEWARE_HPP__
43 changes: 1 addition & 42 deletions components/vision/port/maixcam/maix_camera_mmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,6 @@
#define MAIX_SENSOR_FPS "MAIX_SENSOR_FPS" // Set the frame rate, whether it takes effect or not is determined by the driver
#define MMF_INIT_DO_NOT_RELOAD_KMOD "MMF_INIT_DO_NOT_RELOAD_KMOD" // Disable reloading of kmod on mmf_init

static void try_deinit_mmf()
{
static uint8_t is_called = 0;
if (!is_called) {
mmf_deinit_v2(true);
is_called = 1;
}
}

static void signal_handle(int signal)
{
const char *signal_msg = NULL;
switch (signal) {
case SIGILL: signal_msg = "SIGILL"; break;
case SIGTRAP: signal_msg = "SIGTRAP"; break;
case SIGABRT: signal_msg = "SIGABRT"; break;
case SIGBUS: signal_msg = "SIGBUS"; break;
case SIGFPE: signal_msg = "SIGFPE"; break;
case SIGKILL: signal_msg = "SIGKILL"; break;
case SIGSEGV: signal_msg = "SIGSEGV"; break;
default: signal_msg = "UNKNOWN"; break;
}

maix::log::error("Trigger signal, code:%s(%d)!\r\n", signal_msg, signal);
try_deinit_mmf();
exit(1);
}

static __attribute__((constructor)) void maix_vision_register_signal(void)
{
signal(SIGILL, signal_handle);
signal(SIGTRAP, signal_handle);
signal(SIGABRT, signal_handle);
signal(SIGBUS, signal_handle);
signal(SIGFPE, signal_handle);
signal(SIGKILL, signal_handle);
signal(SIGSEGV, signal_handle);

maix::util::register_exit_function(try_deinit_mmf);
}

namespace maix::camera
{
static bool set_regs_flag = false;
Expand Down Expand Up @@ -450,7 +409,7 @@ namespace maix::camera
// mmf init
err::check_bool_raise(!_mmf_vi_init(_width, _height, _fps), "mmf vi init failed");
err::check_bool_raise((_ch = mmf_get_vi_unused_channel()) >= 0, "mmf get vi channel failed");
if (0 != mmf_add_vi_channel_v2(_ch, _width, _height, mmf_invert_format_to_mmf(_format_impl), _fps, _buff_num, -1, -1, 2, _buff_num)) {
if (0 != mmf_add_vi_channel_v2(_ch, _width, _height, mmf_invert_format_to_mmf(_format_impl), _fps, 2, -1, -1, 2, 3)) {
mmf_vi_deinit();
mmf_deinit_v2(false);
err::check_raise(err::ERR_RUNTIME, "mmf add vi channel failed");
Expand Down

0 comments on commit a597e16

Please sign in to comment.