[longomatch] Use the new discoverer



commit 282ce31ed217daef794ff18c425c1f00de83530e
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Mar 27 21:55:03 2013 +0100

    Use the new discoverer

 LongoMatch.Multimedia/Utils/PreviewMediaFile.cs |   92 ++++++++++++-----------
 1 files changed, 48 insertions(+), 44 deletions(-)
---
diff --git a/LongoMatch.Multimedia/Utils/PreviewMediaFile.cs b/LongoMatch.Multimedia/Utils/PreviewMediaFile.cs
index f1c6c23..dd542b6 100644
--- a/LongoMatch.Multimedia/Utils/PreviewMediaFile.cs
+++ b/LongoMatch.Multimedia/Utils/PreviewMediaFile.cs
@@ -17,6 +17,8 @@
 //
 
 using System;
+using System.Runtime.InteropServices;
+
 using LongoMatch.Interfaces.Multimedia;
 using LongoMatch.Multimedia.Interfaces;
 using LongoMatch.Store;
@@ -25,6 +27,7 @@ using LongoMatch.Video.Common;
 using LongoMatch.Video.Player;
 using Mono.Unix;
 using Gdk;
+using GLib;
 
 namespace LongoMatch.Video.Utils
 {
@@ -35,57 +38,58 @@ namespace LongoMatch.Video.Utils
                const int THUMBNAIL_MAX_HEIGHT=72;
                const int THUMBNAIL_MAX_WIDTH=96;
 
-               /* FIXME: hackish as hell! */
+               [DllImport("libcesarplayer.dll")]
+               static extern unsafe uint lgm_discover_uri(string uri, out long duration,
+                                                          out uint width, out uint height,
+                                                          out uint fps_n, out uint fps_d,
+                                                          out uint par_n, out uint par_d,
+                                                          out IntPtr container,
+                                                          out IntPtr video_codec,
+                                                          out IntPtr audio_codec,
+                                                          out IntPtr err);
+               
                public static MediaFile DiscoverFile(string filePath) {
-                       int duration=0;
-                       bool hasVideo;
-                       bool hasAudio;
-                       string AudioEncoderType = "";
-                       string VideoEncoderType = "";
-                       int fps=0;
-                       int height=0;
-                       int width=0;
-                       double par = 1;
+                       long duration = 0;
+                       uint width, height, fps_n, fps_d, par_n, par_d, ret, fps = 0;
+                       string container, audio_codec, video_codec;
+                       bool has_audio, has_video;
+                       float par = 0;
+                       IntPtr container_ptr, audio_codec_ptr, video_codec_ptr;
+                       IntPtr error = IntPtr.Zero;
                        LongoMatch.Common.Image preview=null;
                        MultimediaFactory factory;
-                       IMetadataReader reader;
                        IFramesCapturer thumbnailer;
 
-                       try {
-                               factory =  new MultimediaFactory();
-                               reader = factory.GetMetadataReader();
-                               reader.Open(filePath);
-                               hasVideo = (bool) reader.GetMetadata(MetadataType.HasVideo);
-                               hasAudio = (bool) reader.GetMetadata(MetadataType.HasAudio);
-                               if(hasAudio) {
-                                       AudioEncoderType = (string) 
reader.GetMetadata(MetadataType.AudioEncoderType);
-                               }
-                               if(hasVideo) {
-                                       VideoEncoderType = (string) 
reader.GetMetadata(MetadataType.VideoEncoderType);
-                                       fps = (int) reader.GetMetadata(MetadataType.Fps);
-                                       thumbnailer = factory.GetFramesCapturer();
-                                       thumbnailer.Open(filePath);
-                                       thumbnailer.SeekTime(1000,false);
-                                       preview = 
thumbnailer.GetCurrentFrame(THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
-                                       duration =(int)((thumbnailer as GstPlayer).StreamLength/1000);        
                  /* On Windows some formats report a 0 duration, try a last time with the reader */
-                                       if(duration == 0)
-                                               duration = (int)reader.GetMetadata(MetadataType.Duration);
-                                       thumbnailer.Dispose();
-                               }
-                               height = (int) reader.GetMetadata(MetadataType.DimensionX);
-                               width = (int) reader.GetMetadata(MetadataType.DimensionY);
-                               par = (double) reader.GetMetadata(MetadataType.Par);
-                               reader.Close();
-                               reader.Dispose();
-                               return new LongoMatch.Store.MediaFile(filePath,duration*1000,
-                                                    (ushort)fps,hasAudio,
-                                                    hasVideo,VideoEncoderType,
-                                                    AudioEncoderType,(uint)height,
-                                                    (uint)width, par, preview);
+                       ret = lgm_discover_uri(filePath, out duration, out width, out height, out fps_n,
+                                              out fps_d, out par_n, out par_d, out container_ptr,
+                                              out video_codec_ptr, out audio_codec_ptr, out error);
+                       if(error != IntPtr.Zero) throw new GLib.GException(error);
+                       if (ret != 0) {
+                               throw new Exception(Catalog.GetString("Could not parse file:") + filePath);
                        }
-                       catch(GLib.GException ex) {
-                               throw new Exception(Catalog.GetString("Invalid video file:")+"\n"+ex.Message);
+                       
+                       has_audio = audio_codec_ptr != IntPtr.Zero;
+                       has_video = video_codec_ptr != IntPtr.Zero;
+                       container = GLib.Marshaller.PtrToStringGFree (container_ptr);
+                       audio_codec = GLib.Marshaller.PtrToStringGFree (audio_codec_ptr);
+                       video_codec = GLib.Marshaller.PtrToStringGFree (video_codec_ptr);
+                       /* From nanoseconds to milliseconds */
+                       duration = duration / (1000 * 1000);
+                       
+                       if(has_video) {
+                               fps = fps_n / fps_d;
+                               par =  (float)par_n / par_d;
+                               factory = new MultimediaFactory ();
+                               thumbnailer = factory.GetFramesCapturer();
+                               thumbnailer.Open(filePath);
+                               thumbnailer.SeekTime(1000,false);
+                               preview = 
thumbnailer.GetCurrentFrame(THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
+                               thumbnailer.Dispose();
                        }
+                       
+                       return new LongoMatch.Store.MediaFile(filePath, duration, (ushort)fps, has_audio, 
has_video,
+                                                             container, video_codec, audio_codec, width, 
height,
+                                                             par, preview);
                }
        }
 }


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