Loading src/application/encoder.vala +35 −7 Original line number Original line Diff line number Diff line Loading @@ -22,11 +22,21 @@ namespace MLM { namespace MLM { /** * Class for encoders. */ public class Encoder : Media { public class Encoder : Media { /* The source filename. */ private string source; private string source; /* The target filename. */ private string target; private string target; /** * Initializes the encoder. * @param source the source filename. * @param target the target filename. */ public Encoder(string source, string target) { public Encoder(string source, string target) { base(); base(); this.source = source; this.source = source; Loading @@ -38,22 +48,34 @@ namespace MLM { sink.set_property("location", target); sink.set_property("location", target); } } /** * Sets the pipeline. */ protected override void set_pipeline() { protected override void set_pipeline() { try { try { pipe = (Gst.Pipeline) pipe = (Gst.Pipeline) Gst.parse_launch( Gst.parse_launch( "filesrc name=src ! " + "filesrc " + " name=src ! " + "decodebin ! " + "decodebin ! " + "audioconvert ! " + "audioconvert ! " + "rglimiter ! " + "rglimiter ! " + "audioconvert ! " + "audioconvert ! " + "lamemp3enc target=1 bitrate=128 cbr=true ! " + "lamemp3enc " + "filesink name=sink"); " target=1 " + " bitrate=128 " + " cbr=true ! " + "filesink " + " name=sink"); } catch (GLib.Error e) { } catch (GLib.Error e) { stderr.printf("%s\n", e.message); stderr.printf("%s\n", e.message); } } } } /** * Handles the message received. * @param message the message. */ protected override void message_received(Gst.Message message) { protected override void message_received(Gst.Message message) { switch (message.type) { switch (message.type) { case Gst.MessageType.EOS: case Gst.MessageType.EOS: Loading @@ -75,11 +97,17 @@ namespace MLM { } } } } /** * Encodes the source. */ public void encode() { public void encode() { pipe.set_state(Gst.State.PLAYING); pipe.set_state(Gst.State.PLAYING); working = true; working = true; } } /** * Cancel the encoding. */ public void cancel() { public void cancel() { pipe.set_state(Gst.State.NULL); pipe.set_state(Gst.State.NULL); } } Loading src/application/media.vala +26 −1 Original line number Original line Diff line number Diff line Loading @@ -22,23 +22,48 @@ namespace MLM { namespace MLM { /** * Abstract class for media. */ public abstract class Media : GLib.Object { public abstract class Media : GLib.Object { /** * The pipeline. */ protected Gst.Pipeline pipe; protected Gst.Pipeline pipe; /** * Whether the media is working. */ public bool working { get; protected set; } public bool working { get; protected set; } /** * Initializes the media. */ public Media() { public Media() { set_pipeline(); set_pipeline(); var bus = pipe.get_bus(); var bus = pipe.get_bus(); bus.add_signal_watch(); bus.add_signal_watch(); bus.message.connect(message_received); bus.message.connect(message_received); } } /** * Sets the pipeline. */ protected abstract void set_pipeline(); protected abstract void set_pipeline(); /** * Handles the message received. * @param message the message. */ protected abstract void message_received(Gst.Message message); protected abstract void message_received(Gst.Message message); /** * Returns the completion percentage of the media. * @param duration the duration of the media. * @param duration the position of the media. * @return the completion percentage of the media. */ public double get_completion(out int64 duration = null, public double get_completion(out int64 duration = null, out int64 position = null) { out int64 position = null) { duration = -1; duration = -1; Loading src/application/player.vala +43 −0 Original line number Original line Diff line number Diff line Loading @@ -22,13 +22,32 @@ namespace MLM { namespace MLM { /** * Class for players. */ public class Player : Media { public class Player : Media { /** * The “state-changed” signal. * * The ''::state-changed'' signal will be emitted when the state of the * player changes. * @param state the new state. */ public signal void state_changed(Gst.State state); public signal void state_changed(Gst.State state); /** * The state. */ public Gst.State state { get { return obtain_state(); } } public Gst.State state { get { return obtain_state(); } } /* The last state. */ private Gst.State last_state; private Gst.State last_state; /** * Initializes the player. * @param filename the filename. */ public Player(string filename) { public Player(string filename) { base(); base(); var src = pipe.get_by_name("src"); var src = pipe.get_by_name("src"); Loading @@ -37,6 +56,9 @@ namespace MLM { last_state = Gst.State.PAUSED; last_state = Gst.State.PAUSED; } } /** * Sets the pipeline. */ protected override void set_pipeline() { protected override void set_pipeline() { try { try { pipe = (Gst.Pipeline) pipe = (Gst.Pipeline) Loading @@ -49,6 +71,10 @@ namespace MLM { } } } } /** * Handles the message received. * @param message the message. */ protected override void message_received(Gst.Message message) { protected override void message_received(Gst.Message message) { switch (message.type) { switch (message.type) { case Gst.MessageType.EOS: case Gst.MessageType.EOS: Loading Loading @@ -78,18 +104,31 @@ namespace MLM { } } } } /** * Plays the player. */ public void play() { public void play() { pipe.set_state(Gst.State.PLAYING); pipe.set_state(Gst.State.PLAYING); } } /** * Pauses the player. */ public void pause() { public void pause() { pipe.set_state(Gst.State.PAUSED); pipe.set_state(Gst.State.PAUSED); } } /** * Finishes the player. */ public void finish() { public void finish() { pipe.set_state(Gst.State.READY); pipe.set_state(Gst.State.READY); } } /** * Seeks a position in the player. * @para percentage the percentage position. */ public bool seek(double percentage) { public bool seek(double percentage) { int64 duration = -1; int64 duration = -1; if (!pipe.query_duration(Gst.Format.TIME, out duration)) if (!pipe.query_duration(Gst.Format.TIME, out duration)) Loading @@ -103,6 +142,10 @@ namespace MLM { return true; return true; } } /** * Returns the current state. * @return the current state. */ private Gst.State obtain_state() { private Gst.State obtain_state() { var new_state = Gst.State.NULL; var new_state = Gst.State.NULL; var pending = Gst.State.NULL; var pending = Gst.State.NULL; Loading Loading
src/application/encoder.vala +35 −7 Original line number Original line Diff line number Diff line Loading @@ -22,11 +22,21 @@ namespace MLM { namespace MLM { /** * Class for encoders. */ public class Encoder : Media { public class Encoder : Media { /* The source filename. */ private string source; private string source; /* The target filename. */ private string target; private string target; /** * Initializes the encoder. * @param source the source filename. * @param target the target filename. */ public Encoder(string source, string target) { public Encoder(string source, string target) { base(); base(); this.source = source; this.source = source; Loading @@ -38,22 +48,34 @@ namespace MLM { sink.set_property("location", target); sink.set_property("location", target); } } /** * Sets the pipeline. */ protected override void set_pipeline() { protected override void set_pipeline() { try { try { pipe = (Gst.Pipeline) pipe = (Gst.Pipeline) Gst.parse_launch( Gst.parse_launch( "filesrc name=src ! " + "filesrc " + " name=src ! " + "decodebin ! " + "decodebin ! " + "audioconvert ! " + "audioconvert ! " + "rglimiter ! " + "rglimiter ! " + "audioconvert ! " + "audioconvert ! " + "lamemp3enc target=1 bitrate=128 cbr=true ! " + "lamemp3enc " + "filesink name=sink"); " target=1 " + " bitrate=128 " + " cbr=true ! " + "filesink " + " name=sink"); } catch (GLib.Error e) { } catch (GLib.Error e) { stderr.printf("%s\n", e.message); stderr.printf("%s\n", e.message); } } } } /** * Handles the message received. * @param message the message. */ protected override void message_received(Gst.Message message) { protected override void message_received(Gst.Message message) { switch (message.type) { switch (message.type) { case Gst.MessageType.EOS: case Gst.MessageType.EOS: Loading @@ -75,11 +97,17 @@ namespace MLM { } } } } /** * Encodes the source. */ public void encode() { public void encode() { pipe.set_state(Gst.State.PLAYING); pipe.set_state(Gst.State.PLAYING); working = true; working = true; } } /** * Cancel the encoding. */ public void cancel() { public void cancel() { pipe.set_state(Gst.State.NULL); pipe.set_state(Gst.State.NULL); } } Loading
src/application/media.vala +26 −1 Original line number Original line Diff line number Diff line Loading @@ -22,23 +22,48 @@ namespace MLM { namespace MLM { /** * Abstract class for media. */ public abstract class Media : GLib.Object { public abstract class Media : GLib.Object { /** * The pipeline. */ protected Gst.Pipeline pipe; protected Gst.Pipeline pipe; /** * Whether the media is working. */ public bool working { get; protected set; } public bool working { get; protected set; } /** * Initializes the media. */ public Media() { public Media() { set_pipeline(); set_pipeline(); var bus = pipe.get_bus(); var bus = pipe.get_bus(); bus.add_signal_watch(); bus.add_signal_watch(); bus.message.connect(message_received); bus.message.connect(message_received); } } /** * Sets the pipeline. */ protected abstract void set_pipeline(); protected abstract void set_pipeline(); /** * Handles the message received. * @param message the message. */ protected abstract void message_received(Gst.Message message); protected abstract void message_received(Gst.Message message); /** * Returns the completion percentage of the media. * @param duration the duration of the media. * @param duration the position of the media. * @return the completion percentage of the media. */ public double get_completion(out int64 duration = null, public double get_completion(out int64 duration = null, out int64 position = null) { out int64 position = null) { duration = -1; duration = -1; Loading
src/application/player.vala +43 −0 Original line number Original line Diff line number Diff line Loading @@ -22,13 +22,32 @@ namespace MLM { namespace MLM { /** * Class for players. */ public class Player : Media { public class Player : Media { /** * The “state-changed” signal. * * The ''::state-changed'' signal will be emitted when the state of the * player changes. * @param state the new state. */ public signal void state_changed(Gst.State state); public signal void state_changed(Gst.State state); /** * The state. */ public Gst.State state { get { return obtain_state(); } } public Gst.State state { get { return obtain_state(); } } /* The last state. */ private Gst.State last_state; private Gst.State last_state; /** * Initializes the player. * @param filename the filename. */ public Player(string filename) { public Player(string filename) { base(); base(); var src = pipe.get_by_name("src"); var src = pipe.get_by_name("src"); Loading @@ -37,6 +56,9 @@ namespace MLM { last_state = Gst.State.PAUSED; last_state = Gst.State.PAUSED; } } /** * Sets the pipeline. */ protected override void set_pipeline() { protected override void set_pipeline() { try { try { pipe = (Gst.Pipeline) pipe = (Gst.Pipeline) Loading @@ -49,6 +71,10 @@ namespace MLM { } } } } /** * Handles the message received. * @param message the message. */ protected override void message_received(Gst.Message message) { protected override void message_received(Gst.Message message) { switch (message.type) { switch (message.type) { case Gst.MessageType.EOS: case Gst.MessageType.EOS: Loading Loading @@ -78,18 +104,31 @@ namespace MLM { } } } } /** * Plays the player. */ public void play() { public void play() { pipe.set_state(Gst.State.PLAYING); pipe.set_state(Gst.State.PLAYING); } } /** * Pauses the player. */ public void pause() { public void pause() { pipe.set_state(Gst.State.PAUSED); pipe.set_state(Gst.State.PAUSED); } } /** * Finishes the player. */ public void finish() { public void finish() { pipe.set_state(Gst.State.READY); pipe.set_state(Gst.State.READY); } } /** * Seeks a position in the player. * @para percentage the percentage position. */ public bool seek(double percentage) { public bool seek(double percentage) { int64 duration = -1; int64 duration = -1; if (!pipe.query_duration(Gst.Format.TIME, out duration)) if (!pipe.query_duration(Gst.Format.TIME, out duration)) Loading @@ -103,6 +142,10 @@ namespace MLM { return true; return true; } } /** * Returns the current state. * @return the current state. */ private Gst.State obtain_state() { private Gst.State obtain_state() { var new_state = Gst.State.NULL; var new_state = Gst.State.NULL; var pending = Gst.State.NULL; var pending = Gst.State.NULL; Loading