1#![allow(non_upper_case_globals)]
2
3use std::ffi::{c_char, c_double, c_int, c_longlong, c_ulonglong, c_void};
4
5use libloading::{Library, Symbol};
6use once_cell::sync::Lazy;
7
8type LazySymbol<T> = Lazy<Symbol<'static, T>>;
9
10pub static MPV_LIB: Lazy<Library> = Lazy::new(|| unsafe { Library::new("mpv.exe").unwrap() });
11
12pub static mpv_error_string: LazySymbol<unsafe extern "C" fn(mpv_error) -> *const c_char> =
13 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_error_string").unwrap() });
14
15pub static mpv_free: LazySymbol<unsafe extern "C" fn(*mut c_void) -> ()> =
16 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_free").unwrap() });
17
18pub static mpv_client_name: LazySymbol<unsafe extern "C" fn(*mut mpv_handle) -> *const c_char> =
19 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_client_name").unwrap() });
20
21pub static mpv_client_id: LazySymbol<unsafe extern "C" fn(*mut mpv_handle) -> c_longlong> =
22 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_client_id").unwrap() });
23
24pub static mpv_create: LazySymbol<unsafe extern "C" fn() -> *mut mpv_handle> =
25 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_create").unwrap() });
26
27pub static mpv_initialize: LazySymbol<unsafe extern "C" fn(*mut mpv_handle) -> mpv_error> =
28 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_initialize").unwrap() });
29
30pub static mpv_destroy: LazySymbol<unsafe extern "C" fn(*mut mpv_handle) -> ()> =
31 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_destroy").unwrap() });
32
33pub static mpv_create_client: LazySymbol<
34 unsafe extern "C" fn(*mut mpv_handle, *const c_char) -> *mut mpv_handle,
35> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_create_client").unwrap() });
36
37pub static mpv_create_weak_client: LazySymbol<
38 unsafe extern "C" fn(*mut mpv_handle, *const c_char) -> *mut mpv_handle,
39> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_create_weak_client").unwrap() });
40
41pub static mpv_command: LazySymbol<
42 unsafe extern "C" fn(*mut mpv_handle, *const *const c_char) -> mpv_error,
43> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_command").unwrap() });
44
45pub static mpv_command_async: LazySymbol<
46 unsafe extern "C" fn(*mut mpv_handle, c_ulonglong, *const *const c_char) -> mpv_error,
47> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_command_async").unwrap() });
48
49pub static mpv_set_property: LazySymbol<
50 unsafe extern "C" fn(*mut mpv_handle, *const c_char, c_int, *const c_void) -> mpv_error,
51> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_set_property").unwrap() });
52
53pub static mpv_get_property: LazySymbol<
54 unsafe extern "C" fn(*mut mpv_handle, *const c_char, c_int, *const c_void) -> mpv_error,
55> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_get_property").unwrap() });
56
57pub static mpv_observe_property: LazySymbol<
58 unsafe extern "C" fn(*mut mpv_handle, c_ulonglong, *const c_char, c_int) -> mpv_error,
59> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_observe_property").unwrap() });
60
61pub static mpv_unobserve_property: LazySymbol<
62 unsafe extern "C" fn(*mut mpv_handle, c_ulonglong) -> mpv_error,
63> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_unobserve_property").unwrap() });
64
65pub static mpv_event_name: LazySymbol<unsafe extern "C" fn(mpv_event_id) -> *const c_char> =
66 Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_event_name").unwrap() });
67
68pub static mpv_wait_event: LazySymbol<
69 unsafe extern "C" fn(*mut mpv_handle, c_double) -> *mut mpv_event,
70> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_wait_event").unwrap() });
71
72pub static mpv_hook_add: LazySymbol<
73 unsafe extern "C" fn(*mut mpv_handle, c_ulonglong, *const c_char, c_int) -> mpv_error,
74> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_hook_add").unwrap() });
75
76pub static mpv_hook_continue: LazySymbol<
77 unsafe extern "C" fn(*mut mpv_handle, c_ulonglong) -> mpv_error,
78> = Lazy::new(|| unsafe { MPV_LIB.get(b"mpv_hook_continue").unwrap() });
79
80#[repr(i32)]
81#[allow(dead_code)]
82#[allow(non_camel_case_types)]
83#[derive(Copy, Clone, PartialEq, Debug)]
84pub enum mpv_error {
85 SUCCESS = 0,
86 EVENT_QUEUE_FULL = -1,
87 NOMEM = -2,
88 UNINITIALIZED = -3,
89 INVALID_PARAMETER = -4,
90 OPTION_NOT_FOUND = -5,
91 OPTION_FORMAT = -6,
92 OPTION_ERROR = -7,
93 PROPERTY_NOT_FOUND = -8,
94 PROPERTY_FORMAT = -9,
95 PROPERTY_UNAVAILABLE = -10,
96 PROPERTY_ERROR = -11,
97 COMMAND = -12,
98 LOADING_FAILED = -13,
99 AO_INIT_FAILED = -14,
100 VO_INIT_FAILED = -15,
101 NOTHING_TO_PLAY = -16,
102 UNKNOWN_FORMAT = -17,
103 UNSUPPORTED = -18,
104 NOT_IMPLEMENTED = -19,
105 GENERIC = -20,
106}
107
108#[repr(i32)]
109#[allow(dead_code)]
110#[allow(non_camel_case_types)]
111#[derive(Copy, Clone, PartialEq)]
112pub enum mpv_event_id {
113 NONE = 0,
114 SHUTDOWN = 1,
115 LOG_MESSAGE = 2,
116 GET_PROPERTY_REPLY = 3,
117 SET_PROPERTY_REPLY = 4,
118 COMMAND_REPLY = 5,
119 START_FILE = 6,
120 END_FILE = 7,
121 FILE_LOADED = 8,
122 CLIENT_MESSAGE = 16,
123 VIDEO_RECONFIG = 17,
124 AUDIO_RECONFIG = 18,
125 SEEK = 20,
126 PLAYBACK_RESTART = 21,
127 PROPERTY_CHANGE = 22,
128 QUEUE_OVERFLOW = 24,
129 HOOK = 25,
130}
131
132#[repr(i32)]
133#[allow(dead_code)]
134#[allow(non_camel_case_types)]
135#[derive(Copy, Clone, PartialEq)]
136pub enum mpv_log_level {
137 MPV_LOG_LEVEL_NONE = 0,
138 MPV_LOG_LEVEL_FATAL = 10,
139 MPV_LOG_LEVEL_ERROR = 20,
140 MPV_LOG_LEVEL_WARN = 30,
141 MPV_LOG_LEVEL_INFO = 40,
142 MPV_LOG_LEVEL_V = 50,
143 MPV_LOG_LEVEL_DEBUG = 60,
144 MPV_LOG_LEVEL_TRACE = 70,
145}
146
147#[repr(i32)]
148#[allow(dead_code)]
149#[allow(non_camel_case_types)]
150#[derive(Copy, Clone, PartialEq)]
151pub enum mpv_end_file_reason {
152 MPV_END_FILE_REASON_EOF = 0,
153 MPV_END_FILE_REASON_STOP = 2,
154 MPV_END_FILE_REASON_QUIT = 3,
155 MPV_END_FILE_REASON_ERROR = 4,
156 MPV_END_FILE_REASON_REDIRECT = 5,
157}
158
159#[allow(non_camel_case_types)]
161pub type mpv_handle = c_void;
162
163#[repr(C)]
164#[allow(non_camel_case_types)]
165pub struct mpv_event_property {
166 pub name: *const c_char,
167 pub format: i32,
168 pub data: *mut c_void,
169}
170
171#[repr(C)]
172#[allow(non_camel_case_types)]
173pub struct mpv_event_log_message {
174 pub prefix: *const c_char,
175 pub level: *const c_char,
176 pub text: *const c_char,
177 pub log_level: mpv_log_level,
178}
179
180#[repr(C)]
181#[allow(non_camel_case_types)]
182pub struct mpv_event_start_file {
183 pub playlist_entry_id: c_ulonglong,
184}
185
186#[repr(C)]
187#[allow(non_camel_case_types)]
188pub struct mpv_event_end_file {
189 pub reason: mpv_end_file_reason,
190 pub error: c_int,
191 pub playlist_entry_id: c_ulonglong,
192 pub playlist_insert_id: c_ulonglong,
193 pub playlist_insert_num_entries: c_int,
194}
195
196#[repr(C)]
197#[allow(non_camel_case_types)]
198pub struct mpv_event_client_message {
199 pub num_args: c_int,
200 pub args: *const *const c_char,
201}
202
203#[repr(C)]
204#[allow(non_camel_case_types)]
205pub struct mpv_event_hook {
206 pub name: *const c_char,
207 pub id: c_ulonglong,
208}
209
210#[repr(C)]
211#[allow(non_camel_case_types)]
212pub struct mpv_event {
213 pub event_id: mpv_event_id,
214 pub error: mpv_error,
215 pub reply_userdata: c_ulonglong,
216 pub data: *mut c_void,
217}