Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phPlayerPtz.cpp

Go to the documentation of this file.
00001 #include <playerc.h>
00002 
00003 #include <phPlayerPtz.h>
00004 #include <phPlayer.h>
00005 #include <phbase.h>
00006 
00007 /* ------------------------------------------------------------------------ */
00008 struct ph_player_ptz_t
00009 {
00010     playerc_ptz_t *m_player_ptz;
00011 };
00012 
00013 /* ------------------------------------------------------------------------ */
00014 phPlayerPtz::phPlayerPtz( )
00015 {
00016     phFUNCTION("phPlayerPtz::phPlayerPtz")
00017     int locked = 0;
00018 
00019     phTHIS_LOOSE_LOCK(locked);
00020     
00021     this->setName("phPlayerPtz");
00022 
00023     this->m_ptz = (struct ph_player_ptz_t *)phCalloc(1,
00024                         sizeof(struct ph_player_ptz_t));
00025     phPRINT_PTR(this->m_ptz,"phCalloc","phCalloc failed");
00026 
00027     this->m_last_pan        = 0.0;
00028     this->m_last_tilt       = 0.0;
00029     this->m_last_zoom       = 0.0;
00030     this->m_last_pan_speed  = 0.0;
00031     this->m_last_tilt_speed = 0.0;
00032     this->m_pan_speed       = 1.0;
00033     this->m_tilt_speed      = 1.0;
00034 
00035     /*
00036     this->m_source = this->m_data = new phPtzData();
00037     phPRINT_PTR(this->m_source,"new", "new failed");
00038     */
00039     phTHIS_LOOSE_UNLOCK(locked);
00040 }
00041 
00042 /* ------------------------------------------------------------------------ */
00043 phPlayerPtz::phPlayerPtz( int index, phPlayerClient *client )
00044 {
00045     phFUNCTION("phPlayerPtz::phPlayerPtz")
00046     int locked = 0;
00047 
00048     phTHIS_LOOSE_LOCK(locked);
00049     
00050     phPlayerPtz();
00051 
00052     rc = this->set(index,client);
00053     phPRINT_RC(rc,NULL,"this->set(%d,%p)\n",index,client);
00054 
00055     phTHIS_LOOSE_UNLOCK(locked);
00056 }
00057 
00058 /* ------------------------------------------------------------------------ */
00059 phPlayerPtz::~phPlayerPtz( )
00060 {
00061     phFUNCTION("phPlayerPositon::~phPlayerPtz")
00062     int locked = 0;
00063 
00064     phTHIS_LOOSE_LOCK(locked);
00065     
00066     if (this->m_ptz != NULL)
00067     {
00068         if (this->m_is_subscribed)
00069         {
00070             rc = this->unsubscribe();
00071             phPRINT_RC(rc,NULL,"this->unsubscribe()");
00072         }
00073    
00074         if (this->m_ptz->m_player_ptz != NULL)
00075         {
00076             playerc_ptz_destroy(this->m_ptz->m_player_ptz);
00077             this->m_ptz->m_player_ptz = NULL;
00078         }
00079 
00080         phFree(this->m_ptz);
00081     }
00082         
00083     rc = this->resetLastVars();
00084     phPRINT_RC(rc,NULL,"this->resetLastVars()");
00085 
00086     this->m_ptz   = NULL;
00087     //phDelete(this->m_data);
00088     
00089     phTHIS_LOOSE_UNLOCK(locked);
00090 }
00091 
00092 /* ------------------------------------------------------------------------ */
00093 int phPlayerPtz::set( int index, phPlayerClient *client )
00094 {
00095     phFUNCTION("phPlayerPtz::set")
00096     int locked = 0;
00097 
00098     if (this->m_ptz == NULL) return phFAIL;
00099 
00100     phTHIS_LOCK(locked);
00101 
00102     if (index >= 0)
00103         this->m_index = index;
00104         
00105     if (client != NULL)
00106         this->m_client = client;
00107 
00108     if (this->m_is_subscribed)
00109     {
00110         rc = this->unsubscribe();
00111         phPRINT_RC(rc,NULL,"this->unsubscribe()");
00112     }
00113    
00114     if (this->m_ptz->m_player_ptz != NULL)
00115     {
00116         playerc_ptz_destroy(this->m_ptz->m_player_ptz);
00117         this->m_ptz->m_player_ptz = NULL;
00118         this->m_is_subscribed = 0;
00119         
00120         rc = this->resetLastVars();
00121         phPRINT_RC(rc,NULL,"this->resetLastVars()");
00122     }
00123 
00124     if ((this->m_ptz->m_player_ptz == NULL) &&
00125         (this->m_client != NULL))
00126     {
00127         this->m_ptz->m_player_ptz = 
00128                 playerc_ptz_create((playerc_client_t*)this->m_client->getClientPtr(),
00129                                         index);
00130         phPRINT_PTR(this->m_ptz->m_player_ptz,
00131                     "playerc_ptz_create","playerc_ptz_create");
00132         if (this->m_ptz->m_player_ptz != NULL)
00133         {
00134             this->m_is_subscribed = 0;
00135         
00136             rc = this->resetLastVars();
00137             phPRINT_RC(rc,NULL,"this->resetLastVars()");
00138         }
00139     }
00140  
00141     phTHIS_UNLOCK(locked);
00142     
00143     return phSUCCESS;
00144 error:
00145     phTHIS_ERROR_UNLOCK(locked);
00146 
00147     return phFAIL;
00148 }
00149 
00150 /* ------------------------------------------------------------------------ */
00151 int phPlayerPtz::subscribe( int access, int index, phPlayerClient *client )
00152 {
00153     phFUNCTION("phPlayerPtz::subscribe")
00154     int locked = 0;
00155     int retrc = phSUCCESS;
00156 
00157     phTHIS_LOCK(locked);
00158     
00159     rc = this->set(index,client);
00160     phPRINT_RC(rc,NULL,"this->set(client:%p)",client);
00161 
00162     retrc = this->subscribe( access );
00163 
00164     phTHIS_UNLOCK(locked);
00165 
00166     return retrc;
00167 error:
00168     phTHIS_ERROR_UNLOCK(locked);
00169 
00170     return phFAIL;
00171 }
00172 
00173 /* ------------------------------------------------------------------------ */
00174 int phPlayerPtz::subscribe( int phaccess )
00175 {
00176     phFUNCTION("phPlayerPtz::subscribe")
00177     int locked = 0;
00178     int access = 0;
00179     int tries = 0;
00180     int max_tries = 35;
00181 
00182     if (this->m_ptz == NULL) return phFAIL;
00183 
00184     phCHECK_PTR(this->m_client,NULL,"No client to subscribe to; call 'set'");
00185 
00186     phTHIS_LOCK(locked);
00187 
00188     if (this->m_is_subscribed)
00189     {
00190         this->unsubscribe();
00191     }
00192   
00193     if ((this->m_ptz->m_player_ptz != NULL) && 
00194         (!this->m_is_subscribed))
00195     {
00196         switch(phaccess)
00197         {
00198             case phMODE_READ:
00199                 access = PLAYER_READ_MODE;
00200                 break;
00201             case phMODE_WRITE:
00202                 access = PLAYER_WRITE_MODE;
00203                 break;
00204             case phMODE_ALL:
00205                 access = PLAYER_ALL_MODE;
00206                 break;
00207             case phMODE_CLOSE:
00208                 access = PLAYER_CLOSE_MODE;
00209                 break;
00210             case phMODE_ERROR:
00211                 access = PLAYER_ERROR_MODE;
00212                 break;
00213             default:
00214                 access = PLAYER_ALL_MODE;
00215                 break;
00216         }
00217         
00218         do 
00219         {
00220             rc = playerc_ptz_subscribe(this->m_ptz->m_player_ptz,access);
00221             tries++;
00222         } while ((rc != phSUCCESS) && (tries <= max_tries));
00223         PLAYER_PRINT_RC(rc,"playerc_ptz_subscribe","playerc_ptz_subscribe");
00224 
00225         if (rc == 0)
00226             this->m_is_subscribed = 1;
00227         else
00228             this->m_is_subscribed = 0;
00229 
00230         if ((this->m_client != NULL) && (this->m_is_subscribed))
00231         {
00232             rc = this->m_client->subscribeDevice(this);
00233             phPRINT_RC(rc,NULL,"this->m_client->subsribeDevice");
00234         }
00235     }
00236     
00237     phTHIS_UNLOCK(locked);
00238 
00239     return phSUCCESS;
00240 error:
00241     phTHIS_ERROR_UNLOCK(locked);
00242 
00243     return phFAIL;
00244 }
00245 
00246 /* ------------------------------------------------------------------------ */
00247 int phPlayerPtz::unsubscribe()
00248 {
00249     phFUNCTION("phPlayerPtz::unsubscribe")
00250     int locked = 0;
00251 
00252     if (this->m_ptz == NULL) return phFAIL;
00253 
00254     phTHIS_LOCK(locked);
00255 
00256     if ((this->m_client != NULL) && (this->m_is_subscribed))
00257     {
00258         rc = this->m_client->unsubscribeDevice(this);
00259         phPRINT_RC(rc,NULL,"this->m_client->unsubsribeDevice");
00260     }
00261     
00262     if (this->m_ptz->m_player_ptz != NULL)
00263     {
00264         rc = playerc_ptz_unsubscribe(this->m_ptz->m_player_ptz);
00265         PLAYER_PRINT_RC(rc,"playerc_ptz_unsubscribe","playerc_ptz_unsubscribe");
00266             
00267         this->m_is_subscribed = 0;
00268         
00269         rc = this->resetLastVars();
00270         phPRINT_RC(rc,NULL,"this->resetLastVars()");
00271     }
00272 
00273     phTHIS_UNLOCK(locked);
00274 
00275     return phSUCCESS;
00276 error:
00277     phTHIS_ERROR_UNLOCK(locked);
00278 
00279     return phFAIL;
00280 }
00281 
00282 /* ------------------------------------------------------------------------ */
00283 int phPlayerPtz::resetLastVars( )
00284 {
00285     phFUNCTION("phPlayerPosition::resetLastVars")
00286     int locked = 0;
00287 
00288     phTHIS_LOCK(locked);
00289 
00290     this->m_last_pan        = 0.0;
00291     this->m_last_tilt       = 0.0;
00292     this->m_last_zoom       = 0.0;
00293     this->m_last_pan_speed  = 0.0;
00294     this->m_last_tilt_speed = 0.0;
00295     
00296     phTHIS_UNLOCK_RET(locked,phSUCCESS,phFAIL);
00297 }
00298 
00299 /* ------------------------------------------------------------------------ */
00300 int phPlayerPtz::setPtz( double pan, double tilt, double zoom,
00301                          double pan_speed, double tilt_speed )
00302 {
00303     return this->panTiltZoomSpeed(pan,tilt,zoom,pan_speed,tilt_speed);
00304 }
00305 
00306 /* ------------------------------------------------------------------------ */
00307 int phPlayerPtz::panTiltZoomSpeed( double pan, double tilt, double zoom,
00308                                     double pan_speed, double tilt_speed )
00309 {
00310     phFUNCTION("phPlayerPosition::panTiltZoom")
00311     int locked = 0;
00312 
00313     if (this->m_ptz == NULL) return phFAIL;
00314 
00315     phTHIS_LOCK(locked);
00316 
00317     if (this->m_ptz->m_player_ptz != NULL)
00318     {
00319         if ((this->m_last_pan != pan) ||
00320             (this->m_last_tilt != tilt) ||
00321             (this->m_last_zoom != zoom) ||
00322             ((this->m_last_pan_speed != pan_speed)  && (pan_speed  > 0.0)) ||
00323             ((this->m_last_tilt_speed != tilt_speed)&& (tilt_speed > 0.0)))
00324         {
00325             /* check method arguments */
00326             pan_speed = (pan_speed > 0.0) ? pan_speed : this->m_pan_speed;
00327             tilt_speed = (tilt_speed > 0.0) ? tilt_speed : this->m_tilt_speed;
00328             /* check private variable values */
00329             pan_speed = (pan_speed > 0.0) ? pan_speed : 1.0;
00330             tilt_speed = (tilt_speed > 0.0) ? tilt_speed : 1.0;
00331             
00332             rc = playerc_ptz_set_ws(this->m_ptz->m_player_ptz,
00333                                  pan,tilt,zoom,pan_speed,tilt_speed);
00334             PLAYER_PRINT_RC(rc,"playerc_ptz_set","playerc_ptz_set");
00335             
00336         this->m_ptz->m_player_ptz->pan= pan;
00337         this->m_ptz->m_player_ptz->tilt= tilt;
00338         this->m_ptz->m_player_ptz->zoom= zoom;
00339 
00340             this->m_last_pan            = pan;
00341             this->m_last_tilt           = tilt;
00342             this->m_last_zoom           = zoom;
00343             if (pan_speed > 0.0)
00344                 this->m_last_pan_speed      = pan_speed;
00345             if (tilt_speed > 0.0)
00346                 this->m_last_tilt_speed     = tilt_speed;
00347         }
00348     }
00349 
00350     phTHIS_UNLOCK_RET(locked,phSUCCESS,phFAIL);
00351 
00352 }
00353 
00354 /* ------------------------------------------------------------------------ */
00355 int phPlayerPtz::panTiltZoom( double pan, double tilt, double zoom )
00356 {
00357     phFUNCTION("phPlayerPosition::panTiltZoom")
00358     int locked = 0;
00359 
00360     if (this->m_ptz == NULL) return phFAIL;
00361 
00362     phTHIS_LOCK(locked);
00363 
00364     if (this->m_ptz->m_player_ptz != NULL)
00365     {
00366         if ((this->m_last_pan != pan) ||
00367             (this->m_last_tilt != tilt) ||
00368             (this->m_last_zoom != zoom))
00369         {
00370             rc = playerc_ptz_set(this->m_ptz->m_player_ptz,
00371                                  pan,tilt,zoom);
00372             PLAYER_PRINT_RC(rc,"playerc_ptz_set","playerc_ptz_set");
00373             
00374         this->m_ptz->m_player_ptz->pan= pan;
00375         this->m_ptz->m_player_ptz->tilt= tilt;
00376         this->m_ptz->m_player_ptz->zoom= zoom;
00377 
00378             this->m_last_pan = pan;
00379             this->m_last_tilt = tilt;
00380             this->m_last_zoom = zoom;
00381         }
00382     }
00383 
00384     phTHIS_UNLOCK_RET(locked,phSUCCESS,phFAIL);
00385 }
00386 
00387 /* ------------------------------------------------------------------------ */
00388 int phPlayerPtz::panTilt( double pan, double tilt)
00389 {
00390     phFUNCTION("phPlayerPosition::panTilt")
00391     int locked = 0;
00392     int retval = 0;
00393 
00394     if (this->m_ptz == NULL) return phFAIL;
00395 
00396     phTHIS_LOCK(locked);
00397 
00398     if (this->m_ptz->m_player_ptz != NULL)
00399     {
00400         retval = this->panTiltZoom(pan,tilt,this->m_last_zoom);
00401     }
00402 
00403     phTHIS_UNLOCK_RET(locked,retval,phFAIL);
00404 }
00405 
00406 /* ------------------------------------------------------------------------ */
00407 int phPlayerPtz::pan( double pan )
00408 {
00409     phFUNCTION("phPlayerPosition::pan")
00410     int locked = 0;
00411     int retval = 0;
00412 
00413     if (this->m_ptz == NULL) return phFAIL;
00414 
00415     phTHIS_LOCK(locked);
00416 
00417     if (this->m_ptz->m_player_ptz != NULL)
00418     {
00419         retval = this->panTiltZoom(pan,this->m_last_tilt,this->m_last_zoom);
00420     }
00421 
00422     phTHIS_UNLOCK_RET(locked,retval,phFAIL);
00423 }
00424 
00425 /* ------------------------------------------------------------------------ */
00426 int phPlayerPtz::tilt( double tilt )
00427 {
00428     phFUNCTION("phPlayerPosition::tilt")
00429     int locked = 0;
00430     int retval = 0;
00431 
00432     if (this->m_ptz == NULL) return phFAIL;
00433 
00434     phTHIS_LOCK(locked);
00435 
00436     if (this->m_ptz->m_player_ptz != NULL)
00437     {
00438         retval = this->panTiltZoom(this->m_last_pan,tilt,this->m_last_zoom);
00439     }
00440 
00441     phTHIS_UNLOCK_RET(locked,retval,phFAIL);
00442 }
00443 
00444 /* ------------------------------------------------------------------------ */
00445 int phPlayerPtz::zoom( double zoom )
00446 {
00447     phFUNCTION("phPlayerPosition::zoom")
00448     int locked = 0;
00449     int retval = 0;
00450 
00451     if (this->m_ptz == NULL) return phFAIL;
00452 
00453     phTHIS_LOCK(locked);
00454 
00455     if (this->m_ptz->m_player_ptz != NULL)
00456     {
00457         retval = this->panTiltZoom(this->m_last_pan,this->m_last_tilt,zoom);
00458     }
00459 
00460     phTHIS_UNLOCK_RET(locked,retval,phFAIL);
00461 }
00462 
00463 /* ------------------------------------------------------------------------ */
00464 int phPlayerPtz::home( )
00465 {
00466     phFUNCTION("phPlayerPosition::home")
00467     int locked = 0;
00468     int retval = 0;
00469 
00470     if (this->m_ptz == NULL) return phFAIL;
00471 
00472     phTHIS_LOCK(locked);
00473 
00474     if (this->m_ptz->m_player_ptz != NULL)
00475     {
00476         retval = this->panTiltZoom(0.0,0.0,0.0);
00477     }
00478 
00479     phTHIS_UNLOCK_RET(locked,retval,phFAIL);
00480 }
00481 
00482 /* ------------------------------------------------------------------------ */
00483 int phPlayerPtz::panSpeed( double pan_speed )
00484 {
00485     phFUNCTION("phPlayerPosition::panSpeed")
00486     int locked = 0;
00487 
00488     phTHIS_LOCK(locked);
00489 
00490     if (pan_speed > 0.0)
00491         this->m_pan_speed = pan_speed;
00492 
00493     phTHIS_UNLOCK_RET(locked,phSUCCESS,phFAIL);
00494 }
00495 
00496 /* ------------------------------------------------------------------------ */
00497 int phPlayerPtz::tiltSpeed( double tilt_speed )
00498 {
00499     phFUNCTION("phPlayerPosition::tiltSpeed")
00500     int locked = 0;
00501 
00502     phTHIS_LOCK(locked);
00503 
00504     if (tilt_speed > 0.0)
00505         this->m_tilt_speed = tilt_speed;
00506 
00507     phTHIS_UNLOCK_RET(locked,phSUCCESS,phFAIL);
00508 }
00509 
00510 /* ------------------------------------------------------------------------ */
00511 int phPlayerPtz::get(double *pan, double *tilt, double *zoom)
00512 {
00513     phFUNCTION("phPlayerPtz::get")
00514     int     locked  = 0;
00515 
00516     if (this->m_ptz == NULL)                return phFAIL;
00517     if (this->m_ptz->m_player_ptz == NULL)  return phFAIL;
00518 
00519     phTHIS_LOCK(locked);
00520 
00521     if (pan != NULL)
00522         *pan  = this->m_ptz->m_player_ptz->pan;
00523     if (tilt != NULL)
00524         *tilt = this->m_ptz->m_player_ptz->tilt;
00525     if (zoom != NULL)
00526         *zoom = this->m_ptz->m_player_ptz->zoom;
00527 
00528     phTHIS_UNLOCK_RET(locked,phSUCCESS,phFAIL);
00529 }
00530 
00531 /* ------------------------------------------------------------------------ */
00532 double phPlayerPtz::getPan()
00533 {
00534     phFUNCTION("phPlayerPtz::getPan")
00535     int     locked  = 0;
00536     double  retval  = 0.0;
00537 
00538     if (this->m_ptz == NULL)                return 0.0;
00539     if (this->m_ptz->m_player_ptz == NULL)  return 0.0;
00540 
00541     phTHIS_LOCK(locked);
00542 
00543     retval = this->m_ptz->m_player_ptz->pan;
00544 
00545     phTHIS_UNLOCK_RET(locked,retval,0.0);
00546 }
00547 
00548 /* ------------------------------------------------------------------------ */
00549 double phPlayerPtz::getTilt()
00550 {
00551     phFUNCTION("phPlayerPtz::getTilt")
00552     int     locked  = 0;
00553     double  retval  = 0.0;
00554 
00555     if (this->m_ptz == NULL)                return 0.0;
00556     if (this->m_ptz->m_player_ptz == NULL)  return 0.0;
00557 
00558     phTHIS_LOCK(locked);
00559 
00560     retval = this->m_ptz->m_player_ptz->tilt;
00561 
00562     phTHIS_UNLOCK_RET(locked,retval,0.0);
00563 }
00564 
00565 /* ------------------------------------------------------------------------ */
00566 double phPlayerPtz::getZoom()
00567 {
00568     phFUNCTION("phPlayerPtz::getZoom")
00569     int     locked  = 0;
00570     double  retval  = 0.0;
00571 
00572     if (this->m_ptz == NULL)                return 0.0;
00573     if (this->m_ptz->m_player_ptz == NULL)  return 0.0;
00574 
00575     phTHIS_LOCK(locked);
00576 
00577     retval = this->m_ptz->m_player_ptz->zoom;
00578 
00579     phTHIS_UNLOCK_RET(locked,retval,0.0);
00580 }
00581 /* ------------------------------------------------------------------------ */
00582 int phPlayerPtz::updateData()
00583 {
00584     phFUNCTION("phPlayerPtz::updateData")
00585     int             locked              = 0;
00586     int             data_locked         = 0;
00587     int             data_rwlocked       = 0;
00588     playerc_ptz_t *pptz             = NULL;
00589     
00590     
00591     int     i       = 0;
00592     int     changed = 0;
00593 
00594     //phPROGRESS("\n");
00595     if (this->m_ptz == NULL) return phFAIL;
00596 
00597     phTHIS_LOCK(locked);
00598     
00599     /*
00600     phPROGRESS("%0.4f:%0.4f:%0.4f\n",
00601              this->m_ptz->m_player_ptz->pan,
00602              this->m_ptz->m_player_ptz->tilt,
00603              this->m_ptz->m_player_ptz->zoom );
00604     */
00605     /*phPROGRESS("\n");*/
00606     if (this->m_ptz->m_player_ptz != NULL)
00607     {
00608         /*
00609         phMUTEX_LOCK((*(this->m_data)),data_locked);
00610         phWRITELOCK((*(this->m_data)),data_rwlocked);
00611         
00612         pptz = this->m_ptz->m_player_ptz;
00613 
00614         if (changed)
00615         {
00616             phCHECK_RC(rc,NULL,"this->m_data->set()");
00617         }
00618 
00619         phRWUNLOCK((*(this->m_data)),data_rwlocked);
00620         phMUTEX_UNLOCK((*(this->m_data)),data_locked);
00621         */
00622     }
00623     
00624     phTHIS_UNLOCK(locked);
00625 
00626     return phSUCCESS;
00627     
00628 error:
00629     /*
00630     phRWUNLOCK_ERROR((*(this->m_data)),data_rwlocked);
00631     phMUTEX_ERROR_UNLOCK((*(this->m_data)),data_locked);
00632     */
00633     phTHIS_ERROR_UNLOCK(locked);
00634 
00635     return phFAIL;
00636 }
00637 
00638 /* ------------------------------------------------------------------------ */
00639 void *phPlayerPtz::getId()
00640 {
00641     void *retrc = NULL;
00642     if (this->m_ptz != NULL)
00643     {
00644         retrc = this->m_ptz->m_player_ptz->info.id;
00645     }
00646     return retrc;
00647 }
00648 
00649 




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:07 2007 for phission by  doxygen 1.4.4