22
décembre
2012
libvlc.vapi : la vapi de la libvlc pour le langage Vala
décembre
2012
Un article de Rachel
Pas de commentaires
dans le cadre de mes travaux sur l’étude d’un lecteur multimédia, j’ai recherché plusieurs langages & et bibliothèques. J’ai finalement adopté vlc et vala. J’ai du écrire un fichier .vapi à la main car vlc n’étant pas développé sur gobject, la génération fut impossible.
Je vous propose une première version de la vapi, ne manque plus que la gestion des évènements et vlm.
[CCode(cheader_filename = "vlc/vlc.h")]
namespace Vlc
{
[CCode(cprefix = "libvlc_")]
public static string errmsg();
[CCode(cprefix = "libvlc_")]
public static void clearerr();
[CCode(cprefix = "libvlc_")]
public static string vprinterr(string format, va_list args);
[CCode(cname = "enum libvlc_state_t",cprefix = "libvlc_")]
public enum State
{
NothingSpecial=0,
Opening,
Buffering,
Playing,
Paused,
Stopped,
Ended,
Error
}
[CCode(cname = "enum libvlc_meta_t", cprefix = "libvlc_meta")]
public enum TagType
{
Title,
Artist,
Genre,
Copyright,
Album,
TrackNumber,
Description,
Rating,
Date,
Setting,
URL,
Language,
NowPlaying,
Publisher,
EncodedBy,
ArtworkURL,
TrackID
}
[CCode(cname = "libvlc_instance_t", unref_function = "libvlc_release", cprefix = "libvlc_")]
public class Instance
{
public static long clock();
[CCode(cname = "libvlc_new")]
public Instance(int argc, string *argv);
public int add_intf(string name);
public void wait();
public void set_user_agent(string name, string http);
public static string get_version();
public static string get_compiler();
public static string get_changeset();
}
[CCode(cname = "struct libvlc_media_t", unref_function = "libvlc_media_release", cprefix = "libvlc_media_")]
public class Media
{
[CCode(cname = "libvlc_media_new_location")]
public Media.location(Instance i, string location);
[CCode(cname = "libvlc_media_new_path")]
public Media.path(Instance i, string path);
public string get_mrl();
public Media duplicate();
public string get_meta(TagType type);
public void set_meta(TagType type, string value);
public int save_meta();
public int get_stats(out MediaStats stats);
public long get_duration();
public void parse();
public void parse_async();
public int is_parsed();
public void set_user_data(void *user_data);
public void *get_user_data();
public void *user_data{get; set;}
public string meta{get; set;}
}
[CCode(cname = "libvlc_media_player_t", unref_function = "libvlc_media_player_release", cprefix = "libvlc_media_player_")]
public class MediaPlayer
{
[CCode(cname = "libvlc_media_player_new")]
public MediaPlayer(Instance i);
[CCode(cname = "libvlc_media_player_new_from_media")]
public MediaPlayer.from_media(Media m);
public void set_media(Media m);
public Media get_media();
public int is_playing();
public int play();
public void set_pause(int do_pause);
public void pause();
public void stop();
[CCode(cname = "libvlc_video_set_callbacks")]
public void set_callbacks(VideoLockFunc l, VideoUnlockFunc u, VideoDisplayFunc d, void *opaque);
[CCode(cname = "libvlc_video_set_format")]
public void set_videoformat(string chroma, uint width, uint height, uint pitch);
[CCode(cname = "libvlc_video_set_format_callbacks")]
public void set_format_callbacks(VideoFormatFunc format, VideoCleanupFunc cleanup);
public void set_xwindow(uint drawable);
public uint get_xwindow();
public long get_length();
public long get_time();
public void set_time(long time);
public float get_position();
public void set_position(float pos);
public void set_chapter(int chapter);
public int get_chapter();
public int get_chapter_count();
public int will_play();
public int get_chapter_count_for_title();
public int get_title();
public void set_title(int title);
public int get_title_count();
public void previous_chapter();
public void next_chapter();
public float get_rate();
public void set_rate(float rate);
public State get_state();
public float get_fps();
public uint has_vout();
public int is_seekable();
public int can_pause();
public void next_frame();
[CCode(cname = "libvlc_set_fullscreen")]
public void set_fullscreen(int f);
[CCode(cname = "libvlc_get_fullscreen")]
public int get_fullscreen();
[CCode(cname = "libvlc_video_get_size")]
public int get_video_size(uint index, out uint x, out uint y);
[CCode(cname = "libvlc_video_get_cursor")]
public int get_cursor_position(uint index, out uint px, out uint py);
[CCode(cname = "libvlc_video_get_scale")]
public float get_videoscale();
[CCode(cname = "libvlc_video_set_scale")]
public void set_videoscale(float scale);
public void navigate(NavigateMode mode);
[CCode(cname = "libvlc_video_get_aspect_ratio")]
public string get_aspect_ratio();
[CCode(cname = "libvlc_video_set_aspect_ratio")]
public void set_aspect_ratio(string ratio);
[CCode(cname = "libvlc_video_get_spu")]
public int get_current_subtitle();
[CCode(cname = "libvlc_video_get_spu_count")]
public int get_subtitles_count();
[CCode(cname = "libvlc_video_get_spu_description")]
public TrackDescription get_subtitles_description();
[CCode(cname = "libvlc_video_set_spu")]
public int set_current_subtitle(uint sub);
[CCode(cname = "libvlc_video_set_subtitle_file")]
public int set_subtitles_file(string file);
[CCode(cname = "libvlc_video_get_spu_delay")]
public long get_subtitle_delay();
[CCode(cname = "libvlc_video_set_spu_delay")]
public int set_subtitle_delay(long delay);
[CCode(cname = "libvlc_video_get_title_description")]
public TrackDescription get_title_description();
[CCode(cname = "libvlc_video_get_chapter_description")]
public TrackDescription get_chapter_description();
[CCode(cname = "libvlc_video_get_crop_geometry")]
public string get_crop_geometry();
[CCode(cname = "libvlc_video_set_crop_geometry")]
public void set_crop_geometry(string crop);
[CCode(cname = "libvlc_video_get_track_count")]
public int get_videotrack_count();
[CCode(cname = "libvlc_video_get_track_description")]
public TrackDescription get_track_description();
[CCode(cname = "libvlc_video_get_track")]
public int get_videotrack();
[CCode(cname = "libvlc_video_set_track")]
public int set_videotrack(int track);
[CCode(cname = "libvlc_video_take_snapshot")]
public int snapshot(uint video_index,string filepath,uint width, uint height);
public int videotrack {get; set;}
public string crop_geometry {get; set;}
public long subtitle_delay {get; set;}
public string aspect_ratio {get; set;}
public float videoscale {get; set;}
public float rate {get; set;}
public int title {get; set;}
public int chapter {get; set;}
public float position {get; set;}
public long time {get; set;}
public uint xwindow {get; set;}
public Media media {get; set;}
}
[CCode(cname = "struct libvlc_track_description_t", unref_function = "libvlc_track_description_list_release")]
public class TrackDescription
{
public int id;
public string name;
public TrackDescription next;
}
[CCode(cprefix = "libvlc_media_list_", cname = "struct libvlc_media_list_t", unref_function = "libvlc_media_list_release")]
public class MediaList
{
[CCode(cname = "libvlc_media_list_new")]
public MediaList(Instance i);
public void set_media(Media m);
[CCode(cname = "libvlc_media_list_media")]
public Media get_media();
public int add_media(Media m);
public int insert_media(Media m, int position);
public int remove_index(int index);
public int count();
public Media item_at_index(int index);
public int index_of_item(Media m);
public int is_readonly();
public void lock();
public void unlock();
public Media media {get; set;}
}
[CCode(cprefix = "libvlc_media_library_", cname = "struct libvlc_media_library_t", ref_function = "libvlc_media_library_retain", unref_function = "libvlc_media_library_release")]
public class MediaLibrary
{
[CCode(cname = "libvlc_media_library_new")]
public MediaLibrary(Instance i){}
public int load();
public MediaList list();
}
[CCode(cprefix = "libvlc_media_discoverer_", cname = "struct libvlc_media_discoverer_t", unref_function = "libvlc_media_discoverer_release")]
public class MediaDiscoverer
{
[CCode(cname = "libvlc_media_discoverer_new_from_name")]
public MediaDiscoverer(Instance i, string name);
public string localized_name();
public MediaList media_list();
public int is_running();
}
[CCode(cprefix = "libvlc_media_list_player_", cname = "struct libvlc_media_list_player_t", unref_function = "libvlc_media_list_player_release")]
public class MediaListPlayer
{
[CCode(cname = "libvlc_media_list_player_new")]
public MediaListPlayer(Instance i);
public void set_media_player(MediaPlayer player);
public void set_media_list(MediaList list);
public void play();
public void pause();
public int is_playing();
public State get_state();
public int play_item_at_index(int index);
public int play_item(Media media);
public void stop();
public void next();
public void previous();
public void set_playback_mode(PlaybackMode mode);
}
[CCode(cname = "int")]
public enum PlaybackMode
{
Default,
Loop,
Repeat
}
[CCode(cname = "uint")]
public enum NavigateMode
{
Activate,
Up,
Down,
Left,
Right
}
public delegate void VideoLockFunc(void *opaque, void **planes);
public delegate void VideoUnlockFunc(void *opaque, void *picture, void **planes);
public delegate void VideoDisplayFunc(void *opaque, void *picture);
public delegate uint VideoFormatFunc(void **opaque, string chroma,
uint *width, uint *height,
uint *pitches,
uint *lines);
public delegate void VideoCleanupFunc(void *opaque);
public delegate void AudioPlayFunc(void *data, void *samples, uint count, long pts);
public delegate void AudioPauseFunc(void *data, long pts);
public struct MediaStats
{
public int i_read_bytes;
public float f_input_bitrate;
public int i_demux_read_bytes;
public float f_demux_bitrate;
public int i_demux_corrupted;
public int i_demux_discontinuity;
public int i_decoded_video;
public int i_decoded_audio;
public int i_displayed_pictures;
public int i_lost_pictures;
public int i_played_abuffers;
public int i_lost_abuffers;
public int i_sent_packets;
public int i_sent_bytes;
public float f_send_bitrate;
}
}
namespace Vlc
{
[CCode(cprefix = "libvlc_")]
public static string errmsg();
[CCode(cprefix = "libvlc_")]
public static void clearerr();
[CCode(cprefix = "libvlc_")]
public static string vprinterr(string format, va_list args);
[CCode(cname = "enum libvlc_state_t",cprefix = "libvlc_")]
public enum State
{
NothingSpecial=0,
Opening,
Buffering,
Playing,
Paused,
Stopped,
Ended,
Error
}
[CCode(cname = "enum libvlc_meta_t", cprefix = "libvlc_meta")]
public enum TagType
{
Title,
Artist,
Genre,
Copyright,
Album,
TrackNumber,
Description,
Rating,
Date,
Setting,
URL,
Language,
NowPlaying,
Publisher,
EncodedBy,
ArtworkURL,
TrackID
}
[CCode(cname = "libvlc_instance_t", unref_function = "libvlc_release", cprefix = "libvlc_")]
public class Instance
{
public static long clock();
[CCode(cname = "libvlc_new")]
public Instance(int argc, string *argv);
public int add_intf(string name);
public void wait();
public void set_user_agent(string name, string http);
public static string get_version();
public static string get_compiler();
public static string get_changeset();
}
[CCode(cname = "struct libvlc_media_t", unref_function = "libvlc_media_release", cprefix = "libvlc_media_")]
public class Media
{
[CCode(cname = "libvlc_media_new_location")]
public Media.location(Instance i, string location);
[CCode(cname = "libvlc_media_new_path")]
public Media.path(Instance i, string path);
public string get_mrl();
public Media duplicate();
public string get_meta(TagType type);
public void set_meta(TagType type, string value);
public int save_meta();
public int get_stats(out MediaStats stats);
public long get_duration();
public void parse();
public void parse_async();
public int is_parsed();
public void set_user_data(void *user_data);
public void *get_user_data();
public void *user_data{get; set;}
public string meta{get; set;}
}
[CCode(cname = "libvlc_media_player_t", unref_function = "libvlc_media_player_release", cprefix = "libvlc_media_player_")]
public class MediaPlayer
{
[CCode(cname = "libvlc_media_player_new")]
public MediaPlayer(Instance i);
[CCode(cname = "libvlc_media_player_new_from_media")]
public MediaPlayer.from_media(Media m);
public void set_media(Media m);
public Media get_media();
public int is_playing();
public int play();
public void set_pause(int do_pause);
public void pause();
public void stop();
[CCode(cname = "libvlc_video_set_callbacks")]
public void set_callbacks(VideoLockFunc l, VideoUnlockFunc u, VideoDisplayFunc d, void *opaque);
[CCode(cname = "libvlc_video_set_format")]
public void set_videoformat(string chroma, uint width, uint height, uint pitch);
[CCode(cname = "libvlc_video_set_format_callbacks")]
public void set_format_callbacks(VideoFormatFunc format, VideoCleanupFunc cleanup);
public void set_xwindow(uint drawable);
public uint get_xwindow();
public long get_length();
public long get_time();
public void set_time(long time);
public float get_position();
public void set_position(float pos);
public void set_chapter(int chapter);
public int get_chapter();
public int get_chapter_count();
public int will_play();
public int get_chapter_count_for_title();
public int get_title();
public void set_title(int title);
public int get_title_count();
public void previous_chapter();
public void next_chapter();
public float get_rate();
public void set_rate(float rate);
public State get_state();
public float get_fps();
public uint has_vout();
public int is_seekable();
public int can_pause();
public void next_frame();
[CCode(cname = "libvlc_set_fullscreen")]
public void set_fullscreen(int f);
[CCode(cname = "libvlc_get_fullscreen")]
public int get_fullscreen();
[CCode(cname = "libvlc_video_get_size")]
public int get_video_size(uint index, out uint x, out uint y);
[CCode(cname = "libvlc_video_get_cursor")]
public int get_cursor_position(uint index, out uint px, out uint py);
[CCode(cname = "libvlc_video_get_scale")]
public float get_videoscale();
[CCode(cname = "libvlc_video_set_scale")]
public void set_videoscale(float scale);
public void navigate(NavigateMode mode);
[CCode(cname = "libvlc_video_get_aspect_ratio")]
public string get_aspect_ratio();
[CCode(cname = "libvlc_video_set_aspect_ratio")]
public void set_aspect_ratio(string ratio);
[CCode(cname = "libvlc_video_get_spu")]
public int get_current_subtitle();
[CCode(cname = "libvlc_video_get_spu_count")]
public int get_subtitles_count();
[CCode(cname = "libvlc_video_get_spu_description")]
public TrackDescription get_subtitles_description();
[CCode(cname = "libvlc_video_set_spu")]
public int set_current_subtitle(uint sub);
[CCode(cname = "libvlc_video_set_subtitle_file")]
public int set_subtitles_file(string file);
[CCode(cname = "libvlc_video_get_spu_delay")]
public long get_subtitle_delay();
[CCode(cname = "libvlc_video_set_spu_delay")]
public int set_subtitle_delay(long delay);
[CCode(cname = "libvlc_video_get_title_description")]
public TrackDescription get_title_description();
[CCode(cname = "libvlc_video_get_chapter_description")]
public TrackDescription get_chapter_description();
[CCode(cname = "libvlc_video_get_crop_geometry")]
public string get_crop_geometry();
[CCode(cname = "libvlc_video_set_crop_geometry")]
public void set_crop_geometry(string crop);
[CCode(cname = "libvlc_video_get_track_count")]
public int get_videotrack_count();
[CCode(cname = "libvlc_video_get_track_description")]
public TrackDescription get_track_description();
[CCode(cname = "libvlc_video_get_track")]
public int get_videotrack();
[CCode(cname = "libvlc_video_set_track")]
public int set_videotrack(int track);
[CCode(cname = "libvlc_video_take_snapshot")]
public int snapshot(uint video_index,string filepath,uint width, uint height);
public int videotrack {get; set;}
public string crop_geometry {get; set;}
public long subtitle_delay {get; set;}
public string aspect_ratio {get; set;}
public float videoscale {get; set;}
public float rate {get; set;}
public int title {get; set;}
public int chapter {get; set;}
public float position {get; set;}
public long time {get; set;}
public uint xwindow {get; set;}
public Media media {get; set;}
}
[CCode(cname = "struct libvlc_track_description_t", unref_function = "libvlc_track_description_list_release")]
public class TrackDescription
{
public int id;
public string name;
public TrackDescription next;
}
[CCode(cprefix = "libvlc_media_list_", cname = "struct libvlc_media_list_t", unref_function = "libvlc_media_list_release")]
public class MediaList
{
[CCode(cname = "libvlc_media_list_new")]
public MediaList(Instance i);
public void set_media(Media m);
[CCode(cname = "libvlc_media_list_media")]
public Media get_media();
public int add_media(Media m);
public int insert_media(Media m, int position);
public int remove_index(int index);
public int count();
public Media item_at_index(int index);
public int index_of_item(Media m);
public int is_readonly();
public void lock();
public void unlock();
public Media media {get; set;}
}
[CCode(cprefix = "libvlc_media_library_", cname = "struct libvlc_media_library_t", ref_function = "libvlc_media_library_retain", unref_function = "libvlc_media_library_release")]
public class MediaLibrary
{
[CCode(cname = "libvlc_media_library_new")]
public MediaLibrary(Instance i){}
public int load();
public MediaList list();
}
[CCode(cprefix = "libvlc_media_discoverer_", cname = "struct libvlc_media_discoverer_t", unref_function = "libvlc_media_discoverer_release")]
public class MediaDiscoverer
{
[CCode(cname = "libvlc_media_discoverer_new_from_name")]
public MediaDiscoverer(Instance i, string name);
public string localized_name();
public MediaList media_list();
public int is_running();
}
[CCode(cprefix = "libvlc_media_list_player_", cname = "struct libvlc_media_list_player_t", unref_function = "libvlc_media_list_player_release")]
public class MediaListPlayer
{
[CCode(cname = "libvlc_media_list_player_new")]
public MediaListPlayer(Instance i);
public void set_media_player(MediaPlayer player);
public void set_media_list(MediaList list);
public void play();
public void pause();
public int is_playing();
public State get_state();
public int play_item_at_index(int index);
public int play_item(Media media);
public void stop();
public void next();
public void previous();
public void set_playback_mode(PlaybackMode mode);
}
[CCode(cname = "int")]
public enum PlaybackMode
{
Default,
Loop,
Repeat
}
[CCode(cname = "uint")]
public enum NavigateMode
{
Activate,
Up,
Down,
Left,
Right
}
public delegate void VideoLockFunc(void *opaque, void **planes);
public delegate void VideoUnlockFunc(void *opaque, void *picture, void **planes);
public delegate void VideoDisplayFunc(void *opaque, void *picture);
public delegate uint VideoFormatFunc(void **opaque, string chroma,
uint *width, uint *height,
uint *pitches,
uint *lines);
public delegate void VideoCleanupFunc(void *opaque);
public delegate void AudioPlayFunc(void *data, void *samples, uint count, long pts);
public delegate void AudioPauseFunc(void *data, long pts);
public struct MediaStats
{
public int i_read_bytes;
public float f_input_bitrate;
public int i_demux_read_bytes;
public float f_demux_bitrate;
public int i_demux_corrupted;
public int i_demux_discontinuity;
public int i_decoded_video;
public int i_decoded_audio;
public int i_displayed_pictures;
public int i_lost_pictures;
public int i_played_abuffers;
public int i_lost_abuffers;
public int i_sent_packets;
public int i_sent_bytes;
public float f_send_bitrate;
}
}
et voici un programme basique, qui montre comment intégrer une vidéo à un widget Gtk :
using Vlc;
using Gtk;
public class MainClass
{
public static void main(string[] args)
{
Gtk.init(ref args);
MainWindow win = new MainWindow();
win.show_all();
Gtk.main();
}
public class MainWindow
{
Builder builder;
Window window;
Button button1;
Button button2;
EventBox eventbox1;
Instance app;
MediaPlayer mp;
public MainWindow(){
app = new Instance(0,null);
mp = new MediaPlayer(app);
Media m = new Media.path(app,"/media/yannick/19BC29823F5213E8/Videos/Buffy.Contre.les.Vampires.S03E21.FRENCH.DVDRip.XviD-G2K.avi");
mp.media = m;
builder = new Builder();
builder.add_from_file("win.ui");
window = (Window)builder.get_object("window");
button1 = (Button)builder.get_object("button1");
button1.clicked.connect(on_button1_clicked);
button2 = (Button)builder.get_object("button2");
button2.clicked.connect(on_button2_clicked);
eventbox1 = (EventBox)builder.get_object("eventbox1");
}
public void show_all(){
window.show_all();
}
void on_button1_clicked(){
mp.snapshot(0,"/home/yannick/Documents/vala/snap.png",0,0);
}
void on_button2_clicked(){
mp.xwindow = (uint)Gdk.X11Window.get_xid(window.get_window());
mp.play();
}
}
}
using Gtk;
public class MainClass
{
public static void main(string[] args)
{
Gtk.init(ref args);
MainWindow win = new MainWindow();
win.show_all();
Gtk.main();
}
public class MainWindow
{
Builder builder;
Window window;
Button button1;
Button button2;
EventBox eventbox1;
Instance app;
MediaPlayer mp;
public MainWindow(){
app = new Instance(0,null);
mp = new MediaPlayer(app);
Media m = new Media.path(app,"/media/yannick/19BC29823F5213E8/Videos/Buffy.Contre.les.Vampires.S03E21.FRENCH.DVDRip.XviD-G2K.avi");
mp.media = m;
builder = new Builder();
builder.add_from_file("win.ui");
window = (Window)builder.get_object("window");
button1 = (Button)builder.get_object("button1");
button1.clicked.connect(on_button1_clicked);
button2 = (Button)builder.get_object("button2");
button2.clicked.connect(on_button2_clicked);
eventbox1 = (EventBox)builder.get_object("eventbox1");
}
public void show_all(){
window.show_all();
}
void on_button1_clicked(){
mp.snapshot(0,"/home/yannick/Documents/vala/snap.png",0,0);
}
void on_button2_clicked(){
mp.xwindow = (uint)Gdk.X11Window.get_xid(window.get_window());
mp.play();
}
}
}