| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/cast/rtp_sender/rtp_packetizer/rtp_packetizer.h" | 5 #include "media/cast/rtp_sender/rtp_packetizer/rtp_packetizer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/cast/cast_defines.h" | 8 #include "media/cast/cast_defines.h" |
| 9 #include "media/cast/pacing/paced_sender.h" | 9 #include "media/cast/pacing/paced_sender.h" |
| 10 #include "net/base/big_endian.h" | 10 #include "net/base/big_endian.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 RtpPacketizer::~RtpPacketizer() {} | 34 RtpPacketizer::~RtpPacketizer() {} |
| 35 | 35 |
| 36 void RtpPacketizer::IncomingEncodedVideoFrame( | 36 void RtpPacketizer::IncomingEncodedVideoFrame( |
| 37 const EncodedVideoFrame* video_frame, | 37 const EncodedVideoFrame* video_frame, |
| 38 const base::TimeTicks& capture_time) { | 38 const base::TimeTicks& capture_time) { |
| 39 DCHECK(!config_.audio) << "Invalid state"; | 39 DCHECK(!config_.audio) << "Invalid state"; |
| 40 if (config_.audio) return; | 40 if (config_.audio) return; |
| 41 | 41 |
| 42 base::TimeTicks zero_time; | |
| 43 base::TimeDelta capture_delta = capture_time - zero_time; | |
| 44 | |
| 45 // Timestamp is in 90 KHz for video. | 42 // Timestamp is in 90 KHz for video. |
| 46 rtp_timestamp_ = static_cast<uint32>(capture_delta.InMilliseconds() * 90); | 43 rtp_timestamp_ = GetVideoRtpTimestamp(capture_time); |
| 47 time_last_sent_rtp_timestamp_ = capture_time; | 44 time_last_sent_rtp_timestamp_ = capture_time; |
| 48 | 45 |
| 49 Cast(video_frame->key_frame, | 46 Cast(video_frame->key_frame, |
| 50 video_frame->frame_id, | 47 video_frame->frame_id, |
| 51 video_frame->last_referenced_frame_id, | 48 video_frame->last_referenced_frame_id, |
| 52 rtp_timestamp_, | 49 rtp_timestamp_, |
| 53 video_frame->data); | 50 video_frame->data); |
| 54 } | 51 } |
| 55 | 52 |
| 56 void RtpPacketizer::IncomingEncodedAudioFrame( | 53 void RtpPacketizer::IncomingEncodedAudioFrame( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 | 68 |
| 72 bool RtpPacketizer::LastSentTimestamp(base::TimeTicks* time_sent, | 69 bool RtpPacketizer::LastSentTimestamp(base::TimeTicks* time_sent, |
| 73 uint32* rtp_timestamp) const { | 70 uint32* rtp_timestamp) const { |
| 74 if (time_last_sent_rtp_timestamp_.is_null()) return false; | 71 if (time_last_sent_rtp_timestamp_.is_null()) return false; |
| 75 | 72 |
| 76 *time_sent = time_last_sent_rtp_timestamp_; | 73 *time_sent = time_last_sent_rtp_timestamp_; |
| 77 *rtp_timestamp = rtp_timestamp_; | 74 *rtp_timestamp = rtp_timestamp_; |
| 78 return true; | 75 return true; |
| 79 } | 76 } |
| 80 | 77 |
| 78 // TODO(mikhal): Switch to pass data with a const_ref. |
| 81 void RtpPacketizer::Cast(bool is_key, | 79 void RtpPacketizer::Cast(bool is_key, |
| 82 uint32 frame_id, | 80 uint32 frame_id, |
| 83 uint32 reference_frame_id, | 81 uint32 reference_frame_id, |
| 84 uint32 timestamp, | 82 uint32 timestamp, |
| 85 const std::string& data) { | 83 const std::string& data) { |
| 86 uint16 rtp_header_length = kCommonRtpHeaderLength + kCastRtpHeaderLength; | 84 uint16 rtp_header_length = kCommonRtpHeaderLength + kCastRtpHeaderLength; |
| 87 uint16 max_length = config_.max_payload_length - rtp_header_length - 1; | 85 uint16 max_length = config_.max_payload_length - rtp_header_length - 1; |
| 88 | 86 |
| 89 // Split the payload evenly (round number up). | 87 // Split the payload evenly (round number up). |
| 90 size_t num_packets = (data.size() + max_length) / max_length; | 88 size_t num_packets = (data.size() + max_length) / max_length; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 packet->resize(start_size + 10); | 144 packet->resize(start_size + 10); |
| 147 net::BigEndianWriter big_endian_writer(&((*packet)[start_size]), 10); | 145 net::BigEndianWriter big_endian_writer(&((*packet)[start_size]), 10); |
| 148 big_endian_writer.WriteU16(sequence_number_); | 146 big_endian_writer.WriteU16(sequence_number_); |
| 149 big_endian_writer.WriteU32(time_stamp); | 147 big_endian_writer.WriteU32(time_stamp); |
| 150 big_endian_writer.WriteU32(config_.ssrc); | 148 big_endian_writer.WriteU32(config_.ssrc); |
| 151 ++sequence_number_; | 149 ++sequence_number_; |
| 152 } | 150 } |
| 153 | 151 |
| 154 } // namespace cast | 152 } // namespace cast |
| 155 } // namespace media | 153 } // namespace media |
| OLD | NEW |