summaryrefslogtreecommitdiffstats
path: root/dom/media/ipc/RemoteDecodeUtils.cpp
blob: 15036a03709352499c5c6ce454ec97de78a1712e (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
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "RemoteDecodeUtils.h"
#include "mozilla/ipc/UtilityProcessChild.h"

namespace mozilla {

using SandboxingKind = ipc::SandboxingKind;

SandboxingKind GetCurrentSandboxingKind() {
  MOZ_ASSERT(XRE_IsUtilityProcess());
  return ipc::UtilityProcessChild::GetSingleton()->mSandbox;
}

SandboxingKind GetSandboxingKindFromLocation(RemoteDecodeIn aLocation) {
  switch (aLocation) {
    case RemoteDecodeIn::UtilityProcess_Generic:
      return SandboxingKind::GENERIC_UTILITY;
#ifdef MOZ_APPLEMEDIA
    case RemoteDecodeIn::UtilityProcess_AppleMedia:
      return SandboxingKind::UTILITY_AUDIO_DECODING_APPLE_MEDIA;
      break;
#endif
#ifdef XP_WIN
    case RemoteDecodeIn::UtilityProcess_WMF:
      return SandboxingKind::UTILITY_AUDIO_DECODING_WMF;
#endif
#ifdef MOZ_WMF_MEDIA_ENGINE
    case RemoteDecodeIn::UtilityProcess_MFMediaEngineCDM:
      return SandboxingKind::MF_MEDIA_ENGINE_CDM;
#endif
    default:
      MOZ_ASSERT_UNREACHABLE("Unsupported RemoteDecodeIn");
      return SandboxingKind::COUNT;
  }
}

RemoteDecodeIn GetRemoteDecodeInFromKind(SandboxingKind aKind) {
  switch (aKind) {
    case SandboxingKind::GENERIC_UTILITY:
      return RemoteDecodeIn::UtilityProcess_Generic;
#ifdef MOZ_APPLEMEDIA
    case SandboxingKind::UTILITY_AUDIO_DECODING_APPLE_MEDIA:
      return RemoteDecodeIn::UtilityProcess_AppleMedia;
#endif
#ifdef XP_WIN
    case SandboxingKind::UTILITY_AUDIO_DECODING_WMF:
      return RemoteDecodeIn::UtilityProcess_WMF;
#endif
#ifdef MOZ_WMF_MEDIA_ENGINE
    case SandboxingKind::MF_MEDIA_ENGINE_CDM:
      return RemoteDecodeIn::UtilityProcess_MFMediaEngineCDM;
#endif
    default:
      MOZ_ASSERT_UNREACHABLE("Unsupported SandboxingKind");
      return RemoteDecodeIn::Unspecified;
  }
}

RemoteDecodeIn GetRemoteDecodeInFromVideoBridgeSource(
    layers::VideoBridgeSource aSource) {
  switch (aSource) {
    case layers::VideoBridgeSource::RddProcess:
      return RemoteDecodeIn::RddProcess;
    case layers::VideoBridgeSource::GpuProcess:
      return RemoteDecodeIn::GpuProcess;
    case layers::VideoBridgeSource::MFMediaEngineCDMProcess:
      return RemoteDecodeIn::UtilityProcess_MFMediaEngineCDM;
    default:
      MOZ_ASSERT_UNREACHABLE("Unsupported VideoBridgeSource");
      return RemoteDecodeIn::Unspecified;
  }
}

const char* RemoteDecodeInToStr(RemoteDecodeIn aLocation) {
  switch (aLocation) {
    case RemoteDecodeIn::RddProcess:
      return "RDD";
    case RemoteDecodeIn::GpuProcess:
      return "GPU";
    case RemoteDecodeIn::UtilityProcess_Generic:
      return "Utility Generic";
#ifdef MOZ_APPLEMEDIA
    case RemoteDecodeIn::UtilityProcess_AppleMedia:
      return "Utility AppleMedia";
#endif
#ifdef XP_WIN
    case RemoteDecodeIn::UtilityProcess_WMF:
      return "Utility WMF";
#endif
#ifdef MOZ_WMF_MEDIA_ENGINE
    case RemoteDecodeIn::UtilityProcess_MFMediaEngineCDM:
      return "Utility MF Media Engine CDM";
#endif
    default:
      MOZ_ASSERT_UNREACHABLE("Unsupported RemoteDecodeIn");
      return "Unknown";
  }
}

}  // namespace mozilla