Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc |
| index 2f3feb34cd3851f53da1bbda45d5f90a9f575bd8..e8adb6c97aba3aef886ecbd00bcd5d5e0fac003b 100644 |
| --- a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc |
| +++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc |
| @@ -313,4 +313,99 @@ bool RepairedRtpStreamId::Write(uint8_t* data, const std::string& rsid) { |
| return RtpStreamId::Write(data, rsid); |
| } |
| +// For Frame Marking RTP Header Extension: |
| +// |
| +// https://tools.ietf.org/html/draft-ietf-avtext-framemarking-04#page-4 |
| +// This extensions provides meta-information about the RTP streams outside the |
| +// encrypted media payload, an RTP switch can do codec-agnostic |
| +// selective forwarding without decrypting the payload. |
| +// |
| +// for Non-Scalable Streams: |
| +// |
| +// 0 1 |
| +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// | ID=? | L=0 |S|E|I|D|0 0 0 0| |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// |
| +// for Scalable Streams: |
| +// |
| +// 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 |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// | ID=? | L=2 |S|E|I|D|B| TID | LID | TL0PICIDX | |
| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| +// |
| +constexpr RTPExtensionType FrameMarking::kId; |
| +constexpr const char* FrameMarking::kUri; |
| + |
| +bool FrameMarking::Parse(rtc::ArrayView<const uint8_t> data, |
| + FrameMarks* frame_marks) { |
| + RTC_DCHECK(frame_marks); |
| + |
| + if (data.empty()) |
| + return false; |
| + |
| + // Set frame marking data |
| + frame_marks->start_of_frame = (data[0] & 0x80) != 0; |
| + frame_marks->end_of_frame = (data[0] & 0x40) != 0; |
| + frame_marks->independent = (data[0] & 0x20) != 0; |
| + frame_marks->discardable = (data[0] & 0x10) != 0; |
| + |
| + // Check variable length. |
| + if (data.size() == 1) { |
| + // We are non-scalable. |
| + frame_marks->base_layer_sync = 0; |
|
danilchap
2017/06/29 13:47:26
may be = false
sergio.garcia.murillo
2017/06/30 10:09:23
Done.
|
| + frame_marks->temporal_layer_id = 0; |
| + frame_marks->spatial_layer_id = 0; |
| + frame_marks->tl0_pic_idx = 0; |
| + } else if (data.size() == 3) { |
| + // Set scalable parts |
| + frame_marks->base_layer_sync = (data[0] & 0x08) != 0; |
| + frame_marks->temporal_layer_id = (data[0] & 0x07) != 0; |
| + frame_marks->spatial_layer_id = data[1]; |
| + frame_marks->tl0_pic_idx = data[2]; |
| + } else { |
| + // Incorrect length. |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +size_t FrameMarking::ValueSize(const FrameMarks& frame_marks) { |
| + // Check if it is scalable. |
| + if (frame_marks.base_layer_sync || |
| + (frame_marks.temporal_layer_id && |
| + frame_marks.temporal_layer_id != kNoTemporalIdx) || |
| + (frame_marks.spatial_layer_id && |
| + frame_marks.spatial_layer_id != kNoSpatialIdx) || |
| + (frame_marks.tl0_pic_idx && |
| + frame_marks.tl0_pic_idx != (uint8_t)kNoTl0PicIdx)) |
| + return 3; |
| + else |
| + return 1; |
| +} |
| + |
| +bool FrameMarking::Write(uint8_t* data, const FrameMarks& frame_marks) { |
| + data[0] = frame_marks.start_of_frame ? 0x80 : 0x00; |
| + data[0] |= frame_marks.end_of_frame ? 0x40 : 0x00; |
| + data[0] |= frame_marks.independent ? 0x20 : 0x00; |
| + data[0] |= frame_marks.discardable ? 0x10 : 0x00; |
| + |
| + // Check if it is scalable. |
| + if (frame_marks.base_layer_sync || |
| + (frame_marks.temporal_layer_id && |
| + frame_marks.temporal_layer_id != kNoTemporalIdx) || |
| + (frame_marks.spatial_layer_id && |
| + frame_marks.spatial_layer_id != kNoSpatialIdx) || |
| + (frame_marks.tl0_pic_idx && |
| + frame_marks.tl0_pic_idx != static_cast<uint8_t>(kNoTl0PicIdx))) { |
| + data[0] |= frame_marks.base_layer_sync ? 0x08 : 0x00; |
| + data[0] |= (frame_marks.temporal_layer_id & 0x07); |
| + data[1] = frame_marks.spatial_layer_id; |
| + data[2] = frame_marks.tl0_pic_idx; |
| + } |
| + return true; |
| +} |
| + |
| } // namespace webrtc |