Now using TSMF debug print.

This commit is contained in:
Armin Novak 2014-05-23 13:12:34 +02:00
parent f62dab9fd3
commit 30ffb98205
3 changed files with 298 additions and 423 deletions

View File

@ -24,7 +24,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <winpr/crt.h>
@ -41,225 +40,194 @@ typedef struct _TSMFALSAAudioDevice
ITSMFAudioDevice iface;
char device[32];
snd_pcm_t* out_handle;
snd_pcm_t *out_handle;
UINT32 source_rate;
UINT32 actual_rate;
UINT32 source_channels;
UINT32 actual_channels;
UINT32 bytes_per_sample;
FREERDP_DSP_CONTEXT* dsp_context;
FREERDP_DSP_CONTEXT *dsp_context;
} TSMFAlsaAudioDevice;
static BOOL tsmf_alsa_open_device(TSMFAlsaAudioDevice* alsa)
static BOOL tsmf_alsa_open_device(TSMFAlsaAudioDevice *alsa)
{
int error;
error = snd_pcm_open(&alsa->out_handle, alsa->device, SND_PCM_STREAM_PLAYBACK, 0);
if (error < 0)
if(error < 0)
{
DEBUG_WARN("failed to open device %s", alsa->device);
return FALSE;
}
DEBUG_DVC("open device %s", alsa->device);
DEBUG_TSMF("open device %s", alsa->device);
return TRUE;
}
static BOOL tsmf_alsa_open(ITSMFAudioDevice* audio, const char* device)
static BOOL tsmf_alsa_open(ITSMFAudioDevice *audio, const char *device)
{
TSMFAlsaAudioDevice* alsa = (TSMFAlsaAudioDevice*) audio;
if (!device)
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
if(!device)
{
if (!alsa->device[0])
if(!alsa->device[0])
strncpy(alsa->device, "default", sizeof(alsa->device));
}
else
{
strncpy(alsa->device, device, sizeof(alsa->device));
}
return tsmf_alsa_open_device(alsa);
}
static BOOL tsmf_alsa_set_format(ITSMFAudioDevice* audio,
UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
static BOOL tsmf_alsa_set_format(ITSMFAudioDevice *audio,
UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
{
int error;
snd_pcm_uframes_t frames;
snd_pcm_hw_params_t* hw_params;
snd_pcm_sw_params_t* sw_params;
TSMFAlsaAudioDevice* alsa = (TSMFAlsaAudioDevice*) audio;
if (!alsa->out_handle)
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
if(!alsa->out_handle)
return FALSE;
snd_pcm_drop(alsa->out_handle);
alsa->actual_rate = alsa->source_rate = sample_rate;
alsa->actual_channels = alsa->source_channels = channels;
alsa->bytes_per_sample = bits_per_sample / 8;
error = snd_pcm_hw_params_malloc(&hw_params);
if (error < 0)
if(error < 0)
{
DEBUG_WARN("snd_pcm_hw_params_malloc failed");
return FALSE;
}
snd_pcm_hw_params_any(alsa->out_handle, hw_params);
snd_pcm_hw_params_set_access(alsa->out_handle, hw_params,
SND_PCM_ACCESS_RW_INTERLEAVED);
SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(alsa->out_handle, hw_params,
SND_PCM_FORMAT_S16_LE);
SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near(alsa->out_handle, hw_params,
&alsa->actual_rate, NULL);
&alsa->actual_rate, NULL);
snd_pcm_hw_params_set_channels_near(alsa->out_handle, hw_params,
&alsa->actual_channels);
&alsa->actual_channels);
frames = sample_rate;
snd_pcm_hw_params_set_buffer_size_near(alsa->out_handle, hw_params,
&frames);
&frames);
snd_pcm_hw_params(alsa->out_handle, hw_params);
snd_pcm_hw_params_free(hw_params);
error = snd_pcm_sw_params_malloc(&sw_params);
if (error < 0)
if(error < 0)
{
DEBUG_WARN("snd_pcm_sw_params_malloc");
return FALSE;
}
snd_pcm_sw_params_current(alsa->out_handle, sw_params);
snd_pcm_sw_params_set_start_threshold(alsa->out_handle, sw_params,
frames / 2);
frames / 2);
snd_pcm_sw_params(alsa->out_handle, sw_params);
snd_pcm_sw_params_free(sw_params);
snd_pcm_prepare(alsa->out_handle);
DEBUG_DVC("sample_rate %d channels %d bits_per_sample %d",
sample_rate, channels, bits_per_sample);
DEBUG_DVC("hardware buffer %d frames", (int)frames);
if ((alsa->actual_rate != alsa->source_rate) ||
(alsa->actual_channels != alsa->source_channels))
DEBUG_TSMF("sample_rate %d channels %d bits_per_sample %d",
sample_rate, channels, bits_per_sample);
DEBUG_TSMF("hardware buffer %d frames", (int)frames);
if((alsa->actual_rate != alsa->source_rate) ||
(alsa->actual_channels != alsa->source_channels))
{
DEBUG_DVC("actual rate %d / channel %d is different "
"from source rate %d / channel %d, resampling required.",
alsa->actual_rate, alsa->actual_channels,
alsa->source_rate, alsa->source_channels);
DEBUG_TSMF("actual rate %d / channel %d is different "
"from source rate %d / channel %d, resampling required.",
alsa->actual_rate, alsa->actual_channels,
alsa->source_rate, alsa->source_channels);
}
return TRUE;
}
static BOOL tsmf_alsa_play(ITSMFAudioDevice* audio, BYTE* data, UINT32 data_size)
static BOOL tsmf_alsa_play(ITSMFAudioDevice *audio, BYTE *data, UINT32 data_size)
{
int len;
int error;
int frames;
BYTE* end;
BYTE* src;
BYTE* pindex;
BYTE *end;
BYTE *src;
BYTE *pindex;
int rbytes_per_frame;
int sbytes_per_frame;
TSMFAlsaAudioDevice* alsa = (TSMFAlsaAudioDevice*) audio;
DEBUG_DVC("data_size %d", data_size);
if (alsa->out_handle)
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
DEBUG_TSMF("data_size %d", data_size);
if(alsa->out_handle)
{
sbytes_per_frame = alsa->source_channels * alsa->bytes_per_sample;
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_sample;
if ((alsa->source_rate == alsa->actual_rate) &&
(alsa->source_channels == alsa->actual_channels))
if((alsa->source_rate == alsa->actual_rate) &&
(alsa->source_channels == alsa->actual_channels))
{
src = data;
}
else
{
alsa->dsp_context->resample(alsa->dsp_context, data, alsa->bytes_per_sample,
alsa->source_channels, alsa->source_rate, data_size / sbytes_per_frame,
alsa->actual_channels, alsa->actual_rate);
alsa->source_channels, alsa->source_rate, data_size / sbytes_per_frame,
alsa->actual_channels, alsa->actual_rate);
frames = alsa->dsp_context->resampled_frames;
DEBUG_DVC("resampled %d frames at %d to %d frames at %d",
data_size / sbytes_per_frame, alsa->source_rate, frames, alsa->actual_rate);
DEBUG_TSMF("resampled %d frames at %d to %d frames at %d",
data_size / sbytes_per_frame, alsa->source_rate, frames, alsa->actual_rate);
data_size = frames * rbytes_per_frame;
src = alsa->dsp_context->resampled_buffer;
}
pindex = src;
end = pindex + data_size;
while (pindex < end)
while(pindex < end)
{
len = end - pindex;
frames = len / rbytes_per_frame;
error = snd_pcm_writei(alsa->out_handle, pindex, frames);
if (error == -EPIPE)
if(error == -EPIPE)
{
snd_pcm_recover(alsa->out_handle, error, 0);
error = 0;
}
else if (error < 0)
{
DEBUG_DVC("error len %d", error);
snd_pcm_close(alsa->out_handle);
alsa->out_handle = 0;
tsmf_alsa_open_device(alsa);
else
if(error < 0)
{
DEBUG_TSMF("error len %d", error);
snd_pcm_close(alsa->out_handle);
alsa->out_handle = 0;
tsmf_alsa_open_device(alsa);
break;
}
DEBUG_TSMF("%d frames played.", error);
if(error == 0)
break;
}
DEBUG_DVC("%d frames played.", error);
if (error == 0)
break;
pindex += error * rbytes_per_frame;
}
}
free(data);
return TRUE;
}
static UINT64 tsmf_alsa_get_latency(ITSMFAudioDevice* audio)
static UINT64 tsmf_alsa_get_latency(ITSMFAudioDevice *audio)
{
UINT64 latency = 0;
snd_pcm_sframes_t frames = 0;
TSMFAlsaAudioDevice* alsa = (TSMFAlsaAudioDevice*) audio;
if (alsa->out_handle && alsa->actual_rate > 0 &&
snd_pcm_delay(alsa->out_handle, &frames) == 0 &&
frames > 0)
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
if(alsa->out_handle && alsa->actual_rate > 0 &&
snd_pcm_delay(alsa->out_handle, &frames) == 0 &&
frames > 0)
{
latency = ((UINT64)frames) * 10000000LL / (UINT64) alsa->actual_rate;
}
return latency;
}
static void tsmf_alsa_flush(ITSMFAudioDevice* audio)
static void tsmf_alsa_flush(ITSMFAudioDevice *audio)
{
}
static void tsmf_alsa_free(ITSMFAudioDevice* audio)
static void tsmf_alsa_free(ITSMFAudioDevice *audio)
{
TSMFAlsaAudioDevice* alsa = (TSMFAlsaAudioDevice*) audio;
DEBUG_DVC("");
if (alsa->out_handle)
TSMFAlsaAudioDevice *alsa = (TSMFAlsaAudioDevice *) audio;
DEBUG_TSMF("");
if(alsa->out_handle)
{
snd_pcm_drain(alsa->out_handle);
snd_pcm_close(alsa->out_handle);
}
freerdp_dsp_context_free(alsa->dsp_context);
free(alsa);
}
@ -268,21 +236,17 @@ static void tsmf_alsa_free(ITSMFAudioDevice* audio)
#define freerdp_tsmf_client_audio_subsystem_entry alsa_freerdp_tsmf_client_audio_subsystem_entry
#endif
ITSMFAudioDevice* freerdp_tsmf_client_audio_subsystem_entry(void)
ITSMFAudioDevice *freerdp_tsmf_client_audio_subsystem_entry(void)
{
TSMFAlsaAudioDevice* alsa;
alsa = (TSMFAlsaAudioDevice*) malloc(sizeof(TSMFAlsaAudioDevice));
TSMFAlsaAudioDevice *alsa;
alsa = (TSMFAlsaAudioDevice *) malloc(sizeof(TSMFAlsaAudioDevice));
ZeroMemory(alsa, sizeof(TSMFAlsaAudioDevice));
alsa->iface.Open = tsmf_alsa_open;
alsa->iface.SetFormat = tsmf_alsa_set_format;
alsa->iface.Play = tsmf_alsa_play;
alsa->iface.GetLatency = tsmf_alsa_get_latency;
alsa->iface.Flush = tsmf_alsa_flush;
alsa->iface.Free = tsmf_alsa_free;
alsa->dsp_context = freerdp_dsp_context_new();
return (ITSMFAudioDevice*) alsa;
return (ITSMFAudioDevice *) alsa;
}

View File

@ -32,8 +32,6 @@
#include <libavcodec/avcodec.h>
#include <pthread.h>
#include "tsmf_constants.h"
#include "tsmf_decoder.h"
@ -59,55 +57,47 @@ typedef struct _TSMFFFmpegDecoder
#else
enum AVCodecID codec_id;
#endif
AVCodecContext* codec_context;
AVCodec* codec;
AVFrame* frame;
AVCodecContext *codec_context;
AVCodec *codec;
AVFrame *frame;
int prepared;
BYTE* decoded_data;
BYTE *decoded_data;
UINT32 decoded_size;
UINT32 decoded_size_max;
} TSMFFFmpegDecoder;
static BOOL tsmf_ffmpeg_init_context(ITSMFDecoder* decoder)
static BOOL tsmf_ffmpeg_init_context(ITSMFDecoder *decoder)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
mdecoder->codec_context = avcodec_alloc_context3(NULL);
if (!mdecoder->codec_context)
if(!mdecoder->codec_context)
{
DEBUG_WARN("avcodec_alloc_context failed.");
return FALSE;
}
return TRUE;
}
static BOOL tsmf_ffmpeg_init_video_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYPE* media_type)
static BOOL tsmf_ffmpeg_init_video_stream(ITSMFDecoder *decoder, const TS_AM_MEDIA_TYPE *media_type)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
mdecoder->codec_context->width = media_type->Width;
mdecoder->codec_context->height = media_type->Height;
mdecoder->codec_context->bit_rate = media_type->BitRate;
mdecoder->codec_context->time_base.den = media_type->SamplesPerSecond.Numerator;
mdecoder->codec_context->time_base.num = media_type->SamplesPerSecond.Denominator;
mdecoder->frame = avcodec_alloc_frame();
return TRUE;
}
static BOOL tsmf_ffmpeg_init_audio_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYPE* media_type)
static BOOL tsmf_ffmpeg_init_audio_stream(ITSMFDecoder *decoder, const TS_AM_MEDIA_TYPE *media_type)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
mdecoder->codec_context->sample_rate = media_type->SamplesPerSecond.Numerator;
mdecoder->codec_context->bit_rate = media_type->BitRate;
mdecoder->codec_context->channels = media_type->Channels;
mdecoder->codec_context->block_align = media_type->BlockAlign;
#if LIBAVCODEC_VERSION_MAJOR < 55
#ifdef AV_CPU_FLAG_SSE2
mdecoder->codec_context->dsp_mask = AV_CPU_FLAG_SSE2 | AV_CPU_FLAG_MMX2;
@ -125,43 +115,38 @@ static BOOL tsmf_ffmpeg_init_audio_stream(ITSMFDecoder* decoder, const TS_AM_MED
av_set_cpu_flags_mask(FF_MM_SSE2 | FF_MM_MMX2);
#endif
#endif /* LIBAVCODEC_VERSION_MAJOR < 55 */
return TRUE;
}
static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYPE* media_type)
static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder *decoder, const TS_AM_MEDIA_TYPE *media_type)
{
BYTE* p;
BYTE *p;
UINT32 size;
const BYTE* s;
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
const BYTE *s;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
mdecoder->codec = avcodec_find_decoder(mdecoder->codec_id);
if (!mdecoder->codec)
if(!mdecoder->codec)
{
DEBUG_WARN("avcodec_find_decoder failed.");
return FALSE;
}
mdecoder->codec_context->codec_id = mdecoder->codec_id;
mdecoder->codec_context->codec_type = mdecoder->media_type;
if (mdecoder->media_type == AVMEDIA_TYPE_VIDEO)
if(mdecoder->media_type == AVMEDIA_TYPE_VIDEO)
{
if (!tsmf_ffmpeg_init_video_stream(decoder, media_type))
if(!tsmf_ffmpeg_init_video_stream(decoder, media_type))
return FALSE;
}
else if (mdecoder->media_type == AVMEDIA_TYPE_AUDIO)
else
if(mdecoder->media_type == AVMEDIA_TYPE_AUDIO)
{
if(!tsmf_ffmpeg_init_audio_stream(decoder, media_type))
return FALSE;
}
if(media_type->ExtraData)
{
if (!tsmf_ffmpeg_init_audio_stream(decoder, media_type))
return FALSE;
}
if (media_type->ExtraData)
{
if (media_type->SubType == TSMF_SUB_TYPE_AVC1 &&
media_type->FormatType == TSMF_FORMAT_TYPE_MPEG2VIDEOINFO)
if(media_type->SubType == TSMF_SUB_TYPE_AVC1 &&
media_type->FormatType == TSMF_FORMAT_TYPE_MPEG2VIDEOINFO)
{
/* The extradata format that FFmpeg uses is following CodecPrivate in Matroska.
See http://haali.su/mkv/codecs.pdf */
@ -194,33 +179,27 @@ static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYP
memset(mdecoder->codec_context->extradata + media_type->ExtraDataSize, 0, 8);
}
}
if (mdecoder->codec->capabilities & CODEC_CAP_TRUNCATED)
if(mdecoder->codec->capabilities & CODEC_CAP_TRUNCATED)
mdecoder->codec_context->flags |= CODEC_FLAG_TRUNCATED;
return TRUE;
}
static BOOL tsmf_ffmpeg_prepare(ITSMFDecoder* decoder)
static BOOL tsmf_ffmpeg_prepare(ITSMFDecoder *decoder)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
if (avcodec_open2(mdecoder->codec_context, mdecoder->codec, NULL) < 0)
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
if(avcodec_open2(mdecoder->codec_context, mdecoder->codec, NULL) < 0)
{
DEBUG_WARN("avcodec_open2 failed.");
return FALSE;
}
mdecoder->prepared = 1;
return TRUE;
}
static BOOL tsmf_ffmpeg_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* media_type)
static BOOL tsmf_ffmpeg_set_format(ITSMFDecoder *decoder, TS_AM_MEDIA_TYPE *media_type)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
switch (media_type->MajorType)
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
switch(media_type->MajorType)
{
case TSMF_MAJOR_TYPE_VIDEO:
mdecoder->media_type = AVMEDIA_TYPE_VIDEO;
@ -231,7 +210,7 @@ static BOOL tsmf_ffmpeg_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* medi
default:
return FALSE;
}
switch (media_type->SubType)
switch(media_type->SubType)
{
case TSMF_SUB_TYPE_WVC1:
mdecoder->codec_id = CODEC_ID_VC1;
@ -259,7 +238,7 @@ static BOOL tsmf_ffmpeg_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* medi
/* For AAC the pFormat is a HEAACWAVEINFO struct, and the codec data
is at the end of it. See
http://msdn.microsoft.com/en-us/library/dd757806.aspx */
if (media_type->ExtraData)
if(media_type->ExtraData)
{
media_type->ExtraData += 12;
media_type->ExtraDataSize -= 12;
@ -275,118 +254,108 @@ static BOOL tsmf_ffmpeg_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* medi
default:
return FALSE;
}
if (!tsmf_ffmpeg_init_context(decoder))
if(!tsmf_ffmpeg_init_context(decoder))
return FALSE;
if (!tsmf_ffmpeg_init_stream(decoder, media_type))
if(!tsmf_ffmpeg_init_stream(decoder, media_type))
return FALSE;
if (!tsmf_ffmpeg_prepare(decoder))
if(!tsmf_ffmpeg_prepare(decoder))
return FALSE;
return TRUE;
}
static BOOL tsmf_ffmpeg_decode_video(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, UINT32 extensions)
static BOOL tsmf_ffmpeg_decode_video(ITSMFDecoder *decoder, const BYTE *data, UINT32 data_size, UINT32 extensions)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
int decoded;
int len;
AVFrame* frame;
AVFrame *frame;
BOOL ret = TRUE;
#if LIBAVCODEC_VERSION_MAJOR < 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR <= 20)
len = avcodec_decode_video(mdecoder->codec_context, mdecoder->frame, &decoded, data, data_size);
#else
{
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = (BYTE*) data;
pkt.data = (BYTE *) data;
pkt.size = data_size;
if (extensions & TSMM_SAMPLE_EXT_CLEANPOINT)
if(extensions & TSMM_SAMPLE_EXT_CLEANPOINT)
pkt.flags |= AV_PKT_FLAG_KEY;
len = avcodec_decode_video2(mdecoder->codec_context, mdecoder->frame, &decoded, &pkt);
}
#endif
if (len < 0)
if(len < 0)
{
DEBUG_WARN("data_size %d, avcodec_decode_video failed (%d)", data_size, len);
ret = FALSE;
}
else if (!decoded)
{
DEBUG_WARN("data_size %d, no frame is decoded.", data_size);
ret = FALSE;
}
else
{
DEBUG_DVC("linesize[0] %d linesize[1] %d linesize[2] %d linesize[3] %d "
"pix_fmt %d width %d height %d",
mdecoder->frame->linesize[0], mdecoder->frame->linesize[1],
mdecoder->frame->linesize[2], mdecoder->frame->linesize[3],
mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
mdecoder->decoded_size = avpicture_get_size(mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
mdecoder->decoded_data = malloc(mdecoder->decoded_size);
ZeroMemory(mdecoder->decoded_data, mdecoder->decoded_size);
frame = avcodec_alloc_frame();
avpicture_fill((AVPicture*) frame, mdecoder->decoded_data,
mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
av_picture_copy((AVPicture*) frame, (AVPicture*) mdecoder->frame,
mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
av_free(frame);
}
if(!decoded)
{
DEBUG_WARN("data_size %d, no frame is decoded.", data_size);
ret = FALSE;
}
else
{
DEBUG_TSMF("linesize[0] %d linesize[1] %d linesize[2] %d linesize[3] %d "
"pix_fmt %d width %d height %d",
mdecoder->frame->linesize[0], mdecoder->frame->linesize[1],
mdecoder->frame->linesize[2], mdecoder->frame->linesize[3],
mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
mdecoder->decoded_size = avpicture_get_size(mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
mdecoder->decoded_data = malloc(mdecoder->decoded_size);
ZeroMemory(mdecoder->decoded_data, mdecoder->decoded_size);
frame = avcodec_alloc_frame();
avpicture_fill((AVPicture *) frame, mdecoder->decoded_data,
mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
av_picture_copy((AVPicture *) frame, (AVPicture *) mdecoder->frame,
mdecoder->codec_context->pix_fmt,
mdecoder->codec_context->width, mdecoder->codec_context->height);
av_free(frame);
}
return ret;
}
static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, UINT32 extensions)
static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder *decoder, const BYTE *data, UINT32 data_size, UINT32 extensions)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
int len;
int frame_size;
UINT32 src_size;
const BYTE* src;
BYTE* dst;
const BYTE *src;
BYTE *dst;
int dst_offset;
#if 0
LLOGLN(0, ("tsmf_ffmpeg_decode_audio: data_size %d", data_size));
int i;
for (i = 0; i < data_size; i++)
for(i = 0; i < data_size; i++)
{
LLOG(0, ("%02X ", data[i]));
if (i % 16 == 15)
if(i % 16 == 15)
LLOG(0, ("\n"));
}
LLOG(0, ("\n"));
#endif
if (mdecoder->decoded_size_max == 0)
if(mdecoder->decoded_size_max == 0)
mdecoder->decoded_size_max = MAX_AUDIO_FRAME_SIZE + 16;
mdecoder->decoded_data = malloc(mdecoder->decoded_size_max);
ZeroMemory(mdecoder->decoded_data, mdecoder->decoded_size_max);
/* align the memory for SSE2 needs */
dst = (BYTE*) (((uintptr_t) mdecoder->decoded_data + 15) & ~ 0x0F);
dst = (BYTE *)(((uintptr_t) mdecoder->decoded_data + 15) & ~ 0x0F);
dst_offset = dst - mdecoder->decoded_data;
src = data;
src_size = data_size;
while (src_size > 0)
while(src_size > 0)
{
/* Ensure enough space for decoding */
if (mdecoder->decoded_size_max - mdecoder->decoded_size < MAX_AUDIO_FRAME_SIZE)
if(mdecoder->decoded_size_max - mdecoder->decoded_size < MAX_AUDIO_FRAME_SIZE)
{
mdecoder->decoded_size_max = mdecoder->decoded_size_max * 2 + 16;
mdecoder->decoded_data = realloc(mdecoder->decoded_data, mdecoder->decoded_size_max);
dst = (BYTE*) (((uintptr_t)mdecoder->decoded_data + 15) & ~ 0x0F);
if (dst - mdecoder->decoded_data != dst_offset)
dst = (BYTE *)(((uintptr_t)mdecoder->decoded_data + 15) & ~ 0x0F);
if(dst - mdecoder->decoded_data != dst_offset)
{
/* re-align the memory if the alignment has changed after realloc */
memmove(dst, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
@ -394,72 +363,64 @@ static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UI
}
dst += mdecoder->decoded_size;
}
frame_size = mdecoder->decoded_size_max - mdecoder->decoded_size;
#if LIBAVCODEC_VERSION_MAJOR < 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR <= 20)
len = avcodec_decode_audio2(mdecoder->codec_context,
(int16_t*) dst, &frame_size, src, src_size);
(int16_t *) dst, &frame_size, src, src_size);
#else
{
AVFrame* decoded_frame = avcodec_alloc_frame();
AVFrame *decoded_frame = avcodec_alloc_frame();
int got_frame = 0;
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = (BYTE*) src;
pkt.data = (BYTE *) src;
pkt.size = src_size;
len = avcodec_decode_audio4(mdecoder->codec_context, decoded_frame, &got_frame, &pkt);
if (len >= 0 && got_frame)
if(len >= 0 && got_frame)
{
frame_size = av_samples_get_buffer_size(NULL, mdecoder->codec_context->channels,
decoded_frame->nb_samples, mdecoder->codec_context->sample_fmt, 1);
decoded_frame->nb_samples, mdecoder->codec_context->sample_fmt, 1);
memcpy(dst, decoded_frame->data[0], frame_size);
}
av_free(decoded_frame);
}
#endif
if (len <= 0 || frame_size <= 0)
if(len <= 0 || frame_size <= 0)
{
DEBUG_WARN("error decoding");
break;
}
src += len;
src_size -= len;
mdecoder->decoded_size += frame_size;
dst += frame_size;
}
if (mdecoder->decoded_size == 0)
if(mdecoder->decoded_size == 0)
{
free(mdecoder->decoded_data);
mdecoder->decoded_data = NULL;
}
else if (dst_offset)
{
/* move the aligned decoded data to original place */
memmove(mdecoder->decoded_data, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
}
DEBUG_DVC("data_size %d decoded_size %d",
data_size, mdecoder->decoded_size);
else
if(dst_offset)
{
/* move the aligned decoded data to original place */
memmove(mdecoder->decoded_data, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size);
}
DEBUG_TSMF("data_size %d decoded_size %d",
data_size, mdecoder->decoded_size);
return TRUE;
}
static BOOL tsmf_ffmpeg_decode(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, UINT32 extensions)
static BOOL tsmf_ffmpeg_decode(ITSMFDecoder *decoder, const BYTE *data, UINT32 data_size, UINT32 extensions)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
if (mdecoder->decoded_data)
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
if(mdecoder->decoded_data)
{
free(mdecoder->decoded_data);
mdecoder->decoded_data = NULL;
}
mdecoder->decoded_size = 0;
switch (mdecoder->media_type)
switch(mdecoder->media_type)
{
case AVMEDIA_TYPE_VIDEO:
return tsmf_ffmpeg_decode_video(decoder, data, data_size, extensions);
@ -471,40 +432,35 @@ static BOOL tsmf_ffmpeg_decode(ITSMFDecoder* decoder, const BYTE* data, UINT32 d
}
}
static BYTE* tsmf_ffmpeg_get_decoded_data(ITSMFDecoder* decoder, UINT32* size)
static BYTE *tsmf_ffmpeg_get_decoded_data(ITSMFDecoder *decoder, UINT32 *size)
{
BYTE* buf;
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
BYTE *buf;
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
*size = mdecoder->decoded_size;
buf = mdecoder->decoded_data;
mdecoder->decoded_data = NULL;
mdecoder->decoded_size = 0;
return buf;
}
static UINT32 tsmf_ffmpeg_get_decoded_format(ITSMFDecoder* decoder)
static UINT32 tsmf_ffmpeg_get_decoded_format(ITSMFDecoder *decoder)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
switch (mdecoder->codec_context->pix_fmt)
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
switch(mdecoder->codec_context->pix_fmt)
{
case PIX_FMT_YUV420P:
return RDP_PIXFMT_I420;
default:
DEBUG_WARN("unsupported pixel format %u",
mdecoder->codec_context->pix_fmt);
mdecoder->codec_context->pix_fmt);
return (UINT32) -1;
}
}
static BOOL tsmf_ffmpeg_get_decoded_dimension(ITSMFDecoder* decoder, UINT32* width, UINT32* height)
static BOOL tsmf_ffmpeg_get_decoded_dimension(ITSMFDecoder *decoder, UINT32 *width, UINT32 *height)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
if (mdecoder->codec_context->width > 0 && mdecoder->codec_context->height > 0)
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
if(mdecoder->codec_context->width > 0 && mdecoder->codec_context->height > 0)
{
*width = mdecoder->codec_context->width;
*height = mdecoder->codec_context->height;
@ -516,25 +472,21 @@ static BOOL tsmf_ffmpeg_get_decoded_dimension(ITSMFDecoder* decoder, UINT32* wid
}
}
static void tsmf_ffmpeg_free(ITSMFDecoder* decoder)
static void tsmf_ffmpeg_free(ITSMFDecoder *decoder)
{
TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*) decoder;
if (mdecoder->frame)
TSMFFFmpegDecoder *mdecoder = (TSMFFFmpegDecoder *) decoder;
if(mdecoder->frame)
av_free(mdecoder->frame);
if (mdecoder->decoded_data)
if(mdecoder->decoded_data)
free(mdecoder->decoded_data);
if (mdecoder->codec_context)
if(mdecoder->codec_context)
{
if (mdecoder->prepared)
if(mdecoder->prepared)
avcodec_close(mdecoder->codec_context);
if (mdecoder->codec_context->extradata)
if(mdecoder->codec_context->extradata)
free(mdecoder->codec_context->extradata);
av_free(mdecoder->codec_context);
}
free(decoder);
}
@ -544,27 +496,22 @@ static BOOL initialized = FALSE;
#define freerdp_tsmf_client_decoder_subsystem_entry ffmpeg_freerdp_tsmf_client_decoder_subsystem_entry
#endif
ITSMFDecoder* freerdp_tsmf_client_decoder_subsystem_entry(void)
ITSMFDecoder *freerdp_tsmf_client_decoder_subsystem_entry(void)
{
TSMFFFmpegDecoder* decoder;
if (!initialized)
TSMFFFmpegDecoder *decoder;
if(!initialized)
{
avcodec_register_all();
initialized = TRUE;
}
fprintf(stderr, "TSMFDecoderEntry FFMPEG\n");
decoder = (TSMFFFmpegDecoder*) malloc(sizeof(TSMFFFmpegDecoder));
decoder = (TSMFFFmpegDecoder *) malloc(sizeof(TSMFFFmpegDecoder));
ZeroMemory(decoder, sizeof(TSMFFFmpegDecoder));
decoder->iface.SetFormat = tsmf_ffmpeg_set_format;
decoder->iface.Decode = tsmf_ffmpeg_decode;
decoder->iface.GetDecodedData = tsmf_ffmpeg_get_decoded_data;
decoder->iface.GetDecodedFormat = tsmf_ffmpeg_get_decoded_format;
decoder->iface.GetDecodedDimension = tsmf_ffmpeg_get_decoded_dimension;
decoder->iface.Free = tsmf_ffmpeg_free;
return (ITSMFDecoder*) decoder;
return (ITSMFDecoder *) decoder;
}

View File

@ -37,75 +37,70 @@ typedef struct _TSMFPulseAudioDevice
ITSMFAudioDevice iface;
char device[32];
pa_threaded_mainloop* mainloop;
pa_context* context;
pa_threaded_mainloop *mainloop;
pa_context *context;
pa_sample_spec sample_spec;
pa_stream* stream;
pa_stream *stream;
} TSMFPulseAudioDevice;
static void tsmf_pulse_context_state_callback(pa_context* context, void* userdata)
static void tsmf_pulse_context_state_callback(pa_context *context, void *userdata)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) userdata;
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
pa_context_state_t state;
state = pa_context_get_state(context);
switch (state)
switch(state)
{
case PA_CONTEXT_READY:
DEBUG_DVC("PA_CONTEXT_READY");
DEBUG_TSMF("PA_CONTEXT_READY");
pa_threaded_mainloop_signal(pulse->mainloop, 0);
break;
case PA_CONTEXT_FAILED:
case PA_CONTEXT_TERMINATED:
DEBUG_DVC("state %d", (int)state);
DEBUG_TSMF("state %d", (int)state);
pa_threaded_mainloop_signal(pulse->mainloop, 0);
break;
default:
DEBUG_DVC("state %d", (int)state);
DEBUG_TSMF("state %d", (int)state);
break;
}
}
static BOOL tsmf_pulse_connect(TSMFPulseAudioDevice* pulse)
static BOOL tsmf_pulse_connect(TSMFPulseAudioDevice *pulse)
{
pa_context_state_t state;
if (!pulse->context)
if(!pulse->context)
return FALSE;
if (pa_context_connect(pulse->context, NULL, 0, NULL))
if(pa_context_connect(pulse->context, NULL, 0, NULL))
{
DEBUG_WARN("pa_context_connect failed (%d)",
pa_context_errno(pulse->context));
pa_context_errno(pulse->context));
return FALSE;
}
pa_threaded_mainloop_lock(pulse->mainloop);
if (pa_threaded_mainloop_start(pulse->mainloop) < 0)
if(pa_threaded_mainloop_start(pulse->mainloop) < 0)
{
pa_threaded_mainloop_unlock(pulse->mainloop);
DEBUG_WARN("pa_threaded_mainloop_start failed (%d)",
pa_context_errno(pulse->context));
pa_context_errno(pulse->context));
return FALSE;
}
for (;;)
for(;;)
{
state = pa_context_get_state(pulse->context);
if (state == PA_CONTEXT_READY)
if(state == PA_CONTEXT_READY)
break;
if (!PA_CONTEXT_IS_GOOD(state))
if(!PA_CONTEXT_IS_GOOD(state))
{
DEBUG_DVC("bad context state (%d)",
pa_context_errno(pulse->context));
DEBUG_TSMF("bad context state (%d)",
pa_context_errno(pulse->context));
break;
}
pa_threaded_mainloop_wait(pulse->mainloop);
}
pa_threaded_mainloop_unlock(pulse->mainloop);
if (state == PA_CONTEXT_READY)
if(state == PA_CONTEXT_READY)
{
DEBUG_DVC("connected");
DEBUG_TSMF("connected");
return TRUE;
}
else
@ -115,166 +110,150 @@ static BOOL tsmf_pulse_connect(TSMFPulseAudioDevice* pulse)
}
}
static BOOL tsmf_pulse_open(ITSMFAudioDevice* audio, const char* device)
static BOOL tsmf_pulse_open(ITSMFAudioDevice *audio, const char *device)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) audio;
if (device)
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
if(device)
{
strcpy(pulse->device, device);
}
pulse->mainloop = pa_threaded_mainloop_new();
if (!pulse->mainloop)
if(!pulse->mainloop)
{
DEBUG_WARN("pa_threaded_mainloop_new failed");
return FALSE;
}
pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
if (!pulse->context)
if(!pulse->context)
{
DEBUG_WARN("pa_context_new failed");
return FALSE;
}
pa_context_set_state_callback(pulse->context, tsmf_pulse_context_state_callback, pulse);
if (tsmf_pulse_connect(pulse))
if(tsmf_pulse_connect(pulse))
{
DEBUG_WARN("tsmf_pulse_connect failed");
return FALSE;
}
DEBUG_DVC("open device %s", pulse->device);
DEBUG_TSMF("open device %s", pulse->device);
return TRUE;
}
static void tsmf_pulse_stream_success_callback(pa_stream* stream, int success, void* userdata)
static void tsmf_pulse_stream_success_callback(pa_stream *stream, int success, void *userdata)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) userdata;
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
pa_threaded_mainloop_signal(pulse->mainloop, 0);
}
static void tsmf_pulse_wait_for_operation(TSMFPulseAudioDevice* pulse, pa_operation* operation)
static void tsmf_pulse_wait_for_operation(TSMFPulseAudioDevice *pulse, pa_operation *operation)
{
if (operation == NULL)
if(operation == NULL)
return;
while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
while(pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
{
pa_threaded_mainloop_wait(pulse->mainloop);
}
pa_operation_unref(operation);
}
static void tsmf_pulse_stream_state_callback(pa_stream* stream, void* userdata)
static void tsmf_pulse_stream_state_callback(pa_stream *stream, void *userdata)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) userdata;
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
pa_stream_state_t state;
state = pa_stream_get_state(stream);
switch (state)
switch(state)
{
case PA_STREAM_READY:
DEBUG_DVC("PA_STREAM_READY");
pa_threaded_mainloop_signal (pulse->mainloop, 0);
DEBUG_TSMF("PA_STREAM_READY");
pa_threaded_mainloop_signal(pulse->mainloop, 0);
break;
case PA_STREAM_FAILED:
case PA_STREAM_TERMINATED:
DEBUG_DVC("state %d", (int)state);
pa_threaded_mainloop_signal (pulse->mainloop, 0);
DEBUG_TSMF("state %d", (int)state);
pa_threaded_mainloop_signal(pulse->mainloop, 0);
break;
default:
DEBUG_DVC("state %d", (int)state);
DEBUG_TSMF("state %d", (int)state);
break;
}
}
static void tsmf_pulse_stream_request_callback(pa_stream* stream, size_t length, void* userdata)
static void tsmf_pulse_stream_request_callback(pa_stream *stream, size_t length, void *userdata)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) userdata;
DEBUG_DVC("%d", (int) length);
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) userdata;
DEBUG_TSMF("%d", (int) length);
pa_threaded_mainloop_signal(pulse->mainloop, 0);
}
static BOOL tsmf_pulse_close_stream(TSMFPulseAudioDevice* pulse)
static BOOL tsmf_pulse_close_stream(TSMFPulseAudioDevice *pulse)
{
if (!pulse->context || !pulse->stream)
if(!pulse->context || !pulse->stream)
return FALSE;
DEBUG_DVC("");
DEBUG_TSMF("");
pa_threaded_mainloop_lock(pulse->mainloop);
pa_stream_set_write_callback(pulse->stream, NULL, NULL);
tsmf_pulse_wait_for_operation(pulse,
pa_stream_drain(pulse->stream, tsmf_pulse_stream_success_callback, pulse));
pa_stream_drain(pulse->stream, tsmf_pulse_stream_success_callback, pulse));
pa_stream_disconnect(pulse->stream);
pa_stream_unref(pulse->stream);
pulse->stream = NULL;
pa_threaded_mainloop_unlock(pulse->mainloop);
return TRUE;
}
static BOOL tsmf_pulse_open_stream(TSMFPulseAudioDevice* pulse)
static BOOL tsmf_pulse_open_stream(TSMFPulseAudioDevice *pulse)
{
pa_stream_state_t state;
pa_buffer_attr buffer_attr = { 0 };
if (!pulse->context)
if(!pulse->context)
return FALSE;
DEBUG_DVC("");
DEBUG_TSMF("");
pa_threaded_mainloop_lock(pulse->mainloop);
pulse->stream = pa_stream_new(pulse->context, "freerdp",
&pulse->sample_spec, NULL);
if (!pulse->stream)
&pulse->sample_spec, NULL);
if(!pulse->stream)
{
pa_threaded_mainloop_unlock(pulse->mainloop);
DEBUG_WARN("pa_stream_new failed (%d)",
pa_context_errno(pulse->context));
pa_context_errno(pulse->context));
return FALSE;
}
pa_stream_set_state_callback(pulse->stream,
tsmf_pulse_stream_state_callback, pulse);
tsmf_pulse_stream_state_callback, pulse);
pa_stream_set_write_callback(pulse->stream,
tsmf_pulse_stream_request_callback, pulse);
tsmf_pulse_stream_request_callback, pulse);
buffer_attr.maxlength = pa_usec_to_bytes(500000, &pulse->sample_spec);
buffer_attr.tlength = pa_usec_to_bytes(250000, &pulse->sample_spec);
buffer_attr.prebuf = (UINT32) -1;
buffer_attr.minreq = (UINT32) -1;
buffer_attr.fragsize = (UINT32) -1;
if (pa_stream_connect_playback(pulse->stream,
pulse->device[0] ? pulse->device : NULL, &buffer_attr,
PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE,
NULL, NULL) < 0)
if(pa_stream_connect_playback(pulse->stream,
pulse->device[0] ? pulse->device : NULL, &buffer_attr,
PA_STREAM_ADJUST_LATENCY | PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE,
NULL, NULL) < 0)
{
pa_threaded_mainloop_unlock(pulse->mainloop);
DEBUG_WARN("pa_stream_connect_playback failed (%d)",
pa_context_errno(pulse->context));
pa_context_errno(pulse->context));
return FALSE;
}
for (;;)
for(;;)
{
state = pa_stream_get_state(pulse->stream);
if (state == PA_STREAM_READY)
if(state == PA_STREAM_READY)
break;
if (!PA_STREAM_IS_GOOD(state))
if(!PA_STREAM_IS_GOOD(state))
{
DEBUG_WARN("bad stream state (%d)",
pa_context_errno(pulse->context));
pa_context_errno(pulse->context));
break;
}
pa_threaded_mainloop_wait(pulse->mainloop);
}
pa_threaded_mainloop_unlock(pulse->mainloop);
if (state == PA_STREAM_READY)
if(state == PA_STREAM_READY)
{
DEBUG_DVC("connected");
DEBUG_TSMF("connected");
return TRUE;
}
else
@ -284,105 +263,93 @@ static BOOL tsmf_pulse_open_stream(TSMFPulseAudioDevice* pulse)
}
}
static BOOL tsmf_pulse_set_format(ITSMFAudioDevice* audio,
UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
static BOOL tsmf_pulse_set_format(ITSMFAudioDevice *audio,
UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) audio;
DEBUG_DVC("sample_rate %d channels %d bits_per_sample %d",
sample_rate, channels, bits_per_sample);
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
DEBUG_TSMF("sample_rate %d channels %d bits_per_sample %d",
sample_rate, channels, bits_per_sample);
pulse->sample_spec.rate = sample_rate;
pulse->sample_spec.channels = channels;
pulse->sample_spec.format = PA_SAMPLE_S16LE;
return tsmf_pulse_open_stream(pulse);
}
static BOOL tsmf_pulse_play(ITSMFAudioDevice* audio, BYTE* data, UINT32 data_size)
static BOOL tsmf_pulse_play(ITSMFAudioDevice *audio, BYTE *data, UINT32 data_size)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) audio;
BYTE* src;
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
BYTE *src;
int len;
int ret;
DEBUG_DVC("data_size %d", data_size);
if (pulse->stream)
DEBUG_TSMF("data_size %d", data_size);
if(pulse->stream)
{
pa_threaded_mainloop_lock(pulse->mainloop);
src = data;
while (data_size > 0)
while(data_size > 0)
{
while ((len = pa_stream_writable_size(pulse->stream)) == 0)
while((len = pa_stream_writable_size(pulse->stream)) == 0)
{
DEBUG_DVC("waiting");
DEBUG_TSMF("waiting");
pa_threaded_mainloop_wait(pulse->mainloop);
}
if (len < 0)
if(len < 0)
break;
if (len > data_size)
if(len > data_size)
len = data_size;
ret = pa_stream_write(pulse->stream, src, len, NULL, 0LL, PA_SEEK_RELATIVE);
if (ret < 0)
if(ret < 0)
{
DEBUG_DVC("pa_stream_write failed (%d)",
pa_context_errno(pulse->context));
DEBUG_TSMF("pa_stream_write failed (%d)",
pa_context_errno(pulse->context));
break;
}
src += len;
data_size -= len;
}
pa_threaded_mainloop_unlock(pulse->mainloop);
}
free(data);
return TRUE;
}
static UINT64 tsmf_pulse_get_latency(ITSMFAudioDevice* audio)
static UINT64 tsmf_pulse_get_latency(ITSMFAudioDevice *audio)
{
pa_usec_t usec;
UINT64 latency = 0;
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) audio;
if (pulse->stream && pa_stream_get_latency(pulse->stream, &usec, NULL) == 0)
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
if(pulse->stream && pa_stream_get_latency(pulse->stream, &usec, NULL) == 0)
{
latency = ((UINT64)usec) * 10LL;
}
return latency;
}
static void tsmf_pulse_flush(ITSMFAudioDevice* audio)
static void tsmf_pulse_flush(ITSMFAudioDevice *audio)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) audio;
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
pa_threaded_mainloop_lock(pulse->mainloop);
tsmf_pulse_wait_for_operation(pulse,
pa_stream_flush(pulse->stream, tsmf_pulse_stream_success_callback, pulse));
pa_stream_flush(pulse->stream, tsmf_pulse_stream_success_callback, pulse));
pa_threaded_mainloop_unlock(pulse->mainloop);
}
static void tsmf_pulse_free(ITSMFAudioDevice* audio)
static void tsmf_pulse_free(ITSMFAudioDevice *audio)
{
TSMFPulseAudioDevice* pulse = (TSMFPulseAudioDevice*) audio;
DEBUG_DVC("");
TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
DEBUG_TSMF("");
tsmf_pulse_close_stream(pulse);
if (pulse->mainloop)
if(pulse->mainloop)
{
pa_threaded_mainloop_stop(pulse->mainloop);
}
if (pulse->context)
if(pulse->context)
{
pa_context_disconnect(pulse->context);
pa_context_unref(pulse->context);
pulse->context = NULL;
}
if (pulse->mainloop)
if(pulse->mainloop)
{
pa_threaded_mainloop_free(pulse->mainloop);
pulse->mainloop = NULL;
@ -394,20 +361,17 @@ static void tsmf_pulse_free(ITSMFAudioDevice* audio)
#define freerdp_tsmf_client_audio_subsystem_entry pulse_freerdp_tsmf_client_audio_subsystem_entry
#endif
ITSMFAudioDevice* freerdp_tsmf_client_audio_subsystem_entry(void)
ITSMFAudioDevice *freerdp_tsmf_client_audio_subsystem_entry(void)
{
TSMFPulseAudioDevice* pulse;
pulse = (TSMFPulseAudioDevice*) malloc(sizeof(TSMFPulseAudioDevice));
TSMFPulseAudioDevice *pulse;
pulse = (TSMFPulseAudioDevice *) malloc(sizeof(TSMFPulseAudioDevice));
ZeroMemory(pulse, sizeof(TSMFPulseAudioDevice));
pulse->iface.Open = tsmf_pulse_open;
pulse->iface.SetFormat = tsmf_pulse_set_format;
pulse->iface.Play = tsmf_pulse_play;
pulse->iface.GetLatency = tsmf_pulse_get_latency;
pulse->iface.Flush = tsmf_pulse_flush;
pulse->iface.Free = tsmf_pulse_free;
return (ITSMFAudioDevice*) pulse;
return (ITSMFAudioDevice *) pulse;
}