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 | #include <gui/CpuConsumer.h> |
| 20 | #include <gui/SurfaceTextureClient.h> |
| 21 | |
| 22 | #include "CameraModuleFixture.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace camera2 { |
| 26 | namespace tests { |
| 27 | |
| 28 | struct CameraStreamParams { |
| 29 | int mCameraId; |
| 30 | int mFormat; |
| 31 | int mHeapCount; |
| 32 | }; |
| 33 | |
| 34 | class CameraStreamFixture |
| 35 | : public CameraModuleFixture</*InfoQuirk*/true> { |
| 36 | |
| 37 | public: |
| 38 | CameraStreamFixture(CameraStreamParams p) |
| 39 | : CameraModuleFixture(p.mCameraId) { |
| 40 | mParam = p; |
| 41 | |
| 42 | SetUp(); |
| 43 | } |
| 44 | |
| 45 | ~CameraStreamFixture() { |
| 46 | TearDown(); |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | |
| 51 | void SetUp() { |
| 52 | CameraStreamParams p = mParam; |
| 53 | sp<Camera2Device> device = mDevice; |
| 54 | |
| 55 | /* use an arbitrary w,h */ |
| 56 | { |
| 57 | const int tag = ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES; |
| 58 | |
| 59 | const android::camera2::CameraMetadata& staticInfo = device->info(); |
| 60 | camera_metadata_ro_entry entry = staticInfo.find(tag); |
| 61 | ASSERT_NE(0u, entry.count) |
| 62 | << "Missing tag android.scaler.availableProcessedSizes"; |
| 63 | |
| 64 | ASSERT_LE(2u, entry.count); |
| 65 | /* this seems like it would always be the smallest w,h |
| 66 | but we actually make no contract that it's sorted asc */; |
| 67 | mWidth = entry.data.i32[0]; |
| 68 | mHeight = entry.data.i32[1]; |
| 69 | } |
| 70 | } |
| 71 | void TearDown() { |
| 72 | } |
| 73 | |
| 74 | protected: |
| 75 | |
| 76 | void CreateStream() { |
| 77 | sp<Camera2Device> device = mDevice; |
| 78 | CameraStreamParams p = mParam; |
| 79 | |
| 80 | mCpuConsumer = new CpuConsumer(p.mHeapCount); |
| 81 | mCpuConsumer->setName(String8("CameraStreamTest::mCpuConsumer")); |
| 82 | |
| 83 | mNativeWindow = new SurfaceTextureClient( |
| 84 | mCpuConsumer->getProducerInterface()); |
| 85 | |
| 86 | ASSERT_EQ(OK, |
| 87 | device->createStream(mNativeWindow, |
| 88 | mWidth, mHeight, p.mFormat, /*size (for jpegs)*/0, |
| 89 | &mStreamId)); |
| 90 | |
| 91 | ASSERT_NE(-1, mStreamId); |
| 92 | } |
| 93 | |
| 94 | void DeleteStream() { |
| 95 | ASSERT_EQ(OK, mDevice->deleteStream(mStreamId)); |
| 96 | } |
| 97 | |
| 98 | /* consider factoring out this common code into |
| 99 | a CameraStreamFixture<T>, e.g. |
| 100 | class CameraStreamTest : TestWithParam<CameraStreamParameters>, |
| 101 | CameraStreamFixture<CameraStreamParameters> |
| 102 | to make it easier for other classes to not duplicate the params |
| 103 | */ |
| 104 | |
| 105 | int mWidth; |
| 106 | int mHeight; |
| 107 | |
| 108 | int mStreamId; |
| 109 | android::sp<CpuConsumer> mCpuConsumer; |
| 110 | android::sp<ANativeWindow> mNativeWindow; |
| 111 | |
| 112 | private: |
| 113 | CameraStreamParams mParam; |
| 114 | }; |
| 115 | |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |