Skip to content

Commit c78e4e8

Browse files
author
Dave Sparks
committed
Allow setVideoSurface to be called multiple times. Allow a null
to be passed so that video can continue playing without a surface.
1 parent 96af7f1 commit c78e4e8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

android/android_surface_output.cpp

+27-8
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,25 @@ OSCL_EXPORT_REF AndroidSurfaceOutput::AndroidSurfaceOutput() :
5353
status_t AndroidSurfaceOutput::set(PVPlayer* pvPlayer, const sp<ISurface>& surface, bool emulation)
5454
{
5555
mPvPlayer = pvPlayer;
56-
mSurface = surface;
5756
mEmulation = emulation;
57+
setVideoSurface(surface);
58+
return NO_ERROR;
59+
}
60+
61+
status_t AndroidSurfaceOutput::setVideoSurface(const sp<ISurface>& surface)
62+
{
63+
LOGV("setVideoSurface(%p)", surface.get());
64+
// unregister buffers for the old surface
65+
if (mSurface != NULL) {
66+
LOGV("unregisterBuffers from old surface");
67+
mSurface->unregisterBuffers();
68+
}
69+
mSurface = surface;
70+
// register buffers for the new surface
71+
if ((mSurface != NULL) && (mFrameHeap != NULL)) {
72+
LOGV("registerBuffers from old surface");
73+
mSurface->registerBuffers(mBufferHeap);
74+
}
5875
return NO_ERROR;
5976
}
6077

@@ -311,6 +328,8 @@ PVMFCommandId AndroidSurfaceOutput::Start(const OsclAny* aContext)
311328
// post the last video frame to refresh screen after pause
312329
void AndroidSurfaceOutput::postLastFrame()
313330
{
331+
// ignore if no surface or heap
332+
if ((mSurface == NULL) || (mFrameHeap == NULL)) return;
314333
mSurface->postBuffer(mFrameBuffers[mFrameBufferIndex]);
315334
}
316335

@@ -957,9 +976,9 @@ OSCL_EXPORT_REF bool AndroidSurfaceOutput::initCheck()
957976
return false;
958977
}
959978

960-
ISurface::BufferHeap buffers(displayWidth, displayHeight,
979+
mBufferHeap = ISurface::BufferHeap(displayWidth, displayHeight,
961980
frameWidth, frameHeight, PIXEL_FORMAT_RGB_565, mFrameHeap);
962-
mSurface->registerBuffers(buffers);
981+
mSurface->registerBuffers(mBufferHeap);
963982

964983
// create frame buffers
965984
for (int i = 0; i < kBufferCount; i++) {
@@ -986,12 +1005,12 @@ OSCL_EXPORT_REF bool AndroidSurfaceOutput::initCheck()
9861005

9871006
OSCL_EXPORT_REF PVMFStatus AndroidSurfaceOutput::writeFrameBuf(uint8* aData, uint32 aDataLen, const PvmiMediaXferHeader& data_header_info)
9881007
{
989-
if (mSurface == 0) return PVMFFailure;
990-
991-
iColorConverter->Convert(aData, static_cast<uint8*>(mFrameHeap->base()) + mFrameBuffers[mFrameBufferIndex]);
9921008
// post to SurfaceFlinger
993-
if (++mFrameBufferIndex == kBufferCount) mFrameBufferIndex = 0;
994-
mSurface->postBuffer(mFrameBuffers[mFrameBufferIndex]);
1009+
if ((mSurface != NULL) && (mFrameHeap != NULL)) {
1010+
if (++mFrameBufferIndex == kBufferCount) mFrameBufferIndex = 0;
1011+
iColorConverter->Convert(aData, static_cast<uint8*>(mFrameHeap->base()) + mFrameBuffers[mFrameBufferIndex]);
1012+
mSurface->postBuffer(mFrameBuffers[mFrameBufferIndex]);
1013+
}
9951014
return PVMFSuccess;
9961015
}
9971016

android/android_surface_output.h

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class AndroidSurfaceOutput : public OsclTimerObject
9595

9696
// parameter initialization
9797
virtual status_t set(android::PVPlayer* pvPlayer, const sp<ISurface>& surface, bool emulation);
98+
virtual status_t setVideoSurface(const sp<ISurface>& surface);
9899

99100
// For frame buffer
100101
virtual bool initCheck();
@@ -307,6 +308,7 @@ class AndroidSurfaceOutput : public OsclTimerObject
307308
static const int kBufferCount = 2;
308309
int mFrameBufferIndex;
309310
sp<MemoryHeapBase> mFrameHeap;
311+
ISurface::BufferHeap mBufferHeap;
310312
size_t mFrameBuffers[kBufferCount];
311313

312314
void convertFrame(void* src, void* dst, size_t len);

0 commit comments

Comments
 (0)