Пример #1
0
   void testEnabledWithData()
   {
       MprToSpkr*        pToSpkr    = NULL;
       OsMsgQ*           pSpkQ      = NULL;
       OsMsgQ*           pEchoQ     = NULL;
       MpBufferMsg*      pSpkMsg    = NULL;
       MpBufferMsg*      pEchoMsg   = NULL;
       MpBufPtr          pBuf;
       OsStatus          res;

       // Create message queues to get data from MprToSpkr
       pSpkQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pSpkQ != NULL);
       pEchoQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pEchoQ != NULL);

       pToSpkr = new MprToSpkr("MprToSpkr",
                               pSpkQ, pEchoQ);
       CPPUNIT_ASSERT(pToSpkr != NULL);

       setupFramework(pToSpkr);

       // pToSpkr enabled, there are buffers on the input 0, message queue
       // is not full.
       CPPUNIT_ASSERT(mpSourceResource->enable());
       CPPUNIT_ASSERT(pToSpkr->enable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Get messages from the queues (wait for 1 second)
       res = pSpkQ->receive((OsMsg*&)pSpkMsg, OsTime(1000));
       CPPUNIT_ASSERT(res == OS_SUCCESS);
       res = pEchoQ->receive((OsMsg*&)pEchoMsg, OsTime(1000));
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Store output buffer for convenience
       pBuf = mpSourceResource->mLastDoProcessArgs.outBufs[0];

       // Buffer is sent to queues and to output
       CPPUNIT_ASSERT(  (mpSinkResource->mLastDoProcessArgs.inBufs[0] == pBuf)
                     && (pSpkMsg->getBuffer().isValid())
                     && (pEchoMsg->getBuffer() == pBuf)
                     );

       // Free received message and stored buffer
       pSpkMsg->releaseMsg();
       pEchoMsg->releaseMsg();
       pBuf.release();

       // Stop flowgraph
       haltFramework();

       // Free message queue
       delete pSpkQ;
       delete pEchoQ;
   }
Пример #2
0
UtlBoolean MpResource::handleMessages(OsMsgQ& msgQ)
{
   UtlBoolean handledAllMsgs = FALSE;
   while(!msgQ.isEmpty())
   {
      OsMsg* msg;
      OsStatus recvStat = msgQ.receive(msg, OsTime::NO_WAIT_TIME);
      UtlBoolean curMsgHandled = FALSE;
      if (recvStat == OS_SUCCESS)
      {
         if (msg->getMsgType() == OsMsg::MP_FLOWGRAPH_MSG)
         {
            MpFlowGraphMsg* fgMsg = static_cast<MpFlowGraphMsg*>(msg);
            if (fgMsg != NULL)
            {
               curMsgHandled = handleMessage(*fgMsg);
            }
         }
         else if (msg->getMsgType() == OsMsg::MP_RESOURCE_MSG)
         {
            MpResourceMsg* rMsg = static_cast<MpResourceMsg*>(msg);
            if (rMsg != NULL)
            {
               curMsgHandled = handleMessage(*rMsg);
            }
         }

         // TODO: If message received is not handled, it might be good
         //       to stuff the message back into the front of the queue
         //       with msgQ.sendUrgent(msg, OsTime::NO_WAIT_TIME);
         //       I haven't thought through the ramifications of this,
         //       so I haven't implemented it yet.
      }

      // Stop at the first message we encounter that is not handled.
      if (curMsgHandled == FALSE)
      {
         break;
      }

      // If the queue is empty at this point,
      // then all messages have been handled.
      if (msgQ.isEmpty())
      {
         handledAllMsgs = TRUE;
      }
   }
   return handledAllMsgs;
}
Пример #3
0
// Sends an MPRM_START_TONE message to the named MprToneGen resource.
// When received, the resource starts generating the toneId tone.
// Returns the result of attempting to queue the message to this resource.
OsStatus MprToneGen::startTone(const UtlString& namedResource,
                               OsMsgQ& fgQ,
                               int toneId)
{
   MpToneResourceMsg msg(namedResource, toneId);
   return fgQ.send(msg, sOperationQueueTimeout);
}
Пример #4
0
OsStatus MpRtpInputConnection::setRtpInactivityTimeout(const UtlString& namedResource,
                                                       OsMsgQ& fgQ,
                                                       int timeoutMs)
{
   MpIntResourceMsg msg((MpResourceMsg::MpResourceMsgType)MPRM_SET_INACTIVITY_TIMEOUT,
                        namedResource, timeoutMs);
   return fgQ.send(msg, sOperationQueueTimeout);
}
Пример #5
0
OsStatus MpRtpInputConnection::enableSsrcDiscard(const UtlString& namedResource,
                                                 OsMsgQ& fgQ,
                                                 UtlBoolean enable, RtpSRC ssrc)
{
   MpIntResourceMsg msg(enable?(MpResourceMsg::MpResourceMsgType)MPRM_ENABLE_SSRC_DISCARD
                              :(MpResourceMsg::MpResourceMsgType)MPRM_DISABLE_SSRC_DISCARD,
                        namedResource, ssrc);
   return fgQ.send(msg, sOperationQueueTimeout);
}
Пример #6
0
OsStatus MpResource::setNotificationsEnabled(UtlBoolean enable,
                                             const UtlString& namedResource, 
                                             OsMsgQ& fgQ)
{
   MpResourceMsg msg(enable?MpResourceMsg::MPRM_ENABLE_ALL_NOTIFICATIONS
                           :MpResourceMsg::MPRM_DISABLE_ALL_NOTIFICATIONS,
                     namedResource);

   return fgQ.send(msg, sOperationQueueTimeout);
}
OsStatus MpRtpInputAudioConnection::stopReceiveRtp(OsMsgQ& messageQueue,
                                                   const UtlString& resourceName)
{
    MpResourceMsg stopReceiveMsg(MpResourceMsg::MPRM_STOP_RECEIVE_RTP, 
                                 resourceName);

    // Send the message in the queue.
    OsStatus result = messageQueue.send(stopReceiveMsg);
    return(result);
}
Пример #8
0
   void testEnabledNoData()
   {
       MprToSpkr*        pToSpkr    = NULL;
       OsMsgQ*           pSpkQ      = NULL;
       OsMsgQ*           pEchoQ     = NULL;
       MpAudioBufPtr     pBuf;
       OsStatus          res;

       // Create message queues to get data from MprToSpkr
       pSpkQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pSpkQ != NULL);
       pEchoQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pEchoQ != NULL);

       pToSpkr = new MprToSpkr("MprToSpkr",
                               pSpkQ, pEchoQ);
       CPPUNIT_ASSERT(pToSpkr != NULL);

       setupFramework(pToSpkr);

       // pToSpkr enabled, there are no buffers on the input 0, message queue
       // is empty.
       CPPUNIT_ASSERT(mpSourceResource->disable());
       CPPUNIT_ASSERT(pToSpkr->enable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // No buffers processed
       CPPUNIT_ASSERT(  !mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                     && !mpSinkResource->mLastDoProcessArgs.inBufs[0].isValid()
                     && pSpkQ->isEmpty()
                     && pEchoQ->isEmpty()
                     );

       // Stop flowgraph
       haltFramework();

       // Free message queues
       delete pSpkQ;
       delete pEchoQ;
   }
Пример #9
0
OsStatus MprBridge::setMixWeightsForInput(const UtlString& namedResource, 
                                          OsMsgQ& fgQ, 
                                          int bridgeInputPort,
                                          int numWeights,
                                          const MpBridgeGain gains[])
{
   MprBridgeSetGainsMsg msg(namedResource, bridgeInputPort, numWeights,
                            gains,
                            MprBridgeSetGainsMsg::GAINS_COLUMN);
   return fgQ.send(msg, sOperationQueueTimeout);
}
OsStatus MpRtpInputAudioConnection::startReceiveRtp(OsMsgQ& messageQueue,
                                                    const UtlString& resourceName,
                                                    const SdpCodecList& sdpCodecList,
                                                    OsSocket& rRtpSocket,
                                                    OsSocket& rRtcpSocket)
{
    OsStatus result = OS_INVALID_ARGUMENT;
    if(sdpCodecList.getCodecCount() > 0)
    {
        // Create a message to contain the startRecieveRtp data
        MprRtpStartReceiveMsg msg(resourceName,
                                  sdpCodecList,
                                  rRtpSocket,
                                  rRtcpSocket);

        // Send the message in the queue.
        result = messageQueue.send(msg);
    }
    return(result);
}
Пример #11
0
    UtlBoolean removeMessage(OsMsgQ& messageQueue,
                             int waitMilliSeconds,
                             const SipMessage*& message)
    {
        UtlBoolean gotMessage = FALSE;
        message = NULL;
        OsTime messageTimeout(0, waitMilliSeconds * 1000);
        OsMsg* osMessage = NULL;
        messageQueue.receive(osMessage, messageTimeout);
        if(osMessage)
        {
            int msgType = osMessage->getMsgType();
            int msgSubType = osMessage->getMsgSubType();
            int messageType = ((SipMessageEvent*)osMessage)->getMessageStatus();
            if(msgType == OsMsg::PHONE_APP &&
               msgSubType == SipMessage::NET_SIP_MESSAGE &&
               messageType == SipMessageEvent::APPLICATION)
            {
                message = ((SipMessageEvent*)osMessage)->getMessage();
                gotMessage = TRUE;

#ifdef TEST_PRINT
                if(message)
                {
                    UtlString messageBytes;
                    int len;
                    message->getBytes(&messageBytes, &len);
                    printf("%s", messageBytes.data());
                }
                else
                {
                    printf("removeMessage: messageBytes: <null>\n");
                }
#endif
            }
        }
        return(gotMessage);
    }
Пример #12
0
UtlBoolean MprFromMic::doProcessFrame(MpBufPtr inBufs[],
                                     MpBufPtr outBufs[],
                                     int inBufsSize,
                                     int outBufsSize,
                                     UtlBoolean isEnabled,
                                     int samplesPerFrame,
                                     int samplesPerSecond)
{
	MpBufPtr        out = NULL ;
	MpBufferMsg*    pMsg;

	if (0 == outBufsSize) 
	{
		return FALSE;
	}
	

	// Clear the the number of empty frames every 512 frames
	mNumFrames++;
	if (0 == (mNumFrames & 0x1ff)) 
	{
		mNumEmpties = 0;
	}

	if (isEnabled) 
	{
		// If the microphone queue (holds unprocessed mic data) has more then
		// the max_mic_buffers threshold, drain the queue until in range)
		OsMsgQ* pMicOutQ;
		pMicOutQ = MpMisc.pMicQ;
		while (pMicOutQ && MpMisc.max_mic_buffers < pMicOutQ->numMsgs()) 
		{
	        if (OS_SUCCESS == pMicOutQ->receive((OsMsg*&) pMsg,
					OsTime::NO_WAIT)) 
			{
				MpBuf_delRef(pMsg->getTag());
				MpBuf_delRef(pMsg->getTag(1));
				pMsg->releaseMsg();
			}
		}

		if (pMicOutQ && pMicOutQ->numMsgs() <= 0)
		{
//			osPrintf("MprFromMic: No data available (total frames=%d, starved frames=%d)\n", 
//					mNumFrames, mNumEmpties);
		}
		else
		{
			if (pMicOutQ && OS_SUCCESS == pMicOutQ->receive((OsMsg*&) pMsg, 
					OsTime::NO_WAIT)) 
			{
				out = pMsg->getTag();
				pMsg->releaseMsg();
				
				if (NULL != out) 
				{
#ifdef REAL_SILENCE_DETECTION /* [ */
					Sample* shpTmpFrame;
					MpBufPtr tpBuf;
					int n;
#endif /* REAL_SILENCE_DETECTION ] */

					switch(MpBuf_getSpeech(out)) 
					{
						case MP_SPEECH_TONE:
							break;
						case MP_SPEECH_MUTED:
							MpBuf_setSpeech(out, MP_SPEECH_SILENT);
							break;
						default:
#ifdef REAL_SILENCE_DETECTION /* [ */
							Sample *shpSamples;
							n = MpBuf_getNumSamples(out);
							shpSamples = MpBuf_getSamples(out);

							tpBuf = MpBuf_getBuf(MpMisc.UcbPool, n, 0, MP_FMT_T12);
							assert(NULL != tpBuf);
							shpTmpFrame = MpBuf_getSamples(tpBuf);
							highpass_filter800(shpSamples, shpTmpFrame, n);

							if(0 == speech_detected(shpTmpFrame,n)) 
							{
								MpBuf_setSpeech(out, MP_SPEECH_SILENT);
							}
							else 
							{
								MpBuf_setSpeech(out, MP_SPEECH_ACTIVE);
							}
							MpBuf_delRef(tpBuf);
#else /* REAL_SILENCE_DETECTION ] [ */
							// 24 April 2001 (HZM)  I am disabling this because it takes
							// too long to recognize the beginning of a talk spurt, and
							// causes the bridge mixer to drop the start of each word.																
							MpBuf_isActiveAudio(out);
#endif /* REAL_SILENCE_DETECTION ] */
							break;
					}
				}
			}
		} 

#ifdef INSERT_SAWTOOTH /* [ */
		if (NULL == out)
		{
			out = MpBuf_getBuf(MpMisc.UcbPool, MpMisc.frameSamples, 0, MP_FMT_T12);
		}
		MpBuf_insertSawTooth(out);
		MpBuf_setSpeech(out, MP_SPEECH_ACTIVE);
#endif /* INSERT_SAWTOOTH ] */

		if (s_fnMicDataHook)
		{
			// 
			// Allow an external identity to source microphone data.  Ideally,
            // this should probably become a different resource, but abstracting
            // a new CallFlowGraph is a lot of work.
            //

			if (NULL == out) 
			{
				out = MpBuf_getBuf(MpMisc.UcbPool, MpMisc.frameSamples, 0, MP_FMT_T12);
			}
			
			if (NULL != out) 
			{
	            int n = 0;
				Sample* s = NULL;

				s = MpBuf_getSamples(out);
				n = MpBuf_getNumSamples(out);
				
				s_fnMicDataHook(n, s) ;

				MpBuf_setSpeech(out, MP_SPEECH_UNKNOWN);
				MpBuf_isActiveAudio(out);
			}
		}

		if (NULL == out)
		{
			out = MpBuf_getFgSilence();
		}
	}

	*outBufs = out;

	return TRUE;
}
Пример #13
0
// Sends an MPRM_STOP_TONE message to the named MprToneGen resource.
// When received, the resource stops generating a tone.
// Returns the result of attempting to queue the message to this resource.
OsStatus MprToneGen::stopTone(const UtlString& namedResource,
                              OsMsgQ& fgQ)
{
   MpResourceMsg msg(MpResourceMsg::MPRM_STOP_TONE, namedResource);
   return fgQ.send(msg, sOperationQueueTimeout);
}
Пример #14
0
OsStatus MpResource::enable(const UtlString& namedResource,
                            OsMsgQ& fgQ)
{
   MpResourceMsg msg(MpResourceMsg::MPRM_RESOURCE_ENABLE, namedResource);
   return fgQ.send(msg, sOperationQueueTimeout);
}
Пример #15
0
UtlBoolean MprDelay::stopPlay(const UtlString& namedResource, 
                              OsMsgQ& fgQ)
{
   MpResourceMsg msg((MpResourceMsg::MpResourceMsgType)MPRM_DELAY_STOP_PLAY, namedResource);
   return fgQ.send(msg);
}
Пример #16
0
//! Send a pager style instant message to the given destination
UtlBoolean SipPimClient::sendPagerMessage(Url& destinationAor,
                                          const char* messageText,
                                          int& responseCode,
                                          UtlString& responseCodeText)
{
    UtlBoolean returnCode = FALSE;
    responseCode = -1;
    responseCodeText.remove(0);

    if(messageText && *messageText)
    {
        // Construct the text body
        HttpBody* textBody = new HttpBody(messageText,
                                          strlen(messageText),
                                          CONTENT_TYPE_TEXT_PLAIN);

        // Construct the MESSAGE request
        UtlString toAddress = destinationAor.toString();
        UtlString requestUri;
        destinationAor.getUri(requestUri);
        UtlString callId;
        CallId::getNewCallId(callId);
        SipMessage messageRequest;
        messageRequest.setRequestData(SIP_MESSAGE_METHOD, requestUri,
                         mFromField, toAddress,
                         callId,
                         1, // sequenceNumber
                         NULL); // contactUrl

        // Attache the body
        messageRequest.setBody(textBody);
        messageRequest.setContentType(CONTENT_TYPE_TEXT_PLAIN);

        // Set the queue to which the response will be deposited
        // for this specific request.
        OsMsgQ responseQueue;
        messageRequest.setResponseListenerQueue(&responseQueue);

        // Send the request
        returnCode = mpUserAgent->send(messageRequest);

        // wait for the response
        OsMsg* qMessage = NULL;
        // For now we will block forever.  Theoretically this should
        // always get a response (e.g. worst case a 408 timed out).
        // If we do not wait forever, we need to be sure to wait the
        // the maximum transaction timeout period so that the qMessage
        // exists when the SipUserAgent queues the response.
        responseQueue.receive(qMessage);


        // If we got a response, get the response status code and text
        if(qMessage)
        {
            int msgType = qMessage->getMsgType();
            int msgSubType = qMessage->getMsgSubType();

            // SIP message
            if(msgType == OsMsg::PHONE_APP &&
               msgSubType == SipMessage::NET_SIP_MESSAGE)
            {
                const SipMessage* messageResponse =
                    ((SipMessageEvent*)qMessage)->getMessage();

                if(messageResponse && messageResponse->isResponse())
                {
                    responseCode = messageResponse->getResponseStatusCode();
                    messageResponse->getResponseStatusText(&responseCodeText);
                }
            }
        }
    }

    return(returnCode);
}