summaryrefslogtreecommitdiffstats
path: root/media/base/cdm_context.h
blob: 7d897608cc39946e513334ca6a0a55cc1ee19e5a (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
// Copyright 2014 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_BASE_CDM_CONTEXT_H_
#define MEDIA_BASE_CDM_CONTEXT_H_

#include "base/callback.h"
#include "base/macros.h"
#include "media/base/media_export.h"

namespace media {

class Decryptor;

// An interface representing the context that a media pipeline needs from a
// content decryption module (CDM) to decrypt (and decode) encrypted buffers.
// Only used for implementing SetCdm().
class MEDIA_EXPORT CdmContext {
 public:
  // Indicates an invalid CDM ID. See GetCdmId() for details.
  static const int kInvalidCdmId = 0;

  virtual ~CdmContext();

  // Gets the Decryptor object associated with the CDM. Returns nullptr if the
  // CDM does not support a Decryptor. Must not return nullptr if GetCdmId()
  // returns kInvalidCdmId. The returned object is only guaranteed to be valid
  // during the CDM's lifetime.
  virtual Decryptor* GetDecryptor() = 0;

  // Returns an ID that identifies a CDM, or kInvalidCdmId. The interpretation
  // is implementation-specific; current implementations use the ID to locate a
  // remote CDM in a different process. The return value will not be
  // kInvalidCdmId if GetDecryptor() returns nullptr.
  virtual int GetCdmId() const = 0;

 protected:
  CdmContext();

 private:
  DISALLOW_COPY_AND_ASSIGN(CdmContext);
};

// An interface for looking up CdmContext objects by the CDM ID.
class MEDIA_EXPORT CdmContextProvider {
 public:
  virtual ~CdmContextProvider();

  // Returns the CdmContext corresponding to |cdm_id|. Returns nullptr if no
  // such CdmContext can be found.
  // Note: Calling GetCdmId() on the returned CdmContext returns kInvalidCdmId
  // (in all current cases) because the CDM will be local in the process where
  // GetCdmContext() is called.
  virtual CdmContext* GetCdmContext(int cdm_id) = 0;

 protected:
  CdmContextProvider();

 private:
  DISALLOW_COPY_AND_ASSIGN(CdmContextProvider);
};

// Callback to notify that the CdmContext has been completely attached to
// the media pipeline. Parameter indicates whether the operation succeeded.
typedef base::Callback<void(bool)> CdmAttachedCB;

// A dummy implementation of CdmAttachedCB.
MEDIA_EXPORT void IgnoreCdmAttached(bool success);

}  // namespace media

#endif  // MEDIA_BASE_CDM_CONTEXT_H_