1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/rtp_receiver/rtp_receiver.h"
7 #include "base/big_endian.h"
8 #include "base/logging.h"
9 #include "media/cast/rtp_receiver/receiver_stats.h"
10 #include "media/cast/rtp_receiver/rtp_parser/rtp_parser.h"
11 #include "media/cast/rtp_receiver/rtp_receiver_defines.h"
16 RtpReceiver::RtpReceiver(base::TickClock
* clock
,
17 const FrameReceiverConfig
* audio_config
,
18 const FrameReceiverConfig
* video_config
) :
19 packet_parser_(audio_config
? audio_config
->incoming_ssrc
:
20 (video_config
? video_config
->incoming_ssrc
: 0),
21 audio_config
? audio_config
->rtp_payload_type
:
22 (video_config
? video_config
->rtp_payload_type
: 0)),
24 DCHECK(audio_config
|| video_config
);
27 RtpReceiver::~RtpReceiver() {}
30 uint32
RtpReceiver::GetSsrcOfSender(const uint8
* rtcp_buffer
, size_t length
) {
31 DCHECK_GE(length
, kMinLengthOfRtp
) << "Invalid RTP packet";
32 uint32 ssrc_of_sender
;
33 base::BigEndianReader
big_endian_reader(
34 reinterpret_cast<const char*>(rtcp_buffer
), length
);
35 big_endian_reader
.Skip(8); // Skip header
36 big_endian_reader
.ReadU32(&ssrc_of_sender
);
37 return ssrc_of_sender
;
40 bool RtpReceiver::ReceivedPacket(const uint8
* packet
, size_t length
) {
41 RtpCastHeader rtp_header
;
42 const uint8
* payload_data
;
44 if (!packet_parser_
.ParsePacket(
45 packet
, length
, &rtp_header
, &payload_data
, &payload_size
)) {
49 OnReceivedPayloadData(payload_data
, payload_size
, rtp_header
);
50 stats_
.UpdateStatistics(rtp_header
);