David Ghandehari | 8c5039b | 2016-08-17 19:39:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. All Rights Reserved. |
| 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 | #ifndef MEDIA_BASE_VIDEO_RESOLUTION_H_ |
| 18 | #define MEDIA_BASE_VIDEO_RESOLUTION_H_ |
| 19 | |
| 20 | #include "media/base/media_export.h" |
| 21 | #include "ui/gfx/size.h" |
| 22 | |
| 23 | namespace media { |
| 24 | |
| 25 | // Enumerates the various representations of the resolution of videos. Note |
| 26 | // that except |kVideoResolutionInvalid|, all other values are guaranteed to be |
| 27 | // in the same order as its (width, height) pair. |
| 28 | enum VideoResolution { |
| 29 | kVideoResolution1080p, // 1920 x 1080 |
| 30 | kVideoResolution2k, // 2560 x 1440 |
| 31 | kVideoResolution4k, // 3840 x 2160 |
| 32 | kVideoResolutionInvalid |
| 33 | }; |
| 34 | |
| 35 | inline VideoResolution GetVideoResolution(int width, int height) { |
| 36 | if (width <= 1920 && height <= 1080) { |
| 37 | return kVideoResolution1080p; |
| 38 | } |
| 39 | if (width <= 2560 && height <= 1440) { |
| 40 | return kVideoResolution2k; |
| 41 | } |
| 42 | if (width <= 3840 && height <= 2160) { |
| 43 | return kVideoResolution4k; |
| 44 | } |
| 45 | return kVideoResolutionInvalid; |
| 46 | } |
| 47 | |
| 48 | inline VideoResolution GetVideoResolution(const gfx::Size& size) { |
| 49 | return GetVideoResolution(size.width(), size.height()); |
| 50 | } |
| 51 | |
| 52 | } // namespace media |
| 53 | |
| 54 | #endif // MEDIA_BASE_VIDEO_RESOLUTION_H_ |