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/channel_layout.h"
11 #include "media/base/pipeline_status.h"
12 #include "media/base/sample_format.h"
13 #include "media/base/video_decoder_config.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "ui/gfx/size.h"
27 // Return a callback that expects to be run once.
28 base::Closure
NewExpectedClosure();
29 PipelineStatusCB
NewExpectedStatusCB(PipelineStatus status
);
31 // Helper class for running a message loop until a callback has run. Useful for
32 // testing classes that run on more than a single thread.
34 // Events are intended for single use and cannot be reset.
35 class WaitableMessageLoopEvent
{
37 WaitableMessageLoopEvent();
38 ~WaitableMessageLoopEvent();
40 // Returns a thread-safe closure that will signal |this| when executed.
41 base::Closure
GetClosure();
42 PipelineStatusCB
GetPipelineStatusCB();
44 // Runs the current message loop until |this| has been signaled.
46 // Fails the test if the timeout is reached.
49 // Runs the current message loop until |this| has been signaled and asserts
50 // that the |expected| status was received.
52 // Fails the test if the timeout is reached.
53 void RunAndWaitForStatus(PipelineStatus expected
);
56 void OnCallback(PipelineStatus status
);
59 base::MessageLoop
* message_loop_
;
61 PipelineStatus status_
;
63 DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent
);
66 // Provides pre-canned VideoDecoderConfig. These types are used for tests that
67 // don't care about detailed parameters of the config.
68 class TestVideoConfig
{
70 // Returns a configuration that is invalid.
71 static VideoDecoderConfig
Invalid();
73 static VideoDecoderConfig
Normal();
74 static VideoDecoderConfig
NormalEncrypted();
76 // Returns a configuration that is larger in dimensions than Normal().
77 static VideoDecoderConfig
Large();
78 static VideoDecoderConfig
LargeEncrypted();
80 // Returns coded size for Normal and Large config.
81 static gfx::Size
NormalCodedSize();
82 static gfx::Size
LargeCodedSize();
85 DISALLOW_IMPLICIT_CONSTRUCTORS(TestVideoConfig
);
88 // Create an AudioBuffer containing |frames| frames of data, where each sample
91 // For interleaved formats, each frame will have the data from |channels|
92 // channels interleaved. |start| and |increment| are used to specify the values
93 // for the samples. Since this is interleaved data, channel 0 data will be:
95 // |start| + |channels| * |increment|
96 // |start| + 2 * |channels| * |increment|, and so on.
97 // Data for subsequent channels is similar. No check is done that |format|
98 // requires data to be of type T, but it is verified that |format| is an
99 // interleaved format.
101 // For planar formats, there will be a block for each of |channel| channels.
102 // |start| and |increment| are used to specify the values for the samples, which
103 // are created in channel order. Since this is planar data, channel 0 data will
106 // |start| + |increment|
107 // |start| + 2 * |increment|, and so on.
108 // Data for channel 1 will follow where channel 0 ends. Subsequent channels are
109 // similar. No check is done that |format| requires data to be of type T, but it
110 // is verified that |format| is a planar format.
112 // |start_time| will be used as the start time for the samples. |duration| is
115 scoped_refptr
<AudioBuffer
> MakeAudioBuffer(SampleFormat format
,
116 ChannelLayout channel_layout
,
122 base::TimeDelta timestamp
,
123 base::TimeDelta duration
);
125 // Create a fake video DecoderBuffer for testing purpose. The buffer contains
126 // part of video decoder config info embedded so that the testing code can do
127 // some sanity check.
128 scoped_refptr
<DecoderBuffer
> CreateFakeVideoBufferForTest(
129 const VideoDecoderConfig
& config
,
130 base::TimeDelta timestamp
,
131 base::TimeDelta duration
);
133 // Verify if a fake video DecoderBuffer is valid.
134 bool VerifyFakeVideoBufferForTest(const scoped_refptr
<DecoderBuffer
>& buffer
,
135 const VideoDecoderConfig
& config
);
139 #endif // MEDIA_BASE_TEST_HELPERS_H_