Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc

Issue 2954503002: Implement FrameMarking header extension support
Patch Set: remove unneeded change in comment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 372 }
373 373
374 size_t RepairedRtpStreamId::ValueSize(const std::string& rsid) { 374 size_t RepairedRtpStreamId::ValueSize(const std::string& rsid) {
375 return RtpStreamId::ValueSize(rsid); 375 return RtpStreamId::ValueSize(rsid);
376 } 376 }
377 377
378 bool RepairedRtpStreamId::Write(uint8_t* data, const std::string& rsid) { 378 bool RepairedRtpStreamId::Write(uint8_t* data, const std::string& rsid) {
379 return RtpStreamId::Write(data, rsid); 379 return RtpStreamId::Write(data, rsid);
380 } 380 }
381 381
382 // For Frame Marking RTP Header Extension:
383 //
384 // https://tools.ietf.org/html/draft-ietf-avtext-framemarking-04#page-4
385 // This extensions provides meta-information about the RTP streams outside the
386 // encrypted media payload, an RTP switch can do codec-agnostic
387 // selective forwarding without decrypting the payload.
388 //
389 // for Non-Scalable Streams:
390 //
391 // 0 1
392 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
393 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
394 // | ID=? | L=0 |S|E|I|D|0 0 0 0|
395 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
396 //
397 // for Scalable Streams:
398 //
399 // 0 1 2 3
400 // 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
401 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
402 // | ID=? | L=2 |S|E|I|D|B| TID | LID | TL0PICIDX |
403 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
404 //
405 constexpr RTPExtensionType FrameMarking::kId;
406 constexpr const char* FrameMarking::kUri;
407
408 bool FrameMarking::Parse(rtc::ArrayView<const uint8_t> data,
409 FrameMarks* frame_marks) {
410 RTC_DCHECK(frame_marks);
411
412 if (data.empty())
413 return false;
414
415 // Set frame marking data
416 frame_marks->start_of_frame = (data[0] & 0x80) != 0;
417 frame_marks->end_of_frame = (data[0] & 0x40) != 0;
418 frame_marks->independent = (data[0] & 0x20) != 0;
419 frame_marks->discardable = (data[0] & 0x10) != 0;
420
421 // Check variable length.
422 if (data.size() == 1) {
423 // We are non-scalable.
424 frame_marks->base_layer_sync = false;
425 frame_marks->temporal_layer_id = 0;
426 frame_marks->layer_id = 0;
427 frame_marks->tl0_pic_idx = 0;
428 } else if (data.size() == 3) {
429 // Set scalable parts
430 frame_marks->base_layer_sync = (data[0] & 0x08) != 0;
431 frame_marks->temporal_layer_id = data[0] & 0x07;
432 frame_marks->layer_id = data[1];
433 frame_marks->tl0_pic_idx = data[2];
434 } else {
435 // Incorrect length.
436 return false;
437 }
438 return true;
439 }
440
441 bool FrameMarking::IsScalable(const FrameMarks& frame_marks) {
442 return (frame_marks.base_layer_sync ||
443 (frame_marks.temporal_layer_id &&
444 frame_marks.temporal_layer_id != kNoTemporalIdx) ||
445 (frame_marks.layer_id && frame_marks.layer_id != kNoSpatialIdx) ||
446 (frame_marks.tl0_pic_idx && frame_marks.tl0_pic_idx != kNoTl0PicIdx));
447 }
448
449 size_t FrameMarking::ValueSize(const FrameMarks& frame_marks) {
450 return IsScalable(frame_marks) ? 3 : 1;
451 }
452
453 bool FrameMarking::Write(uint8_t* data, const FrameMarks& frame_marks) {
454 data[0] = frame_marks.start_of_frame ? 0x80 : 0x00;
455 data[0] |= frame_marks.end_of_frame ? 0x40 : 0x00;
456 data[0] |= frame_marks.independent ? 0x20 : 0x00;
457 data[0] |= frame_marks.discardable ? 0x10 : 0x00;
458
459 // Check if it is scalable.
460 if (IsScalable(frame_marks)) {
461 data[0] |= frame_marks.base_layer_sync ? 0x08 : 0x00;
462 data[0] |= (frame_marks.temporal_layer_id & 0x07);
463 data[1] = frame_marks.layer_id;
464 data[2] = static_cast<uint8_t>(frame_marks.tl0_pic_idx);
465 }
466 return true;
467 }
468
469 uint8_t FrameMarking::CreateLayerId(const RTPVideoHeaderVP9& vp9) {
470 // The following shows VP9 Layer encoding information (3 bits for
471 // spatial and temporal layer) mapped to the generic LID and TID fields.
472 // The P and U bits MUST match the corresponding bits in the VP9 Payload
473 // Description.
474 // 0 1 2 3
475 // 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
476 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
477 // | ID=2 | L=2 |S|E|I|D|B| TID |0|0|0|P|U| SID | TL0PICIDX |
478 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
479 return (vp9.spatial_idx != kNoSpatialIdx ? vp9.spatial_idx & 0x07 : 0x00) |
480 (vp9.temporal_up_switch ? 0x08 : 0x00) |
481 (vp9.inter_pic_predicted ? 0x10 : 0x00);
482 }
483
382 } // namespace webrtc 484 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698