Breaking out RTP header parsing from the RTP module.

This is the first step in order to move bandwidth estimation closer to the network. The goal is to have RTP header parsing and bandwidth estimation before voice and video engine, and have a joint estimate for audio and video.

Moving bandwidth estimation before the RTP module is also required for RTX.

TEST=vie_auto_test, voe_auto_test, trybots.
BUG=1811
R=andresp@webrtc.org, henrika@webrtc.org, mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1545004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4129 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
index bda7f12..ebcfe05 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
@@ -565,77 +565,56 @@
 }
 
 // Called by the network module when we receive a packet.
-int32_t ModuleRtpRtcpImpl::IncomingPacket(
+int32_t ModuleRtpRtcpImpl::IncomingRtpPacket(
     const uint8_t* incoming_packet,
-    const uint16_t incoming_packet_length) {
+    const uint16_t incoming_packet_length,
+    const RTPHeader& parsed_rtp_header) {
   WEBRTC_TRACE(kTraceStream,
                kTraceRtpRtcp,
                id_,
-               "IncomingPacket(packet_length:%u)",
+               "IncomingRtpPacket(packet_length:%u)",
                incoming_packet_length);
+  RTPHeader rtp_header_copy = parsed_rtp_header;
+  return rtp_receiver_->IncomingRTPPacket(&rtp_header_copy,
+                                          incoming_packet,
+                                          incoming_packet_length);
+}
+
+int32_t ModuleRtpRtcpImpl::IncomingRtcpPacket(
+    const uint8_t* rtcp_packet,
+    const uint16_t length) {
+  WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, -1,
+               "IncomingRtcpPacket(packet_length:%u)", length);
   // Minimum RTP is 12 bytes.
   // Minimum RTCP is 8 bytes (RTCP BYE).
-  if (incoming_packet_length < 8 || incoming_packet == NULL) {
-    WEBRTC_TRACE(kTraceDebug,
-                 kTraceRtpRtcp,
-                 id_,
-                 "IncomingPacket invalid buffer or length");
-    return -1;
+  if (length == 8) {
+    WEBRTC_TRACE(kTraceDebug, kTraceRtpRtcp, -1,
+                 "IncomingRtcpPacket invalid length");
+    return false;
   }
   // Check RTP version.
-  const uint8_t version = incoming_packet[0] >> 6;
+  const uint8_t version = rtcp_packet[0] >> 6;
   if (version != 2) {
-    WEBRTC_TRACE(kTraceDebug,
-                 kTraceRtpRtcp,
-                 id_,
-                 "IncomingPacket invalid RTP version");
+    WEBRTC_TRACE(kTraceDebug, kTraceRtpRtcp, -1,
+                 "IncomingRtcpPacket invalid RTP version");
+    return false;
+  }
+  // Allow receive of non-compound RTCP packets.
+  RTCPUtility::RTCPParserV2 rtcp_parser(rtcp_packet, length, true);
+
+  const bool valid_rtcpheader = rtcp_parser.IsValid();
+  if (!valid_rtcpheader) {
+    WEBRTC_TRACE(kTraceDebug, kTraceRtpRtcp, id_,
+                 "IncomingRtcpPacket invalid RTCP packet");
     return -1;
   }
-
-  ModuleRTPUtility::RTPHeaderParser rtp_parser(incoming_packet,
-                                               incoming_packet_length);
-
-  if (rtp_parser.RTCP()) {
-    // Allow receive of non-compound RTCP packets.
-    RTCPUtility::RTCPParserV2 rtcp_parser(incoming_packet,
-                                          incoming_packet_length,
-                                          true);
-
-    const bool valid_rtcpheader = rtcp_parser.IsValid();
-    if (!valid_rtcpheader) {
-      WEBRTC_TRACE(kTraceDebug,
-                   kTraceRtpRtcp,
-                   id_,
-                   "IncomingPacket invalid RTCP packet");
-      return -1;
-    }
-    RTCPHelp::RTCPPacketInformation rtcp_packet_information;
-    int32_t ret_val = rtcp_receiver_.IncomingRTCPPacket(
-        rtcp_packet_information, &rtcp_parser);
-    if (ret_val == 0) {
-      rtcp_receiver_.TriggerCallbacksFromRTCPPacket(rtcp_packet_information);
-    }
-    return ret_val;
-
-  } else {
-    WebRtcRTPHeader rtp_header;
-    memset(&rtp_header, 0, sizeof(rtp_header));
-
-    RtpHeaderExtensionMap map;
-    rtp_receiver_->GetHeaderExtensionMapCopy(&map);
-
-    const bool valid_rtpheader = rtp_parser.Parse(rtp_header, &map);
-    if (!valid_rtpheader) {
-      WEBRTC_TRACE(kTraceDebug,
-                   kTraceRtpRtcp,
-                   id_,
-                   "IncomingPacket invalid RTP header");
-      return -1;
-    }
-    return rtp_receiver_->IncomingRTPPacket(&rtp_header,
-                                            incoming_packet,
-                                            incoming_packet_length);
+  RTCPHelp::RTCPPacketInformation rtcp_packet_information;
+  int32_t ret_val = rtcp_receiver_.IncomingRTCPPacket(
+      rtcp_packet_information, &rtcp_parser);
+  if (ret_val == 0) {
+    rtcp_receiver_.TriggerCallbacksFromRTCPPacket(rtcp_packet_information);
   }
+  return ret_val;
 }
 
 int32_t ModuleRtpRtcpImpl::RegisterSendPayload(
@@ -1434,17 +1413,6 @@
   return rtp_sender_.DeregisterRtpHeaderExtension(type);
 }
 
-int32_t ModuleRtpRtcpImpl::RegisterReceiveRtpHeaderExtension(
-    const RTPExtensionType type,
-    const uint8_t id) {
-  return rtp_receiver_->RegisterRtpHeaderExtension(type, id);
-}
-
-int32_t ModuleRtpRtcpImpl::DeregisterReceiveRtpHeaderExtension(
-  const RTPExtensionType type) {
-  return rtp_receiver_->DeregisterRtpHeaderExtension(type);
-}
-
 // (TMMBR) Temporary Max Media Bit Rate.
 bool ModuleRtpRtcpImpl::TMMBR() const {
   WEBRTC_TRACE(kTraceModuleCall, kTraceRtpRtcp, id_, "TMMBR()");
@@ -1682,11 +1650,6 @@
                enable,
                id);
 
-  if (enable) {
-    rtp_receiver_->RegisterRtpHeaderExtension(kRtpExtensionAudioLevel, id);
-  } else {
-    rtp_receiver_->DeregisterRtpHeaderExtension(kRtpExtensionAudioLevel);
-  }
   return rtp_sender_.SetAudioLevelIndicationStatus(enable, id);
 }