Skip to content

Commit

Permalink
Merge pull request #43 from hao-yao/icamerasrc_slim_api
Browse files Browse the repository at this point in the history
Release on 2024-04-09
  • Loading branch information
hao-yao authored Apr 11, 2024
2 parents 086aa9f + 42438f5 commit 9b2f7e3
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 34 deletions.
4 changes: 2 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 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
libgsticamerasrc_la_CPPFLAGS+= -fstack-protector -fPIE -fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security

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

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

# headers we need but don't want installed
noinst_HEADERS = gstcamerasrc.h \
Expand Down
6 changes: 3 additions & 3 deletions src/gstcambasesrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ gst_cam_base_src_init(GstCamBaseSrc *basesrc, GstCamBaseSrcClass *klass)
gst_video_info_init(&basesrc->srcpad_info);
basesrc->is_info_change = FALSE;
#endif
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
basesrc->is_dma_drm_caps = FALSE;
#endif

Expand Down Expand Up @@ -3737,13 +3737,13 @@ gst_cam_base_src_negotiate (GstCamBaseSrc * basesrc, GstPad *pad)

caps = gst_pad_get_current_caps (pad);

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
basesrc->is_dma_drm_caps = gst_video_is_dma_drm_caps(caps);
#endif

#if GST_VERSION_MINOR >= 18
if (basesrc->is_info_change) {
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (!CameraSrcUtils::gst_video_info_from_dma_drm_caps(&vinfo, caps))
#else
if (!gst_video_info_from_caps(&vinfo, caps))
Expand Down
2 changes: 1 addition & 1 deletion src/gstcambasesrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct _GstCamBaseSrc {
GstVideoInfo srcpad_info;
gboolean is_info_change;
#endif
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
/* indicate current caps is dma_drm type for io_mode=dma_mode. */
bool is_dma_drm_caps;
#endif
Expand Down
16 changes: 8 additions & 8 deletions src/gstcameraformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void update_main_resolution(int format,
cameraSrc_Res_Range res_range,
vector <cameraSrc_Main_Res_Range> &main_res_range);
static GstStructure *create_structure (guint32 fourcc);
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
static void
set_structure_to_caps(vector<cameraSrc_Main_Res_Range> main_res_range,
GstCaps **caps, GstVaDisplay *display_drm);
Expand Down Expand Up @@ -179,7 +179,7 @@ create_structure (guint32 fourcc)
* Merge all structures into caps
*/
#define GST_CAPS_FEATURE_MEMORY_DMABUF "memory:DMABuf"
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
static void
set_structure_to_caps(vector<cameraSrc_Main_Res_Range> main_res_range,
GstCaps **caps, GstVaDisplay *display_drm)
Expand All @@ -190,7 +190,7 @@ set_structure_to_caps(vector <cameraSrc_Main_Res_Range> main_res_range, GstCaps
{
GstStructure *structure = NULL;
int feature_index = 0;
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
/* Set caps with dmabuffer */
for (auto &res_range : main_res_range) {
structure = create_structure(res_range.format);
Expand Down Expand Up @@ -389,7 +389,7 @@ GstCaps *gst_camerasrc_get_all_caps ()
return gst_caps_simplify(caps);
}
caps = gst_caps_new_empty();
#if GST_VERSION_MINOR >= 22
#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) {
Expand All @@ -408,7 +408,7 @@ GstCaps *gst_camerasrc_get_all_caps ()
if (ret != 0) {
GST_ERROR("failed to get camera info from libcamhal");
gst_caps_unref(caps);
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (display_drm) {
gst_object_unref(display_drm);
display_drm = NULL;
Expand All @@ -422,7 +422,7 @@ GstCaps *gst_camerasrc_get_all_caps ()
if (ret != 0) {
GST_ERROR("failed to get format info from libcamhal");
gst_caps_unref(caps);
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (display_drm) {
gst_object_unref(display_drm);
display_drm = NULL;
Expand All @@ -432,13 +432,13 @@ GstCaps *gst_camerasrc_get_all_caps ()
}
}

#if GST_VERSION_MINOR >= 22
#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
main_res_range.clear();
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (display_drm) {
gst_object_unref(display_drm);
display_drm = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/gstcamerasrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ gst_camerasrc_init (Gstcamerasrc * camerasrc)
camerasrc->streams[GST_CAMERASRC_MAIN_STREAM_ID].stream_config_done = FALSE;
camerasrc->streams[GST_CAMERASRC_MAIN_STREAM_ID].activated = TRUE;
camerasrc->streams[GST_CAMERASRC_MAIN_STREAM_ID].stream_usage = DEFAULT_PROP_SRC_STREAM_USAGE;
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
camerasrc->streams[GST_CAMERASRC_MAIN_STREAM_ID].drm_modifier =
DRM_FORMAT_MOD_LINEAR;
#endif
Expand Down Expand Up @@ -2494,7 +2494,7 @@ gst_camerasrc_get_caps_info (Gstcamerasrc* camerasrc, GstCaps * caps, int stream
GstStructure *structure = gst_caps_get_structure (caps, 0);
const gchar *mimetype = gst_structure_get_name (structure);

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (!gst_video_is_dma_drm_caps(caps)) {
#endif
/* raw caps, parse into video info */
Expand All @@ -2503,7 +2503,7 @@ gst_camerasrc_get_caps_info (Gstcamerasrc* camerasrc, GstCaps * caps, int stream
camerasrc->device_id, stream_id);
return FALSE;
}
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
} else {
GstVideoInfoDmaDrm drm_info;
if (!gst_video_info_dma_drm_from_caps(&drm_info, caps)) {
Expand Down Expand Up @@ -2697,7 +2697,7 @@ gst_camerasrc_set_caps(GstCamBaseSrc *src, GstPad *pad, GstCaps *caps)

#if GST_VERSION_MINOR >= 18
if (camerasrc->io_mode == GST_CAMERASRC_IO_MODE_DMA_MODE) {
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (CameraSrcUtils::gst_video_info_from_dma_drm_caps(&vinfo, caps)) {
#else
if (gst_video_info_from_caps(&vinfo, caps)) {
Expand Down
2 changes: 1 addition & 1 deletion src/gstcamerasrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ struct _GstStreamInfo
/* Buffer config */
guint bpl;
GstVideoInfo info;
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
/* drm modifier used currently after negotiated. */
guint64 drm_modifier;
#endif
Expand Down
14 changes: 7 additions & 7 deletions src/gstcamerasrcbufferpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ gst_camerasrc_buffer_pool_finalize (GObject * object)
PERF_CAMERA_ATRACE();
GstCamerasrcBufferPool *pool = GST_CAMERASRC_BUFFER_POOL (object);
GST_INFO("CameraId=%d, StreamId=%d.", pool->src->device_id, pool->stream_id);
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (pool->display_drm) {
gst_object_unref(pool->display_drm);
pool->display_drm = NULL;
Expand Down Expand Up @@ -165,7 +165,7 @@ gst_camerasrc_buffer_pool_init (GstCamerasrcBufferPool * pool)
pool->need_alignment = FALSE;
#endif

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
pool->display_drm = NULL;
#endif
}
Expand All @@ -186,7 +186,7 @@ gst_camerasrc_buffer_pool_new (Gstcamerasrc *camerasrc,

if (camerasrc->io_mode == GST_CAMERASRC_IO_MODE_DMA_MODE) {
#if GST_VERSION_MINOR >= 18
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (!CameraSrcUtils::gst_video_info_from_dma_drm_caps(&info, caps)) {
#else
if (!gst_video_info_from_caps(&info, caps)) {
Expand Down Expand Up @@ -278,7 +278,7 @@ gst_camerasrc_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * conf
}

#if GST_VERSION_MINOR >= 18
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (!CameraSrcUtils::gst_video_info_from_dma_drm_caps(&video_info, caps)) {
#else
if (!gst_video_info_from_caps (&video_info, caps)) {
Expand All @@ -300,7 +300,7 @@ gst_camerasrc_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * conf
pool->allocator = NULL;

if (camerasrc->io_mode == GST_CAMERASRC_IO_MODE_DMA_EXPORT || camerasrc->io_mode == GST_CAMERASRC_IO_MODE_DMA_MODE) {
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (NULL == pool->display_drm) {
pool->display_drm =
gst_va_display_drm_new_from_path("/dev/dri/renderD128");
Expand Down Expand Up @@ -680,7 +680,7 @@ gst_camerasrc_alloc_dma_mode(GstCamerasrcBufferPool *pool,
if ((*meta)->buffer == NULL)
return GST_FLOW_ERROR;

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
if (!GST_CAM_BASE_SRC(src)->is_dma_drm_caps) {
#endif

Expand Down Expand Up @@ -734,7 +734,7 @@ gst_camerasrc_alloc_dma_mode(GstCamerasrcBufferPool *pool,
close(intel_fd);
drm_intel_bufmgr_destroy(bufmgr);
drm_intel_bo_unreference(drm_bo);
#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
} else {
if (NULL == pool->display_drm) {
GST_ERROR("Couldn't create a VA DRM display");
Expand Down
4 changes: 1 addition & 3 deletions src/gstcamerasrcbufferpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
#include "gstcampushsrc.h"
#include "gstcamerasrc.h"

#if GST_VERSION_MINOR >= 22
#include "utils.h"
#endif

typedef struct _GstCamerasrcBufferPool GstCamerasrcBufferPool;//in use of qbuf&dqbuf
typedef struct _GstCamerasrcBufferPoolClass GstCamerasrcBufferPoolClass;//in use of _class_init
Expand Down Expand Up @@ -92,7 +90,7 @@ struct _GstCamerasrcBufferPool
GstVideoAlignment alignment;
#endif

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
/* operate on /dev/dri/renderD128 */
GstVaDisplay *display_drm;
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -DCHROME_SLIM_CAMHAL
endif

# for hardening-check
libgsticamerainterface_@GST_API_VERSION@_la_CPPFLAGS += -fstack-protector-all -fPIE -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
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_LIBADD = $(GST_LIBS) $(CAMHAL_LIBS)

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int CameraSrcUtils::get_stream_id_by_pad(map<string, int> &streamMap, GstPad *pa
return stream_id;
}

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23

#define VA_NSB_FIRST 0 /* No Significant Bit */

Expand Down
5 changes: 3 additions & 2 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@
#include <linux/videodev2.h>
#include <map>

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23
#include <va/va_drmcommon.h>
#include <drm_fourcc.h>
#define GST_USE_UNSTABLE_API
#include <gst/va/gstva.h>
#include <gst/video/video-info-dma.h>
#endif

using namespace std;
Expand Down Expand Up @@ -113,7 +114,7 @@ namespace CameraSrcUtils {

int get_stream_id_by_pad(map<string, int> &streamMap, GstPad *pad);

#if GST_VERSION_MINOR >= 22
#if GST_VERSION_MINOR == 22 && GST_VERSION_MICRO == 6 || GST_VERSION_MINOR >= 23

gboolean gst_video_info_from_dma_drm_caps(GstVideoInfo *info,
const GstCaps *caps);
Expand Down

0 comments on commit 9b2f7e3

Please sign in to comment.