[vlc-devel] [PATCH] NPAPI change: introduce MediaDescription object for exposing media meta information

Sergey Radionov rsatom at gmail.com
Fri Jan 13 04:51:30 CET 2012


2012/1/13 JM Lambert <jeanmichel.lambert7 at gmail.com>:
> ---
>  npapi/control/npolibvlc.cpp |  140 +++++++++++++++++++++++++++++++++++++++++++
>  npapi/control/npolibvlc.h   |   24 +++++++-
>  2 files changed, 163 insertions(+), 1 deletions(-)
>
> diff --git a/npapi/control/npolibvlc.cpp b/npapi/control/npolibvlc.cpp
> index a8a94f6..651a572 100644
> --- a/npapi/control/npolibvlc.cpp
> +++ b/npapi/control/npolibvlc.cpp
> @@ -99,6 +99,7 @@ const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
>     "subtitle",
>     "video",
>     "VersionInfo",
> +    "MediaDescription"
>  };
>  COUNTNAMES(LibvlcRootNPObject,propertyCount,propertyNames);
>
> @@ -110,6 +111,7 @@ enum LibvlcRootNPObjectPropertyIds
>     ID_root_subtitle,
>     ID_root_video,
>     ID_root_VersionInfo,
> +    ID_root_MediaDescription,
>  };
>
>  RuntimeNPObject::InvokeResult
> @@ -143,6 +145,12 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result)
>             case ID_root_VersionInfo:
>                 return invokeResultString(libvlc_get_version(),result);
>             default:
> +            case ID_root_MediaDescription:
> +            {
> +                InstantObj<LibvlcMediaDescriptionNPObject>( mediaDescriptionObj );
> +                OBJECT_TO_NPVARIANT(NPN_RetainObject(mediaDescriptionObj), result);
> +                return INVOKERESULT_NO_ERROR;
> +            }
why did you place it after "default:"?

>                 ;
>         }
>     }
> @@ -616,6 +624,138 @@ LibvlcInputNPObject::invoke(int index, const NPVariant *args,
>  }
>
>  /*
> +** implementation of libvlc MediaDescription object
> +*/
> +
> +const NPUTF8 * const LibvlcMediaDescriptionNPObject::propertyNames[] =
> +{
> +    "title",
> +    "artist",
> +    "genre",
> +    "copyright",
> +    "album",
> +    "trackNumber",
> +    "description",
> +    "rating",
> +    "date",
> +    "setting",
> +    "URL",
> +    "language",
> +    "nowPlaying",
> +    "publisher",
> +    "encodedBy",
> +    "artworkURL",
> +    "trackID",
> +};
> +COUNTNAMES(LibvlcMediaDescriptionNPObject,propertyCount,propertyNames);
> +
> +enum LibvlcMediaDescriptionNPObjectPropertyIds
> +{
> +    ID_meta_title,
> +    ID_meta_artist,
> +    ID_meta_genre,
> +    ID_meta_copyright,
> +    ID_meta_album,
> +    ID_meta_trackNumber,
> +    ID_meta_description,
> +    ID_meta_rating,
> +    ID_meta_date,
> +    ID_meta_setting,
> +    ID_meta_URL,
> +    ID_meta_language,
> +    ID_meta_nowPlaying,
> +    ID_meta_publisher,
> +    ID_meta_EncodedBy,
> +    ID_meta_ArtworkURL,
> +    ID_meta_trackID,
> +};
> +RuntimeNPObject::InvokeResult
> +LibvlcMediaDescriptionNPObject::getProperty(int index, NPVariant &result)
> +{
> +    /* is plugin still running */
> +    if( isPluginRunning() )
> +    {
> +        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
> +        libvlc_media_player_t *p_md = p_plugin->getMD();
> +        if( !p_md )
> +            RETURN_ON_ERROR;
> +        libvlc_media_t * p_media = libvlc_media_player_get_media(p_md);
what if p_media will be ==0 ?

> +        const char *info;
> +        switch( index )
> +        {
> +            case ID_meta_title:
> +            case ID_meta_artist:
> +            case ID_meta_genre:
> +            case ID_meta_copyright:
> +            case ID_meta_album:
> +            case ID_meta_trackNumber:
> +            case ID_meta_description:
> +            case ID_meta_rating:
> +            case ID_meta_date:
> +            case ID_meta_setting:
> +            case ID_meta_URL:
> +            case ID_meta_language:
> +            case ID_meta_nowPlaying:
> +            case ID_meta_publisher:
> +            case ID_meta_EncodedBy:
> +            case ID_meta_ArtworkURL:
> +            case ID_meta_trackID:
> +                info = libvlc_media_get_meta(p_media,(libvlc_meta_t) index);
> +                return invokeResultString(info, result);
> +            default:
> +            ;
> +        }
> +     }
> +     return INVOKERESULT_GENERIC_ERROR;
> +}
> +
> +RuntimeNPObject::InvokeResult
> +LibvlcMediaDescriptionNPObject::setProperty(int index, const NPVariant &value)
> +{
> +    /* is plugin still running */
> +    if( isPluginRunning() )
> +    {
> +        switch( index )
> +        {
> +            case ID_none:
> +                return INVOKERESULT_NO_SUCH_METHOD;
> +            default:
> +                ;
> +        }
> +    }
> +    return INVOKERESULT_GENERIC_ERROR;
> +}
> +
> +const NPUTF8 * const LibvlcMediaDescriptionNPObject::methodNames[] =
> +{
> +    "None"
> +};
> +COUNTNAMES(LibvlcMediaDescriptionNPObject,methodCount,methodNames);
> +
> +enum LibvlcMediaDescriptionNPObjectMethodIds
> +{
> +    ID_mediadescription_method_none,
> +};
> +RuntimeNPObject::InvokeResult
> +LibvlcMediaDescriptionNPObject::invoke(int index, const NPVariant *args,
> +                            uint32_t argCount, NPVariant &result)
> +{
> +    /* is plugin still running */
> +    if( isPluginRunning() )
> +    {
> +        switch( index )
> +        {
> +            case ID_mediadescription_method_none:
> +                return INVOKERESULT_NO_SUCH_METHOD;
> +            default:
> +                ;
> +        }
> +    }
> +    return INVOKERESULT_GENERIC_ERROR;
> +}
> +
> +
> +/*
>  ** implementation of libvlc playlist items object
>  */
>
> diff --git a/npapi/control/npolibvlc.h b/npapi/control/npolibvlc.h
> index c6d8694..d5a57b9 100644
> --- a/npapi/control/npolibvlc.h
> +++ b/npapi/control/npolibvlc.h
> @@ -38,7 +38,8 @@ protected:
>     inputObj(NULL),
>     playlistObj(NULL),
>     subtitleObj(NULL),
> -    videoObj(NULL) { }
> +    videoObj(NULL),
> +    mediaDescriptionObj(NULL) { }
>
>     virtual ~LibvlcRootNPObject();
>
> @@ -58,6 +59,7 @@ private:
>     NPObject *playlistObj;
>     NPObject *subtitleObj;
>     NPObject *videoObj;
> +    NPObject *mediaDescriptionObj;
>  };
>
>  class LibvlcAudioNPObject: public RuntimeNPObject
> @@ -103,6 +105,26 @@ protected:
>     InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
>  };
>
> +class LibvlcMediaDescriptionNPObject: public RuntimeNPObject
> +{
> +protected:
> +    friend class RuntimeNPClass<LibvlcMediaDescriptionNPObject>;
> +    LibvlcMediaDescriptionNPObject(NPP instance, const NPClass *aClass) :
> +        RuntimeNPObject(instance, aClass) {};
> +    virtual ~LibvlcMediaDescriptionNPObject() {};
> +
> +    static const int propertyCount;
> +    static const NPUTF8 * const propertyNames[];
> +
> +    InvokeResult getProperty(int index, NPVariant &result);
> +    InvokeResult setProperty(int index, const NPVariant &value);
> +
> +    static const int methodCount;
> +    static const NPUTF8 * const methodNames[];
> +
> +    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
> +};
> +
>  class LibvlcPlaylistItemsNPObject: public RuntimeNPObject
>  {
>  protected:
> --
> 1.7.5.4
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> http://mailman.videolan.org/listinfo/vlc-devel

And I am still thinking that it will be good to have something like
LibvlcMediaDescriptionNPObject in playlist...



More information about the vlc-devel mailing list