From 1de1e25cba872bd4c077c2e394f8ca9c70b65856 Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Thu, 30 Apr 2015 18:18:34 -0700 Subject: stagefright: remove NativeWindowWrapper Now that Surface and SurfaceTextureClient are the same and Surface, it does not add value. Bug: 19489395 Change-Id: I016ecd1cf5cc51ce6244b6fa34ecd75f84e3db01 --- cmds/stagefright/SimplePlayer.cpp | 14 +++--- cmds/stagefright/SimplePlayer.h | 4 +- cmds/stagefright/sf2.cpp | 5 +-- include/media/stagefright/NativeWindowWrapper.h | 50 --------------------- media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 52 ++++++++++------------ media/libmediaplayerservice/nuplayer/NuPlayer.h | 7 ++- .../nuplayer/NuPlayerDecoder.cpp | 25 +++++------ .../nuplayer/NuPlayerDecoder.h | 4 +- media/libstagefright/ACodec.cpp | 14 +++--- media/libstagefright/MediaCodec.cpp | 11 +---- 10 files changed, 56 insertions(+), 130 deletions(-) delete mode 100644 include/media/stagefright/NativeWindowWrapper.h diff --git a/cmds/stagefright/SimplePlayer.cpp b/cmds/stagefright/SimplePlayer.cpp index bd33d86..50913cd 100644 --- a/cmds/stagefright/SimplePlayer.cpp +++ b/cmds/stagefright/SimplePlayer.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include namespace android { @@ -74,8 +73,7 @@ status_t SimplePlayer::setSurface(const sp &bufferProduc surface = new Surface(bufferProducer); } - msg->setObject( - "native-window", new NativeWindowWrapper(surface)); + msg->setObject("surface", surface); sp response; return PostAndAwaitResponse(msg, &response); @@ -133,10 +131,8 @@ void SimplePlayer::onMessageReceived(const sp &msg) { err = INVALID_OPERATION; } else { sp obj; - CHECK(msg->findObject("native-window", &obj)); - - mNativeWindow = static_cast(obj.get()); - + CHECK(msg->findObject("surface", &obj)); + mSurface = static_cast(obj.get()); err = OK; } @@ -325,7 +321,7 @@ status_t SimplePlayer::onPrepare() { err = state->mCodec->configure( format, - isVideo ? mNativeWindow->getSurfaceTextureClient() : NULL, + isVideo ? mSurface : NULL, NULL /* crypto */, 0 /* flags */); @@ -412,7 +408,7 @@ status_t SimplePlayer::onReset() { mStateByTrackIndex.clear(); mCodecLooper.clear(); mExtractor.clear(); - mNativeWindow.clear(); + mSurface.clear(); mPath.clear(); return OK; diff --git a/cmds/stagefright/SimplePlayer.h b/cmds/stagefright/SimplePlayer.h index ce993e8..ae9dfd2 100644 --- a/cmds/stagefright/SimplePlayer.h +++ b/cmds/stagefright/SimplePlayer.h @@ -25,8 +25,8 @@ struct ALooper; struct AudioTrack; class IGraphicBufferProducer; struct MediaCodec; -struct NativeWindowWrapper; struct NuMediaExtractor; +class Surface; struct SimplePlayer : public AHandler { SimplePlayer(); @@ -84,7 +84,7 @@ private: State mState; AString mPath; - sp mNativeWindow; + sp mSurface; sp mExtractor; sp mCodecLooper; diff --git a/cmds/stagefright/sf2.cpp b/cmds/stagefright/sf2.cpp index 891d84b..0d64d2f 100644 --- a/cmds/stagefright/sf2.cpp +++ b/cmds/stagefright/sf2.cpp @@ -38,10 +38,10 @@ #include #include #include -#include #include #include +#include #include "include/ESDS.h" @@ -154,8 +154,7 @@ protected: sp format = makeFormat(mSource->getFormat()); if (mSurface != NULL) { - format->setObject( - "native-window", new NativeWindowWrapper(mSurface)); + format->setObject("surface", mSurface); } mCodec->initiateSetup(format); diff --git a/include/media/stagefright/NativeWindowWrapper.h b/include/media/stagefright/NativeWindowWrapper.h deleted file mode 100644 index cfeec22..0000000 --- a/include/media/stagefright/NativeWindowWrapper.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 NATIVE_WINDOW_WRAPPER_H_ - -#define NATIVE_WINDOW_WRAPPER_H_ - -#include - -namespace android { - -// Surface derives from ANativeWindow which derives from multiple -// base classes, in order to carry it in AMessages, we'll temporarily wrap it -// into a NativeWindowWrapper. - -struct NativeWindowWrapper : RefBase { - NativeWindowWrapper( - const sp &surfaceTextureClient) : - mSurfaceTextureClient(surfaceTextureClient) { } - - sp getNativeWindow() const { - return mSurfaceTextureClient; - } - - sp getSurfaceTextureClient() const { - return mSurfaceTextureClient; - } - -private: - const sp mSurfaceTextureClient; - - DISALLOW_EVIL_CONSTRUCTORS(NativeWindowWrapper); -}; - -} // namespace android - -#endif // NATIVE_WINDOW_WRAPPER_H_ diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 4e30093..9963353 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -48,7 +48,9 @@ #include #include #include + #include +#include #include "avc_utils.h" @@ -99,16 +101,16 @@ private: }; struct NuPlayer::SetSurfaceAction : public Action { - SetSurfaceAction(const sp &wrapper) - : mWrapper(wrapper) { + SetSurfaceAction(const sp &surface) + : mSurface(surface) { } virtual void execute(NuPlayer *player) { - player->performSetSurface(mWrapper); + player->performSetSurface(mSurface); } private: - sp mWrapper; + sp mSurface; DISALLOW_EVIL_CONSTRUCTORS(SetSurfaceAction); }; @@ -311,15 +313,12 @@ void NuPlayer::prepareAsync() { void NuPlayer::setVideoSurfaceTextureAsync( const sp &bufferProducer) { - sp msg = new AMessage(kWhatSetVideoNativeWindow, this); + sp msg = new AMessage(kWhatSetVideoSurface, this); if (bufferProducer == NULL) { - msg->setObject("native-window", NULL); + msg->setObject("surface", NULL); } else { - msg->setObject( - "native-window", - new NativeWindowWrapper( - new Surface(bufferProducer, true /* controlledByApp */))); + msg->setObject("surface", new Surface(bufferProducer, true /* controlledByApp */)); } msg->post(); @@ -610,15 +609,15 @@ void NuPlayer::onMessageReceived(const sp &msg) { break; } - case kWhatSetVideoNativeWindow: + case kWhatSetVideoSurface: { - ALOGV("kWhatSetVideoNativeWindow"); + ALOGV("kWhatSetVideoSurface"); sp obj; - CHECK(msg->findObject("native-window", &obj)); - + CHECK(msg->findObject("surface", &obj)); + sp surface = static_cast(obj.get()); if (mSource == NULL || mSource->getFormat(false /* audio */) == NULL) { - performSetSurface(static_cast(obj.get())); + performSetSurface(surface); break; } @@ -626,9 +625,7 @@ void NuPlayer::onMessageReceived(const sp &msg) { new FlushDecoderAction(FLUSH_CMD_FLUSH /* audio */, FLUSH_CMD_SHUTDOWN /* video */)); - mDeferredActions.push_back( - new SetSurfaceAction( - static_cast(obj.get()))); + mDeferredActions.push_back(new SetSurfaceAction(surface)); if (obj != NULL) { if (mStarted) { @@ -813,7 +810,7 @@ void NuPlayer::onMessageReceived(const sp &msg) { // initialize video before audio because successful initialization of // video may change deep buffer mode of audio. - if (mNativeWindow != NULL) { + if (mSurface != NULL) { instantiateDecoder(false, &mVideoDecoder); } @@ -861,7 +858,7 @@ void NuPlayer::onMessageReceived(const sp &msg) { } if ((mAudioDecoder == NULL && mAudioSink != NULL) - || (mVideoDecoder == NULL && mNativeWindow != NULL)) { + || (mVideoDecoder == NULL && mSurface != NULL)) { msg->post(100000ll); mScanSourcesPending = true; } @@ -1207,7 +1204,7 @@ status_t NuPlayer::onInstantiateSecureDecoders() { // TRICKY: We rely on mRenderer being null, so that decoder does not start requesting // data on instantiation. - if (mNativeWindow != NULL) { + if (mSurface != NULL) { err = instantiateDecoder(false, &mVideoDecoder); if (err != OK) { return err; @@ -1454,10 +1451,10 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp *decoder) { notify->setInt32("generation", mVideoDecoderGeneration); *decoder = new Decoder( - notify, mSource, mRenderer, mNativeWindow, mCCDecoder); + notify, mSource, mRenderer, mSurface, mCCDecoder); // enable FRC if high-quality AV sync is requested, even if not - // queuing to native window, as this will even improve textureview + // directly queuing to display, as this will even improve textureview // playback. { char value[PROPERTY_VALUE_MAX]; @@ -1629,9 +1626,8 @@ void NuPlayer::queueDecoderShutdown( status_t NuPlayer::setVideoScalingMode(int32_t mode) { mVideoScalingMode = mode; - if (mNativeWindow != NULL) { - status_t ret = native_window_set_scaling_mode( - mNativeWindow->getNativeWindow().get(), mVideoScalingMode); + if (mSurface != NULL) { + status_t ret = native_window_set_scaling_mode(mSurface.get(), mVideoScalingMode); if (ret != OK) { ALOGE("Failed to set scaling mode (%d): %s", -ret, strerror(-ret)); @@ -1825,10 +1821,10 @@ void NuPlayer::performScanSources() { } } -void NuPlayer::performSetSurface(const sp &wrapper) { +void NuPlayer::performSetSurface(const sp &surface) { ALOGV("performSetSurface"); - mNativeWindow = wrapper; + mSurface = surface; // XXX - ignore error from setVideoScalingMode for now setVideoScalingMode(mVideoScalingMode); diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h index 88e929d..fcf6841 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h @@ -21,7 +21,6 @@ #include #include #include -#include namespace android { @@ -112,7 +111,7 @@ private: enum { kWhatSetDataSource = '=DaS', kWhatPrepare = 'prep', - kWhatSetVideoNativeWindow = '=NaW', + kWhatSetVideoSurface = '=VSu', kWhatSetAudioSink = '=AuS', kWhatMoreDataQueued = 'more', kWhatConfigPlayback = 'cfPB', @@ -141,7 +140,7 @@ private: uid_t mUID; sp mSource; uint32_t mSourceFlags; - sp mNativeWindow; + sp mSurface; sp mAudioSink; sp mVideoDecoder; bool mOffloadAudio; @@ -251,7 +250,7 @@ private: void performDecoderFlush(FlushCommand audio, FlushCommand video); void performReset(); void performScanSources(); - void performSetSurface(const sp &wrapper); + void performSetSurface(const sp &wrapper); void performResumeDecoders(bool needNotify); void onSourceNotify(const sp &msg); diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp index 3c4d695..376c93a 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp @@ -33,6 +33,8 @@ #include #include +#include + #include "avc_utils.h" #include "ATSParser.h" @@ -42,10 +44,10 @@ NuPlayer::Decoder::Decoder( const sp ¬ify, const sp &source, const sp &renderer, - const sp &nativeWindow, + const sp &surface, const sp &ccDecoder) : DecoderBase(notify), - mNativeWindow(nativeWindow), + mSurface(surface), mSource(source), mRenderer(renderer), mCCDecoder(ccDecoder), @@ -178,14 +180,9 @@ void NuPlayer::Decoder::onConfigure(const sp &format) { mIsAudio = !strncasecmp("audio/", mime.c_str(), 6); mIsVideoAVC = !strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime.c_str()); - sp surface = NULL; - if (mNativeWindow != NULL) { - surface = mNativeWindow->getSurfaceTextureClient(); - } - mComponentName = mime; mComponentName.append(" decoder"); - ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), surface.get()); + ALOGV("[%s] onConfigure (surface=%p)", mComponentName.c_str(), mSurface.get()); mCodec = MediaCodec::CreateByType(mCodecLooper, mime.c_str(), false /* encoder */); int32_t secure = 0; @@ -210,17 +207,17 @@ void NuPlayer::Decoder::onConfigure(const sp &format) { mCodec->getName(&mComponentName); status_t err; - if (mNativeWindow != NULL) { + if (mSurface != NULL) { // disconnect from surface as MediaCodec will reconnect err = native_window_api_disconnect( - surface.get(), NATIVE_WINDOW_API_MEDIA); + mSurface.get(), NATIVE_WINDOW_API_MEDIA); // We treat this as a warning, as this is a preparatory step. // Codec will try to connect to the surface, which is where // any error signaling will occur. ALOGW_IF(err != OK, "failed to disconnect from surface: %d", err); } err = mCodec->configure( - format, surface, NULL /* crypto */, 0 /* flags */); + format, mSurface, NULL /* crypto */, 0 /* flags */); if (err != OK) { ALOGE("Failed to configure %s decoder (err=%d)", mComponentName.c_str(), err); mCodec->release(); @@ -337,12 +334,10 @@ void NuPlayer::Decoder::onShutdown(bool notifyComplete) { mCodec = NULL; ++mBufferGeneration; - if (mNativeWindow != NULL) { + if (mSurface != NULL) { // reconnect to surface as MediaCodec disconnected from it status_t error = - native_window_api_connect( - mNativeWindow->getNativeWindow().get(), - NATIVE_WINDOW_API_MEDIA); + native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); ALOGW_IF(error != NO_ERROR, "[%s] failed to connect to native window, error=%d", mComponentName.c_str(), error); diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h index dd84620..070d51a 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h @@ -27,7 +27,7 @@ struct NuPlayer::Decoder : public DecoderBase { Decoder(const sp ¬ify, const sp &source, const sp &renderer = NULL, - const sp &nativeWindow = NULL, + const sp &surface = NULL, const sp &ccDecoder = NULL); virtual void getStats( @@ -54,7 +54,7 @@ private: kWhatRenderBuffer = 'rndr', }; - sp mNativeWindow; + sp mSurface; sp mSource; sp mRenderer; diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 4fcee90..7b87676 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -37,7 +39,6 @@ #include #include #include -#include #include #include @@ -1316,9 +1317,8 @@ status_t ACodec::configureCodec( } } if (haveNativeWindow) { - sp windowWrapper( - static_cast(obj.get())); - sp nativeWindow = windowWrapper->getNativeWindow(); + sp nativeWindow = + static_cast(static_cast(obj.get())); // START of temporary support for automatic FRC - THIS WILL BE REMOVED int32_t autoFrc; @@ -1477,10 +1477,8 @@ status_t ACodec::configureCodec( } if (haveNativeWindow) { - sp nativeWindow( - static_cast(obj.get())); - CHECK(nativeWindow != NULL); - mNativeWindow = nativeWindow->getNativeWindow(); + mNativeWindow = static_cast(obj.get()); + CHECK(mNativeWindow != NULL); native_window_set_scaling_mode( mNativeWindow.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 8a2dc35..25887ef 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -481,9 +480,7 @@ status_t MediaCodec::configure( msg->setInt32("flags", flags); if (nativeWindow != NULL) { - msg->setObject( - "native-window", - new NativeWindowWrapper(nativeWindow)); + msg->setObject("native-window", nativeWindow); } if (crypto != NULL) { @@ -1614,11 +1611,7 @@ void MediaCodec::onMessageReceived(const sp &msg) { if (obj != NULL) { format->setObject("native-window", obj); - - status_t err = setNativeWindow( - static_cast(obj.get()) - ->getSurfaceTextureClient()); - + status_t err = setNativeWindow(static_cast(obj.get())); if (err != OK) { PostReplyWithError(replyID, err); break; -- cgit v1.1