From 776d6b8a777bc93e6b813d4de852da1b4bae5ca4 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 7 Mar 2006 21:26:40 +0000 Subject: [PATCH] query jitter buffer size on first connection --- src/channel.cpp | 69 ++++++++++++++++++++---------------------------- src/channel.h | 48 +++++++++++++++++++-------------- src/client.cpp | 3 +++ src/client.h | 1 + src/protocol.cpp | 34 ++++++++++++++++++++++++ src/protocol.h | 11 +++++--- 6 files changed, 101 insertions(+), 65 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 5f6c4a98..5c843a59 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -30,47 +30,31 @@ \******************************************************************************/ CChannelSet::CChannelSet() { -/* -// seems not to work... - // connect "message send"-message for each channel - for ( int i = 0; i < MAX_NUM_CHANNELS; i++ ) - { - QObject::connect ( &vecChannels[i], - SIGNAL ( MessReadyForSending ( CVector ) ), - this, SLOT ( OnSendProtMessage ( i, CVector ) ) ); - } -*/ -// make sure we have MAX_NUM_CHANNELS connections!!! -QObject::connect(&vecChannels[0],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh0(CVector))); -QObject::connect(&vecChannels[1],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh1(CVector))); -QObject::connect(&vecChannels[2],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh2(CVector))); -QObject::connect(&vecChannels[3],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh3(CVector))); -QObject::connect(&vecChannels[4],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh4(CVector))); -QObject::connect(&vecChannels[5],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh5(CVector))); -QObject::connect(&vecChannels[6],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh6(CVector))); -QObject::connect(&vecChannels[7],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh7(CVector))); -QObject::connect(&vecChannels[8],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh8(CVector))); -QObject::connect(&vecChannels[9],SIGNAL(MessReadyForSending(CVector)), - this,SLOT(OnSendProtMessCh9(CVector))); -} + // make sure we have MAX_NUM_CHANNELS connections!!! + // send message + QObject::connect(&vecChannels[0],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh0(CVector))); + QObject::connect(&vecChannels[1],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh1(CVector))); + QObject::connect(&vecChannels[2],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh2(CVector))); + QObject::connect(&vecChannels[3],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh3(CVector))); + QObject::connect(&vecChannels[4],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh4(CVector))); + QObject::connect(&vecChannels[5],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh5(CVector))); + QObject::connect(&vecChannels[6],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh6(CVector))); + QObject::connect(&vecChannels[7],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh7(CVector))); + QObject::connect(&vecChannels[8],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh8(CVector))); + QObject::connect(&vecChannels[9],SIGNAL(MessReadyForSending(CVector)),this,SLOT(OnSendProtMessCh9(CVector))); -/* -// seems not to work... -void CChannelSet::OnSendProtMessage ( int iChID, CVector vecMessage ) -{ - // just pass message through and add channel ID - emit MessReadyForSending ( iChID,vecMessage ); + // request jitter buffer size + QObject::connect(&vecChannels[0],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh0())); + QObject::connect(&vecChannels[1],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh1())); + QObject::connect(&vecChannels[2],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh2())); + QObject::connect(&vecChannels[3],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh3())); + QObject::connect(&vecChannels[4],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh4())); + QObject::connect(&vecChannels[5],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh5())); + QObject::connect(&vecChannels[6],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh6())); + QObject::connect(&vecChannels[7],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh7())); + QObject::connect(&vecChannels[8],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh8())); + QObject::connect(&vecChannels[9],SIGNAL(NewConnection()),this,SLOT(OnNewConnectionCh9())); } -*/ int CChannelSet::GetFreeChan() { @@ -257,6 +241,9 @@ CChannel::CChannel () QObject::connect ( &Protocol, SIGNAL ( ChangeJittBufSize ( int ) ), this, SLOT ( OnJittBufSizeChange ( int ) ) ); + + QObject::connect ( &Protocol, SIGNAL ( ReqJittBufSize() ), + SIGNAL ( ReqJittBufSize() ) ); } void CChannel::OnSendProtMessage ( CVector vecMessage ) @@ -346,8 +333,8 @@ for (int i = 0; i < BLOCK_SIZE_SAMPLES; i++) } Mutex.unlock (); /* put mutex unlock */ - // if channel was not connected, emit signal to inform that new connection - // was established + // if channel was not connected, emit signal to inform that new + // connection was established if ( iConTimeOut == 0 ) { emit NewConnection(); diff --git a/src/channel.h b/src/channel.h index 719843fe..8c343bca 100755 --- a/src/channel.h +++ b/src/channel.h @@ -42,7 +42,8 @@ #define CON_TIME_OUT_SEC_MAX 5 // seconds #define CON_TIME_OUT_CNT_MAX ( ( CON_TIME_OUT_SEC_MAX * 1000 ) / BLOCK_DURATION_MS ) -/* maximum number of internet connections (channels) */ +/* maximum number of internet connections (channels) */ +// if you want to change this paramter, change the connections in this class, too! #define MAX_NUM_CHANNELS 10 /* max number channels for server */ /* no valid channel number */ @@ -86,10 +87,8 @@ public: int GetSockBufSize() { return SockBuf.GetSize(); } // network protocol interface - void CreateJitBufMes ( const int iJitBufSize ) - { - Protocol.CreateJitBufMes ( iJitBufSize ); - } + void CreateJitBufMes ( const int iJitBufSize ) { Protocol.CreateJitBufMes ( iJitBufSize ); } + void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } protected: /* audio compression */ @@ -129,6 +128,7 @@ public slots: signals: void MessReadyForSending ( CVector vecMessage ); void NewConnection(); + void ReqJittBufSize(); }; @@ -172,21 +172,29 @@ protected: QMutex Mutex; public slots: -/* -// seems not to work... - void OnSendProtMessage ( int iChID, CVector vecMessage ); -*/ -// make sure we have MAX_NUM_CHANNELS connections!!! -void OnSendProtMessCh0(CVector mess) {emit MessReadyForSending(0,mess);} -void OnSendProtMessCh1(CVector mess) {emit MessReadyForSending(1,mess);} -void OnSendProtMessCh2(CVector mess) {emit MessReadyForSending(2,mess);} -void OnSendProtMessCh3(CVector mess) {emit MessReadyForSending(3,mess);} -void OnSendProtMessCh4(CVector mess) {emit MessReadyForSending(4,mess);} -void OnSendProtMessCh5(CVector mess) {emit MessReadyForSending(5,mess);} -void OnSendProtMessCh6(CVector mess) {emit MessReadyForSending(6,mess);} -void OnSendProtMessCh7(CVector mess) {emit MessReadyForSending(7,mess);} -void OnSendProtMessCh8(CVector mess) {emit MessReadyForSending(8,mess);} -void OnSendProtMessCh9(CVector mess) {emit MessReadyForSending(9,mess);} + // make sure we have MAX_NUM_CHANNELS connections!!! + // send message + void OnSendProtMessCh0(CVector mess) {emit MessReadyForSending(0,mess);} + void OnSendProtMessCh1(CVector mess) {emit MessReadyForSending(1,mess);} + void OnSendProtMessCh2(CVector mess) {emit MessReadyForSending(2,mess);} + void OnSendProtMessCh3(CVector mess) {emit MessReadyForSending(3,mess);} + void OnSendProtMessCh4(CVector mess) {emit MessReadyForSending(4,mess);} + void OnSendProtMessCh5(CVector mess) {emit MessReadyForSending(5,mess);} + void OnSendProtMessCh6(CVector mess) {emit MessReadyForSending(6,mess);} + void OnSendProtMessCh7(CVector mess) {emit MessReadyForSending(7,mess);} + void OnSendProtMessCh8(CVector mess) {emit MessReadyForSending(8,mess);} + void OnSendProtMessCh9(CVector mess) {emit MessReadyForSending(9,mess);} + + void OnNewConnectionCh0(CVector mess) {vecChannels[0].CreateReqJitBufMes();} + void OnNewConnectionCh1(CVector mess) {vecChannels[1].CreateReqJitBufMes();} + void OnNewConnectionCh2(CVector mess) {vecChannels[2].CreateReqJitBufMes();} + void OnNewConnectionCh3(CVector mess) {vecChannels[3].CreateReqJitBufMes();} + void OnNewConnectionCh4(CVector mess) {vecChannels[4].CreateReqJitBufMes();} + void OnNewConnectionCh5(CVector mess) {vecChannels[5].CreateReqJitBufMes();} + void OnNewConnectionCh6(CVector mess) {vecChannels[6].CreateReqJitBufMes();} + void OnNewConnectionCh7(CVector mess) {vecChannels[7].CreateReqJitBufMes();} + void OnNewConnectionCh8(CVector mess) {vecChannels[8].CreateReqJitBufMes();} + void OnNewConnectionCh9(CVector mess) {vecChannels[9].CreateReqJitBufMes();} signals: void MessReadyForSending ( int iChID, CVector vecMessage ); diff --git a/src/client.cpp b/src/client.cpp index 4b64b95e..1a5dc530 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -34,6 +34,9 @@ CClient::CClient () : bRun ( false ), Socket ( &Channel ), // connection for protocol QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector ) ), this, SLOT ( OnSendProtMessage ( CVector ) ) ); + + QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ), + this, SLOT ( OnReqJittBufSize() ) ); } void CClient::OnSendProtMessage ( CVector vecMessage ) diff --git a/src/client.h b/src/client.h index bda11299..149a1a7b 100755 --- a/src/client.h +++ b/src/client.h @@ -146,6 +146,7 @@ protected: public slots: void OnSendProtMessage ( CVector vecMessage ); + void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufSize() ); } }; diff --git a/src/protocol.cpp b/src/protocol.cpp index 9052cd98..0c7e506e 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -45,6 +45,9 @@ MESSAGES | 2 bytes number of blocks | +--------------------------+ +- Request jitter buffer size: PROTMESSID_REQ_JITT_BUF_SIZE + no data + @@ -240,6 +243,16 @@ for ( int i = 0; i < iNumBytes; i++ ) { // send acknowledge message CreateAndSendAcknMess ( iRecID, iRecCounter ); + break; + + case PROTMESSID_REQ_JITT_BUF_SIZE: + + // invoke message action + emit ReqJittBufSize(); + + // send acknowledge message + CreateAndSendAcknMess ( iRecID, iRecCounter ); + break; } } @@ -286,6 +299,27 @@ void CProtocol::CreateJitBufMes ( const int iJitBufSize ) Mutex.unlock(); } +void CProtocol::CreateReqJitBufMes() +{ + Mutex.lock(); + { + CVector vecNewMessage; + + // store current counter value + const int iCurCounter = iCounter; + + // increase counter (wraps around automatically) + iCounter++; + + // build complete message + GenMessageFrame ( vecNewMessage, iCurCounter, PROTMESSID_REQ_JITT_BUF_SIZE, CVector ( 0 ) ); + + // enqueue message + EnqueueMessage ( vecNewMessage, iCurCounter, PROTMESSID_REQ_JITT_BUF_SIZE ); + } + Mutex.unlock(); +} + /******************************************************************************\ * Message generation (parsing) * diff --git a/src/protocol.h b/src/protocol.h index e583543a..0ec2333d 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -35,10 +35,11 @@ /* Definitions ****************************************************************/ // protocol message IDs -#define PROTMESSID_ILLEGAL 0 // illegal ID -#define PROTMESSID_ACKN 1 // acknowledge -#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size -#define PROTMESSID_PING 11 // for measuring ping time +#define PROTMESSID_ILLEGAL 0 // illegal ID +#define PROTMESSID_ACKN 1 // acknowledge +#define PROTMESSID_JITT_BUF_SIZE 10 // jitter buffer size +#define PROTMESSID_REQ_JITT_BUF_SIZE 11 // request jitter buffer size +#define PROTMESSID_PING 12 // for measuring ping time // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 5 /* ID, cnt, length */ @@ -58,6 +59,7 @@ public: virtual ~CProtocol() {} void CreateJitBufMes ( const int iJitBufSize ); + void CreateReqJitBufMes(); void CreateAndSendAcknMess ( const int& iID, const int& iCnt ); @@ -131,6 +133,7 @@ signals: // receiving void ChangeJittBufSize ( int iNewJitBufSize ); + void ReqJittBufSize(); };