Android-cuttlefish cvd tool
encoder_provider_registry.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 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#pragma once
18
19#include <algorithm>
20#include <memory>
21#include <mutex>
22#include <vector>
23
25
26namespace cuttlefish {
27namespace webrtc_streaming {
28
29// Global registry for EncoderProvider instances. Thread-safe.
31 public:
33
34 // Takes ownership. Skips unavailable providers.
35 void Register(std::unique_ptr<EncoderProvider> provider);
36
37 // Returns available providers sorted by priority (highest first).
38 std::vector<EncoderProvider*> GetProviders() const;
39
40 private:
43
46
47 mutable std::mutex mutex_;
48 std::vector<std::unique_ptr<EncoderProvider>> providers_;
49};
50
51template <typename T>
53 public:
55 EncoderProviderRegistry::Get().Register(std::make_unique<T>());
56 }
57};
58
59#define REGISTER_ENCODER_PROVIDER(ProviderClass) \
60 static ::cuttlefish::webrtc_streaming::EncoderProviderRegistrar< \
61 ProviderClass> \
62 g_encoder_provider_registrar_##ProviderClass
63
64} // namespace webrtc_streaming
65} // namespace cuttlefish
Definition: encoder_provider_registry.h:52
EncoderProviderRegistrar()
Definition: encoder_provider_registry.h:54
Definition: encoder_provider_registry.h:30
std::vector< EncoderProvider * > GetProviders() const
Definition: encoder_provider_registry.cpp:42
void Register(std::unique_ptr< EncoderProvider > provider)
Definition: encoder_provider_registry.cpp:29
std::mutex mutex_
Definition: encoder_provider_registry.h:47
std::vector< std::unique_ptr< EncoderProvider > > providers_
Definition: encoder_provider_registry.h:48
EncoderProviderRegistry(const EncoderProviderRegistry &)=delete
static EncoderProviderRegistry & Get()
Definition: encoder_provider_registry.cpp:24
EncoderProviderRegistry & operator=(const EncoderProviderRegistry &)=delete
Definition: alloc_driver.h:20