[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / mojo_cdm_helper.h
1 // Copyright 2017 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_HELPER_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_HELPER_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/raw_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "build/build_config.h"
15 #include "media/cdm/cdm_auxiliary_helper.h"
16 #include "media/media_buildflags.h"
17 #include "media/mojo/mojom/cdm_document_service.mojom.h"
18 #include "media/mojo/mojom/cdm_storage.mojom.h"
19 #include "media/mojo/mojom/frame_interface_factory.mojom.h"
20 #include "media/mojo/mojom/output_protection.mojom.h"
21 #include "media/mojo/services/media_mojo_export.h"
22 #include "media/mojo/services/mojo_cdm_file_io.h"
23 #include "mojo/public/cpp/bindings/remote.h"
24
25 namespace media {
26
27 // Helper class that connects the CDM to various auxiliary services. All
28 // additional services (FileIO, memory allocation, output protection, and
29 // platform verification) are lazily created.
30 class MEDIA_MOJO_EXPORT MojoCdmHelper final : public CdmAuxiliaryHelper,
31                                               public MojoCdmFileIO::Delegate {
32  public:
33   explicit MojoCdmHelper(mojom::FrameInterfaceFactory* frame_interfaces);
34   MojoCdmHelper(const MojoCdmHelper&) = delete;
35   MojoCdmHelper operator=(const MojoCdmHelper&) = delete;
36   ~MojoCdmHelper() final;
37
38   // CdmAuxiliaryHelper implementation.
39   void SetFileReadCB(FileReadCB file_read_cb) final;
40   cdm::FileIO* CreateCdmFileIO(cdm::FileIOClient* client) final;
41   url::Origin GetCdmOrigin() final;
42   cdm::Buffer* CreateCdmBuffer(size_t capacity) final;
43   std::unique_ptr<VideoFrameImpl> CreateCdmVideoFrame() final;
44   void QueryStatus(QueryStatusCB callback) final;
45   void EnableProtection(uint32_t desired_protection_mask,
46                         EnableProtectionCB callback) final;
47   void ChallengePlatform(const std::string& service_id,
48                          const std::string& challenge,
49                          ChallengePlatformCB callback) final;
50   void GetStorageId(uint32_t version, StorageIdCB callback) final;
51 #if BUILDFLAG(IS_WIN)
52   void GetMediaFoundationCdmData(GetMediaFoundationCdmDataCB callback) final;
53   void SetCdmClientToken(const std::vector<uint8_t>& client_token) final;
54   void OnCdmEvent(CdmEvent event, HRESULT hresult) final;
55 #endif  // BUILDFLAG(IS_WIN)
56
57   // MojoCdmFileIO::Delegate implementation.
58   void CloseCdmFileIO(MojoCdmFileIO* cdm_file_io) final;
59   void ReportFileReadSize(int file_size_bytes) final;
60
61  private:
62   // All services are created lazily.
63   void ConnectToOutputProtection();
64   void ConnectToCdmDocumentService();
65
66   CdmAllocator* GetAllocator();
67
68   // Provides interfaces when needed.
69   raw_ptr<mojom::FrameInterfaceFactory> frame_interfaces_;
70
71   // Connections to the additional services. Will try to reconnect if
72   // disconnected, to handle cases like page refresh, where the document is
73   // destroyed but RenderFrameHostImpl is not.
74   mojo::Remote<mojom::OutputProtection> output_protection_;
75   mojo::Remote<mojom::CdmDocumentService> cdm_document_service_;
76
77   std::unique_ptr<CdmAllocator> allocator_;
78
79   FileReadCB file_read_cb_;
80
81   // A list of open cdm::FileIO objects.
82   // TODO(xhwang): Switch to use UniquePtrComparator.
83   std::vector<std::unique_ptr<MojoCdmFileIO>> cdm_file_io_set_;
84
85   base::WeakPtrFactory<MojoCdmHelper> weak_factory_{this};
86 };
87
88 }  // namespace media
89
90 #endif  // MEDIA_MOJO_SERVICES_MOJO_CDM_HELPER_H_