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

VideoStream.h

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: OptiXDisplayDevice.h
00013 *      $Author: johns $      $Locker:  $               $State: Exp $
00014 *      $Revision: 1.22 $         $Date: 2020/10/15 16:07:31 $
00015 *
00016 ***************************************************************************
00017 * DESCRIPTION:
00018 *   VMD interface for video streaming
00019 *
00020 ***************************************************************************/
00021 
00022 #ifndef VIDEOSTREAM_H
00023 #define VIDEOSTREAM_H
00024 
00025 #define VIDEOSTREAM_SUCCESS  0
00026 #define VIDEOSTREAM_ERROR   -1
00027 
00028 // #define VIDEOSTREAM_STATICBUFS 1
00029 
00030 #include <stdlib.h>
00031 #include "UIObject.h"
00032 #include "WKFUtils.h"
00033 
00034 struct VSMsgHeader_t;
00035 
00036 class VideoStream : public UIObject {
00037   public:
00038     VideoStream(VMDApp *);
00039     ~VideoStream(void);
00040 
00041     int cli_listen(int port);
00042     int cli_connect(const char *hostname, int port);
00043     int cli_wait_msg();
00044     int cli_disconnect();
00045     const char *cli_gethost() { return "Unknown"; };
00046     int cli_getport() { return 0; };
00047     int cli_connected() { return (cli_socket != NULL); }
00048     int cli_decode_frame(unsigned char *cbuf, long cbufsz,
00049                          unsigned char *rgba, int width, int height);
00050 
00051     // client-side UI event transmission routines
00052     int cli_send_rotate_by(float angle, char axis);
00053     int cli_send_translate_by(float dx, float dy, float dz);
00054     int cli_send_scale_by(float scalefactor);
00055     int cli_send_keyboard(int dev, char val, int shift_state);
00056 
00057     int srv_listen(int port);
00058     int srv_connect(const char *hostname, int port);
00059     int srv_send_frame(const unsigned char *rgba, int pitch, 
00060                        int width, int height, int forceIFrame);
00061     int srv_disconnect();
00062     const char *srv_gethost() { return "Unknown"; };
00063     int srv_getport() { return 0; };
00064     int srv_connected() { return (srv_socket != NULL); }
00065 
00066     int set_target_bitrate_Mbps(float Mbps) { 
00067       vs_bitrateMbps = int(Mbps);
00068       vs_codec_reconfig_pending = 1;
00069       return 0;
00070     }
00071 
00072     int set_target_frame_rate(float tfps) { 
00073       vs_targetFPS = int(tfps); 
00074       vs_codec_reconfig_pending = 1;
00075       return 0;
00076     }
00077 
00078     // Key virtual methods inherited from UIObject
00079     int check_event();
00080     int act_on_command(int, Command *);
00081 
00082     // methods used to inform videostream of graphics updates 
00083     // and/or to funnel in incoming image data
00084     void video_frame_pending(const unsigned char *ptr = NULL,
00085                              int pwidth=0, int pheight=0) { 
00086       vs_rgba_pend = ptr;
00087       vs_rgba_width = pwidth;
00088       vs_rgba_height = pheight;
00089       vs_framepending = 1; 
00090     }
00091     void video_frame_force_Iframe() { vs_forceIframe = 1; }
00092 
00093     enum VSEventDev {
00094       VS_EV_NONE,                       
00095       VS_EV_ROTATE_BY,                  
00096       VS_EV_TRANSLATE_BY,               
00097       VS_EV_SCALE_BY,                   
00098       VS_EV_KEYBOARD                    
00099     };
00100 
00101     // special method for use by OptiXRenderer
00102     int srv_check_ui_event();
00103 
00105     int srv_process_all_events() { 
00106       srv_get_one_ui_event=0; 
00107       return 0;
00108     }
00109 
00111     int srv_get_last_event_type(int &eventtype) { 
00112       eventtype = srv_last_event_type; 
00113       return 0;
00114     }
00115 
00117     int srv_get_last_rotate_by(float &angle, int &axis) {
00118       angle = srv_last_rotate_by_angle;
00119       axis = srv_last_rotate_by_axis;
00120 
00121       srv_last_event_type = VS_EV_NONE; // clear event so we read it only once
00122       return 0;
00123     }
00124 
00126     int srv_get_last_translate_by(float &tx, float &ty, float &tz) {
00127       tx = srv_last_translate_by_vec[0];
00128       ty = srv_last_translate_by_vec[1];
00129       tz = srv_last_translate_by_vec[2];
00130  
00131       srv_last_event_type = VS_EV_NONE; // clear event so we read it only once
00132       return 0;
00133     }
00134 
00136     int srv_get_last_scale_by(float &factor) {
00137       factor = srv_last_scale_by_factor;
00138 
00139       srv_last_event_type = VS_EV_NONE; // clear event so we read it only once
00140       return 0;
00141     }
00142 
00144     int srv_get_last_keyboard(int &dev, int &val, int &shift_state) {
00145       dev = srv_last_key_dev;
00146       val = srv_last_key_val;
00147       shift_state = srv_last_key_shift_state;
00148 
00149       srv_last_event_type = VS_EV_NONE; // clear event so we read it only once
00150       return 0;
00151     }
00152 
00153   private:
00154     int srv_get_one_ui_event;           
00155 
00156     int srv_last_event_type;            
00157     int srv_last_rotate_by_axis;        
00158     float srv_last_rotate_by_angle;     
00159     float srv_last_translate_by_vec[3]; 
00160     float srv_last_scale_by_factor;     
00161     int srv_last_key_dev;               
00162     int srv_last_key_val;               
00163     int srv_last_key_shift_state;       
00164 
00165     int vs_framepending;                
00166     const unsigned char *vs_rgba_pend;  
00167     int vs_rgba_width;                  
00168     int vs_rgba_height;                 
00169 
00170     int vs_forceIframe;                 
00171     int vs_width;                       
00172     int vs_height;                      
00173     int vs_targetFPS;                   
00174     int vs_bitrateMbps;                 
00175     int vs_codec_reconfig_pending;      
00176 
00177     double imagesz_comp;                
00178     double imagesz_uncomp;              
00179     double expave_fps;                  
00180 
00181     void *ench;                         
00182     void *cli_socket;                   
00183     void *srv_socket;                   
00184 
00185 #if defined(VIDEOSTREAM_STATICBUFS)
00186     unsigned char *vs_imgbuf;           
00187     int vs_imgbufsz;                    
00188     unsigned char *vs_cbuf;             
00189     int vs_cbufsz;                      
00190 #endif
00191 
00192     wkf_timerhandle timer;              
00193     double lastconsolemesg;             
00194     double cli_lastmsgtime;             
00195     double cli_lastframe;               
00196     double srv_lastmsgtime;             
00197     double srv_lastframe;               
00198     int lastmsgeventloops;              
00199 
00200     enum VSMsgType {
00201         VS_HANDSHAKE,                   
00202         VS_GO,                          
00203         VS_PAUSE,                       
00204         VS_CODEC_RECONFIG,              
00205         VS_IMAGE,                       
00206         VS_RESIZE,                      
00207 #if 0
00208         VS_KILL,                        
00209         VS_TRATE,                       
00210 #endif
00211         VS_UIEVENT,                     
00212         VS_HEARTBEAT,                   
00213         VS_DISCONNECT,                  
00214         VS_IOERROR                      
00215     };
00216 
00217     int vs_encoder_reconfig();
00218 
00219     int vs_recv_handshake(void *sock);
00220     int vs_send_handshake(void *s);
00221 
00222     int vs_recv_header(void *s, VSMsgHeader_t &header);
00223     int vs_recv_header_nolengthswap(void *s, int *length);
00224     int vs_readn(void *s, char *ptr, int n);
00225     int vs_readn_discard(void *s, int n);
00226     int vs_writen(void *s, const char *ptr, int n);
00227     int vs_send_disconnect(void *s);
00228     int vs_send_pause(void *s);
00229     int vs_send_go(void *s); 
00230     int vs_send_heartbeat(void *s);
00231     int vs_send_resize(void *s, int w, int h);
00232     int vs_send_codec_reconfig(void *s, int bitrateMbps, int targetFPS);
00233 };
00234 
00235 #endif

Generated on Wed Oct 9 02:43:41 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002