示例#1
0
 public void removeMediaCodecSurface() {
   synchronized (mSyncObject) {
     if (mCodecSurfaceManager != null) {
       mCodecSurfaceManager.release();
       mCodecSurfaceManager = null;
     }
   }
 }
示例#2
0
  @Override
  public void run() {

    mViewSurfaceManager = new SurfaceManager(getHolder().getSurface());
    mViewSurfaceManager.makeCurrent();
    mTextureManager.createTexture().setOnFrameAvailableListener(this);

    mLock.release();

    try {
      // long ts = 0, oldts = 0;
      long startTimeUS = 0, ts;
      while (mRunning) {
        synchronized (mSyncObject) {
          // mSyncObject.wait(2500);
          // only wait for 100 ms, make it more responsive
          mSyncObject.wait(100);
          if (mFrameAvailable) {
            mFrameAvailable = false;

            mViewSurfaceManager.makeCurrent();
            mTextureManager.updateFrame();
            mTextureManager.drawFrame();
            mViewSurfaceManager.swapBuffer();

            if (mCodecSurfaceManager != null) {
              mCodecSurfaceManager.makeCurrent();
              mTextureManager.drawFrame();
              ts = mTextureManager.getSurfaceTexture().getTimestamp();
              if (mFirstFrame) {
                startTimeUS = ts;
                mFirstFrame = false;
              }
              ts = ts - startTimeUS;
              Log.d(TAG, "input presentation time: " + (ts / 1000000) + "(ms)");
              // Log.d(TAG, "FPS: "+(1000000000/(ts-oldts)));
              mCodecSurfaceManager.setPresentationTime(ts);
              mCodecSurfaceManager.swapBuffer();
            }

          } else {
            Log.e(TAG, "No frame received !");
          }
        }
      }
    } catch (InterruptedException ignore) {
    } finally {
      mViewSurfaceManager.release();
      mTextureManager.release();
    }
  }