aboutsummaryrefslogtreecommitdiff
path: root/Src/vp8x/main.cpp
blob: 418593ccda20a026fd22f7ea193f668669cd8911 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#define WIN32_LEAN_AND_MEAN
#include "api.h"
#include <bfc/platform/export.h>
#include "../Agave/Component/ifc_wa5component.h"
#include "../nu/Singleton.h"
#include "mkv_vp8x_decoder.h"
#include "nsv_vp8_decoder.h"

api_service *WASABI_API_SVC=0;
api_memmgr *WASABI_API_MEMMGR=0;

class VP8XComponent : public ifc_wa5component
{
public:
	void RegisterServices(api_service *service);
	int RegisterServicesSafeModeOk();
	void DeregisterServices(api_service *service);
protected:
	RECVS_DISPATCH;
};

template <class api_T>
void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
{
	if (WASABI_API_SVC)
	{
		waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
		if (factory)
			api_t = reinterpret_cast<api_T *>( factory->getInterface() );
	}
}

template <class api_T>
void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
{
	if (WASABI_API_SVC && api_t)
	{
		waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
		if (factory)
			factory->releaseInterface(api_t);
	}
	api_t = NULL;
}

MKVDecoder mkv_decoder;
static SingletonServiceFactory<svc_mkvdecoder, MKVDecoder> mkv_factory;
static NSVFactory nsv_decoder;
static SingletonServiceFactory<svc_nsvFactory, NSVFactory> nsv_factory;

void VP8XComponent::RegisterServices(api_service *service)
{
	WASABI_API_SVC = service;
	ServiceBuild(WASABI_API_MEMMGR, memMgrApiServiceGuid);
	mkv_factory.Register(WASABI_API_SVC, &mkv_decoder);
	nsv_factory.Register(WASABI_API_SVC, &nsv_decoder);
}

int VP8XComponent::RegisterServicesSafeModeOk()
{
	return 1;
}

void VP8XComponent::DeregisterServices(api_service *service)
{
	mkv_factory.Deregister(WASABI_API_SVC);
	nsv_factory.Deregister(WASABI_API_SVC);
	ServiceRelease(WASABI_API_MEMMGR, memMgrApiServiceGuid);
}

static VP8XComponent component;
extern "C" DLLEXPORT ifc_wa5component *GetWinamp5SystemComponent()
{
	return &component;
}

#define CBCLASS VP8XComponent
START_DISPATCH;
VCB(API_WA5COMPONENT_REGISTERSERVICES, RegisterServices)
CB(15, RegisterServicesSafeModeOk)
VCB(API_WA5COMPONENT_DEREEGISTERSERVICES, DeregisterServices)
END_DISPATCH;
#undef CBCLASS