Merge bindings to trunk

This commit is contained in:
Clément Stenac 2005-06-01 22:19:03 +00:00
parent 9160790e0c
commit b3f7a2eadb
19 changed files with 2108 additions and 0 deletions

34
bindings/STATUS Normal file
View File

@ -0,0 +1,34 @@
###########################
# STATUS for VLC bindings #
###########################
* General
---------
* TODO
- Integrate bindings creation with build system
* API
-----
* TODO
- Clean up / Use VLC coding styles
- VLM control
* Python: (Olivier Aubert)
---------
* Implements the mediacontrol API
* TODO
- Fix win32 build
- Clean up glue file
* Java: (Filippo Carone)
-------
* Implements libvlc base API
* Only works with gcj
* TODO
- Fix crash with command line arguments
- Implement mediacontrol
- provide "make install"
* .NET: (jlj)
-------
* Not commited yet :)

View File

@ -0,0 +1 @@
Filippo Carone <filippo[dontspam]@carone.org>

100
bindings/java-gcj/JVLC.java Normal file
View File

@ -0,0 +1,100 @@
/*****************************************************************************
* JVLC.java: global class for vlc Java Bindings
*****************************************************************************
* Copyright (C) 1998-2004 VideoLAN
*
* Authors: Filippo Carone <filippo@carone.org>
*
* 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, USA.
*****************************************************************************/
public class JVLC {
private int id;
public JVLC(String[] args) {
String[] properArgs = new String[args.length + 1];
properArgs[0] = "jvlc";
for (int i = 0; i < args.length; i++)
properArgs[i+1] = args[i];
this.id = create();
init(properArgs);
}
private native int create();
private native int init(String[] args);
public native int addInterface(String moduleName, boolean blocking, boolean startPlay);
public int addInterface(boolean blocking, boolean startPlay) {
return addInterface(null, blocking, startPlay);
}
public native String getVersion();
public native String getError(int errorCode);
public native int die();
public native int cleanUp();
public native int setVariable(JVLCVariable jvlcVariable);
public native JVLCVariable getVariable(String varName); // XXX in progress
public native int addTarget(String URI, String[] options, int insertMode, int position);
public native int play();
public native int pause();
public native int stop();
public native boolean isPlaying();
public native float getPosition();
public native float setPosition(float position);
public native int getTime();
public native int setTime(int seconds, boolean relative);
public native int getLength();
public native float speedFaster();
public native float speedSlower();
public native int getPlaylistIndex();
public native int getPlaylistItems();
public native int playlistNext();
public native int playlistPrev();
public native int playlistClear();
public native int getVolume();
public native int setVolume(int volume);
public native int muteVolume();
public native int fullScreen();
}

View File

@ -0,0 +1,13 @@
public class JVLCBoolVariable extends JVLCVariable {
public JVLCBoolVariable(String name, int value) {
super(name);
if (value != 0) this.value = new Integer(1);
else this.value = new Integer(0);
}
public int getBoolValue() {
return ((Integer)value).intValue();
}
}

View File

@ -0,0 +1,12 @@
public class JVLCFloatVariable extends JVLCVariable {
public JVLCFloatVariable(String name, float value) {
super(name);
this.value = new Float(value);
}
public float getFloatValue() {
return ((Float)value).floatValue();
}
}

View File

@ -0,0 +1,13 @@
public class JVLCIntVariable extends JVLCVariable {
public JVLCIntVariable(String name, int value) {
super(name);
this.value = new Integer(value);
}
public int getIntValue() {
return ((Integer)value).intValue();
}
}

View File

@ -0,0 +1,12 @@
public class JVLCStringVariable extends JVLCVariable {
public JVLCStringVariable(String name, String value) {
super(name);
this.value = value;
}
public String getStringValue() {
return (String)value;
}
}

View File

@ -0,0 +1,12 @@
public class JVLCTimeVariable extends JVLCVariable {
public JVLCTimeVariable(String name, long value) {
super(name);
this.value = new Long(value);
}
public long getTimeValue() {
return ((Long)value).longValue();
}
}

View File

@ -0,0 +1,19 @@
public class JVLCVarValue {
String name;
int OID;
public JVLCVarValue(String name, int OID) {
this.name = name;
this.OID = OID;
}
public String getName() {
return name;
}
public int getOID() {
return OID;
}
}

View File

@ -0,0 +1,12 @@
public class JVLCVarVariable extends JVLCVariable {
public JVLCVarVariable(String name, JVLCVarValue value) {
super(name);
this.value = value;
}
public JVLCVarValue getVarValue() {
return (JVLCVarValue)value;
}
}

View File

@ -0,0 +1,21 @@
public abstract class JVLCVariable {
String name;
Object value;
public JVLCVariable(String name) {
this.name = name;
}
public String getName() {
return name;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}

View File

@ -0,0 +1,28 @@
OBJECTS = VlcClient.o JVLC.o JVLCVariable.o JVLCVarValue.o JVLCVarVariable.o JVLCIntVariable.o JVLCTimeVariable.o JVLCStringVariable.o JVLCFloatVariable.o JVLCBoolVariable.o vlc-glue.o
FLAGS = -I. -I/usr/local/include/vlc -L../../lib -lvlc `top_builddir=../.. ../../vlc-config --libs vlc builtin extern` `top_builddir=../.. ../../vlc-config --cxxflags` --main=VlcClient
JHEADERS = JVLC.h JVLCVariable.h JVLCIntVariable.h JVLCBoolVariable.h JVLCTimeVariable.h JVLCStringVariable.h JVLCFloatVariable.h JVLCVarVariable.h JVLCVarValue.h
JCC=gcj
CXX=g++
JCH=gcjh
DEBUG=-g
VlcClient: $(OBJECTS)
$(JCC) -o jvlc -I. $(OBJECTS) $(DEBUG) $(FLAGS)
VlcClient.class: VlcClient.java
$(JCC) $(DEBUG) -C VlcClient.java
%.o: %.class
$(JCC) $(DEBUG) -c $?
%.class: %.java
$(JCC) $(DEBUG) -C $?
%.h: %.class
$(JCH) $(*F)
vlc-glue.o: $(JHEADERS) vlc-glue.cc
$(CXX) $(DEBUG) -I./ -c vlc-glue.cc
clean:
rm -f jvlc *.o *.class $(JHEADERS) *~

10
bindings/java-gcj/README Normal file
View File

@ -0,0 +1,10 @@
Implementation Notes
--------------------
The union vlc_value_t has been implemented as a hierarchy of classes
which has JVLCVariable.class as the root. All the children of this
class are named JVLC<type>Variable.class and are mapped 1:1 to the
union members with some exceptions: p_address is not implemented since
there's no notion of address in Java, vlc_object_t is not implemented
since I don't know how to represent it in Java and is not defined in
vlc/vlc.h

View File

@ -0,0 +1,12 @@
public class VlcClient {
public static void main(String[] args) {
JVLC vlc = new JVLC(args);
System.out.println(vlc.getVersion());
vlc.addInterface(true, true);
vlc.die();
vlc.cleanUp();
}
}

View File

@ -0,0 +1,300 @@
/* These are a must*/
#include <gcj/cni.h>
#include <vlc/vlc.h>
#include <stdio.h> // for printf
#include <stdlib.h> // for calloc
/* JVLC internal imports, generated by gcjh */
#include "JVLC.h"
#include "JVLCVariable.h"
#include "JVLCIntVariable.h"
#include "JVLCBoolVariable.h"
#include "JVLCFloatVariable.h"
#include "JVLCStringVariable.h"
#include "JVLCTimeVariable.h"
#include "JVLCVarVariable.h"
#include "JVLCVarValue.h"
/* Java classes used throughout here */
#include <java/lang/String.h>
#include <java/lang/Class.h>
#include <java/lang/System.h>
#include <java/io/PrintStream.h>
void setString(jstring orig, char* dest);
jint JVLC::create () {
return VLC_Create();
}
jint JVLC::init(JArray< ::java::lang::String *> *args) {
int argc = 0;
char* arguments[argc];
if (args != NULL) // It's a very bad day otherwise
{
argc = args->length;
arguments[argc];
/*
* convert the JArray<String*>* in char**
* so in a way suitable for VLC_Init
*/
jstring* argsElements = elements(args);
for (int i = 0; i < argc; i++) {
arguments[i] = (char*) malloc(JvGetStringUTFLength(argsElements[i]) + 1);
setString(argsElements[i], arguments[i]);
}
}
return VLC_Init(this->id, argc, arguments);
}
jint JVLC::addInterface(java::lang::String* moduleName, jboolean blocking, jboolean startPlay) {
char* psz_module = NULL;
if (moduleName != NULL) {
psz_module = (char *) malloc(JvGetStringUTFLength(moduleName));
setString(moduleName, psz_module);
}
int i_blocking = 0;
int i_startPlay = 0;
if (blocking) i_blocking = 1;
if (startPlay) i_startPlay = 1;
int addIntf_res = VLC_AddIntf(this->id, (char* const) psz_module, i_blocking, i_startPlay);
if (psz_module != NULL)
free(psz_module);
return addIntf_res;
}
jstring JVLC::getVersion() {
return JvNewStringUTF(VLC_Version());
}
jstring JVLC::getError(jint errorCode) {
return JvNewStringUTF(VLC_Error(errorCode));
}
jint JVLC::die() {
return VLC_Die(this->id);
}
jint JVLC::cleanUp() {
return VLC_CleanUp(this->id);
}
jint JVLC::setVariable(::JVLCVariable *jvlcVariable) {
/* these are the two parameters given the the
* VLC_VariableSet() function
*/
vlc_value_t value;
char* psz_var = NULL;
if (jvlcVariable != NULL) {
jclass variableClass = jvlcVariable->getClass();
/* We use the class name for kinda of instanceof */
jstring className = variableClass->getName();
/**
* VLC_SetVariable takes a union as its second argument.
* The union members are mapped 1:1 to java types which
* extend JVLCVariable. So here we check the runtime type
* of the actual variable and act consequently. Here is the
* mapping:
*
* typedef union
*{
* int i_int; JVLCIntVariable
* vlc_bool_t b_bool; JVLCBoolVariable
* float f_float; JVLCFloatVariable
* char * psz_string; JVLCStringVariable
* void * p_address; -- NOT IMPLEMENTED --
* vlc_object_t * p_object; -- NOT IMPLEMENTED --
* vlc_list_t * p_list; JVLCListVariable XXX:TODO
* signed long long i_time; JVLCTimeVariable
* struct { char *psz_name; int i_object_id; } var; JVLCVarVariable <- this name sucks
* // Make sure the structure is at least 64bits
* struct { char a, b, c, d, e, f, g, h; } padding; <- Do we really need this?
*
* } vlc_value_t;
*/
/* i_int */
if (className->equals(JvNewStringUTF("VLCIntVariable" ))) {
value.i_int = ((::JVLCIntVariable *)jvlcVariable)->getIntValue();
}
/* b_bool */
else if (className->equals(JvNewStringUTF("VLCBoolVariable"))) {
value.b_bool = ((::JVLCBoolVariable *)jvlcVariable)->getBoolValue();
}
/* f_float */
else if (className->equals(JvNewStringUTF("VLCFloatVariable"))) {
value.f_float = ((::JVLCFloatVariable *)jvlcVariable)->getFloatValue();
}
/* psz_string */
else if (className->equals(JvNewStringUTF("VLCStringVariable"))) {
value.psz_string = (char* const) elements((((::JVLCStringVariable *)jvlcVariable)->getStringValue())->toCharArray());
}
/* i_time */
else if (className->equals(JvNewStringUTF("VLCTimeVariable"))) {
value.i_time = ((::JVLCTimeVariable *)jvlcVariable)->getTimeValue();
}
/* var */
else if (className->equals(JvNewStringUTF("VLCVarVariable"))) {
jstring varValueName = ((::JVLCVarVariable *)jvlcVariable)->getVarValue()->getName();
value.var.psz_name = (char *) malloc(JvGetStringUTFLength(varValueName));
setString(varValueName, value.var.psz_name);
value.var.i_object_id = (((::JVLCVarVariable *)jvlcVariable)->getVarValue())->getOID();
}
psz_var = (char *) malloc(JvGetStringUTFLength(jvlcVariable->getName()));
setString(jvlcVariable->getName(), psz_var);
}
return VLC_VariableSet(this->id, (char* const) psz_var, value);
}
jint JVLC::addTarget(::java::lang::String *URI, JArray< ::java::lang::String *> *options, jint insertMode, jint position) {
char* psz_target = NULL;
char** ppsz_options = NULL;
int options_number = 0;
if (URI != NULL) {
psz_target = (char *) malloc( JvGetStringUTFLength(URI));
setString(URI, psz_target);
}
if (options != NULL) {
options_number = options->length;
ppsz_options[options_number];
jstring* jstr_options = elements(options);
for (jint i = 0; i < options_number; i++) {
ppsz_options[i] = (char *) malloc(JvGetStringUTFLength(jstr_options[i]));
setString(jstr_options[i], ppsz_options[i]);
}
}
return VLC_AddTarget(this->id, (char const *)psz_target, (const char **) ppsz_options, options_number, insertMode, position);
}
jint JVLC::play() {
return VLC_Play(this->id);
}
jint JVLC::pause() {
return VLC_Pause(this->id);
}
jint JVLC::stop() {
return VLC_Stop(this->id);
}
jboolean JVLC::isPlaying() {
return VLC_IsPlaying(this->id);
}
jfloat JVLC::getPosition() {
return VLC_PositionGet(this->id);
}
jfloat JVLC::setPosition(jfloat position) {
return VLC_PositionSet(this->id, position);
}
jint JVLC::getTime() {
return VLC_TimeGet(this->id);
}
jint JVLC::setTime(jint seconds, jboolean relative) {
return VLC_TimeSet(this->id, seconds, relative);
}
jint JVLC::getLength() {
return VLC_LengthGet(this->id);
}
jfloat JVLC::speedFaster() {
return VLC_SpeedFaster(this->id);
}
jfloat JVLC::speedSlower() {
return VLC_SpeedSlower(this->id);
}
jint JVLC::getPlaylistIndex() {
return VLC_PlaylistIndex(this->id);
}
jint JVLC::getPlaylistItems() {
return VLC_PlaylistNumberOfItems(this->id);
}
jint JVLC::playlistNext() {
return VLC_PlaylistNext(this->id);
}
jint JVLC::playlistPrev() {
return VLC_PlaylistPrev(this->id);
}
jint JVLC::playlistClear() {
return VLC_PlaylistClear(this->id);
}
jint JVLC::setVolume(jint volume) {
return VLC_VolumeSet(this->id, volume);
}
jint JVLC::getVolume() {
return VLC_VolumeGet(this->id);
}
jint JVLC::muteVolume() {
return VLC_VolumeMute(this->id);
}
jint JVLC::fullScreen() {
return VLC_FullScreen(this->id);
}
/* XXX: in progress */
::JVLCVariable* JVLC::getVariable(::java::lang::String* varName) {
char* const psz_var = (char* const) elements( varName->toCharArray());
vlc_value_t value;
if (VLC_VariableGet(this->id, psz_var, &value) != VLC_SUCCESS) {
// throw exception
return NULL;
}
return NULL;
}
/*
* This is an helper function to convert jstrings to char*s
* setString _assumes_ the char* dest has been allocated
* XXX: should return >= 0 on success, < 0 on error
*/
void setString(jstring orig, char* dest) {
jsize chars = JvGetStringUTFRegion(orig, 0, orig->length(), dest);
dest[chars] = '\0';
}

15
bindings/python/Makefile Normal file
View File

@ -0,0 +1,15 @@
ifdef HOMEDRIVE
COMPILERARG = --compiler=mingw32
else
COMPILERARG =
endif
all:
python setup.py build $(COMPILERARG)
install:
python setup.py install
clean:
$(RM) -rf build

86
bindings/python/setup.py Normal file
View File

@ -0,0 +1,86 @@
from distutils.core import setup, Extension
import os
def get_vlcconfig():
vlcconfig=None
for n in ( 'vlc-config',
os.path.sep.join( ('..', '..', 'vlc-config' ))):
if os.path.exists(n):
vlcconfig=n
break
if vlcconfig is None:
print "*** Warning *** Cannot find vlc-config"
elif os.sys.platform == 'win32':
# Win32 does not know how to invoke the shell itself.
vlcconfig="sh %s" % vlcconfig
return vlcconfig
def get_cflags():
vlcconfig=get_vlcconfig()
if vlcconfig is None:
return []
else:
cflags=os.popen('%s --cflags' % vlcconfig, 'r').readline().rstrip().split()
return cflags
def get_ldflags():
vlcconfig=get_vlcconfig()
if vlcconfig is None:
return []
else:
os.environ['top_builddir'] = '../..'
ldflags=os.popen('%s --libs vlc builtin' % vlcconfig, 'r').readline().rstrip().split()
return ldflags
# To compile in a local vlc tree
vlclocal = Extension('vlc',
sources = ['vlcglue.c', '../../src/control/init.c'],
include_dirs = ['../../include', '../../', '/usr/win32/include' ],
extra_objects = [ '../../lib/libvlc.a' ],
extra_compile_args = get_cflags(),
extra_link_args = [ '-L../..' ] + get_ldflags(),
)
setup (name = 'MediaControl',
version = '0.8.2-1',
scripts = [ 'vlcdebug.py' ],
description = """VLC bindings for python.
This module provides a MediaControl object, which implements an API
inspired from the OMG Audio/Video Stream 1.0 specification. Moreover,
the module provides a Object type, which gives a low-level access to
the vlc objects and their variables.
Example session:
import vlc
mc=vlc.MediaControl(['--verbose', '1'])
mc.playlist_add_item('movie.mpg')
# Start the movie at 2000ms
p=vlc.Position()
p.origin=vlc.RelativePosition
p.key=vlc.MediaTime
p.value=2000
mc.start(p)
# which could be abbreviated as
# mc.start(2000)
# for the default conversion from int is to make a RelativePosition in MediaTime
# Display some text during 2000ms
mc.display_text('Some useless information', 0, 2000)
# Pause the video
mc.pause(0)
# Get status information
mc.get_stream_information()
# Access lowlevel objets
o=vlc.Object(1)
o.info()
i=o.find_object('input')
i.list()
i.get('time')
""",
ext_modules = [ vlclocal ])

View File

@ -0,0 +1,66 @@
"""Wrapper around vlc module in order to ease the use of vlc.Object
class (completion in ipython, access variable as attributes, etc).
"""
import vlc
class VLCObject(object):
def __init__(self, id):
object.__setattr__(self, '_o', vlc.Object(id))
def find(self, typ):
t=self._o.find_object(typ)
if t is not None:
return VLCObject(t.info()['object-id'])
else:
return None
def __str__(self):
i=self._o.info()
return "VLCObject %d (%s) : %s" % (i['object-id'],
i['object-type'],
i['object-name'])
def tree(self, prefix=" "):
"""Displays the children as a tree."""
print prefix, self
for i in self._o.children():
t=VLCObject(i)
t.tree(prefix=prefix + " ")
return
def __getattribute__(self, attr):
#print "Getting %s" % attr
if attr == '__members__':
o=object.__getattribute__(self, '_o')
l=dir(o)
l.extend([ n.replace('-','_') for n in o.list() ])
return l
try:
return object.__getattribute__ (self, attr)
except AttributeError, e:
try:
return self._o.__getattribute__ (attr)
except AttributeError, e:
attr=attr.replace('_', '-')
if attr in self._o.list():
return self._o.get(attr)
else:
raise e
def __setattr__(self, name, value):
n=name.replace('_', '-')
if n in self._o.list():
self._o.set(n, value)
else:
object.__setattr__(self, name, value)
#mc=vlc.MediaControl()
#mc.playlist_add_item('/tmp/k.mpg')
#mc.start(0)
def test():
global mc,o
mc=vlc.MediaControl()
mc.playlist_add_item('/tmp/k.mpg')
mc.start(0)
o=VLCObject(0)

1342
bindings/python/vlcglue.c Normal file

File diff suppressed because it is too large Load Diff