[longomatch] Use the new remuxer



commit 8686de8beb459346f1f21d5668b2879d200bcc1f
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Oct 5 03:20:53 2012 +0200

    Use the new remuxer

 LongoMatch.Multimedia/Utils/MpegRemuxer.cs |   65 +++++++++++-----------------
 1 files changed, 26 insertions(+), 39 deletions(-)
---
diff --git a/LongoMatch.Multimedia/Utils/MpegRemuxer.cs b/LongoMatch.Multimedia/Utils/MpegRemuxer.cs
index 4d9f48f..edb12f7 100644
--- a/LongoMatch.Multimedia/Utils/MpegRemuxer.cs
+++ b/LongoMatch.Multimedia/Utils/MpegRemuxer.cs
@@ -17,30 +17,32 @@
 // 
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.IO;
-using System.Threading;
 using Mono.Unix;
 using GLib;
 using Gtk;
 
+using LongoMatch.Interfaces.Multimedia;
+
 namespace LongoMatch.Video.Utils
 {
 	public class MpegRemuxer
 	{
-		private static string[] EXTENSIONS =  {"mts", "m2ts", "m2t", "ts", "mpeg", "mpg"};
-		private string filepath;
-		private string newFilepath;
-		private Dialog dialog;
-		private ProgressBar pb;
-		private System.Threading.Thread remuxThread;
-		private uint timeout;
-		private bool cancelled;
+		static string[] EXTENSIONS =  {"mts", "m2ts", "m2t", "ts", "mpeg", "mpg"};
+		string filepath;
+		string newFilepath;
+		Dialog dialog;
+		ProgressBar pb;
+		IRemuxer remuxer;
+		IMultimediaToolkit multimedia;
+		uint timeout;
+		bool cancelled;
 		
 		public MpegRemuxer (string filepath)
 		{
 			this.filepath = filepath;
-			newFilepath = Path.ChangeExtension(filepath, "mp4");
+			this.multimedia = new MultimediaFactory();
+			newFilepath = Path.ChangeExtension(filepath, "webm");
 		}
 		
 		public string Remux(Window parent) {
@@ -59,22 +61,29 @@ namespace LongoMatch.Video.Utils
 			
 			/* Add a button to cancell the task */
 			cancellButton = new Button("gtk-cancel");
-			cancellButton.Clicked += OnStop; 
+			cancellButton.Clicked += (sender, e) => Cancel (); 
 			cancellButton.Show();
 			dialog.VBox.Add(cancellButton);
 			
-			/* Start the remux task in a separate thread */
-			remuxThread = new System.Threading.Thread(new ThreadStart(RemuxTask));
-			remuxThread.Start();
-			
 			/* Add a timeout to refresh the progress bar */ 
 			pb.Pulse();
 			timeout = GLib.Timeout.Add (1000, new GLib.TimeoutHandler (Update));
 			
+			remuxer = multimedia.GetRemuxer(filepath, newFilepath);
+			remuxer.Progress += HandleRemuxerProgress;;
+			remuxer.Start();
+			
 			/* Wait until the thread call Destroy on the dialog */
 			dialog.Run();
 			return cancelled ? null : newFilepath;
 		}
+
+		void HandleRemuxerProgress (float progress)
+		{
+			if (progress == 1) {
+				Stop ();
+			}
+		}
 		
 		private bool Update() {
 			pb.Pulse();			
@@ -82,33 +91,11 @@ namespace LongoMatch.Video.Utils
 		}
 		
 		private void Stop() {
-			if (cancelled) {
-				if (remuxThread.IsAlive)
-					remuxThread.Interrupt();
-				File.Delete (newFilepath);
-			}
 			GLib.Source.Remove (timeout);
 			dialog.Destroy();
 		}
 		
-		private void RemuxTask(){
-			/* ffmpeg looks like the easiest and more accurate way to do the remux */
-			ProcessStartInfo startInfo = new ProcessStartInfo();
-			startInfo.CreateNoWindow = true;
-			startInfo.UseShellExecute = false;
-			startInfo.FileName = "ffmpeg";
-			startInfo.Arguments = String.Format("-i {0} -vcodec copy -acodec copy -y -sn {1} ",
-			                                    filepath, newFilepath);
-			using (System.Diagnostics.Process exeProcess = System.Diagnostics.Process.Start(startInfo))
-			{
-				exeProcess.WaitForExit();
-				Application.Invoke (delegate {
-					Stop();
-				});
-			}
-		}
-		
-		private void OnStop (object sender, System.EventArgs args) {
+		void Cancel() {
 			cancelled = true;
 			Stop();
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]