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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
media / gpu / android / codec_wrapper_unittest.cc [blame]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "media/base/android/media_codec_bridge.h"
#include "media/base/android/mock_media_codec_bridge.h"
#include "media/base/encryption_scheme.h"
#include "media/base/subsample_entry.h"
#include "media/gpu/android/codec_wrapper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
using testing::DoAll;
using testing::Invoke;
using testing::NiceMock;
using testing::Return;
using testing::SetArgPointee;
namespace media {
constexpr gfx::Size kInitialCodedSize(640, 480);
constexpr gfx::Size kCodedSizeAlignment(16, 16);
class CodecWrapperTest : public testing::Test {
public:
CodecWrapperTest() : other_thread_("Other thread") {
auto codec = std::make_unique<NiceMock<MockMediaCodecBridge>>();
codec_ = codec.get();
surface_bundle_ = base::MakeRefCounted<CodecSurfaceBundle>();
wrapper_ = std::make_unique<CodecWrapper>(
CodecSurfacePair(std::move(codec), surface_bundle_),
output_buffer_release_cb_.Get(), kInitialCodedSize,
gfx::ColorSpace::CreateREC709(), kCodedSizeAlignment);
ON_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillByDefault(Return(OkStatus()));
ON_CALL(*codec_, DequeueInputBuffer(_, _))
.WillByDefault(DoAll(SetArgPointee<1>(12), Return(OkStatus())));
ON_CALL(*codec_, QueueInputBuffer(_, _, _))
.WillByDefault(Return(OkStatus()));
uint8_t data = 0;
fake_decoder_buffer_ = DecoderBuffer::CopyFrom(base::span_from_ref(data));
// May fail.
other_thread_.Start();
}
~CodecWrapperTest() override {
// ~CodecWrapper asserts that the codec was taken.
wrapper_->TakeCodecSurfacePair();
}
std::unique_ptr<CodecOutputBuffer> DequeueCodecOutputBuffer() {
std::unique_ptr<CodecOutputBuffer> codec_buffer;
wrapper_->DequeueOutputBuffer(nullptr, nullptr, &codec_buffer);
return codec_buffer;
}
// So that we can get the thread's task runner.
base::test::TaskEnvironment task_environment_;
raw_ptr<NiceMock<MockMediaCodecBridge>> codec_;
std::unique_ptr<CodecWrapper> wrapper_;
scoped_refptr<CodecSurfaceBundle> surface_bundle_;
NiceMock<base::MockCallback<CodecWrapper::OutputReleasedCB>>
output_buffer_release_cb_;
scoped_refptr<DecoderBuffer> fake_decoder_buffer_;
base::Thread other_thread_;
};
TEST_F(CodecWrapperTest, TakeCodecReturnsTheCodecFirstAndNullLater) {
ASSERT_EQ(wrapper_->TakeCodecSurfacePair().first.get(), codec_);
ASSERT_EQ(wrapper_->TakeCodecSurfacePair().first, nullptr);
}
TEST_F(CodecWrapperTest, NoCodecOutputBufferReturnedIfDequeueFails) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kError));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer, nullptr);
}
TEST_F(CodecWrapperTest, InitiallyThereAreNoValidCodecOutputBuffers) {
ASSERT_FALSE(wrapper_->HasUnreleasedOutputBuffers());
}
TEST_F(CodecWrapperTest, FlushInvalidatesCodecOutputBuffers) {
auto codec_buffer = DequeueCodecOutputBuffer();
wrapper_->Flush();
ASSERT_FALSE(codec_buffer->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, TakingTheCodecInvalidatesCodecOutputBuffers) {
auto codec_buffer = DequeueCodecOutputBuffer();
wrapper_->TakeCodecSurfacePair();
ASSERT_FALSE(codec_buffer->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, SetSurfaceInvalidatesCodecOutputBuffers) {
auto codec_buffer = DequeueCodecOutputBuffer();
wrapper_->SetSurface(base::MakeRefCounted<CodecSurfaceBundle>());
ASSERT_FALSE(codec_buffer->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, CodecOutputBuffersAreAllInvalidatedTogether) {
auto codec_buffer1 = DequeueCodecOutputBuffer();
auto codec_buffer2 = DequeueCodecOutputBuffer();
wrapper_->Flush();
ASSERT_FALSE(codec_buffer1->ReleaseToSurface());
ASSERT_FALSE(codec_buffer2->ReleaseToSurface());
ASSERT_FALSE(wrapper_->HasUnreleasedOutputBuffers());
}
TEST_F(CodecWrapperTest, CodecOutputBuffersAfterFlushAreValid) {
auto codec_buffer = DequeueCodecOutputBuffer();
wrapper_->Flush();
codec_buffer = DequeueCodecOutputBuffer();
ASSERT_TRUE(codec_buffer->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, CodecOutputBufferReleaseUsesCorrectIndex) {
// The second arg is the buffer index pointer.
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(DoAll(SetArgPointee<1>(42), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
EXPECT_CALL(*codec_, ReleaseOutputBuffer(42, true));
codec_buffer->ReleaseToSurface();
}
TEST_F(CodecWrapperTest, CodecOutputBuffersAreInvalidatedByRelease) {
auto codec_buffer = DequeueCodecOutputBuffer();
codec_buffer->ReleaseToSurface();
ASSERT_FALSE(codec_buffer->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, CodecOutputBuffersReleaseOnDestruction) {
auto codec_buffer = DequeueCodecOutputBuffer();
EXPECT_CALL(*codec_, ReleaseOutputBuffer(_, false));
codec_buffer = nullptr;
}
TEST_F(CodecWrapperTest, CodecOutputBuffersDoNotReleaseIfAlreadyReleased) {
auto codec_buffer = DequeueCodecOutputBuffer();
codec_buffer->ReleaseToSurface();
EXPECT_CALL(*codec_, ReleaseOutputBuffer(_, _)).Times(0);
codec_buffer = nullptr;
}
TEST_F(CodecWrapperTest, ReleasingCodecOutputBuffersAfterTheCodecIsSafe) {
auto codec_buffer = DequeueCodecOutputBuffer();
wrapper_->TakeCodecSurfacePair();
codec_buffer->ReleaseToSurface();
}
TEST_F(CodecWrapperTest, DeletingCodecOutputBuffersAfterTheCodecIsSafe) {
auto codec_buffer = DequeueCodecOutputBuffer();
wrapper_->TakeCodecSurfacePair();
// This test ensures the destructor doesn't crash.
codec_buffer = nullptr;
}
TEST_F(CodecWrapperTest, CodecOutputBufferReleaseDoesNotInvalidateEarlierOnes) {
auto codec_buffer1 = DequeueCodecOutputBuffer();
auto codec_buffer2 = DequeueCodecOutputBuffer();
codec_buffer2->ReleaseToSurface();
EXPECT_TRUE(codec_buffer1->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, CodecOutputBufferReleaseDoesNotInvalidateLaterOnes) {
auto codec_buffer1 = DequeueCodecOutputBuffer();
auto codec_buffer2 = DequeueCodecOutputBuffer();
codec_buffer1->ReleaseToSurface();
ASSERT_TRUE(codec_buffer2->ReleaseToSurface());
}
TEST_F(CodecWrapperTest, FormatChangedStatusIsSwallowed) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(MediaCodecResult::Codes::kTryAgainLater));
std::unique_ptr<CodecOutputBuffer> codec_buffer;
auto status = wrapper_->DequeueOutputBuffer(nullptr, nullptr, &codec_buffer);
ASSERT_EQ(status, CodecWrapper::DequeueStatus::Codes::kTryAgainLater);
}
TEST_F(CodecWrapperTest, BuffersChangedStatusIsSwallowed) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputBuffersChanged))
.WillOnce(Return(MediaCodecResult::Codes::kTryAgainLater));
std::unique_ptr<CodecOutputBuffer> codec_buffer;
auto status = wrapper_->DequeueOutputBuffer(nullptr, nullptr, &codec_buffer);
ASSERT_EQ(status, CodecWrapper::DequeueStatus::Codes::kTryAgainLater);
}
TEST_F(CodecWrapperTest, MultipleFormatChangedStatusesIsAnError) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillRepeatedly(Return(MediaCodecResult::Codes::kOutputFormatChanged));
std::unique_ptr<CodecOutputBuffer> codec_buffer;
auto status = wrapper_->DequeueOutputBuffer(nullptr, nullptr, &codec_buffer);
ASSERT_EQ(status, CodecWrapper::DequeueStatus::Codes::kError);
}
TEST_F(CodecWrapperTest, CodecOutputBuffersHaveTheCorrectSize) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
EXPECT_CALL(*codec_, GetOutputSize(_))
.WillOnce(DoAll(SetArgPointee<0>(gfx::Size(42, 42)), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->size(), gfx::Size(42, 42));
}
TEST_F(CodecWrapperTest, CodecOutputBuffersGuessCodedSize) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
EXPECT_CALL(*codec_, GetOutputSize(_))
.WillOnce(DoAll(SetArgPointee<0>(gfx::Size(42, 42)), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->size(), gfx::Size(42, 42));
EXPECT_TRUE(codec_buffer->CanGuessCodedSize());
EXPECT_EQ(codec_buffer->GuessCodedSize(), gfx::Size(48, 48));
}
TEST_F(CodecWrapperTest, CodecOutputBuffersGuessCodedSizeNoAlignment) {
auto surface_pair = wrapper_->TakeCodecSurfacePair();
wrapper_ = std::make_unique<CodecWrapper>(
std::move(surface_pair), output_buffer_release_cb_.Get(),
kInitialCodedSize, gfx::ColorSpace::CreateREC709(), std::nullopt);
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
EXPECT_CALL(*codec_, GetOutputSize(_))
.WillOnce(DoAll(SetArgPointee<0>(gfx::Size(42, 42)), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->size(), gfx::Size(42, 42));
EXPECT_FALSE(codec_buffer->CanGuessCodedSize());
}
TEST_F(CodecWrapperTest, CodecOutputBuffersGuessCodedSizeWeirdAlignment) {
auto surface_pair = wrapper_->TakeCodecSurfacePair();
wrapper_ = std::make_unique<CodecWrapper>(
std::move(surface_pair), output_buffer_release_cb_.Get(),
kInitialCodedSize, gfx::ColorSpace::CreateREC709(), gfx::Size(128, 1));
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
EXPECT_CALL(*codec_, GetOutputSize(_))
.WillOnce(DoAll(SetArgPointee<0>(gfx::Size(42, 42)), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->size(), gfx::Size(42, 42));
EXPECT_TRUE(codec_buffer->CanGuessCodedSize());
EXPECT_EQ(codec_buffer->GuessCodedSize(), gfx::Size(128, 42));
}
TEST_F(CodecWrapperTest, OutputBufferReleaseCbIsCalledWhenRendering) {
auto codec_buffer = DequeueCodecOutputBuffer();
EXPECT_CALL(output_buffer_release_cb_, Run(true)).Times(1);
codec_buffer->ReleaseToSurface();
}
TEST_F(CodecWrapperTest, OutputBufferReleaseCbIsCalledWhenDestructing) {
auto codec_buffer = DequeueCodecOutputBuffer();
EXPECT_CALL(output_buffer_release_cb_, Run(true)).Times(1);
}
TEST_F(CodecWrapperTest, OutputBufferReflectsDrainingOrDrainedStatus) {
wrapper_->QueueInputBuffer(*fake_decoder_buffer_);
auto eos = DecoderBuffer::CreateEOSBuffer();
wrapper_->QueueInputBuffer(*eos);
ASSERT_TRUE(wrapper_->IsDraining());
auto codec_buffer = DequeueCodecOutputBuffer();
EXPECT_CALL(output_buffer_release_cb_, Run(true)).Times(1);
}
TEST_F(CodecWrapperTest, CodecStartsInFlushedState) {
ASSERT_TRUE(wrapper_->IsFlushed());
ASSERT_FALSE(wrapper_->IsDraining());
ASSERT_FALSE(wrapper_->IsDrained());
}
TEST_F(CodecWrapperTest, CodecIsNotInFlushedStateAfterAnInputIsQueued) {
wrapper_->QueueInputBuffer(*fake_decoder_buffer_);
ASSERT_FALSE(wrapper_->IsFlushed());
ASSERT_FALSE(wrapper_->IsDraining());
ASSERT_FALSE(wrapper_->IsDrained());
}
TEST_F(CodecWrapperTest, FlushTransitionsToFlushedState) {
wrapper_->QueueInputBuffer(*fake_decoder_buffer_);
wrapper_->Flush();
ASSERT_TRUE(wrapper_->IsFlushed());
}
TEST_F(CodecWrapperTest, EosTransitionsToDrainingState) {
wrapper_->QueueInputBuffer(*fake_decoder_buffer_);
auto eos = DecoderBuffer::CreateEOSBuffer();
wrapper_->QueueInputBuffer(*eos);
ASSERT_TRUE(wrapper_->IsDraining());
}
TEST_F(CodecWrapperTest, DequeuingEosTransitionsToDrainedState) {
// Set EOS on next dequeue.
codec_->ProduceOneOutput(MockMediaCodecBridge::kEos);
DequeueCodecOutputBuffer();
ASSERT_FALSE(wrapper_->IsFlushed());
ASSERT_TRUE(wrapper_->IsDrained());
wrapper_->Flush();
ASSERT_FALSE(wrapper_->IsDrained());
}
TEST_F(CodecWrapperTest, RejectedInputBuffersAreReused) {
// If we get a MediaCodecResult::Codes::kNoKey status, the next time we try to
// queue a buffer the previous input buffer should be reused.
EXPECT_CALL(*codec_, DequeueInputBuffer(_, _))
.WillOnce(DoAll(SetArgPointee<1>(666), Return(OkStatus())));
EXPECT_CALL(*codec_, QueueInputBuffer(666, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kNoKey))
.WillOnce(Return(OkStatus()));
auto status = wrapper_->QueueInputBuffer(*fake_decoder_buffer_);
ASSERT_EQ(status, CodecWrapper::QueueStatus::Codes::kNoKey);
wrapper_->QueueInputBuffer(*fake_decoder_buffer_);
}
TEST_F(CodecWrapperTest, SurfaceBundleIsInitializedByConstructor) {
ASSERT_EQ(surface_bundle_.get(), wrapper_->SurfaceBundle());
}
TEST_F(CodecWrapperTest, SurfaceBundleIsUpdatedBySetSurface) {
auto new_bundle = base::MakeRefCounted<CodecSurfaceBundle>();
EXPECT_CALL(*codec_, SetSurface(_)).WillOnce(Return(true));
wrapper_->SetSurface(new_bundle);
ASSERT_EQ(new_bundle.get(), wrapper_->SurfaceBundle());
}
TEST_F(CodecWrapperTest, SurfaceBundleIsTaken) {
ASSERT_EQ(wrapper_->TakeCodecSurfacePair().second, surface_bundle_);
ASSERT_EQ(wrapper_->SurfaceBundle(), nullptr);
}
TEST_F(CodecWrapperTest, EOSWhileFlushedOrDrainedIsElided) {
// Nothing should call QueueEOS.
EXPECT_CALL(*codec_, QueueEOS(_)).Times(0);
// Codec starts in the flushed state.
auto eos = DecoderBuffer::CreateEOSBuffer();
wrapper_->QueueInputBuffer(*eos);
std::unique_ptr<CodecOutputBuffer> codec_buffer;
bool is_eos = false;
wrapper_->DequeueOutputBuffer(nullptr, &is_eos, &codec_buffer);
ASSERT_TRUE(is_eos);
// Since we also just got the codec into the drained state, make sure that
// it is elided here too.
ASSERT_TRUE(wrapper_->IsDrained());
eos = DecoderBuffer::CreateEOSBuffer();
wrapper_->QueueInputBuffer(*eos);
is_eos = false;
wrapper_->DequeueOutputBuffer(nullptr, &is_eos, &codec_buffer);
ASSERT_TRUE(is_eos);
}
TEST_F(CodecWrapperTest, RenderCallbackCalledIfRendered) {
auto codec_buffer = DequeueCodecOutputBuffer();
bool flag = false;
codec_buffer->set_render_cb(base::BindOnce([](bool* flag) { *flag = true; },
base::Unretained(&flag)));
codec_buffer->ReleaseToSurface();
EXPECT_TRUE(flag);
}
TEST_F(CodecWrapperTest, RenderCallbackIsNotCalledIfNotRendered) {
auto codec_buffer = DequeueCodecOutputBuffer();
bool flag = false;
codec_buffer->set_render_cb(base::BindOnce([](bool* flag) { *flag = true; },
base::Unretained(&flag)));
codec_buffer.reset();
EXPECT_FALSE(flag);
}
TEST_F(CodecWrapperTest, CodecWrapperGetsColorSpaceFromCodec) {
// CodecWrapper should provide the color space that's reported by the bridge.
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
gfx::ColorSpace color_space{gfx::ColorSpace::CreateHDR10()};
EXPECT_CALL(*codec_, GetOutputColorSpace(_))
.WillOnce(DoAll(SetArgPointee<0>(color_space), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->color_space(), color_space);
}
TEST_F(CodecWrapperTest, CodecWrapperDefaultsToSRGB) {
auto surface_pair = wrapper_->TakeCodecSurfacePair();
wrapper_ = std::make_unique<CodecWrapper>(
std::move(surface_pair), output_buffer_release_cb_.Get(),
kInitialCodedSize, gfx::ColorSpace(), std::nullopt);
// If MediaCodec doesn't provide a color space and we don't have a valid
// config color space, then CodecWrapper should default to sRGB for sanity.
// CodecWrapper should provide the color space that's reported by the bridge.
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
EXPECT_CALL(*codec_, GetOutputColorSpace(_))
.WillOnce(Return(MediaCodecResult::Codes::kError));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->color_space(), gfx::ColorSpace::CreateSRGB());
}
TEST_F(CodecWrapperTest, CodecWrapperUseConfigColorSpace) {
auto surface_pair = wrapper_->TakeCodecSurfacePair();
wrapper_ = std::make_unique<CodecWrapper>(
std::move(surface_pair), output_buffer_release_cb_.Get(),
kInitialCodedSize, gfx::ColorSpace::CreateJpeg(), std::nullopt);
// If MediaCodec doesn't provide a color space and we have a valid config
// color space, then CodecWrapper should use it.
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
EXPECT_CALL(*codec_, GetOutputColorSpace(_))
.WillOnce(Return(MediaCodecResult::Codes::kError));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->color_space(), gfx::ColorSpace::CreateJpeg());
}
TEST_F(CodecWrapperTest, CodecOutputsIgnoreZeroSize) {
EXPECT_CALL(*codec_, DequeueOutputBuffer(_, _, _, _, _, _, _))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()))
.WillOnce(Return(MediaCodecResult::Codes::kOutputFormatChanged))
.WillOnce(Return(OkStatus()));
constexpr gfx::Size kNewSize(1280, 720);
EXPECT_CALL(*codec_, GetOutputSize(_))
.WillOnce(DoAll(SetArgPointee<0>(gfx::Size()), Return(OkStatus())))
.WillOnce(DoAll(SetArgPointee<0>(kNewSize), Return(OkStatus())));
auto codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->size(), kInitialCodedSize);
codec_buffer = DequeueCodecOutputBuffer();
ASSERT_EQ(codec_buffer->size(), kNewSize);
}
} // namespace media