Skip to content

Commit

Permalink
made AudioManager class a singleton, moved events from conversationwi…
Browse files Browse the repository at this point in the history
…dget to contactlistwindow
  • Loading branch information
naxuroqa committed Jun 13, 2014
1 parent 7932871 commit 452dfd3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 80 deletions.
72 changes: 46 additions & 26 deletions src/core/AudioManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,59 @@
* along with Venom. If not, see <http://www.gnu.org/licenses/>.
*/

using Gst;

namespace Venom {
public class AudioManager {

private Pipeline pipeline;
private Element asrc;
private Element asink;

public AudioManager(string[] fakeArgs) {
Gst.init(ref fakeArgs);
}
public errordomain AudioManagerError {
INIT
}

public void build_audio_pipeline() {
this.pipeline = new Pipeline("audioPipeline");
this.asrc = ElementFactory.make("autoaudiosrc", "audio");
this.asink = ElementFactory.make("autoaudiosink", "asink");
this.pipeline.add_many(this.asrc, this.asink);
this.asrc.link(this.asink);
}
public class AudioManager {

public void destroy_audio_pipeline() {
this.pipeline.set_state(Gst.State.NULL);
}
private const string PIPELINE = "audioPipeline";
private const string AUDIO_SOURCE = "audioSource";
private const string AUDIO_SINK = "audioSink";

public void set_pipeline_ready() {
this.pipeline.set_state(State.READY);
}
private Gst.Pipeline pipeline;
private Gst.Element audio_source;
private Gst.Element audio_sink;

public static AudioManager instance {get; private set;}

public static void init() throws AudioManagerError {
instance = new AudioManager({""});
}

public void set_pipeline_playing() {
this.pipeline.set_state(State.PLAYING);
private AudioManager(string[] args) throws AudioManagerError {
// Initialize Gstreamer
try {
if(!Gst.init_check(ref args)) {
throw new AudioManagerError.INIT("Gstreamer initialization failed.");
}
} catch (Error e) {
throw new AudioManagerError.INIT(e.message);
}
stdout.printf("Gstreamer initialized\n");

pipeline = new Gst.Pipeline(PIPELINE);
audio_source = Gst.ElementFactory.make("autoaudiosrc", AUDIO_SOURCE);
audio_sink = Gst.ElementFactory.make("autoaudiosink", AUDIO_SINK);
pipeline.add_many(audio_source, audio_sink);
audio_source.link(audio_sink);
}

public void destroy_audio_pipeline() {
pipeline.set_state(Gst.State.NULL);
}

public void set_pipeline_paused() {
pipeline.set_state(Gst.State.PAUSED);
stdout.printf("Pipeline set to paused\n");
}

public void set_pipeline_playing() {
pipeline.set_state(Gst.State.PLAYING);
stdout.printf("Pipeline set to playing\n");
}

}
}

36 changes: 22 additions & 14 deletions src/core/Contact.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@


namespace Venom {
public enum AudioCallState {
RINGING,
STARTING,
ENDING
}


public interface IContact : GLib.Object {
public abstract string get_name_string();
public abstract string get_name_string_with_hyperlinks();
Expand All @@ -33,22 +40,23 @@ namespace Venom {

public class Contact : IContact, GLib.Object {
// Saved in toxs savefile
public uint8[] public_key { get; set; }
public int friend_id { get; set; default = -1;}
public string name { get; set; default = ""; }
public string status_message { get; set; default = ""; }
public DateTime last_seen { get; set; default = null; }
public uint8 user_status { get; set; default = (uint8)Tox.UserStatus.INVALID; }
public uint8[] public_key { get; set; }
public int friend_id { get; set; default = -1;}
public string name { get; set; default = ""; }
public string status_message { get; set; default = ""; }
public DateTime last_seen { get; set; default = null; }
public uint8 user_status { get; set; default = (uint8)Tox.UserStatus.INVALID; }
// Saved in venoms savefile
public string note { get; set; default = ""; }
public string alias { get; set; default = ""; }
public bool is_blocked { get; set; default = false; }
public string group { get; set; default = ""; }
public string note { get; set; default = ""; }
public string alias { get; set; default = ""; }
public bool is_blocked { get; set; default = false; }
public string group { get; set; default = ""; }
// Not saved
public bool online { get; set; default = false; }
public Gdk.Pixbuf? image { get; set; default = null; }
public int unread_messages { get; set; default = 0; }
public bool is_typing { get; set; default = false; }
public bool online { get; set; default = false; }
public Gdk.Pixbuf? image { get; set; default = null; }
public int unread_messages { get; set; default = 0; }
public bool is_typing { get; set; default = false; }
public AudioCallState audio_call_state { get; set; default = AudioCallState.ENDING; }

private GLib.HashTable<uint8, FileTransfer> _file_transfers = new GLib.HashTable<uint8, FileTransfer>(null, null);

Expand Down
5 changes: 5 additions & 0 deletions src/ui/Client.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ namespace Venom {

protected override void startup() {
add_action_entries(app_entries, this);
try {
AudioManager.init();
} catch (AudioManagerError e) {
stderr.printf("Error creating Audio Pipeline: %s\n", e.message);
}

base.startup();
}
Expand Down
10 changes: 10 additions & 0 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,14 @@ namespace Venom {
groupchat_changed(g);
}

private void on_start_audio_call(Contact c) {
AudioManager.instance.set_pipeline_playing();
}

private void on_stop_audio_call(Contact c) {
AudioManager.instance.set_pipeline_paused();
}

private void on_file_sendrequest(int friendnumber, uint8 filenumber, uint64 filesize,string filename) {
stdout.printf ("received file send request friend: %i filenumber: %i filename: %s \n",friendnumber,filenumber,filename );
Contact contact = session.get_contact_list()[friendnumber];
Expand Down Expand Up @@ -968,6 +976,8 @@ namespace Venom {
w.new_outgoing_message.connect(on_outgoing_message);
w.new_outgoing_action.connect(on_outgoing_action);
w.new_outgoing_file.connect(on_outgoing_file);
w.start_audio_call.connect(on_start_audio_call);
w.stop_audio_call.connect(on_stop_audio_call);
w.typing_status.connect( (is_typing) => {
if(Settings.instance.send_typing_status) {
session.set_user_is_typing(c.friend_id, is_typing);
Expand Down
50 changes: 10 additions & 40 deletions src/ui/ConversationWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
* along with Venom. If not, see <http://www.gnu.org/licenses/>.
*/

using Gst;

namespace Venom {

public class ConversationWidget : Gtk.EventBox {
private EditableLabel label_contact_name;
private Gtk.Label label_contact_statusmessage;
Expand All @@ -40,12 +39,10 @@ namespace Venom {
public signal void filetransfer_accepted(FileTransfer ft);
public signal void filetransfer_rejected(FileTransfer ft);
public signal void contact_changed(Contact c);
public bool pipe_built = false;
public bool audio_on = false;
public signal void start_audio_call(Contact c);
public signal void stop_audio_call(Contact c);

private Pipeline pipeline;
private Element asrc;
private Element asink;
private bool audio_on = false;

public ConversationWidget( Contact contact ) {
this.contact = contact;
Expand Down Expand Up @@ -264,40 +261,13 @@ namespace Venom {
prepare_send_file(file);
}

public void button_call_clicked(Gtk.Button source) {
if(!pipe_built){
string[] hackArgs = {"\0"};
build_audio_pipeline(hackArgs);
pipe_built = true;
}

if(!audio_on) {
set_play();
audio_on = true;
} else {
set_ready();
audio_on = false;
public void button_call_clicked(Gtk.Button source) {
if(!audio_on) {
start_audio_call(contact);
} else {
stop_audio_call(contact);
}
}

public void build_audio_pipeline(string[] hackArgs) {
Gst.init(ref hackArgs);
this.pipeline = new Pipeline("mypipeline");
this.asrc = ElementFactory.make("autoaudiosrc", "audio");
this.asink = ElementFactory.make("autoaudiosink", "asink");
this.pipeline.add_many(this.asrc, this.asink);
this.asrc.link(this.asink);
return;
}

public void set_play() {
this.pipeline.set_state(State.PLAYING);
return;
}

public void set_ready() {
this.pipeline.set_state(State.READY);
return;
audio_on = !audio_on;
}

private void on_drag_data_received(Gtk.Widget sender, Gdk.DragContext drag_context, int x, int y, Gtk.SelectionData data, uint info, uint time) {
Expand Down

0 comments on commit 452dfd3

Please sign in to comment.