| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 | 903 |
| 904 // add CSRCs | 904 // add CSRCs |
| 905 for (size_t i = 0; i < csrcs_.size(); i++) | 905 for (size_t i = 0; i < csrcs_.size(); i++) |
| 906 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), csrcs_[i]); | 906 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), csrcs_[i]); |
| 907 | 907 |
| 908 return BuildResult::kSuccess; | 908 return BuildResult::kSuccess; |
| 909 } | 909 } |
| 910 | 910 |
| 911 RTCPSender::BuildResult RTCPSender::BuildReceiverReferenceTime( | 911 RTCPSender::BuildResult RTCPSender::BuildReceiverReferenceTime( |
| 912 RtcpContext* ctx) { | 912 RtcpContext* ctx) { |
| 913 const int kRrTimeBlockLength = 20; | |
| 914 if (ctx->position + kRrTimeBlockLength >= IP_PACKET_SIZE) | |
| 915 return BuildResult::kTruncated; | |
| 916 | 913 |
| 917 if (last_xr_rr_.size() >= RTCP_NUMBER_OF_SR) | 914 if (last_xr_rr_.size() >= RTCP_NUMBER_OF_SR) |
| 918 last_xr_rr_.erase(last_xr_rr_.begin()); | 915 last_xr_rr_.erase(last_xr_rr_.begin()); |
| 919 last_xr_rr_.insert(std::pair<uint32_t, int64_t>( | 916 last_xr_rr_.insert(std::pair<uint32_t, int64_t>( |
| 920 RTCPUtility::MidNtp(ctx->ntp_sec, ctx->ntp_frac), | 917 RTCPUtility::MidNtp(ctx->ntp_sec, ctx->ntp_frac), |
| 921 Clock::NtpToMs(ctx->ntp_sec, ctx->ntp_frac))); | 918 Clock::NtpToMs(ctx->ntp_sec, ctx->ntp_frac))); |
| 922 | 919 |
| 923 // Add XR header. | 920 rtcp::Xr xr; |
| 924 *ctx->AllocateData(1) = 0x80; | 921 xr.From(ssrc_); |
| 925 *ctx->AllocateData(1) = 207; | |
| 926 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 927 4); // XR packet length. | |
| 928 | 922 |
| 929 // Add our own SSRC. | 923 rtcp::Rrtr rrtr; |
| 930 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_); | 924 rrtr.WithNtpSec(ctx->ntp_sec); |
| 925 rrtr.WithNtpFrac(ctx->ntp_frac); |
| 931 | 926 |
| 932 // 0 1 2 3 | 927 xr.WithRrtr(&rrtr); |
| 933 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
| 934 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 935 // | BT=4 | reserved | block length = 2 | | |
| 936 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 937 // | NTP timestamp, most significant word | | |
| 938 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 939 // | NTP timestamp, least significant word | | |
| 940 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 941 | 928 |
| 942 // Add Receiver Reference Time Report block. | 929 // TODO(sprang): Merge XR report sending to contain all of RRTR, DLRR, VOIP? |
| 943 *ctx->AllocateData(1) = 4; // BT. | |
| 944 *ctx->AllocateData(1) = 0; // Reserved. | |
| 945 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 946 2); // Block length. | |
| 947 | 930 |
| 948 // NTP timestamp. | 931 PacketBuiltCallback callback(ctx); |
| 949 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ctx->ntp_sec); | 932 if (!callback.BuildPacket(xr)) |
| 950 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ctx->ntp_frac); | 933 return BuildResult::kTruncated; |
| 951 | 934 |
| 952 return BuildResult::kSuccess; | 935 return BuildResult::kSuccess; |
| 953 } | 936 } |
| 954 | 937 |
| 955 RTCPSender::BuildResult RTCPSender::BuildDlrr(RtcpContext* ctx) { | 938 RTCPSender::BuildResult RTCPSender::BuildDlrr(RtcpContext* ctx) { |
| 956 const int kDlrrBlockLength = 24; | 939 rtcp::Xr xr; |
| 957 if (ctx->position + kDlrrBlockLength >= IP_PACKET_SIZE) | 940 xr.From(ssrc_); |
| 941 |
| 942 rtcp::Dlrr dlrr; |
| 943 const RtcpReceiveTimeInfo& info = ctx->feedback_state.last_xr_rr; |
| 944 dlrr.WithDlrrItem(info.sourceSSRC, info.lastRR, info.delaySinceLastRR); |
| 945 |
| 946 xr.WithDlrr(&dlrr); |
| 947 |
| 948 PacketBuiltCallback callback(ctx); |
| 949 if (!callback.BuildPacket(xr)) |
| 958 return BuildResult::kTruncated; | 950 return BuildResult::kTruncated; |
| 959 | 951 |
| 960 // Add XR header. | |
| 961 *ctx->AllocateData(1) = 0x80; | |
| 962 *ctx->AllocateData(1) = 207; | |
| 963 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 964 5); // XR packet length. | |
| 965 | |
| 966 // Add our own SSRC. | |
| 967 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_); | |
| 968 | |
| 969 // 0 1 2 3 | |
| 970 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
| 971 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 972 // | BT=5 | reserved | block length | | |
| 973 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | |
| 974 // | SSRC_1 (SSRC of first receiver) | sub- | |
| 975 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block | |
| 976 // | last RR (LRR) | 1 | |
| 977 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 978 // | delay since last RR (DLRR) | | |
| 979 // +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | |
| 980 // | SSRC_2 (SSRC of second receiver) | sub- | |
| 981 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block | |
| 982 // : ... : 2 | |
| 983 | |
| 984 // Add DLRR sub block. | |
| 985 *ctx->AllocateData(1) = 5; // BT. | |
| 986 *ctx->AllocateData(1) = 0; // Reserved. | |
| 987 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 988 3); // Block length. | |
| 989 | |
| 990 // NTP timestamp. | |
| 991 | |
| 992 const RtcpReceiveTimeInfo& info = ctx->feedback_state.last_xr_rr; | |
| 993 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), info.sourceSSRC); | |
| 994 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), info.lastRR); | |
| 995 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), | |
| 996 info.delaySinceLastRR); | |
| 997 | |
| 998 return BuildResult::kSuccess; | 952 return BuildResult::kSuccess; |
| 999 } | 953 } |
| 1000 | 954 |
| 1001 // TODO(sprang): Add a unit test for this, or remove if the code isn't used. | 955 // TODO(sprang): Add a unit test for this, or remove if the code isn't used. |
| 1002 RTCPSender::BuildResult RTCPSender::BuildVoIPMetric(RtcpContext* ctx) { | 956 RTCPSender::BuildResult RTCPSender::BuildVoIPMetric(RtcpContext* ctx) { |
| 1003 // sanity | 957 rtcp::Xr xr; |
| 1004 if (ctx->position + 44 >= IP_PACKET_SIZE) | 958 xr.From(ssrc_); |
| 959 |
| 960 rtcp::VoipMetric voip; |
| 961 voip.To(remote_ssrc_); |
| 962 voip.LossRate(xr_voip_metric_.lossRate); |
| 963 voip.DiscardRate(xr_voip_metric_.discardRate); |
| 964 voip.BurstDensity(xr_voip_metric_.burstDensity); |
| 965 voip.GapDensity(xr_voip_metric_.gapDensity); |
| 966 voip.BurstDuration(xr_voip_metric_.burstDuration); |
| 967 voip.GapDuration(xr_voip_metric_.gapDuration); |
| 968 voip.RoundTripDelay(xr_voip_metric_.roundTripDelay); |
| 969 voip.EndSystemDelay(xr_voip_metric_.endSystemDelay); |
| 970 voip.SignalLevel(xr_voip_metric_.signalLevel); |
| 971 voip.NoiseLevel(xr_voip_metric_.noiseLevel); |
| 972 voip.Rerl(xr_voip_metric_.RERL); |
| 973 voip.Gmin(xr_voip_metric_.Gmin); |
| 974 voip.Rfactor(xr_voip_metric_.Rfactor); |
| 975 voip.ExtRfactor(xr_voip_metric_.extRfactor); |
| 976 voip.MosLq(xr_voip_metric_.MOSLQ); |
| 977 voip.MosCq(xr_voip_metric_.MOSCQ); |
| 978 voip.RxConfig(xr_voip_metric_.RXconfig); |
| 979 voip.JbNominal(xr_voip_metric_.JBnominal); |
| 980 voip.JbMax(xr_voip_metric_.JBmax); |
| 981 voip.JbAbsMax(xr_voip_metric_.JBabsMax); |
| 982 |
| 983 xr.WithVoipMetric(&voip); |
| 984 |
| 985 PacketBuiltCallback callback(ctx); |
| 986 if (!callback.BuildPacket(xr)) |
| 1005 return BuildResult::kTruncated; | 987 return BuildResult::kTruncated; |
| 1006 | 988 |
| 1007 // Add XR header | |
| 1008 *ctx->AllocateData(1) = 0x80; | |
| 1009 *ctx->AllocateData(1) = 207; | |
| 1010 | |
| 1011 uint32_t XRLengthPos = ctx->position; | |
| 1012 | |
| 1013 // handle length later on | |
| 1014 ctx->AllocateData(2); | |
| 1015 | |
| 1016 // Add our own SSRC | |
| 1017 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_); | |
| 1018 | |
| 1019 // Add a VoIP metrics block | |
| 1020 *ctx->AllocateData(1) = 7; | |
| 1021 *ctx->AllocateData(1) = 0; | |
| 1022 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), 8); | |
| 1023 | |
| 1024 // Add the remote SSRC | |
| 1025 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), remote_ssrc_); | |
| 1026 | |
| 1027 *ctx->AllocateData(1) = xr_voip_metric_.lossRate; | |
| 1028 *ctx->AllocateData(1) = xr_voip_metric_.discardRate; | |
| 1029 *ctx->AllocateData(1) = xr_voip_metric_.burstDensity; | |
| 1030 *ctx->AllocateData(1) = xr_voip_metric_.gapDensity; | |
| 1031 | |
| 1032 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1033 xr_voip_metric_.burstDuration); | |
| 1034 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1035 xr_voip_metric_.gapDuration); | |
| 1036 | |
| 1037 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1038 xr_voip_metric_.roundTripDelay); | |
| 1039 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1040 xr_voip_metric_.endSystemDelay); | |
| 1041 | |
| 1042 *ctx->AllocateData(1) = xr_voip_metric_.signalLevel; | |
| 1043 *ctx->AllocateData(1) = xr_voip_metric_.noiseLevel; | |
| 1044 *ctx->AllocateData(1) = xr_voip_metric_.RERL; | |
| 1045 *ctx->AllocateData(1) = xr_voip_metric_.Gmin; | |
| 1046 | |
| 1047 *ctx->AllocateData(1) = xr_voip_metric_.Rfactor; | |
| 1048 *ctx->AllocateData(1) = xr_voip_metric_.extRfactor; | |
| 1049 *ctx->AllocateData(1) = xr_voip_metric_.MOSLQ; | |
| 1050 *ctx->AllocateData(1) = xr_voip_metric_.MOSCQ; | |
| 1051 | |
| 1052 *ctx->AllocateData(1) = xr_voip_metric_.RXconfig; | |
| 1053 *ctx->AllocateData(1) = 0; // reserved | |
| 1054 | |
| 1055 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1056 xr_voip_metric_.JBnominal); | |
| 1057 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1058 xr_voip_metric_.JBmax); | |
| 1059 ByteWriter<uint16_t>::WriteBigEndian(ctx->AllocateData(2), | |
| 1060 xr_voip_metric_.JBabsMax); | |
| 1061 | |
| 1062 ByteWriter<uint16_t>::WriteBigEndian(&ctx->buffer[XRLengthPos], 10); | |
| 1063 | |
| 1064 return BuildResult::kSuccess; | 989 return BuildResult::kSuccess; |
| 1065 } | 990 } |
| 1066 | 991 |
| 1067 int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state, | 992 int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state, |
| 1068 RTCPPacketType packetType, | 993 RTCPPacketType packetType, |
| 1069 int32_t nack_size, | 994 int32_t nack_size, |
| 1070 const uint16_t* nack_list, | 995 const uint16_t* nack_list, |
| 1071 bool repeat, | 996 bool repeat, |
| 1072 uint64_t pictureID) { | 997 uint64_t pictureID) { |
| 1073 return SendCompoundRTCP( | 998 return SendCompoundRTCP( |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 | 1273 |
| 1349 bool RTCPSender::AllVolatileFlagsConsumed() const { | 1274 bool RTCPSender::AllVolatileFlagsConsumed() const { |
| 1350 for (const ReportFlag& flag : report_flags_) { | 1275 for (const ReportFlag& flag : report_flags_) { |
| 1351 if (flag.is_volatile) | 1276 if (flag.is_volatile) |
| 1352 return false; | 1277 return false; |
| 1353 } | 1278 } |
| 1354 return true; | 1279 return true; |
| 1355 } | 1280 } |
| 1356 | 1281 |
| 1357 } // namespace webrtc | 1282 } // namespace webrtc |
| OLD | NEW |