From aa8fb7a0164e989e09d2b78867633399a740f1d3 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sun, 5 Sep 1999 05:51:05 +0000 Subject: [PATCH] Added GSocket/wxSocket alias to socket.h to prevent us from using GSocket 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 | 4 +- include/wx/socket.h | 55 +++++++++++++++--- samples/wxsocket/client.cpp | 2 +- src/common/sckipc.cpp | 18 +++--- src/common/socket.cpp | 20 +++---- src/gtk/gsockgtk.c | 10 +--- src/gtk1/gsockgtk.c | 10 +--- utils/wxMMedia2/lib/sndwav.cpp | 100 ++++++++++++++++++++++++--------- utils/wxMMedia2/lib/sndwav.h | 6 +- 9 files changed, 149 insertions(+), 76 deletions(-) diff --git a/include/wx/sckipc.h b/include/wx/sckipc.h index 9cbc4735e5..586b0d06ef 100644 --- a/include/wx/sckipc.h +++ b/include/wx/sckipc.h @@ -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); diff --git a/include/wx/socket.h b/include/wx/socket.h index 496f5a47de..ec578d12d9 100644 --- a/include/wx/socket.h +++ b/include/wx/socket.h @@ -33,6 +33,43 @@ #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; diff --git a/samples/wxsocket/client.cpp b/samples/wxsocket/client.cpp index 56e858ee1b..3714a4f2ba 100644 --- a/samples/wxsocket/client.cpp +++ b/samples/wxsocket/client.cpp @@ -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"); diff --git a/src/common/sckipc.cpp b/src/common/sckipc.cpp index 27dae77d32..2eba13a020 100644 --- a/src/common/sckipc.cpp +++ b/src/common/sckipc.cpp @@ -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); diff --git a/src/common/socket.cpp b/src/common/socket.cpp index ecb0781c7c..399c4f5cd4 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -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) { diff --git a/src/gtk/gsockgtk.c b/src/gtk/gsockgtk.c index 006a04fbf0..d16182e5df 100644 --- a/src/gtk/gsockgtk.c +++ b/src/gtk/gsockgtk.c @@ -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) diff --git a/src/gtk1/gsockgtk.c b/src/gtk1/gsockgtk.c index 006a04fbf0..d16182e5df 100644 --- a/src/gtk1/gsockgtk.c +++ b/src/gtk1/gsockgtk.c @@ -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) diff --git a/utils/wxMMedia2/lib/sndwav.cpp b/utils/wxMMedia2/lib/sndwav.cpp index a5f863e1e8..79c1d20257 100644 --- a/utils/wxMMedia2/lib/sndwav.cpp +++ b/utils/wxMMedia2/lib/sndwav.cpp @@ -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); diff --git a/utils/wxMMedia2/lib/sndwav.h b/utils/wxMMedia2/lib/sndwav.h index 295b4d86a7..7d4e380fe2 100644 --- a/utils/wxMMedia2/lib/sndwav.h +++ b/utils/wxMMedia2/lib/sndwav.h @@ -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 -- 2.45.2