blob: 368656468ffd589383910e1b17fa15729bb5d429 [file] [log] [blame]
Ari Hausman-Cohenc17fd092016-07-18 10:13:26 -07001/*
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_STREAM_FORMAT_H_
18#define V4L2_STREAM_FORMAT_H_
19
20#include <linux/videodev2.h>
21
22#include "Common.h"
23#include "Stream.h"
24
25namespace v4l2_camera_hal {
26
27enum FormatCategory {
28 kFormatCategoryRaw,
29 kFormatCategoryStalling,
30 kFormatCategoryNonStalling,
31 kFormatCategoryUnknown,
32};
33
34class StreamFormat {
35 public:
36 StreamFormat(const default_camera_hal::Stream& stream);
37 StreamFormat(const v4l2_format& format);
38 virtual ~StreamFormat();
39 // Only uint32_t members, use default generated copy and assign.
40
41 void FillFormatRequest(v4l2_format* format) const;
42 FormatCategory Category() const;
43 inline uint32_t get_type() const { return type_; };
44
45 bool operator==(const StreamFormat& other) const;
46 bool operator!=(const StreamFormat& other) const;
47
48 // HAL <-> V4L2 conversions
49 // Returns 0 for unrecognized.
50 static uint32_t HalToV4L2PixelFormat(int hal_pixel_format);
51 // Returns -1 for unrecognized.
52 static int V4L2ToHalPixelFormat(uint32_t v4l2_pixel_format);
53
54 private:
55 uint32_t type_;
56 uint32_t v4l2_pixel_format_;
57 uint32_t width_;
58 uint32_t height_;
59 uint32_t bytes_per_line_;
60 uint32_t min_buffer_size_;
61};
62
63} // namespace v4l2_camera_hal
64
65#endif // V4L2_STREAM_FORMAT_H_