[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / mojo_cdm_service_context.h
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <memory>
12
13 #include "base/synchronization/lock.h"
14 #include "base/thread_annotations.h"
15 #include "base/unguessable_token.h"
16 #include "build/chromeos_buildflags.h"
17 #include "media/media_buildflags.h"
18 #include "media/mojo/services/media_mojo_export.h"
19
20 #if BUILDFLAG(IS_CHROMEOS_ASH)
21 #include "chromeos/components/cdm_factory_daemon/remote_cdm_context.h"
22 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
23
24 namespace media {
25
26 class CdmContextRef;
27 class MojoCdmService;
28
29 // A class that creates, owns and manages all MojoCdmService instances.
30 class MEDIA_MOJO_EXPORT MojoCdmServiceContext {
31  public:
32   MojoCdmServiceContext();
33
34   MojoCdmServiceContext(const MojoCdmServiceContext&) = delete;
35   MojoCdmServiceContext& operator=(const MojoCdmServiceContext&) = delete;
36
37   ~MojoCdmServiceContext();
38
39   // Registers the |cdm_service| and returns a unique (per-process) CDM ID.
40   base::UnguessableToken RegisterCdm(MojoCdmService* cdm_service);
41
42   // Unregisters the CDM. Must be called before the CDM is destroyed.
43   void UnregisterCdm(const base::UnguessableToken& cdm_id);
44
45 #if BUILDFLAG(IS_CHROMEOS_ASH)
46   // Registers the |remote_context| and returns a unique (per-process) CDM ID.
47   // This is used with out-of-process video decoding with HWDRM. We run
48   // MojoCdmServiceContext in the GPU process which works with MojoCdmService.
49   // We also run MojoCdmServiceContext in the Video Decoder process which
50   // doesn't use MojoCdmService, which is why we need to deal with
51   // RemoteCdmContext directly.
52   base::UnguessableToken RegisterRemoteCdmContext(
53       chromeos::RemoteCdmContext* remote_context);
54
55   // Unregisters the RemoteCdmContext. Must be called before the
56   // RemoteCdmContext is destroyed.
57   void UnregisterRemoteCdmContext(const base::UnguessableToken& cdm_id);
58 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
59
60   // Returns the CdmContextRef associated with |cdm_id|.
61   std::unique_ptr<CdmContextRef> GetCdmContextRef(
62       const base::UnguessableToken& cdm_id);
63
64  private:
65   // Lock for cdm_services_. Audio and video decoder may access it from
66   // different threads.
67   base::Lock cdm_services_lock_;
68   // A map between CDM ID and MojoCdmService.
69   std::map<base::UnguessableToken, MojoCdmService*> cdm_services_
70       GUARDED_BY(cdm_services_lock_);
71
72 #if BUILDFLAG(IS_CHROMEOS_ASH)
73   // A map between CDM ID and RemoteCdmContext.
74   std::map<base::UnguessableToken, chromeos::RemoteCdmContext*>
75       remote_cdm_contexts_;
76 #endif  // BUILDFLAG(IS_CHROMEOS_ASH)
77 };
78
79 }  // namespace media
80
81 #endif  // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_