blob: d4243abf2a88a1cc2c7145ed93813b7c647eb080 [file] [log] [blame]
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070017#define LOG_TAG "Camera2_test"
18#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070021#include <gtest/gtest.h>
22#include <iostream>
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070023#include <fstream>
24
25#include <utils/Vector.h>
26#include <gui/CpuConsumer.h>
27#include <system/camera_metadata.h>
28
29#include "camera2_utils.h"
30
31namespace android {
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070032
33class Camera2Test: public testing::Test {
34 public:
35 static void SetUpTestCase() {
36 int res;
37
38 hw_module_t *module = NULL;
39 res = hw_get_module(CAMERA_HARDWARE_MODULE_ID,
40 (const hw_module_t **)&module);
41
42 ASSERT_EQ(0, res)
43 << "Failure opening camera hardware module: " << res;
44 ASSERT_TRUE(NULL != module)
45 << "No camera module was set by hw_get_module";
46
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070047 IF_ALOGV() {
48 std::cout << " Camera module name: "
49 << module->name << std::endl;
50 std::cout << " Camera module author: "
51 << module->author << std::endl;
52 std::cout << " Camera module API version: 0x" << std::hex
53 << module->module_api_version << std::endl;
54 std::cout << " Camera module HAL API version: 0x" << std::hex
55 << module->hal_api_version << std::endl;
56 }
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070057
58 int16_t version2_0 = CAMERA_MODULE_API_VERSION_2_0;
59 ASSERT_EQ(version2_0, module->module_api_version)
60 << "Camera module version is 0x"
61 << std::hex << module->module_api_version
62 << ", not 2.0. (0x"
63 << std::hex << CAMERA_MODULE_API_VERSION_2_0 << ")";
64
65 sCameraModule = reinterpret_cast<camera_module_t*>(module);
66
67 sNumCameras = sCameraModule->get_number_of_cameras();
68 ASSERT_LT(0, sNumCameras) << "No camera devices available!";
69
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070070 IF_ALOGV() {
71 std::cout << " Camera device count: " << sNumCameras << std::endl;
72 }
73
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070074 sCameraSupportsHal2 = new bool[sNumCameras];
75
76 for (int i = 0; i < sNumCameras; i++) {
77 camera_info info;
78 res = sCameraModule->get_camera_info(i, &info);
79 ASSERT_EQ(0, res)
80 << "Failure getting camera info for camera " << i;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070081 IF_ALOGV() {
82 std::cout << " Camera device: " << std::dec
83 << i << std::endl;;
84 std::cout << " Facing: " << std::dec
85 << info.facing << std::endl;
86 std::cout << " Orientation: " << std::dec
87 << info.orientation << std::endl;
88 std::cout << " Version: 0x" << std::hex <<
89 info.device_version << std::endl;
90 }
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070091 if (info.device_version >= CAMERA_DEVICE_API_VERSION_2_0) {
92 sCameraSupportsHal2[i] = true;
93 ASSERT_TRUE(NULL != info.static_camera_characteristics);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070094 IF_ALOGV() {
95 std::cout << " Static camera metadata:" << std::endl;
96 dump_camera_metadata(info.static_camera_characteristics,
97 0, 1);
98 }
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070099 } else {
100 sCameraSupportsHal2[i] = false;
101 }
102 }
103 }
104
105 static const camera_module_t *getCameraModule() {
106 return sCameraModule;
107 }
108
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700109 static int getNumCameras() {
110 return sNumCameras;
111 }
112
113 static bool isHal2Supported(int id) {
114 return sCameraSupportsHal2[id];
115 }
116
117 static camera2_device_t *openCameraDevice(int id) {
118 ALOGV("Opening camera %d", id);
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700119 if (NULL == sCameraSupportsHal2) return NULL;
120 if (id >= sNumCameras) return NULL;
121 if (!sCameraSupportsHal2[id]) return NULL;
122
123 hw_device_t *device = NULL;
124 const camera_module_t *cam_module = getCameraModule();
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700125 if (cam_module == NULL) {
126 return NULL;
127 }
128
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700129 char camId[10];
130 int res;
131
132 snprintf(camId, 10, "%d", id);
133 res = cam_module->common.methods->open(
134 (const hw_module_t*)cam_module,
135 camId,
136 &device);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700137 if (res != NO_ERROR || device == NULL) {
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700138 return NULL;
139 }
140 camera2_device_t *cam_device =
141 reinterpret_cast<camera2_device_t*>(device);
142 return cam_device;
143 }
144
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700145 static status_t configureCameraDevice(camera2_device_t *dev,
146 MetadataQueue &requestQueue,
147 MetadataQueue &frameQueue,
148 NotifierListener &listener) {
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700149
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700150 status_t err;
151
152 err = dev->ops->set_request_queue_src_ops(dev,
153 requestQueue.getToConsumerInterface());
154 if (err != OK) return err;
155
156 requestQueue.setFromConsumerInterface(dev);
157
158 err = dev->ops->set_frame_queue_dst_ops(dev,
159 frameQueue.getToProducerInterface());
160 if (err != OK) return err;
161
162 err = listener.getNotificationsFrom(dev);
163 if (err != OK) return err;
164
165 vendor_tag_query_ops_t *vendor_metadata_tag_ops;
166 err = dev->ops->get_metadata_vendor_tag_ops(dev, &vendor_metadata_tag_ops);
167 if (err != OK) return err;
168
169 err = set_camera_metadata_vendor_tag_ops(vendor_metadata_tag_ops);
170 if (err != OK) return err;
171
172 return OK;
173 }
174
175 static status_t closeCameraDevice(camera2_device_t *cam_dev) {
176 int res;
177 ALOGV("Closing camera %p", cam_dev);
178
179 hw_device_t *dev = reinterpret_cast<hw_device_t *>(cam_dev);
180 res = dev->close(dev);
181 return res;
182 }
183
184 void setUpCamera(int id) {
185 ASSERT_GT(sNumCameras, id);
186 status_t res;
187
188 if (mDevice != NULL) {
189 closeCameraDevice(mDevice);
190 }
191 mDevice = openCameraDevice(id);
192 ASSERT_TRUE(NULL != mDevice) << "Failed to open camera device";
193
194 camera_info info;
195 res = sCameraModule->get_camera_info(id, &info);
196 ASSERT_EQ(OK, res);
197
198 mStaticInfo = info.static_camera_characteristics;
199
200 res = configureCameraDevice(mDevice,
201 mRequests,
202 mFrames,
203 mNotifications);
204 ASSERT_EQ(OK, res) << "Failure to configure camera device";
205
206 }
207
208 void setUpStream(sp<ISurfaceTexture> consumer,
209 int width, int height, int format, int *id) {
210 status_t res;
211
212 StreamAdapter* stream = new StreamAdapter(consumer);
213
214 ALOGV("Creating stream, format 0x%x, %d x %d", format, width, height);
215 res = stream->connectToDevice(mDevice, width, height, format);
216 ASSERT_EQ(NO_ERROR, res) << "Failed to connect to stream: "
217 << strerror(-res);
218 mStreams.push_back(stream);
219
220 *id = stream->getId();
221 }
222
223 void disconnectStream(int id) {
224 status_t res;
225 unsigned int i=0;
226 for (; i < mStreams.size(); i++) {
227 if (mStreams[i]->getId() == id) {
228 res = mStreams[i]->disconnect();
229 ASSERT_EQ(NO_ERROR, res) <<
230 "Failed to disconnect stream " << id;
231 break;
232 }
233 }
234 ASSERT_GT(mStreams.size(), i) << "Stream id not found:" << id;
235 }
236
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700237 void getResolutionList(int32_t format,
238 int32_t **list,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700239 size_t *count) {
240
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700241 status_t res;
Eino-Ville Talvala895ed342012-05-20 17:25:53 -0700242 if (format != CAMERA2_HAL_PIXEL_FORMAT_OPAQUE) {
243 camera_metadata_entry_t availableFormats;
244 res = find_camera_metadata_entry(mStaticInfo,
245 ANDROID_SCALER_AVAILABLE_FORMATS,
246 &availableFormats);
247 ASSERT_EQ(OK, res);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700248
Eino-Ville Talvala895ed342012-05-20 17:25:53 -0700249 uint32_t formatIdx;
250 for (formatIdx=0; formatIdx < availableFormats.count; formatIdx++) {
251 if (availableFormats.data.i32[formatIdx] == format) break;
252 }
253 ASSERT_NE(availableFormats.count, formatIdx)
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700254 << "No support found for format 0x" << std::hex << format;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700255 }
256
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700257 camera_metadata_entry_t availableSizes;
Eino-Ville Talvala895ed342012-05-20 17:25:53 -0700258 if (format == HAL_PIXEL_FORMAT_RAW_SENSOR) {
259 res = find_camera_metadata_entry(mStaticInfo,
260 ANDROID_SCALER_AVAILABLE_RAW_SIZES,
261 &availableSizes);
262 ASSERT_EQ(OK, res);
263 } else {
264 res = find_camera_metadata_entry(mStaticInfo,
265 ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES,
266 &availableSizes);
267 ASSERT_EQ(OK, res);
268 }
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700269
Eino-Ville Talvala895ed342012-05-20 17:25:53 -0700270 *list = availableSizes.data.i32;
271 *count = availableSizes.count;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700272 }
273
274 virtual void SetUp() {
275 const ::testing::TestInfo* const testInfo =
276 ::testing::UnitTest::GetInstance()->current_test_info();
277
278 ALOGV("*** Starting test %s in test case %s", testInfo->name(), testInfo->test_case_name());
279 mDevice = NULL;
280 }
281
282 virtual void TearDown() {
283 for (unsigned int i = 0; i < mStreams.size(); i++) {
284 delete mStreams[i];
285 }
286 if (mDevice != NULL) {
287 closeCameraDevice(mDevice);
288 }
289 }
290
291 camera2_device *mDevice;
292 camera_metadata_t *mStaticInfo;
293
294 MetadataQueue mRequests;
295 MetadataQueue mFrames;
296 NotifierListener mNotifications;
297
298 Vector<StreamAdapter*> mStreams;
299
300 private:
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700301 static camera_module_t *sCameraModule;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700302 static int sNumCameras;
303 static bool *sCameraSupportsHal2;
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700304};
305
306camera_module_t *Camera2Test::sCameraModule = NULL;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700307bool *Camera2Test::sCameraSupportsHal2 = NULL;
308int Camera2Test::sNumCameras = 0;
309
310static const nsecs_t USEC = 1000;
311static const nsecs_t MSEC = 1000*USEC;
312static const nsecs_t SEC = 1000*MSEC;
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700313
314
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700315TEST_F(Camera2Test, OpenClose) {
316 status_t res;
317
318 for (int id = 0; id < getNumCameras(); id++) {
319 if (!isHal2Supported(id)) continue;
320
321 camera2_device_t *d = openCameraDevice(id);
322 ASSERT_TRUE(NULL != d) << "Failed to open camera device";
323
324 res = closeCameraDevice(d);
325 ASSERT_EQ(NO_ERROR, res) << "Failed to close camera device";
326 }
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700327}
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700328
329TEST_F(Camera2Test, Capture1Raw) {
330 status_t res;
331
332 for (int id = 0; id < getNumCameras(); id++) {
333 if (!isHal2Supported(id)) continue;
334
335 ASSERT_NO_FATAL_FAILURE(setUpCamera(id));
336
337 sp<CpuConsumer> rawConsumer = new CpuConsumer(1);
338 sp<FrameWaiter> rawWaiter = new FrameWaiter();
339 rawConsumer->setFrameAvailableListener(rawWaiter);
340
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700341 int32_t *rawResolutions;
342 size_t rawResolutionsCount;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700343
344 int format = HAL_PIXEL_FORMAT_RAW_SENSOR;
345
346 getResolutionList(format,
347 &rawResolutions, &rawResolutionsCount);
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700348 ASSERT_LT((size_t)0, rawResolutionsCount);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700349
350 // Pick first available raw resolution
351 int width = rawResolutions[0];
352 int height = rawResolutions[1];
353
354 int streamId;
355 ASSERT_NO_FATAL_FAILURE(
356 setUpStream(rawConsumer->getProducerInterface(),
357 width, height, format, &streamId) );
358
359 camera_metadata_t *request;
360 request = allocate_camera_metadata(20, 2000);
361
362 uint8_t metadataMode = ANDROID_REQUEST_METADATA_FULL;
363 add_camera_metadata_entry(request,
364 ANDROID_REQUEST_METADATA_MODE,
365 (void**)&metadataMode, 1);
366 uint32_t outputStreams = streamId;
367 add_camera_metadata_entry(request,
368 ANDROID_REQUEST_OUTPUT_STREAMS,
369 (void**)&outputStreams, 1);
370
Eino-Ville Talvala895ed342012-05-20 17:25:53 -0700371 uint64_t exposureTime = 10*MSEC;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700372 add_camera_metadata_entry(request,
373 ANDROID_SENSOR_EXPOSURE_TIME,
374 (void**)&exposureTime, 1);
375 uint64_t frameDuration = 30*MSEC;
376 add_camera_metadata_entry(request,
377 ANDROID_SENSOR_FRAME_DURATION,
378 (void**)&frameDuration, 1);
379 uint32_t sensitivity = 100;
380 add_camera_metadata_entry(request,
381 ANDROID_SENSOR_SENSITIVITY,
382 (void**)&sensitivity, 1);
383
Eino-Ville Talvala895ed342012-05-20 17:25:53 -0700384 uint32_t hourOfDay = 12;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700385 add_camera_metadata_entry(request,
386 0x80000000, // EMULATOR_HOUROFDAY
387 &hourOfDay, 1);
388
389 IF_ALOGV() {
390 std::cout << "Input request: " << std::endl;
391 dump_camera_metadata(request, 0, 1);
392 }
393
394 res = mRequests.enqueue(request);
395 ASSERT_EQ(NO_ERROR, res) << "Can't enqueue request: " << strerror(-res);
396
397 res = mFrames.waitForBuffer(exposureTime + SEC);
398 ASSERT_EQ(NO_ERROR, res) << "No frame to get: " << strerror(-res);
399
400 camera_metadata_t *frame;
401 res = mFrames.dequeue(&frame);
402 ASSERT_EQ(NO_ERROR, res);
403 ASSERT_TRUE(frame != NULL);
404
405 IF_ALOGV() {
406 std::cout << "Output frame:" << std::endl;
407 dump_camera_metadata(frame, 0, 1);
408 }
409
410 res = rawWaiter->waitForFrame(exposureTime + SEC);
411 ASSERT_EQ(NO_ERROR, res);
412
413 CpuConsumer::LockedBuffer buffer;
414 res = rawConsumer->lockNextBuffer(&buffer);
415 ASSERT_EQ(NO_ERROR, res);
416
417 IF_ALOGV() {
418 const char *dumpname =
419 "/data/local/tmp/camera2_test-capture1raw-dump.raw";
420 ALOGV("Dumping raw buffer to %s", dumpname);
421 // Write to file
422 std::ofstream rawFile(dumpname);
423 for (unsigned int y = 0; y < buffer.height; y++) {
424 rawFile.write((const char *)(buffer.data + y * buffer.stride * 2),
425 buffer.width * 2);
426 }
427 rawFile.close();
428 }
429
430 res = rawConsumer->unlockBuffer(buffer);
431 ASSERT_EQ(NO_ERROR, res);
432
433 ASSERT_NO_FATAL_FAILURE(disconnectStream(streamId));
434
435 res = closeCameraDevice(mDevice);
436 ASSERT_EQ(NO_ERROR, res) << "Failed to close camera device";
437
438 }
439}
440
441TEST_F(Camera2Test, CaptureBurstRaw) {
442 status_t res;
443
444 for (int id = 0; id < getNumCameras(); id++) {
445 if (!isHal2Supported(id)) continue;
446
447 ASSERT_NO_FATAL_FAILURE(setUpCamera(id));
448
449 sp<CpuConsumer> rawConsumer = new CpuConsumer(1);
450 sp<FrameWaiter> rawWaiter = new FrameWaiter();
451 rawConsumer->setFrameAvailableListener(rawWaiter);
452
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700453 int32_t *rawResolutions;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700454 size_t rawResolutionsCount;
455
456 int format = HAL_PIXEL_FORMAT_RAW_SENSOR;
457
458 getResolutionList(format,
459 &rawResolutions, &rawResolutionsCount);
460 ASSERT_LT((uint32_t)0, rawResolutionsCount);
461
462 // Pick first available raw resolution
463 int width = rawResolutions[0];
464 int height = rawResolutions[1];
465
466 int streamId;
467 ASSERT_NO_FATAL_FAILURE(
468 setUpStream(rawConsumer->getProducerInterface(),
469 width, height, format, &streamId) );
470
471 camera_metadata_t *request;
472 request = allocate_camera_metadata(20, 2000);
473
474 uint8_t metadataMode = ANDROID_REQUEST_METADATA_FULL;
475 add_camera_metadata_entry(request,
476 ANDROID_REQUEST_METADATA_MODE,
477 (void**)&metadataMode, 1);
478 uint32_t outputStreams = streamId;
479 add_camera_metadata_entry(request,
480 ANDROID_REQUEST_OUTPUT_STREAMS,
481 (void**)&outputStreams, 1);
482
483 uint64_t frameDuration = 30*MSEC;
484 add_camera_metadata_entry(request,
485 ANDROID_SENSOR_FRAME_DURATION,
486 (void**)&frameDuration, 1);
487 uint32_t sensitivity = 100;
488 add_camera_metadata_entry(request,
489 ANDROID_SENSOR_SENSITIVITY,
490 (void**)&sensitivity, 1);
491
492 uint32_t hourOfDay = 12;
493 add_camera_metadata_entry(request,
494 0x80000000, // EMULATOR_HOUROFDAY
495 &hourOfDay, 1);
496
497 IF_ALOGV() {
498 std::cout << "Input request template: " << std::endl;
499 dump_camera_metadata(request, 0, 1);
500 }
501
502 int numCaptures = 10;
503
504 // Enqueue numCaptures requests with increasing exposure time
505
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700506 uint64_t exposureTime = 100 * USEC;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700507 for (int reqCount = 0; reqCount < numCaptures; reqCount++ ) {
508 camera_metadata_t *req;
509 req = allocate_camera_metadata(20, 2000);
510 append_camera_metadata(req, request);
511
512 add_camera_metadata_entry(req,
513 ANDROID_SENSOR_EXPOSURE_TIME,
514 (void**)&exposureTime, 1);
515 exposureTime *= 2;
516
517 res = mRequests.enqueue(req);
518 ASSERT_EQ(NO_ERROR, res) << "Can't enqueue request: "
519 << strerror(-res);
520 }
521
522 // Get frames and image buffers one by one
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700523 uint64_t expectedExposureTime = 100 * USEC;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700524 for (int frameCount = 0; frameCount < 10; frameCount++) {
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700525 res = mFrames.waitForBuffer(SEC + expectedExposureTime);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700526 ASSERT_EQ(NO_ERROR, res) << "No frame to get: " << strerror(-res);
527
528 camera_metadata_t *frame;
529 res = mFrames.dequeue(&frame);
530 ASSERT_EQ(NO_ERROR, res);
531 ASSERT_TRUE(frame != NULL);
532
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700533 camera_metadata_entry_t frameNumber;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700534 res = find_camera_metadata_entry(frame,
535 ANDROID_REQUEST_FRAME_COUNT,
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700536 &frameNumber);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700537 ASSERT_EQ(NO_ERROR, res);
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700538 ASSERT_EQ(frameCount, *frameNumber.data.i32);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700539
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700540 res = rawWaiter->waitForFrame(SEC + expectedExposureTime);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700541 ASSERT_EQ(NO_ERROR, res) <<
542 "Never got raw data for capture " << frameCount;
543
544 CpuConsumer::LockedBuffer buffer;
545 res = rawConsumer->lockNextBuffer(&buffer);
546 ASSERT_EQ(NO_ERROR, res);
547
548 IF_ALOGV() {
549 char dumpname[60];
550 snprintf(dumpname, 60,
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700551 "/data/local/tmp/camera2_test-"
552 "captureBurstRaw-dump_%d.raw",
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700553 frameCount);
554 ALOGV("Dumping raw buffer to %s", dumpname);
555 // Write to file
556 std::ofstream rawFile(dumpname);
557 for (unsigned int y = 0; y < buffer.height; y++) {
558 rawFile.write(
559 (const char *)(buffer.data + y * buffer.stride * 2),
560 buffer.width * 2);
561 }
562 rawFile.close();
563 }
564
565 res = rawConsumer->unlockBuffer(buffer);
566 ASSERT_EQ(NO_ERROR, res);
Eino-Ville Talvalae6a3c3c2012-05-11 16:18:42 -0700567
568 expectedExposureTime *= 2;
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700569 }
570 }
571}
572
Eino-Ville Talvala6adfd6b2012-05-14 15:25:27 -0700573TEST_F(Camera2Test, ConstructDefaultRequests) {
574 status_t res;
575
576 for (int id = 0; id < getNumCameras(); id++) {
577 if (!isHal2Supported(id)) continue;
578
579 ASSERT_NO_FATAL_FAILURE(setUpCamera(id));
580
581 for (int i = CAMERA2_TEMPLATE_PREVIEW; i < CAMERA2_TEMPLATE_COUNT;
582 i++) {
583 camera_metadata_t *request = NULL;
584 res = mDevice->ops->construct_default_request(mDevice,
585 i,
586 &request);
587 EXPECT_EQ(NO_ERROR, res) <<
588 "Unable to construct request from template type %d", i;
589 EXPECT_TRUE(request != NULL);
590 EXPECT_LT((size_t)0, get_camera_metadata_entry_count(request));
591 EXPECT_LT((size_t)0, get_camera_metadata_data_count(request));
592
593 IF_ALOGV() {
594 std::cout << " ** Template type " << i << ":"<<std::endl;
595 dump_camera_metadata(request, 0, 2);
596 }
597
598 free_camera_metadata(request);
599 }
600 }
601}
602
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700603} // namespace android