[xiph-cvs] cvs commit: ogg-python2/src _ogg2module.c _ogg2module.h general.c general.h pyoggpackbuff.c pyoggpackbuff.h pyoggpacket.c pyoggpacket.h pyoggsyncstate.c pyoggsyncstate.h

Arc arc at xiph.org
Sat Nov 29 01:21:57 PST 2003



arc         03/11/29 04:21:57

  Added:       .        AUTHORS COPYING config_unix.py prebuild.sh
                        setup.cfg setup.py
               pysrc    __init__.py
               src      _ogg2module.c _ogg2module.h general.c general.h
                        pyoggpackbuff.c pyoggpackbuff.h pyoggpacket.c
                        pyoggpacket.h pyoggpage.c pyoggpage.h
                        pyoggstreamstate.c pyoggstreamstate.h
                        pyoggsyncstate.c pyoggsyncstate.h
  Log:
  Alpha-0;  Builds, but broken left and right.

Revision  Changes    Path
1.1                  ogg-python2/AUTHORS

Index: AUTHORS
===================================================================
Arc <arc at xiph.org>

<p><p><p>1.1                  ogg-python2/COPYING

Index: COPYING
===================================================================
                    GNU GENERAL PUBLIC LICENSE
                       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

                    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

                            NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 19yy  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

<p>Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) 19yy name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.
$Id: COPYING,v 1.1 2003/11/29 09:21:56 arc Exp $

<p><p>1.1                  ogg-python2/config_unix.py

Index: config_unix.py
===================================================================
#!/usr/bin/env python

import string
import os
import sys

def msg_checking(msg):
    print "Checking", msg, "...",

def execute(cmd, display = 0):
    if display:
        print cmd
    return os.system(cmd)

def run_test(input, flags = ''):
    try:
        f = open('_temp.c', 'w')
        f.write(input)
        f.close()
        compile_cmd = '%s -o _temp _temp.c %s' % (os.environ.get('CC', 'cc'),
                                                  flags)
        if not execute(compile_cmd):
            execute('./_temp')
    finally:
        execute('rm -f _temp.c _temp')
    
ogg_test_program = '''
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ogg2/ogg.h>

int main ()
{
  system("touch conf.oggtest");
  return 0;
}
'''

def find_ogg(ogg_prefix = '/usr/local', enable_oggtest = 1):
    """A rough translation of ogg.m4"""

    ogg_cflags = []
    ogg_libs = []
    
    ogg_include_dir = ogg_prefix + '/include -pthreads'
    ogg_lib_dir = ogg_prefix + '/lib'
    ogg_libs = 'ogg2'

    msg_checking('for Ogg2')

    if enable_oggtest:
        execute('rm -f conf.oggtest', 0)

        try:
            run_test(ogg_test_program, flags="-I" + ogg_include_dir)
            if not os.path.isfile('conf.oggtest'):
                raise RuntimeError, "Did not produce output"
            execute('rm conf.oggtest', 0)
            
        except:
            print "test program failed"
            return None

    print "success"

    return {'ogg_libs' : ogg_libs,
            'ogg_lib_dir' : ogg_lib_dir,
            'ogg_include_dir' : ogg_include_dir}

def write_data(data):
    f = open('Setup', 'w')
    for item in data.items():
        f.write('%s = %s\n' % item)
    f.close()
    print "Wrote Setup file"
            
def print_help():
    print '''%s
    --prefix      Give the prefix in which ogg2 was installed.''' % sys.argv[0]
    sys.exit(0)

def parse_args():
    data = {}
    argv = sys.argv
    for pos in range(len(argv)):
        if argv[pos] == '--help':
            print_help()
        if argv[pos] == '--prefix':
            pos = pos + 1
            if len(argv) == pos:
                print "Prefix needs an argument"
                sys.exit(1)
            data['prefix'] = argv[pos]

    return data
    
def main():
    args = parse_args()
    prefix = args.get('prefix', '/usr/local')

    data = find_ogg(ogg_prefix = prefix)
    if not data:
        print "Config failure"
        sys.exit(1)
    write_data(data)

if __name__ == '__main__':
    main()

<p><p><p><p><p><p>1.1                  ogg-python2/prebuild.sh

Index: prebuild.sh
===================================================================
#!/bin/sh

# This is just a simple script to be run before any automatic
# binary distribution building (like bdist or bdist_rpm). You
# probably don't have to worry about it.

python config_unix.py

<p><p>1.1                  ogg-python2/setup.cfg

Index: setup.cfg
===================================================================
[bdist_rpm]
requires=libogg2
build_script=prebuild.sh

<p><p>1.1                  ogg-python2/setup.py

Index: setup.py
===================================================================
#!/usr/bin/env python

"""Setup script for the Ogg module distribution."""

import os
import re
import sys
import string

from distutils.core import setup
from distutils.extension import Extension

VERSION_MAJOR = 2
VERSION_MINOR = 0
pyogg_version = str(VERSION_MAJOR) + "." + str(VERSION_MINOR)

def get_setup():
    data = {}
    r = re.compile(r'(\S+)\s*?=\s*(.+)')
    
    if not os.path.isfile('Setup'):
        print "No 'Setup' file. Perhaps you need to run the configure script."
        sys.exit(1)

    f = open('Setup', 'r')
    
    for line in f.readlines():
        m = r.search(line)
        if not m:
            print "Error in setup file:", line
            sys.exit(1)
        key = m.group(1)
        val = m.group(2)
        data[key] = val
        
    return data

data = get_setup()
ogg_include_dir = data['ogg_include_dir'] 
ogg_lib_dir = data['ogg_lib_dir']
ogg_libs = string.split(data['ogg_libs'])

_ogg2module = Extension(name='_ogg2',
                       sources=['src/_ogg2module.c',
                                'src/pyoggpacket.c',
                                'src/pyoggstreamstate.c',
                                'src/pyoggpage.c',
###                                'src/pyoggpackbuff.c',
                                'src/pyoggsyncstate.c',
                                'src/general.c'],
                       define_macros = [('VERSION_MAJOR', VERSION_MAJOR),
                                        ('VERSION_MINOR', VERSION_MINOR),
                                        ('VERSION', '"%s"' % pyogg_version)],
                       
                       include_dirs=[ogg_include_dir, 'include'],
                       library_dirs=[ogg_lib_dir],
                       libraries=ogg_libs)

etup ( name = "pyogg",
        version = pyogg_version,
        description = "A wrapper for the Ogg libraries.",
        author = "Arc",
        author_email = "arc at indymedia.org",
        url = "NONEYET",

        headers = ['include/pyogg/pyogg2.h'],
        packages = ['ogg2'],
        package_dir = {'ogg2' : 'pysrc'},
        ext_package = 'ogg2',
        ext_modules = [_ogg2module])

<p><p>1.1                  ogg-python2/pysrc/__init__.py

Index: __init__.py
===================================================================
from _ogg2 import *
__all__ = ['_ogg2']

<p><p>1.1                  ogg-python2/src/_ogg2module.c

Index: _ogg2module.c
===================================================================
#include <ogg2/ogg.h>

#include <pyogg/pyogg2.h>

#include "general.h"
#include "_ogg2module.h"

#include "pyoggstreamstate.h"
#include "pyoggsyncstate.h"
#include "pyoggpacket.h"
/* #include "pyoggpackbuff.h" */
#include "pyoggpage.h"

tatic PyMethodDef Ogg_methods[] = {
  {"OggStreamState", PyOggStreamState_New, 
   METH_VARARGS, PyOggStreamState_Doc},
  /* {"OggPackBuff", PyOggPackBuffer_New,
   METH_VARARGS, PyOggPackBuffer_Doc}, */
  {"OggSyncState", PyOggSyncState_New,
   METH_VARARGS, PyOggSyncState_Doc},
  {NULL, NULL}
};

tatic char docstring[] = "";

tatic ogg2_module_info mi = {
  VERSION_MINOR,
  VERSION_MAJOR,
  &PyOggPacket_Type,
  &PyOggStreamState_Type,
  NULL,                          /* Will be PyOggError */
  PyOggPacket_FromPacket,
  arg_to_int64,
};

void
init_ogg2(void)
{
  PyObject *module, *dict, *Py_module_info;

/*  PyOggPackBuffer_Type.ob_type = &PyType_Type; */
  PyOggPacket_Type.ob_type = &PyType_Type;
  PyOggPage_Type.ob_type = &PyType_Type;
  PyOggStreamState_Type.ob_type = &PyType_Type;
  PyOggSyncState_Type.ob_type = &PyType_Type;
  
  module = Py_InitModule("_ogg2", Ogg_methods);
  dict = PyModule_GetDict(module);

  PyOggError = PyErr_NewException("ogg2.OggError", NULL, NULL);
  PyDict_SetItemString(dict, "OggError", PyOggError);

  mi.PyOggError = PyOggError;

  Py_module_info = PyCObject_FromVoidPtr(&mi, NULL);
  PyDict_SetItemString(dict, "_moduleinfo", Py_module_info);

  PyDict_SetItemString(dict, "__doc__", PyString_FromString(docstring));
  PyDict_SetItemString(dict, "__version__", PyString_FromString("2.0"));

  if (PyErr_Occurred())
    PyErr_SetString(PyExc_ImportError, "_ogg2: init failed");
}

<p><p>1.1                  ogg-python2/src/_ogg2module.h

Index: _ogg2module.h
===================================================================
#ifndef __OGG2MODULE_H__
#define __OGG2MODULE_H__

#include <Python.h>

PyObject *PyOggError;

/* Object docstrings */

extern char PyOggStreamState_Doc[];
extern char PyOggPackBuffer_Doc[];
extern char PyOggSyncState_Doc[];

#endif /* __OGG2MODULE_H__ */

<p><p>1.1                  ogg-python2/src/general.c

Index: general.c
===================================================================
#include "general.h"
#include <pyogg/pyogg2.h>

/* Simple function to turn an object into an ogg_int64_t. Returns 0 on
 * an error. Does not DECREF the argument */

int
arg_to_int64(PyObject *longobj, ogg_int64_t *val)
{
  if(PyLong_Check(longobj))
    *val = PyLong_AsLongLong(longobj);
  else if (PyInt_Check(longobj))
    *val = PyInt_AsLong(longobj);
  else {
    PyErr_SetString(PyExc_TypeError, "Argument must be int or long");
    return 0;
  }
  return 1;
}

/* Based on arg_to_int64, for 32-bit functions */

int
arg_to_int32(PyObject *intobj, ogg_int32_t *val)
{
  if (PyInt_Check(intobj))
    *val = PyInt_AsLong(intobj);
  else {
    PyErr_SetString(PyExc_TypeError, "Argument must be int");
    return 0;
  }
  return 1;
}

<p><p>1.1                  ogg-python2/src/general.h

Index: general.h
===================================================================
#ifndef __GENERAL_H__
#define __GENERAL_H__

#define MSG_SIZE 256
#define KEY_SIZE 1024

#define PY_UNICODE (PY_VERSION_HEX >= 0x01060000)

#define FDEF(x) static PyObject *##x(PyObject *self, PyObject *args); \
static char x##_Doc[] = 

#endif /* __GENERAL_H__ */

<p><p>1.1                  ogg-python2/src/pyoggpackbuff.c

Index: pyoggpackbuff.c
===================================================================
#include "pyoggpackbuff.h"
#include "pyoggpacket.h"
#include "general.h"
#include "_ogg2module.h"

/************************************************************
                         OggPackBuffer Object
************************************************************/

char PyOggPackBuffer_Doc[] = "";

tatic void PyOggPackBuffer_Dealloc(PyObject *);
static PyObject* PyOggPackBuffer_Getattr(PyObject *, char *);
static PyObject *PyOggPackBuffer_Repr(PyObject *self);

FDEF(PyOggPackBuffer_Reset) "Clears and resets the packet buffer";

FDEF(PyOggPackBuffer_Look) "Return the value of n bits without advancing pointer";
FDEF(PyOggPackBuffer_Look1) "Return the value of 1 bit without advancing pointer";

FDEF(PyOggPackBuffer_Bytes) "Return the number of bytes in the buffer";
FDEF(PyOggPackBuffer_Bits) "Return the number of bits in the buffer";

FDEF(PyOggPackBuffer_Read) "Return the value of n bits";
FDEF(PyOggPackBuffer_Read1) "Return the value of 1 bit";

FDEF(PyOggPackBuffer_Adv) "Advance the read location by n bits";
FDEF(PyOggPackBuffer_Adv1) "Advance the read location by 1 bit";

FDEF(PyOggPackBuffer_Export) "Export the OggPacket built by the buffer";

FDEF(PyOggPackBuffer_Write) "Write bits to the buffer.\n\n\
The first parameter is an integer from which the bits will be extracted.\n\
The second parameter is the number of bits to write (defaults to 32)";

PyTypeObject PyOggPackBuffer_Type = {
  PyObject_HEAD_INIT(NULL)
  0,
  "Oggpack_Buffer",
  sizeof(PyOggPackBufferObject),
  0,
  
  /* Standard Methods */
  /* (destructor) */ PyOggPackBuffer_Dealloc,
  /* (printfunc) */ 0,
  /* (getattrfunc) */ PyOggPackBuffer_Getattr,
  /* (setattrfunc) */ 0,
  /* (cmpfunc) */ 0,
  /* (reprfunc) */ PyOggPackBuffer_Repr,
  
  /* Type Categories */
  0, /* as number */
  0, /* as sequence */
  0, /* as mapping */
  0, /* hash */
  0, /* binary */
  0, /* repr */
  0, /* getattro */
  0, /* setattro */
  0, /* as buffer */
  0, /* tp_flags */
  PyOggPackBuffer_Doc
};

tatic PyMethodDef PyOggPackBuffer_methods[] = {
  {"reset", PyOggPackBuffer_Reset,
   METH_VARARGS, PyOggPackBuffer_Reset_Doc},
  {"look", PyOggPackBuffer_Look,
   METH_VARARGS, PyOggPackBuffer_Look_Doc},
  {"look1", PyOggPackBuffer_Look1,
   METH_VARARGS, PyOggPackBuffer_Look1_Doc},
  {"bytes", PyOggPackBuffer_Bytes,
   METH_VARARGS, PyOggPackBuffer_Bytes_Doc},
  {"bits", PyOggPackBuffer_Bits,
   METH_VARARGS, PyOggPackBuffer_Bits_Doc},
  {"read", PyOggPackBuffer_Read,
   METH_VARARGS, PyOggPackBuffer_Read_Doc},
  {"read1", PyOggPackBuffer_Read1,
   METH_VARARGS, PyOggPackBuffer_Read1_Doc},
  {"write", PyOggPackBuffer_Write,
   METH_VARARGS, PyOggPackBuffer_Write_Doc},
  {"adv", PyOggPackBuffer_Adv,
   METH_VARARGS, PyOggPackBuffer_Adv_Doc},
  {"adv1", PyOggPackBuffer_Adv1,
   METH_VARARGS, PyOggPackBuffer_Adv1_Doc},
  {"export", PyOggPackBuffer_Export,
   METH_VARARGS, PyOggPackBuffer_Export_Doc},
  {NULL, NULL}  
};

tatic void
PyOggPackBuffer_Dealloc(PyObject *self)
{
  oggpack_writeclear(PyOggPackBuffer_AsOggPackBuffer(self));
  PyObject_DEL(self);
}

tatic PyObject*
PyOggPackBuffer_Getattr(PyObject *self, char *name)
{
  return Py_FindMethod(PyOggPackBuffer_methods, self, name);
}

PyObject *
PyOggPackBuffer_New(PyObject *self, PyObject *args) 
{
  PyOggPackBufferObject *ret;
  oggpack_buffer *buffer;
  ogg_buffer_state *buffstate;

  if (!PyArg_ParseTuple(args, "")) 
    return NULL;

  ret = (PyOggPackBufferObject *) PyObject_NEW(PyOggPackBufferObject,
                                               &PyOggPackBuffer_type);
  if (ret == NULL)
    return NULL;

  oggpack_writeinit(buffer, buffstate);
  return (PyObject *)ret;
  }

  if (PyArg_ParseTuple(args, "O!", &PyOggPacket_Type,
                       (PyObject *) &packetobj)) {
    oggpack_readinit(&ret->ob, packetobj->op.packet,
                     packetobj->op.bytes);
    return (PyObject *)ret;
  }

    return NULL;
}

tatic PyObject *
PyOggPackBuffer_Reset(PyObject *self, PyObject *args)
{
  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  oggpack_reset(PyOggPackBuffer_AsOggPackBuffer(self));
  Py_INCREF(Py_None);
  return Py_None;
}

tatic PyObject *
PyOggPackBuffer_Look(PyObject *self, PyObject *args) 
{
  int bits = 32;
  long ret;
  if (!PyArg_ParseTuple(args, "l", &bits))
    return NULL;

  if (bits > 32) {
    PyErr_SetString(PyExc_ValueError, "Cannot look at more than 32 bits");
    return NULL;
  }

  ret = oggpack_look(PyOggPackBuffer_AsOggPackBuffer(self), bits);
  return PyLong_FromLong(ret);
}

tatic PyObject *
PyOggPackBuffer_Look1(PyObject *self, PyObject *args) 
{
  long ret;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = oggpack_look1(PyOggPackBuffer_AsOggPackBuffer(self));
  return PyLong_FromLong(ret);
}

tatic PyObject *
PyOggPackBuffer_Bytes(PyObject *self, PyObject *args)
{
  long ret;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
  return PyLong_FromLong(ret);
}

tatic PyObject *
PyOggPackBuffer_Bits(PyObject *self, PyObject *args)
{
  long ret;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = oggpack_bits(PyOggPackBuffer_AsOggPackBuffer(self));
  return PyLong_FromLong(ret);
}

tatic PyObject *
PyOggPackBuffer_Write(PyObject *self, PyObject *args) 
{
  long val;
  int bits = 32;

  if (!PyArg_ParseTuple(args, "l|l", &val, &bits)) 
    return NULL;

  if (bits > 32) {
    PyErr_SetString(PyExc_ValueError, "Cannot write more than 32 bits");
    return NULL;
  }

  oggpack_write(PyOggPackBuffer_AsOggPackBuffer(self), val, bits);

  Py_INCREF(Py_None);
  return Py_None;
}

tatic PyObject *
PyOggPackBuffer_Read(PyObject *self, PyObject *args) 
{
  int bits = 32;
  long ret;
  
  if (!PyArg_ParseTuple(args, "|i", &bits))
    return NULL;
  
  if (bits > 32) {
    PyErr_SetString(PyExc_ValueError, "Cannot read more than 32 bits");
    return NULL;
  }

  ret = oggpack_read(PyOggPackBuffer_AsOggPackBuffer(self),  bits);

  return PyInt_FromLong(ret);
}

tatic PyObject *
PyOggPackBuffer_Read1(PyObject *self, PyObject *args)
{
  long ret;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = oggpack_read1(PyOggPackBuffer_AsOggPackBuffer(self));
  return PyInt_FromLong(ret);
}

tatic PyObject *
PyOggPackBuffer_Adv(PyObject *self, PyObject *args)
{
  int bits;

  if (!PyArg_ParseTuple(args, "i", &bits))
    return NULL;

  oggpack_adv(PyOggPackBuffer_AsOggPackBuffer(self), bits);

  Py_INCREF(Py_None);
  return Py_None;
}

tatic PyObject *
PyOggPackBuffer_Adv1(PyObject *self, PyObject *args)
{
  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  oggpack_adv1(PyOggPackBuffer_AsOggPackBuffer(self));
  Py_INCREF(Py_None);
  return Py_None;
}

tatic PyObject *
PyOggPackBuffer_Export(PyObject *self, PyObject *args)
{
  ogg_packet op;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  op.packet = oggpack_get_buffer(PyOggPackBuffer_AsOggPackBuffer(self));
  op.bytes = oggpack_bytes(PyOggPackBuffer_AsOggPackBuffer(self));
  op.b_o_s = 0;
  op.e_o_s = 0;
  op.granulepos = 0;
  op.packetno = 0;

  return py_ogg_packet_from_packet(&op);
}
  

tatic PyObject *
PyOggPackBuffer_Repr(PyObject *self)
{
  oggpack_buffer *ob = PyOggPackBuffer_AsOggPackBuffer(self);
  char buf[256];

  sprintf(buf, "<OggPackBuff, endbyte = %ld, endbit = %d at %p>", ob->endbyte,
                                        ob->endbit, self);
  return PyString_FromString(buf);
}

<p><p><p>1.1                  ogg-python2/src/pyoggpackbuff.h

Index: pyoggpackbuff.h
===================================================================
#ifndef PYOGGPACKBUFF_H
#define PYOGGPACKBUFF_H

#include <pyogg/pyogg2.h>

typedef struct {
  PyObject_HEAD
  oggpack_buffer *buffer;
} PyOggPackBufferObject;

#define PyOggPackBuffer_AsOggPackBuffer(x) ( ((PyOggPackBufferObject *) (x))->buffer )

extern PyTypeObject PyOggPackBuffer_Type;

PyObject *PyOggPackBuffer_New(PyObject *, PyObject *);

#endif

<p><p>1.1                  ogg-python2/src/pyoggpacket.c

Index: pyoggpacket.c
===================================================================
#include <pyogg/pyogg2.h>
#include "pyoggpacket.h"
#include "general.h"

/************************************************************
                         OggPacket Object
 ************************************************************/

char PyOggPacket_Doc[] = "";

tatic void PyOggPacket_Dealloc(PyObject *);
static PyObject* PyOggPacket_Getattr(PyObject *, char *);
static int PyOggPacket_Setattr(PyObject *, char *, PyObject *);
static PyObject *PyOggPacket_Repr(PyObject *self);

PyTypeObject PyOggPacket_Type = {
  PyObject_HEAD_INIT(NULL)
  0,
  "OggPacket",
  sizeof(PyOggPacketObject),
  0,
  
  /* Standard Methods */
  /* (destructor) */ PyOggPacket_Dealloc,
  /* (printfunc) */ 0,
  /* (getattrfunc) */ PyOggPacket_Getattr,
  /* (setattrfunc) */ PyOggPacket_Setattr,
  /* (cmpfunc) */ 0,
  /* (reprfunc) */ PyOggPacket_Repr,
  
  /* Type Categories */
  0, /* as number */
  0, /* as sequence */
  0, /* as mapping */
  0, /* hash */
  0, /* binary */
  0, /* repr */
  0, /* getattro */
  0, /* setattro */
  0, /* as buffer */
  0, /* tp_flags */
  PyOggPacket_Doc
};

tatic PyMethodDef PyOggPacket_methods[] = {
  {"data", NULL, NULL},
  {"bos", NULL, NULL},
  {"eos", NULL, NULL},
  {"granulepos", NULL, NULL},
  {"packetno", NULL, NULL},
  {NULL, NULL}
};

PyObject *
PyOggPacket_FromPacket(ogg_packet *packet)
{
  PyOggPacketObject *ret = (PyOggPacketObject *) PyObject_NEW(PyOggPacketObject, 
                                                  &PyOggPacket_Type);
  if (ret == NULL)
    return NULL;

  ret->packet = packet;
  return (PyObject *)ret;
}

tatic void
PyOggPacket_Dealloc(PyObject *self)
{
  ogg_packet_release(PyOggPacket_AsOggPacket(self));
  PyMem_DEL(self);
}

tatic PyObject*
PyOggPacket_Getattr(PyObject *self, char *name)
{
  if (strcmp(name, "data") == 0) 
    return PyString_FromStringAndSize((char *) PyOggPacket_AsOggPacket(self)->packet,
                                      PyOggPacket_AsOggPacket(self)->bytes);
  if (strcmp(name, "bos") == 0)
    return PyLong_FromLong(PyOggPacket_AsOggPacket(self)->b_o_s);
  if (strcmp(name, "eos") == 0)
    return PyLong_FromLong(PyOggPacket_AsOggPacket(self)->e_o_s);
  if (strcmp(name, "granulepos") == 0)
    return PyLong_FromLongLong(PyOggPacket_AsOggPacket(self)->granulepos);
  if (strcmp(name, "packetno") == 0)
    return PyLong_FromLongLong(PyOggPacket_AsOggPacket(self)->packetno);
  return Py_FindMethod(PyOggPacket_methods, self, name);
}

tatic int
PyOggPacket_Setattr(PyObject *self, char *name, PyObject *value)
{
  if (strcmp(name, "data") == 0) {
    PyErr_SetString(PyExc_AttributeError, "Function not written yet");
    return -1;
  }
  if (strcmp(name, "bos") == 0) {
    ogg_int32_t v;
    if (!arg_to_int32(value, &v))
      return -1;
    PyOggPacket_AsOggPacket(self)->b_o_s = v;
    return 0;
  }
  if (strcmp(name, "eos") == 0) {
    ogg_int32_t v;
    if (!arg_to_int32(value, &v))
      return -1;
    PyOggPacket_AsOggPacket(self)->e_o_s = v;
    return 0;
  }
  if (strcmp(name, "granulepos") == 0) {
    ogg_int64_t v;
    if (!arg_to_int64(value, &v))
      return -1;
    PyOggPacket_AsOggPacket(self)->granulepos = v;
    return 0;
  }
  if (strcmp(name, "packetno") == 0) {
    ogg_int64_t v;
    if (!arg_to_int64(value, &v))
      return -1;
    PyOggPacket_AsOggPacket(self)->packetno = v;
    return 0;
  }
  
  return -1;
}

tatic PyObject *
PyOggPacket_Repr(PyObject *self)
{
  char buf[256];
  char *bos = PyOggPacket_AsOggPacket(self)->b_o_s ? "BOS, " : "";
  char *eos = PyOggPacket_AsOggPacket(self)->e_o_s ? "EOS, " : "";

  sprintf(buf, "<OggPacket, %s%spacketno = %lld, granulepos = %lld,"
          " length = %ld at %p>", bos, eos, PyOggPacket_AsOggPacket(self)->packetno,
          PyOggPacket_AsOggPacket(self)->granulepos, PyOggPacket_AsOggPacket(self)->bytes, self);
  return PyString_FromString(buf);
}

<p><p>1.1                  ogg-python2/src/pyoggpacket.h

Index: pyoggpacket.h
===================================================================
#ifndef PYOGGPACKET_H
#define PYOGGPACKET_H

typedef struct {
  PyObject_HEAD
  ogg_packet *packet;
} PyOggPacketObject;

extern PyTypeObject PyOggPacket_Type;

#define PyOggPacket_AsOggPacket(x) (((PyOggPacketObject *) (x))->packet)

PyObject *PyOggPacket_FromPacket(ogg_packet *);

#endif /* PYOGGPACKET_H */

<p><p>1.1                  ogg-python2/src/pyoggpage.c

Index: pyoggpage.c
===================================================================
#include "general.h"
#include "_ogg2module.h"
#include "pyoggpage.h"

/*****************************************************************
                            OggPage Object
 *****************************************************************/

<p>char PyOggPage_Doc[] = "This is an Ogg Page.";

tatic void PyOggPage_Dealloc(PyObject *);
static PyObject* PyOggPage_Getattr(PyObject *, char *);
static int PyOggPage_Setattr(PyObject *self, char *name, PyObject *value);
static PyObject *PyOggPage_Repr(PyObject *self);
static PyObject *PyOggPage_Size(PyObject *self, PyObject *args);

PyTypeObject PyOggPage_Type = {
  PyObject_HEAD_INIT(NULL)
  0,
  "OggPage",
  sizeof(PyOggPageObject),
  0,
  
  /* Standard Methods */
  /* (destructor) */ PyOggPage_Dealloc,
  /* (printfunc) */ 0,
  /* (getattrfunc) */ PyOggPage_Getattr,
  /* (setattrfunc) */ PyOggPage_Setattr,
  /* (cmpfunc) */ 0,
  /* (reprfunc) */ PyOggPage_Repr,
  
  /* Type Categories */
  0, /* as number */
  0, /* as sequence */
  0, /* as mapping */
  0, /* hash */
  0, /* binary */
  0, /* repr */
  0, /* getattro */
  0, /* setattro */
  0, /* as buffer */
  0, /* tp_flags */
  PyOggPage_Doc
};

tatic PyMethodDef PyOggPage_methods[] = {
  {"__len__", PyOggPage_Size, METH_VARARGS, NULL},
/*  {"__getattr__", PyOggPage_Getattr, METH_VARARGS, NULL},
  {"__setattr__", PyOggPage_Setattr, METH_VARARGS, NULL}, */
  {"bos", NULL, NULL, "The BOS (Beginning-Of-Stream) flag."},
  {"body", NULL, NULL, NULL},
  {"continued", NULL, NULL, NULL},
  {"eos", NULL, NULL, NULL},
  {"granulepos", NULL, NULL, NULL},
  {"header", NULL, NULL, NULL},
  {"packets", NULL, NULL, NULL},
  {"pageno", NULL, NULL, NULL},
  {"serialno", NULL, NULL, NULL},
  {"version", NULL, NULL, NULL},
  {NULL, NULL}
};

tatic void 
PyOggPage_Dealloc(PyObject *self) {
  ogg_page_release(PyOggPage_AsOggPage(self));
  PyObject_Del(self);
}

<p>PyObject *
PyOggPage_FromOggPage(ogg_page *page) {
  PyOggPageObject *ret = (PyOggPageObject *) PyObject_NEW(PyOggPageObject, 
                                                          &PyOggPage_Type);

  if (ret == NULL)
    return NULL;

  ret->page = page;
  return (PyObject *) ret;
}

tatic PyObject *
PyOggPage_Size(PyObject *self, PyObject *args) {
  int size;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  size = PyOggPage_AsOggPage(self)->header_len +
         PyOggPage_AsOggPage(self)->body_len;
  return PyInt_FromLong(size);
}

tatic PyObject* 
PyOggPage_Getattr(PyObject *self, char *name) {
  ogg_page *page = PyOggPage_AsOggPage(self);

  if (strcmp(name, "body") == 0) 
    return PyString_FromStringAndSize((char *) page->body, page->body_len);

  if (strcmp(name, "bos") == 0) {
    if (ogg_page_bos(page)) {
      Py_INCREF(Py_True);
      return Py_True;
    }
    else {
      Py_INCREF(Py_False);
      return Py_False;
    }
  }
  if (strcmp(name, "continued") == 0) {
    if (ogg_page_continued(page)) {
      Py_INCREF(Py_True);
      return Py_True;
    }
    else {
      Py_INCREF(Py_False);
      return Py_False;
    }
  }
  if (strcmp(name, "eos") == 0) {
    if (ogg_page_eos(page)) {
      Py_INCREF(Py_True);
      return Py_True;
    }
    else {
      Py_INCREF(Py_False);
      return Py_False;
    }
  }
  if (strcmp(name, "granulepos") == 0)
    return PyLong_FromLongLong(ogg_page_granulepos(page));
  if (strcmp(name, "packets") == 0) 
    return PyInt_FromLong(ogg_page_packets(page));
  if (strcmp(name, "pageno") == 0) 
    return PyInt_FromLong(ogg_page_pageno(page));
  if (strcmp(name, "serialno") == 0) 
    return PyInt_FromLong(ogg_page_serialno(page));
  if (strcmp(name, "version") == 0) 
    return PyInt_FromLong(ogg_page_version(page));
  return Py_FindMethod(PyOggPage_methods, self, name);
}

tatic int
PyOggPage_Setattr(PyObject *self, char *name, PyObject *value)
{
  char *head = (char *) PyOggPage_AsOggPage(self)->header;

  if (strcmp(name, "bos") == 0) {
    ogg_int64_t v;

    if (!arg_to_int64(value, &v))
      return -1;
    if (!v) {
      if (head[5] & 0x02) {
        head[5] = head[5] & 0xFD;
        ogg_page_checksum_set(PyOggPage_AsOggPage(self));
      }
    } else {
      if (!(head[5] & 0x02)) {
        head[5] = head[5] | 0x02;
        ogg_page_checksum_set(PyOggPage_AsOggPage(self));
      }
    }
    return 0;
  }

  if (strcmp(name, "continued") == 0) {
    ogg_int64_t v;

    if (!arg_to_int64(value, &v))
      return -1;
    if (!v) {
      if (head[5] & 0x01) {
        head[5] = head[5] & 0xFE;
        ogg_page_checksum_set(PyOggPage_AsOggPage(self));
      }
    } else {
      if (!(head[5] & 0x01)) {
        head[5] = head[5] | 0x01;
        ogg_page_checksum_set(PyOggPage_AsOggPage(self));
      }
    }
    return 0;
  }
 
  if (strcmp(name, "eos") == 0) {
    ogg_int64_t v;

    if (!arg_to_int64(value, &v))
      return -1;
    if (!v) {
      if (head[5] & 0x04) {
        head[5] = head[5] & 0xFB;
        ogg_page_checksum_set(PyOggPage_AsOggPage(self));
      }
    } else {
      if (!(head[5] & 0x04)) {
        head[5] = head[5] | 0x04;
        ogg_page_checksum_set(PyOggPage_AsOggPage(self));
      }
    }
    return 0;
  }

  if (strcmp(name, "granulepos") == 0) {
    int i;
    ogg_int64_t v;
    if (!arg_to_int64(value, &v))
      return -1;
    for (i=6; i<14; i++) {
      head[i] = v & 0xff;
      v >>= 8;
    }
    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
    return 0;
  }

  if (strcmp(name, "pageno") == 0) {
    int i;
    ogg_int32_t v;
    if (!arg_to_int32(value, &v))
      return -1;
    for (i=18; i<22; i++) {
      head[i] = v & 0xff;
      v >>= 8;
    }
    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
    return 0;
  }

  if (strcmp(name, "serialno") == 0) {
    int i;
    ogg_int32_t v;
    if (!arg_to_int32(value, &v))
      return -1;
    for (i=14; i<18; i++) {
      head[i] = v & 0xff;
      v >>= 8;
    }
    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
    return 0;
  }

  if (strcmp(name, "version") == 0) {
    int i;
    ogg_int32_t v;
    if (!arg_to_int32(value, &v))
      return -1;
    if ( v<0 | v>255 ) {
      PyErr_SetString(PyExc_ValueError, "version must be between 0 and 255");  
      return -1;
    }
    head[4] = v;
    ogg_page_checksum_set(PyOggPage_AsOggPage(self));
    return 0;
  }
  PyErr_SetString(PyExc_AttributeError, "OggPage object has no such attribute");  
  return -1;
}

tatic PyObject *
PyOggPage_Repr(PyObject *self)
{
  char buf[256];
  char *bos = ogg_page_bos(PyOggPage_AsOggPage(self)) ? "BOS, " : "";
  char *eos = ogg_page_eos(PyOggPage_AsOggPage(self)) ? "EOS, " : "";
  char *cont = ogg_page_continued(PyOggPage_AsOggPage(self)) ? "CONT, " : "";

  sprintf(buf, "<OggPage, %s%s%spageno = %ld, granulepos = %lld,"
          " packets = %d, serialno = %d, version = %d," 
          " head length = %ld, body length = %ld at %p>",
          cont, bos, eos, ogg_page_pageno(PyOggPage_AsOggPage(self)),
          ogg_page_granulepos(PyOggPage_AsOggPage(self)),
          ogg_page_packets(PyOggPage_AsOggPage(self)),
          ogg_page_serialno(PyOggPage_AsOggPage(self)),
          ogg_page_version(PyOggPage_AsOggPage(self)), 
          PyOggPage_AsOggPage(self)->header_len, 
          PyOggPage_AsOggPage(self)->body_len, self); 
  return PyString_FromString(buf);
}

<p><p>1.1                  ogg-python2/src/pyoggpage.h

Index: pyoggpage.h
===================================================================
#ifndef PYOGG2PAGE_H
#define PYOGG2PAGE_H

#include <pyogg/pyogg2.h>

typedef struct {
  PyObject_HEAD
  ogg_page *page;
} PyOggPageObject;

#define PyOggPage_AsOggPage(x) ( ((PyOggPageObject *) (x))->page )

extern PyTypeObject PyOggPage_Type;

PyObject *PyOggPage_FromOggPage(ogg_page *page);

#endif

<p><p>1.1                  ogg-python2/src/pyoggstreamstate.c

Index: pyoggstreamstate.c
===================================================================
#include "_ogg2module.h"
#include "pyoggstreamstate.h"
#include "pyoggpacket.h"
#include "pyoggpage.h"
#include "general.h"

/*****************************************************************
                            OggStreamState Object
 *****************************************************************/

<p>char PyOggStreamState_Doc[] = "";

tatic void PyOggStreamState_Dealloc(PyObject *);
static PyObject* PyOggStreamState_Getattr(PyObject *, char *);
static PyObject *PyOggStreamState_Repr(PyObject *self);

FDEF(PyOggStreamState_Packetin) "Add a packet to the stream.";
FDEF(PyOggStreamState_Pageout) "Extract and return an OggPage.";
FDEF(PyOggStreamState_Flush) "Produce an ogg page suitable for writing to output.";
FDEF(PyOggStreamState_Pagein) "Write a page to the stream";
FDEF(PyOggStreamState_Packetout) "Extract a packet from the stream";
FDEF(PyOggStreamState_Packetpeek) "Extract a packet from the stream";
FDEF(PyOggStreamState_Reset) "Reset the stream state";
FDEF(PyOggStreamState_Eos) "Return whether the end of the stream is reached.";

PyTypeObject PyOggStreamState_Type = {
  PyObject_HEAD_INIT(NULL)
  0,
  "OggStreamState",
  sizeof(PyOggStreamStateObject),
  0,
  
  /* Standard Methods */
  /* (destructor) */ PyOggStreamState_Dealloc,
  /* (printfunc) */ 0,
  /* (getattrfunc) */ PyOggStreamState_Getattr,
  /* (setattrfunc) */ 0,
  /* (cmpfunc) */ 0,
  /* (reprfunc) */ PyOggStreamState_Repr,
  
  /* Type Categories */
  0, /* as number */
  0, /* as sequence */
  0, /* as mapping */
  0, /* hash */
  0, /* binary */
  0, /* repr */
  0, /* getattro */
  0, /* setattro */
  0, /* as buffer */
  0, /* tp_flags */
  PyOggStreamState_Doc
};

tatic PyMethodDef PyOggStreamState_methods[] = {
  {"packetin", PyOggStreamState_Packetin,
   METH_VARARGS, PyOggStreamState_Packetin_Doc},
  {"pageout", PyOggStreamState_Pageout,
   METH_VARARGS, PyOggStreamState_Pageout_Doc},
  {"flush", PyOggStreamState_Flush,
   METH_VARARGS, PyOggStreamState_Flush_Doc},
  {"pagein", PyOggStreamState_Pagein,
   METH_VARARGS, PyOggStreamState_Pagein_Doc},
  {"packetout", PyOggStreamState_Packetout,
   METH_VARARGS, PyOggStreamState_Packetout_Doc},
  {"packetpeek", PyOggStreamState_Packetpeek,
   METH_VARARGS, PyOggStreamState_Packetpeek_Doc},
  {"reset", PyOggStreamState_Reset,
   METH_VARARGS, PyOggStreamState_Reset_Doc},
  {"eos", PyOggStreamState_Eos, 
   METH_VARARGS, PyOggStreamState_Eos_Doc},
  {NULL, NULL}
};

tatic void 
PyOggStreamState_Dealloc(PyObject *self)
{
  ogg_stream_destroy(PyOggStreamState_AsOggStreamState(self));
  PyObject_DEL(self);
}

tatic PyObject* 
PyOggStreamState_Getattr(PyObject *self, char *name)
{
  return Py_FindMethod(PyOggStreamState_methods, self, name);
}

PyObject *
PyOggStreamState_FromSerialno(int serialno)
{
  PyOggStreamStateObject *ret = PyObject_NEW(PyOggStreamStateObject,
                                             &PyOggStreamState_Type);
  if (ret == NULL)
    return NULL;

  ret->stream = ogg_stream_create(serialno);
  if (ret->stream == NULL) {
    PyObject_DEL(ret);
    return NULL;
  }     
  return (PyObject *) ret;
}

PyObject *
PyOggStreamState_New(PyObject *self, PyObject *args)
{
  int serialno;
  if (!PyArg_ParseTuple(args, "i", &serialno))
    return NULL;
  return PyOggStreamState_FromSerialno(serialno);
}

tatic PyObject *
PyOggStreamState_Packetin(PyObject *self, PyObject *args)
{
  int ret;
  PyOggPacketObject *packet;
  
  if (!PyArg_ParseTuple(args, "O!", &PyOggPacket_Type,
                        (PyObject *) &packet))
    return NULL;
  
  ret = ogg_stream_packetin(PyOggStreamState_AsOggStreamState(self), 
                            PyOggPacket_AsOggPacket(packet));
  if (ret == OGG_SUCCESS) {
    Py_INCREF(Py_None);
    return Py_None;
  } 
  if (ret == OGG_EEOS) {
    PyErr_SetString(PyOggError, "EOS has been set on this stream");
    return NULL;
  }
  PyErr_SetString(PyOggError, "error in ogg_stream_packetin");
  return NULL;
}

<p>static PyObject *
PyOggStreamState_Pageout(PyObject *self, PyObject *args)
{
  int ret;
  ogg_page *page;
  
  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = ogg_stream_pageout(PyOggStreamState_AsOggStreamState(self), page);
  if ( ret == 1 ) return PyOggPage_FromOggPage(page);
  Py_INCREF(Py_None);
  return Py_None;
}

<p>static PyObject *
PyOggStreamState_Flush(PyObject *self, PyObject *args)
{
  int ret;
  ogg_page *page;
  
  if (!PyArg_ParseTuple(args, ""))
    return NULL;
  
  ret = ogg_stream_flush(PyOggStreamState_AsOggStreamState(self), page);
  if ( ret == 1 ) return PyOggPage_FromOggPage(page);
  
  Py_INCREF(Py_None);
  return Py_None;
}

<p>static PyObject *
PyOggStreamState_Pagein(PyObject *self, PyObject *args)
{
  int ret;
  PyOggPageObject *page;
  
  if (!PyArg_ParseTuple(args, "O!", &PyOggPage_Type,
                        (PyObject *) page))
    return NULL;
  
  ret = ogg_stream_pagein(PyOggStreamState_AsOggStreamState(self), 
                          PyOggPage_AsOggPage(page));
  if (ret == OGG_SUCCESS) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  if (ret == OGG_ESERIAL) {
    PyErr_SetString(PyOggError, "Page serial does not match stream.");
    return NULL;
  }
  if (ret == OGG_EVERSION) {
    PyErr_SetString(PyOggError, "Unknown Ogg page version.");
    return NULL;
  } 
  PyErr_SetString(PyOggError, "Unknown return from ogg_stream_pagein.");
  return NULL;
}

<p>static PyObject *
PyOggStreamState_Packetout(PyObject *self, PyObject *args)
{
  int ret;
  ogg_packet *packet;
  
  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self), packet);
  if (ret == 1) return PyOggPacket_FromPacket(packet);

  if (ret == 0) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  if (ret == OGG_HOLE ) {
    PyErr_SetString(PyOggError, "Hole in data, stream is desynced.");
    return NULL;
  }
  if (ret == OGG_SPAN) {
    PyErr_SetString(PyOggError, "Stream spans ??.");
    return NULL;
  }
  PyErr_SetString(PyOggError, "Unknown return from ogg_stream_packetout.");
  return NULL;
}

<p>static PyObject *
PyOggStreamState_Packetpeek(PyObject *self, PyObject *args)
{
  int ret;
  ogg_packet *packet;

  ret = ogg_stream_packetout(PyOggStreamState_AsOggStreamState(self), packet);
  if (ret == 1) {
    Py_INCREF(Py_True);
    return Py_True;
  }
  if (ret == 0) {
    Py_INCREF(Py_False);
    return Py_False;
  }
  if (ret == OGG_HOLE ) {
    PyErr_SetString(PyOggError, "Hole in data, stream is desynced.");
    return NULL;
  }
  if (ret == OGG_SPAN) {
    PyErr_SetString(PyOggError, "Stream spans ??.");
    return NULL;
  }
  PyErr_SetString(PyOggError, "Unknown return from ogg_stream_packetout.");
  return NULL;
}

<p>static PyObject *
PyOggStreamState_Reset(PyObject *self, PyObject *args)
{
  int ret;
  int serialno = -1;

  if (!PyArg_ParseTuple(args, "|i", &serialno))
    return NULL;

  if ( serialno == -1 ) 
    ret = ogg_stream_reset(PyOggStreamState_AsOggStreamState(self));
  else 
    ret = ogg_stream_reset_serialno(PyOggStreamState_AsOggStreamState(self),serialno);  

  if ( ret == OGG_SUCCESS ) {
    Py_INCREF(Py_None);
    return Py_None;
  } else {
    PyErr_SetString(PyOggError, "Unknown error while resetting stream");
    return NULL;
  }
}

<p>static PyObject*
PyOggStreamState_Eos(PyObject *self, PyObject *args)
{
  int eos;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  eos = ogg_stream_eos(PyOggStreamState_AsOggStreamState(self));
  if ( eos == 0 ) {
    Py_INCREF(Py_False);
    return Py_False;
  } 
  Py_INCREF(Py_True);
  return Py_True;
}

<p>static PyObject *
PyOggStreamState_Repr(PyObject *self)
{
  char buf[256];

  sprintf(buf, "<OggStreamState at %p>", self); 
  return PyString_FromString(buf);
}

<p><p>1.1                  ogg-python2/src/pyoggstreamstate.h

Index: pyoggstreamstate.h
===================================================================
#ifndef PYOGGSTREAMSTATE_H
#define PYOGGSTREAMSTATE_H

#include <pyogg/pyogg2.h>

typedef struct {
  PyObject_HEAD
  ogg_stream_state *stream;
} PyOggStreamStateObject;

extern PyTypeObject PyOggStreamState_Type;

#define PyOggStreamState_AsOggStreamState(x) (((PyOggStreamStateObject *) (x))->stream)

PyObject *PyOggStreamState_FromSerialno(int);
PyObject *PyOggStreamState_New(PyObject *, PyObject *);

#endif

<p><p>1.1                  ogg-python2/src/pyoggsyncstate.c

Index: pyoggsyncstate.c
===================================================================
#include "pyoggsyncstate.h"
#include "pyoggpage.h"
#include "general.h"
#include "_ogg2module.h"

/*****************************************************************
                            OggSyncState Object
 *****************************************************************/

char PyOggSyncState_Doc[] = "";

tatic void PyOggSyncState_Dealloc(PyObject *);
static PyObject* PyOggSyncState_Getattr(PyObject *, char *);

FDEF(PyOggSyncState_Pagein) "Add an Ogg page to the sync state buffer.";
FDEF(PyOggSyncState_Read) "Output bytes as a python buffer.";
FDEF(PyOggSyncState_Output) "Write bytes to a file.";
FDEF(PyOggSyncState_Reset) "Reset the PyOggSyncState object.";
FDEF(PyOggSyncState_Write) "Append bytes from a string.";
FDEF(PyOggSyncState_Input) "Append bytes from a file.";
FDEF(PyOggSyncState_Pageout) "Add an Ogg page to the syn.";

PyTypeObject PyOggSyncState_Type = {
  PyObject_HEAD_INIT(NULL)
  0,
  "OggSyncState",
  sizeof(PyOggSyncStateObject),
  0,
  
  /* Standard Methods */
  /* (destructor) */ PyOggSyncState_Dealloc,
  /* (printfunc) */ 0,
  /* (getattrfunc) */ PyOggSyncState_Getattr,
  /* (setattrfunc) */ 0,
  /* (cmpfunc) */ 0,
  /* (reprfunc) */ 0,
  
  /* Type Categories */
  0, /* as number */
  0, /* as sequence */
  0, /* as mapping */
  0, /* hash */
  0, /* binary */
  0, /* repr */
  0, /* getattro */
  0, /* setattro */
  0, /* as buffer */
  0, /* tp_flags */
  PyOggSyncState_Doc
};

tatic PyMethodDef PyOggSyncState_methods[] = {
  {"pagein", PyOggSyncState_Pagein,
   METH_VARARGS, PyOggSyncState_Pagein_Doc},
  {"read", PyOggSyncState_Read,
   METH_VARARGS, PyOggSyncState_Read_Doc},
  {"output", PyOggSyncState_Output,
   METH_VARARGS, PyOggSyncState_Output_Doc},
  {"reset", PyOggSyncState_Reset,
   METH_VARARGS, PyOggSyncState_Reset_Doc},
  {"write", PyOggSyncState_Write,
   METH_VARARGS, PyOggSyncState_Write_Doc},
  {"input", PyOggSyncState_Input,
   METH_VARARGS, PyOggSyncState_Input_Doc},
  {"pageout", PyOggSyncState_Pageout,
   METH_VARARGS, PyOggSyncState_Pageout_Doc},
  {NULL, NULL}
};

PyObject *
PyOggSyncState_New(PyObject *self, PyObject *args)
{
  PyOggSyncStateObject *ret;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;
  ret = PyObject_NEW(PyOggSyncStateObject, &PyOggSyncState_Type);

  if (ret == NULL) 
    return NULL;

  ret->sync = ogg_sync_create();
  return (PyObject *) ret;
}

<p>static void 
PyOggSyncState_Dealloc(PyObject *self)
{
  ogg_sync_destroy(PyOggSyncState_AsOggSyncState(self));
  PyObject_DEL(self);
}

<p>/* This should be changed to return pointer, size, etc */
static PyObject* 
PyOggSyncState_Getattr(PyObject *self, char *name)
{
  return Py_FindMethod(PyOggSyncState_methods, self, name);
}

<p>static PyObject *
PyOggSyncState_Pagein(PyObject *self, PyObject *args)
{
  int ret;
  PyOggPageObject *page;

  if (!PyArg_ParseTuple(args, "O!", &PyOggPage_Type,
                        (PyObject *) page))
    return NULL;
  
  ret = ogg_sync_pagein(PyOggSyncState_AsOggSyncState(self),
                        PyOggPage_AsOggPage(page));

  if (ret == OGG_SUCCESS) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  PyErr_SetString(PyOggError, "Unknown return from ogg_sync_pagein.");
  return NULL;
}

<p>static PyObject *
PyOggSyncState_Read(PyObject *self, PyObject *args)
{
  int ret;
  int ask_bytes;
  int got_bytes;
  unsigned char *ogg_buffer;
  char *pybuffer;
  PyObject *pybufferobj;
  
  if (!PyArg_ParseTuple(args, "i", &ask_bytes))
    return NULL;

  got_bytes = ogg_sync_bufferout(PyOggSyncState_AsOggSyncState(self),
                                 &ogg_buffer);
  if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;

  pybufferobj = PyBuffer_New(ask_bytes);
  PyObject_AsWriteBuffer(pybufferobj, (void **) &pybuffer, &got_bytes);
  if ( got_bytes < ask_bytes ) ask_bytes = got_bytes;
  memcpy(pybuffer, ogg_buffer, ask_bytes);
 
  ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
  if (ret == OGG_SUCCESS) return pybufferobj;

  PyErr_SetString(PyOggError, "Unknown return from ogg_sync_read.");
  return NULL;
}
  
static PyObject *
PyOggSyncState_Output(PyObject *self, PyObject *args)
{
  int ret;
  int ask_bytes = -1;
  int got_bytes;
  unsigned char *ogg_buffer;
  FILE *fp;
  PyObject *pyfile;

  if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &pyfile, &ask_bytes))
    return NULL;
  
  fp = PyFile_AsFile(pyfile);
  
  got_bytes = ogg_sync_bufferout(PyOggSyncState_AsOggSyncState(self),
                                 &ogg_buffer);
  if ( ask_bytes < 0 || got_bytes < ask_bytes ) ask_bytes = got_bytes;
  fwrite(ogg_buffer, 1, ask_bytes, fp);

  ret = ogg_sync_read(PyOggSyncState_AsOggSyncState(self), ask_bytes);
  if (ret == OGG_SUCCESS) return PyInt_FromLong(ask_bytes);

  PyErr_SetString(PyOggError, "Unknown return from ogg_sync_read.");
  return NULL;
}

<p>static PyObject *
PyOggSyncState_Reset(PyObject *self, PyObject *args)
{
  int ret;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  ret = ogg_sync_reset(PyOggSyncState_AsOggSyncState(self));
  if (ret == OGG_SUCCESS) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  PyErr_SetString(PyOggError, "Unknown error from ogg_sync_reset.");
  return NULL;
}

<p>static PyObject *
PyOggSyncState_Write(PyObject *self, PyObject *args)
{
  int ret;
  char *bytes;
  int byte_count;
  char *ogg_buffer;

  if (!PyArg_ParseTuple(args, "s#", &bytes, &byte_count))
    return NULL;

  ogg_buffer = ogg_sync_bufferin(PyOggSyncState_AsOggSyncState(self), 
                                 byte_count);
  memcpy(ogg_buffer, bytes, byte_count);
  ret = ogg_sync_wrote(PyOggSyncState_AsOggSyncState(self), byte_count);
  if (ret == OGG_SUCCESS) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  PyErr_SetString(PyOggError, "Unknown error from ogg_sync_wrote.");
  return NULL;
}

<p>static PyObject *
PyOggSyncState_Input(PyObject *self, PyObject *args)
{
  int ret;
  int bytes = 4096;
  char *ogg_buffer;
  PyObject *pyfile;
  FILE *fp;

  if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &pyfile, &bytes))
    return NULL;
  
  fp = PyFile_AsFile(pyfile);

  ogg_buffer = ogg_sync_bufferin(PyOggSyncState_AsOggSyncState(self),
                                 bytes);
  bytes = fread(ogg_buffer, 1, bytes, fp);
  ret = ogg_sync_wrote(PyOggSyncState_AsOggSyncState(self),
                       bytes);
  if ( ret == OGG_SUCCESS ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  PyErr_SetString(PyOggError, "Unknown error from ogg_sync_wrote.");
  return NULL;
}

<p>static PyObject *
PyOggSyncState_Pageout(PyObject *self, PyObject *args) 
{
  int ret;
  ogg_page *page;

  if (!PyArg_ParseTuple(args, ""))
    return NULL;

  page = NULL;
  ret = ogg_sync_pageout(PyOggSyncState_AsOggSyncState(self), page);

  if ( ret == 1 ) return PyOggPage_FromOggPage(page);
  if ( ret == 0 ) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  if (ret == OGG_HOLE ) {
    PyErr_SetString(PyOggError, "Hole in data, stream is desynced.");
    return NULL;
  }
  PyErr_SetString(PyOggError, "Unknown error from ogg_sync_pageout.");
  return NULL;
}

<p><p>1.1                  ogg-python2/src/pyoggsyncstate.h

Index: pyoggsyncstate.h
===================================================================
#ifndef PYOGGSYNCSTATE_H
#define PYOGGSYNCSTATE_H

#include <pyogg/pyogg2.h>                                                       

typedef struct {
  PyObject_HEAD
  ogg_sync_state *sync;
} PyOggSyncStateObject;

#define PyOggSyncState_AsOggSyncState(x) (((PyOggSyncStateObject *) (x))->sync)

extern PyTypeObject PyOggSyncState_Type;

PyObject *PyOggSyncState_New(PyObject *, PyObject *);

#endif

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list