How to draw the openGL texture retrieved by Remote

2019-08-16 08:35发布

问题:

On webrtc i just do this to get the remote stream:

  mRemoteVideoTrack = getRemoteVideoTrack();
  mRemoteVideoTrack.setEnabled(true);
  mRemoteVideoTrack.addSink(mRemoteProxyVideoSink);

  private VideoTrack getRemoteVideoTrack() {
    for (RtpTransceiver transceiver : mPeerConnection.getTransceivers()) {
      MediaStreamTrack track = transceiver.getReceiver().track();
      if (track instanceof VideoTrack) {
        return (VideoTrack) track;
      }
    }
    return null;
  }    

and I get the texture id in the mRemoteProxyVideoSink :

  private class RemoteProxyVideoSink implements VideoSink {

    @Override
    synchronized public void onFrame(VideoFrame frame) {
       VideoFrame.TextureBuffer textureBuffer = (VideoFrame.TextureBuffer) frame.getBuffer();
       mTextureID = textureBuffer.getTextureId();
    }

  }

NOTE: The onFrame is not fired in the main UI thread, but inside a background thread (I don't know if it's matter). Later in the main UI thread when I draw on a surface the very first retrieved texture frame I have this result :

but on the following refresh (ie onFrame event), when I try to draw again the texture (it's texture id didn't change) then i have this result:

Each subsequent paint of the texture makes the picture pinker and pinker. with time the picture becomes to be absolutely pink, no visible form:

any idea what wrong?