Rewrite enums to use libvlc-sys symbols

2-bindgen
T. Okubo 2019-11-23 20:14:44 +09:00
parent 28fafc02f5
commit c52205075c
2 changed files with 160 additions and 148 deletions

View File

@ -154,7 +154,7 @@ unsafe extern "C" fn logging_cb(
vsnprintf(buf.as_mut_ptr(), BUF_SIZE, fmt, args); vsnprintf(buf.as_mut_ptr(), BUF_SIZE, fmt, args);
f(::std::mem::transmute(level), Log{ptr: ctx}, from_cstr_ref(buf.as_ptr()).unwrap()); f((level as u32).into(), Log{ptr: ctx}, from_cstr_ref(buf.as_ptr()).unwrap());
} }
/// List of module description. /// List of module description.
@ -349,7 +349,7 @@ unsafe extern "C" fn event_manager_callback(pe: *const sys::libvlc_event_t, data
// Convert c-style libvlc_event_t to Event // Convert c-style libvlc_event_t to Event
fn conv_event(pe: *const sys::libvlc_event_t) -> Event { fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
let event_type: EventType = unsafe{ ::std::mem::transmute((*pe)._type) }; let event_type: EventType = (unsafe{ (*pe)._type } as u32).into();
match event_type { match event_type {
EventType::MediaMetaChanged => { EventType::MediaMetaChanged => {

View File

@ -2,158 +2,170 @@
// This file is part of vlc-rs. // This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file. // Licensed under the MIT license, see the LICENSE file.
#[repr(C)] use libvlc_sys as sys;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum LogLevel { macro_rules! define_enum {
Debug = 0, ($enum_name:ident, $original_type:ident; $($value:ident = $c_value:ident,)*) => {
Notice = 2, #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
Warning = 3, #[repr(C)]
Error = 4, pub enum $enum_name {
$(
$value = sys::$c_value as isize,
)*
}
impl From<sys::$original_type> for $enum_name {
fn from(a: sys::$original_type) -> Self {
match a {
$(
sys::$c_value => Self::$value,
)*
_ => unreachable!(),
}
}
}
}
} }
#[repr(C)] define_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] LogLevel, libvlc_log_level;
pub enum Meta { Debug = libvlc_log_level_LIBVLC_DEBUG,
Title, Dotice = libvlc_log_level_LIBVLC_NOTICE,
Artist, Warning = libvlc_log_level_LIBVLC_WARNING,
Genre, Error = libvlc_log_level_LIBVLC_ERROR,
Copyright, );
Album,
TrackNumber,
Description,
Rating,
Date,
Setting,
URL,
Language,
NowPlaying,
Publisher,
EncodedBy,
ArtworkURL,
TrackID,
TrackTotal,
Director,
Season,
Episode,
ShowName,
Actors
}
#[repr(C)] define_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] Meta, libvlc_meta_t;
pub enum State { Title = libvlc_meta_t_libvlc_meta_Title,
NothingSpecial = 0, Artist = libvlc_meta_t_libvlc_meta_Artist,
Opening, Genre = libvlc_meta_t_libvlc_meta_Genre,
Buffering, Copyright = libvlc_meta_t_libvlc_meta_Copyright,
Playing, Album = libvlc_meta_t_libvlc_meta_Album,
Paused, TrackNumber = libvlc_meta_t_libvlc_meta_TrackNumber,
Stopped, Description = libvlc_meta_t_libvlc_meta_Description,
Ended, Rating = libvlc_meta_t_libvlc_meta_Rating,
Error Date = libvlc_meta_t_libvlc_meta_Date,
} Setting = libvlc_meta_t_libvlc_meta_Setting,
URL = libvlc_meta_t_libvlc_meta_URL,
Language = libvlc_meta_t_libvlc_meta_Language,
NowPlaying = libvlc_meta_t_libvlc_meta_NowPlaying,
Publisher = libvlc_meta_t_libvlc_meta_Publisher,
EncodedBy = libvlc_meta_t_libvlc_meta_EncodedBy,
ArtworkURL = libvlc_meta_t_libvlc_meta_ArtworkURL,
TrackID = libvlc_meta_t_libvlc_meta_TrackID,
TrackTotal = libvlc_meta_t_libvlc_meta_TrackTotal,
Director = libvlc_meta_t_libvlc_meta_Director,
Season = libvlc_meta_t_libvlc_meta_Season,
Episode = libvlc_meta_t_libvlc_meta_Episode,
ShowName = libvlc_meta_t_libvlc_meta_ShowName,
Actors = libvlc_meta_t_libvlc_meta_Actors,
);
#[repr(C)] define_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] State, libvlc_state_t;
pub enum TrackType { NothingSpecial = libvlc_state_t_libvlc_NothingSpecial,
Unknown = -1, Opening = libvlc_state_t_libvlc_Opening,
Audio = 0, Buffering = libvlc_state_t_libvlc_Buffering,
Video = 1, Playing = libvlc_state_t_libvlc_Playing,
Text = 2 Paused = libvlc_state_t_libvlc_Paused,
} Stopped = libvlc_state_t_libvlc_Stopped,
Ended = libvlc_state_t_libvlc_Ended,
Error = libvlc_state_t_libvlc_Error,
);
#[repr(C)] define_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] TrackType, libvlc_track_type_t;
pub enum Position { Unknown = libvlc_track_type_t_libvlc_track_unknown,
Disable = -1, Audio = libvlc_track_type_t_libvlc_track_audio,
Center, Video = libvlc_track_type_t_libvlc_track_video,
Left, Text = libvlc_track_type_t_libvlc_track_text,
Right, );
Top,
TopLeft,
TopRight,
Bottom,
BottomLeft,
BottomRight,
}
#[repr(C)] define_enum!(
#[derive(Clone, Copy, Debug)] Position, libvlc_position_t;
pub enum VideoAdjustOption { Disable = libvlc_position_t_libvlc_position_disable,
Enable = 0, Center = libvlc_position_t_libvlc_position_center,
Contrast, Left = libvlc_position_t_libvlc_position_left,
Brightness, Right = libvlc_position_t_libvlc_position_right,
Hue, Top = libvlc_position_t_libvlc_position_top,
Saturation, TopLeft = libvlc_position_t_libvlc_position_top_left,
Gamma TopRight = libvlc_position_t_libvlc_position_top_right,
} Bottom = libvlc_position_t_libvlc_position_bottom,
BottomLeft = libvlc_position_t_libvlc_position_bottom_left,
BottomRight = libvlc_position_t_libvlc_position_bottom_right,
);
// #[repr(C)] define_enum!(
// #[derive(Clone, Copy, PartialEq, Eq, Debug)] VideoAdjustOption, libvlc_video_adjust_option_t;
// pub enum ParseFlag { Enable = libvlc_video_adjust_option_t_libvlc_adjust_Enable,
// ParseLocal, Contrast = libvlc_video_adjust_option_t_libvlc_adjust_Contrast,
// ParseNetwork, Brightness = libvlc_video_adjust_option_t_libvlc_adjust_Brightness,
// FetchLocal, Hue = libvlc_video_adjust_option_t_libvlc_adjust_Hue,
// FetchNetwork, Saturation = libvlc_video_adjust_option_t_libvlc_adjust_Saturation,
// } Gamma = libvlc_video_adjust_option_t_libvlc_adjust_Gamma,
);
#[repr(C)] define_enum!(
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] ParseFlag, libvlc_media_parse_flag_t;
pub enum EventType { DoInteract = libvlc_media_parse_flag_t_libvlc_media_do_interact,
MediaMetaChanged = 0, FetchLocal = libvlc_media_parse_flag_t_libvlc_media_fetch_local,
MediaSubItemAdded, FetchNetwork = libvlc_media_parse_flag_t_libvlc_media_fetch_network,
MediaDurationChanged, ParseLocal = libvlc_media_parse_flag_t_libvlc_media_parse_local,
MediaParsedChanged, ParseNetwork = libvlc_media_parse_flag_t_libvlc_media_parse_network,
MediaFreed, );
MediaStateChanged,
MediaSubItemTreeAdded,
MediaPlayerMediaChanged = 0x100, define_enum!(
MediaPlayerNothingSpecial, EventType, libvlc_event_e;
MediaPlayerOpening, MediaMetaChanged = libvlc_event_e_libvlc_MediaMetaChanged,
MediaPlayerBuffering, MediaSubItemAdded = libvlc_event_e_libvlc_MediaSubItemAdded,
MediaPlayerPlaying, MediaDurationChanged = libvlc_event_e_libvlc_MediaDurationChanged,
MediaPlayerPaused, MediaParsedChanged = libvlc_event_e_libvlc_MediaParsedChanged,
MediaPlayerStopped, MediaFreed = libvlc_event_e_libvlc_MediaFreed,
MediaPlayerForward, MediaStateChanged = libvlc_event_e_libvlc_MediaStateChanged,
MediaPlayerBackward, MediaSubItemTreeAdded = libvlc_event_e_libvlc_MediaSubItemTreeAdded,
MediaPlayerEndReached, MediaPlayerMediaChanged = libvlc_event_e_libvlc_MediaPlayerMediaChanged,
MediaPlayerEncounteredError, MediaPlayerNothingSpecial = libvlc_event_e_libvlc_MediaPlayerNothingSpecial,
MediaPlayerTimeChanged, MediaPlayerOpening = libvlc_event_e_libvlc_MediaPlayerOpening,
MediaPlayerPositionChanged, MediaPlayerBuffering = libvlc_event_e_libvlc_MediaPlayerBuffering,
MediaPlayerSeekableChanged, MediaPlayerPlaying = libvlc_event_e_libvlc_MediaPlayerPlaying,
MediaPlayerPausableChanged, MediaPlayerPaused = libvlc_event_e_libvlc_MediaPlayerPaused,
MediaPlayerTitleChanged, MediaPlayerStopped = libvlc_event_e_libvlc_MediaPlayerStopped,
MediaPlayerSnapshotTaken, MediaPlayerForward = libvlc_event_e_libvlc_MediaPlayerForward,
MediaPlayerLengthChanged, MediaPlayerBackward = libvlc_event_e_libvlc_MediaPlayerBackward,
MediaPlayerVout, MediaPlayerEndReached = libvlc_event_e_libvlc_MediaPlayerEndReached,
MediaPlayerScrambledChanged, MediaPlayerEncounteredError = libvlc_event_e_libvlc_MediaPlayerEncounteredError,
MediaPlayerTimeChanged = libvlc_event_e_libvlc_MediaPlayerTimeChanged,
MediaListItemAdded = 0x200, MediaPlayerPositionChanged = libvlc_event_e_libvlc_MediaPlayerPositionChanged,
MediaListWillAddItem, MediaPlayerSeekableChanged = libvlc_event_e_libvlc_MediaPlayerSeekableChanged,
MediaListItemDeleted, MediaPlayerPausableChanged = libvlc_event_e_libvlc_MediaPlayerPausableChanged,
MediaListWillDeleteItem, MediaPlayerTitleChanged = libvlc_event_e_libvlc_MediaPlayerTitleChanged,
MediaPlayerSnapshotTaken = libvlc_event_e_libvlc_MediaPlayerSnapshotTaken,
MediaListViewItemAdded = 0x300, MediaPlayerLengthChanged = libvlc_event_e_libvlc_MediaPlayerLengthChanged,
MediaListViewWillAddItem, MediaPlayerVout = libvlc_event_e_libvlc_MediaPlayerVout,
MediaListViewItemDeleted, MediaPlayerScrambledChanged = libvlc_event_e_libvlc_MediaPlayerScrambledChanged,
MediaListViewWillDeleteItem, MediaListItemAdded = libvlc_event_e_libvlc_MediaListItemAdded,
MediaListWillAddItem = libvlc_event_e_libvlc_MediaListWillAddItem,
MediaListPlayerPlayed = 0x400, MediaListItemDeleted = libvlc_event_e_libvlc_MediaListItemDeleted,
MediaListPlayerNextItemSet, MediaListWillDeleteItem = libvlc_event_e_libvlc_MediaListWillDeleteItem,
MediaListPlayerStopped, MediaListViewItemAdded = libvlc_event_e_libvlc_MediaListViewItemAdded,
MediaListViewWillAddItem = libvlc_event_e_libvlc_MediaListViewWillAddItem,
MediaDiscovererStarted = 0x500, MediaListViewItemDeleted = libvlc_event_e_libvlc_MediaListViewItemDeleted,
MediaDiscovererEnded, MediaListViewWillDeleteItem = libvlc_event_e_libvlc_MediaListViewWillDeleteItem,
MediaListPlayerPlayed = libvlc_event_e_libvlc_MediaListPlayerPlayed,
VlmMediaAdded = 0x600, MediaListPlayerNextItemSet = libvlc_event_e_libvlc_MediaListPlayerNextItemSet,
VlmMediaRemoved, MediaListPlayerStopped = libvlc_event_e_libvlc_MediaListPlayerStopped,
VlmMediaChanged, MediaDiscovererStarted = libvlc_event_e_libvlc_MediaDiscovererStarted,
VlmMediaInstanceStarted, MediaDiscovererEnded = libvlc_event_e_libvlc_MediaDiscovererEnded,
VlmMediaInstanceStopped, VlmMediaAdded = libvlc_event_e_libvlc_VlmMediaAdded,
VlmMediaInstanceStatusInit, VlmMediaRemoved = libvlc_event_e_libvlc_VlmMediaRemoved,
VlmMediaInstanceStatusOpening, VlmMediaChanged = libvlc_event_e_libvlc_VlmMediaChanged,
VlmMediaInstanceStatusPlaying, VlmMediaInstanceStarted = libvlc_event_e_libvlc_VlmMediaInstanceStarted,
VlmMediaInstanceStatusPause, VlmMediaInstanceStopped = libvlc_event_e_libvlc_VlmMediaInstanceStopped,
VlmMediaInstanceStatusEnd, VlmMediaInstanceStatusInit = libvlc_event_e_libvlc_VlmMediaInstanceStatusInit,
VlmMediaInstanceStatusError VlmMediaInstanceStatusOpening = libvlc_event_e_libvlc_VlmMediaInstanceStatusOpening,
} VlmMediaInstanceStatusPlaying = libvlc_event_e_libvlc_VlmMediaInstanceStatusPlaying,
VlmMediaInstanceStatusPause = libvlc_event_e_libvlc_VlmMediaInstanceStatusPause,
VlmMediaInstanceStatusEnd = libvlc_event_e_libvlc_VlmMediaInstanceStatusEnd,
VlmMediaInstanceStatusError = libvlc_event_e_libvlc_VlmMediaInstanceStatusError,
);