Skip to content

Commit

Permalink
Merge pull request #47 from zouxiaoh/icamerasrc_slim_api
Browse files Browse the repository at this point in the history
release for imx390 on MTL, kernel 6.6
  • Loading branch information
zouxiaoh authored Jun 6, 2024
2 parents 9b2f7e3 + 057400f commit 1baecb1
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 22 deletions.
27 changes: 27 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,33 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ ], [ ])], [
], [
AC_MSG_RESULT([no])
])
CFLAGS="$save_CFLAGS"

AC_DEFUN([AC_CHECK_FORTIFY_SOURCE], [
AC_MSG_CHECKING([for _FORTIFY_SOURCE value with -O2])
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -O2"
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[
#include <stdio.h>
#ifndef _FORTIFY_SOURCE
#error
#endif
int main() { printf("%d\n", _FORTIFY_SOURCE); return 0; }
]])],
[
fortify_source_value=`./conftest$EXEEXT`
],
[
AC_MSG_RESULT([no])
fortify_source_value=0
]
)
CFLAGS="$old_CFLAGS"
AC_SUBST([fortify_source_value])
])
AC_CHECK_FORTIFY_SOURCE
AM_CONDITIONAL([NO_FORTIFY_SOURCE], [test "x$fortify_source_value" = "x0"])

dnl set the plugindir where plugins should be installed (for src/Makefile.am)
if test "x${prefix}" = "x$HOME"; then
Expand Down
10 changes: 8 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ libgsticamerasrc_la_CPPFLAGS += -DCHROME_SLIM_CAMHAL
endif

# for hardening-check
libgsticamerasrc_la_CPPFLAGS+= -fstack-protector -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
libgsticamerasrc_la_CPPFLAGS+= -fstack-protector -fPIE -fPIC -Wformat -Wformat-security

libgsticamerasrc_la_LIBADD = $(GST_LIBS) \
-lgstallocators-$(GST_API_VERSION) \
Expand All @@ -101,7 +101,13 @@ libgsticamerasrc_la_LIBADD = $(GST_LIBS) \

libgsticamerasrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
# for hardening-check
libgsticamerasrc_la_LDFLAGS += -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now
libgsticamerasrc_la_LDFLAGS += -fPIE -fPIC -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now

# test default fortify level
if NO_FORTIFY_SOURCE
libgsticamerasrc_la_CPPFLAGS+= -D_FORTIFY_SOURCE=2
libgsticamerasrc_la_LDFLAGS+= -D_FORTIFY_SOURCE=2
endif

# headers we need but don't want installed
noinst_HEADERS = gstcamerasrc.h \
Expand Down
17 changes: 8 additions & 9 deletions src/gstcameraformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,14 @@ GstCaps *gst_camerasrc_get_all_caps ()
vector <cameraSrc_Main_Res_Range> main_res_range;

static GstCaps *caps = NULL;
if (caps != NULL) {
return gst_caps_simplify(caps);
if (caps != NULL && GST_IS_CAPS(caps)) {
return caps;
}
caps = gst_caps_new_empty();
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
GstVaDisplay *display_drm = NULL;
display_drm = gst_va_display_drm_new_from_path("/dev/dri/renderD128");
if (NULL == display_drm) {
GST_ERROR("Couldn't create a VA DRM display");
g_printerr("Couldn't create a VA DRM display");
return NULL;
}
#endif
Expand All @@ -406,8 +405,7 @@ GstCaps *gst_camerasrc_get_all_caps ()
//get configuration of camera
int ret = get_camera_info(i, info);
if (ret != 0) {
GST_ERROR("failed to get camera info from libcamhal");
gst_caps_unref(caps);
g_printerr("failed to get camera info from libcamhal");
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (display_drm) {
gst_object_unref(display_drm);
Expand All @@ -420,8 +418,7 @@ GstCaps *gst_camerasrc_get_all_caps ()

ret = register_format_and_resolution(configs, fmt_res, main_res_range);
if (ret != 0) {
GST_ERROR("failed to get format info from libcamhal");
gst_caps_unref(caps);
g_printerr("failed to get format info from libcamhal");
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (display_drm) {
gst_object_unref(display_drm);
Expand All @@ -432,11 +429,13 @@ GstCaps *gst_camerasrc_get_all_caps ()
}
}

caps = gst_caps_new_empty();
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
set_structure_to_caps(main_res_range, &caps, display_drm);
#else
set_structure_to_caps(main_res_range, &caps);
#endif
caps = gst_caps_simplify(caps);
main_res_range.clear();
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (display_drm) {
Expand All @@ -445,5 +444,5 @@ GstCaps *gst_camerasrc_get_all_caps ()
}
#endif

return gst_caps_simplify(caps);
return caps;
}
3 changes: 0 additions & 3 deletions src/gstcameraformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
#ifndef __GST_CAMERAFORMAT_H__
#define __GST_CAMERAFORMAT_H__

GST_DEBUG_CATEGORY_EXTERN(gst_camerasrc_debug);
#define GST_CAT_DEFAULT gst_camerasrc_debug

GstCaps *gst_camerasrc_get_all_caps ();

#endif /* __GST_CAMERAFORMAT_H__ */
10 changes: 5 additions & 5 deletions src/gstcamerasrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ G_DEFINE_TYPE_WITH_CODE (Gstcamerasrc, gst_camerasrc, GST_TYPE_CAM_PUSH_SRC,
G_DEFINE_TYPE_WITH_CODE (Gstcamerasrc, gst_camerasrc, GST_TYPE_CAM_PUSH_SRC,
G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_3A_IF, gst_camerasrc_3a_interface_init);
G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_ISP_IF, gst_camerasrc_isp_interface_init);
G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_DEWARPING_IF, gst_camerasrc_dewarping_interface_init) );
G_IMPLEMENT_INTERFACE(GST_TYPE_CAMERASRC_DEWARPING_IF, gst_camerasrc_dewarping_interface_init));
#endif

static void gst_camerasrc_set_property (GObject * object, guint prop_id,
Expand Down Expand Up @@ -922,13 +922,13 @@ static GstStaticPadTemplate video_pad_template = GST_STATIC_PAD_TEMPLATE(
GST_CAM_BASE_VIDEO_PAD_NAMES,
GST_PAD_SRC,
GST_PAD_REQUEST,
gst_camerasrc_get_all_caps());
{gst_camerasrc_get_all_caps()});

static GstStaticPadTemplate still_pad_template = GST_STATIC_PAD_TEMPLATE(
GST_CAM_BASE_STILL_PAD_NAMES,
GST_PAD_SRC,
GST_PAD_REQUEST,
gst_camerasrc_get_all_caps());
{gst_camerasrc_get_all_caps()});

static void
gst_camerasrc_class_init (GstcamerasrcClass * klass)
Expand All @@ -953,6 +953,8 @@ gst_camerasrc_class_init (GstcamerasrcClass * klass)
gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_camerasrc_request_new_pad);
gstelement_class->release_pad = GST_DEBUG_FUNCPTR(gst_camerasrc_release_pad);

GST_DEBUG_CATEGORY_INIT(gst_camerasrc_debug, "icamerasrc", 0, "camerasrc source element");

g_object_class_install_property(gobject_class,PROP_BUFFERCOUNT,
g_param_spec_int("buffer-count","buffer count","The number of buffer to allocate when do the streaming",
MIN_PROP_BUFFERCOUNT,MAX_PROP_BUFFERCOUNT,DEFAULT_PROP_BUFFERCOUNT,
Expand Down Expand Up @@ -1227,8 +1229,6 @@ gst_camerasrc_class_init (GstcamerasrcClass * klass)
basesrc_class->negotiate = GST_DEBUG_FUNCPTR(gst_camerasrc_negotiate);
basesrc_class->decide_allocation = GST_DEBUG_FUNCPTR(gst_camerasrc_decide_allocation);
pushsrc_class->fill = GST_DEBUG_FUNCPTR(gst_camerasrc_fill);

GST_DEBUG_CATEGORY_INIT (gst_camerasrc_debug, "icamerasrc", 0, "camerasrc source element");
}

static void
Expand Down
15 changes: 14 additions & 1 deletion src/gstcamerasrcbufferpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ gst_camerasrc_meta_api_get_type (void)
return type;
}

static gboolean
gst_camerasrc_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
{
GstCamerasrcMeta *emeta = (GstCamerasrcMeta *) meta;

emeta->index = 0;
emeta->mem = NULL;
emeta->buffer = NULL;

return TRUE;
}


const GstMetaInfo *
gst_camerasrc_meta_get_info (void)
{
Expand All @@ -98,7 +111,7 @@ gst_camerasrc_meta_get_info (void)
if (g_once_init_enter (&meta_info)) {
const GstMetaInfo *meta =
gst_meta_register (gst_camerasrc_meta_api_get_type (), "GstCamerasrcMeta",
sizeof (GstCamerasrcMeta), (GstMetaInitFunction) NULL,
sizeof (GstCamerasrcMeta), gst_camerasrc_meta_init,
(GstMetaFreeFunction) NULL, (GstMetaTransformFunction) NULL);
g_once_init_leave (&meta_info, meta);
}
Expand Down
10 changes: 8 additions & 2 deletions src/interfaces/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -DCHROME_SLIM_CAMHAL
endif

# for hardening-check
libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -fstack-protector-all -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -fstack-protector-all -fPIE -fPIC -Wformat -Wformat-security

libgsticamerainterface_@GST_API_VERSION@_la_LIBADD = $(GST_LIBS) $(CAMHAL_LIBS)

# for hardening-check
libgsticamerainterface_@GST_API_VERSION@_la_LDFLAGS = -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now -version-info $(LT_VERSION_INFO)
libgsticamerainterface_@GST_API_VERSION@_la_LDFLAGS = -fPIE -fPIC -Wformat -Wformat-security -Wl,-z,relro -Wl,-z,now -version-info $(LT_VERSION_INFO)

# test default fortify level
if NO_FORTIFY_SOURCE
libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS+= -D_FORTIFY_SOURCE=2
libgsticamerainterface_@GST_API_VERSION@_la_LDFLAGS+= -D_FORTIFY_SOURCE=2
endif

libgsticamerainterfaceincludedir = $(includedir)/gstreamer-@GST_API_VERSION@/gst/icamera

Expand Down

0 comments on commit 1baecb1

Please sign in to comment.