blob: 6e37adb26680e0ce5416b00ad141ddfe5bbc0468 [file] [log] [blame]
Ari Hausman-Cohenf6e178d2016-07-06 17:34:03 -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_GRALLOC_H
18#define V4L2_GRALLOC_H
19
20#include <linux/videodev2.h>
21
22#include <unordered_map>
23
24#include <hardware/camera3.h>
25#include <hardware/gralloc.h>
26#include <system/graphics.h>
27
28namespace v4l2_camera_hal {
29
30// Generously allow up to 3MB.
31static constexpr size_t V4L2_MAX_JPEG_SIZE = 3000000;
32
33// V4L2Gralloc is a wrapper around relevant parts of a gralloc module,
34// with some assistive transformations.
35class V4L2Gralloc {
36public:
37 V4L2Gralloc(const gralloc_module_t* module = nullptr);
38 ~V4L2Gralloc();
39
40 // Lock a camera buffer. Sets device buffer user pointer and length.
41 int lock(const camera3_stream_buffer_t* camera_buffer,
42 uint32_t bytes_per_line,
43 v4l2_buffer* device_buffer);
44 // Unlock a buffer that was locked by this helper (equality determined
45 // based on buffer user pointer, not the specific object).
46 int unlock(const v4l2_buffer* device_buffer);
47
48 // Check that the module passed in to the constructor is supported.
49 bool isValid();
50
51private:
52 const gralloc_module_t* mModule;
53
54 struct BufferData {
55 const camera3_stream_buffer_t* camera_buffer;
56 // Below fields only used when a ycbcr format transform is necessary.
57 std::unique_ptr<android_ycbcr> transform_dest; // nullptr if no transform.
58 uint32_t v4l2_bytes_per_line;
59 };
60 // Map data pointer : BufferData about that buffer.
61 std::unordered_map<void*, const BufferData*> mBufferMap;
62};
63} // namespace default_camera_hal
64
65#endif // CAMERA_GRALLOC_H_