OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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. | |
4 | |
5 #include "media/omx/mock_omx.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace media { | |
11 | |
12 MockOmx* MockOmx::instance_ = NULL; | |
13 | |
14 // Static stub methods. They redirect method calls back to the mock object. | |
15 static OMX_ERRORTYPE MockSendCommand(OMX_HANDLETYPE component, | |
16 OMX_COMMANDTYPE command, | |
17 OMX_U32 param1, | |
18 OMX_PTR command_data) { | |
19 CHECK(MockOmx::get()->component() == | |
20 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
21 return MockOmx::get()->SendCommand(command, param1, command_data); | |
22 } | |
23 | |
24 static OMX_ERRORTYPE MockGetParameter(OMX_HANDLETYPE component, | |
25 OMX_INDEXTYPE param_index, | |
26 OMX_PTR structure) { | |
27 CHECK(MockOmx::get()->component() == | |
28 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
29 return MockOmx::get()->GetParameter(param_index, structure); | |
30 } | |
31 | |
32 static OMX_ERRORTYPE MockSetParameter(OMX_HANDLETYPE component, | |
33 OMX_INDEXTYPE param_index, | |
34 OMX_PTR structure) { | |
35 CHECK(MockOmx::get()->component() == | |
36 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
37 return MockOmx::get()->SetParameter(param_index, structure); | |
38 } | |
39 | |
40 static OMX_ERRORTYPE MockGetConfig(OMX_HANDLETYPE component, | |
41 OMX_INDEXTYPE index, | |
42 OMX_PTR structure) { | |
43 CHECK(MockOmx::get()->component() == | |
44 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
45 return MockOmx::get()->GetConfig(index, structure); | |
46 } | |
47 | |
48 static OMX_ERRORTYPE MockSetConfig(OMX_HANDLETYPE component, | |
49 OMX_INDEXTYPE index, | |
50 OMX_PTR structure) { | |
51 CHECK(MockOmx::get()->component() == | |
52 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
53 return MockOmx::get()->SetConfig(index, structure); | |
54 } | |
55 | |
56 static OMX_ERRORTYPE MockAllocateBuffer(OMX_HANDLETYPE component, | |
57 OMX_BUFFERHEADERTYPE** buffer, | |
58 OMX_U32 port_index, | |
59 OMX_PTR app_private, | |
60 OMX_U32 size_bytes) { | |
61 CHECK(MockOmx::get()->component() == | |
62 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
63 return MockOmx::get()->AllocateBuffer(buffer, port_index, app_private, | |
64 size_bytes); | |
65 } | |
66 | |
67 static OMX_ERRORTYPE MockUseBuffer(OMX_HANDLETYPE component, | |
68 OMX_BUFFERHEADERTYPE** buffer, | |
69 OMX_U32 port_index, | |
70 OMX_PTR app_private, | |
71 OMX_U32 size_bytes, | |
72 OMX_U8* pBuffer) { | |
73 CHECK(MockOmx::get()->component() == | |
74 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
75 return MockOmx::get()->UseBuffer(buffer, port_index, app_private, | |
76 size_bytes, pBuffer); | |
77 } | |
78 | |
79 static OMX_ERRORTYPE MockFreeBuffer(OMX_HANDLETYPE component, | |
80 OMX_U32 port_index, | |
81 OMX_BUFFERHEADERTYPE* buffer) { | |
82 CHECK(MockOmx::get()->component() == | |
83 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
84 return MockOmx::get()->FreeBuffer(port_index, buffer); | |
85 } | |
86 | |
87 static OMX_ERRORTYPE MockEmptyThisBuffer(OMX_HANDLETYPE component, | |
88 OMX_BUFFERHEADERTYPE* buffer) { | |
89 CHECK(MockOmx::get()->component() == | |
90 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
91 return MockOmx::get()->EmptyThisBuffer(buffer); | |
92 } | |
93 | |
94 static OMX_ERRORTYPE MockFillThisBuffer(OMX_HANDLETYPE component, | |
95 OMX_BUFFERHEADERTYPE* buffer) { | |
96 CHECK(MockOmx::get()->component() == | |
97 reinterpret_cast<OMX_COMPONENTTYPE*>(component)); | |
98 return MockOmx::get()->FillThisBuffer(buffer); | |
99 } | |
100 | |
101 // Stub methods to export symbols used for OpenMAX. | |
102 extern "C" { | |
103 OMX_ERRORTYPE OMX_Init() { | |
104 return MockOmx::get()->Init(); | |
105 } | |
106 | |
107 OMX_ERRORTYPE OMX_Deinit() { | |
108 return MockOmx::get()->Deinit(); | |
109 } | |
110 | |
111 OMX_ERRORTYPE OMX_GetHandle( | |
112 OMX_HANDLETYPE* handle, OMX_STRING name, OMX_PTR app_private, | |
113 OMX_CALLBACKTYPE* callbacks) { | |
114 return MockOmx::get()->GetHandle(handle, name, app_private, callbacks); | |
115 } | |
116 | |
117 OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE handle) { | |
118 return MockOmx::get()->FreeHandle(handle); | |
119 } | |
120 | |
121 OMX_ERRORTYPE OMX_GetComponentsOfRole(OMX_STRING name, OMX_U32* roles, | |
122 OMX_U8** component_names) { | |
123 return MockOmx::get()->GetComponentsOfRole(name, roles, component_names); | |
124 } | |
125 } // extern "C" | |
126 | |
127 MockOmx::MockOmx() { | |
128 memset(&callbacks_, 0, sizeof(callbacks_)); | |
129 memset(&component_, 0, sizeof(component_)); | |
130 | |
131 // Setup the function pointers to the static methods. They will redirect back | |
132 // to this mock object. | |
133 component_.SendCommand = &MockSendCommand; | |
134 component_.GetParameter = &MockGetParameter; | |
135 component_.SetParameter = &MockSetParameter; | |
136 component_.GetConfig = &MockGetConfig; | |
137 component_.SetConfig = &MockSetConfig; | |
138 component_.AllocateBuffer = &MockAllocateBuffer; | |
139 component_.UseBuffer = &MockUseBuffer; | |
140 component_.FreeBuffer = &MockFreeBuffer; | |
141 component_.EmptyThisBuffer = &MockEmptyThisBuffer; | |
142 component_.FillThisBuffer = &MockFillThisBuffer; | |
143 | |
144 // Save this instance to static member. | |
145 CHECK(!instance_); | |
146 instance_ = this; | |
147 } | |
148 | |
149 MockOmx::~MockOmx() { | |
150 CHECK(instance_); | |
151 instance_ = NULL; | |
152 } | |
153 | |
154 // static | |
155 MockOmx* MockOmx::get() { | |
156 return instance_; | |
157 } | |
158 | |
159 } // namespace media | |
OLD | NEW |