Commit 68aa3ca3 authored by Clément Stenac's avatar Clément Stenac

Merge 0.8.5-api changes

Fix compilation
parent 91c8dba0
......@@ -63,14 +63,15 @@ pkgincludedir = $(includedir)/vlc
dist_pkginclude_HEADERS = \
include/vlc/vlc.h \
include/vlc/libvlc.h \
include/vlc/aout.h \
include/vlc/vout.h \
include/vlc/sout.h \
include/vlc/decoder.h \
include/vlc/input.h \
include/vlc/intf.h \
include/vlc/control.h \
include/vlc/control_structures.h \
include/vlc/mediacontrol.h \
include/vlc/mediacontrol_structures.h \
$(NULL)
noinst_HEADERS = $(HEADERS_include)
......@@ -105,7 +106,6 @@ HEADERS_include = \
include/vlc_codec.h \
include/vlc_common.h \
include/vlc_config.h \
include/vlc_control.h \
include/vlc_cpu.h \
include/vlc_demux.h \
include/vlc_error.h \
......@@ -137,6 +137,8 @@ HEADERS_include = \
include/vlc_xml.h \
include/vout_synchro.h \
include/win32_specific.h \
include/libvlc_internal.h \
include/mediacontrol_internal.h
$(NULL)
src/misc/modules_builtin.h: Makefile src/misc/modules_builtin.h.in vlc-config
......@@ -471,12 +473,15 @@ SOURCES_libvlc_common = \
src/misc/version.c \
src/extras/libc.c \
src/control/core.c \
src/control/util.c \
src/control/audio_video.c \
src/control/playlist.c \
src/control/input.c \
src/control/mediacontrol_core.c \
src/control/mediacontrol_util.c \
src/control/mediacontrol_audio_video.c \
$(NULL)
# These should be distributed, but not compiled
EXTRA_DIST += src/control/init.c src/control/plugin.c
EXTRA_DIST += src/control/mediacontrol_init.c src/control/mediacontrol_plugin.c
SOURCES_libvlc = \
$(SOURCES_libvlc_common) \
......
......@@ -48,7 +48,7 @@ def get_ldflags():
# To compile in a local vlc tree
vlclocal = Extension('vlc',
sources = ['vlcglue.c',
'../../src/control/init.c'],
'../../src/control/mediacontrol_init.c'],
include_dirs = ['../../include', '../../', '/usr/win32/include' ],
extra_objects = [ '../../lib/libvlc_pic.a' ],
extra_compile_args = get_cflags(),
......
......@@ -29,8 +29,8 @@
#include <stdio.h>
#include <vlc/vlc.h>
#include <vlc/control_structures.h>
#include <vlc/control.h>
#include <vlc/mediacontrol_structures.h>
#include <vlc/mediacontrol.h>
#define SELF ((MediaControl*)self)
......
/*****************************************************************************
* libvlc_internal.h : Definition of opaque structures for libvlc exported API
* Also contains some internal utility functions
*****************************************************************************
* Copyright (C) 2005 the VideoLAN team
* $Id: control_structures.h 13752 2005-12-15 10:14:42Z oaubert $
*
* Authors: Clément Stenac <zorglub@videolan.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.
*****************************************************************************/
#ifndef _LIBVLC_INTERNAL_H
#define _LIBVLC_INTERNAL_H 1
# ifdef __cplusplus
extern "C" {
# endif
#include <vlc/vlc.h>
struct libvlc_instance_t
{
vlc_t *p_vlc;
playlist_t *p_playlist;
int i_vlc_id;
};
struct libvlc_input_t
{
int i_input_id; ///< Input object id. We don't use a pointer to
/// avoid any crash
struct libvlc_instance_t *p_instance; ///< Parent instance
};
# ifdef __cplusplus
}
# endif
#endif
......@@ -21,15 +21,15 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifndef _VLC_PRIVATE_CONTROL_H
#define _VLC_PRIVATE_CONTROL_H 1
#ifndef _VLC_MEDIACONTROL_INTERNAL_H
#define _VLC_MEDIACONTROL_INTERNAL_H 1
# ifdef __cplusplus
extern "C" {
# endif
#include <vlc/vlc.h>
#include "vlc/control_structures.h"
#include "vlc/mediacontrol_structures.h"
typedef struct {
vlc_object_t *p_vlc;
......
/*****************************************************************************
* libvlc.h: libvlc_* new external API
*****************************************************************************
* Copyright (C) 1998-2005 the VideoLAN team
* $Id: vlc.h 13701 2005-12-12 17:58:56Z zorglub $
*
* Authors: Clément Stenac <zorglub@videolan.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.
*****************************************************************************/
/**
* \defgroup libvlc Libvlc
* This is libvlc, the base library of the VLC program.
*
* @{
*/
#ifndef _LIBVLC_H
#define _LIBVLC_H 1
#include <vlc/vlc.h>
# ifdef __cplusplus
extern "C" {
# endif
/*****************************************************************************
* Exception handling
*****************************************************************************/
/** defgroup libvlc_exception Exceptions
* \ingroup libvlc
* LibVLC Exceptions handling
* @{
*/
struct libvlc_exception_t
{
int b_raised;
char *psz_message;
};
typedef struct libvlc_exception_t libvlc_exception_t;
/**
* Initialize an exception structure. This can be called several times to reuse
* an exception structure.
* \param p_exception the exception to initialize
*/
void libvlc_exception_init( libvlc_exception_t *p_exception );
/**
* Has an exception been raised ?
* \param p_exception the exception to query
* \return 0 if no exception raised, 1 else
*/
int libvlc_exception_raised( libvlc_exception_t *p_exception );
/**
* Get exception message
* \param p_exception the exception to query
* \return the exception message or NULL if not applicable (exception not raised
* for example)
*/
char* libvlc_exception_get_message( libvlc_exception_t *p_exception );
/** @} */
/*****************************************************************************
* Core handling
*****************************************************************************/
/** defgroup libvlc_core Core
* \ingroup libvlc
* LibVLC Core
* @{
*/
/** This structure is opaque. It represents a libvlc instance */
typedef struct libvlc_instance_t libvlc_instance_t;
/**
* Create an initialized libvlc instance
* \param argc the number of arguments
* \param argv command-line-type arguments
* \param exception an initialized exception pointer
*/
libvlc_instance_t * libvlc_new( int , char **, libvlc_exception_t *);
/**
* Destroy a libvlc instance
* \param p_instance the instance to destroy
*/
void libvlc_destroy( libvlc_instance_t *);
/** @}*/
/*****************************************************************************
* Playlist
*****************************************************************************/
/** defgroup libvlc_playlist Playlist
* \ingroup libvlc
* LibVLC Playlist handling
* @{
*/
/**
* Start playing. You can give some additionnal playlist item options
* that will be added to the item before playing it.
* \param p_instance the instance
* \param i_options the number of options to add to the item
* \param ppsz_options the options to add to the item
* \param p_exception an initialized exception
*/
void libvlc_playlist_play( libvlc_instance_t*, int, char **,
libvlc_exception_t * );
typedef struct libvlc_input_t libvlc_input_t;
///\todo document me
libvlc_input_t *libvlc_playlist_get_input( libvlc_instance_t *,
libvlc_exception_t * );
/** @}*/
/*****************************************************************************
* Input
*****************************************************************************/
/** defgroup libvlc_input Input
* \ingroup libvlc
* LibVLC Input handling
* @{
*/
/** Free an input object
* \param p_input the input to free
*/
void libvlc_input_free( libvlc_input_t * );
/// \bug This might go away ... to be replaced by a broader system
vlc_int64_t libvlc_input_get_length( libvlc_input_t *, libvlc_exception_t *);
vlc_int64_t libvlc_input_get_time( libvlc_input_t *, libvlc_exception_t *);
float libvlc_input_get_position( libvlc_input_t *, libvlc_exception_t *);
/** @} */
# ifdef __cplusplus
}
# endif
#endif /* <vlc/vlc_control.h> */
......@@ -34,7 +34,7 @@ extern "C" {
#define WINDOWHANDLE int
#endif
#include <vlc/control_structures.h>
#include <vlc/mediacontrol_structures.h>
/************************************************************************
* Position Object Manipulation
......
/*****************************************************************************
* vlc.h: global header for vlc
* vlc.h: global header for libvlc (old-style)
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
* $Id$
......@@ -25,8 +25,9 @@
*****************************************************************************/
/**
* \defgroup libvlc Libvlc
* \defgroup libvlc_old Libvlc Old
* This is libvlc, the base library of the VLC program.
* This is the legacy API. Please consider using the new libvlc API
*
* @{
*/
......
......@@ -419,6 +419,7 @@ typedef struct vlc_meta_t vlc_meta_t;
typedef struct counter_t counter_t;
typedef struct counter_sample_t counter_sample_t;
typedef struct stats_handler_t stats_handler_t;
typedef struct input_stats_t input_stats_t;
/*****************************************************************************
......
/*****************************************************************************
* core.c: Core functions : init, playlist, stream management
* core.c: Core libvlc new API functions : initialization, exceptions handling
*****************************************************************************
* Copyright (C) 2005 the VideoLAN team
* $Id$
*
* Authors: Olivier Aubert <olivier.aubert@liris.univ-lyon1.fr>
* Authors: Clment Stenac <zorglub@videolan.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
......@@ -21,413 +21,92 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <vlc_control.h>
#include <vlc/control.h>
#include <libvlc_internal.h>
#include <vlc/libvlc.h>
#include <vlc/intf.h>
#include <vlc/vout.h>
#include <vlc/aout.h>
#include <vlc_demux.h>
#include <vlc_osd.h>
#define HAS_SNAPSHOT 1
#ifdef HAS_SNAPSHOT
#include <snapshot.h>
#endif
#include <stdlib.h> /* malloc(), free() */
#include <string.h>
#include <errno.h> /* ENOMEM */
#include <stdio.h>
#include <ctype.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#define RAISE( c, m ) exception->code = c; \
exception->message = strdup(m);
vlc_t * vlc_current_object( int );
mediacontrol_Instance* mediacontrol_new_from_object( int vlc_object_id,
mediacontrol_Exception *exception )
{
mediacontrol_Instance* retval;
vlc_object_t *p_vlc;
vlc_object_t *p_object;
p_object = ( vlc_object_t* )vlc_current_object( vlc_object_id );
if( ! p_object )
{
RAISE( mediacontrol_InternalException, "Unable to find vlc object" );
return NULL;
}
p_vlc = vlc_object_find( p_object, VLC_OBJECT_ROOT, FIND_PARENT );
if( ! p_vlc )
{
RAISE( mediacontrol_InternalException, "Unable to initialize VLC" );
return NULL;
}
retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
retval->p_vlc = p_vlc;
retval->vlc_object_id = p_vlc->i_object_id;
/* We can keep references on these, which should not change. Is it true ? */
retval->p_playlist = vlc_object_find( p_vlc,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE );
if( ! retval->p_playlist || ! retval->p_intf )
{
RAISE( mediacontrol_InternalException, "No available interface" );
return NULL;
}
return retval;
};
/**************************************************************************
* Playback management
**************************************************************************/
mediacontrol_Position*
mediacontrol_get_media_position( mediacontrol_Instance *self,
const mediacontrol_PositionOrigin an_origin,
const mediacontrol_PositionKey a_key,
mediacontrol_Exception *exception )
/*************************************************************************
* Exceptions handling
*************************************************************************/
inline void libvlc_exception_init( libvlc_exception_t *p_exception )
{
mediacontrol_Position* retval;
vlc_value_t val;
input_thread_t * p_input = self->p_playlist->p_input;
exception = mediacontrol_exception_init( exception );
retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
retval->origin = an_origin;
retval->key = a_key;
if( ! p_input )
{
RAISE( mediacontrol_InternalException, "No input thread." );
return NULL;
}
if( an_origin != mediacontrol_AbsolutePosition )
{
/* Relative or ModuloPosition make no sense */
RAISE( mediacontrol_PositionOriginNotSupported, "Only absolute position is valid." );
return NULL;
}
/* We are asked for an AbsolutePosition. */
val.i_time = 0;
var_Get( p_input, "time", &val );
/* FIXME: check val.i_time > 0 */
retval->value = mediacontrol_unit_convert( p_input,
mediacontrol_MediaTime,
a_key,
val.i_time / 1000 );
return retval;
p_exception->b_raised = 0;
p_exception->psz_message = NULL;
}
/* Sets the media position */
void
mediacontrol_set_media_position( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
inline int libvlc_exception_raised( libvlc_exception_t *p_exception )
{
vlc_value_t val;
input_thread_t * p_input = self->p_playlist->p_input;
exception=mediacontrol_exception_init( exception );
if( ! p_input )
{
RAISE( mediacontrol_InternalException, "No input thread." );
return;
}
if( !var_GetBool( p_input, "seekable" ) )
{
RAISE( mediacontrol_InvalidPosition, "Stream not seekable" );
return;
}
val.i_time = mediacontrol_position2microsecond( p_input, a_position );
var_Set( p_input, "time", val );
return;
return p_exception->b_raised;
}
/* Starts playing a stream */
/*
* Known issues: since moving in the playlist using playlist_Next
* or playlist_Prev implies starting to play items, the a_position
* argument will be only honored for the 1st item in the list.
*
* XXX:FIXME split moving in the playlist and playing items two
* different actions or make playlist_<Next|Prev> accept a time
* value to start to play from.
*/
void
mediacontrol_start( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
inline char* libvlc_exception_get_message( libvlc_exception_t *p_exception )
{
playlist_t * p_playlist = self->p_playlist;
exception = mediacontrol_exception_init( exception );
if( ! p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No available playlist" );
return;
}
vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->i_size )
{
int i_index;
int i_from;
char * psz_from = ( char * )malloc( 20 * sizeof( char ) );
i_from = mediacontrol_position2microsecond( p_playlist->p_input, a_position ) / 1000000;
i_index = p_playlist->i_index;
if( i_index < 0 )
{
/* We know that there is at least 1 element, since i_size != 0 */
i_index = 0;
}
/* Set start time */
snprintf( psz_from, 20, "start-time=%i", i_from );
playlist_ItemAddOption( p_playlist->pp_items[i_index], psz_from );
free( psz_from );
vlc_mutex_unlock( &p_playlist->object_lock );
playlist_Play( p_playlist );
}
else
if( p_exception->b_raised == 1 && p_exception->psz_message )
{
RAISE( mediacontrol_PlaylistException, "Empty playlist." );
vlc_mutex_unlock( &p_playlist->object_lock );
}
return;
}
void
mediacontrol_pause( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = self->p_playlist->p_input;
/* FIXME: use the a_position parameter */
exception=mediacontrol_exception_init( exception );
if( p_input != NULL )
{
var_SetInteger( p_input, "state", PAUSE_S );
}
else
{
RAISE( mediacontrol_InternalException, "No input" );
}
return;
}
void
mediacontrol_resume( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = self->p_playlist->p_input;
/* FIXME: use the a_position parameter */
exception=mediacontrol_exception_init( exception );
if( p_input != NULL )
{
var_SetInteger( p_input, "state", PAUSE_S );
}
else
{
RAISE( mediacontrol_InternalException, "No input" );
return p_exception->psz_message;
}
return NULL;
}
void
mediacontrol_stop( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
char *psz_message )
{
/* FIXME: use the a_position parameter */
exception=mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
return;
}
playlist_Stop( self->p_playlist );
if( p_exception == NULL ) return;
p_exception->b_raised = 1;
p_exception->psz_message = strdup( psz_message );
}
/**************************************************************************
* Playlist management
**************************************************************************/
void
mediacontrol_playlist_add_item( mediacontrol_Instance *self,
const char * psz_file,
mediacontrol_Exception *exception )
libvlc_instance_t * libvlc_new( int argc, char **argv,
libvlc_exception_t *p_exception )
{
exception=mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_InternalException, "No playlist" );
return;
}
int i_vlc_id;
libvlc_instance_t *p_new;
vlc_t *p_vlc;
playlist_Add( self->p_playlist, psz_file, psz_file , PLAYLIST_INSERT,
PLAYLIST_END );
}
i_vlc_id = VLC_Create();
p_vlc = (vlc_t* ) vlc_current_object( i_vlc_id );
void
mediacontrol_playlist_next_item( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
exception=mediacontrol_exception_init( exception );
if ( !self->p_playlist )
if( !p_vlc )
{
RAISE( mediacontrol_InternalException, "No playlist" );
return;
}
playlist_Next( self->p_playlist );
return;
}
void
mediacontrol_playlist_clear( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
exception=mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
return;
libvlc_exception_raise( p_exception, "VLC initialization failed" );
return NULL;
}
p_new = (libvlc_instance_t *)malloc( sizeof( libvlc_instance_t ) );
playlist_Clear( self->p_playlist );
return;
}
mediacontrol_PlaylistSeq *
mediacontrol_playlist_get_list( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
mediacontrol_PlaylistSeq *retval;
int i_index;
playlist_t * p_playlist = self->p_playlist;
int i_playlist_size;
/** \todo Look for interface settings. If we don't have any, add -I dummy */
/* Because we probably don't want a GUI by default */
exception=mediacontrol_exception_init( exception );
if( !p_playlist )
if( !p_new )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
libvlc_exception_raise( p_exception, "Out of memory" );
return NULL;
}
vlc_mutex_lock( &p_playlist->object_lock );
i_playlist_size = p_playlist->i_size;
VLC_Init( i_vlc_id, argc, argv );
retval = mediacontrol_PlaylistSeq__alloc( i_playlist_size );
p_new->p_vlc = p_vlc;
p_new->p_playlist = (playlist_t *)vlc_object_find( p_new->p_vlc,
VLC_OBJECT_PLAYLIST, FIND_CHILD );
for( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
if( !p_new->p_playlist )
{
retval->data[i_index] = strdup( p_playlist->pp_items[i_index]->input.psz_uri );
libvlc_exception_raise( p_exception, "Playlist creation failed" );
return NULL;
}
vlc_mutex_unlock( &p_playlist->object_lock );
p_new->i_vlc_id = i_vlc_id;
return retval;
return p_new;
}
/***************************************************************************
* Status feedback
***************************************************************************/
mediacontrol_StreamInformation *
mediacontrol_get_stream_information( mediacontrol_Instance *self,
mediacontrol_PositionKey a_key,
mediacontrol_Exception *exception )
void libvlc_destroy( libvlc_instance_t *p_instance )
{
mediacontrol_StreamInformation *retval;
input_thread_t *p_input = self->p_playlist->p_input;
vlc_value_t val;
retval = ( mediacontrol_StreamInformation* )malloc( sizeof( mediacontrol_StreamInformation ) );
if( ! retval )
{
RAISE( mediacontrol_InternalException, "Out of memory" );
return NULL;
}
if( ! p_input )
{
/* No p_input defined */
retval->streamstatus = mediacontrol_UndefinedStatus;
retval->url = strdup( "None" );
retval->position = 0;
retval->length = 0;
}
else
{
switch( var_GetInteger( p_input, "state" ) )
{
case PLAYING_S :
retval->streamstatus = mediacontrol_PlayingStatus;
break;
case PAUSE_S :
retval->streamstatus = mediacontrol_PauseStatus;
break;
case INIT_S :
retval->streamstatus = mediacontrol_InitStatus;
break;
case END_S :
retval->streamstatus = mediacontrol_EndStatus;
break;
default :
retval->streamstatus = mediacontrol_UndefinedStatus;
break;
}
retval->url = strdup( p_input->input.p_item->psz_uri );
/* TIME and LENGTH are in microseconds. We want them in ms */
var_Get( p_input, "time", &val);
retval->position = val.i_time / 1000;
var_Get( p_input, "length", &val);
retval->length = val.i_time / 1000;
retval->position = mediacontrol_unit_convert( p_input,
mediacontrol_MediaTime, a_key,
retval->position );
retval->length = mediacontrol_unit_convert( p_input,
mediacontrol_MediaTime, a_key,
retval->length );
}
return retval;
if( p_instance->p_playlist )
vlc_object_release( p_instance->p_playlist );
vlc_object_release( p_instance->p_vlc );
VLC_CleanUp( p_instance->i_vlc_id );
VLC_Destroy( p_instance->i_vlc_id );
}
/*****************************************************************************
* input.c: Libvlc new API input management functions
*****************************************************************************
* Copyright (C) 2005 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.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.
*****************************************************************************/
#include <libvlc_internal.h>
#include <vlc/libvlc.h>
#include <vlc/intf.h>
void libvlc_input_free( libvlc_input_t *p_input )
{
if( p_input )
free( p_input );
}
/**************************************************************************
* Getters for stream information
**************************************************************************/
vlc_int64_t libvlc_input_get_length( libvlc_input_t *p_input,
libvlc_exception_t *p_exception )
{
input_thread_t *p_input_thread;
vlc_value_t val;
if( !p_input )
{
libvlc_exception_raise( p_exception, "Input is NULL" );
return -1;
}
p_input_thread = (input_thread_t*)vlc_object_get(
p_input->p_instance->p_vlc,
p_input->i_input_id );
if( !p_input_thread )
{
libvlc_exception_raise( p_exception, "Input does not exist" );
return -1;
}
var_Get( p_input_thread, "length", &val );
vlc_object_release( p_input_thread );
return val.i_time / 1000;
}
vlc_int64_t libvlc_input_get_time( libvlc_input_t *p_input,
libvlc_exception_t *p_exception )
{
input_thread_t *p_input_thread;
vlc_value_t val;
if( !p_input )
{
libvlc_exception_raise( p_exception, "Input is NULL" );
return -1;
}
p_input_thread = (input_thread_t*)vlc_object_get(
p_input->p_instance->p_vlc,
p_input->i_input_id );
if( !p_input_thread )
{
libvlc_exception_raise( p_exception, "Input does not exist" );
return -1;
}
var_Get( p_input_thread , "time", &val );
vlc_object_release( p_input_thread );
return val.i_time / 1000;
}
float libvlc_input_get_position( libvlc_input_t *p_input,
libvlc_exception_t *p_exception )
{
input_thread_t *p_input_thread;
vlc_value_t val;
if( !p_input )
{
libvlc_exception_raise( p_exception, "Input is NULL" );
return -1;
}
p_input_thread = (input_thread_t*)vlc_object_get(
p_input->p_instance->p_vlc,
p_input->i_input_id );
if( !p_input_thread )
{
libvlc_exception_raise( p_exception, "Input does not exist" );
return -1.0;
}
var_Get( p_input_thread, "position", &val );
vlc_object_release( p_input_thread );
return val.f_float;
}
......@@ -21,9 +21,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <vlc_control.h>
#include <mediacontrol_internal.h>
#include <vlc/control.h>
#include <vlc/mediacontrol.h>
#include <vlc/intf.h>
#include <vlc/vout.h>
......
/*****************************************************************************
* core.c: Core functions : init, playlist, stream management
*****************************************************************************
* Copyright (C) 2005 the VideoLAN team
* $Id$
*
* Authors: Olivier Aubert <olivier.aubert@liris.univ-lyon1.fr>
*
* 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.
*****************************************************************************/
#include <mediacontrol_internal.h>
#include <vlc/mediacontrol.h>
#include <vlc/intf.h>
#include <vlc/vout.h>
#include <vlc/aout.h>
#include <vlc_demux.h>
#include <vlc_osd.h>
#define HAS_SNAPSHOT 1
#ifdef HAS_SNAPSHOT
#include <snapshot.h>
#endif
#include <stdlib.h> /* malloc(), free() */
#include <string.h>
#include <errno.h> /* ENOMEM */
#include <stdio.h>
#include <ctype.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#define RAISE( c, m ) exception->code = c; \
exception->message = strdup(m);
vlc_t * vlc_current_object( int );
mediacontrol_Instance* mediacontrol_new_from_object( int vlc_object_id,
mediacontrol_Exception *exception )
{
mediacontrol_Instance* retval;
vlc_object_t *p_vlc;
vlc_object_t *p_object;
p_object = ( vlc_object_t* )vlc_current_object( vlc_object_id );
if( ! p_object )
{
RAISE( mediacontrol_InternalException, "Unable to find vlc object" );
return NULL;
}
p_vlc = vlc_object_find( p_object, VLC_OBJECT_ROOT, FIND_PARENT );
if( ! p_vlc )
{
RAISE( mediacontrol_InternalException, "Unable to initialize VLC" );
return NULL;
}
retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
retval->p_vlc = p_vlc;
retval->vlc_object_id = p_vlc->i_object_id;
/* We can keep references on these, which should not change. Is it true ? */
retval->p_playlist = vlc_object_find( p_vlc,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
retval->p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_ANYWHERE );
if( ! retval->p_playlist || ! retval->p_intf )
{
RAISE( mediacontrol_InternalException, "No available interface" );
return NULL;
}
return retval;
};
/**************************************************************************
* Playback management
**************************************************************************/
mediacontrol_Position*
mediacontrol_get_media_position( mediacontrol_Instance *self,
const mediacontrol_PositionOrigin an_origin,
const mediacontrol_PositionKey a_key,
mediacontrol_Exception *exception )
{
mediacontrol_Position* retval;
vlc_value_t val;
input_thread_t * p_input = self->p_playlist->p_input;
exception = mediacontrol_exception_init( exception );
retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
retval->origin = an_origin;
retval->key = a_key;
if( ! p_input )
{
RAISE( mediacontrol_InternalException, "No input thread." );
return NULL;
}
if( an_origin != mediacontrol_AbsolutePosition )
{
/* Relative or ModuloPosition make no sense */
RAISE( mediacontrol_PositionOriginNotSupported, "Only absolute position is valid." );
return NULL;
}
/* We are asked for an AbsolutePosition. */
val.i_time = 0;
var_Get( p_input, "time", &val );
/* FIXME: check val.i_time > 0 */
retval->value = mediacontrol_unit_convert( p_input,
mediacontrol_MediaTime,
a_key,
val.i_time / 1000 );
return retval;
}
/* Sets the media position */
void
mediacontrol_set_media_position( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
vlc_value_t val;
input_thread_t * p_input = self->p_playlist->p_input;
exception=mediacontrol_exception_init( exception );
if( ! p_input )
{
RAISE( mediacontrol_InternalException, "No input thread." );
return;
}
if( !var_GetBool( p_input, "seekable" ) )
{
RAISE( mediacontrol_InvalidPosition, "Stream not seekable" );
return;
}
val.i_time = mediacontrol_position2microsecond( p_input, a_position );
var_Set( p_input, "time", val );
return;
}
/* Starts playing a stream */
/*
* Known issues: since moving in the playlist using playlist_Next
* or playlist_Prev implies starting to play items, the a_position
* argument will be only honored for the 1st item in the list.
*
* XXX:FIXME split moving in the playlist and playing items two
* different actions or make playlist_<Next|Prev> accept a time
* value to start to play from.
*/
void
mediacontrol_start( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
playlist_t * p_playlist = self->p_playlist;
exception = mediacontrol_exception_init( exception );
if( ! p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No available playlist" );
return;
}
vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->i_size )
{
int i_index;
int i_from;
char * psz_from = ( char * )malloc( 20 * sizeof( char ) );
i_from = mediacontrol_position2microsecond( p_playlist->p_input, a_position ) / 1000000;
i_index = p_playlist->i_index;
if( i_index < 0 )
{
/* We know that there is at least 1 element, since i_size != 0 */
i_index = 0;
}
/* Set start time */
snprintf( psz_from, 20, "start-time=%i", i_from );
playlist_ItemAddOption( p_playlist->pp_items[i_index], psz_from );
free( psz_from );
vlc_mutex_unlock( &p_playlist->object_lock );
playlist_Play( p_playlist );
}
else
{
RAISE( mediacontrol_PlaylistException, "Empty playlist." );
vlc_mutex_unlock( &p_playlist->object_lock );
}
return;
}
void
mediacontrol_pause( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = self->p_playlist->p_input;
/* FIXME: use the a_position parameter */
exception=mediacontrol_exception_init( exception );
if( p_input != NULL )
{
var_SetInteger( p_input, "state", PAUSE_S );
}
else
{
RAISE( mediacontrol_InternalException, "No input" );
}
return;
}
void
mediacontrol_resume( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = self->p_playlist->p_input;
/* FIXME: use the a_position parameter */
exception=mediacontrol_exception_init( exception );
if( p_input != NULL )
{
var_SetInteger( p_input, "state", PAUSE_S );
}
else
{
RAISE( mediacontrol_InternalException, "No input" );
}
}
void
mediacontrol_stop( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
/* FIXME: use the a_position parameter */
exception=mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
return;
}
playlist_Stop( self->p_playlist );
}
/**************************************************************************
* Playlist management
**************************************************************************/
void
mediacontrol_playlist_add_item( mediacontrol_Instance *self,
const char * psz_file,
mediacontrol_Exception *exception )
{
exception=mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_InternalException, "No playlist" );
return;
}
playlist_Add( self->p_playlist, psz_file, psz_file , PLAYLIST_INSERT,
PLAYLIST_END );
}
void
mediacontrol_playlist_next_item( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
exception=mediacontrol_exception_init( exception );
if ( !self->p_playlist )
{
RAISE( mediacontrol_InternalException, "No playlist" );
return;
}
playlist_Next( self->p_playlist );
return;
}
void
mediacontrol_playlist_clear( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
exception=mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
return;
}
playlist_Clear( self->p_playlist );
return;
}
mediacontrol_PlaylistSeq *
mediacontrol_playlist_get_list( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
mediacontrol_PlaylistSeq *retval;
int i_index;
playlist_t * p_playlist = self->p_playlist;
int i_playlist_size;
exception=mediacontrol_exception_init( exception );
if( !p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
return NULL;
}
vlc_mutex_lock( &p_playlist->object_lock );
i_playlist_size = p_playlist->i_size;
retval = mediacontrol_PlaylistSeq__alloc( i_playlist_size );
for( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
{
retval->data[i_index] = strdup( p_playlist->pp_items[i_index]->input.psz_uri );
}
vlc_mutex_unlock( &p_playlist->object_lock );
return retval;
}
/***************************************************************************
* Status feedback
***************************************************************************/
mediacontrol_StreamInformation *
mediacontrol_get_stream_information( mediacontrol_Instance *self,
mediacontrol_PositionKey a_key,
mediacontrol_Exception *exception )
{
mediacontrol_StreamInformation *retval;
input_thread_t *p_input = self->p_playlist->p_input;
vlc_value_t val;
retval = ( mediacontrol_StreamInformation* )malloc( sizeof( mediacontrol_StreamInformation ) );
if( ! retval )
{
RAISE( mediacontrol_InternalException, "Out of memory" );
return NULL;
}
if( ! p_input )
{
/* No p_input defined */
retval->streamstatus = mediacontrol_UndefinedStatus;
retval->url = strdup( "None" );
retval->position = 0;
retval->length = 0;
}
else
{
switch( var_GetInteger( p_input, "state" ) )
{
case PLAYING_S :
retval->streamstatus = mediacontrol_PlayingStatus;
break;
case PAUSE_S :
retval->streamstatus = mediacontrol_PauseStatus;
break;
case INIT_S :
retval->streamstatus = mediacontrol_InitStatus;
break;
case END_S :
retval->streamstatus = mediacontrol_EndStatus;
break;
default :
retval->streamstatus = mediacontrol_UndefinedStatus;
break;
}
retval->url = strdup( p_input->input.p_item->psz_uri );
/* TIME and LENGTH are in microseconds. We want them in ms */
var_Get( p_input, "time", &val);
retval->position = val.i_time / 1000;
var_Get( p_input, "length", &val);
retval->length = val.i_time / 1000;
retval->position = mediacontrol_unit_convert( p_input,
mediacontrol_MediaTime, a_key,
retval->position );
retval->length = mediacontrol_unit_convert( p_input,
mediacontrol_MediaTime, a_key,
retval->length );
}
return retval;
}
#define __VLC__
#include <vlc_control.h>
#include <vlc/control.h>
#include <mediacontrol_internal.h>
#include <vlc/mediacontrol.h>
mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *exception )
{
......
#include <vlc_control.h>
#include <vlc/control.h>
#include <mediacontrol_internal.h>
#include <vlc/mediacontrol.h>
#include <vlc/intf.h>
mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *exception )
......
......@@ -21,8 +21,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <vlc_control.h>
#include <vlc/control.h>
#include <mediacontrol_internal.h>
#include <vlc/mediacontrol.h>
#include <vlc/intf.h>
#include <vlc/vout.h>
......
/*****************************************************************************
* playlist.c: libvlc new API playlist handling functions
*****************************************************************************
* Copyright (C) 2005 the VideoLAN team
* $Id$
*
* Authors: Clment Stenac <zorglub@videolan.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.
*****************************************************************************/
#include <libvlc_internal.h>
#include <vlc/libvlc.h>
#include <vlc/intf.h>
void libvlc_playlist_play( libvlc_instance_t *p_instance,
int i_options, char **ppsz_options,
libvlc_exception_t *p_exception )
{
///\todo Handle additionnal options
if( p_instance->p_playlist->i_size == 0 )
{
libvlc_exception_raise( p_exception, "Empty playlist" );
return;
}
playlist_Play( p_instance->p_playlist );
}
libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
libvlc_exception_t *p_exception )
{
libvlc_input_t *p_input;
vlc_mutex_lock( &p_instance->p_playlist->object_lock );
if( p_instance->p_playlist->p_input == NULL )
{
libvlc_exception_raise( p_exception, "No active input" );
vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
return;
}
p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
p_input->i_input_id = p_instance->p_playlist->p_input->i_object_id;
p_input->p_instance = p_instance;
vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
return p_input;
}
......@@ -96,7 +96,7 @@ static int stats_CounterUpdate( stats_handler_t *p_handler,
{
case STATS_LAST:
case STATS_MIN:
case STATS_LAST:
case STATS_MAX:
if( p_counter->i_samples > 1)
{
msg_Err( p_handler, "LAST counter has several samples !" );
......@@ -249,7 +249,7 @@ void stats_ComputeInputStats( input_thread_t *p_input,
{
int i;
/* read_packets and read_bytes are common to all streams */
p_stats->i_read_packets = stats_GetInteger( p_input, "read_packets" );
p_stats->i_read_bytes = stats_GetInteger( p_input, "read_bytes" );
//p_stats->i_read_packets = stats_GetInteger( p_input, "read_packets" );
// p_stats->i_read_bytes = stats_GetInteger( p_input, "read_bytes" );
}
#include <stdio.h>
#include <time.h>
#include <vlc/libvlc.h>
int main(int argc, char **argv)
{
libvlc_instance_t *p_instance1;
libvlc_exception_t exception;
libvlc_input_t *p_input;
int b_started = 0;
libvlc_exception_init( &exception );
p_instance1 = libvlc_new( argc,argv, &exception );
if( libvlc_exception_raised( &exception ) )
{
fprintf( stderr, "FATAL: %s\n",
libvlc_exception_get_message( &exception ) );
return 0;
}
libvlc_playlist_play( p_instance1, 0,NULL, NULL );
while( 1 )
{
sleep( 1 );
libvlc_exception_init( &exception );
p_input = libvlc_playlist_get_input( p_instance1, &exception );
if( libvlc_exception_raised( &exception ) )
{
if( b_started == 1 )
break;
else
continue;
}
else
{
b_started = 1;
}
fprintf( stderr, "Length %lli - Time %lli\n",
libvlc_input_get_length( p_input, NULL ),
libvlc_input_get_time( p_input, NULL ) );
libvlc_input_free( p_input );
}
libvlc_destroy( p_instance1 );
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment