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

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

Issue 2341713002: Use sps and pps to determine decodability of H.264 frames. (Closed)
Patch Set: comments addressed. 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
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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: 507 case H264::NaluType::kSei:
506 FALLTHROUGH(); 508 FALLTHROUGH();
507 case H264::NaluType::kIdr: 509 case H264::NaluType::kIdr:
508 parsed_payload->frame_type = kVideoFrameKey; 510 parsed_payload->frame_type = kVideoFrameKey;
509 FALLTHROUGH(); 511 FALLTHROUGH();
510 default: { 512 default: {
511 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice( 513 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice(
512 &payload_data[start_offset], end_offset - start_offset); 514 &payload_data[start_offset], end_offset - start_offset);
513 if (pps_id) 515 if (pps_id) {
514 nalu.pps_id = *pps_id; 516 nalu.pps_id = *pps_id;
517 } else {
518 LOG(LS_WARNING) << "Failed to parse PPS id from slice of type: "
519 << static_cast<int>(nalu.type);
520 }
515 break; 521 break;
516 } 522 }
517 } 523 }
518 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264; 524 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264;
519 if (h264->nalus_length == kMaxNalusPerPacket) { 525 if (h264->nalus_length == kMaxNalusPerPacket) {
520 LOG(LS_WARNING) 526 LOG(LS_WARNING)
521 << "Received packet containing more than " << kMaxNalusPerPacket 527 << "Received packet containing more than " << kMaxNalusPerPacket
522 << " NAL units. Will not keep track sps and pps ids for all of them."; 528 << " NAL units. Will not keep track sps and pps ids for all of them.";
523 } else { 529 } else {
524 h264->nalus[h264->nalus_length++] = nalu; 530 h264->nalus[h264->nalus_length++] = nalu;
(...skipping 15 matching lines...) Expand all
540 bool first_fragment = (payload_data[1] & kSBit) > 0; 546 bool first_fragment = (payload_data[1] & kSBit) > 0;
541 NaluInfo nalu; 547 NaluInfo nalu;
542 nalu.type = original_nal_type; 548 nalu.type = original_nal_type;
543 nalu.sps_id = -1; 549 nalu.sps_id = -1;
544 nalu.pps_id = -1; 550 nalu.pps_id = -1;
545 if (first_fragment) { 551 if (first_fragment) {
546 offset_ = 0; 552 offset_ = 0;
547 length_ -= kNalHeaderSize; 553 length_ -= kNalHeaderSize;
548 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice( 554 rtc::Optional<uint32_t> pps_id = PpsParser::ParsePpsIdFromSlice(
549 payload_data + 2 * kNalHeaderSize, length_ - kNalHeaderSize); 555 payload_data + 2 * kNalHeaderSize, length_ - kNalHeaderSize);
550 if (pps_id) 556 if (pps_id) {
551 nalu.pps_id = *pps_id; 557 nalu.pps_id = *pps_id;
558 } else {
559 LOG(LS_WARNING) << "Failed to parse PPS from first fragment of FU-A NAL "
560 "unit with original type: "
561 << static_cast<int>(nalu.type);
562 }
552 uint8_t original_nal_header = fnri | original_nal_type; 563 uint8_t original_nal_header = fnri | original_nal_type;
553 modified_buffer_.reset(new rtc::Buffer()); 564 modified_buffer_.reset(new rtc::Buffer());
554 modified_buffer_->AppendData(payload_data + kNalHeaderSize, length_); 565 modified_buffer_->AppendData(payload_data + kNalHeaderSize, length_);
555 (*modified_buffer_)[0] = original_nal_header; 566 (*modified_buffer_)[0] = original_nal_header;
556 } else { 567 } else {
557 offset_ = kFuAHeaderSize; 568 offset_ = kFuAHeaderSize;
558 length_ -= kFuAHeaderSize; 569 length_ -= kFuAHeaderSize;
559 } 570 }
560 571
561 if (original_nal_type == H264::NaluType::kIdr) { 572 if (original_nal_type == H264::NaluType::kIdr) {
562 parsed_payload->frame_type = kVideoFrameKey; 573 parsed_payload->frame_type = kVideoFrameKey;
563 } else { 574 } else {
564 parsed_payload->frame_type = kVideoFrameDelta; 575 parsed_payload->frame_type = kVideoFrameDelta;
565 } 576 }
566 parsed_payload->type.Video.width = 0; 577 parsed_payload->type.Video.width = 0;
567 parsed_payload->type.Video.height = 0; 578 parsed_payload->type.Video.height = 0;
568 parsed_payload->type.Video.codec = kRtpVideoH264; 579 parsed_payload->type.Video.codec = kRtpVideoH264;
569 parsed_payload->type.Video.isFirstPacket = first_fragment; 580 parsed_payload->type.Video.isFirstPacket = first_fragment;
570 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264; 581 RTPVideoHeaderH264* h264 = &parsed_payload->type.Video.codecHeader.H264;
571 h264->packetization_type = kH264FuA; 582 h264->packetization_type = kH264FuA;
572 h264->nalu_type = original_nal_type; 583 h264->nalu_type = original_nal_type;
573 h264->nalus[h264->nalus_length] = nalu; 584 if (first_fragment) {
574 h264->nalus_length = 1; 585 h264->nalus[h264->nalus_length] = nalu;
586 h264->nalus_length = 1;
587 }
575 return true; 588 return true;
576 } 589 }
577 590
578 } // namespace webrtc 591 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698