summaryrefslogtreecommitdiff
path: root/chromium/media/cdm/cdm_manager.h
blob: e56a789a6006c11a5e84d2f7e2b4b3a1c7d25bea (plain)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CDM_CDM_MANAGER_H_
#define MEDIA_CDM_CDM_MANAGER_H_

#include <map>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "media/base/media_export.h"
#include "media/cdm/cdm_manager_export.h"

namespace media {

class ContentDecryptionModule;

// Provides a singleton registry of CDM instances. This is used to share
// ContentDecryptionModules between the MojoMediaService and
// AndroidVideoDecodeAccelerator, and should be removed along with AVDA in the
// future. (MojoCdmServiceContext serves the same purpose for Media Mojo
// services, but scoped to a single InterfaceFactory.)
class CDM_MANAGER_EXPORT CdmManager {
 public:
  CdmManager();
  ~CdmManager();

  static CdmManager* GetInstance();

  // Returns the CDM associated with |cdm_id|. Can be called on any thread.
  scoped_refptr<ContentDecryptionModule> GetCdm(int cdm_id);

  // Registers the |cdm| for |cdm_id|.
  void RegisterCdm(int cdm_id, scoped_refptr<ContentDecryptionModule> cdm);

  // Unregisters the CDM associated with |cdm_id|.
  void UnregisterCdm(int cdm_id);

 private:
  base::Lock lock_;
  std::map<int, scoped_refptr<ContentDecryptionModule>> cdm_map_;

  DISALLOW_COPY_AND_ASSIGN(CdmManager);
};

}  // namespace media

#endif  // MEDIA_CDM_CDM_MANAGER_H_