Skip to content

Commit

Permalink
Merge pull request mavlink#4003 from dogmaphobic/rtspAndroid
Browse files Browse the repository at this point in the history
Adding static RTSP libraries and dependencies to Android.
  • Loading branch information
dogmaphobic authored Aug 31, 2016
2 parents a64fb6b + fffcbe7 commit 681556f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions QGCCommon.pri
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ linux {
equals(ANDROID_TARGET_ARCH, x86) {
CONFIG += Androidx86Build
DEFINES += __androidx86__
DEFINES += QGC_DISABLE_UVC
message("Android x86 build")
} else {
message("Android Arm build")
Expand Down
57 changes: 56 additions & 1 deletion src/VideoStreaming/VideoStreaming.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/****************************************************************************
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
Expand All @@ -19,6 +19,9 @@

#if defined(QGC_GST_STREAMING)
#include <gst/gst.h>
#ifdef __android__
//#define ANDDROID_GST_DEBUG
#endif
#endif

#include "VideoStreaming.h"
Expand All @@ -34,9 +37,11 @@
GST_PLUGIN_STATIC_DECLARE(coreelements);
GST_PLUGIN_STATIC_DECLARE(libav);
GST_PLUGIN_STATIC_DECLARE(rtp);
GST_PLUGIN_STATIC_DECLARE(rtsp);
GST_PLUGIN_STATIC_DECLARE(udp);
GST_PLUGIN_STATIC_DECLARE(videoparsersbad);
GST_PLUGIN_STATIC_DECLARE(x264);
GST_PLUGIN_STATIC_DECLARE(rtpmanager);
#endif
G_END_DECLS
#endif
Expand All @@ -51,6 +56,49 @@ static void qgcputenv(const QString& key, const QString& root, const QString& pa
#endif
#endif

#ifdef ANDDROID_GST_DEBUG
// Redirects stdio and stderr to logcat
#include <unistd.h>
#include <pthread.h>
#include <android/log.h>

static int pfd[2];
static pthread_t thr;
static const char *tag = "myapp";

static void *thread_func(void*)
{
ssize_t rdsz;
char buf[128];
while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
if(buf[rdsz - 1] == '\n') --rdsz;
buf[rdsz] = 0; /* add null-terminator */
__android_log_write(ANDROID_LOG_DEBUG, tag, buf);
}
return 0;
}

int start_logger(const char *app_name)
{
tag = app_name;

/* make stdout line-buffered and stderr unbuffered */
setvbuf(stdout, 0, _IOLBF, 0);
setvbuf(stderr, 0, _IONBF, 0);

/* create the pipe and redirect stdout and stderr */
pipe(pfd);
dup2(pfd[1], 1);
dup2(pfd[1], 2);

/* spawn the logging thread */
if(pthread_create(&thr, 0, thread_func, 0) == -1)
return -1;
pthread_detach(thr);
return 0;
}
#endif

void initializeVideoStreaming(int &argc, char* argv[])
{
#if defined(QGC_GST_STREAMING)
Expand All @@ -70,6 +118,11 @@ void initializeVideoStreaming(int &argc, char* argv[])
qgcputenv("GST_PLUGIN_PATH", currentDir, "/gstreamer-plugins");
#endif
// Initialize GStreamer
#ifdef ANDDROID_GST_DEBUG
start_logger("gst_log");
qputenv("GST_DEBUG", "*:4");
qputenv("GST_DEBUG_NO_COLOR", "1");
#endif
GError* error = NULL;
if (!gst_init_check(&argc, &argv, &error)) {
qCritical() << "gst_init_check() failed: " << error->message;
Expand All @@ -82,9 +135,11 @@ void initializeVideoStreaming(int &argc, char* argv[])
GST_PLUGIN_STATIC_REGISTER(coreelements);
GST_PLUGIN_STATIC_REGISTER(libav);
GST_PLUGIN_STATIC_REGISTER(rtp);
GST_PLUGIN_STATIC_REGISTER(rtsp);
GST_PLUGIN_STATIC_REGISTER(udp);
GST_PLUGIN_STATIC_REGISTER(videoparsersbad);
GST_PLUGIN_STATIC_REGISTER(x264);
GST_PLUGIN_STATIC_REGISTER(rtpmanager);
#endif
#else
Q_UNUSED(argc);
Expand Down
15 changes: 10 additions & 5 deletions src/VideoStreaming/VideoStreaming.pri
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,24 @@ LinuxBuild {
-lgstcoreelements \
-lgstudp \
-lgstrtp \
-lgstrtsp \
-lgstx264 \
-lgstlibav \
-lgstvideoparsersbad
-lgstsdpelem \
-lgstvideoparsersbad \
-lgstrtpmanager \
-lgstrmdemux \

# Rest of GStreamer dependencies
LIBS += -L$$GST_ROOT/lib \
-lgstfft-1.0 -lm \
-lgstnet-1.0 -lgio-2.0 \
-lgstaudio-1.0 -lgstcodecparsers-1.0 -lgstbase-1.0 \
-lgstreamer-1.0 -lgsttag-1.0 -lgstrtp-1.0 -lgstpbutils-1.0 \
-lgstvideo-1.0 -lavformat -lavcodec -lavresample -lavutil -lx264 \
-lbz2 -lgobject-2.0 \
-Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lorc-0.4 -liconv -lffi -lintl
-lgstreamer-1.0 -lgstrtp-1.0 -lgstpbutils-1.0 -lgstrtsp-1.0 -lgsttag-1.0 \
-lgstvideo-1.0 -lavformat -lavcodec -lavutil -lx264 -lavresample \
-lgstriff-1.0 -lgstcontroller-1.0 -lgstapp-1.0 \
-lgstsdp-1.0 -lbz2 -lgobject-2.0 \
-Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lorc-0.4 -liconv -lffi -lintl \

INCLUDEPATH += \
$$GST_ROOT/include/gstreamer-1.0 \
Expand Down

0 comments on commit 681556f

Please sign in to comment.