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

cmd_videostream.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_videostream.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.10 $      $Date: 2020/10/15 17:49:29 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   text commands for interactive MD simulation connection control
00019  ***************************************************************************/
00020 
00021 // #include "CmdVideoStream.h"
00022 #include "VideoStream.h"
00023 #include "CommandQueue.h"
00024 #include "VMDApp.h"
00025 #include "MoleculeList.h"
00026 #include "utilities.h"
00027 #include "config.h"    // for CMDLEN
00028 #include <stdlib.h>
00029 #include <tcl.h>
00030 
00031 int videostream_usage(Tcl_Interp *interp) {
00032   Tcl_AppendResult(interp,
00033     "Usage: videostream [options]: \n",
00034     "  client connect <hostname> <port>\n",
00035     "  client listen <port>\n",
00036     "  server connect <hostname> <port>\n",
00037     "  server listen <port>\n",
00038     "  disconnect",
00039 //    "  detach\n",
00040 //    "  pause [on|off|toggle]\n",
00041 //    "  kill\n",
00042 //    "  transfer <rate>\n",
00043     NULL);
00044   return TCL_ERROR;
00045 }
00046 
00047 
00048 int text_cmd_videostream(ClientData cd, Tcl_Interp *interp, int argc,
00049                          const char *argv[]) {
00050 
00051 #if 1
00052   VMDApp *app = (VMDApp *)cd;
00053 #if 0
00054   CommandQueue *cmdQueue = app->commandQueue; 
00055 #endif
00056 
00057   if (app->uivs == NULL) {
00058     Tcl_AppendResult(interp, "Videostream support is not available.\n", NULL);
00059     return TCL_ERROR;
00060   }
00061 
00062   if (argc == 1) {
00063     return videostream_usage(interp);
00064 
00065 #if 0
00066   } else if (!strupncmp(argv[1], "pause", CMDLEN)) {   
00067     if ((argc == 3) && (!strupncmp(argv[2], "toggle", CMDLEN))) { //"videostream pause"
00068       app->uivs->togglepause();
00069       cmdQueue->runcommand(new CmdVideoStream(CmdVideoStream::PAUSE_TOGGLE));
00070     }
00071     else if ((argc == 3) && (!strupncmp(argv[2], "on", CMDLEN))) {   //"videostream pause on"
00072       app->uivs->pause();
00073       cmdQueue->runcommand(new CmdVideoStream(CmdVideoStream::PAUSE_ON));  
00074     }   
00075     else if ((argc == 3) && (!strupncmp(argv[2], "off", CMDLEN))) {   //"videostream pause off"
00076       app->uivs->unpause();
00077       cmdQueue->runcommand(new CmdVideoStream(CmdVideoStream::PAUSE_OFF));  
00078     }  
00079     else {
00080       Tcl_AppendResult(interp, "Wrong arguments: videostream pause <on|off|toggle>", NULL); 
00081       return TCL_ERROR;
00082     }
00083     
00084     if (!app->uivs->cli_connected()) { 
00085       Tcl_AppendResult(interp, "No videostream connection available.", NULL);
00086       return TCL_ERROR;
00087     }
00088 #endif
00089 
00090   } else if (!strupncmp(argv[1], "disconnect", CMDLEN)) {   
00091     if (app->uivs->cli_connected()) {
00092       app->uivs->cli_disconnect();
00093       Tcl_AppendResult(interp, "Client videostream disconnected.", NULL);
00094       return TCL_OK;
00095     } else if (app->uivs->srv_connected()) {
00096       app->uivs->srv_disconnect();
00097       Tcl_AppendResult(interp, "Server videostream disconnected.", NULL);
00098       return TCL_OK;
00099     } else {
00100       Tcl_AppendResult(interp, "No active videostream connection.", NULL);
00101       return TCL_ERROR;
00102     }
00103   } else if (!strupncmp(argv[1], "bitrate", CMDLEN)) {   
00104     if (argc == 3) {
00105       int brMbps = atoi(argv[3]);
00106       app->uivs->set_target_bitrate_Mbps(float(brMbps));
00107     } else {
00108       return videostream_usage(interp);
00109     }
00110   } else if (!strupncmp(argv[1], "framerate", CMDLEN)) {   
00111     if (argc == 3) {
00112       int tfps = atoi(argv[3]);
00113       app->uivs->set_target_frame_rate(float(tfps));
00114     } else {
00115       return videostream_usage(interp);
00116     }
00117 
00118 //
00119 // Handle "client" subcommands
00120 //
00121   } else if ((argc >= 4) && (!strupncmp(argv[1], "client", CMDLEN)) ) {
00122     if ((argc == 5) && !strupncmp(argv[2], "connect", CMDLEN)) {
00123       int port = atoi(argv[4]);
00124       if (app->uivs->cli_connected()) {
00125         char buf[500];
00126         sprintf(buf, "Can't connect; already connected to videostream server on"
00127                      "host %s over port %d", app->uivs->cli_gethost(), 
00128                       app->uivs->cli_getport());
00129         Tcl_SetResult(interp, buf, TCL_VOLATILE);
00130         return TCL_ERROR;
00131       }
00132       if (app->uivs->cli_connect(argv[3], port)) {
00133         Tcl_AppendResult(interp, "Client unable to connect to server host ", argv[3], 
00134                          " on port ", argv[4], NULL);
00135         return TCL_ERROR;
00136       } else {
00137         Tcl_AppendResult(interp, "Client connected to server host ", argv[3], 
00138                          " on port ", argv[4], NULL);
00139         return TCL_OK;
00140       }
00141     } else if ((argc == 4) && !strupncmp(argv[2], "listen", CMDLEN)) {
00142       int port = atoi(argv[3]);
00143       if (app->uivs->cli_connected()) {
00144          Tcl_AppendResult(interp, "Can't listen for new server; already connected to videostream server", NULL);
00145         return TCL_ERROR;
00146       }
00147       if (app->uivs->cli_listen(port)) {
00148         Tcl_AppendResult(interp, "Unable to listen for videostream servers on port ", argv[3], NULL);
00149         return TCL_ERROR;
00150       }
00151     } else {
00152       return videostream_usage(interp);
00153     }
00154 //
00155 // Handle "server" subcommands
00156 //
00157   } else if ((argc >= 4) && (!strupncmp(argv[1], "server", CMDLEN)) ) {
00158     if ((argc == 4) && (!strupncmp(argv[2], "listen", CMDLEN)) ) {
00159       int port = atoi(argv[3]);
00160       if (app->uivs->srv_connected()) {
00161          Tcl_AppendResult(interp, "Can't listen for new clients; already connected to videostream client", NULL);
00162         return TCL_ERROR;
00163       }
00164       if (app->uivs->srv_listen(port)) {
00165         Tcl_AppendResult(interp, "Unable to listen for videostream clients on port ", argv[3], NULL);
00166         return TCL_ERROR;
00167       }
00168     } else if ((argc == 5) && (!strupncmp(argv[2], "connect", CMDLEN)) ) {
00169       int port = atoi(argv[4]);
00170       if (app->uivs->srv_connected()) {
00171         char buf[500];
00172         sprintf(buf, "Can't connect; already connected to videostream client on"
00173                      "host %s over port %d", app->uivs->srv_gethost(),
00174                       app->uivs->srv_getport());
00175         Tcl_SetResult(interp, buf, TCL_VOLATILE);
00176         return TCL_ERROR;
00177       }
00178       if (app->uivs->srv_connect(argv[3], port)) {
00179         Tcl_AppendResult(interp, "Server unable to connect to client host ", argv[3],
00180                          " on port ", argv[4], NULL);
00181         return TCL_ERROR;
00182       } else {
00183         Tcl_AppendResult(interp, "Server connected to client host ", argv[3],         
00184                          " on port ", argv[4], NULL);
00185         return TCL_OK;
00186       }
00187     } else {
00188       return videostream_usage(interp);
00189     }
00190  
00191 #if 0
00192   } else if (argc == 2) {
00193     if (!app->uivs->cli_connected()) {
00194       Tcl_AppendResult(interp, "No videostream connection available.", NULL);
00195       return TCL_ERROR;
00196     }
00197     else if (!strupncmp(argv[1], "detach", CMDLEN)) {
00198       app->uivs->detach();
00199       cmdQueue->runcommand(new CmdVideoStream(CmdVideoStream::DETACH));
00200     } else if (!strupncmp(argv[1], "kill", CMDLEN)) {
00201       app->uivs->kill();
00202       cmdQueue->runcommand(new CmdVideoStream(CmdVideoStream::KILL));
00203     } else {
00204       return videostream_usage(interp);
00205     }
00206 
00207   } else if ((argc == 3) && (!strupncmp(argv[1], "transfer", CMDLEN)) ) {
00208     int rate = atoi(argv[2]);
00209     app->uivs->set_trans_rate(rate);
00210     cmdQueue->runcommand(new CmdVideoStreamRate(CmdVideoStreamRate::TRANSFER, rate));
00211 #endif
00212 
00213   } else {
00214     return videostream_usage(interp);
00215   }
00216 
00217   return TCL_OK; // No error
00218 #else
00219   Tcl_AppendResult(interp,
00220     "Video streaming functionality not present.  Recompile with it enabled.", NULL);
00221   return TCL_ERROR;
00222 #endif
00223 }
00224 
00225 

Generated on Thu Mar 28 02:42:37 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002