From f890771871a6092d8a8c3229f7eee878fe80e8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 11 Dec 2013 17:21:29 -0500 Subject: [PATCH] channels/rdpsnd: fix audio duration computation for GSM610 format --- channels/rdpsnd/client/mac/rdpsnd_mac.c | 65 +++++++------------------ libfreerdp/codec/audio.c | 14 +++++- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/channels/rdpsnd/client/mac/rdpsnd_mac.c b/channels/rdpsnd/client/mac/rdpsnd_mac.c index 4a00bb3d0..1fe05242c 100644 --- a/channels/rdpsnd/client/mac/rdpsnd_mac.c +++ b/channels/rdpsnd/client/mac/rdpsnd_mac.c @@ -51,9 +51,7 @@ struct rdpsnd_mac_plugin int audioBufferIndex; AudioQueueRef audioQueue; - AudioConverterRef audioConverter; - AudioStreamBasicDescription inputAudioFormat; - AudioStreamBasicDescription outputAudioFormat; + AudioStreamBasicDescription audioFormat; AudioQueueBufferRef audioBuffers[MAC_AUDIO_QUEUE_NUM_BUFFERS]; }; typedef struct rdpsnd_mac_plugin rdpsndMacPlugin; @@ -65,7 +63,6 @@ static void mac_audio_queue_output_cb(void* inUserData, AudioQueueRef inAQ, Audi static void rdpsnd_mac_set_format(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, int latency) { - OSStatus status; rdpsndMacPlugin* mac = (rdpsndMacPlugin*) device; mac->latency = (UINT32) latency; @@ -74,61 +71,33 @@ static void rdpsnd_mac_set_format(rdpsndDevicePlugin* device, AUDIO_FORMAT* form switch (format->wFormatTag) { case WAVE_FORMAT_ALAW: - mac->inputAudioFormat.mFormatID = kAudioFormatALaw; + mac->audioFormat.mFormatID = kAudioFormatALaw; break; case WAVE_FORMAT_MULAW: - mac->inputAudioFormat.mFormatID = kAudioFormatULaw; + mac->audioFormat.mFormatID = kAudioFormatULaw; break; case WAVE_FORMAT_PCM: - mac->inputAudioFormat.mFormatID = kAudioFormatLinearPCM; + mac->audioFormat.mFormatID = kAudioFormatLinearPCM; break; case WAVE_FORMAT_GSM610: - mac->inputAudioFormat.mFormatID = kAudioFormatMicrosoftGSM; + mac->audioFormat.mFormatID = kAudioFormatMicrosoftGSM; break; default: break; } - mac->inputAudioFormat.mSampleRate = format->nSamplesPerSec; - mac->inputAudioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; - mac->inputAudioFormat.mFramesPerPacket = 1; - mac->inputAudioFormat.mChannelsPerFrame = format->nChannels; - mac->inputAudioFormat.mBitsPerChannel = format->wBitsPerSample; - mac->inputAudioFormat.mBytesPerFrame = (format->wBitsPerSample * format->nChannels) / 8; - mac->inputAudioFormat.mBytesPerPacket = format->nBlockAlign; - - mac->outputAudioFormat.mFormatID = kAudioFormatLinearPCM; - mac->outputAudioFormat.mSampleRate = 44100; - mac->outputAudioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; - mac->outputAudioFormat.mFramesPerPacket = 1; - mac->outputAudioFormat.mChannelsPerFrame = 2; - mac->outputAudioFormat.mBitsPerChannel = 16; - mac->outputAudioFormat.mBytesPerFrame = (16 * 2) / 8; - mac->outputAudioFormat.mBytesPerPacket = 4; - - status = AudioConverterNew(&(mac->inputAudioFormat), - &(mac->outputAudioFormat), &(mac->audioConverter)); - - if (status != 0) - { - fprintf(stderr, "AudioConverterNew failure\n"); - return; - } - - SInt32 channelMap[2] = { 0, 0 }; - - status = AudioConverterSetProperty(mac->audioConverter, kAudioConverterChannelMap, - sizeof(channelMap), channelMap); - - if (status != 0) - { - fprintf(stderr, "AudioConverterSetProperty kAudioConverterChannelMap failure\n"); - return; - } + mac->audioFormat.mSampleRate = format->nSamplesPerSec; + mac->audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; + mac->audioFormat.mFramesPerPacket = 1; + mac->audioFormat.mChannelsPerFrame = format->nChannels; + mac->audioFormat.mBitsPerChannel = format->wBitsPerSample; + mac->audioFormat.mBytesPerFrame = (format->wBitsPerSample * format->nChannels) / 8; + mac->audioFormat.mBytesPerPacket = format->nBlockAlign; + mac->audioFormat.mReserved = 0; rdpsnd_print_audio_format(format); } @@ -147,7 +116,7 @@ static void rdpsnd_mac_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, in device->SetFormat(device, format, 0); - status = AudioQueueNewOutput(&(mac->inputAudioFormat), + status = AudioQueueNewOutput(&(mac->audioFormat), mac_audio_queue_output_cb, mac, NULL, NULL, 0, &(mac->audioQueue)); @@ -217,11 +186,11 @@ static BOOL rdpsnd_mac_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT } else if (format->wFormatTag == WAVE_FORMAT_ALAW) { - return FALSE; + return TRUE; } else if (format->wFormatTag == WAVE_FORMAT_MULAW) { - return FALSE; + return TRUE; } else if (format->wFormatTag == WAVE_FORMAT_GSM610) { @@ -288,7 +257,7 @@ static void rdpsnd_mac_play(rdpsndDevicePlugin* device, BYTE* data, int size) audioBuffer = mac->audioBuffers[mac->audioBufferIndex]; - length = size > MAC_AUDIO_QUEUE_BUFFER_SIZE ? MAC_AUDIO_QUEUE_BUFFER_SIZE : size; + length = size > audioBuffer->mAudioDataBytesCapacity ? audioBuffer->mAudioDataBytesCapacity : size; CopyMemory(audioBuffer->mAudioData, data, length); audioBuffer->mAudioDataByteSize = length; diff --git a/libfreerdp/codec/audio.c b/libfreerdp/codec/audio.c index 1e45989d3..4140677e3 100644 --- a/libfreerdp/codec/audio.c +++ b/libfreerdp/codec/audio.c @@ -29,14 +29,24 @@ UINT32 rdpsnd_compute_audio_time_length(AUDIO_FORMAT* format, int size) { UINT32 mstime; UINT32 wSamples; + UINT16 nSamplesPerBlock; /** * [MSDN-AUDIOFORMAT]: * http://msdn.microsoft.com/en-us/library/ms713497.aspx */ - wSamples = (size * 8) / format->wBitsPerSample; - mstime = (((wSamples * 1000) / format->nSamplesPerSec) / format->nChannels); + if (format->wFormatTag == WAVE_FORMAT_GSM610) + { + nSamplesPerBlock = *((UINT16*) format->data); + wSamples = (size / format->nBlockAlign) * nSamplesPerBlock; + mstime = (((wSamples * 1000) / format->nSamplesPerSec) / format->nChannels); + } + else + { + wSamples = (size * 8) / format->wBitsPerSample; + mstime = (((wSamples * 1000) / format->nSamplesPerSec) / format->nChannels); + } return mstime; }