· 9 years ago · Nov 24, 2016, 01:34 PM
1 #! /usr/bin/python 2 # -*- coding: utf-8 -*- 3 4 # Python ctypes bindings for VLC 5 # 6 # Copyright (C) 2009-2012 the VideoLAN team 7 # $Id: $ 8 # 9 # Authors: Olivier Aubert <contact at olivieraubert.net> 10 # Jean Brouwers <MrJean1 at gmail.com> 11 # Geoff Salmon <geoff.salmon at gmail.com> 12 # 13 # This library is free software; you can redistribute it and/or modify 14 # it under the terms of the GNU Lesser General Public License as 15 # published by the Free Software Foundation; either version 2.1 of the 16 # License, or (at your option) any later version. 17 # 18 # This library is distributed in the hope that it will be useful, but 19 # WITHOUT ANY WARRANTY; without even the implied warranty of 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 # Lesser General Public License for more details. 22 # 23 # You should have received a copy of the GNU Lesser General Public 24 # License along with this library; if not, write to the Free Software 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA 26 27 """This module provides bindings for the LibVLC public API, see 28 U{http://wiki.videolan.org/LibVLC}. 29 30 You can find the documentation and a README file with some examples 31 at U{http://www.advene.org/download/python-ctypes/}. 32 33 Basically, the most important class is L{Instance}, which is used 34 to create a libvlc instance. From this instance, you then create 35 L{MediaPlayer} and L{MediaListPlayer} instances. 36 37 Alternatively, you may create instances of the L{MediaPlayer} and 38 L{MediaListPlayer} class directly and an instance of L{Instance} 39 will be implicitly created. The latter can be obtained using the 40 C{get_instance} method of L{MediaPlayer} and L{MediaListPlayer}. 41 """ 42 43 import ctypes 44 from ctypes.util import find_library 45 import os 46 import sys 47 import functools 48 49 # Used by EventManager in override.py 50 from inspect import getargspec 51 52 __version__ = "2.2.4" 53 build_date = "Fri Oct 7 12:04:48 2016 - 2.2.4" 54 55 # The libvlc doc states that filenames are expected to be in UTF8, do 56 # not rely on sys.getfilesystemencoding() which will be confused, 57 # esp. on windows. 58 DEFAULT_ENCODING = 'utf-8' 59 60 if sys.version_info[0] > 2: 61 str = str 62 unicode = str 63 bytes = bytes 64 basestring = (str, bytes) 65 PYTHON3 = True 66 def str_to_bytes(s): 67 """Translate string or bytes to bytes. 68 """ 69 if isinstance(s, str): 70 return bytes(s, DEFAULT_ENCODING) 71 else: 72 return s 73 74 def bytes_to_str(b): 75 """Translate bytes to string. 76 """ 77 if isinstance(b, bytes): 78 return b.decode(DEFAULT_ENCODING) 79 else: 80 return b 81 else: 82 str = str 83 unicode = unicode 84 bytes = str 85 basestring = basestring 86 PYTHON3 = False 87 def str_to_bytes(s): 88 """Translate string or bytes to bytes. 89 """ 90 if isinstance(s, unicode): 91 return s.encode(DEFAULT_ENCODING) 92 else: 93 return s 94 95 def bytes_to_str(b): 96 """Translate bytes to unicode string. 97 """ 98 if isinstance(b, str): 99 return unicode(b, DEFAULT_ENCODING) 100 else: 101 return b 102 103 # Internal guard to prevent internal classes to be directly 104 # instanciated. 105 _internal_guard = object() 106 107 def find_lib(): 108 dll = None 109 plugin_path = None 110 if sys.platform.startswith('linux'): 111 p = find_library('vlc') 112 try: 113 dll = ctypes.CDLL(p) 114 except OSError: # may fail 115 dll = ctypes.CDLL('libvlc.so.5') 116 elif sys.platform.startswith('win'): 117 libname = 'libvlc.dll' 118 p = find_library(libname) 119 if p is None: 120 try: # some registry settings 121 # leaner than win32api, win32con 122 if PYTHON3: 123 import winreg as w 124 else: 125 import _winreg as w 126 for r in w.HKEY_LOCAL_MACHINE, w.HKEY_CURRENT_USER: 127 try: 128 r = w.OpenKey(r, 'Software\\VideoLAN\\VLC') 129 plugin_path, _ = w.QueryValueEx(r, 'InstallDir') 130 w.CloseKey(r) 131 break 132 except w.error: 133 pass 134 except ImportError: # no PyWin32 135 pass 136 if plugin_path is None: 137 # try some standard locations. 138 programfiles = os.environ["ProgramFiles"] 139 homedir = os.environ["HOMEDRIVE"] 140 for p in ('{programfiles}\\VideoLan{libname}', '{homedir}:\\VideoLan{libname}', 141 '{programfiles}{libname}', '{homedir}:{libname}'): 142 p = p.format(homedir = homedir, 143 programfiles = programfiles, 144 libname = '\\VLC\\' + libname) 145 if os.path.exists(p): 146 plugin_path = os.path.dirname(p) 147 break 148 if plugin_path is not None: # try loading 149 p = os.getcwd() 150 os.chdir(plugin_path) 151 # if chdir failed, this will raise an exception 152 dll = ctypes.CDLL(libname) 153 # restore cwd after dll has been loaded 154 os.chdir(p) 155 else: # may fail 156 dll = ctypes.CDLL(libname) 157 else: 158 plugin_path = os.path.dirname(p) 159 dll = ctypes.CDLL(p) 160 161 elif sys.platform.startswith('darwin'): 162 # FIXME: should find a means to configure path 163 d = '/Applications/VLC.app/Contents/MacOS/' 164 p = d + 'lib/libvlc.dylib' 165 if os.path.exists(p): 166 dll = ctypes.CDLL(p) 167 for p in ('modules', 'plugins'): 168 p = d + p 169 if os.path.isdir(p): 170 plugin_path = p 171 break 172 else: # hope, some PATH is set... 173 dll = ctypes.CDLL('libvlc.dylib') 174 175 else: 176 raise NotImplementedError('%s: %s not supported' % (sys.argv[0], sys.platform)) 177 178 return (dll, plugin_path) 179 180 # plugin_path used on win32 and MacOS in override.py 181 dll, plugin_path = find_lib() 182 183 class VLCException(Exception): 184 """Exception raised by libvlc methods. 185 """ 186 pass 187 188 try: 189 _Ints = (int, long) 190 except NameError: # no long in Python 3+ 191 _Ints = int 192 _Seqs = (list, tuple) 193 194 # Used for handling *event_manager() methods. 195 class memoize_parameterless(object): 196 """Decorator. Caches a parameterless method's return value each time it is called. 197 198 If called later with the same arguments, the cached value is returned 199 (not reevaluated). 200 Adapted from https://wiki.python.org/moin/PythonDecoratorLibrary 201 """ 202 def __init__(self, func): 203 self.func = func 204 self._cache = {} 205 206 def __call__(self, obj): 207 try: 208 return self._cache[obj] 209 except KeyError: 210 v = self._cache[obj] = self.func(obj) 211 return v 212 213 def __repr__(self): 214 """Return the function's docstring. 215 """ 216 return self.func.__doc__ 217 218 def __get__(self, obj, objtype): 219 """Support instance methods. 220 """ 221 return functools.partial(self.__call__, obj) 222 223 # Default instance. It is used to instanciate classes directly in the 224 # OO-wrapper. 225 _default_instance = None 226 227 def get_default_instance(): 228 """Return the default VLC.Instance. 229 """ 230 global _default_instance 231 if _default_instance is None: 232 _default_instance = Instance() 233 return _default_instance 234 235 _Cfunctions = {} # from LibVLC __version__ 236 _Globals = globals() # sys.modules[__name__].__dict__ 237 238 def _Cfunction(name, flags, errcheck, *types): 239 """(INTERNAL) New ctypes function binding. 240 """ 241 if hasattr(dll, name) and name in _Globals: 242 p = ctypes.CFUNCTYPE(*types) 243 f = p((name, dll), flags) 244 if errcheck is not None: 245 f.errcheck = errcheck 246 # replace the Python function 247 # in this module, but only when 248 # running as python -O or -OO 249 if __debug__: 250 _Cfunctions[name] = f 251 else: 252 _Globals[name] = f 253 return f 254 raise NameError('no function %r' % (name,)) 255 256 def _Cobject(cls, ctype): 257 """(INTERNAL) New instance from ctypes. 258 """ 259 o = object.__new__(cls) 260 o._as_parameter_ = ctype 261 return o 262 263 def _Constructor(cls, ptr=_internal_guard): 264 """(INTERNAL) New wrapper from ctypes. 265 """ 266 if ptr == _internal_guard: 267 raise VLCException("(INTERNAL) ctypes class. You should get references for this class through methods of the LibVLC API.") 268 if ptr is None or ptr == 0: 269 return None 270 return _Cobject(cls, ctypes.c_void_p(ptr)) 271 272 class _Cstruct(ctypes.Structure): 273 """(INTERNAL) Base class for ctypes structures. 274 """ 275 _fields_ = [] # list of 2-tuples ('name', ctyptes.<type>) 276 277 def __str__(self): 278 l = [' %s:\t%s' % (n, getattr(self, n)) for n, _ in self._fields_] 279 return '\n'.join([self.__class__.__name__] + l) 280 281 def __repr__(self): 282 return '%s.%s' % (self.__class__.__module__, self) 283 284 class _Ctype(object): 285 """(INTERNAL) Base class for ctypes. 286 """ 287 @staticmethod 288 def from_param(this): # not self 289 """(INTERNAL) ctypes parameter conversion method. 290 """ 291 if this is None: 292 return None 293 return this._as_parameter_ 294 295 class ListPOINTER(object): 296 """Just like a POINTER but accept a list of ctype as an argument. 297 """ 298 def __init__(self, etype): 299 self.etype = etype 300 301 def from_param(self, param): 302 if isinstance(param, _Seqs): 303 return (self.etype * len(param))(*param) 304 305 # errcheck functions for some native functions. 306 def string_result(result, func, arguments): 307 """Errcheck function. Returns a string and frees the original pointer. 308 309 It assumes the result is a char *. 310 """ 311 if result: 312 # make a python string copy 313 s = bytes_to_str(ctypes.string_at(result)) 314 # free original string ptr 315 libvlc_free(result) 316 return s 317 return None 318 319 def class_result(classname): 320 """Errcheck function. Returns a function that creates the specified class. 321 """ 322 def wrap_errcheck(result, func, arguments): 323 if result is None: 324 return None 325 return classname(result) 326 return wrap_errcheck 327 328 # Wrapper for the opaque struct libvlc_log_t 329 class Log(ctypes.Structure): 330 pass 331 Log_ptr = ctypes.POINTER(Log) 332 333 # FILE* ctypes wrapper, copied from 334 # http://svn.python.org/projects/ctypes/trunk/ctypeslib/ctypeslib/contrib/pythonhdr.py 335 class FILE(ctypes.Structure): 336 pass 337 FILE_ptr = ctypes.POINTER(FILE) 338 339 if PYTHON3: 340 PyFile_FromFd = ctypes.pythonapi.PyFile_FromFd 341 PyFile_FromFd.restype = ctypes.py_object 342 PyFile_FromFd.argtypes = [ctypes.c_int, 343 ctypes.c_char_p, 344 ctypes.c_char_p, 345 ctypes.c_int, 346 ctypes.c_char_p, 347 ctypes.c_char_p, 348 ctypes.c_char_p, 349 ctypes.c_int ] 350 351 PyFile_AsFd = ctypes.pythonapi.PyObject_AsFileDescriptor 352 PyFile_AsFd.restype = ctypes.c_int 353 PyFile_AsFd.argtypes = [ctypes.py_object] 354 else: 355 PyFile_FromFile = ctypes.pythonapi.PyFile_FromFile 356 PyFile_FromFile.restype = ctypes.py_object 357 PyFile_FromFile.argtypes = [FILE_ptr, 358 ctypes.c_char_p, 359 ctypes.c_char_p, 360 ctypes.CFUNCTYPE(ctypes.c_int, FILE_ptr)] 361 362 PyFile_AsFile = ctypes.pythonapi.PyFile_AsFile 363 PyFile_AsFile.restype = FILE_ptr 364 PyFile_AsFile.argtypes = [ctypes.py_object] 365 366 # Generated enum types # 367 368 class _Enum(ctypes.c_uint): 369 '''(INTERNAL) Base class 370 ''' 371 _enum_names_ = {} 372 373 def __str__(self): 374 n = self._enum_names_.get(self.value, '') or ('FIXME_(%r)' % (self.value,)) 375 return '.'.join((self.__class__.__name__, n)) 376 377 def __hash__(self): 378 return self.value 379 380 def __repr__(self): 381 return '.'.join((self.__class__.__module__, self.__str__())) 382 383 def __eq__(self, other): 384 return ( (isinstance(other, _Enum) and self.value == other.value) 385 or (isinstance(other, _Ints) and self.value == other) ) 386 387 def __ne__(self, other): 388 return not self.__eq__(other) 389 390 class LogLevel(_Enum): 391 '''Logging messages level. 392 \note future libvlc versions may define new levels. 393 ''' 394 _enum_names_ = { 395 0: 'DEBUG', 396 2: 'NOTICE', 397 3: 'WARNING', 398 4: 'ERROR', 399 } 400 LogLevel.DEBUG = LogLevel(0) 401 LogLevel.ERROR = LogLevel(4) 402 LogLevel.NOTICE = LogLevel(2) 403 LogLevel.WARNING = LogLevel(3) 404 405 class EventType(_Enum): 406 '''Event types. 407 ''' 408 _enum_names_ = { 409 0: 'MediaMetaChanged', 410 1: 'MediaSubItemAdded', 411 2: 'MediaDurationChanged', 412 3: 'MediaParsedChanged', 413 4: 'MediaFreed', 414 5: 'MediaStateChanged', 415 6: 'MediaSubItemTreeAdded', 416 0x100: 'MediaPlayerMediaChanged', 417 257: 'MediaPlayerNothingSpecial', 418 258: 'MediaPlayerOpening', 419 259: 'MediaPlayerBuffering', 420 260: 'MediaPlayerPlaying', 421 261: 'MediaPlayerPaused', 422 262: 'MediaPlayerStopped', 423 263: 'MediaPlayerForward', 424 264: 'MediaPlayerBackward', 425 265: 'MediaPlayerEndReached', 426 266: 'MediaPlayerEncounteredError', 427 267: 'MediaPlayerTimeChanged', 428 268: 'MediaPlayerPositionChanged', 429 269: 'MediaPlayerSeekableChanged', 430 270: 'MediaPlayerPausableChanged', 431 271: 'MediaPlayerTitleChanged', 432 272: 'MediaPlayerSnapshotTaken', 433 273: 'MediaPlayerLengthChanged', 434 274: 'MediaPlayerVout', 435 275: 'MediaPlayerScrambledChanged', 436 279: 'MediaPlayerCorked', 437 280: 'MediaPlayerUncorked', 438 281: 'MediaPlayerMuted', 439 282: 'MediaPlayerUnmuted', 440 283: 'MediaPlayerAudioVolume', 441 0x200: 'MediaListItemAdded', 442 513: 'MediaListWillAddItem', 443 514: 'MediaListItemDeleted', 444 515: 'MediaListWillDeleteItem', 445 0x300: 'MediaListViewItemAdded', 446 769: 'MediaListViewWillAddItem', 447 770: 'MediaListViewItemDeleted', 448 771: 'MediaListViewWillDeleteItem', 449 0x400: 'MediaListPlayerPlayed', 450 1025: 'MediaListPlayerNextItemSet', 451 1026: 'MediaListPlayerStopped', 452 0x500: 'MediaDiscovererStarted', 453 1281: 'MediaDiscovererEnded', 454 0x600: 'VlmMediaAdded', 455 1537: 'VlmMediaRemoved', 456 1538: 'VlmMediaChanged', 457 1539: 'VlmMediaInstanceStarted', 458 1540: 'VlmMediaInstanceStopped', 459 1541: 'VlmMediaInstanceStatusInit', 460 1542: 'VlmMediaInstanceStatusOpening', 461 1543: 'VlmMediaInstanceStatusPlaying', 462 1544: 'VlmMediaInstanceStatusPause', 463 1545: 'VlmMediaInstanceStatusEnd', 464 1546: 'VlmMediaInstanceStatusError', 465 } 466 EventType.MediaDiscovererEnded = EventType(1281) 467 EventType.MediaDiscovererStarted = EventType(0x500) 468 EventType.MediaDurationChanged = EventType(2) 469 EventType.MediaFreed = EventType(4) 470 EventType.MediaListItemAdded = EventType(0x200) 471 EventType.MediaListItemDeleted = EventType(514) 472 EventType.MediaListPlayerNextItemSet = EventType(1025) 473 EventType.MediaListPlayerPlayed = EventType(0x400) 474 EventType.MediaListPlayerStopped = EventType(1026) 475 EventType.MediaListViewItemAdded = EventType(0x300) 476 EventType.MediaListViewItemDeleted = EventType(770) 477 EventType.MediaListViewWillAddItem = EventType(769) 478 EventType.MediaListViewWillDeleteItem = EventType(771) 479 EventType.MediaListWillAddItem = EventType(513) 480 EventType.MediaListWillDeleteItem = EventType(515) 481 EventType.MediaMetaChanged = EventType(0) 482 EventType.MediaParsedChanged = EventType(3) 483 EventType.MediaPlayerAudioVolume = EventType(283) 484 EventType.MediaPlayerBackward = EventType(264) 485 EventType.MediaPlayerBuffering = EventType(259) 486 EventType.MediaPlayerCorked = EventType(279) 487 EventType.MediaPlayerEncounteredError = EventType(266) 488 EventType.MediaPlayerEndReached = EventType(265) 489 EventType.MediaPlayerForward = EventType(263) 490 EventType.MediaPlayerLengthChanged = EventType(273) 491 EventType.MediaPlayerMediaChanged = EventType(0x100) 492 EventType.MediaPlayerMuted = EventType(281) 493 EventType.MediaPlayerNothingSpecial = EventType(257) 494 EventType.MediaPlayerOpening = EventType(258) 495 EventType.MediaPlayerPausableChanged = EventType(270) 496 EventType.MediaPlayerPaused = EventType(261) 497 EventType.MediaPlayerPlaying = EventType(260) 498 EventType.MediaPlayerPositionChanged = EventType(268) 499 EventType.MediaPlayerScrambledChanged = EventType(275) 500 EventType.MediaPlayerSeekableChanged = EventType(269) 501 EventType.MediaPlayerSnapshotTaken = EventType(272) 502 EventType.MediaPlayerStopped = EventType(262) 503 EventType.MediaPlayerTimeChanged = EventType(267) 504 EventType.MediaPlayerTitleChanged = EventType(271) 505 EventType.MediaPlayerUncorked = EventType(280) 506 EventType.MediaPlayerUnmuted = EventType(282) 507 EventType.MediaPlayerVout = EventType(274) 508 EventType.MediaStateChanged = EventType(5) 509 EventType.MediaSubItemAdded = EventType(1) 510 EventType.MediaSubItemTreeAdded = EventType(6) 511 EventType.VlmMediaAdded = EventType(0x600) 512 EventType.VlmMediaChanged = EventType(1538) 513 EventType.VlmMediaInstanceStarted = EventType(1539) 514 EventType.VlmMediaInstanceStatusEnd = EventType(1545) 515 EventType.VlmMediaInstanceStatusError = EventType(1546) 516 EventType.VlmMediaInstanceStatusInit = EventType(1541) 517 EventType.VlmMediaInstanceStatusOpening = EventType(1542) 518 EventType.VlmMediaInstanceStatusPause = EventType(1544) 519 EventType.VlmMediaInstanceStatusPlaying = EventType(1543) 520 EventType.VlmMediaInstanceStopped = EventType(1540) 521 EventType.VlmMediaRemoved = EventType(1537) 522 523 class Meta(_Enum): 524 '''Meta data types. 525 ''' 526 _enum_names_ = { 527 0: 'Title', 528 1: 'Artist', 529 2: 'Genre', 530 3: 'Copyright', 531 4: 'Album', 532 5: 'TrackNumber', 533 6: 'Description', 534 7: 'Rating', 535 8: 'Date', 536 9: 'Setting', 537 10: 'URL', 538 11: 'Language', 539 12: 'NowPlaying', 540 13: 'Publisher', 541 14: 'EncodedBy', 542 15: 'ArtworkURL', 543 16: 'TrackID', 544 17: 'TrackTotal', 545 18: 'Director', 546 19: 'Season', 547 20: 'Episode', 548 21: 'ShowName', 549 22: 'Actors', 550 } 551 Meta.Actors = Meta(22) 552 Meta.Album = Meta(4) 553 Meta.Artist = Meta(1) 554 Meta.ArtworkURL = Meta(15) 555 Meta.Copyright = Meta(3) 556 Meta.Date = Meta(8) 557 Meta.Description = Meta(6) 558 Meta.Director = Meta(18) 559 Meta.EncodedBy = Meta(14) 560 Meta.Episode = Meta(20) 561 Meta.Genre = Meta(2) 562 Meta.Language = Meta(11) 563 Meta.NowPlaying = Meta(12) 564 Meta.Publisher = Meta(13) 565 Meta.Rating = Meta(7) 566 Meta.Season = Meta(19) 567 Meta.Setting = Meta(9) 568 Meta.ShowName = Meta(21) 569 Meta.Title = Meta(0) 570 Meta.TrackID = Meta(16) 571 Meta.TrackNumber = Meta(5) 572 Meta.TrackTotal = Meta(17) 573 Meta.URL = Meta(10) 574 575 class State(_Enum): 576 '''Note the order of libvlc_state_t enum must match exactly the order of 577 See mediacontrol_playerstatus, See input_state_e enums, 578 and videolan.libvlc.state (at bindings/cil/src/media.cs). 579 expected states by web plugins are: 580 idle/close=0, opening=1, buffering=2, playing=3, paused=4, 581 stopping=5, ended=6, error=7. 582 ''' 583 _enum_names_ = { 584 0: 'NothingSpecial', 585 1: 'Opening', 586 2: 'Buffering', 587 3: 'Playing', 588 4: 'Paused', 589 5: 'Stopped', 590 6: 'Ended', 591 7: 'Error', 592 } 593 State.Buffering = State(2) 594 State.Ended = State(6) 595 State.Error = State(7) 596 State.NothingSpecial = State(0) 597 State.Opening = State(1) 598 State.Paused = State(4) 599 State.Playing = State(3) 600 State.Stopped = State(5) 601 602 class TrackType(_Enum): 603 '''N/A 604 ''' 605 _enum_names_ = { 606 -1: 'unknown', 607 0: 'audio', 608 1: 'video', 609 2: 'text', 610 } 611 TrackType.audio = TrackType(0) 612 TrackType.text = TrackType(2) 613 TrackType.unknown = TrackType(-1) 614 TrackType.video = TrackType(1) 615 616 class PlaybackMode(_Enum): 617 '''Defines playback modes for playlist. 618 ''' 619 _enum_names_ = { 620 0: 'default', 621 1: 'loop', 622 2: 'repeat', 623 } 624 PlaybackMode.default = PlaybackMode(0) 625 PlaybackMode.loop = PlaybackMode(1) 626 PlaybackMode.repeat = PlaybackMode(2) 627 628 class VideoMarqueeOption(_Enum): 629 '''Marq options definition. 630 ''' 631 _enum_names_ = { 632 0: 'Enable', 633 1: 'Text', 634 2: 'Color', 635 3: 'Opacity', 636 4: 'Position', 637 5: 'Refresh', 638 6: 'Size', 639 7: 'Timeout', 640 8: 'marquee_X', 641 9: 'marquee_Y', 642 } 643 VideoMarqueeOption.Color = VideoMarqueeOption(2) 644 VideoMarqueeOption.Enable = VideoMarqueeOption(0) 645 VideoMarqueeOption.Opacity = VideoMarqueeOption(3) 646 VideoMarqueeOption.Position = VideoMarqueeOption(4) 647 VideoMarqueeOption.Refresh = VideoMarqueeOption(5) 648 VideoMarqueeOption.Size = VideoMarqueeOption(6) 649 VideoMarqueeOption.Text = VideoMarqueeOption(1) 650 VideoMarqueeOption.Timeout = VideoMarqueeOption(7) 651 VideoMarqueeOption.marquee_X = VideoMarqueeOption(8) 652 VideoMarqueeOption.marquee_Y = VideoMarqueeOption(9) 653 654 class NavigateMode(_Enum): 655 '''Navigation mode. 656 ''' 657 _enum_names_ = { 658 0: 'activate', 659 1: 'up', 660 2: 'down', 661 3: 'left', 662 4: 'right', 663 } 664 NavigateMode.activate = NavigateMode(0) 665 NavigateMode.down = NavigateMode(2) 666 NavigateMode.left = NavigateMode(3) 667 NavigateMode.right = NavigateMode(4) 668 NavigateMode.up = NavigateMode(1) 669 670 class Position(_Enum): 671 '''Enumeration of values used to set position (e.g. of video title). 672 ''' 673 _enum_names_ = { 674 -1: 'disable', 675 0: 'center', 676 1: 'left', 677 2: 'right', 678 3: 'top', 679 4: 'left', 680 5: 'right', 681 6: 'bottom', 682 7: 'left', 683 8: 'right', 684 } 685 Position.bottom = Position(6) 686 Position.center = Position(0) 687 Position.disable = Position(-1) 688 Position.left = Position(1) 689 Position.left = Position(4) 690 Position.left = Position(7) 691 Position.right = Position(2) 692 Position.right = Position(5) 693 Position.right = Position(8) 694 Position.top = Position(3) 695 696 class VideoLogoOption(_Enum): 697 '''Option values for libvlc_video_{get,set}_logo_{int,string}. 698 ''' 699 _enum_names_ = { 700 0: 'enable', 701 1: 'file', 702 2: 'logo_x', 703 3: 'logo_y', 704 4: 'delay', 705 5: 'repeat', 706 6: 'opacity', 707 7: 'position', 708 } 709 VideoLogoOption.delay = VideoLogoOption(4) 710 VideoLogoOption.enable = VideoLogoOption(0) 711 VideoLogoOption.file = VideoLogoOption(1) 712 VideoLogoOption.logo_x = VideoLogoOption(2) 713 VideoLogoOption.logo_y = VideoLogoOption(3) 714 VideoLogoOption.opacity = VideoLogoOption(6) 715 VideoLogoOption.position = VideoLogoOption(7) 716 VideoLogoOption.repeat = VideoLogoOption(5) 717 718 class VideoAdjustOption(_Enum): 719 '''Option values for libvlc_video_{get,set}_adjust_{int,float,bool}. 720 ''' 721 _enum_names_ = { 722 0: 'Enable', 723 1: 'Contrast', 724 2: 'Brightness', 725 3: 'Hue', 726 4: 'Saturation', 727 5: 'Gamma', 728 } 729 VideoAdjustOption.Brightness = VideoAdjustOption(2) 730 VideoAdjustOption.Contrast = VideoAdjustOption(1) 731 VideoAdjustOption.Enable = VideoAdjustOption(0) 732 VideoAdjustOption.Gamma = VideoAdjustOption(5) 733 VideoAdjustOption.Hue = VideoAdjustOption(3) 734 VideoAdjustOption.Saturation = VideoAdjustOption(4) 735 736 class AudioOutputDeviceTypes(_Enum): 737 '''Audio device types. 738 ''' 739 _enum_names_ = { 740 -1: 'Error', 741 1: 'Mono', 742 2: 'Stereo', 743 4: '_2F2R', 744 5: '_3F2R', 745 6: '_5_1', 746 7: '_6_1', 747 8: '_7_1', 748 10: 'SPDIF', 749 } 750 AudioOutputDeviceTypes.Error = AudioOutputDeviceTypes(-1) 751 AudioOutputDeviceTypes.Mono = AudioOutputDeviceTypes(1) 752 AudioOutputDeviceTypes.SPDIF = AudioOutputDeviceTypes(10) 753 AudioOutputDeviceTypes.Stereo = AudioOutputDeviceTypes(2) 754 AudioOutputDeviceTypes._2F2R = AudioOutputDeviceTypes(4) 755 AudioOutputDeviceTypes._3F2R = AudioOutputDeviceTypes(5) 756 AudioOutputDeviceTypes._5_1 = AudioOutputDeviceTypes(6) 757 AudioOutputDeviceTypes._6_1 = AudioOutputDeviceTypes(7) 758 AudioOutputDeviceTypes._7_1 = AudioOutputDeviceTypes(8) 759 760 class AudioOutputChannel(_Enum): 761 '''Audio channels. 762 ''' 763 _enum_names_ = { 764 -1: 'Error', 765 1: 'Stereo', 766 2: 'RStereo', 767 3: 'Left', 768 4: 'Right', 769 5: 'Dolbys', 770 } 771 AudioOutputChannel.Dolbys = AudioOutputChannel(5) 772 AudioOutputChannel.Error = AudioOutputChannel(-1) 773 AudioOutputChannel.Left = AudioOutputChannel(3) 774 AudioOutputChannel.RStereo = AudioOutputChannel(2) 775 AudioOutputChannel.Right = AudioOutputChannel(4) 776 AudioOutputChannel.Stereo = AudioOutputChannel(1) 777 778 class Callback(ctypes.c_void_p): 779 """Callback function notification. 780 @param p_event: the event triggering the callback. 781 """ 782 pass 783 class LogCb(ctypes.c_void_p): 784 """Callback prototype for LibVLC log message handler. 785 @param data: data pointer as given to L{libvlc_log_set}(). 786 @param level: message level (@ref enum libvlc_log_level). 787 @param ctx: message context (meta-information about the message). 788 @param fmt: printf() format string (as defined by ISO C11). 789 @param args: variable argument list for the format @note Log message handlers B{must} be thread-safe. @warning The message context pointer, the format string parameters and the variable arguments are only valid until the callback returns. 790 """ 791 pass 792 class VideoLockCb(ctypes.c_void_p): 793 """Callback prototype to allocate and lock a picture buffer. 794 Whenever a new video frame needs to be decoded, the lock callback is 795 invoked. Depending on the video chroma, one or three pixel planes of 796 adequate dimensions must be returned via the second parameter. Those 797 planes must be aligned on 32-bytes boundaries. 798 @param opaque: private pointer as passed to L{libvlc_video_set_callbacks}() [IN]. 799 @param planes: start address of the pixel planes (LibVLC allocates the array of void pointers, this callback must initialize the array) [OUT]. 800 @return: a private pointer for the display and unlock callbacks to identify the picture buffers. 801 """ 802 pass 803 class VideoUnlockCb(ctypes.c_void_p): 804 """Callback prototype to unlock a picture buffer. 805 When the video frame decoding is complete, the unlock callback is invoked. 806 This callback might not be needed at all. It is only an indication that the 807 application can now read the pixel values if it needs to. 808 @warning: A picture buffer is unlocked after the picture is decoded, 809 but before the picture is displayed. 810 @param opaque: private pointer as passed to L{libvlc_video_set_callbacks}() [IN]. 811 @param picture: private pointer returned from the @ref libvlc_video_lock_cb callback [IN]. 812 @param planes: pixel planes as defined by the @ref libvlc_video_lock_cb callback (this parameter is only for convenience) [IN]. 813 """ 814 pass 815 class VideoDisplayCb(ctypes.c_void_p): 816 """Callback prototype to display a picture. 817 When the video frame needs to be shown, as determined by the media playback 818 clock, the display callback is invoked. 819 @param opaque: private pointer as passed to L{libvlc_video_set_callbacks}() [IN]. 820 @param picture: private pointer returned from the @ref libvlc_video_lock_cb callback [IN]. 821 """ 822 pass 823 class VideoFormatCb(ctypes.c_void_p): 824 """Callback prototype to configure picture buffers format. 825 This callback gets the format of the video as output by the video decoder 826 and the chain of video filters (if any). It can opt to change any parameter 827 as it needs. In that case, LibVLC will attempt to convert the video format 828 (rescaling and chroma conversion) but these operations can be CPU intensive. 829 @param opaque: pointer to the private pointer passed to L{libvlc_video_set_callbacks}() [IN/OUT]. 830 @param chroma: pointer to the 4 bytes video format identifier [IN/OUT]. 831 @param width: pointer to the pixel width [IN/OUT]. 832 @param height: pointer to the pixel height [IN/OUT]. 833 @param pitches: table of scanline pitches in bytes for each pixel plane (the table is allocated by LibVLC) [OUT]. 834 @return: lines table of scanlines count for each plane. 835 """ 836 pass 837 class VideoCleanupCb(ctypes.c_void_p): 838 """Callback prototype to configure picture buffers format. 839 @param opaque: private pointer as passed to L{libvlc_video_set_callbacks}() (and possibly modified by @ref libvlc_video_format_cb) [IN]. 840 """ 841 pass