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 <binder/MemoryDealer.h> 27 #include <android/hidl/allocator/1.0/IAllocator.h> 28 #include <android/hidl/memory/1.0/IMemory.h> 29 #include <OMX_Component.h> 30 31 namespace android { 32 33 class MemoryDealer; 34 35 struct Harness : public RefBase { 36 typedef hidl::memory::V1_0::IMemory TMemory; 37 typedef hardware::hidl_memory hidl_memory; 38 enum BufferFlags { 39 kBufferBusy = 1 40 }; 41 struct Buffer { 42 IOMX::buffer_id mID; 43 sp<IMemory> mMemory; 44 hidl_memory mHidlMemory; 45 uint32_t mFlags; 46 }; 47 48 Harness(); 49 50 status_t initCheck() const; 51 52 status_t dequeueMessageForNode(omx_message *msg, int64_t timeoutUs = -1); 53 54 status_t dequeueMessageForNodeIgnoringBuffers( 55 Vector<Buffer> *inputBuffers, 56 Vector<Buffer> *outputBuffers, 57 omx_message *msg, int64_t timeoutUs = -1); 58 59 status_t getPortDefinition( 60 OMX_U32 portIndex, OMX_PARAM_PORTDEFINITIONTYPE *def); 61 62 status_t allocatePortBuffers( 63 OMX_U32 portIndex, Vector<Buffer> *buffers); 64 65 status_t setRole(const char *role); 66 67 status_t testStateTransitions( 68 const char *componentName, const char *componentRole); 69 70 status_t testSeek( 71 const char *componentName, const char *componentRole); 72 73 status_t test( 74 const char *componentName, const char *componentRole); 75 76 status_t testAll(); 77 78 protected: 79 virtual ~Harness(); 80 81 private: 82 typedef hidl::allocator::V1_0::IAllocator IAllocator; 83 84 friend struct NodeReaper; 85 struct CodecObserver; 86 87 Mutex mLock; 88 89 status_t mInitCheck; 90 sp<IOMX> mOMX; 91 sp<IOMXNode> mOMXNode; 92 List<omx_message> mMessageQueue; 93 Condition mMessageAddedCondition; 94 int32_t mLastMsgGeneration; 95 int32_t mCurGeneration; 96 sp<IAllocator> mAllocator; 97 98 status_t initOMX(); 99 100 bool handleBufferMessage( 101 const omx_message &msg, 102 Vector<Buffer> *inputBuffers, 103 Vector<Buffer> *outputBuffers); 104 105 void handleMessages(int32_t gen, const std::list<omx_message> &messages); 106 107 Harness(const Harness &); 108 Harness &operator=(const Harness &); 109 }; 110 111 } // namespace android 112 113 #endif // OMX_HARNESS_H_ 114