answer-之发送方向确定方式:由对端的offer的方向和本地想要的方向做对比最终获取answer的方向。
为了简化篇幅,故只附上相关的源码文件路径及相关的函数。
1. 首先sdp的生成是和peerconnection有密切关系的。
peerconnection对象的track的添加将会影响最终sdp的生成。
详见peerconnection的AddTrack。
2. answer中direction的判定流程。
src/pc/peer_connection.cc
CreateAnswer
src/pc/webrtc_session_description_factory.cc
CreateAnswer
InternalCreateAnswer
src/pc/media_session.cc
CreateAnswer
AddVideoContentForAnswer
CreateMediaContentAnswer
static RtpTransceiverDirection
NegotiateRtpTransceiverDirection( RtpTransceiverDirection offer,
RtpTransceiverDirection wants) {
bool offer_send = webrtc::RtpTransceiverDirectionHasSend(offer);
bool offer_recv = webrtc::RtpTransceiverDirectionHasRecv(offer);
bool wants_send = webrtc::RtpTransceiverDirectionHasSend(wants);
bool wants_recv = webrtc::RtpTransceiverDirectionHasRecv(wants);
return webrtc::RtpTransceiverDirectionFromSendRecv(offer_recv && wants_send,
offer_send && wants_recv);
}
上述为追踪answer中direction的判定;
3. 首先对方传过来的direction已确定,关键是看本地answer生成时wants的是什么?
其中wants的传入是由如下传入:
src/pc/peer_connection.cc
CreateAnswer
cricket::MediaSessionOptions session_options;
GetOptionsForAnswer(options, &session_options);
GetOptionsForUnifiedPlanAnswer
GetMediaDescriptionOptionsForTransceiver
cricket::MediaDescriptionOptions media_description_options( transceiver->media_type(), mid,
transceiver->direction(),
transceiver->stopped());
transceiver的生成位置:
UpdateTransceiversAndDataChannels
AssociateTransceiver
后续请等待......