下面介绍录像的相关流程——从上层应用到底层实现整个流程,其重点主要是底层的流程。
5.1 上层
对于上层来说,整个流程不难,具体的流程图如下:
另外,在进入预览之后可以进行如下操作:
1、拍照或点击屏幕会走JpegPictureCallback的onPictureTaken方法
2、暂停pauseVideoRecording方法,再次点击暂停会走resumeVideoRecording方法然后会继续updateRecordingTime;
3、中间的按钮会走onShutterButtonClick方法;
4、点击闪光灯按钮 onFlashButtonClicked-----> setFlashMode;
5.2 底层
录像前面的过程主要是MediaRecorder,下面只分析在HAL层的处理流程。
5.2.1 HAL层
hardware/qcom/camera/QCamera2/HAL/QCamera2HWI.cpp
**int **QCamera2HardwareInterface::start_recording(**struct
**camera_device *device)
{
ATRACE_CALL();
**int **ret = NO_ERROR;
QCamera2HardwareInterface *hw =
**reinterpret_cast**<QCamera2HardwareInterface
*>(device->priv);
**if **(!hw) {
ALOGE("NULL camera
device");
**return **BAD_VALUE;
}
CDBG_HIGH("[KPI Perf] %s: E
PROFILE_START_RECORDING", __func__);
hw->lockAPI();
qcamera_api_result_t apiResult;
ret = hw->processAPI(QCAMERA_SM_EVT_START_RECORDING,
NULL);
**if **(ret == NO_ERROR) {
hw->waitAPIResult(QCAMERA_SM_EVT_START_RECORDING, &apiResult);
ret = apiResult.status;
}
hw->unlockAPI();
hw->m_bRecordStarted = **true**;
CDBG_HIGH("[KPI Perf] %s:
X", __func__);
**return **ret;
}
更改了状态机的状态。
**case **QCAMERA_SM_EVT_START_RECORDING:
{
rc =
m_parent->startRecording();
**if **(rc == NO_ERROR) {
// move state to recording
state
m_state =
QCAMERA_SM_STATE_RECORDING;
}
result.status = rc;
result.request_api = evt;
result.result_type =
QCAMERA_API_RESULT_TYPE_DEF;
m_parent->signalAPIResult(&result);
}
**break**;
返回到QCamera2HWI.cpp的startRecording方法。
**int **QCamera2HardwareInterface::startRecording()
{
int32_t rc = NO_ERROR;
CDBG_HIGH("%s: E",
__func__);
**if **(mParameters.getRecordingHintValue()
== **false**) {
CDBG_HIGH("%s: start
recording when hint is false, stop preview first", __func__);
stopPreview();
// Set recording hint to TRUE
mParameters.updateRecordingHintValue(TRUE);
rc = preparePreview();
**if **(rc == NO_ERROR) {
rc =
startChannel(QCAMERA_CH_TYPE_PREVIEW);
}
}
//link meta stream with video
channel if low power mode is enabled.
**if **(mParameters.isLowPowerEnabled())
{
// Find and try to link a
metadata stream from preview channel
QCameraChannel *pMetaChannel =
NULL;
QCameraStream *pMetaStream =
NULL;
QCameraChannel *pVideoChannel =
m_channels[QCAMERA_CH_TYPE_VIDEO];
**if **(m_channels[QCAMERA_CH_TYPE_PREVIEW]
!= NULL) {
pMetaChannel =
m_channels[QCAMERA_CH_TYPE_PREVIEW];
uint32_t streamNum =
pMetaChannel->getNumOfStreams();
QCameraStream *pStream =
NULL;
**for **(uint32_t i = 0
; i < streamNum ; i++ ) {
pStream =
pMetaChannel->getStreamByIndex(i);
**if **((NULL !=
pStream) &&
(CAM_STREAM_TYPE_METADATA
== pStream->getMyType())) {
pMetaStream =
pStream;
**break**;
}
}
}
**if **((NULL !=
pMetaChannel) && (NULL != pMetaStream)) {
rc =
pVideoChannel->linkStream(pMetaChannel, pMetaStream);
**if **(NO_ERROR != rc)
{
CDBG_HIGH("%s :
Metadata stream link failed %d", __func__, rc);
}
}
}
**if **(rc == NO_ERROR) {
rc =
startChannel(QCAMERA_CH_TYPE_VIDEO);
}
#ifdef HAS_MULTIMEDIA_HINTS
**if **(rc == NO_ERROR) {
**if **(m_pPowerModule) {
**if **(m_pPowerModule->powerHint)
{
m_pPowerModule->powerHint(m_pPowerModule, POWER_HINT_VIDEO_ENCODE,
(**void ***)"state=1");
}
}
}
#endif
CDBG_HIGH("%s: X",
__func__);
**return **rc;
}
之后就是添加channel,并且启动,然后设置buff,和数据流,之后在mm-camera-stream中对数据流接收处理,然后保存成文件,逐层向上抛数据。在此不做分析。