Exemplo n.º 1
0
//Audio data of the audio talk callback 
void CClientDlg::AudioData(LONG lTalkHandle, char *pDataBuf, DWORD dwBufSize, BYTE byAudioFlag)
{
	if(m_hTalkHandle == lTalkHandle)
	{
		if(0 == byAudioFlag)
		{
			//It means it is the audio data from the local reocrd library
			//TRACE("The audio data lenght to be sent:%d \n",dwBufSize);
			long lSendLen = CLIENT_TalkSendData(lTalkHandle, pDataBuf, dwBufSize);
			if(lSendLen != (long)dwBufSize)
			{
				//Error occurred when sending the user audio data to the device
				
			}
		}
		else if(1 == byAudioFlag)
		{
			//It means it has received the audio data from the device.
			CLIENT_AudioDec(pDataBuf, dwBufSize);
			//TRACE("The audio data lenght received:%d \n",dwBufSize);
#ifdef _DEBUG
			FILE *stream;
			if( (stream = fopen("E:\\Talk.txt", "a+b")) != NULL )
			{
				int numwritten = fwrite( pDataBuf, sizeof( char ), dwBufSize, stream );
				fclose( stream );
			}
#endif
		}
	}
}
Exemplo n.º 2
0
//Audio data of the audio talk callback 
void CDlgTalk::AudioData(LLONG lTalkHandle, char *pDataBuf, DWORD dwBufSize, BYTE byAudioFlag)
{
	if(m_hTalkingHandle == lTalkHandle)
	{
		if(NET_TALK_DATA_LOCAL_AUDIO == byAudioFlag)
		{
#if 0
			FILE *stream;
			if( (stream = fopen("E:\\talk\\Talk_send.dav", "a+b")) != NULL )
			{
				int numwritten = fwrite( pDataBuf, sizeof( char ), dwBufSize, stream );
				fclose( stream );
			}
#endif
			//It means it is the audio data from the local reocrd library
			//TRACE("The audio data lenght to be sent:%d \n",dwBufSize);
			long lSendLen = CLIENT_TalkSendData(lTalkHandle, pDataBuf, dwBufSize);
			if(lSendLen != (long)dwBufSize)
			{
				//Error occurred when sending the user audio data to the device
				
			}
		}
		else if(NET_TALK_DATA_RECV_AUDIO == byAudioFlag || NET_TALK_DATA_RECV_VIDEO == byAudioFlag)
		{
			//It means it has received the audio data from the device.
			CLIENT_AudioDecEx(lTalkHandle, pDataBuf, dwBufSize);
			//TRACE("The audio data lenght received:%d \n",dwBufSize);
#if 0
			FILE *stream;
			if( (stream = fopen("d:\\Talk.dav", "a+b")) != NULL )
			{
				int numwritten = fwrite( pDataBuf, sizeof( char ), dwBufSize, stream );
				fclose( stream );
			}
#endif
		}
		else if (NET_TALK_DATA_RESPOND == byAudioFlag)
		{
			OutputDebugString("device responded...\n");
		}
	}
}
Exemplo n.º 3
0
static int dah_talk_recv(struct service *srv, talk_info_t *talk, char *data, int len, media_info_t *info)
{
    int ret = -1;
    dah_service_t *dah_srv;
    int send_count = 0;
    unsigned char out_buffer[MAX_ENCODE_BUFFER_LEN];
    unsigned char in_buffer[MAX_ENCODE_LEN];
    unsigned int out_buffer_len = MAX_ENCODE_BUFFER_LEN;
    char pcm_data[MAX_ENCODE_BUFFER_LEN];
    int out_pcm_data_len = 0;
    unsigned int in_data_len = 0;
    frame_t *frm = NULL;

    NMP_ASSERT(srv && talk && data);

    frm = (talk_frame_hdr_t*)data;
    if(ntohl(frm->magic) != TALK_MAGIC)
    {
        show_warn("magic[0x%x] error", ntohl(frm->magic));
        return -1;
    }
    in_data_len = ntohl(frm->frame_length);
    memcpy(in_buffer, frm->frame_data, in_data_len);
    //memset(pcm_data, 0, MAX_ENCODE_BUFFER_LEN);

    if(info->attr.encode_type == 0)
    {
        memcpy(pcm_data, in_buffer, in_data_len);
        out_pcm_data_len = in_data_len;
    }
    else if(info->attr.encode_type == 1)
    {
        g711a_Decode2(in_buffer, pcm_data, (int)in_data_len, &out_pcm_data_len);
    }
    else if(info->attr.encode_type == 2)
    {
        g711u_Decode(in_buffer, pcm_data, (int)in_data_len, &out_pcm_data_len);
    }

    dah_srv = (dah_service_t*)srv;
    if( in_data_len <= MAX_ENCODE_LEN)
    {
        //memset(out_buffer, 0, MAX_ENCODE_BUFFER_LEN);
        ret = CLIENT_AudioEncode(0, (unsigned char*)pcm_data, 
                (unsigned int*)&out_pcm_data_len, out_buffer, &out_buffer_len);
        if(ret != 0)
        {
            show_warn("CLIENT_AudioEncode error ret = 0x%x in_data_len = %d out_buffer_len = %d\n",
                ret, in_data_len, out_buffer_len);
            return -1;  
        }
        send_count = CLIENT_TalkSendData(talk->talk_handle, (char*)out_buffer, out_buffer_len);
        if(send_count < 0)          
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }

    return ret;
}