Skip to content

Commit 851a14e

Browse files
Iliyan MalchevAndroid (Google) Code Review
authored andcommitted
Merge "Add initialize method to CameraHardwareInterface"
2 parents d8b505d + 7b6da3c commit 851a14e

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

services/camera/libcameraservice/CameraHardwareInterface.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,33 @@ typedef void (*data_callback_timestamp)(nsecs_t timestamp,
8080

8181
class CameraHardwareInterface : public virtual RefBase {
8282
public:
83-
CameraHardwareInterface(hw_module_t *module, const char *name)
83+
CameraHardwareInterface(const char *name)
8484
{
8585
mDevice = 0;
8686
mName = name;
87-
LOGI("Opening camera %s, this %p", name, this);
88-
int rc = module->methods->open(module, name,
89-
(hw_device_t **)&mDevice);
90-
if (rc != OK)
91-
LOGE("Could not open camera %s: %d", name, rc);
92-
initHalPreviewWindow();
9387
}
9488

9589
~CameraHardwareInterface()
9690
{
9791
LOGI("Destroying camera %s", mName.string());
98-
int rc = mDevice->common.close(&mDevice->common);
99-
if (rc != OK)
100-
LOGE("Could not close camera %s: %d", mName.string(), rc);
92+
if(mDevice) {
93+
int rc = mDevice->common.close(&mDevice->common);
94+
if (rc != OK)
95+
LOGE("Could not close camera %s: %d", mName.string(), rc);
96+
}
97+
}
98+
99+
status_t initialize(hw_module_t *module)
100+
{
101+
LOGI("Opening camera %s", mName.string());
102+
int rc = module->methods->open(module, mName.string(),
103+
(hw_device_t **)&mDevice);
104+
if (rc != OK) {
105+
LOGE("Could not open camera %s: %d", mName.string(), rc);
106+
return rc;
107+
}
108+
initHalPreviewWindow();
109+
return rc;
101110
}
102111

103112
/** Set the ANativeWindow to which preview frames are sent */

services/camera/libcameraservice/CameraService.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ status_t CameraService::getCameraInfo(int cameraId,
133133
sp<ICamera> CameraService::connect(
134134
const sp<ICameraClient>& cameraClient, int cameraId) {
135135
int callingPid = getCallingPid();
136+
sp<CameraHardwareInterface> hardware = NULL;
137+
136138
LOG1("CameraService::connect E (pid %d, id %d)", callingPid, cameraId);
137139

138140
if (!mModule) {
@@ -187,10 +189,13 @@ sp<ICamera> CameraService::connect(
187189
char camera_device_name[10];
188190
snprintf(camera_device_name, sizeof(camera_device_name), "%d", cameraId);
189191

190-
client = new Client(this, cameraClient,
191-
new CameraHardwareInterface(&mModule->common,
192-
camera_device_name),
193-
cameraId, info.facing, callingPid);
192+
hardware = new CameraHardwareInterface(camera_device_name);
193+
if (hardware->initialize(&mModule->common) != OK) {
194+
hardware.clear();
195+
return NULL;
196+
}
197+
198+
client = new Client(this, cameraClient, hardware, cameraId, info.facing, callingPid);
194199
mClient[cameraId] = client;
195200
LOG1("CameraService::connect X");
196201
return client;

0 commit comments

Comments
 (0)