• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 package android.media.cts;
18 
19 
20 import android.content.pm.PackageManager;
21 import android.hardware.Camera;
22 import android.hardware.Camera.Parameters;
23 import android.hardware.Camera.Size;
24 import android.media.CamcorderProfile;
25 import android.test.AndroidTestCase;
26 import android.util.Log;
27 
28 import java.util.List;
29 
30 public class CamcorderProfileTest extends AndroidTestCase {
31 
32     private static final String TAG = "CamcorderProfileTest";
33 
34     // Uses get without id if cameraId == -1 and get with id otherwise.
getWithOptionalId(int quality, int cameraId)35     private CamcorderProfile getWithOptionalId(int quality, int cameraId) {
36         if (cameraId == -1) {
37             return CamcorderProfile.get(quality);
38         } else {
39             return CamcorderProfile.get(cameraId, quality);
40         }
41     }
42 
checkProfile(CamcorderProfile profile, List<Size> videoSizes)43     private void checkProfile(CamcorderProfile profile, List<Size> videoSizes) {
44         Log.v(TAG, String.format("profile: duration=%d, quality=%d, " +
45             "fileFormat=%d, videoCodec=%d, videoBitRate=%d, videoFrameRate=%d, " +
46             "videoFrameWidth=%d, videoFrameHeight=%d, audioCodec=%d, " +
47             "audioBitRate=%d, audioSampleRate=%d, audioChannels=%d",
48             profile.duration,
49             profile.quality,
50             profile.fileFormat,
51             profile.videoCodec,
52             profile.videoBitRate,
53             profile.videoFrameRate,
54             profile.videoFrameWidth,
55             profile.videoFrameHeight,
56             profile.audioCodec,
57             profile.audioBitRate,
58             profile.audioSampleRate,
59             profile.audioChannels));
60         assertTrue(profile.duration > 0);
61         assertTrue(profile.quality == CamcorderProfile.QUALITY_LOW ||
62                    profile.quality == CamcorderProfile.QUALITY_HIGH ||
63                    profile.quality == CamcorderProfile.QUALITY_QCIF ||
64                    profile.quality == CamcorderProfile.QUALITY_CIF ||
65                    profile.quality == CamcorderProfile.QUALITY_480P ||
66                    profile.quality == CamcorderProfile.QUALITY_720P ||
67                    profile.quality == CamcorderProfile.QUALITY_1080P ||
68                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_LOW ||
69                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_HIGH ||
70                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_QCIF ||
71                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_CIF ||
72                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_480P ||
73                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_720P ||
74                    profile.quality == CamcorderProfile.QUALITY_TIME_LAPSE_1080P);
75         assertTrue(profile.videoBitRate > 0);
76         assertTrue(profile.videoFrameRate > 0);
77         assertTrue(profile.videoFrameWidth > 0);
78         assertTrue(profile.videoFrameHeight > 0);
79         assertTrue(profile.audioBitRate > 0);
80         assertTrue(profile.audioSampleRate > 0);
81         assertTrue(profile.audioChannels > 0);
82         assertTrue(isSizeSupported(profile.videoFrameWidth,
83                                    profile.videoFrameHeight,
84                                    videoSizes));
85     }
86 
assertProfileEquals(CamcorderProfile expectedProfile, CamcorderProfile actualProfile)87     private void assertProfileEquals(CamcorderProfile expectedProfile,
88             CamcorderProfile actualProfile) {
89         assertEquals(expectedProfile.duration, actualProfile.duration);
90         assertEquals(expectedProfile.fileFormat, actualProfile.fileFormat);
91         assertEquals(expectedProfile.videoCodec, actualProfile.videoCodec);
92         assertEquals(expectedProfile.videoBitRate, actualProfile.videoBitRate);
93         assertEquals(expectedProfile.videoFrameRate, actualProfile.videoFrameRate);
94         assertEquals(expectedProfile.videoFrameWidth, actualProfile.videoFrameWidth);
95         assertEquals(expectedProfile.videoFrameHeight, actualProfile.videoFrameHeight);
96         assertEquals(expectedProfile.audioCodec, actualProfile.audioCodec);
97         assertEquals(expectedProfile.audioBitRate, actualProfile.audioBitRate);
98         assertEquals(expectedProfile.audioSampleRate, actualProfile.audioSampleRate);
99         assertEquals(expectedProfile.audioChannels, actualProfile.audioChannels);
100     }
101 
checkSpecificProfileDimensions(CamcorderProfile profile, int quality)102     private void checkSpecificProfileDimensions(CamcorderProfile profile, int quality) {
103         Log.v(TAG, String.format("specific profile: quality=%d, width = %d, height = %d",
104                     profile.quality, profile.videoFrameWidth, profile.videoFrameHeight));
105 
106         switch (quality) {
107             case CamcorderProfile.QUALITY_QCIF:
108             case CamcorderProfile.QUALITY_TIME_LAPSE_QCIF:
109                 assertEquals(176, profile.videoFrameWidth);
110                 assertEquals(144, profile.videoFrameHeight);
111                 break;
112 
113             case CamcorderProfile.QUALITY_CIF:
114             case CamcorderProfile.QUALITY_TIME_LAPSE_CIF:
115                 assertEquals(352, profile.videoFrameWidth);
116                 assertEquals(288, profile.videoFrameHeight);
117                 break;
118 
119             case CamcorderProfile.QUALITY_480P:
120             case CamcorderProfile.QUALITY_TIME_LAPSE_480P:
121                 assertTrue(720 == profile.videoFrameWidth ||  // SMPTE 293M/ITU-R Rec. 601
122                            640 == profile.videoFrameWidth ||  // ATSC/NTSC (square sampling)
123                            704 == profile.videoFrameWidth);   // ATSC/NTSC (non-square sampling)
124                 assertEquals(480, profile.videoFrameHeight);
125                 break;
126 
127             case CamcorderProfile.QUALITY_720P:
128             case CamcorderProfile.QUALITY_TIME_LAPSE_720P:
129                 assertEquals(1280, profile.videoFrameWidth);
130                 assertEquals(720, profile.videoFrameHeight);
131                 break;
132 
133             case CamcorderProfile.QUALITY_1080P:
134             case CamcorderProfile.QUALITY_TIME_LAPSE_1080P:
135                 // 1080p could be either 1920x1088 or 1920x1080.
136                 assertEquals(1920, profile.videoFrameWidth);
137                 assertTrue(1088 == profile.videoFrameHeight ||
138                            1080 == profile.videoFrameHeight);
139                 break;
140         }
141     }
142 
143     // Checks if the existing specific profiles have the correct dimensions.
144     // Also checks that the mimimum quality specific profile matches the low profile and
145     // similarly that the maximum quality specific profile matches the high profile.
checkSpecificProfiles( int cameraId, CamcorderProfile low, CamcorderProfile high, int[] specificQualities, List<Size> videoSizes)146     private void checkSpecificProfiles(
147             int cameraId,
148             CamcorderProfile low,
149             CamcorderProfile high,
150             int[] specificQualities,
151             List<Size> videoSizes) {
152 
153         CamcorderProfile minProfile = null;
154         CamcorderProfile maxProfile = null;
155 
156         for (int i = 0; i < specificQualities.length; i++) {
157             int quality = specificQualities[i];
158             if ((cameraId != -1 && CamcorderProfile.hasProfile(cameraId, quality)) ||
159                 (cameraId == -1 && CamcorderProfile.hasProfile(quality))) {
160                 CamcorderProfile profile = getWithOptionalId(quality, cameraId);
161                 checkSpecificProfileDimensions(profile, quality);
162 
163                 assertTrue(isSizeSupported(profile.videoFrameWidth,
164                                            profile.videoFrameHeight,
165                                            videoSizes));
166 
167                 if (minProfile == null) {
168                     minProfile = profile;
169                 }
170                 maxProfile = profile;
171             }
172         }
173 
174         assertNotNull(minProfile);
175         assertNotNull(maxProfile);
176 
177         Log.v(TAG, String.format("min profile: quality=%d, width = %d, height = %d",
178                     minProfile.quality, minProfile.videoFrameWidth, minProfile.videoFrameHeight));
179         Log.v(TAG, String.format("max profile: quality=%d, width = %d, height = %d",
180                     maxProfile.quality, maxProfile.videoFrameWidth, maxProfile.videoFrameHeight));
181 
182         assertProfileEquals(low, minProfile);
183         assertProfileEquals(high, maxProfile);
184 
185     }
186 
checkGet(int cameraId)187     private void checkGet(int cameraId) {
188         Log.v(TAG, (cameraId == -1)
189                    ? "Checking get without id"
190                    : "Checking get with id = " + cameraId);
191 
192         final List<Size> videoSizes = getSupportedVideoSizes(cameraId);
193 
194         CamcorderProfile lowProfile =
195             getWithOptionalId(CamcorderProfile.QUALITY_LOW, cameraId);
196         CamcorderProfile highProfile =
197             getWithOptionalId(CamcorderProfile.QUALITY_HIGH, cameraId);
198         checkProfile(lowProfile, videoSizes);
199         checkProfile(highProfile, videoSizes);
200 
201         CamcorderProfile lowTimeLapseProfile =
202             getWithOptionalId(CamcorderProfile.QUALITY_TIME_LAPSE_LOW, cameraId);
203         CamcorderProfile highTimeLapseProfile =
204             getWithOptionalId(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH, cameraId);
205         checkProfile(lowTimeLapseProfile, null);
206         checkProfile(highTimeLapseProfile, null);
207 
208         int[] specificProfileQualities = {CamcorderProfile.QUALITY_QCIF,
209                                           CamcorderProfile.QUALITY_QVGA,
210                                           CamcorderProfile.QUALITY_CIF,
211                                           CamcorderProfile.QUALITY_480P,
212                                           CamcorderProfile.QUALITY_720P,
213                                           CamcorderProfile.QUALITY_1080P};
214 
215         int[] specificTimeLapseProfileQualities = {CamcorderProfile.QUALITY_TIME_LAPSE_QCIF,
216                                                    CamcorderProfile.QUALITY_TIME_LAPSE_QVGA,
217                                                    CamcorderProfile.QUALITY_TIME_LAPSE_CIF,
218                                                    CamcorderProfile.QUALITY_TIME_LAPSE_480P,
219                                                    CamcorderProfile.QUALITY_TIME_LAPSE_720P,
220                                                    CamcorderProfile.QUALITY_TIME_LAPSE_1080P};
221 
222         checkSpecificProfiles(cameraId, lowProfile, highProfile,
223                 specificProfileQualities, videoSizes);
224         checkSpecificProfiles(cameraId, lowTimeLapseProfile, highTimeLapseProfile,
225                 specificTimeLapseProfileQualities, null);
226     }
227 
testGet()228     public void testGet() {
229         /*
230          * Device may not have rear camera for checkGet(-1).
231          * Checking PackageManager.FEATURE_CAMERA is included or not to decide the flow.
232          * Continue if the feature is included.
233          * Otherwise, exit test.
234          */
235         PackageManager pm = mContext.getPackageManager();
236         if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
237             return;
238         }
239         checkGet(-1);
240     }
241 
testGetWithId()242     public void testGetWithId() {
243         int nCamera = Camera.getNumberOfCameras();
244         for (int cameraId = 0; cameraId < nCamera; cameraId++) {
245             checkGet(cameraId);
246         }
247     }
248 
getSupportedVideoSizes(int cameraId)249     private List<Size> getSupportedVideoSizes(int cameraId) {
250         Camera camera = (cameraId == -1)? Camera.open(): Camera.open(cameraId);
251         Parameters parameters = camera.getParameters();
252         List<Size> videoSizes = parameters.getSupportedVideoSizes();
253         if (videoSizes == null) {
254             videoSizes = parameters.getSupportedPreviewSizes();
255             assertNotNull(videoSizes);
256         }
257         camera.release();
258         return videoSizes;
259     }
260 
isSizeSupported(int width, int height, List<Size> sizes)261     private boolean isSizeSupported(int width, int height, List<Size> sizes) {
262         if (sizes == null) return true;
263 
264         for (Size size: sizes) {
265             if (size.width == width && size.height == height) {
266                 return true;
267             }
268         }
269         Log.e(TAG, "Size (" + width + "x" + height + ") is not supported");
270         return false;
271     }
272 }
273