1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef OMX_HARNESS_H_ 18 19 #define OMX_HARNESS_H_ 20 21 #include <media/IOMX.h> 22 #include <utils/List.h> 23 #include <utils/Vector.h> 24 #include <utils/threads.h> 25 26 #include <OMX_Component.h> 27 28 namespace android { 29 30 class MemoryDealer; 31 32 struct Harness : public BnOMXObserver { 33 enum BufferFlags { 34 kBufferBusy = 1 35 }; 36 struct Buffer { 37 IOMX::buffer_id mID; 38 sp<IMemory> mMemory; 39 uint32_t mFlags; 40 }; 41 42 Harness(); 43 44 status_t initCheck() const; 45 46 status_t dequeueMessageForNode( 47 IOMX::node_id node, omx_message *msg, int64_t timeoutUs = -1); 48 49 status_t dequeueMessageForNodeIgnoringBuffers( 50 IOMX::node_id node, 51 Vector<Buffer> *inputBuffers, 52 Vector<Buffer> *outputBuffers, 53 omx_message *msg, int64_t timeoutUs = -1); 54 55 status_t getPortDefinition( 56 IOMX::node_id node, OMX_U32 portIndex, 57 OMX_PARAM_PORTDEFINITIONTYPE *def); 58 59 status_t allocatePortBuffers( 60 const sp<MemoryDealer> &dealer, 61 IOMX::node_id node, OMX_U32 portIndex, 62 Vector<Buffer> *buffers); 63 64 status_t setRole(IOMX::node_id node, const char *role); 65 66 status_t testStateTransitions( 67 const char *componentName, const char *componentRole); 68 69 status_t testSeek( 70 const char *componentName, const char *componentRole); 71 72 status_t test( 73 const char *componentName, const char *componentRole); 74 75 status_t testAll(); 76 77 virtual void onMessages(const std::list<omx_message> &messages); 78 79 protected: 80 virtual ~Harness(); 81 82 private: 83 friend struct NodeReaper; 84 85 Mutex mLock; 86 87 status_t mInitCheck; 88 sp<IOMX> mOMX; 89 List<omx_message> mMessageQueue; 90 Condition mMessageAddedCondition; 91 92 status_t initOMX(); 93 94 bool handleBufferMessage( 95 const omx_message &msg, 96 Vector<Buffer> *inputBuffers, 97 Vector<Buffer> *outputBuffers); 98 99 Harness(const Harness &); 100 Harness &operator=(const Harness &); 101 }; 102 103 } // namespace android 104 105 #endif // OMX_HARNESS_H_ 106