xref: /aosp_15_r20/external/v4l2_codec2/v4l2/V4L2ComponentStore.cpp (revision 0ec5a0ec62797f775085659156625e7f1bdb369f)
1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //#define LOG_NDEBUG 0
6 #define LOG_TAG "V4L2ComponentStore"
7 
8 #include <v4l2_codec2/v4l2/V4L2ComponentStore.h>
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <mutex>
14 
15 #include <C2.h>
16 #include <C2Config.h>
17 #include <log/log.h>
18 #include <media/stagefright/foundation/MediaDefs.h>
19 
20 #include <v4l2_codec2/components/ComponentStore.h>
21 #include <v4l2_codec2/v4l2/V4L2ComponentCommon.h>
22 #include <v4l2_codec2/v4l2/V4L2ComponentFactory.h>
23 
24 namespace android {
25 
26 // static
Create()27 std::shared_ptr<C2ComponentStore> V4L2ComponentStore::Create() {
28     ALOGV("%s()", __func__);
29 
30     static std::mutex mutex;
31     static std::weak_ptr<C2ComponentStore> platformStore;
32 
33     std::lock_guard<std::mutex> lock(mutex);
34     std::shared_ptr<C2ComponentStore> store = platformStore.lock();
35     if (store != nullptr) return store;
36 
37     auto builder = ComponentStore::Builder("android.componentStore.v4l2");
38 
39     builder.encoder(V4L2ComponentName::kH264Encoder, VideoCodec::H264,
40                     &V4L2ComponentFactory::create);
41     builder.encoder(V4L2ComponentName::kVP8Encoder, VideoCodec::VP8, &V4L2ComponentFactory::create);
42     builder.encoder(V4L2ComponentName::kVP9Encoder, VideoCodec::VP9, &V4L2ComponentFactory::create);
43 
44     builder.decoder(V4L2ComponentName::kH264Decoder, VideoCodec::H264,
45                     &V4L2ComponentFactory::create);
46     builder.decoder(V4L2ComponentName::kVP8Decoder, VideoCodec::VP8, &V4L2ComponentFactory::create);
47     builder.decoder(V4L2ComponentName::kVP9Decoder, VideoCodec::VP9, &V4L2ComponentFactory::create);
48     builder.decoder(V4L2ComponentName::kHEVCDecoder, VideoCodec::HEVC,
49                     &V4L2ComponentFactory::create);
50 
51     builder.decoder(V4L2ComponentName::kH264SecureDecoder, VideoCodec::H264,
52                     &V4L2ComponentFactory::create);
53     builder.decoder(V4L2ComponentName::kVP8SecureDecoder, VideoCodec::VP8,
54                     &V4L2ComponentFactory::create);
55     builder.decoder(V4L2ComponentName::kVP9SecureDecoder, VideoCodec::VP9,
56                     &V4L2ComponentFactory::create);
57     builder.decoder(V4L2ComponentName::kHEVCSecureDecoder, VideoCodec::HEVC,
58                     &V4L2ComponentFactory::create);
59 
60     store = std::shared_ptr<C2ComponentStore>(std::move(builder).build());
61     platformStore = store;
62     return store;
63 }
64 
65 }  // namespace android
66