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

mxcpcAsynchronousCameraLiveMxPEGFastStream.h

00001 //           ///          //                                        Mx clientSDK
00002 //          /////        ////                    Mx Crossplatform Client Library
00003 //         /// XXX     XXX ///
00004 //        ///    XXX XXX    ///     $RCSfile: mxcpcAsynchronousCameraLiveMxPEGFastStream.h,v $
00005 //       ///       XXX       ///     $Revision: 1.5 $
00006 //      ///      XXX XXX      ///     $Date: 2006/01/05 11:56:09 $
00007 //     ////    XXX     XXX    ////     $Author: cvs-kai $
00008 //    ////                     ////
00009 //   ////  M  O  B  O  T  I  X  ////////////////////////////////////////////////
00010 //  //// Security Vision Systems //////////////////////////////////////////////
00011 //                                                                          //
00012 //  Copyright (C) 2005 - 2006, MOBOTIX AG, Germany                         //
00013 //  This software is made available under the BSD licence. Please refer   //
00014 //  to the file LICENCE.TXT contained in this distribution for details.  //
00015 //                                                                      //
00016 //  /////////////////////////////////////////////////////////////////////
00017 
00018 
00019 
00020 #ifndef __MXCPC_ASYNCHRONOUSCAMERALIVEMXPEGFASTSTREAM_H__
00021 #define __MXCPC_ASYNCHRONOUSCAMERALIVEMXPEGFASTSTREAM_H__
00022 
00023 
00024 
00025 #define MXCPC_ASYNCHRONOUSCAMERALIVEMXPEGFASTSTREAM_HEADERBUFFER_SIZE 1024
00026 
00027 
00028 
00029 #include <mxcpcCameraLiveMxPEGFastStream.h>
00030 #include <mxcpcIPAddress.h>
00031 #include <mxcpcProxyConfiguration.h>
00032 
00033 #include <QTcpSocket>
00034 
00035 
00036 
00037 //! Camera FastStream implementation using an asynchronous <tt>Qt</tt>
00038 //! TCP socket.
00039 /*!
00040     \ingroup mxcpc_tek
00041     
00042     Due to the socket's asynchronous nature the fetchBytes() method will not 
00043     block in case no data is available - it will return <tt>0</tt> instead. To
00044     circumvent the need for polling, connect to the bytesAvailable() signal that
00045     will fire when new data comes in over the network.
00046 
00047     If on the specified camera access to live streaming is restricted, the
00048     stream source will automatically handle the HTTP negotiation necessary to
00049     properly authenticate the user, including requesting and authentification 
00050     information via  appropriate signals and slots. Failure to authenticate is
00051     logged via the <tt>mxcpc</tt> status message facility.
00052 */
00053 class mxcpcAsynchronousCameraLiveMxPEGFastStream
00054        : public QObject,
00055          public mxcpcCameraLiveMxPEGFastStream   {
00056 
00057   Q_OBJECT
00058 
00059  private:
00060   enum HTTPNegotiationState {
00061     SendGET_NoAuth,
00062     ReceiveResponseHeader_NoAuth,
00063     RaisedAuthenticationDialog,
00064     WaitForAuthenticationDialog,
00065     SendGET_EnteredAuth,
00066     ReceiveResponseHeader_EnteredAuth,
00067     NegotiationSucceeded,
00068     NegotiationFailed
00069   };
00070   
00071  private:
00072   QTcpSocket *AsyncSocket;
00073   mxcpcIPAddress CameraIP;
00074   int CameraPort;
00075   mxcpcProxyConfiguration CameraProxyConfiguration;
00076   float FPS;
00077   bool HTTPNegotiationMode;
00078   HTTPNegotiationState NegotiationState;
00079   char HTTPHeaderBuffer
00080         [MXCPC_ASYNCHRONOUSCAMERALIVEMXPEGFASTSTREAM_HEADERBUFFER_SIZE];
00081   int HTTPHeaderBytesRead;
00082   int HTTPHeaderSize;      
00083   bool AuthenticationEntered;
00084   bool AuthenticationDialogRaised;
00085   bool AuthenticationDialogWasRaised;
00086   QString AuthenticationUser;
00087   QString AuthenticationPassword;
00088   
00089  public:
00090   mxcpcAsynchronousCameraLiveMxPEGFastStream(
00091     const mxcpcIPAddress& camera_ip, 
00092     int camera_port,
00093     const mxcpcProxyConfiguration& camera_proxy_configuration,
00094     float fps = 4
00095   );
00096   mxcpcAsynchronousCameraLiveMxPEGFastStream(const mxcpcIPAddress& camera_ip, 
00097                                              int port,
00098                                              float fps = 4);
00099   mxcpcAsynchronousCameraLiveMxPEGFastStream(const mxcpcIPAddress& camera_ip, 
00100                                              int port,
00101                                              int fps = 4);
00102   mxcpcAsynchronousCameraLiveMxPEGFastStream(int ip1, int ip2, int ip3, int ip4, 
00103                                              int port,
00104                                              int fps = 4);
00105   ~mxcpcAsynchronousCameraLiveMxPEGFastStream();
00106  private:
00107   void constructCommonStuff(const mxcpcIPAddress& camera_ip, int camera_port,
00108                             float fps);  
00109   
00110  signals:
00111   //! Emitted when bytes have become available to be read.
00112   void bytesAvailable(void);
00113   //! Emitted when during negotiation with the camera, need arises to 
00114   //! get authentication information about the user.
00115   /*!
00116    *  Originally indended to be connected to an mycpcAuthenticationDialog's
00117    *  raise() slot.
00118    *
00119    *  By using the component-oriented signal/slot-mechanism, we avoid doing an
00120    *  upcall from the <tt>mxcpc_tek</tt> to the <tt>mxcpc_gui</tt> library.
00121    */
00122   void authenticationRequest(QString msg);
00123   
00124  public slots:
00125   //! To be activated from an external place after the faststream source has
00126   //! emmitted the authenticationRequest() signal, or, alternatively:
00127   //! the processAuthenticationCancellation() slot.
00128   void processAuthentication(const QString& user, const QString& password);
00129   //! To be activated from an external place after the faststream source has
00130   //! emmitted the authenticationRequest() signal, or, alternatively:
00131   //! the processAuthentication() slot.
00132   void processAuthenticationCancellation(void);
00133   
00134  public:
00135   //! Reimplemented.
00136   int fetchBytes(unsigned char *buffer, int num);
00137   //! Reimplemented.
00138   bool stillUp(void);
00139   //! Blocks for incoming.
00140   bool waitForBytes(int timeout_msecs = -1);
00141   //! Tells whether or not the stream source's authentication dialog is 
00142   //! currently raised.
00143   bool isAuthenticationDialogRaised(void);
00144   //! Tells whether or not the stream source's authentication dialog was 
00145   //! raised since the last call to this method.
00146   bool wasAuthenticationDialogRaised(void);
00147   
00148  private slots:
00149   //! Connected to the encapsuled socket's readyRead() signal.
00150   void processIncomingBytes(void);
00151   
00152  private:
00153   //! Internal method.
00154   void establishConnection(void);
00155   //! Internal method.
00156   void sendGETRequest(const char *user = 0, const char *password = 0);
00157   //! Internal method.
00158   bool receiveHTTPHeader(void);
00159 };
00160 
00161 
00162 
00163 #endif   // __MXCPC_ASYNCHRONOUSCAMERALIVEMXPEGFASTSTREAM_H__
00164 

Generated on Mon Jan 30 15:52:41 2006 for mxcpc by  doxygen 1.4.4