+++ /dev/null
-# FreeRDP: A Remote Desktop Protocol Implementation
-# FreeRDP cmake build script
-#
-# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
-# Copyright 2013 Armin Novak <armin.novak@gmail.com>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-define_channel_client_subsystem("rdpsnd" "audiotrack" "")
-
-set(${MODULE_PREFIX}_SRCS
- audiotrack.cpp
- rdpsnd_audiotrack.c)
-
-include_directories(.)
-include_directories(..)
-include_directories(${AUDIOTRACK_INCLUDE_DIRS})
-
-add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "")
-
-set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
-
-set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
- MONOLITHIC ${MONOLITHIC_BUILD}
- MODULE freerdp
- MODULES freerdp-codec freerdp-utils)
-
-set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
- MONOLITHIC ${MONOLITHIC_BUILD}
- MODULE winpr
- MODULES winpr-utils)
-
-set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${AUDIOTRACK_LIBRARIES})
-
-target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
-
-if(NOT STATIC_CHANNELS)
- install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_ADDIN_PATH})
-endif()
-
-set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client/AudioTrack")
+++ /dev/null
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_ERRORS_H
-#define ANDROID_ERRORS_H
-
-#include <sys/types.h>
-#include <errno.h>
-
-namespace android {
-
-// use this type to return error codes
-#ifdef HAVE_MS_C_RUNTIME
-typedef int status_t;
-#else
-typedef int32_t status_t;
-#endif
-
-/* the MS C runtime lacks a few error codes */
-
-/*
- * Error codes.
- * All error codes are negative values.
- */
-
-// Win32 #defines NO_ERROR as well. It has the same value, so there's no
-// real conflict, though it's a bit awkward.
-#ifdef _WIN32
-# undef NO_ERROR
-#endif
-
-enum {
- OK = 0, // Everything's swell.
- NO_ERROR = 0, // No errors.
-
- UNKNOWN_ERROR = 0x80000000,
-
- NO_MEMORY = -ENOMEM,
- INVALID_OPERATION = -ENOSYS,
- BAD_VALUE = -EINVAL,
- BAD_TYPE = 0x80000001,
- NAME_NOT_FOUND = -ENOENT,
- PERMISSION_DENIED = -EPERM,
- NO_INIT = -ENODEV,
- ALREADY_EXISTS = -EEXIST,
- DEAD_OBJECT = -EPIPE,
- FAILED_TRANSACTION = 0x80000002,
- JPARKS_BROKE_IT = -EPIPE,
-#if !defined(HAVE_MS_C_RUNTIME)
- BAD_INDEX = -EOVERFLOW,
- NOT_ENOUGH_DATA = -ENODATA,
- WOULD_BLOCK = -EWOULDBLOCK,
- TIMED_OUT = -ETIME,
- UNKNOWN_TRANSACTION = -EBADMSG,
-#else
- BAD_INDEX = -E2BIG,
- NOT_ENOUGH_DATA = 0x80000003,
- WOULD_BLOCK = 0x80000004,
- TIMED_OUT = 0x80000005,
- UNKNOWN_TRANSACTION = 0x80000006,
-#endif
-};
-
-// Restore define; enumeration is in "android" namespace, so the value defined
-// there won't work for Win32 code in a different namespace.
-#ifdef _WIN32
-# define NO_ERROR 0L
-#endif
-
-}; // namespace android
-
-// ---------------------------------------------------------------------------
-
-#endif // ANDROID_ERRORS_H
-
+++ /dev/null
-#include <dlfcn.h>\r
-#include <assert.h>\r
-#include <malloc.h>\r
-\r
-#include <android/log.h>\r
-#define TAG "freerdp_android_audiotrack"\r
-#define LOGI(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)\r
-\r
-#include "audiotrack.h"\r
-\r
-#define SIZE_OF_AUDIOTRACK 256\r
-\r
-// _ZN7android11AudioSystem19getOutputFrameCountEPii\r
-typedef int (*AudioSystem_getOutputFrameCount)(int *, int);\r
-// _ZN7android11AudioSystem16getOutputLatencyEPji\r
-typedef int (*AudioSystem_getOutputLatency)(unsigned int *, int);\r
-// _ZN7android11AudioSystem21getOutputSamplingRateEPii\r
-typedef int (*AudioSystem_getOutputSamplingRate)(int *, int);\r
-\r
-// _ZN7android10AudioTrack16getMinFrameCountEPiij\r
-typedef int (*AudioTrack_getMinFrameCount)(int *, int, unsigned int);\r
-\r
-// _ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_ii\r
-typedef void (*AudioTrack_ctor)(void *, int, unsigned int, int, int, int, unsigned int, void (*)(int, void *, void *), void *, int, int);\r
-// _ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_i\r
-typedef void (*AudioTrack_ctor_legacy)(void *, int, unsigned int, int, int, int, unsigned int, void (*)(int, void *, void *), void *, int);\r
-// _ZN7android10AudioTrackD1Ev\r
-typedef void (*AudioTrack_dtor)(void *);\r
-// _ZNK7android10AudioTrack9initCheckEv\r
-typedef int (*AudioTrack_initCheck)(void *);\r
-typedef uint32_t (*AudioTrack_latency)(void *);\r
-// _ZN7android10AudioTrack5startEv\r
-typedef void (*AudioTrack_start)(void *);\r
-// _ZN7android10AudioTrack4stopEv\r
-typedef void (*AudioTrack_stop)(void *);\r
-// _ZN7android10AudioTrack5writeEPKvj\r
-typedef int (*AudioTrack_write)(void *, void const*, unsigned int);\r
-// _ZN7android10AudioTrack5flushEv\r
-typedef void (*AudioTrack_flush)(void *);\r
-\r
-static void *libmedia;\r
-static AudioSystem_getOutputFrameCount as_getOutputFrameCount;\r
-static AudioSystem_getOutputLatency as_getOutputLatency;\r
-static AudioSystem_getOutputSamplingRate as_getOutputSamplingRate;\r
-\r
-static AudioTrack_getMinFrameCount at_getMinFrameCount;\r
-static AudioTrack_ctor at_ctor;\r
-static AudioTrack_ctor_legacy at_ctor_legacy;\r
-static AudioTrack_dtor at_dtor;\r
-static AudioTrack_initCheck at_initCheck;\r
-static AudioTrack_latency at_latency;\r
-static AudioTrack_start at_start;\r
-static AudioTrack_stop at_stop;\r
-static AudioTrack_write at_write;\r
-static AudioTrack_flush at_flush;\r
-\r
-class AndroidAudioTrack\r
-{\r
-private:\r
- void* mAudioTrack;\r
-\r
-public:\r
- AndroidAudioTrack()\r
- : mAudioTrack(NULL)\r
- { \r
- }\r
- \r
- virtual ~AndroidAudioTrack()\r
- {\r
- close();\r
- }\r
- \r
- void close()\r
- {\r
- if (mAudioTrack) {\r
- if (at_stop)\r
- at_stop(mAudioTrack);\r
- if (at_flush)\r
- at_flush(mAudioTrack);\r
- if (at_dtor)\r
- at_dtor(mAudioTrack);\r
- free(mAudioTrack);\r
- mAudioTrack = NULL;\r
- }\r
- }\r
- \r
- int set(int streamType, uint32_t sampleRate, int format, int channels)\r
- {\r
- int status;\r
- int minFrameCount = 0;\r
- int size = 0;\r
- \r
- LOGI("streamTyp = %d, sampleRate = %d, format = %d, channels = %d\n", streamType, sampleRate, format, channels);\r
- close();\r
-\r
- if (at_getMinFrameCount) {\r
- status = at_getMinFrameCount(&minFrameCount, streamType, sampleRate);\r
- LOGI("at_getMinFrameCount %d, %d\n", minFrameCount, status);\r
- }\r
- //size = minFrameCount * (channels == CHANNEL_OUT_STEREO ? 2 : 1) * 4;\r
- \r
- mAudioTrack = malloc(SIZE_OF_AUDIOTRACK);\r
- *((uint32_t *) ((uint32_t)mAudioTrack + SIZE_OF_AUDIOTRACK - 4)) = 0xbaadbaad;\r
- if (at_ctor) {\r
- at_ctor(mAudioTrack, streamType, sampleRate, format, channels, size, 0, NULL, NULL, 0, 0);\r
- } else if (at_ctor_legacy) {\r
- at_ctor_legacy(mAudioTrack, streamType, sampleRate, format, channels, size, 0, NULL, NULL, 0);\r
- } else {\r
- LOGI("Cannot create AudioTrack!");\r
- free(mAudioTrack);\r
- mAudioTrack = NULL;\r
- return -1;\r
- }\r
- assert( (*((uint32_t *) ((uint32_t)mAudioTrack + SIZE_OF_AUDIOTRACK - 4)) == 0xbaadbaad) );\r
-\r
- /* And Init */\r
- status = at_initCheck(mAudioTrack);\r
- LOGI("at_initCheck = %d\n", status);\r
-\r
- /* android 1.6 uses channel count instead of stream_type */\r
- if (status != 0 && at_ctor_legacy) {\r
- channels = (channels == CHANNEL_OUT_STEREO) ? 2 : 1;\r
- at_ctor_legacy(mAudioTrack, streamType, sampleRate, format, channels, size, 0, NULL, NULL, 0);\r
- status = at_initCheck(mAudioTrack);\r
- LOGI("at_initCheck2 = %d\n", status);\r
- }\r
- if (status != 0) { \r
- LOGI("Cannot create AudioTrack!");\r
- free(mAudioTrack);\r
- mAudioTrack = NULL;\r
- }\r
- return status;\r
- }\r
- uint32_t latency()\r
- {\r
- if (mAudioTrack && at_latency) {\r
- return at_latency(mAudioTrack);\r
- }\r
- return 0; \r
- } \r
- int start()\r
- {\r
- if (mAudioTrack && at_start) {\r
- at_start(mAudioTrack);\r
- return ANDROID_AUDIOTRACK_RESULT_SUCCESS;\r
- }\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- }\r
- int write(void* buffer, int size)\r
- {\r
- if (mAudioTrack && at_write) {\r
- return at_write(mAudioTrack, buffer, size);\r
- }\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO; \r
- }\r
- int flush()\r
- {\r
- if (mAudioTrack && at_flush) {\r
- at_flush(mAudioTrack);\r
- return ANDROID_AUDIOTRACK_RESULT_SUCCESS;\r
- }\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- } \r
- int stop()\r
- {\r
- if (mAudioTrack && at_stop) {\r
- at_stop(mAudioTrack);\r
- return ANDROID_AUDIOTRACK_RESULT_SUCCESS;\r
- }\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- }\r
- int reload()\r
- {\r
- return ANDROID_AUDIOTRACK_RESULT_SUCCESS;\r
- }\r
-};\r
-\r
-\r
-static void* InitLibrary()\r
-{\r
- /* DL Open libmedia */\r
- void *p_library;\r
- p_library = dlopen("libmedia.so", RTLD_NOW);\r
- if (!p_library)\r
- return NULL;\r
-\r
- /* Register symbols */\r
- as_getOutputFrameCount = (AudioSystem_getOutputFrameCount)(dlsym(p_library, "_ZN7android11AudioSystem19getOutputFrameCountEPii"));\r
- as_getOutputLatency = (AudioSystem_getOutputLatency)(dlsym(p_library, "_ZN7android11AudioSystem16getOutputLatencyEPji"));\r
- as_getOutputSamplingRate = (AudioSystem_getOutputSamplingRate)(dlsym(p_library, "_ZN7android11AudioSystem21getOutputSamplingRateEPii"));\r
- at_getMinFrameCount = (AudioTrack_getMinFrameCount)(dlsym(p_library, "_ZN7android10AudioTrack16getMinFrameCountEPiij"));\r
- at_ctor = (AudioTrack_ctor)(dlsym(p_library, "_ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_ii"));\r
- at_ctor_legacy = (AudioTrack_ctor_legacy)(dlsym(p_library, "_ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_i"));\r
- at_dtor = (AudioTrack_dtor)(dlsym(p_library, "_ZN7android10AudioTrackD1Ev"));\r
- at_initCheck = (AudioTrack_initCheck)(dlsym(p_library, "_ZNK7android10AudioTrack9initCheckEv"));\r
- at_latency = (AudioTrack_latency)(dlsym(p_library, "_ZNK7android10AudioTrack7latencyEv"));\r
- at_start = (AudioTrack_start)(dlsym(p_library, "_ZN7android10AudioTrack5startEv"));\r
- at_stop = (AudioTrack_stop)(dlsym(p_library, "_ZN7android10AudioTrack4stopEv"));\r
- at_write = (AudioTrack_write)(dlsym(p_library, "_ZN7android10AudioTrack5writeEPKvj"));\r
- at_flush = (AudioTrack_flush)(dlsym(p_library, "_ZN7android10AudioTrack5flushEv"));\r
-\r
- LOGI("p_library : %p\n", p_library);\r
- LOGI("as_getOutputFrameCount : %p\n", as_getOutputFrameCount);\r
- LOGI("as_getOutputLatency : %p\n", as_getOutputLatency);\r
- LOGI("as_getOutputSamplingRate : %p\n", as_getOutputSamplingRate);\r
- LOGI("at_getMinFrameCount : %p\n", at_getMinFrameCount);\r
- LOGI("at_ctor : %p\n", at_ctor);\r
- LOGI("at_ctor_legacy : %p\n", at_ctor_legacy);\r
- LOGI("at_dtor : %p\n", at_dtor);\r
- LOGI("at_initCheck : %p\n", at_initCheck);\r
- LOGI("at_latency : %p\n", at_latency);\r
- LOGI("at_start : %p\n", at_start);\r
- LOGI("at_stop : %p\n", at_stop);\r
- LOGI("at_write : %p\n", at_write);\r
- LOGI("at_flush : %p\n", at_flush);\r
- \r
- /* We need the first 3 or the last 1 */\r
-#if 0 \r
- if (!((as_getOutputFrameCount && as_getOutputLatency && as_getOutputSamplingRate)\r
- || at_getMinFrameCount)) {\r
- dlclose(p_library);\r
- return NULL;\r
- }\r
-#endif \r
-\r
- // We need all the other Symbols\r
- if (!((at_ctor || at_ctor_legacy) && at_dtor && at_initCheck &&\r
- at_start && at_stop && at_write && at_flush)) {\r
- dlclose(p_library);\r
- return NULL;\r
- }\r
- return p_library;\r
-}\r
-\r
-int freerdp_android_at_open(AUDIO_DRIVER_HANDLE* outHandle)\r
-{\r
- int ret = ANDROID_AUDIOTRACK_RESULT_SUCCESS;\r
- AndroidAudioTrack* audioTrack = new AndroidAudioTrack();\r
- \r
- *outHandle = audioTrack;\r
- \r
- return ret;\r
-}\r
-\r
-int freerdp_android_at_close(AUDIO_DRIVER_HANDLE handle)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- delete audioTrack;\r
- return ANDROID_AUDIOTRACK_RESULT_SUCCESS;\r
-}\r
-\r
-int freerdp_android_at_set(AUDIO_DRIVER_HANDLE handle, int streamType, uint32_t sampleRate, int format, int channels)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->set(streamType, sampleRate, format, channels);\r
-}\r
-\r
-int freerdp_android_at_set_volume(AUDIO_DRIVER_HANDLE handle, float left, float right)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return 0; \r
-}\r
-\r
-uint32_t freerdp_android_at_latency(AUDIO_DRIVER_HANDLE handle)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->latency();\r
-}\r
-\r
-int freerdp_android_at_start(AUDIO_DRIVER_HANDLE handle)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->start();\r
-}\r
-\r
-int freerdp_android_at_write(AUDIO_DRIVER_HANDLE handle, void *buffer, int buffer_size)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->write(buffer, buffer_size);\r
-}\r
-\r
-int freerdp_android_at_flush(AUDIO_DRIVER_HANDLE handle)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->flush();\r
-}\r
-\r
-int freerdp_android_at_stop(AUDIO_DRIVER_HANDLE handle)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->stop(); \r
-}\r
-\r
-int freerdp_android_at_reload(AUDIO_DRIVER_HANDLE handle)\r
-{\r
- AndroidAudioTrack* audioTrack = (AndroidAudioTrack*)handle;\r
- if (!audioTrack)\r
- return ANDROID_AUDIOTRACK_RESULT_ERRNO;\r
- return audioTrack->reload(); \r
-}\r
-\r
-int freerdp_android_at_init_library()\r
-{\r
- if (libmedia == NULL)\r
- { \r
- libmedia = InitLibrary();\r
- LOGI("loaded");\r
- }\r
-\r
- return 0;\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_AUDIOTRACK_WRAPPER_H
-#define ANDROID_AUDIOTRACK_WRAPPER_H
-
-#include <stdint.h>
-#include <jni.h>
-
-#define ANDROID_AUDIOTRACK_RESULT_SUCCESS 0
-#define ANDROID_AUDIOTRACK_RESULT_BAD_PARAMETER -1
-#define ANDROID_AUDIOTRACK_RESULT_JNI_EXCEPTION -2
-#define ANDROID_AUDIOTRACK_RESULT_ALLOCATION_FAILED -3
-#define ANDROID_AUDIOTRACK_RESULT_ERRNO -4
-
-enum stream_type {
- DEFAULT =-1,
- VOICE_CALL = 0,
- SYSTEM = 1,
- RING = 2,
- MUSIC = 3,
- ALARM = 4,
- NOTIFICATION = 5,
- BLUETOOTH_SCO = 6,
- ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
- DTMF = 8,
- TTS = 9,
- NUM_STREAM_TYPES
-};
-
-enum {
- NO_MORE_BUFFERS = 0x80000001,
- STOPPED = 1
-};
-
-// Audio sub formats (see AudioSystem::audio_format).
-enum pcm_sub_format {
- PCM_SUB_16_BIT = 0x1, // must be 1 for backward compatibility
- PCM_SUB_8_BIT = 0x2, // must be 2 for backward compatibility
-};
-
-// Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
-// The main format indicates the main codec type. The sub format field indicates options and parameters
-// for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
-// or profile. It can also be used for certain formats to give informations not present in the encoded
-// audio stream (e.g. octet alignement for AMR).
-enum audio_format {
- INVALID_FORMAT = -1,
- FORMAT_DEFAULT = 0,
- PCM = 0x00000000, // must be 0 for backward compatibility
- MP3 = 0x01000000,
- AMR_NB = 0x02000000,
- AMR_WB = 0x03000000,
- AAC = 0x04000000,
- HE_AAC_V1 = 0x05000000,
- HE_AAC_V2 = 0x06000000,
- VORBIS = 0x07000000,
- MAIN_FORMAT_MASK = 0xFF000000,
- SUB_FORMAT_MASK = 0x00FFFFFF,
- // Aliases
- PCM_16_BIT = (PCM|PCM_SUB_16_BIT),
- PCM_8_BIT = (PCM|PCM_SUB_8_BIT)
-};
-
-// Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
-enum audio_channels {
- // output channels
- CHANNEL_OUT_FRONT_LEFT = 0x4,
- CHANNEL_OUT_FRONT_RIGHT = 0x8,
- CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
- CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT)
-};
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void* AUDIO_DRIVER_HANDLE;
-
-int freerdp_android_at_init_library();
-int freerdp_android_at_open(AUDIO_DRIVER_HANDLE* outHandle);
-int freerdp_android_at_set(AUDIO_DRIVER_HANDLE handle, int streamType, uint32_t sampleRate, int format, int channels);
-int freerdp_android_at_set_volume(AUDIO_DRIVER_HANDLE handle, float left, float right);
-int freerdp_android_at_close(AUDIO_DRIVER_HANDLE handle);
-uint32_t freerdp_android_at_latency(AUDIO_DRIVER_HANDLE handle);
-int freerdp_android_at_start(AUDIO_DRIVER_HANDLE handle);
-int freerdp_android_at_write(AUDIO_DRIVER_HANDLE handle, void *buffer, int buffer_size);
-int freerdp_android_at_flush(AUDIO_DRIVER_HANDLE handle);
-int freerdp_android_at_stop(AUDIO_DRIVER_HANDLE handle);
-int freerdp_android_at_reload(AUDIO_DRIVER_HANDLE handle);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-/**
- * FreeRDP: A Remote Desktop Protocol client.
- * Audio Output Virtual Channel
- *
- * Copyright 2009-2011 Jay Sorg
- * Copyright 2010-2011 Vic Lee
- * Copyright 2012 Felix Long
- * Copyright 2013 Armin Novak
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <audiotrack.h>
-
-#include <freerdp/types.h>
-#include <freerdp/utils/svc_plugin.h>
-#include <freerdp/codec/dsp.h>
-
-#include "rdpsnd_main.h"
-
-typedef struct rdpsnd_audiotrack_plugin rdpsndAudioTrackPlugin;
-struct rdpsnd_audiotrack_plugin
-{
- rdpsndDevicePlugin device;
-
- AUDIO_DRIVER_HANDLE out_handle;
-
- UINT32 source_rate;
- UINT32 actual_rate;
- int format;
- UINT32 source_channels;
- UINT32 actual_channels;
- int bytes_per_channel;
- int wformat;
- int block_size;
- int latency;
-
- FREERDP_DSP_CONTEXT* dsp_context;
-};
-
-static void rdpsnd_audiotrack_set_format(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, int latency)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
-
- if (format != NULL)
- {
- audiotrack->source_rate = format->nSamplesPerSec;
- audiotrack->actual_rate = format->nSamplesPerSec;
- audiotrack->source_channels = format->nChannels;
- audiotrack->actual_channels = format->nChannels;
- switch (format->wFormatTag)
- {
- case 1: /* PCM */
- switch (format->wBitsPerSample)
- {
- case 8:
- audiotrack->format = PCM_8_BIT;
- audiotrack->bytes_per_channel = 1;
- break;
- case 16:
- audiotrack->format = PCM_16_BIT;
- audiotrack->bytes_per_channel = 2;
- break;
- }
- break;
-
- case 2: /* MS ADPCM */
- case 0x11: /* IMA ADPCM */
- audiotrack->format = PCM_16_BIT;
- audiotrack->bytes_per_channel = 2;
- break;
- }
- audiotrack->wformat = format->wFormatTag;
- audiotrack->block_size = format->nBlockAlign;
- }
- audiotrack->latency = latency;
-
- freerdp_android_at_set(audiotrack->out_handle,
- MUSIC,
- audiotrack->actual_rate,
- audiotrack->format,
- audiotrack->actual_channels == 2 ? CHANNEL_OUT_STEREO : CHANNEL_OUT_MONO);
-}
-
-static void rdpsnd_audiotrack_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, int latency)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
- int error;
-
- if (audiotrack->out_handle != 0)
- return;
-
- DEBUG_SVC("opening");
-
- error = freerdp_android_at_open(&audiotrack->out_handle);
-
- if (error < 0)
- {
- DEBUG_WARN("freerdp_android_at_open failed");
- }
- else
- {
- freerdp_dsp_context_reset_adpcm(audiotrack->dsp_context);
- rdpsnd_audiotrack_set_format(device, format, latency);
- }
-}
-
-static void rdpsnd_audiotrack_close(rdpsndDevicePlugin* device)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
-
- if (audiotrack->out_handle != 0)
- {
- DEBUG_SVC("close");
- freerdp_android_at_close(audiotrack->out_handle);
- audiotrack->out_handle = 0;
- }
-}
-
-static void rdpsnd_audiotrack_free(rdpsndDevicePlugin* device)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
-
- rdpsnd_audiotrack_close(device);
- freerdp_dsp_context_free(audiotrack->dsp_context);
- free(audiotrack);
-}
-
-static BOOL rdpsnd_audiotrack_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT* format)
-{
- switch (format->wFormatTag)
- {
- case 1: /* PCM */
- if (format->cbSize == 0 &&
- format->nSamplesPerSec <= 48000 &&
- (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
- (format->nChannels == 1 || format->nChannels == 2))
- {
- return TRUE;
- }
- break;
- case 2: /* MS ADPCM */
- case 0x11: /* IMA ADPCM */
- if (format->nSamplesPerSec <= 48000 &&
- format->wBitsPerSample == 4 &&
- (format->nChannels == 1 || format->nChannels == 2))
- {
- return TRUE;
- }
- break;
- }
- return FALSE;
-}
-
-static void rdpsnd_audiotrack_set_volume(rdpsndDevicePlugin* device, UINT32 value)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
- float left;
- float right;
-
- if (audiotrack->out_handle == 0)
- return;
-
- left = ((value & 0xFFFF) * 1.0) / 0xFFFF;
- right = (((value >> 16) & 0xFFFF) * 1.0) / 0xFFFF;
- freerdp_android_at_set_volume(audiotrack->out_handle, left, right);
-}
-
-static void rdpsnd_audiotrack_play(rdpsndDevicePlugin* device, BYTE* data, int size)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
- BYTE* src;
- int len;
- int error;
- int frames;
- int rbytes_per_frame;
- int sbytes_per_frame;
- BYTE* pindex;
- BYTE* end;
-
- if (audiotrack->out_handle == 0)
- return;
-
- if (audiotrack->wformat == 2)
- {
- audiotrack->dsp_context->decode_ms_adpcm(audiotrack->dsp_context,
- data, size, audiotrack->source_channels, audiotrack->block_size);
- size = audiotrack->dsp_context->adpcm_size;
- src = audiotrack->dsp_context->adpcm_buffer;
- }
- else if (audiotrack->wformat == 0x11)
- {
- audiotrack->dsp_context->decode_ima_adpcm(audiotrack->dsp_context,
- data, size, audiotrack->source_channels, audiotrack->block_size);
- size = audiotrack->dsp_context->adpcm_size;
- src = audiotrack->dsp_context->adpcm_buffer;
- }
- else
- {
- src = data;
- }
-
- sbytes_per_frame = audiotrack->source_channels * audiotrack->bytes_per_channel;
- rbytes_per_frame = audiotrack->actual_channels * audiotrack->bytes_per_channel;
- if ((size % sbytes_per_frame) != 0)
- {
- DEBUG_WARN("error len mod");
- return;
- }
-
- if ((audiotrack->source_rate == audiotrack->actual_rate) &&
- (audiotrack->source_channels == audiotrack->actual_channels))
- {
- }
- else
- {
- audiotrack->dsp_context->resample(audiotrack->dsp_context, src, audiotrack->bytes_per_channel,
- audiotrack->source_channels, audiotrack->source_rate, size / sbytes_per_frame,
- audiotrack->actual_channels, audiotrack->actual_rate);
- frames = audiotrack->dsp_context->resampled_frames;
- DEBUG_SVC("resampled %d frames at %d to %d frames at %d",
- size / sbytes_per_frame, audiotrack->source_rate, frames, audiotrack->actual_rate);
- size = frames * rbytes_per_frame;
- src = audiotrack->dsp_context->resampled_buffer;
- }
-
- pindex = src;
- end = pindex + size;
- while (pindex < end)
- {
- len = end - pindex;
-
- error = freerdp_android_at_write(audiotrack->out_handle, pindex, len);
- if (error < 0)
- {
- DEBUG_WARN("error %d", error);
- freerdp_android_at_close(audiotrack->out_handle);
- audiotrack->out_handle = 0;
- rdpsnd_audiotrack_open(device, NULL, audiotrack->latency);
- break;
- }
- pindex += error;
- }
-}
-
-static void rdpsnd_audiotrack_start(rdpsndDevicePlugin* device)
-{
- rdpsndAudioTrackPlugin* audiotrack = (rdpsndAudioTrackPlugin*)device;
-
- if (audiotrack->out_handle == 0)
- return;
-
- freerdp_android_at_start(audiotrack->out_handle);
-}
-
-#ifdef STATIC_CHANNELS
-#define freerdp_rdpsnd_client_subsystem_entry audiotrack_freerdp_rdpsnd_client_subsystem_entry
-#endif
-
-int freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)
-{
- rdpsndAudioTrackPlugin* audiotrack;
-
- freerdp_android_at_init_library();
- audiotrack = malloc(sizeof(rdpsndAudioTrackPlugin));
-
- audiotrack->device.Open = rdpsnd_audiotrack_open;
- audiotrack->device.FormatSupported = rdpsnd_audiotrack_format_supported;
- audiotrack->device.SetFormat = rdpsnd_audiotrack_set_format;
- audiotrack->device.SetVolume = rdpsnd_audiotrack_set_volume;
- audiotrack->device.Play = rdpsnd_audiotrack_play;
- audiotrack->device.Start = rdpsnd_audiotrack_start;
- audiotrack->device.Close = rdpsnd_audiotrack_close;
- audiotrack->device.Free = rdpsnd_audiotrack_free;
-
- audiotrack->out_handle = 0;
- audiotrack->source_rate = 22050;
- audiotrack->actual_rate = 22050;
- audiotrack->format = PCM_16_BIT;
- audiotrack->source_channels = 2;
- audiotrack->actual_channels = 2;
- audiotrack->bytes_per_channel = 2;
-
- audiotrack->dsp_context = freerdp_dsp_context_new();
-
- pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)audiotrack);
-
- return 0;
-}
-