michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ANDROID_MEDIARESOURCEMANAGERSERVICE_H michael@0: #define ANDROID_MEDIARESOURCEMANAGERSERVICE_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "IMediaResourceManagerClient.h" michael@0: #include "IMediaResourceManagerService.h" michael@0: michael@0: namespace android { michael@0: michael@0: /** michael@0: * Manage permissions of using media resources(hw decoder, hw encoder, camera) michael@0: * XXX Current implementaion support only one hw video decoder. michael@0: * Need to extend to support multiple instance and other resources. michael@0: */ michael@0: class MediaResourceManagerService: public BnMediaResourceManagerService, michael@0: public IBinder::DeathRecipient michael@0: { michael@0: public: michael@0: // The maximum number of hardware decoders available. michael@0: enum { VIDEO_DECODER_COUNT = 1 }; michael@0: michael@0: enum { michael@0: kNotifyRequest = 'noti' michael@0: }; michael@0: michael@0: // Instantiate MediaResourceManagerService and register to service manager. michael@0: // If service manager is not present, wait until service manager becomes present. michael@0: static void instantiate(); michael@0: michael@0: // DeathRecipient michael@0: virtual void binderDied(const wp& who); michael@0: michael@0: // derived from IMediaResourceManagerService michael@0: virtual void requestMediaResource(const sp& client, int resourceType); michael@0: virtual status_t cancelClient(const sp& client); michael@0: michael@0: // Receive a message from AHandlerReflector. michael@0: // Called on ALooper thread. michael@0: void onMessageReceived(const sp &msg); michael@0: michael@0: protected: michael@0: MediaResourceManagerService(); michael@0: virtual ~MediaResourceManagerService(); michael@0: michael@0: protected: michael@0: // Represent a media resouce. michael@0: // Hold a IMediaResourceManagerClient that got a media resource as IBinder. michael@0: struct ResourceSlot { michael@0: ResourceSlot () michael@0: { michael@0: } michael@0: sp mClient; michael@0: }; michael@0: michael@0: void cancelClientLocked(const sp& binder); michael@0: michael@0: // mVideoDecoderSlots is the array of slots that represent a media resource. michael@0: ResourceSlot mVideoDecoderSlots[VIDEO_DECODER_COUNT]; michael@0: // The maximum number of hardware decoders available on the device. michael@0: int mVideoDecoderCount; michael@0: michael@0: // The lock protects mVideoDecoderSlots and mVideoCodecRequestQueue called michael@0: // from multiple threads. michael@0: Mutex mLock; michael@0: typedef List > Fifo; michael@0: // Queue of media resource requests. michael@0: // Hold IMediaResourceManagerClient that requesting a media resource as IBinder. michael@0: Fifo mVideoCodecRequestQueue; michael@0: michael@0: // ALooper is a message loop used in stagefright. michael@0: // It creates a thread for messages and handles messages in the thread. michael@0: // ALooper is a clone of Looper in android Java. michael@0: // http://developer.android.com/reference/android/os/Looper.html michael@0: sp mLooper; michael@0: // deliver a message to a wrapped object(OmxDecoder). michael@0: // AHandlerReflector is similar to Handler in android Java. michael@0: // http://developer.android.com/reference/android/os/Handler.html michael@0: sp > mReflector; michael@0: michael@0: }; michael@0: michael@0: }; // namespace android michael@0: michael@0: #endif // ANDROID_MEDIARESOURCEMANAGERSERVICE_H