• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { CameraPlatformCapability } from '../../camera/CameraPlatformCapability'
17import { CameraId } from './CameraId'
18import { Log } from '../../utils/Log'
19
20export default class Resolution {
21  private static TAG = '[Resolution]:'
22  public static readonly ALIAS = 'VideoResolution'
23  public static readonly RESOLUTION_16_9_720P = '[16:9] 720p'
24  public static readonly RESOLUTION_16_9_1080P = '[16:9] 1080p'
25  public static readonly DEFAULT_VALUE = $r('app.string.resolution_1280_720')
26  public static readonly RESOURCE_16_9_720P = Resolution.DEFAULT_VALUE
27  public static readonly RESOURCE_16_9_1080P = $r('app.string.resolution_1620_1080')
28
29  private static getIndex(resolution: Resource): number {
30    if (resolution.id === Resolution.RESOURCE_16_9_720P.id) {
31      return 0
32    } else if (resolution.id === Resolution.RESOURCE_16_9_1080P.id) {
33      return 1
34    }
35    return 0
36  }
37
38  public static getVideoPreviewSize(platform: CameraPlatformCapability, cameraId: string, resolution: Resource) {
39    const index = Resolution.getIndex(resolution)
40    Log.info(`${this.TAG} getVideoPreviewSize size = ${JSON.stringify(platform.mVideoPreviewSize[index])}`)
41    return platform.mVideoPreviewSize[index]
42  }
43
44  public static getVideoFrameSize(platform: CameraPlatformCapability, cameraId: string, resolution: Resource) {
45    const index = Resolution.getIndex(resolution)
46    Log.info(`${this.TAG} getVideoFrameSize size = ${JSON.stringify(platform.mVideoFrameSize[index])}`)
47    return platform.mVideoFrameSize[index]
48  }
49
50  public static convertToResource(resolution: string): Resource {
51    switch (resolution) {
52    case Resolution.RESOLUTION_16_9_720P:
53      return Resolution.RESOURCE_16_9_720P
54    case Resolution.RESOLUTION_16_9_1080P:
55      return Resolution.RESOURCE_16_9_1080P
56    default:
57      return Resolution.RESOURCE_16_9_720P
58    }
59  }
60
61  public static convertToString(res: Resource): string {
62    if (res.id === Resolution.RESOURCE_16_9_720P.id) {
63      return Resolution.RESOLUTION_16_9_720P
64    } else if(res.id === Resolution.RESOURCE_16_9_1080P.id) {
65      return Resolution.RESOLUTION_16_9_1080P
66    }
67  }
68}