mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-06 02:32:23 +00:00
Added a new sample - sample/MetaData.cs
git-svn-id: svn://anonsvn.mono-project.com/source/branches/abock/gstreamer-sharp@64506 e3ebcda4-bce8-0310-ba0a-eca2169e7518
This commit is contained in:
parent
610da9b1d9
commit
5097ae8adc
3 changed files with 160 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2006-08-29 Khaled Mohammed <khaled.mohammed@gmail.com>
|
||||||
|
* sample/MetaData.cs: a sample file which extracts tag information
|
||||||
|
from media files and displays them to console.
|
||||||
|
|
||||||
2006-08-25 Khaled Mohammed <khaled.mohammed@gmail.com>
|
2006-08-25 Khaled Mohammed <khaled.mohammed@gmail.com>
|
||||||
* sample/QueueExample.cs: a sample file showcasing
|
* sample/QueueExample.cs: a sample file showcasing
|
||||||
use of the queue element
|
use of the queue element
|
||||||
|
|
|
@ -22,6 +22,9 @@ typefind.exe: $(srcdir)/TypeFind.cs $(assemblies)
|
||||||
queueexample.exe: $(srcdir)/QueueExample.cs $(assemblies)
|
queueexample.exe: $(srcdir)/QueueExample.cs $(assemblies)
|
||||||
$(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/QueueExample.cs
|
$(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/QueueExample.cs
|
||||||
|
|
||||||
|
metadata.exe: $(srcdir)/MetaData.cs $(assemblies)
|
||||||
|
$(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/MetaData.cs
|
||||||
|
|
||||||
link:
|
link:
|
||||||
ln -sf $(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll gstreamer-sharp.dll
|
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
|
ln -sf $(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll.config gstreamer-sharp.dll.config
|
||||||
|
|
153
sample/MetaData.cs
Normal file
153
sample/MetaData.cs
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
//
|
||||||
|
// Authors
|
||||||
|
// Khaled Mohammed (khaled.mohammed@gmail.com)
|
||||||
|
//
|
||||||
|
// (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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue