MediaSystemResourceManager.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 sts=2 et cindent: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #if !defined(MediaSystemResourceManager_h_)
  7. #define MediaSystemResourceManager_h_
  8. #include <queue>
  9. #include "MediaSystemResourceTypes.h"
  10. #include "mozilla/ReentrantMonitor.h"
  11. #include "mozilla/StaticPtr.h"
  12. #include "nsDataHashtable.h"
  13. #include "nsISupportsImpl.h"
  14. namespace mozilla {
  15. namespace media {
  16. class MediaSystemResourceManagerChild;
  17. } // namespace media
  18. class MediaSystemResourceClient;
  19. class MediaSystemResourceReservationListener;
  20. class ReentrantMonitor;
  21. class TaskQueue;
  22. /**
  23. * Manage media system resource allocation requests within a process.
  24. */
  25. class MediaSystemResourceManager
  26. {
  27. public:
  28. NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaSystemResourceManager)
  29. static MediaSystemResourceManager* Get();
  30. static void Init();
  31. static void Shutdown();
  32. void OnIpcClosed();
  33. void Register(MediaSystemResourceClient* aClient);
  34. void Unregister(MediaSystemResourceClient* aClient);
  35. bool SetListener(MediaSystemResourceClient* aClient,
  36. MediaSystemResourceReservationListener* aListener);
  37. void Acquire(MediaSystemResourceClient* aClient);
  38. bool AcquireSyncNoWait(MediaSystemResourceClient* aClient);
  39. void ReleaseResource(MediaSystemResourceClient* aClient);
  40. void RecvResponse(uint32_t aId, bool aSuccess);
  41. private:
  42. MediaSystemResourceManager();
  43. virtual ~MediaSystemResourceManager();
  44. void OpenIPC();
  45. void CloseIPC();
  46. bool IsIpcClosed();
  47. void DoAcquire(uint32_t aId);
  48. void DoRelease(uint32_t aId);
  49. void HandleAcquireResult(uint32_t aId, bool aSuccess);
  50. ReentrantMonitor mReentrantMonitor;
  51. bool mShutDown;
  52. media::MediaSystemResourceManagerChild* mChild;
  53. nsDataHashtable<nsUint32HashKey, MediaSystemResourceClient*> mResourceClients;
  54. static StaticRefPtr<MediaSystemResourceManager> sSingleton;
  55. };
  56. } // namespace mozilla
  57. #endif