Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.cc b/webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ef5148c2a51871af96a76fd23679b61b9300662 |
| --- /dev/null |
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.cc |
| @@ -0,0 +1,108 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" |
| + |
| +#include "webrtc/base/checks.h" |
| +#include "webrtc/base/logging.h" |
| +#include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| + |
| +using webrtc::RTCPUtility::RtcpCommonHeader; |
| + |
| +namespace webrtc { |
| +namespace rtcp { |
| +const uint8_t Sli::kFeedbackMessageType; |
| + |
| +// RFC 4585: Feedback format. |
| +// |
| +// Common packet format: |
| +// |
| +// 0 1 2 3 |
| +// 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 |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// |V=2|P| FMT | PT | length | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// | SSRC of packet sender | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// | SSRC of media source | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// : Feedback Control Information (FCI) : |
| +// : : |
| +// |
| +// Slice loss indication (SLI) (RFC 4585). |
| +// FCI: |
| +// 0 1 2 3 |
| +// 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 |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// | First | Number | PictureID | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +Sli::Macroblocks::Macroblocks(uint8_t picture_id, |
| + uint16_t first, |
| + uint16_t count) { |
|
åsapersson
2016/01/11 12:13:54
call count -> number?
danilchap
2016/01/11 15:36:32
Done.
|
| + RTC_DCHECK_LE(first, 0x1fff); |
| + RTC_DCHECK_LE(count, 0x1fff); |
| + RTC_DCHECK_LE(picture_id, 0x3d); |
|
åsapersson
2016/01/11 12:13:54
3d -> 3f?
danilchap
2016/01/11 15:36:32
Done.
|
| + item_ = (first << 19) | (count << 6) | picture_id; |
| +} |
| +void Sli::Macroblocks::Parse(const uint8_t* buffer) { |
| + item_ = ByteReader<uint32_t>::ReadBigEndian(buffer); |
| +} |
| +void Sli::Macroblocks::Create(uint8_t* buffer) const { |
| + ByteWriter<uint32_t>::WriteBigEndian(buffer, item_); |
| +} |
| + |
| +bool Sli::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { |
| + RTC_DCHECK_EQ(header.packet_type, kPacketType); |
| + RTC_DCHECK_EQ(header.count_or_format, kFeedbackMessageType); |
| + |
| + if (header.payload_size_bytes < |
| + kCommonFeedbackLength + Macroblocks::kLength) { |
| + LOG(LS_WARNING) << "Packet is too small to be a valid SLI packet"; |
| + return false; |
| + } |
| + |
| + size_t macroblocks_number = |
|
åsapersson
2016/01/11 12:13:54
maybe items?
danilchap
2016/01/11 15:36:32
Done.
åsapersson
2016/01/12 12:35:26
maybe just items or num_items, number_of_items
danilchap
2016/01/12 12:56:35
Done. number_of_items is obviously more clear name
|
| + (header.payload_size_bytes - kCommonFeedbackLength) / |
| + Macroblocks::kLength; |
| + |
| + ParseCommonFeedback(payload); |
| + macroblocks_.resize(macroblocks_number); |
| + |
| + const uint8_t* next_fci_field = payload + kCommonFeedbackLength; |
| + for (Macroblocks& block : macroblocks_) { |
| + block.Parse(next_fci_field); |
| + next_fci_field += Macroblocks::kLength; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool Sli::Create(uint8_t* packet, |
| + size_t* index, |
| + size_t max_length, |
| + RtcpPacket::PacketReadyCallback* callback) const { |
| + RTC_DCHECK(!macroblocks_.empty()); |
|
åsapersson
2016/01/11 12:13:54
use RTC_CHECK here?
danilchap
2016/01/11 15:36:32
Done, but isn't it better to send invalid sli pack
åsapersson
2016/01/12 12:35:26
Ok, RTC_DCHECK might be better.
danilchap
2016/01/12 12:56:35
Reverted.
|
| + while (*index + BlockLength() > max_length) { |
| + if (!OnBufferFull(packet, index, callback)) |
| + return false; |
| + } |
| + CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, |
| + index); |
| + CreateCommonFeedback(packet + *index); |
| + *index += kCommonFeedbackLength; |
| + for (const Macroblocks& mb : macroblocks_) { |
| + mb.Create(packet + *index); |
| + *index += Macroblocks::kLength; |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace rtcp |
| +} // namespace webrtc |