Skip to content

Commit

Permalink
Merge pull request #156 from lidaobing/issue_154
Browse files Browse the repository at this point in the history
replace HAVE_GST with GST_FOUND
  • Loading branch information
lidaobing authored Feb 11, 2018
2 parents a45fc9c + 5a1c7c8 commit bcace8d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [#125] fix crash on UdpData::SomeoneSendmsg.
* [#140] fix crash on TransWindow::TerminateTransTask.
* [#132] fix file accepted when cancel the directory chooser dialog.
* [#154] fix sound system.

### refactor

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ brew install --HEAD https://raw.githubusercontent.com/iptux-src/iptux/master/hom
* for Ubuntu 14.04, please download from https://github.com/iptux-src/iptux/releases/tag/v0.6.4

```
sudo apt-get install git libgtk-3-dev libglib2.0-dev libgstreamer1.0-dev libjsoncpp-dev g++ make cmake
sudo apt-get install git libgtk-3-dev libglib2.0-dev libjsoncpp-dev g++ make cmake
sudo apt-get install libgstreamer1.0-dev gstreamer1.0-plugins-good gstreamer1.0-alsa # if you need the sound support
git clone git://github.com/iptux-src/iptux.git
cd iptux
mkdir build && cd build && cmake .. && make
Expand All @@ -62,7 +63,12 @@ iptux
### Mac OS X

```
brew install gettext gtk+3 cmake jsoncpp gstreamer
brew install gettext gtk+3 cmake jsoncpp
# if need the sound support
brew install gstreamer
brew install gst-plugins-base --with-libogg --with-libvorbis
brew install gst-plugins-good
# endif
git clone git://github.com/iptux-src/iptux.git
cd iptux
mkdir build && cd build && cmake .. && make
Expand Down
4 changes: 3 additions & 1 deletion homebrew/iptux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Iptux < Formula
depends_on 'gtk+' unless build.head?
depends_on 'gtk+3' if build.head?
depends_on 'jsoncpp'
depends_on 'gstreamer'
depends_on 'gstreamer' => :optional
depends_on 'gst-plugins-base' => ["with-ogg", "with-libvorbis"] if build.with? "gstreamer"
depends_on 'gst-plugins-good' if build.with? "gstreamer"
depends_on 'pkg-config' => :build
depends_on 'cmake' => :build
unless OS.mac?
Expand Down
10 changes: 5 additions & 5 deletions src/iptux/DataSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void DataSettings::ResetDataEntry(GtkWidget *parent) {
gtk_notebook_append_page(GTK_NOTEBOOK(note), dset.CreatePersonal(), label);
label = gtk_label_new(_("System"));
gtk_notebook_append_page(GTK_NOTEBOOK(note), dset.CreateSystem(), label);
#ifdef HAVE_GST
#ifdef GST_FOUND
label = gtk_label_new(_("Sound"));
gtk_notebook_append_page(GTK_NOTEBOOK(note), dset.CreateSound(), label);
#endif
Expand All @@ -68,7 +68,7 @@ void DataSettings::ResetDataEntry(GtkWidget *parent) {
/* 设置相关数据默认值 */
dset.SetPersonalValue();
dset.SetSystemValue();
#ifdef HAVE_GST
#ifdef GST_FOUND
dset.SetSoundValue();
#endif
dset.SetNetworkValue();
Expand All @@ -80,7 +80,7 @@ void DataSettings::ResetDataEntry(GtkWidget *parent) {
case GTK_RESPONSE_OK:
dset.ObtainPersonalValue();
dset.ObtainSystemValue();
#ifdef HAVE_GST
#ifdef GST_FOUND
dset.ObtainSoundValue();
#endif
dset.ObtainNetworkValue();
Expand All @@ -90,7 +90,7 @@ void DataSettings::ResetDataEntry(GtkWidget *parent) {
case GTK_RESPONSE_APPLY:
dset.ObtainPersonalValue();
dset.ObtainSystemValue();
#ifdef HAVE_GST
#ifdef GST_FOUND
dset.ObtainSoundValue();
#endif
dset.ObtainNetworkValue();
Expand All @@ -116,7 +116,7 @@ void DataSettings::InitSublayer() {
g_datalist_set_data_full(&mdlset, "icon-model", model,
GDestroyNotify(g_object_unref));
FillIconModel(model);
#ifdef HAVE_GST
#ifdef GST_FOUND
model = CreateSndModel();
g_datalist_set_data_full(&mdlset, "sound-model", model,
GDestroyNotify(g_object_unref));
Expand Down
51 changes: 41 additions & 10 deletions src/iptux/SoundSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
//
#include "SoundSystem.h"

#ifdef HAVE_GST
#ifdef GST_FOUND
#include <sys/time.h>
#include <cstring>
#include <glib/gi18n.h>

#include "iptux/ProgramData.h"
#include "iptux/output.h"
#include "iptux/utils.h"
#include "iptux/global.h"

using namespace std;

namespace iptux {
/**
Expand Down Expand Up @@ -60,10 +67,21 @@ void SoundSystem::InitSublayer() {
sink = gst_element_factory_make("autoaudiosink", "output");
g_datalist_set_data(&eltset, "output-element", sink);

if(!filesrc || !decode || !volume || !convert || !sink ) {
LOG_WARN("init sound system failed");
return;
}

gst_bin_add_many(GST_BIN(pipeline), filesrc, decode, volume, convert, sink,
NULL);
gst_element_link_many(filesrc, decode, NULL);
gst_element_link_many(volume, convert, sink, NULL);
if(!gst_element_link_many(filesrc, decode, NULL)) {
LOG_WARN("init sound system failed");
return;
}
if(!gst_element_link_many(volume, convert, sink, NULL)) {
LOG_WARN("init sound system failed");
return;
}
g_signal_connect_swapped(decode, "pad-added", G_CALLBACK(LinkElement),
&eltset);

Expand All @@ -75,7 +93,7 @@ void SoundSystem::InitSublayer() {
this);
gst_object_unref(bus);

g_object_set(volume, "volume", progdt.volume, NULL);
g_object_set(volume, "volume", g_progdt->volume, NULL);
}

/**
Expand All @@ -99,15 +117,18 @@ void SoundSystem::Playing(const char *file) {
struct timeval time;

gettimeofday(&time, NULL);
if (!FLAG_ISSET(progdt.sndfgs, 0) || (difftimeval(time, timestamp) < 0.1))
if (!FLAG_ISSET(g_progdt->sndfgs, 0) || (difftimeval(time, timestamp) < 0.1))
return;

if (persist) EosMessageOccur(this);
persist = true;
filesrc = GST_ELEMENT(g_datalist_get_data(&eltset, "filesrc-element"));
g_object_set(filesrc, "location", file, NULL);
pipeline = GST_ELEMENT(g_datalist_get_data(&eltset, "pipeline-element"));
gst_element_set_state(pipeline, GST_STATE_PLAYING);
auto res = gst_element_set_state(pipeline, GST_STATE_PLAYING);
if(res == GST_STATE_CHANGE_FAILURE) {
LOG_WARN("gst_element_set_state failed: %d", res);
}
timestamp = time;
}

Expand All @@ -129,8 +150,12 @@ void SoundSystem::LinkElement(GData **eltset, GstPad *pad) {
str = gst_caps_get_structure(caps, 0);
volume = GST_ELEMENT(g_datalist_get_data(eltset, "volume-element"));
if (strcasestr(gst_structure_get_name(str), "audio") &&
(spad = gst_element_get_compatible_pad(volume, pad, caps)))
gst_pad_link(pad, spad);
(spad = gst_element_get_compatible_pad(volume, pad, caps))) {
auto ret = gst_pad_link(pad, spad);
if(ret != GST_PAD_LINK_OK) {
LOG_WARN("gst_pad_link failed: %d", ret);
}
}
gst_caps_unref(caps);
}

Expand All @@ -140,10 +165,15 @@ void SoundSystem::LinkElement(GData **eltset, GstPad *pad) {
void SoundSystem::ErrorMessageOccur(SoundSystem *sndsys, GstMessage *message) {
GstElement *pipeline;
GError *error;
gchar *dbgInfo = nullptr;

gst_message_parse_error(message, &error, NULL);
pwarning(_("Failed to play the prompt tone, %s\n"), error->message);
gst_message_parse_error(message, &error, &dbgInfo);
LOG_WARN(_("Failed to play the prompt tone, [%s] %s, %s"),
GST_MESSAGE_SRC_NAME(message),
error->message,
dbgInfo);
g_error_free(error);
g_free(dbgInfo);
EosMessageOccur(sndsys);
pipeline =
GST_ELEMENT(g_datalist_get_data(&sndsys->eltset, "pipeline-element"));
Expand All @@ -164,6 +194,7 @@ void SoundSystem::EosMessageOccur(SoundSystem *sndsys) {
gst_element_unlink(decode, volume);
sndsys->persist = false;
}

} // namespace iptux

#else
Expand Down

0 comments on commit bcace8d

Please sign in to comment.