1/*
2 * Copyright (C) 2013 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 METADATA_H_
18#define METADATA_H_
19
20#include <hardware/camera3.h>
21#include <hardware/gralloc.h>
22#include <system/camera_metadata.h>
23#include <system/graphics.h>
24
25namespace default_camera_hal {
26// Metadata is a convenience class for dealing with libcamera_metadata
27class Metadata {
28    public:
29        Metadata();
30        ~Metadata();
31        // Constructor used for request metadata templates
32        Metadata(uint8_t mode, uint8_t intent);
33
34        // Parse and add an entry
35        int addUInt8(uint32_t tag, int count, uint8_t *data);
36        int addInt32(uint32_t tag, int count, int32_t *data);
37        int addFloat(uint32_t tag, int count, float *data);
38        int addInt64(uint32_t tag, int count, int64_t *data);
39        int addDouble(uint32_t tag, int count, double *data);
40        int addRational(uint32_t tag, int count,
41                camera_metadata_rational_t *data);
42        // Generate a camera_metadata structure and fill it with internal data
43        camera_metadata_t *generate();
44
45    private:
46        // Validate the tag, type and count for a metadata entry
47        bool validate(uint32_t tag, int tag_type, int count);
48        // Add a verified tag with data to this Metadata structure
49        int add(uint32_t tag, int count, void *tag_data);
50
51        class Entry {
52            public:
53                Entry(uint32_t tag, void *data, int count);
54                ~Entry();
55                Entry *mNext;
56                Entry *mPrev;
57                const uint32_t mTag;
58                const void *mData;
59                const int mCount;
60                void insertAfter(Entry *e);
61        };
62        // List ends
63        Entry *mHead;
64        Entry *mTail;
65        // Append entry to list
66        void push(Entry *e);
67        // Total of entries and entry data size
68        int mEntryCount;
69        int mDataCount;
70        // Save generated metadata, invalidated on update
71        camera_metadata_t *mGenerated;
72        // Flag to force metadata regeneration
73        bool mDirty;
74        // Lock protecting the Metadata object for modifications
75        pthread_mutex_t mMutex;
76};
77} // namespace default_camera_hal
78
79#endif // METADATA_H_
80