commit eea3100610c6d0d6b542c42d9172a9e1047f2dfa
parent 9d4ee1ea7f54e53a1dcb3da3f44e421a30e30a0b
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date: Fri, 7 May 2010 21:08:50 +1000
Re-decode on size change
Also fixed a memory leak, the source wasn't properly unreferenced.
Diffstat:
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/src/spek-source.vala b/src/spek-source.vala
@@ -17,14 +17,29 @@ namespace Spek {
private Pad pad = null;
private int sample;
private float[] values;
+ private uint watch_id;
public Source (string file_name, int bands, int samples, int threshold, Callback callback) {
GLib.Object (file_name: file_name, bands: bands, samples: samples, threshold: threshold);
this.callback = callback;
}
+ public void stop () {
+ if (watch_id > 0) {
+ GLib.Source.remove (watch_id);
+ watch_id = 0;
+ }
+ if (pipeline != null) {
+ pipeline.set_state (State.NULL);
+ pipeline = null;
+ }
+ spectrum = null;
+ pad = null;
+ }
+
~Source () {
- pipeline.set_state (State.NULL);
+ stop ();
+ stdout.printf ("unref\n");
}
construct {
@@ -45,7 +60,7 @@ namespace Spek {
decodebin, "new-decoded-pad",
(GLib.Callback) on_new_decoded_pad, this);
- pipeline.get_bus ().add_watch (on_bus_watch);
+ this.watch_id = pipeline.get_bus ().add_watch (on_bus_watch);
if (pipeline.set_state (State.PAUSED) == StateChangeReturn.ASYNC) {
pipeline.get_state (null, null, -1);
}
diff --git a/src/spek-spectrogram.vala b/src/spek-spectrogram.vala
@@ -6,6 +6,7 @@ namespace Spek {
class Spectrogram : DrawingArea {
private Source source;
+ private string file_name;
private const int THRESHOLD = -92;
private ImageSurface image;
@@ -15,13 +16,29 @@ namespace Spek {
}
public void open (string file_name) {
- image = new ImageSurface (Format.RGB24, allocation.width, allocation.height);
- source = new Source (
+ this.file_name = file_name;
+ start ();
+ }
+
+ private void start () {
+ this.image = new ImageSurface (Format.RGB24, allocation.width, allocation.height);
+ if (this.source != null) {
+ this.source.stop ();
+ this.source = null;
+ }
+ this.source = new Source (
file_name, allocation.height, allocation.width,
THRESHOLD, source_callback);
queue_draw ();
}
+ private override void size_allocate (Gdk.Rectangle allocation) {
+ base.size_allocate (allocation);
+ if (file_name != null) {
+ start ();
+ }
+ }
+
private void source_callback (int sample, float[] values) {
var x = sample;
var stride = image.get_stride ();