files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  
  '''pyglet is a cross-platform games and multimedia package.
  
  Detailed documentation is available at http://www.pyglet.org
  '''
  from __future__ import print_function
  from __future__ import absolute_import
  
  # Check if future is installed, if not use included batteries
  try:
      import future
  except ImportError:
      import os.path as op
      import sys
      future_base = op.abspath(op.join(op.dirname(__file__), 'extlibs', 'future'))
      sys.path.insert(0, op.join(future_base, 'py2_3'))
      if sys.version_info[:2] < (3, 0):
          sys.path.insert(0, op.join(future_base, 'py2'))
      del future_base
      del sys
      del op
      try:
          import future
      except ImportError:
          print('Failed to get python-future')
          raise
  
  from builtins import range
  from builtins import object
  
  import os
  import sys
  import warnings
  
  _is_epydoc = hasattr(sys, 'is_epydoc') and sys.is_epydoc
  
  #: The release version of this pyglet installation.
  #:
  #: Valid only if pyglet was installed from a source or binary distribution
  #: (i.e. not in a checked-out copy from SVN).
  #:
  #: Use setuptools if you need to check for a specific release version, e.g.::
  #:
  #:    >>> import pyglet
  #:    >>> from pkg_resources import parse_version
  #:    >>> parse_version(pyglet.version) >= parse_version('1.1')
  #:    True
  #:
  version = '1.2.2'
  
  # Pyglet platform treats *BSD systems as Linux
  compat_platform = sys.platform
  if "bsd" in compat_platform:
      compat_platform = "linux-compat"
  
  def _require_ctypes_version(version):
      # Check ctypes version
      import ctypes
      req = [int(i) for i in version.split('.')]
      have = [int(i) for i in ctypes.__version__.split('.')]
      if not tuple(have) >= tuple(req):
          raise ImportError('pyglet requires ctypes %s or later.' % version)
  _require_ctypes_version('1.0.0')
  
  _enable_optimisations = not __debug__
  if getattr(sys, 'frozen', None):
      _enable_optimisations = True
  
  #: Global dict of pyglet options.  To change an option from its default, you
  #: must import ``pyglet`` before any sub-packages.  For example::
  #:
  #:      import pyglet
  #:      pyglet.options['debug_gl'] = False
  #:
  #: The default options can be overridden from the OS environment.  The
  #: corresponding environment variable for each option key is prefaced by
  #: ``PYGLET_``.  For example, in Bash you can set the ``debug_gl`` option with::
  #:
  #:      PYGLET_DEBUG_GL=True; export PYGLET_DEBUG_GL
  #:
  #: For options requiring a tuple of values, separate each value with a comma.
  #:
  #: The non-development options are:
  #:
  #: audio
  #:     A sequence of the names of audio modules to attempt to load, in
  #:     order of preference.  Valid driver names are:
  #:
  #:     * directsound, the Windows DirectSound audio module (Windows only)
  #:     * pulse, the PulseAudio module (Linux only)
  #:     * openal, the OpenAL audio module
  #:     * silent, no audio
  #: debug_lib
  #:     If True, prints the path of each dynamic library loaded.
  #: debug_gl
  #:     If True, all calls to OpenGL functions are checked afterwards for
  #:     errors using ``glGetError``.  This will severely impact performance,
  #:     but provides useful exceptions at the point of failure.  By default,
  #:     this option is enabled if ``__debug__`` is (i.e., if Python was not run
  #:     with the -O option).  It is disabled by default when pyglet is "frozen"
  #:     within a py2exe or py2app library archive.
  #: shadow_window
  #:     By default, pyglet creates a hidden window with a GL context when
  #:     pyglet.gl is imported.  This allows resources to be loaded before
  #:     the application window is created, and permits GL objects to be
  #:     shared between windows even after they've been closed.  You can
  #:     disable the creation of the shadow window by setting this option to
  #:     False.
  #:
  #:     Some OpenGL driver implementations may not support shared OpenGL
  #:     contexts and may require disabling the shadow window (and all resources
  #:     must be loaded after the window using them was created).  Recommended
  #:     for advanced developers only.
  #:
  #:     **Since:** pyglet 1.1
  #: vsync
  #:     If set, the `pyglet.window.Window.vsync` property is ignored, and
  #:     this option overrides it (to either force vsync on or off).  If unset,
  #:     or set to None, the `pyglet.window.Window.vsync` property behaves
  #:     as documented.
  #: xsync
  #:     If set (the default), pyglet will attempt to synchronise the drawing of
  #:     double-buffered windows to the border updates of the X11 window
  #:     manager.  This improves the appearance of the window during resize
  #:     operations.  This option only affects double-buffered windows on
  #:     X11 servers supporting the Xsync extension with a window manager
  #:     that implements the _NET_WM_SYNC_REQUEST protocol.
  #:
  #:     **Since:** pyglet 1.1
  #: darwin_cocoa
  #:     If True, the Cocoa-based pyglet implementation is used as opposed to
  #:     the 32-bit Carbon implementation.  When python is running in 64-bit mode
  #:     on Mac OS X 10.6 or later, this option is set to True by default.
  #:     Otherwise the Carbon implementation is preferred.
  #:
  #:     **Since:** pyglet 1.2
  #:
  #: search_local_libs
  #:     If False, pyglet won't try to search for libraries in the script
  #:     directory and its `lib` subdirectory. This is useful to load a local
  #:     library instead of the system installed version. This option is set
  #:     to True by default.
  #:
  #:     **Since:** pyglet 1.2
  #:
  #: ffmpeg_libs_win
  #:      A tuple containing the FFmpeg dll filenames for Windows. As on this
  #:      platform there is no standard way to find the dll files, and the
  #:      FFmpeg dll names have version number appended at the end, it's easier
  #:      for the developer to state what are the filenames, and hence giving
  #:      the version for each dll files. By default, the filenames are
  #:      'avcodec-57', 'avformat-57', 'avutil-55', 'swresample-2', 'swscale-4'
  #:
  #:     **Since:** pyglet 1.4
  #:
  options = {
      'audio': ('directsound', 'pulse', 'openal', 'silent'),
      'font': ('gdiplus', 'win32'), # ignored outside win32; win32 is deprecated
      'debug_font': False,
      'debug_gl': not _enable_optimisations,
      'debug_gl_trace': False,
      'debug_gl_trace_args': False,
      'debug_graphics_batch': False,
      'debug_lib': False,
      'debug_media': False,
      'debug_texture': False,
      'debug_trace': False,
      'debug_trace_args': False,
      'debug_trace_depth': 1,
      'debug_trace_flush': True,
      'debug_win32': False,
      'debug_x11': False,
      'ffmpeg_libs_win': ('avcodec-57', 'avformat-57', 'avutil-55', 
                          'swresample-2', 'swscale-4'),
      'graphics_vbo': True,
      'shadow_window': True,
      'vsync': None,
      'xsync': True,
      'xlib_fullscreen_override_redirect': False,
      'darwin_cocoa': False,
      'search_local_libs': True,
  }
  
  _option_types = {
      'audio': tuple,
      'font': tuple,
      'debug_font': bool,
      'debug_gl': bool,
      'debug_gl_trace': bool,
      'debug_gl_trace_args': bool,
      'debug_graphics_batch': bool,
      'debug_lib': bool,
      'debug_media': bool,
      'debug_texture': bool,
      'debug_trace': bool,
      'debug_trace_args': bool,
      'debug_trace_depth': int,
      'debug_trace_flush': bool,
      'debug_win32': bool,
      'debug_x11': bool,
      'ffmpeg_libs_win': tuple,
      'graphics_vbo': bool,
      'shadow_window': bool,
      'vsync': bool,
      'xsync': bool,
      'xlib_fullscreen_override_redirect': bool,
      'darwin_cocoa': bool,
  }
  
  def _choose_darwin_platform():
      """Choose between Darwin's Carbon and Cocoa implementations."""
      if compat_platform != 'darwin':
          return
      import struct
      numbits = 8*struct.calcsize("P")
      if numbits == 64:
          import platform
          osx_version = platform.mac_ver()[0].split(".")
          if int(osx_version[0]) == 10 and int(osx_version[1]) < 6:
              raise Exception('pyglet is not compatible with 64-bit Python for versions of Mac OS X prior to 10.6.')
          options['darwin_cocoa'] = True
      else:
          options['darwin_cocoa'] = False
  _choose_darwin_platform()  # can be overridden by an environment variable below
  
  def _read_environment():
      '''Read defaults for options from environment'''
      for key in options:
          env = 'PYGLET_%s' % key.upper()
          try:
              value = os.environ[env]
              if _option_types[key] is tuple:
                  options[key] = value.split(',')
              elif _option_types[key] is bool:
                  options[key] = value in ('true', 'TRUE', 'True', '1')
              elif _option_types[key] is int:
                  options[key] = int(value)
          except KeyError:
              pass
  _read_environment()
  
  if compat_platform == 'cygwin':
      # This hack pretends that the posix-like ctypes provides windows
      # functionality.  COM does not work with this hack, so there is no
      # DirectSound support.
      import ctypes
      ctypes.windll = ctypes.cdll
      ctypes.oledll = ctypes.cdll
      ctypes.WINFUNCTYPE = ctypes.CFUNCTYPE
      ctypes.HRESULT = ctypes.c_long
  
  if compat_platform == 'darwin' and not options['darwin_cocoa']:
      warnings.warn('Carbon support is to be deprecated in Pyglet 1.4', PendingDeprecationWarning)
  
  # Call tracing
  # ------------
  
  _trace_filename_abbreviations = {}
  
  def _trace_repr(value, size=40):
      value = repr(value)
      if len(value) > size:
          value = value[:size//2-2] + '...' + value[-size//2-1:]
      return value
  
  def _trace_frame(thread, frame, indent):
      from pyglet import lib
      if frame.f_code is lib._TraceFunction.__call__.__code__:
          is_ctypes = True
          func = frame.f_locals['self']._func
          name = func.__name__
          location = '[ctypes]'
      else:
          is_ctypes = False
          code = frame.f_code
          name = code.co_name
          path = code.co_filename
          line = code.co_firstlineno
  
          try:
              filename = _trace_filename_abbreviations[path]
          except KeyError:
              # Trim path down
              dir = ''
              path, filename = os.path.split(path)
              while len(dir + filename) < 30:
                  filename = os.path.join(dir, filename)
                  path, dir = os.path.split(path)
                  if not dir:
                      filename = os.path.join('', filename)
                      break
              else:
                  filename = os.path.join('...', filename)
              _trace_filename_abbreviations[path] = filename
  
          location = '(%s:%d)' % (filename, line)
  
      if indent:
          name = 'Called from %s' % name
      print('[%d] %s%s %s' % (thread, indent, name, location))
  
      if _trace_args:
          if is_ctypes:
              args = [_trace_repr(arg) for arg in frame.f_locals['args']]
              print('  %sargs=(%s)' % (indent, ', '.join(args)))
          else:
              for argname in code.co_varnames[:code.co_argcount]:
                  try:
                      argvalue = _trace_repr(frame.f_locals[argname])
                      print('  %s%s=%s' % (indent, argname, argvalue))
                  except:
                      pass
  
      if _trace_flush:
          sys.stdout.flush()
  
  def _thread_trace_func(thread):
      def _trace_func(frame, event, arg):
          if event == 'call':
              indent = ''
              for i in range(_trace_depth):
                  _trace_frame(thread, frame, indent)
                  indent += '  '
                  frame = frame.f_back
                  if not frame:
                      break
  
          elif event == 'exception':
              (exception, value, traceback) = arg
              print('First chance exception raised:', repr(exception))
      return _trace_func
  
  def _install_trace():
      global _trace_thread_count
      sys.setprofile(_thread_trace_func(_trace_thread_count))
      _trace_thread_count += 1
  
  _trace_thread_count = 0
  _trace_args = options['debug_trace_args']
  _trace_depth = options['debug_trace_depth']
  _trace_flush = options['debug_trace_flush']
  if options['debug_trace']:
      _install_trace()
  
  # Lazy loading
  # ------------
  
  class _ModuleProxy(object):
      _module = None
  
      def __init__(self, name):
          self.__dict__['_module_name'] = name
  
      def __getattr__(self, name):
          try:
              return getattr(self._module, name)
          except AttributeError:
              if self._module is not None:
                  raise
  
              import_name = 'pyglet.%s' % self._module_name
              __import__(import_name)
              module = sys.modules[import_name]
              object.__setattr__(self, '_module', module)
              globals()[self._module_name] = module
              return getattr(module, name)
  
      def __setattr__(self, name, value):
          try:
              setattr(self._module, name, value)
          except AttributeError:
              if self._module is not None:
                  raise
  
              import_name = 'pyglet.%s' % self._module_name
              __import__(import_name)
              module = sys.modules[import_name]
              object.__setattr__(self, '_module', module)
              globals()[self._module_name] = module
              setattr(module, name, value)
  
  if True:
      app = _ModuleProxy('app')
      canvas = _ModuleProxy('canvas')
      clock = _ModuleProxy('clock')
      com = _ModuleProxy('com')
      event = _ModuleProxy('event')
      font = _ModuleProxy('font')
      gl = _ModuleProxy('gl')
      graphics = _ModuleProxy('graphics')
      image = _ModuleProxy('image')
      input = _ModuleProxy('input')
      lib = _ModuleProxy('lib')
      media = _ModuleProxy('media')
      resource = _ModuleProxy('resource')
      sprite = _ModuleProxy('sprite')
      text = _ModuleProxy('text')
      window = _ModuleProxy('window')
  
  # Fool py2exe, py2app into including all top-level modules (doesn't understand
  # lazy loading)
  if False:
      from . import app
      from . import canvas
      from . import clock
      from . import com
      from . import event
      from . import font
      from . import gl
      from . import graphics
      from . import input
      from . import image
      from . import lib
      from . import media
      from . import resource
      from . import sprite
      from . import text
      from . import window
  
  # Hack around some epydoc bug that causes it to think pyglet.window is None.
  if False:
      from . import window
  
files: pyglet/__init__.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  #
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  
  '''pyglet is a cross-platform games and multimedia package.
  
  Detailed documentation is available at http://www.pyglet.org
  '''
  from __future__ import print_function
  from __future__ import absolute_import
  
  # Check if future is installed, if not use included batteries
  try:
      import future
  except ImportError:
      import os.path as op
      import sys
      future_base = op.abspath(op.join(op.dirname(__file__), 'extlibs', 'future'))
      sys.path.insert(0, op.join(future_base, 'py2_3'))
      if sys.version_info[:2] < (3, 0):
          sys.path.insert(0, op.join(future_base, 'py2'))
      del future_base
      del sys
      del op
      try:
          import future
      except ImportError:
          print('Failed to get python-future')
          raise
  
  from builtins import range
  from builtins import object
  
  import os
  import sys
  import warnings
  
  _is_epydoc = hasattr(sys, 'is_epydoc') and sys.is_epydoc
  
  #: The release version of this pyglet installation.
  #:
  #: Valid only if pyglet was installed from a source or binary distribution
  #: (i.e. not in a checked-out copy from SVN).
  #:
  #: Use setuptools if you need to check for a specific release version, e.g.::
  #:
  #:    >>> import pyglet
  #:    >>> from pkg_resources import parse_version
  #:    >>> parse_version(pyglet.version) >= parse_version('1.1')
  #:    True
  #:
  version = '1.2.2'
  
  # Pyglet platform treats *BSD systems as Linux
  compat_platform = sys.platform
  if "bsd" in compat_platform:
      compat_platform = "linux-compat"
  
  def _require_ctypes_version(version):
      # Check ctypes version
      import ctypes
      req = [int(i) for i in version.split('.')]
      have = [int(i) for i in ctypes.__version__.split('.')]
      if not tuple(have) >= tuple(req):
          raise ImportError('pyglet requires ctypes %s or later.' % version)
  _require_ctypes_version('1.0.0')
  
  _enable_optimisations = not __debug__
  if getattr(sys, 'frozen', None):
      _enable_optimisations = True
  
  #: Global dict of pyglet options.  To change an option from its default, you
  #: must import ``pyglet`` before any sub-packages.  For example::
  #:
  #:      import pyglet
  #:      pyglet.options['debug_gl'] = False
  #:
  #: The default options can be overridden from the OS environment.  The
  #: corresponding environment variable for each option key is prefaced by
  #: ``PYGLET_``.  For example, in Bash you can set the ``debug_gl`` option with::
  #:
  #:      PYGLET_DEBUG_GL=True; export PYGLET_DEBUG_GL
  #:
  #: For options requiring a tuple of values, separate each value with a comma.
  #:
  #: The non-development options are:
  #:
  #: audio
  #:     A sequence of the names of audio modules to attempt to load, in
  #:     order of preference.  Valid driver names are:
  #:
  #:     * directsound, the Windows DirectSound audio module (Windows only)
  #:     * pulse, the PulseAudio module (Linux only)
  #:     * openal, the OpenAL audio module
  #:     * silent, no audio
  #: debug_lib
  #:     If True, prints the path of each dynamic library loaded.
  #: debug_gl
  #:     If True, all calls to OpenGL functions are checked afterwards for
  #:     errors using ``glGetError``.  This will severely impact performance,
  #:     but provides useful exceptions at the point of failure.  By default,
  #:     this option is enabled if ``__debug__`` is (i.e., if Python was not run
  #:     with the -O option).  It is disabled by default when pyglet is "frozen"
  #:     within a py2exe or py2app library archive.
  #: shadow_window
  #:     By default, pyglet creates a hidden window with a GL context when
  #:     pyglet.gl is imported.  This allows resources to be loaded before
  #:     the application window is created, and permits GL objects to be
  #:     shared between windows even after they've been closed.  You can
  #:     disable the creation of the shadow window by setting this option to
  #:     False.
  #:
  #:     Some OpenGL driver implementations may not support shared OpenGL
  #:     contexts and may require disabling the shadow window (and all resources
  #:     must be loaded after the window using them was created).  Recommended
  #:     for advanced developers only.
  #:
  #:     **Since:** pyglet 1.1
  #: vsync
  #:     If set, the `pyglet.window.Window.vsync` property is ignored, and
  #:     this option overrides it (to either force vsync on or off).  If unset,
  #:     or set to None, the `pyglet.window.Window.vsync` property behaves
  #:     as documented.
  #: xsync
  #:     If set (the default), pyglet will attempt to synchronise the drawing of
  #:     double-buffered windows to the border updates of the X11 window
  #:     manager.  This improves the appearance of the window during resize
  #:     operations.  This option only affects double-buffered windows on
  #:     X11 servers supporting the Xsync extension with a window manager
  #:     that implements the _NET_WM_SYNC_REQUEST protocol.
  #:
  #:     **Since:** pyglet 1.1
  #: darwin_cocoa
  #:     If True, the Cocoa-based pyglet implementation is used as opposed to
  #:     the 32-bit Carbon implementation.  When python is running in 64-bit mode
  #:     on Mac OS X 10.6 or later, this option is set to True by default.
  #:     Otherwise the Carbon implementation is preferred.
  #:
  #:     **Since:** pyglet 1.2
  #:
  #: search_local_libs
  #:     If False, pyglet won't try to search for libraries in the script
  #:     directory and its `lib` subdirectory. This is useful to load a local
  #:     library instead of the system installed version. This option is set
  #:     to True by default.
  #:
  #:     **Since:** pyglet 1.2
  #:
  options = {
      'audio': ('directsound', 'pulse', 'openal', 'silent'),
      'font': ('gdiplus', 'win32'), # ignored outside win32; win32 is deprecated
      'debug_font': False,
      'debug_gl': not _enable_optimisations,
      'debug_gl_trace': False,
      'debug_gl_trace_args': False,
      'debug_graphics_batch': False,
      'debug_lib': False,
      'debug_media': False,
      'debug_texture': False,
      'debug_trace': False,
      'debug_trace_args': False,
      'debug_trace_depth': 1,
      'debug_trace_flush': True,
      'debug_win32': False,
      'debug_x11': False,
      'graphics_vbo': True,
      'shadow_window': True,
      'vsync': None,
      'xsync': True,
      'xlib_fullscreen_override_redirect': False,
      'darwin_cocoa': False,
      'search_local_libs': True,
  }
  
  _option_types = {
      'audio': tuple,
      'font': tuple,
      'debug_font': bool,
      'debug_gl': bool,
      'debug_gl_trace': bool,
      'debug_gl_trace_args': bool,
      'debug_graphics_batch': bool,
      'debug_lib': bool,
      'debug_media': bool,
      'debug_texture': bool,
      'debug_trace': bool,
      'debug_trace_args': bool,
      'debug_trace_depth': int,
      'debug_trace_flush': bool,
      'debug_win32': bool,
      'debug_x11': bool,
      'graphics_vbo': bool,
      'shadow_window': bool,
      'vsync': bool,
      'xsync': bool,
      'xlib_fullscreen_override_redirect': bool,
      'darwin_cocoa': bool,
  }
  
  def _choose_darwin_platform():
      """Choose between Darwin's Carbon and Cocoa implementations."""
      if compat_platform != 'darwin':
          return
      import struct
      numbits = 8*struct.calcsize("P")
      if numbits == 64:
          import platform
          osx_version = platform.mac_ver()[0].split(".")
          if int(osx_version[0]) == 10 and int(osx_version[1]) < 6:
              raise Exception('pyglet is not compatible with 64-bit Python for versions of Mac OS X prior to 10.6.')
          options['darwin_cocoa'] = True
      else:
          options['darwin_cocoa'] = False
  _choose_darwin_platform()  # can be overridden by an environment variable below
  
  def _read_environment():
      '''Read defaults for options from environment'''
      for key in options:
          env = 'PYGLET_%s' % key.upper()
          try:
              value = os.environ[env]
              if _option_types[key] is tuple:
                  options[key] = value.split(',')
              elif _option_types[key] is bool:
                  options[key] = value in ('true', 'TRUE', 'True', '1')
              elif _option_types[key] is int:
                  options[key] = int(value)
          except KeyError:
              pass
  _read_environment()
  
  if compat_platform == 'cygwin':
      # This hack pretends that the posix-like ctypes provides windows
      # functionality.  COM does not work with this hack, so there is no
      # DirectSound support.
      import ctypes
      ctypes.windll = ctypes.cdll
      ctypes.oledll = ctypes.cdll
      ctypes.WINFUNCTYPE = ctypes.CFUNCTYPE
      ctypes.HRESULT = ctypes.c_long
  
  if compat_platform == 'darwin' and not options['darwin_cocoa']:
      warnings.warn('Carbon support is to be deprecated in Pyglet 1.4', PendingDeprecationWarning)
  
  # Call tracing
  # ------------
  
  _trace_filename_abbreviations = {}
  
  def _trace_repr(value, size=40):
      value = repr(value)
      if len(value) > size:
          value = value[:size//2-2] + '...' + value[-size//2-1:]
      return value
  
  def _trace_frame(thread, frame, indent):
      from pyglet import lib
      if frame.f_code is lib._TraceFunction.__call__.__code__:
          is_ctypes = True
          func = frame.f_locals['self']._func
          name = func.__name__
          location = '[ctypes]'
      else:
          is_ctypes = False
          code = frame.f_code
          name = code.co_name
          path = code.co_filename
          line = code.co_firstlineno
  
          try:
              filename = _trace_filename_abbreviations[path]
          except KeyError:
              # Trim path down
              dir = ''
              path, filename = os.path.split(path)
              while len(dir + filename) < 30:
                  filename = os.path.join(dir, filename)
                  path, dir = os.path.split(path)
                  if not dir:
                      filename = os.path.join('', filename)
                      break
              else:
                  filename = os.path.join('...', filename)
              _trace_filename_abbreviations[path] = filename
  
          location = '(%s:%d)' % (filename, line)
  
      if indent:
          name = 'Called from %s' % name
      print('[%d] %s%s %s' % (thread, indent, name, location))
  
      if _trace_args:
          if is_ctypes:
              args = [_trace_repr(arg) for arg in frame.f_locals['args']]
              print('  %sargs=(%s)' % (indent, ', '.join(args)))
          else:
              for argname in code.co_varnames[:code.co_argcount]:
                  try:
                      argvalue = _trace_repr(frame.f_locals[argname])
                      print('  %s%s=%s' % (indent, argname, argvalue))
                  except:
                      pass
  
      if _trace_flush:
          sys.stdout.flush()
  
  def _thread_trace_func(thread):
      def _trace_func(frame, event, arg):
          if event == 'call':
              indent = ''
              for i in range(_trace_depth):
                  _trace_frame(thread, frame, indent)
                  indent += '  '
                  frame = frame.f_back
                  if not frame:
                      break
  
          elif event == 'exception':
              (exception, value, traceback) = arg
              print('First chance exception raised:', repr(exception))
      return _trace_func
  
  def _install_trace():
      global _trace_thread_count
      sys.setprofile(_thread_trace_func(_trace_thread_count))
      _trace_thread_count += 1
  
  _trace_thread_count = 0
  _trace_args = options['debug_trace_args']
  _trace_depth = options['debug_trace_depth']
  _trace_flush = options['debug_trace_flush']
  if options['debug_trace']:
      _install_trace()
  
  # Lazy loading
  # ------------
  
  class _ModuleProxy(object):
      _module = None
  
      def __init__(self, name):
          self.__dict__['_module_name'] = name
  
      def __getattr__(self, name):
          try:
              return getattr(self._module, name)
          except AttributeError:
              if self._module is not None:
                  raise
  
              import_name = 'pyglet.%s' % self._module_name
              __import__(import_name)
              module = sys.modules[import_name]
              object.__setattr__(self, '_module', module)
              globals()[self._module_name] = module
              return getattr(module, name)
  
      def __setattr__(self, name, value):
          try:
              setattr(self._module, name, value)
          except AttributeError:
              if self._module is not None:
                  raise
  
              import_name = 'pyglet.%s' % self._module_name
              __import__(import_name)
              module = sys.modules[import_name]
              object.__setattr__(self, '_module', module)
              globals()[self._module_name] = module
              setattr(module, name, value)
  
  if True:
      app = _ModuleProxy('app')
      canvas = _ModuleProxy('canvas')
      clock = _ModuleProxy('clock')
      com = _ModuleProxy('com')
      event = _ModuleProxy('event')
      font = _ModuleProxy('font')
      gl = _ModuleProxy('gl')
      graphics = _ModuleProxy('graphics')
      image = _ModuleProxy('image')
      input = _ModuleProxy('input')
      lib = _ModuleProxy('lib')
      media = _ModuleProxy('media')
      resource = _ModuleProxy('resource')
      sprite = _ModuleProxy('sprite')
      text = _ModuleProxy('text')
      window = _ModuleProxy('window')
  
  # Fool py2exe, py2app into including all top-level modules (doesn't understand
  # lazy loading)
  if False:
      from . import app
      from . import canvas
      from . import clock
      from . import com
      from . import event
      from . import font
      from . import gl
      from . import graphics
      from . import input
      from . import image
      from . import lib
      from . import media
      from . import resource
      from . import sprite
      from . import text
      from . import window
  
  # Hack around some epydoc bug that causes it to think pyglet.window is None.
  if False:
      from . import window
  
files: pyglet/__init__.py
files: """Sources for media playback."""
  
  # Collect public interface
  from .loader import load, have_ffmpeg
  from .base import AudioFormat, VideoFormat, AudioData, SourceInfo
  from .base import Source, StreamingSource, StaticSource, SourceGroup
files: pyglet/media/sources/__init__.py
files: """Sources for media playback."""
  
  # Collect public interface
  from .loader import load, have_ffmpeg
  from .base import AudioFormat, VideoFormat, AudioData, SourceInfo
  from .base import Source, StreamingSource, StaticSource, SourceGroup
  
  # from . import ffmpeg
  
files: pyglet/media/sources/__init__.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libavcodec/avcodec.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  
  import pyglet
  import pyglet.lib
  from . import libavutil
  
  if pyglet.compat_platform == 'win32':
      for libname in pyglet.options['ffmpeg_libs_win']:
          if libname.startswith('avcodec'):
              avcodec = pyglet.lib.load_library(libname)
              break
      else:
          # As a last resort, try to load the dll with default name.
          avcodec = pyglet.lib.load_library('avcodec')
  else:
      avcodec = pyglet.lib.load_library('avcodec')
  
  FF_INPUT_BUFFER_PADDING_SIZE = 32
  
  class AVPacketSideData(Structure): pass
  AVBufferRef = libavutil.AVBufferRef
  
  class AVPacket(Structure):
      _fields_ = [
          ('buf', POINTER(AVBufferRef)),
          ('pts', c_int64),
          ('dts', c_int64),
          ('data', POINTER(c_uint8)),
          ('size', c_int),
          ('stream_index', c_int),
          ('flags', c_int),
          ('side_data', POINTER(AVPacketSideData)),
          ('side_data_elems', c_int),
          ('duration', c_int64),
          ('pos', c_int64),
          ('convergence_duration', c_int64) #Deprecated
      ]
  class AVCodecParserContext(Structure): pass
  
  AVRational = libavutil.AVRational
  class AVCodecParameters(Structure):
      _fields_ = [
          ('codec_type', c_int),
          ('codec_id', c_int),
          ('codec_tag', c_uint32),
          ('extradata', POINTER(c_uint8)),
          ('extradata_size', c_int),
          ('format', c_int),
          ('bit_rate', c_int64),
          ('bits_per_coded_sample', c_int),
          ('bits_per_raw_sample', c_int),
          ('profile', c_int),
          ('level', c_int),
          ('width', c_int),
          ('height', c_int),
          ('sample_aspect_ratio', AVRational),
          ('field_order', c_int),
          ('color_range', c_int),
          ('color_primaries', c_int),
          ('color_trc', c_int),
          ('color_space', c_int),
          ('chroma_location', c_int),
          ('video_delay', c_int),
          ('channel_layout', c_uint64),
          ('channels', c_int),
          ('sample_rate', c_int),
          ('block_align', c_int),
          ('frame_size', c_int),
          ('initial_padding', c_int),
          ('trailing_padding', c_int),
          ('seek_preroll', c_int),
      ]
  class AVCodecInternal(Structure): pass
  class AVCodec(Structure):
      _fields_ = [
          ('name', c_char_p),
          ('long_name', c_char_p),
          # And more...
      ]
  class AVCodecContext(Structure): pass
  class RcOverride(Structure): pass
  class AVHWAccel(Structure): pass
  AVClass = libavutil.AVClass
  AVFrame = libavutil.AVFrame
  AV_NUM_DATA_POINTERS = libavutil.AV_NUM_DATA_POINTERS
  AVCodecContext._fields_ = [
          ('av_class', POINTER(AVClass)),
          ('log_level_offset', c_int),
          ('codec_type', c_int),
          ('codec', POINTER(AVCodec)),
          ('name', c_char * 32),
          ('codec_id', c_int),
          ('codec_tag', c_uint),
          ('stream_codec_tag', c_uint),
          ('priv_data', c_void_p),
          ('internal', POINTER(AVCodecInternal)),
          ('opaque', c_void_p),
          ('bit_rate', c_int64),
          ('bit_rate_tolerance', c_int),
          ('global_quality', c_int),
          ('compression_level', c_int),
          ('flags', c_int),
          ('flags2', c_int),
          ('extradata', POINTER(c_uint8)),
          ('extradata_size', c_int),
          ('time_base', AVRational),
          ('ticks_per_frame', c_int),
          ('delay', c_int),
          ('width', c_int),
          ('height', c_int),
          ('coded_width', c_int),
          ('coded_height', c_int),
          ('gop_size', c_int),
          ('pix_fmt', c_int),
          ('me_method', c_int),
          ('draw_horiz_band', CFUNCTYPE(None,
              POINTER(AVCodecContext), POINTER(AVFrame),
              c_int*8, c_int, c_int, c_int)),
          ('get_format', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), POINTER(c_int))),
          ('max_b_frames', c_int),
          ('b_quant_factor', c_float),
          ('rc_strategy', c_int),
          ('b_frame_strategy', c_int),
          ('b_quant_offset', c_float),
          ('has_b_frames', c_int),
          ('mpeg_quant', c_int),
          ('i_quant_factor', c_float),
          ('i_quant_offset', c_float),
          ('lumi_masking', c_float),
          ('temporal_cplx_masking', c_float),
          ('spatial_cplx_masking', c_float),
          ('p_masking', c_float),
          ('dark_masking', c_float),
          ('slice_count', c_int),
          ('prediction_method', c_int),
          ('slice_offset', POINTER(c_int)),
          ('sample_aspect_ratio', AVRational),
          ('me_cmp', c_int),
          ('me_sub_cmp', c_int),
          ('mb_cmp', c_int),
          ('ildct_cmp', c_int),
          ('dia_size', c_int),
          ('last_predictor_count', c_int),
          ('pre_me', c_int),
          ('me_pre_cmp', c_int),
          ('pre_dia_size', c_int),
          ('me_subpel_quality', c_int),
          ('dtg_active_format', c_int),
          ('me_range', c_int),
          ('intra_quant_bias', c_int),
          ('inter_quant_bias', c_int),
          ('slice_flags', c_int),
          ('xvmc_acceleration', c_int),
          ('mb_decision', c_int),
          ('intra_matrix', POINTER(c_uint16)),
          ('inter_matrix', POINTER(c_uint16)),
          ('scenechange_threshold', c_int),
          ('noise_reduction', c_int),
          ('me_threshold', c_int),
          ('mb_threshold', c_int),
          ('intra_dc_precision', c_int),
          ('skip_top', c_int),
          ('skip_bottom', c_int),
          ('border_masking', c_float),
          ('mb_lmin', c_int),
          ('mb_lmax', c_int),
          ('me_penalty_compensation', c_int),
          ('bidir_refine', c_int),
          ('brd_scale', c_int),
          ('keyint_min', c_int),
          ('refs', c_int),
          ('chromaoffset', c_int),
          ('scenechange_factor', c_int),
          ('mv0_threshold', c_int),
          ('b_sensitivity', c_int),
          ('color_primaries', c_int),
          ('color_trc', c_int),
          ('colorspace', c_int),
          ('color_range', c_int),
          ('chroma_sample_location', c_int),
          ('slices', c_int),
          ('field_order', c_int),
          ('sample_rate', c_int),
          ('channels', c_int),
          ('sample_fmt', c_int),
          ('frame_size', c_int),
          ('frame_number', c_int),
          ('block_align', c_int),
          ('cutoff', c_int),
          ('channel_layout', c_uint64),
          ('request_channel_layout', c_uint64),
          ('audio_service_type', c_int),
          ('request_sample_fmt', c_int),
          ('get_buffer2', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), POINTER(AVFrame), c_int)),
          ('refcounted_frames', c_int),
          ('qcompress', c_float),
          ('qblur', c_float),
          ('qmin', c_int),
          ('qmax', c_int),
          ('max_qdiff', c_int),
          ('rc_qsquish', c_float),
          ('rc_qmod_amp', c_float),
          ('rc_qmod_freq', c_int),
          ('rc_buffer_size', c_int),
          ('rc_override_count', c_int),
          ('rc_override', POINTER(RcOverride)),
          ('rc_eq', c_char_p),
          ('rc_max_rate', c_int64),
          ('rc_min_rate', c_int64),
          ('rc_buffer_aggressivity', c_float),
          ('rc_initial_cplx', c_float),
          ('rc_max_available_vbv_use', c_float),
          ('rc_min_vbv_overflow_use', c_float),
          ('rc_initial_buffer_occupancy', c_int),
          ('coder_type', c_int),
          ('context_model', c_int),
          ('lmin', c_int),
          ('lmax', c_int),
          ('frame_skip_threshold', c_int),
          ('frame_skip_factor', c_int),
          ('frame_skip_exp', c_int),
          ('frame_skip_cmp', c_int),
          ('trellis', c_int),
          ('min_prediction_order', c_int),
          ('max_prediction_order', c_int),
          ('timecode_frame_start', c_int64),
          ('rtp_callback', CFUNCTYPE(None,
              POINTER(AVCodecContext), c_void_p, c_int, c_int)),
          ('rtp_payload_size', c_int),
          ('mv_bits', c_int),
          ('header_bits', c_int),
          ('i_tex_bits', c_int),
          ('p_tex_bits', c_int),
          ('i_count', c_int),
          ('p_count', c_int),
          ('skip_count', c_int),
          ('misc_bits', c_int),
          ('frame_bits', c_int),
          ('stats_out', c_char_p),
          ('stats_in', c_char_p),
          ('workaround_bugs', c_int),
          ('strict_std_compliance', c_int),
          ('error_concealment', c_int),
          ('debug', c_int),
          ('debug_mv', c_int),
          ('err_recognition', c_int),
          ('reordered_opaque', c_int64),
          ('hwaccel', POINTER(AVHWAccel)),
          ('hwaccel_context', c_void_p),
          ('error', c_uint64 * AV_NUM_DATA_POINTERS),
          ('dct_algo', c_int),
          ('idct_algo', c_int),
          ('bits_per_coded_sample', c_int),
          ('bits_per_raw_sample', c_int),
          ('lowres', c_int),
          ('coded_frame', POINTER(AVFrame)),
          ('thread_count', c_int),
          ('thread_type', c_int),
          ('active_thread_type', c_int),
          ('thread_safe_callbacks', c_int),
          ('execute', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), 
              CFUNCTYPE(c_int, POINTER(AVCodecContext), c_void_p),
              c_void_p, c_int, c_int, c_int)),
          ('execute2', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), 
              CFUNCTYPE(c_int, POINTER(AVCodecContext), c_void_p, c_int, c_int),
              c_void_p, c_int, c_int)),
          ('nsse_weight', c_int),
          ('profile', c_int),
          ('level', c_int),
          ('skip_loop_filter', c_int),
          ('skip_idct', c_int),
          ('skip_frame', c_int),
          ('subtitle_header', POINTER(c_uint8)),
          ('subtitle_header_size', c_int),
          ('error_rate', c_int),
          ('vbv_delay', c_uint64),
          ('side_data_only_packets', c_int),
          ('initial_padding', c_int),
          ('framerate', AVRational),
      ]
  class AVPicture(Structure):
      _fields_ = [
          ('data', POINTER(c_uint8) * AV_NUM_DATA_POINTERS),
          ('linesize', c_int * AV_NUM_DATA_POINTERS)
      ]
  avcodec.av_packet_unref.argtypes = [POINTER(AVPacket)]
  avcodec.avcodec_find_decoder.restype = POINTER(AVCodec)
  avcodec.avcodec_find_decoder.argtypes = [c_int]
  AVDictionary = libavutil.AVDictionary
  avcodec.avcodec_open2.restype = c_int
  avcodec.avcodec_open2.argtypes = [POINTER(AVCodecContext),
              POINTER(AVCodec), 
              POINTER(POINTER(AVDictionary))]
  avcodec.avcodec_free_context.argtypes = [POINTER(POINTER(AVCodecContext))]
  avcodec.av_packet_alloc.restype = POINTER(AVPacket)
  avcodec.av_init_packet.argtypes = [POINTER(AVPacket)]
  avcodec.avcodec_decode_audio4.restype = c_int
  avcodec.avcodec_decode_audio4.argtypes = [POINTER(AVCodecContext),
              POINTER(AVFrame), POINTER(c_int),
              POINTER(AVPacket)]
  avcodec.avcodec_decode_video2.restype = c_int
  avcodec.avcodec_decode_video2.argtypes = [POINTER(AVCodecContext),
              POINTER(AVFrame), POINTER(c_int),
              POINTER(AVPacket)]
  avcodec.avpicture_fill.restype = c_int
  avcodec.avpicture_fill.argtypes = [POINTER(AVPicture),
              POINTER(c_uint8), c_int,
              c_int, c_int]
  avcodec.avcodec_flush_buffers.argtypes = [POINTER(AVCodecContext)]
  avcodec.avcodec_alloc_context3.restype = POINTER(AVCodecContext)
  avcodec.avcodec_alloc_context3.argtypes = [POINTER(AVCodec)]
  avcodec.avcodec_free_context.argtypes = [POINTER(POINTER(AVCodecContext))]
  avcodec.avcodec_parameters_to_context.restype = c_int
  avcodec.avcodec_parameters_to_context.argtypes = [POINTER(AVCodecContext),
              POINTER(AVCodecParameters)]
  
  __all__ = [
  'avcodec',
  'FF_INPUT_BUFFER_PADDING_SIZE',
  'AVPacket',
  'AVCodecContext',
  'AVPicture'
  ]
files: pyglet/media/sources/ffmpeg_lib/libavcodec.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libavcodec/avcodec.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  from sys import platform
  
  import pyglet.lib
  from . import libavutil
  
  if platform == 'win32':
      avcodec = pyglet.lib.load_library('avcodec-57')
  else:
      avcodec = pyglet.lib.load_library('avcodec')
  
  FF_INPUT_BUFFER_PADDING_SIZE = 32
  
  class AVPacketSideData(Structure): pass
  AVBufferRef = libavutil.AVBufferRef
  
  class AVPacket(Structure):
      _fields_ = [
          ('buf', POINTER(AVBufferRef)),
          ('pts', c_int64),
          ('dts', c_int64),
          ('data', POINTER(c_uint8)),
          ('size', c_int),
          ('stream_index', c_int),
          ('flags', c_int),
          ('side_data', POINTER(AVPacketSideData)),
          ('side_data_elems', c_int),
          ('duration', c_int64),
          ('pos', c_int64),
          ('convergence_duration', c_int64) #Deprecated
      ]
  class AVCodecParserContext(Structure): pass
  
  AVRational = libavutil.AVRational
  class AVCodecParameters(Structure):
      _fields_ = [
          ('codec_type', c_int),
          ('codec_id', c_int),
          ('codec_tag', c_uint32),
          ('extradata', POINTER(c_uint8)),
          ('extradata_size', c_int),
          ('format', c_int),
          ('bit_rate', c_int64),
          ('bits_per_coded_sample', c_int),
          ('bits_per_raw_sample', c_int),
          ('profile', c_int),
          ('level', c_int),
          ('width', c_int),
          ('height', c_int),
          ('sample_aspect_ratio', AVRational),
          ('field_order', c_int),
          ('color_range', c_int),
          ('color_primaries', c_int),
          ('color_trc', c_int),
          ('color_space', c_int),
          ('chroma_location', c_int),
          ('video_delay', c_int),
          ('channel_layout', c_uint64),
          ('channels', c_int),
          ('sample_rate', c_int),
          ('block_align', c_int),
          ('frame_size', c_int),
          ('initial_padding', c_int),
          ('trailing_padding', c_int),
          ('seek_preroll', c_int),
      ]
  class AVCodecInternal(Structure): pass
  class AVCodec(Structure):
      _fields_ = [
          ('name', c_char_p),
          ('long_name', c_char_p),
          # And more...
      ]
  class AVCodecContext(Structure): pass
  class RcOverride(Structure): pass
  class AVHWAccel(Structure): pass
  AVClass = libavutil.AVClass
  AVFrame = libavutil.AVFrame
  AV_NUM_DATA_POINTERS = libavutil.AV_NUM_DATA_POINTERS
  AVCodecContext._fields_ = [
          ('av_class', POINTER(AVClass)),
          ('log_level_offset', c_int),
          ('codec_type', c_int),
          ('codec', POINTER(AVCodec)),
          ('name', c_char * 32),
          ('codec_id', c_int),
          ('codec_tag', c_uint),
          ('stream_codec_tag', c_uint),
          ('priv_data', c_void_p),
          ('internal', POINTER(AVCodecInternal)),
          ('opaque', c_void_p),
          ('bit_rate', c_int64),
          ('bit_rate_tolerance', c_int),
          ('global_quality', c_int),
          ('compression_level', c_int),
          ('flags', c_int),
          ('flags2', c_int),
          ('extradata', POINTER(c_uint8)),
          ('extradata_size', c_int),
          ('time_base', AVRational),
          ('ticks_per_frame', c_int),
          ('delay', c_int),
          ('width', c_int),
          ('height', c_int),
          ('coded_width', c_int),
          ('coded_height', c_int),
          ('gop_size', c_int),
          ('pix_fmt', c_int),
          ('me_method', c_int),
          ('draw_horiz_band', CFUNCTYPE(None,
              POINTER(AVCodecContext), POINTER(AVFrame),
              c_int*8, c_int, c_int, c_int)),
          ('get_format', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), POINTER(c_int))),
          ('max_b_frames', c_int),
          ('b_quant_factor', c_float),
          ('rc_strategy', c_int),
          ('b_frame_strategy', c_int),
          ('b_quant_offset', c_float),
          ('has_b_frames', c_int),
          ('mpeg_quant', c_int),
          ('i_quant_factor', c_float),
          ('i_quant_offset', c_float),
          ('lumi_masking', c_float),
          ('temporal_cplx_masking', c_float),
          ('spatial_cplx_masking', c_float),
          ('p_masking', c_float),
          ('dark_masking', c_float),
          ('slice_count', c_int),
          ('prediction_method', c_int),
          ('slice_offset', POINTER(c_int)),
          ('sample_aspect_ratio', AVRational),
          ('me_cmp', c_int),
          ('me_sub_cmp', c_int),
          ('mb_cmp', c_int),
          ('ildct_cmp', c_int),
          ('dia_size', c_int),
          ('last_predictor_count', c_int),
          ('pre_me', c_int),
          ('me_pre_cmp', c_int),
          ('pre_dia_size', c_int),
          ('me_subpel_quality', c_int),
          ('dtg_active_format', c_int),
          ('me_range', c_int),
          ('intra_quant_bias', c_int),
          ('inter_quant_bias', c_int),
          ('slice_flags', c_int),
          ('xvmc_acceleration', c_int),
          ('mb_decision', c_int),
          ('intra_matrix', POINTER(c_uint16)),
          ('inter_matrix', POINTER(c_uint16)),
          ('scenechange_threshold', c_int),
          ('noise_reduction', c_int),
          ('me_threshold', c_int),
          ('mb_threshold', c_int),
          ('intra_dc_precision', c_int),
          ('skip_top', c_int),
          ('skip_bottom', c_int),
          ('border_masking', c_float),
          ('mb_lmin', c_int),
          ('mb_lmax', c_int),
          ('me_penalty_compensation', c_int),
          ('bidir_refine', c_int),
          ('brd_scale', c_int),
          ('keyint_min', c_int),
          ('refs', c_int),
          ('chromaoffset', c_int),
          ('scenechange_factor', c_int),
          ('mv0_threshold', c_int),
          ('b_sensitivity', c_int),
          ('color_primaries', c_int),
          ('color_trc', c_int),
          ('colorspace', c_int),
          ('color_range', c_int),
          ('chroma_sample_location', c_int),
          ('slices', c_int),
          ('field_order', c_int),
          ('sample_rate', c_int),
          ('channels', c_int),
          ('sample_fmt', c_int),
          ('frame_size', c_int),
          ('frame_number', c_int),
          ('block_align', c_int),
          ('cutoff', c_int),
          ('channel_layout', c_uint64),
          ('request_channel_layout', c_uint64),
          ('audio_service_type', c_int),
          ('request_sample_fmt', c_int),
          ('get_buffer2', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), POINTER(AVFrame), c_int)),
          ('refcounted_frames', c_int),
          ('qcompress', c_float),
          ('qblur', c_float),
          ('qmin', c_int),
          ('qmax', c_int),
          ('max_qdiff', c_int),
          ('rc_qsquish', c_float),
          ('rc_qmod_amp', c_float),
          ('rc_qmod_freq', c_int),
          ('rc_buffer_size', c_int),
          ('rc_override_count', c_int),
          ('rc_override', POINTER(RcOverride)),
          ('rc_eq', c_char_p),
          ('rc_max_rate', c_int64),
          ('rc_min_rate', c_int64),
          ('rc_buffer_aggressivity', c_float),
          ('rc_initial_cplx', c_float),
          ('rc_max_available_vbv_use', c_float),
          ('rc_min_vbv_overflow_use', c_float),
          ('rc_initial_buffer_occupancy', c_int),
          ('coder_type', c_int),
          ('context_model', c_int),
          ('lmin', c_int),
          ('lmax', c_int),
          ('frame_skip_threshold', c_int),
          ('frame_skip_factor', c_int),
          ('frame_skip_exp', c_int),
          ('frame_skip_cmp', c_int),
          ('trellis', c_int),
          ('min_prediction_order', c_int),
          ('max_prediction_order', c_int),
          ('timecode_frame_start', c_int64),
          ('rtp_callback', CFUNCTYPE(None,
              POINTER(AVCodecContext), c_void_p, c_int, c_int)),
          ('rtp_payload_size', c_int),
          ('mv_bits', c_int),
          ('header_bits', c_int),
          ('i_tex_bits', c_int),
          ('p_tex_bits', c_int),
          ('i_count', c_int),
          ('p_count', c_int),
          ('skip_count', c_int),
          ('misc_bits', c_int),
          ('frame_bits', c_int),
          ('stats_out', c_char_p),
          ('stats_in', c_char_p),
          ('workaround_bugs', c_int),
          ('strict_std_compliance', c_int),
          ('error_concealment', c_int),
          ('debug', c_int),
          ('debug_mv', c_int),
          ('err_recognition', c_int),
          ('reordered_opaque', c_int64),
          ('hwaccel', POINTER(AVHWAccel)),
          ('hwaccel_context', c_void_p),
          ('error', c_uint64 * AV_NUM_DATA_POINTERS),
          ('dct_algo', c_int),
          ('idct_algo', c_int),
          ('bits_per_coded_sample', c_int),
          ('bits_per_raw_sample', c_int),
          ('lowres', c_int),
          ('coded_frame', POINTER(AVFrame)),
          ('thread_count', c_int),
          ('thread_type', c_int),
          ('active_thread_type', c_int),
          ('thread_safe_callbacks', c_int),
          ('execute', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), 
              CFUNCTYPE(c_int, POINTER(AVCodecContext), c_void_p),
              c_void_p, c_int, c_int, c_int)),
          ('execute2', CFUNCTYPE(c_int,
              POINTER(AVCodecContext), 
              CFUNCTYPE(c_int, POINTER(AVCodecContext), c_void_p, c_int, c_int),
              c_void_p, c_int, c_int)),
          ('nsse_weight', c_int),
          ('profile', c_int),
          ('level', c_int),
          ('skip_loop_filter', c_int),
          ('skip_idct', c_int),
          ('skip_frame', c_int),
          ('subtitle_header', POINTER(c_uint8)),
          ('subtitle_header_size', c_int),
          ('error_rate', c_int),
          ('vbv_delay', c_uint64),
          ('side_data_only_packets', c_int),
          ('initial_padding', c_int),
          ('framerate', AVRational),
      ]
  class AVPicture(Structure):
      _fields_ = [
          ('data', POINTER(c_uint8) * AV_NUM_DATA_POINTERS),
          ('linesize', c_int * AV_NUM_DATA_POINTERS)
      ]
  avcodec.av_packet_unref.argtypes = [POINTER(AVPacket)]
  avcodec.avcodec_find_decoder.restype = POINTER(AVCodec)
  avcodec.avcodec_find_decoder.argtypes = [c_int]
  AVDictionary = libavutil.AVDictionary
  avcodec.avcodec_open2.restype = c_int
  avcodec.avcodec_open2.argtypes = [POINTER(AVCodecContext),
              POINTER(AVCodec), 
              POINTER(POINTER(AVDictionary))]
  avcodec.avcodec_free_context.argtypes = [POINTER(POINTER(AVCodecContext))]
  avcodec.av_packet_alloc.restype = POINTER(AVPacket)
  avcodec.av_init_packet.argtypes = [POINTER(AVPacket)]
  avcodec.avcodec_decode_audio4.restype = c_int
  avcodec.avcodec_decode_audio4.argtypes = [POINTER(AVCodecContext),
              POINTER(AVFrame), POINTER(c_int),
              POINTER(AVPacket)]
  avcodec.avcodec_decode_video2.restype = c_int
  avcodec.avcodec_decode_video2.argtypes = [POINTER(AVCodecContext),
              POINTER(AVFrame), POINTER(c_int),
              POINTER(AVPacket)]
  avcodec.avpicture_fill.restype = c_int
  avcodec.avpicture_fill.argtypes = [POINTER(AVPicture),
              POINTER(c_uint8), c_int,
              c_int, c_int]
  avcodec.avcodec_flush_buffers.argtypes = [POINTER(AVCodecContext)]
  avcodec.avcodec_alloc_context3.restype = POINTER(AVCodecContext)
  avcodec.avcodec_alloc_context3.argtypes = [POINTER(AVCodec)]
  avcodec.avcodec_free_context.argtypes = [POINTER(POINTER(AVCodecContext))]
  avcodec.avcodec_parameters_to_context.restype = c_int
  avcodec.avcodec_parameters_to_context.argtypes = [POINTER(AVCodecContext),
              POINTER(AVCodecParameters)]
  
  __all__ = [
  'avcodec',
  'FF_INPUT_BUFFER_PADDING_SIZE',
  'AVPacket',
  'AVCodecContext',
  'AVPicture'
  ]
files: pyglet/media/sources/ffmpeg_lib/libavcodec.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libavformat/avformat.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  
  import pyglet
  import pyglet.lib
  from . import libavcodec
  from . import libavutil
  
  if pyglet.compat_platform == 'win32':
      for libname in pyglet.options['ffmpeg_libs_win']:
          if libname.startswith('avformat'):
              avformat = pyglet.lib.load_library(libname)
              break
      else:
          # As a last resort, try to load the dll with default name.
          avformat = pyglet.lib.load_library('avformat')
  else:
      avformat = pyglet.lib.load_library('avformat')
  
  AVSEEK_FLAG_BACKWARD = 1 # ///< seek backward
  AVSEEK_FLAG_BYTE = 2     # ///< seeking based on position in bytes
  AVSEEK_FLAG_ANY = 4      # ///< seek to any frame, even non-keyframes
  AVSEEK_FLAG_FRAME = 8    # ///< seeking based on frame number
  
  MAX_REORDER_DELAY = 16
  
  class AVPacketList(Structure): pass
  class AVInputFormat(Structure): 
      _fields_ = [
          ('name', c_char_p)
      ]
  class AVOutputFormat(Structure): pass
  class AVIOContext(Structure): pass
  class AVIndexEntry(Structure): pass
  class AVStreamInfo(Structure):
      _fields_ = [
          ('last_dts', c_int64),
          ('duration_gcd', c_int64),
          ('duration_count', c_int),
          ('rfps_duration_sum', c_int64),
          ('duration_error', POINTER(c_double * 2 * (30*12+30+3+6))),
          ('codec_info_duration', c_int64), 
          ('codec_info_duration_fields', c_int64), 
          ('found_decoder', c_int), 
          ('last_duration', c_int64), 
          ('fps_first_dts', c_int64), 
          ('fps_first_dts_idx', c_int), 
          ('fps_last_dts', c_int64), 
          ('fps_last_dts_idx', c_int), 
       ]
  class AVProbeData(Structure):
      _fields_ = [
          ('filename', c_char_p),
          ('buf', POINTER(c_ubyte)),
          ('buf_size', c_int),
          ('mime_type', c_char_p)
      ]
  class FFFrac(Structure): pass
  class AVStreamInternal(Structure): pass
  class AVFrac(Structure):
      _fields_ = [
          ('val', c_int64),
          ('num', c_int64),
          ('den', c_int64),
      ]
  
  AVCodecContext = libavcodec.AVCodecContext
  AVPacketSideData = libavcodec.AVPacketSideData
  AVPacket = libavcodec.AVPacket
  AVCodecParserContext = libavcodec.AVCodecParserContext
  AVCodecParameters = libavcodec.AVCodecParameters
  AVRational = libavutil.AVRational
  AVDictionary = libavutil.AVDictionary
  class AVStream(Structure):
      _fields_ = [
          ('index', c_int),
          ('id', c_int),
          ('codec', POINTER(AVCodecContext)),
          ('priv_data', c_void_p),
          ('pts', AVFrac),
          ('time_base', AVRational),
          ('start_time', c_int64),
          ('duration', c_int64),
          ('nb_frames', c_int64),
          ('disposition', c_int),
          ('discard', c_int),
          ('sample_aspect_ratio', AVRational),
          ('metadata', POINTER(AVDictionary)),
          ('avg_frame_rate', AVRational),
          ('attached_pic', AVPacket),
          ('side_data', POINTER(AVPacketSideData)),
          ('nb_side_data', c_int),
          ('event_flags', c_int),
          ('info', POINTER(AVStreamInfo)),
          ('pts_wrap_bits', c_int),
          ('first_dts', c_int64),
          ('cur_dts', c_int64),
          ('last_IP_pts', c_int64),
          ('last_IP_duration', c_int),
          ('probe_packets', c_int),
          ('codec_info_nb_frames', c_int),
          ('need_parsing', c_int),
          ('parser', POINTER(AVCodecParserContext)),
          ('last_in_packet_buffer', POINTER(AVPacketList)),
          ('probe_data', AVProbeData),
          ('pts_buffer', c_int64 * (MAX_REORDER_DELAY+1)),
          ('index_entries', POINTER(AVIndexEntry)),
          ('nb_index_entries', c_int),
          ('index_entries_allocated_size', c_uint),
          ('r_frame_rate', AVRational),
          ('stream_identifier', c_int),
          ('interleaver_chunk_size', c_int64),
          ('interleaver_chunk_duration', c_int64),
          ('request_probe', c_int),
          ('skip_to_keyframe', c_int),
          ('skip_samples', c_int),
          ('start_skip_samples', c_int64),
          ('first_discard_sample', c_int64),
          ('last_discard_sample', c_int64),
          ('nb_decoded_frames', c_int),
          ('mux_ts_offset', c_int64),
          ('pts_wrap_reference', c_int64),
          ('pts_wrap_behavior', c_int),
          ('update_initial_durations_done', c_int),
          ('pts_reorder_error', c_int64 * (MAX_REORDER_DELAY+1)),
          ('pts_reorder_error_count', c_uint8 * (MAX_REORDER_DELAY+1)),
          ('last_dts_for_order_check', c_int64),
          ('dts_ordered', c_uint8),
          ('dts_misordered', c_uint8),
          ('inject_global_side_data', c_int),
          ('recommended_encoder_configuration', c_char_p),
          ('display_aspect_ratio', AVRational),
          ('priv_pts', POINTER(FFFrac)),
          ('internal', POINTER(AVStreamInternal)),
          ('codecpar', POINTER(AVCodecParameters)),
      ]
  class AVProgram(Structure): pass
  class AVChapter(Structure): pass
  class AVFormatInternal(Structure): pass
  class AVIOInterruptCB(Structure):
      _fields_ = [
          ('callback', CFUNCTYPE(c_int, c_void_p)),
          ('opaque', c_void_p)
      ]
  class AVFormatContext(Structure):
      pass
  
  AVClass = libavutil.AVClass
  AVCodec = libavcodec.AVCodec
  AVFormatContext._fields_ = [
          ('av_class', POINTER(AVClass)),
          ('iformat', POINTER(AVInputFormat)),
          ('oformat', POINTER(AVOutputFormat)),
          ('priv_data', c_void_p),
          ('pb', POINTER(AVIOContext)),
          ('ctx_flags', c_int),
          ('nb_streams', c_uint),
          ('streams', POINTER(POINTER(AVStream))),
          ('filename', c_char*1024),
          ('start_time', c_int64),
          ('duration', c_int64),
          ('bit_rate', c_int64),
          ('packet_size', c_uint),
          ('max_delay', c_int),
          ('flag', c_int),
          ('probesize', c_int64),
          ('max_analyze_duration', c_int64),
          ('key', POINTER(c_uint8)),
          ('keylen', c_int),
          ('nb_programs', c_uint),
          ('programs', POINTER(POINTER(AVProgram))),
          ('video_codec_id', c_int),
          ('audio_codec_id', c_int),
          ('subtitle_codec_id', c_int),
          ('max_index_size', c_uint),
          ('max_picture_buffer', c_uint),
          ('nb_chapters', c_uint),
          ('chapters', POINTER(POINTER(AVChapter))),
          ('metadata', POINTER(AVDictionary)),
          ('start_time_realtime', c_int64),
          ('fps_probe_size', c_int),
          ('error_recognition', c_int),
          ('interrupt_callback', AVIOInterruptCB),
          ('debug', c_int),
          ('max_interleave_delta', c_int64),
          ('strict_std_compliance', c_int),
          ('event_flags', c_int),
          ('max_ts_probe', c_int),
          ('avoid_negative_ts', c_int),
          ('ts_id', c_int),
          ('audio_preload', c_int),
          ('max_chunk_duration', c_int),
          ('max_chunk_size', c_int),
          ('use_wallclock_as_timestamps', c_int),
          ('avio_flags', c_int),
          ('duration_estimation_method', c_uint),
          ('skip_initial_bytes', c_int64),
          ('correct_ts_overflow', c_uint),
          ('seek2any', c_int),
          ('flush_packets', c_int),
          ('probe_score', c_int),
          ('format_probesize', c_int),
          ('codec_whitelist', c_char_p),
          ('format_whitelist', c_char_p),
          ('internal', POINTER(AVFormatInternal)),
          ('io_repositioned', c_int),
          ('video_codec', POINTER(AVCodec)),
          ('audio_codec', POINTER(AVCodec)),
          ('subtitle_codec', POINTER(AVCodec)),
          ('data_codec', POINTER(AVCodec)),
          ('metadata_header_padding', c_int),
          ('opaque', c_void_p),
          ('control_message_cb', CFUNCTYPE(c_int, 
              POINTER(AVFormatContext), c_int, c_void_p,
              c_size_t)),
          ('output_ts_offset', c_int64),
          ('dump_separator', POINTER(c_uint8)),
          ('data_codec_id', c_uint),
          ('protocol_whitelist', c_char_p),
          ('io_open', CFUNCTYPE(c_int, 
              POINTER(AVFormatContext), 
              POINTER(POINTER(AVIOContext)),
              c_char_p, c_int,
              POINTER(POINTER(AVDictionary)))),
          ('io_close', CFUNCTYPE(None, 
              POINTER(AVFormatContext), POINTER(AVIOContext))),
          ('protocol_blacklist', c_char_p),
          ('max_streams', c_int)
          ]
  
  avformat.av_register_all.restype = None
  avformat.av_find_input_format.restype = c_int
  avformat.av_find_input_format.argtypes = [c_int]
  avformat.avformat_open_input.restype = c_int
  avformat.avformat_open_input.argtypes = [
              POINTER(POINTER(AVFormatContext)),
              c_char_p,
              POINTER(AVInputFormat),
              POINTER(POINTER(AVDictionary))]
  avformat.avformat_find_stream_info.restype = c_int
  avformat.avformat_find_stream_info.argtypes = [
              POINTER(AVFormatContext),
              POINTER(POINTER(AVDictionary))]
  avformat.avformat_close_input.restype = None            
  avformat.avformat_close_input.argtypes = [
                              POINTER(POINTER(AVFormatContext))]
  avformat.av_read_frame.restype = c_int
  avformat.av_read_frame.argtypes = [POINTER(AVFormatContext),
              POINTER(AVPacket)]
  avformat.av_seek_frame.restype = c_int
  avformat.av_seek_frame.argtypes = [POINTER(AVFormatContext),
          c_int, c_int64, c_int]
  avformat.avformat_seek_file.restype = c_int
  avformat.avformat_seek_file.argtypes = [POINTER(AVFormatContext),
          c_int, c_int64, c_int64, c_int64, c_int]
  
  __all__ = [
  'avformat',
  'AVSEEK_FLAG_BACKWARD',
  'AVSEEK_FLAG_BYTE',
  'AVSEEK_FLAG_ANY',
  'AVSEEK_FLAG_FRAME',
  'AVFormatContext'
  ]
  
files: pyglet/media/sources/ffmpeg_lib/libavformat.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libavformat/avformat.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  from sys import platform
  
  import pyglet.lib
  from . import libavcodec
  from . import libavutil
  
  if platform == 'win32':
      avformat = pyglet.lib.load_library('avformat-57')
  else:
      avformat = pyglet.lib.load_library('avformat')
  
  AVSEEK_FLAG_BACKWARD = 1 # ///< seek backward
  AVSEEK_FLAG_BYTE = 2     # ///< seeking based on position in bytes
  AVSEEK_FLAG_ANY = 4      # ///< seek to any frame, even non-keyframes
  AVSEEK_FLAG_FRAME = 8    # ///< seeking based on frame number
  
  MAX_REORDER_DELAY = 16
  
  class AVPacketList(Structure): pass
  class AVInputFormat(Structure): 
      _fields_ = [
          ('name', c_char_p)
      ]
  class AVOutputFormat(Structure): pass
  class AVIOContext(Structure): pass
  class AVIndexEntry(Structure): pass
  class AVStreamInfo(Structure):
      _fields_ = [
          ('last_dts', c_int64),
          ('duration_gcd', c_int64),
          ('duration_count', c_int),
          ('rfps_duration_sum', c_int64),
          ('duration_error', POINTER(c_double * 2 * (30*12+30+3+6))),
          ('codec_info_duration', c_int64), 
          ('codec_info_duration_fields', c_int64), 
          ('found_decoder', c_int), 
          ('last_duration', c_int64), 
          ('fps_first_dts', c_int64), 
          ('fps_first_dts_idx', c_int), 
          ('fps_last_dts', c_int64), 
          ('fps_last_dts_idx', c_int), 
       ]
  class AVProbeData(Structure):
      _fields_ = [
          ('filename', c_char_p),
          ('buf', POINTER(c_ubyte)),
          ('buf_size', c_int),
          ('mime_type', c_char_p)
      ]
  class FFFrac(Structure): pass
  class AVStreamInternal(Structure): pass
  class AVFrac(Structure):
      _fields_ = [
          ('val', c_int64),
          ('num', c_int64),
          ('den', c_int64),
      ]
  
  AVCodecContext = libavcodec.AVCodecContext
  AVPacketSideData = libavcodec.AVPacketSideData
  AVPacket = libavcodec.AVPacket
  AVCodecParserContext = libavcodec.AVCodecParserContext
  AVCodecParameters = libavcodec.AVCodecParameters
  AVRational = libavutil.AVRational
  AVDictionary = libavutil.AVDictionary
  class AVStream(Structure):
      _fields_ = [
          ('index', c_int),
          ('id', c_int),
          ('codec', POINTER(AVCodecContext)),
          ('priv_data', c_void_p),
          ('pts', AVFrac),
          ('time_base', AVRational),
          ('start_time', c_int64),
          ('duration', c_int64),
          ('nb_frames', c_int64),
          ('disposition', c_int),
          ('discard', c_int),
          ('sample_aspect_ratio', AVRational),
          ('metadata', POINTER(AVDictionary)),
          ('avg_frame_rate', AVRational),
          ('attached_pic', AVPacket),
          ('side_data', POINTER(AVPacketSideData)),
          ('nb_side_data', c_int),
          ('event_flags', c_int),
          ('info', POINTER(AVStreamInfo)),
          ('pts_wrap_bits', c_int),
          ('first_dts', c_int64),
          ('cur_dts', c_int64),
          ('last_IP_pts', c_int64),
          ('last_IP_duration', c_int),
          ('probe_packets', c_int),
          ('codec_info_nb_frames', c_int),
          ('need_parsing', c_int),
          ('parser', POINTER(AVCodecParserContext)),
          ('last_in_packet_buffer', POINTER(AVPacketList)),
          ('probe_data', AVProbeData),
          ('pts_buffer', c_int64 * (MAX_REORDER_DELAY+1)),
          ('index_entries', POINTER(AVIndexEntry)),
          ('nb_index_entries', c_int),
          ('index_entries_allocated_size', c_uint),
          ('r_frame_rate', AVRational),
          ('stream_identifier', c_int),
          ('interleaver_chunk_size', c_int64),
          ('interleaver_chunk_duration', c_int64),
          ('request_probe', c_int),
          ('skip_to_keyframe', c_int),
          ('skip_samples', c_int),
          ('start_skip_samples', c_int64),
          ('first_discard_sample', c_int64),
          ('last_discard_sample', c_int64),
          ('nb_decoded_frames', c_int),
          ('mux_ts_offset', c_int64),
          ('pts_wrap_reference', c_int64),
          ('pts_wrap_behavior', c_int),
          ('update_initial_durations_done', c_int),
          ('pts_reorder_error', c_int64 * (MAX_REORDER_DELAY+1)),
          ('pts_reorder_error_count', c_uint8 * (MAX_REORDER_DELAY+1)),
          ('last_dts_for_order_check', c_int64),
          ('dts_ordered', c_uint8),
          ('dts_misordered', c_uint8),
          ('inject_global_side_data', c_int),
          ('recommended_encoder_configuration', c_char_p),
          ('display_aspect_ratio', AVRational),
          ('priv_pts', POINTER(FFFrac)),
          ('internal', POINTER(AVStreamInternal)),
          ('codecpar', POINTER(AVCodecParameters)),
      ]
  class AVProgram(Structure): pass
  class AVChapter(Structure): pass
  class AVFormatInternal(Structure): pass
  class AVIOInterruptCB(Structure):
      _fields_ = [
          ('callback', CFUNCTYPE(c_int, c_void_p)),
          ('opaque', c_void_p)
      ]
  class AVFormatContext(Structure):
      pass
  
  AVClass = libavutil.AVClass
  AVCodec = libavcodec.AVCodec
  AVFormatContext._fields_ = [
          ('av_class', POINTER(AVClass)),
          ('iformat', POINTER(AVInputFormat)),
          ('oformat', POINTER(AVOutputFormat)),
          ('priv_data', c_void_p),
          ('pb', POINTER(AVIOContext)),
          ('ctx_flags', c_int),
          ('nb_streams', c_uint),
          ('streams', POINTER(POINTER(AVStream))),
          ('filename', c_char*1024),
          ('start_time', c_int64),
          ('duration', c_int64),
          ('bit_rate', c_int64),
          ('packet_size', c_uint),
          ('max_delay', c_int),
          ('flag', c_int),
          ('probesize', c_int64),
          ('max_analyze_duration', c_int64),
          ('key', POINTER(c_uint8)),
          ('keylen', c_int),
          ('nb_programs', c_uint),
          ('programs', POINTER(POINTER(AVProgram))),
          ('video_codec_id', c_int),
          ('audio_codec_id', c_int),
          ('subtitle_codec_id', c_int),
          ('max_index_size', c_uint),
          ('max_picture_buffer', c_uint),
          ('nb_chapters', c_uint),
          ('chapters', POINTER(POINTER(AVChapter))),
          ('metadata', POINTER(AVDictionary)),
          ('start_time_realtime', c_int64),
          ('fps_probe_size', c_int),
          ('error_recognition', c_int),
          ('interrupt_callback', AVIOInterruptCB),
          ('debug', c_int),
          ('max_interleave_delta', c_int64),
          ('strict_std_compliance', c_int),
          ('event_flags', c_int),
          ('max_ts_probe', c_int),
          ('avoid_negative_ts', c_int),
          ('ts_id', c_int),
          ('audio_preload', c_int),
          ('max_chunk_duration', c_int),
          ('max_chunk_size', c_int),
          ('use_wallclock_as_timestamps', c_int),
          ('avio_flags', c_int),
          ('duration_estimation_method', c_uint),
          ('skip_initial_bytes', c_int64),
          ('correct_ts_overflow', c_uint),
          ('seek2any', c_int),
          ('flush_packets', c_int),
          ('probe_score', c_int),
          ('format_probesize', c_int),
          ('codec_whitelist', c_char_p),
          ('format_whitelist', c_char_p),
          ('internal', POINTER(AVFormatInternal)),
          ('io_repositioned', c_int),
          ('video_codec', POINTER(AVCodec)),
          ('audio_codec', POINTER(AVCodec)),
          ('subtitle_codec', POINTER(AVCodec)),
          ('data_codec', POINTER(AVCodec)),
          ('metadata_header_padding', c_int),
          ('opaque', c_void_p),
          ('control_message_cb', CFUNCTYPE(c_int, 
              POINTER(AVFormatContext), c_int, c_void_p,
              c_size_t)),
          ('output_ts_offset', c_int64),
          ('dump_separator', POINTER(c_uint8)),
          ('data_codec_id', c_uint),
          ('protocol_whitelist', c_char_p),
          ('io_open', CFUNCTYPE(c_int, 
              POINTER(AVFormatContext), 
              POINTER(POINTER(AVIOContext)),
              c_char_p, c_int,
              POINTER(POINTER(AVDictionary)))),
          ('io_close', CFUNCTYPE(None, 
              POINTER(AVFormatContext), POINTER(AVIOContext))),
          ('protocol_blacklist', c_char_p),
          ('max_streams', c_int)
          ]
  
  avformat.av_register_all.restype = None
  avformat.av_find_input_format.restype = c_int
  avformat.av_find_input_format.argtypes = [c_int]
  avformat.avformat_open_input.restype = c_int
  avformat.avformat_open_input.argtypes = [
              POINTER(POINTER(AVFormatContext)),
              c_char_p,
              POINTER(AVInputFormat),
              POINTER(POINTER(AVDictionary))]
  avformat.avformat_find_stream_info.restype = c_int
  avformat.avformat_find_stream_info.argtypes = [
              POINTER(AVFormatContext),
              POINTER(POINTER(AVDictionary))]
  avformat.avformat_close_input.restype = None            
  avformat.avformat_close_input.argtypes = [
                              POINTER(POINTER(AVFormatContext))]
  avformat.av_read_frame.restype = c_int
  avformat.av_read_frame.argtypes = [POINTER(AVFormatContext),
              POINTER(AVPacket)]
  avformat.av_seek_frame.restype = c_int
  avformat.av_seek_frame.argtypes = [POINTER(AVFormatContext),
          c_int, c_int64, c_int]
  avformat.avformat_seek_file.restype = c_int
  avformat.avformat_seek_file.argtypes = [POINTER(AVFormatContext),
          c_int, c_int64, c_int64, c_int64, c_int]
  
  __all__ = [
  'avformat',
  'AVSEEK_FLAG_BACKWARD',
  'AVSEEK_FLAG_BYTE',
  'AVSEEK_FLAG_ANY',
  'AVSEEK_FLAG_FRAME',
  'AVFormatContext'
  ]
  
files: pyglet/media/sources/ffmpeg_lib/libavformat.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libavutil/avutil.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  
  import pyglet
  import pyglet.lib
  
  if pyglet.compat_platform == 'win32':
      for libname in pyglet.options['ffmpeg_libs_win']:
          if libname.startswith('avutil'):
              avutil = pyglet.lib.load_library(libname)
              break
      else:
          # As a last resort, try to load the dll with default name.
          avutil = pyglet.lib.load_library('avutil')
  else:
      avutil = pyglet.lib.load_library('avutil')
  
  AVMEDIA_TYPE_UNKNOWN = -1
  AVMEDIA_TYPE_VIDEO = 0
  AVMEDIA_TYPE_AUDIO = 1
  AVMEDIA_TYPE_DATA = 2
  AVMEDIA_TYPE_SUBTITLE = 3
  AVMEDIA_TYPE_ATTACHMENT = 4
  AVMEDIA_TYPE_NB = 5
  
  AV_SAMPLE_FMT_U8 = 0
  AV_SAMPLE_FMT_S16 = 1
  AV_SAMPLE_FMT_S32 = 2
  AV_SAMPLE_FMT_FLT = 3
  AV_SAMPLE_FORMAT_DOUBLE = 4
  AV_SAMPLE_FMT_U8P = 5
  AV_SAMPLE_FMT_S16P = 6
  AV_SAMPLE_FMT_S32P = 7
  AV_SAMPLE_FMT_FLTP = 8
  AV_SAMPLE_FMT_DBLP = 9
  AV_SAMPLE_FMT_S64 = 10
  AV_SAMPLE_FMT_S64P = 11
  
  AV_NUM_DATA_POINTERS = 8
  
  AV_PIX_FMT_RGB24 = 2
  
  class AVBufferRef(Structure): pass
  
  
  class AVDictionaryEntry(Structure):
      _fields_ = [
          ('key', c_char_p),
          ('value', c_char_p)
      ]
  class AVDictionary(Structure):
      _fields_ = [
          ('count', c_int),
          ('elems', POINTER(AVDictionaryEntry))
      ]
  
  class AVClass(Structure): pass
  class AVRational(Structure):
      _fields_ = [
          ('num', c_int),
          ('den', c_int)
      ]
  
  class AVFrameSideData(Structure): pass
  class AVFrame(Structure): 
      _fields_ = [
          ('data', POINTER(c_uint8) * AV_NUM_DATA_POINTERS),
          ('linesize', c_int * AV_NUM_DATA_POINTERS),
          ('extended_data', POINTER(POINTER(c_uint8))),
          ('width', c_int),
          ('height', c_int),
          ('nb_samples', c_int),
          ('format', c_int),
          ('key_frame', c_int),
          ('pict_type', c_int),
          ('sample_aspect_ratio', AVRational),
          ('pts', c_int64),
          ('pkt_pts', c_int64),
          ('pkt_dts', c_int64),
          ('coded_picture_number', c_int),
          ('display_picture_number', c_int),
          ('quality', c_int),
          ('opaque', c_void_p),
          ('error', c_uint64),
          ('repeat_pict', c_int),
          ('interlaced_frame', c_int),
          ('top_field_first', c_int),
          ('palette_has_changed', c_int),
          ('reordered_opaque', c_int64),
          ('sample_rate', c_int),
          ('channel_layout', c_uint64),
          ('buf', POINTER(AVBufferRef) * AV_NUM_DATA_POINTERS),
          ('extended_buf', POINTER(POINTER(AVBufferRef))),
          ('nb_extended_buf', c_int),
          ('side_data', POINTER(POINTER(AVFrameSideData))),
          ('nb_side_data', c_int)
      ]
  AV_TIME_BASE = 1000000  
  AV_TIME_BASE_Q = AVRational(1, AV_TIME_BASE)
  
  avutil.av_version_info.restype = c_char_p
  avutil.av_dict_get.restype = POINTER(AVDictionaryEntry)
  avutil.av_dict_get.argtypes = [POINTER(AVDictionary),
              c_char_p, POINTER(AVDictionaryEntry),
              c_int]
  avutil.av_rescale_q.restype = c_int64
  avutil.av_rescale_q.argtypes = [c_int64, AVRational, AVRational]
  avutil.av_samples_get_buffer_size.restype = c_int
  avutil.av_samples_get_buffer_size.argtypes = [POINTER(c_int),
              c_int, c_int, c_int]
  avutil.av_frame_alloc.restype = POINTER(AVFrame)
  avutil.av_frame_free.argtypes = [POINTER(POINTER(AVFrame))]
  avutil.av_get_default_channel_layout.restype = c_int64
  avutil.av_get_default_channel_layout.argtypes = [c_int]
  avutil.av_get_bytes_per_sample.restype = c_int
  avutil.av_get_bytes_per_sample.argtypes = [c_int]
  avutil.av_strerror.restype = c_int
  avutil.av_strerror.argtypes = [c_int, c_char_p, c_size_t]
  
  __all__ = [
  'avutil',
  'AVMEDIA_TYPE_UNKNOWN',
  'AVMEDIA_TYPE_VIDEO',
  'AVMEDIA_TYPE_AUDIO',
  'AVMEDIA_TYPE_DATA',
  'AVMEDIA_TYPE_SUBTITLE',
  'AVMEDIA_TYPE_ATTACHMENT',
  'AVMEDIA_TYPE_NB',
  'AV_SAMPLE_FMT_U8',
  'AV_SAMPLE_FMT_S16',
  'AV_SAMPLE_FMT_S32',
  'AV_SAMPLE_FMT_FLT',
  'AV_SAMPLE_FORMAT_DOUBLE',
  'AV_SAMPLE_FMT_U8P',
  'AV_SAMPLE_FMT_S16P',
  'AV_SAMPLE_FMT_S32P',
  'AV_SAMPLE_FMT_FLTP',
  'AV_SAMPLE_FMT_DBLP',
  'AV_SAMPLE_FMT_S64',
  'AV_SAMPLE_FMT_S64P',
  'AV_NUM_DATA_POINTERS',
  'AV_PIX_FMT_RGB24',
  'AV_TIME_BASE',
  'AV_TIME_BASE_Q',
  'AVFrame',
  ]
files: pyglet/media/sources/ffmpeg_lib/libavutil.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libavutil/avutil.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  from sys import platform
  
  import pyglet.lib
  
  if platform == 'win32':
      avutil = pyglet.lib.load_library('avutil-55')
  else:
      avutil = pyglet.lib.load_library('avutil')
  
  AVMEDIA_TYPE_UNKNOWN = -1
  AVMEDIA_TYPE_VIDEO = 0
  AVMEDIA_TYPE_AUDIO = 1
  AVMEDIA_TYPE_DATA = 2
  AVMEDIA_TYPE_SUBTITLE = 3
  AVMEDIA_TYPE_ATTACHMENT = 4
  AVMEDIA_TYPE_NB = 5
  
  AV_SAMPLE_FMT_U8 = 0
  AV_SAMPLE_FMT_S16 = 1
  AV_SAMPLE_FMT_S32 = 2
  AV_SAMPLE_FMT_FLT = 3
  AV_SAMPLE_FORMAT_DOUBLE = 4
  AV_SAMPLE_FMT_U8P = 5
  AV_SAMPLE_FMT_S16P = 6
  AV_SAMPLE_FMT_S32P = 7
  AV_SAMPLE_FMT_FLTP = 8
  AV_SAMPLE_FMT_DBLP = 9
  AV_SAMPLE_FMT_S64 = 10
  AV_SAMPLE_FMT_S64P = 11
  
  AV_NUM_DATA_POINTERS = 8
  
  AV_PIX_FMT_RGB24 = 2
  
  class AVBufferRef(Structure): pass
  
  
  class AVDictionaryEntry(Structure):
      _fields_ = [
          ('key', c_char_p),
          ('value', c_char_p)
      ]
  class AVDictionary(Structure):
      _fields_ = [
          ('count', c_int),
          ('elems', POINTER(AVDictionaryEntry))
      ]
  
  class AVClass(Structure): pass
  class AVRational(Structure):
      _fields_ = [
          ('num', c_int),
          ('den', c_int)
      ]
  
  class AVFrameSideData(Structure): pass
  class AVFrame(Structure): 
      _fields_ = [
          ('data', POINTER(c_uint8) * AV_NUM_DATA_POINTERS),
          ('linesize', c_int * AV_NUM_DATA_POINTERS),
          ('extended_data', POINTER(POINTER(c_uint8))),
          ('width', c_int),
          ('height', c_int),
          ('nb_samples', c_int),
          ('format', c_int),
          ('key_frame', c_int),
          ('pict_type', c_int),
          ('sample_aspect_ratio', AVRational),
          ('pts', c_int64),
          ('pkt_pts', c_int64),
          ('pkt_dts', c_int64),
          ('coded_picture_number', c_int),
          ('display_picture_number', c_int),
          ('quality', c_int),
          ('opaque', c_void_p),
          ('error', c_uint64),
          ('repeat_pict', c_int),
          ('interlaced_frame', c_int),
          ('top_field_first', c_int),
          ('palette_has_changed', c_int),
          ('reordered_opaque', c_int64),
          ('sample_rate', c_int),
          ('channel_layout', c_uint64),
          ('buf', POINTER(AVBufferRef) * AV_NUM_DATA_POINTERS),
          ('extended_buf', POINTER(POINTER(AVBufferRef))),
          ('nb_extended_buf', c_int),
          ('side_data', POINTER(POINTER(AVFrameSideData))),
          ('nb_side_data', c_int)
      ]
  AV_TIME_BASE = 1000000  
  AV_TIME_BASE_Q = AVRational(1, AV_TIME_BASE)
  
  avutil.av_version_info.restype = c_char_p
  avutil.av_dict_get.restype = POINTER(AVDictionaryEntry)
  avutil.av_dict_get.argtypes = [POINTER(AVDictionary),
              c_char_p, POINTER(AVDictionaryEntry),
              c_int]
  avutil.av_rescale_q.restype = c_int64
  avutil.av_rescale_q.argtypes = [c_int64, AVRational, AVRational]
  avutil.av_samples_get_buffer_size.restype = c_int
  avutil.av_samples_get_buffer_size.argtypes = [POINTER(c_int),
              c_int, c_int, c_int]
  avutil.av_frame_alloc.restype = POINTER(AVFrame)
  avutil.av_frame_free.argtypes = [POINTER(POINTER(AVFrame))]
  avutil.av_get_default_channel_layout.restype = c_int64
  avutil.av_get_default_channel_layout.argtypes = [c_int]
  avutil.av_get_bytes_per_sample.restype = c_int
  avutil.av_get_bytes_per_sample.argtypes = [c_int]
  avutil.av_strerror.restype = c_int
  avutil.av_strerror.argtypes = [c_int, c_char_p, c_size_t]
  
  __all__ = [
  'avutil',
  'AVMEDIA_TYPE_UNKNOWN',
  'AVMEDIA_TYPE_VIDEO',
  'AVMEDIA_TYPE_AUDIO',
  'AVMEDIA_TYPE_DATA',
  'AVMEDIA_TYPE_SUBTITLE',
  'AVMEDIA_TYPE_ATTACHMENT',
  'AVMEDIA_TYPE_NB',
  'AV_SAMPLE_FMT_U8',
  'AV_SAMPLE_FMT_S16',
  'AV_SAMPLE_FMT_S32',
  'AV_SAMPLE_FMT_FLT',
  'AV_SAMPLE_FORMAT_DOUBLE',
  'AV_SAMPLE_FMT_U8P',
  'AV_SAMPLE_FMT_S16P',
  'AV_SAMPLE_FMT_S32P',
  'AV_SAMPLE_FMT_FLTP',
  'AV_SAMPLE_FMT_DBLP',
  'AV_SAMPLE_FMT_S64',
  'AV_SAMPLE_FMT_S64P',
  'AV_NUM_DATA_POINTERS',
  'AV_PIX_FMT_RGB24',
  'AV_TIME_BASE',
  'AV_TIME_BASE_Q',
  'AVFrame',
  ]
files: pyglet/media/sources/ffmpeg_lib/libavutil.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libswresample/swresample.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  
  import pyglet
  import pyglet.lib
  
  if pyglet.compat_platform == 'win32':
      for libname in pyglet.options['ffmpeg_libs_win']:
          if libname.startswith('swresample'):
              swresample = pyglet.lib.load_library(libname)
              break
      else:
          # As a last resort, try to load the dll with default name.
          swresample = pyglet.lib.load_library('swresample')
  else:
      swresample = pyglet.lib.load_library('swresample')
  
  SWR_CH_MAX = 32
  
  class SwrContext(Structure): pass
  
  swresample.swr_alloc_set_opts.restype = POINTER(SwrContext)
  swresample.swr_alloc_set_opts.argtypes = [POINTER(SwrContext),
          c_int64, c_int, c_int, c_int64,
          c_int, c_int, c_int, c_void_p]
  swresample.swr_init.restype = c_int
  swresample.swr_init.argtypes = [POINTER(SwrContext)]
  swresample.swr_free.argtypes = [POINTER(POINTER(SwrContext))]
  swresample.swr_convert.restype = c_int
  swresample.swr_convert.argtypes = [POINTER(SwrContext),
          POINTER(c_uint8) * SWR_CH_MAX,
          c_int,
          POINTER(POINTER(c_uint8)),
          c_int]
  
  __all__ = [
  'swresample',
  'SWR_CH_MAX',
  'SwrContext'
  ]
files: pyglet/media/sources/ffmpeg_lib/libswresample.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libswresample/swresample.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  from sys import platform
  
  import pyglet.lib
  
  if platform == 'win32':
      swresample = pyglet.lib.load_library('swresample-2')
  else:
      swresample = pyglet.lib.load_library('swresample')
  
  SWR_CH_MAX = 32
  
  class SwrContext(Structure): pass
  
  swresample.swr_alloc_set_opts.restype = POINTER(SwrContext)
  swresample.swr_alloc_set_opts.argtypes = [POINTER(SwrContext),
          c_int64, c_int, c_int, c_int64,
          c_int, c_int, c_int, c_void_p]
  swresample.swr_init.restype = c_int
  swresample.swr_init.argtypes = [POINTER(SwrContext)]
  swresample.swr_free.argtypes = [POINTER(POINTER(SwrContext))]
  swresample.swr_convert.restype = c_int
  swresample.swr_convert.argtypes = [POINTER(SwrContext),
          POINTER(c_uint8) * SWR_CH_MAX,
          c_int,
          POINTER(POINTER(c_uint8)),
          c_int]
  
  __all__ = [
  'swresample',
  'SWR_CH_MAX',
  'SwrContext'
  ]
files: pyglet/media/sources/ffmpeg_lib/libswresample.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libswscale/swscale.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  
  import pyglet
  import pyglet.lib
  
  if pyglet.compat_platform == 'win32':
      for libname in pyglet.options['ffmpeg_libs_win']:
          if libname.startswith('swscale'):
              swscale = pyglet.lib.load_library(libname)
              break
      else:
          # As a last resort, try to load the dll with default name.
          swscale = pyglet.lib.load_library('swscale')
  else:
      swscale = pyglet.lib.load_library('swscale')
  
  SWS_FAST_BILINEAR = 1
  
  class SwsContext(Structure): pass
  class SwsFilter(Structure): pass
  
  swscale.sws_getCachedContext.restype = POINTER(SwsContext)
  swscale.sws_getCachedContext.argtypes = [POINTER(SwsContext),
              c_int, c_int, c_int, c_int, 
              c_int, c_int, c_int, 
              POINTER(SwsFilter), POINTER(SwsFilter), 
              POINTER(c_double)]
  swscale.sws_freeContext.argtypes = [POINTER(SwsContext)]
  swscale.sws_scale.restype = c_int
  swscale.sws_scale.argtypes = [POINTER(SwsContext),
          POINTER(POINTER(c_uint8)),
          POINTER(c_int),
          c_int, c_int,
          POINTER(POINTER(c_uint8)),
          POINTER(c_int)]
  
  __all__ = [
  'swscale',
  'SWS_FAST_BILINEAR',
  'SwsContext',
  'SwsFilter'
  ]
files: pyglet/media/sources/ffmpeg_lib/libswscale.py
files: # ----------------------------------------------------------------------------
  # pyglet
  # Copyright (c) 2006-2008 Alex Holkner
  # All rights reserved.
  # 
  # Redistribution and use in source and binary forms, with or without
  # modification, are permitted provided that the following conditions 
  # are met:
  #
  #  * Redistributions of source code must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
  #  * Redistributions in binary form must reproduce the above copyright 
  #    notice, this list of conditions and the following disclaimer in
  #    the documentation and/or other materials provided with the
  #    distribution.
  #  * Neither the name of pyglet nor the names of its
  #    contributors may be used to endorse or promote products
  #    derived from this software without specific prior written
  #    permission.
  #
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  # POSSIBILITY OF SUCH DAMAGE.
  # ----------------------------------------------------------------------------
  '''Wrapper for include/libswscale/swscale.h
  '''
  
  from ctypes import (c_int, c_uint16, c_int32, c_int64, c_uint32, c_uint64, 
      c_uint8, c_uint, c_double, c_float, c_ubyte, c_size_t, c_char, c_char_p, 
      c_void_p, addressof, byref, cast, POINTER, CFUNCTYPE, Structure, Union, 
      create_string_buffer, memmove)
  from sys import platform
  
  import pyglet.lib
  
  if platform == 'win32':
      swscale = pyglet.lib.load_library('swscale-4')
  else:
      swscale = pyglet.lib.load_library('swscale')
  
  SWS_FAST_BILINEAR = 1
  
  class SwsContext(Structure): pass
  class SwsFilter(Structure): pass
  
  swscale.sws_getCachedContext.restype = POINTER(SwsContext)
  swscale.sws_getCachedContext.argtypes = [POINTER(SwsContext),
              c_int, c_int, c_int, c_int, 
              c_int, c_int, c_int, 
              POINTER(SwsFilter), POINTER(SwsFilter), 
              POINTER(c_double)]
  swscale.sws_freeContext.argtypes = [POINTER(SwsContext)]
  swscale.sws_scale.restype = c_int
  swscale.sws_scale.argtypes = [POINTER(SwsContext),
          POINTER(POINTER(c_uint8)),
          POINTER(c_int),
          c_int, c_int,
          POINTER(POINTER(c_uint8)),
          POINTER(c_int)]
  
  __all__ = [
  'swscale',
  'SWS_FAST_BILINEAR',
  'SwsContext',
  'SwsFilter'
  ]
files: pyglet/media/sources/ffmpeg_lib/libswscale.py