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 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 17 | #ifndef __ANDROID_HAL_CAMERA2_TESTS_STREAM_FIXTURE__ |
| 18 | #define __ANDROID_HAL_CAMERA2_TESTS_STREAM_FIXTURE__ |
| 19 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 20 | #include <gtest/gtest.h> |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 21 | #include <iostream> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 22 | |
| 23 | #include <gui/CpuConsumer.h> |
| 24 | #include <gui/SurfaceTextureClient.h> |
| 25 | |
| 26 | #include "CameraModuleFixture.h" |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 27 | #include "TestExtensions.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace camera2 { |
| 31 | namespace tests { |
| 32 | |
| 33 | struct CameraStreamParams { |
| 34 | int mCameraId; |
| 35 | int mFormat; |
| 36 | int mHeapCount; |
| 37 | }; |
| 38 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 39 | inline void PrintTo(const CameraStreamParams& p, ::std::ostream* os) { |
| 40 | *os << "{ "; |
| 41 | *os << "CameraID: " << p.mCameraId << ", "; |
| 42 | *os << "Format: " << p.mCameraId << ", "; |
| 43 | *os << "HeapCount: " << p.mCameraId; |
| 44 | *os << " }"; |
| 45 | } |
| 46 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 47 | class CameraStreamFixture |
| 48 | : public CameraModuleFixture</*InfoQuirk*/true> { |
| 49 | |
| 50 | public: |
| 51 | CameraStreamFixture(CameraStreamParams p) |
| 52 | : CameraModuleFixture(p.mCameraId) { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 53 | TEST_EXTENSION_FORKING_CONSTRUCTOR; |
| 54 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 55 | mParam = p; |
| 56 | |
| 57 | SetUp(); |
| 58 | } |
| 59 | |
| 60 | ~CameraStreamFixture() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 61 | TEST_EXTENSION_FORKING_DESTRUCTOR; |
| 62 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 63 | TearDown(); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | |
| 68 | void SetUp() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 69 | TEST_EXTENSION_FORKING_SET_UP; |
| 70 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 71 | CameraStreamParams p = mParam; |
| 72 | sp<Camera2Device> device = mDevice; |
| 73 | |
| 74 | /* use an arbitrary w,h */ |
| 75 | { |
| 76 | const int tag = ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES; |
| 77 | |
| 78 | const android::camera2::CameraMetadata& staticInfo = device->info(); |
| 79 | camera_metadata_ro_entry entry = staticInfo.find(tag); |
| 80 | ASSERT_NE(0u, entry.count) |
| 81 | << "Missing tag android.scaler.availableProcessedSizes"; |
| 82 | |
| 83 | ASSERT_LE(2u, entry.count); |
| 84 | /* this seems like it would always be the smallest w,h |
| 85 | but we actually make no contract that it's sorted asc */; |
| 86 | mWidth = entry.data.i32[0]; |
| 87 | mHeight = entry.data.i32[1]; |
| 88 | } |
| 89 | } |
| 90 | void TearDown() { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 91 | TEST_EXTENSION_FORKING_TEAR_DOWN; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | protected: |
| 95 | |
| 96 | void CreateStream() { |
| 97 | sp<Camera2Device> device = mDevice; |
| 98 | CameraStreamParams p = mParam; |
| 99 | |
| 100 | mCpuConsumer = new CpuConsumer(p.mHeapCount); |
| 101 | mCpuConsumer->setName(String8("CameraStreamTest::mCpuConsumer")); |
| 102 | |
| 103 | mNativeWindow = new SurfaceTextureClient( |
| 104 | mCpuConsumer->getProducerInterface()); |
| 105 | |
| 106 | ASSERT_EQ(OK, |
| 107 | device->createStream(mNativeWindow, |
| 108 | mWidth, mHeight, p.mFormat, /*size (for jpegs)*/0, |
| 109 | &mStreamId)); |
| 110 | |
| 111 | ASSERT_NE(-1, mStreamId); |
| 112 | } |
| 113 | |
| 114 | void DeleteStream() { |
| 115 | ASSERT_EQ(OK, mDevice->deleteStream(mStreamId)); |
| 116 | } |
| 117 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 118 | int mWidth; |
| 119 | int mHeight; |
| 120 | |
| 121 | int mStreamId; |
| 122 | android::sp<CpuConsumer> mCpuConsumer; |
| 123 | android::sp<ANativeWindow> mNativeWindow; |
| 124 | |
| 125 | private: |
| 126 | CameraStreamParams mParam; |
| 127 | }; |
| 128 | |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame^] | 133 | #endif |