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 | |
| 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" |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 35 | #include "TestExtensions.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 36 | |
| 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 | |
| 41 | using namespace android; |
| 42 | using namespace android::camera2; |
| 43 | |
| 44 | namespace android { |
| 45 | namespace camera2 { |
| 46 | namespace tests { |
| 47 | |
| 48 | static CameraStreamParams STREAM_PARAMETERS = { |
| 49 | /*mCameraId*/ 0, |
| 50 | /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, |
| 51 | /*mHeapCount*/ CAMERA_HEAP_COUNT |
| 52 | }; |
| 53 | |
| 54 | class CameraFrameTest |
| 55 | : public ::testing::TestWithParam<int>, |
| 56 | public CameraStreamFixture { |
| 57 | |
| 58 | public: |
| 59 | CameraFrameTest() : CameraStreamFixture(STREAM_PARAMETERS) { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 60 | TEST_EXTENSION_FORKING_CONSTRUCTOR; |
| 61 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 62 | if (!HasFatalFailure()) { |
| 63 | CreateStream(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | ~CameraFrameTest() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 68 | TEST_EXTENSION_FORKING_DESTRUCTOR; |
| 69 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 70 | if (mDevice.get()) { |
| 71 | mDevice->waitUntilDrained(); |
| 72 | } |
| 73 | DeleteStream(); |
| 74 | } |
| 75 | |
| 76 | virtual void SetUp() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 77 | TEST_EXTENSION_FORKING_SET_UP; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 78 | } |
| 79 | virtual void TearDown() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 80 | TEST_EXTENSION_FORKING_TEAR_DOWN; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | protected: |
| 84 | |
| 85 | }; |
| 86 | |
| 87 | TEST_P(CameraFrameTest, GetFrame) { |
| 88 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 89 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 90 | |
| 91 | /* Submit a PREVIEW type request, then wait until we get the frame back */ |
| 92 | CameraMetadata previewRequest; |
| 93 | ASSERT_EQ(OK, mDevice->createDefaultRequest(CAMERA2_TEMPLATE_PREVIEW, |
| 94 | &previewRequest)); |
| 95 | { |
| 96 | Vector<uint8_t> outputStreamIds; |
| 97 | outputStreamIds.push(mStreamId); |
| 98 | ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_OUTPUT_STREAMS, |
| 99 | outputStreamIds)); |
| 100 | if (CAMERA_FRAME_DEBUGGING) { |
| 101 | int frameCount = 0; |
| 102 | ASSERT_EQ(OK, previewRequest.update(ANDROID_REQUEST_FRAME_COUNT, |
| 103 | &frameCount, 1)); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if (CAMERA_FRAME_DEBUGGING) { |
| 108 | previewRequest.dump(STDOUT_FILENO); |
| 109 | } |
| 110 | |
| 111 | for (int i = 0; i < GetParam(); ++i) { |
| 112 | ALOGV("Submitting capture request"); |
| 113 | CameraMetadata tmpRequest = previewRequest; |
| 114 | ASSERT_EQ(OK, mDevice->capture(tmpRequest)); |
| 115 | } |
| 116 | |
| 117 | for (int i = 0; i < GetParam(); ++i) { |
| 118 | ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT)); |
| 119 | CameraMetadata frameMetadata; |
| 120 | ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata)); |
| 121 | } |
| 122 | |
| 123 | } |
| 124 | |
| 125 | //FIXME: dont hardcode stream params, and also test multistream |
| 126 | INSTANTIATE_TEST_CASE_P(FrameParameterCombinations, CameraFrameTest, |
| 127 | testing::Range(1, 10)); |
| 128 | |
| 129 | |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |