Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Eino-Ville Talvala | 48bb03f | 2013-07-25 17:09:14 -0700 | [diff] [blame] | 26 | #include <common/CameraDeviceBase.h> |
| 27 | #include <utils/StrongPointer.h> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 28 | #include <gui/CpuConsumer.h> |
Mathias Agopian | cc50111 | 2013-02-14 17:34:35 -0800 | [diff] [blame] | 29 | #include <gui/Surface.h> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 30 | |
| 31 | #include <unistd.h> |
| 32 | |
| 33 | #include "CameraStreamFixture.h" |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 34 | #include "TestExtensions.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 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 | |
| 40 | using namespace android; |
| 41 | using namespace android::camera2; |
| 42 | |
| 43 | namespace android { |
| 44 | namespace camera2 { |
| 45 | namespace tests { |
| 46 | |
| 47 | static CameraStreamParams STREAM_PARAMETERS = { |
Eino-Ville Talvala | 4c543a1 | 2013-06-25 18:12:19 -0700 | [diff] [blame] | 48 | /*mFormat*/ CAMERA_STREAM_AUTO_CPU_FORMAT, |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 49 | /*mHeapCount*/ CAMERA_HEAP_COUNT |
| 50 | }; |
| 51 | |
| 52 | class CameraFrameTest |
| 53 | : public ::testing::TestWithParam<int>, |
| 54 | public CameraStreamFixture { |
| 55 | |
| 56 | public: |
| 57 | CameraFrameTest() : CameraStreamFixture(STREAM_PARAMETERS) { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 58 | TEST_EXTENSION_FORKING_CONSTRUCTOR; |
| 59 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 60 | if (!HasFatalFailure()) { |
| 61 | CreateStream(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | ~CameraFrameTest() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 66 | TEST_EXTENSION_FORKING_DESTRUCTOR; |
| 67 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 68 | if (mDevice.get()) { |
| 69 | mDevice->waitUntilDrained(); |
| 70 | } |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | virtual void SetUp() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 74 | TEST_EXTENSION_FORKING_SET_UP; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 75 | } |
| 76 | virtual void TearDown() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 77 | TEST_EXTENSION_FORKING_TEAR_DOWN; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | protected: |
| 81 | |
| 82 | }; |
| 83 | |
| 84 | TEST_P(CameraFrameTest, GetFrame) { |
| 85 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 86 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 87 | |
| 88 | /* Submit a PREVIEW type request, then wait until we get the frame back */ |
| 89 | CameraMetadata previewRequest; |
| 90 | ASSERT_EQ(OK, mDevice->createDefaultRequest(CAMERA2_TEMPLATE_PREVIEW, |
| 91 | &previewRequest)); |
| 92 | { |
| 93 | Vector<uint8_t> outputStreamIds; |
| 94 | outputStreamIds.push(mStreamId); |
| 95 | ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, |
| 96 | outputStreamIds)); |
| 97 | if (CAMERA_FRAME_DEBUGGING) { |
| 98 | int frameCount = 0; |
| 99 | ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_FRAME_COUNT, |
| 100 | &frameCount, 1)); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if (CAMERA_FRAME_DEBUGGING) { |
| 105 | previewRequest.dump(STDOUT_FILENO); |
| 106 | } |
| 107 | |
| 108 | for (int i = 0; i < GetParam(); ++i) { |
Igor Murashkin | f1b9ae7 | 2012-12-07 15:08:35 -0800 | [diff] [blame] | 109 | ALOGV("Submitting capture request %d", i); |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 110 | CameraMetadata tmpRequest = previewRequest; |
| 111 | ASSERT_EQ(OK, mDevice->capture(tmpRequest)); |
| 112 | } |
| 113 | |
| 114 | for (int i = 0; i < GetParam(); ++i) { |
Igor Murashkin | f1b9ae7 | 2012-12-07 15:08:35 -0800 | [diff] [blame] | 115 | ALOGV("Reading capture request %d", i); |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 116 | ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT)); |
Igor Murashkin | 981c903 | 2012-12-18 13:40:32 -0800 | [diff] [blame] | 117 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 118 | CameraMetadata frameMetadata; |
| 119 | ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata)); |
Igor Murashkin | 981c903 | 2012-12-18 13:40:32 -0800 | [diff] [blame] | 120 | |
| 121 | // wait for buffer to be available |
| 122 | ASSERT_EQ(OK, mFrameListener->waitForFrame(CAMERA_FRAME_TIMEOUT)); |
| 123 | ALOGV("We got the frame now"); |
| 124 | |
| 125 | // mark buffer consumed so producer can re-dequeue it |
| 126 | CpuConsumer::LockedBuffer imgBuffer; |
| 127 | ASSERT_EQ(OK, mCpuConsumer->lockNextBuffer(&imgBuffer)); |
| 128 | ASSERT_EQ(OK, mCpuConsumer->unlockBuffer(imgBuffer)); |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | } |
| 132 | |
| 133 | //FIXME: dont hardcode stream params, and also test multistream |
| 134 | INSTANTIATE_TEST_CASE_P(FrameParameterCombinations, CameraFrameTest, |
| 135 | testing::Range(1, 10)); |
| 136 | |
| 137 | |
| 138 | } |
| 139 | } |
| 140 | } |