]> git.saurik.com Git - wxWidgets.git/commitdiff
Added GSocket/wxSocket alias to socket.h to prevent us from using GSocket
authorGuilhem Lavaux <lavaux@easynet.fr>
Sun, 5 Sep 1999 05:51:05 +0000 (05:51 +0000)
committerGuilhem Lavaux <lavaux@easynet.fr>
Sun, 5 Sep 1999 05:51:05 +0000 (05:51 +0000)
internal symbols
Added G721 filter for Wave
Fixed a bug in wxsocket sample

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3563 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/sckipc.h
include/wx/socket.h
samples/wxsocket/client.cpp
src/common/sckipc.cpp
src/common/socket.cpp
src/gtk/gsockgtk.c
src/gtk1/gsockgtk.c
utils/wxMMedia2/lib/sndwav.cpp
utils/wxMMedia2/lib/sndwav.h

index 9cbc4735e5c15b7e65ebe8d1b1fc88201e3b5c34..586b0d06effcf7df94aa475690151552378d1a86 100644 (file)
@@ -63,9 +63,9 @@ protected:
   friend class wxTCPServer;
   friend class wxTCPClient;
   friend void Client_OnRequest(wxSocketBase&,
-                              GSocketEvent, char *);
+                              wxSocketNotify, char *);
   friend void Server_OnRequest(wxSocketServer&,
-                              GSocketEvent, char *);
+                              wxSocketNotify, char *);
 public:
 
   wxTCPConnection(char *buffer, int size);
index 496f5a47de73756a3c2c21f21d201fe7b8c055b2..ec578d12d981059cbb9d399200a2446dd9d17ba4 100644 (file)
 #include "wx/sckaddr.h"
 #include "wx/gsocket.h"
 
+// ------------------------------------------------------------------------
+// GSocket type alias
+// ------------------------------------------------------------------------
+
+typedef enum {
+  wxSOCKET_INPUT = GSOCK_INPUT,
+  wxSOCKET_OUTPUT = GSOCK_OUTPUT,
+  wxSOCKET_CONNECTION = GSOCK_CONNECTION,
+  wxSOCKET_LOST = GSOCK_LOST
+} wxSocketNotify;
+
+enum {
+  wxSOCKET_INPUT_FLAG = GSOCK_INPUT_FLAG,
+  wxSOCKET_OUTPUT_FLAG = GSOCK_OUTPUT_FLAG,
+  wxSOCKET_CONNECTION_FLAG = GSOCK_CONNECTION_FLAG,
+  wxSOCKET_LOST_FLAG = GSOCK_LOST_FLAG,
+};
+
+typedef GSocketEventFlags wxSocketEventFlags;
+
+typedef enum {
+  wxSOCKET_NOERROR = GSOCK_NOERROR,
+  wxSOCKET_INPOP = GSOCK_INVOP,
+  wxSOCKET_IOERR = GSOCK_IOERR,
+  wxSOCKET_INVADDR = GSOCK_INVADDR,
+  wxSOCKET_INVSOCK = GSOCK_INVSOCK,
+  wxSOCKET_NOHOST = GSOCK_NOHOST,
+  wxSOCKET_INVPORT = GSOCK_INVPORT,
+  wxSOCKET_WOULDBLOCK = GSOCK_WOULDBLOCK,
+  wxSOCKET_TIMEOUT = GSOCK_TIMEOUT,
+  wxSOCKET_MEMERR = GSOCK_MEMERR
+} wxSocketError;
+
+// ------------------------------------------------------------------------
+// wxSocket base
+// ------------------------------------------------------------------------
+
 class WXDLLEXPORT wxTimer;
 class WXDLLEXPORT wxSocketEvent;
 class WXDLLEXPORT wxSocketBase : public wxEvtHandler
@@ -45,7 +82,7 @@ public:
   // Type of request
 
   enum wxSockType { SOCK_CLIENT, SOCK_SERVER, SOCK_INTERNAL, SOCK_UNINIT };
-  typedef void (*wxSockCbk)(wxSocketBase& sock,GSocketEvent evt,char *cdata);
+  typedef void (*wxSockCbk)(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
 
 protected:
   GSocket *m_socket;                   // wxSocket socket
@@ -103,7 +140,7 @@ public:
   inline bool IsNoWait() const { return ((m_flags & NOWAIT) != 0); };
   bool IsData() const;
   inline size_t LastCount() const { return m_lcount; }
-  inline GSocketError LastError() const { return GSocket_GetError(m_socket); }
+  inline wxSocketError LastError() const { return (wxSocketError)GSocket_GetError(m_socket); }
   inline wxSockType GetType() const { return m_type; }
 
   void SetFlags(wxSockFlags _flags);
@@ -130,11 +167,11 @@ public:
   void SetEventHandler(wxEvtHandler& evt_hdlr, int id = -1);
 
   // Method called when it happens something on the socket
-  void SetNotify(GSocketEventFlags flags);
-  virtual void OnRequest(GSocketEvent req_evt);
+  void SetNotify(wxSocketEventFlags flags);
+  virtual void OnRequest(wxSocketNotify req_evt);
 
   // Public internal callback
-  virtual void OldOnNotify(GSocketEvent WXUNUSED(evt));
+  virtual void OldOnNotify(wxSocketNotify WXUNUSED(evt));
 
   // Some info on the socket...
   virtual bool GetPeer(wxSockAddress& addr_man) const;
@@ -144,9 +181,9 @@ public:
   void Notify(bool notify);
 
   // So you can know what the socket driver is looking for ...
-  inline GSocketEventFlags NeededReq() const { return m_neededreq; }
+  inline wxSocketEventFlags NeededReq() const { return m_neededreq; }
 
-  static GSocketEventFlags EventToNotify(GSocketEvent evt);
+  static wxSocketEventFlags EventToNotify(wxSocketNotify evt);
 
 protected:
   friend class wxSocketServer;
@@ -202,7 +239,7 @@ public:
 
   bool WaitOnConnect(long seconds = -1, long microseconds = 0);
 
-  virtual void OnRequest(GSocketEvent flags);
+  virtual void OnRequest(wxSocketNotify flags);
 };
 
 class WXDLLEXPORT wxSocketEvent : public wxEvent {
@@ -210,7 +247,7 @@ class WXDLLEXPORT wxSocketEvent : public wxEvent {
 public:
   wxSocketEvent(int id = 0);
 
-  GSocketEvent SocketEvent() const { return m_skevt; }
+  wxSocketNotify SocketEvent() const { return (wxSocketNotify)m_skevt; }
   wxSocketBase *Socket() const { return m_socket; }
 
   void CopyObject(wxObject& obj_d) const;
index 56e858ee1b7d00accd80027190c5cbb861e1e578..3714a4f2bac7a66de38fd698f9e1ff91c363d65b 100644 (file)
@@ -281,7 +281,7 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
 
   /* No 2 */
   sock->SetEventHandler(*this, SKDEMO_SCK);
-  sock->SetNotify(GSOCK_INPUT | GSOCK_LOST);
+  sock->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
   sock->Notify(TRUE);
 
   text_win->WriteText("Test 1B: sending bytes to the server\n");
index 27dae77d322c6cab2f0dde33a4ee443b21e579dd..2eba13a020c9a082a4109003bb3dec35ebecfd0d 100644 (file)
@@ -60,10 +60,10 @@ enum {
 #endif
 
 void Server_OnRequest(wxSocketServer& server,
-                     GSocketEvent evt,
+                     wxSocketNotify evt,
                      char *cdata);
 void Client_OnRequest(wxSocketBase& sock,
-                     GSocketEvent evt,
+                     wxSocketNotify evt,
                      char *cdata);
 
 // ---------------------------------------------------------------------------
@@ -96,7 +96,7 @@ wxConnectionBase *wxTCPClient::MakeConnection (const wxString& host,
   wxDataInputStream data_is(*stream);
   wxDataOutputStream data_os(*stream);
   
-  client->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
+  client->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
   addr.Service(server_name);
   addr.Hostname(host);
 
@@ -162,7 +162,7 @@ bool wxTCPServer::Create(const wxString& server_name)
   // Create a socket listening on specified port
   server = new wxSocketServer(addr);
   server->Callback((wxSocketBase::wxSockCbk)Server_OnRequest);
-  server->SetNotify(GSOCK_CONNECTION_FLAG);
+  server->SetNotify(wxSOCKET_CONNECTION_FLAG);
 
   server->CallbackData((char *)this);
 
@@ -336,7 +336,7 @@ bool wxTCPConnection::Advise (const wxString& item,
   return TRUE;
 }
 
-void Client_OnRequest(wxSocketBase& sock, GSocketEvent evt,
+void Client_OnRequest(wxSocketBase& sock, wxSocketNotify evt,
                      char *cdata)
 {
   int msg = 0;
@@ -348,7 +348,7 @@ void Client_OnRequest(wxSocketBase& sock, GSocketEvent evt,
   wxString item;
 
   // The socket handler signals us that we lost the connection: destroy all.
-  if (evt == GSOCK_LOST) {
+  if (evt == wxSOCKET_LOST) {
     sock.Close();
     connection->OnDisconnect();
     return;
@@ -464,20 +464,20 @@ void Client_OnRequest(wxSocketBase& sock, GSocketEvent evt,
 }
 
 void Server_OnRequest(wxSocketServer& server,
-                     GSocketEvent evt, char *cdata)
+                     wxSocketNotify evt, char *cdata)
 {
   wxTCPServer *ipcserv = (wxTCPServer *)cdata;
   wxSocketStream *stream;
   wxDataInputStream *codeci;
   wxDataOutputStream *codeco;
 
-  if (evt != GSOCK_CONNECTION)
+  if (evt != wxSOCKET_CONNECTION)
     return;
 
   /* Accept the connection, getting a new socket */
   wxSocketBase *sock = server.Accept();
   sock->Notify(FALSE);
-  sock->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
+  sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
 
   stream = new wxSocketStream(*sock);
   codeci = new wxDataInputStream(*stream);
index ecb0781c7c4866fbb8a28a650aaa110159581be5..399c4f5cd4fa3252818a068d93b9b6721ebf7615 100644 (file)
@@ -637,7 +637,7 @@ bool wxSocketBase::WaitForLost(long seconds, long milliseconds)
 // --------- wxSocketBase callback management -------------------
 // --------------------------------------------------------------
 
-GSocketEventFlags wxSocketBase::EventToNotify(GSocketEvent evt)
+wxSocketEventFlags wxSocketBase::EventToNotify(wxSocketNotify evt)
 {
   switch (evt)
   {
@@ -665,7 +665,7 @@ wxSocketBase::wxSockFlags wxSocketBase::GetFlags() const
   return m_flags;
 }
 
-void wxSocketBase::SetNotify(GSocketEventFlags flags)
+void wxSocketBase::SetNotify(wxSocketEventFlags flags)
 {
   /* Check if server */
   if (m_type != SOCK_SERVER)
@@ -686,7 +686,7 @@ static void wx_socket_fallback(GSocket *socket, GSocketEvent event, char *cdata)
 {
   wxSocketBase *sckobj = (wxSocketBase *)cdata;
 
-  sckobj->OnRequest(event);
+  sckobj->OnRequest((wxSocketNotify)event);
 }
 
 void wxSocketBase::Notify(bool notify)
@@ -703,28 +703,28 @@ void wxSocketBase::Notify(bool notify)
   GSocket_SetCallback(m_socket, m_neededreq, wx_socket_fallback, (char *)this);
 }
 
-void wxSocketBase::OnRequest(GSocketEvent req_evt)
+void wxSocketBase::OnRequest(wxSocketNotify req_evt)
 {
   wxSocketEvent event(m_id);
   GSocketEventFlags notify = EventToNotify(req_evt);
 
   if (m_defering != NO_DEFER) {
-    DoDefer(req_evt);
+    DoDefer((GSocketEvent)req_evt);
     return;
   }
 
   if ((m_neededreq & notify) == notify) {
     event.m_socket = this;
-    event.m_skevt = req_evt;
+    event.m_skevt = (GSocketEvent) req_evt;
     ProcessEvent(event);
     OldOnNotify(req_evt);
   }
 
-  if (req_evt == GSOCK_LOST)
+  if ((GSocketEvent)req_evt == GSOCK_LOST)
     Close();
 }
 
-void wxSocketBase::OldOnNotify(GSocketEvent evt)
+void wxSocketBase::OldOnNotify(wxSocketNotify evt)
 {
 }
 
@@ -913,9 +913,9 @@ bool wxSocketClient::WaitOnConnect(long seconds, long microseconds)
   return m_connected;
 }
 
-void wxSocketClient::OnRequest(GSocketEvent evt)
+void wxSocketClient::OnRequest(wxSocketNotify evt)
 {
-  if (evt == GSOCK_CONNECTION)
+  if ((GSocketEvent)evt == GSOCK_CONNECTION)
   {
     if (m_connected)
     {
index 006a04fbf03c3a9966dbbd4e3c70e3ef7e04b0ab..d16182e5df59593738cf092d1b2eb468666f1da3 100644 (file)
@@ -19,16 +19,10 @@ void _GSocket_GDK_Input(gpointer data, gint source, GdkInputCondition condition)
 {
   GSocket *socket = (GSocket *)data;
 
-  switch (condition) {
-  case GDK_INPUT_READ:
+  if (condition & GDK_INPUT_READ)
     _GSocket_Detected_Read(socket);
-    break;
-  case GDK_INPUT_WRITE:
+  if (condition & GDK_INPUT_WRITE)
     _GSocket_Detected_Write(socket);
-    break;
-  default:
-    break;
-  } 
 }
 
 void _GSocket_GUI_Init(GSocket *socket)
index 006a04fbf03c3a9966dbbd4e3c70e3ef7e04b0ab..d16182e5df59593738cf092d1b2eb468666f1da3 100644 (file)
@@ -19,16 +19,10 @@ void _GSocket_GDK_Input(gpointer data, gint source, GdkInputCondition condition)
 {
   GSocket *socket = (GSocket *)data;
 
-  switch (condition) {
-  case GDK_INPUT_READ:
+  if (condition & GDK_INPUT_READ)
     _GSocket_Detected_Read(socket);
-    break;
-  case GDK_INPUT_WRITE:
+  if (condition & GDK_INPUT_WRITE)
     _GSocket_Detected_Write(socket);
-    break;
-  default:
-    break;
-  } 
 }
 
 void _GSocket_GUI_Init(GSocket *socket)
index a5f863e1e86b51b0d697357f5b1b3e3636c5a0a8..79c1d20257eb5dce12c18828630303e99b47ddd4 100644 (file)
@@ -77,7 +77,7 @@ bool wxSoundWave::CanRead()
   return TRUE;
 }
 
-bool wxSoundWave::HandlePCM(wxDataInputStream& data, wxUint16 channels, 
+bool wxSoundWave::HandleOutputPCM(wxDataInputStream& data, wxUint16 channels, 
                             wxUint32 sample_fq, wxUint32 byte_p_sec,
                             wxUint16 byte_p_spl, wxUint16 bits_p_spl)
 {
@@ -95,7 +95,7 @@ bool wxSoundWave::HandlePCM(wxDataInputStream& data, wxUint16 channels,
   return TRUE;
 }
 
-bool wxSoundWave::HandleG721(wxDataInputStream& data, wxUint16 channels,
+bool wxSoundWave::HandleOutputG721(wxDataInputStream& data, wxUint16 channels,
                              wxUint32 sample_fq, wxUint32 byte_p_sec,
                              wxUint16 byte_p_spl, wxUint16 bits_p_spl)
 {
@@ -152,12 +152,12 @@ bool wxSoundWave::PrepareToPlay()
 
       switch (format) {
       case 0x01:
-        if (!HandlePCM(data, channels, sample_fq,
+        if (!HandleOutputPCM(data, channels, sample_fq,
                        byte_p_sec, byte_p_spl, bits_p_spl))
           return FALSE;
         break;
       case 0x40:
-        if (!HandleG721(data, channels, sample_fq,
+        if (!HandleOutputG721(data, channels, sample_fq,
                         byte_p_sec, byte_p_spl, bits_p_spl))
           return FALSE;
         break;
@@ -178,6 +178,60 @@ bool wxSoundWave::PrepareToPlay()
   return TRUE;
 }
 
+wxSoundFormatBase *wxSoundWave::HandleInputPCM(wxDataOutputStream& data)
+{
+  wxUint16 format, channels, byte_p_spl, bits_p_spl;
+  wxUint32 sample_fq, byte_p_sec;
+  wxSoundFormatPcm *pcm;
+
+  pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
+
+  // Write block length
+  data.Write32(16);
+
+  sample_fq  = pcm->GetSampleRate();
+  bits_p_spl = pcm->GetBPS();
+  channels   = pcm->GetChannels();
+  byte_p_spl = pcm->GetBPS() / 8;
+  byte_p_sec = pcm->GetBytesFromTime(1);
+  format     = 0x01;
+
+  pcm->Signed(TRUE);
+  pcm->SetOrder(wxLITTLE_ENDIAN);
+
+  data << format << channels << sample_fq
+       << byte_p_sec << byte_p_spl << bits_p_spl;
+
+  return pcm;
+}
+
+wxSoundFormatBase *wxSoundWave::HandleInputG72X(wxDataOutputStream& data)
+{
+  wxUint16 format, channels, byte_p_spl, bits_p_spl;
+  wxUint32 sample_fq, byte_p_sec;
+  wxSoundFormatG72X *g72x;
+
+  // Write block length
+  data.Write32(16);
+
+  g72x = (wxSoundFormatG72X *)(m_sndformat->Clone());
+  if (g72x->GetG72XType() != wxSOUND_G721) {
+    delete g72x;
+    return NULL;
+  } 
+
+  sample_fq  = g72x->GetSampleRate();
+  bits_p_spl = 4;
+  channels   = 1;
+  byte_p_spl = 0;
+  byte_p_sec = g72x->GetBytesFromTime(1);
+  format     = 0x40;
+  data << format << channels << sample_fq
+       << byte_p_sec << byte_p_spl << bits_p_spl;
+
+  return g72x;
+}
+
 bool wxSoundWave::PrepareToRecord(unsigned long time)
 {
 #define WRITE_SIGNATURE(sig) \
@@ -207,38 +261,30 @@ FAIL_WITH(m_output->Write(&signature, 4).LastWrite() != 4, wxSOUND_INVSTRM);
   WRITE_SIGNATURE(WAVE_SIGNATURE);
 
   {
-    wxUint16 format, channels, byte_p_spl, bits_p_spl;
-    wxUint32 sample_fq, byte_p_sec;
-    wxSoundFormatPcm *pcm;
+    wxSoundFormatBase *frmt;
+
+    WRITE_SIGNATURE(FMT_SIGNATURE);
 
-    if (m_sndformat->GetType() != wxSOUND_PCM) {
+    switch (m_sndformat->GetType()) {
+    case wxSOUND_PCM:
+      frmt = HandleInputPCM(data);
+      break;
+    case wxSOUND_G72X:
+      frmt = HandleInputG72X(data);
+      break;
+    default:
       m_snderror = wxSOUND_NOCODEC;
       return FALSE;
     }
 
-    pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
+    FAIL_WITH(!frmt, wxSOUND_NOCODEC);
 
-    WRITE_SIGNATURE(FMT_SIGNATURE);
-    data.Write32(16);
-
-    sample_fq  = pcm->GetSampleRate();
-    bits_p_spl = pcm->GetBPS();
-    channels   = pcm->GetChannels();
-    byte_p_spl = pcm->GetBPS() / 8;
-    byte_p_sec = pcm->GetBytesFromTime(1);
-    format     = 1;
-    data << format << channels << sample_fq
-         << byte_p_sec << byte_p_spl << bits_p_spl;
-
-    pcm->Signed(TRUE);
-    pcm->SetOrder(wxLITTLE_ENDIAN);
-    
-    if (!SetSoundFormat(*pcm)) {
-      delete pcm;
+    if (!SetSoundFormat(*frmt)) {
+      delete frmt;
       return FALSE;
     }
 
-    delete pcm;
+    delete frmt;
   }
 
   WRITE_SIGNATURE(DATA_SIGNATURE);
index 295b4d86a70ebf58ddab6487d078e31dc75562fc..7d4e380fe2a167e9f9bf7069f7a6f6b796bd1c0c 100644 (file)
@@ -39,12 +39,14 @@ class wxSoundWave: public wxSoundFileStream {
   wxUint32 GetData(void *buffer, wxUint32 len);
   wxUint32 PutData(const void *buffer, wxUint32 len);
 
-  bool HandlePCM(wxDataInputStream& data, wxUint16 channels,
+  bool HandleOutputPCM(wxDataInputStream& data, wxUint16 channels,
                  wxUint32 sample_fq, wxUint32 byte_p_sec,
                  wxUint16 byte_p_spl, wxUint16 bits_p_spl);
-  bool HandleG721(wxDataInputStream& data, wxUint16 channels,
+  bool HandleOutputG721(wxDataInputStream& data, wxUint16 channels,
                   wxUint32 sample_fq, wxUint32 byte_p_sec,
                   wxUint16 byte_p_spl, wxUint16 bits_p_spl);
+  wxSoundFormatBase *HandleInputPCM(wxDataOutputStream& data);
+  wxSoundFormatBase *HandleInputG72X(wxDataOutputStream& data);
 };
 
 #endif