diff options
-rw-r--r-- | include/media/IOMX.h | 18 | ||||
-rw-r--r-- | include/media/stagefright/OMXClient.h | 18 | ||||
-rw-r--r-- | media/libmedia/IOMX.cpp | 43 | ||||
-rw-r--r-- | media/libstagefright/OMXClient.cpp | 156 | ||||
-rw-r--r-- | media/libstagefright/OMXDecoder.cpp | 24 | ||||
-rw-r--r-- | media/libstagefright/omx/OMX.cpp | 172 | ||||
-rw-r--r-- | media/libstagefright/omx/OMX.h | 17 |
7 files changed, 15 insertions, 433 deletions
diff --git a/include/media/IOMX.h b/include/media/IOMX.h index 0010d84..857b2bd 100644 --- a/include/media/IOMX.h +++ b/include/media/IOMX.h @@ -25,8 +25,6 @@ #include <OMX_Core.h> #include <OMX_Video.h> -#define IOMX_USES_SOCKETS 0 - namespace android { class IMemory; @@ -41,12 +39,6 @@ public: typedef void *buffer_id; typedef void *node_id; -#if IOMX_USES_SOCKETS - // If successful, returns a socket descriptor used for further - // communication. Caller assumes ownership of "*sd". - virtual status_t connect(int *sd) = 0; -#endif - virtual status_t list_nodes(List<String8> *list) = 0; virtual status_t allocate_node(const char *name, node_id *node) = 0; @@ -78,7 +70,6 @@ public: virtual status_t free_buffer( node_id node, OMX_U32 port_index, buffer_id buffer) = 0; -#if !IOMX_USES_SOCKETS virtual status_t observe_node( node_id node, const sp<IOMXObserver> &observer) = 0; @@ -89,7 +80,6 @@ public: buffer_id buffer, OMX_U32 range_offset, OMX_U32 range_length, OMX_U32 flags, OMX_TICKS timestamp) = 0; -#endif virtual sp<IOMXRenderer> createRenderer( const sp<ISurface> &surface, @@ -105,14 +95,6 @@ struct omx_message { EMPTY_BUFFER_DONE, FILL_BUFFER_DONE, -#if IOMX_USES_SOCKETS - EMPTY_BUFFER, - FILL_BUFFER, - SEND_COMMAND, - DISCONNECT, - DISCONNECTED, -#endif - // reserved for OMXDecoder use. START, INITIAL_FILL_BUFFER, diff --git a/include/media/stagefright/OMXClient.h b/include/media/stagefright/OMXClient.h index 454c38b..7027e1b 100644 --- a/include/media/stagefright/OMXClient.h +++ b/include/media/stagefright/OMXClient.h @@ -87,32 +87,14 @@ public: status_t registerObserver(IOMX::node_id node, OMXObserver *observer); void unregisterObserver(IOMX::node_id node); - status_t fillBuffer(IOMX::node_id node, IOMX::buffer_id buffer); - - status_t emptyBuffer( - IOMX::node_id node, IOMX::buffer_id buffer, - OMX_U32 range_offset, OMX_U32 range_length, - OMX_U32 flags, OMX_TICKS timestamp); - - status_t send_command( - IOMX::node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param); - private: sp<IOMX> mOMX; - - int mSock; Mutex mLock; - pthread_t mThread; KeyedVector<IOMX::node_id, OMXObserver *> mObservers; sp<OMXClientReflector> mReflector; -#if IOMX_USES_SOCKETS - static void *ThreadWrapper(void *me); - void threadEntry(); -#endif - bool onOMXMessage(const omx_message &msg); OMXClient(const OMXClient &); diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp index 4661af6..b0f466b 100644 --- a/media/libmedia/IOMX.cpp +++ b/media/libmedia/IOMX.cpp @@ -45,23 +45,6 @@ public: : BpInterface<IOMX>(impl) { } -#if IOMX_USES_SOCKETS - virtual status_t connect(int *sd) { - Parcel data, reply; - data.writeInterfaceToken(IOMX::getInterfaceDescriptor()); - remote()->transact(CONNECT, data, &reply); - - status_t err = reply.readInt32(); - if (err == OK) { - *sd = dup(reply.readFileDescriptor()); - } else { - *sd = -1; - } - - return reply.readInt32(); - } -#endif - virtual status_t list_nodes(List<String8> *list) { list->clear(); @@ -229,7 +212,6 @@ public: return reply.readInt32(); } -#if !IOMX_USES_SOCKETS virtual status_t observe_node( node_id node, const sp<IOMXObserver> &observer) { Parcel data, reply; @@ -264,7 +246,6 @@ public: data.writeInt64(timestamp); remote()->transact(EMPTY_BUFFER, data, &reply, IBinder::FLAG_ONEWAY); } -#endif virtual sp<IOMXRenderer> createRenderer( const sp<ISurface> &surface, @@ -302,28 +283,6 @@ IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX"); status_t BnOMX::onTransact( uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { switch (code) { -#if IOMX_USES_SOCKETS - case CONNECT: - { - CHECK_INTERFACE(IOMX, data, reply); - - int s; - status_t err = connect(&s); - - reply->writeInt32(err); - if (err == OK) { - assert(s >= 0); - reply->writeDupFileDescriptor(s); - close(s); - s = -1; - } else { - assert(s == -1); - } - - return NO_ERROR; - } -#endif - case LIST_NODES: { CHECK_INTERFACE(IOMX, data, reply); @@ -495,7 +454,6 @@ status_t BnOMX::onTransact( return NO_ERROR; } -#if !IOMX_USES_SOCKETS case OBSERVE_NODE: { CHECK_INTERFACE(IOMX, data, reply); @@ -536,7 +494,6 @@ status_t BnOMX::onTransact( return NO_ERROR; } -#endif case CREATE_RENDERER: { diff --git a/media/libstagefright/OMXClient.cpp b/media/libstagefright/OMXClient.cpp index 1bc8a44..3e7cf3c 100644 --- a/media/libstagefright/OMXClient.cpp +++ b/media/libstagefright/OMXClient.cpp @@ -30,8 +30,7 @@ namespace android { -OMXClient::OMXClient() - : mSock(-1) { +OMXClient::OMXClient() { } OMXClient::~OMXClient() { @@ -41,10 +40,6 @@ OMXClient::~OMXClient() { status_t OMXClient::connect() { Mutex::Autolock autoLock(mLock); - if (mSock >= 0) { - return UNKNOWN_ERROR; - } - sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->getService(String16("media.player")); sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); @@ -54,152 +49,22 @@ status_t OMXClient::connect() { mOMX = service->createOMX(); assert(mOMX.get() != NULL); -#if IOMX_USES_SOCKETS - status_t result = mOMX->connect(&mSock); - if (result != OK) { - mSock = -1; - - mOMX = NULL; - return result; - } - - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - int err = pthread_create(&mThread, &attr, ThreadWrapper, this); - assert(err == 0); - - pthread_attr_destroy(&attr); -#else mReflector = new OMXClientReflector(this); -#endif return OK; } void OMXClient::disconnect() { - { - Mutex::Autolock autoLock(mLock); - - if (mSock < 0) { - return; - } + Mutex::Autolock autoLock(mLock); - assert(mObservers.isEmpty()); + if (mReflector.get() != NULL) { + return; } -#if IOMX_USES_SOCKETS - omx_message msg; - msg.type = omx_message::DISCONNECT; - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); + assert(mObservers.isEmpty()); - void *dummy; - pthread_join(mThread, &dummy); -#else mReflector->reset(); mReflector.clear(); -#endif -} - -#if IOMX_USES_SOCKETS -// static -void *OMXClient::ThreadWrapper(void *me) { - ((OMXClient *)me)->threadEntry(); - - return NULL; -} - -void OMXClient::threadEntry() { - bool done = false; - while (!done) { - omx_message msg; - ssize_t n = recv(mSock, &msg, sizeof(msg), 0); - - if (n <= 0) { - break; - } - - done = onOMXMessage(msg); - } - - Mutex::Autolock autoLock(mLock); - close(mSock); - mSock = -1; -} -#endif - -status_t OMXClient::fillBuffer(IOMX::node_id node, IOMX::buffer_id buffer) { -#if !IOMX_USES_SOCKETS - mOMX->fill_buffer(node, buffer); -#else - if (mSock < 0) { - return UNKNOWN_ERROR; - } - - omx_message msg; - msg.type = omx_message::FILL_BUFFER; - msg.u.buffer_data.node = node; - msg.u.buffer_data.buffer = buffer; - - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); -#endif - - return OK; -} - -status_t OMXClient::emptyBuffer( - IOMX::node_id node, IOMX::buffer_id buffer, - OMX_U32 range_offset, OMX_U32 range_length, - OMX_U32 flags, OMX_TICKS timestamp) { -#if !IOMX_USES_SOCKETS - mOMX->empty_buffer( - node, buffer, range_offset, range_length, flags, timestamp); -#else - if (mSock < 0) { - return UNKNOWN_ERROR; - } - - // XXX I don't like all this copying... - - omx_message msg; - msg.type = omx_message::EMPTY_BUFFER; - msg.u.extended_buffer_data.node = node; - msg.u.extended_buffer_data.buffer = buffer; - msg.u.extended_buffer_data.range_offset = range_offset; - msg.u.extended_buffer_data.range_length = range_length; - msg.u.extended_buffer_data.flags = flags; - msg.u.extended_buffer_data.timestamp = timestamp; - - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); -#endif - - return OK; -} - -status_t OMXClient::send_command( - IOMX::node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) { -#if !IOMX_USES_SOCKETS - return mOMX->send_command(node, cmd, param); -#else - if (mSock < 0) { - return UNKNOWN_ERROR; - } - - omx_message msg; - msg.type = omx_message::SEND_COMMAND; - msg.u.send_command_data.node = node; - msg.u.send_command_data.cmd = cmd; - msg.u.send_command_data.param = param; - - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); -#endif - - return OK; } status_t OMXClient::registerObserver( @@ -214,9 +79,7 @@ status_t OMXClient::registerObserver( mObservers.add(node, observer); observer->start(); -#if !IOMX_USES_SOCKETS mOMX->observe_node(node, mReflector); -#endif return OK; } @@ -263,15 +126,6 @@ bool OMXClient::onOMXMessage(const omx_message &msg) { break; } -#if IOMX_USES_SOCKETS - case omx_message::DISCONNECTED: - { - LOGV("Disconnected"); - done = true; - break; - } -#endif - default: LOGE("received unknown omx_message type %d", msg.type); break; diff --git a/media/libstagefright/OMXDecoder.cpp b/media/libstagefright/OMXDecoder.cpp index c570278..a00872f 100644 --- a/media/libstagefright/OMXDecoder.cpp +++ b/media/libstagefright/OMXDecoder.cpp @@ -1041,8 +1041,7 @@ void OMXDecoder::onEventCmdComplete(OMX_COMMANDTYPE type, OMX_U32 data) { IOMX::buffer_id buffer = *obuffers->begin(); obuffers->erase(obuffers->begin()); - status_t err = mClient->fillBuffer(mNode, buffer); - assert(err == NO_ERROR); + mOMX->fill_buffer(mNode, buffer); } break; @@ -1178,7 +1177,7 @@ void OMXDecoder::onStateChanged(OMX_STATETYPE to) { LOGV("Executing->Idle complete, initiating Idle->Loaded"); status_t err = - mClient->send_command(mNode, OMX_CommandStateSet, OMX_StateLoaded); + mOMX->send_command(mNode, OMX_CommandStateSet, OMX_StateLoaded); assert(err == NO_ERROR); freePortBuffers(kPortIndexInput); @@ -1215,7 +1214,7 @@ void OMXDecoder::initiateShutdown() { setPortStatus(kPortIndexInput, kPortStatusFlushingToShutdown); setPortStatus(kPortIndexOutput, kPortStatusFlushingToShutdown); } else { - err = mClient->send_command( + err = mOMX->send_command( mNode, OMX_CommandStateSet, OMX_StateIdle); setPortStatus(kPortIndexInput, kPortStatusShutdown); @@ -1300,14 +1299,14 @@ void OMXDecoder::onFillBufferDone(const omx_message &msg) { default: { if (msg.type == omx_message::INITIAL_FILL_BUFFER) { - err = mClient->fillBuffer(mNode, buffer); + mOMX->fill_buffer(mNode, buffer); } else { LOGV("[%s] Filled OUTPUT buffer %p, flags=0x%08lx.", mComponentName, buffer, msg.u.extended_buffer_data.flags); onRealFillBufferDone(msg); - err = NO_ERROR; } + err = NO_ERROR; break; } } @@ -1348,13 +1347,11 @@ void OMXDecoder::onRealEmptyBufferDone(IOMX::buffer_id buffer) { ++mCodecSpecificDataIterator; - status_t err = mClient->emptyBuffer( + mOMX->empty_buffer( mNode, buffer, 0, range_length, OMX_BUFFERFLAG_ENDOFFRAME | OMX_BUFFERFLAG_CODECCONFIG, 0); - assert(err == NO_ERROR); - return; } @@ -1385,10 +1382,9 @@ void OMXDecoder::onRealEmptyBufferDone(IOMX::buffer_id buffer) { } if (err != OK) { - status_t err2 = mClient->emptyBuffer( + mOMX->empty_buffer( mNode, buffer, 0, 0, OMX_BUFFERFLAG_EOS, 0); - assert(err2 == NO_ERROR); return; } @@ -1452,9 +1448,8 @@ void OMXDecoder::onRealEmptyBufferDone(IOMX::buffer_id buffer) { LOGV("[%s] Calling EmptyBuffer on buffer %p size:%d flags:0x%08lx", mComponentName, buffer, src_length, flags); - status_t err2 = mClient->emptyBuffer( + mOMX->empty_buffer( mNode, buffer, 0, src_length, flags, timestamp); - assert(err2 == OK); } void OMXDecoder::onRealFillBufferDone(const omx_message &msg) { @@ -1517,8 +1512,7 @@ void OMXDecoder::signalBufferReturned(MediaBuffer *_buffer) { } else { LOGV("[%s] Calling FillBuffer on buffer %p.", mComponentName, buffer); - status_t err = mClient->fillBuffer(mNode, buffer); - assert(err == NO_ERROR); + mOMX->fill_buffer(mNode, buffer); } } diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp index 062afd4..d44e3a3 100644 --- a/media/libstagefright/omx/OMX.cpp +++ b/media/libstagefright/omx/OMX.cpp @@ -154,151 +154,9 @@ OMX_ERRORTYPE OMX::OnFillBufferDone( return meta->owner()->OnFillBufferDone(meta, pBuffer); } -OMX::OMX() -#if IOMX_USES_SOCKETS - : mSock(-1) -#endif -{ +OMX::OMX() { } -OMX::~OMX() { -#if IOMX_USES_SOCKETS - assert(mSock < 0); -#endif -} - -#if IOMX_USES_SOCKETS -status_t OMX::connect(int *sd) { - Mutex::Autolock autoLock(mLock); - - if (mSock >= 0) { - return UNKNOWN_ERROR; - } - - int sockets[2]; - if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) < 0) { - return UNKNOWN_ERROR; - } - - mSock = sockets[0]; - *sd = sockets[1]; - - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - int err = pthread_create(&mThread, &attr, ThreadWrapper, this); - assert(err == 0); - - pthread_attr_destroy(&attr); - - return OK; -} - -// static -void *OMX::ThreadWrapper(void *me) { - ((OMX *)me)->threadEntry(); - - return NULL; -} - -void OMX::threadEntry() { - bool done = false; - while (!done) { - omx_message msg; - ssize_t n = recv(mSock, &msg, sizeof(msg), 0); - - if (n <= 0) { - break; - } - - Mutex::Autolock autoLock(mLock); - - switch (msg.type) { - case omx_message::FILL_BUFFER: - { - OMX_BUFFERHEADERTYPE *header = - static_cast<OMX_BUFFERHEADERTYPE *>( - msg.u.buffer_data.buffer); - - header->nFilledLen = 0; - header->nOffset = 0; - header->hMarkTargetComponent = NULL; - header->nFlags = 0; - - NodeMeta *node_meta = static_cast<NodeMeta *>( - msg.u.buffer_data.node); - - LOGV("FillThisBuffer buffer=%p", header); - - OMX_ERRORTYPE err = - OMX_FillThisBuffer(node_meta->handle(), header); - assert(err == OMX_ErrorNone); - break; - } - - case omx_message::EMPTY_BUFFER: - { - OMX_BUFFERHEADERTYPE *header = - static_cast<OMX_BUFFERHEADERTYPE *>( - msg.u.extended_buffer_data.buffer); - - header->nFilledLen = msg.u.extended_buffer_data.range_length; - header->nOffset = msg.u.extended_buffer_data.range_offset; - header->hMarkTargetComponent = NULL; - header->nFlags = msg.u.extended_buffer_data.flags; - header->nTimeStamp = msg.u.extended_buffer_data.timestamp; - - BufferMeta *buffer_meta = - static_cast<BufferMeta *>(header->pAppPrivate); - buffer_meta->CopyToOMX(header); - - NodeMeta *node_meta = static_cast<NodeMeta *>( - msg.u.extended_buffer_data.node); - - LOGV("EmptyThisBuffer buffer=%p", header); - - OMX_ERRORTYPE err = - OMX_EmptyThisBuffer(node_meta->handle(), header); - assert(err == OMX_ErrorNone); - break; - } - - case omx_message::SEND_COMMAND: - { - NodeMeta *node_meta = static_cast<NodeMeta *>( - msg.u.send_command_data.node); - - OMX_ERRORTYPE err = - OMX_SendCommand( - node_meta->handle(), msg.u.send_command_data.cmd, - msg.u.send_command_data.param, NULL); - assert(err == OMX_ErrorNone); - break; - } - - case omx_message::DISCONNECT: - { - omx_message msg; - msg.type = omx_message::DISCONNECTED; - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); - done = true; - break; - } - - default: - LOGE("received unknown omx_message type %d", msg.type); - break; - } - } - - Mutex::Autolock autoLock(mLock); - close(mSock); - mSock = -1; -} -#endif - status_t OMX::list_nodes(List<String8> *list) { OMX_MasterInit(); // XXX Put this somewhere else. @@ -362,12 +220,6 @@ status_t OMX::send_command( node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) { Mutex::Autolock autoLock(mLock); -#if IOMX_USES_SOCKETS - if (mSock < 0) { - return UNKNOWN_ERROR; - } -#endif - NodeMeta *meta = static_cast<NodeMeta *>(node); OMX_ERRORTYPE err = OMX_SendCommand(meta->handle(), cmd, param, NULL); @@ -510,17 +362,10 @@ OMX_ERRORTYPE OMX::OnEvent( msg.u.event_data.data1 = nData1; msg.u.event_data.data2 = nData2; -#if !IOMX_USES_SOCKETS sp<IOMXObserver> observer = meta->observer(); if (observer.get() != NULL) { observer->on_message(msg); } -#else - assert(mSock >= 0); - - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); -#endif return OMX_ErrorNone; } @@ -534,16 +379,10 @@ OMX_ERRORTYPE OMX::OnEmptyBufferDone( msg.u.buffer_data.node = meta; msg.u.buffer_data.buffer = pBuffer; -#if !IOMX_USES_SOCKETS sp<IOMXObserver> observer = meta->observer(); if (observer.get() != NULL) { observer->on_message(msg); } -#else - assert(mSock >= 0); - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); -#endif return OMX_ErrorNone; } @@ -564,22 +403,14 @@ OMX_ERRORTYPE OMX::OnFillBufferDone( msg.u.extended_buffer_data.timestamp = pBuffer->nTimeStamp; msg.u.extended_buffer_data.platform_private = pBuffer->pPlatformPrivate; -#if !IOMX_USES_SOCKETS sp<IOMXObserver> observer = meta->observer(); if (observer.get() != NULL) { observer->on_message(msg); } -#else - assert(mSock >= 0); - - ssize_t n = send(mSock, &msg, sizeof(msg), 0); - assert(n > 0 && static_cast<size_t>(n) == sizeof(msg)); -#endif return OMX_ErrorNone; } -#if !IOMX_USES_SOCKETS status_t OMX::observe_node( node_id node, const sp<IOMXObserver> &observer) { NodeMeta *node_meta = static_cast<NodeMeta *>(node); @@ -623,7 +454,6 @@ void OMX::empty_buffer( OMX_EmptyThisBuffer(node_meta->handle(), header); assert(err == OMX_ErrorNone); } -#endif //////////////////////////////////////////////////////////////////////////////// diff --git a/media/libstagefright/omx/OMX.h b/media/libstagefright/omx/OMX.h index 20430bb..8ac311c 100644 --- a/media/libstagefright/omx/OMX.h +++ b/media/libstagefright/omx/OMX.h @@ -17,8 +17,6 @@ #ifndef ANDROID_OMX_H_ #define ANDROID_OMX_H_ -#include <pthread.h> - #include <media/IOMX.h> #include <utils/threads.h> @@ -29,11 +27,6 @@ class NodeMeta; class OMX : public BnOMX { public: OMX(); - virtual ~OMX(); - -#if IOMX_USES_SOCKETS - virtual status_t connect(int *sd); -#endif virtual status_t list_nodes(List<String8> *list); @@ -66,7 +59,6 @@ public: virtual status_t free_buffer( node_id node, OMX_U32 port_index, buffer_id buffer); -#if !IOMX_USES_SOCKETS virtual status_t observe_node( node_id node, const sp<IOMXObserver> &observer); @@ -77,7 +69,6 @@ public: buffer_id buffer, OMX_U32 range_offset, OMX_U32 range_length, OMX_U32 flags, OMX_TICKS timestamp); -#endif virtual sp<IOMXRenderer> createRenderer( const sp<ISurface> &surface, @@ -89,14 +80,6 @@ public: private: static OMX_CALLBACKTYPE kCallbacks; -#if IOMX_USES_SOCKETS - int mSock; - pthread_t mThread; - - static void *ThreadWrapper(void *me); - void threadEntry(); -#endif - Mutex mLock; static OMX_ERRORTYPE OnEvent( |