Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrapper/gstreamer plugin #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

SUBDIRS = xcore tests pkgconfig
SUBDIRS = xcore wrapper tests pkgconfig
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ AM_CONDITIONAL([USE_LOCAL_AIQ], [test "$USE_LOCAL_AIQ" -eq 1])

AC_CONFIG_FILES([Makefile
xcore/Makefile
wrapper/Makefile
wrapper/gstreamer/Makefile
tests/Makefile
pkgconfig/Makefile
pkgconfig/xcam_core.pc
Expand Down
3 changes: 3 additions & 0 deletions tests/test-xcamsrc-camera.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

gst-launch-1.0 xcamsrc sensor=0 capturemode=0x4000 memtype=4 buffercount=8 fpsn=25 fpsd=1 width=1920 height=1080 pixelformat=0 field=0 bytesperline=3840 ! video/x-raw, format=NV12, width=1920, height=1080, framerate=30/1 ! queue ! vaapiencode_h264 ! fakesink
1 change: 1 addition & 0 deletions wrapper/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBDIRS = gstreamer
69 changes: 69 additions & 0 deletions wrapper/gstreamer/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
lib_LTLIBRARIES = libstub.la

GST_CFLAGS = -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/lib/glib-2.0/include

PTHREAD_LDFLAGS = -pthread

STUB_CXXFLAGS = -fPIC -std=c++11
STUB_LIBS = \
$(NULL)

if HAVE_LIBDRM
STUB_CXXFLAGS += $(LIBDRM_CFLAGS)
STUB_LIBS += $(LIBDRM_LIBS)
endif

libstub_la_SOURCES = stub.cpp bufmap.cpp v4l2dev.cpp fmt.cpp

libstub_la_CXXFLAGS = -I$(top_builddir)/xcore -I$(top_builddir)/xcore/base \
$(GST_CFLAGS) \
$(STUB_CXXFLAGS) \
$(NULL)
libstub_la_LDFLAGS = \
-no-undefined \
$(PTHREAD_LDFLAGS) \
$(NULL)

libstub_la_LIBADD = $(top_builddir)/xcore/libxcam_core.la \
$(STUB_LIBS) \
-lpthread \
$(NULL)

noinst_HEADERS = stub.h bufmap.h v4l2dev.h fmt.h

# Note: plugindir is set in configure
plugindir="\$(libdir)/gstreamer-1.0"

##############################################################################
# TODO: change libgstxcamsrc.la to something else, e.g. libmysomething.la #
##############################################################################
plugin_LTLIBRARIES = libgstxcamsrc.la

##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
# e.g. libmysomething.la => libmysomething_la_SOURCES #
# libmysomething_la_CFLAGS #
# libmysomething_la_LIBADD #
# libmysomething_la_LDFLAGS #
##############################################################################

# sources used to compile this plug-in
libgstxcamsrc_la_SOURCES = gstxcambufferpool.c \
gstxcamsrc.c

# compiler and linker flags used to compile this plugin, set in configure.ac
libgstxcamsrc_la_CFLAGS = $(GST_CFLAGS) \
-I$(top_builddir)/xcore -I$(top_builddir)/xcore/base \
-I$(top_builddir)/wrapper/gstreamer

libgstxcamsrc_la_LIBADD = $(GST_LIBS) \
$(top_builddir)/wrapper/gstreamer/libstub.la \
-lgstvideo-1.0 \
-lgstallocators-1.0

libgstxcamsrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstxcamsrc_la_LIBTOOLFLAGS = --tag=disable-static

# headers we need but don't want installed
noinst_HEADERS = gstxcambufferpool.h \
gstxcamsrc.h
38 changes: 38 additions & 0 deletions wrapper/gstreamer/bufmap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* bufmap.cpp - map V4l2Buffer to GstBuffer
*
* Copyright (c) 2015 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: John Ye <john.ye@intel.com>
*/

#include "bufmap.h"

namespace XCam {

SmartPtr<BufMap> BufMap::_instance(NULL);
Mutex BufMap::_mutex;

SmartPtr<BufMap>
BufMap::instance()
{
SmartLock lock(_mutex);
if (_instance.ptr())
return _instance;
_instance = new BufMap;
return _instance;
}

};
72 changes: 72 additions & 0 deletions wrapper/gstreamer/bufmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* bufmap.h - map V4l2Buffer to GstBuffer
*
* Copyright (c) 2015 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: John Ye <john.ye@intel.com>
*/

#ifndef __BUFMAP_H__
#define __BUFMAP_H__

#include <gst/gst.h>
#include <map>
#include "xcam_defs.h"
#include "v4l2_buffer_proxy.h"
#include "atomisp_device.h"

namespace XCam {

class BufMap {
public:
static SmartPtr<BufMap> instance();

GstBuffer* gbuf(SmartPtr<V4l2Buffer> &buf) {
uint32_t vbuf_idx = buf->get_buf().index;
if (_v2g.find(vbuf_idx) == _v2g.end()) { //non-existing
return NULL;
}
return _v2g[vbuf_idx];
}
SmartPtr<V4l2Buffer> vbuf(GstBuffer* gbuf) {
if (_g2v.find(gbuf) == _g2v.end()) { //non-existing
return NULL;
}
return _g2v[gbuf];
}
void setmap(GstBuffer* gbuf, SmartPtr<V4l2Buffer>& buf) {
_g2v[gbuf] = buf;
_v2g[buf->get_buf().index] = gbuf;
}

private:
XCAM_DEAD_COPY (BufMap);

private:
BufMap()
: _g2v(std::map<GstBuffer*, SmartPtr<V4l2Buffer> >())
, _v2g(std::map<uint32_t, GstBuffer*>())
{};

static SmartPtr<BufMap> _instance;
static Mutex _mutex;

std::map <GstBuffer*, SmartPtr<V4l2Buffer> > _g2v;
std::map <uint32_t, GstBuffer*> _v2g;
};

} //namespace

#endif // __BUFMAP_H__
62 changes: 62 additions & 0 deletions wrapper/gstreamer/fmt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* fmt.cpp - deal with the supported formats
*
* Copyright (c) 2015 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: John Ye <john.ye@intel.com>
*/

#include "fmt.h"
#include <linux/videodev2.h>

#include <map>

std::map<uint32_t, GstVideoFormat> fourcc2fmt = {

{ V4L2_PIX_FMT_NV12, GST_VIDEO_FORMAT_NV12 },
{ V4L2_PIX_FMT_NV21, GST_VIDEO_FORMAT_NV21 },
{ V4L2_PIX_FMT_YVU410, GST_VIDEO_FORMAT_YVU9 },
{ V4L2_PIX_FMT_YUV410, GST_VIDEO_FORMAT_YUV9 },
{ V4L2_PIX_FMT_YUV420, GST_VIDEO_FORMAT_I420 },
{ V4L2_PIX_FMT_YUYV, GST_VIDEO_FORMAT_YUY2 },
{ V4L2_PIX_FMT_YVU420, GST_VIDEO_FORMAT_YV12 },
{ V4L2_PIX_FMT_UYVY, GST_VIDEO_FORMAT_UYVY },
{ V4L2_PIX_FMT_YUV411P, GST_VIDEO_FORMAT_Y41B },
{ V4L2_PIX_FMT_YUV422P, GST_VIDEO_FORMAT_Y42B }
#ifdef V4L2_PIX_FMT_YVYU
, { V4L2_PIX_FMT_YVYU, GST_VIDEO_FORMAT_YVYU}
#endif

};

#define GST_V4L2_MAX_SIZE (1<<15)

void caps_append(GstCaps *caps)
{
GstStructure *structure;
std::map<uint32_t, GstVideoFormat>::iterator iter;

for (iter = fourcc2fmt.begin(); iter != fourcc2fmt.end(); iter++) {
structure = gst_structure_new ("video/x-raw",
"format", G_TYPE_STRING,
gst_video_format_to_string (iter->second),
NULL);
gst_structure_set (structure,
"width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
"height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1, NULL);
gst_caps_append_structure (caps, structure);
}
}
37 changes: 37 additions & 0 deletions wrapper/gstreamer/fmt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* fmt.h - deal with the supported formats
*
* Copyright (c) 2015 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: John Ye <john.ye@intel.com>
*/

#ifndef __FMT_H__
#define __FMT_H__

#include <gst/video/video-format.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

void caps_append(GstCaps *caps);

#ifdef __cplusplus
}
#endif

#endif // __FMT_H__
Loading