Author: khaled
Date: 2006-08-29 03:28:18 -0400 (Tue, 29 Aug 2006)
New Revision: 64506

Added:
   branches/abock/gstreamer-sharp/sample/MetaData.cs
Modified:
   branches/abock/gstreamer-sharp/ChangeLog
   branches/abock/gstreamer-sharp/sample/Makefile.am
Log:
Added a new sample - sample/MetaData.cs

Modified: branches/abock/gstreamer-sharp/ChangeLog
===================================================================
--- branches/abock/gstreamer-sharp/ChangeLog    2006-08-29 02:48:25 UTC (rev 
64505)
+++ branches/abock/gstreamer-sharp/ChangeLog    2006-08-29 07:28:18 UTC (rev 
64506)
@@ -1,3 +1,7 @@
+2006-08-29  Khaled Mohammed <[EMAIL PROTECTED]>
+       * sample/MetaData.cs: a sample file which extracts tag information
+       from media files and displays them to console.
+
 2006-08-25  Khaled Mohammed <[EMAIL PROTECTED]>
        * sample/QueueExample.cs: a sample file showcasing 
        use of the queue element

Modified: branches/abock/gstreamer-sharp/sample/Makefile.am
===================================================================
--- branches/abock/gstreamer-sharp/sample/Makefile.am   2006-08-29 02:48:25 UTC 
(rev 64505)
+++ branches/abock/gstreamer-sharp/sample/Makefile.am   2006-08-29 07:28:18 UTC 
(rev 64506)
@@ -22,6 +22,9 @@
 queueexample.exe: $(srcdir)/QueueExample.cs $(assemblies)
        $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/QueueExample.cs
 
+metadata.exe: $(srcdir)/MetaData.cs $(assemblies)
+       $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/MetaData.cs
+
 link:
        ln -sf $(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll 
gstreamer-sharp.dll
        ln -sf $(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll.config 
gstreamer-sharp.dll.config

Added: branches/abock/gstreamer-sharp/sample/MetaData.cs
===================================================================
--- branches/abock/gstreamer-sharp/sample/MetaData.cs   2006-08-29 02:48:25 UTC 
(rev 64505)
+++ branches/abock/gstreamer-sharp/sample/MetaData.cs   2006-08-29 07:28:18 UTC 
(rev 64506)
@@ -0,0 +1,153 @@
+//
+// Authors
+//   Khaled Mohammed ([EMAIL PROTECTED])
+//
+// (C) 2006
+//
+
+using Gst;
+using System;
+
+public class MetaData 
+{
+
+       static Element pipeline = null;
+       static Element source = null;
+
+       static void PrintTag( TagList list, string tag) {
+               uint count = list.GetTagSize(tag);
+
+               for(uint i =0; i < count; i++) 
+               {
+                       string str;
+                       if(Tag.GetGType(tag) == GLib.GType.String) {
+                               if(!list.GetStringIndex(tag, i, out str))
+                                       
Console.Error.WriteLine("g_assert_not_reached()???");
+                       } else {
+                               str = (String) list.GetValueIndex(tag, i).Val; 
+                       }
+
+                       if(i == 0) 
+                               Console.WriteLine("{0}:\t {1}", 
Tag.GetNick(tag), str);
+                       else
+                               Console.WriteLine("\t{0}", str);
+               }
+       }
+
+       static bool MessageLoop(Element element, TagList tags) 
+       {
+               Bus bus = element.Bus;
+               bool done = false;
+
+               while(!done) {
+                       Message message = bus.Pop();
+                       if(message == null)
+                               break;
+
+                       switch(message.Type) {
+                               case MessageType.Error:
+                                       message.Dispose();
+                                       return true;
+                               case MessageType.Eos:
+                                       message.Dispose();
+                                       return true;
+                               case MessageType.Tag: {
+                                       TagList new_tags = new TagList();
+                                       message.ParseTag(new_tags);
+                                       if(tags != null) {
+                                               tags = tags.Merge(new_tags, 
TagMergeMode.KeepAll);
+                                       }
+                                       else {
+                                               tags = new_tags;
+                                       }
+                                       new_tags.Dispose();
+                                       break;
+                               }
+                               default:
+                                       break;
+                       }       
+                       message.Dispose();
+               }
+               bus.Dispose();
+               return true;
+       }
+
+       static void MakePipeline() 
+       {
+               Element decodebin;
+
+               if(pipeline != null) {
+                       pipeline.Dispose();
+               }
+               
+               pipeline = new Pipeline(String.Empty);
+               source = ElementFactory.Make("filesrc", "source");
+               decodebin = ElementFactory.Make("decodebin", "decodebin");
+
+               Bin bin = (Bin) pipeline;
+               bin.AddMany(source, decodebin);
+               source.Link(decodebin);
+               decodebin.Dispose();
+       }
+
+       public static void Main(string [] args) 
+       {
+               Application.Init();
+
+               if(args.Length < 1) 
+               {
+                       Console.Error.WriteLine("Please give filenames to read 
metadata from\n\n");
+                       return;
+               }
+
+               MakePipeline();         
+
+               int i=-1;
+               while(++i < args.Length)
+               {
+                       State state, pending;
+                       TagList tags = null;
+
+                       string filename = args[i];
+                       source.SetProperty("location", filename);
+
+                       StateChangeReturn sret = 
pipeline.SetState(State.Paused);
+
+                       if(sret == StateChangeReturn.Async) {
+                               if(StateChangeReturn.Success != 
pipeline.GetState(out state, out pending, Clock.Second * 5)) {
+                                       Console.Error.WriteLine("State change 
failed for {0}. Aborting\n", filename);
+                                       break;
+                               }
+                       } else if(sret != StateChangeReturn.Success) {
+                               Console.Error.WriteLine("{0} - Could not read 
file\n", filename);
+                               continue;
+                       }
+
+                       if(!MessageLoop(pipeline, tags)) {
+                               Console.Error.WriteLine("Failed in message 
reading for {0}", args[i]);
+                       }
+
+                       if(tags != null) {
+                               Console.WriteLine("Metadata for {0}:", args[i]);
+                               tags.Foreach(PrintTag);
+                               tags.Dispose();
+                               tags = null;
+                       } else Console.Error.WriteLine("No metadata found for 
{0}", args[0]);
+
+                       sret = pipeline.SetState(State.Null);
+
+                       if(StateChangeReturn.Async == sret) {
+                               if(StateChangeReturn.Failure == 
pipeline.GetState(out state, out pending, Clock.TimeNone)) {
+                                       Console.Error.WriteLine("State change 
failed. Aborting");
+                               }
+                       }
+               }
+
+               if(pipeline != null) 
+               {
+                       pipeline.Dispose();
+               }
+
+       }
+}
+

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to