Commit 50e226c6 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Update qsa soundcard and mediastream api to be able to control audio output...

Update qsa soundcard and mediastream api to be able to control audio output device in the playback filter
parent 998cdbcc
......@@ -207,6 +207,7 @@ if(ENABLE_PULSEAUDIO)
endif()
if(ENABLE_QSA)
find_package(QSA REQUIRED)
find_package(QnxAudioManager REQUIRED)
endif()
if(ENABLE_VIDEO)
add_definitions(-DVIDEO_ENABLED)
......@@ -252,7 +253,6 @@ if(ENABLE_VPX)
set(ENABLE_VPX OFF CACHE BOOL "Build mediastreamer2 with VPX codec." FORCE)
endif()
endif()
<<<<<<< HEAD
if(ENABLE_MKV)
find_package(Matroska2)
if(NOT MATROSKA2_FOUND)
......@@ -260,7 +260,6 @@ if(ENABLE_MKV)
endif()
endif()
=======
if (ENABLE_QNX)
find_package(Screen)
if(NOT SCREEN_FOUND)
......@@ -271,7 +270,6 @@ if (ENABLE_QNX)
message(FATAL_ERROR "CAMAPI NOT FOUND")
endif()
endif()
>>>>>>> dev_bb10
if(ENABLE_SOUND AND NOT(WIN32 OR ENABLE_ALSA OR ENABLE_ARTSC OR ENABLE_MACSND OR ENABLE_MACAQSND OR ENABLE_OSS OR ENABLE_PORTAUDIO OR ENABLE_PULSEAUDIO OR ENABLE_QSA))
message(FATAL_ERROR "Could not find a support sound driver API. Use -DENABLE_SOUND=NO if you don't care about having sound.")
......@@ -324,6 +322,9 @@ endif()
if(QSA_FOUND)
include_directories(${QSA_INCLUDE_DIRS})
endif()
if(QNXAUDIOMANAGER_FOUND)
include_directories(${QNXAUDIOMANAGER_INCLUDE_DIRS})
endif()
if(FFMPEG_FOUND)
include_directories(${FFMPEG_INCLUDE_DIRS})
endif()
......
############################################################################
# FindQnxAudioManager.txt
# Copyright (C) 2015 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
############################################################################
#
# - Find the Qnx AudioManager include file and library
#
# QNXAUDIOMANAGER_FOUND - system has QNX Audio Manager
# QNXAUDIOMANAGER_INCLUDE_DIRS - the Audio Manager include directory
# QNXAUDIOMANAGER_LIBRARIES - The libraries needed to use Audio Manager
include(CheckSymbolExists)
include(CMakePushCheckState)
set(_QNXAUDIOMANAGER_ROOT_PATHS
${CMAKE_INSTALL_PREFIX}
)
find_path(QNXAUDIOMANAGER_INCLUDE_DIRS
NAMES audio/audio_manager_routing.h
HINTS _QNXAUDIOMANAGER_ROOT_PATHS
PATH_SUFFIXES include
)
if(QNXAUDIOMANAGER_INCLUDE_DIRS)
set(HAVE_QNX_AUDIOMANAGER_H 1)
endif()
find_library(QNXAUDIOMANAGER_LIBRARIES
NAMES audio_manager
HINTS _QNXAUDIOMANAGER_ROOT_PATHS
PATH_SUFFIXES bin lib
)
if(QNXAUDIOMANAGER_LIBRARIES)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${QNXAUDIOMANAGER_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${QNXAUDIOMANAGER_LIBRARIES})
check_symbol_exists(audio_manager_snd_pcm_open_name "audio/audio_manager_routing.h" HAVE_AUDIO_MANAGER_SND_PCM_OPEN)
cmake_pop_check_state()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(QNXAUDIOMANAGER
DEFAULT_MSG
QNXAUDIOMANAGER_INCLUDE_DIRS QNXAUDIOMANAGER_LIBRARIES HAVE_QNX_AUDIOMANAGER_H HAVE_AUDIO_MANAGER_SND_PCM_OPEN
)
mark_as_advanced(QNXAUDIOMANAGER_INCLUDE_DIRS QNXAUDIOMANAGER_LIBRARIES HAVE_QNX_AUDIOMANAGER_H HAVE_AUDIO_MANAGER_SND_PCM_OPEN)
......@@ -1156,6 +1156,13 @@ MS2_PUBLIC MSWebCamDesc *ms_mire_webcam_desc_get(void);
*/
MS2_PUBLIC RtpSession * ms_create_duplex_rtp_session(const char* local_ip, int loc_rtp_port, int loc_rtcp_port);
/**
* Asks the audio playback filter to route to the selected device
* @param[in] stream The AudioStream object
* @param[in] route The wanted audio output device (earpiece, speaker)
*/
MS2_PUBLIC void audio_stream_set_audio_route(AudioStream *stream, MSAudioRoute route);
/**
* @}
**/
......
......@@ -279,10 +279,18 @@ typedef enum _MSRecorderState MSRecorderState;
MS_FILTER_METHOD(MSFilterAudioCaptureInterface, 255, bool_t)
/** Interface definitions for audio playback */
enum _MSAudioRoute{
MSAudioRouteEarpiece,
MSAudioRouteSpeaker
};
typedef enum _MSAudioRoute MSAudioRoute;
#define MS_AUDIO_PLAYBACK_SET_VOLUME_GAIN \
MS_FILTER_METHOD(MSFilterAudioPlaybackInterface, 0, float)
#define MS_AUDIO_PLAYBACK_GET_VOLUME_GAIN \
MS_FILTER_METHOD(MSFilterAudioPlaybackInterface, 1, float)
#define MS_AUDIO_PLAYBACK_SET_ROUTE \
MS_FILTER_METHOD(MSFilterAudioPlaybackInterface, 2, MSAudioRoute)
/** Interface definitions for audio encoder */
#define MS_AUDIO_ENCODER_SET_PTIME \
......
......@@ -402,6 +402,7 @@ if(PULSEAUDIO_FOUND)
endif()
if(QSA_FOUND)
list(APPEND VOIP_LIBS ${QSA_LIBRARIES})
list(APPEND VOIP_LIBS ${QNXAUDIOMANAGER_LIBRARIES})
endif()
if(FFMPEG_FOUND)
list(APPEND VOIP_LIBS ${FFMPEG_LIBRARIES})
......
......@@ -23,6 +23,7 @@
#endif
#include <errno.h>
#include <audio/audio_manager_routing.h>
#include <sys/asoundlib.h>
#include <sys/select.h>
#include <sys/time.h>
......@@ -367,6 +368,7 @@ typedef struct _MSQSAWriteData {
int rate;
int nchannels;
bool_t initialized;
unsigned int *audioman_handle;
} MSQSAWriteData;
static int ms_qsa_write_set_sample_rate(MSFilter *f, void *arg);
......@@ -384,7 +386,7 @@ static MSFilter * ms_qsa_write_new(MSSndCard *card) {
d->pcmdev = ms_strdup(card->name);
err = snd_pcm_open_name(&handle, d->pcmdev, SND_PCM_OPEN_PLAYBACK | SND_PCM_OPEN_NONBLOCK);
if (err != 0) {
ms_error("%s: snd_pcm_open_preferred() failed: %s", __FUNCTION__, snd_strerror(err));
ms_error("%s: audio_manager_snd_pcm_open_name() failed: %s", __FUNCTION__, snd_strerror(err));
} else {
memset(&d->info, 0, sizeof(d->info));
d->info.channel = SND_PCM_CHANNEL_PLAYBACK;
......@@ -425,9 +427,9 @@ static void ms_qsa_write_process(MSFilter *f) {
if (d->initialized != TRUE) goto setup_failure;
if ((d->handle == NULL) && (d->pcmdev != NULL)) {
err = snd_pcm_open_name(&d->handle, d->pcmdev, SND_PCM_OPEN_PLAYBACK);
err = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, &d->handle, &d->audioman_handle, d->pcmdev, SND_PCM_OPEN_PLAYBACK);
if (err != 0) {
ms_error("%s: snd_pcm_open_name(%s) failed: %s", __FUNCTION__, d->pcmdev, snd_strerror(err));
ms_error("%s: audio_manager_snd_pcm_open_name(%s) failed: %s", __FUNCTION__, d->pcmdev, snd_strerror(err));
goto setup_failure;
}
err = snd_pcm_info(d->handle, &info);
......@@ -580,6 +582,9 @@ static void ms_qsa_write_postprocess(MSFilter *f) {
snd_pcm_close(d->handle);
d->handle = NULL;
}
if (d->audioman_handle != NULL) {
d->audioman_handle = NULL;
}
}
static void ms_qsa_write_uninit(MSFilter *f) {
......@@ -632,12 +637,35 @@ static int ms_qsa_write_get_nchannels(MSFilter *f, void *arg) {
return 0;
}
static int ms_qsa_write_set_route(MSFilter *f, void *arg) {
MSQSAWriteData *d = (MSQSAWriteData *)f->data;
MSAudioRoute audio_route = *((MSAudioRoute *)arg);
int err;
if (d->audioman_handle) {
audio_manager_device_t output_device = AUDIO_DEVICE_DEFAULT;
if (audio_route == MSAudioRouteSpeaker) {
output_device = AUDIO_DEVICE_SPEAKER;
}
err = audio_manager_set_handle_type(d->audioman_handle, AUDIO_TYPE_VOICE, output_device, AUDIO_DEVICE_UNCHANGED);
if (err != 0) {
ms_error("%s: audio_manager_set_handle_type(%i) failed: %s", __FUNCTION__, output_device, snd_strerror(err));
return -1;
}
return 0;
}
return -1;
}
static MSFilterMethod ms_qsa_write_methods[] = {
{ MS_FILTER_SET_SAMPLE_RATE, ms_qsa_write_set_sample_rate },
{ MS_FILTER_GET_SAMPLE_RATE, ms_qsa_write_get_sample_rate },
{ MS_FILTER_GET_NCHANNELS, ms_qsa_write_get_nchannels },
{ MS_FILTER_SET_NCHANNELS, ms_qsa_write_set_nchannels },
{ 0, NULL }
{ MS_FILTER_SET_SAMPLE_RATE, ms_qsa_write_set_sample_rate },
{ MS_FILTER_GET_SAMPLE_RATE, ms_qsa_write_get_sample_rate },
{ MS_FILTER_GET_NCHANNELS, ms_qsa_write_get_nchannels },
{ MS_FILTER_SET_NCHANNELS, ms_qsa_write_set_nchannels },
{ MS_AUDIO_PLAYBACK_SET_ROUTE, ms_qsa_write_set_route };
{ 0, NULL }
};
......
......@@ -1701,5 +1701,11 @@ void audio_stream_unlink_video(AudioStream *stream, VideoStream *video){
}
}
void audio_stream_set_audio_route(AudioStream *stream, MSAudioRoute route) {
if (stream->soundwrite) {
if (ms_filter_implements_interface(stream->soundwrite, MSFilterAudioPlaybackInterface)) {
ms_filter_call_method(stream->soundwrite, MS_AUDIO_PLAYBACK_SET_ROUTE, &route);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment