-
Notifications
You must be signed in to change notification settings - Fork 6
CameraCapture
buliaoyin edited this page Nov 22, 2017
·
1 revision
Table of Contents
CameraCapture 类基于Android的Camera接口实现了视频采集功能,输出Texture或NV12格式的图像数据。
CameraCapture 包含两个SrcPin, 一个Frame格式为ImgTexFrame, 一个为ImgBufFrame.
/** * 实现输出类型为ImgTexFrame的SrcPin, 以实现Texture图像的输出. */ public SrcPin<ImgTexFrame> getImgTexSrcPin(); /** * 实现输出类型为ImgBufFrame的SrcPin, 以实现buffer图像数据的输出. */ public SrcPin<ImgBufFrame> getImgBufSrcPin();
/** * 配置视频采集分辨率. */ public void setPreviewSize(int width, int height); /** * 配置采集帧率. */ public void setPreviewFps(float fps) { mPresetPreviewFps = fps; } /** * 配置采集预览的方向 * @param degrees the rotate degrees of current Activity.<br/> * Acceptable value: 0, 90, 180, 270, * other values will be ignored.<br/> * Default value is 0. */ public void setOrientation(int degrees);
/** * 开始采集, 为异步接口。 */ public void start(); /** * 停止采集, 为同步接口,调用返回后既完全释放Camera实例。 */ public void stop(); /** * 释放其他相关资源 */ public void release();
该模块同时提供了自定义Camera参数的能力,方便开发者的进阶需求。
开发者可以使用该功能实现诸如:手动对焦、zoom、曝光补偿、防闪烁等Android Camera系统API所提供的功能。
/** * Get parameters of current camera.<br/> * Should be called on state {@link #CAMERA_STATE_PREVIEWING}. * * @return Camera parameters instance or null on invalid state. */ public Camera.Parameters getCameraParameters(); /** * Set new parameters to current camera.<br/> * Should be called on state {@link #CAMERA_STATE_PREVIEWING}. * * @param parameters Camera parameters to be set. * @return true on success, false otherwise. */ public boolean setCameraParameters(Camera.Parameters parameters); /** * Starts camera auto-focus and registers a callback function to run * when the camera is focused.<br/> * Should be called on state {@link #CAMERA_STATE_PREVIEWING}. * * @param cb the callback to run */ public void autoFocus(Camera.AutoFocusCallback cb); /** * Cancels any auto-focus function in progress.Whether or not auto-focus is currently * in progress,this function will return the focus position to the default. * If the camera does not support auto-focus, this is a no-op.<br/> * Should be called on state {@link #CAMERA_STATE_PREVIEWING}. */ public void cancelAutoFocus();
实现方式:
-
使用getCameraParameters()获取当前Camera的Camera.Parameters;
-
根据需求操作获取的Camera.Parameters;
-
使用setCameraParameters()将更改后的Camera.Parameters设置给Camera实例.
Note
其中CameraCapture的get/setCameraParameters是Android Camera系统API的一个封装,仅仅做了一些异常保护工作,
开发者可以可以参照系统的Camera API来实现自定义功能。
如果将Camera的对焦模式设置为FOCUS_MODE_AUTO,则可以通过mStreamer.getCameraCapture().autoFocus()方法启动对焦过程, 通过mStreamer.getCameraCapture().cancelAutoFocus()方法取消对焦,分别对应于Android Camera对象的autoFocus和 cancelAutoFocus方法。