2. setVideoSurfaceTexture
display设置这里用了SurfaceTexture,可以说替换了以前的SurfaceView。SurfaceTexture比SurfaceView更优化和强大,主要是体现在现实窗口的绘画和控制方面,这方面以后再详细研究。
mediaplayer.cpp
status_t MediaPlayer::setVideoSurfaceTexture(
const sp<IGraphicBufferProducer>& bufferProducer)
{
ALOGV("setVideoSurfaceTexture");
Mutex::Autolock _l(mLock);
if (mPlayer == 0) return NO_INIT;
return mPlayer->setVideoSurfaceTexture(bufferProducer);
}
NuPlayer.cpp
void NuPlayer::setVideoSurfaceTextureAsync(
const sp<IGraphicBufferProducer> &bufferProducer) {
sp<AMessage> msg = new AMessage(kWhatSetVideoNativeWindow, id());
if (bufferProducer == NULL) {
msg->setObject("native-window", NULL);
} else {
msg->setObject(
"native-window",
new NativeWindowWrapper(
new Surface(bufferProducer, true /* controlledByApp */)));
}
msg->post();
}
onMessageReceived处理:
case kWhatSetVideoNativeWindow:
{
ALOGV("kWhatSetVideoNativeWindow");
mDeferredActions.push_back(
new ShutdownDecoderAction(
false /* audio */, true /* video */));
sp<RefBase> obj;
CHECK(msg->findObject("native-window", &obj));
mDeferredActions.push_back(
new SetSurfaceAction(
static_cast<NativeWindowWrapper *>(obj.get())));
if (obj != NULL) {
if (mStarted && mSource->getFormat(false /* audio */) != NULL) {
// Issue a seek to refresh the video screen only if started otherwise
// the extractor may not yet be started and will assert.
// If the video decoder is not set (perhaps audio only in this case)
// do not perform a seek as it is not needed.
int64_t currentPositionUs = 0;
if (getCurrentPosition(¤tPositionUs) == OK) {
mDeferredActions.push_back(
new SeekAction(currentPositionUs, false /* needNotify */));
}
}
// If there is a new surface texture, instantiate decoders
// again if possible.
mDeferredActions.push_back(
new SimpleAction(&NuPlayer::performScanSources));
}
processDeferredActions();
break;
}