Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

kdenserver.hh

00001 /*
00002  * PIAVE - PIAVE Is A Video Editor
00003  *
00004  * Copyright (C) 2002 Rolf Dubitzky, rolf@dubitzky.de
00005  *
00006  */
00007 
00008 /*
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 /* \file
00025  * Here lives the server functionality of piave.
00026  *
00027  * This functionality is at the moment only used by kdenlive.  
00028  *
00029  * "Server" contains all functionality that would in principle be common
00030  * between serves for other GUIs, clients.
00031  *
00032  * "KdenLiveServer" implements the xml based protokoll to talk to kdenlive
00033  *
00034  */
00035 
00036 #if ! defined ( KDENSERVER_HH )
00037 #define KDENSERVER_HH
00038 
00039 // std
00040 #include <sys/types.h>
00041 #include <sys/socket.h>
00042 #include <netinet/in.h>
00043 #include <arpa/inet.h>
00044 #include <unistd.h>
00045 
00046 // std++
00047 #include <iostream>
00048 #include <string>
00049 #include <algorithm>
00050 #include <functional>
00051 #include <list>
00052 
00053 // piave
00054 #include "server.hh"
00055 #include "libpiave/piave_base.hh"
00056 #include "libpiave/storybase.hh"
00057 #include "libpiave/player.hh"
00058 #include "libpiave/ringbuffer.hh"
00059 #include "libpiave/VEML.hh"
00060 
00061 namespace PIAVE {
00062 
00067     class KdenLiveServer : public Server
00068     {
00069 
00070       private:
00071 
00072         struct CommandQueue
00073         {
00074             enum AccessMode { block, non_block };
00075             PtrRingBuffer< VEMLCmnd > dropQ;
00076             PtrRingBuffer< VEMLCmnd > stdQ;
00077             pthread_mutex_t lock;               /* mutex ensuring exclusive access to buffer */
00078             pthread_cond_t  notempty;   /* signaled when buffer is not empty */
00079             pthread_cond_t  notfull;    /* signaled when buffer is not full */
00080             CommandQueue() {
00081                 pthread_mutex_init( &lock, NULL );
00082                 pthread_cond_init( &notempty, NULL );
00083                 pthread_cond_init( &notfull, NULL );
00084             }
00085             void kick();
00086             void push( const VEMLCmnd * c );
00087             const VEMLCmnd * pop( AccessMode a );
00088         };
00089 
00090       public:
00091         KdenLiveServer(  unsigned short port );
00092         virtual ~KdenLiveServer();
00093 
00094         /* this function is only for temporary tests
00095          * the storyboard should be read from socket 
00096          */
00097         void setStoryBoard( StoryBoard * s ) { _theStoryBoard = s; }
00098 
00099         /*   to get an overview what is implemented
00100          */
00101         void printAllVEML( std::ostream & o ) const ;
00102 
00103         /* */
00104         void inc_seek_pos();
00105         void dec_seek_pos();
00106         void push_cmnd( const std::string & c );
00107 
00108         // tmporary ... start thread or not?  FIXME
00109         bool _listenForSDLEvents;
00110 
00111       protected:
00112         /*   main entry point
00113          */
00114         void startProcessCommandsLoop();
00115 
00116       private:
00117         /* the two thread routines: producer and consumer
00118          * these are static wrappes for the member functions
00119          */
00120         static void * _listen_for_commands( void * );
00121         static void * _listen_for_SDL_events( void * );
00122         static void * _process_commands( void * );
00123 
00124         /* Process any commands that have been recieved, send any
00125          * acknowledgements that are required. 
00126          */
00127         virtual void listenForCommands();
00128         virtual void listenForSDLEvents();
00129         virtual void processCommands();
00130 
00131         /* 
00132          * available VEML commands: 
00133          */
00135         virtual PropertyNode * veml_createVideoXWindow( const VEMLCmnd * cmd );
00136         virtual PropertyNode * veml_closeVideoXWindow( const VEMLCmnd * cmd  );
00137         virtual PropertyNode * veml_seek( const VEMLCmnd * cmd  );
00138         virtual PropertyNode * veml_play( const VEMLCmnd * cmd  );
00139         virtual PropertyNode * veml_quit( const VEMLCmnd * cmd  );
00140         virtual PropertyNode * veml_stop( const VEMLCmnd * cmd  );
00141         virtual PropertyNode * veml_getFileProperties( const VEMLCmnd * cmd );
00142         virtual PropertyNode * veml_render( const VEMLCmnd * cmd );
00143         virtual PropertyNode * veml_ping( const VEMLCmnd * cmd );
00144         virtual PropertyNode * veml_setSceneList( const VEMLCmnd * cmd );
00145         virtual PropertyNode * veml_getCapabilities( const VEMLCmnd * cmd );
00146 
00147         /*   
00148          */
00149 
00150       private:
00152         OutAVStreamIFace        * _screenOut;
00154         OutAudioStreamIFace     * _audioOut;
00155 
00157         StoryBoard              * _theStoryBoard;
00158 
00159         /*  this is the main map of known commands
00160          *  by appending commands to this map the cmnd will become
00161          *  recognizable by the precoessCommands thread
00162          */
00163         VEMLCmndMap        _allVEMLCommands;
00164 
00165         /* the listen thread puts commands in this buffer
00166          * the process thread reads commands from this buffer
00167          */
00168         CommandQueue _q;
00169 
00171         Player _player;
00172         Time _seek_pos;
00173 
00174         // the child threads
00175         pthread_t _main_thread;
00176         pthread_t _listen_thread;
00177         pthread_t _listen_SDL_thread;
00178         pthread_t _process_thread;
00179 
00180     };
00181 };
00182 
00183 #endif

Generated on Tue Oct 14 20:45:36 2003 for piave by doxygen1.2.18