aboutsummaryrefslogtreecommitdiff
path: root/components/include/v4l2_codec2/components/V4L2ComponentStore.h
blob: bfec40733af87fb445d510473999d1342dc99da0 (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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H
#define ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H

#include <map>
#include <mutex>

#include <C2Component.h>
#include <C2ComponentFactory.h>
#include <android-base/thread_annotations.h>
#include <util/C2InterfaceHelper.h>

namespace android {

class V4L2ComponentStore : public C2ComponentStore {
public:
    static std::shared_ptr<C2ComponentStore> Create();
    ~V4L2ComponentStore();

    // C2ComponentStore implementation.
    C2String getName() const override;
    c2_status_t createComponent(C2String name,
                                std::shared_ptr<C2Component>* const component) override;
    c2_status_t createInterface(C2String name,
                                std::shared_ptr<C2ComponentInterface>* const interface) override;
    std::vector<std::shared_ptr<const C2Component::Traits>> listComponents() override;
    std::shared_ptr<C2ParamReflector> getParamReflector() const override;
    c2_status_t copyBuffer(std::shared_ptr<C2GraphicBuffer> src,
                           std::shared_ptr<C2GraphicBuffer> dst) override;
    c2_status_t querySupportedParams_nb(
            std::vector<std::shared_ptr<C2ParamDescriptor>>* const params) const override;
    c2_status_t query_sm(const std::vector<C2Param*>& stackParams,
                         const std::vector<C2Param::Index>& heapParamIndices,
                         std::vector<std::unique_ptr<C2Param>>* const heapParams) const override;
    c2_status_t config_sm(const std::vector<C2Param*>& params,
                          std::vector<std::unique_ptr<C2SettingResult>>* const failures) override;
    c2_status_t querySupportedValues_sm(
            std::vector<C2FieldSupportedValuesQuery>& fields) const override;

private:
    V4L2ComponentStore();

    ::C2ComponentFactory* GetFactory(const C2String& name);
    std::shared_ptr<const C2Component::Traits> GetTraits(const C2String& name);

    std::shared_ptr<C2ReflectorHelper> mReflector;

    std::mutex mCachedFactoriesLock;
    std::map<C2String, std::unique_ptr<::C2ComponentFactory>> mCachedFactories
            GUARDED_BY(mCachedFactoriesLock);
    std::mutex mCachedTraitsLock;
    std::map<C2String, std::shared_ptr<const C2Component::Traits>> mCachedTraits
            GUARDED_BY(mCachedTraitsLock);
};

}  // namespace android

#endif  // ANDROID_V4L2_CODEC2_COMPONENTS_V4L2_COMPONENT_STORE_H