Changeset 31

Show
Ignore:
Timestamp:
02/10/08 22:16:27 (6 months ago)
Author:
sip
Message:

Implemented mosaic position logic.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • media/Makefile

    r20 r31  
    33########################################### 
    44include ../config.mk 
     5 
     6OPTS+= -fPIC -DPIC 
    57 
    68#DEBUG 
  • media/include/log.h

    r17 r31  
    99#define log_error Error 
    1010 
    11 inline void LogFile(char *msg, ...) 
     11inline void LogFile(const char *msg, ...) 
    1212{ 
    1313          
     
    2828} 
    2929 
    30 inline void Out(char *msg, ...) 
     30inline void Out(const char *msg, ...) 
    3131{ 
    3232         va_list ap; 
     
    3838} 
    3939 
    40 inline void Log(char *msg, ...) 
     40inline void Log(const char *msg, ...) 
    4141{ 
    4242         va_list ap; 
     
    4949} 
    5050 
    51 inline void Debug(char *msg, ...) 
     51inline void Debug(const char *msg, ...) 
    5252{ 
    5353         va_list ap; 
     
    5858} 
    5959 
    60 inline int Error(char *msg, ...) 
     60inline int Error(const char *msg, ...) 
    6161{ 
    6262        va_list ap; 
  • media/include/mosaic.h

    r6 r31  
    1212        virtual void Reset(); 
    1313 
     14        virtual int GetSlots()=0; 
    1415        virtual BYTE* GetFrame() = 0; 
    1516        virtual int GetWidth() = 0; 
  • media/include/multiconf.h

    r6 r31  
    1818        int CreateParticipant(); 
    1919        int SetCompositionType(int comp,int size); 
     20        int SetMosaicSlot(int num,int id); 
    2021 
    2122        //Video 
  • media/include/partedmosaic.h

    r6 r31  
    1111        PartedMosaic(int num, int size); 
    1212        virtual ~PartedMosaic(); 
     13 
     14        virtual int GetSlots(); 
    1315 
    1416        virtual BYTE* GetFrame(); 
  • media/include/videomixer.h

    r6 r31  
    3333        VideoOutput* GetOutput(int id); 
    3434        int GetCompositionType(); 
     35        int SetSlot(int num,int id); 
    3536        int SetCompositionType(CompositionType comp,int size); 
    3637        int End(); 
     
    3839protected: 
    3940        int MixVideo(); 
     41        int CalculatePositions(); 
     42        int GetPosition(int id); 
    4043         
    4144private: 
     
    6063        BYTE    *logo; 
    6164        Mosaic  *mosaic; 
     65        int     *mosaicSlots; 
     66        int     *mosaicPos; 
     67        int     numSlots; 
    6268 
    6369        //Threads, mutex y condiciones 
  • media/include/xmlhandler.h

    r17 r31  
    44#include "xmlrpcserver.h" 
    55 
    6 xmlrpc_value* xmlerror (xmlrpc_env *env,char *msg); 
     6xmlrpc_value* xmlerror (xmlrpc_env *env,const char *msg); 
    77xmlrpc_value* xmlok (xmlrpc_env *env,xmlrpc_value *array=NULL); 
    88 
  • media/include/xmlrpcmcuclient.h

    r6 r31  
    3131        int CreateParticipant(int confId); 
    3232        int SetCompositionType(int confId,int comp,int size); 
     33        int SetMosaicSlot(int confId,int num,int id); 
    3334 
    3435        //Video 
     
    5455 
    5556private: 
    56         int MakeCall(xmlrpc_env *env,char *method,xmlrpc_value* param,xmlrpc_value **result); 
     57        int MakeCall(xmlrpc_env *env,const char *method,xmlrpc_value* param,xmlrpc_value **result); 
    5758        //Atributos 
    5859        string serverUrl; 
     
    7475int     SetCompositionType(void *mcu,int confId,int comp,int size) 
    7576        { return ((XmlRpcMcuClient*)mcu)->SetCompositionType(confId,comp,size); } 
     77int     SetMosaicSlot(void *mcu,int confId,int num,int id) 
     78        { return ((XmlRpcMcuClient*)mcu)->SetCompositionType(confId,num,id);    } 
    7679 
    7780//Video 
     
    120123int     CreateParticipant(void *mcu,int confId); 
    121124int     SetCompositionType(void *mcu,int confId,int comp,int size); 
     125int     SetMosaicSlot(void *mcu,int confId,int num,int id); 
    122126 
    123127//Video 
  • media/include/xmlrpcserver.h

    r8 r31  
    1616{ 
    1717public: 
    18         XmlRpcServer(); 
     18        XmlRpcServer(int port); 
    1919 
    2020        int AddHandler(string base,Handler* hnd); 
  • media/src/audiomixer.cpp

    r6 r31  
    139139                 pthread_mutex_lock(&tickerMutex); 
    140140        } 
     141 
     142        //Y desprotegemos 
     143        pthread_mutex_unlock(&tickerMutex); 
    141144 
    142145        //Logeamos 
     
    163166void AudioMixer::Process(void) 
    164167{ 
    165  
    166168        LstAudios::iterator     it; 
    167169 
     
    338340 
    339341        //Si esta devolvemos el input 
    340         return true;; 
     342        return true; 
    341343} 
    342344 
  • media/src/main.cpp

    r17 r31  
    1313#endif 
    1414 
    15 int main(
     15int main(int argc,char **argv
    1616{ 
    17         XmlRpcServer server; 
     17        int port = 8080; 
     18 
     19        //Get port 
     20        if(argc>1) 
     21                port = atoi(argv[1]); 
     22 
     23        XmlRpcServer server(port); 
    1824        StatusHandler status; 
    1925        MCU mcu; 
  • media/src/multiconf.cpp

    r10 r31  
    6161        //POnemos el tipo de video mixer 
    6262        return videoMixer.SetCompositionType((CompositionType)comp,size); 
     63} 
     64 
     65/************************ 
     66* SetMosaicSlot 
     67*       Set slot position on mosaic 
     68*************************/ 
     69int MultiConf::SetMosaicSlot(int num,int id) 
     70{ 
     71        Log("-SetMosaicSlot [%d,%d]\n",num,id); 
     72 
     73        //Set it 
     74        return videoMixer.SetSlot(num,id); 
    6375} 
    6476 
  • media/src/partedmosaic.cpp

    r6 r31  
    6464        //Free memory 
    6565        free(resizer); 
     66} 
     67/***************************** 
     68* GetSlots 
     69*       Get number of slots 
     70*****************************/ 
     71int PartedMosaic::GetSlots() 
     72{ 
     73        return mosaicNum; 
    6674} 
    6775 
  • media/src/videomixer.cpp

    r6 r31  
    1212{ 
    1313        //Incializamos a cero 
    14         mosaic  = NULL; 
     14        mosaic          = NULL; 
     15        mosaicSlots     = NULL; 
     16        mosaicPos       = NULL; 
     17        numSlots        = 0; 
    1518 
    1619        //Inciamos lso mutex y la condicion 
     
    2528VideoMixer::~VideoMixer() 
    2629{ 
     30        //If we've got mosaic 
     31        if (mosaic) 
     32                //Delete it 
     33                delete mosaic; 
     34 
     35        //If already have slot list 
     36        if (mosaicSlots) 
     37                //Delete it 
     38                free(mosaicSlots); 
     39 
     40        //If already have position list 
     41        if (mosaicPos) 
     42                //Delete it 
     43                free(mosaicPos); 
     44 
    2745         //Liberamos los mutex 
    2846         pthread_mutex_destroy(&mixVideoMutex); 
    2947         pthread_cond_destroy(&mixVideoCond); 
     48         
    3049} 
    3150 
     
    5473int VideoMixer::MixVideo() 
    5574{ 
    56         int id; 
    57         VideoSource *video; 
    58  
    59         //El iterador para los videos 
     75        //Video Iterator 
    6076        LstVideos::iterator it; 
    6177 
     
    7288                { 
    7389                        //Nos recorremos los videos 
    74                         for (it=lstVideos.begin();it!=lstVideos.end();it++
     90                        for (it=lstVideos.begin();it!=lstVideos.end();++it
    7591                        { 
    76                                 //Obtenemos el indice y el video  
    77                                 id = (*it).first; 
    78                                 video = (*it).second; 
     92                                //Get input 
     93                                PipeVideoInput *input = (*it).second->input; 
    7994 
    8095                                //Colocamos el frame 
    81                                 video->input->SetFrame(mosaic->GetFrame(),mosaic->GetWidth(),mosaic->GetHeight()); 
     96                                input->SetFrame(mosaic->GetFrame(),mosaic->GetWidth(),mosaic->GetHeight()); 
    8297                        } 
    8398                } 
     
    96111                         
    97112                //Nos recorremos los videos 
    98                 for (it=lstVideos.begin();it!=lstVideos.end();it++
     113                for (it=lstVideos.begin();it!=lstVideos.end();++it
    99114                { 
    100                         //Obtenemos el indice y el video  
    101                         id = (*it).first; 
    102                         video = (*it).second; 
     115                        //Get Id 
     116                        int id = (*it).first; 
     117 
     118                        //Get output 
     119                        PipeVideoOutput *output = (*it).second->output; 
    103120                         
    104121                        //If we've got a new frame on source 
    105                         if (video->output->IsChanged()) 
    106                                 //Change mosaic 
    107                                 mosaic->Update(id-1,video->output->GetFrame(),video->output->GetWidth(),video->output->GetHeight()); 
     122                        if (output->IsChanged()) 
     123                        { 
     124                                //Get position 
     125                                int pos = GetPosition(id); 
     126 
     127                                //If it's visible 
     128                                if (pos!=1) 
     129                                        //Change mosaic 
     130                                        mosaic->Update(id-1,output->GetFrame(),output->GetWidth(),output->GetHeight()); 
     131                        } 
    108132                } 
    109133 
     
    175199 
    176200        //Recorremos la lista 
    177         for (it =lstVideos.begin();it!=lstVideos.end();it++
     201        for (it =lstVideos.begin();it!=lstVideos.end();++it
    178202                //Borramos el video 
    179203                DeleteMixer((*it).first); 
    180  
    181         //If we've got mosaic 
    182         if (mosaic) 
    183                 //Delete it 
    184                 delete mosaic; 
    185  
    186         //Y el logo 
    187         //free(logo); 
    188204 
    189205        Log("<End videomixer\n"); 
     
    220236        //Y lo aƱadimos a la lista 
    221237        lstVideos[id] = video; 
     238 
     239        //Calculate it's position 
     240        for (int i=0; i<numSlots; i++) 
     241                //It's free?  
     242                if(mosaicPos[i]==0 && mosaicSlots[i]==0) 
     243                { 
     244                        //Here we are 
     245                        mosaicPos[i]=id; 
     246                        //Exit 
     247                        break; 
     248                } 
     249 
     250        //Log Slots 
     251        for (int i=0;i<numSlots;i++) 
     252                if (i==0) 
     253                        Log("-Slots [%d",mosaicSlots[i]); 
     254                else 
     255                        Log(",%d",mosaicSlots[i]); 
     256        Log("]\n"); 
     257 
     258        //Log postions 
     259        for (int i=0;i<numSlots;i++) 
     260                if (i==0) 
     261                        Log("-Pos   [%d",mosaicPos[i]); 
     262                else 
     263                        Log(",%d",mosaicPos[i]); 
     264        Log("]\n"); 
    222265 
    223266        //Desprotegemos la lista 
     
    322365        if (it == lstVideos.end()) 
    323366        { 
    324                 //DDesprotegemos la lista 
     367                //Desprotegemos la lista 
    325368                lstVideosUse.Unlock(); 
    326369                //Salimos 
     
    333376        //Lo quitamos de la lista 
    334377        lstVideos.erase(id); 
     378 
     379        //If still mixing video 
     380        if (mixingVideo) 
     381                //Reset positions 
     382                for (int i=0;i<numSlots;i++) 
     383                        //it's me? 
     384                        if (mosaicPos[i]==id) 
     385                        { 
     386                                //was fixed? 
     387                                if (mosaicSlots[i]==id) 
     388                                        //lock it 
     389                                        mosaicSlots[i]=-1; 
     390                                else  
     391                                        //Recalculate participant positions 
     392                                        CalculatePositions(); 
     393                                 
     394                                //Finish 
     395                                break; 
     396                        } 
    335397 
    336398        //Desprotegemos la lista 
     
    412474int VideoMixer::SetCompositionType(CompositionType comp, int type) 
    413475{ 
    414  
    415476        Log(">SetCompositionType [%d,%d]\n",comp,type); 
    416477 
     
    446507        compositionType = comp; 
    447508 
     509        //Save old values 
     510        int oldNumSlots = numSlots; 
     511        int *oldSlots = mosaicSlots; 
     512        int *oldPos = mosaicPos; 
     513 
     514        //Get number of participants visible 
     515        numSlots = mosaic->GetSlots(); 
     516         
     517        //Malloc lists 
     518        mosaicSlots = (int*) malloc(numSlots*sizeof(int)); 
     519        mosaicPos = (int*) malloc(numSlots*sizeof(int)); 
     520 
     521        //Reset slot list 
     522        memset(mosaicSlots,0,numSlots*sizeof(int)); 
     523 
     524        //If we have old slots 
     525        if (oldSlots) 
     526        { 
     527                //Which was bigger? 
     528                if (oldNumSlots<numSlots) 
     529                        //Copy 
     530                        memcpy(mosaicSlots,oldSlots,oldNumSlots*sizeof(int)); 
     531                else 
     532                        //Copy 
     533                        memcpy(mosaicSlots,oldSlots,numSlots*sizeof(int)); 
     534        } 
     535         
     536         
     537        //If already have slot list 
     538        if (oldSlots) 
     539                //Delete it 
     540                free(oldSlots); 
     541 
     542        //If already have position list 
     543        if (oldPos) 
     544                //Delete it 
     545                free(oldPos); 
     546 
     547        //Recalculate positions 
     548        CalculatePositions(); 
     549 
    448550        //Desprotegemos la lista 
    449551        lstVideosUse.Unlock(); 
     
    454556} 
    455557 
     558/************************ 
     559* CalculatePosition 
     560*       Calculate positions for participants 
     561*************************/ 
     562int VideoMixer::CalculatePositions() 
     563{ 
     564        LstVideos::iterator it; 
     565 
     566        Log(">CalculatePositions\n"); 
     567 
     568        //First erase positions 
     569        memset(mosaicPos,0,numSlots*sizeof(int)); 
     570 
     571        //Start from the begining 
     572        int first = 0; 
     573 
     574 
     575        //Iterate Videos 
     576        for (it=lstVideos.begin(); it!=lstVideos.end(); ++it) 
     577        { 
     578                //Get id 
     579                int id = (*it).first; 
     580 
     581                //Not found the first free one 
     582                int firstFree = -1; 
     583 
     584                //Look in the slots  
     585                for (int i=first;i<numSlots;i++) 
     586                { 
     587                        //It's lock for me? 
     588                        if (mosaicSlots[i]==id) 
     589                        { 
     590                                //Set our position 
     591                                mosaicPos[i]=id; 
     592                                //If we were the first one 
     593                                if (first==i) 
     594                                        //Start after me next pass 
     595                                        first++;         
     596                                //Next 
     597                                break; 
     598                        } else if (mosaicSlots[i]==-1 && i==first) { 
     599                                //If the first one was a locked one skip it next time 
     600                                first++; 
     601                        } else if (mosaicSlots[i]==0 && mosaicPos[i]==0 && firstFree==-1) { 
     602                                //If it's free and we have still not a free one save it 
     603                                firstFree=i; 
     604                        } else if (mosaicPos[i]>0 && i==first) { 
     605                                //The first one was already calculated 
     606                                first++; 
     607                        } 
     608 
     609                } 
     610 
     611                //I have not fixed position check if there is any free slot 
     612                if (firstFree!=-1) 
     613                { 
     614                        //Here we are 
     615                        mosaicPos[firstFree]=id; 
     616                        //If we were the first one 
     617                        if (first==firstFree) 
     618                                //Start after me next pass 
     619                                first++;         
     620                } 
     621 
     622                //If we have been over the end 
     623                if (first==numSlots) 
     624                        //Exit 
     625                        break; 
     626        }        
     627 
     628        //Log Slots 
     629        for (int i=0;i<numSlots;i++) 
     630                if (i==0) 
     631                        Log("-Slots [%d",mosaicSlots[i]); 
     632                else 
     633                        Log(",%d",mosaicSlots[i]); 
     634        Log("]\n"); 
     635 
     636        //Log postions 
     637        for (int i=0;i<numSlots;i++) 
     638                if (i==0) 
     639                        Log("-Pos   [%d",mosaicPos[i]); 
     640                else 
     641                        Log(",%d",mosaicPos[i]); 
     642        Log("]\n"); 
     643 
     644        Log("<CalculatePositions\n"); 
     645} 
     646 
     647/************************ 
     648* SetSlot 
     649*       Set slot participant 
     650*************************/ 
     651int VideoMixer::SetSlot(int num,int id) 
     652{ 
     653        Log(">SetPosition"); 
     654 
     655        //Check num 
     656        if (num>numSlots-1) 
     657                //Exit 
     658                return Error("Slot not in mosaic \n"); 
     659 
     660        //Protegemos la lista 
     661        lstVideosUse.WaitUnusedAndLock(); 
     662 
     663        //Set it 
     664        mosaicSlots[num] = id; 
     665 
     666        //Calculate positions 
     667        CalculatePositions(); 
     668 
     669        //Desprotegemos la lista 
     670        lstVideosUse.Unlock(); 
     671 
     672        Log("<SetPosition"); 
     673 
     674        return 1; 
     675} 
     676 
     677/************************ 
     678* GetPosition 
     679*       Get position for participant 
     680*************************/ 
     681int VideoMixer::GetPosition(int id) 
     682{ 
     683        //Check if it has a fixed position 
     684        for (int i=0;i<numSlots;i++) 
     685                //If it's this participant 
     686                if (mosaicPos[i]==id) 
     687                        //Return it 
     688                        return i; 
     689 
     690        //Not found 
     691        return -1; 
     692} 
     693 
  • media/src/xmlhandler.cpp

    r17 r31  
    55#include "xmlhandler.h" 
    66 
    7 xmlrpc_value* xmlerror (xmlrpc_env *env,char *msg) 
     7xmlrpc_value* xmlerror (xmlrpc_env *env,const char *msg) 
    88{ 
    99        return xmlrpc_build_value(env,"{s:i,s:s}","returnCode",0,"errorMsg",msg); 
  • media/src/xmlrpcmcu.cpp

    r17 r31  
    588588        //La borramos 
    589589        int res = conf->SetCompositionType(comp,size); 
     590 
     591        //Liberamos la referencia 
     592        mcu->ReleaseConferenceRef(confId); 
     593 
     594        //Salimos 
     595        if(!res) 
     596                return xmlerror(env,"Error\n"); 
     597 
     598        //Devolvemos el resultado 
     599        return xmlok(env); 
     600} 
     601 
     602xmlrpc_value* SetMosaicSlot(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) 
     603{ 
     604        MCU *mcu = (MCU *)user_data; 
     605        MultiConf *conf = NULL; 
     606 
     607         //Parseamos 
     608        int confId; 
     609        int num; 
     610        int id; 
     611        xmlrpc_parse_value(env, param_array, "(iii)", &confId,&num,&id); 
     612 
     613        //Comprobamos si ha habido error 
     614        if(env->fault_occurred) 
     615                return 0; 
     616          
     617        //Obtenemos la referencia 
     618        if(!mcu->GetConferenceRef(confId,&conf)) 
     619                return xmlerror(env,"La conferencia no existe\n"); 
     620 
     621        //Set slot 
     622        int res = conf->SetMosaicSlot(num,id); 
    590623 
    591624        //Liberamos la referencia 
     
    621654        {"IsReceivingAudio",IsReceivingAudio}, 
    622655        {"SetCompositionType",SetCompositionType}, 
     656        {"SetMosaicSlot",SetMosaicSlot}, 
    623657        {NULL,NULL} 
    624658}; 
  • media/src/xmlrpcmcuclient.cpp

    r8 r31  
    2929*       Realiza una llamada a un procedimiento remoto y parsea la respuesta 
    3030***************************************/ 
    31 int XmlRpcMcuClient::MakeCall(xmlrpc_env *env,char *method,xmlrpc_value* param,xmlrpc_value **result) 
     31int XmlRpcMcuClient::MakeCall(xmlrpc_env *env,const char *method,xmlrpc_value* param,xmlrpc_value **result) 
    3232{ 
    3333        Log(">MakeCall  [%s]\n",method); 
     
    149149        return true; 
    150150} 
     151 
    151152/************************************ 
    152153* SetCompositionType 
     
    181182} 
    182183 
     184/************************************ 
     185* SetMosaicSlot 
     186*       MosaicSlot 
     187***************************************/ 
     188int XmlRpcMcuClient::SetMosaicSlot(int confId,int num,int id) 
     189{ 
     190        //Logeamos 
     191        Log(">SetMosaicSlot [%d,%d,%d]\n",confId,num,id); 
     192 
     193        //Los parametros 
     194        xmlrpc_env env; 
     195        xmlrpc_env_init(&env); 
     196        xmlrpc_value *result = NULL; 
     197        xmlrpc_value *params = xmlrpc_build_value(&env,"(iii)",confId,num,id); 
     198 
     199        //Llamamos 
     200        if (!MakeCall(&env,"SetMosaicSlot",params,&result)) 
     201                return Error("Error al realizar la operacion\n"); 
     202 
     203        //Liberamos 
     204        if (result) 
     205                xmlrpc_DECREF(result); 
     206        if (params) 
     207                xmlrpc_DECREF(params); 
     208        xmlrpc_env_clean(&env); 
     209         
     210        Log("<SetMosaicSlot\n",confId); 
     211 
     212        //Salimos 
     213        return true; 
     214} 
    183215 
    184216/************************************ 
  • media/src/xmlrpcserver.cpp

    r8 r31  
    1111*       Constructor 
    1212**************************************/ 
    13 XmlRpcServer::XmlRpcServer(
     13XmlRpcServer::XmlRpcServer(int port
    1414{ 
    1515        char name[65]; 
     
    2222 
    2323        //Le pasamos como nombre un puntero a nosotros mismos 
    24         sprintf(name,"0x%x",this);     
     24        sprintf(name,"%p",this);       
    2525 
    2626        //Creamos el servidor 
    27         ServerCreate(&srv,name, 8080, DEFAULT_DOCS, NULL); 
     27        ServerCreate(&srv,name, port, DEFAULT_DOCS, NULL); 
    2828 
    2929        //Leemos el fichero de configuracion 
     
    4343int XmlRpcServer::Start() 
    4444{ 
     45        Log("-Start [%p]\n",this); 
    4546 
    4647        return 1; 
     
    5354int XmlRpcServer::Run() 
    5455{ 
    55         Log(">Run [0x%x]\n",this); 
     56        Log(">Run [%p]\n",this); 
    5657 
    5758        //Vamos a buscar en orden inverso 
     
    7778int XmlRpcServer::Stop() 
    7879{ 
     80        Log("-Stop [%p]\n",this); 
     81 
    7982        return 1; 
    8083} 
     
    99102 
    100103        //Get pointer 
    101         sscanf(r->server->name,"%x", &serv); 
     104        sscanf(r->server->name,"%p", &serv); 
    102105 
    103106        //Procesamos la llamada 
Copyright 2006 - Sergio García Murillo
Powered by Trac - Edgewall Software