main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #define WIN32_LEAN_AND_MEAN
  2. #include "api__h264.h"
  3. #include <bfc/platform/export.h>
  4. #include "../Agave/Component/ifc_wa5component.h"
  5. #include "../nu/Singleton.h"
  6. #include "../nu/factoryt.h"
  7. #include "h264_flv_decoder.h"
  8. #include "h264_mp4_decoder.h"
  9. #include "h264_mkv_decoder.h"
  10. #include "avi_h264_decoder.h"
  11. #include "NSVFactory.h"
  12. api_service *WASABI_API_SVC=0;
  13. api_memmgr *WASABI_API_MEMMGR=0;
  14. api_winamp *AGAVE_API_WINAMP=0;
  15. class H264Component : public ifc_wa5component
  16. {
  17. public:
  18. void RegisterServices(api_service *service);
  19. void DeregisterServices(api_service *service);
  20. protected:
  21. RECVS_DISPATCH;
  22. };
  23. template <class api_T>
  24. void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  25. {
  26. if (WASABI_API_SVC)
  27. {
  28. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  29. if (factory)
  30. api_t = reinterpret_cast<api_T *>( factory->getInterface() );
  31. }
  32. }
  33. template <class api_T>
  34. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  35. {
  36. if (WASABI_API_SVC)
  37. {
  38. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  39. if (factory)
  40. factory->releaseInterface(api_t);
  41. }
  42. api_t = NULL;
  43. }
  44. static FLVDecoderCreator flvCreator;
  45. static SingletonServiceFactory<svc_flvdecoder, FLVDecoderCreator> flvFactory;
  46. static MKVDecoderCreator mkvCreator;
  47. static SingletonServiceFactory<svc_mkvdecoder, MKVDecoderCreator> mkvFactory;
  48. static AVIDecoderCreator aviCreator;
  49. static SingletonServiceFactory<svc_avidecoder, AVIDecoderCreator> aviFactory;
  50. static ServiceFactoryT<MP4VideoDecoder, H264MP4Decoder> mp4Factory;
  51. static NSVFactory nsvCreator;
  52. static SingletonServiceFactory<svc_nsvFactory, NSVFactory> nsvFactory;
  53. void H264Component::RegisterServices(api_service *service)
  54. {
  55. WASABI_API_SVC = service;
  56. ServiceBuild(AGAVE_API_WINAMP, winampApiGuid);
  57. if (!AGAVE_API_WINAMP || AGAVE_API_WINAMP->GetRegVer() >= 1)
  58. {
  59. ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  60. mp4Factory.Register(WASABI_API_SVC);
  61. flvFactory.Register(WASABI_API_SVC, &flvCreator);
  62. mkvFactory.Register(WASABI_API_SVC, &mkvCreator);
  63. aviFactory.Register(WASABI_API_SVC, &aviCreator);
  64. nsvFactory.Register(WASABI_API_SVC, &nsvCreator);
  65. }
  66. }
  67. void H264Component::DeregisterServices(api_service *service)
  68. {
  69. mp4Factory.Deregister(WASABI_API_SVC);
  70. flvFactory.Deregister(WASABI_API_SVC);
  71. mkvFactory.Deregister(WASABI_API_SVC);
  72. aviFactory.Deregister(WASABI_API_SVC);
  73. nsvFactory.Deregister(WASABI_API_SVC);
  74. ServiceRelease(WASABI_API_MEMMGR, memMgrApiServiceGuid);
  75. ServiceRelease(AGAVE_API_WINAMP, winampApiGuid);
  76. }
  77. static H264Component component;
  78. extern "C" DLLEXPORT ifc_wa5component *GetWinamp5SystemComponent()
  79. {
  80. return &component;
  81. }
  82. #define CBCLASS H264Component
  83. START_DISPATCH;
  84. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  85. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  86. END_DISPATCH;
  87. #undef CBCLASS