Commit 9268b772 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added a way to store and use the stream type in soundcard

parent eeac0168
......@@ -123,6 +123,22 @@ struct _MSSndCardDesc{
*/
typedef struct _MSSndCardDesc MSSndCardDesc;
/**
* Structure for sound card object.
* @var MSSndCard
*/
typedef struct _MSSndCard MSSndCard;
enum _MSSndCardStreamType{
MS_SND_CARD_STREAM_VOICE,
MS_SND_CARD_STREAM_RING
};
/**
* Structure for sound card stream type.
*/
typedef enum _MSSndCardStreamType MSSndCardStreamType;
#define MS_SND_CARD_CAP_DISABLED (0) /**<This soundcard is disabled.*/
#define MS_SND_CARD_CAP_CAPTURE (1) /**<This sound card can capture sound */
#define MS_SND_CARD_CAP_PLAYBACK (1<<1) /**<This sound card can playback sound */
......@@ -138,14 +154,9 @@ struct _MSSndCard{
void *data;
int preferred_sample_rate;
int latency;
MSSndCardStreamType streamType;
};
/**
* Structure for sound card object.
* @var MSSndCard
*/
typedef struct _MSSndCard MSSndCard;
#ifdef __cplusplus
extern "C"{
#endif
......@@ -519,6 +530,16 @@ MS2_PUBLIC int ms_snd_card_set_preferred_sample_rate(MSSndCard *obj,int rate);
**/
MS2_PUBLIC void ms_snd_card_set_usage_hint(MSSndCard *obj, bool_t is_going_to_be_used);
/**
* Sets the stream type for this soundcard, default is VOICE
**/
MS2_PUBLIC void ms_snd_card_set_stream_type(MSSndCard *obj, MSSndCardStreamType type);
/**
* Gets the stream type for this soundcard, default is VOICE
**/
MS2_PUBLIC MSSndCardStreamType ms_snd_card_get_stream_type(MSSndCard *obj);
/**
* Create a alsa card with user supplied pcm name and mixer name.
* @param pcmdev The pcm device name following alsa conventions (ex: plughw:0)
......
......@@ -184,12 +184,20 @@ struct AndroidSndWriteData{
ms_mutex_destroy(&mutex);
ms_bufferizer_uninit(&bf);
}
void updateStreamTypeFromMsSndCard() {
MSSndCardStreamType type = ms_snd_card_get_stream_type(soundCard);
stype = AUDIO_STREAM_VOICE_CALL;
if (type == MS_SND_CARD_STREAM_RING) {
stype = AUDIO_STREAM_RING;
}
}
void setCard(AndroidNativeSndCardData *card){
mCard=card;
#ifdef NATIVE_USE_HARDWARE_RATE
rate=card->mPlayRate;
#endif
}
MSSndCard *soundCard;
AndroidNativeSndCardData *mCard;
audio_stream_type_t stype;
int rate;
......@@ -213,6 +221,7 @@ static MSFilter *android_snd_card_create_reader(MSSndCard *card){
static MSFilter *android_snd_card_create_writer(MSSndCard *card){
MSFilter *f=ms_android_snd_write_new(ms_snd_card_get_factory(card));
(static_cast<AndroidSndWriteData*>(f->data))->setCard((AndroidNativeSndCardData*)card->data);
(static_cast<AndroidSndWriteData*>(f->data))->soundCard = card;
return f;
}
......@@ -706,6 +715,7 @@ static void android_snd_write_preprocess(MSFilter *obj){
ad->mCard->enableVoipMode();
ad->nFramesRequested=0;
ad->updateStreamTypeFromMsSndCard();
if (AudioTrack::getMinFrameCount(&play_buf_size,ad->stype,ad->rate)==0){
ms_message("AudioTrack: min frame count is %i",play_buf_size);
}else{
......
......@@ -159,6 +159,14 @@ struct OpenSLESOutputContext {
ms_flow_controlled_bufferizer_set_flow_control_interval_ms(&buffer, flowControlIntervalMs);
}
void updateStreamTypeFromMsSndCard() {
MSSndCardStreamType type = ms_snd_card_get_stream_type(soundCard);
streamType = SL_ANDROID_STREAM_VOICE;
if (type == MS_SND_CARD_STREAM_RING) {
streamType = SL_ANDROID_STREAM_RING;
}
}
OpenSLESContext *opensles_context;
SLObjectItf outputMixObject;
......@@ -168,6 +176,7 @@ struct OpenSLESOutputContext {
SLAndroidConfigurationItf playerConfig;
SLint32 streamType;
MSSndCard *soundCard;
MSFilter *filter;
MSFlowControlledBufferizer buffer;
int nbufs;
......@@ -738,6 +747,7 @@ static SLresult opensles_sink_init(OpenSLESOutputContext *octx) {
return result;
}
octx->updateStreamTypeFromMsSndCard();
result = (*octx->playerConfig)->SetConfiguration(octx->playerConfig, SL_ANDROID_KEY_STREAM_TYPE, &octx->streamType, sizeof(SLint32));
if (result != SL_RESULT_SUCCESS) {
ms_error("OpenSLES Error %u while setting stream type configuration", result);
......@@ -841,6 +851,7 @@ static SLresult opensles_player_callback_init(OpenSLESOutputContext *octx) {
static MSFilter *android_snd_card_create_writer(MSSndCard *card) {
MSFilter *f = ms_android_snd_write_new(ms_snd_card_get_factory(card));
OpenSLESOutputContext *octx = static_cast<OpenSLESOutputContext*>(f->data);
octx->soundCard = card;
octx->setContext((OpenSLESContext*)card->data);
return f;
}
......
......@@ -174,6 +174,7 @@ MSSndCard * ms_snd_card_new_with_name(MSSndCardDesc *desc,const char* name) {
obj->data=NULL;
obj->id=NULL;
obj->capabilities=MS_SND_CARD_CAP_CAPTURE|MS_SND_CARD_CAP_PLAYBACK;
obj->streamType=MS_SND_CARD_STREAM_VOICE;
if (desc->init!=NULL)
desc->init(obj);
return obj;
......@@ -276,6 +277,14 @@ int ms_snd_card_set_preferred_sample_rate(MSSndCard *obj,int rate) {
return 0;
}
void ms_snd_card_set_stream_type(MSSndCard *obj, MSSndCardStreamType type) {
obj->streamType = type;
}
MSSndCardStreamType ms_snd_card_get_stream_type(MSSndCard *obj) {
return obj->streamType;
}
#ifdef __linux
#ifndef __ALSA_ENABLED__
MSSndCard * ms_alsa_card_new_custom(const char *pcmdev, const char *mixdev){
......
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