blob: 9e3482c916db252225c8cfaafd9e0ad277ba5a40 [file] [log] [blame]
Igor Murashkine302ee32012-11-05 11:14:49 -08001/*
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
17#include <gtest/gtest.h>
18
19#define LOG_TAG "CameraFrameTest"
20//#define LOG_NDEBUG 0
21#include <utils/Log.h>
22
23#include "hardware/hardware.h"
24#include "hardware/camera2.h"
25
26#include "Camera2Device.h"
27#include "utils/StrongPointer.h"
28
29#include <gui/CpuConsumer.h>
30#include <gui/SurfaceTextureClient.h>
31
32#include <unistd.h>
33
34#include "CameraStreamFixture.h"
35
36#define CAMERA_FRAME_TIMEOUT 1000000000 //nsecs (1 secs)
37#define CAMERA_HEAP_COUNT 2 //HALBUG: 1 means registerBuffers fails
38#define CAMERA_FRAME_DEBUGGING 0
39
40using namespace android;
41using namespace android::camera2;
42
43namespace android {
44namespace camera2 {
45namespace tests {
46
47static CameraStreamParams STREAM_PARAMETERS = {
48 /*mCameraId*/ 0,
49 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP,
50 /*mHeapCount*/ CAMERA_HEAP_COUNT
51};
52
53class CameraFrameTest
54 : public ::testing::TestWithParam<int>,
55 public CameraStreamFixture {
56
57public:
58 CameraFrameTest() : CameraStreamFixture(STREAM_PARAMETERS) {
59 if (!HasFatalFailure()) {
60 CreateStream();
61 }
62 }
63
64 ~CameraFrameTest() {
65 if (mDevice.get()) {
66 mDevice->waitUntilDrained();
67 }
68 DeleteStream();
69 }
70
71 virtual void SetUp() {
72 }
73 virtual void TearDown() {
74 }
75
76protected:
77
78};
79
80TEST_P(CameraFrameTest, GetFrame) {
81
82 if (HasFatalFailure()) {
83 return;
84 }
85
86 /* Submit a PREVIEW type request, then wait until we get the frame back */
87 CameraMetadata previewRequest;
88 ASSERT_EQ(OK, mDevice->createDefaultRequest(CAMERA2_TEMPLATE_PREVIEW,
89 &previewRequest));
90 {
91 Vector<uint8_t> outputStreamIds;
92 outputStreamIds.push(mStreamId);
93 ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS,
94 outputStreamIds));
95 if (CAMERA_FRAME_DEBUGGING) {
96 int frameCount = 0;
97 ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_FRAME_COUNT,
98 &frameCount, 1));
99 }
100 }
101
102 if (CAMERA_FRAME_DEBUGGING) {
103 previewRequest.dump(STDOUT_FILENO);
104 }
105
106 for (int i = 0; i < GetParam(); ++i) {
107 ALOGV("Submitting capture request");
108 CameraMetadata tmpRequest = previewRequest;
109 ASSERT_EQ(OK, mDevice->capture(tmpRequest));
110 }
111
112 for (int i = 0; i < GetParam(); ++i) {
113 ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT));
114 CameraMetadata frameMetadata;
115 ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata));
116 }
117
118}
119
120//FIXME: dont hardcode stream params, and also test multistream
121INSTANTIATE_TEST_CASE_P(FrameParameterCombinations, CameraFrameTest,
122 testing::Range(1, 10));
123
124
125}
126}
127}
128