diff --git a/include/media/drm/DrmAPI.h b/include/media/drm/DrmAPI.h index 81d1ec02d..c89f2d6a7 100644 --- a/include/media/drm/DrmAPI.h +++ b/include/media/drm/DrmAPI.h @@ -22,6 +22,7 @@ #include #include #include +#include #include // Loadable DrmEngine shared libraries should define the entry points @@ -34,7 +35,8 @@ namespace android { - struct DrmPlugin; + class DrmPlugin; + class DrmPluginListener; // DRMs are implemented in DrmEngine plugins, which are dynamically // loadable shared libraries that implement the entry points @@ -70,7 +72,7 @@ namespace android { class DrmPlugin { public: enum EventType { - kDrmPluginEventProvisionRequired, + kDrmPluginEventProvisionRequired = 1, kDrmPluginEventKeyNeeded, kDrmPluginEventKeyExpired, kDrmPluginEventVendorDefined @@ -261,12 +263,46 @@ namespace android { bool &match) = 0; + status_t setListener(const sp& listener) { + Mutex::Autolock lock(mEventLock); + mListener = listener; + return OK; + } + + protected: + // Plugins call sendEvent to deliver events to the java app + void sendEvent(EventType eventType, int extra, + Vector const *sessionId, + Vector const *data); - // TODO: provide way to send an event private: + Mutex mEventLock; + sp mListener; + DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin); }; + class DrmPluginListener: virtual public RefBase + { + public: + virtual void sendEvent(DrmPlugin::EventType eventType, int extra, + Vector const *sesionId, + Vector const *data) = 0; + }; + + inline void DrmPlugin::sendEvent(EventType eventType, int extra, + Vector const *sessionId, + Vector const *data) { + + mEventLock.lock(); + sp listener = mListener; + mEventLock.unlock(); + + if (listener != NULL) { + listener->sendEvent(eventType, extra, sessionId, data); + } + } + } // namespace android #endif // DRM_API_H_