зеркало из https://github.com/mozilla/gecko-dev.git
Bug 969395 - Add stub library for accesing VP8 HW codec through android native mediacodec interface. r=rjesup
This commit is contained in:
Родитель
a597c57860
Коммит
c9bd29e3a3
|
@ -2634,7 +2634,7 @@ MOZ_CHECK_HEADERS([linux/quota.h],,,[#include <sys/socket.h>])
|
|||
dnl SCTP support - needs various network include headers
|
||||
MOZ_CHECK_HEADERS([linux/if_addr.h linux/rtnetlink.h],,,[#include <sys/socket.h>])
|
||||
|
||||
MOZ_CHECK_HEADERS(sys/types.h netinet/in.h byteswap.h)
|
||||
MOZ_CHECK_HEADERS(sys/types.h netinet/in.h byteswap.h sys/uio.h)
|
||||
|
||||
dnl Check for sin_len and sin6_len - used by SCTP; only appears in Mac/*BSD generally
|
||||
AC_CACHE_CHECK(for sockaddr_in.sin_len,
|
||||
|
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ANDROID_LOOPER_H
|
||||
#define ANDROID_LOOPER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ALooper
|
||||
*
|
||||
* A looper is the state tracking an event loop for a thread.
|
||||
* Loopers do not define event structures or other such things; rather
|
||||
* they are a lower-level facility to attach one or more discrete objects
|
||||
* listening for an event. An "event" here is simply data available on
|
||||
* a file descriptor: each attached object has an associated file descriptor,
|
||||
* and waiting for "events" means (internally) polling on all of these file
|
||||
* descriptors until one or more of them have data available.
|
||||
*
|
||||
* A thread can have only one ALooper associated with it.
|
||||
*/
|
||||
struct ALooper;
|
||||
typedef struct ALooper ALooper;
|
||||
|
||||
/**
|
||||
* Returns the looper associated with the calling thread, or NULL if
|
||||
* there is not one.
|
||||
*/
|
||||
ALooper* ALooper_forThread();
|
||||
|
||||
enum {
|
||||
/**
|
||||
* Option for ALooper_prepare: this looper will accept calls to
|
||||
* ALooper_addFd() that do not have a callback (that is provide NULL
|
||||
* for the callback). In this case the caller of ALooper_pollOnce()
|
||||
* or ALooper_pollAll() MUST check the return from these functions to
|
||||
* discover when data is available on such fds and process it.
|
||||
*/
|
||||
ALOOPER_PREPARE_ALLOW_NON_CALLBACKS = 1<<0
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepares a looper associated with the calling thread, and returns it.
|
||||
* If the thread already has a looper, it is returned. Otherwise, a new
|
||||
* one is created, associated with the thread, and returned.
|
||||
*
|
||||
* The opts may be ALOOPER_PREPARE_ALLOW_NON_CALLBACKS or 0.
|
||||
*/
|
||||
ALooper* ALooper_prepare(int opts);
|
||||
|
||||
enum {
|
||||
/**
|
||||
* Result from ALooper_pollOnce() and ALooper_pollAll():
|
||||
* The poll was awoken using wake() before the timeout expired
|
||||
* and no callbacks were executed and no other file descriptors were ready.
|
||||
*/
|
||||
ALOOPER_POLL_WAKE = -1,
|
||||
|
||||
/**
|
||||
* Result from ALooper_pollOnce() and ALooper_pollAll():
|
||||
* One or more callbacks were executed.
|
||||
*/
|
||||
ALOOPER_POLL_CALLBACK = -2,
|
||||
|
||||
/**
|
||||
* Result from ALooper_pollOnce() and ALooper_pollAll():
|
||||
* The timeout expired.
|
||||
*/
|
||||
ALOOPER_POLL_TIMEOUT = -3,
|
||||
|
||||
/**
|
||||
* Result from ALooper_pollOnce() and ALooper_pollAll():
|
||||
* An error occurred.
|
||||
*/
|
||||
ALOOPER_POLL_ERROR = -4,
|
||||
};
|
||||
|
||||
/**
|
||||
* Acquire a reference on the given ALooper object. This prevents the object
|
||||
* from being deleted until the reference is removed. This is only needed
|
||||
* to safely hand an ALooper from one thread to another.
|
||||
*/
|
||||
void ALooper_acquire(ALooper* looper);
|
||||
|
||||
/**
|
||||
* Remove a reference that was previously acquired with ALooper_acquire().
|
||||
*/
|
||||
void ALooper_release(ALooper* looper);
|
||||
|
||||
/**
|
||||
* Flags for file descriptor events that a looper can monitor.
|
||||
*
|
||||
* These flag bits can be combined to monitor multiple events at once.
|
||||
*/
|
||||
enum {
|
||||
/**
|
||||
* The file descriptor is available for read operations.
|
||||
*/
|
||||
ALOOPER_EVENT_INPUT = 1 << 0,
|
||||
|
||||
/**
|
||||
* The file descriptor is available for write operations.
|
||||
*/
|
||||
ALOOPER_EVENT_OUTPUT = 1 << 1,
|
||||
|
||||
/**
|
||||
* The file descriptor has encountered an error condition.
|
||||
*
|
||||
* The looper always sends notifications about errors; it is not necessary
|
||||
* to specify this event flag in the requested event set.
|
||||
*/
|
||||
ALOOPER_EVENT_ERROR = 1 << 2,
|
||||
|
||||
/**
|
||||
* The file descriptor was hung up.
|
||||
* For example, indicates that the remote end of a pipe or socket was closed.
|
||||
*
|
||||
* The looper always sends notifications about hangups; it is not necessary
|
||||
* to specify this event flag in the requested event set.
|
||||
*/
|
||||
ALOOPER_EVENT_HANGUP = 1 << 3,
|
||||
|
||||
/**
|
||||
* The file descriptor is invalid.
|
||||
* For example, the file descriptor was closed prematurely.
|
||||
*
|
||||
* The looper always sends notifications about invalid file descriptors; it is not necessary
|
||||
* to specify this event flag in the requested event set.
|
||||
*/
|
||||
ALOOPER_EVENT_INVALID = 1 << 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* For callback-based event loops, this is the prototype of the function
|
||||
* that is called when a file descriptor event occurs.
|
||||
* It is given the file descriptor it is associated with,
|
||||
* a bitmask of the poll events that were triggered (typically ALOOPER_EVENT_INPUT),
|
||||
* and the data pointer that was originally supplied.
|
||||
*
|
||||
* Implementations should return 1 to continue receiving callbacks, or 0
|
||||
* to have this file descriptor and callback unregistered from the looper.
|
||||
*/
|
||||
typedef int (*ALooper_callbackFunc)(int fd, int events, void* data);
|
||||
|
||||
/**
|
||||
* Waits for events to be available, with optional timeout in milliseconds.
|
||||
* Invokes callbacks for all file descriptors on which an event occurred.
|
||||
*
|
||||
* If the timeout is zero, returns immediately without blocking.
|
||||
* If the timeout is negative, waits indefinitely until an event appears.
|
||||
*
|
||||
* Returns ALOOPER_POLL_WAKE if the poll was awoken using wake() before
|
||||
* the timeout expired and no callbacks were invoked and no other file
|
||||
* descriptors were ready.
|
||||
*
|
||||
* Returns ALOOPER_POLL_CALLBACK if one or more callbacks were invoked.
|
||||
*
|
||||
* Returns ALOOPER_POLL_TIMEOUT if there was no data before the given
|
||||
* timeout expired.
|
||||
*
|
||||
* Returns ALOOPER_POLL_ERROR if an error occurred.
|
||||
*
|
||||
* Returns a value >= 0 containing an identifier if its file descriptor has data
|
||||
* and it has no callback function (requiring the caller here to handle it).
|
||||
* In this (and only this) case outFd, outEvents and outData will contain the poll
|
||||
* events and data associated with the fd, otherwise they will be set to NULL.
|
||||
*
|
||||
* This method does not return until it has finished invoking the appropriate callbacks
|
||||
* for all file descriptors that were signalled.
|
||||
*/
|
||||
int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
||||
|
||||
/**
|
||||
* Like ALooper_pollOnce(), but performs all pending callbacks until all
|
||||
* data has been consumed or a file descriptor is available with no callback.
|
||||
* This function will never return ALOOPER_POLL_CALLBACK.
|
||||
*/
|
||||
int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);
|
||||
|
||||
/**
|
||||
* Wakes the poll asynchronously.
|
||||
*
|
||||
* This method can be called on any thread.
|
||||
* This method returns immediately.
|
||||
*/
|
||||
void ALooper_wake(ALooper* looper);
|
||||
|
||||
/**
|
||||
* Adds a new file descriptor to be polled by the looper.
|
||||
* If the same file descriptor was previously added, it is replaced.
|
||||
*
|
||||
* "fd" is the file descriptor to be added.
|
||||
* "ident" is an identifier for this event, which is returned from ALooper_pollOnce().
|
||||
* The identifier must be >= 0, or ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
|
||||
* "events" are the poll events to wake up on. Typically this is ALOOPER_EVENT_INPUT.
|
||||
* "callback" is the function to call when there is an event on the file descriptor.
|
||||
* "data" is a private data pointer to supply to the callback.
|
||||
*
|
||||
* There are two main uses of this function:
|
||||
*
|
||||
* (1) If "callback" is non-NULL, then this function will be called when there is
|
||||
* data on the file descriptor. It should execute any events it has pending,
|
||||
* appropriately reading from the file descriptor. The 'ident' is ignored in this case.
|
||||
*
|
||||
* (2) If "callback" is NULL, the 'ident' will be returned by ALooper_pollOnce
|
||||
* when its file descriptor has data available, requiring the caller to take
|
||||
* care of processing it.
|
||||
*
|
||||
* Returns 1 if the file descriptor was added or -1 if an error occurred.
|
||||
*
|
||||
* This method can be called on any thread.
|
||||
* This method may block briefly if it needs to wake the poll.
|
||||
*/
|
||||
int ALooper_addFd(ALooper* looper, int fd, int ident, int events,
|
||||
ALooper_callbackFunc callback, void* data);
|
||||
|
||||
/**
|
||||
* Removes a previously added file descriptor from the looper.
|
||||
*
|
||||
* When this method returns, it is safe to close the file descriptor since the looper
|
||||
* will no longer have a reference to it. However, it is possible for the callback to
|
||||
* already be running or for it to run one last time if the file descriptor was already
|
||||
* signalled. Calling code is responsible for ensuring that this case is safely handled.
|
||||
* For example, if the callback takes care of removing itself during its own execution either
|
||||
* by returning 0 or by calling this method, then it can be guaranteed to not be invoked
|
||||
* again at any later time unless registered anew.
|
||||
*
|
||||
* Returns 1 if the file descriptor was removed, 0 if none was previously registered
|
||||
* or -1 if an error occurred.
|
||||
*
|
||||
* This method can be called on any thread.
|
||||
* This method may block briefly if it needs to wake the poll.
|
||||
*/
|
||||
int ALooper_removeFd(ALooper* looper, int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // ANDROID_NATIVE_WINDOW_H
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ANDROID_RECT_H
|
||||
#define ANDROID_RECT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ARect {
|
||||
#ifdef __cplusplus
|
||||
typedef int32_t value_type;
|
||||
#endif
|
||||
int32_t left;
|
||||
int32_t top;
|
||||
int32_t right;
|
||||
int32_t bottom;
|
||||
} ARect;
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // ANDROID_RECT_H
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_BINDER_H
|
||||
#define ANDROID_BINDER_H
|
||||
|
||||
#include <binder/IBinder.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
|
||||
class BBinder : public IBinder
|
||||
{
|
||||
public:
|
||||
BBinder();
|
||||
|
||||
virtual const String16& getInterfaceDescriptor() const;
|
||||
virtual bool isBinderAlive() const;
|
||||
virtual status_t pingBinder();
|
||||
virtual status_t dump(int fd, const Vector<String16>& args);
|
||||
|
||||
virtual status_t transact( uint32_t code,
|
||||
const Parcel& data,
|
||||
Parcel* reply,
|
||||
uint32_t flags = 0);
|
||||
|
||||
virtual status_t linkToDeath(const sp<DeathRecipient>& recipient,
|
||||
void* cookie = NULL,
|
||||
uint32_t flags = 0);
|
||||
|
||||
virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient,
|
||||
void* cookie = NULL,
|
||||
uint32_t flags = 0,
|
||||
wp<DeathRecipient>* outRecipient = NULL);
|
||||
|
||||
virtual void attachObject( const void* objectID,
|
||||
void* object,
|
||||
void* cleanupCookie,
|
||||
object_cleanup_func func);
|
||||
virtual void* findObject(const void* objectID) const;
|
||||
virtual void detachObject(const void* objectID);
|
||||
|
||||
virtual BBinder* localBinder();
|
||||
|
||||
protected:
|
||||
virtual ~BBinder();
|
||||
|
||||
virtual status_t onTransact( uint32_t code,
|
||||
const Parcel& data,
|
||||
Parcel* reply,
|
||||
uint32_t flags = 0);
|
||||
|
||||
private:
|
||||
BBinder(const BBinder& o);
|
||||
BBinder& operator=(const BBinder& o);
|
||||
|
||||
class Extras;
|
||||
|
||||
Extras* mExtras;
|
||||
void* mReserved0;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class BpRefBase : public virtual RefBase
|
||||
{
|
||||
protected:
|
||||
BpRefBase(const sp<IBinder>& o);
|
||||
virtual ~BpRefBase();
|
||||
virtual void onFirstRef();
|
||||
virtual void onLastStrongRef(const void* id);
|
||||
virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
|
||||
|
||||
inline IBinder* remote() { return mRemote; }
|
||||
inline IBinder* remote() const { return mRemote; }
|
||||
|
||||
private:
|
||||
BpRefBase(const BpRefBase& o);
|
||||
BpRefBase& operator=(const BpRefBase& o);
|
||||
|
||||
IBinder* const mRemote;
|
||||
RefBase::weakref_type* mRefs;
|
||||
volatile int32_t mState;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_BINDER_H
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_IBINDER_H
|
||||
#define ANDROID_IBINDER_H
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/String16.h>
|
||||
#include <utils/Vector.h>
|
||||
|
||||
|
||||
#define B_PACK_CHARS(c1, c2, c3, c4) \
|
||||
((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
|
||||
class BBinder;
|
||||
class BpBinder;
|
||||
class IInterface;
|
||||
class Parcel;
|
||||
|
||||
/**
|
||||
* Base class and low-level protocol for a remotable object.
|
||||
* You can derive from this class to create an object for which other
|
||||
* processes can hold references to it. Communication between processes
|
||||
* (method calls, property get and set) is down through a low-level
|
||||
* protocol implemented on top of the transact() API.
|
||||
*/
|
||||
class IBinder : public virtual RefBase
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
FIRST_CALL_TRANSACTION = 0x00000001,
|
||||
LAST_CALL_TRANSACTION = 0x00ffffff,
|
||||
|
||||
PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'),
|
||||
DUMP_TRANSACTION = B_PACK_CHARS('_','D','M','P'),
|
||||
INTERFACE_TRANSACTION = B_PACK_CHARS('_', 'N', 'T', 'F'),
|
||||
SYSPROPS_TRANSACTION = B_PACK_CHARS('_', 'S', 'P', 'R'),
|
||||
|
||||
// Corresponds to TF_ONE_WAY -- an asynchronous call.
|
||||
FLAG_ONEWAY = 0x00000001
|
||||
};
|
||||
|
||||
IBinder();
|
||||
|
||||
/**
|
||||
* Check if this IBinder implements the interface named by
|
||||
* @a descriptor. If it does, the base pointer to it is returned,
|
||||
* which you can safely static_cast<> to the concrete C++ interface.
|
||||
*/
|
||||
virtual sp<IInterface> queryLocalInterface(const String16& descriptor);
|
||||
|
||||
/**
|
||||
* Return the canonical name of the interface provided by this IBinder
|
||||
* object.
|
||||
*/
|
||||
virtual const String16& getInterfaceDescriptor() const = 0;
|
||||
|
||||
virtual bool isBinderAlive() const = 0;
|
||||
virtual status_t pingBinder() = 0;
|
||||
virtual status_t dump(int fd, const Vector<String16>& args) = 0;
|
||||
|
||||
virtual status_t transact( uint32_t code,
|
||||
const Parcel& data,
|
||||
Parcel* reply,
|
||||
uint32_t flags = 0) = 0;
|
||||
|
||||
/**
|
||||
* This method allows you to add data that is transported through
|
||||
* IPC along with your IBinder pointer. When implementing a Binder
|
||||
* object, override it to write your desired data in to @a outData.
|
||||
* You can then call getConstantData() on your IBinder to retrieve
|
||||
* that data, from any process. You MUST return the number of bytes
|
||||
* written in to the parcel (including padding).
|
||||
*/
|
||||
class DeathRecipient : public virtual RefBase
|
||||
{
|
||||
public:
|
||||
virtual void binderDied(const wp<IBinder>& who) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register the @a recipient for a notification if this binder
|
||||
* goes away. If this binder object unexpectedly goes away
|
||||
* (typically because its hosting process has been killed),
|
||||
* then DeathRecipient::binderDied() will be called with a reference
|
||||
* to this.
|
||||
*
|
||||
* The @a cookie is optional -- if non-NULL, it should be a
|
||||
* memory address that you own (that is, you know it is unique).
|
||||
*
|
||||
* @note You will only receive death notifications for remote binders,
|
||||
* as local binders by definition can't die without you dying as well.
|
||||
* Trying to use this function on a local binder will result in an
|
||||
* INVALID_OPERATION code being returned and nothing happening.
|
||||
*
|
||||
* @note This link always holds a weak reference to its recipient.
|
||||
*
|
||||
* @note You will only receive a weak reference to the dead
|
||||
* binder. You should not try to promote this to a strong reference.
|
||||
* (Nor should you need to, as there is nothing useful you can
|
||||
* directly do with it now that it has passed on.)
|
||||
*/
|
||||
virtual status_t linkToDeath(const sp<DeathRecipient>& recipient,
|
||||
void* cookie = NULL,
|
||||
uint32_t flags = 0) = 0;
|
||||
|
||||
/**
|
||||
* Remove a previously registered death notification.
|
||||
* The @a recipient will no longer be called if this object
|
||||
* dies. The @a cookie is optional. If non-NULL, you can
|
||||
* supply a NULL @a recipient, and the recipient previously
|
||||
* added with that cookie will be unlinked.
|
||||
*/
|
||||
virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient,
|
||||
void* cookie = NULL,
|
||||
uint32_t flags = 0,
|
||||
wp<DeathRecipient>* outRecipient = NULL) = 0;
|
||||
|
||||
virtual bool checkSubclass(const void* subclassID) const;
|
||||
|
||||
typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie);
|
||||
|
||||
virtual void attachObject( const void* objectID,
|
||||
void* object,
|
||||
void* cleanupCookie,
|
||||
object_cleanup_func func) = 0;
|
||||
virtual void* findObject(const void* objectID) const = 0;
|
||||
virtual void detachObject(const void* objectID) = 0;
|
||||
|
||||
virtual BBinder* localBinder();
|
||||
virtual BpBinder* remoteBinder();
|
||||
|
||||
protected:
|
||||
virtual ~IBinder();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_IBINDER_H
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
#ifndef ANDROID_IINTERFACE_H
|
||||
#define ANDROID_IINTERFACE_H
|
||||
|
||||
#include <binder/Binder.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
class IInterface : public virtual RefBase
|
||||
{
|
||||
public:
|
||||
IInterface();
|
||||
sp<IBinder> asBinder();
|
||||
sp<const IBinder> asBinder() const;
|
||||
|
||||
protected:
|
||||
virtual ~IInterface();
|
||||
virtual IBinder* onAsBinder() = 0;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
template<typename INTERFACE>
|
||||
inline sp<INTERFACE> interface_cast(const sp<IBinder>& obj)
|
||||
{
|
||||
return INTERFACE::asInterface(obj);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
template<typename INTERFACE>
|
||||
class BnInterface : public INTERFACE, public BBinder
|
||||
{
|
||||
public:
|
||||
virtual sp<IInterface> queryLocalInterface(const String16& _descriptor);
|
||||
virtual const String16& getInterfaceDescriptor() const;
|
||||
|
||||
protected:
|
||||
virtual IBinder* onAsBinder();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
template<typename INTERFACE>
|
||||
class BpInterface : public INTERFACE, public BpRefBase
|
||||
{
|
||||
public:
|
||||
BpInterface(const sp<IBinder>& remote);
|
||||
|
||||
protected:
|
||||
virtual IBinder* onAsBinder();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#define DECLARE_META_INTERFACE(INTERFACE) \
|
||||
static const android::String16 descriptor; \
|
||||
static android::sp<I##INTERFACE> asInterface( \
|
||||
const android::sp<android::IBinder>& obj); \
|
||||
virtual const android::String16& getInterfaceDescriptor() const; \
|
||||
I##INTERFACE(); \
|
||||
virtual ~I##INTERFACE(); \
|
||||
|
||||
|
||||
#define IMPLEMENT_META_INTERFACE(INTERFACE, NAME) \
|
||||
const android::String16 I##INTERFACE::descriptor(NAME); \
|
||||
const android::String16& \
|
||||
I##INTERFACE::getInterfaceDescriptor() const { \
|
||||
return I##INTERFACE::descriptor; \
|
||||
} \
|
||||
android::sp<I##INTERFACE> I##INTERFACE::asInterface( \
|
||||
const android::sp<android::IBinder>& obj) \
|
||||
{ \
|
||||
android::sp<I##INTERFACE> intr; \
|
||||
if (obj != NULL) { \
|
||||
intr = static_cast<I##INTERFACE*>( \
|
||||
obj->queryLocalInterface( \
|
||||
I##INTERFACE::descriptor).get()); \
|
||||
if (intr == NULL) { \
|
||||
intr = new Bp##INTERFACE(obj); \
|
||||
} \
|
||||
} \
|
||||
return intr; \
|
||||
} \
|
||||
I##INTERFACE::I##INTERFACE() { } \
|
||||
I##INTERFACE::~I##INTERFACE() { } \
|
||||
|
||||
|
||||
#define CHECK_INTERFACE(interface, data, reply) \
|
||||
if (!data.checkInterface(this)) { return PERMISSION_DENIED; } \
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// No user-serviceable parts after this...
|
||||
|
||||
template<typename INTERFACE>
|
||||
inline sp<IInterface> BnInterface<INTERFACE>::queryLocalInterface(
|
||||
const String16& _descriptor)
|
||||
{
|
||||
if (_descriptor == INTERFACE::descriptor) return this;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename INTERFACE>
|
||||
inline const String16& BnInterface<INTERFACE>::getInterfaceDescriptor() const
|
||||
{
|
||||
return INTERFACE::getInterfaceDescriptor();
|
||||
}
|
||||
|
||||
template<typename INTERFACE>
|
||||
IBinder* BnInterface<INTERFACE>::onAsBinder()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
template<typename INTERFACE>
|
||||
inline BpInterface<INTERFACE>::BpInterface(const sp<IBinder>& remote)
|
||||
: BpRefBase(remote)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename INTERFACE>
|
||||
inline IBinder* BpInterface<INTERFACE>::onAsBinder()
|
||||
{
|
||||
return remote();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_IINTERFACE_H
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_CUTILS_ATOMIC_H
|
||||
#define ANDROID_CUTILS_ATOMIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A handful of basic atomic operations. The appropriate pthread
|
||||
* functions should be used instead of these whenever possible.
|
||||
*
|
||||
* The "acquire" and "release" terms can be defined intuitively in terms
|
||||
* of the placement of memory barriers in a simple lock implementation:
|
||||
* - wait until compare-and-swap(lock-is-free --> lock-is-held) succeeds
|
||||
* - barrier
|
||||
* - [do work]
|
||||
* - barrier
|
||||
* - store(lock-is-free)
|
||||
* In very crude terms, the initial (acquire) barrier prevents any of the
|
||||
* "work" from happening before the lock is held, and the later (release)
|
||||
* barrier ensures that all of the work happens before the lock is released.
|
||||
* (Think of cached writes, cache read-ahead, and instruction reordering
|
||||
* around the CAS and store instructions.)
|
||||
*
|
||||
* The barriers must apply to both the compiler and the CPU. Note it is
|
||||
* legal for instructions that occur before an "acquire" barrier to be
|
||||
* moved down below it, and for instructions that occur after a "release"
|
||||
* barrier to be moved up above it.
|
||||
*
|
||||
* The ARM-driven implementation we use here is short on subtlety,
|
||||
* and actually requests a full barrier from the compiler and the CPU.
|
||||
* The only difference between acquire and release is in whether they
|
||||
* are issued before or after the atomic operation with which they
|
||||
* are associated. To ease the transition to C/C++ atomic intrinsics,
|
||||
* you should not rely on this, and instead assume that only the minimal
|
||||
* acquire/release protection is provided.
|
||||
*
|
||||
* NOTE: all int32_t* values are expected to be aligned on 32-bit boundaries.
|
||||
* If they are not, atomicity is not guaranteed.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Basic arithmetic and bitwise operations. These all provide a
|
||||
* barrier with "release" ordering, and return the previous value.
|
||||
*
|
||||
* These have the same characteristics (e.g. what happens on overflow)
|
||||
* as the equivalent non-atomic C operations.
|
||||
*/
|
||||
int32_t android_atomic_inc(volatile int32_t* addr);
|
||||
int32_t android_atomic_dec(volatile int32_t* addr);
|
||||
int32_t android_atomic_add(int32_t value, volatile int32_t* addr);
|
||||
int32_t android_atomic_and(int32_t value, volatile int32_t* addr);
|
||||
int32_t android_atomic_or(int32_t value, volatile int32_t* addr);
|
||||
|
||||
/*
|
||||
* Perform an atomic load with "acquire" or "release" ordering.
|
||||
*
|
||||
* This is only necessary if you need the memory barrier. A 32-bit read
|
||||
* from a 32-bit aligned address is atomic on all supported platforms.
|
||||
*/
|
||||
int32_t android_atomic_acquire_load(volatile const int32_t* addr);
|
||||
int32_t android_atomic_release_load(volatile const int32_t* addr);
|
||||
|
||||
/*
|
||||
* Perform an atomic store with "acquire" or "release" ordering.
|
||||
*
|
||||
* This is only necessary if you need the memory barrier. A 32-bit write
|
||||
* to a 32-bit aligned address is atomic on all supported platforms.
|
||||
*/
|
||||
void android_atomic_acquire_store(int32_t value, volatile int32_t* addr);
|
||||
void android_atomic_release_store(int32_t value, volatile int32_t* addr);
|
||||
|
||||
/*
|
||||
* Compare-and-set operation with "acquire" or "release" ordering.
|
||||
*
|
||||
* This returns zero if the new value was successfully stored, which will
|
||||
* only happen when *addr == oldvalue.
|
||||
*
|
||||
* (The return value is inverted from implementations on other platforms,
|
||||
* but matches the ARM ldrex/strex result.)
|
||||
*
|
||||
* Implementations that use the release CAS in a loop may be less efficient
|
||||
* than possible, because we re-issue the memory barrier on each iteration.
|
||||
*/
|
||||
int android_atomic_acquire_cas(int32_t oldvalue, int32_t newvalue,
|
||||
volatile int32_t* addr);
|
||||
int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue,
|
||||
volatile int32_t* addr);
|
||||
|
||||
/*
|
||||
* Aliases for code using an older version of this header. These are now
|
||||
* deprecated and should not be used. The definitions will be removed
|
||||
* in a future release.
|
||||
*/
|
||||
#define android_atomic_write android_atomic_release_store
|
||||
#define android_atomic_cmpxchg android_atomic_release_cas
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // ANDROID_CUTILS_ATOMIC_H
|
|
@ -0,0 +1,587 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// C/C++ logging functions. See the logging documentation for API details.
|
||||
//
|
||||
// We'd like these to be available from C code (in case we import some from
|
||||
// somewhere), so this has a C interface.
|
||||
//
|
||||
// The output will be correct when the log file is shared between multiple
|
||||
// threads and/or multiple processes so long as the operating system
|
||||
// supports O_APPEND. These calls have mutex-protected data structures
|
||||
// and so are NOT reentrant. Do not use LOG in a signal handler.
|
||||
//
|
||||
#ifndef _LIBS_CUTILS_LOG_H
|
||||
#define _LIBS_CUTILS_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <cutils/uio.h>
|
||||
#include <cutils/logd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Normally we strip ALOGV (VERBOSE messages) from release builds.
|
||||
* You can modify this (for example with "#define LOG_NDEBUG 0"
|
||||
* at the top of your source file) to change that behavior.
|
||||
*/
|
||||
#ifndef LOG_NDEBUG
|
||||
#ifdef NDEBUG
|
||||
#define LOG_NDEBUG 1
|
||||
#else
|
||||
#define LOG_NDEBUG 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is the local tag used for the following simplified
|
||||
* logging macros. You can change this preprocessor definition
|
||||
* before using the other macros to change the tag.
|
||||
*/
|
||||
#ifndef LOG_TAG
|
||||
#define LOG_TAG NULL
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Simplified macro to send a verbose log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef ALOGV
|
||||
#if LOG_NDEBUG
|
||||
#define ALOGV(...) ((void)0)
|
||||
#else
|
||||
#define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
#endif
|
||||
/////
|
||||
#define LOGV ALOGV
|
||||
|
||||
#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
|
||||
|
||||
#ifndef ALOGV_IF
|
||||
#if LOG_NDEBUG
|
||||
#define ALOGV_IF(cond, ...) ((void)0)
|
||||
#else
|
||||
#define ALOGV_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
#endif
|
||||
//////
|
||||
#define LOGV_IF ALOGV_IF
|
||||
|
||||
|
||||
/*
|
||||
* Simplified macro to send a debug log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef ALOGD
|
||||
#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGD_IF
|
||||
#define ALOGD_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
//////
|
||||
#define LOGD ALOGD
|
||||
#define LOGD_IF ALOGD_IF
|
||||
/*
|
||||
* Simplified macro to send an info log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef ALOGI
|
||||
#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGI_IF
|
||||
#define ALOGI_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
///////
|
||||
#define LOGI ALOGI
|
||||
#define LOGI_IF ALOGI_IF
|
||||
/*
|
||||
* Simplified macro to send a warning log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef ALOGW
|
||||
#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGW_IF
|
||||
#define ALOGW_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
//////
|
||||
#define LOGW ALOGW
|
||||
#define LOGW_IF ALOGW_IF
|
||||
/*
|
||||
* Simplified macro to send an error log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef ALOGE
|
||||
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGE_IF
|
||||
#define ALOGE_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
///////
|
||||
#define LOGE ALOGE
|
||||
#define LOGE_IF ALOGE_IF
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Conditional based on whether the current LOG_TAG is enabled at
|
||||
* verbose priority.
|
||||
*/
|
||||
#ifndef IF_ALOGV
|
||||
#if LOG_NDEBUG
|
||||
#define IF_ALOGV() if (false)
|
||||
#else
|
||||
#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
|
||||
#endif
|
||||
#endif
|
||||
/////
|
||||
#define IF_LOGV IF_LOGV
|
||||
/*
|
||||
* Conditional based on whether the current LOG_TAG is enabled at
|
||||
* debug priority.
|
||||
*/
|
||||
#ifndef IF_ALOGD
|
||||
#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
|
||||
#endif
|
||||
/////
|
||||
#define IF_LOGD IF_ALOGD
|
||||
/*
|
||||
* Conditional based on whether the current LOG_TAG is enabled at
|
||||
* info priority.
|
||||
*/
|
||||
#ifndef IF_ALOGI
|
||||
#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
|
||||
#endif
|
||||
////
|
||||
#define IF_LOGI IF_ALOGI
|
||||
/*
|
||||
* Conditional based on whether the current LOG_TAG is enabled at
|
||||
* warn priority.
|
||||
*/
|
||||
#ifndef IF_ALOGW
|
||||
#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
|
||||
#endif
|
||||
/////
|
||||
#define IF_LOGW IF_ALOGW
|
||||
/*
|
||||
* Conditional based on whether the current LOG_TAG is enabled at
|
||||
* error priority.
|
||||
*/
|
||||
#ifndef IF_ALOGE
|
||||
#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
|
||||
#endif
|
||||
|
||||
////
|
||||
#define IF_LOGE IF_ALOGE
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Simplified macro to send a verbose system log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef SLOGV
|
||||
#if LOG_NDEBUG
|
||||
#define SLOGV(...) ((void)0)
|
||||
#else
|
||||
#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
|
||||
|
||||
|
||||
#ifndef SLOGV_IF
|
||||
#if LOG_NDEBUG
|
||||
#define SLOGV_IF(cond, ...) ((void)0)
|
||||
#else
|
||||
#define SLOGV_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send a debug system log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef SLOGD
|
||||
#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef SLOGD_IF
|
||||
#define SLOGD_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send an info system log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef SLOGI
|
||||
#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef SLOGI_IF
|
||||
#define SLOGI_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send a warning system log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef SLOGW
|
||||
#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef SLOGW_IF
|
||||
#define SLOGW_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send an error system log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef SLOGE
|
||||
#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef SLOGE_IF
|
||||
#define SLOGE_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Simplified macro to send a verbose radio log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef RLOGV
|
||||
#if LOG_NDEBUG
|
||||
#define RLOGV(...) ((void)0)
|
||||
#else
|
||||
#define RLOGV(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
|
||||
|
||||
#ifndef RLOGV_IF
|
||||
#if LOG_NDEBUG
|
||||
#define RLOGV_IF(cond, ...) ((void)0)
|
||||
#else
|
||||
#define RLOGV_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send a debug radio log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef RLOGD
|
||||
#define RLOGD(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef RLOGD_IF
|
||||
#define RLOGD_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send an info radio log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef RLOGI
|
||||
#define RLOGI(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef RLOGI_IF
|
||||
#define RLOGI_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send a warning radio log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef RLOGW
|
||||
#define RLOGW(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef RLOGW_IF
|
||||
#define RLOGW_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simplified macro to send an error radio log message using the current LOG_TAG.
|
||||
*/
|
||||
#ifndef RLOGE
|
||||
#define RLOGE(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef RLOGE_IF
|
||||
#define RLOGE_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Log a fatal error. If the given condition fails, this stops program
|
||||
* execution like a normal assertion, but also generating the given message.
|
||||
* It is NOT stripped from release builds. Note that the condition test
|
||||
* is -inverted- from the normal assert() semantics.
|
||||
*/
|
||||
#ifndef LOG_ALWAYS_FATAL_IF
|
||||
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
|
||||
( (CONDITION(cond)) \
|
||||
? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
|
||||
: (void)0 )
|
||||
#endif
|
||||
|
||||
#ifndef LOG_ALWAYS_FATAL
|
||||
#define LOG_ALWAYS_FATAL(...) \
|
||||
( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
|
||||
* are stripped out of release builds.
|
||||
*/
|
||||
#if LOG_NDEBUG
|
||||
|
||||
#ifndef LOG_FATAL_IF
|
||||
#define LOG_FATAL_IF(cond, ...) ((void)0)
|
||||
#endif
|
||||
#ifndef LOG_FATAL
|
||||
#define LOG_FATAL(...) ((void)0)
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifndef LOG_FATAL_IF
|
||||
#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
|
||||
#endif
|
||||
#ifndef LOG_FATAL
|
||||
#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Assertion that generates a log message when the assertion fails.
|
||||
* Stripped out of release builds. Uses the current LOG_TAG.
|
||||
*/
|
||||
#ifndef ALOG_ASSERT
|
||||
#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
|
||||
//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Basic log message macro.
|
||||
*
|
||||
* Example:
|
||||
* ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
|
||||
*
|
||||
* The second argument may be NULL or "" to indicate the "global" tag.
|
||||
*/
|
||||
#ifndef ALOG
|
||||
#define ALOG(priority, tag, ...) \
|
||||
LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Log macro that allows you to specify a number for the priority.
|
||||
*/
|
||||
#ifndef LOG_PRI
|
||||
#define LOG_PRI(priority, tag, ...) \
|
||||
android_printLog(priority, tag, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Log macro that allows you to pass in a varargs ("args" is a va_list).
|
||||
*/
|
||||
#ifndef LOG_PRI_VA
|
||||
#define LOG_PRI_VA(priority, tag, fmt, args) \
|
||||
android_vprintLog(priority, NULL, tag, fmt, args)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Conditional given a desired logging priority and tag.
|
||||
*/
|
||||
#ifndef IF_ALOG
|
||||
#define IF_ALOG(priority, tag) \
|
||||
if (android_testLog(ANDROID_##priority, tag))
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Event logging.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Event log entry types. These must match up with the declarations in
|
||||
* java/android/android/util/EventLog.java.
|
||||
*/
|
||||
typedef enum {
|
||||
EVENT_TYPE_INT = 0,
|
||||
EVENT_TYPE_LONG = 1,
|
||||
EVENT_TYPE_STRING = 2,
|
||||
EVENT_TYPE_LIST = 3,
|
||||
} AndroidEventLogType;
|
||||
|
||||
|
||||
#ifndef LOG_EVENT_INT
|
||||
#define LOG_EVENT_INT(_tag, _value) { \
|
||||
int intBuf = _value; \
|
||||
(void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
|
||||
sizeof(intBuf)); \
|
||||
}
|
||||
#endif
|
||||
#ifndef LOG_EVENT_LONG
|
||||
#define LOG_EVENT_LONG(_tag, _value) { \
|
||||
long long longBuf = _value; \
|
||||
(void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
|
||||
sizeof(longBuf)); \
|
||||
}
|
||||
#endif
|
||||
#ifndef LOG_EVENT_STRING
|
||||
#define LOG_EVENT_STRING(_tag, _value) \
|
||||
((void) 0) /* not implemented -- must combine len with string */
|
||||
#endif
|
||||
/* TODO: something for LIST */
|
||||
|
||||
/*
|
||||
* ===========================================================================
|
||||
*
|
||||
* The stuff in the rest of this file should not be used directly.
|
||||
*/
|
||||
|
||||
#define android_printLog(prio, tag, fmt...) \
|
||||
__android_log_print(prio, tag, fmt)
|
||||
|
||||
#define android_vprintLog(prio, cond, tag, fmt...) \
|
||||
__android_log_vprint(prio, tag, fmt)
|
||||
|
||||
/* XXX Macros to work around syntax errors in places where format string
|
||||
* arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
|
||||
* (happens only in debug builds).
|
||||
*/
|
||||
|
||||
/* Returns 2nd arg. Used to substitute default value if caller's vararg list
|
||||
* is empty.
|
||||
*/
|
||||
#define __android_second(dummy, second, ...) second
|
||||
|
||||
/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
|
||||
* returns nothing.
|
||||
*/
|
||||
#define __android_rest(first, ...) , ## __VA_ARGS__
|
||||
|
||||
#define android_printAssert(cond, tag, fmt...) \
|
||||
__android_log_assert(cond, tag, \
|
||||
__android_second(0, ## fmt, NULL) __android_rest(fmt))
|
||||
|
||||
#define android_writeLog(prio, tag, text) \
|
||||
__android_log_write(prio, tag, text)
|
||||
|
||||
#define android_bWriteLog(tag, payload, len) \
|
||||
__android_log_bwrite(tag, payload, len)
|
||||
#define android_btWriteLog(tag, type, payload, len) \
|
||||
__android_log_btwrite(tag, type, payload, len)
|
||||
|
||||
// TODO: remove these prototypes and their users
|
||||
#define android_testLog(prio, tag) (1)
|
||||
#define android_writevLog(vec,num) do{}while(0)
|
||||
#define android_write1Log(str,len) do{}while (0)
|
||||
#define android_setMinPriority(tag, prio) do{}while(0)
|
||||
//#define android_logToCallback(func) do{}while(0)
|
||||
#define android_logToFile(tag, file) (0)
|
||||
#define android_logToFd(tag, fd) (0)
|
||||
|
||||
typedef enum {
|
||||
LOG_ID_MAIN = 0,
|
||||
LOG_ID_RADIO = 1,
|
||||
LOG_ID_EVENTS = 2,
|
||||
LOG_ID_SYSTEM = 3,
|
||||
|
||||
LOG_ID_MAX
|
||||
} log_id_t;
|
||||
|
||||
/*
|
||||
* Send a simple string to the log.
|
||||
*/
|
||||
int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
|
||||
int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _LIBS_CUTILS_LOG_H
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _ANDROID_CUTILS_LOGD_H
|
||||
#define _ANDROID_CUTILS_LOGD_H
|
||||
|
||||
/* the stable/frozen log-related definitions have been
|
||||
* moved to this header, which is exposed by the NDK
|
||||
*/
|
||||
#include <android/log.h>
|
||||
|
||||
/* the rest is only used internally by the system */
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <cutils/uio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int __android_log_bwrite(int32_t tag, const void *payload, size_t len);
|
||||
int __android_log_btwrite(int32_t tag, char type, const void *payload,
|
||||
size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LOGD_H */
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NATIVE_HANDLE_H_
|
||||
#define NATIVE_HANDLE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct native_handle
|
||||
{
|
||||
int version; /* sizeof(native_handle_t) */
|
||||
int numFds; /* number of file-descriptors at &data[0] */
|
||||
int numInts; /* number of ints at &data[numFds] */
|
||||
int data[0]; /* numFds + numInts ints */
|
||||
} native_handle_t;
|
||||
|
||||
/*
|
||||
* native_handle_close
|
||||
*
|
||||
* closes the file descriptors contained in this native_handle_t
|
||||
*
|
||||
* return 0 on success, or a negative error code on failure
|
||||
*
|
||||
*/
|
||||
int native_handle_close(const native_handle_t* h);
|
||||
|
||||
|
||||
/*
|
||||
* native_handle_create
|
||||
*
|
||||
* creates a native_handle_t and initializes it. must be destroyed with
|
||||
* native_handle_delete().
|
||||
*
|
||||
*/
|
||||
native_handle_t* native_handle_create(int numFds, int numInts);
|
||||
|
||||
/*
|
||||
* native_handle_delete
|
||||
*
|
||||
* frees a native_handle_t allocated with native_handle_create().
|
||||
* This ONLY frees the memory allocated for the native_handle_t, but doesn't
|
||||
* close the file descriptors; which can be achieved with native_handle_close().
|
||||
*
|
||||
* return 0 on success, or a negative error code on failure
|
||||
*
|
||||
*/
|
||||
int native_handle_delete(native_handle_t* h);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NATIVE_HANDLE_H_ */
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// implementation of sys/uio.h for platforms that don't have it (Win32)
|
||||
//
|
||||
#ifndef _LIBS_CUTILS_UIO_H
|
||||
#define _LIBS_CUTILS_UIO_H
|
||||
|
||||
#ifdef HAVE_SYS_UIO_H
|
||||
#include <sys/uio.h>
|
||||
#else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct iovec {
|
||||
const void* iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
extern int readv( int fd, struct iovec* vecs, int count );
|
||||
extern int writev( int fd, const struct iovec* vecs, int count );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !HAVE_SYS_UIO_H */
|
||||
|
||||
#endif /* _LIBS_UTILS_UIO_H */
|
||||
|
|
@ -0,0 +1,665 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_BUFFERQUEUE_H
|
||||
#define ANDROID_GUI_BUFFERQUEUE_H
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include <gui/IGraphicBufferAlloc.h>
|
||||
#include <gui/IGraphicBufferProducer.h>
|
||||
|
||||
#include <ui/Fence.h>
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
namespace android {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class BufferQueue : public BnGraphicBufferProducer {
|
||||
public:
|
||||
enum { MIN_UNDEQUEUED_BUFFERS = 2 };
|
||||
enum { NUM_BUFFER_SLOTS =
|
||||
#ifdef GFX_BUF_EXT
|
||||
64 }; // extend GFX buffer from 32 to 64 for VPP support
|
||||
#else
|
||||
32 };
|
||||
#endif
|
||||
enum { NO_CONNECTED_API = 0 };
|
||||
enum { INVALID_BUFFER_SLOT = -1 };
|
||||
enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE };
|
||||
|
||||
// When in async mode we reserve two slots in order to guarantee that the
|
||||
// producer and consumer can run asynchronously.
|
||||
enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 };
|
||||
|
||||
// ConsumerListener is the interface through which the BufferQueue notifies
|
||||
// the consumer of events that the consumer may wish to react to. Because
|
||||
// the consumer will generally have a mutex that is locked during calls from
|
||||
// the consumer to the BufferQueue, these calls from the BufferQueue to the
|
||||
// consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
|
||||
struct ConsumerListener : public virtual RefBase {
|
||||
// onFrameAvailable is called from queueBuffer each time an additional
|
||||
// frame becomes available for consumption. This means that frames that
|
||||
// are queued while in asynchronous mode only trigger the callback if no
|
||||
// previous frames are pending. Frames queued while in synchronous mode
|
||||
// always trigger the callback.
|
||||
//
|
||||
// This is called without any lock held and can be called concurrently
|
||||
// by multiple threads.
|
||||
virtual void onFrameAvailable() = 0;
|
||||
|
||||
// onBuffersReleased is called to notify the buffer consumer that the
|
||||
// BufferQueue has released its references to one or more GraphicBuffers
|
||||
// contained in its slots. The buffer consumer should then call
|
||||
// BufferQueue::getReleasedBuffers to retrieve the list of buffers
|
||||
//
|
||||
// This is called without any lock held and can be called concurrently
|
||||
// by multiple threads.
|
||||
virtual void onBuffersReleased() = 0;
|
||||
};
|
||||
|
||||
// ProxyConsumerListener is a ConsumerListener implementation that keeps a weak
|
||||
// reference to the actual consumer object. It forwards all calls to that
|
||||
// consumer object so long as it exists.
|
||||
//
|
||||
// This class exists to avoid having a circular reference between the
|
||||
// BufferQueue object and the consumer object. The reason this can't be a weak
|
||||
// reference in the BufferQueue class is because we're planning to expose the
|
||||
// consumer side of a BufferQueue as a binder interface, which doesn't support
|
||||
// weak references.
|
||||
class ProxyConsumerListener : public BufferQueue::ConsumerListener {
|
||||
public:
|
||||
|
||||
ProxyConsumerListener(const wp<BufferQueue::ConsumerListener>& consumerListener);
|
||||
virtual ~ProxyConsumerListener();
|
||||
virtual void onFrameAvailable();
|
||||
virtual void onBuffersReleased();
|
||||
|
||||
private:
|
||||
|
||||
// mConsumerListener is a weak reference to the ConsumerListener. This is
|
||||
// the raison d'etre of ProxyConsumerListener.
|
||||
wp<BufferQueue::ConsumerListener> mConsumerListener;
|
||||
};
|
||||
|
||||
|
||||
// BufferQueue manages a pool of gralloc memory slots to be used by
|
||||
// producers and consumers. allowSynchronousMode specifies whether or not
|
||||
// synchronous mode can be enabled by the producer. allocator is used to
|
||||
// allocate all the needed gralloc buffers.
|
||||
BufferQueue(bool allowSynchronousMode = true,
|
||||
const sp<IGraphicBufferAlloc>& allocator = NULL);
|
||||
virtual ~BufferQueue();
|
||||
|
||||
// Query native window attributes. The "what" values are enumerated in
|
||||
// window.h (e.g. NATIVE_WINDOW_FORMAT).
|
||||
virtual int query(int what, int* value);
|
||||
|
||||
// setBufferCount updates the number of available buffer slots. If this
|
||||
// method succeeds, buffer slots will be both unallocated and owned by
|
||||
// the BufferQueue object (i.e. they are not owned by the producer or
|
||||
// consumer).
|
||||
//
|
||||
// This will fail if the producer has dequeued any buffers, or if
|
||||
// bufferCount is invalid. bufferCount must generally be a value
|
||||
// between the minimum undequeued buffer count and NUM_BUFFER_SLOTS
|
||||
// (inclusive). It may also be set to zero (the default) to indicate
|
||||
// that the producer does not wish to set a value. The minimum value
|
||||
// can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
|
||||
// ...).
|
||||
//
|
||||
// This may only be called by the producer. The consumer will be told
|
||||
// to discard buffers through the onBuffersReleased callback.
|
||||
virtual status_t setBufferCount(int bufferCount);
|
||||
|
||||
// requestBuffer returns the GraphicBuffer for slot N.
|
||||
//
|
||||
// In normal operation, this is called the first time slot N is returned
|
||||
// by dequeueBuffer. It must be called again if dequeueBuffer returns
|
||||
// flags indicating that previously-returned buffers are no longer valid.
|
||||
virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
|
||||
|
||||
// dequeueBuffer gets the next buffer slot index for the producer to use.
|
||||
// If a buffer slot is available then that slot index is written to the
|
||||
// location pointed to by the buf argument and a status of OK is returned.
|
||||
// If no slot is available then a status of -EBUSY is returned and buf is
|
||||
// unmodified.
|
||||
//
|
||||
// The fence parameter will be updated to hold the fence associated with
|
||||
// the buffer. The contents of the buffer must not be overwritten until the
|
||||
// fence signals. If the fence is Fence::NO_FENCE, the buffer may be
|
||||
// written immediately.
|
||||
//
|
||||
// The width and height parameters must be no greater than the minimum of
|
||||
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
|
||||
// An error due to invalid dimensions might not be reported until
|
||||
// updateTexImage() is called. If width and height are both zero, the
|
||||
// default values specified by setDefaultBufferSize() are used instead.
|
||||
//
|
||||
// The pixel formats are enumerated in graphics.h, e.g.
|
||||
// HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format
|
||||
// will be used.
|
||||
//
|
||||
// The usage argument specifies gralloc buffer usage flags. The values
|
||||
// are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These
|
||||
// will be merged with the usage flags specified by setConsumerUsageBits.
|
||||
//
|
||||
// The return value may be a negative error value or a non-negative
|
||||
// collection of flags. If the flags are set, the return values are
|
||||
// valid, but additional actions must be performed.
|
||||
//
|
||||
// If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the
|
||||
// producer must discard cached GraphicBuffer references for the slot
|
||||
// returned in buf.
|
||||
// If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer
|
||||
// must discard cached GraphicBuffer references for all slots.
|
||||
//
|
||||
// In both cases, the producer will need to call requestBuffer to get a
|
||||
// GraphicBuffer handle for the returned slot.
|
||||
virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence,
|
||||
uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
|
||||
|
||||
// queueBuffer returns a filled buffer to the BufferQueue.
|
||||
//
|
||||
// Additional data is provided in the QueueBufferInput struct. Notably,
|
||||
// a timestamp must be provided for the buffer. The timestamp is in
|
||||
// nanoseconds, and must be monotonically increasing. Its other semantics
|
||||
// (zero point, etc) are producer-specific and should be documented by the
|
||||
// producer.
|
||||
//
|
||||
// The caller may provide a fence that signals when all rendering
|
||||
// operations have completed. Alternatively, NO_FENCE may be used,
|
||||
// indicating that the buffer is ready immediately.
|
||||
//
|
||||
// Some values are returned in the output struct: the current settings
|
||||
// for default width and height, the current transform hint, and the
|
||||
// number of queued buffers.
|
||||
virtual status_t queueBuffer(int buf,
|
||||
const QueueBufferInput& input, QueueBufferOutput* output);
|
||||
|
||||
// cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't
|
||||
// queue it for use by the consumer.
|
||||
//
|
||||
// The buffer will not be overwritten until the fence signals. The fence
|
||||
// will usually be the one obtained from dequeueBuffer.
|
||||
virtual void cancelBuffer(int buf, const sp<Fence>& fence);
|
||||
|
||||
// setSynchronousMode sets whether dequeueBuffer is synchronous or
|
||||
// asynchronous. In synchronous mode, dequeueBuffer blocks until
|
||||
// a buffer is available, the currently bound buffer can be dequeued and
|
||||
// queued buffers will be acquired in order. In asynchronous mode,
|
||||
// a queued buffer may be replaced by a subsequently queued buffer.
|
||||
//
|
||||
// The default mode is asynchronous.
|
||||
virtual status_t setSynchronousMode(bool enabled);
|
||||
|
||||
// connect attempts to connect a producer API to the BufferQueue. This
|
||||
// must be called before any other IGraphicBufferProducer methods are
|
||||
// called except for getAllocator. A consumer must already be connected.
|
||||
//
|
||||
// This method will fail if connect was previously called on the
|
||||
// BufferQueue and no corresponding disconnect call was made (i.e. if
|
||||
// it's still connected to a producer).
|
||||
//
|
||||
// APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU).
|
||||
virtual status_t connect(int api, QueueBufferOutput* output);
|
||||
|
||||
// disconnect attempts to disconnect a producer API from the BufferQueue.
|
||||
// Calling this method will cause any subsequent calls to other
|
||||
// IGraphicBufferProducer methods to fail except for getAllocator and connect.
|
||||
// Successfully calling connect after this will allow the other methods to
|
||||
// succeed again.
|
||||
//
|
||||
// This method will fail if the the BufferQueue is not currently
|
||||
// connected to the specified producer API.
|
||||
virtual status_t disconnect(int api);
|
||||
|
||||
// dump our state in a String
|
||||
virtual void dump(String8& result) const;
|
||||
virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
|
||||
|
||||
// public facing structure for BufferSlot
|
||||
struct BufferItem {
|
||||
|
||||
BufferItem()
|
||||
:
|
||||
mTransform(0),
|
||||
mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
|
||||
mTimestamp(0),
|
||||
mFrameNumber(0),
|
||||
mTrickMode(false),
|
||||
mBuf(INVALID_BUFFER_SLOT),
|
||||
mVideoSessionID(0) {
|
||||
mCrop.makeInvalid();
|
||||
}
|
||||
// mGraphicBuffer points to the buffer allocated for this slot, or is NULL
|
||||
// if the buffer in this slot has been acquired in the past (see
|
||||
// BufferSlot.mAcquireCalled).
|
||||
sp<GraphicBuffer> mGraphicBuffer;
|
||||
|
||||
// mCrop is the current crop rectangle for this buffer slot.
|
||||
Rect mCrop;
|
||||
|
||||
// mTransform is the current transform flags for this buffer slot.
|
||||
uint32_t mTransform;
|
||||
|
||||
// mScalingMode is the current scaling mode for this buffer slot.
|
||||
uint32_t mScalingMode;
|
||||
|
||||
// mTimestamp is the current timestamp for this buffer slot. This gets
|
||||
// to set by queueBuffer each time this slot is queued.
|
||||
int64_t mTimestamp;
|
||||
|
||||
// mFrameNumber is the number of the queued frame for this slot.
|
||||
uint64_t mFrameNumber;
|
||||
|
||||
// mBuf is the slot index of this buffer
|
||||
int mBuf;
|
||||
|
||||
// mFence is a fence that will signal when the buffer is idle.
|
||||
sp<Fence> mFence;
|
||||
|
||||
// Indicates whether this buffer is used for trick mode
|
||||
bool mTrickMode;
|
||||
|
||||
// Indicate current video session ID
|
||||
uint32_t mVideoSessionID;
|
||||
};
|
||||
|
||||
// The following public functions are the consumer-facing interface
|
||||
|
||||
// acquireBuffer attempts to acquire ownership of the next pending buffer in
|
||||
// the BufferQueue. If no buffer is pending then it returns -EINVAL. If a
|
||||
// buffer is successfully acquired, the information about the buffer is
|
||||
// returned in BufferItem. If the buffer returned had previously been
|
||||
// acquired then the BufferItem::mGraphicBuffer field of buffer is set to
|
||||
// NULL and it is assumed that the consumer still holds a reference to the
|
||||
// buffer.
|
||||
status_t acquireBuffer(BufferItem *buffer);
|
||||
|
||||
// releaseBuffer releases a buffer slot from the consumer back to the
|
||||
// BufferQueue. This may be done while the buffer's contents are still
|
||||
// being accessed. The fence will signal when the buffer is no longer
|
||||
// in use.
|
||||
//
|
||||
// If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
|
||||
// any references to the just-released buffer that it might have, as if it
|
||||
// had received a onBuffersReleased() call with a mask set for the released
|
||||
// buffer.
|
||||
//
|
||||
// Note that the dependencies on EGL will be removed once we switch to using
|
||||
// the Android HW Sync HAL.
|
||||
status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence,
|
||||
const sp<Fence>& releaseFence);
|
||||
|
||||
// consumerConnect connects a consumer to the BufferQueue. Only one
|
||||
// consumer may be connected, and when that consumer disconnects the
|
||||
// BufferQueue is placed into the "abandoned" state, causing most
|
||||
// interactions with the BufferQueue by the producer to fail.
|
||||
//
|
||||
// consumer may not be NULL.
|
||||
status_t consumerConnect(const sp<ConsumerListener>& consumer);
|
||||
|
||||
// consumerDisconnect disconnects a consumer from the BufferQueue. All
|
||||
// buffers will be freed and the BufferQueue is placed in the "abandoned"
|
||||
// state, causing most interactions with the BufferQueue by the producer to
|
||||
// fail.
|
||||
status_t consumerDisconnect();
|
||||
|
||||
// getReleasedBuffers sets the value pointed to by slotMask to a bit mask
|
||||
// indicating which buffer slots have been released by the BufferQueue
|
||||
// but have not yet been released by the consumer.
|
||||
//
|
||||
// This should be called from the onBuffersReleased() callback.
|
||||
status_t getReleasedBuffers(uint64_t* slotMask);
|
||||
|
||||
// setDefaultBufferSize is used to set the size of buffers returned by
|
||||
// dequeueBuffer when a width and height of zero is requested. Default
|
||||
// is 1x1.
|
||||
status_t setDefaultBufferSize(uint32_t w, uint32_t h);
|
||||
|
||||
// setDefaultMaxBufferCount sets the default value for the maximum buffer
|
||||
// count (the initial default is 2). If the producer has requested a
|
||||
// buffer count using setBufferCount, the default buffer count will only
|
||||
// take effect if the producer sets the count back to zero.
|
||||
//
|
||||
// The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
|
||||
status_t setDefaultMaxBufferCount(int bufferCount);
|
||||
|
||||
// setMaxAcquiredBufferCount sets the maximum number of buffers that can
|
||||
// be acquired by the consumer at one time (default 1). This call will
|
||||
// fail if a producer is connected to the BufferQueue.
|
||||
status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);
|
||||
|
||||
// isSynchronousMode returns whether the BufferQueue is currently in
|
||||
// synchronous mode.
|
||||
bool isSynchronousMode() const;
|
||||
|
||||
// setConsumerName sets the name used in logging
|
||||
void setConsumerName(const String8& name);
|
||||
|
||||
// setDefaultBufferFormat allows the BufferQueue to create
|
||||
// GraphicBuffers of a defaultFormat if no format is specified
|
||||
// in dequeueBuffer. Formats are enumerated in graphics.h; the
|
||||
// initial default is HAL_PIXEL_FORMAT_RGBA_8888.
|
||||
status_t setDefaultBufferFormat(uint32_t defaultFormat);
|
||||
|
||||
// setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
|
||||
// These are merged with the bits passed to dequeueBuffer. The values are
|
||||
// enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
|
||||
status_t setConsumerUsageBits(uint32_t usage);
|
||||
|
||||
// setTransformHint bakes in rotation to buffers so overlays can be used.
|
||||
// The values are enumerated in window.h, e.g.
|
||||
// NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform).
|
||||
status_t setTransformHint(uint32_t hint);
|
||||
|
||||
private:
|
||||
// freeBufferLocked frees the GraphicBuffer and sync resources for the
|
||||
// given slot.
|
||||
void freeBufferLocked(int index);
|
||||
|
||||
// freeAllBuffersLocked frees the GraphicBuffer and sync resources for
|
||||
// all slots.
|
||||
void freeAllBuffersLocked();
|
||||
|
||||
// freeAllBuffersExceptHeadLocked frees the GraphicBuffer and sync
|
||||
// resources for all slots except the head of mQueue.
|
||||
void freeAllBuffersExceptHeadLocked();
|
||||
|
||||
// drainQueueLocked waits for the buffer queue to empty if we're in
|
||||
// synchronous mode, or returns immediately otherwise. It returns NO_INIT
|
||||
// if the BufferQueue is abandoned (consumer disconnected) or disconnected
|
||||
// (producer disconnected) during the call.
|
||||
status_t drainQueueLocked();
|
||||
|
||||
// drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
|
||||
// synchronous mode and free all buffers. In asynchronous mode, all buffers
|
||||
// are freed except the currently queued buffer (if it exists).
|
||||
status_t drainQueueAndFreeBuffersLocked();
|
||||
|
||||
// setDefaultMaxBufferCountLocked sets the maximum number of buffer slots
|
||||
// that will be used if the producer does not override the buffer slot
|
||||
// count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
|
||||
// The initial default is 2.
|
||||
status_t setDefaultMaxBufferCountLocked(int count);
|
||||
|
||||
// getMinBufferCountLocked returns the minimum number of buffers allowed
|
||||
// given the current BufferQueue state.
|
||||
int getMinMaxBufferCountLocked() const;
|
||||
|
||||
// getMinUndequeuedBufferCountLocked returns the minimum number of buffers
|
||||
// that must remain in a state other than DEQUEUED.
|
||||
int getMinUndequeuedBufferCountLocked() const;
|
||||
|
||||
// getMaxBufferCountLocked returns the maximum number of buffers that can
|
||||
// be allocated at once. This value depends upon the following member
|
||||
// variables:
|
||||
//
|
||||
// mSynchronousMode
|
||||
// mMaxAcquiredBufferCount
|
||||
// mDefaultMaxBufferCount
|
||||
// mOverrideMaxBufferCount
|
||||
//
|
||||
// Any time one of these member variables is changed while a producer is
|
||||
// connected, mDequeueCondition must be broadcast.
|
||||
int getMaxBufferCountLocked() const;
|
||||
|
||||
struct BufferSlot {
|
||||
|
||||
BufferSlot()
|
||||
: mEglDisplay(EGL_NO_DISPLAY),
|
||||
mBufferState(BufferSlot::FREE),
|
||||
mRequestBufferCalled(false),
|
||||
mTransform(0),
|
||||
mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
|
||||
mTimestamp(0),
|
||||
mFrameNumber(0),
|
||||
mEglFence(EGL_NO_SYNC_KHR),
|
||||
mAcquireCalled(false),
|
||||
mTrickMode(false),
|
||||
mNeedsCleanupOnRelease(false),
|
||||
mVideoSessionID(0) {
|
||||
mCrop.makeInvalid();
|
||||
}
|
||||
|
||||
// mGraphicBuffer points to the buffer allocated for this slot or is NULL
|
||||
// if no buffer has been allocated.
|
||||
sp<GraphicBuffer> mGraphicBuffer;
|
||||
|
||||
// mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects.
|
||||
EGLDisplay mEglDisplay;
|
||||
|
||||
// BufferState represents the different states in which a buffer slot
|
||||
// can be. All slots are initially FREE.
|
||||
enum BufferState {
|
||||
// FREE indicates that the buffer is available to be dequeued
|
||||
// by the producer. The buffer may be in use by the consumer for
|
||||
// a finite time, so the buffer must not be modified until the
|
||||
// associated fence is signaled.
|
||||
//
|
||||
// The slot is "owned" by BufferQueue. It transitions to DEQUEUED
|
||||
// when dequeueBuffer is called.
|
||||
FREE = 0,
|
||||
|
||||
// DEQUEUED indicates that the buffer has been dequeued by the
|
||||
// producer, but has not yet been queued or canceled. The
|
||||
// producer may modify the buffer's contents as soon as the
|
||||
// associated ready fence is signaled.
|
||||
//
|
||||
// The slot is "owned" by the producer. It can transition to
|
||||
// QUEUED (via queueBuffer) or back to FREE (via cancelBuffer).
|
||||
DEQUEUED = 1,
|
||||
|
||||
// QUEUED indicates that the buffer has been filled by the
|
||||
// producer and queued for use by the consumer. The buffer
|
||||
// contents may continue to be modified for a finite time, so
|
||||
// the contents must not be accessed until the associated fence
|
||||
// is signaled.
|
||||
//
|
||||
// The slot is "owned" by BufferQueue. It can transition to
|
||||
// ACQUIRED (via acquireBuffer) or to FREE (if another buffer is
|
||||
// queued in asynchronous mode).
|
||||
QUEUED = 2,
|
||||
|
||||
// ACQUIRED indicates that the buffer has been acquired by the
|
||||
// consumer. As with QUEUED, the contents must not be accessed
|
||||
// by the consumer until the fence is signaled.
|
||||
//
|
||||
// The slot is "owned" by the consumer. It transitions to FREE
|
||||
// when releaseBuffer is called.
|
||||
ACQUIRED = 3
|
||||
};
|
||||
|
||||
// mBufferState is the current state of this buffer slot.
|
||||
BufferState mBufferState;
|
||||
|
||||
// mRequestBufferCalled is used for validating that the producer did
|
||||
// call requestBuffer() when told to do so. Technically this is not
|
||||
// needed but useful for debugging and catching producer bugs.
|
||||
bool mRequestBufferCalled;
|
||||
|
||||
// mCrop is the current crop rectangle for this buffer slot.
|
||||
Rect mCrop;
|
||||
|
||||
// mTransform is the current transform flags for this buffer slot.
|
||||
// (example: NATIVE_WINDOW_TRANSFORM_ROT_90)
|
||||
uint32_t mTransform;
|
||||
|
||||
// mScalingMode is the current scaling mode for this buffer slot.
|
||||
// (example: NATIVE_WINDOW_SCALING_MODE_FREEZE)
|
||||
// refer the definition in system/core/include/system/window.h
|
||||
// FIXME: This variable is reused by MDS(HDMI middleware) to pass video sessionID
|
||||
// Original usage only use low 2 bits, MDS reuse it like this:
|
||||
// Bit 30: trcik mode (HDMI timing seeking)
|
||||
// Bit 29: has video session ID?
|
||||
// Bit 24 ~ 27: video session ID
|
||||
uint32_t mScalingMode;
|
||||
|
||||
// mTimestamp is the current timestamp for this buffer slot. This gets
|
||||
// to set by queueBuffer each time this slot is queued.
|
||||
int64_t mTimestamp;
|
||||
|
||||
// mFrameNumber is the number of the queued frame for this slot. This
|
||||
// is used to dequeue buffers in LRU order (useful because buffers
|
||||
// may be released before their release fence is signaled).
|
||||
uint64_t mFrameNumber;
|
||||
|
||||
// mEglFence is the EGL sync object that must signal before the buffer
|
||||
// associated with this buffer slot may be dequeued. It is initialized
|
||||
// to EGL_NO_SYNC_KHR when the buffer is created and may be set to a
|
||||
// new sync object in releaseBuffer. (This is deprecated in favor of
|
||||
// mFence, below.)
|
||||
EGLSyncKHR mEglFence;
|
||||
|
||||
// mFence is a fence which will signal when work initiated by the
|
||||
// previous owner of the buffer is finished. When the buffer is FREE,
|
||||
// the fence indicates when the consumer has finished reading
|
||||
// from the buffer, or when the producer has finished writing if it
|
||||
// called cancelBuffer after queueing some writes. When the buffer is
|
||||
// QUEUED, it indicates when the producer has finished filling the
|
||||
// buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
|
||||
// passed to the consumer or producer along with ownership of the
|
||||
// buffer, and mFence is set to NO_FENCE.
|
||||
sp<Fence> mFence;
|
||||
|
||||
// Indicates whether this buffer has been seen by a consumer yet
|
||||
bool mAcquireCalled;
|
||||
|
||||
// Indicates whether this buffer needs to be cleaned up by the
|
||||
// consumer. This is set when a buffer in ACQUIRED state is freed.
|
||||
// It causes releaseBuffer to return STALE_BUFFER_SLOT.
|
||||
bool mNeedsCleanupOnRelease;
|
||||
|
||||
// Indicates whether this buffer is used for trick mode
|
||||
bool mTrickMode;
|
||||
|
||||
// Indicate current video session ID
|
||||
uint32_t mVideoSessionID;
|
||||
};
|
||||
|
||||
// mSlots is the array of buffer slots that must be mirrored on the
|
||||
// producer side. This allows buffer ownership to be transferred between
|
||||
// the producer and consumer without sending a GraphicBuffer over binder.
|
||||
// The entire array is initialized to NULL at construction time, and
|
||||
// buffers are allocated for a slot when requestBuffer is called with
|
||||
// that slot's index.
|
||||
BufferSlot mSlots[NUM_BUFFER_SLOTS];
|
||||
|
||||
// mDefaultWidth holds the default width of allocated buffers. It is used
|
||||
// in dequeueBuffer() if a width and height of zero is specified.
|
||||
uint32_t mDefaultWidth;
|
||||
|
||||
// mDefaultHeight holds the default height of allocated buffers. It is used
|
||||
// in dequeueBuffer() if a width and height of zero is specified.
|
||||
uint32_t mDefaultHeight;
|
||||
|
||||
// mMaxAcquiredBufferCount is the number of buffers that the consumer may
|
||||
// acquire at one time. It defaults to 1 and can be changed by the
|
||||
// consumer via the setMaxAcquiredBufferCount method, but this may only be
|
||||
// done when no producer is connected to the BufferQueue.
|
||||
//
|
||||
// This value is used to derive the value returned for the
|
||||
// MIN_UNDEQUEUED_BUFFERS query by the producer.
|
||||
int mMaxAcquiredBufferCount;
|
||||
|
||||
// mDefaultMaxBufferCount is the default limit on the number of buffers
|
||||
// that will be allocated at one time. This default limit is set by the
|
||||
// consumer. The limit (as opposed to the default limit) may be
|
||||
// overridden by the producer.
|
||||
int mDefaultMaxBufferCount;
|
||||
|
||||
// mOverrideMaxBufferCount is the limit on the number of buffers that will
|
||||
// be allocated at one time. This value is set by the image producer by
|
||||
// calling setBufferCount. The default is zero, which means the producer
|
||||
// doesn't care about the number of buffers in the pool. In that case
|
||||
// mDefaultMaxBufferCount is used as the limit.
|
||||
int mOverrideMaxBufferCount;
|
||||
|
||||
// mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
|
||||
// allocate new GraphicBuffer objects.
|
||||
sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
|
||||
|
||||
// mConsumerListener is used to notify the connected consumer of
|
||||
// asynchronous events that it may wish to react to. It is initially set
|
||||
// to NULL and is written by consumerConnect and consumerDisconnect.
|
||||
sp<ConsumerListener> mConsumerListener;
|
||||
|
||||
// mSynchronousMode whether we're in synchronous mode or not
|
||||
bool mSynchronousMode;
|
||||
|
||||
// mAllowSynchronousMode whether we allow synchronous mode or not. Set
|
||||
// when the BufferQueue is created (by the consumer).
|
||||
const bool mAllowSynchronousMode;
|
||||
|
||||
// mConnectedApi indicates the producer API that is currently connected
|
||||
// to this BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets
|
||||
// updated by the connect and disconnect methods.
|
||||
int mConnectedApi;
|
||||
|
||||
// mDequeueCondition condition used for dequeueBuffer in synchronous mode
|
||||
mutable Condition mDequeueCondition;
|
||||
|
||||
// mQueue is a FIFO of queued buffers used in synchronous mode
|
||||
typedef Vector<int> Fifo;
|
||||
Fifo mQueue;
|
||||
|
||||
// mAbandoned indicates that the BufferQueue will no longer be used to
|
||||
// consume image buffers pushed to it using the IGraphicBufferProducer
|
||||
// interface. It is initialized to false, and set to true in the
|
||||
// consumerDisconnect method. A BufferQueue that has been abandoned will
|
||||
// return the NO_INIT error from all IGraphicBufferProducer methods
|
||||
// capable of returning an error.
|
||||
bool mAbandoned;
|
||||
|
||||
// mConsumerName is a string used to identify the BufferQueue in log
|
||||
// messages. It is set by the setConsumerName method.
|
||||
String8 mConsumerName;
|
||||
|
||||
// mMutex is the mutex used to prevent concurrent access to the member
|
||||
// variables of BufferQueue objects. It must be locked whenever the
|
||||
// member variables are accessed.
|
||||
mutable Mutex mMutex;
|
||||
|
||||
// mFrameCounter is the free running counter, incremented on every
|
||||
// successful queueBuffer call.
|
||||
uint64_t mFrameCounter;
|
||||
|
||||
// mBufferHasBeenQueued is true once a buffer has been queued. It is
|
||||
// reset when something causes all buffers to be freed (e.g. changing the
|
||||
// buffer count).
|
||||
bool mBufferHasBeenQueued;
|
||||
|
||||
// mDefaultBufferFormat can be set so it will override
|
||||
// the buffer format when it isn't specified in dequeueBuffer
|
||||
uint32_t mDefaultBufferFormat;
|
||||
|
||||
// mConsumerUsageBits contains flags the consumer wants for GraphicBuffers
|
||||
uint32_t mConsumerUsageBits;
|
||||
|
||||
// mTransformHint is used to optimize for screen rotations
|
||||
uint32_t mTransformHint;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_BUFFERQUEUE_H
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_CONSUMERBASE_H
|
||||
#define ANDROID_GUI_CONSUMERBASE_H
|
||||
|
||||
#include <gui/BufferQueue.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
namespace android {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class String8;
|
||||
|
||||
// ConsumerBase is a base class for BufferQueue consumer end-points. It
|
||||
// handles common tasks like management of the connection to the BufferQueue
|
||||
// and the buffer pool.
|
||||
class ConsumerBase : public virtual RefBase,
|
||||
protected BufferQueue::ConsumerListener {
|
||||
public:
|
||||
struct FrameAvailableListener : public virtual RefBase {
|
||||
// onFrameAvailable() is called each time an additional frame becomes
|
||||
// available for consumption. This means that frames that are queued
|
||||
// while in asynchronous mode only trigger the callback if no previous
|
||||
// frames are pending. Frames queued while in synchronous mode always
|
||||
// trigger the callback.
|
||||
//
|
||||
// This is called without any lock held and can be called concurrently
|
||||
// by multiple threads.
|
||||
virtual void onFrameAvailable() = 0;
|
||||
};
|
||||
|
||||
virtual ~ConsumerBase();
|
||||
|
||||
// abandon frees all the buffers and puts the ConsumerBase into the
|
||||
// 'abandoned' state. Once put in this state the ConsumerBase can never
|
||||
// leave it. When in the 'abandoned' state, all methods of the
|
||||
// IGraphicBufferProducer interface will fail with the NO_INIT error.
|
||||
//
|
||||
// Note that while calling this method causes all the buffers to be freed
|
||||
// from the perspective of the the ConsumerBase, if there are additional
|
||||
// references on the buffers (e.g. if a buffer is referenced by a client
|
||||
// or by OpenGL ES as a texture) then those buffer will remain allocated.
|
||||
void abandon();
|
||||
|
||||
// set the name of the ConsumerBase that will be used to identify it in
|
||||
// log messages.
|
||||
void setName(const String8& name);
|
||||
|
||||
// getBufferQueue returns the BufferQueue object to which this
|
||||
// ConsumerBase is connected.
|
||||
sp<BufferQueue> getBufferQueue() const;
|
||||
|
||||
// dump writes the current state to a string. Child classes should add
|
||||
// their state to the dump by overriding the dumpLocked method, which is
|
||||
// called by these methods after locking the mutex.
|
||||
void dump(String8& result) const;
|
||||
void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
|
||||
|
||||
// setFrameAvailableListener sets the listener object that will be notified
|
||||
// when a new frame becomes available.
|
||||
void setFrameAvailableListener(const wp<FrameAvailableListener>& listener);
|
||||
|
||||
private:
|
||||
ConsumerBase(const ConsumerBase&);
|
||||
void operator=(const ConsumerBase&);
|
||||
|
||||
protected:
|
||||
|
||||
// ConsumerBase constructs a new ConsumerBase object to consume image
|
||||
// buffers from the given BufferQueue.
|
||||
ConsumerBase(const sp<BufferQueue> &bufferQueue);
|
||||
|
||||
// onLastStrongRef gets called by RefBase just before the dtor of the most
|
||||
// derived class. It is used to clean up the buffers so that ConsumerBase
|
||||
// can coordinate the clean-up by calling into virtual methods implemented
|
||||
// by the derived classes. This would not be possible from the
|
||||
// ConsuemrBase dtor because by the time that gets called the derived
|
||||
// classes have already been destructed.
|
||||
//
|
||||
// This methods should not need to be overridden by derived classes, but
|
||||
// if they are overridden the ConsumerBase implementation must be called
|
||||
// from the derived class.
|
||||
virtual void onLastStrongRef(const void* id);
|
||||
|
||||
// Implementation of the BufferQueue::ConsumerListener interface. These
|
||||
// calls are used to notify the ConsumerBase of asynchronous events in the
|
||||
// BufferQueue. These methods should not need to be overridden by derived
|
||||
// classes, but if they are overridden the ConsumerBase implementation
|
||||
// must be called from the derived class.
|
||||
virtual void onFrameAvailable();
|
||||
virtual void onBuffersReleased();
|
||||
|
||||
// freeBufferLocked frees up the given buffer slot. If the slot has been
|
||||
// initialized this will release the reference to the GraphicBuffer in that
|
||||
// slot. Otherwise it has no effect.
|
||||
//
|
||||
// Derived classes should override this method to clean up any state they
|
||||
// keep per slot. If it is overridden, the derived class's implementation
|
||||
// must call ConsumerBase::freeBufferLocked.
|
||||
//
|
||||
// This method must be called with mMutex locked.
|
||||
virtual void freeBufferLocked(int slotIndex);
|
||||
|
||||
// abandonLocked puts the BufferQueue into the abandoned state, causing
|
||||
// all future operations on it to fail. This method rather than the public
|
||||
// abandon method should be overridden by child classes to add abandon-
|
||||
// time behavior.
|
||||
//
|
||||
// Derived classes should override this method to clean up any object
|
||||
// state they keep (as opposed to per-slot state). If it is overridden,
|
||||
// the derived class's implementation must call ConsumerBase::abandonLocked.
|
||||
//
|
||||
// This method must be called with mMutex locked.
|
||||
virtual void abandonLocked();
|
||||
|
||||
// dumpLocked dumps the current state of the ConsumerBase object to the
|
||||
// result string. Each line is prefixed with the string pointed to by the
|
||||
// prefix argument. The buffer argument points to a buffer that may be
|
||||
// used for intermediate formatting data, and the size of that buffer is
|
||||
// indicated by the size argument.
|
||||
//
|
||||
// Derived classes should override this method to dump their internal
|
||||
// state. If this method is overridden the derived class's implementation
|
||||
// should call ConsumerBase::dumpLocked.
|
||||
//
|
||||
// This method must be called with mMutex locked.
|
||||
virtual void dumpLocked(String8& result, const char* prefix, char* buffer,
|
||||
size_t size) const;
|
||||
|
||||
// acquireBufferLocked fetches the next buffer from the BufferQueue and
|
||||
// updates the buffer slot for the buffer returned.
|
||||
//
|
||||
// Derived classes should override this method to perform any
|
||||
// initialization that must take place the first time a buffer is assigned
|
||||
// to a slot. If it is overridden the derived class's implementation must
|
||||
// call ConsumerBase::acquireBufferLocked.
|
||||
virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item);
|
||||
|
||||
// releaseBufferLocked relinquishes control over a buffer, returning that
|
||||
// control to the BufferQueue.
|
||||
//
|
||||
// Derived classes should override this method to perform any cleanup that
|
||||
// must take place when a buffer is released back to the BufferQueue. If
|
||||
// it is overridden the derived class's implementation must call
|
||||
// ConsumerBase::releaseBufferLocked.
|
||||
virtual status_t releaseBufferLocked(int buf, EGLDisplay display,
|
||||
EGLSyncKHR eglFence);
|
||||
|
||||
// addReleaseFence* adds the sync points associated with a fence to the set
|
||||
// of sync points that must be reached before the buffer in the given slot
|
||||
// may be used after the slot has been released. This should be called by
|
||||
// derived classes each time some asynchronous work is kicked off that
|
||||
// references the buffer.
|
||||
status_t addReleaseFence(int slot, const sp<Fence>& fence);
|
||||
status_t addReleaseFenceLocked(int slot, const sp<Fence>& fence);
|
||||
|
||||
// Slot contains the information and object references that
|
||||
// ConsumerBase maintains about a BufferQueue buffer slot.
|
||||
struct Slot {
|
||||
// mGraphicBuffer is the Gralloc buffer store in the slot or NULL if
|
||||
// no Gralloc buffer is in the slot.
|
||||
sp<GraphicBuffer> mGraphicBuffer;
|
||||
|
||||
// mFence is a fence which will signal when the buffer associated with
|
||||
// this buffer slot is no longer being used by the consumer and can be
|
||||
// overwritten. The buffer can be dequeued before the fence signals;
|
||||
// the producer is responsible for delaying writes until it signals.
|
||||
sp<Fence> mFence;
|
||||
};
|
||||
|
||||
// mSlots stores the buffers that have been allocated by the BufferQueue
|
||||
// for each buffer slot. It is initialized to null pointers, and gets
|
||||
// filled in with the result of BufferQueue::acquire when the
|
||||
// client dequeues a buffer from a
|
||||
// slot that has not yet been used. The buffer allocated to a slot will also
|
||||
// be replaced if the requested buffer usage or geometry differs from that
|
||||
// of the buffer allocated to a slot.
|
||||
Slot mSlots[BufferQueue::NUM_BUFFER_SLOTS];
|
||||
|
||||
// mAbandoned indicates that the BufferQueue will no longer be used to
|
||||
// consume images buffers pushed to it using the IGraphicBufferProducer
|
||||
// interface. It is initialized to false, and set to true in the abandon
|
||||
// method. A BufferQueue that has been abandoned will return the NO_INIT
|
||||
// error from all IConsumerBase methods capable of returning an error.
|
||||
bool mAbandoned;
|
||||
|
||||
// mName is a string used to identify the ConsumerBase in log messages.
|
||||
// It can be set by the setName method.
|
||||
String8 mName;
|
||||
|
||||
// mFrameAvailableListener is the listener object that will be called when a
|
||||
// new frame becomes available. If it is not NULL it will be called from
|
||||
// queueBuffer.
|
||||
wp<FrameAvailableListener> mFrameAvailableListener;
|
||||
|
||||
// The ConsumerBase has-a BufferQueue and is responsible for creating this object
|
||||
// if none is supplied
|
||||
sp<BufferQueue> mBufferQueue;
|
||||
|
||||
// mMutex is the mutex used to prevent concurrent access to the member
|
||||
// variables of ConsumerBase objects. It must be locked whenever the
|
||||
// member variables are accessed or when any of the *Locked methods are
|
||||
// called.
|
||||
//
|
||||
// This mutex is intended to be locked by derived classes.
|
||||
mutable Mutex mMutex;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_CONSUMERBASE_H
|
|
@ -0,0 +1,442 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_CONSUMER_H
|
||||
#define ANDROID_GUI_CONSUMER_H
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <gui/IGraphicBufferProducer.h>
|
||||
#include <gui/BufferQueue.h>
|
||||
#include <gui/ConsumerBase.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture"
|
||||
#define ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID \
|
||||
"mFrameAvailableListener"
|
||||
|
||||
namespace android {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class String8;
|
||||
|
||||
/*
|
||||
* GLConsumer consumes buffers of graphics data from a BufferQueue,
|
||||
* and makes them available to OpenGL as a texture.
|
||||
*
|
||||
* A typical usage pattern is to set up the GLConsumer with the
|
||||
* desired options, and call updateTexImage() when a new frame is desired.
|
||||
* If a new frame is available, the texture will be updated. If not,
|
||||
* the previous contents are retained.
|
||||
*
|
||||
* By default, the texture is attached to the GL_TEXTURE_EXTERNAL_OES
|
||||
* texture target, in the EGL context of the first thread that calls
|
||||
* updateTexImage().
|
||||
*
|
||||
* This class was previously called SurfaceTexture.
|
||||
*/
|
||||
class GLConsumer : public ConsumerBase {
|
||||
public:
|
||||
typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
|
||||
|
||||
// GLConsumer constructs a new GLConsumer object. tex indicates the
|
||||
// name of the OpenGL ES texture to which images are to be streamed.
|
||||
// allowSynchronousMode specifies whether or not synchronous mode can be
|
||||
// enabled. texTarget specifies the OpenGL ES texture target to which the
|
||||
// texture will be bound in updateTexImage. useFenceSync specifies whether
|
||||
// fences should be used to synchronize access to buffers if that behavior
|
||||
// is enabled at compile-time. A custom bufferQueue can be specified
|
||||
// if behavior for queue/dequeue/connect etc needs to be customized.
|
||||
// Otherwise a default BufferQueue will be created and used.
|
||||
//
|
||||
// For legacy reasons, the GLConsumer is created in a state where it is
|
||||
// considered attached to an OpenGL ES context for the purposes of the
|
||||
// attachToContext and detachFromContext methods. However, despite being
|
||||
// considered "attached" to a context, the specific OpenGL ES context
|
||||
// doesn't get latched until the first call to updateTexImage. After that
|
||||
// point, all calls to updateTexImage must be made with the same OpenGL ES
|
||||
// context current.
|
||||
//
|
||||
// A GLConsumer may be detached from one OpenGL ES context and then
|
||||
// attached to a different context using the detachFromContext and
|
||||
// attachToContext methods, respectively. The intention of these methods is
|
||||
// purely to allow a GLConsumer to be transferred from one consumer
|
||||
// context to another. If such a transfer is not needed there is no
|
||||
// requirement that either of these methods be called.
|
||||
GLConsumer(GLuint tex, bool allowSynchronousMode = true,
|
||||
GLenum texTarget = GL_TEXTURE_EXTERNAL_OES, bool useFenceSync = true,
|
||||
const sp<BufferQueue> &bufferQueue = 0);
|
||||
|
||||
virtual ~GLConsumer();
|
||||
|
||||
// updateTexImage acquires the most recently queued buffer, and sets the
|
||||
// image contents of the target texture to it.
|
||||
//
|
||||
// This call may only be made while the OpenGL ES context to which the
|
||||
// target texture belongs is bound to the calling thread.
|
||||
//
|
||||
// This calls doGLFenceWait to ensure proper synchronization.
|
||||
status_t updateTexImage();
|
||||
|
||||
// setReleaseFence stores a fence that will signal when the current buffer
|
||||
// is no longer being read. This fence will be returned to the producer
|
||||
// when the current buffer is released by updateTexImage(). Multiple
|
||||
// fences can be set for a given buffer; they will be merged into a single
|
||||
// union fence.
|
||||
void setReleaseFence(const sp<Fence>& fence);
|
||||
|
||||
// setDefaultMaxBufferCount sets the default limit on the maximum number
|
||||
// of buffers that will be allocated at one time. The image producer may
|
||||
// override the limit.
|
||||
status_t setDefaultMaxBufferCount(int bufferCount);
|
||||
|
||||
// getTransformMatrix retrieves the 4x4 texture coordinate transform matrix
|
||||
// associated with the texture image set by the most recent call to
|
||||
// updateTexImage.
|
||||
//
|
||||
// This transform matrix maps 2D homogeneous texture coordinates of the form
|
||||
// (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture
|
||||
// coordinate that should be used to sample that location from the texture.
|
||||
// Sampling the texture outside of the range of this transform is undefined.
|
||||
//
|
||||
// This transform is necessary to compensate for transforms that the stream
|
||||
// content producer may implicitly apply to the content. By forcing users of
|
||||
// a GLConsumer to apply this transform we avoid performing an extra
|
||||
// copy of the data that would be needed to hide the transform from the
|
||||
// user.
|
||||
//
|
||||
// The matrix is stored in column-major order so that it may be passed
|
||||
// directly to OpenGL ES via the glLoadMatrixf or glUniformMatrix4fv
|
||||
// functions.
|
||||
void getTransformMatrix(float mtx[16]);
|
||||
|
||||
// getTimestamp retrieves the timestamp associated with the texture image
|
||||
// set by the most recent call to updateTexImage.
|
||||
//
|
||||
// The timestamp is in nanoseconds, and is monotonically increasing. Its
|
||||
// other semantics (zero point, etc) are source-dependent and should be
|
||||
// documented by the source.
|
||||
int64_t getTimestamp();
|
||||
|
||||
// setDefaultBufferSize is used to set the size of buffers returned by
|
||||
// requestBuffers when a with and height of zero is requested.
|
||||
// A call to setDefaultBufferSize() may trigger requestBuffers() to
|
||||
// be called from the client.
|
||||
// The width and height parameters must be no greater than the minimum of
|
||||
// GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
|
||||
// An error due to invalid dimensions might not be reported until
|
||||
// updateTexImage() is called.
|
||||
status_t setDefaultBufferSize(uint32_t width, uint32_t height);
|
||||
|
||||
// setFilteringEnabled sets whether the transform matrix should be computed
|
||||
// for use with bilinear filtering.
|
||||
void setFilteringEnabled(bool enabled);
|
||||
|
||||
// getCurrentBuffer returns the buffer associated with the current image.
|
||||
sp<GraphicBuffer> getCurrentBuffer() const;
|
||||
|
||||
// getCurrentTextureTarget returns the texture target of the current
|
||||
// texture as returned by updateTexImage().
|
||||
GLenum getCurrentTextureTarget() const;
|
||||
|
||||
// getCurrentCrop returns the cropping rectangle of the current buffer.
|
||||
Rect getCurrentCrop() const;
|
||||
|
||||
// getCurrentTransform returns the transform of the current buffer.
|
||||
uint32_t getCurrentTransform() const;
|
||||
|
||||
// getCurrentScalingMode returns the scaling mode of the current buffer.
|
||||
uint32_t getCurrentScalingMode() const;
|
||||
|
||||
// getCurrentFence returns the fence indicating when the current buffer is
|
||||
// ready to be read from.
|
||||
sp<Fence> getCurrentFence() const;
|
||||
|
||||
// doGLFenceWait inserts a wait command into the OpenGL ES command stream
|
||||
// to ensure that it is safe for future OpenGL ES commands to access the
|
||||
// current texture buffer.
|
||||
status_t doGLFenceWait() const;
|
||||
|
||||
// isSynchronousMode returns whether the GLConsumer is currently in
|
||||
// synchronous mode.
|
||||
bool isSynchronousMode() const;
|
||||
|
||||
// set the name of the GLConsumer that will be used to identify it in
|
||||
// log messages.
|
||||
void setName(const String8& name);
|
||||
|
||||
// getTrickMode returns whether video is in trick playback
|
||||
bool getTrickMode() const;
|
||||
|
||||
// getVideoSessionID returns video session ID
|
||||
uint32_t getVideoSessionID() const;
|
||||
|
||||
// These functions call the corresponding BufferQueue implementation
|
||||
// so the refactoring can proceed smoothly
|
||||
status_t setDefaultBufferFormat(uint32_t defaultFormat);
|
||||
status_t setConsumerUsageBits(uint32_t usage);
|
||||
status_t setTransformHint(uint32_t hint);
|
||||
virtual status_t setSynchronousMode(bool enabled);
|
||||
|
||||
// getBufferQueue returns the BufferQueue object to which this
|
||||
// GLConsumer is connected.
|
||||
sp<BufferQueue> getBufferQueue() const {
|
||||
return mBufferQueue;
|
||||
}
|
||||
|
||||
// detachFromContext detaches the GLConsumer from the calling thread's
|
||||
// current OpenGL ES context. This context must be the same as the context
|
||||
// that was current for previous calls to updateTexImage.
|
||||
//
|
||||
// Detaching a GLConsumer from an OpenGL ES context will result in the
|
||||
// deletion of the OpenGL ES texture object into which the images were being
|
||||
// streamed. After a GLConsumer has been detached from the OpenGL ES
|
||||
// context calls to updateTexImage will fail returning INVALID_OPERATION
|
||||
// until the GLConsumer is attached to a new OpenGL ES context using the
|
||||
// attachToContext method.
|
||||
status_t detachFromContext();
|
||||
|
||||
// attachToContext attaches a GLConsumer that is currently in the
|
||||
// 'detached' state to the current OpenGL ES context. A GLConsumer is
|
||||
// in the 'detached' state iff detachFromContext has successfully been
|
||||
// called and no calls to attachToContext have succeeded since the last
|
||||
// detachFromContext call. Calls to attachToContext made on a
|
||||
// GLConsumer that is not in the 'detached' state will result in an
|
||||
// INVALID_OPERATION error.
|
||||
//
|
||||
// The tex argument specifies the OpenGL ES texture object name in the
|
||||
// new context into which the image contents will be streamed. A successful
|
||||
// call to attachToContext will result in this texture object being bound to
|
||||
// the texture target and populated with the image contents that were
|
||||
// current at the time of the last call to detachFromContext.
|
||||
status_t attachToContext(GLuint tex);
|
||||
|
||||
protected:
|
||||
|
||||
// abandonLocked overrides the ConsumerBase method to clear
|
||||
// mCurrentTextureBuf in addition to the ConsumerBase behavior.
|
||||
virtual void abandonLocked();
|
||||
|
||||
// dumpLocked overrides the ConsumerBase method to dump GLConsumer-
|
||||
// specific info in addition to the ConsumerBase behavior.
|
||||
virtual void dumpLocked(String8& result, const char* prefix, char* buffer,
|
||||
size_t size) const;
|
||||
|
||||
// acquireBufferLocked overrides the ConsumerBase method to update the
|
||||
// mEglSlots array in addition to the ConsumerBase behavior.
|
||||
virtual status_t acquireBufferLocked(BufferQueue::BufferItem *item);
|
||||
|
||||
// releaseBufferLocked overrides the ConsumerBase method to update the
|
||||
// mEglSlots array in addition to the ConsumerBase.
|
||||
virtual status_t releaseBufferLocked(int buf, EGLDisplay display,
|
||||
EGLSyncKHR eglFence);
|
||||
|
||||
status_t releaseBufferLocked(int buf, EGLSyncKHR eglFence) {
|
||||
return releaseBufferLocked(buf, mEglDisplay, eglFence);
|
||||
}
|
||||
|
||||
static bool isExternalFormat(uint32_t format);
|
||||
|
||||
// This releases the buffer in the slot referenced by mCurrentTexture,
|
||||
// then updates state to refer to the BufferItem, which must be a
|
||||
// newly-acquired buffer.
|
||||
status_t releaseAndUpdateLocked(const BufferQueue::BufferItem& item);
|
||||
|
||||
// Binds mTexName and the current buffer to mTexTarget. Uses
|
||||
// mCurrentTexture if it's set, mCurrentTextureBuf if not. If the
|
||||
// bind succeeds, this calls doGLFenceWait.
|
||||
status_t bindTextureImageLocked();
|
||||
|
||||
// Gets the current EGLDisplay and EGLContext values, and compares them
|
||||
// to mEglDisplay and mEglContext. If the fields have been previously
|
||||
// set, the values must match; if not, the fields are set to the current
|
||||
// values.
|
||||
status_t checkAndUpdateEglStateLocked();
|
||||
|
||||
private:
|
||||
// createImage creates a new EGLImage from a GraphicBuffer.
|
||||
EGLImageKHR createImage(EGLDisplay dpy,
|
||||
const sp<GraphicBuffer>& graphicBuffer);
|
||||
|
||||
// freeBufferLocked frees up the given buffer slot. If the slot has been
|
||||
// initialized this will release the reference to the GraphicBuffer in that
|
||||
// slot and destroy the EGLImage in that slot. Otherwise it has no effect.
|
||||
//
|
||||
// This method must be called with mMutex locked.
|
||||
virtual void freeBufferLocked(int slotIndex);
|
||||
|
||||
// computeCurrentTransformMatrixLocked computes the transform matrix for the
|
||||
// current texture. It uses mCurrentTransform and the current GraphicBuffer
|
||||
// to compute this matrix and stores it in mCurrentTransformMatrix.
|
||||
// mCurrentTextureBuf must not be NULL.
|
||||
void computeCurrentTransformMatrixLocked();
|
||||
|
||||
// doGLFenceWaitLocked inserts a wait command into the OpenGL ES command
|
||||
// stream to ensure that it is safe for future OpenGL ES commands to
|
||||
// access the current texture buffer.
|
||||
status_t doGLFenceWaitLocked() const;
|
||||
|
||||
// syncForReleaseLocked performs the synchronization needed to release the
|
||||
// current slot from an OpenGL ES context. If needed it will set the
|
||||
// current slot's fence to guard against a producer accessing the buffer
|
||||
// before the outstanding accesses have completed.
|
||||
status_t syncForReleaseLocked(EGLDisplay dpy);
|
||||
|
||||
// Normally, when we bind a buffer to a texture target, we bind a buffer
|
||||
// that is referenced by an entry in mEglSlots. In some situations we
|
||||
// have a buffer in mCurrentTextureBuf, but no corresponding entry for
|
||||
// it in our slot array. bindUnslottedBuffer handles that situation by
|
||||
// binding the buffer without touching the EglSlots.
|
||||
status_t bindUnslottedBufferLocked(EGLDisplay dpy);
|
||||
|
||||
// The default consumer usage flags that GLConsumer always sets on its
|
||||
// BufferQueue instance; these will be OR:d with any additional flags passed
|
||||
// from the GLConsumer user. In particular, GLConsumer will always
|
||||
// consume buffers as hardware textures.
|
||||
static const uint32_t DEFAULT_USAGE_FLAGS = GraphicBuffer::USAGE_HW_TEXTURE;
|
||||
|
||||
// mCurrentTextureBuf is the graphic buffer of the current texture. It's
|
||||
// possible that this buffer is not associated with any buffer slot, so we
|
||||
// must track it separately in order to support the getCurrentBuffer method.
|
||||
sp<GraphicBuffer> mCurrentTextureBuf;
|
||||
|
||||
// mCurrentCrop is the crop rectangle that applies to the current texture.
|
||||
// It gets set each time updateTexImage is called.
|
||||
Rect mCurrentCrop;
|
||||
|
||||
// mCurrentTransform is the transform identifier for the current texture. It
|
||||
// gets set each time updateTexImage is called.
|
||||
uint32_t mCurrentTransform;
|
||||
|
||||
// mCurrentScalingMode is the scaling mode for the current texture. It gets
|
||||
// set each time updateTexImage is called.
|
||||
uint32_t mCurrentScalingMode;
|
||||
|
||||
// mCurrentFence is the fence received from BufferQueue in updateTexImage.
|
||||
sp<Fence> mCurrentFence;
|
||||
|
||||
// mCurrentTransformMatrix is the transform matrix for the current texture.
|
||||
// It gets computed by computeTransformMatrix each time updateTexImage is
|
||||
// called.
|
||||
float mCurrentTransformMatrix[16];
|
||||
|
||||
// mCurrentTimestamp is the timestamp for the current texture. It
|
||||
// gets set each time updateTexImage is called.
|
||||
int64_t mCurrentTimestamp;
|
||||
|
||||
uint32_t mDefaultWidth, mDefaultHeight;
|
||||
|
||||
// mFilteringEnabled indicates whether the transform matrix is computed for
|
||||
// use with bilinear filtering. It defaults to true and is changed by
|
||||
// setFilteringEnabled().
|
||||
bool mFilteringEnabled;
|
||||
|
||||
// mTexName is the name of the OpenGL texture to which streamed images will
|
||||
// be bound when updateTexImage is called. It is set at construction time
|
||||
// and can be changed with a call to attachToContext.
|
||||
GLuint mTexName;
|
||||
|
||||
// mUseFenceSync indicates whether creation of the EGL_KHR_fence_sync
|
||||
// extension should be used to prevent buffers from being dequeued before
|
||||
// it's safe for them to be written. It gets set at construction time and
|
||||
// never changes.
|
||||
const bool mUseFenceSync;
|
||||
|
||||
// mTexTarget is the GL texture target with which the GL texture object is
|
||||
// associated. It is set in the constructor and never changed. It is
|
||||
// almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android
|
||||
// Browser. In that case it is set to GL_TEXTURE_2D to allow
|
||||
// glCopyTexSubImage to read from the texture. This is a hack to work
|
||||
// around a GL driver limitation on the number of FBO attachments, which the
|
||||
// browser's tile cache exceeds.
|
||||
const GLenum mTexTarget;
|
||||
|
||||
// EGLSlot contains the information and object references that
|
||||
// GLConsumer maintains about a BufferQueue buffer slot.
|
||||
struct EglSlot {
|
||||
EglSlot()
|
||||
: mEglImage(EGL_NO_IMAGE_KHR),
|
||||
mEglFence(EGL_NO_SYNC_KHR) {
|
||||
}
|
||||
|
||||
// mEglImage is the EGLImage created from mGraphicBuffer.
|
||||
EGLImageKHR mEglImage;
|
||||
|
||||
// mFence is the EGL sync object that must signal before the buffer
|
||||
// associated with this buffer slot may be dequeued. It is initialized
|
||||
// to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
|
||||
// on a compile-time option) set to a new sync object in updateTexImage.
|
||||
EGLSyncKHR mEglFence;
|
||||
};
|
||||
|
||||
// mEglDisplay is the EGLDisplay with which this GLConsumer is currently
|
||||
// associated. It is intialized to EGL_NO_DISPLAY and gets set to the
|
||||
// current display when updateTexImage is called for the first time and when
|
||||
// attachToContext is called.
|
||||
EGLDisplay mEglDisplay;
|
||||
|
||||
// mEglContext is the OpenGL ES context with which this GLConsumer is
|
||||
// currently associated. It is initialized to EGL_NO_CONTEXT and gets set
|
||||
// to the current GL context when updateTexImage is called for the first
|
||||
// time and when attachToContext is called.
|
||||
EGLContext mEglContext;
|
||||
|
||||
// mEGLSlots stores the buffers that have been allocated by the BufferQueue
|
||||
// for each buffer slot. It is initialized to null pointers, and gets
|
||||
// filled in with the result of BufferQueue::acquire when the
|
||||
// client dequeues a buffer from a
|
||||
// slot that has not yet been used. The buffer allocated to a slot will also
|
||||
// be replaced if the requested buffer usage or geometry differs from that
|
||||
// of the buffer allocated to a slot.
|
||||
EglSlot mEglSlots[BufferQueue::NUM_BUFFER_SLOTS];
|
||||
|
||||
// mCurrentTexture is the buffer slot index of the buffer that is currently
|
||||
// bound to the OpenGL texture. It is initialized to INVALID_BUFFER_SLOT,
|
||||
// indicating that no buffer slot is currently bound to the texture. Note,
|
||||
// however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
|
||||
// that no buffer is bound to the texture. A call to setBufferCount will
|
||||
// reset mCurrentTexture to INVALID_BUFFER_SLOT.
|
||||
int mCurrentTexture;
|
||||
|
||||
// mAttached indicates whether the ConsumerBase is currently attached to
|
||||
// an OpenGL ES context. For legacy reasons, this is initialized to true,
|
||||
// indicating that the ConsumerBase is considered to be attached to
|
||||
// whatever context is current at the time of the first updateTexImage call.
|
||||
// It is set to false by detachFromContext, and then set to true again by
|
||||
// attachToContext.
|
||||
bool mAttached;
|
||||
|
||||
// mTrickMode indicates whether the current surface is used for trick
|
||||
// playback.
|
||||
bool mTrickMode;
|
||||
|
||||
// mVideoSessionID indicates video session ID
|
||||
uint32_t mVideoSessionID;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_CONSUMER_H
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_IGRAPHIC_BUFFER_ALLOC_H
|
||||
#define ANDROID_GUI_IGRAPHIC_BUFFER_ALLOC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <binder/IInterface.h>
|
||||
#include <ui/PixelFormat.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class GraphicBuffer;
|
||||
|
||||
class IGraphicBufferAlloc : public IInterface
|
||||
{
|
||||
public:
|
||||
DECLARE_META_INTERFACE(GraphicBufferAlloc);
|
||||
|
||||
/* Create a new GraphicBuffer for the client to use.
|
||||
*/
|
||||
virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
|
||||
PixelFormat format, uint32_t usage, status_t* error) = 0;
|
||||
|
||||
virtual void acquireBufferReferenceSlot(int32_t slot) {}
|
||||
virtual void releaseBufferReferenceSlot(int32_t slot) {}
|
||||
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class BnGraphicBufferAlloc : public BnInterface<IGraphicBufferAlloc>
|
||||
{
|
||||
public:
|
||||
virtual status_t onTransact( uint32_t code,
|
||||
const Parcel& data,
|
||||
Parcel* reply,
|
||||
uint32_t flags = 0);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_IGRAPHIC_BUFFER_ALLOC_H
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
||||
#define ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
#include <binder/IInterface.h>
|
||||
|
||||
#include <ui/Fence.h>
|
||||
#include <ui/GraphicBuffer.h>
|
||||
#include <ui/Rect.h>
|
||||
|
||||
namespace android {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class Surface;
|
||||
|
||||
/*
|
||||
* This class defines the Binder IPC interface for the producer side of
|
||||
* a queue of graphics buffers. It's used to send graphics data from one
|
||||
* component to another. For example, a class that decodes video for
|
||||
* playback might use this to provide frames. This is typically done
|
||||
* indirectly, through Surface.
|
||||
*
|
||||
* The underlying mechanism is a BufferQueue, which implements
|
||||
* BnGraphicBufferProducer. In normal operation, the producer calls
|
||||
* dequeueBuffer() to get an empty buffer, fills it with data, then
|
||||
* calls queueBuffer() to make it available to the consumer.
|
||||
*
|
||||
* This class was previously called ISurfaceTexture.
|
||||
*/
|
||||
class IGraphicBufferProducer : public IInterface
|
||||
{
|
||||
public:
|
||||
DECLARE_META_INTERFACE(GraphicBufferProducer);
|
||||
|
||||
enum {
|
||||
BUFFER_NEEDS_REALLOCATION = 0x1,
|
||||
RELEASE_ALL_BUFFERS = 0x2,
|
||||
};
|
||||
|
||||
// requestBuffer requests a new buffer for the given index. The server (i.e.
|
||||
// the IGraphicBufferProducer implementation) assigns the newly created
|
||||
// buffer to the given slot index, and the client is expected to mirror the
|
||||
// slot->buffer mapping so that it's not necessary to transfer a
|
||||
// GraphicBuffer for every dequeue operation.
|
||||
virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
|
||||
|
||||
// setBufferCount sets the number of buffer slots available. Calling this
|
||||
// will also cause all buffer slots to be emptied. The caller should empty
|
||||
// its mirrored copy of the buffer slots when calling this method.
|
||||
virtual status_t setBufferCount(int bufferCount) = 0;
|
||||
|
||||
// dequeueBuffer requests a new buffer slot for the client to use. Ownership
|
||||
// of the slot is transfered to the client, meaning that the server will not
|
||||
// use the contents of the buffer associated with that slot. The slot index
|
||||
// returned may or may not contain a buffer. If the slot is empty the client
|
||||
// should call requestBuffer to assign a new buffer to that slot. The client
|
||||
// is expected to either call cancelBuffer on the dequeued slot or to fill
|
||||
// in the contents of its associated buffer contents and call queueBuffer.
|
||||
// If dequeueBuffer return BUFFER_NEEDS_REALLOCATION, the client is
|
||||
// expected to call requestBuffer immediately.
|
||||
//
|
||||
// The fence parameter will be updated to hold the fence associated with
|
||||
// the buffer. The contents of the buffer must not be overwritten until the
|
||||
// fence signals. If the fence is NULL, the buffer may be written
|
||||
// immediately.
|
||||
virtual status_t dequeueBuffer(int *slot, sp<Fence>* fence,
|
||||
uint32_t w, uint32_t h, uint32_t format, uint32_t usage) = 0;
|
||||
|
||||
// queueBuffer indicates that the client has finished filling in the
|
||||
// contents of the buffer associated with slot and transfers ownership of
|
||||
// that slot back to the server. It is not valid to call queueBuffer on a
|
||||
// slot that is not owned by the client or one for which a buffer associated
|
||||
// via requestBuffer. In addition, a timestamp must be provided by the
|
||||
// client for this buffer. The timestamp is measured in nanoseconds, and
|
||||
// must be monotonically increasing. Its other properties (zero point, etc)
|
||||
// are client-dependent, and should be documented by the client.
|
||||
//
|
||||
// outWidth, outHeight and outTransform are filled with the default width
|
||||
// and height of the window and current transform applied to buffers,
|
||||
// respectively.
|
||||
|
||||
struct QueueBufferInput : public Flattenable {
|
||||
inline QueueBufferInput(const Parcel& parcel);
|
||||
inline QueueBufferInput(int64_t timestamp,
|
||||
const Rect& crop, int scalingMode, uint32_t transform,
|
||||
sp<Fence> fence)
|
||||
: timestamp(timestamp), crop(crop), scalingMode(scalingMode),
|
||||
transform(transform), fence(fence) { }
|
||||
inline void deflate(int64_t* outTimestamp, Rect* outCrop,
|
||||
int* outScalingMode, uint32_t* outTransform,
|
||||
sp<Fence>* outFence) const {
|
||||
*outTimestamp = timestamp;
|
||||
*outCrop = crop;
|
||||
*outScalingMode = scalingMode;
|
||||
*outTransform = transform;
|
||||
*outFence = fence;
|
||||
}
|
||||
|
||||
// Flattenable interface
|
||||
virtual size_t getFlattenedSize() const;
|
||||
virtual size_t getFdCount() const;
|
||||
virtual status_t flatten(void* buffer, size_t size,
|
||||
int fds[], size_t count) const;
|
||||
virtual status_t unflatten(void const* buffer, size_t size,
|
||||
int fds[], size_t count);
|
||||
|
||||
private:
|
||||
int64_t timestamp;
|
||||
Rect crop;
|
||||
int scalingMode;
|
||||
uint32_t transform;
|
||||
sp<Fence> fence;
|
||||
};
|
||||
|
||||
// QueueBufferOutput must be a POD structure
|
||||
struct QueueBufferOutput {
|
||||
inline QueueBufferOutput() { }
|
||||
inline void deflate(uint32_t* outWidth,
|
||||
uint32_t* outHeight,
|
||||
uint32_t* outTransformHint,
|
||||
uint32_t* outNumPendingBuffers) const {
|
||||
*outWidth = width;
|
||||
*outHeight = height;
|
||||
*outTransformHint = transformHint;
|
||||
*outNumPendingBuffers = numPendingBuffers;
|
||||
}
|
||||
inline void inflate(uint32_t inWidth, uint32_t inHeight,
|
||||
uint32_t inTransformHint, uint32_t inNumPendingBuffers) {
|
||||
width = inWidth;
|
||||
height = inHeight;
|
||||
transformHint = inTransformHint;
|
||||
numPendingBuffers = inNumPendingBuffers;
|
||||
}
|
||||
private:
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t transformHint;
|
||||
uint32_t numPendingBuffers;
|
||||
};
|
||||
|
||||
virtual status_t queueBuffer(int slot,
|
||||
const QueueBufferInput& input, QueueBufferOutput* output) = 0;
|
||||
|
||||
// cancelBuffer indicates that the client does not wish to fill in the
|
||||
// buffer associated with slot and transfers ownership of the slot back to
|
||||
// the server.
|
||||
virtual void cancelBuffer(int slot, const sp<Fence>& fence) = 0;
|
||||
|
||||
// query retrieves some information for this surface
|
||||
// 'what' tokens allowed are that of android_natives.h
|
||||
virtual int query(int what, int* value) = 0;
|
||||
|
||||
// setSynchronousMode set whether dequeueBuffer is synchronous or
|
||||
// asynchronous. In synchronous mode, dequeueBuffer blocks until
|
||||
// a buffer is available, the currently bound buffer can be dequeued and
|
||||
// queued buffers will be retired in order.
|
||||
// The default mode is asynchronous.
|
||||
virtual status_t setSynchronousMode(bool enabled) = 0;
|
||||
|
||||
// connect attempts to connect a client API to the IGraphicBufferProducer.
|
||||
// This must be called before any other IGraphicBufferProducer methods are
|
||||
// called except for getAllocator.
|
||||
//
|
||||
// This method will fail if the connect was previously called on the
|
||||
// IGraphicBufferProducer and no corresponding disconnect call was made.
|
||||
//
|
||||
// outWidth, outHeight and outTransform are filled with the default width
|
||||
// and height of the window and current transform applied to buffers,
|
||||
// respectively.
|
||||
virtual status_t connect(int api, QueueBufferOutput* output) = 0;
|
||||
|
||||
// disconnect attempts to disconnect a client API from the
|
||||
// IGraphicBufferProducer. Calling this method will cause any subsequent
|
||||
// calls to other IGraphicBufferProducer methods to fail except for
|
||||
// getAllocator and connect. Successfully calling connect after this will
|
||||
// allow the other methods to succeed again.
|
||||
//
|
||||
// This method will fail if the the IGraphicBufferProducer is not currently
|
||||
// connected to the specified client API.
|
||||
virtual status_t disconnect(int api) = 0;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class BnGraphicBufferProducer : public BnInterface<IGraphicBufferProducer>
|
||||
{
|
||||
public:
|
||||
virtual status_t onTransact( uint32_t code,
|
||||
const Parcel& data,
|
||||
Parcel* reply,
|
||||
uint32_t flags = 0);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_IGRAPHICBUFFERPRODUCER_H
|
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_SURFACE_H
|
||||
#define ANDROID_GUI_SURFACE_H
|
||||
|
||||
#include <gui/IGraphicBufferProducer.h>
|
||||
#include <gui/GLConsumer.h>
|
||||
#include <gui/BufferQueue.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/Region.h>
|
||||
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/threads.h>
|
||||
#include <utils/KeyedVector.h>
|
||||
|
||||
struct ANativeWindow_Buffer;
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* An implementation of ANativeWindow that feeds graphics buffers into a
|
||||
* BufferQueue.
|
||||
*
|
||||
* This is typically used by programs that want to render frames through
|
||||
* some means (maybe OpenGL, a software renderer, or a hardware decoder)
|
||||
* and have the frames they create forwarded to SurfaceFlinger for
|
||||
* compositing. For example, a video decoder could render a frame and call
|
||||
* eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
|
||||
* Surface. Surface then forwards the buffers through Binder IPC
|
||||
* to the BufferQueue's producer interface, providing the new frame to a
|
||||
* consumer such as GLConsumer.
|
||||
*/
|
||||
class Surface
|
||||
: public ANativeObjectBase<ANativeWindow, Surface, RefBase>
|
||||
{
|
||||
public:
|
||||
|
||||
/*
|
||||
* creates a Surface from the given IGraphicBufferProducer (which concrete
|
||||
* implementation is a BufferQueue).
|
||||
*
|
||||
* Surface is mainly state-less while it's disconnected, it can be
|
||||
* viewed as a glorified IGraphicBufferProducer holder. It's therefore
|
||||
* safe to create other Surfaces from the same IGraphicBufferProducer.
|
||||
*
|
||||
* However, once a Surface is connected, it'll prevent other Surfaces
|
||||
* referring to the same IGraphicBufferProducer to become connected and
|
||||
* therefore prevent them to be used as actual producers of buffers.
|
||||
*/
|
||||
Surface(const sp<IGraphicBufferProducer>& bufferProducer);
|
||||
|
||||
/* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
|
||||
* Surface was created with. Usually it's an error to use the
|
||||
* IGraphicBufferProducer while the Surface is connected.
|
||||
*/
|
||||
sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
|
||||
|
||||
/* convenience function to check that the given surface is non NULL as
|
||||
* well as its IGraphicBufferProducer */
|
||||
static bool isValid(const sp<Surface>& surface) {
|
||||
return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~Surface();
|
||||
|
||||
private:
|
||||
// can't be copied
|
||||
Surface& operator = (const Surface& rhs);
|
||||
Surface(const Surface& rhs);
|
||||
|
||||
// ANativeWindow hooks
|
||||
static int hook_cancelBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer, int fenceFd);
|
||||
static int hook_dequeueBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer** buffer, int* fenceFd);
|
||||
static int hook_perform(ANativeWindow* window, int operation, ...);
|
||||
static int hook_query(const ANativeWindow* window, int what, int* value);
|
||||
static int hook_queueBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer, int fenceFd);
|
||||
static int hook_setSwapInterval(ANativeWindow* window, int interval);
|
||||
|
||||
static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer);
|
||||
static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer** buffer);
|
||||
static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer);
|
||||
static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer);
|
||||
|
||||
int dispatchConnect(va_list args);
|
||||
int dispatchDisconnect(va_list args);
|
||||
int dispatchSetBufferCount(va_list args);
|
||||
int dispatchSetBuffersGeometry(va_list args);
|
||||
int dispatchSetBuffersDimensions(va_list args);
|
||||
int dispatchSetBuffersUserDimensions(va_list args);
|
||||
int dispatchSetBuffersFormat(va_list args);
|
||||
int dispatchSetScalingMode(va_list args);
|
||||
int dispatchSetBuffersTransform(va_list args);
|
||||
int dispatchSetBuffersTimestamp(va_list args);
|
||||
int dispatchSetCrop(va_list args);
|
||||
int dispatchSetPostTransformCrop(va_list args);
|
||||
int dispatchSetUsage(va_list args);
|
||||
int dispatchLock(va_list args);
|
||||
int dispatchUnlockAndPost(va_list args);
|
||||
|
||||
protected:
|
||||
virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
|
||||
virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
|
||||
virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
|
||||
virtual int perform(int operation, va_list args);
|
||||
virtual int query(int what, int* value) const;
|
||||
virtual int setSwapInterval(int interval);
|
||||
|
||||
virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
|
||||
|
||||
virtual int connect(int api);
|
||||
virtual int disconnect(int api);
|
||||
virtual int setBufferCount(int bufferCount);
|
||||
virtual int setBuffersDimensions(int w, int h);
|
||||
virtual int setBuffersUserDimensions(int w, int h);
|
||||
virtual int setBuffersFormat(int format);
|
||||
virtual int setScalingMode(int mode);
|
||||
virtual int setBuffersTransform(int transform);
|
||||
virtual int setBuffersTimestamp(int64_t timestamp);
|
||||
virtual int setCrop(Rect const* rect);
|
||||
virtual int setUsage(uint32_t reqUsage);
|
||||
|
||||
public:
|
||||
virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
|
||||
virtual int unlockAndPost();
|
||||
|
||||
protected:
|
||||
enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS };
|
||||
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
|
||||
|
||||
private:
|
||||
void freeAllBuffers();
|
||||
int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
|
||||
|
||||
struct BufferSlot {
|
||||
sp<GraphicBuffer> buffer;
|
||||
Region dirtyRegion;
|
||||
};
|
||||
|
||||
// mSurfaceTexture is the interface to the surface texture server. All
|
||||
// operations on the surface texture client ultimately translate into
|
||||
// interactions with the server using this interface.
|
||||
// TODO: rename to mBufferProducer
|
||||
sp<IGraphicBufferProducer> mGraphicBufferProducer;
|
||||
|
||||
// mSlots stores the buffers that have been allocated for each buffer slot.
|
||||
// It is initialized to null pointers, and gets filled in with the result of
|
||||
// IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
|
||||
// slot that has not yet been used. The buffer allocated to a slot will also
|
||||
// be replaced if the requested buffer usage or geometry differs from that
|
||||
// of the buffer allocated to a slot.
|
||||
BufferSlot mSlots[NUM_BUFFER_SLOTS];
|
||||
|
||||
// mReqWidth is the buffer width that will be requested at the next dequeue
|
||||
// operation. It is initialized to 1.
|
||||
uint32_t mReqWidth;
|
||||
|
||||
// mReqHeight is the buffer height that will be requested at the next
|
||||
// dequeue operation. It is initialized to 1.
|
||||
uint32_t mReqHeight;
|
||||
|
||||
// mReqFormat is the buffer pixel format that will be requested at the next
|
||||
// deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
|
||||
uint32_t mReqFormat;
|
||||
|
||||
// mReqUsage is the set of buffer usage flags that will be requested
|
||||
// at the next deuque operation. It is initialized to 0.
|
||||
uint32_t mReqUsage;
|
||||
|
||||
// mTimestamp is the timestamp that will be used for the next buffer queue
|
||||
// operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
|
||||
// a timestamp is auto-generated when queueBuffer is called.
|
||||
int64_t mTimestamp;
|
||||
|
||||
// mCrop is the crop rectangle that will be used for the next buffer
|
||||
// that gets queued. It is set by calling setCrop.
|
||||
Rect mCrop;
|
||||
|
||||
// mScalingMode is the scaling mode that will be used for the next
|
||||
// buffers that get queued. It is set by calling setScalingMode.
|
||||
int mScalingMode;
|
||||
|
||||
// mTransform is the transform identifier that will be used for the next
|
||||
// buffer that gets queued. It is set by calling setTransform.
|
||||
uint32_t mTransform;
|
||||
|
||||
// mDefaultWidth is default width of the buffers, regardless of the
|
||||
// native_window_set_buffers_dimensions call.
|
||||
uint32_t mDefaultWidth;
|
||||
|
||||
// mDefaultHeight is default height of the buffers, regardless of the
|
||||
// native_window_set_buffers_dimensions call.
|
||||
uint32_t mDefaultHeight;
|
||||
|
||||
// mUserWidth, if non-zero, is an application-specified override
|
||||
// of mDefaultWidth. This is lower priority than the width set by
|
||||
// native_window_set_buffers_dimensions.
|
||||
uint32_t mUserWidth;
|
||||
|
||||
// mUserHeight, if non-zero, is an application-specified override
|
||||
// of mDefaultHeight. This is lower priority than the height set
|
||||
// by native_window_set_buffers_dimensions.
|
||||
uint32_t mUserHeight;
|
||||
|
||||
// mTransformHint is the transform probably applied to buffers of this
|
||||
// window. this is only a hint, actual transform may differ.
|
||||
uint32_t mTransformHint;
|
||||
|
||||
// mConsumerRunningBehind whether the consumer is running more than
|
||||
// one buffer behind the producer.
|
||||
mutable bool mConsumerRunningBehind;
|
||||
|
||||
// mMutex is the mutex used to prevent concurrent access to the member
|
||||
// variables of Surface objects. It must be locked whenever the
|
||||
// member variables are accessed.
|
||||
mutable Mutex mMutex;
|
||||
|
||||
// must be used from the lock/unlock thread
|
||||
sp<GraphicBuffer> mLockedBuffer;
|
||||
sp<GraphicBuffer> mPostedBuffer;
|
||||
bool mConnectedToCpu;
|
||||
|
||||
// must be accessed from lock/unlock thread only
|
||||
Region mDirtyRegion;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_SURFACE_H
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ANDROID_FB_INTERFACE_H
|
||||
#define ANDROID_FB_INTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
|
||||
#include <hardware/hardware.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define GRALLOC_HARDWARE_FB0 "fb0"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct framebuffer_device_t {
|
||||
struct hw_device_t common;
|
||||
|
||||
/* flags describing some attributes of the framebuffer */
|
||||
const uint32_t flags;
|
||||
|
||||
/* dimensions of the framebuffer in pixels */
|
||||
const uint32_t width;
|
||||
const uint32_t height;
|
||||
|
||||
/* frambuffer stride in pixels */
|
||||
const int stride;
|
||||
|
||||
/* framebuffer pixel format */
|
||||
const int format;
|
||||
|
||||
/* resolution of the framebuffer's display panel in pixel per inch*/
|
||||
const float xdpi;
|
||||
const float ydpi;
|
||||
|
||||
/* framebuffer's display panel refresh rate in frames per second */
|
||||
const float fps;
|
||||
|
||||
/* min swap interval supported by this framebuffer */
|
||||
const int minSwapInterval;
|
||||
|
||||
/* max swap interval supported by this framebuffer */
|
||||
const int maxSwapInterval;
|
||||
|
||||
/* Number of framebuffers supported*/
|
||||
const int numFramebuffers;
|
||||
|
||||
int reserved[7];
|
||||
|
||||
/*
|
||||
* requests a specific swap-interval (same definition than EGL)
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*setSwapInterval)(struct framebuffer_device_t* window,
|
||||
int interval);
|
||||
|
||||
/*
|
||||
* This hook is OPTIONAL.
|
||||
*
|
||||
* It is non NULL If the framebuffer driver supports "update-on-demand"
|
||||
* and the given rectangle is the area of the screen that gets
|
||||
* updated during (*post)().
|
||||
*
|
||||
* This is useful on devices that are able to DMA only a portion of
|
||||
* the screen to the display panel, upon demand -- as opposed to
|
||||
* constantly refreshing the panel 60 times per second, for instance.
|
||||
*
|
||||
* Only the area defined by this rectangle is guaranteed to be valid, that
|
||||
* is, the driver is not allowed to post anything outside of this
|
||||
* rectangle.
|
||||
*
|
||||
* The rectangle evaluated during (*post)() and specifies which area
|
||||
* of the buffer passed in (*post)() shall to be posted.
|
||||
*
|
||||
* return -EINVAL if width or height <=0, or if left or top < 0
|
||||
*/
|
||||
int (*setUpdateRect)(struct framebuffer_device_t* window,
|
||||
int left, int top, int width, int height);
|
||||
|
||||
/*
|
||||
* Post <buffer> to the display (display it on the screen)
|
||||
* The buffer must have been allocated with the
|
||||
* GRALLOC_USAGE_HW_FB usage flag.
|
||||
* buffer must be the same width and height as the display and must NOT
|
||||
* be locked.
|
||||
*
|
||||
* The buffer is shown during the next VSYNC.
|
||||
*
|
||||
* If the same buffer is posted again (possibly after some other buffer),
|
||||
* post() will block until the the first post is completed.
|
||||
*
|
||||
* Internally, post() is expected to lock the buffer so that a
|
||||
* subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
|
||||
* USAGE_*_WRITE will block until it is safe; that is typically once this
|
||||
* buffer is shown and another buffer has been posted.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
|
||||
|
||||
|
||||
/*
|
||||
* The (*compositionComplete)() method must be called after the
|
||||
* compositor has finished issuing GL commands for client buffers.
|
||||
*/
|
||||
|
||||
int (*compositionComplete)(struct framebuffer_device_t* dev);
|
||||
|
||||
/*
|
||||
* This hook is OPTIONAL.
|
||||
*
|
||||
* If non NULL it will be caused by SurfaceFlinger on dumpsys
|
||||
*/
|
||||
void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
|
||||
|
||||
/*
|
||||
* (*enableScreen)() is used to either blank (enable=0) or
|
||||
* unblank (enable=1) the screen this framebuffer is attached to.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
|
||||
int (*setFramecount)(int cmd, int count, int x, int y);
|
||||
void* reserved_proc[6];
|
||||
|
||||
} framebuffer_device_t;
|
||||
|
||||
|
||||
/** convenience API for opening and closing a supported device */
|
||||
|
||||
static inline int framebuffer_open(const struct hw_module_t* module,
|
||||
struct framebuffer_device_t** device) {
|
||||
return module->methods->open(module,
|
||||
GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
|
||||
}
|
||||
|
||||
static inline int framebuffer_close(struct framebuffer_device_t* device) {
|
||||
return device->common.close(&device->common);
|
||||
}
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // ANDROID_FB_INTERFACE_H
|
|
@ -0,0 +1,315 @@
|
|||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ANDROID_GRALLOC_INTERFACE_H
|
||||
#define ANDROID_GRALLOC_INTERFACE_H
|
||||
|
||||
#include <system/window.h>
|
||||
#include <system/graphics.h>
|
||||
#include <hardware/hardware.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
|
||||
#include <hardware/hardware.h>
|
||||
#include <hardware/fb.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* Module versioning information for the Gralloc hardware module, based on
|
||||
* gralloc_module_t.common.module_api_version.
|
||||
*
|
||||
* Version History:
|
||||
*
|
||||
* GRALLOC_MODULE_API_VERSION_0_1:
|
||||
* Initial Gralloc hardware module API.
|
||||
*
|
||||
* GRALLOC_MODULE_API_VERSION_0_2:
|
||||
* Add support for flexible YCbCr format with (*lock_ycbcr)() method.
|
||||
*/
|
||||
|
||||
#define GRALLOC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
|
||||
#define GRALLOC_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
|
||||
|
||||
#define GRALLOC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
|
||||
|
||||
/**
|
||||
* The id of this module
|
||||
*/
|
||||
#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
|
||||
|
||||
/**
|
||||
* Name of the graphics device to open
|
||||
*/
|
||||
|
||||
#define GRALLOC_HARDWARE_GPU0 "gpu0"
|
||||
|
||||
enum {
|
||||
/* buffer is never read in software */
|
||||
GRALLOC_USAGE_SW_READ_NEVER = 0x00000000,
|
||||
/* buffer is rarely read in software */
|
||||
GRALLOC_USAGE_SW_READ_RARELY = 0x00000002,
|
||||
/* buffer is often read in software */
|
||||
GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003,
|
||||
/* mask for the software read values */
|
||||
GRALLOC_USAGE_SW_READ_MASK = 0x0000000F,
|
||||
|
||||
/* buffer is never written in software */
|
||||
GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000,
|
||||
/* buffer is rarely written in software */
|
||||
GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
|
||||
/* buffer is often written in software */
|
||||
GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030,
|
||||
/* mask for the software write values */
|
||||
GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0,
|
||||
|
||||
/* buffer will be used as an OpenGL ES texture */
|
||||
GRALLOC_USAGE_HW_TEXTURE = 0x00000100,
|
||||
/* buffer will be used as an OpenGL ES render target */
|
||||
GRALLOC_USAGE_HW_RENDER = 0x00000200,
|
||||
/* buffer will be used by the 2D hardware blitter */
|
||||
GRALLOC_USAGE_HW_2D = 0x00000400,
|
||||
/* buffer will be used by the HWComposer HAL module */
|
||||
GRALLOC_USAGE_HW_COMPOSER = 0x00000800,
|
||||
/* buffer will be used with the framebuffer device */
|
||||
GRALLOC_USAGE_HW_FB = 0x00001000,
|
||||
/* buffer will be used with the HW video encoder */
|
||||
GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000,
|
||||
/* buffer will be written by the HW camera pipeline */
|
||||
GRALLOC_USAGE_HW_CAMERA_WRITE = 0x00020000,
|
||||
/* buffer will be read by the HW camera pipeline */
|
||||
GRALLOC_USAGE_HW_CAMERA_READ = 0x00040000,
|
||||
/* buffer will be used as part of zero-shutter-lag queue */
|
||||
GRALLOC_USAGE_HW_CAMERA_ZSL = 0x00060000,
|
||||
/* mask for the camera access values */
|
||||
GRALLOC_USAGE_HW_CAMERA_MASK = 0x00060000,
|
||||
/* mask for the software usage bit-mask */
|
||||
GRALLOC_USAGE_HW_MASK = 0x00071F00,
|
||||
|
||||
/* buffer should be displayed full-screen on an external display when
|
||||
* possible
|
||||
*/
|
||||
GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000,
|
||||
|
||||
/* Must have a hardware-protected path to external display sink for
|
||||
* this buffer. If a hardware-protected path is not available, then
|
||||
* either don't composite only this buffer (preferred) to the
|
||||
* external sink, or (less desirable) do not route the entire
|
||||
* composition to the external sink.
|
||||
*/
|
||||
GRALLOC_USAGE_PROTECTED = 0x00004000,
|
||||
|
||||
/* bit 24 ~ bit 27 used by video playback if bit 31 is set */
|
||||
/* mask for the HDMI middleware(MDS) usage bit-mask */
|
||||
GRALLOC_USAGE_MDS_SESSION_ID_MASK = 0x0F000000,
|
||||
|
||||
/* implementation-specific private usage flags */
|
||||
GRALLOC_USAGE_PRIVATE_0 = 0x10000000,
|
||||
GRALLOC_USAGE_PRIVATE_1 = 0x20000000,
|
||||
GRALLOC_USAGE_PRIVATE_2 = 0x40000000,
|
||||
/* used by video playback */
|
||||
GRALLOC_USAGE_PRIVATE_3 = 0x80000000,
|
||||
GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
|
||||
* and the fields of this data structure must begin with hw_module_t
|
||||
* followed by module specific information.
|
||||
*/
|
||||
typedef struct gralloc_module_t {
|
||||
struct hw_module_t common;
|
||||
|
||||
/*
|
||||
* (*registerBuffer)() must be called before a buffer_handle_t that has not
|
||||
* been created with (*alloc_device_t::alloc)() can be used.
|
||||
*
|
||||
* This is intended to be used with buffer_handle_t's that have been
|
||||
* received in this process through IPC.
|
||||
*
|
||||
* This function checks that the handle is indeed a valid one and prepares
|
||||
* it for use with (*lock)() and (*unlock)().
|
||||
*
|
||||
* It is not necessary to call (*registerBuffer)() on a handle created
|
||||
* with (*alloc_device_t::alloc)().
|
||||
*
|
||||
* returns an error if this buffer_handle_t is not valid.
|
||||
*/
|
||||
int (*registerBuffer)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle);
|
||||
|
||||
/*
|
||||
* (*unregisterBuffer)() is called once this handle is no longer needed in
|
||||
* this process. After this call, it is an error to call (*lock)(),
|
||||
* (*unlock)(), or (*registerBuffer)().
|
||||
*
|
||||
* This function doesn't close or free the handle itself; this is done
|
||||
* by other means, usually through libcutils's native_handle_close() and
|
||||
* native_handle_free().
|
||||
*
|
||||
* It is an error to call (*unregisterBuffer)() on a buffer that wasn't
|
||||
* explicitly registered first.
|
||||
*/
|
||||
int (*unregisterBuffer)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle);
|
||||
|
||||
/*
|
||||
* The (*lock)() method is called before a buffer is accessed for the
|
||||
* specified usage. This call may block, for instance if the h/w needs
|
||||
* to finish rendering or if CPU caches need to be synchronized.
|
||||
*
|
||||
* The caller promises to modify only pixels in the area specified
|
||||
* by (l,t,w,h).
|
||||
*
|
||||
* The content of the buffer outside of the specified area is NOT modified
|
||||
* by this call.
|
||||
*
|
||||
* If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
|
||||
* of the buffer in virtual memory.
|
||||
*
|
||||
* Note calling (*lock)() on HAL_PIXEL_FORMAT_YCbCr_*_888 buffers will fail
|
||||
* and return -EINVAL. These buffers must be locked with (*lock_ycbcr)()
|
||||
* instead.
|
||||
*
|
||||
* THREADING CONSIDERATIONS:
|
||||
*
|
||||
* It is legal for several different threads to lock a buffer from
|
||||
* read access, none of the threads are blocked.
|
||||
*
|
||||
* However, locking a buffer simultaneously for write or read/write is
|
||||
* undefined, but:
|
||||
* - shall not result in termination of the process
|
||||
* - shall not block the caller
|
||||
* It is acceptable to return an error or to leave the buffer's content
|
||||
* into an indeterminate state.
|
||||
*
|
||||
* If the buffer was created with a usage mask incompatible with the
|
||||
* requested usage flags here, -EINVAL is returned.
|
||||
*
|
||||
*/
|
||||
|
||||
int (*lock)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int usage,
|
||||
int l, int t, int w, int h,
|
||||
void** vaddr);
|
||||
|
||||
|
||||
/*
|
||||
* The (*unlock)() method must be called after all changes to the buffer
|
||||
* are completed.
|
||||
*/
|
||||
|
||||
int (*unlock)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle);
|
||||
|
||||
|
||||
/* reserved for future use */
|
||||
int (*perform)(struct gralloc_module_t const* module,
|
||||
int operation, ... );
|
||||
|
||||
/*
|
||||
* The (*lock_ycbcr)() method is like the (*lock)() method, with the
|
||||
* difference that it fills a struct ycbcr with a description of the buffer
|
||||
* layout, and zeroes out the reserved fields.
|
||||
*
|
||||
* This will only work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888, and
|
||||
* will return -EINVAL on any other buffer formats.
|
||||
*
|
||||
* Added in GRALLOC_MODULE_API_VERSION_0_2.
|
||||
*/
|
||||
|
||||
int (*lock_ycbcr)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int usage,
|
||||
int l, int t, int w, int h,
|
||||
struct android_ycbcr *ycbcr);
|
||||
|
||||
/* reserved for future use */
|
||||
void* reserved_proc[6];
|
||||
} gralloc_module_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Every device data structure must begin with hw_device_t
|
||||
* followed by module specific public methods and attributes.
|
||||
*/
|
||||
|
||||
typedef struct alloc_device_t {
|
||||
struct hw_device_t common;
|
||||
|
||||
/*
|
||||
* (*alloc)() Allocates a buffer in graphic memory with the requested
|
||||
* parameters and returns a buffer_handle_t and the stride in pixels to
|
||||
* allow the implementation to satisfy hardware constraints on the width
|
||||
* of a pixmap (eg: it may have to be multiple of 8 pixels).
|
||||
* The CALLER TAKES OWNERSHIP of the buffer_handle_t.
|
||||
*
|
||||
* If format is HAL_PIXEL_FORMAT_YCbCr_420_888, the returned stride must be
|
||||
* 0, since the actual strides are available from the android_ycbcr
|
||||
* structure.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
|
||||
int (*alloc)(struct alloc_device_t* dev,
|
||||
int w, int h, int format, int usage,
|
||||
buffer_handle_t* handle, int* stride);
|
||||
|
||||
/*
|
||||
* (*free)() Frees a previously allocated buffer.
|
||||
* Behavior is undefined if the buffer is still mapped in any process,
|
||||
* but shall not result in termination of the program or security breaches
|
||||
* (allowing a process to get access to another process' buffers).
|
||||
* THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
|
||||
* invalid after the call.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*free)(struct alloc_device_t* dev,
|
||||
buffer_handle_t handle);
|
||||
|
||||
/* This hook is OPTIONAL.
|
||||
*
|
||||
* If non NULL it will be caused by SurfaceFlinger on dumpsys
|
||||
*/
|
||||
void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
|
||||
|
||||
void* reserved_proc[7];
|
||||
} alloc_device_t;
|
||||
|
||||
|
||||
/** convenience API for opening and closing a supported device */
|
||||
|
||||
static inline int gralloc_open(const struct hw_module_t* module,
|
||||
struct alloc_device_t** device) {
|
||||
return module->methods->open(module,
|
||||
GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
|
||||
}
|
||||
|
||||
static inline int gralloc_close(struct alloc_device_t* device) {
|
||||
return device->common.close(&device->common);
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // ANDROID_GRALLOC_INTERFACE_H
|
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
|
||||
#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
#include <system/graphics.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Value for the hw_module_t.tag field
|
||||
*/
|
||||
|
||||
#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
|
||||
|
||||
#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
|
||||
#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
|
||||
|
||||
#define HARDWARE_MAKE_API_VERSION(maj,min) \
|
||||
((((maj) & 0xff) << 8) | ((min) & 0xff))
|
||||
|
||||
#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
|
||||
((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
|
||||
#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
|
||||
#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
|
||||
|
||||
|
||||
/*
|
||||
* The current HAL API version.
|
||||
*
|
||||
* All module implementations must set the hw_module_t.hal_api_version field
|
||||
* to this value when declaring the module with HAL_MODULE_INFO_SYM.
|
||||
*
|
||||
* Note that previous implementations have always set this field to 0.
|
||||
* Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
|
||||
* to be 100% binary compatible.
|
||||
*
|
||||
*/
|
||||
#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
|
||||
|
||||
/*
|
||||
* Helper macros for module implementors.
|
||||
*
|
||||
* The derived modules should provide convenience macros for supported
|
||||
* versions so that implementations can explicitly specify module/device
|
||||
* versions at definition time.
|
||||
*
|
||||
* Use this macro to set the hw_module_t.module_api_version field.
|
||||
*/
|
||||
#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
|
||||
#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
|
||||
|
||||
/*
|
||||
* Use this macro to set the hw_device_t.version field
|
||||
*/
|
||||
#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
|
||||
#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
|
||||
|
||||
struct hw_module_t;
|
||||
struct hw_module_methods_t;
|
||||
struct hw_device_t;
|
||||
|
||||
/**
|
||||
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
|
||||
* and the fields of this data structure must begin with hw_module_t
|
||||
* followed by module specific information.
|
||||
*/
|
||||
typedef struct hw_module_t {
|
||||
/** tag must be initialized to HARDWARE_MODULE_TAG */
|
||||
uint32_t tag;
|
||||
|
||||
/**
|
||||
* The API version of the implemented module. The module owner is
|
||||
* responsible for updating the version when a module interface has
|
||||
* changed.
|
||||
*
|
||||
* The derived modules such as gralloc and audio own and manage this field.
|
||||
* The module user must interpret the version field to decide whether or
|
||||
* not to inter-operate with the supplied module implementation.
|
||||
* For example, SurfaceFlinger is responsible for making sure that
|
||||
* it knows how to manage different versions of the gralloc-module API,
|
||||
* and AudioFlinger must know how to do the same for audio-module API.
|
||||
*
|
||||
* The module API version should include a major and a minor component.
|
||||
* For example, version 1.0 could be represented as 0x0100. This format
|
||||
* implies that versions 0x0100-0x01ff are all API-compatible.
|
||||
*
|
||||
* In the future, libhardware will expose a hw_get_module_version()
|
||||
* (or equivalent) function that will take minimum/maximum supported
|
||||
* versions as arguments and would be able to reject modules with
|
||||
* versions outside of the supplied range.
|
||||
*/
|
||||
uint16_t module_api_version;
|
||||
#define version_major module_api_version
|
||||
/**
|
||||
* version_major/version_minor defines are supplied here for temporary
|
||||
* source code compatibility. They will be removed in the next version.
|
||||
* ALL clients must convert to the new version format.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The API version of the HAL module interface. This is meant to
|
||||
* version the hw_module_t, hw_module_methods_t, and hw_device_t
|
||||
* structures and definitions.
|
||||
*
|
||||
* The HAL interface owns this field. Module users/implementations
|
||||
* must NOT rely on this value for version information.
|
||||
*
|
||||
* Presently, 0 is the only valid value.
|
||||
*/
|
||||
uint16_t hal_api_version;
|
||||
#define version_minor hal_api_version
|
||||
|
||||
/** Identifier of module */
|
||||
const char *id;
|
||||
|
||||
/** Name of this module */
|
||||
const char *name;
|
||||
|
||||
/** Author/owner/implementor of the module */
|
||||
const char *author;
|
||||
|
||||
/** Modules methods */
|
||||
struct hw_module_methods_t* methods;
|
||||
|
||||
/** module's dso */
|
||||
void* dso;
|
||||
|
||||
/** padding to 128 bytes, reserved for future use */
|
||||
uint32_t reserved[32-7];
|
||||
|
||||
} hw_module_t;
|
||||
|
||||
typedef struct hw_module_methods_t {
|
||||
/** Open a specific device */
|
||||
int (*open)(const struct hw_module_t* module, const char* id,
|
||||
struct hw_device_t** device);
|
||||
|
||||
} hw_module_methods_t;
|
||||
|
||||
/**
|
||||
* Every device data structure must begin with hw_device_t
|
||||
* followed by module specific public methods and attributes.
|
||||
*/
|
||||
typedef struct hw_device_t {
|
||||
/** tag must be initialized to HARDWARE_DEVICE_TAG */
|
||||
uint32_t tag;
|
||||
|
||||
/**
|
||||
* Version of the module-specific device API. This value is used by
|
||||
* the derived-module user to manage different device implementations.
|
||||
*
|
||||
* The module user is responsible for checking the module_api_version
|
||||
* and device version fields to ensure that the user is capable of
|
||||
* communicating with the specific module implementation.
|
||||
*
|
||||
* One module can support multiple devices with different versions. This
|
||||
* can be useful when a device interface changes in an incompatible way
|
||||
* but it is still necessary to support older implementations at the same
|
||||
* time. One such example is the Camera 2.0 API.
|
||||
*
|
||||
* This field is interpreted by the module user and is ignored by the
|
||||
* HAL interface itself.
|
||||
*/
|
||||
uint32_t version;
|
||||
|
||||
/** reference to the module this device belongs to */
|
||||
struct hw_module_t* module;
|
||||
|
||||
/** padding reserved for future use */
|
||||
uint32_t reserved[12];
|
||||
|
||||
/** Close this device */
|
||||
int (*close)(struct hw_device_t* device);
|
||||
|
||||
} hw_device_t;
|
||||
|
||||
/**
|
||||
* Name of the hal_module_info
|
||||
*/
|
||||
#define HAL_MODULE_INFO_SYM HMI
|
||||
|
||||
/**
|
||||
* Name of the hal_module_info as a string
|
||||
*/
|
||||
#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
|
||||
|
||||
/**
|
||||
* Get the module info associated with a module by id.
|
||||
*
|
||||
* @return: 0 == success, <0 == error and *module == NULL
|
||||
*/
|
||||
int hw_get_module(const char *id, const struct hw_module_t **module);
|
||||
|
||||
/**
|
||||
* Get the module info associated with a module instance by class 'class_id'
|
||||
* and instance 'inst'.
|
||||
*
|
||||
* Some modules types necessitate multiple instances. For example audio supports
|
||||
* multiple concurrent interfaces and thus 'audio' is the module class
|
||||
* and 'primary' or 'a2dp' are module interfaces. This implies that the files
|
||||
* providing these modules would be named audio.primary.<variant>.so and
|
||||
* audio.a2dp.<variant>.so
|
||||
*
|
||||
* @return: 0 == success, <0 == error and *module == NULL
|
||||
*/
|
||||
int hw_get_module_by_class(const char *class_id, const char *inst,
|
||||
const struct hw_module_t **module);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <binder/IInterface.h>
|
||||
#include <media/stagefright/foundation/ABase.h>
|
||||
#include <media/hardware/CryptoAPI.h>
|
||||
|
||||
#ifndef ANDROID_ICRYPTO_H_
|
||||
|
||||
#define ANDROID_ICRYPTO_H_
|
||||
|
||||
namespace android {
|
||||
|
||||
struct AString;
|
||||
|
||||
struct ICrypto : public IInterface {
|
||||
DECLARE_META_INTERFACE(Crypto);
|
||||
|
||||
virtual status_t initCheck() const = 0;
|
||||
|
||||
virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) = 0;
|
||||
|
||||
virtual status_t createPlugin(
|
||||
const uint8_t uuid[16], const void *data, size_t size) = 0;
|
||||
|
||||
virtual status_t destroyPlugin() = 0;
|
||||
|
||||
virtual bool requiresSecureDecoderComponent(
|
||||
const char *mime) const = 0;
|
||||
|
||||
virtual ssize_t decrypt(
|
||||
bool secure,
|
||||
const uint8_t key[16],
|
||||
const uint8_t iv[16],
|
||||
CryptoPlugin::Mode mode,
|
||||
const void *srcPtr,
|
||||
const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
|
||||
void *dstPtr,
|
||||
AString *errorDetailMsg) = 0;
|
||||
|
||||
private:
|
||||
DISALLOW_EVIL_CONSTRUCTORS(ICrypto);
|
||||
};
|
||||
|
||||
struct BnCrypto : public BnInterface<ICrypto> {
|
||||
virtual status_t onTransact(
|
||||
uint32_t code, const Parcel &data, Parcel *reply,
|
||||
uint32_t flags = 0);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_ICRYPTO_H_
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_IOMX_H_
|
||||
|
||||
#define ANDROID_IOMX_H_
|
||||
|
||||
#include <binder/IInterface.h>
|
||||
#include <gui/IGraphicBufferProducer.h>
|
||||
#include <ui/GraphicBuffer.h>
|
||||
#include <utils/List.h>
|
||||
#include <utils/String8.h>
|
||||
|
||||
#include <OMX_Core.h>
|
||||
#include <OMX_Video.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class IMemory;
|
||||
class IOMXObserver;
|
||||
class IOMXRenderer;
|
||||
class Surface;
|
||||
|
||||
class IOMX : public IInterface {
|
||||
public:
|
||||
DECLARE_META_INTERFACE(OMX);
|
||||
|
||||
typedef void *buffer_id;
|
||||
typedef void *node_id;
|
||||
|
||||
// Given a node_id and the calling process' pid, returns true iff
|
||||
// the implementation of the OMX interface lives in the same
|
||||
// process.
|
||||
virtual bool livesLocally(node_id node, pid_t pid) = 0;
|
||||
|
||||
struct ComponentInfo {
|
||||
String8 mName;
|
||||
List<String8> mRoles;
|
||||
};
|
||||
virtual status_t listNodes(List<ComponentInfo> *list) = 0;
|
||||
|
||||
virtual status_t allocateNode(
|
||||
const char *name, const sp<IOMXObserver> &observer,
|
||||
node_id *node) = 0;
|
||||
|
||||
virtual status_t freeNode(node_id node) = 0;
|
||||
|
||||
virtual status_t sendCommand(
|
||||
node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
|
||||
|
||||
virtual status_t getParameter(
|
||||
node_id node, OMX_INDEXTYPE index,
|
||||
void *params, size_t size) = 0;
|
||||
|
||||
virtual status_t setParameter(
|
||||
node_id node, OMX_INDEXTYPE index,
|
||||
const void *params, size_t size) = 0;
|
||||
|
||||
virtual status_t getConfig(
|
||||
node_id node, OMX_INDEXTYPE index,
|
||||
void *params, size_t size) = 0;
|
||||
|
||||
virtual status_t setConfig(
|
||||
node_id node, OMX_INDEXTYPE index,
|
||||
const void *params, size_t size) = 0;
|
||||
|
||||
virtual status_t getState(
|
||||
node_id node, OMX_STATETYPE* state) = 0;
|
||||
|
||||
virtual status_t storeMetaDataInBuffers(
|
||||
node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
|
||||
|
||||
virtual status_t enableGraphicBuffers(
|
||||
node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
|
||||
|
||||
virtual status_t getGraphicBufferUsage(
|
||||
node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
|
||||
|
||||
virtual status_t useBuffer(
|
||||
node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms,
|
||||
buffer_id *buffer) = 0;
|
||||
|
||||
virtual status_t useGraphicBuffer(
|
||||
node_id node, OMX_U32 port_index,
|
||||
const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
|
||||
|
||||
virtual status_t createInputSurface(
|
||||
node_id node, OMX_U32 port_index,
|
||||
sp<IGraphicBufferProducer> *bufferProducer) = 0;
|
||||
|
||||
virtual status_t signalEndOfInputStream(node_id node) = 0;
|
||||
|
||||
// This API clearly only makes sense if the caller lives in the
|
||||
// same process as the callee, i.e. is the media_server, as the
|
||||
// returned "buffer_data" pointer is just that, a pointer into local
|
||||
// address space.
|
||||
virtual status_t allocateBuffer(
|
||||
node_id node, OMX_U32 port_index, size_t size,
|
||||
buffer_id *buffer, void **buffer_data) = 0;
|
||||
|
||||
virtual status_t allocateBufferWithBackup(
|
||||
node_id node, OMX_U32 port_index, const sp<IMemory> ¶ms,
|
||||
buffer_id *buffer) = 0;
|
||||
|
||||
virtual status_t freeBuffer(
|
||||
node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
|
||||
|
||||
virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
|
||||
|
||||
virtual status_t emptyBuffer(
|
||||
node_id node,
|
||||
buffer_id buffer,
|
||||
OMX_U32 range_offset, OMX_U32 range_length,
|
||||
OMX_U32 flags, OMX_TICKS timestamp) = 0;
|
||||
|
||||
virtual status_t getExtensionIndex(
|
||||
node_id node,
|
||||
const char *parameter_name,
|
||||
OMX_INDEXTYPE *index) = 0;
|
||||
};
|
||||
|
||||
struct omx_message {
|
||||
enum {
|
||||
EVENT,
|
||||
EMPTY_BUFFER_DONE,
|
||||
FILL_BUFFER_DONE,
|
||||
|
||||
} type;
|
||||
|
||||
IOMX::node_id node;
|
||||
|
||||
union {
|
||||
// if type == EVENT
|
||||
struct {
|
||||
OMX_EVENTTYPE event;
|
||||
OMX_U32 data1;
|
||||
OMX_U32 data2;
|
||||
} event_data;
|
||||
|
||||
// if type == EMPTY_BUFFER_DONE
|
||||
struct {
|
||||
IOMX::buffer_id buffer;
|
||||
} buffer_data;
|
||||
|
||||
// if type == FILL_BUFFER_DONE
|
||||
struct {
|
||||
IOMX::buffer_id buffer;
|
||||
OMX_U32 range_offset;
|
||||
OMX_U32 range_length;
|
||||
OMX_U32 flags;
|
||||
OMX_TICKS timestamp;
|
||||
OMX_PTR platform_private;
|
||||
OMX_PTR data_ptr;
|
||||
} extended_buffer_data;
|
||||
|
||||
} u;
|
||||
};
|
||||
|
||||
class IOMXObserver : public IInterface {
|
||||
public:
|
||||
DECLARE_META_INTERFACE(OMXObserver);
|
||||
|
||||
virtual void onMessage(const omx_message &msg) = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class BnOMX : public BnInterface<IOMX> {
|
||||
public:
|
||||
virtual status_t onTransact(
|
||||
uint32_t code, const Parcel &data, Parcel *reply,
|
||||
uint32_t flags = 0);
|
||||
};
|
||||
|
||||
class BnOMXObserver : public BnInterface<IOMXObserver> {
|
||||
public:
|
||||
virtual status_t onTransact(
|
||||
uint32_t code, const Parcel &data, Parcel *reply,
|
||||
uint32_t flags = 0);
|
||||
};
|
||||
|
||||
struct CodecProfileLevel {
|
||||
OMX_U32 mProfile;
|
||||
OMX_U32 mLevel;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_IOMX_H_
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,951 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/**
|
||||
* Copyright (c) 2008 The Khronos Group Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file OMX_IVCommon.h - OpenMax IL version 1.1.2
|
||||
* The structures needed by Video and Image components to exchange
|
||||
* parameters and configuration data with the components.
|
||||
*/
|
||||
#ifndef OMX_IVCommon_h
|
||||
#define OMX_IVCommon_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* Each OMX header must include all required header files to allow the header
|
||||
* to compile without errors. The includes below are required for this header
|
||||
* file to compile successfully
|
||||
*/
|
||||
|
||||
#include <OMX_Core.h>
|
||||
|
||||
/** @defgroup iv OpenMAX IL Imaging and Video Domain
|
||||
* Common structures for OpenMAX IL Imaging and Video domains
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Enumeration defining possible uncompressed image/video formats.
|
||||
*
|
||||
* ENUMS:
|
||||
* Unused : Placeholder value when format is N/A
|
||||
* Monochrome : black and white
|
||||
* 8bitRGB332 : Red 7:5, Green 4:2, Blue 1:0
|
||||
* 12bitRGB444 : Red 11:8, Green 7:4, Blue 3:0
|
||||
* 16bitARGB4444 : Alpha 15:12, Red 11:8, Green 7:4, Blue 3:0
|
||||
* 16bitARGB1555 : Alpha 15, Red 14:10, Green 9:5, Blue 4:0
|
||||
* 16bitRGB565 : Red 15:11, Green 10:5, Blue 4:0
|
||||
* 16bitBGR565 : Blue 15:11, Green 10:5, Red 4:0
|
||||
* 18bitRGB666 : Red 17:12, Green 11:6, Blue 5:0
|
||||
* 18bitARGB1665 : Alpha 17, Red 16:11, Green 10:5, Blue 4:0
|
||||
* 19bitARGB1666 : Alpha 18, Red 17:12, Green 11:6, Blue 5:0
|
||||
* 24bitRGB888 : Red 24:16, Green 15:8, Blue 7:0
|
||||
* 24bitBGR888 : Blue 24:16, Green 15:8, Red 7:0
|
||||
* 24bitARGB1887 : Alpha 23, Red 22:15, Green 14:7, Blue 6:0
|
||||
* 25bitARGB1888 : Alpha 24, Red 23:16, Green 15:8, Blue 7:0
|
||||
* 32bitBGRA8888 : Blue 31:24, Green 23:16, Red 15:8, Alpha 7:0
|
||||
* 32bitARGB8888 : Alpha 31:24, Red 23:16, Green 15:8, Blue 7:0
|
||||
* YUV411Planar : U,Y are subsampled by a factor of 4 horizontally
|
||||
* YUV411PackedPlanar : packed per payload in planar slices
|
||||
* YUV420Planar : Three arrays Y,U,V.
|
||||
* YUV420PackedPlanar : packed per payload in planar slices
|
||||
* YUV420SemiPlanar : Two arrays, one is all Y, the other is U and V
|
||||
* YUV422Planar : Three arrays Y,U,V.
|
||||
* YUV422PackedPlanar : packed per payload in planar slices
|
||||
* YUV422SemiPlanar : Two arrays, one is all Y, the other is U and V
|
||||
* YCbYCr : Organized as 16bit YUYV (i.e. YCbYCr)
|
||||
* YCrYCb : Organized as 16bit YVYU (i.e. YCrYCb)
|
||||
* CbYCrY : Organized as 16bit UYVY (i.e. CbYCrY)
|
||||
* CrYCbY : Organized as 16bit VYUY (i.e. CrYCbY)
|
||||
* YUV444Interleaved : Each pixel contains equal parts YUV
|
||||
* RawBayer8bit : SMIA camera output format
|
||||
* RawBayer10bit : SMIA camera output format
|
||||
* RawBayer8bitcompressed : SMIA camera output format
|
||||
*/
|
||||
typedef enum OMX_COLOR_FORMATTYPE {
|
||||
OMX_COLOR_FormatUnused,
|
||||
OMX_COLOR_FormatMonochrome,
|
||||
OMX_COLOR_Format8bitRGB332,
|
||||
OMX_COLOR_Format12bitRGB444,
|
||||
OMX_COLOR_Format16bitARGB4444,
|
||||
OMX_COLOR_Format16bitARGB1555,
|
||||
OMX_COLOR_Format16bitRGB565,
|
||||
OMX_COLOR_Format16bitBGR565,
|
||||
OMX_COLOR_Format18bitRGB666,
|
||||
OMX_COLOR_Format18bitARGB1665,
|
||||
OMX_COLOR_Format19bitARGB1666,
|
||||
OMX_COLOR_Format24bitRGB888,
|
||||
OMX_COLOR_Format24bitBGR888,
|
||||
OMX_COLOR_Format24bitARGB1887,
|
||||
OMX_COLOR_Format25bitARGB1888,
|
||||
OMX_COLOR_Format32bitBGRA8888,
|
||||
OMX_COLOR_Format32bitARGB8888,
|
||||
OMX_COLOR_FormatYUV411Planar,
|
||||
OMX_COLOR_FormatYUV411PackedPlanar,
|
||||
OMX_COLOR_FormatYUV420Planar,
|
||||
OMX_COLOR_FormatYUV420PackedPlanar,
|
||||
OMX_COLOR_FormatYUV420SemiPlanar,
|
||||
OMX_COLOR_FormatYUV422Planar,
|
||||
OMX_COLOR_FormatYUV422PackedPlanar,
|
||||
OMX_COLOR_FormatYUV422SemiPlanar,
|
||||
OMX_COLOR_FormatYCbYCr,
|
||||
OMX_COLOR_FormatYCrYCb,
|
||||
OMX_COLOR_FormatCbYCrY,
|
||||
OMX_COLOR_FormatCrYCbY,
|
||||
OMX_COLOR_FormatYUV444Interleaved,
|
||||
OMX_COLOR_FormatRawBayer8bit,
|
||||
OMX_COLOR_FormatRawBayer10bit,
|
||||
OMX_COLOR_FormatRawBayer8bitcompressed,
|
||||
OMX_COLOR_FormatL2,
|
||||
OMX_COLOR_FormatL4,
|
||||
OMX_COLOR_FormatL8,
|
||||
OMX_COLOR_FormatL16,
|
||||
OMX_COLOR_FormatL24,
|
||||
OMX_COLOR_FormatL32,
|
||||
OMX_COLOR_FormatYUV420PackedSemiPlanar,
|
||||
OMX_COLOR_FormatYUV422PackedSemiPlanar,
|
||||
OMX_COLOR_Format18BitBGR666,
|
||||
OMX_COLOR_Format24BitARGB6666,
|
||||
OMX_COLOR_Format24BitABGR6666,
|
||||
OMX_COLOR_FormatKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_COLOR_FormatVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
/**<Reserved android opaque colorformat. Tells the encoder that
|
||||
* the actual colorformat will be relayed by the
|
||||
* Gralloc Buffers.
|
||||
* FIXME: In the process of reserving some enum values for
|
||||
* Android-specific OMX IL colorformats. Change this enum to
|
||||
* an acceptable range once that is done.
|
||||
* */
|
||||
OMX_COLOR_FormatAndroidOpaque = 0x7F000789,
|
||||
OMX_TI_COLOR_FormatYUV420PackedSemiPlanar = 0x7F000100,
|
||||
OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar = 0x7FA00E00,
|
||||
OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled = 0x7FA00F00,
|
||||
OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00,
|
||||
OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka = 0x7FA30C03,
|
||||
OMX_SEC_COLOR_FormatNV12Tiled = 0x7FC00002,
|
||||
OMX_COLOR_FormatMax = 0x7FFFFFFF
|
||||
} OMX_COLOR_FORMATTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the matrix for conversion from RGB to YUV or vice versa.
|
||||
* iColorMatrix should be initialized with the fixed point values
|
||||
* used in converting between formats.
|
||||
*/
|
||||
typedef struct OMX_CONFIG_COLORCONVERSIONTYPE {
|
||||
OMX_U32 nSize; /**< Size of the structure in bytes */
|
||||
OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
|
||||
OMX_U32 nPortIndex; /**< Port that this struct applies to */
|
||||
OMX_S32 xColorMatrix[3][3]; /**< Stored in signed Q16 format */
|
||||
OMX_S32 xColorOffset[4]; /**< Stored in signed Q16 format */
|
||||
}OMX_CONFIG_COLORCONVERSIONTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Structure defining percent to scale each frame dimension. For example:
|
||||
* To make the width 50% larger, use fWidth = 1.5 and to make the width
|
||||
* 1/2 the original size, use fWidth = 0.5
|
||||
*/
|
||||
typedef struct OMX_CONFIG_SCALEFACTORTYPE {
|
||||
OMX_U32 nSize; /**< Size of the structure in bytes */
|
||||
OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
|
||||
OMX_U32 nPortIndex; /**< Port that this struct applies to */
|
||||
OMX_S32 xWidth; /**< Fixed point value stored as Q16 */
|
||||
OMX_S32 xHeight; /**< Fixed point value stored as Q16 */
|
||||
}OMX_CONFIG_SCALEFACTORTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Enumeration of possible image filter types
|
||||
*/
|
||||
typedef enum OMX_IMAGEFILTERTYPE {
|
||||
OMX_ImageFilterNone,
|
||||
OMX_ImageFilterNoise,
|
||||
OMX_ImageFilterEmboss,
|
||||
OMX_ImageFilterNegative,
|
||||
OMX_ImageFilterSketch,
|
||||
OMX_ImageFilterOilPaint,
|
||||
OMX_ImageFilterHatch,
|
||||
OMX_ImageFilterGpen,
|
||||
OMX_ImageFilterAntialias,
|
||||
OMX_ImageFilterDeRing,
|
||||
OMX_ImageFilterSolarize,
|
||||
OMX_ImageFilterKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_ImageFilterVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_ImageFilterMax = 0x7FFFFFFF
|
||||
} OMX_IMAGEFILTERTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Image filter configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* eImageFilter : Image filter type enumeration
|
||||
*/
|
||||
typedef struct OMX_CONFIG_IMAGEFILTERTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_IMAGEFILTERTYPE eImageFilter;
|
||||
} OMX_CONFIG_IMAGEFILTERTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Customized U and V for color enhancement
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* bColorEnhancement : Enable/disable color enhancement
|
||||
* nCustomizedU : Practical values: 16-240, range: 0-255, value set for
|
||||
* U component
|
||||
* nCustomizedV : Practical values: 16-240, range: 0-255, value set for
|
||||
* V component
|
||||
*/
|
||||
typedef struct OMX_CONFIG_COLORENHANCEMENTTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bColorEnhancement;
|
||||
OMX_U8 nCustomizedU;
|
||||
OMX_U8 nCustomizedV;
|
||||
} OMX_CONFIG_COLORENHANCEMENTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Define color key and color key mask
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nARGBColor : 32bit Alpha, Red, Green, Blue Color
|
||||
* nARGBMask : 32bit Mask for Alpha, Red, Green, Blue channels
|
||||
*/
|
||||
typedef struct OMX_CONFIG_COLORKEYTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nARGBColor;
|
||||
OMX_U32 nARGBMask;
|
||||
} OMX_CONFIG_COLORKEYTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* List of color blend types for pre/post processing
|
||||
*
|
||||
* ENUMS:
|
||||
* None : No color blending present
|
||||
* AlphaConstant : Function is (alpha_constant * src) +
|
||||
* (1 - alpha_constant) * dst)
|
||||
* AlphaPerPixel : Function is (alpha * src) + (1 - alpha) * dst)
|
||||
* Alternate : Function is alternating pixels from src and dst
|
||||
* And : Function is (src & dst)
|
||||
* Or : Function is (src | dst)
|
||||
* Invert : Function is ~src
|
||||
*/
|
||||
typedef enum OMX_COLORBLENDTYPE {
|
||||
OMX_ColorBlendNone,
|
||||
OMX_ColorBlendAlphaConstant,
|
||||
OMX_ColorBlendAlphaPerPixel,
|
||||
OMX_ColorBlendAlternate,
|
||||
OMX_ColorBlendAnd,
|
||||
OMX_ColorBlendOr,
|
||||
OMX_ColorBlendInvert,
|
||||
OMX_ColorBlendKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_ColorBlendVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_ColorBlendMax = 0x7FFFFFFF
|
||||
} OMX_COLORBLENDTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Color blend configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nRGBAlphaConstant : Constant global alpha values when global alpha is used
|
||||
* eColorBlend : Color blend type enumeration
|
||||
*/
|
||||
typedef struct OMX_CONFIG_COLORBLENDTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nRGBAlphaConstant;
|
||||
OMX_COLORBLENDTYPE eColorBlend;
|
||||
} OMX_CONFIG_COLORBLENDTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Hold frame dimension
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nWidth : Frame width in pixels
|
||||
* nHeight : Frame height in pixels
|
||||
*/
|
||||
typedef struct OMX_FRAMESIZETYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nWidth;
|
||||
OMX_U32 nHeight;
|
||||
} OMX_FRAMESIZETYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Rotation configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nRotation : +/- integer rotation value
|
||||
*/
|
||||
typedef struct OMX_CONFIG_ROTATIONTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nRotation;
|
||||
} OMX_CONFIG_ROTATIONTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Possible mirroring directions for pre/post processing
|
||||
*
|
||||
* ENUMS:
|
||||
* None : No mirroring
|
||||
* Vertical : Vertical mirroring, flip on X axis
|
||||
* Horizontal : Horizontal mirroring, flip on Y axis
|
||||
* Both : Both vertical and horizontal mirroring
|
||||
*/
|
||||
typedef enum OMX_MIRRORTYPE {
|
||||
OMX_MirrorNone = 0,
|
||||
OMX_MirrorVertical,
|
||||
OMX_MirrorHorizontal,
|
||||
OMX_MirrorBoth,
|
||||
OMX_MirrorKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_MirrorVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_MirrorMax = 0x7FFFFFFF
|
||||
} OMX_MIRRORTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Mirroring configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* eMirror : Mirror type enumeration
|
||||
*/
|
||||
typedef struct OMX_CONFIG_MIRRORTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_MIRRORTYPE eMirror;
|
||||
} OMX_CONFIG_MIRRORTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Position information only
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nX : X coordinate for the point
|
||||
* nY : Y coordinate for the point
|
||||
*/
|
||||
typedef struct OMX_CONFIG_POINTTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nX;
|
||||
OMX_S32 nY;
|
||||
} OMX_CONFIG_POINTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Frame size plus position
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nLeft : X Coordinate of the top left corner of the rectangle
|
||||
* nTop : Y Coordinate of the top left corner of the rectangle
|
||||
* nWidth : Width of the rectangle
|
||||
* nHeight : Height of the rectangle
|
||||
*/
|
||||
typedef struct OMX_CONFIG_RECTTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nLeft;
|
||||
OMX_S32 nTop;
|
||||
OMX_U32 nWidth;
|
||||
OMX_U32 nHeight;
|
||||
} OMX_CONFIG_RECTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Deblocking state; it is required to be set up before starting the codec
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* bDeblocking : Enable/disable deblocking mode
|
||||
*/
|
||||
typedef struct OMX_PARAM_DEBLOCKINGTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bDeblocking;
|
||||
} OMX_PARAM_DEBLOCKINGTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Stabilization state
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* bStab : Enable/disable frame stabilization state
|
||||
*/
|
||||
typedef struct OMX_CONFIG_FRAMESTABTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bStab;
|
||||
} OMX_CONFIG_FRAMESTABTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* White Balance control type
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* SunLight : Referenced in JSR-234
|
||||
* Flash : Optimal for device's integrated flash
|
||||
*/
|
||||
typedef enum OMX_WHITEBALCONTROLTYPE {
|
||||
OMX_WhiteBalControlOff = 0,
|
||||
OMX_WhiteBalControlAuto,
|
||||
OMX_WhiteBalControlSunLight,
|
||||
OMX_WhiteBalControlCloudy,
|
||||
OMX_WhiteBalControlShade,
|
||||
OMX_WhiteBalControlTungsten,
|
||||
OMX_WhiteBalControlFluorescent,
|
||||
OMX_WhiteBalControlIncandescent,
|
||||
OMX_WhiteBalControlFlash,
|
||||
OMX_WhiteBalControlHorizon,
|
||||
OMX_WhiteBalControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_WhiteBalControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_WhiteBalControlMax = 0x7FFFFFFF
|
||||
} OMX_WHITEBALCONTROLTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* White Balance control configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* eWhiteBalControl : White balance enumeration
|
||||
*/
|
||||
typedef struct OMX_CONFIG_WHITEBALCONTROLTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_WHITEBALCONTROLTYPE eWhiteBalControl;
|
||||
} OMX_CONFIG_WHITEBALCONTROLTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Exposure control type
|
||||
*/
|
||||
typedef enum OMX_EXPOSURECONTROLTYPE {
|
||||
OMX_ExposureControlOff = 0,
|
||||
OMX_ExposureControlAuto,
|
||||
OMX_ExposureControlNight,
|
||||
OMX_ExposureControlBackLight,
|
||||
OMX_ExposureControlSpotLight,
|
||||
OMX_ExposureControlSports,
|
||||
OMX_ExposureControlSnow,
|
||||
OMX_ExposureControlBeach,
|
||||
OMX_ExposureControlLargeAperture,
|
||||
OMX_ExposureControlSmallApperture,
|
||||
OMX_ExposureControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_ExposureControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_ExposureControlMax = 0x7FFFFFFF
|
||||
} OMX_EXPOSURECONTROLTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* White Balance control configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* eExposureControl : Exposure control enumeration
|
||||
*/
|
||||
typedef struct OMX_CONFIG_EXPOSURECONTROLTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_EXPOSURECONTROLTYPE eExposureControl;
|
||||
} OMX_CONFIG_EXPOSURECONTROLTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines sensor supported mode.
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nFrameRate : Single shot mode is indicated by a 0
|
||||
* bOneShot : Enable for single shot, disable for streaming
|
||||
* sFrameSize : Framesize
|
||||
*/
|
||||
typedef struct OMX_PARAM_SENSORMODETYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nFrameRate;
|
||||
OMX_BOOL bOneShot;
|
||||
OMX_FRAMESIZETYPE sFrameSize;
|
||||
} OMX_PARAM_SENSORMODETYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines contrast level
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nContrast : Values allowed for contrast -100 to 100, zero means no change
|
||||
*/
|
||||
typedef struct OMX_CONFIG_CONTRASTTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nContrast;
|
||||
} OMX_CONFIG_CONTRASTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines brightness level
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nBrightness : 0-100%
|
||||
*/
|
||||
typedef struct OMX_CONFIG_BRIGHTNESSTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nBrightness;
|
||||
} OMX_CONFIG_BRIGHTNESSTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines backlight level configuration for a video sink, e.g. LCD panel
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nBacklight : Values allowed for backlight 0-100%
|
||||
* nTimeout : Number of milliseconds before backlight automatically turns
|
||||
* off. A value of 0x0 disables backight timeout
|
||||
*/
|
||||
typedef struct OMX_CONFIG_BACKLIGHTTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nBacklight;
|
||||
OMX_U32 nTimeout;
|
||||
} OMX_CONFIG_BACKLIGHTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines setting for Gamma
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nGamma : Values allowed for gamma -100 to 100, zero means no change
|
||||
*/
|
||||
typedef struct OMX_CONFIG_GAMMATYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nGamma;
|
||||
} OMX_CONFIG_GAMMATYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Define for setting saturation
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nSaturation : Values allowed for saturation -100 to 100, zero means
|
||||
* no change
|
||||
*/
|
||||
typedef struct OMX_CONFIG_SATURATIONTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nSaturation;
|
||||
} OMX_CONFIG_SATURATIONTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Define for setting Lightness
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* nLightness : Values allowed for lightness -100 to 100, zero means no
|
||||
* change
|
||||
*/
|
||||
typedef struct OMX_CONFIG_LIGHTNESSTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_S32 nLightness;
|
||||
} OMX_CONFIG_LIGHTNESSTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Plane blend configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Index of input port associated with the plane.
|
||||
* nDepth : Depth of the plane in relation to the screen. Higher
|
||||
* numbered depths are "behind" lower number depths.
|
||||
* This number defaults to the Port Index number.
|
||||
* nAlpha : Transparency blending component for the entire plane.
|
||||
* See blending modes for more detail.
|
||||
*/
|
||||
typedef struct OMX_CONFIG_PLANEBLENDTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_U32 nDepth;
|
||||
OMX_U32 nAlpha;
|
||||
} OMX_CONFIG_PLANEBLENDTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Define interlace type
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* bEnable : Enable control variable for this functionality
|
||||
* (see below)
|
||||
* nInterleavePortIndex : Index of input or output port associated with
|
||||
* the interleaved plane.
|
||||
* pPlanarPortIndexes[4] : Index of input or output planar ports.
|
||||
*/
|
||||
typedef struct OMX_PARAM_INTERLEAVETYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bEnable;
|
||||
OMX_U32 nInterleavePortIndex;
|
||||
} OMX_PARAM_INTERLEAVETYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the picture effect used for an input picture
|
||||
*/
|
||||
typedef enum OMX_TRANSITIONEFFECTTYPE {
|
||||
OMX_EffectNone,
|
||||
OMX_EffectFadeFromBlack,
|
||||
OMX_EffectFadeToBlack,
|
||||
OMX_EffectUnspecifiedThroughConstantColor,
|
||||
OMX_EffectDissolve,
|
||||
OMX_EffectWipe,
|
||||
OMX_EffectUnspecifiedMixOfTwoScenes,
|
||||
OMX_EffectKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_EffectVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_EffectMax = 0x7FFFFFFF
|
||||
} OMX_TRANSITIONEFFECTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Structure used to configure current transition effect
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* eEffect : Effect to enable
|
||||
*/
|
||||
typedef struct OMX_CONFIG_TRANSITIONEFFECTTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_TRANSITIONEFFECTTYPE eEffect;
|
||||
} OMX_CONFIG_TRANSITIONEFFECTTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines possible data unit types for encoded video data. The data unit
|
||||
* types are used both for encoded video input for playback as well as
|
||||
* encoded video output from recording.
|
||||
*/
|
||||
typedef enum OMX_DATAUNITTYPE {
|
||||
OMX_DataUnitCodedPicture,
|
||||
OMX_DataUnitVideoSegment,
|
||||
OMX_DataUnitSeveralSegments,
|
||||
OMX_DataUnitArbitraryStreamSection,
|
||||
OMX_DataUnitKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_DataUnitVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_DataUnitMax = 0x7FFFFFFF
|
||||
} OMX_DATAUNITTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines possible encapsulation types for coded video data unit. The
|
||||
* encapsulation information is used both for encoded video input for
|
||||
* playback as well as encoded video output from recording.
|
||||
*/
|
||||
typedef enum OMX_DATAUNITENCAPSULATIONTYPE {
|
||||
OMX_DataEncapsulationElementaryStream,
|
||||
OMX_DataEncapsulationGenericPayload,
|
||||
OMX_DataEncapsulationRtpPayload,
|
||||
OMX_DataEncapsulationKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_DataEncapsulationVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_DataEncapsulationMax = 0x7FFFFFFF
|
||||
} OMX_DATAUNITENCAPSULATIONTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Structure used to configure the type of being decoded/encoded
|
||||
*/
|
||||
typedef struct OMX_PARAM_DATAUNITTYPE {
|
||||
OMX_U32 nSize; /**< Size of the structure in bytes */
|
||||
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
|
||||
OMX_U32 nPortIndex; /**< Port that this structure applies to */
|
||||
OMX_DATAUNITTYPE eUnitType;
|
||||
OMX_DATAUNITENCAPSULATIONTYPE eEncapsulationType;
|
||||
} OMX_PARAM_DATAUNITTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Defines dither types
|
||||
*/
|
||||
typedef enum OMX_DITHERTYPE {
|
||||
OMX_DitherNone,
|
||||
OMX_DitherOrdered,
|
||||
OMX_DitherErrorDiffusion,
|
||||
OMX_DitherOther,
|
||||
OMX_DitherKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_DitherVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_DitherMax = 0x7FFFFFFF
|
||||
} OMX_DITHERTYPE;
|
||||
|
||||
|
||||
/**
|
||||
* Structure used to configure current type of dithering
|
||||
*/
|
||||
typedef struct OMX_CONFIG_DITHERTYPE {
|
||||
OMX_U32 nSize; /**< Size of the structure in bytes */
|
||||
OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
|
||||
OMX_U32 nPortIndex; /**< Port that this structure applies to */
|
||||
OMX_DITHERTYPE eDither; /**< Type of dithering to use */
|
||||
} OMX_CONFIG_DITHERTYPE;
|
||||
|
||||
typedef struct OMX_CONFIG_CAPTUREMODETYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex; /**< Port that this structure applies to */
|
||||
OMX_BOOL bContinuous; /**< If true then ignore frame rate and emit capture
|
||||
* data as fast as possible (otherwise obey port's frame rate). */
|
||||
OMX_BOOL bFrameLimited; /**< If true then terminate capture after the port emits the
|
||||
* specified number of frames (otherwise the port does not
|
||||
* terminate the capture until instructed to do so by the client).
|
||||
* Even if set, the client may manually terminate the capture prior
|
||||
* to reaching the limit. */
|
||||
OMX_U32 nFrameLimit; /**< Limit on number of frames emitted during a capture (only
|
||||
* valid if bFrameLimited is set). */
|
||||
} OMX_CONFIG_CAPTUREMODETYPE;
|
||||
|
||||
typedef enum OMX_METERINGTYPE {
|
||||
|
||||
OMX_MeteringModeAverage, /**< Center-weighted average metering. */
|
||||
OMX_MeteringModeSpot, /**< Spot (partial) metering. */
|
||||
OMX_MeteringModeMatrix, /**< Matrix or evaluative metering. */
|
||||
|
||||
OMX_MeteringKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_MeteringVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_EVModeMax = 0x7fffffff
|
||||
} OMX_METERINGTYPE;
|
||||
|
||||
typedef struct OMX_CONFIG_EXPOSUREVALUETYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_METERINGTYPE eMetering;
|
||||
OMX_S32 xEVCompensation; /**< Fixed point value stored as Q16 */
|
||||
OMX_U32 nApertureFNumber; /**< e.g. nApertureFNumber = 2 implies "f/2" - Q16 format */
|
||||
OMX_BOOL bAutoAperture; /**< Whether aperture number is defined automatically */
|
||||
OMX_U32 nShutterSpeedMsec; /**< Shutterspeed in milliseconds */
|
||||
OMX_BOOL bAutoShutterSpeed; /**< Whether shutter speed is defined automatically */
|
||||
OMX_U32 nSensitivity; /**< e.g. nSensitivity = 100 implies "ISO 100" */
|
||||
OMX_BOOL bAutoSensitivity; /**< Whether sensitivity is defined automatically */
|
||||
} OMX_CONFIG_EXPOSUREVALUETYPE;
|
||||
|
||||
/**
|
||||
* Focus region configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* bCenter : Use center region as focus region of interest
|
||||
* bLeft : Use left region as focus region of interest
|
||||
* bRight : Use right region as focus region of interest
|
||||
* bTop : Use top region as focus region of interest
|
||||
* bBottom : Use bottom region as focus region of interest
|
||||
* bTopLeft : Use top left region as focus region of interest
|
||||
* bTopRight : Use top right region as focus region of interest
|
||||
* bBottomLeft : Use bottom left region as focus region of interest
|
||||
* bBottomRight : Use bottom right region as focus region of interest
|
||||
*/
|
||||
typedef struct OMX_CONFIG_FOCUSREGIONTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bCenter;
|
||||
OMX_BOOL bLeft;
|
||||
OMX_BOOL bRight;
|
||||
OMX_BOOL bTop;
|
||||
OMX_BOOL bBottom;
|
||||
OMX_BOOL bTopLeft;
|
||||
OMX_BOOL bTopRight;
|
||||
OMX_BOOL bBottomLeft;
|
||||
OMX_BOOL bBottomRight;
|
||||
} OMX_CONFIG_FOCUSREGIONTYPE;
|
||||
|
||||
/**
|
||||
* Focus Status type
|
||||
*/
|
||||
typedef enum OMX_FOCUSSTATUSTYPE {
|
||||
OMX_FocusStatusOff = 0,
|
||||
OMX_FocusStatusRequest,
|
||||
OMX_FocusStatusReached,
|
||||
OMX_FocusStatusUnableToReach,
|
||||
OMX_FocusStatusLost,
|
||||
OMX_FocusStatusKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
OMX_FocusStatusVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
|
||||
OMX_FocusStatusMax = 0x7FFFFFFF
|
||||
} OMX_FOCUSSTATUSTYPE;
|
||||
|
||||
/**
|
||||
* Focus status configuration
|
||||
*
|
||||
* STRUCT MEMBERS:
|
||||
* nSize : Size of the structure in bytes
|
||||
* nVersion : OMX specification version information
|
||||
* nPortIndex : Port that this structure applies to
|
||||
* eFocusStatus : Specifies the focus status
|
||||
* bCenterStatus : Use center region as focus region of interest
|
||||
* bLeftStatus : Use left region as focus region of interest
|
||||
* bRightStatus : Use right region as focus region of interest
|
||||
* bTopStatus : Use top region as focus region of interest
|
||||
* bBottomStatus : Use bottom region as focus region of interest
|
||||
* bTopLeftStatus : Use top left region as focus region of interest
|
||||
* bTopRightStatus : Use top right region as focus region of interest
|
||||
* bBottomLeftStatus : Use bottom left region as focus region of interest
|
||||
* bBottomRightStatus : Use bottom right region as focus region of interest
|
||||
*/
|
||||
typedef struct OMX_PARAM_FOCUSSTATUSTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_FOCUSSTATUSTYPE eFocusStatus;
|
||||
OMX_BOOL bCenterStatus;
|
||||
OMX_BOOL bLeftStatus;
|
||||
OMX_BOOL bRightStatus;
|
||||
OMX_BOOL bTopStatus;
|
||||
OMX_BOOL bBottomStatus;
|
||||
OMX_BOOL bTopLeftStatus;
|
||||
OMX_BOOL bTopRightStatus;
|
||||
OMX_BOOL bBottomLeftStatus;
|
||||
OMX_BOOL bBottomRightStatus;
|
||||
} OMX_PARAM_FOCUSSTATUSTYPE;
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
/* File EOF */
|
|
@ -0,0 +1,276 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2008 The Khronos Group Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @file OMX_Index.h - OpenMax IL version 1.1.2
|
||||
* The OMX_Index header file contains the definitions for both applications
|
||||
* and components .
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OMX_Index_h
|
||||
#define OMX_Index_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/* Each OMX header must include all required header files to allow the
|
||||
* header to compile without errors. The includes below are required
|
||||
* for this header file to compile successfully
|
||||
*/
|
||||
#include <OMX_Types.h>
|
||||
|
||||
|
||||
/** The OMX_INDEXTYPE enumeration is used to select a structure when either
|
||||
* getting or setting parameters and/or configuration data. Each entry in
|
||||
* this enumeration maps to an OMX specified structure. When the
|
||||
* OMX_GetParameter, OMX_SetParameter, OMX_GetConfig or OMX_SetConfig methods
|
||||
* are used, the second parameter will always be an entry from this enumeration
|
||||
* and the third entry will be the structure shown in the comments for the entry.
|
||||
* For example, if the application is initializing a cropping function, the
|
||||
* OMX_SetConfig command would have OMX_IndexConfigCommonInputCrop as the second parameter
|
||||
* and would send a pointer to an initialized OMX_RECTTYPE structure as the
|
||||
* third parameter.
|
||||
*
|
||||
* The enumeration entries named with the OMX_Config prefix are sent using
|
||||
* the OMX_SetConfig command and the enumeration entries named with the
|
||||
* OMX_PARAM_ prefix are sent using the OMX_SetParameter command.
|
||||
*/
|
||||
typedef enum OMX_INDEXTYPE {
|
||||
|
||||
OMX_IndexComponentStartUnused = 0x01000000,
|
||||
OMX_IndexParamPriorityMgmt, /**< reference: OMX_PRIORITYMGMTTYPE */
|
||||
OMX_IndexParamAudioInit, /**< reference: OMX_PORT_PARAM_TYPE */
|
||||
OMX_IndexParamImageInit, /**< reference: OMX_PORT_PARAM_TYPE */
|
||||
OMX_IndexParamVideoInit, /**< reference: OMX_PORT_PARAM_TYPE */
|
||||
OMX_IndexParamOtherInit, /**< reference: OMX_PORT_PARAM_TYPE */
|
||||
OMX_IndexParamNumAvailableStreams, /**< reference: OMX_PARAM_U32TYPE */
|
||||
OMX_IndexParamActiveStream, /**< reference: OMX_PARAM_U32TYPE */
|
||||
OMX_IndexParamSuspensionPolicy, /**< reference: OMX_PARAM_SUSPENSIONPOLICYTYPE */
|
||||
OMX_IndexParamComponentSuspended, /**< reference: OMX_PARAM_SUSPENSIONTYPE */
|
||||
OMX_IndexConfigCapturing, /**< reference: OMX_CONFIG_BOOLEANTYPE */
|
||||
OMX_IndexConfigCaptureMode, /**< reference: OMX_CONFIG_CAPTUREMODETYPE */
|
||||
OMX_IndexAutoPauseAfterCapture, /**< reference: OMX_CONFIG_BOOLEANTYPE */
|
||||
OMX_IndexParamContentURI, /**< reference: OMX_PARAM_CONTENTURITYPE */
|
||||
OMX_IndexParamCustomContentPipe, /**< reference: OMX_PARAM_CONTENTPIPETYPE */
|
||||
OMX_IndexParamDisableResourceConcealment, /**< reference: OMX_RESOURCECONCEALMENTTYPE */
|
||||
OMX_IndexConfigMetadataItemCount, /**< reference: OMX_CONFIG_METADATAITEMCOUNTTYPE */
|
||||
OMX_IndexConfigContainerNodeCount, /**< reference: OMX_CONFIG_CONTAINERNODECOUNTTYPE */
|
||||
OMX_IndexConfigMetadataItem, /**< reference: OMX_CONFIG_METADATAITEMTYPE */
|
||||
OMX_IndexConfigCounterNodeID, /**< reference: OMX_CONFIG_CONTAINERNODEIDTYPE */
|
||||
OMX_IndexParamMetadataFilterType, /**< reference: OMX_PARAM_METADATAFILTERTYPE */
|
||||
OMX_IndexParamMetadataKeyFilter, /**< reference: OMX_PARAM_METADATAFILTERTYPE */
|
||||
OMX_IndexConfigPriorityMgmt, /**< reference: OMX_PRIORITYMGMTTYPE */
|
||||
OMX_IndexParamStandardComponentRole, /**< reference: OMX_PARAM_COMPONENTROLETYPE */
|
||||
|
||||
OMX_IndexPortStartUnused = 0x02000000,
|
||||
OMX_IndexParamPortDefinition, /**< reference: OMX_PARAM_PORTDEFINITIONTYPE */
|
||||
OMX_IndexParamCompBufferSupplier, /**< reference: OMX_PARAM_BUFFERSUPPLIERTYPE */
|
||||
OMX_IndexReservedStartUnused = 0x03000000,
|
||||
|
||||
/* Audio parameters and configurations */
|
||||
OMX_IndexAudioStartUnused = 0x04000000,
|
||||
OMX_IndexParamAudioPortFormat, /**< reference: OMX_AUDIO_PARAM_PORTFORMATTYPE */
|
||||
OMX_IndexParamAudioPcm, /**< reference: OMX_AUDIO_PARAM_PCMMODETYPE */
|
||||
OMX_IndexParamAudioAac, /**< reference: OMX_AUDIO_PARAM_AACPROFILETYPE */
|
||||
OMX_IndexParamAudioRa, /**< reference: OMX_AUDIO_PARAM_RATYPE */
|
||||
OMX_IndexParamAudioMp3, /**< reference: OMX_AUDIO_PARAM_MP3TYPE */
|
||||
OMX_IndexParamAudioAdpcm, /**< reference: OMX_AUDIO_PARAM_ADPCMTYPE */
|
||||
OMX_IndexParamAudioG723, /**< reference: OMX_AUDIO_PARAM_G723TYPE */
|
||||
OMX_IndexParamAudioG729, /**< reference: OMX_AUDIO_PARAM_G729TYPE */
|
||||
OMX_IndexParamAudioAmr, /**< reference: OMX_AUDIO_PARAM_AMRTYPE */
|
||||
OMX_IndexParamAudioWma, /**< reference: OMX_AUDIO_PARAM_WMATYPE */
|
||||
OMX_IndexParamAudioSbc, /**< reference: OMX_AUDIO_PARAM_SBCTYPE */
|
||||
OMX_IndexParamAudioMidi, /**< reference: OMX_AUDIO_PARAM_MIDITYPE */
|
||||
OMX_IndexParamAudioGsm_FR, /**< reference: OMX_AUDIO_PARAM_GSMFRTYPE */
|
||||
OMX_IndexParamAudioMidiLoadUserSound, /**< reference: OMX_AUDIO_PARAM_MIDILOADUSERSOUNDTYPE */
|
||||
OMX_IndexParamAudioG726, /**< reference: OMX_AUDIO_PARAM_G726TYPE */
|
||||
OMX_IndexParamAudioGsm_EFR, /**< reference: OMX_AUDIO_PARAM_GSMEFRTYPE */
|
||||
OMX_IndexParamAudioGsm_HR, /**< reference: OMX_AUDIO_PARAM_GSMHRTYPE */
|
||||
OMX_IndexParamAudioPdc_FR, /**< reference: OMX_AUDIO_PARAM_PDCFRTYPE */
|
||||
OMX_IndexParamAudioPdc_EFR, /**< reference: OMX_AUDIO_PARAM_PDCEFRTYPE */
|
||||
OMX_IndexParamAudioPdc_HR, /**< reference: OMX_AUDIO_PARAM_PDCHRTYPE */
|
||||
OMX_IndexParamAudioTdma_FR, /**< reference: OMX_AUDIO_PARAM_TDMAFRTYPE */
|
||||
OMX_IndexParamAudioTdma_EFR, /**< reference: OMX_AUDIO_PARAM_TDMAEFRTYPE */
|
||||
OMX_IndexParamAudioQcelp8, /**< reference: OMX_AUDIO_PARAM_QCELP8TYPE */
|
||||
OMX_IndexParamAudioQcelp13, /**< reference: OMX_AUDIO_PARAM_QCELP13TYPE */
|
||||
OMX_IndexParamAudioEvrc, /**< reference: OMX_AUDIO_PARAM_EVRCTYPE */
|
||||
OMX_IndexParamAudioSmv, /**< reference: OMX_AUDIO_PARAM_SMVTYPE */
|
||||
OMX_IndexParamAudioVorbis, /**< reference: OMX_AUDIO_PARAM_VORBISTYPE */
|
||||
OMX_IndexParamAudioFlac, /**< reference: OMX_AUDIO_PARAM_FLACTYPE */
|
||||
|
||||
OMX_IndexConfigAudioMidiImmediateEvent, /**< reference: OMX_AUDIO_CONFIG_MIDIIMMEDIATEEVENTTYPE */
|
||||
OMX_IndexConfigAudioMidiControl, /**< reference: OMX_AUDIO_CONFIG_MIDICONTROLTYPE */
|
||||
OMX_IndexConfigAudioMidiSoundBankProgram, /**< reference: OMX_AUDIO_CONFIG_MIDISOUNDBANKPROGRAMTYPE */
|
||||
OMX_IndexConfigAudioMidiStatus, /**< reference: OMX_AUDIO_CONFIG_MIDISTATUSTYPE */
|
||||
OMX_IndexConfigAudioMidiMetaEvent, /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTTYPE */
|
||||
OMX_IndexConfigAudioMidiMetaEventData, /**< reference: OMX_AUDIO_CONFIG_MIDIMETAEVENTDATATYPE */
|
||||
OMX_IndexConfigAudioVolume, /**< reference: OMX_AUDIO_CONFIG_VOLUMETYPE */
|
||||
OMX_IndexConfigAudioBalance, /**< reference: OMX_AUDIO_CONFIG_BALANCETYPE */
|
||||
OMX_IndexConfigAudioChannelMute, /**< reference: OMX_AUDIO_CONFIG_CHANNELMUTETYPE */
|
||||
OMX_IndexConfigAudioMute, /**< reference: OMX_AUDIO_CONFIG_MUTETYPE */
|
||||
OMX_IndexConfigAudioLoudness, /**< reference: OMX_AUDIO_CONFIG_LOUDNESSTYPE */
|
||||
OMX_IndexConfigAudioEchoCancelation, /**< reference: OMX_AUDIO_CONFIG_ECHOCANCELATIONTYPE */
|
||||
OMX_IndexConfigAudioNoiseReduction, /**< reference: OMX_AUDIO_CONFIG_NOISEREDUCTIONTYPE */
|
||||
OMX_IndexConfigAudioBass, /**< reference: OMX_AUDIO_CONFIG_BASSTYPE */
|
||||
OMX_IndexConfigAudioTreble, /**< reference: OMX_AUDIO_CONFIG_TREBLETYPE */
|
||||
OMX_IndexConfigAudioStereoWidening, /**< reference: OMX_AUDIO_CONFIG_STEREOWIDENINGTYPE */
|
||||
OMX_IndexConfigAudioChorus, /**< reference: OMX_AUDIO_CONFIG_CHORUSTYPE */
|
||||
OMX_IndexConfigAudioEqualizer, /**< reference: OMX_AUDIO_CONFIG_EQUALIZERTYPE */
|
||||
OMX_IndexConfigAudioReverberation, /**< reference: OMX_AUDIO_CONFIG_REVERBERATIONTYPE */
|
||||
OMX_IndexConfigAudioChannelVolume, /**< reference: OMX_AUDIO_CONFIG_CHANNELVOLUMETYPE */
|
||||
|
||||
/* Image specific parameters and configurations */
|
||||
OMX_IndexImageStartUnused = 0x05000000,
|
||||
OMX_IndexParamImagePortFormat, /**< reference: OMX_IMAGE_PARAM_PORTFORMATTYPE */
|
||||
OMX_IndexParamFlashControl, /**< reference: OMX_IMAGE_PARAM_FLASHCONTROLTYPE */
|
||||
OMX_IndexConfigFocusControl, /**< reference: OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE */
|
||||
OMX_IndexParamQFactor, /**< reference: OMX_IMAGE_PARAM_QFACTORTYPE */
|
||||
OMX_IndexParamQuantizationTable, /**< reference: OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE */
|
||||
OMX_IndexParamHuffmanTable, /**< reference: OMX_IMAGE_PARAM_HUFFMANTTABLETYPE */
|
||||
OMX_IndexConfigFlashControl, /**< reference: OMX_IMAGE_PARAM_FLASHCONTROLTYPE */
|
||||
|
||||
/* Video specific parameters and configurations */
|
||||
OMX_IndexVideoStartUnused = 0x06000000,
|
||||
OMX_IndexParamVideoPortFormat, /**< reference: OMX_VIDEO_PARAM_PORTFORMATTYPE */
|
||||
OMX_IndexParamVideoQuantization, /**< reference: OMX_VIDEO_PARAM_QUANTIZATIONTYPE */
|
||||
OMX_IndexParamVideoFastUpdate, /**< reference: OMX_VIDEO_PARAM_VIDEOFASTUPDATETYPE */
|
||||
OMX_IndexParamVideoBitrate, /**< reference: OMX_VIDEO_PARAM_BITRATETYPE */
|
||||
OMX_IndexParamVideoMotionVector, /**< reference: OMX_VIDEO_PARAM_MOTIONVECTORTYPE */
|
||||
OMX_IndexParamVideoIntraRefresh, /**< reference: OMX_VIDEO_PARAM_INTRAREFRESHTYPE */
|
||||
OMX_IndexParamVideoErrorCorrection, /**< reference: OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE */
|
||||
OMX_IndexParamVideoVBSMC, /**< reference: OMX_VIDEO_PARAM_VBSMCTYPE */
|
||||
OMX_IndexParamVideoMpeg2, /**< reference: OMX_VIDEO_PARAM_MPEG2TYPE */
|
||||
OMX_IndexParamVideoMpeg4, /**< reference: OMX_VIDEO_PARAM_MPEG4TYPE */
|
||||
OMX_IndexParamVideoWmv, /**< reference: OMX_VIDEO_PARAM_WMVTYPE */
|
||||
OMX_IndexParamVideoRv, /**< reference: OMX_VIDEO_PARAM_RVTYPE */
|
||||
OMX_IndexParamVideoAvc, /**< reference: OMX_VIDEO_PARAM_AVCTYPE */
|
||||
OMX_IndexParamVideoH263, /**< reference: OMX_VIDEO_PARAM_H263TYPE */
|
||||
OMX_IndexParamVideoProfileLevelQuerySupported, /**< reference: OMX_VIDEO_PARAM_PROFILELEVELTYPE */
|
||||
OMX_IndexParamVideoProfileLevelCurrent, /**< reference: OMX_VIDEO_PARAM_PROFILELEVELTYPE */
|
||||
OMX_IndexConfigVideoBitrate, /**< reference: OMX_VIDEO_CONFIG_BITRATETYPE */
|
||||
OMX_IndexConfigVideoFramerate, /**< reference: OMX_CONFIG_FRAMERATETYPE */
|
||||
OMX_IndexConfigVideoIntraVOPRefresh, /**< reference: OMX_CONFIG_INTRAREFRESHVOPTYPE */
|
||||
OMX_IndexConfigVideoIntraMBRefresh, /**< reference: OMX_CONFIG_MACROBLOCKERRORMAPTYPE */
|
||||
OMX_IndexConfigVideoMBErrorReporting, /**< reference: OMX_CONFIG_MBERRORREPORTINGTYPE */
|
||||
OMX_IndexParamVideoMacroblocksPerFrame, /**< reference: OMX_PARAM_MACROBLOCKSTYPE */
|
||||
OMX_IndexConfigVideoMacroBlockErrorMap, /**< reference: OMX_CONFIG_MACROBLOCKERRORMAPTYPE */
|
||||
OMX_IndexParamVideoSliceFMO, /**< reference: OMX_VIDEO_PARAM_AVCSLICEFMO */
|
||||
OMX_IndexConfigVideoAVCIntraPeriod, /**< reference: OMX_VIDEO_CONFIG_AVCINTRAPERIOD */
|
||||
OMX_IndexConfigVideoNalSize, /**< reference: OMX_VIDEO_CONFIG_NALSIZE */
|
||||
|
||||
/* Image & Video common Configurations */
|
||||
OMX_IndexCommonStartUnused = 0x07000000,
|
||||
OMX_IndexParamCommonDeblocking, /**< reference: OMX_PARAM_DEBLOCKINGTYPE */
|
||||
OMX_IndexParamCommonSensorMode, /**< reference: OMX_PARAM_SENSORMODETYPE */
|
||||
OMX_IndexParamCommonInterleave, /**< reference: OMX_PARAM_INTERLEAVETYPE */
|
||||
OMX_IndexConfigCommonColorFormatConversion, /**< reference: OMX_CONFIG_COLORCONVERSIONTYPE */
|
||||
OMX_IndexConfigCommonScale, /**< reference: OMX_CONFIG_SCALEFACTORTYPE */
|
||||
OMX_IndexConfigCommonImageFilter, /**< reference: OMX_CONFIG_IMAGEFILTERTYPE */
|
||||
OMX_IndexConfigCommonColorEnhancement, /**< reference: OMX_CONFIG_COLORENHANCEMENTTYPE */
|
||||
OMX_IndexConfigCommonColorKey, /**< reference: OMX_CONFIG_COLORKEYTYPE */
|
||||
OMX_IndexConfigCommonColorBlend, /**< reference: OMX_CONFIG_COLORBLENDTYPE */
|
||||
OMX_IndexConfigCommonFrameStabilisation,/**< reference: OMX_CONFIG_FRAMESTABTYPE */
|
||||
OMX_IndexConfigCommonRotate, /**< reference: OMX_CONFIG_ROTATIONTYPE */
|
||||
OMX_IndexConfigCommonMirror, /**< reference: OMX_CONFIG_MIRRORTYPE */
|
||||
OMX_IndexConfigCommonOutputPosition, /**< reference: OMX_CONFIG_POINTTYPE */
|
||||
OMX_IndexConfigCommonInputCrop, /**< reference: OMX_CONFIG_RECTTYPE */
|
||||
OMX_IndexConfigCommonOutputCrop, /**< reference: OMX_CONFIG_RECTTYPE */
|
||||
OMX_IndexConfigCommonDigitalZoom, /**< reference: OMX_CONFIG_SCALEFACTORTYPE */
|
||||
OMX_IndexConfigCommonOpticalZoom, /**< reference: OMX_CONFIG_SCALEFACTORTYPE*/
|
||||
OMX_IndexConfigCommonWhiteBalance, /**< reference: OMX_CONFIG_WHITEBALCONTROLTYPE */
|
||||
OMX_IndexConfigCommonExposure, /**< reference: OMX_CONFIG_EXPOSURECONTROLTYPE */
|
||||
OMX_IndexConfigCommonContrast, /**< reference: OMX_CONFIG_CONTRASTTYPE */
|
||||
OMX_IndexConfigCommonBrightness, /**< reference: OMX_CONFIG_BRIGHTNESSTYPE */
|
||||
OMX_IndexConfigCommonBacklight, /**< reference: OMX_CONFIG_BACKLIGHTTYPE */
|
||||
OMX_IndexConfigCommonGamma, /**< reference: OMX_CONFIG_GAMMATYPE */
|
||||
OMX_IndexConfigCommonSaturation, /**< reference: OMX_CONFIG_SATURATIONTYPE */
|
||||
OMX_IndexConfigCommonLightness, /**< reference: OMX_CONFIG_LIGHTNESSTYPE */
|
||||
OMX_IndexConfigCommonExclusionRect, /**< reference: OMX_CONFIG_RECTTYPE */
|
||||
OMX_IndexConfigCommonDithering, /**< reference: OMX_CONFIG_DITHERTYPE */
|
||||
OMX_IndexConfigCommonPlaneBlend, /**< reference: OMX_CONFIG_PLANEBLENDTYPE */
|
||||
OMX_IndexConfigCommonExposureValue, /**< reference: OMX_CONFIG_EXPOSUREVALUETYPE */
|
||||
OMX_IndexConfigCommonOutputSize, /**< reference: OMX_FRAMESIZETYPE */
|
||||
OMX_IndexParamCommonExtraQuantData, /**< reference: OMX_OTHER_EXTRADATATYPE */
|
||||
OMX_IndexConfigCommonFocusRegion, /**< reference: OMX_CONFIG_FOCUSREGIONTYPE */
|
||||
OMX_IndexConfigCommonFocusStatus, /**< reference: OMX_PARAM_FOCUSSTATUSTYPE */
|
||||
OMX_IndexConfigCommonTransitionEffect, /**< reference: OMX_CONFIG_TRANSITIONEFFECTTYPE */
|
||||
|
||||
/* Reserved Configuration range */
|
||||
OMX_IndexOtherStartUnused = 0x08000000,
|
||||
OMX_IndexParamOtherPortFormat, /**< reference: OMX_OTHER_PARAM_PORTFORMATTYPE */
|
||||
OMX_IndexConfigOtherPower, /**< reference: OMX_OTHER_CONFIG_POWERTYPE */
|
||||
OMX_IndexConfigOtherStats, /**< reference: OMX_OTHER_CONFIG_STATSTYPE */
|
||||
|
||||
|
||||
/* Reserved Time range */
|
||||
OMX_IndexTimeStartUnused = 0x09000000,
|
||||
OMX_IndexConfigTimeScale, /**< reference: OMX_TIME_CONFIG_SCALETYPE */
|
||||
OMX_IndexConfigTimeClockState, /**< reference: OMX_TIME_CONFIG_CLOCKSTATETYPE */
|
||||
OMX_IndexConfigTimeActiveRefClock, /**< reference: OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE */
|
||||
OMX_IndexConfigTimeCurrentMediaTime, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only) */
|
||||
OMX_IndexConfigTimeCurrentWallTime, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (read only) */
|
||||
OMX_IndexConfigTimeCurrentAudioReference, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
|
||||
OMX_IndexConfigTimeCurrentVideoReference, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
|
||||
OMX_IndexConfigTimeMediaTimeRequest, /**< reference: OMX_TIME_CONFIG_MEDIATIMEREQUESTTYPE (write only) */
|
||||
OMX_IndexConfigTimeClientStartTime, /**<reference: OMX_TIME_CONFIG_TIMESTAMPTYPE (write only) */
|
||||
OMX_IndexConfigTimePosition, /**< reference: OMX_TIME_CONFIG_TIMESTAMPTYPE */
|
||||
OMX_IndexConfigTimeSeekMode, /**< reference: OMX_TIME_CONFIG_SEEKMODETYPE */
|
||||
|
||||
|
||||
OMX_IndexKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
|
||||
/* Vendor specific area */
|
||||
OMX_IndexVendorStartUnused = 0x7F000000,
|
||||
/* Vendor specific structures should be in the range of 0x7F000000
|
||||
to 0x7FFFFFFE. This range is not broken out by vendor, so
|
||||
private indexes are not guaranteed unique and therefore should
|
||||
only be sent to the appropriate component. */
|
||||
|
||||
OMX_IndexMax = 0x7FFFFFFF
|
||||
|
||||
} OMX_INDEXTYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
/* File EOF */
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2010 The Khronos Group Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @file OMX_IndexExt.h - OpenMax IL version 1.1.2
|
||||
* The OMX_IndexExt header file contains extensions to the definitions
|
||||
* for both applications and components .
|
||||
*/
|
||||
|
||||
#ifndef OMX_IndexExt_h
|
||||
#define OMX_IndexExt_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Each OMX header shall include all required header files to allow the
|
||||
* header to compile without errors. The includes below are required
|
||||
* for this header file to compile successfully
|
||||
*/
|
||||
#include <OMX_Index.h>
|
||||
|
||||
|
||||
/** Khronos standard extension indices.
|
||||
|
||||
This enum lists the current Khronos extension indices to OpenMAX IL.
|
||||
*/
|
||||
typedef enum OMX_INDEXEXTTYPE {
|
||||
|
||||
/* Component parameters and configurations */
|
||||
OMX_IndexExtComponentStartUnused = OMX_IndexKhronosExtensions + 0x00100000,
|
||||
OMX_IndexConfigCallbackRequest, /**< reference: OMX_CONFIG_CALLBACKREQUESTTYPE */
|
||||
OMX_IndexConfigCommitMode, /**< reference: OMX_CONFIG_COMMITMODETYPE */
|
||||
OMX_IndexConfigCommit, /**< reference: OMX_CONFIG_COMMITTYPE */
|
||||
|
||||
/* Port parameters and configurations */
|
||||
OMX_IndexExtPortStartUnused = OMX_IndexKhronosExtensions + 0x00200000,
|
||||
|
||||
/* Audio parameters and configurations */
|
||||
OMX_IndexExtAudioStartUnused = OMX_IndexKhronosExtensions + 0x00400000,
|
||||
|
||||
/* Image parameters and configurations */
|
||||
OMX_IndexExtImageStartUnused = OMX_IndexKhronosExtensions + 0x00500000,
|
||||
|
||||
/* Video parameters and configurations */
|
||||
OMX_IndexExtVideoStartUnused = OMX_IndexKhronosExtensions + 0x00600000,
|
||||
OMX_IndexParamNalStreamFormatSupported, /**< reference: OMX_NALSTREAMFORMATTYPE */
|
||||
OMX_IndexParamNalStreamFormat, /**< reference: OMX_NALSTREAMFORMATTYPE */
|
||||
OMX_IndexParamNalStreamFormatSelect, /**< reference: OMX_NALSTREAMFORMATTYPE */
|
||||
OMX_IndexParamVideoVp8, /**< reference: OMX_VIDEO_PARAM_VP8TYPE */
|
||||
OMX_IndexConfigVideoVp8ReferenceFrame, /**< reference: OMX_VIDEO_VP8REFERENCEFRAMETYPE */
|
||||
OMX_IndexConfigVideoVp8ReferenceFrameType, /**< reference: OMX_VIDEO_VP8REFERENCEFRAMEINFOTYPE */
|
||||
|
||||
/* Image & Video common configurations */
|
||||
OMX_IndexExtCommonStartUnused = OMX_IndexKhronosExtensions + 0x00700000,
|
||||
|
||||
/* Other configurations */
|
||||
OMX_IndexExtOtherStartUnused = OMX_IndexKhronosExtensions + 0x00800000,
|
||||
|
||||
/* Time configurations */
|
||||
OMX_IndexExtTimeStartUnused = OMX_IndexKhronosExtensions + 0x00900000,
|
||||
|
||||
OMX_IndexExtMax = 0x7FFFFFFF
|
||||
} OMX_INDEXEXTTYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OMX_IndexExt_h */
|
||||
/* File EOF */
|
|
@ -0,0 +1,365 @@
|
|||
/* ------------------------------------------------------------------
|
||||
* Copyright (C) 1998-2009 PacketVideo
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
* -------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2008 The Khronos Group Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/** OMX_Types.h - OpenMax IL version 1.1.2
|
||||
* The OMX_Types header file contains the primitive type definitions used by
|
||||
* the core, the application and the component. This file may need to be
|
||||
* modified to be used on systems that do not have "char" set to 8 bits,
|
||||
* "short" set to 16 bits and "long" set to 32 bits.
|
||||
*/
|
||||
|
||||
#ifndef OMX_Types_h
|
||||
#define OMX_Types_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/** The OMX_API and OMX_APIENTRY are platform specific definitions used
|
||||
* to declare OMX function prototypes. They are modified to meet the
|
||||
* requirements for a particular platform */
|
||||
#ifdef __SYMBIAN32__
|
||||
# ifdef __OMX_EXPORTS
|
||||
# define OMX_API __declspec(dllexport)
|
||||
# else
|
||||
# ifdef _WIN32
|
||||
# define OMX_API __declspec(dllexport)
|
||||
# else
|
||||
# define OMX_API __declspec(dllimport)
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# ifdef _WIN32
|
||||
# ifdef __OMX_EXPORTS
|
||||
# define OMX_API __declspec(dllexport)
|
||||
# else
|
||||
//# define OMX_API __declspec(dllimport)
|
||||
#define OMX_API
|
||||
# endif
|
||||
# else
|
||||
# ifdef __OMX_EXPORTS
|
||||
# define OMX_API
|
||||
# else
|
||||
# define OMX_API extern
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OMX_APIENTRY
|
||||
#define OMX_APIENTRY
|
||||
#endif
|
||||
|
||||
/** OMX_IN is used to identify inputs to an OMX function. This designation
|
||||
will also be used in the case of a pointer that points to a parameter
|
||||
that is used as an output. */
|
||||
#ifndef OMX_IN
|
||||
#define OMX_IN
|
||||
#endif
|
||||
|
||||
/** OMX_OUT is used to identify outputs from an OMX function. This
|
||||
designation will also be used in the case of a pointer that points
|
||||
to a parameter that is used as an input. */
|
||||
#ifndef OMX_OUT
|
||||
#define OMX_OUT
|
||||
#endif
|
||||
|
||||
|
||||
/** OMX_INOUT is used to identify parameters that may be either inputs or
|
||||
outputs from an OMX function at the same time. This designation will
|
||||
also be used in the case of a pointer that points to a parameter that
|
||||
is used both as an input and an output. */
|
||||
#ifndef OMX_INOUT
|
||||
#define OMX_INOUT
|
||||
#endif
|
||||
|
||||
/** OMX_ALL is used to as a wildcard to select all entities of the same type
|
||||
* when specifying the index, or referring to a object by an index. (i.e.
|
||||
* use OMX_ALL to indicate all N channels). When used as a port index
|
||||
* for a config or parameter this OMX_ALL denotes that the config or
|
||||
* parameter applies to the entire component not just one port. */
|
||||
#define OMX_ALL 0xFFFFFFFF
|
||||
|
||||
/** In the following we define groups that help building doxygen documentation */
|
||||
|
||||
/** @defgroup core OpenMAX IL core
|
||||
* Functions and structure related to the OMX IL core
|
||||
*/
|
||||
|
||||
/** @defgroup comp OpenMAX IL component
|
||||
* Functions and structure related to the OMX IL component
|
||||
*/
|
||||
|
||||
/** @defgroup rpm Resource and Policy Management
|
||||
* Structures for resource and policy management of components
|
||||
*/
|
||||
|
||||
/** @defgroup buf Buffer Management
|
||||
* Buffer handling functions and structures
|
||||
*/
|
||||
|
||||
/** @defgroup tun Tunneling
|
||||
* @ingroup core comp
|
||||
* Structures and functions to manage tunnels among component ports
|
||||
*/
|
||||
|
||||
/** @defgroup cp Content Pipes
|
||||
* @ingroup core
|
||||
*/
|
||||
|
||||
/** @defgroup metadata Metadata handling
|
||||
*
|
||||
*/
|
||||
|
||||
/** OMX_U8 is an 8 bit unsigned quantity that is byte aligned */
|
||||
typedef unsigned char OMX_U8;
|
||||
|
||||
/** OMX_S8 is an 8 bit signed quantity that is byte aligned */
|
||||
typedef signed char OMX_S8;
|
||||
|
||||
/** OMX_U16 is a 16 bit unsigned quantity that is 16 bit word aligned */
|
||||
typedef unsigned short OMX_U16;
|
||||
|
||||
/** OMX_S16 is a 16 bit signed quantity that is 16 bit word aligned */
|
||||
typedef signed short OMX_S16;
|
||||
|
||||
/** OMX_U32 is a 32 bit unsigned quantity that is 32 bit word aligned */
|
||||
typedef unsigned long OMX_U32;
|
||||
|
||||
/** OMX_S32 is a 32 bit signed quantity that is 32 bit word aligned */
|
||||
typedef signed long OMX_S32;
|
||||
|
||||
|
||||
/* Users with compilers that cannot accept the "long long" designation should
|
||||
define the OMX_SKIP64BIT macro. It should be noted that this may cause
|
||||
some components to fail to compile if the component was written to require
|
||||
64 bit integral types. However, these components would NOT compile anyway
|
||||
since the compiler does not support the way the component was written.
|
||||
*/
|
||||
#ifndef OMX_SKIP64BIT
|
||||
#ifdef __SYMBIAN32__
|
||||
/** OMX_U64 is a 64 bit unsigned quantity that is 64 bit word aligned */
|
||||
typedef unsigned long long OMX_U64;
|
||||
|
||||
/** OMX_S64 is a 64 bit signed quantity that is 64 bit word aligned */
|
||||
typedef signed long long OMX_S64;
|
||||
|
||||
#elif defined(WIN32)
|
||||
|
||||
/** OMX_U64 is a 64 bit unsigned quantity that is 64 bit word aligned */
|
||||
typedef unsigned __int64 OMX_U64;
|
||||
|
||||
/** OMX_S64 is a 64 bit signed quantity that is 64 bit word aligned */
|
||||
typedef signed __int64 OMX_S64;
|
||||
|
||||
#else /* WIN32 */
|
||||
|
||||
/** OMX_U64 is a 64 bit unsigned quantity that is 64 bit word aligned */
|
||||
typedef unsigned long long OMX_U64;
|
||||
|
||||
/** OMX_S64 is a 64 bit signed quantity that is 64 bit word aligned */
|
||||
typedef signed long long OMX_S64;
|
||||
|
||||
#endif /* WIN32 */
|
||||
#endif
|
||||
|
||||
|
||||
/** The OMX_BOOL type is intended to be used to represent a true or a false
|
||||
value when passing parameters to and from the OMX core and components. The
|
||||
OMX_BOOL is a 32 bit quantity and is aligned on a 32 bit word boundary.
|
||||
*/
|
||||
typedef enum OMX_BOOL {
|
||||
OMX_FALSE = 0,
|
||||
OMX_TRUE = !OMX_FALSE,
|
||||
OMX_BOOL_MAX = 0x7FFFFFFF
|
||||
} OMX_BOOL;
|
||||
|
||||
/** The OMX_PTR type is intended to be used to pass pointers between the OMX
|
||||
applications and the OMX Core and components. This is a 32 bit pointer and
|
||||
is aligned on a 32 bit boundary.
|
||||
*/
|
||||
typedef void* OMX_PTR;
|
||||
|
||||
/** The OMX_STRING type is intended to be used to pass "C" type strings between
|
||||
the application and the core and component. The OMX_STRING type is a 32
|
||||
bit pointer to a zero terminated string. The pointer is word aligned and
|
||||
the string is byte aligned.
|
||||
*/
|
||||
typedef char* OMX_STRING;
|
||||
|
||||
/** The OMX_BYTE type is intended to be used to pass arrays of bytes such as
|
||||
buffers between the application and the component and core. The OMX_BYTE
|
||||
type is a 32 bit pointer to a zero terminated string. The pointer is word
|
||||
aligned and the string is byte aligned.
|
||||
*/
|
||||
typedef unsigned char* OMX_BYTE;
|
||||
|
||||
/** OMX_UUIDTYPE is a very long unique identifier to uniquely identify
|
||||
at runtime. This identifier should be generated by a component in a way
|
||||
that guarantees that every instance of the identifier running on the system
|
||||
is unique. */
|
||||
typedef unsigned char OMX_UUIDTYPE[128];
|
||||
|
||||
/** The OMX_DIRTYPE enumeration is used to indicate if a port is an input or
|
||||
an output port. This enumeration is common across all component types.
|
||||
*/
|
||||
typedef enum OMX_DIRTYPE
|
||||
{
|
||||
OMX_DirInput, /**< Port is an input port */
|
||||
OMX_DirOutput, /**< Port is an output port */
|
||||
OMX_DirMax = 0x7FFFFFFF
|
||||
} OMX_DIRTYPE;
|
||||
|
||||
/** The OMX_ENDIANTYPE enumeration is used to indicate the bit ordering
|
||||
for numerical data (i.e. big endian, or little endian).
|
||||
*/
|
||||
typedef enum OMX_ENDIANTYPE
|
||||
{
|
||||
OMX_EndianBig, /**< big endian */
|
||||
OMX_EndianLittle, /**< little endian */
|
||||
OMX_EndianMax = 0x7FFFFFFF
|
||||
} OMX_ENDIANTYPE;
|
||||
|
||||
|
||||
/** The OMX_NUMERICALDATATYPE enumeration is used to indicate if data
|
||||
is signed or unsigned
|
||||
*/
|
||||
typedef enum OMX_NUMERICALDATATYPE
|
||||
{
|
||||
OMX_NumericalDataSigned, /**< signed data */
|
||||
OMX_NumericalDataUnsigned, /**< unsigned data */
|
||||
OMX_NumercialDataMax = 0x7FFFFFFF
|
||||
} OMX_NUMERICALDATATYPE;
|
||||
|
||||
|
||||
/** Unsigned bounded value type */
|
||||
typedef struct OMX_BU32 {
|
||||
OMX_U32 nValue; /**< actual value */
|
||||
OMX_U32 nMin; /**< minimum for value (i.e. nValue >= nMin) */
|
||||
OMX_U32 nMax; /**< maximum for value (i.e. nValue <= nMax) */
|
||||
} OMX_BU32;
|
||||
|
||||
|
||||
/** Signed bounded value type */
|
||||
typedef struct OMX_BS32 {
|
||||
OMX_S32 nValue; /**< actual value */
|
||||
OMX_S32 nMin; /**< minimum for value (i.e. nValue >= nMin) */
|
||||
OMX_S32 nMax; /**< maximum for value (i.e. nValue <= nMax) */
|
||||
} OMX_BS32;
|
||||
|
||||
|
||||
/** Structure representing some time or duration in microseconds. This structure
|
||||
* must be interpreted as a signed 64 bit value. The quantity is signed to accommodate
|
||||
* negative deltas and preroll scenarios. The quantity is represented in microseconds
|
||||
* to accomodate high resolution timestamps (e.g. DVD presentation timestamps based
|
||||
* on a 90kHz clock) and to allow more accurate and synchronized delivery (e.g.
|
||||
* individual audio samples delivered at 192 kHz). The quantity is 64 bit to
|
||||
* accommodate a large dynamic range (signed 32 bit values would allow only for plus
|
||||
* or minus 35 minutes).
|
||||
*
|
||||
* Implementations with limited precision may convert the signed 64 bit value to
|
||||
* a signed 32 bit value internally but risk loss of precision.
|
||||
*/
|
||||
#ifndef OMX_SKIP64BIT
|
||||
typedef OMX_S64 OMX_TICKS;
|
||||
#else
|
||||
typedef struct OMX_TICKS
|
||||
{
|
||||
OMX_U32 nLowPart; /** low bits of the signed 64 bit tick value */
|
||||
OMX_U32 nHighPart; /** high bits of the signed 64 bit tick value */
|
||||
} OMX_TICKS;
|
||||
#endif
|
||||
#define OMX_TICKS_PER_SECOND 1000000
|
||||
|
||||
/** Define the public interface for the OMX Handle. The core will not use
|
||||
this value internally, but the application should only use this value.
|
||||
*/
|
||||
typedef void* OMX_HANDLETYPE;
|
||||
|
||||
typedef struct OMX_MARKTYPE
|
||||
{
|
||||
OMX_HANDLETYPE hMarkTargetComponent; /**< The component that will
|
||||
generate a mark event upon
|
||||
processing the mark. */
|
||||
OMX_PTR pMarkData; /**< Application specific data associated with
|
||||
the mark sent on a mark event to disambiguate
|
||||
this mark from others. */
|
||||
} OMX_MARKTYPE;
|
||||
|
||||
|
||||
/** OMX_NATIVE_DEVICETYPE is used to map a OMX video port to the
|
||||
* platform & operating specific object used to reference the display
|
||||
* or can be used by a audio port for native audio rendering */
|
||||
typedef void* OMX_NATIVE_DEVICETYPE;
|
||||
|
||||
/** OMX_NATIVE_WINDOWTYPE is used to map a OMX video port to the
|
||||
* platform & operating specific object used to reference the window */
|
||||
typedef void* OMX_NATIVE_WINDOWTYPE;
|
||||
|
||||
/** The OMX_VERSIONTYPE union is used to specify the version for
|
||||
a structure or component. For a component, the version is entirely
|
||||
specified by the component vendor. Components doing the same function
|
||||
from different vendors may or may not have the same version. For
|
||||
structures, the version shall be set by the entity that allocates the
|
||||
structure. For structures specified in the OMX 1.1 specification, the
|
||||
value of the version shall be set to 1.1.0.0 in all cases. Access to the
|
||||
OMX_VERSIONTYPE can be by a single 32 bit access (e.g. by nVersion) or
|
||||
by accessing one of the structure elements to, for example, check only
|
||||
the Major revision.
|
||||
*/
|
||||
typedef union OMX_VERSIONTYPE
|
||||
{
|
||||
struct
|
||||
{
|
||||
OMX_U8 nVersionMajor; /**< Major version accessor element */
|
||||
OMX_U8 nVersionMinor; /**< Minor version accessor element */
|
||||
OMX_U8 nRevision; /**< Revision version accessor element */
|
||||
OMX_U8 nStep; /**< Step version accessor element */
|
||||
} s;
|
||||
OMX_U32 nVersion; /**< 32 bit value to make accessing the
|
||||
version easily done in a single word
|
||||
size copy/compare operation */
|
||||
} OMX_VERSIONTYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
/* File EOF */
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2010 The Khronos Group Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject
|
||||
* to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/** OMX_VideoExt.h - OpenMax IL version 1.1.2
|
||||
* The OMX_VideoExt header file contains extensions to the
|
||||
* definitions used by both the application and the component to
|
||||
* access video items.
|
||||
*/
|
||||
|
||||
#ifndef OMX_VideoExt_h
|
||||
#define OMX_VideoExt_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Each OMX header shall include all required header files to allow the
|
||||
* header to compile without errors. The includes below are required
|
||||
* for this header file to compile successfully
|
||||
*/
|
||||
#include <OMX_Core.h>
|
||||
|
||||
/** NALU Formats */
|
||||
typedef enum OMX_NALUFORMATSTYPE {
|
||||
OMX_NaluFormatStartCodes = 1,
|
||||
OMX_NaluFormatOneNaluPerBuffer = 2,
|
||||
OMX_NaluFormatOneByteInterleaveLength = 4,
|
||||
OMX_NaluFormatTwoByteInterleaveLength = 8,
|
||||
OMX_NaluFormatFourByteInterleaveLength = 16,
|
||||
OMX_NaluFormatCodingMax = 0x7FFFFFFF
|
||||
} OMX_NALUFORMATSTYPE;
|
||||
|
||||
/** NAL Stream Format */
|
||||
typedef struct OMX_NALSTREAMFORMATTYPE{
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_NALUFORMATSTYPE eNaluFormat;
|
||||
} OMX_NALSTREAMFORMATTYPE;
|
||||
|
||||
/** Enum for standard video codingtype extensions */
|
||||
typedef enum OMX_VIDEO_CODINGEXTTYPE {
|
||||
OMX_VIDEO_ExtCodingUnused = OMX_VIDEO_CodingKhronosExtensions,
|
||||
OMX_VIDEO_CodingVP8, /**< VP8/WebM */
|
||||
} OMX_VIDEO_CODINGEXTTYPE;
|
||||
|
||||
/** VP8 profiles */
|
||||
typedef enum OMX_VIDEO_VP8PROFILETYPE {
|
||||
OMX_VIDEO_VP8ProfileMain = 0x01,
|
||||
OMX_VIDEO_VP8ProfileUnknown = 0x6EFFFFFF,
|
||||
OMX_VIDEO_VP8ProfileMax = 0x7FFFFFFF
|
||||
} OMX_VIDEO_VP8PROFILETYPE;
|
||||
|
||||
/** VP8 levels */
|
||||
typedef enum OMX_VIDEO_VP8LEVELTYPE {
|
||||
OMX_VIDEO_VP8Level_Version0 = 0x01,
|
||||
OMX_VIDEO_VP8Level_Version1 = 0x02,
|
||||
OMX_VIDEO_VP8Level_Version2 = 0x04,
|
||||
OMX_VIDEO_VP8Level_Version3 = 0x08,
|
||||
OMX_VIDEO_VP8LevelUnknown = 0x6EFFFFFF,
|
||||
OMX_VIDEO_VP8LevelMax = 0x7FFFFFFF
|
||||
} OMX_VIDEO_VP8LEVELTYPE;
|
||||
|
||||
/** VP8 Param */
|
||||
typedef struct OMX_VIDEO_PARAM_VP8TYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_VIDEO_VP8PROFILETYPE eProfile;
|
||||
OMX_VIDEO_VP8LEVELTYPE eLevel;
|
||||
OMX_U32 nDCTPartitions;
|
||||
OMX_BOOL bErrorResilientMode;
|
||||
} OMX_VIDEO_PARAM_VP8TYPE;
|
||||
|
||||
/** Structure for configuring VP8 reference frames */
|
||||
typedef struct OMX_VIDEO_VP8REFERENCEFRAMETYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bPreviousFrameRefresh;
|
||||
OMX_BOOL bGoldenFrameRefresh;
|
||||
OMX_BOOL bAlternateFrameRefresh;
|
||||
OMX_BOOL bUsePreviousFrame;
|
||||
OMX_BOOL bUseGoldenFrame;
|
||||
OMX_BOOL bUseAlternateFrame;
|
||||
} OMX_VIDEO_VP8REFERENCEFRAMETYPE;
|
||||
|
||||
/** Structure for querying VP8 reference frame type */
|
||||
typedef struct OMX_VIDEO_VP8REFERENCEFRAMEINFOTYPE {
|
||||
OMX_U32 nSize;
|
||||
OMX_VERSIONTYPE nVersion;
|
||||
OMX_U32 nPortIndex;
|
||||
OMX_BOOL bIsIntraFrame;
|
||||
OMX_BOOL bIsGoldenOrAlternateFrame;
|
||||
} OMX_VIDEO_VP8REFERENCEFRAMEINFOTYPE;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OMX_VideoExt_h */
|
||||
/* File EOF */
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <utils/Errors.h>
|
||||
|
||||
#ifndef CRYPTO_API_H_
|
||||
|
||||
#define CRYPTO_API_H_
|
||||
|
||||
namespace android {
|
||||
|
||||
struct AString;
|
||||
struct CryptoPlugin;
|
||||
|
||||
struct CryptoFactory {
|
||||
CryptoFactory() {}
|
||||
virtual ~CryptoFactory() {}
|
||||
|
||||
virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) const = 0;
|
||||
|
||||
virtual status_t createPlugin(
|
||||
const uint8_t uuid[16], const void *data, size_t size,
|
||||
CryptoPlugin **plugin) = 0;
|
||||
|
||||
private:
|
||||
CryptoFactory(const CryptoFactory &);
|
||||
CryptoFactory &operator=(const CryptoFactory &);
|
||||
};
|
||||
|
||||
struct CryptoPlugin {
|
||||
enum Mode {
|
||||
kMode_Unencrypted = 0,
|
||||
kMode_AES_CTR = 1,
|
||||
|
||||
// Neither key nor iv are being used in this mode.
|
||||
// Each subsample is encrypted w/ an iv of all zeroes.
|
||||
kMode_AES_WV = 2, // FIX constant
|
||||
};
|
||||
|
||||
struct SubSample {
|
||||
size_t mNumBytesOfClearData;
|
||||
size_t mNumBytesOfEncryptedData;
|
||||
};
|
||||
|
||||
CryptoPlugin() {}
|
||||
virtual ~CryptoPlugin() {}
|
||||
|
||||
// If this method returns false, a non-secure decoder will be used to
|
||||
// decode the data after decryption. The decrypt API below will have
|
||||
// to support insecure decryption of the data (secure = false) for
|
||||
// media data of the given mime type.
|
||||
virtual bool requiresSecureDecoderComponent(const char *mime) const = 0;
|
||||
|
||||
// If the error returned falls into the range
|
||||
// ERROR_DRM_VENDOR_MIN..ERROR_DRM_VENDOR_MAX, errorDetailMsg should be
|
||||
// filled in with an appropriate string.
|
||||
// At the java level these special errors will then trigger a
|
||||
// MediaCodec.CryptoException that gives clients access to both
|
||||
// the error code and the errorDetailMsg.
|
||||
// Returns a non-negative result to indicate the number of bytes written
|
||||
// to the dstPtr, or a negative result to indicate an error.
|
||||
virtual ssize_t decrypt(
|
||||
bool secure,
|
||||
const uint8_t key[16],
|
||||
const uint8_t iv[16],
|
||||
Mode mode,
|
||||
const void *srcPtr,
|
||||
const SubSample *subSamples, size_t numSubSamples,
|
||||
void *dstPtr,
|
||||
AString *errorDetailMsg) = 0;
|
||||
|
||||
private:
|
||||
CryptoPlugin(const CryptoPlugin &);
|
||||
CryptoPlugin &operator=(const CryptoPlugin &);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
extern "C" {
|
||||
extern android::CryptoFactory *createCryptoFactory();
|
||||
}
|
||||
|
||||
#endif // CRYPTO_API_H_
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* Copyright 2012, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MEDIA_CODEC_H_
|
||||
|
||||
#define MEDIA_CODEC_H_
|
||||
|
||||
#include <gui/IGraphicBufferProducer.h>
|
||||
#include <media/hardware/CryptoAPI.h>
|
||||
#include <media/stagefright/foundation/AHandler.h>
|
||||
#include <utils/Vector.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct ABuffer;
|
||||
struct ACodec;
|
||||
struct AMessage;
|
||||
struct AString;
|
||||
struct ICrypto;
|
||||
struct SoftwareRenderer;
|
||||
struct Surface;
|
||||
|
||||
struct MediaCodec : public AHandler {
|
||||
enum ConfigureFlags {
|
||||
CONFIGURE_FLAG_ENCODE = 1,
|
||||
};
|
||||
|
||||
enum BufferFlags {
|
||||
BUFFER_FLAG_SYNCFRAME = 1,
|
||||
BUFFER_FLAG_CODECCONFIG = 2,
|
||||
BUFFER_FLAG_EOS = 4,
|
||||
};
|
||||
|
||||
static sp<MediaCodec> CreateByType(
|
||||
const sp<ALooper> &looper, const char *mime, bool encoder);
|
||||
|
||||
static sp<MediaCodec> CreateByComponentName(
|
||||
const sp<ALooper> &looper, const char *name);
|
||||
|
||||
status_t configure(
|
||||
const sp<AMessage> &format,
|
||||
const sp<Surface> &nativeWindow,
|
||||
const sp<ICrypto> &crypto,
|
||||
uint32_t flags);
|
||||
|
||||
status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
|
||||
|
||||
status_t start();
|
||||
|
||||
// Returns to a state in which the component remains allocated but
|
||||
// unconfigured.
|
||||
status_t stop();
|
||||
|
||||
// Client MUST call release before releasing final reference to this
|
||||
// object.
|
||||
status_t release();
|
||||
|
||||
status_t flush();
|
||||
|
||||
status_t queueInputBuffer(
|
||||
size_t index,
|
||||
size_t offset,
|
||||
size_t size,
|
||||
int64_t presentationTimeUs,
|
||||
uint32_t flags,
|
||||
AString *errorDetailMsg = NULL);
|
||||
|
||||
status_t queueSecureInputBuffer(
|
||||
size_t index,
|
||||
size_t offset,
|
||||
const CryptoPlugin::SubSample *subSamples,
|
||||
size_t numSubSamples,
|
||||
const uint8_t key[16],
|
||||
const uint8_t iv[16],
|
||||
CryptoPlugin::Mode mode,
|
||||
int64_t presentationTimeUs,
|
||||
uint32_t flags,
|
||||
AString *errorDetailMsg = NULL);
|
||||
|
||||
status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs = 0ll);
|
||||
|
||||
status_t dequeueOutputBuffer(
|
||||
size_t *index,
|
||||
size_t *offset,
|
||||
size_t *size,
|
||||
int64_t *presentationTimeUs,
|
||||
uint32_t *flags,
|
||||
int64_t timeoutUs = 0ll);
|
||||
|
||||
status_t renderOutputBufferAndRelease(size_t index);
|
||||
status_t releaseOutputBuffer(size_t index);
|
||||
|
||||
status_t signalEndOfInputStream();
|
||||
|
||||
status_t getOutputFormat(sp<AMessage> *format) const;
|
||||
|
||||
status_t getInputBuffers(Vector<sp<ABuffer> > *buffers) const;
|
||||
status_t getOutputBuffers(Vector<sp<ABuffer> > *buffers) const;
|
||||
|
||||
status_t requestIDRFrame();
|
||||
|
||||
// Notification will be posted once there "is something to do", i.e.
|
||||
// an input/output buffer has become available, a format change is
|
||||
// pending, an error is pending.
|
||||
void requestActivityNotification(const sp<AMessage> ¬ify);
|
||||
|
||||
status_t getName(AString *componentName) const;
|
||||
|
||||
status_t setParameters(const sp<AMessage> ¶ms);
|
||||
|
||||
protected:
|
||||
virtual ~MediaCodec();
|
||||
virtual void onMessageReceived(const sp<AMessage> &msg);
|
||||
|
||||
private:
|
||||
enum State {
|
||||
UNINITIALIZED,
|
||||
INITIALIZING,
|
||||
INITIALIZED,
|
||||
CONFIGURING,
|
||||
CONFIGURED,
|
||||
STARTING,
|
||||
STARTED,
|
||||
FLUSHING,
|
||||
STOPPING,
|
||||
RELEASING,
|
||||
};
|
||||
|
||||
enum {
|
||||
kPortIndexInput = 0,
|
||||
kPortIndexOutput = 1,
|
||||
};
|
||||
|
||||
enum {
|
||||
kWhatInit = 'init',
|
||||
kWhatConfigure = 'conf',
|
||||
kWhatCreateInputSurface = 'cisf',
|
||||
kWhatStart = 'strt',
|
||||
kWhatStop = 'stop',
|
||||
kWhatRelease = 'rele',
|
||||
kWhatDequeueInputBuffer = 'deqI',
|
||||
kWhatQueueInputBuffer = 'queI',
|
||||
kWhatDequeueOutputBuffer = 'deqO',
|
||||
kWhatReleaseOutputBuffer = 'relO',
|
||||
kWhatSignalEndOfInputStream = 'eois',
|
||||
kWhatGetBuffers = 'getB',
|
||||
kWhatFlush = 'flus',
|
||||
kWhatGetOutputFormat = 'getO',
|
||||
kWhatDequeueInputTimedOut = 'dITO',
|
||||
kWhatDequeueOutputTimedOut = 'dOTO',
|
||||
kWhatCodecNotify = 'codc',
|
||||
kWhatRequestIDRFrame = 'ridr',
|
||||
kWhatRequestActivityNotification = 'racN',
|
||||
kWhatGetName = 'getN',
|
||||
kWhatSetParameters = 'setP',
|
||||
};
|
||||
|
||||
enum {
|
||||
kFlagIsSoftwareCodec = 1,
|
||||
kFlagOutputFormatChanged = 2,
|
||||
kFlagOutputBuffersChanged = 4,
|
||||
kFlagStickyError = 8,
|
||||
kFlagDequeueInputPending = 16,
|
||||
kFlagDequeueOutputPending = 32,
|
||||
kFlagIsSecure = 64,
|
||||
kFlagSawMediaServerDie = 128,
|
||||
kFlagIsEncoder = 256,
|
||||
kFlagGatherCodecSpecificData = 512,
|
||||
};
|
||||
|
||||
struct BufferInfo {
|
||||
void *mBufferID;
|
||||
sp<ABuffer> mData;
|
||||
sp<ABuffer> mEncryptedData;
|
||||
sp<AMessage> mNotify;
|
||||
bool mOwnedByClient;
|
||||
};
|
||||
|
||||
State mState;
|
||||
sp<ALooper> mLooper;
|
||||
sp<ALooper> mCodecLooper;
|
||||
sp<ACodec> mCodec;
|
||||
AString mComponentName;
|
||||
uint32_t mReplyID;
|
||||
uint32_t mFlags;
|
||||
sp<Surface> mNativeWindow;
|
||||
SoftwareRenderer *mSoftRenderer;
|
||||
sp<AMessage> mOutputFormat;
|
||||
|
||||
List<size_t> mAvailPortBuffers[2];
|
||||
Vector<BufferInfo> mPortBuffers[2];
|
||||
|
||||
int32_t mDequeueInputTimeoutGeneration;
|
||||
uint32_t mDequeueInputReplyID;
|
||||
|
||||
int32_t mDequeueOutputTimeoutGeneration;
|
||||
uint32_t mDequeueOutputReplyID;
|
||||
|
||||
sp<ICrypto> mCrypto;
|
||||
|
||||
List<sp<ABuffer> > mCSD;
|
||||
|
||||
sp<AMessage> mActivityNotify;
|
||||
|
||||
bool mHaveInputSurface;
|
||||
|
||||
MediaCodec(const sp<ALooper> &looper);
|
||||
|
||||
static status_t PostAndAwaitResponse(
|
||||
const sp<AMessage> &msg, sp<AMessage> *response);
|
||||
|
||||
status_t init(const char *name, bool nameIsType, bool encoder);
|
||||
|
||||
void setState(State newState);
|
||||
void returnBuffersToCodec();
|
||||
void returnBuffersToCodecOnPort(int32_t portIndex);
|
||||
size_t updateBuffers(int32_t portIndex, const sp<AMessage> &msg);
|
||||
status_t onQueueInputBuffer(const sp<AMessage> &msg);
|
||||
status_t onReleaseOutputBuffer(const sp<AMessage> &msg);
|
||||
ssize_t dequeuePortBuffer(int32_t portIndex);
|
||||
|
||||
bool handleDequeueInputBuffer(uint32_t replyID, bool newRequest = false);
|
||||
bool handleDequeueOutputBuffer(uint32_t replyID, bool newRequest = false);
|
||||
void cancelPendingDequeueOperations();
|
||||
|
||||
void extractCSD(const sp<AMessage> &format);
|
||||
status_t queueCSDInputBuffer(size_t bufferIndex);
|
||||
|
||||
status_t setNativeWindow(
|
||||
const sp<Surface> &surface);
|
||||
|
||||
void postActivityNotificationIfPossible();
|
||||
|
||||
status_t onSetParameters(const sp<AMessage> ¶ms);
|
||||
|
||||
status_t amendOutputFormatWithCodecSpecificData(const sp<ABuffer> &buffer);
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(MediaCodec);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // MEDIA_CODEC_H_
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MEDIA_DEFS_H_
|
||||
|
||||
#define MEDIA_DEFS_H_
|
||||
|
||||
namespace android {
|
||||
|
||||
extern const char *MEDIA_MIMETYPE_IMAGE_JPEG;
|
||||
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_VP8;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_VP9;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_AVC;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_HEVC;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_MPEG4;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_H263;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_MPEG2;
|
||||
extern const char *MEDIA_MIMETYPE_VIDEO_RAW;
|
||||
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_AMR_NB;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_AMR_WB;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_MPEG; // layer III
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_I;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_AAC;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_QCELP;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_VORBIS;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_G711_ALAW;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_G711_MLAW;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_RAW;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_FLAC;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_AAC_ADTS;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_MSGSM;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_ALAC;
|
||||
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG4;
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_WAV;
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_OGG;
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_MATROSKA;
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG2TS;
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_AVI;
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_MPEG2PS;
|
||||
|
||||
extern const char *MEDIA_MIMETYPE_CONTAINER_WVM;
|
||||
|
||||
extern const char *MEDIA_MIMETYPE_TEXT_3GPP;
|
||||
extern const char *MEDIA_MIMETYPE_TEXT_SUBRIP;
|
||||
#ifdef USE_INTEL_MDP
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_AAC_EXTENDED;
|
||||
#endif
|
||||
|
||||
#ifdef DOLBY_UDC
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_AC3;
|
||||
extern const char *MEDIA_MIMETYPE_AUDIO_EC3;
|
||||
#endif // DOLBY_UDC
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // MEDIA_DEFS_H_
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MEDIA_ERRORS_H_
|
||||
|
||||
#define MEDIA_ERRORS_H_
|
||||
|
||||
#include <utils/Errors.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
enum {
|
||||
MEDIA_ERROR_BASE = -1000,
|
||||
|
||||
ERROR_ALREADY_CONNECTED = MEDIA_ERROR_BASE,
|
||||
ERROR_NOT_CONNECTED = MEDIA_ERROR_BASE - 1,
|
||||
ERROR_UNKNOWN_HOST = MEDIA_ERROR_BASE - 2,
|
||||
ERROR_CANNOT_CONNECT = MEDIA_ERROR_BASE - 3,
|
||||
ERROR_IO = MEDIA_ERROR_BASE - 4,
|
||||
ERROR_CONNECTION_LOST = MEDIA_ERROR_BASE - 5,
|
||||
ERROR_MALFORMED = MEDIA_ERROR_BASE - 7,
|
||||
ERROR_OUT_OF_RANGE = MEDIA_ERROR_BASE - 8,
|
||||
ERROR_BUFFER_TOO_SMALL = MEDIA_ERROR_BASE - 9,
|
||||
ERROR_UNSUPPORTED = MEDIA_ERROR_BASE - 10,
|
||||
ERROR_END_OF_STREAM = MEDIA_ERROR_BASE - 11,
|
||||
|
||||
// Not technically an error.
|
||||
INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12,
|
||||
INFO_DISCONTINUITY = MEDIA_ERROR_BASE - 13,
|
||||
INFO_OUTPUT_BUFFERS_CHANGED = MEDIA_ERROR_BASE - 14,
|
||||
|
||||
// The following constant values should be in sync with
|
||||
// drm/drm_framework_common.h
|
||||
DRM_ERROR_BASE = -2000,
|
||||
|
||||
ERROR_DRM_UNKNOWN = DRM_ERROR_BASE,
|
||||
ERROR_DRM_NO_LICENSE = DRM_ERROR_BASE - 1,
|
||||
ERROR_DRM_LICENSE_EXPIRED = DRM_ERROR_BASE - 2,
|
||||
ERROR_DRM_SESSION_NOT_OPENED = DRM_ERROR_BASE - 3,
|
||||
ERROR_DRM_DECRYPT_UNIT_NOT_INITIALIZED = DRM_ERROR_BASE - 4,
|
||||
ERROR_DRM_DECRYPT = DRM_ERROR_BASE - 5,
|
||||
ERROR_DRM_CANNOT_HANDLE = DRM_ERROR_BASE - 6,
|
||||
ERROR_DRM_TAMPER_DETECTED = DRM_ERROR_BASE - 7,
|
||||
ERROR_DRM_NOT_PROVISIONED = DRM_ERROR_BASE - 8,
|
||||
ERROR_DRM_DEVICE_REVOKED = DRM_ERROR_BASE - 9,
|
||||
ERROR_DRM_RESOURCE_BUSY = DRM_ERROR_BASE - 10,
|
||||
|
||||
ERROR_DRM_VENDOR_MAX = DRM_ERROR_BASE - 500,
|
||||
ERROR_DRM_VENDOR_MIN = DRM_ERROR_BASE - 999,
|
||||
|
||||
// Deprecated
|
||||
ERROR_DRM_WV_VENDOR_MAX = ERROR_DRM_VENDOR_MAX,
|
||||
ERROR_DRM_WV_VENDOR_MIN = ERROR_DRM_VENDOR_MIN,
|
||||
|
||||
// Heartbeat Error Codes
|
||||
HEARTBEAT_ERROR_BASE = -3000,
|
||||
ERROR_HEARTBEAT_TERMINATE_REQUESTED = HEARTBEAT_ERROR_BASE,
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // MEDIA_ERRORS_H_
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef A_BASE_H_
|
||||
|
||||
#define A_BASE_H_
|
||||
|
||||
#define DISALLOW_EVIL_CONSTRUCTORS(name) \
|
||||
name(const name &); \
|
||||
name &operator=(const name &)
|
||||
|
||||
#endif // A_BASE_H_
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef A_BUFFER_H_
|
||||
|
||||
#define A_BUFFER_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <media/stagefright/foundation/ABase.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct AMessage;
|
||||
|
||||
struct ABuffer : public RefBase {
|
||||
ABuffer(size_t capacity);
|
||||
ABuffer(void *data, size_t capacity);
|
||||
|
||||
void setFarewellMessage(const sp<AMessage> msg);
|
||||
|
||||
uint8_t *base() { return (uint8_t *)mData; }
|
||||
uint8_t *data() { return (uint8_t *)mData + mRangeOffset; }
|
||||
size_t capacity() const { return mCapacity; }
|
||||
size_t size() const { return mRangeLength; }
|
||||
size_t offset() const { return mRangeOffset; }
|
||||
|
||||
void setRange(size_t offset, size_t size);
|
||||
|
||||
void setInt32Data(int32_t data) { mInt32Data = data; }
|
||||
int32_t int32Data() const { return mInt32Data; }
|
||||
|
||||
sp<AMessage> meta();
|
||||
|
||||
protected:
|
||||
virtual ~ABuffer();
|
||||
|
||||
private:
|
||||
sp<AMessage> mFarewell;
|
||||
sp<AMessage> mMeta;
|
||||
|
||||
void *mData;
|
||||
size_t mCapacity;
|
||||
size_t mRangeOffset;
|
||||
size_t mRangeLength;
|
||||
|
||||
int32_t mInt32Data;
|
||||
|
||||
bool mOwnsData;
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(ABuffer);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // A_BUFFER_H_
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef A_HANDLER_H_
|
||||
|
||||
#define A_HANDLER_H_
|
||||
|
||||
#include <media/stagefright/foundation/ALooper.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct AMessage;
|
||||
|
||||
struct AHandler : public RefBase {
|
||||
AHandler()
|
||||
: mID(0) {
|
||||
}
|
||||
|
||||
ALooper::handler_id id() const {
|
||||
return mID;
|
||||
}
|
||||
|
||||
sp<ALooper> looper();
|
||||
|
||||
protected:
|
||||
virtual void onMessageReceived(const sp<AMessage> &msg) = 0;
|
||||
|
||||
private:
|
||||
friend struct ALooperRoster;
|
||||
|
||||
ALooper::handler_id mID;
|
||||
|
||||
void setID(ALooper::handler_id id) {
|
||||
mID = id;
|
||||
}
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(AHandler);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // A_HANDLER_H_
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef A_LOOPER_H_
|
||||
|
||||
#define A_LOOPER_H_
|
||||
|
||||
#include <media/stagefright/foundation/ABase.h>
|
||||
#include <media/stagefright/foundation/AString.h>
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/KeyedVector.h>
|
||||
#include <utils/List.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct AHandler;
|
||||
struct AMessage;
|
||||
|
||||
struct ALooper : public RefBase {
|
||||
typedef int32_t event_id;
|
||||
typedef int32_t handler_id;
|
||||
|
||||
ALooper();
|
||||
|
||||
// Takes effect in a subsequent call to start().
|
||||
void setName(const char *name);
|
||||
|
||||
handler_id registerHandler(const sp<AHandler> &handler);
|
||||
void unregisterHandler(handler_id handlerID);
|
||||
|
||||
status_t start(
|
||||
bool runOnCallingThread = false,
|
||||
bool canCallJava = false,
|
||||
int32_t priority = PRIORITY_DEFAULT
|
||||
);
|
||||
|
||||
status_t stop();
|
||||
|
||||
static int64_t GetNowUs();
|
||||
|
||||
protected:
|
||||
virtual ~ALooper();
|
||||
|
||||
private:
|
||||
friend struct ALooperRoster;
|
||||
|
||||
struct Event {
|
||||
int64_t mWhenUs;
|
||||
sp<AMessage> mMessage;
|
||||
};
|
||||
|
||||
Mutex mLock;
|
||||
Condition mQueueChangedCondition;
|
||||
|
||||
AString mName;
|
||||
|
||||
List<Event> mEventQueue;
|
||||
|
||||
struct LooperThread;
|
||||
sp<LooperThread> mThread;
|
||||
bool mRunningLocally;
|
||||
|
||||
void post(const sp<AMessage> &msg, int64_t delayUs);
|
||||
bool loop();
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(ALooper);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // A_LOOPER_H_
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef A_MESSAGE_H_
|
||||
|
||||
#define A_MESSAGE_H_
|
||||
|
||||
#include <media/stagefright/foundation/ABase.h>
|
||||
#include <media/stagefright/foundation/ALooper.h>
|
||||
#include <utils/KeyedVector.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct ABuffer;
|
||||
struct AString;
|
||||
struct Parcel;
|
||||
|
||||
struct AMessage : public RefBase {
|
||||
AMessage(uint32_t what = 0, ALooper::handler_id target = 0);
|
||||
|
||||
static sp<AMessage> FromParcel(const Parcel &parcel);
|
||||
void writeToParcel(Parcel *parcel) const;
|
||||
|
||||
void setWhat(uint32_t what);
|
||||
uint32_t what() const;
|
||||
|
||||
void setTarget(ALooper::handler_id target);
|
||||
ALooper::handler_id target() const;
|
||||
|
||||
void clear();
|
||||
|
||||
void setInt32(const char *name, int32_t value);
|
||||
void setInt64(const char *name, int64_t value);
|
||||
void setSize(const char *name, size_t value);
|
||||
void setFloat(const char *name, float value);
|
||||
void setDouble(const char *name, double value);
|
||||
void setPointer(const char *name, void *value);
|
||||
void setString(const char *name, const char *s, int len = -1);
|
||||
void setObject(const char *name, const sp<RefBase> &obj);
|
||||
void setBuffer(const char *name, const sp<ABuffer> &buffer);
|
||||
void setMessage(const char *name, const sp<AMessage> &obj);
|
||||
|
||||
void setRect(
|
||||
const char *name,
|
||||
int32_t left, int32_t top, int32_t right, int32_t bottom);
|
||||
|
||||
bool findInt32(const char *name, int32_t *value) const;
|
||||
bool findInt64(const char *name, int64_t *value) const;
|
||||
bool findSize(const char *name, size_t *value) const;
|
||||
bool findFloat(const char *name, float *value) const;
|
||||
bool findDouble(const char *name, double *value) const;
|
||||
bool findPointer(const char *name, void **value) const;
|
||||
bool findString(const char *name, AString *value) const;
|
||||
bool findObject(const char *name, sp<RefBase> *obj) const;
|
||||
bool findBuffer(const char *name, sp<ABuffer> *buffer) const;
|
||||
bool findMessage(const char *name, sp<AMessage> *obj) const;
|
||||
|
||||
bool findRect(
|
||||
const char *name,
|
||||
int32_t *left, int32_t *top, int32_t *right, int32_t *bottom) const;
|
||||
|
||||
void post(int64_t delayUs = 0);
|
||||
|
||||
// Posts the message to its target and waits for a response (or error)
|
||||
// before returning.
|
||||
status_t postAndAwaitResponse(sp<AMessage> *response);
|
||||
|
||||
// If this returns true, the sender of this message is synchronously
|
||||
// awaiting a response, the "replyID" can be used to send the response
|
||||
// via "postReply" below.
|
||||
bool senderAwaitsResponse(uint32_t *replyID) const;
|
||||
|
||||
void postReply(uint32_t replyID);
|
||||
|
||||
// Performs a deep-copy of "this", contained messages are in turn "dup'ed".
|
||||
// Warning: RefBase items, i.e. "objects" are _not_ copied but only have
|
||||
// their refcount incremented.
|
||||
sp<AMessage> dup() const;
|
||||
|
||||
AString debugString(int32_t indent = 0) const;
|
||||
|
||||
enum Type {
|
||||
kTypeInt32,
|
||||
kTypeInt64,
|
||||
kTypeSize,
|
||||
kTypeFloat,
|
||||
kTypeDouble,
|
||||
kTypePointer,
|
||||
kTypeString,
|
||||
kTypeObject,
|
||||
kTypeMessage,
|
||||
kTypeRect,
|
||||
kTypeBuffer,
|
||||
};
|
||||
|
||||
size_t countEntries() const;
|
||||
const char *getEntryNameAt(size_t index, Type *type) const;
|
||||
|
||||
protected:
|
||||
virtual ~AMessage();
|
||||
|
||||
private:
|
||||
uint32_t mWhat;
|
||||
ALooper::handler_id mTarget;
|
||||
|
||||
struct Rect {
|
||||
int32_t mLeft, mTop, mRight, mBottom;
|
||||
};
|
||||
|
||||
struct Item {
|
||||
union {
|
||||
int32_t int32Value;
|
||||
int64_t int64Value;
|
||||
size_t sizeValue;
|
||||
float floatValue;
|
||||
double doubleValue;
|
||||
void *ptrValue;
|
||||
RefBase *refValue;
|
||||
AString *stringValue;
|
||||
Rect rectValue;
|
||||
} u;
|
||||
const char *mName;
|
||||
Type mType;
|
||||
};
|
||||
|
||||
enum {
|
||||
kMaxNumItems = 64
|
||||
};
|
||||
Item mItems[kMaxNumItems];
|
||||
size_t mNumItems;
|
||||
|
||||
Item *allocateItem(const char *name);
|
||||
void freeItem(Item *item);
|
||||
const Item *findItem(const char *name, Type type) const;
|
||||
|
||||
void setObjectInternal(
|
||||
const char *name, const sp<RefBase> &obj, Type type);
|
||||
|
||||
DISALLOW_EVIL_CONSTRUCTORS(AMessage);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // A_MESSAGE_H_
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef A_STRING_H_
|
||||
|
||||
#define A_STRING_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct AString {
|
||||
AString();
|
||||
AString(const char *s);
|
||||
AString(const char *s, size_t size);
|
||||
AString(const AString &from);
|
||||
AString(const AString &from, size_t offset, size_t n);
|
||||
~AString();
|
||||
|
||||
AString &operator=(const AString &from);
|
||||
void setTo(const char *s);
|
||||
void setTo(const char *s, size_t size);
|
||||
void setTo(const AString &from, size_t offset, size_t n);
|
||||
|
||||
size_t size() const;
|
||||
const char *c_str() const;
|
||||
|
||||
bool empty() const;
|
||||
|
||||
void clear();
|
||||
void trim();
|
||||
void erase(size_t start, size_t n);
|
||||
|
||||
void append(char c) { append(&c, 1); }
|
||||
void append(const char *s);
|
||||
void append(const char *s, size_t size);
|
||||
void append(const AString &from);
|
||||
void append(const AString &from, size_t offset, size_t n);
|
||||
void append(int x);
|
||||
void append(unsigned x);
|
||||
void append(long x);
|
||||
void append(unsigned long x);
|
||||
void append(long long x);
|
||||
void append(unsigned long long x);
|
||||
void append(float x);
|
||||
void append(double x);
|
||||
void append(void *x);
|
||||
|
||||
void insert(const AString &from, size_t insertionPos);
|
||||
void insert(const char *from, size_t size, size_t insertionPos);
|
||||
|
||||
ssize_t find(const char *substring, size_t start = 0) const;
|
||||
|
||||
size_t hash() const;
|
||||
|
||||
bool operator==(const AString &other) const;
|
||||
bool operator<(const AString &other) const;
|
||||
bool operator>(const AString &other) const;
|
||||
|
||||
int compare(const AString &other) const;
|
||||
|
||||
bool startsWith(const char *prefix) const;
|
||||
bool endsWith(const char *suffix) const;
|
||||
|
||||
void tolower();
|
||||
|
||||
private:
|
||||
static const char *kEmptyString;
|
||||
|
||||
char *mData;
|
||||
size_t mSize;
|
||||
size_t mAllocSize;
|
||||
|
||||
void makeMutable();
|
||||
};
|
||||
|
||||
AString StringPrintf(const char *format, ...);
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // A_STRING_H_
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_PIXELFLINGER_FORMAT_H
|
||||
#define ANDROID_PIXELFLINGER_FORMAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
enum GGLPixelFormat {
|
||||
// these constants need to match those
|
||||
// in graphics/PixelFormat.java, ui/PixelFormat.h, BlitHardware.h
|
||||
GGL_PIXEL_FORMAT_UNKNOWN = 0,
|
||||
GGL_PIXEL_FORMAT_NONE = 0,
|
||||
|
||||
GGL_PIXEL_FORMAT_RGBA_8888 = 1, // 4x8-bit ARGB
|
||||
GGL_PIXEL_FORMAT_RGBX_8888 = 2, // 3x8-bit RGB stored in 32-bit chunks
|
||||
GGL_PIXEL_FORMAT_RGB_888 = 3, // 3x8-bit RGB
|
||||
GGL_PIXEL_FORMAT_RGB_565 = 4, // 16-bit RGB
|
||||
GGL_PIXEL_FORMAT_BGRA_8888 = 5, // 4x8-bit BGRA
|
||||
GGL_PIXEL_FORMAT_RGBA_5551 = 6, // 16-bit RGBA
|
||||
GGL_PIXEL_FORMAT_RGBA_4444 = 7, // 16-bit RGBA
|
||||
|
||||
GGL_PIXEL_FORMAT_A_8 = 8, // 8-bit A
|
||||
GGL_PIXEL_FORMAT_L_8 = 9, // 8-bit L (R=G=B = L)
|
||||
GGL_PIXEL_FORMAT_LA_88 = 0xA, // 16-bit LA
|
||||
GGL_PIXEL_FORMAT_RGB_332 = 0xB, // 8-bit RGB (non paletted)
|
||||
|
||||
// reserved range. don't use.
|
||||
GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
|
||||
GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
|
||||
GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
|
||||
GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
|
||||
GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
|
||||
GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
|
||||
GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
|
||||
GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,
|
||||
|
||||
// reserved/special formats
|
||||
GGL_PIXEL_FORMAT_Z_16 = 0x18,
|
||||
GGL_PIXEL_FORMAT_S_8 = 0x19,
|
||||
GGL_PIXEL_FORMAT_SZ_24 = 0x1A,
|
||||
GGL_PIXEL_FORMAT_SZ_8 = 0x1B,
|
||||
|
||||
// reserved range. don't use.
|
||||
GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
|
||||
GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,
|
||||
};
|
||||
|
||||
enum GGLFormatComponents {
|
||||
GGL_STENCIL_INDEX = 0x1901,
|
||||
GGL_DEPTH_COMPONENT = 0x1902,
|
||||
GGL_ALPHA = 0x1906,
|
||||
GGL_RGB = 0x1907,
|
||||
GGL_RGBA = 0x1908,
|
||||
GGL_LUMINANCE = 0x1909,
|
||||
GGL_LUMINANCE_ALPHA = 0x190A,
|
||||
};
|
||||
|
||||
enum GGLFormatComponentIndex {
|
||||
GGL_INDEX_ALPHA = 0,
|
||||
GGL_INDEX_RED = 1,
|
||||
GGL_INDEX_GREEN = 2,
|
||||
GGL_INDEX_BLUE = 3,
|
||||
GGL_INDEX_STENCIL = 0,
|
||||
GGL_INDEX_DEPTH = 1,
|
||||
GGL_INDEX_Y = 0,
|
||||
GGL_INDEX_CB = 1,
|
||||
GGL_INDEX_CR = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
#ifdef __cplusplus
|
||||
enum {
|
||||
ALPHA = GGL_INDEX_ALPHA,
|
||||
RED = GGL_INDEX_RED,
|
||||
GREEN = GGL_INDEX_GREEN,
|
||||
BLUE = GGL_INDEX_BLUE,
|
||||
STENCIL = GGL_INDEX_STENCIL,
|
||||
DEPTH = GGL_INDEX_DEPTH,
|
||||
LUMA = GGL_INDEX_Y,
|
||||
CHROMAB = GGL_INDEX_CB,
|
||||
CHROMAR = GGL_INDEX_CR,
|
||||
};
|
||||
inline uint32_t mask(int i) const {
|
||||
return ((1<<(c[i].h-c[i].l))-1)<<c[i].l;
|
||||
}
|
||||
inline uint32_t bits(int i) const {
|
||||
return c[i].h - c[i].l;
|
||||
}
|
||||
#endif
|
||||
uint8_t size; // bytes per pixel
|
||||
uint8_t bitsPerPixel;
|
||||
union {
|
||||
struct {
|
||||
uint8_t ah; // alpha high bit position + 1
|
||||
uint8_t al; // alpha low bit position
|
||||
uint8_t rh; // red high bit position + 1
|
||||
uint8_t rl; // red low bit position
|
||||
uint8_t gh; // green high bit position + 1
|
||||
uint8_t gl; // green low bit position
|
||||
uint8_t bh; // blue high bit position + 1
|
||||
uint8_t bl; // blue low bit position
|
||||
};
|
||||
struct {
|
||||
uint8_t h;
|
||||
uint8_t l;
|
||||
} __attribute__((__packed__)) c[4];
|
||||
} __attribute__((__packed__));
|
||||
uint16_t components; // GGLFormatComponents
|
||||
} GGLFormat;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" const GGLFormat* gglGetPixelFormatTable(size_t* numEntries = 0);
|
||||
#else
|
||||
const GGLFormat* gglGetPixelFormatTable(size_t* numEntries);
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_PIXELFLINGER_FORMAT_H
|
|
@ -0,0 +1,330 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_PIXELFLINGER_H
|
||||
#define ANDROID_PIXELFLINGER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <pixelflinger/format.h>
|
||||
|
||||
// GGL types
|
||||
|
||||
typedef int8_t GGLbyte; // b
|
||||
typedef int16_t GGLshort; // s
|
||||
typedef int32_t GGLint; // i
|
||||
typedef ssize_t GGLsizei; // i
|
||||
typedef int32_t GGLfixed; // x
|
||||
typedef int32_t GGLclampx; // x
|
||||
typedef float GGLfloat; // f
|
||||
typedef float GGLclampf; // f
|
||||
typedef double GGLdouble; // d
|
||||
typedef double GGLclampd; // d
|
||||
typedef uint8_t GGLubyte; // ub
|
||||
typedef uint8_t GGLboolean; // ub
|
||||
typedef uint16_t GGLushort; // us
|
||||
typedef uint32_t GGLuint; // ui
|
||||
typedef unsigned int GGLenum; // ui
|
||||
typedef unsigned int GGLbitfield; // ui
|
||||
typedef void GGLvoid;
|
||||
typedef int32_t GGLfixed32;
|
||||
typedef int32_t GGLcolor;
|
||||
typedef int32_t GGLcoord;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define GGL_MAX_VIEWPORT_DIMS 4096
|
||||
#define GGL_MAX_TEXTURE_SIZE 4096
|
||||
#define GGL_MAX_ALIASED_POINT_SIZE 0x7FFFFFF
|
||||
#define GGL_MAX_SMOOTH_POINT_SIZE 2048
|
||||
#define GGL_MAX_SMOOTH_LINE_WIDTH 2048
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// All these names are compatible with their OpenGL equivalents
|
||||
// some of them are listed only for completeness
|
||||
enum GGLNames {
|
||||
GGL_FALSE = 0,
|
||||
GGL_TRUE = 1,
|
||||
|
||||
// enable/disable
|
||||
GGL_SCISSOR_TEST = 0x0C11,
|
||||
GGL_TEXTURE_2D = 0x0DE1,
|
||||
GGL_ALPHA_TEST = 0x0BC0,
|
||||
GGL_BLEND = 0x0BE2,
|
||||
GGL_COLOR_LOGIC_OP = 0x0BF2,
|
||||
GGL_DITHER = 0x0BD0,
|
||||
GGL_STENCIL_TEST = 0x0B90,
|
||||
GGL_DEPTH_TEST = 0x0B71,
|
||||
GGL_AA = 0x80000001,
|
||||
GGL_W_LERP = 0x80000004,
|
||||
GGL_POINT_SMOOTH_NICE = 0x80000005,
|
||||
|
||||
// buffers, pixel drawing/reading
|
||||
GGL_COLOR = 0x1800,
|
||||
|
||||
// fog
|
||||
GGL_FOG = 0x0B60,
|
||||
|
||||
// shade model
|
||||
GGL_FLAT = 0x1D00,
|
||||
GGL_SMOOTH = 0x1D01,
|
||||
|
||||
// Texture parameter name
|
||||
GGL_TEXTURE_MIN_FILTER = 0x2801,
|
||||
GGL_TEXTURE_MAG_FILTER = 0x2800,
|
||||
GGL_TEXTURE_WRAP_S = 0x2802,
|
||||
GGL_TEXTURE_WRAP_T = 0x2803,
|
||||
GGL_TEXTURE_WRAP_R = 0x2804,
|
||||
|
||||
// Texture Filter
|
||||
GGL_NEAREST = 0x2600,
|
||||
GGL_LINEAR = 0x2601,
|
||||
GGL_NEAREST_MIPMAP_NEAREST = 0x2700,
|
||||
GGL_LINEAR_MIPMAP_NEAREST = 0x2701,
|
||||
GGL_NEAREST_MIPMAP_LINEAR = 0x2702,
|
||||
GGL_LINEAR_MIPMAP_LINEAR = 0x2703,
|
||||
|
||||
// Texture Wrap Mode
|
||||
GGL_CLAMP = 0x2900,
|
||||
GGL_REPEAT = 0x2901,
|
||||
GGL_CLAMP_TO_EDGE = 0x812F,
|
||||
|
||||
// Texture Env Mode
|
||||
GGL_REPLACE = 0x1E01,
|
||||
GGL_MODULATE = 0x2100,
|
||||
GGL_DECAL = 0x2101,
|
||||
GGL_ADD = 0x0104,
|
||||
|
||||
// Texture Env Parameter
|
||||
GGL_TEXTURE_ENV_MODE = 0x2200,
|
||||
GGL_TEXTURE_ENV_COLOR = 0x2201,
|
||||
|
||||
// Texture Env Target
|
||||
GGL_TEXTURE_ENV = 0x2300,
|
||||
|
||||
// Texture coord generation
|
||||
GGL_TEXTURE_GEN_MODE = 0x2500,
|
||||
GGL_S = 0x2000,
|
||||
GGL_T = 0x2001,
|
||||
GGL_R = 0x2002,
|
||||
GGL_Q = 0x2003,
|
||||
GGL_ONE_TO_ONE = 0x80000002,
|
||||
GGL_AUTOMATIC = 0x80000003,
|
||||
|
||||
// AlphaFunction
|
||||
GGL_NEVER = 0x0200,
|
||||
GGL_LESS = 0x0201,
|
||||
GGL_EQUAL = 0x0202,
|
||||
GGL_LEQUAL = 0x0203,
|
||||
GGL_GREATER = 0x0204,
|
||||
GGL_NOTEQUAL = 0x0205,
|
||||
GGL_GEQUAL = 0x0206,
|
||||
GGL_ALWAYS = 0x0207,
|
||||
|
||||
// LogicOp
|
||||
GGL_CLEAR = 0x1500, // 0
|
||||
GGL_AND = 0x1501, // s & d
|
||||
GGL_AND_REVERSE = 0x1502, // s & ~d
|
||||
GGL_COPY = 0x1503, // s
|
||||
GGL_AND_INVERTED = 0x1504, // ~s & d
|
||||
GGL_NOOP = 0x1505, // d
|
||||
GGL_XOR = 0x1506, // s ^ d
|
||||
GGL_OR = 0x1507, // s | d
|
||||
GGL_NOR = 0x1508, // ~(s | d)
|
||||
GGL_EQUIV = 0x1509, // ~(s ^ d)
|
||||
GGL_INVERT = 0x150A, // ~d
|
||||
GGL_OR_REVERSE = 0x150B, // s | ~d
|
||||
GGL_COPY_INVERTED = 0x150C, // ~s
|
||||
GGL_OR_INVERTED = 0x150D, // ~s | d
|
||||
GGL_NAND = 0x150E, // ~(s & d)
|
||||
GGL_SET = 0x150F, // 1
|
||||
|
||||
// blending equation & function
|
||||
GGL_ZERO = 0, // SD
|
||||
GGL_ONE = 1, // SD
|
||||
GGL_SRC_COLOR = 0x0300, // D
|
||||
GGL_ONE_MINUS_SRC_COLOR = 0x0301, // D
|
||||
GGL_SRC_ALPHA = 0x0302, // SD
|
||||
GGL_ONE_MINUS_SRC_ALPHA = 0x0303, // SD
|
||||
GGL_DST_ALPHA = 0x0304, // SD
|
||||
GGL_ONE_MINUS_DST_ALPHA = 0x0305, // SD
|
||||
GGL_DST_COLOR = 0x0306, // S
|
||||
GGL_ONE_MINUS_DST_COLOR = 0x0307, // S
|
||||
GGL_SRC_ALPHA_SATURATE = 0x0308, // S
|
||||
|
||||
// clear bits
|
||||
GGL_DEPTH_BUFFER_BIT = 0x00000100,
|
||||
GGL_STENCIL_BUFFER_BIT = 0x00000400,
|
||||
GGL_COLOR_BUFFER_BIT = 0x00004000,
|
||||
|
||||
// errors
|
||||
GGL_NO_ERROR = 0,
|
||||
GGL_INVALID_ENUM = 0x0500,
|
||||
GGL_INVALID_VALUE = 0x0501,
|
||||
GGL_INVALID_OPERATION = 0x0502,
|
||||
GGL_STACK_OVERFLOW = 0x0503,
|
||||
GGL_STACK_UNDERFLOW = 0x0504,
|
||||
GGL_OUT_OF_MEMORY = 0x0505
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef struct {
|
||||
GGLsizei version; // always set to sizeof(GGLSurface)
|
||||
GGLuint width; // width in pixels
|
||||
GGLuint height; // height in pixels
|
||||
GGLint stride; // stride in pixels
|
||||
GGLubyte* data; // pointer to the bits
|
||||
GGLubyte format; // pixel format
|
||||
GGLubyte rfu[3]; // must be zero
|
||||
// these values are dependent on the used format
|
||||
union {
|
||||
GGLint compressedFormat;
|
||||
GGLint vstride;
|
||||
};
|
||||
void* reserved;
|
||||
} GGLSurface;
|
||||
|
||||
|
||||
typedef struct {
|
||||
// immediate rendering
|
||||
void (*pointx)(void *con, const GGLcoord* v, GGLcoord r);
|
||||
void (*linex)(void *con,
|
||||
const GGLcoord* v0, const GGLcoord* v1, GGLcoord width);
|
||||
void (*recti)(void* c, GGLint l, GGLint t, GGLint r, GGLint b);
|
||||
void (*trianglex)(void* c,
|
||||
GGLcoord const* v0, GGLcoord const* v1, GGLcoord const* v2);
|
||||
|
||||
// scissor
|
||||
void (*scissor)(void* c, GGLint x, GGLint y, GGLsizei width, GGLsizei height);
|
||||
|
||||
// Set the textures and color buffers
|
||||
void (*activeTexture)(void* c, GGLuint tmu);
|
||||
void (*bindTexture)(void* c, const GGLSurface* surface);
|
||||
void (*colorBuffer)(void* c, const GGLSurface* surface);
|
||||
void (*readBuffer)(void* c, const GGLSurface* surface);
|
||||
void (*depthBuffer)(void* c, const GGLSurface* surface);
|
||||
void (*bindTextureLod)(void* c, GGLuint tmu, const GGLSurface* surface);
|
||||
|
||||
// enable/disable features
|
||||
void (*enable)(void* c, GGLenum name);
|
||||
void (*disable)(void* c, GGLenum name);
|
||||
void (*enableDisable)(void* c, GGLenum name, GGLboolean en);
|
||||
|
||||
// specify the fragment's color
|
||||
void (*shadeModel)(void* c, GGLenum mode);
|
||||
void (*color4xv)(void* c, const GGLclampx* color);
|
||||
// specify color iterators (16.16)
|
||||
void (*colorGrad12xv)(void* c, const GGLcolor* grad);
|
||||
|
||||
// specify Z coordinate iterators (0.32)
|
||||
void (*zGrad3xv)(void* c, const GGLfixed32* grad);
|
||||
|
||||
// specify W coordinate iterators (16.16)
|
||||
void (*wGrad3xv)(void* c, const GGLfixed* grad);
|
||||
|
||||
// specify fog iterator & color (16.16)
|
||||
void (*fogGrad3xv)(void* c, const GGLfixed* grad);
|
||||
void (*fogColor3xv)(void* c, const GGLclampx* color);
|
||||
|
||||
// specify blending parameters
|
||||
void (*blendFunc)(void* c, GGLenum src, GGLenum dst);
|
||||
void (*blendFuncSeparate)(void* c, GGLenum src, GGLenum dst,
|
||||
GGLenum srcAlpha, GGLenum dstAplha);
|
||||
|
||||
// texture environnement (REPLACE / MODULATE / DECAL / BLEND)
|
||||
void (*texEnvi)(void* c, GGLenum target,
|
||||
GGLenum pname,
|
||||
GGLint param);
|
||||
|
||||
void (*texEnvxv)(void* c, GGLenum target,
|
||||
GGLenum pname, const GGLfixed* params);
|
||||
|
||||
// texture parameters (Wrapping, filter)
|
||||
void (*texParameteri)(void* c, GGLenum target,
|
||||
GGLenum pname,
|
||||
GGLint param);
|
||||
|
||||
// texture iterators (16.16)
|
||||
void (*texCoord2i)(void* c, GGLint s, GGLint t);
|
||||
void (*texCoord2x)(void* c, GGLfixed s, GGLfixed t);
|
||||
|
||||
// s, dsdx, dsdy, scale, t, dtdx, dtdy, tscale
|
||||
// This api uses block floating-point for S and T texture coordinates.
|
||||
// All values are given in 16.16, scaled by 'scale'. In other words,
|
||||
// set scale to 0, for 16.16 values.
|
||||
void (*texCoordGradScale8xv)(void* c, GGLint tmu, const int32_t* grad8);
|
||||
|
||||
void (*texGeni)(void* c, GGLenum coord, GGLenum pname, GGLint param);
|
||||
|
||||
// masking
|
||||
void (*colorMask)(void* c, GGLboolean red,
|
||||
GGLboolean green,
|
||||
GGLboolean blue,
|
||||
GGLboolean alpha);
|
||||
|
||||
void (*depthMask)(void* c, GGLboolean flag);
|
||||
|
||||
void (*stencilMask)(void* c, GGLuint mask);
|
||||
|
||||
// alpha func
|
||||
void (*alphaFuncx)(void* c, GGLenum func, GGLclampx ref);
|
||||
|
||||
// depth func
|
||||
void (*depthFunc)(void* c, GGLenum func);
|
||||
|
||||
// logic op
|
||||
void (*logicOp)(void* c, GGLenum opcode);
|
||||
|
||||
// clear
|
||||
void (*clear)(void* c, GGLbitfield mask);
|
||||
void (*clearColorx)(void* c,
|
||||
GGLclampx r, GGLclampx g, GGLclampx b, GGLclampx a);
|
||||
void (*clearDepthx)(void* c, GGLclampx depth);
|
||||
void (*clearStencil)(void* c, GGLint s);
|
||||
|
||||
// framebuffer operations
|
||||
void (*copyPixels)(void* c, GGLint x, GGLint y,
|
||||
GGLsizei width, GGLsizei height, GGLenum type);
|
||||
void (*rasterPos2x)(void* c, GGLfixed x, GGLfixed y);
|
||||
void (*rasterPos2i)(void* c, GGLint x, GGLint y);
|
||||
} GGLContext;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// construct / destroy the context
|
||||
ssize_t gglInit(GGLContext** context);
|
||||
ssize_t gglUninit(GGLContext* context);
|
||||
|
||||
GGLint gglBitBlit(
|
||||
GGLContext* c,
|
||||
int tmu,
|
||||
GGLint crop[4],
|
||||
GGLint where[4]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_PIXELFLINGER_H
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* sync.h
|
||||
*
|
||||
* Copyright 2012 Google, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __SYS_CORE_SYNC_H
|
||||
#define __SYS_CORE_SYNC_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdint.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
// XXX: These structs are copied from the header "linux/sync.h".
|
||||
struct sync_fence_info_data {
|
||||
uint32_t len;
|
||||
char name[32];
|
||||
int32_t status;
|
||||
uint8_t pt_info[0];
|
||||
};
|
||||
|
||||
struct sync_pt_info {
|
||||
uint32_t len;
|
||||
char obj_name[32];
|
||||
char driver_name[32];
|
||||
int32_t status;
|
||||
uint64_t timestamp_ns;
|
||||
uint8_t driver_data[0];
|
||||
};
|
||||
|
||||
/* timeout in msecs */
|
||||
int sync_wait(int fd, int timeout);
|
||||
int sync_merge(const char *name, int fd1, int fd2);
|
||||
struct sync_fence_info_data *sync_fence_info(int fd);
|
||||
struct sync_pt_info *sync_pt_info(struct sync_fence_info_data *info,
|
||||
struct sync_pt_info *itr);
|
||||
void sync_fence_info_free(struct sync_fence_info_data *info);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __SYS_CORE_SYNC_H */
|
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
|
||||
#define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If the HAL needs to create service threads to handle graphics related
|
||||
* tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
|
||||
* if they can block the main rendering thread in any way.
|
||||
*
|
||||
* the priority of the current thread can be set with:
|
||||
*
|
||||
* #include <sys/resource.h>
|
||||
* setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
|
||||
*
|
||||
*/
|
||||
|
||||
#define HAL_PRIORITY_URGENT_DISPLAY (-8)
|
||||
|
||||
/**
|
||||
* pixel format definitions
|
||||
*/
|
||||
|
||||
enum {
|
||||
HAL_PIXEL_FORMAT_RGBA_8888 = 1,
|
||||
HAL_PIXEL_FORMAT_RGBX_8888 = 2,
|
||||
HAL_PIXEL_FORMAT_RGB_888 = 3,
|
||||
HAL_PIXEL_FORMAT_RGB_565 = 4,
|
||||
HAL_PIXEL_FORMAT_BGRA_8888 = 5,
|
||||
HAL_PIXEL_FORMAT_RGBA_5551 = 6,
|
||||
HAL_PIXEL_FORMAT_RGBA_4444 = 7,
|
||||
|
||||
/* 0x8 - 0xFF range unavailable */
|
||||
|
||||
/*
|
||||
* 0x100 - 0x1FF
|
||||
*
|
||||
* This range is reserved for pixel formats that are specific to the HAL
|
||||
* implementation. Implementations can use any value in this range to
|
||||
* communicate video pixel formats between their HAL modules. These formats
|
||||
* must not have an alpha channel. Additionally, an EGLimage created from a
|
||||
* gralloc buffer of one of these formats must be supported for use with the
|
||||
* GL_OES_EGL_image_external OpenGL ES extension.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Android YUV format:
|
||||
*
|
||||
* This format is exposed outside of the HAL to software decoders and
|
||||
* applications. EGLImageKHR must support it in conjunction with the
|
||||
* OES_EGL_image_external extension.
|
||||
*
|
||||
* YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
|
||||
* by (W/2) x (H/2) Cr and Cb planes.
|
||||
*
|
||||
* This format assumes
|
||||
* - an even width
|
||||
* - an even height
|
||||
* - a horizontal stride multiple of 16 pixels
|
||||
* - a vertical stride equal to the height
|
||||
*
|
||||
* y_size = stride * height
|
||||
* c_stride = ALIGN(stride/2, 16)
|
||||
* c_size = c_stride * height/2
|
||||
* size = y_size + c_size * 2
|
||||
* cr_offset = y_size
|
||||
* cb_offset = y_size + c_size
|
||||
*
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar
|
||||
|
||||
|
||||
/*
|
||||
* Android Y8 format:
|
||||
*
|
||||
* This format is exposed outside of the HAL to the framework.
|
||||
* The expected gralloc usage flags are SW_* and HW_CAMERA_*,
|
||||
* and no other HW_ flags will be used.
|
||||
*
|
||||
* Y8 is a YUV planar format comprised of a WxH Y plane,
|
||||
* with each pixel being represented by 8 bits.
|
||||
*
|
||||
* It is equivalent to just the Y plane from YV12.
|
||||
*
|
||||
* This format assumes
|
||||
* - an even width
|
||||
* - an even height
|
||||
* - a horizontal stride multiple of 16 pixels
|
||||
* - a vertical stride equal to the height
|
||||
*
|
||||
* size = stride * height
|
||||
*
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_Y8 = 0x20203859,
|
||||
|
||||
/*
|
||||
* Android Y16 format:
|
||||
*
|
||||
* This format is exposed outside of the HAL to the framework.
|
||||
* The expected gralloc usage flags are SW_* and HW_CAMERA_*,
|
||||
* and no other HW_ flags will be used.
|
||||
*
|
||||
* Y16 is a YUV planar format comprised of a WxH Y plane,
|
||||
* with each pixel being represented by 16 bits.
|
||||
*
|
||||
* It is just like Y8, but has double the bits per pixel (little endian).
|
||||
*
|
||||
* This format assumes
|
||||
* - an even width
|
||||
* - an even height
|
||||
* - a horizontal stride multiple of 16 pixels
|
||||
* - a vertical stride equal to the height
|
||||
* - strides are specified in pixels, not in bytes
|
||||
*
|
||||
* size = stride * height * 2
|
||||
*
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_Y16 = 0x20363159,
|
||||
|
||||
/*
|
||||
* Android RAW sensor format:
|
||||
*
|
||||
* This format is exposed outside of the HAL to applications.
|
||||
*
|
||||
* RAW_SENSOR is a single-channel 16-bit format, typically representing raw
|
||||
* Bayer-pattern images from an image sensor, with minimal processing.
|
||||
*
|
||||
* The exact pixel layout of the data in the buffer is sensor-dependent, and
|
||||
* needs to be queried from the camera device.
|
||||
*
|
||||
* Generally, not all 16 bits are used; more common values are 10 or 12
|
||||
* bits. All parameters to interpret the raw data (black and white points,
|
||||
* color space, etc) must be queried from the camera device.
|
||||
*
|
||||
* This format assumes
|
||||
* - an even width
|
||||
* - an even height
|
||||
* - a horizontal stride multiple of 16 pixels (32 bytes).
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_RAW_SENSOR = 0x20,
|
||||
|
||||
/*
|
||||
* Android binary blob graphics buffer format:
|
||||
*
|
||||
* This format is used to carry task-specific data which does not have a
|
||||
* standard image structure. The details of the format are left to the two
|
||||
* endpoints.
|
||||
*
|
||||
* A typical use case is for transporting JPEG-compressed images from the
|
||||
* Camera HAL to the framework or to applications.
|
||||
*
|
||||
* Buffers of this format must have a height of 1, and width equal to their
|
||||
* size in bytes.
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_BLOB = 0x21,
|
||||
|
||||
/*
|
||||
* Android format indicating that the choice of format is entirely up to the
|
||||
* device-specific Gralloc implementation.
|
||||
*
|
||||
* The Gralloc implementation should examine the usage bits passed in when
|
||||
* allocating a buffer with this format, and it should derive the pixel
|
||||
* format from those usage flags. This format will never be used with any
|
||||
* of the GRALLOC_USAGE_SW_* usage flags.
|
||||
*
|
||||
* If a buffer of this format is to be used as an OpenGL ES texture, the
|
||||
* framework will assume that sampling the texture will always return an
|
||||
* alpha value of 1.0 (i.e. the buffer contains only opaque pixel values).
|
||||
*
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22,
|
||||
|
||||
/*
|
||||
* Android flexible YCbCr formats
|
||||
*
|
||||
* This format allows platforms to use an efficient YCbCr/YCrCb buffer
|
||||
* layout, while still describing the buffer layout in a way accessible to
|
||||
* the CPU in a device-independent manner. While called YCbCr, it can be
|
||||
* used to describe formats with either chromatic ordering, as well as
|
||||
* whole planar or semiplanar layouts.
|
||||
*
|
||||
* struct android_ycbcr (below) is the the struct used to describe it.
|
||||
*
|
||||
* This format must be accepted by the gralloc module when
|
||||
* USAGE_HW_CAMERA_WRITE and USAGE_SW_READ_* are set.
|
||||
*
|
||||
* This format is locked for use by gralloc's (*lock_ycbcr) method, and
|
||||
* locking with the (*lock) method will return an error.
|
||||
*/
|
||||
HAL_PIXEL_FORMAT_YCbCr_420_888 = 0x23,
|
||||
|
||||
/* Legacy formats (deprecated), used by ImageFormat.java */
|
||||
HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16
|
||||
HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21
|
||||
HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure for describing YCbCr formats for consumption by applications.
|
||||
* This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
|
||||
*
|
||||
* Buffer chroma subsampling is defined in the format.
|
||||
* e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
|
||||
*
|
||||
* Buffers must have a 8 bit depth.
|
||||
*
|
||||
* @y, @cb, and @cr point to the first byte of their respective planes.
|
||||
*
|
||||
* Stride describes the distance in bytes from the first value of one row of
|
||||
* the image to the first value of the next row. It includes the width of the
|
||||
* image plus padding.
|
||||
* @ystride is the stride of the luma plane.
|
||||
* @cstride is the stride of the chroma planes.
|
||||
*
|
||||
* @chroma_step is the distance in bytes from one chroma pixel value to the
|
||||
* next. This is 2 bytes for semiplanar (because chroma values are interleaved
|
||||
* and each chroma value is one byte) and 1 for planar.
|
||||
*/
|
||||
|
||||
struct android_ycbcr {
|
||||
void *y;
|
||||
void *cb;
|
||||
void *cr;
|
||||
size_t ystride;
|
||||
size_t cstride;
|
||||
size_t chroma_step;
|
||||
|
||||
/** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
|
||||
uint32_t reserved[8];
|
||||
};
|
||||
|
||||
/**
|
||||
* Transformation definitions
|
||||
*
|
||||
* IMPORTANT NOTE:
|
||||
* HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}.
|
||||
*
|
||||
*/
|
||||
|
||||
enum {
|
||||
/* flip source image horizontally (around the vertical axis) */
|
||||
HAL_TRANSFORM_FLIP_H = 0x01,
|
||||
/* flip source image vertically (around the horizontal axis)*/
|
||||
HAL_TRANSFORM_FLIP_V = 0x02,
|
||||
/* rotate source image 90 degrees clockwise */
|
||||
HAL_TRANSFORM_ROT_90 = 0x04,
|
||||
/* rotate source image 180 degrees */
|
||||
HAL_TRANSFORM_ROT_180 = 0x03,
|
||||
/* rotate source image 270 degrees clockwise */
|
||||
HAL_TRANSFORM_ROT_270 = 0x07,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
|
|
@ -0,0 +1,833 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
|
||||
#define SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sync/sync.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <system/graphics.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
|
||||
(((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
|
||||
|
||||
#define ANDROID_NATIVE_WINDOW_MAGIC \
|
||||
ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
|
||||
|
||||
#define ANDROID_NATIVE_BUFFER_MAGIC \
|
||||
ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// This #define may be used to conditionally compile device-specific code to
|
||||
// support either the prior ANativeWindow interface, which did not pass libsync
|
||||
// fences around, or the new interface that does. This #define is only present
|
||||
// when the ANativeWindow interface does include libsync support.
|
||||
#define ANDROID_NATIVE_WINDOW_HAS_SYNC 1
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef const native_handle_t* buffer_handle_t;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef struct android_native_rect_t
|
||||
{
|
||||
int32_t left;
|
||||
int32_t top;
|
||||
int32_t right;
|
||||
int32_t bottom;
|
||||
} android_native_rect_t;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef struct android_native_base_t
|
||||
{
|
||||
/* a magic value defined by the actual EGL native type */
|
||||
int magic;
|
||||
|
||||
/* the sizeof() of the actual EGL native type */
|
||||
int version;
|
||||
|
||||
void* reserved[4];
|
||||
|
||||
/* reference-counting interface */
|
||||
void (*incRef)(struct android_native_base_t* base);
|
||||
void (*decRef)(struct android_native_base_t* base);
|
||||
} android_native_base_t;
|
||||
|
||||
typedef struct ANativeWindowBuffer
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
ANativeWindowBuffer() {
|
||||
common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
|
||||
common.version = sizeof(ANativeWindowBuffer);
|
||||
memset(common.reserved, 0, sizeof(common.reserved));
|
||||
}
|
||||
|
||||
// Implement the methods that sp<ANativeWindowBuffer> expects so that it
|
||||
// can be used to automatically refcount ANativeWindowBuffer's.
|
||||
void incStrong(const void* id) const {
|
||||
common.incRef(const_cast<android_native_base_t*>(&common));
|
||||
}
|
||||
void decStrong(const void* id) const {
|
||||
common.decRef(const_cast<android_native_base_t*>(&common));
|
||||
}
|
||||
#endif
|
||||
|
||||
struct android_native_base_t common;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int stride;
|
||||
int format;
|
||||
int usage;
|
||||
|
||||
void* reserved[2];
|
||||
|
||||
buffer_handle_t handle;
|
||||
|
||||
void* reserved_proc[8];
|
||||
} ANativeWindowBuffer_t;
|
||||
|
||||
// Old typedef for backwards compatibility.
|
||||
typedef ANativeWindowBuffer_t android_native_buffer_t;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/* attributes queriable with query() */
|
||||
enum {
|
||||
NATIVE_WINDOW_WIDTH = 0,
|
||||
NATIVE_WINDOW_HEIGHT = 1,
|
||||
NATIVE_WINDOW_FORMAT = 2,
|
||||
|
||||
/* The minimum number of buffers that must remain un-dequeued after a buffer
|
||||
* has been queued. This value applies only if set_buffer_count was used to
|
||||
* override the number of buffers and if a buffer has since been queued.
|
||||
* Users of the set_buffer_count ANativeWindow method should query this
|
||||
* value before calling set_buffer_count. If it is necessary to have N
|
||||
* buffers simultaneously dequeued as part of the steady-state operation,
|
||||
* and this query returns M then N+M buffers should be requested via
|
||||
* native_window_set_buffer_count.
|
||||
*
|
||||
* Note that this value does NOT apply until a single buffer has been
|
||||
* queued. In particular this means that it is possible to:
|
||||
*
|
||||
* 1. Query M = min undequeued buffers
|
||||
* 2. Set the buffer count to N + M
|
||||
* 3. Dequeue all N + M buffers
|
||||
* 4. Cancel M buffers
|
||||
* 5. Queue, dequeue, queue, dequeue, ad infinitum
|
||||
*/
|
||||
NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
|
||||
|
||||
/* Check whether queueBuffer operations on the ANativeWindow send the buffer
|
||||
* to the window compositor. The query sets the returned 'value' argument
|
||||
* to 1 if the ANativeWindow DOES send queued buffers directly to the window
|
||||
* compositor and 0 if the buffers do not go directly to the window
|
||||
* compositor.
|
||||
*
|
||||
* This can be used to determine whether protected buffer content should be
|
||||
* sent to the ANativeWindow. Note, however, that a result of 1 does NOT
|
||||
* indicate that queued buffers will be protected from applications or users
|
||||
* capturing their contents. If that behavior is desired then some other
|
||||
* mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
|
||||
* conjunction with this query.
|
||||
*/
|
||||
NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
|
||||
|
||||
/* Get the concrete type of a ANativeWindow. See below for the list of
|
||||
* possible return values.
|
||||
*
|
||||
* This query should not be used outside the Android framework and will
|
||||
* likely be removed in the near future.
|
||||
*/
|
||||
NATIVE_WINDOW_CONCRETE_TYPE = 5,
|
||||
|
||||
|
||||
/*
|
||||
* Default width and height of ANativeWindow buffers, these are the
|
||||
* dimensions of the window buffers irrespective of the
|
||||
* NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
|
||||
* size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
|
||||
*/
|
||||
NATIVE_WINDOW_DEFAULT_WIDTH = 6,
|
||||
NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
|
||||
|
||||
/*
|
||||
* transformation that will most-likely be applied to buffers. This is only
|
||||
* a hint, the actual transformation applied might be different.
|
||||
*
|
||||
* INTENDED USE:
|
||||
*
|
||||
* The transform hint can be used by a producer, for instance the GLES
|
||||
* driver, to pre-rotate the rendering such that the final transformation
|
||||
* in the composer is identity. This can be very useful when used in
|
||||
* conjunction with the h/w composer HAL, in situations where it
|
||||
* cannot handle arbitrary rotations.
|
||||
*
|
||||
* 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
|
||||
* queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
|
||||
*
|
||||
* 2. The GL driver overrides the width and height of the ANW to
|
||||
* account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
|
||||
* NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
|
||||
* according to NATIVE_WINDOW_TRANSFORM_HINT and calling
|
||||
* native_window_set_buffers_dimensions().
|
||||
*
|
||||
* 3. The GL driver dequeues a buffer of the new pre-rotated size.
|
||||
*
|
||||
* 4. The GL driver renders to the buffer such that the image is
|
||||
* already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
|
||||
* to the rendering.
|
||||
*
|
||||
* 5. The GL driver calls native_window_set_transform to apply
|
||||
* inverse transformation to the buffer it just rendered.
|
||||
* In order to do this, the GL driver needs
|
||||
* to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
|
||||
* done easily:
|
||||
*
|
||||
* int hintTransform, inverseTransform;
|
||||
* query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
|
||||
* inverseTransform = hintTransform;
|
||||
* if (hintTransform & HAL_TRANSFORM_ROT_90)
|
||||
* inverseTransform ^= HAL_TRANSFORM_ROT_180;
|
||||
*
|
||||
*
|
||||
* 6. The GL driver queues the pre-transformed buffer.
|
||||
*
|
||||
* 7. The composer combines the buffer transform with the display
|
||||
* transform. If the buffer transform happens to cancel out the
|
||||
* display transform then no rotation is needed.
|
||||
*
|
||||
*/
|
||||
NATIVE_WINDOW_TRANSFORM_HINT = 8,
|
||||
|
||||
/*
|
||||
* Boolean that indicates whether the consumer is running more than
|
||||
* one buffer behind the producer.
|
||||
*/
|
||||
NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9
|
||||
};
|
||||
|
||||
/* Valid operations for the (*perform)() hook.
|
||||
*
|
||||
* Values marked as 'deprecated' are supported, but have been superceded by
|
||||
* other functionality.
|
||||
*
|
||||
* Values marked as 'private' should be considered private to the framework.
|
||||
* HAL implementation code with access to an ANativeWindow should not use these,
|
||||
* as it may not interact properly with the framework's use of the
|
||||
* ANativeWindow.
|
||||
*/
|
||||
enum {
|
||||
NATIVE_WINDOW_SET_USAGE = 0,
|
||||
NATIVE_WINDOW_CONNECT = 1, /* deprecated */
|
||||
NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
|
||||
NATIVE_WINDOW_SET_CROP = 3, /* private */
|
||||
NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
|
||||
NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
|
||||
NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
|
||||
NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
|
||||
NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
|
||||
NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
|
||||
NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
|
||||
NATIVE_WINDOW_LOCK = 11, /* private */
|
||||
NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
|
||||
NATIVE_WINDOW_API_CONNECT = 13, /* private */
|
||||
NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
|
||||
NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
|
||||
NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */
|
||||
};
|
||||
|
||||
/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
|
||||
enum {
|
||||
/* Buffers will be queued by EGL via eglSwapBuffers after being filled using
|
||||
* OpenGL ES.
|
||||
*/
|
||||
NATIVE_WINDOW_API_EGL = 1,
|
||||
|
||||
/* Buffers will be queued after being filled using the CPU
|
||||
*/
|
||||
NATIVE_WINDOW_API_CPU = 2,
|
||||
|
||||
/* Buffers will be queued by Stagefright after being filled by a video
|
||||
* decoder. The video decoder can either be a software or hardware decoder.
|
||||
*/
|
||||
NATIVE_WINDOW_API_MEDIA = 3,
|
||||
|
||||
/* Buffers will be queued by the the camera HAL.
|
||||
*/
|
||||
NATIVE_WINDOW_API_CAMERA = 4,
|
||||
};
|
||||
|
||||
/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
|
||||
enum {
|
||||
/* flip source image horizontally */
|
||||
NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
|
||||
/* flip source image vertically */
|
||||
NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
|
||||
/* rotate source image 90 degrees clock-wise */
|
||||
NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
|
||||
/* rotate source image 180 degrees */
|
||||
NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
|
||||
/* rotate source image 270 degrees clock-wise */
|
||||
NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
|
||||
};
|
||||
|
||||
/* parameter for NATIVE_WINDOW_SET_SCALING_MODE */
|
||||
enum {
|
||||
/* the window content is not updated (frozen) until a buffer of
|
||||
* the window size is received (enqueued)
|
||||
*/
|
||||
NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
|
||||
/* the buffer is scaled in both dimensions to match the window size */
|
||||
NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
|
||||
/* the buffer is scaled uniformly such that the smaller dimension
|
||||
* of the buffer matches the window size (cropping in the process)
|
||||
*/
|
||||
NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
|
||||
/* the window is clipped to the size of the buffer's crop rectangle; pixels
|
||||
* outside the crop rectangle are treated as if they are completely
|
||||
* transparent.
|
||||
*/
|
||||
NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
|
||||
};
|
||||
|
||||
/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
|
||||
enum {
|
||||
NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
|
||||
NATIVE_WINDOW_SURFACE = 1, /* Surface */
|
||||
};
|
||||
|
||||
/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
|
||||
*
|
||||
* Special timestamp value to indicate that timestamps should be auto-generated
|
||||
* by the native window when queueBuffer is called. This is equal to INT64_MIN,
|
||||
* defined directly to avoid problems with C99/C++ inclusion of stdint.h.
|
||||
*/
|
||||
static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
|
||||
|
||||
struct ANativeWindow
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
ANativeWindow()
|
||||
: flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
|
||||
{
|
||||
common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
|
||||
common.version = sizeof(ANativeWindow);
|
||||
memset(common.reserved, 0, sizeof(common.reserved));
|
||||
}
|
||||
|
||||
/* Implement the methods that sp<ANativeWindow> expects so that it
|
||||
can be used to automatically refcount ANativeWindow's. */
|
||||
void incStrong(const void* id) const {
|
||||
common.incRef(const_cast<android_native_base_t*>(&common));
|
||||
}
|
||||
void decStrong(const void* id) const {
|
||||
common.decRef(const_cast<android_native_base_t*>(&common));
|
||||
}
|
||||
#endif
|
||||
|
||||
struct android_native_base_t common;
|
||||
|
||||
/* flags describing some attributes of this surface or its updater */
|
||||
const uint32_t flags;
|
||||
|
||||
/* min swap interval supported by this updated */
|
||||
const int minSwapInterval;
|
||||
|
||||
/* max swap interval supported by this updated */
|
||||
const int maxSwapInterval;
|
||||
|
||||
/* horizontal and vertical resolution in DPI */
|
||||
const float xdpi;
|
||||
const float ydpi;
|
||||
|
||||
/* Some storage reserved for the OEM's driver. */
|
||||
intptr_t oem[4];
|
||||
|
||||
/*
|
||||
* Set the swap interval for this surface.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*setSwapInterval)(struct ANativeWindow* window,
|
||||
int interval);
|
||||
|
||||
/*
|
||||
* Hook called by EGL to acquire a buffer. After this call, the buffer
|
||||
* is not locked, so its content cannot be modified. This call may block if
|
||||
* no buffers are available.
|
||||
*
|
||||
* The window holds a reference to the buffer between dequeueBuffer and
|
||||
* either queueBuffer or cancelBuffer, so clients only need their own
|
||||
* reference if they might use the buffer after queueing or canceling it.
|
||||
* Holding a reference to a buffer after queueing or canceling it is only
|
||||
* allowed if a specific buffer count has been set.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*
|
||||
* XXX: This function is deprecated. It will continue to work for some
|
||||
* time for binary compatibility, but the new dequeueBuffer function that
|
||||
* outputs a fence file descriptor should be used in its place.
|
||||
*/
|
||||
int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer** buffer);
|
||||
|
||||
/*
|
||||
* hook called by EGL to lock a buffer. This MUST be called before modifying
|
||||
* the content of a buffer. The buffer must have been acquired with
|
||||
* dequeueBuffer first.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*
|
||||
* XXX: This function is deprecated. It will continue to work for some
|
||||
* time for binary compatibility, but it is essentially a no-op, and calls
|
||||
* to it should be removed.
|
||||
*/
|
||||
int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer* buffer);
|
||||
|
||||
/*
|
||||
* Hook called by EGL when modifications to the render buffer are done.
|
||||
* This unlocks and post the buffer.
|
||||
*
|
||||
* The window holds a reference to the buffer between dequeueBuffer and
|
||||
* either queueBuffer or cancelBuffer, so clients only need their own
|
||||
* reference if they might use the buffer after queueing or canceling it.
|
||||
* Holding a reference to a buffer after queueing or canceling it is only
|
||||
* allowed if a specific buffer count has been set.
|
||||
*
|
||||
* Buffers MUST be queued in the same order than they were dequeued.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*
|
||||
* XXX: This function is deprecated. It will continue to work for some
|
||||
* time for binary compatibility, but the new queueBuffer function that
|
||||
* takes a fence file descriptor should be used in its place (pass a value
|
||||
* of -1 for the fence file descriptor if there is no valid one to pass).
|
||||
*/
|
||||
int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer* buffer);
|
||||
|
||||
/*
|
||||
* hook used to retrieve information about the native window.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*query)(const struct ANativeWindow* window,
|
||||
int what, int* value);
|
||||
|
||||
/*
|
||||
* hook used to perform various operations on the surface.
|
||||
* (*perform)() is a generic mechanism to add functionality to
|
||||
* ANativeWindow while keeping backward binary compatibility.
|
||||
*
|
||||
* DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
|
||||
* defined below.
|
||||
*
|
||||
* (*perform)() returns -ENOENT if the 'what' parameter is not supported
|
||||
* by the surface's implementation.
|
||||
*
|
||||
* The valid operations are:
|
||||
* NATIVE_WINDOW_SET_USAGE
|
||||
* NATIVE_WINDOW_CONNECT (deprecated)
|
||||
* NATIVE_WINDOW_DISCONNECT (deprecated)
|
||||
* NATIVE_WINDOW_SET_CROP (private)
|
||||
* NATIVE_WINDOW_SET_BUFFER_COUNT
|
||||
* NATIVE_WINDOW_SET_BUFFERS_GEOMETRY (deprecated)
|
||||
* NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
|
||||
* NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
|
||||
* NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
|
||||
* NATIVE_WINDOW_SET_BUFFERS_FORMAT
|
||||
* NATIVE_WINDOW_SET_SCALING_MODE (private)
|
||||
* NATIVE_WINDOW_LOCK (private)
|
||||
* NATIVE_WINDOW_UNLOCK_AND_POST (private)
|
||||
* NATIVE_WINDOW_API_CONNECT (private)
|
||||
* NATIVE_WINDOW_API_DISCONNECT (private)
|
||||
* NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS (private)
|
||||
* NATIVE_WINDOW_SET_POST_TRANSFORM_CROP (private)
|
||||
*
|
||||
*/
|
||||
|
||||
int (*perform)(struct ANativeWindow* window,
|
||||
int operation, ... );
|
||||
|
||||
/*
|
||||
* Hook used to cancel a buffer that has been dequeued.
|
||||
* No synchronization is performed between dequeue() and cancel(), so
|
||||
* either external synchronization is needed, or these functions must be
|
||||
* called from the same thread.
|
||||
*
|
||||
* The window holds a reference to the buffer between dequeueBuffer and
|
||||
* either queueBuffer or cancelBuffer, so clients only need their own
|
||||
* reference if they might use the buffer after queueing or canceling it.
|
||||
* Holding a reference to a buffer after queueing or canceling it is only
|
||||
* allowed if a specific buffer count has been set.
|
||||
*
|
||||
* XXX: This function is deprecated. It will continue to work for some
|
||||
* time for binary compatibility, but the new cancelBuffer function that
|
||||
* takes a fence file descriptor should be used in its place (pass a value
|
||||
* of -1 for the fence file descriptor if there is no valid one to pass).
|
||||
*/
|
||||
int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer* buffer);
|
||||
|
||||
/*
|
||||
* Hook called by EGL to acquire a buffer. This call may block if no
|
||||
* buffers are available.
|
||||
*
|
||||
* The window holds a reference to the buffer between dequeueBuffer and
|
||||
* either queueBuffer or cancelBuffer, so clients only need their own
|
||||
* reference if they might use the buffer after queueing or canceling it.
|
||||
* Holding a reference to a buffer after queueing or canceling it is only
|
||||
* allowed if a specific buffer count has been set.
|
||||
*
|
||||
* The libsync fence file descriptor returned in the int pointed to by the
|
||||
* fenceFd argument will refer to the fence that must signal before the
|
||||
* dequeued buffer may be written to. A value of -1 indicates that the
|
||||
* caller may access the buffer immediately without waiting on a fence. If
|
||||
* a valid file descriptor is returned (i.e. any value except -1) then the
|
||||
* caller is responsible for closing the file descriptor.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*dequeueBuffer)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer** buffer, int* fenceFd);
|
||||
|
||||
/*
|
||||
* Hook called by EGL when modifications to the render buffer are done.
|
||||
* This unlocks and post the buffer.
|
||||
*
|
||||
* The window holds a reference to the buffer between dequeueBuffer and
|
||||
* either queueBuffer or cancelBuffer, so clients only need their own
|
||||
* reference if they might use the buffer after queueing or canceling it.
|
||||
* Holding a reference to a buffer after queueing or canceling it is only
|
||||
* allowed if a specific buffer count has been set.
|
||||
*
|
||||
* The fenceFd argument specifies a libsync fence file descriptor for a
|
||||
* fence that must signal before the buffer can be accessed. If the buffer
|
||||
* can be accessed immediately then a value of -1 should be used. The
|
||||
* caller must not use the file descriptor after it is passed to
|
||||
* queueBuffer, and the ANativeWindow implementation is responsible for
|
||||
* closing it.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*queueBuffer)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer* buffer, int fenceFd);
|
||||
|
||||
/*
|
||||
* Hook used to cancel a buffer that has been dequeued.
|
||||
* No synchronization is performed between dequeue() and cancel(), so
|
||||
* either external synchronization is needed, or these functions must be
|
||||
* called from the same thread.
|
||||
*
|
||||
* The window holds a reference to the buffer between dequeueBuffer and
|
||||
* either queueBuffer or cancelBuffer, so clients only need their own
|
||||
* reference if they might use the buffer after queueing or canceling it.
|
||||
* Holding a reference to a buffer after queueing or canceling it is only
|
||||
* allowed if a specific buffer count has been set.
|
||||
*
|
||||
* The fenceFd argument specifies a libsync fence file decsriptor for a
|
||||
* fence that must signal before the buffer can be accessed. If the buffer
|
||||
* can be accessed immediately then a value of -1 should be used.
|
||||
*
|
||||
* Note that if the client has not waited on the fence that was returned
|
||||
* from dequeueBuffer, that same fence should be passed to cancelBuffer to
|
||||
* ensure that future uses of the buffer are preceded by a wait on that
|
||||
* fence. The caller must not use the file descriptor after it is passed
|
||||
* to cancelBuffer, and the ANativeWindow implementation is responsible for
|
||||
* closing it.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*cancelBuffer)(struct ANativeWindow* window,
|
||||
struct ANativeWindowBuffer* buffer, int fenceFd);
|
||||
};
|
||||
|
||||
/* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
|
||||
* android_native_window_t is deprecated.
|
||||
*/
|
||||
typedef struct ANativeWindow ANativeWindow;
|
||||
typedef struct ANativeWindow android_native_window_t;
|
||||
|
||||
/*
|
||||
* native_window_set_usage(..., usage)
|
||||
* Sets the intended usage flags for the next buffers
|
||||
* acquired with (*lockBuffer)() and on.
|
||||
* By default (if this function is never called), a usage of
|
||||
* GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
|
||||
* is assumed.
|
||||
* Calling this function will usually cause following buffers to be
|
||||
* reallocated.
|
||||
*/
|
||||
|
||||
static inline int native_window_set_usage(
|
||||
struct ANativeWindow* window, int usage)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage);
|
||||
}
|
||||
|
||||
/* deprecated. Always returns 0. Don't call. */
|
||||
static inline int native_window_connect(
|
||||
struct ANativeWindow* window, int api) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* deprecated. Always returns 0. Don't call. */
|
||||
static inline int native_window_disconnect(
|
||||
struct ANativeWindow* window, int api) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_crop(..., crop)
|
||||
* Sets which region of the next queued buffers needs to be considered.
|
||||
* Depending on the scaling mode, a buffer's crop region is scaled and/or
|
||||
* cropped to match the surface's size. This function sets the crop in
|
||||
* pre-transformed buffer pixel coordinates.
|
||||
*
|
||||
* The specified crop region applies to all buffers queued after it is called.
|
||||
*
|
||||
* If 'crop' is NULL, subsequently queued buffers won't be cropped.
|
||||
*
|
||||
* An error is returned if for instance the crop region is invalid, out of the
|
||||
* buffer's bound or if the window is invalid.
|
||||
*/
|
||||
static inline int native_window_set_crop(
|
||||
struct ANativeWindow* window,
|
||||
android_native_rect_t const * crop)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_post_transform_crop(..., crop)
|
||||
* Sets which region of the next queued buffers needs to be considered.
|
||||
* Depending on the scaling mode, a buffer's crop region is scaled and/or
|
||||
* cropped to match the surface's size. This function sets the crop in
|
||||
* post-transformed pixel coordinates.
|
||||
*
|
||||
* The specified crop region applies to all buffers queued after it is called.
|
||||
*
|
||||
* If 'crop' is NULL, subsequently queued buffers won't be cropped.
|
||||
*
|
||||
* An error is returned if for instance the crop region is invalid, out of the
|
||||
* buffer's bound or if the window is invalid.
|
||||
*/
|
||||
static inline int native_window_set_post_transform_crop(
|
||||
struct ANativeWindow* window,
|
||||
android_native_rect_t const * crop)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_active_rect(..., active_rect)
|
||||
*
|
||||
* This function is deprecated and will be removed soon. For now it simply
|
||||
* sets the post-transform crop for compatibility while multi-project commits
|
||||
* get checked.
|
||||
*/
|
||||
static inline int native_window_set_active_rect(
|
||||
struct ANativeWindow* window,
|
||||
android_native_rect_t const * active_rect)
|
||||
{
|
||||
return native_window_set_post_transform_crop(window, active_rect);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffer_count(..., count)
|
||||
* Sets the number of buffers associated with this native window.
|
||||
*/
|
||||
static inline int native_window_set_buffer_count(
|
||||
struct ANativeWindow* window,
|
||||
size_t bufferCount)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffers_geometry(..., int w, int h, int format)
|
||||
* All buffers dequeued after this call will have the dimensions and format
|
||||
* specified. A successful call to this function has the same effect as calling
|
||||
* native_window_set_buffers_size and native_window_set_buffers_format.
|
||||
*
|
||||
* XXX: This function is deprecated. The native_window_set_buffers_dimensions
|
||||
* and native_window_set_buffers_format functions should be used instead.
|
||||
*/
|
||||
static inline int native_window_set_buffers_geometry(
|
||||
struct ANativeWindow* window,
|
||||
int w, int h, int format)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
|
||||
w, h, format);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffers_dimensions(..., int w, int h)
|
||||
* All buffers dequeued after this call will have the dimensions specified.
|
||||
* In particular, all buffers will have a fixed-size, independent from the
|
||||
* native-window size. They will be scaled according to the scaling mode
|
||||
* (see native_window_set_scaling_mode) upon window composition.
|
||||
*
|
||||
* If w and h are 0, the normal behavior is restored. That is, dequeued buffers
|
||||
* following this call will be sized to match the window's size.
|
||||
*
|
||||
* Calling this function will reset the window crop to a NULL value, which
|
||||
* disables cropping of the buffers.
|
||||
*/
|
||||
static inline int native_window_set_buffers_dimensions(
|
||||
struct ANativeWindow* window,
|
||||
int w, int h)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
|
||||
w, h);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffers_user_dimensions(..., int w, int h)
|
||||
*
|
||||
* Sets the user buffer size for the window, which overrides the
|
||||
* window's size. All buffers dequeued after this call will have the
|
||||
* dimensions specified unless overridden by
|
||||
* native_window_set_buffers_dimensions. All buffers will have a
|
||||
* fixed-size, independent from the native-window size. They will be
|
||||
* scaled according to the scaling mode (see
|
||||
* native_window_set_scaling_mode) upon window composition.
|
||||
*
|
||||
* If w and h are 0, the normal behavior is restored. That is, the
|
||||
* default buffer size will match the windows's size.
|
||||
*
|
||||
* Calling this function will reset the window crop to a NULL value, which
|
||||
* disables cropping of the buffers.
|
||||
*/
|
||||
static inline int native_window_set_buffers_user_dimensions(
|
||||
struct ANativeWindow* window,
|
||||
int w, int h)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
|
||||
w, h);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffers_format(..., int format)
|
||||
* All buffers dequeued after this call will have the format specified.
|
||||
*
|
||||
* If the specified format is 0, the default buffer format will be used.
|
||||
*/
|
||||
static inline int native_window_set_buffers_format(
|
||||
struct ANativeWindow* window,
|
||||
int format)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffers_transform(..., int transform)
|
||||
* All buffers queued after this call will be displayed transformed according
|
||||
* to the transform parameter specified.
|
||||
*/
|
||||
static inline int native_window_set_buffers_transform(
|
||||
struct ANativeWindow* window,
|
||||
int transform)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
|
||||
transform);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_buffers_timestamp(..., int64_t timestamp)
|
||||
* All buffers queued after this call will be associated with the timestamp
|
||||
* parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
|
||||
* (the default), timestamps will be generated automatically when queueBuffer is
|
||||
* called. The timestamp is measured in nanoseconds, and is normally monotonically
|
||||
* increasing. The timestamp should be unaffected by time-of-day adjustments,
|
||||
* and for a camera should be strictly monotonic but for a media player may be
|
||||
* reset when the position is set.
|
||||
*/
|
||||
static inline int native_window_set_buffers_timestamp(
|
||||
struct ANativeWindow* window,
|
||||
int64_t timestamp)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
|
||||
timestamp);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_set_scaling_mode(..., int mode)
|
||||
* All buffers queued after this call will be associated with the scaling mode
|
||||
* specified.
|
||||
*/
|
||||
static inline int native_window_set_scaling_mode(
|
||||
struct ANativeWindow* window,
|
||||
int mode)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
|
||||
mode);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_api_connect(..., int api)
|
||||
* connects an API to this window. only one API can be connected at a time.
|
||||
* Returns -EINVAL if for some reason the window cannot be connected, which
|
||||
* can happen if it's connected to some other API.
|
||||
*/
|
||||
static inline int native_window_api_connect(
|
||||
struct ANativeWindow* window, int api)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_api_disconnect(..., int api)
|
||||
* disconnect the API from this window.
|
||||
* An error is returned if for instance the window wasn't connected in the
|
||||
* first place.
|
||||
*/
|
||||
static inline int native_window_api_disconnect(
|
||||
struct ANativeWindow* window, int api)
|
||||
{
|
||||
return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
|
||||
}
|
||||
|
||||
/*
|
||||
* native_window_dequeue_buffer_and_wait(...)
|
||||
* Dequeue a buffer and wait on the fence associated with that buffer. The
|
||||
* buffer may safely be accessed immediately upon this function returning. An
|
||||
* error is returned if either of the dequeue or the wait operations fail.
|
||||
*/
|
||||
static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
|
||||
struct ANativeWindowBuffer** anb) {
|
||||
return anw->dequeueBuffer_DEPRECATED(anw, anb);
|
||||
}
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_ANDROID_NATIVES_H
|
||||
#define ANDROID_ANDROID_NATIVES_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hardware/gralloc.h>
|
||||
#include <system/window.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/* FIXME: this is legacy for pixmaps */
|
||||
typedef struct egl_native_pixmap_t
|
||||
{
|
||||
int32_t version; /* must be 32 */
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t stride;
|
||||
uint8_t* data;
|
||||
uint8_t format;
|
||||
uint8_t rfu[3];
|
||||
union {
|
||||
uint32_t compressedFormat;
|
||||
int32_t vstride;
|
||||
};
|
||||
int32_t reserved;
|
||||
} egl_native_pixmap_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* This helper class turns a ANativeXXX object type into a C++
|
||||
* reference-counted object; with proper type conversions.
|
||||
*/
|
||||
template <typename NATIVE_TYPE, typename TYPE, typename REF>
|
||||
class ANativeObjectBase : public NATIVE_TYPE, public REF
|
||||
{
|
||||
public:
|
||||
// Disambiguate between the incStrong in REF and NATIVE_TYPE
|
||||
void incStrong(const void* id) const {
|
||||
REF::incStrong(id);
|
||||
}
|
||||
void decStrong(const void* id) const {
|
||||
REF::decStrong(id);
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef ANativeObjectBase<NATIVE_TYPE, TYPE, REF> BASE;
|
||||
ANativeObjectBase() : NATIVE_TYPE(), REF() {
|
||||
NATIVE_TYPE::common.incRef = incRef;
|
||||
NATIVE_TYPE::common.decRef = decRef;
|
||||
}
|
||||
static inline TYPE* getSelf(NATIVE_TYPE* self) {
|
||||
return static_cast<TYPE*>(self);
|
||||
}
|
||||
static inline TYPE const* getSelf(NATIVE_TYPE const* self) {
|
||||
return static_cast<TYPE const *>(self);
|
||||
}
|
||||
static inline TYPE* getSelf(android_native_base_t* base) {
|
||||
return getSelf(reinterpret_cast<NATIVE_TYPE*>(base));
|
||||
}
|
||||
static inline TYPE const * getSelf(android_native_base_t const* base) {
|
||||
return getSelf(reinterpret_cast<NATIVE_TYPE const*>(base));
|
||||
}
|
||||
static void incRef(android_native_base_t* base) {
|
||||
ANativeObjectBase* self = getSelf(base);
|
||||
self->incStrong(self);
|
||||
}
|
||||
static void decRef(android_native_base_t* base) {
|
||||
ANativeObjectBase* self = getSelf(base);
|
||||
self->decStrong(self);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
#endif // __cplusplus
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* ANDROID_ANDROID_NATIVES_H */
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UI_DISPLAY_INFO_H
|
||||
#define ANDROID_UI_DISPLAY_INFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/PixelFormat.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct DisplayInfo {
|
||||
uint32_t w;
|
||||
uint32_t h;
|
||||
float xdpi;
|
||||
float ydpi;
|
||||
float fps;
|
||||
float density;
|
||||
uint8_t orientation;
|
||||
bool secure;
|
||||
uint8_t reserved[2];
|
||||
// TODO: this needs to go away (currently needed only by webkit)
|
||||
PixelFormatInfo pixelFormatInfo;
|
||||
};
|
||||
|
||||
/* Display orientations as defined in Surface.java and ISurfaceComposer.h. */
|
||||
enum {
|
||||
DISPLAY_ORIENTATION_0 = 0,
|
||||
DISPLAY_ORIENTATION_90 = 1,
|
||||
DISPLAY_ORIENTATION_180 = 2,
|
||||
DISPLAY_ORIENTATION_270 = 3
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_COMPOSER_DISPLAY_INFO_H
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_FENCE_H
|
||||
#define ANDROID_FENCE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/PixelFormat.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Timers.h>
|
||||
|
||||
struct ANativeWindowBuffer;
|
||||
|
||||
namespace android {
|
||||
|
||||
// ===========================================================================
|
||||
// Fence
|
||||
// ===========================================================================
|
||||
|
||||
class Fence
|
||||
: public LightRefBase<Fence>, public Flattenable
|
||||
{
|
||||
public:
|
||||
static const sp<Fence> NO_FENCE;
|
||||
|
||||
// TIMEOUT_NEVER may be passed to the wait method to indicate that it
|
||||
// should wait indefinitely for the fence to signal.
|
||||
enum { TIMEOUT_NEVER = -1 };
|
||||
|
||||
// Construct a new Fence object with an invalid file descriptor. This
|
||||
// should be done when the Fence object will be set up by unflattening
|
||||
// serialized data.
|
||||
Fence();
|
||||
|
||||
// Construct a new Fence object to manage a given fence file descriptor.
|
||||
// When the new Fence object is destructed the file descriptor will be
|
||||
// closed.
|
||||
Fence(int fenceFd);
|
||||
|
||||
// Check whether the Fence has an open fence file descriptor. Most Fence
|
||||
// methods treat an invalid file descriptor just like a valid fence that
|
||||
// is already signalled, so using this is usually not necessary.
|
||||
bool isValid() const { return mFenceFd != -1; }
|
||||
|
||||
// wait waits for up to timeout milliseconds for the fence to signal. If
|
||||
// the fence signals then NO_ERROR is returned. If the timeout expires
|
||||
// before the fence signals then -ETIME is returned. A timeout of
|
||||
// TIMEOUT_NEVER may be used to indicate that the call should wait
|
||||
// indefinitely for the fence to signal.
|
||||
status_t wait(unsigned int timeout);
|
||||
|
||||
// waitForever is a convenience function for waiting forever for a fence to
|
||||
// signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the
|
||||
// system log and fence state to the kernel log if the wait lasts longer
|
||||
// than a warning timeout.
|
||||
// The logname argument should be a string identifying
|
||||
// the caller and will be included in the log message.
|
||||
status_t waitForever(const char* logname);
|
||||
|
||||
// merge combines two Fence objects, creating a new Fence object that
|
||||
// becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is
|
||||
// destroyed before it becomes signaled). The name argument specifies the
|
||||
// human-readable name to associated with the new Fence object.
|
||||
static sp<Fence> merge(const String8& name, const sp<Fence>& f1,
|
||||
const sp<Fence>& f2);
|
||||
|
||||
// Return a duplicate of the fence file descriptor. The caller is
|
||||
// responsible for closing the returned file descriptor. On error, -1 will
|
||||
// be returned and errno will indicate the problem.
|
||||
int dup() const;
|
||||
|
||||
// getSignalTime returns the system monotonic clock time at which the
|
||||
// fence transitioned to the signaled state. If the fence is not signaled
|
||||
// then INT64_MAX is returned. If the fence is invalid or if an error
|
||||
// occurs then -1 is returned.
|
||||
nsecs_t getSignalTime() const;
|
||||
|
||||
// Flattenable interface
|
||||
size_t getFlattenedSize() const;
|
||||
size_t getFdCount() const;
|
||||
status_t flatten(void* buffer, size_t size,
|
||||
int fds[], size_t count) const;
|
||||
status_t unflatten(void const* buffer, size_t size,
|
||||
int fds[], size_t count);
|
||||
|
||||
private:
|
||||
// Only allow instantiation using ref counting.
|
||||
friend class LightRefBase<Fence>;
|
||||
virtual ~Fence();
|
||||
|
||||
// Disallow copying
|
||||
Fence(const Fence& rhs);
|
||||
Fence& operator = (const Fence& rhs);
|
||||
const Fence& operator = (const Fence& rhs) const;
|
||||
|
||||
int mFenceFd;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_FENCE_H
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GRAPHIC_BUFFER_H
|
||||
#define ANDROID_GRAPHIC_BUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/PixelFormat.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/RefBase.h>
|
||||
|
||||
|
||||
struct ANativeWindowBuffer;
|
||||
|
||||
namespace android {
|
||||
|
||||
class GraphicBufferMapper;
|
||||
|
||||
// ===========================================================================
|
||||
// GraphicBuffer
|
||||
// ===========================================================================
|
||||
|
||||
class GraphicBuffer
|
||||
: public ANativeObjectBase< ANativeWindowBuffer, GraphicBuffer, RefBase >,
|
||||
public Flattenable
|
||||
{
|
||||
public:
|
||||
|
||||
enum {
|
||||
USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
|
||||
USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
|
||||
USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
|
||||
USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
|
||||
|
||||
USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
|
||||
USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
|
||||
USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
|
||||
USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
|
||||
|
||||
USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
|
||||
|
||||
USAGE_PROTECTED = GRALLOC_USAGE_PROTECTED,
|
||||
|
||||
USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
|
||||
USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
|
||||
USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
|
||||
USAGE_HW_COMPOSER = GRALLOC_USAGE_HW_COMPOSER,
|
||||
USAGE_HW_VIDEO_ENCODER = GRALLOC_USAGE_HW_VIDEO_ENCODER,
|
||||
USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
|
||||
};
|
||||
|
||||
GraphicBuffer();
|
||||
|
||||
// creates w * h buffer
|
||||
GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage);
|
||||
|
||||
// create a buffer from an existing handle
|
||||
GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
|
||||
uint32_t stride, native_handle_t* handle, bool keepOwnership);
|
||||
|
||||
// create a buffer from an existing ANativeWindowBuffer
|
||||
GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
|
||||
|
||||
// return status
|
||||
status_t initCheck() const;
|
||||
|
||||
uint32_t getWidth() const { return width; }
|
||||
uint32_t getHeight() const { return height; }
|
||||
uint32_t getStride() const { return stride; }
|
||||
uint32_t getUsage() const { return usage; }
|
||||
PixelFormat getPixelFormat() const { return format; }
|
||||
Rect getBounds() const { return Rect(width, height); }
|
||||
|
||||
status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage);
|
||||
|
||||
status_t lock(uint32_t usage, void** vaddr);
|
||||
status_t lock(uint32_t usage, const Rect& rect, void** vaddr);
|
||||
// For HAL_PIXEL_FORMAT_YCbCr_420_888
|
||||
status_t lockYCbCr(uint32_t usage, android_ycbcr *ycbcr);
|
||||
status_t lockYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr);
|
||||
status_t unlock();
|
||||
|
||||
ANativeWindowBuffer* getNativeBuffer() const;
|
||||
|
||||
void setIndex(int index);
|
||||
int getIndex() const;
|
||||
|
||||
// for debugging
|
||||
static void dumpAllocationsToSystemLog();
|
||||
|
||||
private:
|
||||
virtual ~GraphicBuffer();
|
||||
|
||||
enum {
|
||||
ownNone = 0,
|
||||
ownHandle = 1,
|
||||
ownData = 2,
|
||||
};
|
||||
|
||||
inline const GraphicBufferMapper& getBufferMapper() const {
|
||||
return mBufferMapper;
|
||||
}
|
||||
inline GraphicBufferMapper& getBufferMapper() {
|
||||
return mBufferMapper;
|
||||
}
|
||||
uint8_t mOwner;
|
||||
|
||||
private:
|
||||
friend class Surface;
|
||||
friend class BpSurface;
|
||||
friend class BnSurface;
|
||||
friend class LightRefBase<GraphicBuffer>;
|
||||
GraphicBuffer(const GraphicBuffer& rhs);
|
||||
GraphicBuffer& operator = (const GraphicBuffer& rhs);
|
||||
const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
|
||||
|
||||
status_t initSize(uint32_t w, uint32_t h, PixelFormat format,
|
||||
uint32_t usage);
|
||||
|
||||
void free_handle();
|
||||
|
||||
// Flattenable interface
|
||||
size_t getFlattenedSize() const;
|
||||
size_t getFdCount() const;
|
||||
status_t flatten(void* buffer, size_t size,
|
||||
int fds[], size_t count) const;
|
||||
status_t unflatten(void const* buffer, size_t size,
|
||||
int fds[], size_t count);
|
||||
|
||||
|
||||
GraphicBufferMapper& mBufferMapper;
|
||||
ssize_t mInitCheck;
|
||||
int mIndex;
|
||||
|
||||
// If we're wrapping another buffer then this reference will make sure it
|
||||
// doesn't get freed.
|
||||
sp<ANativeWindowBuffer> mWrappedBuffer;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GRAPHIC_BUFFER_H
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
|
||||
// Pixel formats used across the system.
|
||||
// These formats might not all be supported by all renderers, for instance
|
||||
// skia or SurfaceFlinger are not required to support all of these formats
|
||||
// (either as source or destination)
|
||||
|
||||
|
||||
#ifndef UI_PIXELFORMAT_H
|
||||
#define UI_PIXELFORMAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <utils/Errors.h>
|
||||
#include <hardware/hardware.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
enum {
|
||||
//
|
||||
// these constants need to match those
|
||||
// in graphics/PixelFormat.java & pixelflinger/format.h
|
||||
//
|
||||
PIXEL_FORMAT_UNKNOWN = 0,
|
||||
PIXEL_FORMAT_NONE = 0,
|
||||
|
||||
// logical pixel formats used by the SurfaceFlinger -----------------------
|
||||
PIXEL_FORMAT_CUSTOM = -4,
|
||||
// Custom pixel-format described by a PixelFormatInfo structure
|
||||
|
||||
PIXEL_FORMAT_TRANSLUCENT = -3,
|
||||
// System chooses a format that supports translucency (many alpha bits)
|
||||
|
||||
PIXEL_FORMAT_TRANSPARENT = -2,
|
||||
// System chooses a format that supports transparency
|
||||
// (at least 1 alpha bit)
|
||||
|
||||
PIXEL_FORMAT_OPAQUE = -1,
|
||||
// System chooses an opaque format (no alpha bits required)
|
||||
|
||||
// real pixel formats supported for rendering -----------------------------
|
||||
|
||||
PIXEL_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA
|
||||
PIXEL_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0
|
||||
PIXEL_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB
|
||||
PIXEL_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, // 16-bit RGB
|
||||
PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA
|
||||
PIXEL_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB
|
||||
PIXEL_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB
|
||||
PIXEL_FORMAT_A_8 = 8, // 8-bit A
|
||||
};
|
||||
|
||||
typedef int32_t PixelFormat;
|
||||
|
||||
struct PixelFormatInfo {
|
||||
enum {
|
||||
INDEX_ALPHA = 0,
|
||||
INDEX_RED = 1,
|
||||
INDEX_GREEN = 2,
|
||||
INDEX_BLUE = 3
|
||||
};
|
||||
|
||||
enum { // components
|
||||
ALPHA = 1,
|
||||
RGB = 2,
|
||||
RGBA = 3,
|
||||
L = 4,
|
||||
LA = 5,
|
||||
OTHER = 0xFF
|
||||
};
|
||||
|
||||
struct szinfo {
|
||||
uint8_t h;
|
||||
uint8_t l;
|
||||
};
|
||||
|
||||
inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
|
||||
size_t getScanlineSize(unsigned int width) const;
|
||||
size_t getSize(size_t ci) const {
|
||||
return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0;
|
||||
}
|
||||
size_t version;
|
||||
PixelFormat format;
|
||||
size_t bytesPerPixel;
|
||||
size_t bitsPerPixel;
|
||||
union {
|
||||
szinfo cinfo[4];
|
||||
struct {
|
||||
uint8_t h_alpha;
|
||||
uint8_t l_alpha;
|
||||
uint8_t h_red;
|
||||
uint8_t l_red;
|
||||
uint8_t h_green;
|
||||
uint8_t l_green;
|
||||
uint8_t h_blue;
|
||||
uint8_t l_blue;
|
||||
};
|
||||
};
|
||||
uint8_t components;
|
||||
uint8_t reserved0[3];
|
||||
uint32_t reserved1;
|
||||
};
|
||||
|
||||
// Consider caching the results of these functions are they're not
|
||||
// guaranteed to be fast.
|
||||
ssize_t bytesPerPixel(PixelFormat format);
|
||||
ssize_t bitsPerPixel(PixelFormat format);
|
||||
status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info);
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // UI_PIXELFORMAT_H
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UI_POINT
|
||||
#define ANDROID_UI_POINT
|
||||
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class Point : public LightFlattenablePod<Point>
|
||||
{
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
// Default constructor doesn't initialize the Point
|
||||
inline Point() {
|
||||
}
|
||||
inline Point(int x, int y) : x(x), y(y) {
|
||||
}
|
||||
|
||||
inline bool operator == (const Point& rhs) const {
|
||||
return (x == rhs.x) && (y == rhs.y);
|
||||
}
|
||||
inline bool operator != (const Point& rhs) const {
|
||||
return !operator == (rhs);
|
||||
}
|
||||
|
||||
inline bool isOrigin() const {
|
||||
return !(x|y);
|
||||
}
|
||||
|
||||
// operator < defines an order which allows to use points in sorted
|
||||
// vectors.
|
||||
bool operator < (const Point& rhs) const {
|
||||
return y<rhs.y || (y==rhs.y && x<rhs.x);
|
||||
}
|
||||
|
||||
inline Point& operator - () {
|
||||
x = -x;
|
||||
y = -y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Point& operator += (const Point& rhs) {
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
return *this;
|
||||
}
|
||||
inline Point& operator -= (const Point& rhs) {
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const Point operator + (const Point& rhs) const {
|
||||
const Point result(x+rhs.x, y+rhs.y);
|
||||
return result;
|
||||
}
|
||||
const Point operator - (const Point& rhs) const {
|
||||
const Point result(x-rhs.x, y-rhs.y);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
ANDROID_BASIC_TYPES_TRAITS(Point)
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_POINT
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UI_RECT
|
||||
#define ANDROID_UI_RECT
|
||||
|
||||
#include <utils/Flattenable.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
#include <ui/Point.h>
|
||||
|
||||
#include <android/rect.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class Rect : public ARect, public LightFlattenablePod<Rect>
|
||||
{
|
||||
public:
|
||||
typedef ARect::value_type value_type;
|
||||
|
||||
// we don't provide copy-ctor and operator= on purpose
|
||||
// because we want the compiler generated versions
|
||||
|
||||
inline Rect() {
|
||||
}
|
||||
inline Rect(int32_t w, int32_t h) {
|
||||
left = top = 0; right = w; bottom = h;
|
||||
}
|
||||
inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) {
|
||||
left = l; top = t; right = r; bottom = b;
|
||||
}
|
||||
inline Rect(const Point& lt, const Point& rb) {
|
||||
left = lt.x; top = lt.y; right = rb.x; bottom = rb.y;
|
||||
}
|
||||
|
||||
void makeInvalid();
|
||||
|
||||
inline void clear() {
|
||||
left = top = right = bottom = 0;
|
||||
}
|
||||
|
||||
// a valid rectangle has a non negative width and height
|
||||
inline bool isValid() const {
|
||||
return (width()>=0) && (height()>=0);
|
||||
}
|
||||
|
||||
// an empty rect has a zero width or height, or is invalid
|
||||
inline bool isEmpty() const {
|
||||
return (width()<=0) || (height()<=0);
|
||||
}
|
||||
|
||||
inline void set(const Rect& rhs) {
|
||||
operator = (rhs);
|
||||
}
|
||||
|
||||
// rectangle's width
|
||||
inline int32_t getWidth() const {
|
||||
return right-left;
|
||||
}
|
||||
|
||||
// rectangle's height
|
||||
inline int32_t getHeight() const {
|
||||
return bottom-top;
|
||||
}
|
||||
|
||||
inline Rect getBounds() const {
|
||||
return Rect(right-left, bottom-top);
|
||||
}
|
||||
|
||||
inline int32_t width() const { return getWidth(); }
|
||||
inline int32_t height() const { return getHeight(); }
|
||||
|
||||
void setLeftTop(const Point& lt) {
|
||||
left = lt.x;
|
||||
top = lt.y;
|
||||
}
|
||||
|
||||
void setRightBottom(const Point& rb) {
|
||||
right = rb.x;
|
||||
bottom = rb.y;
|
||||
}
|
||||
|
||||
// the following 4 functions return the 4 corners of the rect as Point
|
||||
Point leftTop() const {
|
||||
return Point(left, top);
|
||||
}
|
||||
Point rightBottom() const {
|
||||
return Point(right, bottom);
|
||||
}
|
||||
Point rightTop() const {
|
||||
return Point(right, top);
|
||||
}
|
||||
Point leftBottom() const {
|
||||
return Point(left, bottom);
|
||||
}
|
||||
|
||||
// comparisons
|
||||
inline bool operator == (const Rect& rhs) const {
|
||||
return (left == rhs.left) && (top == rhs.top) &&
|
||||
(right == rhs.right) && (bottom == rhs.bottom);
|
||||
}
|
||||
|
||||
inline bool operator != (const Rect& rhs) const {
|
||||
return !operator == (rhs);
|
||||
}
|
||||
|
||||
// operator < defines an order which allows to use rectangles in sorted
|
||||
// vectors.
|
||||
bool operator < (const Rect& rhs) const;
|
||||
|
||||
Rect& offsetToOrigin() {
|
||||
right -= left;
|
||||
bottom -= top;
|
||||
left = top = 0;
|
||||
return *this;
|
||||
}
|
||||
Rect& offsetTo(const Point& p) {
|
||||
return offsetTo(p.x, p.y);
|
||||
}
|
||||
Rect& offsetBy(const Point& dp) {
|
||||
return offsetBy(dp.x, dp.y);
|
||||
}
|
||||
Rect& operator += (const Point& rhs) {
|
||||
return offsetBy(rhs.x, rhs.y);
|
||||
}
|
||||
Rect& operator -= (const Point& rhs) {
|
||||
return offsetBy(-rhs.x, -rhs.y);
|
||||
}
|
||||
const Rect operator + (const Point& rhs) const;
|
||||
const Rect operator - (const Point& rhs) const;
|
||||
|
||||
void translate(int32_t dx, int32_t dy) { // legacy, don't use.
|
||||
offsetBy(dx, dy);
|
||||
}
|
||||
|
||||
Rect& offsetTo(int32_t x, int32_t y);
|
||||
Rect& offsetBy(int32_t x, int32_t y);
|
||||
bool intersect(const Rect& with, Rect* result) const;
|
||||
|
||||
// Create a new Rect by transforming this one using a graphics HAL
|
||||
// transform. This rectangle is defined in a coordinate space starting at
|
||||
// the origin and extending to (width, height). If the transform includes
|
||||
// a ROT90 then the output rectangle is defined in a space extending to
|
||||
// (height, width). Otherwise the output rectangle is in the same space as
|
||||
// the input.
|
||||
Rect transform(uint32_t xform, int32_t width, int32_t height) const;
|
||||
};
|
||||
|
||||
ANDROID_BASIC_TYPES_TRAITS(Rect)
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_RECT
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UI_REGION_H
|
||||
#define ANDROID_UI_REGION_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <utils/Vector.h>
|
||||
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Flattenable.h>
|
||||
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class SharedBuffer;
|
||||
class String8;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
class Region : public LightFlattenable<Region>
|
||||
{
|
||||
public:
|
||||
Region();
|
||||
Region(const Region& rhs);
|
||||
explicit Region(const Rect& rhs);
|
||||
~Region();
|
||||
|
||||
static Region createTJunctionFreeRegion(const Region& r);
|
||||
|
||||
Region& operator = (const Region& rhs);
|
||||
|
||||
inline bool isEmpty() const { return getBounds().isEmpty(); }
|
||||
inline bool isRect() const { return mStorage.size() == 1; }
|
||||
|
||||
inline Rect getBounds() const { return mStorage[mStorage.size() - 1]; }
|
||||
inline Rect bounds() const { return getBounds(); }
|
||||
|
||||
// the region becomes its bounds
|
||||
Region& makeBoundsSelf();
|
||||
|
||||
void clear();
|
||||
void set(const Rect& r);
|
||||
void set(uint32_t w, uint32_t h);
|
||||
|
||||
Region& orSelf(const Rect& rhs);
|
||||
Region& xorSelf(const Rect& rhs);
|
||||
Region& andSelf(const Rect& rhs);
|
||||
Region& subtractSelf(const Rect& rhs);
|
||||
|
||||
// boolean operators, applied on this
|
||||
Region& orSelf(const Region& rhs);
|
||||
Region& xorSelf(const Region& rhs);
|
||||
Region& andSelf(const Region& rhs);
|
||||
Region& subtractSelf(const Region& rhs);
|
||||
|
||||
// boolean operators
|
||||
const Region merge(const Rect& rhs) const;
|
||||
const Region mergeExclusive(const Rect& rhs) const;
|
||||
const Region intersect(const Rect& rhs) const;
|
||||
const Region subtract(const Rect& rhs) const;
|
||||
|
||||
// boolean operators
|
||||
const Region merge(const Region& rhs) const;
|
||||
const Region mergeExclusive(const Region& rhs) const;
|
||||
const Region intersect(const Region& rhs) const;
|
||||
const Region subtract(const Region& rhs) const;
|
||||
|
||||
// these translate rhs first
|
||||
Region& translateSelf(int dx, int dy);
|
||||
Region& orSelf(const Region& rhs, int dx, int dy);
|
||||
Region& xorSelf(const Region& rhs, int dx, int dy);
|
||||
Region& andSelf(const Region& rhs, int dx, int dy);
|
||||
Region& subtractSelf(const Region& rhs, int dx, int dy);
|
||||
|
||||
// these translate rhs first
|
||||
const Region translate(int dx, int dy) const;
|
||||
const Region merge(const Region& rhs, int dx, int dy) const;
|
||||
const Region mergeExclusive(const Region& rhs, int dx, int dy) const;
|
||||
const Region intersect(const Region& rhs, int dx, int dy) const;
|
||||
const Region subtract(const Region& rhs, int dx, int dy) const;
|
||||
|
||||
// convenience operators overloads
|
||||
inline const Region operator | (const Region& rhs) const;
|
||||
inline const Region operator ^ (const Region& rhs) const;
|
||||
inline const Region operator & (const Region& rhs) const;
|
||||
inline const Region operator - (const Region& rhs) const;
|
||||
inline const Region operator + (const Point& pt) const;
|
||||
|
||||
inline Region& operator |= (const Region& rhs);
|
||||
inline Region& operator ^= (const Region& rhs);
|
||||
inline Region& operator &= (const Region& rhs);
|
||||
inline Region& operator -= (const Region& rhs);
|
||||
inline Region& operator += (const Point& pt);
|
||||
|
||||
|
||||
// returns true if the regions share the same underlying storage
|
||||
bool isTriviallyEqual(const Region& region) const;
|
||||
|
||||
|
||||
/* various ways to access the rectangle list */
|
||||
|
||||
|
||||
// STL-like iterators
|
||||
typedef Rect const* const_iterator;
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
||||
// returns an array of rect which has the same life-time has this
|
||||
// Region object.
|
||||
Rect const* getArray(size_t* count) const;
|
||||
|
||||
// returns a SharedBuffer as well as the number of rects.
|
||||
// ownership is transfered to the caller.
|
||||
// the caller must call SharedBuffer::release() to free the memory.
|
||||
SharedBuffer const* getSharedBuffer(size_t* count) const;
|
||||
|
||||
/* no user serviceable parts here... */
|
||||
|
||||
// add a rectangle to the internal list. This rectangle must
|
||||
// be sorted in Y and X and must not make the region invalid.
|
||||
void addRectUnchecked(int l, int t, int r, int b);
|
||||
|
||||
inline bool isFixedSize() const { return false; }
|
||||
size_t getSize() const;
|
||||
status_t flatten(void* buffer) const;
|
||||
status_t unflatten(void const* buffer, size_t size);
|
||||
|
||||
void dump(String8& out, const char* what, uint32_t flags=0) const;
|
||||
void dump(const char* what, uint32_t flags=0) const;
|
||||
|
||||
private:
|
||||
class rasterizer;
|
||||
friend class rasterizer;
|
||||
|
||||
Region& operationSelf(const Rect& r, int op);
|
||||
Region& operationSelf(const Region& r, int op);
|
||||
Region& operationSelf(const Region& r, int dx, int dy, int op);
|
||||
const Region operation(const Rect& rhs, int op) const;
|
||||
const Region operation(const Region& rhs, int op) const;
|
||||
const Region operation(const Region& rhs, int dx, int dy, int op) const;
|
||||
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Region& rhs, int dx, int dy);
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Rect& rhs, int dx, int dy);
|
||||
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Region& rhs);
|
||||
static void boolean_operation(int op, Region& dst,
|
||||
const Region& lhs, const Rect& rhs);
|
||||
|
||||
static void translate(Region& reg, int dx, int dy);
|
||||
static void translate(Region& dst, const Region& reg, int dx, int dy);
|
||||
|
||||
static bool validate(const Region& reg,
|
||||
const char* name, bool silent = false);
|
||||
|
||||
// mStorage is a (manually) sorted array of Rects describing the region
|
||||
// with an extra Rect as the last element which is set to the
|
||||
// bounds of the region. However, if the region is
|
||||
// a simple Rect then mStorage contains only that rect.
|
||||
Vector<Rect> mStorage;
|
||||
};
|
||||
|
||||
|
||||
const Region Region::operator | (const Region& rhs) const {
|
||||
return merge(rhs);
|
||||
}
|
||||
const Region Region::operator ^ (const Region& rhs) const {
|
||||
return mergeExclusive(rhs);
|
||||
}
|
||||
const Region Region::operator & (const Region& rhs) const {
|
||||
return intersect(rhs);
|
||||
}
|
||||
const Region Region::operator - (const Region& rhs) const {
|
||||
return subtract(rhs);
|
||||
}
|
||||
const Region Region::operator + (const Point& pt) const {
|
||||
return translate(pt.x, pt.y);
|
||||
}
|
||||
|
||||
|
||||
Region& Region::operator |= (const Region& rhs) {
|
||||
return orSelf(rhs);
|
||||
}
|
||||
Region& Region::operator ^= (const Region& rhs) {
|
||||
return xorSelf(rhs);
|
||||
}
|
||||
Region& Region::operator &= (const Region& rhs) {
|
||||
return andSelf(rhs);
|
||||
}
|
||||
Region& Region::operator -= (const Region& rhs) {
|
||||
return subtractSelf(rhs);
|
||||
}
|
||||
Region& Region::operator += (const Point& pt) {
|
||||
return translateSelf(pt.x, pt.y);
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_UI_REGION_H
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_ANDROID_THREADS_H
|
||||
#define _LIBS_UTILS_ANDROID_THREADS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <utils/ThreadDefs.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C API
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Create and run a new thread.
|
||||
extern int androidCreateThread(android_thread_func_t, void *);
|
||||
|
||||
// Create thread with lots of parameters
|
||||
extern int androidCreateThreadEtc(android_thread_func_t entryFunction,
|
||||
void *userData,
|
||||
const char* threadName,
|
||||
int32_t threadPriority,
|
||||
size_t threadStackSize,
|
||||
android_thread_id_t *threadId);
|
||||
|
||||
// Get some sort of unique identifier for the current thread.
|
||||
extern android_thread_id_t androidGetThreadId();
|
||||
|
||||
// Low-level thread creation -- never creates threads that can
|
||||
// interact with the Java VM.
|
||||
extern int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
|
||||
void *userData,
|
||||
const char* threadName,
|
||||
int32_t threadPriority,
|
||||
size_t threadStackSize,
|
||||
android_thread_id_t *threadId);
|
||||
|
||||
// set the same of the running thread
|
||||
extern void androidSetThreadName(const char* name);
|
||||
|
||||
// Used by the Java Runtime to control how threads are created, so that
|
||||
// they can be proper and lovely Java threads.
|
||||
typedef int (*android_create_thread_fn)(android_thread_func_t entryFunction,
|
||||
void *userData,
|
||||
const char* threadName,
|
||||
int32_t threadPriority,
|
||||
size_t threadStackSize,
|
||||
android_thread_id_t *threadId);
|
||||
|
||||
extern void androidSetCreateThreadFunc(android_create_thread_fn func);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Extra functions working with raw pids.
|
||||
|
||||
// Get pid for the current thread.
|
||||
extern pid_t androidGetTid();
|
||||
|
||||
#ifdef HAVE_ANDROID_OS
|
||||
// Change the priority AND scheduling group of a particular thread. The priority
|
||||
// should be one of the ANDROID_PRIORITY constants. Returns INVALID_OPERATION
|
||||
// if the priority set failed, else another value if just the group set failed;
|
||||
// in either case errno is set. Thread ID zero means current thread.
|
||||
extern int androidSetThreadPriority(pid_t tid, int prio);
|
||||
|
||||
// Get the current priority of a particular thread. Returns one of the
|
||||
// ANDROID_PRIORITY constants or a negative result in case of error.
|
||||
extern int androidGetThreadPriority(pid_t tid);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// C++ API
|
||||
#ifdef __cplusplus
|
||||
namespace android {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Create and run a new thread.
|
||||
inline bool createThread(thread_func_t f, void *a) {
|
||||
return androidCreateThread(f, a) ? true : false;
|
||||
}
|
||||
|
||||
// Create thread with lots of parameters
|
||||
inline bool createThreadEtc(thread_func_t entryFunction,
|
||||
void *userData,
|
||||
const char* threadName = "android:unnamed_thread",
|
||||
int32_t threadPriority = PRIORITY_DEFAULT,
|
||||
size_t threadStackSize = 0,
|
||||
thread_id_t *threadId = 0)
|
||||
{
|
||||
return androidCreateThreadEtc(entryFunction, userData, threadName,
|
||||
threadPriority, threadStackSize, threadId) ? true : false;
|
||||
}
|
||||
|
||||
// Get some sort of unique identifier for the current thread.
|
||||
inline thread_id_t getThreadId() {
|
||||
return androidGetThreadId();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
#endif // __cplusplus
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif // _LIBS_UTILS_ANDROID_THREADS_H
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UTILS_ATOMIC_H
|
||||
#define ANDROID_UTILS_ATOMIC_H
|
||||
|
||||
#include <cutils/atomic.h>
|
||||
|
||||
#endif // ANDROID_UTILS_ATOMIC_H
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_CONDITION_H
|
||||
#define _LIBS_UTILS_CONDITION_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/Mutex.h>
|
||||
#include <utils/Timers.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Condition variable class. The implementation is system-dependent.
|
||||
*
|
||||
* Condition variables are paired up with mutexes. Lock the mutex,
|
||||
* call wait(), then either re-wait() if things aren't quite what you want,
|
||||
* or unlock the mutex and continue. All threads calling wait() must
|
||||
* use the same mutex for a given Condition.
|
||||
*/
|
||||
class Condition {
|
||||
public:
|
||||
enum {
|
||||
PRIVATE = 0,
|
||||
SHARED = 1
|
||||
};
|
||||
|
||||
enum WakeUpType {
|
||||
WAKE_UP_ONE = 0,
|
||||
WAKE_UP_ALL = 1
|
||||
};
|
||||
|
||||
Condition();
|
||||
Condition(int type);
|
||||
~Condition();
|
||||
// Wait on the condition variable. Lock the mutex before calling.
|
||||
status_t wait(Mutex& mutex);
|
||||
// same with relative timeout
|
||||
status_t waitRelative(Mutex& mutex, nsecs_t reltime);
|
||||
// Signal the condition variable, allowing one thread to continue.
|
||||
void signal();
|
||||
// Signal the condition variable, allowing one or all threads to continue.
|
||||
void signal(WakeUpType type) {
|
||||
if (type == WAKE_UP_ONE) {
|
||||
signal();
|
||||
} else {
|
||||
broadcast();
|
||||
}
|
||||
}
|
||||
// Signal the condition variable, allowing all threads to continue.
|
||||
void broadcast();
|
||||
|
||||
private:
|
||||
#if defined(HAVE_PTHREADS)
|
||||
pthread_cond_t mCond;
|
||||
#else
|
||||
void* mState;
|
||||
#endif
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
|
||||
inline Condition::Condition() {
|
||||
pthread_cond_init(&mCond, NULL);
|
||||
}
|
||||
inline Condition::Condition(int type) {
|
||||
if (type == SHARED) {
|
||||
pthread_condattr_t attr;
|
||||
pthread_condattr_init(&attr);
|
||||
pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_cond_init(&mCond, &attr);
|
||||
pthread_condattr_destroy(&attr);
|
||||
} else {
|
||||
pthread_cond_init(&mCond, NULL);
|
||||
}
|
||||
}
|
||||
inline Condition::~Condition() {
|
||||
pthread_cond_destroy(&mCond);
|
||||
}
|
||||
inline status_t Condition::wait(Mutex& mutex) {
|
||||
return -pthread_cond_wait(&mCond, &mutex.mMutex);
|
||||
}
|
||||
inline status_t Condition::waitRelative(Mutex& mutex, nsecs_t reltime) {
|
||||
#if defined(HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE)
|
||||
struct timespec ts;
|
||||
ts.tv_sec = reltime/1000000000;
|
||||
ts.tv_nsec = reltime%1000000000;
|
||||
return -pthread_cond_timedwait_relative_np(&mCond, &mutex.mMutex, &ts);
|
||||
#else // HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE
|
||||
struct timespec ts;
|
||||
#if defined(HAVE_POSIX_CLOCKS)
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
#else // HAVE_POSIX_CLOCKS
|
||||
// we don't support the clocks here.
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
ts.tv_sec = t.tv_sec;
|
||||
ts.tv_nsec= t.tv_usec*1000;
|
||||
#endif // HAVE_POSIX_CLOCKS
|
||||
ts.tv_sec += reltime/1000000000;
|
||||
ts.tv_nsec+= reltime%1000000000;
|
||||
if (ts.tv_nsec >= 1000000000) {
|
||||
ts.tv_nsec -= 1000000000;
|
||||
ts.tv_sec += 1;
|
||||
}
|
||||
return -pthread_cond_timedwait(&mCond, &mutex.mMutex, &ts);
|
||||
#endif // HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE
|
||||
}
|
||||
inline void Condition::signal() {
|
||||
pthread_cond_signal(&mCond);
|
||||
}
|
||||
inline void Condition::broadcast() {
|
||||
pthread_cond_broadcast(&mCond);
|
||||
}
|
||||
|
||||
#endif // HAVE_PTHREADS
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // _LIBS_UTILS_CONDITON_H
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_ERRORS_H
|
||||
#define ANDROID_ERRORS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
// use this type to return error codes
|
||||
#ifdef HAVE_MS_C_RUNTIME
|
||||
typedef int status_t;
|
||||
#else
|
||||
typedef int32_t status_t;
|
||||
#endif
|
||||
|
||||
/* the MS C runtime lacks a few error codes */
|
||||
|
||||
/*
|
||||
* Error codes.
|
||||
* All error codes are negative values.
|
||||
*/
|
||||
|
||||
// Win32 #defines NO_ERROR as well. It has the same value, so there's no
|
||||
// real conflict, though it's a bit awkward.
|
||||
#ifdef _WIN32
|
||||
# undef NO_ERROR
|
||||
#endif
|
||||
|
||||
enum {
|
||||
OK = 0, // Everything's swell.
|
||||
NO_ERROR = 0, // No errors.
|
||||
|
||||
UNKNOWN_ERROR = 0x80000000,
|
||||
|
||||
NO_MEMORY = -ENOMEM,
|
||||
INVALID_OPERATION = -ENOSYS,
|
||||
BAD_VALUE = -EINVAL,
|
||||
BAD_TYPE = 0x80000001,
|
||||
NAME_NOT_FOUND = -ENOENT,
|
||||
PERMISSION_DENIED = -EPERM,
|
||||
NO_INIT = -ENODEV,
|
||||
ALREADY_EXISTS = -EEXIST,
|
||||
DEAD_OBJECT = -EPIPE,
|
||||
FAILED_TRANSACTION = 0x80000002,
|
||||
JPARKS_BROKE_IT = -EPIPE,
|
||||
#if !defined(HAVE_MS_C_RUNTIME)
|
||||
BAD_INDEX = -EOVERFLOW,
|
||||
NOT_ENOUGH_DATA = -ENODATA,
|
||||
WOULD_BLOCK = -EWOULDBLOCK,
|
||||
TIMED_OUT = -ETIMEDOUT,
|
||||
UNKNOWN_TRANSACTION = -EBADMSG,
|
||||
#else
|
||||
BAD_INDEX = -E2BIG,
|
||||
NOT_ENOUGH_DATA = 0x80000003,
|
||||
WOULD_BLOCK = 0x80000004,
|
||||
TIMED_OUT = 0x80000005,
|
||||
UNKNOWN_TRANSACTION = 0x80000006,
|
||||
#endif
|
||||
FDS_NOT_ALLOWED = 0x80000007,
|
||||
};
|
||||
|
||||
// Restore define; enumeration is in "android" namespace, so the value defined
|
||||
// there won't work for Win32 code in a different namespace.
|
||||
#ifdef _WIN32
|
||||
# define NO_ERROR 0L
|
||||
#endif
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_ERRORS_H
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UTILS_FLATTENABLE_H
|
||||
#define ANDROID_UTILS_FLATTENABLE_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* The Flattenable interface allows an object to serialize itself out
|
||||
* to a byte-buffer and an array of file descriptors.
|
||||
*/
|
||||
|
||||
class Flattenable
|
||||
{
|
||||
public:
|
||||
// size in bytes of the flattened object
|
||||
virtual size_t getFlattenedSize() const = 0;
|
||||
|
||||
// number of file descriptors to flatten
|
||||
virtual size_t getFdCount() const = 0;
|
||||
|
||||
// flattens the object into buffer.
|
||||
// size should be at least of getFlattenedSize()
|
||||
// file descriptors are written in the fds[] array but ownership is
|
||||
// not transfered (ie: they must be dupped by the caller of
|
||||
// flatten() if needed).
|
||||
virtual status_t flatten(void* buffer, size_t size,
|
||||
int fds[], size_t count) const = 0;
|
||||
|
||||
// unflattens the object from buffer.
|
||||
// size should be equal to the value of getFlattenedSize() when the
|
||||
// object was flattened.
|
||||
// unflattened file descriptors are found in the fds[] array and
|
||||
// don't need to be dupped(). ie: the caller of unflatten doesn't
|
||||
// keep ownership. If a fd is not retained by unflatten() it must be
|
||||
// explicitly closed.
|
||||
virtual status_t unflatten(void const* buffer, size_t size,
|
||||
int fds[], size_t count) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~Flattenable() = 0;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* LightFlattenable is a protocol allowing object to serialize themselves out
|
||||
* to a byte-buffer.
|
||||
*
|
||||
* LightFlattenable objects must implement this protocol.
|
||||
*
|
||||
* LightFlattenable doesn't require the object to be virtual.
|
||||
*/
|
||||
template <typename T>
|
||||
class LightFlattenable {
|
||||
public:
|
||||
// returns whether this object always flatten into the same size.
|
||||
// for efficiency, this should always be inline.
|
||||
inline bool isFixedSize() const;
|
||||
|
||||
// returns size in bytes of the flattened object. must be a constant.
|
||||
inline size_t getSize() const;
|
||||
|
||||
// flattens the object into buffer.
|
||||
inline status_t flatten(void* buffer) const;
|
||||
|
||||
// unflattens the object from buffer of given size.
|
||||
inline status_t unflatten(void const* buffer, size_t size);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool LightFlattenable<T>::isFixedSize() const {
|
||||
return static_cast<T const*>(this)->T::isFixedSize();
|
||||
}
|
||||
template <typename T>
|
||||
inline size_t LightFlattenable<T>::getSize() const {
|
||||
return static_cast<T const*>(this)->T::getSize();
|
||||
}
|
||||
template <typename T>
|
||||
inline status_t LightFlattenable<T>::flatten(void* buffer) const {
|
||||
return static_cast<T const*>(this)->T::flatten(buffer);
|
||||
}
|
||||
template <typename T>
|
||||
inline status_t LightFlattenable<T>::unflatten(void const* buffer, size_t size) {
|
||||
return static_cast<T*>(this)->T::unflatten(buffer, size);
|
||||
}
|
||||
|
||||
/*
|
||||
* LightFlattenablePod is an implementation of the LightFlattenable protocol
|
||||
* for POD (plain-old-data) objects.
|
||||
*/
|
||||
template <typename T>
|
||||
class LightFlattenablePod : public LightFlattenable<T> {
|
||||
public:
|
||||
inline bool isFixedSize() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline size_t getSize() const {
|
||||
return sizeof(T);
|
||||
}
|
||||
inline status_t flatten(void* buffer) const {
|
||||
*reinterpret_cast<T*>(buffer) = *static_cast<T const*>(this);
|
||||
return NO_ERROR;
|
||||
}
|
||||
inline status_t unflatten(void const* buffer, size_t) {
|
||||
*static_cast<T*>(this) = *reinterpret_cast<T const*>(buffer);
|
||||
return NO_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}; // namespace android
|
||||
|
||||
|
||||
#endif /* ANDROID_UTILS_FLATTENABLE_H */
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_KEYED_VECTOR_H
|
||||
#define ANDROID_KEYED_VECTOR_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/log.h>
|
||||
|
||||
#include <utils/SortedVector.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
template <typename KEY, typename VALUE>
|
||||
class KeyedVector
|
||||
{
|
||||
public:
|
||||
typedef KEY key_type;
|
||||
typedef VALUE value_type;
|
||||
|
||||
inline KeyedVector();
|
||||
|
||||
/*
|
||||
* empty the vector
|
||||
*/
|
||||
|
||||
inline void clear() { mVector.clear(); }
|
||||
|
||||
/*!
|
||||
* vector stats
|
||||
*/
|
||||
|
||||
//! returns number of items in the vector
|
||||
inline size_t size() const { return mVector.size(); }
|
||||
//! returns whether or not the vector is empty
|
||||
inline bool isEmpty() const { return mVector.isEmpty(); }
|
||||
//! returns how many items can be stored without reallocating the backing store
|
||||
inline size_t capacity() const { return mVector.capacity(); }
|
||||
//! sets the capacity. capacity can never be reduced less than size()
|
||||
inline ssize_t setCapacity(size_t size) { return mVector.setCapacity(size); }
|
||||
|
||||
// returns true if the arguments is known to be identical to this vector
|
||||
inline bool isIdenticalTo(const KeyedVector& rhs) const;
|
||||
|
||||
/*!
|
||||
* accessors
|
||||
*/
|
||||
const VALUE& valueFor(const KEY& key) const;
|
||||
const VALUE& valueAt(size_t index) const;
|
||||
const KEY& keyAt(size_t index) const;
|
||||
ssize_t indexOfKey(const KEY& key) const;
|
||||
const VALUE& operator[] (size_t index) const;
|
||||
|
||||
/*!
|
||||
* modifying the array
|
||||
*/
|
||||
|
||||
VALUE& editValueFor(const KEY& key);
|
||||
VALUE& editValueAt(size_t index);
|
||||
|
||||
/*!
|
||||
* add/insert/replace items
|
||||
*/
|
||||
|
||||
ssize_t add(const KEY& key, const VALUE& item);
|
||||
ssize_t replaceValueFor(const KEY& key, const VALUE& item);
|
||||
ssize_t replaceValueAt(size_t index, const VALUE& item);
|
||||
|
||||
/*!
|
||||
* remove items
|
||||
*/
|
||||
|
||||
ssize_t removeItem(const KEY& key);
|
||||
ssize_t removeItemsAt(size_t index, size_t count = 1);
|
||||
|
||||
private:
|
||||
SortedVector< key_value_pair_t<KEY, VALUE> > mVector;
|
||||
};
|
||||
|
||||
// KeyedVector<KEY, VALUE> can be trivially moved using memcpy() because its
|
||||
// underlying SortedVector can be trivially moved.
|
||||
template<typename KEY, typename VALUE> struct trait_trivial_move<KeyedVector<KEY, VALUE> > {
|
||||
enum { value = trait_trivial_move<SortedVector< key_value_pair_t<KEY, VALUE> > >::value };
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Variation of KeyedVector that holds a default value to return when
|
||||
* valueFor() is called with a key that doesn't exist.
|
||||
*/
|
||||
template <typename KEY, typename VALUE>
|
||||
class DefaultKeyedVector : public KeyedVector<KEY, VALUE>
|
||||
{
|
||||
public:
|
||||
inline DefaultKeyedVector(const VALUE& defValue = VALUE());
|
||||
const VALUE& valueFor(const KEY& key) const;
|
||||
|
||||
private:
|
||||
VALUE mDefault;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
KeyedVector<KEY,VALUE>::KeyedVector()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
bool KeyedVector<KEY,VALUE>::isIdenticalTo(const KeyedVector<KEY,VALUE>& rhs) const {
|
||||
return mVector.array() == rhs.mVector.array();
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
ssize_t KeyedVector<KEY,VALUE>::indexOfKey(const KEY& key) const {
|
||||
return mVector.indexOf( key_value_pair_t<KEY,VALUE>(key) );
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
const VALUE& KeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
|
||||
ssize_t i = this->indexOfKey(key);
|
||||
LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__);
|
||||
return mVector.itemAt(i).value;
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
const VALUE& KeyedVector<KEY,VALUE>::valueAt(size_t index) const {
|
||||
return mVector.itemAt(index).value;
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
const VALUE& KeyedVector<KEY,VALUE>::operator[] (size_t index) const {
|
||||
return valueAt(index);
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
const KEY& KeyedVector<KEY,VALUE>::keyAt(size_t index) const {
|
||||
return mVector.itemAt(index).key;
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
VALUE& KeyedVector<KEY,VALUE>::editValueFor(const KEY& key) {
|
||||
ssize_t i = this->indexOfKey(key);
|
||||
LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__);
|
||||
return mVector.editItemAt(i).value;
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
VALUE& KeyedVector<KEY,VALUE>::editValueAt(size_t index) {
|
||||
return mVector.editItemAt(index).value;
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
ssize_t KeyedVector<KEY,VALUE>::add(const KEY& key, const VALUE& value) {
|
||||
return mVector.add( key_value_pair_t<KEY,VALUE>(key, value) );
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
ssize_t KeyedVector<KEY,VALUE>::replaceValueFor(const KEY& key, const VALUE& value) {
|
||||
key_value_pair_t<KEY,VALUE> pair(key, value);
|
||||
mVector.remove(pair);
|
||||
return mVector.add(pair);
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
ssize_t KeyedVector<KEY,VALUE>::replaceValueAt(size_t index, const VALUE& item) {
|
||||
if (index<size()) {
|
||||
mVector.editItemAt(index).value = item;
|
||||
return index;
|
||||
}
|
||||
return BAD_INDEX;
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
ssize_t KeyedVector<KEY,VALUE>::removeItem(const KEY& key) {
|
||||
return mVector.remove(key_value_pair_t<KEY,VALUE>(key));
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
ssize_t KeyedVector<KEY, VALUE>::removeItemsAt(size_t index, size_t count) {
|
||||
return mVector.removeItemsAt(index, count);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
DefaultKeyedVector<KEY,VALUE>::DefaultKeyedVector(const VALUE& defValue)
|
||||
: mDefault(defValue)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename KEY, typename VALUE> inline
|
||||
const VALUE& DefaultKeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
|
||||
ssize_t i = this->indexOfKey(key);
|
||||
return i >= 0 ? KeyedVector<KEY,VALUE>::valueAt(i) : mDefault;
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_KEYED_VECTOR_H
|
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// Templated list class. Normally we'd use STL, but we don't have that.
|
||||
// This class mimics STL's interfaces.
|
||||
//
|
||||
// Objects are copied into the list with the '=' operator or with copy-
|
||||
// construction, so if the compiler's auto-generated versions won't work for
|
||||
// you, define your own.
|
||||
//
|
||||
// The only class you want to use from here is "List".
|
||||
//
|
||||
#ifndef _LIBS_UTILS_LIST_H
|
||||
#define _LIBS_UTILS_LIST_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* Doubly-linked list. Instantiate with "List<MyClass> myList".
|
||||
*
|
||||
* Objects added to the list are copied using the assignment operator,
|
||||
* so this must be defined.
|
||||
*/
|
||||
template<typename T>
|
||||
class List
|
||||
{
|
||||
protected:
|
||||
/*
|
||||
* One element in the list.
|
||||
*/
|
||||
class _Node {
|
||||
public:
|
||||
explicit _Node(const T& val) : mVal(val) {}
|
||||
~_Node() {}
|
||||
inline T& getRef() { return mVal; }
|
||||
inline const T& getRef() const { return mVal; }
|
||||
inline _Node* getPrev() const { return mpPrev; }
|
||||
inline _Node* getNext() const { return mpNext; }
|
||||
inline void setVal(const T& val) { mVal = val; }
|
||||
inline void setPrev(_Node* ptr) { mpPrev = ptr; }
|
||||
inline void setNext(_Node* ptr) { mpNext = ptr; }
|
||||
private:
|
||||
friend class List;
|
||||
friend class _ListIterator;
|
||||
T mVal;
|
||||
_Node* mpPrev;
|
||||
_Node* mpNext;
|
||||
};
|
||||
|
||||
/*
|
||||
* Iterator for walking through the list.
|
||||
*/
|
||||
|
||||
template <typename TYPE>
|
||||
struct CONST_ITERATOR {
|
||||
typedef _Node const * NodePtr;
|
||||
typedef const TYPE Type;
|
||||
};
|
||||
|
||||
template <typename TYPE>
|
||||
struct NON_CONST_ITERATOR {
|
||||
typedef _Node* NodePtr;
|
||||
typedef TYPE Type;
|
||||
};
|
||||
|
||||
template<
|
||||
typename U,
|
||||
template <class> class Constness
|
||||
>
|
||||
class _ListIterator {
|
||||
typedef _ListIterator<U, Constness> _Iter;
|
||||
typedef typename Constness<U>::NodePtr _NodePtr;
|
||||
typedef typename Constness<U>::Type _Type;
|
||||
|
||||
explicit _ListIterator(_NodePtr ptr) : mpNode(ptr) {}
|
||||
|
||||
public:
|
||||
_ListIterator() {}
|
||||
_ListIterator(const _Iter& rhs) : mpNode(rhs.mpNode) {}
|
||||
~_ListIterator() {}
|
||||
|
||||
// this will handle conversions from iterator to const_iterator
|
||||
// (and also all convertible iterators)
|
||||
// Here, in this implementation, the iterators can be converted
|
||||
// if the nodes can be converted
|
||||
template<typename V> explicit
|
||||
_ListIterator(const V& rhs) : mpNode(rhs.mpNode) {}
|
||||
|
||||
|
||||
/*
|
||||
* Dereference operator. Used to get at the juicy insides.
|
||||
*/
|
||||
_Type& operator*() const { return mpNode->getRef(); }
|
||||
_Type* operator->() const { return &(mpNode->getRef()); }
|
||||
|
||||
/*
|
||||
* Iterator comparison.
|
||||
*/
|
||||
inline bool operator==(const _Iter& right) const {
|
||||
return mpNode == right.mpNode; }
|
||||
|
||||
inline bool operator!=(const _Iter& right) const {
|
||||
return mpNode != right.mpNode; }
|
||||
|
||||
/*
|
||||
* handle comparisons between iterator and const_iterator
|
||||
*/
|
||||
template<typename OTHER>
|
||||
inline bool operator==(const OTHER& right) const {
|
||||
return mpNode == right.mpNode; }
|
||||
|
||||
template<typename OTHER>
|
||||
inline bool operator!=(const OTHER& right) const {
|
||||
return mpNode != right.mpNode; }
|
||||
|
||||
/*
|
||||
* Incr/decr, used to move through the list.
|
||||
*/
|
||||
inline _Iter& operator++() { // pre-increment
|
||||
mpNode = mpNode->getNext();
|
||||
return *this;
|
||||
}
|
||||
const _Iter operator++(int) { // post-increment
|
||||
_Iter tmp(*this);
|
||||
mpNode = mpNode->getNext();
|
||||
return tmp;
|
||||
}
|
||||
inline _Iter& operator--() { // pre-increment
|
||||
mpNode = mpNode->getPrev();
|
||||
return *this;
|
||||
}
|
||||
const _Iter operator--(int) { // post-increment
|
||||
_Iter tmp(*this);
|
||||
mpNode = mpNode->getPrev();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline _NodePtr getNode() const { return mpNode; }
|
||||
|
||||
_NodePtr mpNode; /* should be private, but older gcc fails */
|
||||
private:
|
||||
friend class List;
|
||||
};
|
||||
|
||||
public:
|
||||
List() {
|
||||
prep();
|
||||
}
|
||||
List(const List<T>& src) { // copy-constructor
|
||||
prep();
|
||||
insert(begin(), src.begin(), src.end());
|
||||
}
|
||||
virtual ~List() {
|
||||
clear();
|
||||
delete[] (unsigned char*) mpMiddle;
|
||||
}
|
||||
|
||||
typedef _ListIterator<T, NON_CONST_ITERATOR> iterator;
|
||||
typedef _ListIterator<T, CONST_ITERATOR> const_iterator;
|
||||
|
||||
List<T>& operator=(const List<T>& right);
|
||||
|
||||
/* returns true if the list is empty */
|
||||
inline bool empty() const { return mpMiddle->getNext() == mpMiddle; }
|
||||
|
||||
/* return #of elements in list */
|
||||
size_t size() const {
|
||||
return size_t(distance(begin(), end()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the first element or one past the last element. The
|
||||
* _Node* we're returning is converted to an "iterator" by a
|
||||
* constructor in _ListIterator.
|
||||
*/
|
||||
inline iterator begin() {
|
||||
return iterator(mpMiddle->getNext());
|
||||
}
|
||||
inline const_iterator begin() const {
|
||||
return const_iterator(const_cast<_Node const*>(mpMiddle->getNext()));
|
||||
}
|
||||
inline iterator end() {
|
||||
return iterator(mpMiddle);
|
||||
}
|
||||
inline const_iterator end() const {
|
||||
return const_iterator(const_cast<_Node const*>(mpMiddle));
|
||||
}
|
||||
|
||||
/* add the object to the head or tail of the list */
|
||||
void push_front(const T& val) { insert(begin(), val); }
|
||||
void push_back(const T& val) { insert(end(), val); }
|
||||
|
||||
/* insert before the current node; returns iterator at new node */
|
||||
iterator insert(iterator posn, const T& val)
|
||||
{
|
||||
_Node* newNode = new _Node(val); // alloc & copy-construct
|
||||
newNode->setNext(posn.getNode());
|
||||
newNode->setPrev(posn.getNode()->getPrev());
|
||||
posn.getNode()->getPrev()->setNext(newNode);
|
||||
posn.getNode()->setPrev(newNode);
|
||||
return iterator(newNode);
|
||||
}
|
||||
|
||||
/* insert a range of elements before the current node */
|
||||
void insert(iterator posn, const_iterator first, const_iterator last) {
|
||||
for ( ; first != last; ++first)
|
||||
insert(posn, *first);
|
||||
}
|
||||
|
||||
/* remove one entry; returns iterator at next node */
|
||||
iterator erase(iterator posn) {
|
||||
_Node* pNext = posn.getNode()->getNext();
|
||||
_Node* pPrev = posn.getNode()->getPrev();
|
||||
pPrev->setNext(pNext);
|
||||
pNext->setPrev(pPrev);
|
||||
delete posn.getNode();
|
||||
return iterator(pNext);
|
||||
}
|
||||
|
||||
/* remove a range of elements */
|
||||
iterator erase(iterator first, iterator last) {
|
||||
while (first != last)
|
||||
erase(first++); // don't erase than incr later!
|
||||
return iterator(last);
|
||||
}
|
||||
|
||||
/* remove all contents of the list */
|
||||
void clear() {
|
||||
_Node* pCurrent = mpMiddle->getNext();
|
||||
_Node* pNext;
|
||||
|
||||
while (pCurrent != mpMiddle) {
|
||||
pNext = pCurrent->getNext();
|
||||
delete pCurrent;
|
||||
pCurrent = pNext;
|
||||
}
|
||||
mpMiddle->setPrev(mpMiddle);
|
||||
mpMiddle->setNext(mpMiddle);
|
||||
}
|
||||
|
||||
/*
|
||||
* Measure the distance between two iterators. On exist, "first"
|
||||
* will be equal to "last". The iterators must refer to the same
|
||||
* list.
|
||||
*
|
||||
* FIXME: This is actually a generic iterator function. It should be a
|
||||
* template function at the top-level with specializations for things like
|
||||
* vector<>, which can just do pointer math). Here we limit it to
|
||||
* _ListIterator of the same type but different constness.
|
||||
*/
|
||||
template<
|
||||
typename U,
|
||||
template <class> class CL,
|
||||
template <class> class CR
|
||||
>
|
||||
ptrdiff_t distance(
|
||||
_ListIterator<U, CL> first, _ListIterator<U, CR> last) const
|
||||
{
|
||||
ptrdiff_t count = 0;
|
||||
while (first != last) {
|
||||
++first;
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
/*
|
||||
* I want a _Node but don't need it to hold valid data. More
|
||||
* to the point, I don't want T's constructor to fire, since it
|
||||
* might have side-effects or require arguments. So, we do this
|
||||
* slightly uncouth storage alloc.
|
||||
*/
|
||||
void prep() {
|
||||
mpMiddle = (_Node*) new unsigned char[sizeof(_Node)];
|
||||
mpMiddle->setPrev(mpMiddle);
|
||||
mpMiddle->setNext(mpMiddle);
|
||||
}
|
||||
|
||||
/*
|
||||
* This node plays the role of "pointer to head" and "pointer to tail".
|
||||
* It sits in the middle of a circular list of nodes. The iterator
|
||||
* runs around the circle until it encounters this one.
|
||||
*/
|
||||
_Node* mpMiddle;
|
||||
};
|
||||
|
||||
/*
|
||||
* Assignment operator.
|
||||
*
|
||||
* The simplest way to do this would be to clear out the target list and
|
||||
* fill it with the source. However, we can speed things along by
|
||||
* re-using existing elements.
|
||||
*/
|
||||
template<class T>
|
||||
List<T>& List<T>::operator=(const List<T>& right)
|
||||
{
|
||||
if (this == &right)
|
||||
return *this; // self-assignment
|
||||
iterator firstDst = begin();
|
||||
iterator lastDst = end();
|
||||
const_iterator firstSrc = right.begin();
|
||||
const_iterator lastSrc = right.end();
|
||||
while (firstSrc != lastSrc && firstDst != lastDst)
|
||||
*firstDst++ = *firstSrc++;
|
||||
if (firstSrc == lastSrc) // ran out of elements in source?
|
||||
erase(firstDst, lastDst); // yes, erase any extras
|
||||
else
|
||||
insert(lastDst, firstSrc, lastSrc); // copy remaining over
|
||||
return *this;
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // _LIBS_UTILS_LIST_H
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// C/C++ logging functions. See the logging documentation for API details.
|
||||
//
|
||||
// We'd like these to be available from C code (in case we import some from
|
||||
// somewhere), so this has a C interface.
|
||||
//
|
||||
// The output will be correct when the log file is shared between multiple
|
||||
// threads and/or multiple processes so long as the operating system
|
||||
// supports O_APPEND. These calls have mutex-protected data structures
|
||||
// and so are NOT reentrant. Do not use LOG in a signal handler.
|
||||
//
|
||||
#ifndef _LIBS_UTILS_LOG_H
|
||||
#define _LIBS_UTILS_LOG_H
|
||||
|
||||
#include <cutils/log.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* A very simple utility that yells in the log when an operation takes too long.
|
||||
*/
|
||||
class LogIfSlow {
|
||||
public:
|
||||
LogIfSlow(const char* tag, android_LogPriority priority,
|
||||
int timeoutMillis, const char* message);
|
||||
~LogIfSlow();
|
||||
|
||||
private:
|
||||
const char* const mTag;
|
||||
const android_LogPriority mPriority;
|
||||
const int mTimeoutMillis;
|
||||
const char* const mMessage;
|
||||
const int64_t mStart;
|
||||
};
|
||||
|
||||
/*
|
||||
* Writes the specified debug log message if this block takes longer than the
|
||||
* specified number of milliseconds to run. Includes the time actually taken.
|
||||
*
|
||||
* {
|
||||
* ALOGD_IF_SLOW(50, "Excessive delay doing something.");
|
||||
* doSomething();
|
||||
* }
|
||||
*/
|
||||
#define ALOGD_IF_SLOW(timeoutMillis, message) \
|
||||
LogIfSlow _logIfSlow(LOG_TAG, ANDROID_LOG_DEBUG, timeoutMillis, message);
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // _LIBS_UTILS_LOG_H
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_MUTEX_H
|
||||
#define _LIBS_UTILS_MUTEX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <utils/Errors.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class Condition;
|
||||
|
||||
/*
|
||||
* Simple mutex class. The implementation is system-dependent.
|
||||
*
|
||||
* The mutex must be unlocked by the thread that locked it. They are not
|
||||
* recursive, i.e. the same thread can't lock it multiple times.
|
||||
*/
|
||||
class Mutex {
|
||||
public:
|
||||
enum {
|
||||
PRIVATE = 0,
|
||||
SHARED = 1
|
||||
};
|
||||
|
||||
Mutex();
|
||||
Mutex(const char* name);
|
||||
Mutex(int type, const char* name = NULL);
|
||||
~Mutex();
|
||||
|
||||
// lock or unlock the mutex
|
||||
status_t lock();
|
||||
void unlock();
|
||||
|
||||
// lock if possible; returns 0 on success, error otherwise
|
||||
status_t tryLock();
|
||||
|
||||
// Manages the mutex automatically. It'll be locked when Autolock is
|
||||
// constructed and released when Autolock goes out of scope.
|
||||
class Autolock {
|
||||
public:
|
||||
inline Autolock(Mutex& mutex) : mLock(mutex) { mLock.lock(); }
|
||||
inline Autolock(Mutex* mutex) : mLock(*mutex) { mLock.lock(); }
|
||||
inline ~Autolock() { mLock.unlock(); }
|
||||
private:
|
||||
Mutex& mLock;
|
||||
};
|
||||
|
||||
private:
|
||||
friend class Condition;
|
||||
|
||||
// A mutex cannot be copied
|
||||
Mutex(const Mutex&);
|
||||
Mutex& operator = (const Mutex&);
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
pthread_mutex_t mMutex;
|
||||
#else
|
||||
void _init();
|
||||
void* mState;
|
||||
#endif
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
|
||||
inline Mutex::Mutex() {
|
||||
pthread_mutex_init(&mMutex, NULL);
|
||||
}
|
||||
inline Mutex::Mutex(__attribute__((unused)) const char* name) {
|
||||
pthread_mutex_init(&mMutex, NULL);
|
||||
}
|
||||
inline Mutex::Mutex(int type, __attribute__((unused)) const char* name) {
|
||||
if (type == SHARED) {
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_mutex_init(&mMutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
} else {
|
||||
pthread_mutex_init(&mMutex, NULL);
|
||||
}
|
||||
}
|
||||
inline Mutex::~Mutex() {
|
||||
pthread_mutex_destroy(&mMutex);
|
||||
}
|
||||
inline status_t Mutex::lock() {
|
||||
return -pthread_mutex_lock(&mMutex);
|
||||
}
|
||||
inline void Mutex::unlock() {
|
||||
pthread_mutex_unlock(&mMutex);
|
||||
}
|
||||
inline status_t Mutex::tryLock() {
|
||||
return -pthread_mutex_trylock(&mMutex);
|
||||
}
|
||||
|
||||
#endif // HAVE_PTHREADS
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Automatic mutex. Declare one of these at the top of a function.
|
||||
* When the function returns, it will go out of scope, and release the
|
||||
* mutex.
|
||||
*/
|
||||
|
||||
typedef Mutex::Autolock AutoMutex;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // _LIBS_UTILS_MUTEX_H
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_RWLOCK_H
|
||||
#define _LIBS_UTILS_RWLOCK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/ThreadDefs.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
|
||||
/*
|
||||
* Simple mutex class. The implementation is system-dependent.
|
||||
*
|
||||
* The mutex must be unlocked by the thread that locked it. They are not
|
||||
* recursive, i.e. the same thread can't lock it multiple times.
|
||||
*/
|
||||
class RWLock {
|
||||
public:
|
||||
enum {
|
||||
PRIVATE = 0,
|
||||
SHARED = 1
|
||||
};
|
||||
|
||||
RWLock();
|
||||
RWLock(const char* name);
|
||||
RWLock(int type, const char* name = NULL);
|
||||
~RWLock();
|
||||
|
||||
status_t readLock();
|
||||
status_t tryReadLock();
|
||||
status_t writeLock();
|
||||
status_t tryWriteLock();
|
||||
void unlock();
|
||||
|
||||
class AutoRLock {
|
||||
public:
|
||||
inline AutoRLock(RWLock& rwlock) : mLock(rwlock) { mLock.readLock(); }
|
||||
inline ~AutoRLock() { mLock.unlock(); }
|
||||
private:
|
||||
RWLock& mLock;
|
||||
};
|
||||
|
||||
class AutoWLock {
|
||||
public:
|
||||
inline AutoWLock(RWLock& rwlock) : mLock(rwlock) { mLock.writeLock(); }
|
||||
inline ~AutoWLock() { mLock.unlock(); }
|
||||
private:
|
||||
RWLock& mLock;
|
||||
};
|
||||
|
||||
private:
|
||||
// A RWLock cannot be copied
|
||||
RWLock(const RWLock&);
|
||||
RWLock& operator = (const RWLock&);
|
||||
|
||||
pthread_rwlock_t mRWLock;
|
||||
};
|
||||
|
||||
inline RWLock::RWLock() {
|
||||
pthread_rwlock_init(&mRWLock, NULL);
|
||||
}
|
||||
inline RWLock::RWLock(__attribute__((unused)) const char* name) {
|
||||
pthread_rwlock_init(&mRWLock, NULL);
|
||||
}
|
||||
inline RWLock::RWLock(int type, __attribute__((unused)) const char* name) {
|
||||
if (type == SHARED) {
|
||||
pthread_rwlockattr_t attr;
|
||||
pthread_rwlockattr_init(&attr);
|
||||
pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_rwlock_init(&mRWLock, &attr);
|
||||
pthread_rwlockattr_destroy(&attr);
|
||||
} else {
|
||||
pthread_rwlock_init(&mRWLock, NULL);
|
||||
}
|
||||
}
|
||||
inline RWLock::~RWLock() {
|
||||
pthread_rwlock_destroy(&mRWLock);
|
||||
}
|
||||
inline status_t RWLock::readLock() {
|
||||
return -pthread_rwlock_rdlock(&mRWLock);
|
||||
}
|
||||
inline status_t RWLock::tryReadLock() {
|
||||
return -pthread_rwlock_tryrdlock(&mRWLock);
|
||||
}
|
||||
inline status_t RWLock::writeLock() {
|
||||
return -pthread_rwlock_wrlock(&mRWLock);
|
||||
}
|
||||
inline status_t RWLock::tryWriteLock() {
|
||||
return -pthread_rwlock_trywrlock(&mRWLock);
|
||||
}
|
||||
inline void RWLock::unlock() {
|
||||
pthread_rwlock_unlock(&mRWLock);
|
||||
}
|
||||
|
||||
#endif // HAVE_PTHREADS
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // _LIBS_UTILS_RWLOCK_H
|
|
@ -0,0 +1,546 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_REF_BASE_H
|
||||
#define ANDROID_REF_BASE_H
|
||||
|
||||
#include <cutils/atomic.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <utils/StrongPointer.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
|
||||
class TextOutput;
|
||||
TextOutput& printWeakPointer(TextOutput& to, const void* val);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#define COMPARE_WEAK(_op_) \
|
||||
inline bool operator _op_ (const sp<T>& o) const { \
|
||||
return m_ptr _op_ o.m_ptr; \
|
||||
} \
|
||||
inline bool operator _op_ (const T* o) const { \
|
||||
return m_ptr _op_ o; \
|
||||
} \
|
||||
template<typename U> \
|
||||
inline bool operator _op_ (const sp<U>& o) const { \
|
||||
return m_ptr _op_ o.m_ptr; \
|
||||
} \
|
||||
template<typename U> \
|
||||
inline bool operator _op_ (const U* o) const { \
|
||||
return m_ptr _op_ o; \
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class ReferenceRenamer {
|
||||
protected:
|
||||
// destructor is purposedly not virtual so we avoid code overhead from
|
||||
// subclasses; we have to make it protected to guarantee that it
|
||||
// cannot be called from this base class (and to make strict compilers
|
||||
// happy).
|
||||
~ReferenceRenamer() { }
|
||||
public:
|
||||
virtual void operator()(size_t i) const = 0;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class RefBase
|
||||
{
|
||||
public:
|
||||
void incStrong(const void* id) const;
|
||||
void decStrong(const void* id) const;
|
||||
|
||||
void forceIncStrong(const void* id) const;
|
||||
|
||||
//! DEBUGGING ONLY: Get current strong ref count.
|
||||
int32_t getStrongCount() const;
|
||||
|
||||
class weakref_type
|
||||
{
|
||||
public:
|
||||
RefBase* refBase() const;
|
||||
|
||||
void incWeak(const void* id);
|
||||
void decWeak(const void* id);
|
||||
|
||||
// acquires a strong reference if there is already one.
|
||||
bool attemptIncStrong(const void* id);
|
||||
|
||||
// acquires a weak reference if there is already one.
|
||||
// This is not always safe. see ProcessState.cpp and BpBinder.cpp
|
||||
// for proper use.
|
||||
bool attemptIncWeak(const void* id);
|
||||
|
||||
//! DEBUGGING ONLY: Get current weak ref count.
|
||||
int32_t getWeakCount() const;
|
||||
|
||||
//! DEBUGGING ONLY: Print references held on object.
|
||||
void printRefs() const;
|
||||
|
||||
//! DEBUGGING ONLY: Enable tracking for this object.
|
||||
// enable -- enable/disable tracking
|
||||
// retain -- when tracking is enable, if true, then we save a stack trace
|
||||
// for each reference and dereference; when retain == false, we
|
||||
// match up references and dereferences and keep only the
|
||||
// outstanding ones.
|
||||
|
||||
void trackMe(bool enable, bool retain);
|
||||
};
|
||||
|
||||
weakref_type* createWeak(const void* id) const;
|
||||
|
||||
weakref_type* getWeakRefs() const;
|
||||
|
||||
//! DEBUGGING ONLY: Print references held on object.
|
||||
inline void printRefs() const { getWeakRefs()->printRefs(); }
|
||||
|
||||
//! DEBUGGING ONLY: Enable tracking of object.
|
||||
inline void trackMe(bool enable, bool retain)
|
||||
{
|
||||
getWeakRefs()->trackMe(enable, retain);
|
||||
}
|
||||
|
||||
typedef RefBase basetype;
|
||||
|
||||
protected:
|
||||
RefBase();
|
||||
virtual ~RefBase();
|
||||
|
||||
//! Flags for extendObjectLifetime()
|
||||
enum {
|
||||
OBJECT_LIFETIME_STRONG = 0x0000,
|
||||
OBJECT_LIFETIME_WEAK = 0x0001,
|
||||
OBJECT_LIFETIME_MASK = 0x0001
|
||||
};
|
||||
|
||||
void extendObjectLifetime(int32_t mode);
|
||||
|
||||
//! Flags for onIncStrongAttempted()
|
||||
enum {
|
||||
FIRST_INC_STRONG = 0x0001
|
||||
};
|
||||
|
||||
virtual void onFirstRef();
|
||||
virtual void onLastStrongRef(const void* id);
|
||||
virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
|
||||
virtual void onLastWeakRef(const void* id);
|
||||
|
||||
private:
|
||||
friend class weakref_type;
|
||||
class weakref_impl;
|
||||
|
||||
RefBase(const RefBase& o);
|
||||
RefBase& operator=(const RefBase& o);
|
||||
|
||||
private:
|
||||
friend class ReferenceMover;
|
||||
|
||||
static void renameRefs(size_t n, const ReferenceRenamer& renamer);
|
||||
|
||||
static void renameRefId(weakref_type* ref,
|
||||
const void* old_id, const void* new_id);
|
||||
|
||||
static void renameRefId(RefBase* ref,
|
||||
const void* old_id, const void* new_id);
|
||||
|
||||
weakref_impl* const mRefs;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template <class T>
|
||||
class LightRefBase
|
||||
{
|
||||
public:
|
||||
inline LightRefBase() : mCount(0) { }
|
||||
inline void incStrong(__attribute__((unused)) const void* id) const {
|
||||
android_atomic_inc(&mCount);
|
||||
}
|
||||
inline void decStrong(__attribute__((unused)) const void* id) const {
|
||||
if (android_atomic_dec(&mCount) == 1) {
|
||||
delete static_cast<const T*>(this);
|
||||
}
|
||||
}
|
||||
//! DEBUGGING ONLY: Get current strong ref count.
|
||||
inline int32_t getStrongCount() const {
|
||||
return mCount;
|
||||
}
|
||||
|
||||
typedef LightRefBase<T> basetype;
|
||||
|
||||
protected:
|
||||
inline ~LightRefBase() { }
|
||||
|
||||
private:
|
||||
friend class ReferenceMover;
|
||||
inline static void renameRefs(size_t n, const ReferenceRenamer& renamer) { }
|
||||
inline static void renameRefId(T* ref,
|
||||
const void* old_id, const void* new_id) { }
|
||||
|
||||
private:
|
||||
mutable volatile int32_t mCount;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
class wp
|
||||
{
|
||||
public:
|
||||
typedef typename RefBase::weakref_type weakref_type;
|
||||
|
||||
inline wp() : m_ptr(0) { }
|
||||
|
||||
wp(T* other);
|
||||
wp(const wp<T>& other);
|
||||
wp(const sp<T>& other);
|
||||
template<typename U> wp(U* other);
|
||||
template<typename U> wp(const sp<U>& other);
|
||||
template<typename U> wp(const wp<U>& other);
|
||||
|
||||
~wp();
|
||||
|
||||
// Assignment
|
||||
|
||||
wp& operator = (T* other);
|
||||
wp& operator = (const wp<T>& other);
|
||||
wp& operator = (const sp<T>& other);
|
||||
|
||||
template<typename U> wp& operator = (U* other);
|
||||
template<typename U> wp& operator = (const wp<U>& other);
|
||||
template<typename U> wp& operator = (const sp<U>& other);
|
||||
|
||||
void set_object_and_refs(T* other, weakref_type* refs);
|
||||
|
||||
// promotion to sp
|
||||
|
||||
sp<T> promote() const;
|
||||
|
||||
// Reset
|
||||
|
||||
void clear();
|
||||
|
||||
// Accessors
|
||||
|
||||
inline weakref_type* get_refs() const { return m_refs; }
|
||||
|
||||
inline T* unsafe_get() const { return m_ptr; }
|
||||
|
||||
// Operators
|
||||
|
||||
COMPARE_WEAK(==)
|
||||
COMPARE_WEAK(!=)
|
||||
COMPARE_WEAK(>)
|
||||
COMPARE_WEAK(<)
|
||||
COMPARE_WEAK(<=)
|
||||
COMPARE_WEAK(>=)
|
||||
|
||||
inline bool operator == (const wp<T>& o) const {
|
||||
return (m_ptr == o.m_ptr) && (m_refs == o.m_refs);
|
||||
}
|
||||
template<typename U>
|
||||
inline bool operator == (const wp<U>& o) const {
|
||||
return m_ptr == o.m_ptr;
|
||||
}
|
||||
|
||||
inline bool operator > (const wp<T>& o) const {
|
||||
return (m_ptr == o.m_ptr) ? (m_refs > o.m_refs) : (m_ptr > o.m_ptr);
|
||||
}
|
||||
template<typename U>
|
||||
inline bool operator > (const wp<U>& o) const {
|
||||
return (m_ptr == o.m_ptr) ? (m_refs > o.m_refs) : (m_ptr > o.m_ptr);
|
||||
}
|
||||
|
||||
inline bool operator < (const wp<T>& o) const {
|
||||
return (m_ptr == o.m_ptr) ? (m_refs < o.m_refs) : (m_ptr < o.m_ptr);
|
||||
}
|
||||
template<typename U>
|
||||
inline bool operator < (const wp<U>& o) const {
|
||||
return (m_ptr == o.m_ptr) ? (m_refs < o.m_refs) : (m_ptr < o.m_ptr);
|
||||
}
|
||||
inline bool operator != (const wp<T>& o) const { return m_refs != o.m_refs; }
|
||||
template<typename U> inline bool operator != (const wp<U>& o) const { return !operator == (o); }
|
||||
inline bool operator <= (const wp<T>& o) const { return !operator > (o); }
|
||||
template<typename U> inline bool operator <= (const wp<U>& o) const { return !operator > (o); }
|
||||
inline bool operator >= (const wp<T>& o) const { return !operator < (o); }
|
||||
template<typename U> inline bool operator >= (const wp<U>& o) const { return !operator < (o); }
|
||||
|
||||
private:
|
||||
template<typename Y> friend class sp;
|
||||
template<typename Y> friend class wp;
|
||||
|
||||
T* m_ptr;
|
||||
weakref_type* m_refs;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
TextOutput& operator<<(TextOutput& to, const wp<T>& val);
|
||||
|
||||
#undef COMPARE_WEAK
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user serviceable parts below here.
|
||||
|
||||
template<typename T>
|
||||
wp<T>::wp(T* other)
|
||||
: m_ptr(other)
|
||||
{
|
||||
if (other) m_refs = other->createWeak(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wp<T>::wp(const wp<T>& other)
|
||||
: m_ptr(other.m_ptr), m_refs(other.m_refs)
|
||||
{
|
||||
if (m_ptr) m_refs->incWeak(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wp<T>::wp(const sp<T>& other)
|
||||
: m_ptr(other.m_ptr)
|
||||
{
|
||||
if (m_ptr) {
|
||||
m_refs = m_ptr->createWeak(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
wp<T>::wp(U* other)
|
||||
: m_ptr(other)
|
||||
{
|
||||
if (other) m_refs = other->createWeak(this);
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
wp<T>::wp(const wp<U>& other)
|
||||
: m_ptr(other.m_ptr)
|
||||
{
|
||||
if (m_ptr) {
|
||||
m_refs = other.m_refs;
|
||||
m_refs->incWeak(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
wp<T>::wp(const sp<U>& other)
|
||||
: m_ptr(other.m_ptr)
|
||||
{
|
||||
if (m_ptr) {
|
||||
m_refs = m_ptr->createWeak(this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wp<T>::~wp()
|
||||
{
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wp<T>& wp<T>::operator = (T* other)
|
||||
{
|
||||
weakref_type* newRefs =
|
||||
other ? other->createWeak(this) : 0;
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = other;
|
||||
m_refs = newRefs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wp<T>& wp<T>::operator = (const wp<T>& other)
|
||||
{
|
||||
weakref_type* otherRefs(other.m_refs);
|
||||
T* otherPtr(other.m_ptr);
|
||||
if (otherPtr) otherRefs->incWeak(this);
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = otherPtr;
|
||||
m_refs = otherRefs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
wp<T>& wp<T>::operator = (const sp<T>& other)
|
||||
{
|
||||
weakref_type* newRefs =
|
||||
other != NULL ? other->createWeak(this) : 0;
|
||||
T* otherPtr(other.m_ptr);
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = otherPtr;
|
||||
m_refs = newRefs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
wp<T>& wp<T>::operator = (U* other)
|
||||
{
|
||||
weakref_type* newRefs =
|
||||
other ? other->createWeak(this) : 0;
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = other;
|
||||
m_refs = newRefs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
wp<T>& wp<T>::operator = (const wp<U>& other)
|
||||
{
|
||||
weakref_type* otherRefs(other.m_refs);
|
||||
U* otherPtr(other.m_ptr);
|
||||
if (otherPtr) otherRefs->incWeak(this);
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = otherPtr;
|
||||
m_refs = otherRefs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
wp<T>& wp<T>::operator = (const sp<U>& other)
|
||||
{
|
||||
weakref_type* newRefs =
|
||||
other != NULL ? other->createWeak(this) : 0;
|
||||
U* otherPtr(other.m_ptr);
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = otherPtr;
|
||||
m_refs = newRefs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void wp<T>::set_object_and_refs(T* other, weakref_type* refs)
|
||||
{
|
||||
if (other) refs->incWeak(this);
|
||||
if (m_ptr) m_refs->decWeak(this);
|
||||
m_ptr = other;
|
||||
m_refs = refs;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sp<T> wp<T>::promote() const
|
||||
{
|
||||
sp<T> result;
|
||||
if (m_ptr && m_refs->attemptIncStrong(&result)) {
|
||||
result.set_pointer(m_ptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void wp<T>::clear()
|
||||
{
|
||||
if (m_ptr) {
|
||||
m_refs->decWeak(this);
|
||||
m_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline TextOutput& operator<<(TextOutput& to, const wp<T>& val)
|
||||
{
|
||||
return printWeakPointer(to, val.unsafe_get());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// this class just serves as a namespace so TYPE::moveReferences can stay
|
||||
// private.
|
||||
class ReferenceMover {
|
||||
public:
|
||||
// it would be nice if we could make sure no extra code is generated
|
||||
// for sp<TYPE> or wp<TYPE> when TYPE is a descendant of RefBase:
|
||||
// Using a sp<RefBase> override doesn't work; it's a bit like we wanted
|
||||
// a template<typename TYPE inherits RefBase> template...
|
||||
|
||||
template<typename TYPE> static inline
|
||||
void move_references(sp<TYPE>* d, sp<TYPE> const* s, size_t n) {
|
||||
|
||||
class Renamer : public ReferenceRenamer {
|
||||
sp<TYPE>* d;
|
||||
sp<TYPE> const* s;
|
||||
virtual void operator()(size_t i) const {
|
||||
// The id are known to be the sp<>'s this pointer
|
||||
TYPE::renameRefId(d[i].get(), &s[i], &d[i]);
|
||||
}
|
||||
public:
|
||||
Renamer(sp<TYPE>* d, sp<TYPE> const* s) : s(s), d(d) { }
|
||||
};
|
||||
|
||||
memmove(d, s, n*sizeof(sp<TYPE>));
|
||||
TYPE::renameRefs(n, Renamer(d, s));
|
||||
}
|
||||
|
||||
|
||||
template<typename TYPE> static inline
|
||||
void move_references(wp<TYPE>* d, wp<TYPE> const* s, size_t n) {
|
||||
|
||||
class Renamer : public ReferenceRenamer {
|
||||
wp<TYPE>* d;
|
||||
wp<TYPE> const* s;
|
||||
virtual void operator()(size_t i) const {
|
||||
// The id are known to be the wp<>'s this pointer
|
||||
TYPE::renameRefId(d[i].get_refs(), &s[i], &d[i]);
|
||||
}
|
||||
public:
|
||||
Renamer(wp<TYPE>* d, wp<TYPE> const* s) : s(s), d(d) { }
|
||||
};
|
||||
|
||||
memmove(d, s, n*sizeof(wp<TYPE>));
|
||||
TYPE::renameRefs(n, Renamer(d, s));
|
||||
}
|
||||
};
|
||||
|
||||
// specialization for moving sp<> and wp<> types.
|
||||
// these are used by the [Sorted|Keyed]Vector<> implementations
|
||||
// sp<> and wp<> need to be handled specially, because they do not
|
||||
// have trivial copy operation in the general case (see RefBase.cpp
|
||||
// when DEBUG ops are enabled), but can be implemented very
|
||||
// efficiently in most cases.
|
||||
|
||||
template<typename TYPE> inline
|
||||
void move_forward_type(sp<TYPE>* d, sp<TYPE> const* s, size_t n) {
|
||||
ReferenceMover::move_references(d, s, n);
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void move_backward_type(sp<TYPE>* d, sp<TYPE> const* s, size_t n) {
|
||||
ReferenceMover::move_references(d, s, n);
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void move_forward_type(wp<TYPE>* d, wp<TYPE> const* s, size_t n) {
|
||||
ReferenceMover::move_references(d, s, n);
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void move_backward_type(wp<TYPE>* d, wp<TYPE> const* s, size_t n) {
|
||||
ReferenceMover::move_references(d, s, n);
|
||||
}
|
||||
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_REF_BASE_H
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_SHARED_BUFFER_H
|
||||
#define ANDROID_SHARED_BUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
class SharedBuffer
|
||||
{
|
||||
public:
|
||||
|
||||
/* flags to use with release() */
|
||||
enum {
|
||||
eKeepStorage = 0x00000001
|
||||
};
|
||||
|
||||
/*! allocate a buffer of size 'size' and acquire() it.
|
||||
* call release() to free it.
|
||||
*/
|
||||
static SharedBuffer* alloc(size_t size);
|
||||
|
||||
/*! free the memory associated with the SharedBuffer.
|
||||
* Fails if there are any users associated with this SharedBuffer.
|
||||
* In other words, the buffer must have been release by all its
|
||||
* users.
|
||||
*/
|
||||
static ssize_t dealloc(const SharedBuffer* released);
|
||||
|
||||
//! access the data for read
|
||||
inline const void* data() const;
|
||||
|
||||
//! access the data for read/write
|
||||
inline void* data();
|
||||
|
||||
//! get size of the buffer
|
||||
inline size_t size() const;
|
||||
|
||||
//! get back a SharedBuffer object from its data
|
||||
static inline SharedBuffer* bufferFromData(void* data);
|
||||
|
||||
//! get back a SharedBuffer object from its data
|
||||
static inline const SharedBuffer* bufferFromData(const void* data);
|
||||
|
||||
//! get the size of a SharedBuffer object from its data
|
||||
static inline size_t sizeFromData(const void* data);
|
||||
|
||||
//! edit the buffer (get a writtable, or non-const, version of it)
|
||||
SharedBuffer* edit() const;
|
||||
|
||||
//! edit the buffer, resizing if needed
|
||||
SharedBuffer* editResize(size_t size) const;
|
||||
|
||||
//! like edit() but fails if a copy is required
|
||||
SharedBuffer* attemptEdit() const;
|
||||
|
||||
//! resize and edit the buffer, loose it's content.
|
||||
SharedBuffer* reset(size_t size) const;
|
||||
|
||||
//! acquire/release a reference on this buffer
|
||||
void acquire() const;
|
||||
|
||||
/*! release a reference on this buffer, with the option of not
|
||||
* freeing the memory associated with it if it was the last reference
|
||||
* returns the previous reference count
|
||||
*/
|
||||
int32_t release(uint32_t flags = 0) const;
|
||||
|
||||
//! returns wether or not we're the only owner
|
||||
inline bool onlyOwner() const;
|
||||
|
||||
|
||||
private:
|
||||
inline SharedBuffer() { }
|
||||
inline ~SharedBuffer() { }
|
||||
SharedBuffer(const SharedBuffer&);
|
||||
SharedBuffer& operator = (const SharedBuffer&);
|
||||
|
||||
// 16 bytes. must be sized to preserve correct alignment.
|
||||
mutable int32_t mRefs;
|
||||
size_t mSize;
|
||||
uint32_t mReserved[2];
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const void* SharedBuffer::data() const {
|
||||
return this + 1;
|
||||
}
|
||||
|
||||
void* SharedBuffer::data() {
|
||||
return this + 1;
|
||||
}
|
||||
|
||||
size_t SharedBuffer::size() const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
SharedBuffer* SharedBuffer::bufferFromData(void* data) {
|
||||
return data ? static_cast<SharedBuffer *>(data)-1 : 0;
|
||||
}
|
||||
|
||||
const SharedBuffer* SharedBuffer::bufferFromData(const void* data) {
|
||||
return data ? static_cast<const SharedBuffer *>(data)-1 : 0;
|
||||
}
|
||||
|
||||
size_t SharedBuffer::sizeFromData(const void* data) {
|
||||
return data ? bufferFromData(data)->mSize : 0;
|
||||
}
|
||||
|
||||
bool SharedBuffer::onlyOwner() const {
|
||||
return (mRefs == 1);
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_VECTOR_H
|
|
@ -0,0 +1,282 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_SORTED_VECTOR_H
|
||||
#define ANDROID_SORTED_VECTOR_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/log.h>
|
||||
|
||||
#include <utils/Vector.h>
|
||||
#include <utils/VectorImpl.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
template <class TYPE>
|
||||
class SortedVector : private SortedVectorImpl
|
||||
{
|
||||
friend class Vector<TYPE>;
|
||||
|
||||
public:
|
||||
typedef TYPE value_type;
|
||||
|
||||
/*!
|
||||
* Constructors and destructors
|
||||
*/
|
||||
|
||||
SortedVector();
|
||||
SortedVector(const SortedVector<TYPE>& rhs);
|
||||
virtual ~SortedVector();
|
||||
|
||||
/*! copy operator */
|
||||
const SortedVector<TYPE>& operator = (const SortedVector<TYPE>& rhs) const;
|
||||
SortedVector<TYPE>& operator = (const SortedVector<TYPE>& rhs);
|
||||
|
||||
/*
|
||||
* empty the vector
|
||||
*/
|
||||
|
||||
inline void clear() { VectorImpl::clear(); }
|
||||
|
||||
/*!
|
||||
* vector stats
|
||||
*/
|
||||
|
||||
//! returns number of items in the vector
|
||||
inline size_t size() const { return VectorImpl::size(); }
|
||||
//! returns whether or not the vector is empty
|
||||
inline bool isEmpty() const { return VectorImpl::isEmpty(); }
|
||||
//! returns how many items can be stored without reallocating the backing store
|
||||
inline size_t capacity() const { return VectorImpl::capacity(); }
|
||||
//! sets the capacity. capacity can never be reduced less than size()
|
||||
inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
|
||||
|
||||
/*!
|
||||
* C-style array access
|
||||
*/
|
||||
|
||||
//! read-only C-style access
|
||||
inline const TYPE* array() const;
|
||||
|
||||
//! read-write C-style access. BE VERY CAREFUL when modifying the array
|
||||
//! you must keep it sorted! You usually don't use this function.
|
||||
TYPE* editArray();
|
||||
|
||||
//! finds the index of an item
|
||||
ssize_t indexOf(const TYPE& item) const;
|
||||
|
||||
//! finds where this item should be inserted
|
||||
size_t orderOf(const TYPE& item) const;
|
||||
|
||||
|
||||
/*!
|
||||
* accessors
|
||||
*/
|
||||
|
||||
//! read-only access to an item at a given index
|
||||
inline const TYPE& operator [] (size_t index) const;
|
||||
//! alternate name for operator []
|
||||
inline const TYPE& itemAt(size_t index) const;
|
||||
//! stack-usage of the vector. returns the top of the stack (last element)
|
||||
const TYPE& top() const;
|
||||
|
||||
/*!
|
||||
* modifying the array
|
||||
*/
|
||||
|
||||
//! add an item in the right place (and replace the one that is there)
|
||||
ssize_t add(const TYPE& item);
|
||||
|
||||
//! editItemAt() MUST NOT change the order of this item
|
||||
TYPE& editItemAt(size_t index) {
|
||||
return *( static_cast<TYPE *>(VectorImpl::editItemLocation(index)) );
|
||||
}
|
||||
|
||||
//! merges a vector into this one
|
||||
ssize_t merge(const Vector<TYPE>& vector);
|
||||
ssize_t merge(const SortedVector<TYPE>& vector);
|
||||
|
||||
//! removes an item
|
||||
ssize_t remove(const TYPE&);
|
||||
|
||||
//! remove several items
|
||||
inline ssize_t removeItemsAt(size_t index, size_t count = 1);
|
||||
//! remove one item
|
||||
inline ssize_t removeAt(size_t index) { return removeItemsAt(index); }
|
||||
|
||||
protected:
|
||||
virtual void do_construct(void* storage, size_t num) const;
|
||||
virtual void do_destroy(void* storage, size_t num) const;
|
||||
virtual void do_copy(void* dest, const void* from, size_t num) const;
|
||||
virtual void do_splat(void* dest, const void* item, size_t num) const;
|
||||
virtual void do_move_forward(void* dest, const void* from, size_t num) const;
|
||||
virtual void do_move_backward(void* dest, const void* from, size_t num) const;
|
||||
virtual int do_compare(const void* lhs, const void* rhs) const;
|
||||
};
|
||||
|
||||
// SortedVector<T> can be trivially moved using memcpy() because moving does not
|
||||
// require any change to the underlying SharedBuffer contents or reference count.
|
||||
template<typename T> struct trait_trivial_move<SortedVector<T> > { enum { value = true }; };
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user serviceable parts from here...
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template<class TYPE> inline
|
||||
SortedVector<TYPE>::SortedVector()
|
||||
: SortedVectorImpl(sizeof(TYPE),
|
||||
((traits<TYPE>::has_trivial_ctor ? HAS_TRIVIAL_CTOR : 0)
|
||||
|(traits<TYPE>::has_trivial_dtor ? HAS_TRIVIAL_DTOR : 0)
|
||||
|(traits<TYPE>::has_trivial_copy ? HAS_TRIVIAL_COPY : 0))
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
SortedVector<TYPE>::SortedVector(const SortedVector<TYPE>& rhs)
|
||||
: SortedVectorImpl(rhs) {
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
SortedVector<TYPE>::~SortedVector() {
|
||||
finish_vector();
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
SortedVector<TYPE>& SortedVector<TYPE>::operator = (const SortedVector<TYPE>& rhs) {
|
||||
SortedVectorImpl::operator = (rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const SortedVector<TYPE>& SortedVector<TYPE>::operator = (const SortedVector<TYPE>& rhs) const {
|
||||
SortedVectorImpl::operator = (rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE* SortedVector<TYPE>::array() const {
|
||||
return static_cast<const TYPE *>(arrayImpl());
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
TYPE* SortedVector<TYPE>::editArray() {
|
||||
return static_cast<TYPE *>(editArrayImpl());
|
||||
}
|
||||
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE& SortedVector<TYPE>::operator[](size_t index) const {
|
||||
LOG_FATAL_IF(index>=size(),
|
||||
"%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
|
||||
int(index), int(size()));
|
||||
return *(array() + index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE& SortedVector<TYPE>::itemAt(size_t index) const {
|
||||
return operator[](index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE& SortedVector<TYPE>::top() const {
|
||||
return *(array() + size() - 1);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t SortedVector<TYPE>::add(const TYPE& item) {
|
||||
return SortedVectorImpl::add(&item);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t SortedVector<TYPE>::indexOf(const TYPE& item) const {
|
||||
return SortedVectorImpl::indexOf(&item);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
size_t SortedVector<TYPE>::orderOf(const TYPE& item) const {
|
||||
return SortedVectorImpl::orderOf(&item);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t SortedVector<TYPE>::merge(const Vector<TYPE>& vector) {
|
||||
return SortedVectorImpl::merge(reinterpret_cast<const VectorImpl&>(vector));
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t SortedVector<TYPE>::merge(const SortedVector<TYPE>& vector) {
|
||||
return SortedVectorImpl::merge(reinterpret_cast<const SortedVectorImpl&>(vector));
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t SortedVector<TYPE>::remove(const TYPE& item) {
|
||||
return SortedVectorImpl::remove(&item);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t SortedVector<TYPE>::removeItemsAt(size_t index, size_t count) {
|
||||
return VectorImpl::removeItemsAt(index, count);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template<class TYPE>
|
||||
void SortedVector<TYPE>::do_construct(void* storage, size_t num) const {
|
||||
construct_type( reinterpret_cast<TYPE*>(storage), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void SortedVector<TYPE>::do_destroy(void* storage, size_t num) const {
|
||||
destroy_type( reinterpret_cast<TYPE*>(storage), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void SortedVector<TYPE>::do_copy(void* dest, const void* from, size_t num) const {
|
||||
copy_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void SortedVector<TYPE>::do_splat(void* dest, const void* item, size_t num) const {
|
||||
splat_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(item), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void SortedVector<TYPE>::do_move_forward(void* dest, const void* from, size_t num) const {
|
||||
move_forward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void SortedVector<TYPE>::do_move_backward(void* dest, const void* from, size_t num) const {
|
||||
move_backward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
int SortedVector<TYPE>::do_compare(const void* lhs, const void* rhs) const {
|
||||
return compare_type( *reinterpret_cast<const TYPE*>(lhs), *reinterpret_cast<const TYPE*>(rhs) );
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_SORTED_VECTOR_H
|
|
@ -0,0 +1,243 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_STRING16_H
|
||||
#define ANDROID_STRING16_H
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/SharedBuffer.h>
|
||||
#include <utils/Unicode.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class String8;
|
||||
class TextOutput;
|
||||
|
||||
//! This is a string holding UTF-16 characters.
|
||||
class String16
|
||||
{
|
||||
public:
|
||||
String16();
|
||||
String16(const String16& o);
|
||||
String16(const String16& o,
|
||||
size_t len,
|
||||
size_t begin=0);
|
||||
explicit String16(const char16_t* o);
|
||||
explicit String16(const char16_t* o, size_t len);
|
||||
explicit String16(const String8& o);
|
||||
explicit String16(const char* o);
|
||||
explicit String16(const char* o, size_t len);
|
||||
|
||||
~String16();
|
||||
|
||||
inline const char16_t* string() const;
|
||||
inline size_t size() const;
|
||||
|
||||
inline const SharedBuffer* sharedBuffer() const;
|
||||
|
||||
void setTo(const String16& other);
|
||||
status_t setTo(const char16_t* other);
|
||||
status_t setTo(const char16_t* other, size_t len);
|
||||
status_t setTo(const String16& other,
|
||||
size_t len,
|
||||
size_t begin=0);
|
||||
|
||||
status_t append(const String16& other);
|
||||
status_t append(const char16_t* other, size_t len);
|
||||
|
||||
inline String16& operator=(const String16& other);
|
||||
|
||||
inline String16& operator+=(const String16& other);
|
||||
inline String16 operator+(const String16& other) const;
|
||||
|
||||
status_t insert(size_t pos, const char16_t* chrs);
|
||||
status_t insert(size_t pos,
|
||||
const char16_t* chrs, size_t len);
|
||||
|
||||
ssize_t findFirst(char16_t c) const;
|
||||
ssize_t findLast(char16_t c) const;
|
||||
|
||||
bool startsWith(const String16& prefix) const;
|
||||
bool startsWith(const char16_t* prefix) const;
|
||||
|
||||
status_t makeLower();
|
||||
|
||||
status_t replaceAll(char16_t replaceThis,
|
||||
char16_t withThis);
|
||||
|
||||
status_t remove(size_t len, size_t begin=0);
|
||||
|
||||
inline int compare(const String16& other) const;
|
||||
|
||||
inline bool operator<(const String16& other) const;
|
||||
inline bool operator<=(const String16& other) const;
|
||||
inline bool operator==(const String16& other) const;
|
||||
inline bool operator!=(const String16& other) const;
|
||||
inline bool operator>=(const String16& other) const;
|
||||
inline bool operator>(const String16& other) const;
|
||||
|
||||
inline bool operator<(const char16_t* other) const;
|
||||
inline bool operator<=(const char16_t* other) const;
|
||||
inline bool operator==(const char16_t* other) const;
|
||||
inline bool operator!=(const char16_t* other) const;
|
||||
inline bool operator>=(const char16_t* other) const;
|
||||
inline bool operator>(const char16_t* other) const;
|
||||
|
||||
inline operator const char16_t*() const;
|
||||
|
||||
private:
|
||||
const char16_t* mString;
|
||||
};
|
||||
|
||||
// String16 can be trivially moved using memcpy() because moving does not
|
||||
// require any change to the underlying SharedBuffer contents or reference count.
|
||||
ANDROID_TRIVIAL_MOVE_TRAIT(String16)
|
||||
|
||||
TextOutput& operator<<(TextOutput& to, const String16& val);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user servicable parts below.
|
||||
|
||||
inline int compare_type(const String16& lhs, const String16& rhs)
|
||||
{
|
||||
return lhs.compare(rhs);
|
||||
}
|
||||
|
||||
inline int strictly_order_type(const String16& lhs, const String16& rhs)
|
||||
{
|
||||
return compare_type(lhs, rhs) < 0;
|
||||
}
|
||||
|
||||
inline const char16_t* String16::string() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
inline size_t String16::size() const
|
||||
{
|
||||
return SharedBuffer::sizeFromData(mString)/sizeof(char16_t)-1;
|
||||
}
|
||||
|
||||
inline const SharedBuffer* String16::sharedBuffer() const
|
||||
{
|
||||
return SharedBuffer::bufferFromData(mString);
|
||||
}
|
||||
|
||||
inline String16& String16::operator=(const String16& other)
|
||||
{
|
||||
setTo(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline String16& String16::operator+=(const String16& other)
|
||||
{
|
||||
append(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline String16 String16::operator+(const String16& other) const
|
||||
{
|
||||
String16 tmp(*this);
|
||||
tmp += other;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int String16::compare(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size());
|
||||
}
|
||||
|
||||
inline bool String16::operator<(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size()) < 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator<=(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size()) <= 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator==(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size()) == 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator!=(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size()) != 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator>=(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size()) >= 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator>(const String16& other) const
|
||||
{
|
||||
return strzcmp16(mString, size(), other.mString, other.size()) > 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator<(const char16_t* other) const
|
||||
{
|
||||
return strcmp16(mString, other) < 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator<=(const char16_t* other) const
|
||||
{
|
||||
return strcmp16(mString, other) <= 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator==(const char16_t* other) const
|
||||
{
|
||||
return strcmp16(mString, other) == 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator!=(const char16_t* other) const
|
||||
{
|
||||
return strcmp16(mString, other) != 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator>=(const char16_t* other) const
|
||||
{
|
||||
return strcmp16(mString, other) >= 0;
|
||||
}
|
||||
|
||||
inline bool String16::operator>(const char16_t* other) const
|
||||
{
|
||||
return strcmp16(mString, other) > 0;
|
||||
}
|
||||
|
||||
inline String16::operator const char16_t*() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_STRING16_H
|
|
@ -0,0 +1,388 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_STRING8_H
|
||||
#define ANDROID_STRING8_H
|
||||
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/SharedBuffer.h>
|
||||
#include <utils/Unicode.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
#include <string.h> // for strcmp
|
||||
#include <stdarg.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
class String16;
|
||||
class TextOutput;
|
||||
|
||||
//! This is a string holding UTF-8 characters. Does not allow the value more
|
||||
// than 0x10FFFF, which is not valid unicode codepoint.
|
||||
class String8
|
||||
{
|
||||
public:
|
||||
String8();
|
||||
String8(const String8& o);
|
||||
explicit String8(const char* o);
|
||||
explicit String8(const char* o, size_t numChars);
|
||||
|
||||
explicit String8(const String16& o);
|
||||
explicit String8(const char16_t* o);
|
||||
explicit String8(const char16_t* o, size_t numChars);
|
||||
explicit String8(const char32_t* o);
|
||||
explicit String8(const char32_t* o, size_t numChars);
|
||||
~String8();
|
||||
|
||||
static inline const String8 empty();
|
||||
|
||||
static String8 format(const char* fmt, ...) __attribute__((format (printf, 1, 2)));
|
||||
static String8 formatV(const char* fmt, va_list args);
|
||||
|
||||
inline const char* string() const;
|
||||
inline size_t size() const;
|
||||
inline size_t length() const;
|
||||
inline size_t bytes() const;
|
||||
inline bool isEmpty() const;
|
||||
|
||||
inline const SharedBuffer* sharedBuffer() const;
|
||||
|
||||
void clear();
|
||||
|
||||
void setTo(const String8& other);
|
||||
status_t setTo(const char* other);
|
||||
status_t setTo(const char* other, size_t numChars);
|
||||
status_t setTo(const char16_t* other, size_t numChars);
|
||||
status_t setTo(const char32_t* other,
|
||||
size_t length);
|
||||
|
||||
status_t append(const String8& other);
|
||||
status_t append(const char* other);
|
||||
status_t append(const char* other, size_t numChars);
|
||||
|
||||
status_t appendFormat(const char* fmt, ...)
|
||||
__attribute__((format (printf, 2, 3)));
|
||||
status_t appendFormatV(const char* fmt, va_list args);
|
||||
|
||||
// Note that this function takes O(N) time to calculate the value.
|
||||
// No cache value is stored.
|
||||
size_t getUtf32Length() const;
|
||||
int32_t getUtf32At(size_t index,
|
||||
size_t *next_index) const;
|
||||
void getUtf32(char32_t* dst) const;
|
||||
|
||||
inline String8& operator=(const String8& other);
|
||||
inline String8& operator=(const char* other);
|
||||
|
||||
inline String8& operator+=(const String8& other);
|
||||
inline String8 operator+(const String8& other) const;
|
||||
|
||||
inline String8& operator+=(const char* other);
|
||||
inline String8 operator+(const char* other) const;
|
||||
|
||||
inline int compare(const String8& other) const;
|
||||
|
||||
inline bool operator<(const String8& other) const;
|
||||
inline bool operator<=(const String8& other) const;
|
||||
inline bool operator==(const String8& other) const;
|
||||
inline bool operator!=(const String8& other) const;
|
||||
inline bool operator>=(const String8& other) const;
|
||||
inline bool operator>(const String8& other) const;
|
||||
|
||||
inline bool operator<(const char* other) const;
|
||||
inline bool operator<=(const char* other) const;
|
||||
inline bool operator==(const char* other) const;
|
||||
inline bool operator!=(const char* other) const;
|
||||
inline bool operator>=(const char* other) const;
|
||||
inline bool operator>(const char* other) const;
|
||||
|
||||
inline operator const char*() const;
|
||||
|
||||
char* lockBuffer(size_t size);
|
||||
void unlockBuffer();
|
||||
status_t unlockBuffer(size_t size);
|
||||
|
||||
// return the index of the first byte of other in this at or after
|
||||
// start, or -1 if not found
|
||||
ssize_t find(const char* other, size_t start = 0) const;
|
||||
|
||||
void toLower();
|
||||
void toLower(size_t start, size_t numChars);
|
||||
void toUpper();
|
||||
void toUpper(size_t start, size_t numChars);
|
||||
|
||||
/*
|
||||
* These methods operate on the string as if it were a path name.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set the filename field to a specific value.
|
||||
*
|
||||
* Normalizes the filename, removing a trailing '/' if present.
|
||||
*/
|
||||
void setPathName(const char* name);
|
||||
void setPathName(const char* name, size_t numChars);
|
||||
|
||||
/*
|
||||
* Get just the filename component.
|
||||
*
|
||||
* "/tmp/foo/bar.c" --> "bar.c"
|
||||
*/
|
||||
String8 getPathLeaf(void) const;
|
||||
|
||||
/*
|
||||
* Remove the last (file name) component, leaving just the directory
|
||||
* name.
|
||||
*
|
||||
* "/tmp/foo/bar.c" --> "/tmp/foo"
|
||||
* "/tmp" --> "" // ????? shouldn't this be "/" ???? XXX
|
||||
* "bar.c" --> ""
|
||||
*/
|
||||
String8 getPathDir(void) const;
|
||||
|
||||
/*
|
||||
* Retrieve the front (root dir) component. Optionally also return the
|
||||
* remaining components.
|
||||
*
|
||||
* "/tmp/foo/bar.c" --> "tmp" (remain = "foo/bar.c")
|
||||
* "/tmp" --> "tmp" (remain = "")
|
||||
* "bar.c" --> "bar.c" (remain = "")
|
||||
*/
|
||||
String8 walkPath(String8* outRemains = NULL) const;
|
||||
|
||||
/*
|
||||
* Return the filename extension. This is the last '.' and any number
|
||||
* of characters that follow it. The '.' is included in case we
|
||||
* decide to expand our definition of what constitutes an extension.
|
||||
*
|
||||
* "/tmp/foo/bar.c" --> ".c"
|
||||
* "/tmp" --> ""
|
||||
* "/tmp/foo.bar/baz" --> ""
|
||||
* "foo.jpeg" --> ".jpeg"
|
||||
* "foo." --> ""
|
||||
*/
|
||||
String8 getPathExtension(void) const;
|
||||
|
||||
/*
|
||||
* Return the path without the extension. Rules for what constitutes
|
||||
* an extension are described in the comment for getPathExtension().
|
||||
*
|
||||
* "/tmp/foo/bar.c" --> "/tmp/foo/bar"
|
||||
*/
|
||||
String8 getBasePath(void) const;
|
||||
|
||||
/*
|
||||
* Add a component to the pathname. We guarantee that there is
|
||||
* exactly one path separator between the old path and the new.
|
||||
* If there is no existing name, we just copy the new name in.
|
||||
*
|
||||
* If leaf is a fully qualified path (i.e. starts with '/', it
|
||||
* replaces whatever was there before.
|
||||
*/
|
||||
String8& appendPath(const char* leaf);
|
||||
String8& appendPath(const String8& leaf) { return appendPath(leaf.string()); }
|
||||
|
||||
/*
|
||||
* Like appendPath(), but does not affect this string. Returns a new one instead.
|
||||
*/
|
||||
String8 appendPathCopy(const char* leaf) const
|
||||
{ String8 p(*this); p.appendPath(leaf); return p; }
|
||||
String8 appendPathCopy(const String8& leaf) const { return appendPathCopy(leaf.string()); }
|
||||
|
||||
/*
|
||||
* Converts all separators in this string to /, the default path separator.
|
||||
*
|
||||
* If the default OS separator is backslash, this converts all
|
||||
* backslashes to slashes, in-place. Otherwise it does nothing.
|
||||
* Returns self.
|
||||
*/
|
||||
String8& convertToResPath();
|
||||
|
||||
private:
|
||||
status_t real_append(const char* other, size_t numChars);
|
||||
char* find_extension(void) const;
|
||||
|
||||
const char* mString;
|
||||
};
|
||||
|
||||
// String8 can be trivially moved using memcpy() because moving does not
|
||||
// require any change to the underlying SharedBuffer contents or reference count.
|
||||
ANDROID_TRIVIAL_MOVE_TRAIT(String8)
|
||||
|
||||
TextOutput& operator<<(TextOutput& to, const String16& val);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user servicable parts below.
|
||||
|
||||
inline int compare_type(const String8& lhs, const String8& rhs)
|
||||
{
|
||||
return lhs.compare(rhs);
|
||||
}
|
||||
|
||||
inline int strictly_order_type(const String8& lhs, const String8& rhs)
|
||||
{
|
||||
return compare_type(lhs, rhs) < 0;
|
||||
}
|
||||
|
||||
inline const String8 String8::empty() {
|
||||
return String8();
|
||||
}
|
||||
|
||||
inline const char* String8::string() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
inline size_t String8::length() const
|
||||
{
|
||||
return SharedBuffer::sizeFromData(mString)-1;
|
||||
}
|
||||
|
||||
inline size_t String8::size() const
|
||||
{
|
||||
return length();
|
||||
}
|
||||
|
||||
inline bool String8::isEmpty() const
|
||||
{
|
||||
return length() == 0;
|
||||
}
|
||||
|
||||
inline size_t String8::bytes() const
|
||||
{
|
||||
return SharedBuffer::sizeFromData(mString)-1;
|
||||
}
|
||||
|
||||
inline const SharedBuffer* String8::sharedBuffer() const
|
||||
{
|
||||
return SharedBuffer::bufferFromData(mString);
|
||||
}
|
||||
|
||||
inline String8& String8::operator=(const String8& other)
|
||||
{
|
||||
setTo(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline String8& String8::operator=(const char* other)
|
||||
{
|
||||
setTo(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline String8& String8::operator+=(const String8& other)
|
||||
{
|
||||
append(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline String8 String8::operator+(const String8& other) const
|
||||
{
|
||||
String8 tmp(*this);
|
||||
tmp += other;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline String8& String8::operator+=(const char* other)
|
||||
{
|
||||
append(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline String8 String8::operator+(const char* other) const
|
||||
{
|
||||
String8 tmp(*this);
|
||||
tmp += other;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline int String8::compare(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString);
|
||||
}
|
||||
|
||||
inline bool String8::operator<(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString) < 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator<=(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString) <= 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator==(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString) == 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator!=(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString) != 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator>=(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString) >= 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator>(const String8& other) const
|
||||
{
|
||||
return strcmp(mString, other.mString) > 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator<(const char* other) const
|
||||
{
|
||||
return strcmp(mString, other) < 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator<=(const char* other) const
|
||||
{
|
||||
return strcmp(mString, other) <= 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator==(const char* other) const
|
||||
{
|
||||
return strcmp(mString, other) == 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator!=(const char* other) const
|
||||
{
|
||||
return strcmp(mString, other) != 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator>=(const char* other) const
|
||||
{
|
||||
return strcmp(mString, other) >= 0;
|
||||
}
|
||||
|
||||
inline bool String8::operator>(const char* other) const
|
||||
{
|
||||
return strcmp(mString, other) > 0;
|
||||
}
|
||||
|
||||
inline String8::operator const char*() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_STRING8_H
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// Sortable array of strings. STL-ish, but STL-free.
|
||||
//
|
||||
#ifndef _LIBS_UTILS_STRING_ARRAY_H
|
||||
#define _LIBS_UTILS_STRING_ARRAY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
//
|
||||
// An expanding array of strings. Add, get, sort, delete.
|
||||
//
|
||||
class StringArray {
|
||||
public:
|
||||
StringArray();
|
||||
virtual ~StringArray();
|
||||
|
||||
//
|
||||
// Add a string. A copy of the string is made.
|
||||
//
|
||||
bool push_back(const char* str);
|
||||
|
||||
//
|
||||
// Delete an entry.
|
||||
//
|
||||
void erase(int idx);
|
||||
|
||||
//
|
||||
// Sort the array.
|
||||
//
|
||||
void sort(int (*compare)(const void*, const void*));
|
||||
|
||||
//
|
||||
// Pass this to the sort routine to do an ascending alphabetical sort.
|
||||
//
|
||||
static int cmpAscendingAlpha(const void* pstr1, const void* pstr2);
|
||||
|
||||
//
|
||||
// Get the #of items in the array.
|
||||
//
|
||||
inline int size(void) const { return mCurrent; }
|
||||
|
||||
//
|
||||
// Return entry N.
|
||||
// [should use operator[] here]
|
||||
//
|
||||
const char* getEntry(int idx) const {
|
||||
return (unsigned(idx) >= unsigned(mCurrent)) ? NULL : mArray[idx];
|
||||
}
|
||||
|
||||
//
|
||||
// Set entry N to specified string.
|
||||
// [should use operator[] here]
|
||||
//
|
||||
void setEntry(int idx, const char* str);
|
||||
|
||||
private:
|
||||
int mMax;
|
||||
int mCurrent;
|
||||
char** mArray;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // _LIBS_UTILS_STRING_ARRAY_H
|
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_STRONG_POINTER_H
|
||||
#define ANDROID_STRONG_POINTER_H
|
||||
|
||||
#include <cutils/atomic.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
|
||||
class TextOutput;
|
||||
TextOutput& printStrongPointer(TextOutput& to, const void* val);
|
||||
|
||||
template<typename T> class wp;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#define COMPARE(_op_) \
|
||||
inline bool operator _op_ (const sp<T>& o) const { \
|
||||
return m_ptr _op_ o.m_ptr; \
|
||||
} \
|
||||
inline bool operator _op_ (const T* o) const { \
|
||||
return m_ptr _op_ o; \
|
||||
} \
|
||||
template<typename U> \
|
||||
inline bool operator _op_ (const sp<U>& o) const { \
|
||||
return m_ptr _op_ o.m_ptr; \
|
||||
} \
|
||||
template<typename U> \
|
||||
inline bool operator _op_ (const U* o) const { \
|
||||
return m_ptr _op_ o; \
|
||||
} \
|
||||
inline bool operator _op_ (const wp<T>& o) const { \
|
||||
return m_ptr _op_ o.m_ptr; \
|
||||
} \
|
||||
template<typename U> \
|
||||
inline bool operator _op_ (const wp<U>& o) const { \
|
||||
return m_ptr _op_ o.m_ptr; \
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
class sp
|
||||
{
|
||||
public:
|
||||
inline sp() : m_ptr(0) { }
|
||||
|
||||
sp(T* other);
|
||||
sp(const sp<T>& other);
|
||||
template<typename U> sp(U* other);
|
||||
template<typename U> sp(const sp<U>& other);
|
||||
|
||||
~sp();
|
||||
|
||||
// Assignment
|
||||
|
||||
sp& operator = (T* other);
|
||||
sp& operator = (const sp<T>& other);
|
||||
|
||||
template<typename U> sp& operator = (const sp<U>& other);
|
||||
template<typename U> sp& operator = (U* other);
|
||||
|
||||
//! Special optimization for use by ProcessState (and nobody else).
|
||||
void force_set(T* other);
|
||||
|
||||
// Reset
|
||||
|
||||
void clear();
|
||||
|
||||
// Accessors
|
||||
|
||||
inline T& operator* () const { return *m_ptr; }
|
||||
inline T* operator-> () const { return m_ptr; }
|
||||
inline T* get() const { return m_ptr; }
|
||||
|
||||
// Operators
|
||||
|
||||
COMPARE(==)
|
||||
COMPARE(!=)
|
||||
COMPARE(>)
|
||||
COMPARE(<)
|
||||
COMPARE(<=)
|
||||
COMPARE(>=)
|
||||
|
||||
private:
|
||||
template<typename Y> friend class sp;
|
||||
template<typename Y> friend class wp;
|
||||
void set_pointer(T* ptr);
|
||||
T* m_ptr;
|
||||
};
|
||||
|
||||
#undef COMPARE
|
||||
|
||||
template <typename T>
|
||||
TextOutput& operator<<(TextOutput& to, const sp<T>& val);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user serviceable parts below here.
|
||||
|
||||
template<typename T>
|
||||
sp<T>::sp(T* other)
|
||||
: m_ptr(other)
|
||||
{
|
||||
if (other) other->incStrong(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sp<T>::sp(const sp<T>& other)
|
||||
: m_ptr(other.m_ptr)
|
||||
{
|
||||
if (m_ptr) m_ptr->incStrong(this);
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
sp<T>::sp(U* other) : m_ptr(other)
|
||||
{
|
||||
if (other) ((T*)other)->incStrong(this);
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
sp<T>::sp(const sp<U>& other)
|
||||
: m_ptr(other.m_ptr)
|
||||
{
|
||||
if (m_ptr) m_ptr->incStrong(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sp<T>::~sp()
|
||||
{
|
||||
if (m_ptr) m_ptr->decStrong(this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sp<T>& sp<T>::operator = (const sp<T>& other) {
|
||||
T* otherPtr(other.m_ptr);
|
||||
if (otherPtr) otherPtr->incStrong(this);
|
||||
if (m_ptr) m_ptr->decStrong(this);
|
||||
m_ptr = otherPtr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
sp<T>& sp<T>::operator = (T* other)
|
||||
{
|
||||
if (other) other->incStrong(this);
|
||||
if (m_ptr) m_ptr->decStrong(this);
|
||||
m_ptr = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
sp<T>& sp<T>::operator = (const sp<U>& other)
|
||||
{
|
||||
T* otherPtr(other.m_ptr);
|
||||
if (otherPtr) otherPtr->incStrong(this);
|
||||
if (m_ptr) m_ptr->decStrong(this);
|
||||
m_ptr = otherPtr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> template<typename U>
|
||||
sp<T>& sp<T>::operator = (U* other)
|
||||
{
|
||||
if (other) ((T*)other)->incStrong(this);
|
||||
if (m_ptr) m_ptr->decStrong(this);
|
||||
m_ptr = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void sp<T>::force_set(T* other)
|
||||
{
|
||||
other->forceIncStrong(this);
|
||||
m_ptr = other;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void sp<T>::clear()
|
||||
{
|
||||
if (m_ptr) {
|
||||
m_ptr->decStrong(this);
|
||||
m_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void sp<T>::set_pointer(T* ptr) {
|
||||
m_ptr = ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline TextOutput& operator<<(TextOutput& to, const sp<T>& val)
|
||||
{
|
||||
return printStrongPointer(to, val.get());
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_STRONG_POINTER_H
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_THREAD_H
|
||||
#define _LIBS_UTILS_THREAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(HAVE_PTHREADS)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <utils/Condition.h>
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/Mutex.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/Timers.h>
|
||||
#include <utils/ThreadDefs.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class Thread : virtual public RefBase
|
||||
{
|
||||
public:
|
||||
// Create a Thread object, but doesn't create or start the associated
|
||||
// thread. See the run() method.
|
||||
Thread(bool canCallJava = true);
|
||||
virtual ~Thread();
|
||||
|
||||
// Start the thread in threadLoop() which needs to be implemented.
|
||||
virtual status_t run( const char* name = 0,
|
||||
int32_t priority = PRIORITY_DEFAULT,
|
||||
size_t stack = 0);
|
||||
|
||||
// Ask this object's thread to exit. This function is asynchronous, when the
|
||||
// function returns the thread might still be running. Of course, this
|
||||
// function can be called from a different thread.
|
||||
virtual void requestExit();
|
||||
|
||||
// Good place to do one-time initializations
|
||||
virtual status_t readyToRun();
|
||||
|
||||
// Call requestExit() and wait until this object's thread exits.
|
||||
// BE VERY CAREFUL of deadlocks. In particular, it would be silly to call
|
||||
// this function from this object's thread. Will return WOULD_BLOCK in
|
||||
// that case.
|
||||
status_t requestExitAndWait();
|
||||
|
||||
// Wait until this object's thread exits. Returns immediately if not yet running.
|
||||
// Do not call from this object's thread; will return WOULD_BLOCK in that case.
|
||||
status_t join();
|
||||
|
||||
// Indicates whether this thread is running or not.
|
||||
bool isRunning() const;
|
||||
|
||||
#ifdef HAVE_ANDROID_OS
|
||||
// Return the thread's kernel ID, same as the thread itself calling gettid() or
|
||||
// androidGetTid(), or -1 if the thread is not running.
|
||||
pid_t getTid() const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// exitPending() returns true if requestExit() has been called.
|
||||
bool exitPending() const;
|
||||
|
||||
private:
|
||||
// Derived class must implement threadLoop(). The thread starts its life
|
||||
// here. There are two ways of using the Thread object:
|
||||
// 1) loop: if threadLoop() returns true, it will be called again if
|
||||
// requestExit() wasn't called.
|
||||
// 2) once: if threadLoop() returns false, the thread will exit upon return.
|
||||
virtual bool threadLoop() = 0;
|
||||
|
||||
private:
|
||||
Thread& operator=(const Thread&);
|
||||
static int _threadLoop(void* user);
|
||||
const bool mCanCallJava;
|
||||
// always hold mLock when reading or writing
|
||||
thread_id_t mThread;
|
||||
mutable Mutex mLock;
|
||||
Condition mThreadExitedCondition;
|
||||
status_t mStatus;
|
||||
// note that all accesses of mExitPending and mRunning need to hold mLock
|
||||
volatile bool mExitPending;
|
||||
volatile bool mRunning;
|
||||
sp<Thread> mHoldSelf;
|
||||
#ifdef HAVE_ANDROID_OS
|
||||
// legacy for debugging, not used by getTid() as it is set by the child thread
|
||||
// and so is not initialized until the child reaches that point
|
||||
pid_t mTid;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
#endif // _LIBS_UTILS_THREAD_H
|
||||
// ---------------------------------------------------------------------------
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_THREAD_DEFS_H
|
||||
#define _LIBS_UTILS_THREAD_DEFS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <system/graphics.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C API
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* android_thread_id_t;
|
||||
|
||||
typedef int (*android_thread_func_t)(void*);
|
||||
|
||||
enum {
|
||||
/*
|
||||
* ***********************************************
|
||||
* ** Keep in sync with android.os.Process.java **
|
||||
* ***********************************************
|
||||
*
|
||||
* This maps directly to the "nice" priorities we use in Android.
|
||||
* A thread priority should be chosen inverse-proportionally to
|
||||
* the amount of work the thread is expected to do. The more work
|
||||
* a thread will do, the less favorable priority it should get so that
|
||||
* it doesn't starve the system. Threads not behaving properly might
|
||||
* be "punished" by the kernel.
|
||||
* Use the levels below when appropriate. Intermediate values are
|
||||
* acceptable, preferably use the {MORE|LESS}_FAVORABLE constants below.
|
||||
*/
|
||||
ANDROID_PRIORITY_LOWEST = 19,
|
||||
|
||||
/* use for background tasks */
|
||||
ANDROID_PRIORITY_BACKGROUND = 10,
|
||||
|
||||
/* most threads run at normal priority */
|
||||
ANDROID_PRIORITY_NORMAL = 0,
|
||||
|
||||
/* threads currently running a UI that the user is interacting with */
|
||||
ANDROID_PRIORITY_FOREGROUND = -2,
|
||||
|
||||
/* the main UI thread has a slightly more favorable priority */
|
||||
ANDROID_PRIORITY_DISPLAY = -4,
|
||||
|
||||
/* ui service treads might want to run at a urgent display (uncommon) */
|
||||
ANDROID_PRIORITY_URGENT_DISPLAY = HAL_PRIORITY_URGENT_DISPLAY,
|
||||
|
||||
/* all normal audio threads */
|
||||
ANDROID_PRIORITY_AUDIO = -16,
|
||||
|
||||
/* service audio threads (uncommon) */
|
||||
ANDROID_PRIORITY_URGENT_AUDIO = -19,
|
||||
|
||||
/* should never be used in practice. regular process might not
|
||||
* be allowed to use this level */
|
||||
ANDROID_PRIORITY_HIGHEST = -20,
|
||||
|
||||
ANDROID_PRIORITY_DEFAULT = ANDROID_PRIORITY_NORMAL,
|
||||
ANDROID_PRIORITY_MORE_FAVORABLE = -1,
|
||||
ANDROID_PRIORITY_LESS_FAVORABLE = +1,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C++ API
|
||||
#ifdef __cplusplus
|
||||
namespace android {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef android_thread_id_t thread_id_t;
|
||||
typedef android_thread_func_t thread_func_t;
|
||||
|
||||
enum {
|
||||
PRIORITY_LOWEST = ANDROID_PRIORITY_LOWEST,
|
||||
PRIORITY_BACKGROUND = ANDROID_PRIORITY_BACKGROUND,
|
||||
PRIORITY_NORMAL = ANDROID_PRIORITY_NORMAL,
|
||||
PRIORITY_FOREGROUND = ANDROID_PRIORITY_FOREGROUND,
|
||||
PRIORITY_DISPLAY = ANDROID_PRIORITY_DISPLAY,
|
||||
PRIORITY_URGENT_DISPLAY = ANDROID_PRIORITY_URGENT_DISPLAY,
|
||||
PRIORITY_AUDIO = ANDROID_PRIORITY_AUDIO,
|
||||
PRIORITY_URGENT_AUDIO = ANDROID_PRIORITY_URGENT_AUDIO,
|
||||
PRIORITY_HIGHEST = ANDROID_PRIORITY_HIGHEST,
|
||||
PRIORITY_DEFAULT = ANDROID_PRIORITY_DEFAULT,
|
||||
PRIORITY_MORE_FAVORABLE = ANDROID_PRIORITY_MORE_FAVORABLE,
|
||||
PRIORITY_LESS_FAVORABLE = ANDROID_PRIORITY_LESS_FAVORABLE,
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
}; // namespace android
|
||||
#endif // __cplusplus
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
#endif // _LIBS_UTILS_THREAD_DEFS_H
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// Timer functions.
|
||||
//
|
||||
#ifndef _LIBS_UTILS_TIMERS_H
|
||||
#define _LIBS_UTILS_TIMERS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// C API
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int64_t nsecs_t; // nano-seconds
|
||||
|
||||
static inline nsecs_t seconds_to_nanoseconds(nsecs_t secs)
|
||||
{
|
||||
return secs*1000000000;
|
||||
}
|
||||
|
||||
static inline nsecs_t milliseconds_to_nanoseconds(nsecs_t secs)
|
||||
{
|
||||
return secs*1000000;
|
||||
}
|
||||
|
||||
static inline nsecs_t microseconds_to_nanoseconds(nsecs_t secs)
|
||||
{
|
||||
return secs*1000;
|
||||
}
|
||||
|
||||
static inline nsecs_t nanoseconds_to_seconds(nsecs_t secs)
|
||||
{
|
||||
return secs/1000000000;
|
||||
}
|
||||
|
||||
static inline nsecs_t nanoseconds_to_milliseconds(nsecs_t secs)
|
||||
{
|
||||
return secs/1000000;
|
||||
}
|
||||
|
||||
static inline nsecs_t nanoseconds_to_microseconds(nsecs_t secs)
|
||||
{
|
||||
return secs/1000;
|
||||
}
|
||||
|
||||
static inline nsecs_t s2ns(nsecs_t v) {return seconds_to_nanoseconds(v);}
|
||||
static inline nsecs_t ms2ns(nsecs_t v) {return milliseconds_to_nanoseconds(v);}
|
||||
static inline nsecs_t us2ns(nsecs_t v) {return microseconds_to_nanoseconds(v);}
|
||||
static inline nsecs_t ns2s(nsecs_t v) {return nanoseconds_to_seconds(v);}
|
||||
static inline nsecs_t ns2ms(nsecs_t v) {return nanoseconds_to_milliseconds(v);}
|
||||
static inline nsecs_t ns2us(nsecs_t v) {return nanoseconds_to_microseconds(v);}
|
||||
|
||||
static inline nsecs_t seconds(nsecs_t v) { return s2ns(v); }
|
||||
static inline nsecs_t milliseconds(nsecs_t v) { return ms2ns(v); }
|
||||
static inline nsecs_t microseconds(nsecs_t v) { return us2ns(v); }
|
||||
|
||||
enum {
|
||||
SYSTEM_TIME_REALTIME = 0, // system-wide realtime clock
|
||||
SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point
|
||||
SYSTEM_TIME_PROCESS = 2, // high-resolution per-process clock
|
||||
SYSTEM_TIME_THREAD = 3, // high-resolution per-thread clock
|
||||
SYSTEM_TIME_BOOTTIME = 4 // same as SYSTEM_TIME_MONOTONIC, but including CPU suspend time
|
||||
};
|
||||
|
||||
// return the system-time according to the specified clock
|
||||
#ifdef __cplusplus
|
||||
nsecs_t systemTime(int clock = SYSTEM_TIME_MONOTONIC);
|
||||
#else
|
||||
nsecs_t systemTime(int clock);
|
||||
#endif // def __cplusplus
|
||||
|
||||
/**
|
||||
* Returns the number of milliseconds to wait between the reference time and the timeout time.
|
||||
* If the timeout is in the past relative to the reference time, returns 0.
|
||||
* If the timeout is more than INT_MAX milliseconds in the future relative to the reference time,
|
||||
* such as when timeoutTime == LLONG_MAX, returns -1 to indicate an infinite timeout delay.
|
||||
* Otherwise, returns the difference between the reference time and timeout time
|
||||
* rounded up to the next millisecond.
|
||||
*/
|
||||
int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// C++ API
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace android {
|
||||
/*
|
||||
* Time the duration of something.
|
||||
*
|
||||
* Includes some timeval manipulation functions.
|
||||
*/
|
||||
class DurationTimer {
|
||||
public:
|
||||
DurationTimer() {}
|
||||
~DurationTimer() {}
|
||||
|
||||
// Start the timer.
|
||||
void start();
|
||||
// Stop the timer.
|
||||
void stop();
|
||||
// Get the duration in microseconds.
|
||||
long long durationUsecs() const;
|
||||
|
||||
// Subtract two timevals. Returns the difference (ptv1-ptv2) in
|
||||
// microseconds.
|
||||
static long long subtractTimevals(const struct timeval* ptv1,
|
||||
const struct timeval* ptv2);
|
||||
|
||||
// Add the specified amount of time to the timeval.
|
||||
static void addToTimeval(struct timeval* ptv, long usec);
|
||||
|
||||
private:
|
||||
struct timeval mStartWhen;
|
||||
struct timeval mStopWhen;
|
||||
};
|
||||
|
||||
}; // android
|
||||
#endif // def __cplusplus
|
||||
|
||||
#endif // _LIBS_UTILS_TIMERS_H
|
|
@ -0,0 +1,302 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_TYPE_HELPERS_H
|
||||
#define ANDROID_TYPE_HELPERS_H
|
||||
|
||||
#include <new>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* Types traits
|
||||
*/
|
||||
|
||||
template <typename T> struct trait_trivial_ctor { enum { value = false }; };
|
||||
template <typename T> struct trait_trivial_dtor { enum { value = false }; };
|
||||
template <typename T> struct trait_trivial_copy { enum { value = false }; };
|
||||
template <typename T> struct trait_trivial_move { enum { value = false }; };
|
||||
template <typename T> struct trait_pointer { enum { value = false }; };
|
||||
template <typename T> struct trait_pointer<T*> { enum { value = true }; };
|
||||
|
||||
template <typename TYPE>
|
||||
struct traits {
|
||||
enum {
|
||||
// whether this type is a pointer
|
||||
is_pointer = trait_pointer<TYPE>::value,
|
||||
// whether this type's constructor is a no-op
|
||||
has_trivial_ctor = is_pointer || trait_trivial_ctor<TYPE>::value,
|
||||
// whether this type's destructor is a no-op
|
||||
has_trivial_dtor = is_pointer || trait_trivial_dtor<TYPE>::value,
|
||||
// whether this type type can be copy-constructed with memcpy
|
||||
has_trivial_copy = is_pointer || trait_trivial_copy<TYPE>::value,
|
||||
// whether this type can be moved with memmove
|
||||
has_trivial_move = is_pointer || trait_trivial_move<TYPE>::value
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct aggregate_traits {
|
||||
enum {
|
||||
is_pointer = false,
|
||||
has_trivial_ctor =
|
||||
traits<T>::has_trivial_ctor && traits<U>::has_trivial_ctor,
|
||||
has_trivial_dtor =
|
||||
traits<T>::has_trivial_dtor && traits<U>::has_trivial_dtor,
|
||||
has_trivial_copy =
|
||||
traits<T>::has_trivial_copy && traits<U>::has_trivial_copy,
|
||||
has_trivial_move =
|
||||
traits<T>::has_trivial_move && traits<U>::has_trivial_move
|
||||
};
|
||||
};
|
||||
|
||||
#define ANDROID_TRIVIAL_CTOR_TRAIT( T ) \
|
||||
template<> struct trait_trivial_ctor< T > { enum { value = true }; };
|
||||
|
||||
#define ANDROID_TRIVIAL_DTOR_TRAIT( T ) \
|
||||
template<> struct trait_trivial_dtor< T > { enum { value = true }; };
|
||||
|
||||
#define ANDROID_TRIVIAL_COPY_TRAIT( T ) \
|
||||
template<> struct trait_trivial_copy< T > { enum { value = true }; };
|
||||
|
||||
#define ANDROID_TRIVIAL_MOVE_TRAIT( T ) \
|
||||
template<> struct trait_trivial_move< T > { enum { value = true }; };
|
||||
|
||||
#define ANDROID_BASIC_TYPES_TRAITS( T ) \
|
||||
ANDROID_TRIVIAL_CTOR_TRAIT( T ) \
|
||||
ANDROID_TRIVIAL_DTOR_TRAIT( T ) \
|
||||
ANDROID_TRIVIAL_COPY_TRAIT( T ) \
|
||||
ANDROID_TRIVIAL_MOVE_TRAIT( T )
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* basic types traits
|
||||
*/
|
||||
|
||||
ANDROID_BASIC_TYPES_TRAITS( void )
|
||||
ANDROID_BASIC_TYPES_TRAITS( bool )
|
||||
ANDROID_BASIC_TYPES_TRAITS( char )
|
||||
ANDROID_BASIC_TYPES_TRAITS( unsigned char )
|
||||
ANDROID_BASIC_TYPES_TRAITS( short )
|
||||
ANDROID_BASIC_TYPES_TRAITS( unsigned short )
|
||||
ANDROID_BASIC_TYPES_TRAITS( int )
|
||||
ANDROID_BASIC_TYPES_TRAITS( unsigned int )
|
||||
ANDROID_BASIC_TYPES_TRAITS( long )
|
||||
ANDROID_BASIC_TYPES_TRAITS( unsigned long )
|
||||
ANDROID_BASIC_TYPES_TRAITS( long long )
|
||||
ANDROID_BASIC_TYPES_TRAITS( unsigned long long )
|
||||
ANDROID_BASIC_TYPES_TRAITS( float )
|
||||
ANDROID_BASIC_TYPES_TRAITS( double )
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
/*
|
||||
* compare and order types
|
||||
*/
|
||||
|
||||
template<typename TYPE> inline
|
||||
int strictly_order_type(const TYPE& lhs, const TYPE& rhs) {
|
||||
return (lhs < rhs) ? 1 : 0;
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
int compare_type(const TYPE& lhs, const TYPE& rhs) {
|
||||
return strictly_order_type(rhs, lhs) - strictly_order_type(lhs, rhs);
|
||||
}
|
||||
|
||||
/*
|
||||
* create, destroy, copy and move types...
|
||||
*/
|
||||
|
||||
template<typename TYPE> inline
|
||||
void construct_type(TYPE* p, size_t n) {
|
||||
if (!traits<TYPE>::has_trivial_ctor) {
|
||||
while (n--) {
|
||||
new(p++) TYPE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void destroy_type(TYPE* p, size_t n) {
|
||||
if (!traits<TYPE>::has_trivial_dtor) {
|
||||
while (n--) {
|
||||
p->~TYPE();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void copy_type(TYPE* d, const TYPE* s, size_t n) {
|
||||
if (!traits<TYPE>::has_trivial_copy) {
|
||||
while (n--) {
|
||||
new(d) TYPE(*s);
|
||||
d++, s++;
|
||||
}
|
||||
} else {
|
||||
memcpy(d,s,n*sizeof(TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void splat_type(TYPE* where, const TYPE* what, size_t n) {
|
||||
if (!traits<TYPE>::has_trivial_copy) {
|
||||
while (n--) {
|
||||
new(where) TYPE(*what);
|
||||
where++;
|
||||
}
|
||||
} else {
|
||||
while (n--) {
|
||||
*where++ = *what;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
|
||||
if ((traits<TYPE>::has_trivial_dtor && traits<TYPE>::has_trivial_copy)
|
||||
|| traits<TYPE>::has_trivial_move)
|
||||
{
|
||||
memmove(d,s,n*sizeof(TYPE));
|
||||
} else {
|
||||
d += n;
|
||||
s += n;
|
||||
while (n--) {
|
||||
--d, --s;
|
||||
if (!traits<TYPE>::has_trivial_copy) {
|
||||
new(d) TYPE(*s);
|
||||
} else {
|
||||
*d = *s;
|
||||
}
|
||||
if (!traits<TYPE>::has_trivial_dtor) {
|
||||
s->~TYPE();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TYPE> inline
|
||||
void move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
|
||||
if ((traits<TYPE>::has_trivial_dtor && traits<TYPE>::has_trivial_copy)
|
||||
|| traits<TYPE>::has_trivial_move)
|
||||
{
|
||||
memmove(d,s,n*sizeof(TYPE));
|
||||
} else {
|
||||
while (n--) {
|
||||
if (!traits<TYPE>::has_trivial_copy) {
|
||||
new(d) TYPE(*s);
|
||||
} else {
|
||||
*d = *s;
|
||||
}
|
||||
if (!traits<TYPE>::has_trivial_dtor) {
|
||||
s->~TYPE();
|
||||
}
|
||||
d++, s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* a key/value pair
|
||||
*/
|
||||
|
||||
template <typename KEY, typename VALUE>
|
||||
struct key_value_pair_t {
|
||||
typedef KEY key_t;
|
||||
typedef VALUE value_t;
|
||||
|
||||
KEY key;
|
||||
VALUE value;
|
||||
key_value_pair_t() { }
|
||||
key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { }
|
||||
key_value_pair_t(const KEY& k, const VALUE& v) : key(k), value(v) { }
|
||||
key_value_pair_t(const KEY& k) : key(k) { }
|
||||
inline bool operator < (const key_value_pair_t& o) const {
|
||||
return strictly_order_type(key, o.key);
|
||||
}
|
||||
inline const KEY& getKey() const {
|
||||
return key;
|
||||
}
|
||||
inline const VALUE& getValue() const {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct trait_trivial_ctor< key_value_pair_t<K, V> >
|
||||
{ enum { value = aggregate_traits<K,V>::has_trivial_ctor }; };
|
||||
template <typename K, typename V>
|
||||
struct trait_trivial_dtor< key_value_pair_t<K, V> >
|
||||
{ enum { value = aggregate_traits<K,V>::has_trivial_dtor }; };
|
||||
template <typename K, typename V>
|
||||
struct trait_trivial_copy< key_value_pair_t<K, V> >
|
||||
{ enum { value = aggregate_traits<K,V>::has_trivial_copy }; };
|
||||
template <typename K, typename V>
|
||||
struct trait_trivial_move< key_value_pair_t<K, V> >
|
||||
{ enum { value = aggregate_traits<K,V>::has_trivial_move }; };
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Hash codes.
|
||||
*/
|
||||
typedef uint32_t hash_t;
|
||||
|
||||
template <typename TKey>
|
||||
hash_t hash_type(const TKey& key);
|
||||
|
||||
/* Built-in hash code specializations.
|
||||
* Assumes pointers are 32bit. */
|
||||
#define ANDROID_INT32_HASH(T) \
|
||||
template <> inline hash_t hash_type(const T& value) { return hash_t(value); }
|
||||
#define ANDROID_INT64_HASH(T) \
|
||||
template <> inline hash_t hash_type(const T& value) { \
|
||||
return hash_t((value >> 32) ^ value); }
|
||||
#define ANDROID_REINTERPRET_HASH(T, R) \
|
||||
template <> inline hash_t hash_type(const T& value) { \
|
||||
return hash_type(*reinterpret_cast<const R*>(&value)); }
|
||||
|
||||
ANDROID_INT32_HASH(bool)
|
||||
ANDROID_INT32_HASH(int8_t)
|
||||
ANDROID_INT32_HASH(uint8_t)
|
||||
ANDROID_INT32_HASH(int16_t)
|
||||
ANDROID_INT32_HASH(uint16_t)
|
||||
ANDROID_INT32_HASH(int32_t)
|
||||
ANDROID_INT32_HASH(uint32_t)
|
||||
ANDROID_INT64_HASH(int64_t)
|
||||
ANDROID_INT64_HASH(uint64_t)
|
||||
ANDROID_REINTERPRET_HASH(float, uint32_t)
|
||||
ANDROID_REINTERPRET_HASH(double, uint64_t)
|
||||
|
||||
template <typename T> inline hash_t hash_type(T* const & value) {
|
||||
return hash_type(uintptr_t(value));
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_TYPE_HELPERS_H
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_UNICODE_H
|
||||
#define ANDROID_UNICODE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if !defined(__cplusplus) || __cplusplus == 199711L // C or C++98
|
||||
typedef uint32_t char32_t;
|
||||
typedef uint16_t char16_t;
|
||||
#endif
|
||||
|
||||
// Standard string functions on char16_t strings.
|
||||
int strcmp16(const char16_t *, const char16_t *);
|
||||
int strncmp16(const char16_t *s1, const char16_t *s2, size_t n);
|
||||
size_t strlen16(const char16_t *);
|
||||
size_t strnlen16(const char16_t *, size_t);
|
||||
char16_t *strcpy16(char16_t *, const char16_t *);
|
||||
char16_t *strncpy16(char16_t *, const char16_t *, size_t);
|
||||
|
||||
// Version of comparison that supports embedded nulls.
|
||||
// This is different than strncmp() because we don't stop
|
||||
// at a nul character and consider the strings to be different
|
||||
// if the lengths are different (thus we need to supply the
|
||||
// lengths of both strings). This can also be used when
|
||||
// your string is not nul-terminated as it will have the
|
||||
// equivalent result as strcmp16 (unlike strncmp16).
|
||||
int strzcmp16(const char16_t *s1, size_t n1, const char16_t *s2, size_t n2);
|
||||
|
||||
// Version of strzcmp16 for comparing strings in different endianness.
|
||||
int strzcmp16_h_n(const char16_t *s1H, size_t n1, const char16_t *s2N, size_t n2);
|
||||
|
||||
// Standard string functions on char32_t strings.
|
||||
size_t strlen32(const char32_t *);
|
||||
size_t strnlen32(const char32_t *, size_t);
|
||||
|
||||
/**
|
||||
* Measure the length of a UTF-32 string in UTF-8. If the string is invalid
|
||||
* such as containing a surrogate character, -1 will be returned.
|
||||
*/
|
||||
ssize_t utf32_to_utf8_length(const char32_t *src, size_t src_len);
|
||||
|
||||
/**
|
||||
* Stores a UTF-8 string converted from "src" in "dst", if "dst_length" is not
|
||||
* large enough to store the string, the part of the "src" string is stored
|
||||
* into "dst" as much as possible. See the examples for more detail.
|
||||
* Returns the size actually used for storing the string.
|
||||
* dst" is not null-terminated when dst_len is fully used (like strncpy).
|
||||
*
|
||||
* Example 1
|
||||
* "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
|
||||
* "src_len" == 2
|
||||
* "dst_len" >= 7
|
||||
* ->
|
||||
* Returned value == 6
|
||||
* "dst" becomes \xE3\x81\x82\xE3\x81\x84\0
|
||||
* (note that "dst" is null-terminated)
|
||||
*
|
||||
* Example 2
|
||||
* "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
|
||||
* "src_len" == 2
|
||||
* "dst_len" == 5
|
||||
* ->
|
||||
* Returned value == 3
|
||||
* "dst" becomes \xE3\x81\x82\0
|
||||
* (note that "dst" is null-terminated, but \u3044 is not stored in "dst"
|
||||
* since "dst" does not have enough size to store the character)
|
||||
*
|
||||
* Example 3
|
||||
* "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
|
||||
* "src_len" == 2
|
||||
* "dst_len" == 6
|
||||
* ->
|
||||
* Returned value == 6
|
||||
* "dst" becomes \xE3\x81\x82\xE3\x81\x84
|
||||
* (note that "dst" is NOT null-terminated, like strncpy)
|
||||
*/
|
||||
void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst);
|
||||
|
||||
/**
|
||||
* Returns the unicode value at "index".
|
||||
* Returns -1 when the index is invalid (equals to or more than "src_len").
|
||||
* If returned value is positive, it is able to be converted to char32_t, which
|
||||
* is unsigned. Then, if "next_index" is not NULL, the next index to be used is
|
||||
* stored in "next_index". "next_index" can be NULL.
|
||||
*/
|
||||
int32_t utf32_from_utf8_at(const char *src, size_t src_len, size_t index, size_t *next_index);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the UTF-8 length of UTF-16 string "src".
|
||||
*/
|
||||
ssize_t utf16_to_utf8_length(const char16_t *src, size_t src_len);
|
||||
|
||||
/**
|
||||
* Converts a UTF-16 string to UTF-8. The destination buffer must be large
|
||||
* enough to fit the UTF-16 as measured by utf16_to_utf8_length with an added
|
||||
* NULL terminator.
|
||||
*/
|
||||
void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst);
|
||||
|
||||
/**
|
||||
* Returns the length of "src" when "src" is valid UTF-8 string.
|
||||
* Returns 0 if src is NULL or 0-length string. Returns -1 when the source
|
||||
* is an invalid string.
|
||||
*
|
||||
* This function should be used to determine whether "src" is valid UTF-8
|
||||
* characters with valid unicode codepoints. "src" must be null-terminated.
|
||||
*
|
||||
* If you are going to use other utf8_to_... functions defined in this header
|
||||
* with string which may not be valid UTF-8 with valid codepoint (form 0 to
|
||||
* 0x10FFFF), you should use this function before calling others, since the
|
||||
* other functions do not check whether the string is valid UTF-8 or not.
|
||||
*
|
||||
* If you do not care whether "src" is valid UTF-8 or not, you should use
|
||||
* strlen() as usual, which should be much faster.
|
||||
*/
|
||||
ssize_t utf8_length(const char *src);
|
||||
|
||||
/**
|
||||
* Measure the length of a UTF-32 string.
|
||||
*/
|
||||
size_t utf8_to_utf32_length(const char *src, size_t src_len);
|
||||
|
||||
/**
|
||||
* Stores a UTF-32 string converted from "src" in "dst". "dst" must be large
|
||||
* enough to store the entire converted string as measured by
|
||||
* utf8_to_utf32_length plus space for a NULL terminator.
|
||||
*/
|
||||
void utf8_to_utf32(const char* src, size_t src_len, char32_t* dst);
|
||||
|
||||
/**
|
||||
* Returns the UTF-16 length of UTF-8 string "src".
|
||||
*/
|
||||
ssize_t utf8_to_utf16_length(const uint8_t* src, size_t srcLen);
|
||||
|
||||
/**
|
||||
* Convert UTF-8 to UTF-16 including surrogate pairs.
|
||||
* Returns a pointer to the end of the string (where a null terminator might go
|
||||
* if you wanted to add one).
|
||||
*/
|
||||
char16_t* utf8_to_utf16_no_null_terminator(const uint8_t* src, size_t srcLen, char16_t* dst);
|
||||
|
||||
/**
|
||||
* Convert UTF-8 to UTF-16 including surrogate pairs. The destination buffer
|
||||
* must be large enough to hold the result as measured by utf8_to_utf16_length
|
||||
* plus an added NULL terminator.
|
||||
*/
|
||||
void utf8_to_utf16(const uint8_t* src, size_t srcLen, char16_t* dst);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,239 @@
|
|||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* === NOTE === NOTE === NOTE === NOTE === NOTE === NOTE === NOTE === NOTE ===
|
||||
*
|
||||
* THIS IS A COPY OF libcore/include/UniquePtr.h AND AS SUCH THAT IS THE
|
||||
* CANONICAL SOURCE OF THIS FILE. PLEASE KEEP THEM IN SYNC.
|
||||
*
|
||||
* === NOTE === NOTE === NOTE === NOTE === NOTE === NOTE === NOTE === NOTE ===
|
||||
*/
|
||||
|
||||
#ifndef UNIQUE_PTR_H_included
|
||||
#define UNIQUE_PTR_H_included
|
||||
|
||||
#include <cstdlib> // For NULL.
|
||||
|
||||
// Default deleter for pointer types.
|
||||
template <typename T>
|
||||
struct DefaultDelete {
|
||||
enum { type_must_be_complete = sizeof(T) };
|
||||
DefaultDelete() {}
|
||||
void operator()(T* p) const {
|
||||
delete p;
|
||||
}
|
||||
};
|
||||
|
||||
// Default deleter for array types.
|
||||
template <typename T>
|
||||
struct DefaultDelete<T[]> {
|
||||
enum { type_must_be_complete = sizeof(T) };
|
||||
void operator()(T* p) const {
|
||||
delete[] p;
|
||||
}
|
||||
};
|
||||
|
||||
// A smart pointer that deletes the given pointer on destruction.
|
||||
// Equivalent to C++0x's std::unique_ptr (a combination of boost::scoped_ptr
|
||||
// and boost::scoped_array).
|
||||
// Named to be in keeping with Android style but also to avoid
|
||||
// collision with any other implementation, until we can switch over
|
||||
// to unique_ptr.
|
||||
// Use thus:
|
||||
// UniquePtr<C> c(new C);
|
||||
template <typename T, typename D = DefaultDelete<T> >
|
||||
class UniquePtr {
|
||||
public:
|
||||
// Construct a new UniquePtr, taking ownership of the given raw pointer.
|
||||
explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) {
|
||||
}
|
||||
|
||||
~UniquePtr() {
|
||||
reset();
|
||||
}
|
||||
|
||||
// Accessors.
|
||||
T& operator*() const { return *mPtr; }
|
||||
T* operator->() const { return mPtr; }
|
||||
T* get() const { return mPtr; }
|
||||
|
||||
// Returns the raw pointer and hands over ownership to the caller.
|
||||
// The pointer will not be deleted by UniquePtr.
|
||||
T* release() __attribute__((warn_unused_result)) {
|
||||
T* result = mPtr;
|
||||
mPtr = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Takes ownership of the given raw pointer.
|
||||
// If this smart pointer previously owned a different raw pointer, that
|
||||
// raw pointer will be freed.
|
||||
void reset(T* ptr = NULL) {
|
||||
if (ptr != mPtr) {
|
||||
D()(mPtr);
|
||||
mPtr = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// The raw pointer.
|
||||
T* mPtr;
|
||||
|
||||
// Comparing unique pointers is probably a mistake, since they're unique.
|
||||
template <typename T2> bool operator==(const UniquePtr<T2>& p) const;
|
||||
template <typename T2> bool operator!=(const UniquePtr<T2>& p) const;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
UniquePtr(const UniquePtr&);
|
||||
void operator=(const UniquePtr&);
|
||||
};
|
||||
|
||||
// Partial specialization for array types. Like std::unique_ptr, this removes
|
||||
// operator* and operator-> but adds operator[].
|
||||
template <typename T, typename D>
|
||||
class UniquePtr<T[], D> {
|
||||
public:
|
||||
explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) {
|
||||
}
|
||||
|
||||
~UniquePtr() {
|
||||
reset();
|
||||
}
|
||||
|
||||
T& operator[](size_t i) const {
|
||||
return mPtr[i];
|
||||
}
|
||||
T* get() const { return mPtr; }
|
||||
|
||||
T* release() __attribute__((warn_unused_result)) {
|
||||
T* result = mPtr;
|
||||
mPtr = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
void reset(T* ptr = NULL) {
|
||||
if (ptr != mPtr) {
|
||||
D()(mPtr);
|
||||
mPtr = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T* mPtr;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
UniquePtr(const UniquePtr&);
|
||||
void operator=(const UniquePtr&);
|
||||
};
|
||||
|
||||
#if UNIQUE_PTR_TESTS
|
||||
|
||||
// Run these tests with:
|
||||
// g++ -g -DUNIQUE_PTR_TESTS -x c++ UniquePtr.h && ./a.out
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static void assert(bool b) {
|
||||
if (!b) {
|
||||
fprintf(stderr, "FAIL\n");
|
||||
abort();
|
||||
}
|
||||
fprintf(stderr, "OK\n");
|
||||
}
|
||||
static int cCount = 0;
|
||||
struct C {
|
||||
C() { ++cCount; }
|
||||
~C() { --cCount; }
|
||||
};
|
||||
static bool freed = false;
|
||||
struct Freer {
|
||||
void operator()(int* p) {
|
||||
assert(*p == 123);
|
||||
free(p);
|
||||
freed = true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
//
|
||||
// UniquePtr<T> tests...
|
||||
//
|
||||
|
||||
// Can we free a single object?
|
||||
{
|
||||
UniquePtr<C> c(new C);
|
||||
assert(cCount == 1);
|
||||
}
|
||||
assert(cCount == 0);
|
||||
// Does release work?
|
||||
C* rawC;
|
||||
{
|
||||
UniquePtr<C> c(new C);
|
||||
assert(cCount == 1);
|
||||
rawC = c.release();
|
||||
}
|
||||
assert(cCount == 1);
|
||||
delete rawC;
|
||||
// Does reset work?
|
||||
{
|
||||
UniquePtr<C> c(new C);
|
||||
assert(cCount == 1);
|
||||
c.reset(new C);
|
||||
assert(cCount == 1);
|
||||
}
|
||||
assert(cCount == 0);
|
||||
|
||||
//
|
||||
// UniquePtr<T[]> tests...
|
||||
//
|
||||
|
||||
// Can we free an array?
|
||||
{
|
||||
UniquePtr<C[]> cs(new C[4]);
|
||||
assert(cCount == 4);
|
||||
}
|
||||
assert(cCount == 0);
|
||||
// Does release work?
|
||||
{
|
||||
UniquePtr<C[]> c(new C[4]);
|
||||
assert(cCount == 4);
|
||||
rawC = c.release();
|
||||
}
|
||||
assert(cCount == 4);
|
||||
delete[] rawC;
|
||||
// Does reset work?
|
||||
{
|
||||
UniquePtr<C[]> c(new C[4]);
|
||||
assert(cCount == 4);
|
||||
c.reset(new C[2]);
|
||||
assert(cCount == 2);
|
||||
}
|
||||
assert(cCount == 0);
|
||||
|
||||
//
|
||||
// Custom deleter tests...
|
||||
//
|
||||
assert(!freed);
|
||||
{
|
||||
UniquePtr<int, Freer> i(reinterpret_cast<int*>(malloc(sizeof(int))));
|
||||
*i = 123;
|
||||
}
|
||||
assert(freed);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UNIQUE_PTR_H_included
|
|
@ -0,0 +1,423 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_VECTOR_H
|
||||
#define ANDROID_VECTOR_H
|
||||
|
||||
#include <new>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/log.h>
|
||||
|
||||
#include <utils/VectorImpl.h>
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
template <typename TYPE>
|
||||
class SortedVector;
|
||||
|
||||
/*!
|
||||
* The main templated vector class ensuring type safety
|
||||
* while making use of VectorImpl.
|
||||
* This is the class users want to use.
|
||||
*/
|
||||
|
||||
template <class TYPE>
|
||||
class Vector : private VectorImpl
|
||||
{
|
||||
public:
|
||||
typedef TYPE value_type;
|
||||
|
||||
/*!
|
||||
* Constructors and destructors
|
||||
*/
|
||||
|
||||
Vector();
|
||||
Vector(const Vector<TYPE>& rhs);
|
||||
explicit Vector(const SortedVector<TYPE>& rhs);
|
||||
virtual ~Vector();
|
||||
|
||||
/*! copy operator */
|
||||
const Vector<TYPE>& operator = (const Vector<TYPE>& rhs) const;
|
||||
Vector<TYPE>& operator = (const Vector<TYPE>& rhs);
|
||||
|
||||
const Vector<TYPE>& operator = (const SortedVector<TYPE>& rhs) const;
|
||||
Vector<TYPE>& operator = (const SortedVector<TYPE>& rhs);
|
||||
|
||||
/*
|
||||
* empty the vector
|
||||
*/
|
||||
|
||||
inline void clear() { VectorImpl::clear(); }
|
||||
|
||||
/*!
|
||||
* vector stats
|
||||
*/
|
||||
|
||||
//! returns number of items in the vector
|
||||
inline size_t size() const { return VectorImpl::size(); }
|
||||
//! returns whether or not the vector is empty
|
||||
inline bool isEmpty() const { return VectorImpl::isEmpty(); }
|
||||
//! returns how many items can be stored without reallocating the backing store
|
||||
inline size_t capacity() const { return VectorImpl::capacity(); }
|
||||
//! sets the capacity. capacity can never be reduced less than size()
|
||||
inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
|
||||
|
||||
/*!
|
||||
* set the size of the vector. items are appended with the default
|
||||
* constructor, or removed from the end as needed.
|
||||
*/
|
||||
inline ssize_t resize(size_t size) { return VectorImpl::resize(size); }
|
||||
|
||||
/*!
|
||||
* C-style array access
|
||||
*/
|
||||
|
||||
//! read-only C-style access
|
||||
inline const TYPE* array() const;
|
||||
//! read-write C-style access
|
||||
TYPE* editArray();
|
||||
|
||||
/*!
|
||||
* accessors
|
||||
*/
|
||||
|
||||
//! read-only access to an item at a given index
|
||||
inline const TYPE& operator [] (size_t index) const;
|
||||
//! alternate name for operator []
|
||||
inline const TYPE& itemAt(size_t index) const;
|
||||
//! stack-usage of the vector. returns the top of the stack (last element)
|
||||
const TYPE& top() const;
|
||||
|
||||
/*!
|
||||
* modifying the array
|
||||
*/
|
||||
|
||||
//! copy-on write support, grants write access to an item
|
||||
TYPE& editItemAt(size_t index);
|
||||
//! grants right access to the top of the stack (last element)
|
||||
TYPE& editTop();
|
||||
|
||||
/*!
|
||||
* append/insert another vector
|
||||
*/
|
||||
|
||||
//! insert another vector at a given index
|
||||
ssize_t insertVectorAt(const Vector<TYPE>& vector, size_t index);
|
||||
|
||||
//! append another vector at the end of this one
|
||||
ssize_t appendVector(const Vector<TYPE>& vector);
|
||||
|
||||
|
||||
//! insert an array at a given index
|
||||
ssize_t insertArrayAt(const TYPE* array, size_t index, size_t length);
|
||||
|
||||
//! append an array at the end of this vector
|
||||
ssize_t appendArray(const TYPE* array, size_t length);
|
||||
|
||||
/*!
|
||||
* add/insert/replace items
|
||||
*/
|
||||
|
||||
//! insert one or several items initialized with their default constructor
|
||||
inline ssize_t insertAt(size_t index, size_t numItems = 1);
|
||||
//! insert one or several items initialized from a prototype item
|
||||
ssize_t insertAt(const TYPE& prototype_item, size_t index, size_t numItems = 1);
|
||||
//! pop the top of the stack (removes the last element). No-op if the stack's empty
|
||||
inline void pop();
|
||||
//! pushes an item initialized with its default constructor
|
||||
inline void push();
|
||||
//! pushes an item on the top of the stack
|
||||
void push(const TYPE& item);
|
||||
//! same as push() but returns the index the item was added at (or an error)
|
||||
inline ssize_t add();
|
||||
//! same as push() but returns the index the item was added at (or an error)
|
||||
ssize_t add(const TYPE& item);
|
||||
//! replace an item with a new one initialized with its default constructor
|
||||
inline ssize_t replaceAt(size_t index);
|
||||
//! replace an item with a new one
|
||||
ssize_t replaceAt(const TYPE& item, size_t index);
|
||||
|
||||
/*!
|
||||
* remove items
|
||||
*/
|
||||
|
||||
//! remove several items
|
||||
inline ssize_t removeItemsAt(size_t index, size_t count = 1);
|
||||
//! remove one item
|
||||
inline ssize_t removeAt(size_t index) { return removeItemsAt(index); }
|
||||
|
||||
/*!
|
||||
* sort (stable) the array
|
||||
*/
|
||||
|
||||
typedef int (*compar_t)(const TYPE* lhs, const TYPE* rhs);
|
||||
typedef int (*compar_r_t)(const TYPE* lhs, const TYPE* rhs, void* state);
|
||||
|
||||
inline status_t sort(compar_t cmp);
|
||||
inline status_t sort(compar_r_t cmp, void* state);
|
||||
|
||||
// for debugging only
|
||||
inline size_t getItemSize() const { return itemSize(); }
|
||||
|
||||
|
||||
/*
|
||||
* these inlines add some level of compatibility with STL. eventually
|
||||
* we should probably turn things around.
|
||||
*/
|
||||
typedef TYPE* iterator;
|
||||
typedef TYPE const* const_iterator;
|
||||
|
||||
inline iterator begin() { return editArray(); }
|
||||
inline iterator end() { return editArray() + size(); }
|
||||
inline const_iterator begin() const { return array(); }
|
||||
inline const_iterator end() const { return array() + size(); }
|
||||
inline void reserve(size_t n) { setCapacity(n); }
|
||||
inline bool empty() const{ return isEmpty(); }
|
||||
inline void push_back(const TYPE& item) { insertAt(item, size(), 1); }
|
||||
inline void push_front(const TYPE& item) { insertAt(item, 0, 1); }
|
||||
inline iterator erase(iterator pos) {
|
||||
ssize_t index = removeItemsAt(pos-array());
|
||||
return begin() + index;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void do_construct(void* storage, size_t num) const;
|
||||
virtual void do_destroy(void* storage, size_t num) const;
|
||||
virtual void do_copy(void* dest, const void* from, size_t num) const;
|
||||
virtual void do_splat(void* dest, const void* item, size_t num) const;
|
||||
virtual void do_move_forward(void* dest, const void* from, size_t num) const;
|
||||
virtual void do_move_backward(void* dest, const void* from, size_t num) const;
|
||||
};
|
||||
|
||||
// Vector<T> can be trivially moved using memcpy() because moving does not
|
||||
// require any change to the underlying SharedBuffer contents or reference count.
|
||||
template<typename T> struct trait_trivial_move<Vector<T> > { enum { value = true }; };
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user serviceable parts from here...
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template<class TYPE> inline
|
||||
Vector<TYPE>::Vector()
|
||||
: VectorImpl(sizeof(TYPE),
|
||||
((traits<TYPE>::has_trivial_ctor ? HAS_TRIVIAL_CTOR : 0)
|
||||
|(traits<TYPE>::has_trivial_dtor ? HAS_TRIVIAL_DTOR : 0)
|
||||
|(traits<TYPE>::has_trivial_copy ? HAS_TRIVIAL_COPY : 0))
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
Vector<TYPE>::Vector(const Vector<TYPE>& rhs)
|
||||
: VectorImpl(rhs) {
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
Vector<TYPE>::Vector(const SortedVector<TYPE>& rhs)
|
||||
: VectorImpl(static_cast<const VectorImpl&>(rhs)) {
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
Vector<TYPE>::~Vector() {
|
||||
finish_vector();
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) {
|
||||
VectorImpl::operator = (rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) const {
|
||||
VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
Vector<TYPE>& Vector<TYPE>::operator = (const SortedVector<TYPE>& rhs) {
|
||||
VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const Vector<TYPE>& Vector<TYPE>::operator = (const SortedVector<TYPE>& rhs) const {
|
||||
VectorImpl::operator = (rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE* Vector<TYPE>::array() const {
|
||||
return static_cast<const TYPE *>(arrayImpl());
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
TYPE* Vector<TYPE>::editArray() {
|
||||
return static_cast<TYPE *>(editArrayImpl());
|
||||
}
|
||||
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE& Vector<TYPE>::operator[](size_t index) const {
|
||||
LOG_FATAL_IF(index>=size(),
|
||||
"%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
|
||||
int(index), int(size()));
|
||||
return *(array() + index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE& Vector<TYPE>::itemAt(size_t index) const {
|
||||
return operator[](index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
const TYPE& Vector<TYPE>::top() const {
|
||||
return *(array() + size() - 1);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
TYPE& Vector<TYPE>::editItemAt(size_t index) {
|
||||
return *( static_cast<TYPE *>(editItemLocation(index)) );
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
TYPE& Vector<TYPE>::editTop() {
|
||||
return *( static_cast<TYPE *>(editItemLocation(size()-1)) );
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::insertVectorAt(const Vector<TYPE>& vector, size_t index) {
|
||||
return VectorImpl::insertVectorAt(reinterpret_cast<const VectorImpl&>(vector), index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::appendVector(const Vector<TYPE>& vector) {
|
||||
return VectorImpl::appendVector(reinterpret_cast<const VectorImpl&>(vector));
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::insertArrayAt(const TYPE* array, size_t index, size_t length) {
|
||||
return VectorImpl::insertArrayAt(array, index, length);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::appendArray(const TYPE* array, size_t length) {
|
||||
return VectorImpl::appendArray(array, length);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::insertAt(const TYPE& item, size_t index, size_t numItems) {
|
||||
return VectorImpl::insertAt(&item, index, numItems);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
void Vector<TYPE>::push(const TYPE& item) {
|
||||
return VectorImpl::push(&item);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::add(const TYPE& item) {
|
||||
return VectorImpl::add(&item);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::replaceAt(const TYPE& item, size_t index) {
|
||||
return VectorImpl::replaceAt(&item, index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::insertAt(size_t index, size_t numItems) {
|
||||
return VectorImpl::insertAt(index, numItems);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
void Vector<TYPE>::pop() {
|
||||
VectorImpl::pop();
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
void Vector<TYPE>::push() {
|
||||
VectorImpl::push();
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::add() {
|
||||
return VectorImpl::add();
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::replaceAt(size_t index) {
|
||||
return VectorImpl::replaceAt(index);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
ssize_t Vector<TYPE>::removeItemsAt(size_t index, size_t count) {
|
||||
return VectorImpl::removeItemsAt(index, count);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
status_t Vector<TYPE>::sort(Vector<TYPE>::compar_t cmp) {
|
||||
return VectorImpl::sort((VectorImpl::compar_t)cmp);
|
||||
}
|
||||
|
||||
template<class TYPE> inline
|
||||
status_t Vector<TYPE>::sort(Vector<TYPE>::compar_r_t cmp, void* state) {
|
||||
return VectorImpl::sort((VectorImpl::compar_r_t)cmp, state);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
template<class TYPE>
|
||||
void Vector<TYPE>::do_construct(void* storage, size_t num) const {
|
||||
construct_type( reinterpret_cast<TYPE*>(storage), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void Vector<TYPE>::do_destroy(void* storage, size_t num) const {
|
||||
destroy_type( reinterpret_cast<TYPE*>(storage), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void Vector<TYPE>::do_copy(void* dest, const void* from, size_t num) const {
|
||||
copy_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void Vector<TYPE>::do_splat(void* dest, const void* item, size_t num) const {
|
||||
splat_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(item), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void Vector<TYPE>::do_move_forward(void* dest, const void* from, size_t num) const {
|
||||
move_forward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
|
||||
}
|
||||
|
||||
template<class TYPE>
|
||||
void Vector<TYPE>::do_move_backward(void* dest, const void* from, size_t num) const {
|
||||
move_backward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_VECTOR_H
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* Copyright (C) 2005 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_VECTOR_IMPL_H
|
||||
#define ANDROID_VECTOR_IMPL_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// No user serviceable parts in here...
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace android {
|
||||
|
||||
/*!
|
||||
* Implementation of the guts of the vector<> class
|
||||
* this ensures backward binary compatibility and
|
||||
* reduces code size.
|
||||
* For performance reasons, we expose mStorage and mCount
|
||||
* so these fields are set in stone.
|
||||
*
|
||||
*/
|
||||
|
||||
class VectorImpl
|
||||
{
|
||||
public:
|
||||
enum { // flags passed to the ctor
|
||||
HAS_TRIVIAL_CTOR = 0x00000001,
|
||||
HAS_TRIVIAL_DTOR = 0x00000002,
|
||||
HAS_TRIVIAL_COPY = 0x00000004,
|
||||
};
|
||||
|
||||
VectorImpl(size_t itemSize, uint32_t flags);
|
||||
VectorImpl(const VectorImpl& rhs);
|
||||
virtual ~VectorImpl();
|
||||
|
||||
/*! must be called from subclasses destructor */
|
||||
void finish_vector();
|
||||
|
||||
VectorImpl& operator = (const VectorImpl& rhs);
|
||||
|
||||
/*! C-style array access */
|
||||
inline const void* arrayImpl() const { return mStorage; }
|
||||
void* editArrayImpl();
|
||||
|
||||
/*! vector stats */
|
||||
inline size_t size() const { return mCount; }
|
||||
inline bool isEmpty() const { return mCount == 0; }
|
||||
size_t capacity() const;
|
||||
ssize_t setCapacity(size_t size);
|
||||
ssize_t resize(size_t size);
|
||||
|
||||
/*! append/insert another vector or array */
|
||||
ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
|
||||
ssize_t appendVector(const VectorImpl& vector);
|
||||
ssize_t insertArrayAt(const void* array, size_t index, size_t length);
|
||||
ssize_t appendArray(const void* array, size_t length);
|
||||
|
||||
/*! add/insert/replace items */
|
||||
ssize_t insertAt(size_t where, size_t numItems = 1);
|
||||
ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
|
||||
void pop();
|
||||
void push();
|
||||
void push(const void* item);
|
||||
ssize_t add();
|
||||
ssize_t add(const void* item);
|
||||
ssize_t replaceAt(size_t index);
|
||||
ssize_t replaceAt(const void* item, size_t index);
|
||||
|
||||
/*! remove items */
|
||||
ssize_t removeItemsAt(size_t index, size_t count = 1);
|
||||
void clear();
|
||||
|
||||
const void* itemLocation(size_t index) const;
|
||||
void* editItemLocation(size_t index);
|
||||
|
||||
typedef int (*compar_t)(const void* lhs, const void* rhs);
|
||||
typedef int (*compar_r_t)(const void* lhs, const void* rhs, void* state);
|
||||
status_t sort(compar_t cmp);
|
||||
status_t sort(compar_r_t cmp, void* state);
|
||||
|
||||
protected:
|
||||
size_t itemSize() const;
|
||||
void release_storage();
|
||||
|
||||
virtual void do_construct(void* storage, size_t num) const = 0;
|
||||
virtual void do_destroy(void* storage, size_t num) const = 0;
|
||||
virtual void do_copy(void* dest, const void* from, size_t num) const = 0;
|
||||
virtual void do_splat(void* dest, const void* item, size_t num) const = 0;
|
||||
virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0;
|
||||
virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0;
|
||||
|
||||
private:
|
||||
void* _grow(size_t where, size_t amount);
|
||||
void _shrink(size_t where, size_t amount);
|
||||
|
||||
inline void _do_construct(void* storage, size_t num) const;
|
||||
inline void _do_destroy(void* storage, size_t num) const;
|
||||
inline void _do_copy(void* dest, const void* from, size_t num) const;
|
||||
inline void _do_splat(void* dest, const void* item, size_t num) const;
|
||||
inline void _do_move_forward(void* dest, const void* from, size_t num) const;
|
||||
inline void _do_move_backward(void* dest, const void* from, size_t num) const;
|
||||
|
||||
// These 2 fields are exposed in the inlines below,
|
||||
// so they're set in stone.
|
||||
void * mStorage; // base address of the vector
|
||||
size_t mCount; // number of items
|
||||
|
||||
const uint32_t mFlags;
|
||||
const size_t mItemSize;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SortedVectorImpl : public VectorImpl
|
||||
{
|
||||
public:
|
||||
SortedVectorImpl(size_t itemSize, uint32_t flags);
|
||||
SortedVectorImpl(const VectorImpl& rhs);
|
||||
virtual ~SortedVectorImpl();
|
||||
|
||||
SortedVectorImpl& operator = (const SortedVectorImpl& rhs);
|
||||
|
||||
//! finds the index of an item
|
||||
ssize_t indexOf(const void* item) const;
|
||||
|
||||
//! finds where this item should be inserted
|
||||
size_t orderOf(const void* item) const;
|
||||
|
||||
//! add an item in the right place (or replaces it if there is one)
|
||||
ssize_t add(const void* item);
|
||||
|
||||
//! merges a vector into this one
|
||||
ssize_t merge(const VectorImpl& vector);
|
||||
ssize_t merge(const SortedVectorImpl& vector);
|
||||
|
||||
//! removes an item
|
||||
ssize_t remove(const void* item);
|
||||
|
||||
protected:
|
||||
virtual int do_compare(const void* lhs, const void* rhs) const = 0;
|
||||
|
||||
private:
|
||||
ssize_t _indexOrderOf(const void* item, size_t* order = 0) const;
|
||||
|
||||
// these are made private, because they can't be used on a SortedVector
|
||||
// (they don't have an implementation either)
|
||||
ssize_t add();
|
||||
void pop();
|
||||
void push();
|
||||
void push(const void* item);
|
||||
ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
|
||||
ssize_t appendVector(const VectorImpl& vector);
|
||||
ssize_t insertArrayAt(const void* array, size_t index, size_t length);
|
||||
ssize_t appendArray(const void* array, size_t length);
|
||||
ssize_t insertAt(size_t where, size_t numItems = 1);
|
||||
ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
|
||||
ssize_t replaceAt(size_t index);
|
||||
ssize_t replaceAt(const void* item, size_t index);
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#endif // ANDROID_VECTOR_IMPL_H
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBS_UTILS_THREADS_H
|
||||
#define _LIBS_UTILS_THREADS_H
|
||||
|
||||
/*
|
||||
* Please, DO NOT USE!
|
||||
*
|
||||
* This file is here only for legacy reasons. Instead, include directly
|
||||
* the headers you need below.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <utils/AndroidThreads.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <utils/Condition.h>
|
||||
#include <utils/Errors.h>
|
||||
#include <utils/Mutex.h>
|
||||
#include <utils/RWLock.h>
|
||||
#include <utils/Thread.h>
|
||||
#endif
|
||||
|
||||
#endif // _LIBS_UTILS_THREADS_H
|
|
@ -0,0 +1,28 @@
|
|||
# Copyright 2012 Mozilla Foundation and Mozilla contributors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Don't use STL wrappers; this isn't Gecko code
|
||||
STL_FLAGS =
|
||||
|
||||
# must link statically with the CRT; this isn't Gecko code
|
||||
USE_STATIC_LIBS = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libstagefright_foundation \
|
||||
-lstagefright_foundation \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libutils \
|
||||
-lutils \
|
||||
$(NULL)
|
|
@ -0,0 +1,107 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "mozilla/Types.h"
|
||||
#define STAGEFRIGHT_EXPORT __attribute__ ((visibility ("default")))
|
||||
|
||||
#include "media/stagefright/MediaCodec.h"
|
||||
#include "media/stagefright/foundation/ALooper.h"
|
||||
#include "media/stagefright/foundation/AMessage.h"
|
||||
#include "media/stagefright/foundation/ABuffer.h"
|
||||
#include "media/ICrypto.h"
|
||||
#include "gui/Surface.h"
|
||||
|
||||
|
||||
namespace android {
|
||||
|
||||
// stub for MediaCodec
|
||||
MOZ_EXPORT sp<MediaCodec> MediaCodec::CreateByType(
|
||||
const sp<ALooper> &looper, const char *mime, bool encoder)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::start()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::release()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::stop()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::configure(
|
||||
const sp<AMessage> &format,
|
||||
const sp<Surface> &nativeWindow,
|
||||
const sp<ICrypto> &crypto,
|
||||
uint32_t flags)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::getInputBuffers(Vector<sp<ABuffer> > *buffers) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::getOutputBuffers(Vector<sp<ABuffer> > *buffers) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::dequeueInputBuffer(size_t *index, int64_t timeoutUs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::queueInputBuffer(size_t index,
|
||||
size_t offset,
|
||||
size_t size,
|
||||
int64_t presentationTimeUs,
|
||||
uint32_t flags,
|
||||
AString *errorDetailMsg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::dequeueOutputBuffer(size_t *index,
|
||||
size_t *offset,
|
||||
size_t *size,
|
||||
int64_t *presentationTimeUs,
|
||||
uint32_t *flags,
|
||||
int64_t timeoutUs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::releaseOutputBuffer(size_t index)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
MediaCodec::setParameters(const sp<AMessage> ¶ms)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
NO_DIST_INSTALL = True
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
|
||||
SOURCES += [
|
||||
'libstagefright.cpp',
|
||||
]
|
||||
|
||||
LIBRARY_NAME = 'stagefright'
|
||||
|
||||
FORCE_SHARED_LIB = True
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/media/omx-plugin/include/kk',
|
||||
'/media/omx-plugin/include/kk/media/stagefright/foundation',
|
||||
]
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright 2012 Mozilla Foundation and Mozilla contributors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Don't use STL wrappers; this isn't Gecko code
|
||||
STL_FLAGS =
|
||||
|
||||
# must link statically with the CRT; this isn't Gecko code
|
||||
USE_STATIC_LIBS = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libutils \
|
||||
-lutils \
|
||||
$(NULL)
|
|
@ -0,0 +1,120 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "mozilla/Types.h"
|
||||
#define STAGEFRIGHT_EXPORT __attribute__ ((visibility ("default")))
|
||||
|
||||
#include "media/stagefright/foundation/ALooper.h"
|
||||
#include "media/stagefright/foundation/AMessage.h"
|
||||
#include "media/stagefright/foundation/ABuffer.h"
|
||||
#include "media/stagefright/foundation/AString.h"
|
||||
#include "media/ICrypto.h"
|
||||
#include "gui/Surface.h"
|
||||
|
||||
|
||||
namespace android {
|
||||
|
||||
// stub for Mutex
|
||||
MOZ_EXPORT
|
||||
Mutex::Mutex()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
}
|
||||
|
||||
// stub for Condition
|
||||
MOZ_EXPORT
|
||||
Condition::Condition()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT
|
||||
Condition::~Condition()
|
||||
{
|
||||
}
|
||||
|
||||
// stub for AString
|
||||
MOZ_EXPORT
|
||||
AString::AString()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT
|
||||
AString::~AString()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT
|
||||
struct ALooper::LooperThread:public Thread
|
||||
{
|
||||
};
|
||||
|
||||
// stub for ALooper
|
||||
MOZ_EXPORT
|
||||
ALooper::ALooper() : mRunningLocally(false)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT
|
||||
ALooper::~ALooper()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
ALooper::start(bool runOnCallingThread,
|
||||
bool canCallJava,
|
||||
int32_t priority)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_EXPORT status_t
|
||||
ALooper::stop()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// stub for AMessage
|
||||
MOZ_EXPORT
|
||||
AMessage::AMessage(uint32_t what,
|
||||
int target)
|
||||
: mWhat(what),
|
||||
mTarget(target),
|
||||
mNumItems(0)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void
|
||||
AMessage::clear()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT
|
||||
AMessage::~AMessage()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void
|
||||
AMessage::setString(
|
||||
const char *name, const char *s, int len)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void
|
||||
AMessage::setInt32(const char *name, int32_t value)
|
||||
{
|
||||
}
|
||||
|
||||
// stub for ABuffer
|
||||
MOZ_EXPORT void
|
||||
ABuffer::setRange(size_t offset, size_t size)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
NO_DIST_INSTALL = True
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
|
||||
SOURCES += [
|
||||
'libstagefright_foundation.cpp',
|
||||
]
|
||||
|
||||
LIBRARY_NAME = 'stagefright_foundation'
|
||||
|
||||
FORCE_SHARED_LIB = True
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/media/omx-plugin/include/kk',
|
||||
'/media/omx-plugin/include/kk/media/stagefright/foundation',
|
||||
]
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# Copyright 2012 Mozilla Foundation and Mozilla contributors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Don't use STL wrappers; this isn't Gecko code
|
||||
STL_FLAGS =
|
||||
|
||||
# must link statically with the CRT; this isn't Gecko code
|
||||
USE_STATIC_LIBS = 1
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "mozilla/Types.h"
|
||||
#include "utils/RefBase.h"
|
||||
#include "utils/String16.h"
|
||||
#include "utils/String8.h"
|
||||
#include "utils/Vector.h"
|
||||
|
||||
namespace android {
|
||||
MOZ_EXPORT RefBase::RefBase() : mRefs(0)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT RefBase::~RefBase()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::incStrong(const void *id) const
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::decStrong(const void *id) const
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::onFirstRef()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::onLastStrongRef(const void* id)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT bool RefBase::onIncStrongAttempted(uint32_t flags, const void* id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::onLastWeakRef(void const* id)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT String16::String16(char const*)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT String16::~String16()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT String8::String8()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT String8::String8(const String8 &)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT String8::~String8()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT VectorImpl::VectorImpl(size_t, uint32_t)
|
||||
: mFlags(0), mItemSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT VectorImpl::VectorImpl(const VectorImpl &)
|
||||
: mFlags(0), mItemSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT VectorImpl::~VectorImpl()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void VectorImpl::finish_vector()
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::renameRefId(RefBase*, void const*, void const*)
|
||||
{
|
||||
}
|
||||
|
||||
MOZ_EXPORT void RefBase::renameRefs(unsigned int, ReferenceRenamer const&)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
NO_DIST_INSTALL = True
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
|
||||
SOURCES += [
|
||||
'libutils.cpp',
|
||||
]
|
||||
|
||||
LIBRARY_NAME = 'utils'
|
||||
|
||||
FORCE_SHARED_LIB = True
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/media/omx-plugin/include/kk',
|
||||
'/media/omx-plugin/include/kk/media/stagefright/openmax',
|
||||
]
|
||||
|
|
@ -62,7 +62,9 @@ if CONFIG['MOZ_WEBRTC_SIGNALING']:
|
|||
'signaling/src/callcontrol/CallControlManagerImpl.cpp',
|
||||
'signaling/src/common/browser_logging/CSFLog.cpp',
|
||||
'signaling/src/media-conduit/AudioConduit.cpp',
|
||||
'signaling/src/media-conduit/ExtVideoCodec.cpp',
|
||||
'signaling/src/media-conduit/VideoConduit.cpp',
|
||||
'signaling/src/media-conduit/WebrtcExtVideoCodec.cpp',
|
||||
'signaling/src/media/CSFAudioControlWrapper.cpp',
|
||||
'signaling/src/media/CSFVideoControlWrapper.cpp',
|
||||
'signaling/src/media/VcmSIPCCBinding.cpp',
|
||||
|
|
|
@ -67,6 +67,8 @@
|
|||
'../../../netwerk/srtp/src/crypto/include',
|
||||
'../../../ipc/chromium/src',
|
||||
'../../mtransport/third_party/nrappkit/src/util/libekr',
|
||||
'../../../media/omx-plugin/include/kk',
|
||||
'../../../media/omx-plugin/include/kk/media',
|
||||
],
|
||||
|
||||
#
|
||||
|
@ -84,6 +86,10 @@
|
|||
#
|
||||
'sources': [
|
||||
# Media Conduit
|
||||
'./src/media-conduit/ExtVideoCodec.h',
|
||||
'./src/media-conduit/ExtVideoCodec.cpp',
|
||||
'./src/media-conduit/WebrtcExtVideoCodec.h',
|
||||
'./src/media-conduit/WebrtcExtVideoCodec.cpp',
|
||||
'./src/media-conduit/AudioConduit.h',
|
||||
'./src/media-conduit/AudioConduit.cpp',
|
||||
'./src/media-conduit/VideoConduit.h',
|
||||
|
@ -174,7 +180,7 @@
|
|||
'USE_SSLEAY',
|
||||
'_CPR_USE_EXTERNAL_LOGGER',
|
||||
'WEBRTC_RELATIVE_PATH',
|
||||
'HAVE_WEBRTC_VIDEO',
|
||||
'HAVE_WEBRTC_VIDEO',
|
||||
'HAVE_WEBRTC_VOICE',
|
||||
'HAVE_STDINT_H=1',
|
||||
'HAVE_STDLIB_H=1',
|
||||
|
@ -245,7 +251,11 @@
|
|||
'SECLIB_OPENSSL',
|
||||
],
|
||||
|
||||
# This flag used for ignore harmless "-Wmultichar" compilation warning which
|
||||
# is reported during compiling VP8 HW accleration related code(see signaling/src/media-conduit/WebrtcExtVideoCodec.h .cpp)
|
||||
# where some android mediacodec relevant header files are refered.
|
||||
'cflags_mozilla': [
|
||||
'-Wno-multichar',
|
||||
],
|
||||
}],
|
||||
['OS=="win"', {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "CSFLog.h"
|
||||
#include "nspr.h"
|
||||
|
||||
#include "WebrtcExtVideoCodec.h"
|
||||
#include "ExtVideoCodec.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static const char* logTag ="ExtVideoCodec";
|
||||
|
||||
VideoEncoder* ExtVideoCodec::CreateEncoder() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
WebrtcExtVideoEncoder *enc =
|
||||
new WebrtcExtVideoEncoder();
|
||||
return enc;
|
||||
}
|
||||
|
||||
VideoDecoder* ExtVideoCodec::CreateDecoder() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
WebrtcExtVideoDecoder *dec =
|
||||
new WebrtcExtVideoDecoder();
|
||||
return dec;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef ExtVideoCodec_h__
|
||||
#define ExtVideoCodec_h__
|
||||
|
||||
#include "MediaConduitInterface.h"
|
||||
|
||||
namespace mozilla {
|
||||
class ExtVideoCodec {
|
||||
public:
|
||||
static VideoEncoder* CreateEncoder();
|
||||
static VideoDecoder* CreateDecoder();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ExtVideoCodec_h__
|
|
@ -4,10 +4,16 @@
|
|||
|
||||
#include "CSFLog.h"
|
||||
#include "nspr.h"
|
||||
#include "nsIGfxInfo.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
// For rtcp-fb constants
|
||||
#include "ccsdp.h"
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "mozilla/Preferences.h"
|
||||
#endif
|
||||
|
||||
#include "VideoConduit.h"
|
||||
#include "AudioConduit.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
@ -24,6 +30,8 @@
|
|||
#include "AndroidJNIWrapper.h"
|
||||
#endif
|
||||
|
||||
#include "ExtVideoCodec.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -277,6 +285,14 @@ MediaConduitErrorCode WebrtcVideoConduit::Init(WebrtcVideoConduit *other)
|
|||
return kMediaConduitSessionNotInited;
|
||||
}
|
||||
|
||||
mPtrExtCodec = webrtc::ViEExternalCodec::GetInterface(mVideoEngine);
|
||||
|
||||
if (!mPtrExtCodec) {
|
||||
CSFLogError(logTag, "%s Unable to get external codec interface: %d ",
|
||||
__FUNCTION__, mPtrViEBase->LastError());
|
||||
return kMediaConduitSessionNotInited;
|
||||
}
|
||||
|
||||
if( !(mPtrRTP = webrtc::ViERTP_RTCP::GetInterface(mVideoEngine)))
|
||||
{
|
||||
CSFLogError(logTag, "%s Unable to get video RTCP interface ", __FUNCTION__);
|
||||
|
@ -509,6 +525,37 @@ WebrtcVideoConduit::ConfigureSendMediaCodec(const VideoCodecConfig* codecConfig)
|
|||
return kMediaConduitInvalidSendCodec;
|
||||
}
|
||||
|
||||
CSFLogDebug(logTag, "%s, Before ExtVideoCodec codec %s(%d)", __FUNCTION__,
|
||||
video_codec.plName, video_codec.plType);
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
CSFLogError(logTag, "%s Start to check hardware acceleration 1", __FUNCTION__);
|
||||
bool enabled = Preferences::GetBool("media.navigator.hardware.vp8_encode.acceleration_enabled", false);
|
||||
#else
|
||||
bool enabled = false;
|
||||
#endif
|
||||
|
||||
if (enabled) {
|
||||
CSFLogError(logTag, "%s Start to check hardware acceleration", __FUNCTION__);
|
||||
|
||||
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
||||
if (gfxInfo) {
|
||||
int32_t status;
|
||||
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION, &status))) {
|
||||
if (status != nsIGfxInfo::FEATURE_NO_INFO) {
|
||||
NS_WARNING("XXX webrtc hardware acceleration blacklisted\n");
|
||||
CSFLogError(logTag, "%s XXX webrtc hardware acceleration blacklisted", __FUNCTION__);
|
||||
} else {
|
||||
CSFLogError(logTag, "%s Start to registr hardware acceleration", __FUNCTION__);
|
||||
CSFLogDebug(logTag, "%s, in ExtVideoCodec codec %s(%d)", __FUNCTION__,
|
||||
payloadName.c_str(), video_codec.plType);
|
||||
VideoEncoder* extEncoder = ExtVideoCodec::CreateEncoder();
|
||||
SetExternalSendCodec(video_codec.plType, extEncoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mPtrViECodec->SetSendCodec(mChannel, video_codec) == -1)
|
||||
{
|
||||
error = mPtrViEBase->LastError();
|
||||
|
@ -655,6 +702,35 @@ WebrtcVideoConduit::ConfigureRecvMediaCodecs(
|
|||
}
|
||||
}//end for codeclist
|
||||
|
||||
CSFLogDebug(logTag, "%s, Before ExtVideoCodec codec %s(%d)", __FUNCTION__,
|
||||
video_codec.plName, video_codec.plType);
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
CSFLogError(logTag, "%s Start to check hardware acceleration 1", __FUNCTION__);
|
||||
bool enabled = Preferences::GetBool("media.navigator.hardware.vp8_decode.acceleration_enabled", false);
|
||||
#else
|
||||
bool enabled = false;
|
||||
#endif
|
||||
|
||||
if (enabled) {
|
||||
CSFLogError(logTag, "%s Start to check hardware acceleration", __FUNCTION__);
|
||||
|
||||
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
||||
if (gfxInfo) {
|
||||
int32_t status;
|
||||
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION, &status))) {
|
||||
if (status != nsIGfxInfo::FEATURE_NO_INFO) {
|
||||
NS_WARNING("XXX webrtc hardware acceleration blacklisted\n");
|
||||
CSFLogError(logTag, "%s XXX webrtc hardware acceleration blacklisted", __FUNCTION__);
|
||||
} else {
|
||||
CSFLogError(logTag, "%s Start to registr hardware acceleration", __FUNCTION__);
|
||||
CSFLogDebug(logTag, "%s, in ExtVideoCodec codec %s(%d)", __FUNCTION__,
|
||||
video_codec.plName, video_codec.plType);
|
||||
VideoDecoder* extDecoder = ExtVideoCodec::CreateDecoder();
|
||||
SetExternalRecvCodec(video_codec.plType, extDecoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
|
||||
if(!success)
|
||||
|
|
|
@ -0,0 +1,648 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
#include "CSFLog.h"
|
||||
#include "nspr.h"
|
||||
#include "runnable_utils.h"
|
||||
|
||||
#include "WebrtcExtVideoCodec.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
|
||||
#include "AudioConduit.h"
|
||||
#include "VideoConduit.h"
|
||||
#include "libyuv/convert_from.h"
|
||||
#include "libyuv/convert.h"
|
||||
#include "libyuv/row.h"
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <ICrypto.h>
|
||||
#include <IOMX.h>
|
||||
#include <OMX_VideoExt.h>
|
||||
#include <gui/Surface.h>
|
||||
#include <stagefright/MediaCodec.h>
|
||||
#include <stagefright/MediaDefs.h>
|
||||
#include <stagefright/MediaErrors.h>
|
||||
#include <stagefright/foundation/ABuffer.h>
|
||||
#include <stagefright/foundation/AMessage.h>
|
||||
#include <vie_external_codec.h>
|
||||
#include <webrtc/common_video/libyuv/include/webrtc_libyuv.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
static const int64_t DEQUEUE_BUFFER_TIMEOUT_US = 100 * 1000ll; // 100ms
|
||||
static const int64_t START_DEQUEUE_BUFFER_TIMEOUT_US = 10 * DEQUEUE_BUFFER_TIMEOUT_US; // 1s
|
||||
static const char MEDIACODEC_VIDEO_MIME_VP8[] = "video/x-vnd.on2.vp8";
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static const char* logTag ="WebrtcExtVideoCodec";
|
||||
|
||||
// Link to Stagefright
|
||||
class WebrtcOMX {
|
||||
public:
|
||||
WebrtcOMX()
|
||||
: mLooper(new ALooper),
|
||||
mMsg(new AMessage),
|
||||
mOmx(nullptr),
|
||||
isStarted(false) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
mLooper->start();
|
||||
}
|
||||
|
||||
virtual ~WebrtcOMX() {
|
||||
if (mMsg != nullptr) {
|
||||
mMsg.clear();
|
||||
}
|
||||
if (mOmx != nullptr) {
|
||||
mOmx->release();
|
||||
}
|
||||
if (mLooper != nullptr) {
|
||||
mLooper.clear();
|
||||
}
|
||||
}
|
||||
|
||||
status_t Configure(const sp<Surface>& nativeWindow,
|
||||
const sp<ICrypto>& crypto,
|
||||
uint32_t flags,
|
||||
const char* mime,
|
||||
bool encoder) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
status_t err = BAD_VALUE;
|
||||
|
||||
if (mOmx == nullptr) {
|
||||
mOmx = MediaCodec::CreateByType(mLooper, mime, encoder);
|
||||
if (mOmx == nullptr) {
|
||||
return BAD_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
err = mOmx->configure(mMsg, nativeWindow, crypto, flags);
|
||||
CSFLogDebug(logTag, "WebrtcOMX::%s, err = %d", __FUNCTION__, err);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
status_t Start() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
if (mOmx == nullptr) {
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
status_t err = mOmx->start();
|
||||
CSFLogDebug(logTag, "WebrtcOMX::%s, mOmx->start() return err = %d",
|
||||
__FUNCTION__, err);
|
||||
|
||||
mOmx->getInputBuffers(&mInput);
|
||||
mOmx->getOutputBuffers(&mOutput);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
status_t Stop() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
return mOmx->stop();
|
||||
}
|
||||
|
||||
Vector<sp<ABuffer>>* getInput() {
|
||||
return &mInput;
|
||||
}
|
||||
|
||||
Vector<sp<ABuffer>>* getOutput() {
|
||||
return &mOutput;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class WebrtcExtVideoEncoder;
|
||||
friend class WebrtcExtVideoDecoder;
|
||||
|
||||
sp<ALooper> mLooper;
|
||||
sp<MediaCodec> mOmx;
|
||||
sp<AMessage> mMsg;
|
||||
bool isStarted;
|
||||
Vector<sp<ABuffer>> mInput;
|
||||
Vector<sp<ABuffer>> mOutput;
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebrtcOMX)
|
||||
};
|
||||
|
||||
|
||||
// Encoder.
|
||||
WebrtcExtVideoEncoder::WebrtcExtVideoEncoder()
|
||||
: mTimestamp(0),
|
||||
mCallback(nullptr),
|
||||
mOmxEncoder(nullptr) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
}
|
||||
|
||||
static bool I420toNV12(uint8_t* dstY, uint16_t* dstUV, const webrtc::I420VideoFrame& inputImage) {
|
||||
uint8_t* buffer = dstY;
|
||||
uint8_t* dst_y = buffer;
|
||||
int dst_stride_y = inputImage.stride(webrtc::kYPlane);
|
||||
uint8_t* dst_uv = buffer + inputImage.stride(webrtc::kYPlane) *
|
||||
inputImage.height();
|
||||
int dst_stride_uv = inputImage.stride(webrtc::kUPlane) * 2;
|
||||
|
||||
// Why NV12? Because COLOR_FORMAT_YUV420_SEMIPLANAR. Most hardware is NV12-friendly.
|
||||
bool converted = !libyuv::I420ToNV12(inputImage.buffer(webrtc::kYPlane),
|
||||
inputImage.stride(webrtc::kYPlane),
|
||||
inputImage.buffer(webrtc::kUPlane),
|
||||
inputImage.stride(webrtc::kUPlane),
|
||||
inputImage.buffer(webrtc::kVPlane),
|
||||
inputImage.stride(webrtc::kVPlane),
|
||||
dst_y,
|
||||
dst_stride_y,
|
||||
dst_uv,
|
||||
dst_stride_uv,
|
||||
inputImage.width(),
|
||||
inputImage.height());
|
||||
return converted;
|
||||
}
|
||||
|
||||
static void VideoCodecSettings2AMessage(
|
||||
sp<AMessage> &format,
|
||||
const webrtc::VideoCodec* codecSettings,
|
||||
const char* mime,
|
||||
bool isEncoder) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
format->setString("mime", mime);
|
||||
format->setInt32("width", codecSettings->width);
|
||||
format->setInt32("height", codecSettings->height);
|
||||
format->setInt32("bitrate", codecSettings->startBitrate * 1000); // kbps->bps
|
||||
format->setInt32("frame-rate", 30);
|
||||
// QCOM encoder only support this format. See
|
||||
// <B2G>/hardware/qcom/media/mm-video/vidc/venc/src/video_encoder_device.cpp:
|
||||
// venc_dev::venc_set_color_format()
|
||||
format->setInt32("color-format", OMX_COLOR_FormatYUV420SemiPlanar);
|
||||
if (isEncoder) {
|
||||
format->setInt32("i-frame-interval", std::numeric_limits<int>::max()); // should generate I-frame on demand
|
||||
}
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoEncoder::InitEncode(
|
||||
const webrtc::VideoCodec* codecSettings,
|
||||
int32_t numberOfCores,
|
||||
uint32_t maxPayloadSize) {
|
||||
mMaxPayloadSize = maxPayloadSize;
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
if (!mOmxEncoder) {
|
||||
mOmxEncoder = new WebrtcOMX();
|
||||
} else {
|
||||
VideoCodecSettings2AMessage(mOmxEncoder->mMsg, codecSettings, MEDIACODEC_VIDEO_MIME_VP8, true /*encoder*/);
|
||||
|
||||
status_t err = mOmxEncoder->Configure(nullptr, nullptr, MediaCodec::CONFIGURE_FLAG_ENCODE, MEDIACODEC_VIDEO_MIME_VP8, true /* encoder */);
|
||||
if (err != OK) {
|
||||
CSFLogDebug(logTag, "MediaCodecEncoderImpl::%s, err = %d", __FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
mOmxEncoder->isStarted = false;
|
||||
}
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoEncoder::Encode(
|
||||
const webrtc::I420VideoFrame& inputImage,
|
||||
const webrtc::CodecSpecificInfo* codecSpecificInfo,
|
||||
const std::vector<webrtc::VideoFrameType>* frame_types) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
status_t err = OK;
|
||||
|
||||
if (!mOmxEncoder) {
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
uint32_t time = PR_IntervalNow();
|
||||
#endif
|
||||
if (!mOmxEncoder->isStarted) {
|
||||
err = mOmxEncoder->Start();
|
||||
if (err != OK) {
|
||||
mOmxEncoder->isStarted = false;
|
||||
CSFLogDebug(logTag, "%s mOmxEncoder->start(), err = %d", __FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
mOmxEncoder->isStarted = true;
|
||||
}
|
||||
|
||||
size_t sizeY = inputImage.allocated_size(webrtc::kYPlane);
|
||||
size_t sizeUV = inputImage.allocated_size(webrtc::kUPlane);
|
||||
size_t size = sizeY + 2 * sizeUV;
|
||||
|
||||
sp<MediaCodec> omx = mOmxEncoder->mOmx;
|
||||
size_t index = 0;
|
||||
err = omx->dequeueInputBuffer(&index, DEQUEUE_BUFFER_TIMEOUT_US);
|
||||
if (err != OK) {
|
||||
CSFLogError(logTag, "%s WebrtcExtVideoEncoder::Encode() dequeue OMX input buffer error:%d", __FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() dequeue OMX input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
#endif
|
||||
|
||||
const sp<ABuffer>& omxIn = mOmxEncoder->getInput()->itemAt(index);
|
||||
omxIn->setRange(0, size);
|
||||
uint8_t* dstY = omxIn->data();
|
||||
uint16_t* dstUV = reinterpret_cast<uint16_t*>(dstY + sizeY);
|
||||
|
||||
bool converted = I420toNV12(dstY, dstUV, inputImage);
|
||||
if (!converted) {
|
||||
CSFLogError(logTag, "%s WebrtcExtVideoEncoder::Encode() convert input buffer to NV12 error.", __FUNCTION__);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
time = PR_IntervalNow();
|
||||
#endif
|
||||
|
||||
err = omx->queueInputBuffer(index, 0, size, inputImage.render_time_ms() * PR_USEC_PER_MSEC /* ms to us */, 0);
|
||||
if (err != OK) {
|
||||
CSFLogError(logTag, "%s WebrtcExtVideoEncoder::Encode() queue OMX input buffer error:%d", __FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() queue OMX input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
#endif
|
||||
|
||||
mEncodedImage._encodedWidth = inputImage.width();
|
||||
mEncodedImage._encodedHeight = inputImage.height();
|
||||
mEncodedImage._timeStamp = inputImage.timestamp();
|
||||
mEncodedImage.capture_time_ms_ = inputImage.timestamp();
|
||||
|
||||
size_t outOffset;
|
||||
size_t outSize;
|
||||
int64_t outTime;
|
||||
uint32_t outFlags;
|
||||
err = omx->dequeueOutputBuffer(&index, &outOffset, &outSize, &outTime, &outFlags, 0);
|
||||
if (err == INFO_FORMAT_CHANGED) {
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() dequeue OMX output format change", __FUNCTION__);
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
} else if (err == INFO_OUTPUT_BUFFERS_CHANGED) {
|
||||
err = omx->getOutputBuffers(mOmxEncoder->getOutput());
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() dequeue OMX output buffer change", __FUNCTION__);
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
} else if (err != OK) {
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() dequeue OMX output buffer error:%d", __FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() dequeue OMX output buffer err:%d len:%u time:%lld flags:0x%08x took %u ms",
|
||||
__FUNCTION__, err, outSize, outTime, outFlags, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
#endif
|
||||
|
||||
sp<ABuffer> omxOut = mOmxEncoder->getOutput()->itemAt(index);
|
||||
mEncodedImage._length = omxOut->size();
|
||||
uint8_t* data = omxOut->data();
|
||||
|
||||
// xxx It's too bad the mediacodec native API forces us to memcpy this....
|
||||
// we should find a way that able to 'hold' the buffer or transfer it from inputImage (ping-pong
|
||||
// buffers or select them from a small pool)
|
||||
memcpy(mEncodedImage._buffer, data, mEncodedImage._length);
|
||||
omx->releaseOutputBuffer(index);
|
||||
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() outFlags:%d ", __FUNCTION__, outFlags);
|
||||
|
||||
mEncodedImage._completeFrame = true;
|
||||
mEncodedImage._frameType =
|
||||
(outFlags & (MediaCodec::BUFFER_FLAG_SYNCFRAME | MediaCodec::BUFFER_FLAG_CODECCONFIG)) ?
|
||||
webrtc::kKeyFrame : webrtc::kDeltaFrame;
|
||||
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoEncoder::Encode() frame type:%d size:%u", __FUNCTION__, mEncodedImage._frameType, mEncodedImage._length);
|
||||
|
||||
webrtc::CodecSpecificInfo info;
|
||||
info.codecType = webrtc::kVideoCodecVP8;
|
||||
info.codecSpecific.VP8.pictureId = -1;
|
||||
info.codecSpecific.VP8.tl0PicIdx = -1;
|
||||
info.codecSpecific.VP8.keyIdx = -1;
|
||||
|
||||
// Generate a header describing a single fragment.
|
||||
webrtc::RTPFragmentationHeader header;
|
||||
memset(&header, 0, sizeof(header));
|
||||
header.VerifyAndAllocateFragmentationHeader(1);
|
||||
header.fragmentationLength[0] = mEncodedImage._length;
|
||||
|
||||
mCallback->Encoded(mEncodedImage, &info, &header);
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoEncoder::RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback* callback) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
mCallback = callback;
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoEncoder::Release() {
|
||||
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
delete mOmxEncoder;
|
||||
mOmxEncoder = nullptr;
|
||||
|
||||
delete [] mEncodedImage._buffer;
|
||||
mEncodedImage._buffer = nullptr;
|
||||
mEncodedImage._size = 0;
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
WebrtcExtVideoEncoder::~WebrtcExtVideoEncoder() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
Release();
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoEncoder::SetChannelParameters(uint32_t packetLoss, int rtt) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
if (!mOmxEncoder || !mOmxEncoder->mOmx.get()) {
|
||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
||||
}
|
||||
|
||||
sp<MediaCodec> omx = mOmxEncoder->mOmx;
|
||||
sp<AMessage> msg = new AMessage;
|
||||
msg->setInt32("videoBitrate", newBitRate * 1000 /* kbps -> bps */);
|
||||
msg->setInt32("frame-rate", frameRate);
|
||||
omx->setParameters(msg);
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
|
||||
// Decoder.
|
||||
WebrtcExtVideoDecoder::WebrtcExtVideoDecoder()
|
||||
: mCallback(nullptr)
|
||||
, mFrameWidth(0)
|
||||
, mFrameHeight(0)
|
||||
, mOmxDecoder(nullptr) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoDecoder::InitDecode(
|
||||
const webrtc::VideoCodec* codecSettings,
|
||||
int32_t numberOfCores) {
|
||||
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
if (!mOmxDecoder) {
|
||||
mOmxDecoder = new WebrtcOMX();
|
||||
} else {
|
||||
VideoCodecSettings2AMessage(mOmxDecoder->mMsg, codecSettings, MEDIACODEC_VIDEO_MIME_VP8, false /* decoder */);
|
||||
|
||||
status_t err = mOmxDecoder->Configure(nullptr, nullptr, 0, MEDIACODEC_VIDEO_MIME_VP8, false /* decoder */);
|
||||
|
||||
if (err != OK) {
|
||||
CSFLogDebug(logTag, "MediaCodecDecoderImpl::%s, decoder configure return err = %d",
|
||||
__FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
mOmxDecoder->isStarted = false;
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
static void GenerateVideoFrame(
|
||||
size_t width, size_t height, uint32_t timeStamp,
|
||||
const sp<ABuffer>& decoded,
|
||||
webrtc::I420VideoFrame* videoFrame) {
|
||||
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
// TODO: eliminate extra pixel copy/color conversion
|
||||
// TODO: The hardware output buffer is likely to contain the pixels in a vendor-specific,
|
||||
// opaque/non-standard format. It's not possible to negotiate the decoder
|
||||
// to emit a specific colorspace
|
||||
// For example, QCOM HW only support OMX_QCOM_COLOR_FormatYVU420PackedSemiPlanar32m4ka
|
||||
// INTEL HW support OMX_COLOR_FormatYUV420PackedSemiPlanar
|
||||
size_t widthUV = (width + 1) / 2;
|
||||
if (videoFrame->CreateEmptyFrame(width, height, width, widthUV, widthUV)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t* src_nv12 = decoded->data();
|
||||
int src_nv12_y_size = width * height;
|
||||
|
||||
uint8_t* dstY = videoFrame->buffer(webrtc::kYPlane);
|
||||
uint8_t* dstU = videoFrame->buffer(webrtc::kUPlane);
|
||||
uint8_t* dstV = videoFrame->buffer(webrtc::kVPlane);
|
||||
|
||||
libyuv::NV12ToI420(src_nv12, width,
|
||||
src_nv12 + src_nv12_y_size, (width + 1) & ~1,
|
||||
dstY, width,
|
||||
dstU, (width + 1) / 2,
|
||||
dstV,
|
||||
(width + 1) / 2,
|
||||
width, height);
|
||||
|
||||
videoFrame->set_timestamp(timeStamp);
|
||||
}
|
||||
|
||||
static status_t FeedOMXInput(
|
||||
WebrtcOMX* decoder,
|
||||
const sp<MediaCodec>& omx,
|
||||
const webrtc::EncodedImage& inputImage,
|
||||
int64_t renderTimeMs) {
|
||||
|
||||
static int64_t firstTime = -1;
|
||||
size_t index;
|
||||
|
||||
#ifdef DEBUG
|
||||
uint32_t time = PR_IntervalNow();
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
#endif
|
||||
|
||||
status_t err = omx->dequeueInputBuffer(&index,
|
||||
(firstTime < 0) ? START_DEQUEUE_BUFFER_TIMEOUT_US : DEQUEUE_BUFFER_TIMEOUT_US);
|
||||
if (err != OK) {
|
||||
CSFLogError(logTag, "%s WebrtcExtVideoDecoder::Decode() dequeue input buffer error:%d", __FUNCTION__, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() dequeue input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
time = PR_IntervalNow();
|
||||
#endif
|
||||
|
||||
uint32_t flags = 0;
|
||||
if (inputImage._frameType == webrtc::kKeyFrame) {
|
||||
flags |= (firstTime < 0) ? MediaCodec::BUFFER_FLAG_CODECCONFIG : MediaCodec::BUFFER_FLAG_SYNCFRAME;
|
||||
}
|
||||
size_t size = inputImage._length;
|
||||
const sp<ABuffer>& omxIn = decoder->getInput()->itemAt(index);
|
||||
omxIn->setRange(0, size);
|
||||
|
||||
// TODO, find a better way to eliminate this memcpy ...
|
||||
memcpy(omxIn->data(), inputImage._buffer, size);
|
||||
|
||||
if (firstTime < 0) {
|
||||
firstTime = inputImage._timeStamp;
|
||||
}
|
||||
|
||||
err = omx->queueInputBuffer(index, 0, size, renderTimeMs, flags);
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() queue input buffer len:%u flags:%u time:%lld took %u ms",
|
||||
__FUNCTION__, size, flags, *timeUs, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static status_t GetOMXOutput(
|
||||
WebrtcOMX* decoder,
|
||||
const sp<MediaCodec>& omx,
|
||||
const webrtc::EncodedImage& inputImage,
|
||||
webrtc::I420VideoFrame* video_frame,
|
||||
webrtc::DecodedImageCallback* mCallback,
|
||||
uint32_t width,
|
||||
uint32_t height) {
|
||||
|
||||
sp<ABuffer> omxOut;
|
||||
|
||||
CSFLogDebug(logTag, "%s , encodedWidth = %d, encodedHeight = %d",
|
||||
__FUNCTION__, inputImage._encodedWidth, inputImage._encodedHeight);
|
||||
|
||||
#ifdef DEBUG
|
||||
uint32_t time = PR_IntervalNow();
|
||||
#endif
|
||||
|
||||
size_t index;
|
||||
size_t outOffset;
|
||||
size_t outSize;
|
||||
int64_t outTime;
|
||||
uint32_t outFlags;
|
||||
status_t err = omx->dequeueOutputBuffer(&index, &outOffset, &outSize, &outTime, &outFlags);
|
||||
if (err == INFO_FORMAT_CHANGED) {
|
||||
// handle format change
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
} else if (err == INFO_OUTPUT_BUFFERS_CHANGED) {
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() dequeue OMX output buffer change:%d", __FUNCTION__, err);
|
||||
err = omx->getOutputBuffers(decoder->getOutput());
|
||||
MOZ_ASSERT(err == OK);
|
||||
err = INFO_OUTPUT_BUFFERS_CHANGED;
|
||||
} else if (err != OK) {
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() dequeue OMX output buffer error:%d", __FUNCTION__, err);
|
||||
} else {
|
||||
omxOut = decoder->getOutput()->itemAt(index);
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() dequeue output buffer#%u(%p) err:%d len:%u time:%lld flags:0x%08x took %u ms", __FUNCTION__, index, omxOut.get(), err, outSize, outTime, outFlags, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
#endif
|
||||
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() generate video frame", __FUNCTION__);
|
||||
GenerateVideoFrame(width, height, inputImage._timeStamp, omxOut, video_frame);
|
||||
mCallback->Decoded(*video_frame);
|
||||
omx->releaseOutputBuffer(index);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoDecoder::Decode(
|
||||
const webrtc::EncodedImage& inputImage,
|
||||
bool missingFrames,
|
||||
const webrtc::RTPFragmentationHeader* fragmentation,
|
||||
const webrtc::CodecSpecificInfo* codecSpecificInfo,
|
||||
int64_t renderTimeMs) {
|
||||
|
||||
CSFLogDebug(logTag, "%s, renderTimeMs = %lld ", __FUNCTION__, renderTimeMs);
|
||||
|
||||
if (inputImage._length== 0 || !inputImage._buffer) {
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
if (inputImage._frameType == webrtc::kKeyFrame) {
|
||||
mFrameWidth = inputImage._encodedWidth;
|
||||
mFrameHeight = inputImage._encodedHeight;
|
||||
}
|
||||
|
||||
if (!mOmxDecoder->isStarted) {
|
||||
#ifdef DEBUG
|
||||
uint32_t time = PR_IntervalNow();
|
||||
#endif
|
||||
status_t err = mOmxDecoder->Start();
|
||||
|
||||
if (err != OK) {
|
||||
mOmxDecoder->isStarted = false;
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() start decoder. err = %d", __FUNCTION__, err);
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
mOmxDecoder->isStarted = true;
|
||||
|
||||
#ifdef DEBUG
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() start decoder took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time));
|
||||
#endif
|
||||
}
|
||||
|
||||
sp<MediaCodec> omx = mOmxDecoder->mOmx;
|
||||
bool feedFrame = true;
|
||||
status_t err;
|
||||
|
||||
while (feedFrame) {
|
||||
err = FeedOMXInput(mOmxDecoder, omx, inputImage, renderTimeMs);
|
||||
feedFrame = (err == -EAGAIN);
|
||||
do {
|
||||
err = GetOMXOutput(mOmxDecoder, omx, inputImage, &mVideoFrame, mCallback, mFrameWidth, mFrameHeight);
|
||||
} while (err == INFO_OUTPUT_BUFFERS_CHANGED);
|
||||
}
|
||||
|
||||
CSFLogDebug(logTag, "%s WebrtcExtVideoDecoder::Decode() end, err = %d", __FUNCTION__, err);
|
||||
|
||||
if (err != OK) {
|
||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||
}
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
void WebrtcExtVideoDecoder::DecodeFrame(EncodedFrame* frame) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoDecoder::RegisterDecodeCompleteCallback(webrtc::DecodedImageCallback* callback) {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
mCallback = callback;
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoDecoder::Release() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
delete mOmxDecoder;
|
||||
mOmxDecoder = nullptr;
|
||||
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
WebrtcExtVideoDecoder::~WebrtcExtVideoDecoder() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
|
||||
Release();
|
||||
}
|
||||
|
||||
int32_t WebrtcExtVideoDecoder::Reset() {
|
||||
CSFLogDebug(logTag, "%s ", __FUNCTION__);
|
||||
return WEBRTC_VIDEO_CODEC_OK;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef WebrtcExtVideoCodec_h__
|
||||
#define WebrtcExtVideoCodec_h__
|
||||
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
#include "MediaConduitInterface.h"
|
||||
#include "AudioConduit.h"
|
||||
#include "VideoConduit.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
struct EncodedFrame {
|
||||
uint32_t width_;
|
||||
uint32_t height_;
|
||||
uint32_t timestamp_;
|
||||
uint64_t decode_timestamp_;
|
||||
};
|
||||
|
||||
class WebrtcOMX;
|
||||
|
||||
class WebrtcExtVideoEncoder : public WebrtcVideoEncoder {
|
||||
public:
|
||||
WebrtcExtVideoEncoder();
|
||||
|
||||
virtual ~WebrtcExtVideoEncoder() MOZ_OVERRIDE;
|
||||
|
||||
// Implement VideoEncoder interface.
|
||||
virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings,
|
||||
int32_t numberOfCores,
|
||||
uint32_t maxPayloadSize) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t Encode(const webrtc::I420VideoFrame& inputImage,
|
||||
const webrtc::CodecSpecificInfo* codecSpecificInfo,
|
||||
const std::vector<webrtc::VideoFrameType>* frame_types) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback* callback) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t Release() MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t SetChannelParameters(uint32_t packetLoss, int rtt) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
int32_t VerifyAndAllocate(const uint32_t minimumSize);
|
||||
|
||||
size_t mMaxPayloadSize;
|
||||
uint32_t mTimestamp;
|
||||
webrtc::EncodedImage mEncodedImage;
|
||||
webrtc::EncodedImageCallback* mCallback;
|
||||
|
||||
WebrtcOMX* mOmxEncoder;
|
||||
};
|
||||
|
||||
|
||||
class WebrtcExtVideoDecoder : public WebrtcVideoDecoder {
|
||||
public:
|
||||
WebrtcExtVideoDecoder();
|
||||
|
||||
virtual ~WebrtcExtVideoDecoder() MOZ_OVERRIDE;
|
||||
|
||||
// Implement VideoDecoder interface.
|
||||
virtual int32_t InitDecode(const webrtc::VideoCodec* codecSettings,
|
||||
int32_t numberOfCores) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t Decode(const webrtc::EncodedImage& inputImage,
|
||||
bool missingFrames,
|
||||
const webrtc::RTPFragmentationHeader* fragmentation,
|
||||
const webrtc::CodecSpecificInfo*
|
||||
codecSpecificInfo = NULL,
|
||||
int64_t renderTimeMs = -1) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t RegisterDecodeCompleteCallback(webrtc::DecodedImageCallback* callback) MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t Release() MOZ_OVERRIDE;
|
||||
|
||||
virtual int32_t Reset() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
void DecodeFrame(EncodedFrame* frame);
|
||||
void RunCallback();
|
||||
|
||||
webrtc::DecodedImageCallback* mCallback;
|
||||
webrtc::I420VideoFrame mDecodedImage;
|
||||
webrtc::I420VideoFrame mVideoFrame;
|
||||
uint32_t mFrameWidth;
|
||||
uint32_t mFrameHeight;
|
||||
|
||||
WebrtcOMX* mOmxDecoder;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // WebrtcExtVideoCodec_h__
|
|
@ -36,6 +36,12 @@ ifeq ($(OS_TARGET),Android)
|
|||
LIBS += \
|
||||
$(STLPORT_LDFLAGS) \
|
||||
$(STLPORT_LIBS) \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libutils \
|
||||
-lutils \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libstagefright_foundation \
|
||||
-lstagefright_foundation \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libstagefright \
|
||||
-lstagefright \
|
||||
$(NULL)
|
||||
CPPFLAGS += \
|
||||
$(STLPORT_CPPFLAGS) \
|
||||
|
|
|
@ -96,6 +96,17 @@ endif
|
|||
EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME_PATH,gkmedias,$(DIST)/lib)
|
||||
|
||||
ifdef MOZ_WEBRTC
|
||||
ifeq (Android,$(OS_TARGET))
|
||||
OS_LIBS += \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libutils \
|
||||
-lutils \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libstagefright_foundation \
|
||||
-lstagefright_foundation \
|
||||
-L$(DEPTH)/media/omx-plugin/lib/kk/libstagefright \
|
||||
-lstagefright \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifeq (WINNT,$(OS_TARGET))
|
||||
ifndef MOZ_HAS_WINSDK_WITH_D3D
|
||||
EXTRA_DSO_LDOPTS += \
|
||||
|
|
|
@ -71,6 +71,9 @@ if CONFIG['MOZ_WEBRTC']:
|
|||
|
||||
if CONFIG['MOZ_OMX_PLUGIN']:
|
||||
add_tier_dir('platform', [
|
||||
'media/omx-plugin/lib/kk/libutils',
|
||||
'media/omx-plugin/lib/kk/libstagefright_foundation',
|
||||
'media/omx-plugin/lib/kk/libstagefright',
|
||||
'media/omx-plugin/lib/ics/libutils',
|
||||
'media/omx-plugin/lib/ics/libstagefright',
|
||||
'media/omx-plugin/lib/ics/libvideoeditorplayer',
|
||||
|
|
Загрузка…
Ссылка в новой задаче