blob: d4ba7643f8bb3ce58d455c0cb67cbd2c6b1bffaf [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
Igor Murashkineab33fc2012-11-06 17:02:54 -080017#ifndef __ANDROID_HAL_CAMERA2_TESTS_STREAM_FIXTURE__
18#define __ANDROID_HAL_CAMERA2_TESTS_STREAM_FIXTURE__
19
Igor Murashkine302ee32012-11-05 11:14:49 -080020#include <gtest/gtest.h>
Igor Murashkineab33fc2012-11-06 17:02:54 -080021#include <iostream>
Igor Murashkine302ee32012-11-05 11:14:49 -080022
23#include <gui/CpuConsumer.h>
24#include <gui/SurfaceTextureClient.h>
25
26#include "CameraModuleFixture.h"
Igor Murashkineab33fc2012-11-06 17:02:54 -080027#include "TestExtensions.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080028
29namespace android {
30namespace camera2 {
31namespace tests {
32
33struct CameraStreamParams {
34 int mCameraId;
35 int mFormat;
36 int mHeapCount;
37};
38
Igor Murashkineab33fc2012-11-06 17:02:54 -080039inline 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 Murashkine302ee32012-11-05 11:14:49 -080047class CameraStreamFixture
48 : public CameraModuleFixture</*InfoQuirk*/true> {
49
50public:
51 CameraStreamFixture(CameraStreamParams p)
52 : CameraModuleFixture(p.mCameraId) {
Igor Murashkineab33fc2012-11-06 17:02:54 -080053 TEST_EXTENSION_FORKING_CONSTRUCTOR;
54
Igor Murashkine302ee32012-11-05 11:14:49 -080055 mParam = p;
56
57 SetUp();
58 }
59
60 ~CameraStreamFixture() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080061 TEST_EXTENSION_FORKING_DESTRUCTOR;
62
Igor Murashkine302ee32012-11-05 11:14:49 -080063 TearDown();
64 }
65
66private:
67
68 void SetUp() {
Igor Murashkineab33fc2012-11-06 17:02:54 -080069 TEST_EXTENSION_FORKING_SET_UP;
70
Igor Murashkine302ee32012-11-05 11:14:49 -080071 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 Murashkineab33fc2012-11-06 17:02:54 -080091 TEST_EXTENSION_FORKING_TEAR_DOWN;
Igor Murashkine302ee32012-11-05 11:14:49 -080092 }
93
94protected:
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 Murashkine302ee32012-11-05 11:14:49 -0800118 int mWidth;
119 int mHeight;
120
121 int mStreamId;
122 android::sp<CpuConsumer> mCpuConsumer;
123 android::sp<ANativeWindow> mNativeWindow;
124
125private:
126 CameraStreamParams mParam;
127};
128
129}
130}
131}
132
Igor Murashkineab33fc2012-11-06 17:02:54 -0800133#endif