Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7eafcae5 authored by Jeff Tinker's avatar Jeff Tinker
Browse files

Implement async event callout from drm plugin to Java app

Change-Id: I83a7757a7b83676ce1a9ffa6ff0a8e495e31b859
parent bcbd78bd
Loading
Loading
Loading
Loading
+39 −3
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@
#include <utils/Vector.h>
#include <utils/Vector.h>
#include <utils/KeyedVector.h>
#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include <utils/RefBase.h>
#include <utils/Mutex.h>
#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/ABase.h>


//  Loadable DrmEngine shared libraries should define the entry points
//  Loadable DrmEngine shared libraries should define the entry points
@@ -34,7 +35,8 @@


namespace android {
namespace android {


    struct DrmPlugin;
    class DrmPlugin;
    class DrmPluginListener;


    // DRMs are implemented in DrmEngine plugins, which are dynamically
    // DRMs are implemented in DrmEngine plugins, which are dynamically
    // loadable shared libraries that implement the entry points
    // loadable shared libraries that implement the entry points
@@ -70,7 +72,7 @@ namespace android {
    class DrmPlugin {
    class DrmPlugin {
    public:
    public:
        enum EventType {
        enum EventType {
            kDrmPluginEventProvisionRequired,
            kDrmPluginEventProvisionRequired = 1,
            kDrmPluginEventKeyNeeded,
            kDrmPluginEventKeyNeeded,
            kDrmPluginEventKeyExpired,
            kDrmPluginEventKeyExpired,
            kDrmPluginEventVendorDefined
            kDrmPluginEventVendorDefined
@@ -261,12 +263,46 @@ namespace android {
                                bool &match) = 0;
                                bool &match) = 0;




        status_t setListener(const sp<DrmPluginListener>& 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<uint8_t> const *sessionId,
                       Vector<uint8_t> const *data);


        // TODO: provide way to send an event
    private:
    private:
        Mutex mEventLock;
        sp<DrmPluginListener> mListener;

        DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin);
        DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin);
    };
    };


    class DrmPluginListener: virtual public RefBase
    {
    public:
        virtual void sendEvent(DrmPlugin::EventType eventType, int extra,
                               Vector<uint8_t> const *sesionId,
                               Vector<uint8_t> const *data) = 0;
    };

    inline void DrmPlugin::sendEvent(EventType eventType, int extra,
                                     Vector<uint8_t> const *sessionId,
                                     Vector<uint8_t> const *data) {

        mEventLock.lock();
        sp<DrmPluginListener> listener = mListener;
        mEventLock.unlock();

        if (listener != NULL) {
            listener->sendEvent(eventType, extra, sessionId, data);
        }
    }

}  // namespace android
}  // namespace android


#endif // DRM_API_H_
#endif // DRM_API_H_