1/*
2 * Copyright (C) 2014 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
17package android.hardware.camera2.legacy;
18
19import android.hardware.Camera;
20import android.hardware.camera2.CameraCharacteristics;
21import android.hardware.camera2.CaptureRequest;
22import android.util.Size;
23
24import static com.android.internal.util.Preconditions.*;
25
26/**
27 * Hold important data necessary to build the camera1 parameters up from a capture request.
28 */
29public class LegacyRequest {
30    /** Immutable characteristics for the camera corresponding to this request */
31    public final CameraCharacteristics characteristics;
32    /** Immutable capture request, as requested by the user */
33    public final CaptureRequest captureRequest;
34    /** Immutable api1 preview buffer size at the time of the request */
35    public final Size previewSize;
36    /** <em>Mutable</em> camera parameters */
37    public final Camera.Parameters parameters;
38
39    /**
40     * Create a new legacy request; the parameters are copied.
41     *
42     * @param characteristics immutable static camera characteristics for this camera
43     * @param captureRequest immutable user-defined capture request
44     * @param previewSize immutable internal preview size used for {@link Camera#setPreviewSurface}
45     * @param parameters the initial camera1 parameter state; (copied) can be mutated
46     */
47    public LegacyRequest(CameraCharacteristics characteristics, CaptureRequest captureRequest,
48            Size previewSize, Camera.Parameters parameters) {
49        this.characteristics = checkNotNull(characteristics, "characteristics must not be null");
50        this.captureRequest = checkNotNull(captureRequest, "captureRequest must not be null");
51        this.previewSize = checkNotNull(previewSize, "previewSize must not be null");
52        checkNotNull(parameters, "parameters must not be null");
53
54        this.parameters = Camera.getParametersCopy(parameters);
55    }
56
57    /**
58     * Update the current parameters in-place to be a copy of the new parameters.
59     *
60     * @param parameters non-{@code null} parameters for api1 camera
61     */
62    public void setParameters(Camera.Parameters parameters) {
63        checkNotNull(parameters, "parameters must not be null");
64
65        this.parameters.copyFrom(parameters);
66    }
67}
68