Implement SurfaceTexture frame-available callback.
This change implements the onFrameAvailable callback for the SurfaceTexture java class. It includes the C++ SurfaceTexture code as well as the JNI and Java code to enable the callback. Change-Id: Ifd8b8e7ad46ee70cba6da1c2e96dab8045d1ea30
This commit is contained in:
parent
a214c64d7f
commit
c4d4aeab52
|
@ -40,6 +40,10 @@ public:
|
||||||
enum { MIN_BUFFER_SLOTS = 3 };
|
enum { MIN_BUFFER_SLOTS = 3 };
|
||||||
enum { NUM_BUFFER_SLOTS = 32 };
|
enum { NUM_BUFFER_SLOTS = 32 };
|
||||||
|
|
||||||
|
struct FrameAvailableListener : public virtual RefBase {
|
||||||
|
virtual void onFrameAvailable() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
// tex indicates the name OpenGL texture to which images are to be streamed.
|
// tex indicates the name OpenGL texture to which images are to be streamed.
|
||||||
// This texture name cannot be changed once the SurfaceTexture is created.
|
// This texture name cannot be changed once the SurfaceTexture is created.
|
||||||
SurfaceTexture(GLuint tex);
|
SurfaceTexture(GLuint tex);
|
||||||
|
@ -93,6 +97,10 @@ public:
|
||||||
// functions.
|
// functions.
|
||||||
void getTransformMatrix(float mtx[16]);
|
void getTransformMatrix(float mtx[16]);
|
||||||
|
|
||||||
|
// setFrameAvailableListener sets the listener object that will be notified
|
||||||
|
// when a new frame becomes available.
|
||||||
|
void setFrameAvailableListener(const sp<FrameAvailableListener>& l);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// freeAllBuffers frees the resources (both GraphicBuffer and EGLImage) for
|
// freeAllBuffers frees the resources (both GraphicBuffer and EGLImage) for
|
||||||
|
@ -195,6 +203,11 @@ private:
|
||||||
// to a buffer, but other processes do.
|
// to a buffer, but other processes do.
|
||||||
Vector<sp<GraphicBuffer> > mAllocdBuffers;
|
Vector<sp<GraphicBuffer> > mAllocdBuffers;
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
sp<FrameAvailableListener> mFrameAvailableListener;
|
||||||
|
|
||||||
// mMutex is the mutex used to prevent concurrent access to the member
|
// mMutex is the mutex used to prevent concurrent access to the member
|
||||||
// variables of SurfaceTexture objects. It must be locked whenever the
|
// variables of SurfaceTexture objects. It must be locked whenever the
|
||||||
// member variables are accessed.
|
// member variables are accessed.
|
||||||
|
|
|
@ -166,6 +166,9 @@ status_t SurfaceTexture::queueBuffer(int buf) {
|
||||||
mLastQueued = buf;
|
mLastQueued = buf;
|
||||||
mLastQueuedCrop = mNextCrop;
|
mLastQueuedCrop = mNextCrop;
|
||||||
mLastQueuedTransform = mNextTransform;
|
mLastQueuedTransform = mNextTransform;
|
||||||
|
if (mFrameAvailableListener != 0) {
|
||||||
|
mFrameAvailableListener->onFrameAvailable();
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +297,13 @@ void SurfaceTexture::getTransformMatrix(float mtx[16]) {
|
||||||
mtxMul(mtx, mtxFlipV, mtxBeforeFlipV);
|
mtxMul(mtx, mtxFlipV, mtxBeforeFlipV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SurfaceTexture::setFrameAvailableListener(
|
||||||
|
const sp<FrameAvailableListener>& l) {
|
||||||
|
LOGV("SurfaceTexture::setFrameAvailableListener");
|
||||||
|
Mutex::Autolock lock(mMutex);
|
||||||
|
mFrameAvailableListener = l;
|
||||||
|
}
|
||||||
|
|
||||||
void SurfaceTexture::freeAllBuffers() {
|
void SurfaceTexture::freeAllBuffers() {
|
||||||
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
||||||
mSlots[i].mGraphicBuffer = 0;
|
mSlots[i].mGraphicBuffer = 0;
|
||||||
|
|
Loading…
Reference in New Issue