[longomatch] Add a remuxer for ASF



commit bc44fc5deaf83438325c657b49adca6a9976100e
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Dec 6 18:19:24 2012 +0100

    Add a remuxer for ASF

 .../Gui/Component/ProjectDetailsWidget.cs          |    8 ++
 LongoMatch.Multimedia/LongoMatch.Multimedia.mdp    |    1 +
 LongoMatch.Multimedia/Makefile.am                  |    1 +
 LongoMatch.Multimedia/Utils/AsfRemuxer.cs          |  123 ++++++++++++++++++++
 libcesarplayer/gst-remuxer.c                       |    3 +
 5 files changed, 136 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
index 896a487..c514166 100644
--- a/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/ProjectDetailsWidget.cs
@@ -467,6 +467,14 @@ namespace LongoMatch.Gui.Component
 							filename = newFilename;
 					}
 					
+					if (AsfRemuxer.FileIsAsf(filename) &&
+					    MpegRemuxer.AskForConversion(this.Toplevel as Gtk.Window)) {
+						var remux = new AsfRemuxer(filename);
+						var newFilename = remux.Remux(this.Toplevel as Gtk.Window);
+						if (newFilename != null)
+							filename = newFilename;
+					}
+					
 					try {
 						md = new MessageDialog((Gtk.Window)this.Toplevel,
 						                       DialogFlags.Modal,
diff --git a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
index 3498a7d..d8307ba 100644
--- a/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
+++ b/LongoMatch.Multimedia/LongoMatch.Multimedia.mdp
@@ -58,6 +58,7 @@
     <File subtype="Directory" buildaction="Compile" name="Remuxer" />
     <File subtype="Code" buildaction="Compile" name="Remuxer/GstRemuxer.cs" />
     <File subtype="Code" buildaction="Compile" name="Remuxer/ObjectManager.cs" />
+    <File subtype="Code" buildaction="Compile" name="Utils/AsfRemuxer.cs" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="libcesarplayer" />
diff --git a/LongoMatch.Multimedia/Makefile.am b/LongoMatch.Multimedia/Makefile.am
index a3d3ee2..9280c6b 100644
--- a/LongoMatch.Multimedia/Makefile.am
+++ b/LongoMatch.Multimedia/Makefile.am
@@ -19,6 +19,7 @@ SOURCES = \
 	Player/ObjectManager.cs \
 	Remuxer/GstRemuxer.cs \
 	Remuxer/ObjectManager.cs \
+	Utils/AsfRemuxer.cs \
 	Utils/FramesCapturer.cs \
 	Utils/GStreamer.cs \
 	Utils/IMetadataReader.cs \
diff --git a/LongoMatch.Multimedia/Utils/AsfRemuxer.cs b/LongoMatch.Multimedia/Utils/AsfRemuxer.cs
new file mode 100644
index 0000000..99e0ce7
--- /dev/null
+++ b/LongoMatch.Multimedia/Utils/AsfRemuxer.cs
@@ -0,0 +1,123 @@
+// 
+//  Copyright (C) 2011 Andoni Morales Alastruey
+// 
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+// 
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//  
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+// 
+using System;
+using System.Collections.Generic;
+using System.IO;
+using Mono.Unix;
+using GLib;
+using Gtk;
+
+using LongoMatch.Interfaces.Multimedia;
+
+namespace LongoMatch.Video.Utils
+{
+	public class AsfRemuxer
+	{
+		static string[] EXTENSIONS =  {"asf", "wmv"};
+		string filepath;
+		string newFilepath;
+		Dialog dialog;
+		ProgressBar pb;
+		IRemuxer remuxer;
+		IMultimediaToolkit multimedia;
+		uint timeout;
+		bool cancelled;
+		
+		public AsfRemuxer (string filepath)
+		{
+			this.filepath = filepath;
+			this.multimedia = new MultimediaFactory();
+			newFilepath = Path.ChangeExtension(filepath, "webm");
+		}
+		
+		public string Remux(Window parent) {
+			Button cancellButton;
+			
+			/* Create the dialog */
+			dialog = new Dialog(Catalog.GetString("Remuxing file..."), parent, DialogFlags.Modal);
+			dialog.AllowGrow = false;
+			dialog.AllowShrink = false;
+			dialog.Deletable = false;
+			
+			/* Add a progress bar */
+			pb = new ProgressBar();
+			pb.Show();
+			dialog.VBox.Add(pb);
+			
+			/* Add a button to cancell the task */
+			cancellButton = new Button("gtk-cancel");
+			cancellButton.Clicked += (sender, e) => Cancel (); 
+			cancellButton.Show();
+			dialog.VBox.Add(cancellButton);
+			
+			/* 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();			
+			return true;
+		}
+		
+		private void Stop() {
+			GLib.Source.Remove (timeout);
+			dialog.Destroy();
+		}
+		
+		void Cancel() {
+			cancelled = true;
+			Stop();
+		}
+		
+		public static bool FileIsAsf(string filepath) {
+			string extension = Path.GetExtension(filepath).Replace(".", "").ToLower();
+			var extensions = new List<string> (AsfRemuxer.EXTENSIONS);
+			return extensions.Contains(extension);
+		}
+		
+		public static bool AskForConversion(Window parent) {
+			bool ret;
+			MessageDialog md = new MessageDialog(parent, DialogFlags.Modal, MessageType.Question,
+			                                     ButtonsType.YesNo,
+			                                     Catalog.GetString("The file you are trying to load is not properly " +
+			                                     	"supported. Would you like to convert it into a more suitable " +
+			                                     	"format?"));
+			md.TransientFor = parent;
+			ret = md.Run() == (int)ResponseType.Yes;
+			md.Destroy();
+			
+			return ret;
+		}
+	}
+}
\ No newline at end of file
diff --git a/libcesarplayer/gst-remuxer.c b/libcesarplayer/gst-remuxer.c
index b4cdcc6..166996b 100644
--- a/libcesarplayer/gst-remuxer.c
+++ b/libcesarplayer/gst-remuxer.c
@@ -348,6 +348,9 @@ gst_remuxer_have_type_cb (GstElement *typefind, guint prob,
   if (g_strrstr (mime, "video/mpegts")) {
     GST_INFO_OBJECT (remuxer, "Using tsdemux as demuxer");
     demuxer = gst_element_factory_make ("tsdemux", NULL);
+  } else if (g_strrstr (mime, "video/x-ms-asf")) {
+    GST_INFO_OBJECT (remuxer, "Using asfdemux as demuxer");
+    demuxer = gst_element_factory_make ("asfdemux", NULL);
   } else if (g_strrstr (mime, "video/mpeg")) {
     gboolean sysstream;
 



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