WebRTC VideoSendStreamParameters 的构造函数中,为什么不通过引用传递配置参数?
In the constructor of WebRTC VideoSendStreamParameters, why is the config argument not passed by a reference?
在WebRTC VideoSendStreamParameters的构造函数中,config参数通过一个值传递(因此引入了复制开销),但是options 参数通过引用传递。
config 成员也由 std::move(config) 初始化。
我想知道他们为什么这样设计。
以下内容是从 Chromium 源代码中截取的。
namespace webrtc {
...
class VideoSendStream {
...
struct Config {
...
Config() = delete;
Config(Config&&);
... // It's followed by many data members.
};
...
};
...
}
namespace cricket {
...
class WebRtcVideoChannel ... {
...
class WebRtcVideoSendStream {
...
struct VideoSendStreamParameters {
VideoSendStreamParameters(
webrtc::VideoSendStream::Config config,
const VideoOptions& options, ...)
...
webrtc::VideoSendStream::Config config;
VideoOptions options;
...
};
VideoSendStreamParameters parameters_ ... ;
...
};
...
};
WebRtcVideoChannel::WebRtcVideoSendStream::VideoSendStreamParameters::
VideoSendStreamParameters(
webrtc::VideoSendStream::Config config,
const VideoOptions& options, ...)
: config(std::move(config)),
options(options), ... {}
WebRtcVideoChannel::WebRtcVideoSendStream::WebRtcVideoSendStream(
...
webrtc::VideoSendStream::Config config,
const VideoOptions& options, ...)
: ...,
parameters_(std::move(config), options, ...), ...
{
...
}
...
}
因为配置在流的生命周期内被修改。您已经在信息流 constructor 中:
parameters_.config.rtp.max_packet_size =
std::min<size_t>(parameters_.config.rtp.max_packet_size, kVideoMtu);
而在SetSendParameters中,例如:
parameters_.config.rtp.rtcp_mode = *params.rtcp_mode;
当 class“拥有”数据时,通常的模式是按值传递数据并使用 std::move
初始化成员。这有时被称为接收器参数。
编辑
抱歉,我漏掉了VideoOptions
也是按值存储的部分,也在SetVideoSend()中被修改:
parameters_.options.SetAll(*options);
因此,Config
被移动的另一个解释是 Config
主要是移动类型。 Its assign operator 被删除,复制构造函数是私有的并且 Copy()
函数注释为:
Mostly used by tests. Avoid creating copies if you can.
这是为什么?真的不能确定。它已在 cc168360f413 as part of Issue 5687: Refactor Encoder - MediaTransport layer to use rtc::VideoSink/Source interface 中更改。
在WebRTC VideoSendStreamParameters的构造函数中,config参数通过一个值传递(因此引入了复制开销),但是options 参数通过引用传递。 config 成员也由 std::move(config) 初始化。 我想知道他们为什么这样设计。
以下内容是从 Chromium 源代码中截取的。
namespace webrtc {
...
class VideoSendStream {
...
struct Config {
...
Config() = delete;
Config(Config&&);
... // It's followed by many data members.
};
...
};
...
}
namespace cricket {
...
class WebRtcVideoChannel ... {
...
class WebRtcVideoSendStream {
...
struct VideoSendStreamParameters {
VideoSendStreamParameters(
webrtc::VideoSendStream::Config config,
const VideoOptions& options, ...)
...
webrtc::VideoSendStream::Config config;
VideoOptions options;
...
};
VideoSendStreamParameters parameters_ ... ;
...
};
...
};
WebRtcVideoChannel::WebRtcVideoSendStream::VideoSendStreamParameters::
VideoSendStreamParameters(
webrtc::VideoSendStream::Config config,
const VideoOptions& options, ...)
: config(std::move(config)),
options(options), ... {}
WebRtcVideoChannel::WebRtcVideoSendStream::WebRtcVideoSendStream(
...
webrtc::VideoSendStream::Config config,
const VideoOptions& options, ...)
: ...,
parameters_(std::move(config), options, ...), ...
{
...
}
...
}
因为配置在流的生命周期内被修改。您已经在信息流 constructor 中:
parameters_.config.rtp.max_packet_size =
std::min<size_t>(parameters_.config.rtp.max_packet_size, kVideoMtu);
而在SetSendParameters中,例如:
parameters_.config.rtp.rtcp_mode = *params.rtcp_mode;
当 class“拥有”数据时,通常的模式是按值传递数据并使用 std::move
初始化成员。这有时被称为接收器参数。
编辑
抱歉,我漏掉了VideoOptions
也是按值存储的部分,也在SetVideoSend()中被修改:
parameters_.options.SetAll(*options);
因此,Config
被移动的另一个解释是 Config
主要是移动类型。 Its assign operator 被删除,复制构造函数是私有的并且 Copy()
函数注释为:
Mostly used by tests. Avoid creating copies if you can.
这是为什么?真的不能确定。它已在 cc168360f413 as part of Issue 5687: Refactor Encoder - MediaTransport layer to use rtc::VideoSink/Source interface 中更改。