summaryrefslogtreecommitdiff
path: root/chromium/media/cdm/cdm_module.h
blob: 3e8ed8068b78da90b1c2a2d10a054a712b063bf9 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 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_MODULE_H_
#define MEDIA_CDM_CDM_MODULE_H_

#include <memory>
#include <vector>

#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/scoped_native_library.h"
#include "media/base/media_export.h"
#include "media/cdm/api/content_decryption_module.h"
#include "media/media_buildflags.h"

#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
#include "media/cdm/cdm_host_file.h"
#include "media/cdm/cdm_host_files.h"
#endif  // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)

namespace media {

class MEDIA_EXPORT CdmModule {
 public:
  static CdmModule* GetInstance();

  // Reset the CdmModule instance so that each test have it's own instance.
  static void ResetInstanceForTesting();

  ~CdmModule();

  using CreateCdmFunc = decltype(&::CreateCdmInstance);

  CreateCdmFunc GetCreateCdmFunc();

// Loads the CDM, initialize function pointers and initialize the CDM module.
// This must only be called only once.
#if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
  bool Initialize(const base::FilePath& cdm_path,
                  std::vector<CdmHostFilePath> cdm_host_file_paths);
#else
  bool Initialize(const base::FilePath& cdm_path);
#endif  // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)

  // Calls INITIALIZE_CDM_MODULE on the actually library CDM. Must be called
  // within the sandbox!
  void InitializeCdmModule();

  base::FilePath GetCdmPath() const;

  bool was_initialize_called() const { return was_initialize_called_; }

 private:
  using InitializeCdmModuleFunc = decltype(&::INITIALIZE_CDM_MODULE);
  using DeinitializeCdmModuleFunc = decltype(&::DeinitializeCdmModule);
  using GetCdmVersionFunc = decltype(&::GetCdmVersion);

  CdmModule();

  bool was_initialize_called_ = false;
  base::FilePath cdm_path_;
  base::ScopedNativeLibrary library_;
  CreateCdmFunc create_cdm_func_ = nullptr;
  InitializeCdmModuleFunc initialize_cdm_module_func_ = nullptr;
  DeinitializeCdmModuleFunc deinitialize_cdm_module_func_ = nullptr;
  GetCdmVersionFunc get_cdm_version_func_ = nullptr;

  DISALLOW_COPY_AND_ASSIGN(CdmModule);
};

}  // namespace media

#endif  // MEDIA_CDM_CDM_MODULE_H_