summaryrefslogtreecommitdiffstats
path: root/modules/camera/Metadata.h
blob: 22d2f223175bafc0bae619cb1146d231a4fbe8b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef METADATA_H_
#define METADATA_H_

#include <hardware/camera3.h>
#include <hardware/gralloc.h>
#include <system/camera_metadata.h>
#include <system/graphics.h>

namespace default_camera_hal {
// Metadata is a convenience class for dealing with libcamera_metadata
class Metadata {
    public:
        Metadata();
        ~Metadata();
        // Constructor used for request metadata templates
        Metadata(uint8_t mode, uint8_t intent);

        // Parse and add an entry
        int addUInt8(uint32_t tag, int count, uint8_t *data);
        int addInt32(uint32_t tag, int count, int32_t *data);
        int addFloat(uint32_t tag, int count, float *data);
        int addInt64(uint32_t tag, int count, int64_t *data);
        int addDouble(uint32_t tag, int count, double *data);
        int addRational(uint32_t tag, int count,
                camera_metadata_rational_t *data);
        // Generate a camera_metadata structure and fill it with internal data
        camera_metadata_t *generate();

    private:
        // Validate the tag, type and count for a metadata entry
        bool validate(uint32_t tag, int tag_type, int count);
        // Add a verified tag with data to this Metadata structure
        int add(uint32_t tag, int count, void *tag_data);

        class Entry {
            public:
                Entry(uint32_t tag, void *data, int count);
                ~Entry();
                Entry *mNext;
                Entry *mPrev;
                const uint32_t mTag;
                const void *mData;
                const int mCount;
                void insertAfter(Entry *e);
        };
        // List ends
        Entry *mHead;
        Entry *mTail;
        // Append entry to list
        void push(Entry *e);
        // Total of entries and entry data size
        int mEntryCount;
        int mDataCount;
        // Save generated metadata, invalidated on update
        camera_metadata_t *mGenerated;
        // Flag to force metadata regeneration
        bool mDirty;
        // Lock protecting the Metadata object for modifications
        pthread_mutex_t mMutex;
};
} // namespace default_camera_hal

#endif // METADATA_H_