Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / channels / drdynvc / tsmf / tsmf_audio.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol client.
3  * Video Redirection Virtual Channel - Audio Device Manager
4  *
5  * Copyright 2010-2011 Vic Lee
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <freerdp/utils/memory.h>
24 #include <freerdp/utils/load_plugin.h>
25
26 #include "tsmf_audio.h"
27
28 static ITSMFAudioDevice* tsmf_load_audio_device_by_name(const char* name, const char* device)
29 {
30         ITSMFAudioDevice* audio;
31         TSMF_AUDIO_DEVICE_ENTRY entry;
32         char* fullname;
33
34         if (strrchr(name, '.') != NULL)
35                 entry = (TSMF_AUDIO_DEVICE_ENTRY) freerdp_load_plugin(name, TSMF_AUDIO_DEVICE_EXPORT_FUNC_NAME);
36         else
37         {
38                 fullname = xzalloc(strlen(name) + 6);
39                 strcpy(fullname, "tsmf_");
40                 strcat(fullname, name);
41                 entry = (TSMF_AUDIO_DEVICE_ENTRY) freerdp_load_plugin(fullname, TSMF_AUDIO_DEVICE_EXPORT_FUNC_NAME);
42                 xfree(fullname);
43         }
44         if (entry == NULL)
45         {
46                 return NULL;
47         }
48
49         audio = entry();
50         if (audio == NULL)
51         {
52                 DEBUG_WARN("failed to call export function in %s", name);
53                 return NULL;
54         }
55         if (!audio->Open(audio, device))
56         {
57                 audio->Free(audio);
58                 audio = NULL;
59         }
60         return audio;
61 }
62
63 ITSMFAudioDevice* tsmf_load_audio_device(const char* name, const char* device)
64 {
65         ITSMFAudioDevice* audio;
66
67         if (name)
68         {
69                 audio = tsmf_load_audio_device_by_name(name, device);
70         }
71         else
72         {
73                 audio = tsmf_load_audio_device_by_name("pulse", device);
74                 if (!audio)
75                         audio = tsmf_load_audio_device_by_name("alsa", device);
76         }
77
78         return audio;
79 }
80