@@ -53,8 +53,25 @@ OSCL_EXPORT_REF AndroidSurfaceOutput::AndroidSurfaceOutput() :
53
53
status_t AndroidSurfaceOutput::set (PVPlayer* pvPlayer, const sp<ISurface>& surface, bool emulation)
54
54
{
55
55
mPvPlayer = pvPlayer;
56
- mSurface = surface;
57
56
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
+ }
58
75
return NO_ERROR;
59
76
}
60
77
@@ -311,6 +328,8 @@ PVMFCommandId AndroidSurfaceOutput::Start(const OsclAny* aContext)
311
328
// post the last video frame to refresh screen after pause
312
329
void AndroidSurfaceOutput::postLastFrame ()
313
330
{
331
+ // ignore if no surface or heap
332
+ if ((mSurface == NULL ) || (mFrameHeap == NULL )) return ;
314
333
mSurface ->postBuffer (mFrameBuffers [mFrameBufferIndex ]);
315
334
}
316
335
@@ -957,9 +976,9 @@ OSCL_EXPORT_REF bool AndroidSurfaceOutput::initCheck()
957
976
return false ;
958
977
}
959
978
960
- ISurface::BufferHeap buffers (displayWidth, displayHeight,
979
+ mBufferHeap = ISurface::BufferHeap (displayWidth, displayHeight,
961
980
frameWidth, frameHeight, PIXEL_FORMAT_RGB_565, mFrameHeap );
962
- mSurface ->registerBuffers (buffers );
981
+ mSurface ->registerBuffers (mBufferHeap );
963
982
964
983
// create frame buffers
965
984
for (int i = 0 ; i < kBufferCount ; i++) {
@@ -986,12 +1005,12 @@ OSCL_EXPORT_REF bool AndroidSurfaceOutput::initCheck()
986
1005
987
1006
OSCL_EXPORT_REF PVMFStatus AndroidSurfaceOutput::writeFrameBuf (uint8* aData, uint32 aDataLen, const PvmiMediaXferHeader& data_header_info)
988
1007
{
989
- if (mSurface == 0 ) return PVMFFailure;
990
-
991
- iColorConverter->Convert (aData, static_cast <uint8*>(mFrameHeap ->base ()) + mFrameBuffers [mFrameBufferIndex ]);
992
1008
// 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
+ }
995
1014
return PVMFSuccess;
996
1015
}
997
1016
0 commit comments