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

Add additional AOS and LOS functionality #192

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ else
AC_MSG_ERROR(Gpredict requires libgoocanvas-2.0-dev)
fi

# check for gstreamer (optional)
if pkg-config --atleast-version=1.0 gstreamer-1.0; then
CFLAGS="$CFLAGS `pkg-config --cflags gstreamer-1.0`"
LIBS="$LIBS `pkg-config --libs gstreamer-1.0`"
havelibgstreamer=true;
AC_DEFINE(HAS_LIBGSTREAMER, 1, [Define if libgstreamer is available])
else
havelibgstreamer=false;
fi

# check for libgps (optional)
if pkg-config --atleast-version=2.90 libgps; then
CFLAGS="$CFLAGS `pkg-config --cflags libgps`"
Expand Down Expand Up @@ -94,6 +104,11 @@ GTHR_V=`pkg-config --modversion gthread-2.0`
GDK_V=`pkg-config --modversion gdk-3.0`
GTK_V=`pkg-config --modversion gtk+-3.0`
GOOC_V=`pkg-config --modversion goocanvas-2.0`
if test "$havelibgstreamer" = true ; then
GST_V=`pkg-config --modversion gstreamer-1.0`
else
GST_V='Not found'
fi
CURL_V=`pkg-config --modversion libcurl`
if test "$havelibgps" = true ; then
GPS_V=`pkg-config --modversion libgps`
Expand Down Expand Up @@ -132,6 +147,7 @@ echo Gthread version.... : $GTHR_V
echo Gdk version........ : $GDK_V
echo Gtk+ version....... : $GTK_V
echo GooCanvas version.. : $GOOC_V
echo gstreamer version.. : $GST_V
echo Libcurl version.... : $CURL_V
if test "$havelibgps" = true ; then
echo Libgps version..... : $GPS_V
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gpredict_SOURCES = \
first-time.c first-time.h \
gpredict-help.c gpredict-help.h \
gpredict-utils.c gpredict-utils.h \
gtk-audio.c gtk-audio.h \
gtk-azel-plot.c gtk-azel-plot.h \
gtk-event-list.c gtk-event-list.h \
gtk-event-list-popup.c gtk-event-list-popup.h \
Expand Down
81 changes: 81 additions & 0 deletions src/gtk-audio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* Functions to play audio files (.wav etc).
*
* This uses the gstreamer library & requires the playbin and wav plugins.
* On Windows/msys2, these can be installed with:
* pacman -S mingw-w64-i686-gstreamer mingw-w64-i686-gst-plugins-base mingw-w64-i686-gst-plugins-good
* On Centos 8:
* yum install gstreamer1 streamer1-plugins-good gstreamer1-devel
*/

#ifdef HAVE_CONFIG_H
#include <build-config.h>
#endif

#include <glib.h>
#include <glib/gi18n.h>
#ifdef HAS_LIBGSTREAMER
#include <gst/gst.h>
#endif

#include "gtk-audio.h"
#include "sat-log.h"

/* Convert path to absolute path */
gchar *
absolute_path (const gchar *filename)
{
gchar *abs_path;

if (!g_path_is_absolute (filename))
{
gchar *cwd = NULL;

cwd = g_get_current_dir();
abs_path = g_build_filename(cwd, filename, NULL);
g_free(cwd);
}
else
abs_path = g_strdup(filename);

return abs_path;
}

#ifdef HAS_LIBGSTREAMER
void audio_play_uri(gchar *uri)
{
GstElement *pipeline;

/* playbin requires an absolute URI. E.g. file:///absolute/path.
We try to see if the input uri is actually a file path. If so, we make it
into a uri.
*/
if (g_file_test(uri, G_FILE_TEST_EXISTS))
{
gchar *filename;
GError *error = NULL;

filename = absolute_path(uri);
uri = g_filename_to_uri(filename, NULL, &error);
g_free(filename);
}

/* Play audio using playbin plugin. */
pipeline = gst_element_factory_make("playbin", NULL);
if (!pipeline) {
/* This will fail if the playbin plugin isn't found. */
sat_log_log(SAT_LOG_LEVEL_ERROR,
_("%s: Failed to create playbin pipeline. Are gst plugins installed?"),
__func__);
return;
}
g_object_set(pipeline, "uri", uri, NULL);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
}
#else
void audio_play_uri(gchar *uri)
{
sat_log_log(SAT_LOG_LEVEL_WARN,
_("%s: Request to play audio \"%s\", but gpredict was compiled without libgstreamer"),
__func__, uri);
}
#endif
21 changes: 21 additions & 0 deletions src/gtk-audio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef __GTK_AUDIO_H
#define __GTK_AUDIO_H 1

#include <glib.h>

#ifdef __cplusplus
extern "C" {
#endif

/**< Play audio file. E.g. .wav
uri can be a relative pathname or URI.
E.g. ../path/file.wav, file:///path/something.wav or http://server/file.wav
Supported file formats depend on which plugins are installed.
*/
void audio_play_uri(gchar *uri);

#ifdef __cplusplus
}
#endif

#endif
Loading