@@ -86,8 +86,6 @@ void MediaPlayer::disconnect()
8686 if (p != 0 ) {
8787 p->disconnect ();
8888 }
89-
90- disconnectNativeWindow ();
9189}
9290
9391// always call with lock held
@@ -221,63 +219,12 @@ status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *m
221219 return mPlayer ->getMetadata (update_only, apply_filter, metadata);
222220}
223221
224- void MediaPlayer::disconnectNativeWindow () {
225- if (mConnectedWindow != NULL ) {
226- status_t err = native_window_api_disconnect (mConnectedWindow .get (),
227- NATIVE_WINDOW_API_MEDIA );
228-
229- if (err != OK ) {
230- LOGW (" native_window_api_disconnect returned an error: %s (%d)" ,
231- strerror (-err), err);
232- }
233- }
234- mConnectedWindow .clear ();
235- }
236-
237222status_t MediaPlayer::setVideoSurface (const sp<Surface>& surface)
238223{
239224 LOGV (" setVideoSurface" );
240225 Mutex::Autolock _l (mLock );
241226 if (mPlayer == 0 ) return NO_INIT ;
242-
243- sp<IBinder> binder (surface == NULL ? NULL : surface->asBinder ());
244- if (mConnectedWindowBinder == binder) {
245- return OK ;
246- }
247-
248- if (surface != NULL ) {
249- status_t err = native_window_api_connect (surface.get (),
250- NATIVE_WINDOW_API_MEDIA );
251-
252- if (err != OK ) {
253- LOGE (" setVideoSurface failed: %d" , err);
254- // Note that we must do the reset before disconnecting from the ANW.
255- // Otherwise queue/dequeue calls could be made on the disconnected
256- // ANW, which may result in errors.
257- reset_l ();
258-
259- disconnectNativeWindow ();
260-
261- return err;
262- }
263- }
264-
265- // Note that we must set the player's new surface before disconnecting the
266- // old one. Otherwise queue/dequeue calls could be made on the disconnected
267- // ANW, which may result in errors.
268- status_t err = mPlayer ->setVideoSurface (surface);
269-
270- disconnectNativeWindow ();
271-
272- mConnectedWindow = surface;
273-
274- if (err == OK ) {
275- mConnectedWindowBinder = binder;
276- } else {
277- disconnectNativeWindow ();
278- }
279-
280- return err;
227+ return mPlayer ->setVideoSurface (surface);
281228}
282229
283230status_t MediaPlayer::setVideoSurfaceTexture (
@@ -286,48 +233,7 @@ status_t MediaPlayer::setVideoSurfaceTexture(
286233 LOGV (" setVideoSurfaceTexture" );
287234 Mutex::Autolock _l (mLock );
288235 if (mPlayer == 0 ) return NO_INIT ;
289-
290- sp<IBinder> binder (surfaceTexture == NULL ? NULL :
291- surfaceTexture->asBinder ());
292- if (mConnectedWindowBinder == binder) {
293- return OK ;
294- }
295-
296- sp<ANativeWindow> anw;
297- if (surfaceTexture != NULL ) {
298- anw = new SurfaceTextureClient (surfaceTexture);
299- status_t err = native_window_api_connect (anw.get (),
300- NATIVE_WINDOW_API_MEDIA );
301-
302- if (err != OK ) {
303- LOGE (" setVideoSurfaceTexture failed: %d" , err);
304- // Note that we must do the reset before disconnecting from the ANW.
305- // Otherwise queue/dequeue calls could be made on the disconnected
306- // ANW, which may result in errors.
307- reset_l ();
308-
309- disconnectNativeWindow ();
310-
311- return err;
312- }
313- }
314-
315- // Note that we must set the player's new SurfaceTexture before
316- // disconnecting the old one. Otherwise queue/dequeue calls could be made
317- // on the disconnected ANW, which may result in errors.
318- status_t err = mPlayer ->setVideoSurfaceTexture (surfaceTexture);
319-
320- disconnectNativeWindow ();
321-
322- mConnectedWindow = anw;
323-
324- if (err == OK ) {
325- mConnectedWindowBinder = binder;
326- } else {
327- disconnectNativeWindow ();
328- }
329-
330- return err;
236+ return mPlayer ->setVideoSurfaceTexture (surfaceTexture);
331237}
332238
333239// must call with lock held
0 commit comments