• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #ifndef V4L2_CAMERA_HAL_STREAM_FORMAT_H_
18 #define V4L2_CAMERA_HAL_STREAM_FORMAT_H_
19 
20 #include <cstring>
21 
22 #include <linux/videodev2.h>
23 #include "arc/common_types.h"
24 
25 namespace v4l2_camera_hal {
26 
27 enum FormatCategory {
28   kFormatCategoryRaw,
29   kFormatCategoryStalling,
30   kFormatCategoryNonStalling,
31   kFormatCategoryUnknown,
32 };
33 
34 class StreamFormat {
35  public:
36   StreamFormat(int format, uint32_t width, uint32_t height);
37   StreamFormat(const v4l2_format& format);
38   StreamFormat(const arc::SupportedFormat& format);
39   virtual ~StreamFormat() = default;
40   // Only uint32_t members, use default generated copy and assign.
41 
42   void FillFormatRequest(v4l2_format* format) const;
43   FormatCategory Category() const;
44 
45   // Accessors.
type()46   inline uint32_t type() const { return type_; };
width()47   inline uint32_t width() const { return width_; };
height()48   inline uint32_t height() const { return height_; };
v4l2_pixel_format()49   inline uint32_t v4l2_pixel_format() const { return v4l2_pixel_format_; }
bytes_per_line()50   inline uint32_t bytes_per_line() const { return bytes_per_line_; };
51 
52   bool operator==(const StreamFormat& other) const;
53   bool operator!=(const StreamFormat& other) const;
54 
55   // HAL <-> V4L2 conversions
56   // Returns 0 for unrecognized.
57   static uint32_t HalToV4L2PixelFormat(int hal_pixel_format);
58   // Returns -1 for unrecognized.
59   static int V4L2ToHalPixelFormat(uint32_t v4l2_pixel_format);
60 
61   // ARC++ SupportedFormat Helpers
62   static bool FindBestFitFormat(const arc::SupportedFormats& supported_formats,
63                                 const arc::SupportedFormats& qualified_formats,
64                                 uint32_t fourcc, uint32_t width,
65                                 uint32_t height,
66                                 arc::SupportedFormat* out_format);
67   static bool FindFormatByResolution(const arc::SupportedFormats& formats,
68                                      uint32_t width, uint32_t height,
69                                      arc::SupportedFormat* out_format);
70   static arc::SupportedFormats GetQualifiedFormats(
71       const arc::SupportedFormats& supported_formats);
72 
73  private:
74   uint32_t type_;
75   uint32_t v4l2_pixel_format_;
76   uint32_t width_;
77   uint32_t height_;
78   uint32_t bytes_per_line_;
79 };
80 
81 }  // namespace v4l2_camera_hal
82 
83 #endif  // V4L2_CAMERA_HAL_STREAM_FORMAT_H_
84