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 #ifndef MEDIA_BASE_TEST_HELPERS_H_
6 #define MEDIA_BASE_TEST_HELPERS_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "media/base/pipeline_status.h"
11 #include "media/base/sample_format.h"
12 #include "media/base/video_decoder_config.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "ui/gfx/size.h"
26 // Return a callback that expects to be run once.
27 base::Closure
NewExpectedClosure();
28 PipelineStatusCB
NewExpectedStatusCB(PipelineStatus status
);
30 // Helper class for running a message loop until a callback has run. Useful for
31 // testing classes that run on more than a single thread.
33 // Events are intended for single use and cannot be reset.
34 class WaitableMessageLoopEvent
{
36 WaitableMessageLoopEvent();
37 ~WaitableMessageLoopEvent();
39 // Returns a thread-safe closure that will signal |this| when executed.
40 base::Closure
GetClosure();
41 PipelineStatusCB
GetPipelineStatusCB();
43 // Runs the current message loop until |this| has been signaled.
45 // Fails the test if the timeout is reached.
48 // Runs the current message loop until |this| has been signaled and asserts
49 // that the |expected| status was received.
51 // Fails the test if the timeout is reached.
52 void RunAndWaitForStatus(PipelineStatus expected
);
55 void OnCallback(PipelineStatus status
);
58 base::MessageLoop
* message_loop_
;
60 PipelineStatus status_
;
62 DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent
);
65 // Provides pre-canned VideoDecoderConfig. These types are used for tests that
66 // don't care about detailed parameters of the config.
67 class TestVideoConfig
{
69 // Returns a configuration that is invalid.
70 static VideoDecoderConfig
Invalid();
72 static VideoDecoderConfig
Normal();
73 static VideoDecoderConfig
NormalEncrypted();
75 // Returns a configuration that is larger in dimensions than Normal().
76 static VideoDecoderConfig
Large();
77 static VideoDecoderConfig
LargeEncrypted();
79 // Returns coded size for Normal and Large config.
80 static gfx::Size
NormalCodedSize();
81 static gfx::Size
LargeCodedSize();
84 DISALLOW_IMPLICIT_CONSTRUCTORS(TestVideoConfig
);
87 // Create an AudioBuffer containing |frames| frames of data, where each sample
88 // is of type T. Each frame will have the data from |channels| channels
89 // interleaved. |start| and |increment| are used to specify the values for the
90 // samples. Since this is interleaved data, channel 0 data will be:
92 // |start| + |channels| * |increment|
93 // |start| + 2 * |channels| * |increment|, and so on.
94 // Data for subsequent channels is similar. No check is done that |format|
95 // requires data to be of type T, but it is verified that |format| is an
96 // interleaved format.
98 // |start_time| will be used as the start time for the samples. |duration| is
101 scoped_refptr
<AudioBuffer
> MakeInterleavedAudioBuffer(
107 base::TimeDelta start_time
,
108 base::TimeDelta duration
);
110 // Create an AudioBuffer containing |frames| frames of data, where each sample
111 // is of type T. Since this is planar data, there will be a block for each of
112 // |channel| channels. |start| and |increment| are used to specify the values
113 // for the samples, which are created in channel order. Since this is planar
114 // data, channel 0 data will be:
116 // |start| + |increment|
117 // |start| + 2 * |increment|, and so on.
118 // Data for channel 1 will follow where channel 0 ends. Subsequent channels are
119 // similar. No check is done that |format| requires data to be of type T, but it
120 // is verified that |format| is a planar format.
122 // |start_time| will be used as the start time for the samples. |duration| is
125 scoped_refptr
<AudioBuffer
> MakePlanarAudioBuffer(
131 base::TimeDelta start_time
,
132 base::TimeDelta duration
);
134 // Create a fake video DecoderBuffer for testing purpose. The buffer contains
135 // part of video decoder config info embedded so that the testing code can do
136 // some sanity check.
137 scoped_refptr
<DecoderBuffer
> CreateFakeVideoBufferForTest(
138 const VideoDecoderConfig
& config
,
139 base::TimeDelta timestamp
,
140 base::TimeDelta duration
);
142 // Verify if a fake video DecoderBuffer is valid.
143 bool VerifyFakeVideoBufferForTest(const scoped_refptr
<DecoderBuffer
>& buffer
,
144 const VideoDecoderConfig
& config
);
148 #endif // MEDIA_BASE_TEST_HELPERS_H_