Beispiel #1
0
 public void Release()
 {
     Logger.Debug("release()");
     //	        if(released.compareAndSet(false, true)) {
     LibVlc.libvlc_media_release(media);
     //	        }
 }
Beispiel #2
0
        /**
         * Create a new native media instance.
         *
         * @param media media resource locator
         * @param mediaOptions zero or more media options
         * @return native media instance
         */
        private IntPtr newMediaDescriptor(string media, params string[] mediaOptions)
        {
            Logger.Debug("newMediaDescriptor(media={},mediaOptions={})", media, mediaOptions);
            IntPtr mediaPointer  = NativeString.StringPointer(media);
            IntPtr mediaInstance = IntPtr.Zero;

            if (mediaPointer != IntPtr.Zero)
            {
                try {
                    mediaInstance = LibVlc.libvlc_media_new_path(instance, mediaPointer);
                    Logger.Debug("mediaDescriptor={}", mediaInstance);
                    if (mediaListInstance != IntPtr.Zero)
                    {
                        // Set the standard media options (if any)...
                        AddMediaOptions(mediaInstance, standardMediaOptions); // FIXME handle return false?
                        // Set the particular media options (if any)...
                        AddMediaOptions(mediaInstance, mediaOptions);         // FIXME handle return false?
                    }
                }
                finally {
                    NativeString.Release(mediaPointer);
                }
            }
            return(mediaInstance);
        }
Beispiel #3
0
 /**
  * Add native media options.
  *
  * @param mediaInstance native media instance
  * @param options options to add
  * @return <code>true</code> if the options were added; <code>false</code> if they were not
  */
 private bool AddMediaOptions(IntPtr mediaInstance, params string[] options)
 {
     Logger.Debug("AddMediaOptions(options={})", options);
     if (options != null)
     {
         IntPtr optionPtr = IntPtr.Zero;
         foreach (string option in options)
         {
             Logger.Debug("option={}", option);
             optionPtr = NativeString.StringPointer(option);
             if (optionPtr != IntPtr.Zero)
             {
                 try {
                     LibVlc.libvlc_media_add_option(mediaInstance, optionPtr);
                 }
                 finally {
                     NativeString.Release(optionPtr);
                 }
             }
             else
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #4
0
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                }

                // Release unmanaged resources. If disposing is false,
                // only the following code is executed.
                if (playing)
                {
                    Stop();
                }
                LibVlc.libvlc_release(instance);
                instance = IntPtr.Zero;

                // Note that this is not thread safe.
                // Another thread could start disposing the object
                // after the managed resources are disposed,
                // but before the disposed flag is set to true.
                // If thread safety is necessary, it must be
                // implemented by the client.
            }
            disposed = true;
        }
Beispiel #5
0
        /**
         * Create a new media list item for a give native media instance.
         *
         * @param mediaInstance native media instance
         * @return media list item
         */
        private MediaListItem NewMediaListItem(IntPtr mediaInstance)
        {
            string name = NativeString.GetNativeString(LibVlc.libvlc_media_get_meta(mediaInstance, (int)libvlc_meta_e.libvlc_meta_Title));
            string mrl  = NativeString.GetNativeString(LibVlc.libvlc_media_get_mrl(mediaInstance));
            List <MediaListItem> subItems;
            IntPtr subItemList = LibVlc.libvlc_media_subitems(mediaInstance);

            if (subItemList != IntPtr.Zero)
            {
                try {
                    LibVlc.libvlc_media_list_lock(subItemList);
                    subItems = new List <MediaListItem>();
                    for (int i = 0; i < LibVlc.libvlc_media_list_count(subItemList); i++)
                    {
                        IntPtr subItemInstance = LibVlc.libvlc_media_list_item_at_index(subItemList, i);
                        subItems.Add(NewMediaListItem(subItemInstance));
                        LibVlc.libvlc_media_release(subItemInstance);
                    }
                }
                finally {
                    LibVlc.libvlc_media_list_unlock(subItemList);
                }
                LibVlc.libvlc_media_list_release(subItemList);
            }
            else
            {
                subItems = new List <MediaListItem>(0);
            }
            return(new MediaListItem(name, mrl, subItems));
        }
Beispiel #6
0
 /**
  * Release the native resources associated with this factory.
  */
 public void Release()
 {
     Logger.Debug("Release()");
     if (instance != IntPtr.Zero)
     {
         LibVlc.libvlc_release(instance);
     }
 }
Beispiel #7
0
        /**
         * Get the available video filters.
         *
         * @return collection of video filter descriptions
         *
         * @since libvlc 2.0.0
         */
        public List <ModuleDescription> GetVideoFilters()
        {
            Logger.Debug("GetVideoFilters()");
            IntPtr moduleDescriptions       = LibVlc.libvlc_video_filter_list_get(instance);
            List <ModuleDescription> result = GetModuleDescriptions(moduleDescriptions);

            LibVlc.libvlc_module_description_list_release(moduleDescriptions);
            return(result);
        }
 public void Play()
 {
     Logger.Debug("Play()");
     // If there is an associated media player then make sure the video surface
     // is attached
     if (mediaPlayer is EmbeddedMediaPlayer)
     {
         ((EmbeddedMediaPlayer)mediaPlayer).AttachVideoSurface();
     }
     LibVlc.libvlc_media_list_player_play(mediaListPlayerInstance);
 }
Beispiel #9
0
 /**
  * Get the number of items currently in the list.
  *
  * @return item count
  */
 public int Size()
 {
     Logger.Debug("Size()");
     try {
         LockList();
         int size = LibVlc.libvlc_media_list_count(mediaListInstance);
         return(size);
     }
     finally {
         UnlockList();
     }
 }
Beispiel #10
0
        /**
         * Set a local meta data value for a media instance.
         * <p>
         * Setting meta does not affect the underlying media file until {@link #save()} is called.
         *
         * @param metaType type of meta data
         * @param media media instance
         * @param value meta data value
         */
        private void SetMeta(libvlc_meta_e metaType, string metaValue)
        {
            Logger.Trace("SetMeta(metaType={},media={},value={})", metaType, media, metaValue);
            IntPtr metaValuePtr = NativeString.StringPointer(metaValue);

            try {
                LibVlc.libvlc_media_set_meta(media, (int)metaType, metaValuePtr);
            }
            finally {
                NativeString.Release(metaValuePtr);
            }
        }
        /**
         *
         */
        private void CreateInstance()
        {
            Logger.Debug("CreateInstance()");

            mediaListPlayerInstance = LibVlc.libvlc_media_list_player_new(instance);

            mediaListPlayerEventManager = LibVlc.libvlc_media_list_player_event_manager(mediaListPlayerInstance);
            Logger.Debug("mediaListPlayerEventManager={}", mediaListPlayerEventManager);

            RegisterEventListener();

            //        AddMediaListPlayerEventListener(new NextItemHandler());
        }
Beispiel #12
0
        /**
         * De-register the call-back used to receive native media player events.
         */
        private void DeregisterEventListener()
        {
            Logger.Debug("DeregisterEventListener()");
            IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(callback);

            foreach (int value in Enum.GetValues(typeof(libvlc_event_e)))
            {
                if (value >= (int)libvlc_event_e.libvlc_MediaListItemAdded && value <= (int)libvlc_event_e.libvlc_MediaListWillDeleteItem)
                {
                    Logger.Debug("event={}", value);
                    LibVlc.libvlc_event_detach(mediaListEventManager, value, callbackPtr, IntPtr.Zero);
                }
            }
        }
Beispiel #13
0
 public void Stop()
 {
     if (playing)
     {
         LibVlc.libvlc_media_player_stop(player);
         LibVlc.libvlc_media_player_release(player);
         playing = false;
         player  = IntPtr.Zero;
     }
     else
     {
         throw new InvalidOperationException("VLC is not currently playing media");
     }
 }
Beispiel #14
0
        /**
         * Clean up and free the media list instance.
         */
        private void DestroyInstance()
        {
            Logger.Debug("DestroyInstance()");

            DeregisterEventListener();

            if (mediaListInstance != IntPtr.Zero)
            {
                LibVlc.libvlc_media_list_release(mediaListInstance);
            }

            Logger.Debug("Shut down listeners...");
            listenersService.Shutdown();
            Logger.Debug("Listeners shut down.");
        }
Beispiel #15
0
 /**
  * Clear the list.
  */
 public void Clear()
 {
     Logger.Debug("Clear()");
     try {
         LockList();
         // Traverse the list from the end back to the start...
         for (int i = LibVlc.libvlc_media_list_count(mediaListInstance) - 1; i >= 0; i--)
         {
             LibVlc.libvlc_media_list_remove_index(mediaListInstance, i);
         }
     }
     finally {
         UnlockList();
     }
 }
Beispiel #16
0
        /**
         * Create and initialise a new media list instance.
         */
        private void CreateInstance(IntPtr mediaListInstance)
        {
            Logger.Debug("CreateInstance()");
            if (mediaListInstance == IntPtr.Zero)
            {
                mediaListInstance = LibVlc.libvlc_media_list_new(instance);
            }

            this.mediaListInstance = mediaListInstance;
            Logger.Debug("mediaListInstance={}", mediaListInstance);

            mediaListEventManager = LibVlc.libvlc_media_list_event_manager(mediaListInstance);
            Logger.Debug("mediaListEventManager={}", mediaListEventManager);

            RegisterEventListener();
        }
Beispiel #17
0
 /**
  * Insert a media item, with options, to the play-list.
  *
  * @param index position at which to insert the media item (counting from zero)
  * @param mrl media resource locator
  * @param mediaOptions zero or more media item options
  */
 public void InsertMedia(int index, string mrl, params string[] mediaOptions)
 {
     Logger.Debug("InsertMedia(index={},mrl={},mediaOptions={})", index, mrl, mediaOptions);
     try {
         LockList();
         // Create a new native media descriptor
         IntPtr mediaDescriptor = newMediaDescriptor(mrl, mediaOptions);
         // Insert the media descriptor into the media list
         LibVlc.libvlc_media_list_insert_media(mediaListInstance, mediaDescriptor, index);
         // Release the native reference
         ReleaseMediaDescriptor(mediaDescriptor);
     }
     finally {
         UnlockList();
     }
 }
Beispiel #18
0
        /**
         * Get the available audio outputs.
         * <p>
         * Each audio output has zero or more audio devices, each device having it's own unique
         * identifier that can be used on a media player to set the select the required output device.
         *
         * @return collection of audio outputs
         */
        public List <AudioOutput> GetAudioOutputs()
        {
            Logger.Debug("GetAudioOutputs()");
            List <AudioOutput> result          = new List <AudioOutput>();
            IntPtr             audioOutputsPtr = LibVlc.libvlc_audio_output_list_get(instance);
            IntPtr             audioOutputPtr  = audioOutputsPtr;

            while (audioOutputPtr != IntPtr.Zero)
            {
                libvlc_audio_output_t audioOutput = (libvlc_audio_output_t)Marshal.PtrToStructure(audioOutputPtr, typeof(libvlc_audio_output_t));
                string name = NativeString.String(audioOutput.psz_name);
                result.Add(new AudioOutput(name, NativeString.String(audioOutput.psz_description), GetAudioOutputDevices(name)));
                audioOutputPtr = audioOutput.p_next;
            }
            LibVlc.libvlc_audio_output_list_release(audioOutputsPtr);
            return(result);
        }
Beispiel #19
0
        /**
         * Get the devices associated with an audio output.
         *
         * @param outputName output
         * @return collection of audio output devices
         */
        private List <AudioDevice> GetAudioOutputDevices(string outputName)
        {
            Logger.Debug("GetAudioOutputDevices(outputName={})", outputName);
            IntPtr outputNamePtr = NativeString.StringPointer(outputName);
            int    deviceCount   = LibVlc.libvlc_audio_output_device_count(instance, outputNamePtr);

            Logger.Debug("deviceCount={}", deviceCount);
            List <AudioDevice> result = new List <AudioDevice>(deviceCount);

            for (int i = 0; i < deviceCount; i++)
            {
                string deviceId = NativeString.GetNativeString(LibVlc.libvlc_audio_output_device_id(instance, outputNamePtr, i));
                string longName = NativeString.GetNativeString(LibVlc.libvlc_audio_output_device_longname(instance, outputNamePtr, i));
                result.Add(new AudioDevice(deviceId, longName));
            }
            return(result);
        }
        /**
         *
         */
        private void RegisterEventListener()
        {
            Logger.Debug("RegisterEventListener()");
            callback = new VlcVideoPlayerCallbackDelegate(HandleEvent);
            IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(callback);

            foreach (int value in Enum.GetValues(typeof(libvlc_event_e)))
            {
                // The native event manager reports that it does not support
                // libvlc_MediaListPlayerPlayed or libvlc_MediaListPlayerStopped
                if (value >= (int)libvlc_event_e.libvlc_MediaListPlayerNextItemSet && value <= (int)libvlc_event_e.libvlc_MediaListPlayerNextItemSet)
                {
                    Logger.Debug("event={}", (libvlc_event_e)value);
                    int result = LibVlc.libvlc_event_attach(mediaListPlayerEventManager, value, callbackPtr, IntPtr.Zero);
                    Logger.Debug("result={}", result);
                }
            }
        }
Beispiel #21
0
        /**
         * Get the list of items.
         *
         * @return list of items
         */
        // FIXME readonly collection?
        public List <MediaListItem> Items()
        {
            Logger.Debug("Items()");
            List <MediaListItem> result = new List <MediaListItem>();

            try {
                LockList();
                for (int i = 0; i < LibVlc.libvlc_media_list_count(mediaListInstance); i++)
                {
                    IntPtr mediaInstance = LibVlc.libvlc_media_list_item_at_index(mediaListInstance, i);
                    result.Add(NewMediaListItem(mediaInstance));
                }
            }
            finally {
                UnlockList();
            }
            return(result);
        }
Beispiel #22
0
        public void Play(string mediaPath, IntPtr hWnd)
        {
            if (!playing)
            {
                IntPtr media = LibVlc.libvlc_media_new_path(instance, mediaPath);
                player = LibVlc.libvlc_media_player_new_from_media(media);

                LibVlc.libvlc_media_release(media);
                LibVlc.libvlc_media_player_set_hwnd(player, hWnd);
                LibVlc.libvlc_media_player_play(player);

                playing = true;
            }
            else
            {
                throw new InvalidOperationException("VLC is currently playing media");
            }
        }
Beispiel #23
0
 /**
  * Remove a media item from the play-list.
  *
  * @param index item to remove (counting from zero)
  */
 public void RemoveMedia(int index)
 {
     Logger.Debug("RemoveMedia(index={})", index);
     try {
         LockList();
         IntPtr oldMediaInstance = LibVlc.libvlc_media_list_item_at_index(mediaListInstance, index);
         if (oldMediaInstance != IntPtr.Zero)
         {
             // Remove the media descriptor from the media list
             LibVlc.libvlc_media_list_remove_index(mediaListInstance, index);
             // Release the native media instance
             LibVlc.libvlc_media_release(oldMediaInstance);
         }
     }
     finally {
         UnlockList();
     }
 }
 /**
  *
  */
 private void DeregisterEventListener()
 {
     Logger.Debug("DeregisterEventListener()");
     if (callback != null)
     {
         IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(callback);
         foreach (int value in Enum.GetValues(typeof(libvlc_event_e)))
         {
             // The native event manager reports that it does not support
             // libvlc_MediaListPlayerPlayed or libvlc_MediaListPlayerStopped
             if (value >= (int)libvlc_event_e.libvlc_MediaListPlayerNextItemSet && value <= (int)libvlc_event_e.libvlc_MediaListPlayerNextItemSet)
             {
                 Logger.Debug("event={}", (libvlc_event_e)value);
                 LibVlc.libvlc_event_detach(mediaListPlayerEventManager, value, callbackPtr, IntPtr.Zero);
             }
         }
         callback = null;
     }
 }
Beispiel #25
0
        /**
         * Set the application name.
         *
         * @param userAgent application name
         * @param httpUserAgent application name for HTTP
         */
        public void SetUserAgent(string userAgent, string httpUserAgent)
        {
            Logger.Debug("SetUserAgent(userAgent={},httpUserAgent)", userAgent, httpUserAgent);
            IntPtr userAgentPtr     = IntPtr.Zero;
            IntPtr httpUserAgentPtr = IntPtr.Zero;

            try {
                userAgentPtr = NativeString.StringPointer(userAgent);
                if (httpUserAgent != null)
                {
                    httpUserAgentPtr = NativeString.StringPointer(httpUserAgent);
                }
                LibVlc.libvlc_set_user_agent(instance, userAgentPtr, httpUserAgentPtr);
            }
            finally {
                NativeString.Release(httpUserAgentPtr);
                NativeString.Release(userAgentPtr);
            }
        }
        /**
         *
         */
        private void DestroyInstance()
        {
            Logger.Debug("DestroyInstance()");

            Logger.Debug("Detach events...");
            DeregisterEventListener();
            Logger.Debug("Events detached.");

            eventListenerList.Clear();
            if (mediaListPlayerInstance != IntPtr.Zero)
            {
                Logger.Debug("Release media list player...");
                LibVlc.libvlc_media_list_player_release(mediaListPlayerInstance);
                Logger.Debug("Media list player released");
            }

            Logger.Debug("Shut down listeners...");
            listenersService.Shutdown();
            Logger.Debug("Listeners shut down.");
        }
        public void SetMode(MediaListPlayerMode mode)
        {
            Logger.Debug("SetMode(mode={})", mode);
            libvlc_playback_mode_e playbackMode;

            switch (mode)
            {
            case MediaListPlayerMode.DEFAULT:
                playbackMode = libvlc_playback_mode_e.libvlc_playback_mode_default;
                break;

            case MediaListPlayerMode.LOOP:
                playbackMode = libvlc_playback_mode_e.libvlc_playback_mode_loop;
                break;

            case MediaListPlayerMode.REPEAT:
                playbackMode = libvlc_playback_mode_e.libvlc_playback_mode_repeat;
                break;

            default:
                throw new ArgumentException("Invalid mode " + mode);
            }
            LibVlc.libvlc_media_list_player_set_playback_mode(mediaListPlayerInstance, (int)playbackMode);
        }
Beispiel #28
0
 public void Parse()
 {
     Logger.Debug("parse()");
     LibVlc.libvlc_media_parse(media);
 }
Beispiel #29
0
 /**
  * Create media meta.
  *
  * @param media media instance
  */
 public DefaultMediaMeta(IntPtr media)
 {
     this.media = media;
     // Keep a native reference
     LibVlc.libvlc_media_retain(media);
 }
Beispiel #30
0
        /*	    protected void finalize() throws Throwable {
         *      Logger.Debug("finalize()");
         *      Logger.Debug("Meta data has been garbage collected");
         *      // FIXME should this invoke release()?
         *  }*/

        /**
         * Get a local meta data value for a media instance.
         *
         * @param metaType type of meta data
         * @return meta data value
         */
        private string GetMeta(libvlc_meta_e metaType)
        {
            Logger.Trace("GetMeta(metaType={},media={})", metaType, media);
            return(NativeString.GetNativeString(LibVlc.libvlc_media_get_meta(media, (int)metaType)));
        }