tools: gst-play: add volume control

This commit is contained in:
Tim-Philipp Müller 2014-02-14 20:16:04 +00:00
parent a6890ec7ef
commit 6767d26cb2
2 changed files with 36 additions and 5 deletions

View file

@ -21,7 +21,7 @@ LDADD = $(top_builddir)/gst-libs/gst/pbutils/libgstpbutils-@GST_API_VERSION@.la
$(top_builddir)/gst-libs/gst/tag/libgsttag-@GST_API_VERSION@.la \ $(top_builddir)/gst-libs/gst/tag/libgsttag-@GST_API_VERSION@.la \
$(top_builddir)/gst-libs/gst/audio/libgstaudio-@GST_API_VERSION@.la \ $(top_builddir)/gst-libs/gst/audio/libgstaudio-@GST_API_VERSION@.la \
$(top_builddir)/gst-libs/gst/video/libgstvideo-@GST_API_VERSION@.la \ $(top_builddir)/gst-libs/gst/video/libgstvideo-@GST_API_VERSION@.la \
$(GST_BASE_LIBS) $(GST_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(LIBM)
AM_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) AM_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)

View file

@ -1,6 +1,6 @@
/* GStreamer command line playback testing utility /* GStreamer command line playback testing utility
* *
* Copyright (C) 2013 Tim-Philipp Müller <tim centricular net> * Copyright (C) 2013-2014 Tim-Philipp Müller <tim centricular net>
* Copyright (C) 2013 Collabora Ltd. * Copyright (C) 2013 Collabora Ltd.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -27,13 +27,17 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/gst-i18n-app.h> #include <gst/gst-i18n-app.h>
#include <gst/audio/audio.h>
#include <gst/pbutils/pbutils.h> #include <gst/pbutils/pbutils.h>
#include <gst/math-compat.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "gst-play-kb.h" #include "gst-play-kb.h"
#define VOLUME_STEPS 20
GST_DEBUG_CATEGORY (play_debug); GST_DEBUG_CATEGORY (play_debug);
#define GST_CAT_DEFAULT play_debug #define GST_CAT_DEFAULT play_debug
@ -67,10 +71,11 @@ static gboolean play_prev (GstPlay * play);
static gboolean play_timeout (gpointer user_data); static gboolean play_timeout (gpointer user_data);
static void play_about_to_finish (GstElement * playbin, gpointer user_data); static void play_about_to_finish (GstElement * playbin, gpointer user_data);
static void play_reset (GstPlay * play); static void play_reset (GstPlay * play);
static void play_set_relative_volume (GstPlay * play, gdouble volume_step);
static GstPlay * static GstPlay *
play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink, play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
gboolean gapless) gboolean gapless, gdouble initial_volume)
{ {
GstElement *sink; GstElement *sink;
GstPlay *play; GstPlay *play;
@ -126,6 +131,8 @@ play_new (gchar ** uris, const gchar * audio_sink, const gchar * video_sink,
G_CALLBACK (play_about_to_finish), play); G_CALLBACK (play_about_to_finish), play);
} }
play_set_relative_volume (play, initial_volume - 1.0);
return play; return play;
} }
@ -156,6 +163,23 @@ play_reset (GstPlay * play)
play->is_live = FALSE; play->is_live = FALSE;
} }
static void
play_set_relative_volume (GstPlay * play, gdouble volume_step)
{
gdouble volume;
volume = gst_stream_volume_get_volume (GST_STREAM_VOLUME (play->playbin),
GST_STREAM_VOLUME_FORMAT_LINEAR);
volume = round ((volume + volume_step) * VOLUME_STEPS) / VOLUME_STEPS;
volume = CLAMP (volume, 0.0, 10.0);
gst_stream_volume_set_volume (GST_STREAM_VOLUME (play->playbin),
GST_STREAM_VOLUME_FORMAT_LINEAR, volume);
g_print ("Volume: %.0f%% \n", volume * 100);
}
/* returns TRUE if something was installed and we should restart playback */ /* returns TRUE if something was installed and we should restart playback */
static gboolean static gboolean
play_install_missing_plugins (GstPlay * play) play_install_missing_plugins (GstPlay * play)
@ -603,6 +627,10 @@ keyboard_cb (const gchar * key_input, gpointer user_data)
relative_seek (play, +0.08); relative_seek (play, +0.08);
} else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) { } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
relative_seek (play, -0.01); relative_seek (play, -0.01);
} else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) {
play_set_relative_volume (play, +1.0 / VOLUME_STEPS);
} else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) {
play_set_relative_volume (play, -1.0 / VOLUME_STEPS);
} else { } else {
GST_INFO ("keyboard input:"); GST_INFO ("keyboard input:");
for (; *key_input != '\0'; ++key_input) for (; *key_input != '\0'; ++key_input)
@ -621,6 +649,7 @@ main (int argc, char **argv)
gboolean interactive = FALSE; /* FIXME: maybe enable by default? */ gboolean interactive = FALSE; /* FIXME: maybe enable by default? */
gboolean gapless = FALSE; gboolean gapless = FALSE;
gboolean shuffle = FALSE; gboolean shuffle = FALSE;
gdouble volume = 1.0;
gchar **filenames = NULL; gchar **filenames = NULL;
gchar *audio_sink = NULL; gchar *audio_sink = NULL;
gchar *video_sink = NULL; gchar *video_sink = NULL;
@ -640,7 +669,9 @@ main (int argc, char **argv)
{"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle, {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle,
N_("Shuffle playlist"), NULL}, N_("Shuffle playlist"), NULL},
{"interactive", 0, 0, G_OPTION_ARG_NONE, &interactive, {"interactive", 0, 0, G_OPTION_ARG_NONE, &interactive,
N_("interactive"), NULL}, N_("Interactive control via keyboard"), NULL},
{"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume,
N_("Volume"), NULL},
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
{NULL} {NULL}
}; };
@ -705,7 +736,7 @@ main (int argc, char **argv)
shuffle_uris (uris, num); shuffle_uris (uris, num);
/* prepare */ /* prepare */
play = play_new (uris, audio_sink, video_sink, gapless); play = play_new (uris, audio_sink, video_sink, gapless, volume);
if (interactive) { if (interactive) {
if (gst_play_kb_set_key_handler (keyboard_cb, play)) { if (gst_play_kb_set_key_handler (keyboard_cb, play)) {