📄 corba.c
字号:
/***************************************************************************** * corba.c : CORBA (ORBit) remote control module for vlc ***************************************************************************** * Copyright (C) 2001 VideoLAN * $Id: corba.c,v 1.4 2004/01/25 16:17:03 anil Exp $ * * Authors: Olivier Aubert <oaubert at lisi dot univ-lyon1 dot 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. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************//* For CORBA */#include "mediacontrol.h"#include "orbit/poa/portableserver-poa-type.h"#define VLC_IOR_FILE "/tmp/vlc-ior.ref"#define handle_exception(m) if(ev->_major != CORBA_NO_EXCEPTION) \ { \ msg_Err (servant->p_intf, m); \ return; \ }#define handle_exception_no_servant(p,m) if(ev->_major != CORBA_NO_EXCEPTION) \ { \ msg_Err (p, m); \ return; \ }#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/vout.h>#include <vlc/aout.h>#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#include <sys/types.h>/***************************************************************************** * intf_sys_t: description and status of corba interface *****************************************************************************/struct intf_sys_t{ CORBA_ORB orb; VLC_MediaControl mc; PortableServer_POA root_poa; PortableServer_POAManager root_poa_manager; GMainLoop* corbaloop; vlc_bool_t b_playing; input_thread_t * p_input; /* The input thread */ msg_subscription_t* p_sub; /* message bank subscription */};/* Convert an offset into seconds. Taken from input_ext-intf.c. The 50 hardcoded constant comes from the definition of i_mux_rate : i_mux_rate : the rate we read the stream (in units of 50 bytes/s) ; 0 if undef */long long offsetToSeconds (input_thread_t *p_input, off_t l_offset){ long long l_res; l_res = -1; if (p_input != NULL && p_input->stream.i_mux_rate != 0) { l_res = (long long) l_offset / 50 / p_input->stream.i_mux_rate; } return l_res;}/* Convert an offset into milliseconds */long long offsetToMilliseconds (input_thread_t *p_input, off_t l_offset){ long long l_res; l_res = -1; if (p_input != NULL && p_input->stream.i_mux_rate != 0) { l_res = (long long) 1000 * l_offset / 50 / p_input->stream.i_mux_rate; } return l_res;}/* Convert seconds to an offset */off_t secondsToOffset (input_thread_t *p_input, long long l_seconds){ off_t l_res; l_res = -1; if (p_input != NULL) { l_res = (off_t) l_seconds * 50 * p_input->stream.i_mux_rate; } return l_res;}/* Convert milliseconds to an offset */off_t millisecondsToOffset (input_thread_t *p_input, long long l_milliseconds){ off_t l_res; l_res = -1; if (p_input != NULL) { l_res = (off_t) l_milliseconds * 50 * p_input->stream.i_mux_rate / 1000; } return l_res;}/* Returns the current offset. */off_t currentOffset (input_thread_t *p_input){ off_t l_offset; if( p_input == NULL ) { return -1; } /* offset contient la valeur en unit閟 arbitraires (cf include/input_ext-intf.h) */ vlc_mutex_lock( &p_input->stream.stream_lock );#define A p_input->stream.p_selected_area l_offset = A->i_tell + A->i_start;#undef A vlc_mutex_unlock( &p_input->stream.stream_lock ); return l_offset;}/*** App-specific servant structures ***//* We can add attributes to this structure, which is both a pointer on a specific structure, and on a POA_VLC_MediaControl (servant). Cf http://developer.gnome.org/doc/guides/corba/html/corba-poa-example.html */typedef struct{ POA_VLC_MediaControl servant; PortableServer_POA poa; /* Ajouter ici les attributs utiles */ intf_thread_t *p_intf;}impl_POA_VLC_MediaControl;/* Beginning of the CORBA code generated in Mediacontrol-skelimpl.c *//* BEGIN INSERT *//*** Implementation stub prototypes ***/static void impl_VLC_MediaControl__destroy(impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev);static VLC_Positionimpl_VLC_MediaControl_get_media_position(impl_POA_VLC_MediaControl * servant, const VLC_PositionOrigin an_origin, const VLC_PositionKey a_key, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_set_media_position(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_start(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_pause(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_resume(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_stop(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_exit(impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev);static voidimpl_VLC_MediaControl_add_to_playlist(impl_POA_VLC_MediaControl * servant, const CORBA_char * a_file, CORBA_Environment * ev);static VLC_PlaylistSeq *impl_VLC_MediaControl_get_playlist(impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev);/*** epv structures ***/static PortableServer_ServantBase__epv impl_VLC_MediaControl_base_epv = { NULL, /* _private data */ NULL, /* finalize routine */ NULL, /* default_POA routine */};static POA_VLC_MediaControl__epv impl_VLC_MediaControl_epv = { NULL, /* _private */ (gpointer) & impl_VLC_MediaControl_get_media_position, (gpointer) & impl_VLC_MediaControl_set_media_position, (gpointer) & impl_VLC_MediaControl_start, (gpointer) & impl_VLC_MediaControl_pause, (gpointer) & impl_VLC_MediaControl_resume, (gpointer) & impl_VLC_MediaControl_stop, (gpointer) & impl_VLC_MediaControl_exit, (gpointer) & impl_VLC_MediaControl_add_to_playlist, (gpointer) & impl_VLC_MediaControl_get_playlist,};/*** vepv structures ***/static POA_VLC_MediaControl__vepv impl_VLC_MediaControl_vepv = { &impl_VLC_MediaControl_base_epv, &impl_VLC_MediaControl_epv,};/*** Stub implementations ***/static VLC_MediaControlimpl_VLC_MediaControl__create(PortableServer_POA poa, CORBA_Environment * ev){ VLC_MediaControl retval; impl_POA_VLC_MediaControl *newservant; PortableServer_ObjectId *objid; newservant = g_new0(impl_POA_VLC_MediaControl, 1); newservant->servant.vepv = &impl_VLC_MediaControl_vepv; newservant->poa = poa; POA_VLC_MediaControl__init((PortableServer_Servant) newservant, ev); objid = PortableServer_POA_activate_object(poa, newservant, ev); CORBA_free(objid); retval = PortableServer_POA_servant_to_reference(poa, newservant, ev); return retval;}static voidimpl_VLC_MediaControl__destroy(impl_POA_VLC_MediaControl * servant, CORBA_Environment * ev){ PortableServer_ObjectId *objid; objid = PortableServer_POA_servant_to_id(servant->poa, servant, ev); PortableServer_POA_deactivate_object(servant->poa, objid, ev); CORBA_free(objid); POA_VLC_MediaControl__fini((PortableServer_Servant) servant, ev); g_free(servant);}/* END INSERT *//* Beginning of the CORBA functions that we define *//* Returns the current position in the stream. The returned value can be relative or absolute (according to PositionOrigin) and the unit is set by PositionKey */static VLC_Positionimpl_VLC_MediaControl_get_media_position(impl_POA_VLC_MediaControl * servant, const VLC_PositionOrigin an_origin, const VLC_PositionKey a_key, CORBA_Environment * ev){ VLC_Position retval; off_t l_offset; VLC_PositionKeyNotSupported *exception; input_thread_t * p_input = servant->p_intf->p_sys->p_input; /* msg_Warn (servant->p_intf, "Calling MediaControl::get_media_position"); */ retval.origin = an_origin; retval.key = a_key; if ( an_origin == VLC_RelativePosition || an_origin == VLC_ModuloPosition ) { /* Relative or ModuloPosition make no sense */ /* FIXME: should we return 0 or raise an exception ? */ retval.value = 0; return retval; } if ( p_input == NULL ) { /* FIXME: should we return 0 or raise an exception ? */ retval.value = 0; return retval; } /* We are asked for an AbsolutePosition. */ /* Cf modules/gui/gtk/gtk_display.c */ /* The lock is taken by the currentOffset function */ l_offset = currentOffset (p_input); if (a_key == VLC_ByteCount) { retval.value = l_offset; return retval; } if (a_key == VLC_MediaTime) { retval.value = offsetToSeconds (p_input, l_offset); return retval; } if (a_key == VLC_SampleCount) { /* Raising exceptions in C : cf the good explanations in http://developer.gnome.org/doc/guides/corba/html/corba-module-complete-helloworld.html */ exception = VLC_PositionKeyNotSupported__alloc (); memcpy (&exception->key, &a_key, sizeof (a_key)); CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_VLC_PositionKeyNotSupported, exception); retval.value = 0; return retval; } /* http://catb.org/~esr/jargon/html/entry/can't-happen.html */ return retval;}/* Sets the media position */static voidimpl_VLC_MediaControl_set_media_position(impl_POA_VLC_MediaControl * servant, const VLC_Position * a_position, CORBA_Environment * ev){ VLC_InvalidPosition *pe_exception; VLC_PositionKeyNotSupported *pe_key_exception; off_t l_offset_destination = 0; int i_whence = 0; input_thread_t * p_input = servant->p_intf->p_sys->p_input; msg_Warn (servant->p_intf, "Calling MediaControl::set_media_position"); if( p_input == NULL ) return; if ( !p_input->stream.b_seekable ) { pe_exception = VLC_InvalidPosition__alloc (); memcpy (&pe_exception->key, &a_position->key, sizeof (&a_position->key)); CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_VLC_InvalidPosition, pe_exception); return; } switch ( a_position->key ) { case VLC_SampleCount: /* The SampleCount unit is still a bit mysterious... */ pe_key_exception = VLC_PositionKeyNotSupported__alloc (); memcpy (&pe_key_exception->key, &a_position->key, sizeof (&a_position->key)); CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_VLC_PositionKeyNotSupported, pe_key_exception); return; break; case VLC_MediaTime: i_whence |= INPUT_SEEK_SECONDS; break; case VLC_ByteCount: i_whence |= INPUT_SEEK_BYTES; break; default: i_whence |= INPUT_SEEK_BYTES; break; } switch ( a_position->origin) { case VLC_RelativePosition: i_whence |= INPUT_SEEK_CUR; break; case VLC_ModuloPosition: i_whence |= INPUT_SEEK_END; break; case VLC_AbsolutePosition: i_whence |= INPUT_SEEK_SET;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -