OMXClient.h revision 20111aa043c5f404472bc63b90bc5aad906b1101
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_CLIENT_H_ 18 19#define OMX_CLIENT_H_ 20 21#include <media/IOMX.h> 22 23#include <utils/KeyedVector.h> 24#include <utils/List.h> 25#include <utils/threads.h> 26 27namespace android { 28 29class OMXObserver { 30public: 31 OMXObserver(); 32 virtual ~OMXObserver(); 33 34 void postMessage(const omx_message &msg); 35 36protected: 37 virtual void onOMXMessage(const omx_message &msg) = 0; 38 39private: 40 friend class OMXClient; 41 42 pthread_t mThread; 43 Mutex mLock; 44 Condition mQueueNotEmpty; 45 List<omx_message> mQueue; 46 47 void start(); 48 void stop(); 49 50 static void *ThreadWrapper(void *me); 51 void threadEntry(); 52 53 OMXObserver(const OMXObserver &); 54 OMXObserver &operator=(const OMXObserver &); 55}; 56 57class OMXClient; 58 59class OMXClientReflector : public BnOMXObserver { 60public: 61 OMXClientReflector(OMXClient *client); 62 63 virtual void on_message(const omx_message &msg); 64 void reset(); 65 66private: 67 OMXClient *mClient; 68 69 OMXClientReflector(const OMXClientReflector &); 70 OMXClientReflector &operator=(const OMXClientReflector &); 71}; 72 73class OMXClient { 74public: 75 friend class OMXClientReflector; 76 77 OMXClient(); 78 ~OMXClient(); 79 80 status_t connect(); 81 void disconnect(); 82 83 sp<IOMX> interface() { 84 return mOMX; 85 } 86 87 status_t registerObserver(IOMX::node_id node, OMXObserver *observer); 88 void unregisterObserver(IOMX::node_id node); 89 90 status_t fillBuffer(IOMX::node_id node, IOMX::buffer_id buffer); 91 92 status_t emptyBuffer( 93 IOMX::node_id node, IOMX::buffer_id buffer, 94 OMX_U32 range_offset, OMX_U32 range_length, 95 OMX_U32 flags, OMX_TICKS timestamp); 96 97 status_t send_command( 98 IOMX::node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param); 99 100private: 101 sp<IOMX> mOMX; 102 103 int mSock; 104 Mutex mLock; 105 pthread_t mThread; 106 107 KeyedVector<IOMX::node_id, OMXObserver *> mObservers; 108 109 sp<OMXClientReflector> mReflector; 110 111#if IOMX_USES_SOCKETS 112 static void *ThreadWrapper(void *me); 113 void threadEntry(); 114#endif 115 116 bool onOMXMessage(const omx_message &msg); 117 118 OMXClient(const OMXClient &); 119 OMXClient &operator=(const OMXClient &); 120}; 121 122} // namespace android 123 124#endif // OMX_CLIENT_H_ 125