1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // The bulk of this file is support code; sorry about that. Here's an overview
6 // to hopefully help readers of this code:
7 // - RenderingHelper is charged with interacting with X11/{EGL/GLES2,GLX/GL} or
9 // - ClientState is an enum for the state of the decode client used by the test.
10 // - ClientStateNotification is a barrier abstraction that allows the test code
11 // to be written sequentially and wait for the decode client to see certain
13 // - GLRenderingVDAClient is a VideoDecodeAccelerator::Client implementation
14 // - Finally actual TEST cases are at the bottom of this file, using the above
20 #include <sys/types.h>
23 // Include gtest.h out of order because <X11/X.h> #define's Bool & None, which
24 // gtest uses as struct names (inside a namespace). This means that
25 // #include'ing gtest after anything that pulls in X.h fails to compile.
26 // This is http://code.google.com/p/googletest/issues/detail?id=371
27 #include "testing/gtest/include/gtest/gtest.h"
29 #include "base/at_exit.h"
30 #include "base/bind.h"
31 #include "base/command_line.h"
32 #include "base/file_util.h"
33 #include "base/format_macros.h"
35 #include "base/message_loop/message_loop_proxy.h"
36 #include "base/platform_file.h"
37 #include "base/process/process.h"
38 #include "base/stl_util.h"
39 #include "base/strings/string_number_conversions.h"
40 #include "base/strings/string_split.h"
41 #include "base/strings/stringize_macros.h"
42 #include "base/strings/stringprintf.h"
43 #include "base/strings/utf_string_conversions.h"
44 #include "base/synchronization/condition_variable.h"
45 #include "base/synchronization/lock.h"
46 #include "base/synchronization/waitable_event.h"
47 #include "base/threading/thread.h"
48 #include "content/common/gpu/media/rendering_helper.h"
49 #include "content/common/gpu/media/video_accelerator_unittest_helpers.h"
50 #include "content/public/common/content_switches.h"
51 #include "ui/gfx/codec/png_codec.h"
54 #include "content/common/gpu/media/dxva_video_decode_accelerator.h"
55 #elif defined(OS_CHROMEOS)
56 #if defined(ARCH_CPU_ARMEL)
57 #include "content/common/gpu/media/exynos_video_decode_accelerator.h"
58 #elif defined(ARCH_CPU_X86_FAMILY)
59 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
60 #include "content/common/gpu/media/vaapi_wrapper.h"
61 #endif // ARCH_CPU_ARMEL
63 #error The VideoAccelerator tests are not supported on this platform.
66 using media::VideoDecodeAccelerator
;
71 // Values optionally filled in from flags; see main() below.
72 // The syntax of multiple test videos is:
73 // test-video1;test-video2;test-video3
74 // where only the first video is required and other optional videos would be
75 // decoded by concurrent decoders.
76 // The syntax of each test-video is:
77 // filename:width:height:numframes:numfragments:minFPSwithRender:minFPSnoRender
78 // where only the first field is required. Value details:
79 // - |filename| must be an h264 Annex B (NAL) stream or an IVF VP8 stream.
80 // - |width| and |height| are in pixels.
81 // - |numframes| is the number of picture frames in the file.
82 // - |numfragments| NALU (h264) or frame (VP8) count in the stream.
83 // - |minFPSwithRender| and |minFPSnoRender| are minimum frames/second speeds
84 // expected to be achieved with and without rendering to the screen, resp.
85 // (the latter tests just decode speed).
86 // - |profile| is the media::VideoCodecProfile set during Initialization.
87 // An empty value for a numeric field means "ignore".
88 const base::FilePath::CharType
* g_test_video_data
=
89 // FILE_PATH_LITERAL("test-25fps.vp8:320:240:250:250:50:175:11");
90 FILE_PATH_LITERAL("test-25fps.h264:320:240:250:258:50:175:1");
92 // The path of the frame delivery time log. We can enable the log and specify
93 // the filename by the "--frame_delivery_log" switch.
94 const base::FilePath::CharType
* g_frame_delivery_log
= NULL
;
96 // The value is set by the switch "--rendering_fps".
97 double g_rendering_fps
= 0;
99 // Disable rendering, the value is set by the switch "--disable_rendering".
100 bool g_disable_rendering
= false;
102 // Magic constants for differentiating the reasons for NotifyResetDone being
105 START_OF_STREAM_RESET
= -3,
106 MID_STREAM_RESET
= -2,
107 END_OF_STREAM_RESET
= -1
110 const int kMaxResetAfterFrameNum
= 100;
111 const int kMaxFramesToDelayReuse
= 64;
112 const base::TimeDelta kReuseDelay
= base::TimeDelta::FromSeconds(1);
114 struct TestVideoFile
{
115 explicit TestVideoFile(base::FilePath::StringType file_name
)
116 : file_name(file_name
),
122 min_fps_no_render(-1),
124 reset_after_frame_num(END_OF_STREAM_RESET
) {
127 base::FilePath::StringType file_name
;
133 int min_fps_no_render
;
135 int reset_after_frame_num
;
136 std::string data_str
;
139 // Presumed minimal display size.
140 const gfx::Size
kThumbnailsDisplaySize(1366, 768);
141 const gfx::Size
kThumbnailsPageSize(1600, 1200);
142 const gfx::Size
kThumbnailSize(160, 120);
143 const int kMD5StringLength
= 32;
145 // Parse |data| into its constituent parts, set the various output fields
146 // accordingly, and read in video stream. CHECK-fails on unexpected or
147 // missing required data. Unspecified optional fields are set to -1.
148 void ParseAndReadTestVideoData(base::FilePath::StringType data
,
149 size_t num_concurrent_decoders
,
151 std::vector
<TestVideoFile
*>* test_video_files
) {
152 std::vector
<base::FilePath::StringType
> entries
;
153 base::SplitString(data
, ';', &entries
);
154 CHECK_GE(entries
.size(), 1U) << data
;
155 for (size_t index
= 0; index
< entries
.size(); ++index
) {
156 std::vector
<base::FilePath::StringType
> fields
;
157 base::SplitString(entries
[index
], ':', &fields
);
158 CHECK_GE(fields
.size(), 1U) << entries
[index
];
159 CHECK_LE(fields
.size(), 8U) << entries
[index
];
160 TestVideoFile
* video_file
= new TestVideoFile(fields
[0]);
161 if (!fields
[1].empty())
162 CHECK(base::StringToInt(fields
[1], &video_file
->width
));
163 if (!fields
[2].empty())
164 CHECK(base::StringToInt(fields
[2], &video_file
->height
));
165 if (!fields
[3].empty()) {
166 CHECK(base::StringToInt(fields
[3], &video_file
->num_frames
));
167 // If we reset mid-stream and start playback over, account for frames
168 // that are decoded twice in our expectations.
169 if (video_file
->num_frames
> 0 && reset_point
== MID_STREAM_RESET
) {
170 // Reset should not go beyond the last frame; reset after the first
171 // frame for short videos.
172 video_file
->reset_after_frame_num
= kMaxResetAfterFrameNum
;
173 if (video_file
->num_frames
<= kMaxResetAfterFrameNum
)
174 video_file
->reset_after_frame_num
= 1;
175 video_file
->num_frames
+= video_file
->reset_after_frame_num
;
177 video_file
->reset_after_frame_num
= reset_point
;
180 if (!fields
[4].empty())
181 CHECK(base::StringToInt(fields
[4], &video_file
->num_fragments
));
182 if (!fields
[5].empty()) {
183 CHECK(base::StringToInt(fields
[5], &video_file
->min_fps_render
));
184 video_file
->min_fps_render
/= num_concurrent_decoders
;
186 if (!fields
[6].empty()) {
187 CHECK(base::StringToInt(fields
[6], &video_file
->min_fps_no_render
));
188 video_file
->min_fps_no_render
/= num_concurrent_decoders
;
190 if (!fields
[7].empty())
191 CHECK(base::StringToInt(fields
[7], &video_file
->profile
));
193 // Read in the video data.
194 base::FilePath
filepath(video_file
->file_name
);
195 CHECK(base::ReadFileToString(filepath
, &video_file
->data_str
))
196 << "test_video_file: " << filepath
.MaybeAsASCII();
198 test_video_files
->push_back(video_file
);
202 // Read in golden MD5s for the thumbnailed rendering of this video
203 void ReadGoldenThumbnailMD5s(const TestVideoFile
* video_file
,
204 std::vector
<std::string
>* md5_strings
) {
205 base::FilePath
filepath(video_file
->file_name
);
206 filepath
= filepath
.AddExtension(FILE_PATH_LITERAL(".md5"));
207 std::string all_md5s
;
208 base::ReadFileToString(filepath
, &all_md5s
);
209 base::SplitString(all_md5s
, '\n', md5_strings
);
210 // Check these are legitimate MD5s.
211 for (std::vector
<std::string
>::iterator md5_string
= md5_strings
->begin();
212 md5_string
!= md5_strings
->end(); ++md5_string
) {
213 // Ignore the empty string added by SplitString
214 if (!md5_string
->length())
217 CHECK_EQ(static_cast<int>(md5_string
->length()),
218 kMD5StringLength
) << *md5_string
;
219 bool hex_only
= std::count_if(md5_string
->begin(),
220 md5_string
->end(), isxdigit
) ==
222 CHECK(hex_only
) << *md5_string
;
224 CHECK_GE(md5_strings
->size(), 1U) << all_md5s
;
227 // State of the GLRenderingVDAClient below. Order matters here as the test
228 // makes assumptions about it.
239 CS_MAX
, // Must be last entry.
242 // A wrapper client that throttles the PictureReady callbacks to a given rate.
243 // It may drops or queues frame to deliver them on time.
244 class ThrottlingVDAClient
: public VideoDecodeAccelerator::Client
,
245 public base::SupportsWeakPtr
<ThrottlingVDAClient
> {
247 // Callback invoked whan the picture is dropped and should be reused for
248 // the decoder again.
249 typedef base::Callback
<void(int32 picture_buffer_id
)> ReusePictureCB
;
251 ThrottlingVDAClient(VideoDecodeAccelerator::Client
* client
,
253 ReusePictureCB reuse_picture_cb
);
254 virtual ~ThrottlingVDAClient();
256 // VideoDecodeAccelerator::Client implementation
257 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers
,
258 const gfx::Size
& dimensions
,
259 uint32 texture_target
) OVERRIDE
;
260 virtual void DismissPictureBuffer(int32 picture_buffer_id
) OVERRIDE
;
261 virtual void PictureReady(const media::Picture
& picture
) OVERRIDE
;
262 virtual void NotifyInitializeDone() OVERRIDE
;
263 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id
) OVERRIDE
;
264 virtual void NotifyFlushDone() OVERRIDE
;
265 virtual void NotifyResetDone() OVERRIDE
;
266 virtual void NotifyError(VideoDecodeAccelerator::Error error
) OVERRIDE
;
268 int num_decoded_frames() { return num_decoded_frames_
; }
272 void CallClientPictureReady(int version
);
274 VideoDecodeAccelerator::Client
* client_
;
275 ReusePictureCB reuse_picture_cb_
;
276 base::TimeTicks next_frame_delivered_time_
;
277 base::TimeDelta frame_duration_
;
279 int num_decoded_frames_
;
281 std::deque
<media::Picture
> pending_pictures_
;
283 DISALLOW_IMPLICIT_CONSTRUCTORS(ThrottlingVDAClient
);
286 ThrottlingVDAClient::ThrottlingVDAClient(VideoDecodeAccelerator::Client
* client
,
288 ReusePictureCB reuse_picture_cb
)
290 reuse_picture_cb_(reuse_picture_cb
),
291 num_decoded_frames_(0),
295 frame_duration_
= base::TimeDelta::FromSeconds(1) / fps
;
298 ThrottlingVDAClient::~ThrottlingVDAClient() {}
300 void ThrottlingVDAClient::ProvidePictureBuffers(uint32 requested_num_of_buffers
,
301 const gfx::Size
& dimensions
,
302 uint32 texture_target
) {
303 client_
->ProvidePictureBuffers(
304 requested_num_of_buffers
, dimensions
, texture_target
);
307 void ThrottlingVDAClient::DismissPictureBuffer(int32 picture_buffer_id
) {
308 client_
->DismissPictureBuffer(picture_buffer_id
);
311 void ThrottlingVDAClient::PictureReady(const media::Picture
& picture
) {
312 ++num_decoded_frames_
;
314 if (pending_pictures_
.empty()) {
315 base::TimeDelta delay
=
316 next_frame_delivered_time_
.is_null()
318 : next_frame_delivered_time_
- base::TimeTicks::Now();
319 base::MessageLoop::current()->PostDelayedTask(
321 base::Bind(&ThrottlingVDAClient::CallClientPictureReady
,
326 pending_pictures_
.push_back(picture
);
329 void ThrottlingVDAClient::CallClientPictureReady(int version
) {
330 // Just return if we have reset the decoder
331 if (version
!= stream_version_
)
334 base::TimeTicks now
= base::TimeTicks::Now();
336 if (next_frame_delivered_time_
.is_null())
337 next_frame_delivered_time_
= now
;
339 if (next_frame_delivered_time_
+ frame_duration_
< now
) {
340 // Too late, drop the frame
341 reuse_picture_cb_
.Run(pending_pictures_
.front().picture_buffer_id());
343 client_
->PictureReady(pending_pictures_
.front());
346 pending_pictures_
.pop_front();
347 next_frame_delivered_time_
+= frame_duration_
;
348 if (!pending_pictures_
.empty()) {
349 base::MessageLoop::current()->PostDelayedTask(
351 base::Bind(&ThrottlingVDAClient::CallClientPictureReady
,
354 next_frame_delivered_time_
- base::TimeTicks::Now());
358 void ThrottlingVDAClient::NotifyInitializeDone() {
359 client_
->NotifyInitializeDone();
362 void ThrottlingVDAClient::NotifyEndOfBitstreamBuffer(
363 int32 bitstream_buffer_id
) {
364 client_
->NotifyEndOfBitstreamBuffer(bitstream_buffer_id
);
367 void ThrottlingVDAClient::NotifyFlushDone() {
368 if (!pending_pictures_
.empty()) {
369 base::MessageLoop::current()->PostDelayedTask(
371 base::Bind(&ThrottlingVDAClient::NotifyFlushDone
,
372 base::Unretained(this)),
373 next_frame_delivered_time_
- base::TimeTicks::Now());
376 client_
->NotifyFlushDone();
379 void ThrottlingVDAClient::NotifyResetDone() {
381 while (!pending_pictures_
.empty()) {
382 reuse_picture_cb_
.Run(pending_pictures_
.front().picture_buffer_id());
383 pending_pictures_
.pop_front();
385 next_frame_delivered_time_
= base::TimeTicks();
386 client_
->NotifyResetDone();
389 void ThrottlingVDAClient::NotifyError(VideoDecodeAccelerator::Error error
) {
390 client_
->NotifyError(error
);
393 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by
395 class GLRenderingVDAClient
396 : public VideoDecodeAccelerator::Client
,
397 public base::SupportsWeakPtr
<GLRenderingVDAClient
> {
399 // Doesn't take ownership of |rendering_helper| or |note|, which must outlive
401 // |num_fragments_per_decode| counts NALUs for h264 and frames for VP8.
402 // |num_play_throughs| indicates how many times to play through the video.
403 // |reset_after_frame_num| can be a frame number >=0 indicating a mid-stream
404 // Reset() should be done after that frame number is delivered, or
405 // END_OF_STREAM_RESET to indicate no mid-stream Reset().
406 // |delete_decoder_state| indicates when the underlying decoder should be
407 // Destroy()'d and deleted and can take values: N<0: delete after -N Decode()
408 // calls have been made, N>=0 means interpret as ClientState.
409 // Both |reset_after_frame_num| & |delete_decoder_state| apply only to the
410 // last play-through (governed by |num_play_throughs|).
411 // |rendering_fps| indicates the target rendering fps. 0 means no target fps
412 // and it would render as fast as possible.
413 // |suppress_rendering| indicates GL rendering is suppressed or not.
414 // After |delay_reuse_after_frame_num| frame has been delivered, the client
415 // will start delaying the call to ReusePictureBuffer() for kReuseDelay.
416 GLRenderingVDAClient(RenderingHelper
* rendering_helper
,
417 int rendering_window_id
,
418 ClientStateNotification
<ClientState
>* note
,
419 const std::string
& encoded_data
,
420 int num_fragments_per_decode
,
421 int num_in_flight_decodes
,
422 int num_play_throughs
,
423 int reset_after_frame_num
,
424 int delete_decoder_state
,
428 double rendering_fps
,
429 bool suppress_rendering
,
430 int delay_reuse_after_frame_num
);
431 virtual ~GLRenderingVDAClient();
432 void CreateDecoder();
434 // VideoDecodeAccelerator::Client implementation.
435 // The heart of the Client.
436 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers
,
437 const gfx::Size
& dimensions
,
438 uint32 texture_target
) OVERRIDE
;
439 virtual void DismissPictureBuffer(int32 picture_buffer_id
) OVERRIDE
;
440 virtual void PictureReady(const media::Picture
& picture
) OVERRIDE
;
441 // Simple state changes.
442 virtual void NotifyInitializeDone() OVERRIDE
;
443 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id
) OVERRIDE
;
444 virtual void NotifyFlushDone() OVERRIDE
;
445 virtual void NotifyResetDone() OVERRIDE
;
446 virtual void NotifyError(VideoDecodeAccelerator::Error error
) OVERRIDE
;
448 void OutputFrameDeliveryTimes(base::PlatformFile output
);
450 void NotifyFrameDropped(int32 picture_buffer_id
);
452 // Simple getters for inspecting the state of the Client.
453 int num_done_bitstream_buffers() { return num_done_bitstream_buffers_
; }
454 int num_skipped_fragments() { return num_skipped_fragments_
; }
455 int num_queued_fragments() { return num_queued_fragments_
; }
456 int num_decoded_frames();
457 double frames_per_second();
458 bool decoder_deleted() { return !decoder_
.get(); }
461 typedef std::map
<int, media::PictureBuffer
*> PictureBufferById
;
463 void SetState(ClientState new_state
);
465 // Delete the associated decoder helper.
466 void DeleteDecoder();
468 // Compute & return the first encoded bytes (including a start frame) to send
469 // to the decoder, starting at |start_pos| and returning
470 // |num_fragments_per_decode| units. Skips to the first decodable position.
471 std::string
GetBytesForFirstFragments(size_t start_pos
, size_t* end_pos
);
472 // Compute & return the next encoded bytes to send to the decoder (based on
473 // |start_pos| & |num_fragments_per_decode_|).
474 std::string
GetBytesForNextFragments(size_t start_pos
, size_t* end_pos
);
475 // Helpers for GetRangeForNextFragments above.
476 void GetBytesForNextNALU(size_t start_pos
, size_t* end_pos
); // For h.264.
477 std::string
GetBytesForNextFrames(
478 size_t start_pos
, size_t* end_pos
); // For VP8.
480 // Request decode of the next batch of fragments in the encoded data.
481 void DecodeNextFragments();
483 RenderingHelper
* rendering_helper_
;
484 int rendering_window_id_
;
485 std::string encoded_data_
;
486 const int num_fragments_per_decode_
;
487 const int num_in_flight_decodes_
;
488 int outstanding_decodes_
;
489 size_t encoded_data_next_pos_to_decode_
;
490 int next_bitstream_buffer_id_
;
491 ClientStateNotification
<ClientState
>* note_
;
492 scoped_ptr
<VideoDecodeAccelerator
> decoder_
;
493 std::set
<int> outstanding_texture_ids_
;
494 int remaining_play_throughs_
;
495 int reset_after_frame_num_
;
496 int delete_decoder_state_
;
498 int num_skipped_fragments_
;
499 int num_queued_fragments_
;
500 int num_decoded_frames_
;
501 int num_done_bitstream_buffers_
;
502 PictureBufferById picture_buffers_by_id_
;
503 base::TimeTicks initialize_done_ticks_
;
505 bool suppress_rendering_
;
506 std::vector
<base::TimeTicks
> frame_delivery_times_
;
507 int delay_reuse_after_frame_num_
;
508 scoped_ptr
<ThrottlingVDAClient
> throttling_client_
;
510 DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient
);
513 GLRenderingVDAClient::GLRenderingVDAClient(
514 RenderingHelper
* rendering_helper
,
515 int rendering_window_id
,
516 ClientStateNotification
<ClientState
>* note
,
517 const std::string
& encoded_data
,
518 int num_fragments_per_decode
,
519 int num_in_flight_decodes
,
520 int num_play_throughs
,
521 int reset_after_frame_num
,
522 int delete_decoder_state
,
526 double rendering_fps
,
527 bool suppress_rendering
,
528 int delay_reuse_after_frame_num
)
529 : rendering_helper_(rendering_helper
),
530 rendering_window_id_(rendering_window_id
),
531 encoded_data_(encoded_data
),
532 num_fragments_per_decode_(num_fragments_per_decode
),
533 num_in_flight_decodes_(num_in_flight_decodes
),
534 outstanding_decodes_(0),
535 encoded_data_next_pos_to_decode_(0),
536 next_bitstream_buffer_id_(0),
538 remaining_play_throughs_(num_play_throughs
),
539 reset_after_frame_num_(reset_after_frame_num
),
540 delete_decoder_state_(delete_decoder_state
),
542 num_skipped_fragments_(0),
543 num_queued_fragments_(0),
544 num_decoded_frames_(0),
545 num_done_bitstream_buffers_(0),
547 suppress_rendering_(suppress_rendering
),
548 delay_reuse_after_frame_num_(delay_reuse_after_frame_num
) {
549 CHECK_GT(num_fragments_per_decode
, 0);
550 CHECK_GT(num_in_flight_decodes
, 0);
551 CHECK_GT(num_play_throughs
, 0);
552 CHECK_GE(rendering_fps
, 0);
553 if (rendering_fps
> 0)
554 throttling_client_
.reset(new ThrottlingVDAClient(
557 base::Bind(&GLRenderingVDAClient::NotifyFrameDropped
,
558 base::Unretained(this))));
561 GLRenderingVDAClient::~GLRenderingVDAClient() {
562 DeleteDecoder(); // Clean up in case of expected error.
563 CHECK(decoder_deleted());
564 STLDeleteValues(&picture_buffers_by_id_
);
565 SetState(CS_DESTROYED
);
568 static bool DoNothingReturnTrue() { return true; }
570 void GLRenderingVDAClient::CreateDecoder() {
571 CHECK(decoder_deleted());
572 CHECK(!decoder_
.get());
574 VideoDecodeAccelerator::Client
* client
= this;
575 base::WeakPtr
<VideoDecodeAccelerator::Client
> weak_client
= AsWeakPtr();
576 if (throttling_client_
) {
577 client
= throttling_client_
.get();
578 weak_client
= throttling_client_
->AsWeakPtr();
582 new DXVAVideoDecodeAccelerator(client
, base::Bind(&DoNothingReturnTrue
)));
583 #elif defined(OS_CHROMEOS)
584 #if defined(ARCH_CPU_ARMEL)
585 decoder_
.reset(new ExynosVideoDecodeAccelerator(
586 static_cast<EGLDisplay
>(rendering_helper_
->GetGLDisplay()),
587 static_cast<EGLContext
>(rendering_helper_
->GetGLContext()),
590 base::Bind(&DoNothingReturnTrue
),
591 base::MessageLoopProxy::current()));
592 #elif defined(ARCH_CPU_X86_FAMILY)
593 decoder_
.reset(new VaapiVideoDecodeAccelerator(
594 static_cast<Display
*>(rendering_helper_
->GetGLDisplay()),
595 static_cast<GLXContext
>(rendering_helper_
->GetGLContext()),
597 base::Bind(&DoNothingReturnTrue
)));
598 #endif // ARCH_CPU_ARMEL
600 CHECK(decoder_
.get());
601 SetState(CS_DECODER_SET
);
602 if (decoder_deleted())
605 // Configure the decoder.
606 media::VideoCodecProfile profile
= media::H264PROFILE_BASELINE
;
608 profile
= static_cast<media::VideoCodecProfile
>(profile_
);
609 CHECK(decoder_
->Initialize(profile
));
612 void GLRenderingVDAClient::ProvidePictureBuffers(
613 uint32 requested_num_of_buffers
,
614 const gfx::Size
& dimensions
,
615 uint32 texture_target
) {
616 if (decoder_deleted())
618 std::vector
<media::PictureBuffer
> buffers
;
620 for (uint32 i
= 0; i
< requested_num_of_buffers
; ++i
) {
621 uint32 id
= picture_buffers_by_id_
.size();
623 base::WaitableEvent
done(false, false);
624 rendering_helper_
->CreateTexture(
625 rendering_window_id_
, texture_target
, &texture_id
, &done
);
627 CHECK(outstanding_texture_ids_
.insert(texture_id
).second
);
628 media::PictureBuffer
* buffer
=
629 new media::PictureBuffer(id
, dimensions
, texture_id
);
630 CHECK(picture_buffers_by_id_
.insert(std::make_pair(id
, buffer
)).second
);
631 buffers
.push_back(*buffer
);
633 decoder_
->AssignPictureBuffers(buffers
);
636 void GLRenderingVDAClient::DismissPictureBuffer(int32 picture_buffer_id
) {
637 PictureBufferById::iterator it
=
638 picture_buffers_by_id_
.find(picture_buffer_id
);
639 CHECK(it
!= picture_buffers_by_id_
.end());
640 CHECK_EQ(outstanding_texture_ids_
.erase(it
->second
->texture_id()), 1U);
641 rendering_helper_
->DeleteTexture(it
->second
->texture_id());
643 picture_buffers_by_id_
.erase(it
);
646 void GLRenderingVDAClient::PictureReady(const media::Picture
& picture
) {
647 // We shouldn't be getting pictures delivered after Reset has completed.
648 CHECK_LT(state_
, CS_RESET
);
650 if (decoder_deleted())
653 frame_delivery_times_
.push_back(base::TimeTicks::Now());
655 CHECK_LE(picture
.bitstream_buffer_id(), next_bitstream_buffer_id_
);
656 ++num_decoded_frames_
;
658 // Mid-stream reset applies only to the last play-through per constructor
660 if (remaining_play_throughs_
== 1 &&
661 reset_after_frame_num_
== num_decoded_frames()) {
662 reset_after_frame_num_
= MID_STREAM_RESET
;
664 // Re-start decoding from the beginning of the stream to avoid needing to
665 // know how to find I-frames and so on in this test.
666 encoded_data_next_pos_to_decode_
= 0;
669 media::PictureBuffer
* picture_buffer
=
670 picture_buffers_by_id_
[picture
.picture_buffer_id()];
671 CHECK(picture_buffer
);
672 if (!suppress_rendering_
) {
673 rendering_helper_
->RenderTexture(picture_buffer
->texture_id());
676 if (num_decoded_frames() > delay_reuse_after_frame_num_
) {
677 base::MessageLoop::current()->PostDelayedTask(
679 base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer
,
680 decoder_
->AsWeakPtr(),
681 picture
.picture_buffer_id()),
684 decoder_
->ReusePictureBuffer(picture
.picture_buffer_id());
688 void GLRenderingVDAClient::NotifyInitializeDone() {
689 SetState(CS_INITIALIZED
);
690 initialize_done_ticks_
= base::TimeTicks::Now();
692 if (reset_after_frame_num_
== START_OF_STREAM_RESET
) {
697 for (int i
= 0; i
< num_in_flight_decodes_
; ++i
)
698 DecodeNextFragments();
699 DCHECK_EQ(outstanding_decodes_
, num_in_flight_decodes_
);
702 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer(
703 int32 bitstream_buffer_id
) {
704 // TODO(fischman): this test currently relies on this notification to make
705 // forward progress during a Reset(). But the VDA::Reset() API doesn't
706 // guarantee this, so stop relying on it (and remove the notifications from
707 // VaapiVideoDecodeAccelerator::FinishReset()).
708 ++num_done_bitstream_buffers_
;
709 --outstanding_decodes_
;
710 DecodeNextFragments();
713 void GLRenderingVDAClient::NotifyFlushDone() {
714 if (decoder_deleted())
716 SetState(CS_FLUSHED
);
717 --remaining_play_throughs_
;
718 DCHECK_GE(remaining_play_throughs_
, 0);
719 if (decoder_deleted())
722 SetState(CS_RESETTING
);
725 void GLRenderingVDAClient::NotifyResetDone() {
726 if (decoder_deleted())
729 if (reset_after_frame_num_
== MID_STREAM_RESET
) {
730 reset_after_frame_num_
= END_OF_STREAM_RESET
;
731 DecodeNextFragments();
733 } else if (reset_after_frame_num_
== START_OF_STREAM_RESET
) {
734 reset_after_frame_num_
= END_OF_STREAM_RESET
;
735 for (int i
= 0; i
< num_in_flight_decodes_
; ++i
)
736 DecodeNextFragments();
740 if (remaining_play_throughs_
) {
741 encoded_data_next_pos_to_decode_
= 0;
742 NotifyInitializeDone();
747 if (!decoder_deleted())
751 void GLRenderingVDAClient::NotifyError(VideoDecodeAccelerator::Error error
) {
755 void GLRenderingVDAClient::OutputFrameDeliveryTimes(base::PlatformFile output
) {
756 std::string s
= base::StringPrintf("frame count: %" PRIuS
"\n",
757 frame_delivery_times_
.size());
758 base::WritePlatformFileAtCurrentPos(output
, s
.data(), s
.length());
759 base::TimeTicks t0
= initialize_done_ticks_
;
760 for (size_t i
= 0; i
< frame_delivery_times_
.size(); ++i
) {
761 s
= base::StringPrintf("frame %04" PRIuS
": %" PRId64
" us\n",
763 (frame_delivery_times_
[i
] - t0
).InMicroseconds());
764 t0
= frame_delivery_times_
[i
];
765 base::WritePlatformFileAtCurrentPos(output
, s
.data(), s
.length());
769 void GLRenderingVDAClient::NotifyFrameDropped(int32 picture_buffer_id
) {
770 decoder_
->ReusePictureBuffer(picture_buffer_id
);
773 static bool LookingAtNAL(const std::string
& encoded
, size_t pos
) {
774 return encoded
[pos
] == 0 && encoded
[pos
+ 1] == 0 &&
775 encoded
[pos
+ 2] == 0 && encoded
[pos
+ 3] == 1;
778 void GLRenderingVDAClient::SetState(ClientState new_state
) {
779 note_
->Notify(new_state
);
781 if (!remaining_play_throughs_
&& new_state
== delete_decoder_state_
) {
782 CHECK(!decoder_deleted());
787 void GLRenderingVDAClient::DeleteDecoder() {
788 if (decoder_deleted())
790 decoder_
.release()->Destroy();
791 STLClearObject(&encoded_data_
);
792 for (std::set
<int>::iterator it
= outstanding_texture_ids_
.begin();
793 it
!= outstanding_texture_ids_
.end(); ++it
) {
794 rendering_helper_
->DeleteTexture(*it
);
796 outstanding_texture_ids_
.clear();
797 // Cascade through the rest of the states to simplify test code below.
798 for (int i
= state_
+ 1; i
< CS_MAX
; ++i
)
799 SetState(static_cast<ClientState
>(i
));
802 std::string
GLRenderingVDAClient::GetBytesForFirstFragments(
803 size_t start_pos
, size_t* end_pos
) {
804 if (profile_
< media::H264PROFILE_MAX
) {
805 *end_pos
= start_pos
;
806 while (*end_pos
+ 4 < encoded_data_
.size()) {
807 if ((encoded_data_
[*end_pos
+ 4] & 0x1f) == 0x7) // SPS start frame
808 return GetBytesForNextFragments(*end_pos
, end_pos
);
809 GetBytesForNextNALU(*end_pos
, end_pos
);
810 num_skipped_fragments_
++;
812 *end_pos
= start_pos
;
813 return std::string();
815 DCHECK_LE(profile_
, media::VP8PROFILE_MAX
);
816 return GetBytesForNextFragments(start_pos
, end_pos
);
819 std::string
GLRenderingVDAClient::GetBytesForNextFragments(
820 size_t start_pos
, size_t* end_pos
) {
821 if (profile_
< media::H264PROFILE_MAX
) {
822 size_t new_end_pos
= start_pos
;
823 *end_pos
= start_pos
;
824 for (int i
= 0; i
< num_fragments_per_decode_
; ++i
) {
825 GetBytesForNextNALU(*end_pos
, &new_end_pos
);
826 if (*end_pos
== new_end_pos
)
828 *end_pos
= new_end_pos
;
829 num_queued_fragments_
++;
831 return encoded_data_
.substr(start_pos
, *end_pos
- start_pos
);
833 DCHECK_LE(profile_
, media::VP8PROFILE_MAX
);
834 return GetBytesForNextFrames(start_pos
, end_pos
);
837 void GLRenderingVDAClient::GetBytesForNextNALU(
838 size_t start_pos
, size_t* end_pos
) {
839 *end_pos
= start_pos
;
840 if (*end_pos
+ 4 > encoded_data_
.size())
842 CHECK(LookingAtNAL(encoded_data_
, start_pos
));
844 while (*end_pos
+ 4 <= encoded_data_
.size() &&
845 !LookingAtNAL(encoded_data_
, *end_pos
)) {
848 if (*end_pos
+ 3 >= encoded_data_
.size())
849 *end_pos
= encoded_data_
.size();
852 std::string
GLRenderingVDAClient::GetBytesForNextFrames(
853 size_t start_pos
, size_t* end_pos
) {
854 // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF
857 start_pos
= 32; // Skip IVF header.
858 *end_pos
= start_pos
;
859 for (int i
= 0; i
< num_fragments_per_decode_
; ++i
) {
860 uint32 frame_size
= *reinterpret_cast<uint32
*>(&encoded_data_
[*end_pos
]);
861 *end_pos
+= 12; // Skip frame header.
862 bytes
.append(encoded_data_
.substr(*end_pos
, frame_size
));
863 *end_pos
+= frame_size
;
864 num_queued_fragments_
++;
865 if (*end_pos
+ 12 >= encoded_data_
.size())
871 void GLRenderingVDAClient::DecodeNextFragments() {
872 if (decoder_deleted())
874 if (encoded_data_next_pos_to_decode_
== encoded_data_
.size()) {
875 if (outstanding_decodes_
== 0) {
877 SetState(CS_FLUSHING
);
882 std::string next_fragment_bytes
;
883 if (encoded_data_next_pos_to_decode_
== 0) {
884 next_fragment_bytes
= GetBytesForFirstFragments(0, &end_pos
);
886 next_fragment_bytes
=
887 GetBytesForNextFragments(encoded_data_next_pos_to_decode_
, &end_pos
);
889 size_t next_fragment_size
= next_fragment_bytes
.size();
891 // Populate the shared memory buffer w/ the fragments, duplicate its handle,
892 // and hand it off to the decoder.
893 base::SharedMemory shm
;
894 CHECK(shm
.CreateAndMapAnonymous(next_fragment_size
));
895 memcpy(shm
.memory(), next_fragment_bytes
.data(), next_fragment_size
);
896 base::SharedMemoryHandle dup_handle
;
897 CHECK(shm
.ShareToProcess(base::Process::Current().handle(), &dup_handle
));
898 media::BitstreamBuffer
bitstream_buffer(
899 next_bitstream_buffer_id_
, dup_handle
, next_fragment_size
);
900 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer.
901 next_bitstream_buffer_id_
= (next_bitstream_buffer_id_
+ 1) & 0x3FFFFFFF;
902 decoder_
->Decode(bitstream_buffer
);
903 ++outstanding_decodes_
;
904 encoded_data_next_pos_to_decode_
= end_pos
;
906 if (!remaining_play_throughs_
&&
907 -delete_decoder_state_
== next_bitstream_buffer_id_
) {
912 int GLRenderingVDAClient::num_decoded_frames() {
913 return throttling_client_
? throttling_client_
->num_decoded_frames()
914 : num_decoded_frames_
;
917 double GLRenderingVDAClient::frames_per_second() {
918 base::TimeDelta delta
= frame_delivery_times_
.back() - initialize_done_ticks_
;
919 if (delta
.InSecondsF() == 0)
921 return num_decoded_frames() / delta
.InSecondsF();
925 // - Number of fragments per Decode() call.
926 // - Number of concurrent decoders.
927 // - Number of concurrent in-flight Decode() calls per decoder.
928 // - Number of play-throughs.
929 // - reset_after_frame_num: see GLRenderingVDAClient ctor.
930 // - delete_decoder_phase: see GLRenderingVDAClient ctor.
931 // - whether to test slow rendering by delaying ReusePictureBuffer().
932 // - whether the video frames are rendered as thumbnails.
933 class VideoDecodeAcceleratorTest
934 : public ::testing::TestWithParam
<
935 Tuple8
<int, int, int, int, ResetPoint
, ClientState
, bool, bool> > {
938 // Helper so that gtest failures emit a more readable version of the tuple than
939 // its byte representation.
940 ::std::ostream
& operator<<(
942 const Tuple8
<int, int, int, int, ResetPoint
, ClientState
, bool, bool>& t
) {
943 return os
<< t
.a
<< ", " << t
.b
<< ", " << t
.c
<< ", " << t
.d
<< ", " << t
.e
944 << ", " << t
.f
<< ", " << t
.g
<< ", " << t
.h
;
947 // Wait for |note| to report a state and if it's not |expected_state| then
948 // assert |client| has deleted its decoder.
949 static void AssertWaitForStateOrDeleted(
950 ClientStateNotification
<ClientState
>* note
,
951 GLRenderingVDAClient
* client
,
952 ClientState expected_state
) {
953 ClientState state
= note
->Wait();
954 if (state
== expected_state
) return;
955 ASSERT_TRUE(client
->decoder_deleted())
956 << "Decoder not deleted but Wait() returned " << state
957 << ", instead of " << expected_state
;
960 // We assert a minimal number of concurrent decoders we expect to succeed.
961 // Different platforms can support more concurrent decoders, so we don't assert
962 // failure above this.
963 enum { kMinSupportedNumConcurrentDecoders
= 3 };
965 // Test the most straightforward case possible: data is decoded from a single
966 // chunk and rendered to the screen.
967 TEST_P(VideoDecodeAcceleratorTest
, TestSimpleDecode
) {
968 // Required for Thread to work. Not used otherwise.
969 base::ShadowingAtExitManager at_exit_manager
;
971 const int num_fragments_per_decode
= GetParam().a
;
972 const size_t num_concurrent_decoders
= GetParam().b
;
973 const size_t num_in_flight_decodes
= GetParam().c
;
974 const int num_play_throughs
= GetParam().d
;
975 const int reset_point
= GetParam().e
;
976 const int delete_decoder_state
= GetParam().f
;
977 bool test_reuse_delay
= GetParam().g
;
978 const bool render_as_thumbnails
= GetParam().h
;
980 std::vector
<TestVideoFile
*> test_video_files
;
981 ParseAndReadTestVideoData(g_test_video_data
,
982 num_concurrent_decoders
,
986 // Suppress GL rendering for all tests when the "--disable_rendering" is set.
987 // Otherwise, suppress rendering in all but a few tests, to cut down overall
989 const bool suppress_rendering
=
990 num_fragments_per_decode
> 1 || g_disable_rendering
;
992 std::vector
<ClientStateNotification
<ClientState
>*>
993 notes(num_concurrent_decoders
, NULL
);
994 std::vector
<GLRenderingVDAClient
*> clients(num_concurrent_decoders
, NULL
);
996 // Initialize the rendering helper.
997 base::Thread
rendering_thread("GLRenderingVDAClientThread");
998 base::Thread::Options options
;
999 options
.message_loop_type
= base::MessageLoop::TYPE_DEFAULT
;
1001 // For windows the decoding thread initializes the media foundation decoder
1002 // which uses COM. We need the thread to be a UI thread.
1003 options
.message_loop_type
= base::MessageLoop::TYPE_UI
;
1006 rendering_thread
.StartWithOptions(options
);
1007 scoped_ptr
<RenderingHelper
> rendering_helper(RenderingHelper::Create());
1009 base::WaitableEvent
done(false, false);
1010 RenderingHelperParams helper_params
;
1011 helper_params
.num_windows
= num_concurrent_decoders
;
1012 helper_params
.render_as_thumbnails
= render_as_thumbnails
;
1013 if (render_as_thumbnails
) {
1014 // Only one decoder is supported with thumbnail rendering
1015 CHECK_EQ(num_concurrent_decoders
, 1U);
1016 gfx::Size
frame_size(test_video_files
[0]->width
,
1017 test_video_files
[0]->height
);
1018 helper_params
.frame_dimensions
.push_back(frame_size
);
1019 helper_params
.window_dimensions
.push_back(kThumbnailsDisplaySize
);
1020 helper_params
.thumbnails_page_size
= kThumbnailsPageSize
;
1021 helper_params
.thumbnail_size
= kThumbnailSize
;
1023 for (size_t index
= 0; index
< test_video_files
.size(); ++index
) {
1024 gfx::Size
frame_size(test_video_files
[index
]->width
,
1025 test_video_files
[index
]->height
);
1026 helper_params
.frame_dimensions
.push_back(frame_size
);
1027 helper_params
.window_dimensions
.push_back(frame_size
);
1030 rendering_thread
.message_loop()->PostTask(
1032 base::Bind(&RenderingHelper::Initialize
,
1033 base::Unretained(rendering_helper
.get()),
1038 // First kick off all the decoders.
1039 for (size_t index
= 0; index
< num_concurrent_decoders
; ++index
) {
1040 TestVideoFile
* video_file
=
1041 test_video_files
[index
% test_video_files
.size()];
1042 ClientStateNotification
<ClientState
>* note
=
1043 new ClientStateNotification
<ClientState
>();
1044 notes
[index
] = note
;
1046 int delay_after_frame_num
= std::numeric_limits
<int>::max();
1047 if (test_reuse_delay
&&
1048 kMaxFramesToDelayReuse
* 2 < video_file
->num_frames
) {
1049 delay_after_frame_num
= video_file
->num_frames
- kMaxFramesToDelayReuse
;
1052 GLRenderingVDAClient
* client
=
1053 new GLRenderingVDAClient(rendering_helper
.get(),
1056 video_file
->data_str
,
1057 num_fragments_per_decode
,
1058 num_in_flight_decodes
,
1060 video_file
->reset_after_frame_num
,
1061 delete_decoder_state
,
1064 video_file
->profile
,
1067 delay_after_frame_num
);
1068 clients
[index
] = client
;
1070 rendering_thread
.message_loop()->PostTask(
1072 base::Bind(&GLRenderingVDAClient::CreateDecoder
,
1073 base::Unretained(client
)));
1075 ASSERT_EQ(note
->Wait(), CS_DECODER_SET
);
1077 // Then wait for all the decodes to finish.
1078 // Only check performance & correctness later if we play through only once.
1079 bool skip_performance_and_correctness_checks
= num_play_throughs
> 1;
1080 for (size_t i
= 0; i
< num_concurrent_decoders
; ++i
) {
1081 ClientStateNotification
<ClientState
>* note
= notes
[i
];
1082 ClientState state
= note
->Wait();
1083 if (state
!= CS_INITIALIZED
) {
1084 skip_performance_and_correctness_checks
= true;
1085 // We expect initialization to fail only when more than the supported
1086 // number of decoders is instantiated. Assert here that something else
1087 // didn't trigger failure.
1088 ASSERT_GT(num_concurrent_decoders
,
1089 static_cast<size_t>(kMinSupportedNumConcurrentDecoders
));
1092 ASSERT_EQ(state
, CS_INITIALIZED
);
1093 for (int n
= 0; n
< num_play_throughs
; ++n
) {
1094 // For play-throughs other than the first, we expect initialization to
1095 // succeed unconditionally.
1097 ASSERT_NO_FATAL_FAILURE(
1098 AssertWaitForStateOrDeleted(note
, clients
[i
], CS_INITIALIZED
));
1100 // InitializeDone kicks off decoding inside the client, so we just need to
1102 ASSERT_NO_FATAL_FAILURE(
1103 AssertWaitForStateOrDeleted(note
, clients
[i
], CS_FLUSHING
));
1104 ASSERT_NO_FATAL_FAILURE(
1105 AssertWaitForStateOrDeleted(note
, clients
[i
], CS_FLUSHED
));
1106 // FlushDone requests Reset().
1107 ASSERT_NO_FATAL_FAILURE(
1108 AssertWaitForStateOrDeleted(note
, clients
[i
], CS_RESETTING
));
1110 ASSERT_NO_FATAL_FAILURE(
1111 AssertWaitForStateOrDeleted(note
, clients
[i
], CS_RESET
));
1112 // ResetDone requests Destroy().
1113 ASSERT_NO_FATAL_FAILURE(
1114 AssertWaitForStateOrDeleted(note
, clients
[i
], CS_DESTROYED
));
1116 // Finally assert that decoding went as expected.
1117 for (size_t i
= 0; i
< num_concurrent_decoders
&&
1118 !skip_performance_and_correctness_checks
; ++i
) {
1119 // We can only make performance/correctness assertions if the decoder was
1120 // allowed to finish.
1121 if (delete_decoder_state
< CS_FLUSHED
)
1123 GLRenderingVDAClient
* client
= clients
[i
];
1124 TestVideoFile
* video_file
= test_video_files
[i
% test_video_files
.size()];
1125 if (video_file
->num_frames
> 0) {
1126 // Expect the decoded frames may be more than the video frames as frames
1127 // could still be returned until resetting done.
1128 if (video_file
->reset_after_frame_num
> 0)
1129 EXPECT_GE(client
->num_decoded_frames(), video_file
->num_frames
);
1131 EXPECT_EQ(client
->num_decoded_frames(), video_file
->num_frames
);
1133 if (reset_point
== END_OF_STREAM_RESET
) {
1134 EXPECT_EQ(video_file
->num_fragments
, client
->num_skipped_fragments() +
1135 client
->num_queued_fragments());
1136 EXPECT_EQ(client
->num_done_bitstream_buffers(),
1137 ceil(static_cast<double>(client
->num_queued_fragments()) /
1138 num_fragments_per_decode
));
1140 LOG(INFO
) << "Decoder " << i
<< " fps: " << client
->frames_per_second();
1141 if (!render_as_thumbnails
) {
1142 int min_fps
= suppress_rendering
?
1143 video_file
->min_fps_no_render
: video_file
->min_fps_render
;
1144 if (min_fps
> 0 && !test_reuse_delay
)
1145 EXPECT_GT(client
->frames_per_second(), min_fps
);
1149 if (render_as_thumbnails
) {
1150 std::vector
<unsigned char> rgb
;
1152 rendering_thread
.message_loop()->PostTask(
1154 base::Bind(&RenderingHelper::GetThumbnailsAsRGB
,
1155 base::Unretained(rendering_helper
.get()),
1156 &rgb
, &alpha_solid
, &done
));
1159 std::vector
<std::string
> golden_md5s
;
1160 std::string md5_string
= base::MD5String(
1161 base::StringPiece(reinterpret_cast<char*>(&rgb
[0]), rgb
.size()));
1162 ReadGoldenThumbnailMD5s(test_video_files
[0], &golden_md5s
);
1163 std::vector
<std::string
>::iterator match
=
1164 find(golden_md5s
.begin(), golden_md5s
.end(), md5_string
);
1165 if (match
== golden_md5s
.end()) {
1166 // Convert raw RGB into PNG for export.
1167 std::vector
<unsigned char> png
;
1168 gfx::PNGCodec::Encode(&rgb
[0],
1169 gfx::PNGCodec::FORMAT_RGB
,
1170 kThumbnailsPageSize
,
1171 kThumbnailsPageSize
.width() * 3,
1173 std::vector
<gfx::PNGCodec::Comment
>(),
1176 LOG(ERROR
) << "Unknown thumbnails MD5: " << md5_string
;
1178 base::FilePath
filepath(test_video_files
[0]->file_name
);
1179 filepath
= filepath
.AddExtension(FILE_PATH_LITERAL(".bad_thumbnails"));
1180 filepath
= filepath
.AddExtension(FILE_PATH_LITERAL(".png"));
1181 int num_bytes
= file_util::WriteFile(filepath
,
1182 reinterpret_cast<char*>(&png
[0]),
1184 ASSERT_EQ(num_bytes
, static_cast<int>(png
.size()));
1186 ASSERT_NE(match
, golden_md5s
.end());
1187 EXPECT_EQ(alpha_solid
, true) << "RGBA frame had incorrect alpha";
1190 // Output the frame delivery time to file
1191 // We can only make performance/correctness assertions if the decoder was
1192 // allowed to finish.
1193 if (g_frame_delivery_log
!= NULL
&& delete_decoder_state
>= CS_FLUSHED
) {
1194 base::PlatformFile output_file
= base::CreatePlatformFile(
1195 base::FilePath(g_frame_delivery_log
),
1196 base::PLATFORM_FILE_CREATE_ALWAYS
| base::PLATFORM_FILE_WRITE
,
1199 for (size_t i
= 0; i
< num_concurrent_decoders
; ++i
) {
1200 clients
[i
]->OutputFrameDeliveryTimes(output_file
);
1202 base::ClosePlatformFile(output_file
);
1205 rendering_thread
.message_loop()->PostTask(
1207 base::Bind(&STLDeleteElements
<std::vector
<GLRenderingVDAClient
*> >,
1209 rendering_thread
.message_loop()->PostTask(
1211 base::Bind(&STLDeleteElements
<
1212 std::vector
<ClientStateNotification
<ClientState
>*> >,
1214 rendering_thread
.message_loop()->PostTask(
1216 base::Bind(&STLDeleteElements
<std::vector
<TestVideoFile
*> >,
1217 &test_video_files
));
1218 rendering_thread
.message_loop()->PostTask(
1220 base::Bind(&RenderingHelper::UnInitialize
,
1221 base::Unretained(rendering_helper
.get()),
1224 rendering_thread
.Stop();
1227 // Test that replay after EOS works fine.
1228 INSTANTIATE_TEST_CASE_P(
1229 ReplayAfterEOS
, VideoDecodeAcceleratorTest
,
1231 MakeTuple(1, 1, 1, 4, END_OF_STREAM_RESET
, CS_RESET
, false, false)));
1233 // This hangs on Exynos, preventing further testing and wasting test machine
1235 // TODO(ihf): Enable again once http://crbug.com/269754 is fixed.
1236 #if defined(ARCH_CPU_X86_FAMILY)
1237 // Test that Reset() before the first Decode() works fine.
1238 INSTANTIATE_TEST_CASE_P(
1239 ResetBeforeDecode
, VideoDecodeAcceleratorTest
,
1241 MakeTuple(1, 1, 1, 1, START_OF_STREAM_RESET
, CS_RESET
, false, false)));
1242 #endif // ARCH_CPU_X86_FAMILY
1244 // Test that Reset() mid-stream works fine and doesn't affect decoding even when
1245 // Decode() calls are made during the reset.
1246 INSTANTIATE_TEST_CASE_P(
1247 MidStreamReset
, VideoDecodeAcceleratorTest
,
1249 MakeTuple(1, 1, 1, 1, MID_STREAM_RESET
, CS_RESET
, false, false)));
1251 INSTANTIATE_TEST_CASE_P(
1252 SlowRendering
, VideoDecodeAcceleratorTest
,
1254 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, true, false)));
1256 // Test that Destroy() mid-stream works fine (primarily this is testing that no
1258 INSTANTIATE_TEST_CASE_P(
1259 TearDownTiming
, VideoDecodeAcceleratorTest
,
1261 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_DECODER_SET
, false,
1263 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_INITIALIZED
, false,
1265 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_FLUSHING
, false, false),
1266 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_FLUSHED
, false, false),
1267 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESETTING
, false, false),
1268 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1269 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
,
1270 static_cast<ClientState
>(-1), false, false),
1271 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
,
1272 static_cast<ClientState
>(-10), false, false),
1273 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
,
1274 static_cast<ClientState
>(-100), false, false)));
1276 // Test that decoding various variation works: multiple fragments per Decode()
1277 // call and multiple in-flight decodes.
1278 INSTANTIATE_TEST_CASE_P(
1279 DecodeVariations
, VideoDecodeAcceleratorTest
,
1281 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1282 MakeTuple(1, 1, 10, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1284 MakeTuple(1, 1, 15, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1285 MakeTuple(2, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1286 MakeTuple(3, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1287 MakeTuple(5, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1288 MakeTuple(8, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false),
1289 // TODO(fischman): decoding more than 15 NALUs at once breaks decode -
1290 // visual artifacts are introduced as well as spurious frames are
1291 // delivered (more pictures are returned than NALUs are fed to the
1292 // decoder). Increase the "15" below when
1293 // http://code.google.com/p/chrome-os-partner/issues/detail?id=4378 is
1295 MakeTuple(15, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, false)));
1297 // Find out how many concurrent decoders can go before we exhaust system
1299 INSTANTIATE_TEST_CASE_P(
1300 ResourceExhaustion
, VideoDecodeAcceleratorTest
,
1302 // +0 hack below to promote enum to int.
1303 MakeTuple(1, kMinSupportedNumConcurrentDecoders
+ 0, 1, 1,
1304 END_OF_STREAM_RESET
, CS_RESET
, false, false),
1305 MakeTuple(1, kMinSupportedNumConcurrentDecoders
+ 1, 1, 1,
1306 END_OF_STREAM_RESET
, CS_RESET
, false, false)));
1308 // Thumbnailing test
1309 INSTANTIATE_TEST_CASE_P(
1310 Thumbnail
, VideoDecodeAcceleratorTest
,
1312 MakeTuple(1, 1, 1, 1, END_OF_STREAM_RESET
, CS_RESET
, false, true)));
1314 // TODO(fischman, vrk): add more tests! In particular:
1315 // - Test life-cycle: Seek/Stop/Pause/Play for a single decoder.
1316 // - Test alternate configurations
1317 // - Test failure conditions.
1318 // - Test frame size changes mid-stream
1321 } // namespace content
1323 int main(int argc
, char **argv
) {
1324 testing::InitGoogleTest(&argc
, argv
); // Removes gtest-specific args.
1325 CommandLine::Init(argc
, argv
);
1327 // Needed to enable DVLOG through --vmodule.
1328 logging::LoggingSettings settings
;
1329 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
1330 settings
.dcheck_state
=
1331 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
;
1332 CHECK(logging::InitLogging(settings
));
1334 CommandLine
* cmd_line
= CommandLine::ForCurrentProcess();
1337 CommandLine::SwitchMap switches
= cmd_line
->GetSwitches();
1338 for (CommandLine::SwitchMap::const_iterator it
= switches
.begin();
1339 it
!= switches
.end(); ++it
) {
1340 if (it
->first
== "test_video_data") {
1341 content::g_test_video_data
= it
->second
.c_str();
1344 if (it
->first
== "frame_delivery_log") {
1345 content::g_frame_delivery_log
= it
->second
.c_str();
1348 if (it
->first
== "rendering_fps") {
1349 // On Windows, CommandLine::StringType is wstring. We need to convert
1350 // it to std::string first
1351 std::string
input(it
->second
.begin(), it
->second
.end());
1352 CHECK(base::StringToDouble(input
, &content::g_rendering_fps
));
1355 if (it
->first
== "disable_rendering") {
1356 content::g_disable_rendering
= true;
1359 if (it
->first
== "v" || it
->first
== "vmodule")
1361 LOG(FATAL
) << "Unexpected switch: " << it
->first
<< ":" << it
->second
;
1364 base::ShadowingAtExitManager at_exit_manager
;
1367 content::DXVAVideoDecodeAccelerator::PreSandboxInitialization();
1368 #elif defined(OS_CHROMEOS)
1369 #if defined(ARCH_CPU_ARMEL)
1370 content::ExynosVideoDecodeAccelerator::PreSandboxInitialization();
1371 #elif defined(ARCH_CPU_X86_FAMILY)
1372 content::VaapiWrapper::PreSandboxInitialization();
1373 #endif // ARCH_CPU_ARMEL
1374 #endif // OS_CHROMEOS
1376 return RUN_ALL_TESTS();