webrtc中BEGIN_PROXY_MAP代码功能介绍

BEGIN_PROXY_MAP(VideoSource)

开始声明VideoSourceProxy类,包括构造函数、析构函数和静态成员函数Create()。

VideoSourceProxy继承VideoSourceInterface类。静态成员函数Create()创建一个VideoSourceProxy对象,并返回指针。


PROXY_METHOD0(r, method)将方法method放在某个线程上下文执行,并返回结果r

PROXY_METHODx将所有的方法放在线程上下文执行。

调用例子:

talk_base::scoped_refptr<VideoSource> source(...)

VideoSourceProxy::Create(signaling_thread_, source);

// VideoSourceProxy makes sure the real VideoSourceInterface implementation is
// destroyed on the signaling thread and marshals all method calls to the
// signaling thread.
BEGIN_PROXY_MAP(VideoSource)
  PROXY_CONSTMETHOD0(SourceState, state)
  PROXY_METHOD0(cricket::VideoCapturer*, GetVideoCapturer)
  PROXY_METHOD1(void, AddSink, cricket::VideoRenderer*)
  PROXY_METHOD1(void, RemoveSink, cricket::VideoRenderer*)
  PROXY_CONSTMETHOD0(const cricket::VideoOptions*, options)
  PROXY_METHOD0(cricket::VideoRenderer*, FrameInput)
  PROXY_METHOD1(void, RegisterObserver, ObserverInterface*)
  PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*)
END_PROXY()

#define BEGIN_PROXY_MAP(c) \
  class c##Proxy : public c##Interface {\
   protected:\
    typedef c##Interface C;\
    c##Proxy(talk_base::Thread* thread, C* c)\
      : owner_thread_(thread), \
        c_(c)  {}\
    ~c##Proxy() {\
      MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s);\
      call.Marshal(owner_thread_);\
    }\
   public:\
    static talk_base::scoped_refptr<C> Create(talk_base::Thread* thread, \
                                              C* c) {\
      return new talk_base::RefCountedObject<c##Proxy>(thread, c);\
    }\

#define PROXY_METHOD0(r, method)\
    r method() OVERRIDE {\
      MethodCall0<C, r> call(c_.get(), &C::method);\
      return call.Marshal(owner_thread_);\
    }\

#define PROXY_CONSTMETHOD0(r, method)\
    r method() const OVERRIDE {\
      ConstMethodCall0<C, r> call(c_.get(), &C::method);\
      return call.Marshal(owner_thread_);\
     }\

#define PROXY_METHOD1(r, method, t1)\
    r method(t1 a1) OVERRIDE {\
      MethodCall1<C, r, t1> call(c_.get(), &C::method, a1);\
      return call.Marshal(owner_thread_);\
    }\

#define PROXY_CONSTMETHOD1(r, method, t1)\
    r method(t1 a1) const OVERRIDE {\
      ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1);\
      return call.Marshal(owner_thread_);\
    }\

#define PROXY_METHOD2(r, method, t1, t2)\
    r method(t1 a1, t2 a2) OVERRIDE {\
      MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2);\
      return call.Marshal(owner_thread_);\
    }\

#define PROXY_METHOD3(r, method, t1, t2, t3)\
    r method(t1 a1, t2 a2, t3 a3) OVERRIDE {\
      MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, a1, a2, a3);\
      return call.Marshal(owner_thread_);\
    }\

#define END_PROXY() \
   private:\
    void Release_s() {\
      c_ = NULL;\
    }\
    mutable talk_base::Thread* owner_thread_;\
    talk_base::scoped_refptr<C> c_;\
  };\






  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值