| 1 | // |
| 2 | // libtgvoip is free and unencumbered public domain software. |
| 3 | // For more information, see http://unlicense.org or the UNLICENSE file |
| 4 | // you should have received with this source code distribution. |
| 5 | // |
| 6 | |
| 7 | #include <cstddef> |
| 8 | #include "OpenSLEngineWrapper.h" |
| 9 | #include "../../logging.h" |
| 10 | |
| 11 | #define CHECK_SL_ERROR(res, msg) if(res!=SL_RESULT_SUCCESS){ LOGE(msg); return NULL; } |
| 12 | |
| 13 | using namespace tgvoip; |
| 14 | using namespace tgvoip::audio; |
| 15 | |
| 16 | |
| 17 | SLObjectItf OpenSLEngineWrapper::sharedEngineObj=NULL; |
| 18 | SLEngineItf OpenSLEngineWrapper::sharedEngine=NULL; |
| 19 | int OpenSLEngineWrapper::count=0; |
| 20 | |
| 21 | void OpenSLEngineWrapper::DestroyEngine(){ |
| 22 | count--; |
| 23 | LOGI("release: engine instance count %d", count); |
| 24 | if(count==0){ |
| 25 | (*sharedEngineObj)->Destroy(sharedEngineObj); |
| 26 | sharedEngineObj=NULL; |
| 27 | sharedEngine=NULL; |
| 28 | } |
| 29 | LOGI("after release"); |
| 30 | } |
| 31 | |
| 32 | SLEngineItf OpenSLEngineWrapper::CreateEngine(){ |
| 33 | count++; |
| 34 | if(sharedEngine) |
| 35 | return sharedEngine; |
| 36 | const SLInterfaceID pIDs[1] = {SL_IID_ENGINE}; |
| 37 | const SLboolean pIDsRequired[1] = {SL_BOOLEAN_TRUE}; |
| 38 | SLresult result = slCreateEngine(&sharedEngineObj, 0, NULL, 1, pIDs, pIDsRequired); |
| 39 | CHECK_SL_ERROR(result, "Error creating engine"); |
| 40 | |
| 41 | result=(*sharedEngineObj)->Realize(sharedEngineObj, SL_BOOLEAN_FALSE); |
| 42 | CHECK_SL_ERROR(result, "Error realizing engine"); |
| 43 | |
| 44 | result = (*sharedEngineObj)->GetInterface(sharedEngineObj, SL_IID_ENGINE, &sharedEngine); |
| 45 | CHECK_SL_ERROR(result, "Error getting engine interface"); |
| 46 | return sharedEngine; |
| 47 | } |
| 48 | |
| 49 | |