File: remote_cdm_context.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (107 lines) | stat: -rw-r--r-- 4,754 bytes parent folder | download | duplicates (5)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_COMPONENTS_CDM_FACTORY_DAEMON_REMOTE_CDM_CONTEXT_H_
#define CHROMEOS_COMPONENTS_CDM_FACTORY_DAEMON_REMOTE_CDM_CONTEXT_H_

#include <memory>

#include "base/component_export.h"
#include "base/memory/ref_counted.h"
#include "chromeos/components/cdm_factory_daemon/chromeos_cdm_context.h"
#include "media/base/cdm_context.h"
#include "media/base/decryptor.h"
#include "media/mojo/mojom/cdm_context_for_oopvd.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"

namespace chromeos {

// Provides the implementation that runs in out of process video decoding that
// proxies the media::CdmContext calls back through a mojom::CdmContextForOOPVD
// IPC connection.
//
// This particular media::CdmContext/chromeos::ChromeOsCdmContext implementation
// has some threading restrictions: after construction, all methods should be
// called on the same sequence unless otherwise noted (in particular, it's safe
// to release the last reference to a RemoteCdmContext on any sequence because
// we guarantee that sequence-affine state is destroyed on the correct
// sequence).
class COMPONENT_EXPORT(CDM_FACTORY_DAEMON) RemoteCdmContext
    : public media::CdmContext,
      public ChromeOsCdmContext,
      public media::Decryptor,
      public base::RefCountedThreadSafe<RemoteCdmContext> {
 public:
  explicit RemoteCdmContext(
      mojo::PendingRemote<media::mojom::CdmContextForOOPVD>
          cdm_context_for_oopvd);

  RemoteCdmContext(const RemoteCdmContext&) = delete;
  RemoteCdmContext& operator=(const RemoteCdmContext&) = delete;

  // media::CdmContext:
  std::unique_ptr<media::CallbackRegistration> RegisterEventCB(
      EventCB event_cb) override;
  media::Decryptor* GetDecryptor() override;
  // GetChromeOsCdmContext() may be called on any sequence.
  ChromeOsCdmContext* GetChromeOsCdmContext() override;

  // chromeos::ChromeOsCdmContext:
  void GetHwKeyData(const media::DecryptConfig* decrypt_config,
                    const std::vector<uint8_t>& hw_identifier,
                    GetHwKeyDataCB callback) override;
  void GetHwConfigData(GetHwConfigDataCB callback) override;
  void GetScreenResolutions(GetScreenResolutionsCB callback) override;
  // GetCdmContextRef() may be called on any sequence.
  std::unique_ptr<media::CdmContextRef> GetCdmContextRef() override;
  // UsingArcCdm() may be called on any sequence.
  bool UsingArcCdm() const override;
  // IsRemoteCdm() may be called on any sequence.
  bool IsRemoteCdm() const override;
  void AllocateSecureBuffer(uint32_t size,
                            AllocateSecureBufferCB callback) override;
  void ParseEncryptedSliceHeader(uint64_t secure_handle,
                                 uint32_t offset,
                                 const std::vector<uint8_t>& stream_data,
                                 ParseEncryptedSliceHeaderCB callback) override;

  // media::Decryptor:
  void Decrypt(StreamType stream_type,
               scoped_refptr<media::DecoderBuffer> encrypted,
               DecryptCB decrypt_cb) override;
  void CancelDecrypt(StreamType stream_type) override;
  void InitializeAudioDecoder(const media::AudioDecoderConfig& config,
                              DecoderInitCB init_cb) override;
  void InitializeVideoDecoder(const media::VideoDecoderConfig& config,
                              DecoderInitCB init_cb) override;
  void DecryptAndDecodeAudio(scoped_refptr<media::DecoderBuffer> encrypted,
                             AudioDecodeCB audio_decode_cb) override;
  void DecryptAndDecodeVideo(scoped_refptr<media::DecoderBuffer> encrypted,
                             VideoDecodeCB video_decode_cb) override;
  void ResetDecoder(StreamType stream_type) override;
  void DeinitializeDecoder(StreamType stream_type) override;
  bool CanAlwaysDecrypt() override;

 private:
  friend class base::RefCountedThreadSafe<RemoteCdmContext>;

  // MojoSequenceState encapsulates sequence-affine state that is initialized
  // lazily. The custom deleter for |mojo_sequence_state_| guarantees that this
  // state is destroyed on the correct sequence.
  class MojoSequenceState;

  ~RemoteCdmContext() override;

  void OnDecryptVideoBufferDone(DecryptCB decrypt_cb,
                                media::Decryptor::Status status,
                                media::mojom::DecoderBufferPtr decoder_buffer,
                                const std::vector<uint8_t>& bytes);

  std::unique_ptr<MojoSequenceState, void (*)(MojoSequenceState*)>
      mojo_sequence_state_;
};

}  // namespace chromeos

#endif  // CHROMEOS_COMPONENTS_CDM_FACTORY_DAEMON_REMOTE_CDM_CONTEXT_H_