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.
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_
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"
20 #if BUILDFLAG(IS_CHROMEOS_ASH)
21 #include "chromeos/components/cdm_factory_daemon/remote_cdm_context.h"
22 #endif // BUILDFLAG(IS_CHROMEOS_ASH)
29 // A class that creates, owns and manages all MojoCdmService instances.
30 class MEDIA_MOJO_EXPORT MojoCdmServiceContext {
32 MojoCdmServiceContext();
34 MojoCdmServiceContext(const MojoCdmServiceContext&) = delete;
35 MojoCdmServiceContext& operator=(const MojoCdmServiceContext&) = delete;
37 ~MojoCdmServiceContext();
39 // Registers the |cdm_service| and returns a unique (per-process) CDM ID.
40 base::UnguessableToken RegisterCdm(MojoCdmService* cdm_service);
42 // Unregisters the CDM. Must be called before the CDM is destroyed.
43 void UnregisterCdm(const base::UnguessableToken& cdm_id);
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);
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)
60 // Returns the CdmContextRef associated with |cdm_id|.
61 std::unique_ptr<CdmContextRef> GetCdmContextRef(
62 const base::UnguessableToken& cdm_id);
65 // Lock for cdm_services_. Audio and video decoder may access it from
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_);
72 #if BUILDFLAG(IS_CHROMEOS_ASH)
73 // A map between CDM ID and RemoteCdmContext.
74 std::map<base::UnguessableToken, chromeos::RemoteCdmContext*>
76 #endif // BUILDFLAG(IS_CHROMEOS_ASH)
81 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_SERVICE_CONTEXT_H_