1
0

main.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "api.h"
  2. #include <bfc/platform/export.h>
  3. #include "../Agave/Component/ifc_wa5component.h"
  4. #include "../nu/Singleton.h"
  5. #include "NSVFactory.h"
  6. #include "duck_dxl.h"
  7. #include "flv_vp6_decoder.h"
  8. #include "avi_vp6_decoder.h"
  9. api_service *WASABI_API_SVC=0;
  10. api_memmgr *WASABI_API_MEMMGR=0;
  11. class VP6Component : public ifc_wa5component
  12. {
  13. public:
  14. void RegisterServices(api_service *service);
  15. int RegisterServicesSafeModeOk();
  16. void DeregisterServices(api_service *service);
  17. protected:
  18. RECVS_DISPATCH;
  19. };
  20. template <class api_T>
  21. void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  22. {
  23. if (WASABI_API_SVC)
  24. {
  25. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  26. if (factory)
  27. api_t = reinterpret_cast<api_T *>( factory->getInterface() );
  28. }
  29. }
  30. template <class api_T>
  31. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  32. {
  33. if (WASABI_API_SVC && api_t)
  34. {
  35. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  36. if (factory)
  37. factory->releaseInterface(api_t);
  38. }
  39. api_t = NULL;
  40. }
  41. static AVIDecoderCreator aviCreator;
  42. static SingletonServiceFactory<svc_avidecoder, AVIDecoderCreator> aviFactory;
  43. FLVDecoderCreator flvCreator;
  44. SingletonServiceFactory<svc_flvdecoder, FLVDecoderCreator> flvFactory;
  45. static NSVFactory nsvFactory;
  46. static SingletonServiceFactory<svc_nsvFactory, NSVFactory> factory;
  47. extern "C"
  48. {
  49. int vp60_Init(void);
  50. int vp60_Exit(void);
  51. }
  52. void VP6Component::RegisterServices(api_service *service)
  53. {
  54. WASABI_API_SVC = service;
  55. ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  56. factory.Register(WASABI_API_SVC, &nsvFactory);
  57. flvFactory.Register(WASABI_API_SVC, &flvCreator);
  58. aviFactory.Register(WASABI_API_SVC, &aviCreator);
  59. /* since we're delay loaded via WBM, it's safe to do this at load time */
  60. DXL_InitVideo();
  61. vp60_Init();
  62. }
  63. int VP6Component::RegisterServicesSafeModeOk()
  64. {
  65. return 1;
  66. }
  67. void VP6Component::DeregisterServices(api_service *service)
  68. {
  69. factory.Deregister(WASABI_API_SVC);
  70. flvFactory.Deregister(WASABI_API_SVC);
  71. aviFactory.Deregister(WASABI_API_SVC);
  72. ServiceRelease(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  73. vp60_Exit();
  74. DXL_ExitVideo();
  75. }
  76. static VP6Component component;
  77. extern "C" DLLEXPORT ifc_wa5component *GetWinamp5SystemComponent()
  78. {
  79. return &component;
  80. }
  81. #define CBCLASS VP6Component
  82. START_DISPATCH;
  83. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  84. CB(15, RegisterServicesSafeModeOk)
  85. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  86. END_DISPATCH;
  87. #undef CBCLASS