How to enable TRACE_EVENT in WebRTC codes

news/2024/7/10 22:18:03 标签: webrtc, 源码, ffmpeg, chrome, google

WebRTC源码中有这样的代码片段:

bool WebRtcVideoChannel2::SetRtpSendParameters(
    uint32_t ssrc,
    const webrtc::RtpParameters& parameters) {
  TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRtpSendParameters");
  rtc::CritScope stream_lock(&stream_crit_);
  auto it = send_streams_.find(ssrc);
  if (it == send_streams_.end()) {
    LOG(LS_ERROR) << "Attempting to set RTP send parameters for stream "
                  << "with ssrc " << ssrc << " which doesn't exist.";
    return false;
  }

  // TODO(deadbeef): Handle setting parameters with a list of codecs in a
  // different order (which should change the send codec).
  webrtc::RtpParameters current_parameters = GetRtpSendParameters(ssrc);
  if (current_parameters.codecs != parameters.codecs) {
    LOG(LS_ERROR) << "Using SetParameters to change the set of codecs "
                  << "is not currently supported.";
    return false;
  }

  return it->second->SetRtpParameters(parameters);
}

这里面的 TRACE_EVENT0 会 trace 一些事件,对通过日志调试有一些帮助。类似的还有 TRACE_EVENT1 等。但是这些宏默认不输出日志,需要客户代码为 WebRTC 配置下面两个函数指针才能生效:

typedef const unsigned char* (*GetCategoryEnabledPtr)(const char* name);
typedef void (*AddTraceEventPtr)(char phase,
                                 const unsigned char* category_enabled,
                                 const char* name,
                                 unsigned long long id,
                                 int num_args,
                                 const char** arg_names,
                                 const unsigned char* arg_types,
                                 const unsigned long long* arg_values,
                                 unsigned char flags);

调用下面的函数可以完成配置:

void SetupEventTracer(
    GetCategoryEnabledPtr get_category_enabled_ptr,
    AddTraceEventPtr add_trace_event_ptr);

上述函数及前面函数指针类型,都在 webrtc/base/event_tracer.h 头文件中。

GetCategoryEnabledPtr 返回一个 const unsigned char* ,指示特定名字的事件是否被使能。下面是一个简单的实现:

static const unsigned char* _GetCategoryEnabled(const char* name)
{
    return reinterpret_cast<const unsigned char*>("\1");
}

AddTraceEventPtr 用来响应 trace event 操作,下面是一个参考实现:

static void _AddTraceEvent(char phase,
                                 const unsigned char* category_enabled,
                                 const char* name,
                                 unsigned long long id,
                                 int num_args,
                                 const char** arg_names,
                                 const unsigned char* arg_types,
                                 const unsigned long long* arg_values,
                                 unsigned char flags)
{
    if(category_enabled[0] == 0) return; // disabled
    fprintf(stderr, "trace_event : %s ", name);
    for(int i = 0; i < num_args; ++i)
    {
        switch(arg_types[i])
        {
        case TRACE_VALUE_TYPE_STRING:
            if(strcmp("src_file_and_line", arg_names[i]) == 0 ||
                strcmp("src_func", arg_names[i]) == 0)
            {
                fprintf(stderr, "%s ", (const char*)arg_values[i]);
            }else{
                fprintf(stderr, "%s - %s ", arg_names[i], (const char*)arg_values[i]);
            }   
            break;
        case TRACE_VALUE_TYPE_UINT:
            fprintf(stderr, "%s %u ", arg_names[i], (unsigned int)arg_values[i]);
            break;
        case TRACE_VALUE_TYPE_INT:
        case TRACE_VALUE_TYPE_BOOL:
            fprintf(stderr, "%s %d ", arg_names[i], (int)arg_values[i]);
            break;
        case TRACE_VALUE_TYPE_DOUBLE:
            fprintf(stderr, "%s %.4f ", arg_names[i], (double)arg_values[i]);
            break;
        }
    }
    fprintf(stderr, "\n");
}

我根据事件名字和类型(类似TRACE_VALUE_TYPE_INT宏在webrtc/base/trace_event.h中定义)输出了一些信息,结果类似下面这样:

trace_event : MessageQueue::Dispatch ../../webrtc/pc/channel.cc:701 SendPacket 
trace_event : BaseChannel::OnMessage 
trace_event : BaseChannel::SendPacket 
trace_event : BaseChannel::SendPacket 
trace_event : BaseChannel::OnMessage 
trace_event : MessageQueue::Dispatch 
trace_event : MessageQueue::Dispatch ../../webrtc/p2p/base/p2ptransportchannel.cc:1550 OnCheckAndPing 
trace_event : MessageQueue::Dispatch 
trace_event : JB::RecycleFramesUntilKeyFrame 
trace_event : MessageQueue::Dispatch ../../webrtc/p2p/base/p2ptransportchannel.cc:1550 OnCheckAndPing 
trace_event : MessageQueue::Dispatch 
trace_event : JB::RecycleFramesUntilKeyFrame 
trace_event : MessageQueue::Dispatch ../../webrtc/pc/channel.cc:701 SendPacket 
trace_event : BaseChannel::OnMessage 

要把我们实现的函数配置给 WebRTC ,需要在调用任何其它 WebRTC 函数之前进行,比如在 main 函数一开始,类似下面这样:

webrtc::SetupEventTracer(_GetCategoryEnabled, _AddTraceEvent);

相关阅读:

  • WebRTC学习资料大全
  • Ubuntu 14.04下编译WebRTC
  • WebRTC源码中turnserver的使用方法
  • 打开 WebRTC 的日志(native api)
  • 让WebRTC支持H264编解码
  • WebRTC编译系统之gn和ninja
  • WebRTC编译系统之gn files

http://www.niftyadmin.cn/n/817612.html

相关文章

android_button onclick点击事件的5种写法

android项目开发中经常使用button按钮的onclick点击事件来做一些操作&#xff0c;android onclick事件通常有这5种写法经常被使用&#xff0c;本文以android Toast弹窗来举例&#xff0c;原文转自&#xff1a;http://www.tpyyes.com/a/android/2017/0526/109.html 首先我们新建…

生信——制作bed file

bed file是靶向测序中一个重要的文件&#xff0c;是告诉call SNP的软件&#xff0c;目标的基因位置在染色体的什么地方。主要用到的工具是UCSC gene browser 1.外显子的靶向文件 UCSC:http://genome.ucsc.edu/cgi-bin/hgTables. 按照下表填好&#xff0c;把自己的目标基因名字&…

让 WebRTC 使用外部的音视频编解码器

WebRTC 支持使用自己的编解码器&#xff08;限 native 开发&#xff09;&#xff0c;音频&#xff0c;视频都可以。这里以视频编码为例来分析下 WebRTC 中相应的源码。 CreatePeerConnectionFactory 在 webrtc/api/peerconnectioninterface.h 中有个方法 CreatePeerConnectio…

前端IDE:VSCode + WebStorm

VSCode 插件安装 官网&#xff1a;Extensions for the Visual Studio family of products&#xff1b; &#xff08;1&#xff09;拼接下载链接&#xff1a; https://${publisher}.gallery.vsassets.io/_apis/public/gallery /publisher/${publisher}/extension/${extension na…

四无年轻人如何逆袭

一个问题&#xff1a;“普普通通的年轻人&#xff0c;没关系没资源&#xff0c;没有一技之长&#xff0c;没有什么兴趣爱好&#xff0c;该如何逆袭&#xff1f;” 这是我在分答上收到的众多类似问题中的一个。看起来有很多人都正为此类困惑。但实际上&#xff0c;它的答案却是…

c# winform Chart Pie 中若X轴数据为字符串时,#VALX取值为0

https://q.cnblogs.com/q/83848/ 在winform程序中用自带的Chart进行画图表时&#xff0c;若画饼图&#xff0c;其中X轴数据为字符串&#xff0c;这时候如果想设置Label值的格式为#VALX&#xff1a;#VAL&#xff0c;在图中显示的总是0&#xff1a;y值&#xff0c;或者图例中也为…

Android ListView adapter使用教程

&#xfeff;&#xfeff;android ListView组件使用实在是太频繁了&#xff0c;因此特意制作了Android ListView的详细使用教程&#xff0c;还有和listview配套使用的BaseAdapter以及ArrayAdapter都会在文章后面有讲到&#xff0c;非常的实用。 为了便于理解下面listview的使用…

程序员职场规划之转型-安晓辉-专题视频课程

程序员职场规划之转型—2492人已学习 课程介绍 如果你有这些困惑&#xff0c;本课程可能就是你想找的&#xff1a; 不知道开发之路如何继续&#xff0c; 不知道自己除了开发还能干什么&#xff0c; 不知道什么时候真的该跳槽了&#xff0c; 不知道如何为想做的职业做准备&am…