OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
11 #include "webrtc/video/payload_router.h" | 11 #include "webrtc/video/payload_router.h" |
12 | 12 |
| 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" |
13 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
15 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
16 #include "webrtc/rtc_base/checks.h" | 18 #include "webrtc/rtc_base/checks.h" |
17 | 19 |
18 namespace webrtc { | 20 namespace webrtc { |
19 | 21 |
20 namespace { | 22 namespace { |
| 23 // Map information from encoded_image into rtp. |
| 24 void CopyEncodedImage(const EncodedImage* encoded_image, RTPVideoHeader* rtp) { |
| 25 rtp->rotation = encoded_image->rotation_; |
| 26 rtp->content_type = encoded_image->content_type_; |
| 27 if (encoded_image->timing_.is_timing_frame) { |
| 28 rtp->video_timing.encode_start_delta_ms = |
| 29 VideoSendTiming::GetDeltaCappedMs( |
| 30 encoded_image->capture_time_ms_, |
| 31 encoded_image->timing_.encode_start_ms); |
| 32 rtp->video_timing.encode_finish_delta_ms = |
| 33 VideoSendTiming::GetDeltaCappedMs( |
| 34 encoded_image->capture_time_ms_, |
| 35 encoded_image->timing_.encode_finish_ms); |
| 36 rtp->video_timing.packetization_finish_delta_ms = 0; |
| 37 rtp->video_timing.pacer_exit_delta_ms = 0; |
| 38 rtp->video_timing.network_timstamp_delta_ms = 0; |
| 39 rtp->video_timing.network2_timstamp_delta_ms = 0; |
| 40 rtp->video_timing.is_timing_frame = true; |
| 41 } else { |
| 42 rtp->video_timing.is_timing_frame = false; |
| 43 } |
| 44 rtp->playout_delay = encoded_image->playout_delay_; |
| 45 } |
| 46 |
21 // Map information from info into rtp. | 47 // Map information from info into rtp. |
22 void CopyCodecSpecific(const CodecSpecificInfo* info, RTPVideoHeader* rtp) { | 48 void CopyCodecSpecific(const CodecSpecificInfo* info, |
23 RTC_DCHECK(info); | 49 const EncodedImage* encoded_image, |
| 50 RTPVideoHeader* rtp) { |
| 51 CopyEncodedImage(encoded_image, rtp); |
| 52 if (!info) |
| 53 return; |
| 54 |
24 switch (info->codecType) { | 55 switch (info->codecType) { |
25 case kVideoCodecVP8: { | 56 case kVideoCodecVP8: { |
26 rtp->codec = kRtpVideoVp8; | 57 rtp->codec = kRtpVideoVp8; |
27 rtp->codecHeader.VP8.InitRTPVideoHeaderVP8(); | 58 rtp->codecHeader.VP8.InitRTPVideoHeaderVP8(); |
28 rtp->codecHeader.VP8.pictureId = info->codecSpecific.VP8.pictureId; | 59 rtp->codecHeader.VP8.pictureId = info->codecSpecific.VP8.pictureId; |
29 rtp->codecHeader.VP8.nonReference = info->codecSpecific.VP8.nonReference; | 60 rtp->codecHeader.VP8.nonReference = info->codecSpecific.VP8.nonReference; |
30 rtp->codecHeader.VP8.temporalIdx = info->codecSpecific.VP8.temporalIdx; | 61 rtp->codecHeader.VP8.temporalIdx = info->codecSpecific.VP8.temporalIdx; |
31 rtp->codecHeader.VP8.layerSync = info->codecSpecific.VP8.layerSync; | 62 rtp->codecHeader.VP8.layerSync = info->codecSpecific.VP8.layerSync; |
32 rtp->codecHeader.VP8.tl0PicIdx = info->codecSpecific.VP8.tl0PicIdx; | 63 rtp->codecHeader.VP8.tl0PicIdx = info->codecSpecific.VP8.tl0PicIdx; |
33 rtp->codecHeader.VP8.keyIdx = info->codecSpecific.VP8.keyIdx; | 64 rtp->codecHeader.VP8.keyIdx = info->codecSpecific.VP8.keyIdx; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 106 } |
76 case kVideoCodecH264: | 107 case kVideoCodecH264: |
77 rtp->codec = kRtpVideoH264; | 108 rtp->codec = kRtpVideoH264; |
78 rtp->codecHeader.H264.packetization_mode = | 109 rtp->codecHeader.H264.packetization_mode = |
79 info->codecSpecific.H264.packetization_mode; | 110 info->codecSpecific.H264.packetization_mode; |
80 return; | 111 return; |
81 case kVideoCodecGeneric: | 112 case kVideoCodecGeneric: |
82 rtp->codec = kRtpVideoGeneric; | 113 rtp->codec = kRtpVideoGeneric; |
83 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; | 114 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; |
84 return; | 115 return; |
| 116 case kVideoCodecStereo: { |
| 117 CodecSpecificInfo* codec_specific_info = |
| 118 const_cast<CodecSpecificInfo*>(info); |
| 119 codec_specific_info->codecType = info->stereoInfo.stereoCodecType; |
| 120 CopyCodecSpecific(codec_specific_info, encoded_image, rtp); |
| 121 |
| 122 rtp->stereoInfo.stereoCodecType = rtp->codec; |
| 123 rtp->codec = kRtpVideoStereo; |
| 124 rtp->stereoInfo.num_frames = info->stereoInfo.num_frames; |
| 125 for (int stereo_idx = 0; stereo_idx < info->stereoInfo.num_frames; |
| 126 ++stereo_idx) { |
| 127 LOG(LS_ERROR) << __func__; |
| 128 rtp->stereoInfo.encoded_images[stereo_idx] = |
| 129 info->stereoInfo.encoded_images[stereo_idx]; |
| 130 rtp->stereoInfo.fragmentations[stereo_idx] = |
| 131 info->stereoInfo.fragmentations[stereo_idx]; |
| 132 RTPVideoHeader* header = new RTPVideoHeader(); |
| 133 memset(&header, 0, sizeof(RTPVideoHeader)); |
| 134 CopyCodecSpecific(info->stereoInfo.codec_specific_infos[stereo_idx], |
| 135 rtp->stereoInfo.encoded_images[stereo_idx], header); |
| 136 rtp->stereoInfo.rtp_video_headers[stereo_idx] = header; |
| 137 } |
| 138 return; |
| 139 } |
85 default: | 140 default: |
86 return; | 141 return; |
87 } | 142 } |
88 } | 143 } |
89 | 144 |
90 } // namespace | 145 } // namespace |
91 | 146 |
92 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, | 147 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, |
93 int payload_type) | 148 int payload_type) |
94 : active_(false), | 149 : active_(false), |
(...skipping 24 matching lines...) Expand all Loading... |
119 const EncodedImage& encoded_image, | 174 const EncodedImage& encoded_image, |
120 const CodecSpecificInfo* codec_specific_info, | 175 const CodecSpecificInfo* codec_specific_info, |
121 const RTPFragmentationHeader* fragmentation) { | 176 const RTPFragmentationHeader* fragmentation) { |
122 rtc::CritScope lock(&crit_); | 177 rtc::CritScope lock(&crit_); |
123 RTC_DCHECK(!rtp_modules_.empty()); | 178 RTC_DCHECK(!rtp_modules_.empty()); |
124 if (!active_) | 179 if (!active_) |
125 return Result(Result::ERROR_SEND_FAILED); | 180 return Result(Result::ERROR_SEND_FAILED); |
126 | 181 |
127 RTPVideoHeader rtp_video_header; | 182 RTPVideoHeader rtp_video_header; |
128 memset(&rtp_video_header, 0, sizeof(RTPVideoHeader)); | 183 memset(&rtp_video_header, 0, sizeof(RTPVideoHeader)); |
129 if (codec_specific_info) | 184 CopyCodecSpecific(codec_specific_info, &encoded_image, &rtp_video_header); |
130 CopyCodecSpecific(codec_specific_info, &rtp_video_header); | |
131 rtp_video_header.rotation = encoded_image.rotation_; | |
132 rtp_video_header.content_type = encoded_image.content_type_; | |
133 if (encoded_image.timing_.is_timing_frame) { | |
134 rtp_video_header.video_timing.encode_start_delta_ms = | |
135 VideoSendTiming::GetDeltaCappedMs( | |
136 encoded_image.capture_time_ms_, | |
137 encoded_image.timing_.encode_start_ms); | |
138 rtp_video_header.video_timing.encode_finish_delta_ms = | |
139 VideoSendTiming::GetDeltaCappedMs( | |
140 encoded_image.capture_time_ms_, | |
141 encoded_image.timing_.encode_finish_ms); | |
142 rtp_video_header.video_timing.packetization_finish_delta_ms = 0; | |
143 rtp_video_header.video_timing.pacer_exit_delta_ms = 0; | |
144 rtp_video_header.video_timing.network_timstamp_delta_ms = 0; | |
145 rtp_video_header.video_timing.network2_timstamp_delta_ms = 0; | |
146 rtp_video_header.video_timing.is_timing_frame = true; | |
147 } else { | |
148 rtp_video_header.video_timing.is_timing_frame = false; | |
149 } | |
150 rtp_video_header.playout_delay = encoded_image.playout_delay_; | |
151 | 185 |
152 int stream_index = rtp_video_header.simulcastIdx; | 186 int stream_index = rtp_video_header.simulcastIdx; |
153 RTC_DCHECK_LT(stream_index, rtp_modules_.size()); | 187 RTC_DCHECK_LT(stream_index, rtp_modules_.size()); |
154 uint32_t frame_id; | 188 uint32_t frame_id; |
155 bool send_result = rtp_modules_[stream_index]->SendOutgoingData( | 189 bool send_result = rtp_modules_[stream_index]->SendOutgoingData( |
156 encoded_image._frameType, payload_type_, encoded_image._timeStamp, | 190 encoded_image._frameType, payload_type_, encoded_image._timeStamp, |
157 encoded_image.capture_time_ms_, encoded_image._buffer, | 191 encoded_image.capture_time_ms_, encoded_image._buffer, |
158 encoded_image._length, fragmentation, &rtp_video_header, &frame_id); | 192 encoded_image._length, fragmentation, &rtp_video_header, &frame_id); |
159 if (!send_result) | 193 if (!send_result) |
160 return Result(Result::ERROR_SEND_FAILED); | 194 return Result(Result::ERROR_SEND_FAILED); |
(...skipping 19 matching lines...) Expand all Loading... |
180 BitrateAllocation layer_bitrate; | 214 BitrateAllocation layer_bitrate; |
181 for (int tl = 0; tl < kMaxTemporalStreams; ++tl) | 215 for (int tl = 0; tl < kMaxTemporalStreams; ++tl) |
182 layer_bitrate.SetBitrate(0, tl, bitrate.GetBitrate(si, tl)); | 216 layer_bitrate.SetBitrate(0, tl, bitrate.GetBitrate(si, tl)); |
183 rtp_modules_[si]->SetVideoBitrateAllocation(layer_bitrate); | 217 rtp_modules_[si]->SetVideoBitrateAllocation(layer_bitrate); |
184 } | 218 } |
185 } | 219 } |
186 } | 220 } |
187 } | 221 } |
188 | 222 |
189 } // namespace webrtc | 223 } // namespace webrtc |
OLD | NEW |