Avoid calling RtpFrameObject::GetCodecHeader twice in the RtpFrameReferenceFinder.

This is good for a few reasons:
 - We avoid grabing a lock twice.
 - We avoid an unnecessary copy.
 - We avoid a race where a packet could potentially be removed before the
   second time we call GetCodecHeader.

BUG=None

Review-Url: https://codereview.webrtc.org/3009833002
Cr-Commit-Position: refs/heads/master@{#19635}
diff --git a/webrtc/modules/video_coding/rtp_frame_reference_finder.cc b/webrtc/modules/video_coding/rtp_frame_reference_finder.cc
index 8d74c36..52947cb 100644
--- a/webrtc/modules/video_coding/rtp_frame_reference_finder.cc
+++ b/webrtc/modules/video_coding/rtp_frame_reference_finder.cc
@@ -285,7 +285,7 @@
   if (frame->frame_type() == kVideoFrameKey) {
     frame->num_references = 0;
     layer_info_[codec_header.tl0PicIdx].fill(-1);
-    UpdateLayerInfoVp8(frame);
+    UpdateLayerInfoVp8(frame, codec_header);
     return kHandOff;
   }
 
@@ -307,7 +307,7 @@
             .first;
     frame->num_references = 1;
     frame->references[0] = layer_info_it->second[0];
-    UpdateLayerInfoVp8(frame);
+    UpdateLayerInfoVp8(frame, codec_header);
     return kHandOff;
   }
 
@@ -316,7 +316,7 @@
     frame->num_references = 1;
     frame->references[0] = layer_info_it->second[0];
 
-    UpdateLayerInfoVp8(frame);
+    UpdateLayerInfoVp8(frame, codec_header);
     return kHandOff;
   }
 
@@ -359,15 +359,13 @@
     frame->references[layer] = layer_info_it->second[layer];
   }
 
-  UpdateLayerInfoVp8(frame);
+  UpdateLayerInfoVp8(frame, codec_header);
   return kHandOff;
 }
 
-void RtpFrameReferenceFinder::UpdateLayerInfoVp8(RtpFrameObject* frame) {
-  rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader();
-  RTC_DCHECK(rtp_codec_header);
-  const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8;
-
+void RtpFrameReferenceFinder::UpdateLayerInfoVp8(
+    RtpFrameObject* frame,
+    const RTPVideoHeaderVP8& codec_header) {
   uint8_t tl0_pic_idx = codec_header.tl0PicIdx;
   uint8_t temporal_index = codec_header.temporalIdx;
   auto layer_info_it = layer_info_.find(tl0_pic_idx);
@@ -394,7 +392,9 @@
 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9(
     RtpFrameObject* frame) {
   rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader();
-  RTC_DCHECK(rtp_codec_header);
+  if (!rtp_codec_header)
+    return kDrop;
+
   const RTPVideoHeaderVP9& codec_header = rtp_codec_header->VP9;
 
   if (codec_header.picture_id == kNoPictureId ||
diff --git a/webrtc/modules/video_coding/rtp_frame_reference_finder.h b/webrtc/modules/video_coding/rtp_frame_reference_finder.h
index 74db45a..f31ee64 100644
--- a/webrtc/modules/video_coding/rtp_frame_reference_finder.h
+++ b/webrtc/modules/video_coding/rtp_frame_reference_finder.h
@@ -99,7 +99,8 @@
 
   // Updates necessary layer info state used to determine frame references for
   // Vp8.
-  void UpdateLayerInfoVp8(RtpFrameObject* frame)
+  void UpdateLayerInfoVp8(RtpFrameObject* frame,
+                          const RTPVideoHeaderVP8& codec_header)
       EXCLUSIVE_LOCKS_REQUIRED(crit_);
 
   // Find references for Vp9 frames