Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GMPMessageUtils_h_
7 : #define GMPMessageUtils_h_
8 :
9 : #include "gmp-video-codec.h"
10 : #include "gmp-video-frame-encoded.h"
11 : #include "gmp-decryption.h"
12 : #include "IPCMessageUtils.h"
13 :
14 : namespace IPC {
15 :
16 : template <>
17 : struct ParamTraits<GMPErr>
18 : : public ContiguousEnumSerializer<GMPErr,
19 : GMPNoErr,
20 : GMPLastErr>
21 : {};
22 :
23 : struct GMPDomExceptionValidator {
24 0 : static bool IsLegalValue(GMPDOMException aValue) {
25 0 : switch (aValue) {
26 : case kGMPNoModificationAllowedError:
27 : case kGMPNotFoundError:
28 : case kGMPNotSupportedError:
29 : case kGMPInvalidStateError:
30 : case kGMPSyntaxError:
31 : case kGMPInvalidModificationError:
32 : case kGMPInvalidAccessError:
33 : case kGMPSecurityError:
34 : case kGMPAbortError:
35 : case kGMPQuotaExceededError:
36 : case kGMPTimeoutError:
37 : case kGMPTypeError:
38 0 : return true;
39 : default:
40 0 : return false;
41 : }
42 : }
43 : };
44 :
45 : template <>
46 : struct ParamTraits<GMPVideoFrameType>
47 : : public ContiguousEnumSerializer<GMPVideoFrameType,
48 : kGMPKeyFrame,
49 : kGMPVideoFrameInvalid>
50 : {};
51 :
52 : template<>
53 : struct ParamTraits<GMPDOMException>
54 : : public EnumSerializer<GMPDOMException, GMPDomExceptionValidator>
55 : {};
56 :
57 : template <>
58 : struct ParamTraits<GMPSessionMessageType>
59 : : public ContiguousEnumSerializer<GMPSessionMessageType,
60 : kGMPLicenseRequest,
61 : kGMPMessageInvalid>
62 : {};
63 :
64 : template <>
65 : struct ParamTraits<GMPMediaKeyStatus>
66 : : public ContiguousEnumSerializer<GMPMediaKeyStatus,
67 : kGMPUsable,
68 : kGMPMediaKeyStatusInvalid>
69 : {};
70 :
71 : template <>
72 : struct ParamTraits<GMPSessionType>
73 : : public ContiguousEnumSerializer<GMPSessionType,
74 : kGMPTemporySession,
75 : kGMPSessionInvalid>
76 : {};
77 :
78 : template <>
79 : struct ParamTraits<GMPVideoCodecComplexity>
80 : : public ContiguousEnumSerializer<GMPVideoCodecComplexity,
81 : kGMPComplexityNormal,
82 : kGMPComplexityInvalid>
83 : {};
84 :
85 : template <>
86 : struct ParamTraits<GMPVP8ResilienceMode>
87 : : public ContiguousEnumSerializer<GMPVP8ResilienceMode,
88 : kResilienceOff,
89 : kResilienceInvalid>
90 : {};
91 :
92 : template <>
93 : struct ParamTraits<GMPVideoCodecType>
94 : : public ContiguousEnumSerializer<GMPVideoCodecType,
95 : kGMPVideoCodecVP8,
96 : kGMPVideoCodecInvalid>
97 : {};
98 :
99 : template <>
100 : struct ParamTraits<GMPVideoCodecMode>
101 : : public ContiguousEnumSerializer<GMPVideoCodecMode,
102 : kGMPRealtimeVideo,
103 : kGMPCodecModeInvalid>
104 : {};
105 :
106 : template <>
107 : struct ParamTraits<GMPBufferType>
108 : : public ContiguousEnumSerializer<GMPBufferType,
109 : GMP_BufferSingle,
110 : GMP_BufferInvalid>
111 : {};
112 :
113 : template <>
114 : struct ParamTraits<GMPSimulcastStream>
115 : {
116 : typedef GMPSimulcastStream paramType;
117 :
118 0 : static void Write(Message* aMsg, const paramType& aParam)
119 : {
120 0 : WriteParam(aMsg, aParam.mWidth);
121 0 : WriteParam(aMsg, aParam.mHeight);
122 0 : WriteParam(aMsg, aParam.mNumberOfTemporalLayers);
123 0 : WriteParam(aMsg, aParam.mMaxBitrate);
124 0 : WriteParam(aMsg, aParam.mTargetBitrate);
125 0 : WriteParam(aMsg, aParam.mMinBitrate);
126 0 : WriteParam(aMsg, aParam.mQPMax);
127 0 : }
128 :
129 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
130 : {
131 0 : if (ReadParam(aMsg, aIter, &(aResult->mWidth)) &&
132 0 : ReadParam(aMsg, aIter, &(aResult->mHeight)) &&
133 0 : ReadParam(aMsg, aIter, &(aResult->mNumberOfTemporalLayers)) &&
134 0 : ReadParam(aMsg, aIter, &(aResult->mMaxBitrate)) &&
135 0 : ReadParam(aMsg, aIter, &(aResult->mTargetBitrate)) &&
136 0 : ReadParam(aMsg, aIter, &(aResult->mMinBitrate)) &&
137 0 : ReadParam(aMsg, aIter, &(aResult->mQPMax))) {
138 0 : return true;
139 : }
140 0 : return false;
141 : }
142 :
143 : static void Log(const paramType& aParam, std::wstring* aLog)
144 : {
145 : aLog->append(StringPrintf(L"[%u, %u, %u, %u, %u, %u, %u]", aParam.mWidth, aParam.mHeight,
146 : aParam.mNumberOfTemporalLayers, aParam.mMaxBitrate,
147 : aParam.mTargetBitrate, aParam.mMinBitrate, aParam.mQPMax));
148 : }
149 : };
150 :
151 : template <>
152 : struct ParamTraits<GMPVideoCodec>
153 : {
154 : typedef GMPVideoCodec paramType;
155 :
156 0 : static void Write(Message* aMsg, const paramType& aParam)
157 : {
158 0 : WriteParam(aMsg, aParam.mGMPApiVersion);
159 0 : WriteParam(aMsg, aParam.mCodecType);
160 0 : WriteParam(aMsg, static_cast<const nsCString&>(nsDependentCString(aParam.mPLName)));
161 0 : WriteParam(aMsg, aParam.mPLType);
162 0 : WriteParam(aMsg, aParam.mWidth);
163 0 : WriteParam(aMsg, aParam.mHeight);
164 0 : WriteParam(aMsg, aParam.mStartBitrate);
165 0 : WriteParam(aMsg, aParam.mMaxBitrate);
166 0 : WriteParam(aMsg, aParam.mMinBitrate);
167 0 : WriteParam(aMsg, aParam.mMaxFramerate);
168 0 : WriteParam(aMsg, aParam.mFrameDroppingOn);
169 0 : WriteParam(aMsg, aParam.mKeyFrameInterval);
170 0 : WriteParam(aMsg, aParam.mQPMax);
171 0 : WriteParam(aMsg, aParam.mNumberOfSimulcastStreams);
172 0 : for (uint32_t i = 0; i < aParam.mNumberOfSimulcastStreams; i++) {
173 0 : WriteParam(aMsg, aParam.mSimulcastStream[i]);
174 : }
175 0 : WriteParam(aMsg, aParam.mMode);
176 0 : }
177 :
178 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
179 : {
180 : // NOTE: make sure this matches any versions supported
181 0 : if (!ReadParam(aMsg, aIter, &(aResult->mGMPApiVersion)) ||
182 0 : aResult->mGMPApiVersion != kGMPVersion33) {
183 0 : return false;
184 : }
185 0 : if (!ReadParam(aMsg, aIter, &(aResult->mCodecType))) {
186 0 : return false;
187 : }
188 :
189 0 : nsAutoCString plName;
190 0 : if (!ReadParam(aMsg, aIter, &plName) ||
191 0 : plName.Length() > kGMPPayloadNameSize - 1) {
192 0 : return false;
193 : }
194 0 : memcpy(aResult->mPLName, plName.get(), plName.Length());
195 0 : memset(aResult->mPLName + plName.Length(), 0, kGMPPayloadNameSize - plName.Length());
196 :
197 0 : if (!ReadParam(aMsg, aIter, &(aResult->mPLType)) ||
198 0 : !ReadParam(aMsg, aIter, &(aResult->mWidth)) ||
199 0 : !ReadParam(aMsg, aIter, &(aResult->mHeight)) ||
200 0 : !ReadParam(aMsg, aIter, &(aResult->mStartBitrate)) ||
201 0 : !ReadParam(aMsg, aIter, &(aResult->mMaxBitrate)) ||
202 0 : !ReadParam(aMsg, aIter, &(aResult->mMinBitrate)) ||
203 0 : !ReadParam(aMsg, aIter, &(aResult->mMaxFramerate)) ||
204 0 : !ReadParam(aMsg, aIter, &(aResult->mFrameDroppingOn)) ||
205 0 : !ReadParam(aMsg, aIter, &(aResult->mKeyFrameInterval))) {
206 0 : return false;
207 : }
208 :
209 0 : if (!ReadParam(aMsg, aIter, &(aResult->mQPMax)) ||
210 0 : !ReadParam(aMsg, aIter, &(aResult->mNumberOfSimulcastStreams))) {
211 0 : return false;
212 : }
213 :
214 0 : if (aResult->mNumberOfSimulcastStreams > kGMPMaxSimulcastStreams) {
215 0 : return false;
216 : }
217 :
218 0 : for (uint32_t i = 0; i < aResult->mNumberOfSimulcastStreams; i++) {
219 0 : if (!ReadParam(aMsg, aIter, &(aResult->mSimulcastStream[i]))) {
220 0 : return false;
221 : }
222 : }
223 :
224 0 : if (!ReadParam(aMsg, aIter, &(aResult->mMode))) {
225 0 : return false;
226 : }
227 :
228 0 : return true;
229 : }
230 :
231 : static void Log(const paramType& aParam, std::wstring* aLog)
232 : {
233 : const char* codecName = nullptr;
234 : if (aParam.mCodecType == kGMPVideoCodecVP8) {
235 : codecName = "VP8";
236 : }
237 : aLog->append(StringPrintf(L"[%s, %u, %u]",
238 : codecName,
239 : aParam.mWidth,
240 : aParam.mHeight));
241 : }
242 : };
243 :
244 : } // namespace IPC
245 :
246 : #endif // GMPMessageUtils_h_
|