banshee r3671 - in trunk/banshee: . src/Backends/Banshee.GStreamer/Banshee.GStreamer src/Extensions/Banshee.AudioCd/Banshee.AudioCd src/Libraries/Hyena/Hyena.SExpEngine



Author: abock
Date: Fri Apr  4 04:34:26 2008
New Revision: 3671
URL: http://svn.gnome.org/viewvc/banshee?rev=3671&view=rev

Log:
2008-04-03  Aaron Bockover  <abock gnome org>

    * src/Backends/Banshee.GStreamer/Banshee.GStreamer/AudioCdRipper.cs:
    Get the cd importing profile and generate the pipeline for the encoder

    * src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs: Ported
    the GStreamer media profile process stuff, including the SExpEngine
    extensions/GStreamer binding, fully enabling GStreamer media profiles

    * src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs:
    Cleaned up

    * src/Libraries/Hyena/Hyena.SExpEngine/EvaluatorBase.cs: Minor API fix



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/AudioCdRipper.cs
   trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs
   trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.SExpEngine/EvaluatorBase.cs

Modified: trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/AudioCdRipper.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/AudioCdRipper.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/AudioCdRipper.cs	Fri Apr  4 04:34:26 2008
@@ -28,21 +28,41 @@
 
 using System;
 using System.Threading;
+using Mono.Unix;
 
 using Banshee.Base;
 using Banshee.Collection;
+using Banshee.ServiceStack;
 using Banshee.MediaEngine;
+using Banshee.MediaProfiles;
 
 namespace Banshee.GStreamer
 {
     public class AudioCdRipper : IAudioCdRipper
     {
+        private string encoder_pipeline;
+    
         public event AudioCdRipperProgressHandler Progress;
         public event AudioCdRipperTrackFinishedHandler TrackFinished;
         public event AudioCdRipperErrorHandler Error;
         
         public void Begin ()
         {
+            try {
+                Profile profile = ServiceManager.MediaProfileManager.GetConfiguredActiveProfile ("cd-importing");
+                if (profile != null) {
+                    encoder_pipeline = profile.Pipeline.GetProcessById ("gstreamer");
+                }
+                
+                if (String.IsNullOrEmpty (encoder_pipeline)) {
+                    throw new ApplicationException ();
+                }
+                
+                Hyena.Log.InformationFormat ("Ripping using encoder profile `{0}' with pipeline: {1}", 
+                    profile.Name, encoder_pipeline);
+            } catch (Exception e) {
+                throw new ApplicationException (Catalog.GetString ("Could not find an encoder for ripping."), e);
+            }
         }
         
         public void Finish ()

Modified: trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.GStreamer/Banshee.GStreamer/Service.cs	Fri Apr  4 04:34:26 2008
@@ -4,7 +4,7 @@
 // Author:
 //   Aaron Bockover <abockover novell com>
 //
-// Copyright (C) 2007 Novell, Inc.
+// Copyright (C) 2006-2008 Novell, Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -27,9 +27,13 @@
 //
 
 using System;
+using System.Text;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 
+using Hyena.SExpEngine;
 using Banshee.ServiceStack;
+using Banshee.MediaProfiles;
 
 namespace Banshee.GStreamer
 {
@@ -39,16 +43,157 @@
         {
         }
         
+        [DllImport ("libbanshee")]
+        private static extern void gstreamer_initialize ();
+        
         void IExtensionService.Initialize ()
         {
             gstreamer_initialize ();
+            
+            MediaProfileManager profile_manager = ServiceManager.MediaProfileManager;
+            if (profile_manager != null) {
+                Pipeline.AddSExprFunction ("gst-element-is-available", SExprTestElement);
+                Pipeline.AddSExprFunction ("gst-construct-pipeline", SExprConstructPipeline);
+                Pipeline.AddSExprFunction ("gst-construct-caps", SExprConstructCaps);
+                Pipeline.AddSExprFunction ("gst-construct-element", SExprConstructElement);
+                
+                profile_manager.TestProfile += OnTestMediaProfile;
+                profile_manager.TestAll ();
+            }
+        }
+        
+        private static void OnTestMediaProfile (object o, TestProfileArgs args)
+        {
+            bool no_test = Banshee.Base.ApplicationContext.EnvironmentIsSet ("BANSHEE_PROFILES_NO_TEST");
+            bool available = false;
+            
+            foreach (Pipeline.Process process in args.Profile.Pipeline.GetPendingProcessesById ("gstreamer")) {
+                string pipeline = args.Profile.Pipeline.CompileProcess (process);
+                if (no_test || TestPipeline (pipeline)) {
+                    args.Profile.Pipeline.AddProcess (process);
+                    available = true;
+                    break;
+                } else if (!no_test) {
+                    Hyena.Log.DebugFormat ("GStreamer pipeline does not run: {0}", pipeline);
+                }
+            }
+            
+            args.ProfileAvailable = available;
+        }
+        
+        [DllImport ("libbanshee")]
+        private static extern bool gstreamer_test_pipeline (IntPtr pipeline);
+        
+        internal static bool TestPipeline (string pipeline)
+        {
+            if (String.IsNullOrEmpty (pipeline)) {
+                return false;
+            }
+        
+            IntPtr pipeline_ptr = GLib.Marshaller.StringToPtrGStrdup (pipeline);
+            
+            if (pipeline_ptr == IntPtr.Zero) {
+                return false;
+            }
+            
+            try {
+                return gstreamer_test_pipeline (pipeline_ptr);
+            } finally {
+                GLib.Marshaller.Free (pipeline_ptr);
+            }
+        }
+        
+        private TreeNode SExprTestElement (EvaluatorBase evaluator, TreeNode [] args)
+        {
+            if (args.Length != 1) {
+                throw new ArgumentException ("gst-test-element accepts one argument");
+            }
+            
+            TreeNode arg = evaluator.Evaluate (args[0]);
+            if (!(arg is StringLiteral)) {
+                throw new ArgumentException ("gst-test-element requires a string argument");
+            }
+            
+            StringLiteral element_node = (StringLiteral)arg;
+            return new BooleanLiteral (TestPipeline (element_node.Value));
+        }
+        
+        private TreeNode SExprConstructPipeline (EvaluatorBase evaluator, TreeNode [] args)
+        {
+            StringBuilder builder = new StringBuilder ();
+            List<string> elements = new List<string> ();
+            
+            for (int i = 0; i < args.Length; i++) {
+                TreeNode node = evaluator.Evaluate (args[i]);
+                if (!(node is LiteralNodeBase)) {
+                    throw new ArgumentException ("node must evaluate to a literal");
+                }
+                
+                string value = node.ToString ().Trim ();
+                
+                if (value.Length == 0) {
+                    continue;
+                }
+                
+                elements.Add (value);
+            }
+            
+            for (int i = 0; i < elements.Count; i++) {
+                builder.Append (elements[i]);
+                if (i < elements.Count - 1) {
+                    builder.Append (" ! ");
+                }
+            }
+            
+            return new StringLiteral (builder.ToString ());
+        }
+        
+        private TreeNode SExprConstructElement (EvaluatorBase evaluator, TreeNode [] args)
+        {
+            return SExprConstructPipelinePart (evaluator, args, true);
+        }
+        
+        private TreeNode SExprConstructCaps (EvaluatorBase evaluator, TreeNode [] args)
+        {
+            return SExprConstructPipelinePart (evaluator, args, false);
+        }
+        
+        private TreeNode SExprConstructPipelinePart (EvaluatorBase evaluator, TreeNode [] args, bool element)
+        {
+            StringBuilder builder = new StringBuilder ();
+            
+            TreeNode list = new TreeNode ();
+            foreach (TreeNode arg in args) {
+                list.AddChild (evaluator.Evaluate (arg));
+            }
+            
+            list = list.Flatten ();
+            
+            for (int i = 0; i < list.ChildCount; i++) {
+                TreeNode node = list.Children[i];
+                
+                string value = node.ToString ().Trim ();
+                
+                builder.Append (value);
+                
+                if (i == 0) {
+                    if (list.ChildCount > 1) {
+                        builder.Append (element ? ' ' : ',');
+                    }
+                    
+                    continue;
+                } else if (i % 2 == 1) {
+                    builder.Append ('=');
+                } else if (i < list.ChildCount - 1) {
+                    builder.Append (element ? ' ' : ',');
+                }
+            }
+            
+            return new StringLiteral (builder.ToString ());
         }
         
         string IService.ServiceName {
             get { return "GStreamerCoreService"; }
         }
-        
-        [DllImport("libbanshee")]
-        private static extern void gstreamer_initialize ();
     }
 }

Modified: trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdRipper.cs	Fri Apr  4 04:34:26 2008
@@ -69,6 +69,7 @@
         
         // State to process the rip operation
         private Queue<AudioCdTrackInfo> queue = new Queue<AudioCdTrackInfo> ();
+        
         private TimeSpan ripped_duration;
         private TimeSpan total_duration;
         private int track_index;
@@ -107,12 +108,7 @@
             if (queue.Count == 0) {
                 return;
             }
-            
-//            ServiceManager.
-//            
-//            profile = Globals.AudioProfileManager.GetConfiguredActiveProfile ("cd-importing", 
-//                new string [] { "audio/ogg", "audio/mp3", "audio/wav" });
-//            
+
             source.LockAllTracks ();
                                                 
             user_job = new UserJob (Catalog.GetString ("Importing Audio CD"), 

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.SExpEngine/EvaluatorBase.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.SExpEngine/EvaluatorBase.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.SExpEngine/EvaluatorBase.cs	Fri Apr  4 04:34:26 2008
@@ -195,7 +195,7 @@
             return null;
         }
        
-        internal TreeNode Evaluate(TreeNode node)
+        public TreeNode Evaluate(TreeNode node)
         {
             if(!node.HasChildren || node is FunctionNode) {
                 return EvaluateNode(node);



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