USB camera 的 HAL 层
/** Copyright (C) 2010 SpectraCore Technologies
** Author : Venkat Raju
** Email : [email protected]
** Initial Code : http://code.google.com/p/android-m912/downloads/detail?name=v4l2_camera_v2.patch
**
** Copyright (C) 2009 0xlab.org - http://0xlab.org/
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#define LOG_TAG "CameraHardwareStub"
#include <utils/Log.h>
#include "CameraHardware.h"
#include <utils/threads.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "converter.h"
#define MIN_WIDTH 640
#define MIN_HEIGHT 480 // 预设的分辨率
namespace android {
CameraHardwareStub::CameraHardwareStub(int cameraId) //这个叫构造函数,与自己类同名的。
: mParameters(),
mPreviewHeap(0), //这些叫成员变量初始化。
mRawHeap(0),
mFakeCamera(0),
mPreviewFrameSize(0),
mNotifyCb(0),
mDataCb(0),
mDataCbTimestamp(0),
mCallbackCookie(0),
mMsgEnabled(0),
mRecordRunning(false)
// mCurrentPreviewFrame(0)
{
initDefaultParameters();
if (cameraId == 0) //支持2个摄像头
strcpy(mVideoDevice, "/dev/video0");
else
strcpy(mVideoDevice, "/dev/video1");
}
void CameraHardwareStub::initDefaultParameters()
{
CameraParameters p;
p.setPreviewSize(MIN_WIDTH, MIN_HEIGHT);
p.setPreviewFrameRate(30); //帧率30,即一秒钟播放30帧,1/30秒播放一帧
p.setPreviewFormat(CameraParameters::PIXEL_FORMAT_RGB565);
//preview 图像格式RGB565. 即RRRRRGGGGGGBBBBB 18位宽.
p.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES,
"1600x1200,1024x768,640x480,352x288,320x240");
p.setPictureSize(MIN_WIDTH, MIN_HEIGHT);
p.setPictureFormat(CameraParameters::PIXEL_FORMAT_JPEG);
// picture 图像格式 jpeg。
p.set(CameraParameters::KEY_JPEG_QUALITY, "100"); // max quality //图像质量100.
p.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT,
CameraParameters::PIXEL_FORMAT_YUV420SP); //视频录像格式 YUV420SP.