webrtc代码解读一:音频数据的接收解码播放过程

RTP connection创建过程(从下往上调用):

Channel::Channel调用RtpRtcp::CreateRtpRtcp

Channel::Channel 调用RtpReceiver::CreateAudioReceiver (RtpReceiver,这里注册Channel类为RTP包回调处理类)

ChannelProxy::ChannelProxy里调用new voe::Channel

CreateChannelAndProxy里调用new voe::ChannelProxy

AudioReceiveStream::AudioReceiveStream调用CreateChannelAndProxy

call::CreateAudioReceiveStream里new internal::AudioReceiveStream (成员列表里也保存了new出的对象,注意:internal::AudioReceiveStream 继承自webrtc::AudioReceiveStream )

WebRtcVoiceMediaChannel::RecreateAudioReceiveStream里调用: call::CreateAudioReceiveStream; (保存到成员变量:webrtc::AudioReceiveStream* stream_)

WebRtcVoiceMediaChannel构造函数等里调用RecreateAudioReceiveStream

WebRtcVoiceEngine::CreateChannel 里new出WebRtcVoiceMediaChannel对象

ChannelManager::CreateVoiceChannel里调用WebRtcVoiceEngine::CreateChannel

PeerConnection::CreateVoiceChannel里调用ChannelManager::CreateVoiceChannel

PeerConnection::CreateChannels里调用PeerConnection::CreateVoiceChannel

PeerConnection::ApplyLocalDescription里调用PeerConnection::CreateChannels

PeerConnection::SetLocalDescription里调用PeerConnection::ApplyLocalDescription

 

RTP回调函数注册:

注册SignalReadPacket的回调:

PeerConnection::SetLocalDescription->PeerConnection::ApplyLocalDescription->PeerConnection::PushdownTransportDescription -> JsepTransportController::SetLocalDescription->JsepTransportController::ApplyDescription_n -> JsepTransportController::MaybeCreateJsepTransport->JsepTransportController::CreateDtlsSrtpTransport-> DtlsSrtpTransport::SetDtlsTransports->RtpTransport::SetRtpPacketTransport -> new_packet_transport->SignalReadPacket.connect(this,&RtpTransport::OnReadPacket);

JsepTransportController::MaybeCreateJsepTransport -> JsepTransportController::CreateDtlsTransport -> new cricket::P2PTransportChannel 

AllocationSequence::CreateUDPPorts调用UDPPort::Create

AllocationSequence::Init调用rtc::AsyncPacketSocket::connect(this, &AllocationSequence::OnReadPacket)

AllocationSequence::OnReadPacket调用UDPPort::OnReadPacket调用(Connection::OnReadPacket或Port::OnReadPacket)

Connection::OnReadPacket转发到P2PTransportChannel::OnReadPacket

 

注册SignalPacketReceived的回调:

PeerConnection::CreateVoiceChannel 调用 voice_channel->SetRtpTransport(rtp_transport); 调用BaseChannel::ConnectToRtpTransport 调用 rtp_transport_->SignalPacketReceived.connect(this,
                                               &BaseChannel::OnPacketReceived);

RTP包投递过程:

AsyncUDPSocket::OnReadEvent发出SignalReadPacket事件, RtpTransport::OnReadPacket 处理事件,转发 BaseChannel::OnPacketReceived->BaseChannel::ProcessPacket->WebRtcVoiceMediaChannel::OnPacketReceived -> Call::DeliverPacket->Call::DeliverRtp -> audio_receiver_controller_.OnRtpPacket  -> demuxer_.OnRtpPacket -> (sink->OnRtpPacket(packet) 此处sink为addsink添加的ChannelProxy指针) -> ChannelProxy::OnRtpPacket -> Channel::OnRtpPacket->Channel::ReceivePacket-> (rtp_receiver_->IncomingRtpPacket) -> RTPReceiverVideo::ParseRtpPacket ->Channel::OnReceivedPayloadData(rtp模块回调未解码原始帧) -> audio_coding_->IncomingPacket ->receiver_.InsertPacket -> NetEqImpl::InsertPacket -> NetEqImpl::InsertPacketInternal 

 

音频解码:

AudioDeviceWindowsCore::DoRenderThread()->AudioDeviceBuffer::RequestPlayoutData->AudioTransportImpl::NeedMorePlayData->AudioTransportImpl::PullRenderData->AudioMixerImpl::Mix->AudioMixerImpl::GetAudioFromSources->AudioReceiveStream::GetAudioFrameWithInfo(AudioReceiveStream实现了AudioMixer::Source) ->ChannelProxy::GetAudioFrameWithInfo->Channel::GetAudioFrameWithInfo->AudioCodingModuleImpl::PlayoutData10Ms->AcmReceiver::GetAudio->NetEqImpl::GetAudio->NetEqImpl::GetAudioInternal -> NetEqImpl::Decode -> NetEqImpl::DecodeLoop

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值