/work/obj-fuzz/dist/include/GMPMessageUtils.h
Line | Count | Source (jump to first uncovered line) |
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 "IPCMessageUtils.h" |
12 | | |
13 | | namespace IPC { |
14 | | |
15 | | template<> |
16 | | struct ParamTraits<GMPErr> |
17 | | : public ContiguousEnumSerializer<GMPErr, GMPNoErr, GMPLastErr> |
18 | | { |
19 | | }; |
20 | | |
21 | | template<> |
22 | | struct ParamTraits<GMPVideoFrameType> |
23 | | : public ContiguousEnumSerializer<GMPVideoFrameType, |
24 | | kGMPKeyFrame, |
25 | | kGMPVideoFrameInvalid> |
26 | | { |
27 | | }; |
28 | | |
29 | | template<> |
30 | | struct ParamTraits<GMPVideoCodecComplexity> |
31 | | : public ContiguousEnumSerializer<GMPVideoCodecComplexity, |
32 | | kGMPComplexityNormal, |
33 | | kGMPComplexityInvalid> |
34 | | { |
35 | | }; |
36 | | |
37 | | template<> |
38 | | struct ParamTraits<GMPVP8ResilienceMode> |
39 | | : public ContiguousEnumSerializer<GMPVP8ResilienceMode, |
40 | | kResilienceOff, |
41 | | kResilienceInvalid> |
42 | | { |
43 | | }; |
44 | | |
45 | | template<> |
46 | | struct ParamTraits<GMPVideoCodecType> |
47 | | : public ContiguousEnumSerializer<GMPVideoCodecType, |
48 | | kGMPVideoCodecVP8, |
49 | | kGMPVideoCodecInvalid> |
50 | | { |
51 | | }; |
52 | | |
53 | | template<> |
54 | | struct ParamTraits<GMPVideoCodecMode> |
55 | | : public ContiguousEnumSerializer<GMPVideoCodecMode, |
56 | | kGMPRealtimeVideo, |
57 | | kGMPCodecModeInvalid> |
58 | | { |
59 | | }; |
60 | | |
61 | | template<> |
62 | | struct ParamTraits<GMPBufferType> |
63 | | : public ContiguousEnumSerializer<GMPBufferType, |
64 | | GMP_BufferSingle, |
65 | | GMP_BufferInvalid> |
66 | | { |
67 | | }; |
68 | | |
69 | | template<> |
70 | | struct ParamTraits<GMPEncryptionScheme> |
71 | | : public ContiguousEnumSerializer<GMPEncryptionScheme, |
72 | | GMPEncryptionScheme::kGMPEncryptionNone, |
73 | | GMPEncryptionScheme::kGMPEncryptionInvalid> |
74 | | { |
75 | | }; |
76 | | |
77 | | template<> |
78 | | struct ParamTraits<GMPSimulcastStream> |
79 | | { |
80 | | typedef GMPSimulcastStream paramType; |
81 | | |
82 | | static void Write(Message* aMsg, const paramType& aParam) |
83 | 0 | { |
84 | 0 | WriteParam(aMsg, aParam.mWidth); |
85 | 0 | WriteParam(aMsg, aParam.mHeight); |
86 | 0 | WriteParam(aMsg, aParam.mNumberOfTemporalLayers); |
87 | 0 | WriteParam(aMsg, aParam.mMaxBitrate); |
88 | 0 | WriteParam(aMsg, aParam.mTargetBitrate); |
89 | 0 | WriteParam(aMsg, aParam.mMinBitrate); |
90 | 0 | WriteParam(aMsg, aParam.mQPMax); |
91 | 0 | } |
92 | | |
93 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
94 | 0 | { |
95 | 0 | if (ReadParam(aMsg, aIter, &(aResult->mWidth)) && |
96 | 0 | ReadParam(aMsg, aIter, &(aResult->mHeight)) && |
97 | 0 | ReadParam(aMsg, aIter, &(aResult->mNumberOfTemporalLayers)) && |
98 | 0 | ReadParam(aMsg, aIter, &(aResult->mMaxBitrate)) && |
99 | 0 | ReadParam(aMsg, aIter, &(aResult->mTargetBitrate)) && |
100 | 0 | ReadParam(aMsg, aIter, &(aResult->mMinBitrate)) && |
101 | 0 | ReadParam(aMsg, aIter, &(aResult->mQPMax))) { |
102 | 0 | return true; |
103 | 0 | } |
104 | 0 | return false; |
105 | 0 | } |
106 | | |
107 | | static void Log(const paramType& aParam, std::wstring* aLog) |
108 | 0 | { |
109 | 0 | aLog->append(StringPrintf(L"[%u, %u, %u, %u, %u, %u, %u]", aParam.mWidth, aParam.mHeight, |
110 | 0 | aParam.mNumberOfTemporalLayers, aParam.mMaxBitrate, |
111 | 0 | aParam.mTargetBitrate, aParam.mMinBitrate, aParam.mQPMax)); |
112 | 0 | } |
113 | | }; |
114 | | |
115 | | template <> |
116 | | struct ParamTraits<GMPVideoCodec> |
117 | | { |
118 | | typedef GMPVideoCodec paramType; |
119 | | |
120 | | static void Write(Message* aMsg, const paramType& aParam) |
121 | 0 | { |
122 | 0 | WriteParam(aMsg, aParam.mGMPApiVersion); |
123 | 0 | WriteParam(aMsg, aParam.mCodecType); |
124 | 0 | WriteParam(aMsg, static_cast<const nsCString&>(nsDependentCString(aParam.mPLName))); |
125 | 0 | WriteParam(aMsg, aParam.mPLType); |
126 | 0 | WriteParam(aMsg, aParam.mWidth); |
127 | 0 | WriteParam(aMsg, aParam.mHeight); |
128 | 0 | WriteParam(aMsg, aParam.mStartBitrate); |
129 | 0 | WriteParam(aMsg, aParam.mMaxBitrate); |
130 | 0 | WriteParam(aMsg, aParam.mMinBitrate); |
131 | 0 | WriteParam(aMsg, aParam.mMaxFramerate); |
132 | 0 | WriteParam(aMsg, aParam.mFrameDroppingOn); |
133 | 0 | WriteParam(aMsg, aParam.mKeyFrameInterval); |
134 | 0 | WriteParam(aMsg, aParam.mQPMax); |
135 | 0 | WriteParam(aMsg, aParam.mNumberOfSimulcastStreams); |
136 | 0 | for (uint32_t i = 0; i < aParam.mNumberOfSimulcastStreams; i++) { |
137 | 0 | WriteParam(aMsg, aParam.mSimulcastStream[i]); |
138 | 0 | } |
139 | 0 | WriteParam(aMsg, aParam.mMode); |
140 | 0 | } |
141 | | |
142 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
143 | 0 | { |
144 | 0 | // NOTE: make sure this matches any versions supported |
145 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->mGMPApiVersion)) || |
146 | 0 | aResult->mGMPApiVersion != kGMPVersion33) { |
147 | 0 | return false; |
148 | 0 | } |
149 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->mCodecType))) { |
150 | 0 | return false; |
151 | 0 | } |
152 | 0 | |
153 | 0 | nsAutoCString plName; |
154 | 0 | if (!ReadParam(aMsg, aIter, &plName) || |
155 | 0 | plName.Length() > kGMPPayloadNameSize - 1) { |
156 | 0 | return false; |
157 | 0 | } |
158 | 0 | memcpy(aResult->mPLName, plName.get(), plName.Length()); |
159 | 0 | memset(aResult->mPLName + plName.Length(), 0, kGMPPayloadNameSize - plName.Length()); |
160 | 0 |
|
161 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->mPLType)) || |
162 | 0 | !ReadParam(aMsg, aIter, &(aResult->mWidth)) || |
163 | 0 | !ReadParam(aMsg, aIter, &(aResult->mHeight)) || |
164 | 0 | !ReadParam(aMsg, aIter, &(aResult->mStartBitrate)) || |
165 | 0 | !ReadParam(aMsg, aIter, &(aResult->mMaxBitrate)) || |
166 | 0 | !ReadParam(aMsg, aIter, &(aResult->mMinBitrate)) || |
167 | 0 | !ReadParam(aMsg, aIter, &(aResult->mMaxFramerate)) || |
168 | 0 | !ReadParam(aMsg, aIter, &(aResult->mFrameDroppingOn)) || |
169 | 0 | !ReadParam(aMsg, aIter, &(aResult->mKeyFrameInterval))) { |
170 | 0 | return false; |
171 | 0 | } |
172 | 0 | |
173 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->mQPMax)) || |
174 | 0 | !ReadParam(aMsg, aIter, &(aResult->mNumberOfSimulcastStreams))) { |
175 | 0 | return false; |
176 | 0 | } |
177 | 0 | |
178 | 0 | if (aResult->mNumberOfSimulcastStreams > kGMPMaxSimulcastStreams) { |
179 | 0 | return false; |
180 | 0 | } |
181 | 0 | |
182 | 0 | for (uint32_t i = 0; i < aResult->mNumberOfSimulcastStreams; i++) { |
183 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->mSimulcastStream[i]))) { |
184 | 0 | return false; |
185 | 0 | } |
186 | 0 | } |
187 | 0 |
|
188 | 0 | if (!ReadParam(aMsg, aIter, &(aResult->mMode))) { |
189 | 0 | return false; |
190 | 0 | } |
191 | 0 | |
192 | 0 | return true; |
193 | 0 | } |
194 | | |
195 | | static void Log(const paramType& aParam, std::wstring* aLog) |
196 | 0 | { |
197 | 0 | const char* codecName = nullptr; |
198 | 0 | if (aParam.mCodecType == kGMPVideoCodecVP8) { |
199 | 0 | codecName = "VP8"; |
200 | 0 | } |
201 | 0 | aLog->append(StringPrintf(L"[%s, %u, %u]", |
202 | 0 | codecName, |
203 | 0 | aParam.mWidth, |
204 | 0 | aParam.mHeight)); |
205 | 0 | } |
206 | | }; |
207 | | |
208 | | } // namespace IPC |
209 | | |
210 | | #endif // GMPMessageUtils_h_ |