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

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

Issue 2385143002: Revert "Revert of Use sps and pps to determine decodability of H.264 frames. (patchset #4 id:60001 … (Closed)
Patch Set: Add unittest. Created 4 years, 2 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 RTC_HISTOGRAM_ENUMERATION(kSpsValidHistogramName, 477 RTC_HISTOGRAM_ENUMERATION(kSpsValidHistogramName,
478 SpsValidEvent::kReceivedSpsParseFailure, 478 SpsValidEvent::kReceivedSpsParseFailure,
479 SpsValidEvent::kSpsRewrittenMax); 479 SpsValidEvent::kSpsRewrittenMax);
480 break; 480 break;
481 } 481 }
482 482
483 if (sps) { 483 if (sps) {
484 parsed_payload->type.Video.width = sps->width; 484 parsed_payload->type.Video.width = sps->width;
485 parsed_payload->type.Video.height = sps->height; 485 parsed_payload->type.Video.height = sps->height;
486 nalu.sps_id = sps->id; 486 nalu.sps_id = sps->id;
487 } else {
488 LOG(LS_WARNING) << "Failed to parse SPS id from SPS slice.";
487 } 489 }
488 parsed_payload->frame_type = kVideoFrameKey; 490 parsed_payload->frame_type = kVideoFrameKey;
489 break; 491 break;
490 } 492 }
491 case H264::NaluType::kPps: { 493 case H264::NaluType::kPps: {
492 uint32_t pps_id; 494 uint32_t pps_id;
493 uint32_t sps_id; 495 uint32_t sps_id;
494 if (PpsParser::ParsePpsIds(&payload_data[start_offset], 496 if (PpsParser::ParsePpsIds(&payload_data[start_offset],
495 end_offset - start_offset, &pps_id, 497 end_offset - start_offset, &pps_id,
496 &sps_id)) { 498 &sps_id)) {
497 nalu.pps_id = pps_id; 499 nalu.pps_id = pps_id;
498 nalu.sps_id = sps_id; 500 nalu.sps_id = sps_id;
499 } else { 501 } else {
500 LOG(LS_WARNING) 502 LOG(LS_WARNING)
501 << "Failed to parse PPS id and SPS id from PPS slice."; 503 << "Failed to parse PPS id and SPS id from PPS slice.";
502 } 504 }
503 break; 505 break;
504 } 506 }
505 case H264::NaluType::kSei:
506 FALLTHROUGH();
507 case H264::NaluType::kIdr: 507 case H264::NaluType::kIdr:
508 parsed_payload->frame_type = kVideoFrameKey; 508 parsed_payload->frame_type = kVideoFrameKey;
509 FALLTHROUGH(); 509 FALLTHROUGH();
510 default: { 510 case H264::NaluType::kSlice: {
511 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice( 511 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice(
512 &payload_data[start_offset], end_offset - start_offset); 512 &payload_data[start_offset], end_offset - start_offset);
513 if (pps_id) 513 if (pps_id) {
514 nalu.pps_id = *pps_id; 514 nalu.pps_id = *pps_id;
515 } else {
516 LOG(LS_WARNING) << "Failed to parse PPS id from slice of type: "
517 << static_cast<int>(nalu.type);
518 }
515 break; 519 break;
516 } 520 }
521 // Slices below don't contain SPS or PPS ids.
522 case H264::NaluType::kAud:
523 case H264::NaluType::kEndOfSequence:
524 case H264::NaluType::kEndOfStream:
525 case H264::NaluType::kFiller:
526 break;
527 case H264::NaluType::kSei:
528 parsed_payload->frame_type = kVideoFrameKey;
529 break;
530 case H264::NaluType::kStapA:
531 case H264::NaluType::kFuA:
532 RTC_NOTREACHED();
517 } 533 }
518 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264; 534 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264;
519 if (h264->nalus_length == kMaxNalusPerPacket) { 535 if (h264->nalus_length == kMaxNalusPerPacket) {
520 LOG(LS_WARNING) 536 LOG(LS_WARNING)
521 << "Received packet containing more than " << kMaxNalusPerPacket 537 << "Received packet containing more than " << kMaxNalusPerPacket
522 << " NAL units. Will not keep track sps and pps ids for all of them."; 538 << " NAL units. Will not keep track sps and pps ids for all of them.";
523 } else { 539 } else {
524 h264->nalus[h264->nalus_length++] = nalu; 540 h264->nalus[h264->nalus_length++] = nalu;
525 } 541 }
526 } 542 }
(...skipping 13 matching lines...) Expand all
540 bool first_fragment = (payload_data[1] & kSBit) > 0; 556 bool first_fragment = (payload_data[1] & kSBit) > 0;
541 NaluInfo nalu; 557 NaluInfo nalu;
542 nalu.type = original_nal_type; 558 nalu.type = original_nal_type;
543 nalu.sps_id = -1; 559 nalu.sps_id = -1;
544 nalu.pps_id = -1; 560 nalu.pps_id = -1;
545 if (first_fragment) { 561 if (first_fragment) {
546 offset_ = 0; 562 offset_ = 0;
547 length_ -= kNalHeaderSize; 563 length_ -= kNalHeaderSize;
548 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice( 564 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice(
549 payload_data + 2 * kNalHeaderSize, length_ - kNalHeaderSize); 565 payload_data + 2 * kNalHeaderSize, length_ - kNalHeaderSize);
550 if (pps_id) 566 if (pps_id) {
551 nalu.pps_id = *pps_id; 567 nalu.pps_id = *pps_id;
568 } else {
569 LOG(LS_WARNING) << "Failed to parse PPS from first fragment of FU-A NAL "
570 "unit with original type: "
571 << static_cast<int>(nalu.type);
572 }
552 uint8_t original_nal_header = fnri | original_nal_type; 573 uint8_t original_nal_header = fnri | original_nal_type;
553 modified_buffer_.reset(new rtc::Buffer()); 574 modified_buffer_.reset(new rtc::Buffer());
554 modified_buffer_->AppendData(payload_data + kNalHeaderSize, length_); 575 modified_buffer_->AppendData(payload_data + kNalHeaderSize, length_);
555 (*modified_buffer_)[0] = original_nal_header; 576 (*modified_buffer_)[0] = original_nal_header;
556 } else { 577 } else {
557 offset_ = kFuAHeaderSize; 578 offset_ = kFuAHeaderSize;
558 length_ -= kFuAHeaderSize; 579 length_ -= kFuAHeaderSize;
559 } 580 }
560 581
561 if (original_nal_type == H264::NaluType::kIdr) { 582 if (original_nal_type == H264::NaluType::kIdr) {
562 parsed_payload->frame_type = kVideoFrameKey; 583 parsed_payload->frame_type = kVideoFrameKey;
563 } else { 584 } else {
564 parsed_payload->frame_type = kVideoFrameDelta; 585 parsed_payload->frame_type = kVideoFrameDelta;
565 } 586 }
566 parsed_payload->type.Video.width = 0; 587 parsed_payload->type.Video.width = 0;
567 parsed_payload->type.Video.height = 0; 588 parsed_payload->type.Video.height = 0;
568 parsed_payload->type.Video.codec = kRtpVideoH264; 589 parsed_payload->type.Video.codec = kRtpVideoH264;
569 parsed_payload->type.Video.isFirstPacket = first_fragment; 590 parsed_payload->type.Video.isFirstPacket = first_fragment;
570 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264; 591 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264;
571 h264->packetization_type = kH264FuA; 592 h264->packetization_type = kH264FuA;
572 h264->nalu_type = original_nal_type; 593 h264->nalu_type = original_nal_type;
573 h264->nalus[h264->nalus_length] = nalu; 594 if (first_fragment) {
574 h264->nalus_length = 1; 595 h264->nalus[h264->nalus_length] = nalu;
596 h264->nalus_length = 1;
597 }
575 return true; 598 return true;
576 } 599 }
577 600
578 } // namespace webrtc 601 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698