Java 类android.view.Surface 实例源码

项目:opencv-documentscanner-android    文件:Camera2BasicFragment.java   
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
项目:MyAnimeViewer    文件:CropUtil.java   
public static int getOrientationInDegree(Activity activity) {

        int rotation = activity.getWindowManager().getDefaultDisplay()
                .getRotation();
        int degrees = 0;

        switch (rotation) {
            case Surface.ROTATION_0:
                degrees = 0;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_270:
                degrees = 270;
                break;
        }

        return degrees;
    }
项目:RobotIGS    文件:Sensors.java   
/**
 * Get the natural orientation of the device. For larger phones it is often LANDSCAPE - for smaller, PORTRAIT.
 *
 * @return LANDSCAPE or PORTRAIT, based on the screen information
 */
public ScreenOrientation getDeviceDefaultOrientation() {

    WindowManager windowManager = (WindowManager) Util.getContext().getSystemService(Context.WINDOW_SERVICE);

    Configuration config = Util.getContext().getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
            config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
            config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return ScreenOrientation.LANDSCAPE;
    } else {
        return ScreenOrientation.PORTRAIT;
    }
}
项目:aos-Video    文件:VideoEffectRenderer.java   
@Override
protected synchronized void initGLComponents()
{
    if (mEffect != null) {
    mEffect.initGLComponents();
    int videoTexture = mEffect.getVideoTexture();
    mVideoSurfaceTexture = new SurfaceTexture(videoTexture);
    mVideoSurfaceTexture.setOnFrameAvailableListener(this);

    int uiTexture = mEffect.getUIOverlayTexture();
    mUISurfaceTexture = new SurfaceTexture(uiTexture);
    mUISurfaceTexture.setDefaultBufferSize(mViewWidth, mViewHeight);
    mUISurface = new Surface(mUISurfaceTexture);
    try {
        Canvas c = mUISurface.lockCanvas(null);
        c.drawColor(0x0);
        mUISurface.unlockCanvasAndPost(c);
    } catch (Exception e) { }
    }
    notifyInit();
}
项目:ImageClassify    文件:CameraConnectionFragment.java   
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
  final Activity activity = getActivity();
  if (null == textureView || null == previewSize || null == activity) {
    return;
  }
  final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  final Matrix matrix = new Matrix();
  final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  final float centerX = viewRect.centerX();
  final float centerY = viewRect.centerY();
  if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
    bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
    matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
    final float scale =
        Math.max(
            (float) viewHeight / previewSize.getHeight(),
            (float) viewWidth / previewSize.getWidth());
    matrix.postScale(scale, scale, centerX, centerY);
    matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  } else if (Surface.ROTATION_180 == rotation) {
    matrix.postRotate(180, centerX, centerY);
  }
  textureView.setTransform(matrix);
}
项目:AAVT    文件:Mp4Provider.java   
@Override
public Point open(SurfaceTexture surface) {
    try {
        if(!extractMedia()){
            return new Point(0,0);
        }
        mFrameSem=new Semaphore(0);
        mDecodeSem=new Semaphore(1);
        videoProvideEndFlag=false;
        isUserWantToStop=false;
        mAudioEncodeTrack=mStore.addTrack(mExtractor.getTrackFormat(mAudioDecodeTrack));
        MediaFormat format=mExtractor.getTrackFormat(mVideoDecodeTrack);
        mVideoDecoder = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
        mVideoDecoder.configure(format,new Surface(surface),null,0);
        mVideoDecoder.start();
        startDecodeThread();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return mVideoSize;
}
项目:AndroidBlueprints    文件:Utils.java   
/**
 * Locks the device window in actual screen mode
 */
public static void lockOrientation(Activity activity) {
    Display display = ((WindowManager) activity.
            getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;

    switch (activity.getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_LANDSCAPE:
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            else
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        case Configuration.ORIENTATION_PORTRAIT:
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            else
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    }
    //noinspection ResourceType
    activity.setRequestedOrientation(orientation);
}
项目:SortingHatAndroid    文件:CameraConnectionFragment.java   
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
  final Activity activity = getActivity();
  if (null == textureView || null == previewSize || null == activity) {
    return;
  }
  final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  final Matrix matrix = new Matrix();
  final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  final float centerX = viewRect.centerX();
  final float centerY = viewRect.centerY();
  if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
    bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
    matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
    final float scale = Math.max((float) viewHeight / previewSize.getHeight(),
        (float) viewWidth / previewSize.getWidth());
    matrix.postScale(scale, scale, centerX, centerY);
    matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  } else if (Surface.ROTATION_180 == rotation) {
    matrix.postRotate(180, centerX, centerY);
  }
  textureView.setTransform(matrix);
}
项目:VideoRecorder-master    文件:Util.java   
public static int getRotationAngle(int rotation)
{
    int degrees  = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;
        break;

    case Surface.ROTATION_90:
        degrees = 90;
        break;

    case Surface.ROTATION_180:
        degrees = 180;
        break;

    case Surface.ROTATION_270:
        degrees = 270;
        break;
    default:
        break;
    }
    return degrees;
}
项目:android-api    文件:HeadingService.java   
private float adjustHeadingForDeviceOrientation(float heading)
{
    switch (m_deviceRotation) {
        case Surface.ROTATION_0:
            heading += 0.f;
            break;
        case Surface.ROTATION_90:
            heading += 90.f;
            break;
        case Surface.ROTATION_180:
            heading += 180.f;
            break;
        default:
            heading += 90.f;
            break;
    }

    heading = (heading + 360.f)%360.f;
    return heading;
}
项目:VideoApplication    文件:MoviePlayer.java   
public MoviePlayer(File sourceFile, Surface outputSurface)
        throws IOException {
    // Pop the file open and pull out the video characteristics.
    // TODO: consider leaving the extractor open.  Should be able to just seek back to
    //       the start after each iteration of play.  Need to rearrange the API a bit --
    //       currently play() is taking an all-in-one open+work+release approach.
    try {
        Log.d(TAG, sourceFile.toString());
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(sourceFile.toString());
        mVideoDuration = Long.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        Log.d(TAG, "Duration: " + mVideoDuration);
        retriever.release();

        mVideoDecoder = new VideoDecoder(this, sourceFile);
        mVideoDecoder.setOutputSurface(outputSurface);
        mAudioDecoder = new AudioDecoder(this, sourceFile);
        mVideoDecoder.prepare();
        mAudioDecoder.prepare();
    } catch (Exception ex) {
        release();
        throw new IOException(ex.getMessage());
    }
}
项目:habpanelviewer    文件:MotionDetectorCamera2.java   
private void configureTransform(TextureView textureView) {
    if (null == textureView || null == mPreviewSize || null == mActivity) {
        return;
    }
    int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, textureView.getWidth(), textureView.getHeight());
    RectF bufferRect = new RectF(0, 0, mPreviewSize.y, mPreviewSize.x);
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) textureView.getHeight() / mPreviewSize.y,
                (float) textureView.getWidth() / mPreviewSize.x);
        matrix.postScale(scale, scale, centerX, centerY);
    }
    matrix.postRotate(-90 * rotation, centerX, centerY);
    textureView.setTransform(matrix);
}
项目:smart-lens    文件:Camera2Api.java   
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    if (mPreviewSize == null) return;

    final int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mAutoFitTextureView.setTransform(matrix);
}
项目:Android-opencv-native-samples    文件:ImageControllers.java   
private int getDisplayRotation(Context context) {
    WindowManager windowManager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch (rotation) {
        case Surface.ROTATION_0:
            return 0;
        case Surface.ROTATION_90:
            return 90;
        case Surface.ROTATION_180:
            return 180;
        case Surface.ROTATION_270:
            return 270;
    }
    return 0;
}
项目:AndroidRTC    文件:Camera1Session.java   
private int getDeviceOrientation() {
  int orientation = 0;

  WindowManager wm = (WindowManager) applicationContext.getSystemService(Context.WINDOW_SERVICE);
  switch (wm.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
      orientation = 90;
      break;
    case Surface.ROTATION_180:
      orientation = 180;
      break;
    case Surface.ROTATION_270:
      orientation = 270;
      break;
    case Surface.ROTATION_0:
    default:
      orientation = 0;
      break;
  }
  return orientation;
}
项目:Ocr-android    文件:CameraPreview.java   
/**
 * 在确定相机预览大小后应调用此方法
 *
 * @param viewWidth  宽
 * @param viewHeight 高
 */
private void configureTransform(int viewWidth, int viewHeight) {
    if (null == mPreviewSize) {
        return;
    }
    int rotation = getDisplayRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    this.setTransform(matrix);
}
项目:CommonsLab    文件:Camera2VideoFragment.java   
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should not to be called until the camera preview size is determined in
 * openCamera, or until the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
项目:Paper-Melody    文件:PlayActivity.java   
/**
 * 当手机屏幕的朝向改变时,要对获取到的视频流进行方向上的调整
 *
 * @param viewWidth  TextureView的宽度
 * @param viewHeight TextureView的高度
 */
private void configureTransform(int viewWidth, int viewHeight) {

    if (viewPlay == null || previewSize == null) {
        return;
    }
    int rotation = getWindowManager().getDefaultDisplay().getRotation();

    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    viewPlay.setTransform(matrix);
}
项目:xbot_head    文件:CommentaryFragment.java   
private void startPreview() {
    try {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

        Size previewSize = Util.getPreferredPreviewSize(
                configMap.getOutputSizes(ImageFormat.JPEG),textureView.getWidth(), textureView.getHeight());

        surfaceTexture.setDefaultBufferSize(previewSize.getWidth(),previewSize.getHeight());
        Surface surface = new Surface(surfaceTexture);
        captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        captureBuilder.addTarget(surface);

        cameraDevice.createCaptureSession(Arrays.asList(surface),captureSessionCallback,backgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
项目:Fatigue-Detection    文件:EGLBase.java   
EglSurface(final EGLBase egl, final Object surface) {
    if (DEBUG) Log.v(TAG, "EglSurface:");
    if (!(surface instanceof SurfaceView)
        && !(surface instanceof Surface)
        && !(surface instanceof SurfaceHolder)
        && !(surface instanceof SurfaceTexture))
        throw new IllegalArgumentException("unsupported surface");
    mEgl = egl;
    mEglSurface = mEgl.createWindowSurface(surface);
       mWidth = mEgl.querySurface(mEglSurface, EGL14.EGL_WIDTH);
       mHeight = mEgl.querySurface(mEglSurface, EGL14.EGL_HEIGHT);
       if (DEBUG) Log.v(TAG, String.format("EglSurface:size(%d,%d)", mWidth, mHeight));
}
项目:InsideCodec    文件:FrameProducer.java   
public FrameProducer(final EglBase eglBase, final File videoFile, final int fps,
        final Callback callback) {
    mVideoFile = videoFile;
    mFps = fps;
    mCallback = callback;
    mBufferInfo = new MediaCodec.BufferInfo();

    mSurfaceTextureHelper = SurfaceTextureHelper.create("SurfaceTextureHelper",
            eglBase.getEglBaseContext());
    mSurfaceTextureHelper.startListening(this);
    mHubSurface = new Surface(mSurfaceTextureHelper.getSurfaceTexture());
}
项目:CustomAndroidOneSheeld    文件:CameraHeadService.java   
public void setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    int rotation = windowManager.getDefaultDisplay()
            .getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
}
项目:TimePicker    文件:Utils.java   
public static boolean isLandscape(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    switch (rotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
            return false;

        case Surface.ROTATION_90:
        case Surface.ROTATION_270:
            return true;
    }
    return true;
}
项目:GitHub    文件:SurfaceRenderView.java   
@Nullable
@Override
public Surface openSurface() {
    if (mSurfaceHolder == null)
        return null;
    return mSurfaceHolder.getSurface();
}
项目:TPlayer    文件:MediaPlayer.java   
/**
 * Sets the Surface to use for displaying the video portion of the media. This
 * is similar to {@link #setDisplay(SurfaceHolder)}.
 *
 * @param surface the Surface to use for video display
 */
public void setSurface(Surface surface) {
  if (surface == null) {
    releaseDisplay();
  } else {
    mSurfaceHolder = null;
    mSurface = surface;
    _setVideoSurface(mSurface);
    updateSurfaceScreenOn();
  }
}
项目:live_master    文件:SurfaceRenderView.java   
@Nullable
@Override
public Surface openSurface() {
    if (mSurfaceHolder == null)
        return null;
    return mSurfaceHolder.getSurface();
}
项目:PlusGram    文件:MediaCodecVideoTrackRenderer.java   
/**
 * @param surface The surface to set.
 * @throws ExoPlaybackException
 */
private void setSurface(Surface surface) throws ExoPlaybackException {
  if (this.surface == surface) {
    return;
  }
  this.surface = surface;
  this.reportedDrawnToSurface = false;
  int state = getState();
  if (state == TrackRenderer.STATE_ENABLED || state == TrackRenderer.STATE_STARTED) {
    releaseCodec();
    maybeInitCodec();
  }
}
项目:ZxingForAndroid    文件:CameraManager.java   
private int calculateDisplayRotation() {
    // http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
    int rotation = displayConfiguration.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (cameraInfo.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (cameraInfo.orientation - degrees + 360) % 360;
    }
    Log.i(TAG, "Camera Display Orientation: " + result);
    return result;
}
项目:CameraFragment    文件:Utils.java   
public static int getDeviceDefaultOrientation(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Configuration config = context.getResources().getConfiguration();

    int rotation = windowManager.getDefaultDisplay().getRotation();

    if (((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
            config.orientation == Configuration.ORIENTATION_LANDSCAPE)
            || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
            config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
        return Configuration.ORIENTATION_LANDSCAPE;
    } else {
        return Configuration.ORIENTATION_PORTRAIT;
    }
}
项目:mpeg-encoder    文件:InputSurfaceAndroidTest.java   
/** Common "before" functionality. */
@Before
public final void setUp() throws Exception {
    mEglDisplay = GLTools.newDisplay();

    final EGLConfig eglConfig = GLTools.newConfig(mEglDisplay, true);
    mEglContext = GLTools.newContext(mEglDisplay, eglConfig);
    mEglSurface = GLTools.newSurface(mEglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);
    GLTools.makeCurrent(mEglDisplay, mEglSurface, mEglContext);

    mTexture = GLTools.newTexture(TEXTURE_LEVEL);
    mSurfaceTexture = new SurfaceTexture(mTexture, true);
    mSurface = new Surface(mSurfaceTexture);
}
项目:OkayCamera-Android    文件:OkCaptureRequestBuilder.java   
/**
 * Add a surface to the list of targets for this request,
 * The Surface added must be one of the surfaces included in the most recent call to createCaptureSession(List,
 * CameraCaptureSession.StateCallback, Handler), when the request is given to the camera device.
 * @param outputTarget Surface to use as an output target for this request
 * @throws ObjectNotInitializedException You should call init() before call this method otherwise
 * it will throw a ObjectNotInitializedException
 * @see CaptureRequest.Builder#addTarget(Surface)
 */
@Deprecated
public OkCaptureRequestBuilder addTarget(@NonNull Surface outputTarget)
        throws ObjectNotInitializedException {
    if (mBuilder != null) {
        mBuilder.addTarget(outputTarget);
    } else {
        throw genException();
    }
    return this;
}
项目:polling-station-app    文件:CameraFragment.java   
/**
 * Extract a bitmap from the textureview of this fragment.
 * @return
 */
public Bitmap extractBitmap() {
    try {
        Bitmap bitmap = mTextureView.getBitmap();
        int rotate = Surface.ROTATION_0;
        switch (getActivity().getWindowManager().getDefaultDisplay().getRotation()) {
            case Surface.ROTATION_0:
                rotate = 0;
                break;
            case Surface.ROTATION_90:
                rotate = 270;
                break;
            case Surface.ROTATION_180:
                rotate = 180;
                break;
            case Surface.ROTATION_270:
                rotate = 90;
                break;
        }
        if (rotate != Surface.ROTATION_0) {
            bitmap = CameraFragmentUtil.rotateBitmap(bitmap, rotate);
        }
        Bitmap croppedBitmap = CameraFragmentUtil.cropBitmap(bitmap, scanSegment);

        return CameraFragmentUtil.getResizedBitmap(croppedBitmap, croppedBitmap.getWidth(), croppedBitmap.getHeight());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}
项目:ZxingScan    文件:CameraConfigurationManager.java   
public int getDisplayOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;
    } else {
        result = (info.orientation - degrees + 360) % 360;
    }
    return result;
}
项目:OkayCamera-Android    文件:OkCaptureRequestBuilder.java   
public OkCaptureRequestBuilder  removeTarget(@NonNull Surface outputTarget)
        throws ObjectNotInitializedException {
    if (mBuilder != null) {
        mBuilder.removeTarget(outputTarget);
    } else {
        throw genException();
    }
    return this;
}
项目:NSMPlayer-Android    文件:TextureRenderView.java   
@Nullable
@Override
public Surface openSurface() {
    if (mSurfaceTexture == null)
        return null;
    return new Surface(mSurfaceTexture);
}
项目:Camera2Vision    文件:CameraSource.java   
/**
 * Calculates the correct rotation for the given camera id and sets the rotation in the
 * parameters.  It also sets the camera's display orientation and rotation.
 *
 * @param parameters the camera parameters for which to set the rotation
 * @param cameraId   the camera id to set rotation based on
 */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    switch (windowManager.getDefaultDisplay().getRotation()) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
        default:
            Log.e(TAG, "Bad rotation value");
    }

    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int angle;
    int displayAngle;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        displayAngle = (360 - angle) % 360; // compensate for it being mirrored
    } else {  // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }

    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;

    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}
项目:aos-MediaLib    文件:AvosMediaPlayer.java   
public void setDisplay(SurfaceHolder sh) {
    mSurfaceHolder = sh;
    Surface surface;
    if (sh != null) {
        surface = sh.getSurface();
    } else {
        surface = null;
    }
    setVideoSurface(surface);
    updateSurfaceScreenOn();
}
项目:Exoplayer2Radio    文件:SimpleExoPlayer.java   
@Override
public void onRenderedFirstFrame(Surface surface) {
  if (videoListener != null && SimpleExoPlayer.this.surface == surface) {
    videoListener.onRenderedFirstFrame();
  }
  if (videoDebugListener != null) {
    videoDebugListener.onRenderedFirstFrame(surface);
  }
}
项目:xbot_head    文件:FaceOverlayView.java   
@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mFaces != null && mFaces.length > 0) {

            float scaleX = (float) getWidth() / (float) previewWidth;
            float scaleY = (float) getHeight() / (float) previewHeight;
            switch (mDisplayOrientation) {
                case Surface.ROTATION_90:
                case Surface.ROTATION_270:
                    scaleX = (float) getWidth() / (float) previewHeight;
                    scaleY = (float) getHeight() / (float) previewWidth;
                    break;
            }

            canvas.save();
            canvas.rotate(-mOrientation);

            for (FaceResult face : mFaces) {
                PointF mid = new PointF();
                face.getMidPoint(mid);
                if (mid.x != 0.0f && mid.y != 0.0f) {
                    float eyesDis = face.eyesDistance();
                    RectF rectF = ImageUtils.getDrawFaceRectF(mid,eyesDis,scaleX,scaleY);

                    canvas.drawRect(rectF, mPaint);
//                    canvas.drawText("ID " + face.getId(), rectF.left, rectF.bottom + mTextPaint.getTextSize(), mTextPaint);
//                    canvas.drawText("Confidence " + face.getConfidence(), rectF.left, rectF.bottom + mTextPaint.getTextSize() * 2, mTextPaint);
//                    canvas.drawText("EyesDistance " + face.eyesDistance(), rectF.left, rectF.bottom + mTextPaint.getTextSize() * 3, mTextPaint);
                }
            }
            canvas.restore();
        }



//        DecimalFormat df2 = new DecimalFormat(".##");
//        canvas.drawText("Detected_Frame/s: " + df2.format(fps) + " @ " + previewWidth + "x" + previewHeight, mTextPaint.getTextSize(), mTextPaint.getTextSize(), mTextPaint);
    }
项目:Hitalk    文件:CameraConfigurationManager.java   
public int getDisplayOrientation() {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;
    } else {
        result = (info.orientation - degrees + 360) % 360;
    }
    return result;
}