Agora C++ API Reference for All Platforms

extension_provider_i.h
1 //
2 // Agora SDK
3 //
4 // Copyright (c) 2021 Agora.io. All rights reserved.
5 //
6
7 #pragma once
8
9 #include <string>
10
11 #include "NGIAgoraExtensionProvider.h"
12 #include "NGIAgoraExtensionScreenSource.h"
13 #include "api2/internal/AgoraRefCountedObjectInternal.h"
14
15 namespace agora {
16 namespace rtc {
17
18 class ExtProviderDeleter
19 {
20 public:
21 template<typename T>
22 void operator()(const T* p) const {
23 /*
24 * We can't use std::default_delete here because RefCountInterface::Release is marked as const member function!!!
25 */
26 delete p;
27 }
28 };
29
30 template<typename T>
31 using ExtRefCountedObject = agora::RefCountedObject<T, ExtProviderDeleter>;
32
33 class ICustomExtensionProvider : public IExtensionProvider {
34 public:
35 virtual void* createCustomExtension(const char* name) = 0;
36 virtual void destroyCustomExtension(const char* name, void* object) = 0;
37 virtual agora_refptr<ILipSyncFilter> createLipSyncFilter(const char* name) {
38 return NULL;
39 }
40 };
41
42 #define RESERVED_INTERNAL_MAJOR_VERSION 999
43
44 template <>
45 struct ExtensionInterfaceVersion<ICustomExtensionProvider> {
46 static ExtensionVersion Version() {
47 return ExtensionVersion(RESERVED_INTERNAL_MAJOR_VERSION, 0, 0);
48 }
49 };
50
51 template <class ExtInterface>
52 class CustomExtensionWrapper {
53 public:
54 CustomExtensionWrapper(ICustomExtensionProvider* provider,
55 const char* extension, bool refcounted)
56 : provider_(provider), ext_name_(extension) {
57 assert(provider_ && !ext_name_.empty());
58 if (refcounted) {
59 ref_ptr_ = static_cast<RefCountedObject<ExtInterface>*>(
60 provider_->createCustomExtension(extension));
61 } else {
62 raw_ptr_ = static_cast<ExtInterface*>(provider_->createCustomExtension(extension));
63 }
64 }
65
66 ~CustomExtensionWrapper() {
67 if (raw_ptr_) {
68 assert(provider_ && !ext_name_.empty());
69 provider_->destroyCustomExtension(ext_name_.c_str(), raw_ptr_);
70 }
71 }
72
73 CustomExtensionWrapper(const CustomExtensionWrapper&) = default;
74 CustomExtensionWrapper& operator=(const CustomExtensionWrapper&) = default;
75 CustomExtensionWrapper(CustomExtensionWrapper&&) = default;
76 CustomExtensionWrapper& operator=(CustomExtensionWrapper&&) = default;
77
78 ExtInterface* get() {
79 return raw_ptr_? raw_ptr_ : ref_ptr_.get();
80 }
81
82 agora_refptr<ExtInterface> getRefPtr() {
83 return ref_ptr_;
84 }
85
86 private:
87 std::string ext_name_;
88 ICustomExtensionProvider* provider_ = nullptr;
89 agora_refptr<ExtInterface> ref_ptr_ = nullptr;
90 ExtInterface* raw_ptr_ = nullptr;
91 };
92
93 } // namespace rtc
94 } // namespace agora
agora::rtc::ICustomExtensionProvider::destroyCustomExtension
virtual void destroyCustomExtension(const char *name, void *object)=0
agora::rtc::ExtProviderDeleter
Definition: extension_provider_i.h:19
agora::rtc::ExtensionVersion
Definition: AgoraExtensionVersion.h:14
agora::agora_refptr
Definition: AgoraRefPtr.h:44
agora::agora_refptr::get
T * get() const
Definition: AgoraRefPtr.h:77
agora::rtc::CustomExtensionWrapper::CustomExtensionWrapper
CustomExtensionWrapper(const CustomExtensionWrapper &)=default
agora::rtc::ExtensionInterfaceVersion< ICustomExtensionProvider >::Version
static ExtensionVersion Version()
Definition: extension_provider_i.h:46
agora::rtc::CustomExtensionWrapper::~CustomExtensionWrapper
~CustomExtensionWrapper()
Definition: extension_provider_i.h:66
agora::rtc::CustomExtensionWrapper
Definition: extension_provider_i.h:52
agora::rtc::CustomExtensionWrapper::get
ExtInterface * get()
Definition: extension_provider_i.h:78
agora::rtc::ICustomExtensionProvider
Definition: extension_provider_i.h:33
agora::RefCountedObject
Definition: AgoraRefCountedObject.h:71
agora
Definition: AgoraAtomicOps.h:21
agora::rtc::CustomExtensionWrapper::getRefPtr
agora_refptr< ExtInterface > getRefPtr()
Definition: extension_provider_i.h:82
agora::rtc::IExtensionProvider
Definition: NGIAgoraExtensionProvider.h:35
agora::rtc::CustomExtensionWrapper::CustomExtensionWrapper
CustomExtensionWrapper(ICustomExtensionProvider *provider, const char *extension, bool refcounted)
Definition: extension_provider_i.h:54
agora::rtc::CustomExtensionWrapper::operator=
CustomExtensionWrapper & operator=(const CustomExtensionWrapper &)=default
agora::rtc::CustomExtensionWrapper::CustomExtensionWrapper
CustomExtensionWrapper(CustomExtensionWrapper &&)=default
agora::rtc::ExtProviderDeleter::operator()
void operator()(const T *p) const
Definition: extension_provider_i.h:22
agora::rtc::ICustomExtensionProvider::createLipSyncFilter
virtual agora_refptr< ILipSyncFilter > createLipSyncFilter(const char *name)
Definition: extension_provider_i.h:37
agora::rtc::CustomExtensionWrapper::operator=
CustomExtensionWrapper & operator=(CustomExtensionWrapper &&)=default
agora::rtc::ExtensionInterfaceVersion
Definition: AgoraExtensionVersion.h:66
rtc
Definition: video_node_i.h:28
agora::rtc::ICustomExtensionProvider::createCustomExtension
virtual void * createCustomExtension(const char *name)=0