webrtc中BEGIN_PROXY_MAP代码功能介绍

来源:互联网 发布:淘宝开直通车有用吗 编辑:程序博客网 时间:2024/05/18 18:01

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_;\  };\






0 0