1
0

main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "../nu/factoryt.h"
  7. #include "mp4_mp4v_decoder.h"
  8. #include "mkv_mp4v_decoder.h"
  9. #include "avi_mp4v_decoder.h"
  10. #define MF_INIT_GUIDS
  11. #include <Mfapi.h>
  12. #include <Mftransform.h>
  13. #include <wmcodecdsp.h>
  14. api_winamp *AGAVE_API_WINAMP=0;
  15. api_service *WASABI_API_SVC = 0;
  16. class MP4VComponent : public ifc_wa5component
  17. {
  18. public:
  19. void RegisterServices(api_service *service);
  20. void DeregisterServices(api_service *service);
  21. protected:
  22. RECVS_DISPATCH;
  23. };
  24. template <class api_T>
  25. void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  26. {
  27. if (WASABI_API_SVC)
  28. {
  29. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  30. if (factory)
  31. api_t = reinterpret_cast<api_T *>( factory->getInterface() );
  32. }
  33. }
  34. template <class api_T>
  35. void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  36. {
  37. if (WASABI_API_SVC)
  38. {
  39. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  40. if (factory)
  41. factory->releaseInterface(api_t);
  42. }
  43. api_t = NULL;
  44. }
  45. static ServiceFactoryT<MP4VideoDecoder, MP4VMP4Decoder> mp4Factory;
  46. static MKVDecoderCreator mkvCreator;
  47. static SingletonServiceFactory<svc_mkvdecoder, MKVDecoderCreator> mkvFactory;
  48. static AVIDecoderCreator aviCreator;
  49. static SingletonServiceFactory<svc_avidecoder, AVIDecoderCreator> aviFactory;
  50. void MP4VComponent::RegisterServices(api_service *service)
  51. {
  52. WASABI_API_SVC = service;
  53. ServiceBuild(AGAVE_API_WINAMP, winampApiGuid);
  54. if (!AGAVE_API_WINAMP || AGAVE_API_WINAMP->GetRegVer() >= 1)
  55. {
  56. mp4Factory.Register(WASABI_API_SVC);
  57. mkvFactory.Register(WASABI_API_SVC, &mkvCreator);
  58. aviFactory.Register(WASABI_API_SVC, &aviCreator);
  59. }
  60. }
  61. void MP4VComponent::DeregisterServices(api_service *service)
  62. {
  63. mp4Factory.Deregister(WASABI_API_SVC);
  64. mkvFactory.Deregister(WASABI_API_SVC);
  65. aviFactory.Deregister(WASABI_API_SVC);
  66. }
  67. static MP4VComponent component;
  68. extern "C" DLLEXPORT ifc_wa5component *GetWinamp5SystemComponent()
  69. {
  70. return &component;
  71. }
  72. #define CBCLASS MP4VComponent
  73. START_DISPATCH;
  74. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  75. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  76. END_DISPATCH;
  77. #undef CBCLASS