OpenSLEngineWrapper.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <cstddef>
  7. #include "OpenSLEngineWrapper.h"
  8. #include "../../logging.h"
  9. #define CHECK_SL_ERROR(res, msg) if(res!=SL_RESULT_SUCCESS){ LOGE(msg); return NULL; }
  10. using namespace tgvoip;
  11. using namespace tgvoip::audio;
  12. SLObjectItf OpenSLEngineWrapper::sharedEngineObj=NULL;
  13. SLEngineItf OpenSLEngineWrapper::sharedEngine=NULL;
  14. int OpenSLEngineWrapper::count=0;
  15. void OpenSLEngineWrapper::DestroyEngine(){
  16. count--;
  17. LOGI("release: engine instance count %d", count);
  18. if(count==0){
  19. (*sharedEngineObj)->Destroy(sharedEngineObj);
  20. sharedEngineObj=NULL;
  21. sharedEngine=NULL;
  22. }
  23. LOGI("after release");
  24. }
  25. SLEngineItf OpenSLEngineWrapper::CreateEngine(){
  26. count++;
  27. if(sharedEngine)
  28. return sharedEngine;
  29. const SLInterfaceID pIDs[1] = {SL_IID_ENGINE};
  30. const SLboolean pIDsRequired[1] = {SL_BOOLEAN_TRUE};
  31. SLresult result = slCreateEngine(&sharedEngineObj, 0, NULL, 1, pIDs, pIDsRequired);
  32. CHECK_SL_ERROR(result, "Error creating engine");
  33. result=(*sharedEngineObj)->Realize(sharedEngineObj, SL_BOOLEAN_FALSE);
  34. CHECK_SL_ERROR(result, "Error realizing engine");
  35. result = (*sharedEngineObj)->GetInterface(sharedEngineObj, SL_IID_ENGINE, &sharedEngine);
  36. CHECK_SL_ERROR(result, "Error getting engine interface");
  37. return sharedEngine;
  38. }