Home | History | Annotate | Download | only in preprocessing

Lines Matching full:session

50 // Session state
89 preproc_session_t *session; // session the effect is on
99 // Session context
101 struct preproc_effect_s effects[PREPROC_NUM_EFFECTS]; // effects in this session
103 int id; // audio session ID
104 int io; // handle of input stream this session is on
282 webrtc::GainControl *agc = effect->session->apm->gain_control();
445 webrtc::EchoControlMobile *aec = effect->session->apm->echo_control_mobile();
470 *(uint32_t *)pValue = 1000 * effect->session->apm->stream_delay_ms();
490 status = effect->session->apm->set_stream_delay_ms(value/1000);
573 effect->session->apm->SetExtraOptions(config);
576 effect->session->apm->SetExtraOptions(config);
583 webrtc::NoiseSuppression *ns = effect->session->apm->noise_suppression();
622 effect->session->apm->SetExtraOptions(config);
644 effect->session->apm->SetExtraOptions(config);
656 effect->session->apm->SetExtraOptions(config);
682 void Session_SetProcEnabled(preproc_session_t *session, uint32_t procId, bool enabled);
699 Session_SetProcEnabled(effect->session, effect->procId, false);
731 Session_SetProcEnabled(effect->session, effect->procId, false);
752 Session_SetProcEnabled(effect->session, effect->procId, true);
781 preproc_session_t *session,
784 effect->session = session;
796 // Session functions
804 int Session_Init(preproc_session_t *session)
809 session->state = PREPROC_SESSION_STATE_INIT;
810 session->id = 0;
811 session->io = 0;
812 session->createdMsk = 0;
813 session->apm = NULL;
815 status = Effect_Init(&session->effects[i], i);
821 extern "C" int Session_CreateEffect(preproc_session_t *session,
827 ALOGV("Session_CreateEffect procId %d, createdMsk %08x", procId, session->createdMsk);
829 if (session->createdMsk == 0) {
830 session->apm = webrtc::AudioProcessing::Create();
831 if (session->apm == NULL) {
840 session->apm->Initialize(processing_config);
841 session->procFrame = new webrtc::AudioFrame();
842 if (session->procFrame == NULL) {
846 session->revFrame = new webrtc::AudioFrame();
847 if (session->revFrame == NULL) {
851 session->apmSamplingRate = kPreprocDefaultSr;
852 session->apmFrameCount = (kPreprocDefaultSr) / 100;
853 session->frameCount = session->apmFrameCount;
854 session->samplingRate = kPreprocDefaultSr;
855 session->inChannelCount = kPreProcDefaultCnl;
856 session->outChannelCount = kPreProcDefaultCnl;
857 session->procFrame->sample_rate_hz_ = kPreprocDefaultSr;
858 session->procFrame->num_channels_ = kPreProcDefaultCnl;
859 session->revChannelCount = kPreProcDefaultCnl;
860 session->revFrame->sample_rate_hz_ = kPreprocDefaultSr;
861 session->revFrame->num_channels_ = kPreProcDefaultCnl;
862 session->enabledMsk = 0;
863 session->processedMsk = 0;
864 session->revEnabledMsk = 0;
865 session->revProcessedMsk = 0;
866 session->inResampler = NULL;
867 session->inBuf = NULL;
868 session->inBufSize = 0;
869 session->outResampler = NULL;
870 session->outBuf = NULL;
871 session->outBufSize = 0;
872 session->revResampler = NULL;
873 session->revBuf = NULL;
874 session->revBufSize = 0;
876 status = Effect_Create(&session->effects[procId], session, interface);
881 session->createdMsk |= (1<<procId);
885 if (session->createdMsk == 0) {
886 delete session->revFrame;
887 session->revFrame = NULL;
888 delete session->procFrame;
889 session->procFrame = NULL;
890 delete session->apm;
891 session->apm = NULL;
896 int Session_ReleaseEffect(preproc_session_t *session,
900 session->createdMsk &= ~(1<<fx->procId);
901 if (session->createdMsk == 0) {
902 delete session->apm;
903 session->apm = NULL;
904 delete session->procFrame;
905 session->procFrame = NULL;
906 delete session->revFrame;
907 session->revFrame = NULL;
908 if (session->inResampler != NULL) {
909 speex_resampler_destroy(session->inResampler);
910 session->inResampler = NULL;
912 if (session->outResampler != NULL) {
913 speex_resampler_destroy(session->outResampler);
914 session->outResampler = NULL;
916 if (session->revResampler != NULL) {
917 speex_resampler_destroy(session->revResampler);
918 session->revResampler = NULL;
920 delete session->inBuf;
921 session->inBuf = NULL;
922 delete session->outBuf;
923 session->outBuf = NULL;
924 delete session->revBuf;
925 session->revBuf = NULL;
927 session->io = 0;
934 int Session_SetConfig(preproc_session_t *session, effect_config_t *config)
951 if (config->inputCfg.samplingRate >= 32000 && !(session
952 session->apmSamplingRate = 32000;
955 session->apmSamplingRate = 16000;
957 session->apmSamplingRate = 8000;
961 {{static_cast<int>(session->apmSamplingRate), inCnl},
962 {static_cast<int>(session->apmSamplingRate), outCnl},
963 {static_cast<int>(session->apmSamplingRate), inCnl},
964 {static_cast<int>(session->apmSamplingRate), inCnl}}};
965 status = session->apm->Initialize(processing_config);
970 session->samplingRate = config->inputCfg.samplingRate;
971 session->apmFrameCount = session->apmSamplingRate / 100;
972 if (session->samplingRate == session->apmSamplingRate) {
973 session->frameCount = session->apmFrameCount;
975 session->frameCount = (session->apmFrameCount * session->samplingRate) /
976 session->apmSamplingRate + 1;
978 session->inChannelCount = inCnl;
979 session->outChannelCount = outCnl;
980 session->procFrame->num_channels_ = inCnl;
981 session->procFrame->sample_rate_hz_ = session->apmSamplingRate;
983 session->revChannelCount = inCnl;
984 session->revFrame->num_channels_ = inCnl;
985 session->revFrame->sample_rate_hz_ = session->apmSamplingRate;
988 session->inBufSize = 0;
989 session->outBufSize = 0;
990 session->framesIn = 0;
991 session->framesOut = 0;
994 if (session->inResampler != NULL) {
995 speex_resampler_destroy(session->inResampler);
996 session->inResampler = NULL;
998 if (session->outResampler != NULL) {
999 speex_resampler_destroy(session->outResampler);
1000 session->outResampler = NULL;
1002 if (session->revResampler != NULL) {
1003 speex_resampler_destroy(session->revResampler);
1004 session->revResampler = NULL;
1006 if (session->samplingRate != session->apmSamplingRate) {
1008 session->inResampler = speex_resampler_init(session->inChannelCount,
1009 session->samplingRate,
1010 session->apmSamplingRate,
1013 if (session->inResampler == NULL) {
1018 session->outResampler = speex_resampler_init(session->outChannelCount,
1019 session->apmSamplingRate,
1020 session->samplingRate,
1023 if (session->outResampler == NULL) {
1026 speex_resampler_destroy(session->inResampler);
1027 session->inResampler = NULL;
1030 session->revResampler = speex_resampler_init(session->inChannelCount,
1031 session->samplingRate,
1032 session->apmSamplingRate,
1035 if (session->revResampler == NULL) {
1038 speex_resampler_destroy(session->inResampler);
1039 session->inResampler = NULL;
1040 speex_resampler_destroy(session->outResampler);
1041 session->outResampler = NULL;
1046 session->state = PREPROC_SESSION_STATE_CONFIG;
1050 void Session_GetConfig(preproc_session_t *session, effect_config_t *config)
1053 config->inputCfg.samplingRate = config->outputCfg.samplingRate = session->samplingRate;
1055 config->inputCfg.channels = audio_channel_in_mask_from_count(session->inChannelCount);
1057 config->outputCfg.channels = audio_channel_in_mask_from_count(session->outChannelCount);
1062 int Session_SetReverseConfig(preproc_session_t *session, effect_config_t *config)
1073 if (session->state < PREPROC_SESSION_STATE_CONFIG) {
1076 if (config->inputCfg.samplingRate != session->samplingRate ||
1082 {{static_cast<int>(session->apmSamplingRate), session->inChannelCount},
1083 {static_cast<int>(session->apmSamplingRate), session->outChannelCount},
1084 {static_cast<int>(session->apmSamplingRate), inCnl},
1085 {static_cast<int>(session->apmSamplingRate), inCnl}}};
1086 int status = session->apm->Initialize(processing_config);
1090 session->revChannelCount = inCnl;
1091 session->revFrame->num_channels_ = inCnl;
1092 session->revFrame->sample_rate_hz_ = session->apmSamplingRate;
1094 session->revBufSize = 0;
1095 session->framesRev = 0;
1100 void Session_GetReverseConfig(preproc_session_t *session, effect_config_t *config)
1103 config->inputCfg.samplingRate = config->outputCfg.samplingRate = session->samplingRate;
1106 audio_channel_in_mask_from_count(session->revChannelCount);
1111 void Session_SetProcEnabled(preproc_session_t *session, uint32_t procId, bool enabled)
1114 if(session->enabledMsk == 0) {
1115 session->framesIn = 0;
1116 if (session->inResampler != NULL) {
1117 speex_resampler_reset_mem(session->inResampler);
1119 session->framesOut = 0;
1120 if (session->outResampler != NULL) {
1121 speex_resampler_reset_mem(session->outResampler);
1124 session->enabledMsk |= (1 << procId);
1126 session->framesRev = 0;
1127 if (session->revResampler != NULL) {
1128 speex_resampler_reset_mem(session->revResampler);
1130 session->revEnabledMsk |= (1 << procId);
1133 session->enabledMsk &= ~(1 << procId);
1135 session->revEnabledMsk &= ~(1 << procId);
1139 procId, enabled, session->enabledMsk, session->revEnabledMsk);
1140 session->processedMsk = 0;
1142 session->revProcessedMsk = 0;
1219 preproc_session_t * session = (preproc_session_t *)effect->session;
1227 session->processedMsk |= (1<<effect->procId);
1230 // inBuffer->frameCount, session->enabledMsk, session->processedMsk);
1232 if ((session->processedMsk & session->enabledMsk) == session->enabledMsk) {
1233 effect->session->processedMsk = 0;
1236 if (session->framesOut) {
1237 size_t fr = session->framesOut;
1242 session->outBuf,
1243 fr * session->outChannelCount * sizeof(int16_t));
1244 memcpy(session->outBuf,
1245 session->outBuf + fr * session->outChannelCount,
1246 (session->framesOut - fr) * session->outChannelCount * sizeof(int16_t));
1247 session->framesOut -= fr;
1256 if (session->inResampler != NULL) {
1257 size_t fr = session->frameCount - session->framesIn;
1261 if (session->inBufSize < session->framesIn + fr) {
1263 session->inBufSize = session->framesIn + fr;
1264 buf = (int16_t *)realloc(session->inBuf,
1265 session->inBufSize * session->inChannelCount * sizeof(int16_t));
1267 session->framesIn = 0;
1268 free(session->inBuf);
1269 session->inBuf = NULL;
1272 session->inBuf = buf;
1274 memcpy(session->inBuf + session->framesIn * session->inChannelCount,
1276 fr * session->inChannelCount * sizeof(int16_t));
1281 fr * session->inChannelCount * sizeof(int16_t), 1, gPcmDumpFh);
1286 session->framesIn += fr;
1288 if (session->framesIn < session->frameCount) {
1291 spx_uint32_t frIn = session->framesIn;
1292 spx_uint32_t frOut = session->apmFrameCount;
1293 if (session->inChannelCount == 1) {
1294 speex_resampler_process_int(session->inResampler,
1296 session->inBuf,
1298 session->procFrame->data_,
1301 speex_resampler_process_interleaved_int(session->inResampler,
1302 session->inBuf,
1304 session->procFrame->data_,
1307 memcpy(session->inBuf,
1308 session->inBuf + frIn * session->inChannelCount,
1309 (session->framesIn - frIn) * session->inChannelCount * sizeof(int16_t));
1310 session->framesIn -= frIn;
1312 size_t fr = session->frameCount - session->framesIn;
1316 memcpy(session->procFrame->data_ + session->framesIn * session->inChannelCount,
1318 fr * session->inChannelCount * sizeof(int16_t));
1324 fr * session->inChannelCount * sizeof(int16_t), 1, gPcmDumpFh);
1329 session->framesIn += fr;
1331 if (session->framesIn < session->frameCount) {
1334 session->framesIn = 0;
1336 session->procFrame->samples_per_channel_ = session->apmFrameCount;
1338 effect->session->apm->ProcessStream(session->procFrame);
1340 if (session->outBufSize < session->framesOut + session->frameCount) {
1342 session->outBufSize = session->framesOut + session->frameCount;
1343 buf = (int16_t *)realloc(session->outBuf,
1344 session->outBufSize * session->outChannelCount * sizeof(int16_t));
1346 session->framesOut = 0;
1347 free(session->outBuf);
1348 session->outBuf = NULL;
1351 session->outBuf = buf;
1354 if (session->outResampler != NULL) {
1355 spx_uint32_t frIn = session->apmFrameCount;
1356 spx_uint32_t frOut = session->frameCount;
1357 if (session->inChannelCount == 1) {
1358 speex_resampler_process_int(session->outResampler,
1360 session->procFrame->data_,
1362 session->outBuf + sessionsession->outChannelCount,
1365 speex_resampler_process_interleaved_int(session->outResampler,
1366 session->procFrame->data_,
1368 session->outBuf + session->framesOut * session->outChannelCount,
1371 session->framesOut += frOut;
1373 memcpy(session->outBuf + session->framesOut * session->outChannelCount,
1374 session->procFrame->data_,
1375 session->frameCount * session->outChannelCount * sizeof(int16_t));
1376 session->framesOut += session->frameCount;
1378 size_t fr = session->framesOut;
1382 memcpy(outBuffer->s16 + framesWr * session->outChannelCount,
1383 session->outBuf,
1384 fr * session->outChannelCount * sizeof(int16_t));
1385 memcpy(session->outBuf,
1386 session->outBuf + fr * session->outChannelCount,
1387 (session->framesOut - fr) * session->outChannelCount * sizeof(int16_t));
1388 session->framesOut -= fr;
1437 uint32_t enabledMsk = effect->session->enabledMsk;
1439 effect->session->enabledMsk = 0;
1442 *(int *)pReplyData = Session_SetConfig(effect->session, (effect_config_t *)pCmdData);
1445 effect->session->enabledMsk = enabledMsk;
1464 Session_GetConfig(effect->session, (effect_config_t *)pReplyData);
1476 *(int *)pReplyData = Session_SetReverseConfig(effect->session,
1490 Session_GetReverseConfig(effect->session, (effect_config_t *)pCmdData);
1597 effect->cur_channel_config = (effect->session->inChannelCount == 1) ?
1786 preproc_session_t * session = (preproc_session_t *)effect->session;
1793 session->revProcessedMsk |= (1<<effect->procId);
1796 // inBuffer->frameCount, session->revEnabledMsk, session->revProcessedMsk);
1799 if ((session->revProcessedMsk & session->revEnabledMsk) == session->revEnabledMsk) {
1800 effect->session->revProcessedMsk = 0;
1801 if (session->revResampler != NULL) {
1802 size_t fr = session->frameCount - session->framesRev;
1806 if (session->revBufSize < session->framesRev + fr) {
1808 session->revBufSize = session->framesRev + fr;
1809 buf = (int16_t *)realloc(session->revBuf,
1810 session->revBufSize * session->inChannelCount * sizeof(int16_t));
1812 session->framesRev = 0;
1813 free(session->revBuf);
1814 session->revBuf = NULL;
1817 session->revBuf = buf;
1819 memcpy(session->revBuf + session->framesRev * session->inChannelCount,
1821 fr * session->inChannelCount * sizeof(int16_t));
1823 session->framesRev += fr;
1825 if (session->framesRev < session->frameCount) {
1828 spx_uint32_t frIn = session->framesRev;
1829 spx_uint32_t frOut = session->apmFrameCount;
1830 if (session->inChannelCount == 1) {
1831 speex_resampler_process_int(session->revResampler,
1833 session->revBuf,
1835 session->revFrame->data_,
1838 speex_resampler_process_interleaved_int(session->revResampler,
1839 session->revBuf,
1841 session->revFrame->data_,
1844 memcpy(session->revBuf,
1845 session->revBuf + frIn * session->inChannelCount,
1846 (session->framesRev - frIn) * session->inChannelCount * sizeof(int16_t));
1847 session->framesRev -= frIn;
1849 size_t fr = session->frameCount - session->framesRev;
1853 memcpy(session->revFrame->data_ + session->framesRev * session->inChannelCount,
1855 fr * session->inChannelCount * sizeof(int16_t));
1856 session->framesRev += fr;
1858 if (session->framesRev < session->frameCount) {
1861 session->framesRev = 0;
1863 session->revFrame->samples_per_channel_ = session->apmFrameCount;
1864 effect->session->apm->AnalyzeReverseStream(session->revFrame);
1896 ALOGV("EffectCreate: uuid: %08x session %d IO: %d", uuid->timeLow, sessionId, ioId);
1900 preproc_session_t *session;
1913 session = PreProc_GetSession(procId, sessionId, ioId);
1914 if (session == NULL) {
1915 ALOGW("EffectCreate: no more session available");
1919 status = Session_CreateEffect(session, procId, pInterface);
1921 if (status < 0 && session->createdMsk == 0) {
1922 session->io = 0;
1937 if (fx->session->io == 0) {
1940 return Session_ReleaseEffect(fx->session, fx);