main.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "api__mp3-mpg123.h"
  2. #include "../nu/Singleton.h"
  3. #include "../nu/factoryt.h"
  4. #include "avi_mp3_decoder.h"
  5. #include "flv_mp3_decoder.h"
  6. #include "mkv_mp3_decoder.h"
  7. #include "mp3_in_mp4.h"
  8. #include "adts_mpg123.h"
  9. #include "MP4Factory.h"
  10. #include "NSVFactory.h"
  11. #include <bfc/platform/export.h>
  12. #include "../Agave/Component/ifc_wa5component.h"
  13. #include "../nu/ServiceBuilder.h"
  14. #include <mpg123.h>
  15. api_service *WASABI_API_SVC = 0;
  16. api_config *AGAVE_API_CONFIG = 0;
  17. api_memmgr *WASABI_API_MEMMGR = 0;
  18. class MP3DecoderComponent : public ifc_wa5component
  19. {
  20. public:
  21. void RegisterServices(api_service *service);
  22. int RegisterServicesSafeModeOk();
  23. void DeregisterServices(api_service *service);
  24. protected:
  25. RECVS_DISPATCH;
  26. };
  27. static SingletonServiceFactory<svc_avidecoder, AVIDecoder> avi_factory;
  28. static AVIDecoder avi_decoder;
  29. static SingletonServiceFactory<svc_mkvdecoder, MKVDecoder> mkv_factory;
  30. static MKVDecoder mkv_decoder;
  31. static SingletonServiceFactory<svc_flvdecoder, FLVDecoderCreator> flv_factory;
  32. static FLVDecoderCreator flv_decoder;
  33. static MPEG4Factory mp4_factory;
  34. static ServiceFactoryT<adts, ADTS_MPG123> adts_factory;
  35. static NSVFactory nsv_decoder;
  36. static SingletonServiceFactory<svc_nsvFactory, NSVFactory> nsv_factory;
  37. void MP3DecoderComponent::RegisterServices(api_service *service)
  38. {
  39. WASABI_API_SVC = service;
  40. if (mpg123_init() == MPG123_OK) {
  41. WASABI_API_SVC->service_register(&mp4_factory);
  42. avi_factory.Register(WASABI_API_SVC, &avi_decoder);
  43. mkv_factory.Register(WASABI_API_SVC, &mkv_decoder);
  44. flv_factory.Register(WASABI_API_SVC, &flv_decoder);
  45. nsv_factory.Register(WASABI_API_SVC, &nsv_decoder);
  46. adts_factory.Register(WASABI_API_SVC);
  47. }
  48. ServiceBuild(WASABI_API_SVC, AGAVE_API_CONFIG, AgaveConfigGUID);
  49. ServiceBuild(WASABI_API_SVC, WASABI_API_MEMMGR, memMgrApiServiceGuid);
  50. }
  51. void MP3DecoderComponent::DeregisterServices(api_service *service)
  52. {
  53. avi_factory.Deregister(WASABI_API_SVC);
  54. mkv_factory.Deregister(WASABI_API_SVC);
  55. WASABI_API_SVC->service_deregister(&mp4_factory);
  56. flv_factory.Deregister(WASABI_API_SVC);
  57. nsv_factory.Deregister(WASABI_API_SVC);
  58. adts_factory.Deregister(WASABI_API_SVC);
  59. ServiceRelease(WASABI_API_SVC, AGAVE_API_CONFIG, AgaveConfigGUID);
  60. ServiceRelease(WASABI_API_SVC, WASABI_API_MEMMGR, memMgrApiServiceGuid);
  61. mpg123_exit();
  62. }
  63. int MP3DecoderComponent::RegisterServicesSafeModeOk()
  64. {
  65. return 1;
  66. }
  67. MP3DecoderComponent mp3_decoder_component;
  68. extern "C" DLLEXPORT ifc_wa5component *GetWinamp5SystemComponent()
  69. {
  70. return &mp3_decoder_component;
  71. }
  72. #define CBCLASS MP3DecoderComponent
  73. START_DISPATCH;
  74. VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
  75. CB(15, RegisterServicesSafeModeOk)
  76. VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
  77. END_DISPATCH;
  78. #undef CBCLASS