1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ANDROID_V4L2_CODEC2_COMMON_COMMON_H 6 #define ANDROID_V4L2_CODEC2_COMMON_COMMON_H 7 8 #include <inttypes.h> 9 10 #include <optional> 11 #include <string> 12 #include <vector> 13 14 #include <ui/Rect.h> 15 #include <ui/Size.h> 16 17 #include <v4l2_codec2/common/VideoPixelFormat.h> 18 #include <v4l2_codec2/common/VideoTypes.h> 19 20 namespace android { 21 22 // The stride, offset and size of a video frame plane. 23 struct VideoFramePlane { 24 uint32_t mStride = 0; 25 size_t mOffset = 0; 26 size_t mSize = 0; 27 }; 28 29 // A video frame's layout, containing pixel format, size and layout of individual planes. 30 struct VideoFrameLayout { 31 VideoPixelFormat mFormat = VideoPixelFormat::UNKNOWN; 32 android::ui::Size mCodedSize; 33 std::vector<VideoFramePlane> mPlanes; 34 bool mMultiPlanar = false; 35 }; 36 37 // Specification of an encoding profile supported by an encoder or decoder. 38 struct SupportedProfile { 39 C2Config::profile_t profile = C2Config::PROFILE_UNUSED; 40 ui::Size min_resolution; 41 ui::Size max_resolution; 42 uint32_t max_framerate_numerator = 0; 43 uint32_t max_framerate_denominator = 0; 44 bool encrypted_only = false; 45 }; 46 using SupportedProfiles = std::vector<SupportedProfile>; 47 48 // Contains the capabilites of the decoder or encoder. 49 struct SupportedCapabilities { 50 VideoCodec codec; 51 SupportedProfiles supportedProfiles; 52 C2Config::profile_t defaultProfile = C2Config::PROFILE_UNUSED; 53 std::vector<C2Config::level_t> supportedLevels; 54 C2Config::level_t defaultLevel = C2Config::LEVEL_UNUSED; 55 }; 56 57 // Check whether |rect1| completely contains |rect2|. 58 bool contains(const Rect& rect1, const Rect& rect2); 59 60 // Convert the specified |rect| to a string. 61 std::string toString(const Rect& rect); 62 63 // Get the area encapsulated by the |size|. Returns nullopt if multiplication causes overflow. 64 std::optional<int> getArea(const ui::Size& size); 65 66 // Check whether the specified |size| is empty 67 bool isEmpty(const ui::Size& size); 68 69 // Convert the specified |size| to a string. 70 std::string toString(const ui::Size& size); 71 72 // Check whether specified profile can be used with specified codec 73 bool isValidProfileForCodec(VideoCodec codec, C2Config::profile_t profile); 74 75 } // namespace android 76 77 #endif // ANDROID_V4L2_CODEC2_COMMON_COMMON_H 78