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