Difference between revisions of "MediaControlAPI"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
== Description ==
 
== Description ==
  
The MediaControl API is the extended API to control VLC from external applications (extension of LibVLC). Its core part (playback control) has been taken from the [http://www.omg.org/docs/formal/00-01-03.pdf OMG Audio/Video Stream specification], and extended with additional functionalities. An [http://liris.cnrs.fr/advene/download/MediaControl.idl IDL specification MediaControl.idl] has been the base of this work.
+
The MediaControl API is a generic Media player API. The idea is to define a generic video-player API, that could be reused with other players. It will be implemented in VLC by using the [[ExternaAPI#VLC_Control|New libvlc API]].
  
The idea is to define a generic video-player API, that could be reused with other players.
+
Its core part (playback control) has been taken from the [http://www.omg.org/docs/formal/00-01-03.pdf OMG Audio/Video Stream specification], and extended with additional functionalities. An [http://liris.cnrs.fr/advene/download/MediaControl.idl IDL specification MediaControl.idl] has been the base of this work.
  
The API is defined in [http://trac.videolan.org/vlc/browser/trunk/include/vlc/control.h "include/vlc/control.h"] and implemented in  
+
FIXME : The API is defined in [http://trac.videolan.org/vlc/browser/trunk/include/vlc/control.h "include/vlc/control.h"] and implemented in  
 
[http://trac.videolan.org/vlc/browser/trunk/src/control "src/control"].
 
[http://trac.videolan.org/vlc/browser/trunk/src/control "src/control"].
  
Line 39: Line 39:
 
* Fix VLC initialization on Win32 so that it uses the registry key to find the default plugins directory by default. Currently, it uses the vlc.exe path, which it cannot find when using VLC embedded. A workaround is to chdir to the vlc.exe directory before instanciating the MediaControl() object.
 
* Fix VLC initialization on Win32 so that it uses the registry key to find the default plugins directory by default. Currently, it uses the vlc.exe path, which it cannot find when using VLC embedded. A workaround is to chdir to the vlc.exe directory before instanciating the MediaControl() object.
  
A proposal for the new API (in IDL syntax) is in [[MediaControlIDL]]
+
== Full API ==
 +
 
 +
Here is an IDL description of the MediaControlAPI
 +
 
 +
<pre>
 +
module VLC {
 +
 
 +
  const float VERSION = 1.0;
 +
 
 +
  enum PositionOrigin {
 +
    AbsolutePosition,
 +
    RelativePosition,
 +
    // Like relative, but wraps at the end of a file for instance:
 +
    ModuloPosition
 +
  };
 +
 
 +
  enum PositionKey {
 +
    // For raw access
 +
    ByteCount,
 +
    // Frame number
 +
    SampleCount,
 +
    // In milliseconds
 +
    MediaTime
 +
  };
 +
 
 +
  struct Position {
 +
    PositionOrigin origin;
 +
    PositionKey key;
 +
    long long value;
 +
  };
 +
 
 +
  exception PositionKeyNotSupported    { string message; };
 +
  exception PositionOriginNotSupported { string message; };
 +
  exception InvalidPosition            { string message; };
 +
  exception PlaylistException          { string message; };
 +
  exception InternalException          { string message; };
 +
 
 +
  typedef sequence<string> PlaylistSeq;
 +
  typedef sequence<octet> ByteSeq;
 +
 
 +
  struct RGBPicture {
 +
    short width;
 +
    short height;
 +
    long type;
 +
    ByteSeq data;
 +
    // Timestamp (absolute position in the movie) in ms
 +
    long long date;
 +
  };
 +
 
 +
  struct StreamInformation {
 +
    short width;
 +
    short height;
 +
    float aspect_ratio;
 +
    long bitrate;
 +
    string codec;
 +
    string author;
 +
  };
 +
 
 +
  typedef sequence<RGBPicture> RGBPictureSeq;
 +
 
 +
  enum PlayerStatus { PlayingStatus, PauseStatus, ForwardStatus, BackwardStatus, InitStatus, EndStatus, UndefinedStatus };
 +
 
 +
  struct StatusInformation {
 +
    PlayerStatus streamstatus;
 +
    string url;            /* The URL of the current media stream  */
 +
    long long position;    /* actual location in the stream (in ms) */
 +
    long long length;      /* total length of the stream (in ms)    */
 +
  };
 +
 
 +
  interface Playlist
 +
  {
 +
    // Return a playlist item id
 +
    int add(in string a_file)
 +
      raises (PlaylistException);
 +
 
 +
    void next(in string a_file)
 +
      raises (PlaylistException);
 +
 
 +
    void prev(in string a_file)
 +
      raises (PlaylistException);
 +
 
 +
    // Set the new current item
 +
    void set(int item_id)
 +
      raises (PlaylistException);
 +
 
 +
    void remove(int item_id)
 +
      raises (PlaylistException);
 +
 
 +
    // Clear the whole playlist
 +
    void clear ()
 +
      raises (PlaylistException);
 +
 
 +
    // Return the list of files in playlist
 +
    PlaylistSeq get_list ()
 +
      raises (PlaylistException);
 +
  }
 +
 
 +
  // MediaControl interface is similar to
 +
  // ControlledStream interface in MSS.
 +
  // It can be inherited by flow endpoints or
 +
  // FlowConnection interfaces.
 +
  interface MediaControl
 +
  {
 +
    // *** Initialization
 +
    // Exit the player
 +
    oneway void exit ();
 +
 
 +
    // Return the IDL API version
 +
    string get_api_version();
 +
 
 +
    // Return the player version (player name + version)
 +
    string get_player_version();
 +
 
 +
    // *** Playback control
 +
    // The a_position parameters are facultative.
 +
    void start(in Position a_position)
 +
      raises (InternalException, InvalidPosition, PlaylistException);
 +
 
 +
    void pause(in Position a_position)
 +
      raises (InternalException, InvalidPosition);
 +
 
 +
    void resume(in Position a_position)
 +
      raises (InternalException, InvalidPosition);
 +
 
 +
    void stop(in Position a_position)
 +
      raises (InternalException, InvalidPosition);
 +
 
 +
    Position get_media_position(in PositionOrigin an_origin,
 +
in PositionKey a_key)
 +
      raises (InternalException, PositionKeyNotSupported);
 +
 
 +
    void set_media_position(in Position a_position)
 +
      raises (InternalException, PositionKeyNotSupported, InvalidPosition);
 +
 
 +
    // Rate control. The rate is a signed value, corresponding to
 +
    // the percentage of the speed (+100 = normal, -100 = reverse...)
  
== Todo ==
+
    int get_rate()
 +
      raises (InternalException);
  
* Add missing features (see next section)
+
    void set_rate(int rate)
* Bind the new API to .NET
+
      raises (InternalException);
  
== Full API ==
+
    // *** Media information
  
=== Initialization ===
+
    StatusInformation get_status_information ()
* mediacontrol_new ''Create a new instance of a MediaControl object''
+
      raises (InternalException);
* '''mediacontrol_get_version''' ''Return the version of the API''
 
* mediacontrol_new_from_object(object_id) ''Use an existing VLC object id to initialize the MediaControl object''
 
* mediacontrol_exit ''Stop VLC''
 
  
=== Playback control ===
+
    // Return information about the current stream
 +
    StreamInformation get_stream_information ()
 +
      raises (InternalException);
  
''Playback control methods use a Position object as parameter to specify start or stop position.''
+
    // *** Playlist handling
 +
    Playlist playlist()
 +
      raises (InternalException);
  
* mediacontrol_start( position )
+
    // *** Video
* mediacontrol_pause( position ) ''The position parameter may be ignored by bindings. In this case, it defaults to a 0-relative position.''
 
* mediacontrol_resume( position )
 
* mediacontrol_stop( position )
 
* mediacontrol_get_media_position( origin, key )
 
* mediacontrol_set_media_position( position )
 
* '''mediacontrol_set_rate'''
 
* '''mediacontrol_get_rate'''
 
  
=== Media info ===
+
    // Return a snapshot of the currently displayed picture
 +
    RGBPicture snapshot (in Position a_position)
 +
      raises (InternalException);
  
* mediacontrol_get_stream_information
+
    // Return the whole snapshot cache contents
 +
    RGBPictureSeq all_snapshots ()
 +
      raises (InternalException);
  
See [[Talk:MediaControlAPI]]
+
    // Display the message string as caption,
 +
    // between "begin" and "end" positions
 +
    void render_text (in string message, in Position begin, in Position end)
 +
      raises (InternalException);
  
=== Playlist ===
+
    // Set the visual ID (XID in X-Window, HWIN on Win32, ??? on MacOS
 +
    // X) for the player window
 +
    void set_visual(long xid)
 +
      raises (InternalException);
  
* mediacontrol_playlist_add_item ( MRL ) '''should return item id'''
+
    boolean get_fullscreen()
* mediacontrol_playlist_clear()
+
      raises (InternalException);
* mediacontrol_playlist_get_list
 
* '''mediacontrol_playlist_next'''
 
* '''mediacontrol_playlist_prev'''
 
* '''mediacontrol_playlist_play( id )'''
 
* '''mediacontrol_playlist_remove( id )'''
 
* '''mediacontrol_playlist_sort( int )''' <- int is a const, the rule to sort with
 
  
See [[Talk:MediaControlAPI]]
+
    void set_fullscreen(boolean full)
 +
      raises (InternalException);
  
 +
    // *** Audio
  
=== Video ===
+
    // Volume is normalized in [0..100]
* mediacontrol_snapshot(position) <-- returns an RGB picture '''should probably use vout_Snapshot instead of the snapshot module''' (but cf discussion in [[VoutReworkUserRequirements]] and [[PythonBinding]])
+
    unsigned short sound_get_volume()
* mediacontrol_all_snapshots() ''Return a list of RGB pictures contained in the cache. Could allow for precise selection of a snapshot.''
+
      raises (InternalException);
* mediacontrol_display_text( text, start_time, stop_time ) ''Send a text to the text renderer.''
 
* mediacontrol_set_visual(visual_id) ''Set the visual ID when embedding VLC''
 
* '''mediacontrol_toggle_fullscreen'''
 
* '''mediacontrol_set_fullscreen( boolean )'''
 
* '''mediacontrol_get_fullscreen( boolean )''' <-- Maybe integrate a variable get facility -> Too VLC-specific
 
* '''mediacontrol_apply_filter ( filter, position )''' <-- is there a filter structure in VLC? -> Too VLC-specific
 
  
=== Audio ===
+
    void sound_set_volume(in unsigned short volume)
* mediacontrol_sound_get_volume
+
      raises (InternalException);
* mediacontrol_sound_set_volume
 
* '''mediacontrol_sound_mute'''
 
  
=== VLM ===
+
    void sound_mute()
* '''mediacontrol_vlm_add_broadcast( name, input, output, options)'''
+
      raises (InternalException);
* '''mediacontrol_vlm_add_vod'''
+
  };
* '''mediacontrol_vlm_get_broadcasts'''
+
};
* '''mediacontrol_vlm_get_vods'''
+
</pre>
* '''mediacontrol_vlm_delete_broadcast( name )'''
 
* '''mediacontrol_vlm_delete_vod( name )'''
 
* '''mediacontrol_vlm_load( file )'''
 
* '''mediacontrol_vlm_save( file )'''
 

Revision as of 14:27, 18 December 2005

Description

The MediaControl API is a generic Media player API. The idea is to define a generic video-player API, that could be reused with other players. It will be implemented in VLC by using the New libvlc API.

Its core part (playback control) has been taken from the OMG Audio/Video Stream specification, and extended with additional functionalities. An IDL specification MediaControl.idl has been the base of this work.

FIXME : The API is defined in "include/vlc/control.h" and implemented in "src/control".

The Doxygen documentation can be found at [1].

Current status

The API currently includes functions for the following things:

  • Playback
    • Basic features (play/pause/stop)
    • Seeking
    • Basic playlist interaction
    • Stream information
  • Audio/Video
    • Snapshot control (requires the use of the snapshot vout module via the clone video filter; invoke with: vlc --video-filter clone --clone-vout-list default,snapshot )
    • OSD display (of text and SVG graphics through the svg rendering module)
    • Volume setting
    • Setting the visual ID of an embedding window

Current uses

The MediaControl API is used by the following modules :

Foreseen evolutions

The following evolutions should be integrated in the API, but discussion is necessary to ensure that they are sufficiently flexible to match various needs :

  • sound_[sg]et_volume: normalize volume in [0..100]
  • implement get_api_version() or get_capabilities() (which would return the list of capabilities supported by the player: ("core", "svg", "snapshot", etc)
  • Complete the implementation. For instance, the frame-by-frame unit (mediacontrol_SampleCount) is not implemented, and the stop/pause do not take the Position parameter into account (they are applied immediately).
  • Fix VLC initialization on Win32 so that it uses the registry key to find the default plugins directory by default. Currently, it uses the vlc.exe path, which it cannot find when using VLC embedded. A workaround is to chdir to the vlc.exe directory before instanciating the MediaControl() object.

Full API

Here is an IDL description of the MediaControlAPI

module VLC {

  const float VERSION = 1.0;

  enum PositionOrigin {
    AbsolutePosition, 
    RelativePosition, 
    // Like relative, but wraps at the end of a file for instance:
    ModuloPosition
  };

  enum PositionKey {
    // For raw access
    ByteCount, 
    // Frame number
    SampleCount,
    // In milliseconds
    MediaTime
  };

  struct Position {
    PositionOrigin origin;
    PositionKey key;
    long long value;
  };

  exception PositionKeyNotSupported    { string message; };
  exception PositionOriginNotSupported { string message; };
  exception InvalidPosition            { string message; };
  exception PlaylistException          { string message; };
  exception InternalException          { string message; };

  typedef sequence<string> PlaylistSeq;
  typedef sequence<octet> ByteSeq;

  struct RGBPicture {
    short width;
    short height;
    long type;
    ByteSeq data;
    // Timestamp (absolute position in the movie) in ms
    long long date;
  };

  struct StreamInformation {
    short width;
    short height;
    float aspect_ratio;
    long bitrate;
    string codec;
    string author;
  };

  typedef sequence<RGBPicture> RGBPictureSeq;

  enum PlayerStatus { PlayingStatus, PauseStatus, ForwardStatus, BackwardStatus, InitStatus, EndStatus, UndefinedStatus };

  struct StatusInformation {
    PlayerStatus streamstatus;
    string url;             /* The URL of the current media stream   */
    long long position;     /* actual location in the stream (in ms) */
    long long length;       /* total length of the stream (in ms)    */
  };

  interface Playlist 
  {
    // Return a playlist item id
    int add(in string a_file)
      raises (PlaylistException);

    void next(in string a_file)
      raises (PlaylistException);

    void prev(in string a_file)
      raises (PlaylistException);

    // Set the new current item
    void set(int item_id)
      raises (PlaylistException);

    void remove(int item_id)
      raises (PlaylistException);

    // Clear the whole playlist
    void clear ()
      raises (PlaylistException);

    // Return the list of files in playlist
    PlaylistSeq get_list ()
      raises (PlaylistException);
  }

  // MediaControl interface is similar to
  // ControlledStream interface in MSS.
  // It can be inherited by flow endpoints or
  // FlowConnection interfaces.
  interface MediaControl
  {
    // *** Initialization
    // Exit the player
    oneway void exit ();

    // Return the IDL API version
    string get_api_version();

    // Return the player version (player name + version)
    string get_player_version();

    // *** Playback control
    // The a_position parameters are facultative.
    void start(in Position a_position)
      raises (InternalException, InvalidPosition, PlaylistException);

    void pause(in Position a_position)
      raises (InternalException, InvalidPosition);

    void resume(in Position a_position)
      raises (InternalException, InvalidPosition);

    void stop(in Position a_position)
      raises (InternalException, InvalidPosition);

    Position get_media_position(in PositionOrigin an_origin,
				in PositionKey a_key)
      raises (InternalException, PositionKeyNotSupported);

    void set_media_position(in Position a_position)
      raises (InternalException, PositionKeyNotSupported, InvalidPosition);

    // Rate control. The rate is a signed value, corresponding to
    // the percentage of the speed (+100 = normal, -100 = reverse...)

    int get_rate()
      raises (InternalException);

    void set_rate(int rate)
      raises (InternalException);

    // *** Media information

    StatusInformation get_status_information ()
      raises (InternalException);

    // Return information about the current stream
    StreamInformation get_stream_information ()
      raises (InternalException);

    // *** Playlist handling
    Playlist playlist()
      raises (InternalException);

    // *** Video

    // Return a snapshot of the currently displayed picture
    RGBPicture snapshot (in Position a_position)
      raises (InternalException);

    // Return the whole snapshot cache contents
    RGBPictureSeq all_snapshots ()
      raises (InternalException);

    // Display the message string as caption, 
    // between "begin" and "end" positions
    void render_text (in string message, in Position begin, in Position end)
      raises (InternalException);

    // Set the visual ID (XID in X-Window, HWIN on Win32, ??? on MacOS
    // X) for the player window
    void set_visual(long xid)
      raises (InternalException);

    boolean get_fullscreen()
      raises (InternalException);

    void set_fullscreen(boolean full)
      raises (InternalException);

    // *** Audio

    // Volume is normalized in [0..100]
    unsigned short sound_get_volume()
      raises (InternalException);

    void sound_set_volume(in unsigned short volume)
      raises (InternalException);

    void sound_mute()
      raises (InternalException);
  };
};