title: The surface has been released Media Codec
body: <p>I'm trying to code a encoder/decoder to send a camera through a TCP server and display it with a <code>SurfaceView</code>, when I do <code>decodec.configure</code> I have the "The surface has been released"</p>
  
  <p>This is my code:</p>
  
  <pre><code>SurfaceHolder.Callback callback1 = new SurfaceHolder.Callback() {
  
      @Override
      public void surfaceCreated(SurfaceHolder surfaceHolder) {
          Log.d(TAG,"inSurfaceCreated");
          hasActiveHolder = true;
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
          Log.d(TAG,"inSurfaceChanged");
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
          Log.d(TAG,"inSurfaceDestroyed");
          hasActiveHolder = false;
      }
  };
  FrameLayout frameLayout1=findViewById(R.id.frameLayout);
  SurfaceView surfaceView = new SurfaceView(this);
  SurfaceHolder holder1 = (surfaceView.getHolder());
  holder1.addCallback(callback1);
  Surface surfaceAffichage = holder1.getSurface();
  frameLayout1.addView(surfaceView);
  //while(!hasActiveHolder){ }
  
  MediaFormat mediaFormat = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, 640, 640);
  mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 1000000);
  mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 20);
  mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Flexible);
  mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
  final MediaCodec decodec = MediaCodec.createDecoderByType("video/avc");
  decodec.configure(mediaFormat, surfaceAffichage, null, 0);
  </code></pre>
  
  <p>If I remove the comment on while loop, I wait forever and the program never gets in the callback <code>surfaceCreated</code>  </p>
  
  <p>Can someone help me? </p>