1
0

main.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #define WIN32_LEAN_AND_MEAN
  2. #include "api.h"
  3. #include <bfc/platform/export.h>
  4. #include "../Agave/Component/ifc_wa5component.h"
  5. #include "../nu/Singleton.h"
  6. #include "mkv_vp8x_decoder.h"
  7. #include "nsv_vp8_decoder.h"
  8. api_service *WASABI_API_SVC=0;
  9. api_memmgr *WASABI_API_MEMMGR=0;
  10. class VP8XComponent : public ifc_wa5component
  11. {
  12. public:
  13. void RegisterServices(api_service *service);
  14. int RegisterServicesSafeModeOk();
  15. void DeregisterServices(api_service *service);
  16. protected:
  17. RECVS_DISPATCH;
  18. };
  19. template <class api_T>
  20. void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  21. {
  22. if (WASABI_API_SVC)
  23. {
  24. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  25. if (factory)
  26. api_t = reinterpret_cast<api_T *>( factory->getInterface() );
  27. }
  28. }
  29. template <class api_T>
  30. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  31. {
  32. if (WASABI_API_SVC && api_t)
  33. {
  34. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  35. if (factory)
  36. factory->releaseInterface(api_t);
  37. }
  38. api_t = NULL;
  39. }
  40. MKVDecoder mkv_decoder;
  41. static SingletonServiceFactory<svc_mkvdecoder, MKVDecoder> mkv_factory;
  42. static NSVFactory nsv_decoder;
  43. static SingletonServiceFactory<svc_nsvFactory, NSVFactory> nsv_factory;
  44. void VP8XComponent::RegisterServices(api_service *service)
  45. {
  46. WASABI_API_SVC = service;
  47. ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  48. mkv_factory.Register(WASABI_API_SVC, &mkv_decoder);
  49. nsv_factory.Register(WASABI_API_SVC, &nsv_decoder);
  50. }
  51. int VP8XComponent::RegisterServicesSafeModeOk()
  52. {
  53. return 1;
  54. }
  55. void VP8XComponent::DeregisterServices(api_service *service)
  56. {
  57. mkv_factory.Deregister(WASABI_API_SVC);
  58. nsv_factory.Deregister(WASABI_API_SVC);
  59. ServiceRelease(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  60. }
  61. static VP8XComponent component;
  62. extern "C" DLLEXPORT ifc_wa5component *GetWinamp5SystemComponent()
  63. {
  64. return &component;
  65. }
  66. #define CBCLASS VP8XComponent
  67. START_DISPATCH;
  68. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  69. CB(15, RegisterServicesSafeModeOk)
  70. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  71. END_DISPATCH;
  72. #undef CBCLASS