blob: 2b5b546ad08b24c306c910ac96476cab50411017 [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>
Mathias Agopiancc501112013-02-14 17:34:35 -080030#include <gui/Surface.h>
Igor Murashkine302ee32012-11-05 11:14:49 -080031
32#include <unistd.h>
33
34#include "CameraStreamFixture.h"
Igor Murashkineab33fc2012-11-06 17:02:54 -080035#include "TestExtensions.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080036
37#define CAMERA_FRAME_TIMEOUT 1000000000 //nsecs (1 secs)
38#define CAMERA_HEAP_COUNT 2 //HALBUG: 1 means registerBuffers fails
39#define CAMERA_FRAME_DEBUGGING 0
40
41using namespace android;
42using namespace android::camera2;
43
44namespace android {
45namespace camera2 {
46namespace tests {
47
48static CameraStreamParams STREAM_PARAMETERS = {
Igor Murashkine302ee32012-11-05 11:14:49 -080049 /*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) {
Igor Murashkineab33fc2012-11-06 17:02:54 -080059 TEST_EXTENSION_FORKING_CONSTRUCTOR;
60
Igor Murashkine302ee32012-11-05 11:14:49 -080061 if (!HasFatalFailure()) {
62 CreateStream();
63 }
64 }
65
66 ~CameraFrameTest() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080067 TEST_EXTENSION_FORKING_DESTRUCTOR;
68
Igor Murashkine302ee32012-11-05 11:14:49 -080069 if (mDevice.get()) {
70 mDevice->waitUntilDrained();
71 }
Igor Murashkine302ee32012-11-05 11:14:49 -080072 }
73
74 virtual void SetUp() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080075 TEST_EXTENSION_FORKING_SET_UP;
Igor Murashkine302ee32012-11-05 11:14:49 -080076 }
77 virtual void TearDown() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080078 TEST_EXTENSION_FORKING_TEAR_DOWN;
Igor Murashkine302ee32012-11-05 11:14:49 -080079 }
80
81protected:
82
83};
84
85TEST_P(CameraFrameTest, GetFrame) {
86
Igor Murashkineab33fc2012-11-06 17:02:54 -080087 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080088
89 /* Submit a PREVIEW type request, then wait until we get the frame back */
90 CameraMetadata previewRequest;
91 ASSERT_EQ(OK, mDevice->createDefaultRequest(CAMERA2_TEMPLATE_PREVIEW,
92 &previewRequest));
93 {
94 Vector<uint8_t> outputStreamIds;
95 outputStreamIds.push(mStreamId);
96 ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS,
97 outputStreamIds));
98 if (CAMERA_FRAME_DEBUGGING) {
99 int frameCount = 0;
100 ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_FRAME_COUNT,
101 &frameCount, 1));
102 }
103 }
104
105 if (CAMERA_FRAME_DEBUGGING) {
106 previewRequest.dump(STDOUT_FILENO);
107 }
108
109 for (int i = 0; i < GetParam(); ++i) {
Igor Murashkinf1b9ae72012-12-07 15:08:35 -0800110 ALOGV("Submitting capture request %d", i);
Igor Murashkine302ee32012-11-05 11:14:49 -0800111 CameraMetadata tmpRequest = previewRequest;
112 ASSERT_EQ(OK, mDevice->capture(tmpRequest));
113 }
114
115 for (int i = 0; i < GetParam(); ++i) {
Igor Murashkinf1b9ae72012-12-07 15:08:35 -0800116 ALOGV("Reading capture request %d", i);
Igor Murashkine302ee32012-11-05 11:14:49 -0800117 ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT));
Igor Murashkin981c9032012-12-18 13:40:32 -0800118
Igor Murashkine302ee32012-11-05 11:14:49 -0800119 CameraMetadata frameMetadata;
120 ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata));
Igor Murashkin981c9032012-12-18 13:40:32 -0800121
122 // wait for buffer to be available
123 ASSERT_EQ(OK, mFrameListener->waitForFrame(CAMERA_FRAME_TIMEOUT));
124 ALOGV("We got the frame now");
125
126 // mark buffer consumed so producer can re-dequeue it
127 CpuConsumer::LockedBuffer imgBuffer;
128 ASSERT_EQ(OK, mCpuConsumer->lockNextBuffer(&imgBuffer));
129 ASSERT_EQ(OK, mCpuConsumer->unlockBuffer(imgBuffer));
Igor Murashkine302ee32012-11-05 11:14:49 -0800130 }
131
132}
133
134//FIXME: dont hardcode stream params, and also test multistream
135INSTANTIATE_TEST_CASE_P(FrameParameterCombinations, CameraFrameTest,
136 testing::Range(1, 10));
137
138
139}
140}
141}
142