Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: talk/session/media/channel.cc

Issue 1229283003: Refactor the relationship between BaseChannel and MediaChannel so that we send over all the paramet… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: remove duplication Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return direction == MD_SENDRECV || direction == MD_SENDONLY; 143 return direction == MD_SENDRECV || direction == MD_SENDONLY;
144 } 144 }
145 145
146 static const MediaContentDescription* GetContentDescription( 146 static const MediaContentDescription* GetContentDescription(
147 const ContentInfo* cinfo) { 147 const ContentInfo* cinfo) {
148 if (cinfo == NULL) 148 if (cinfo == NULL)
149 return NULL; 149 return NULL;
150 return static_cast<const MediaContentDescription*>(cinfo->description); 150 return static_cast<const MediaContentDescription*>(cinfo->description);
151 } 151 }
152 152
153 // ***
pbos-webrtc 2015/07/16 14:39:51 Remove this comment (regardless of which CL it bel
154 template <class Codec>
155 std::vector<int> CodecIds(const std::vector<Codec>& codecs) {
156 std::vector<int> ids;
157 for (const Codec& codec : codecs) {
158 ids.push_back(codec.id);
159 }
160 return ids;
161 }
162
163 template <class Codec>
164 void RtpParametersFromMediaDescription(
165 const MediaContentDescriptionImpl<Codec>* desc,
166 RtpParameters<Codec>* params) {
167 // TODO(pthatcher): Remove this once we're sure no one will give us
168 // a description without codecs (currently a CA_UPDATE with just
169 // streams can).
170 if (desc->has_codecs()) {
171 params->codecs = desc->codecs();
172 }
173 // TODO(pthatcher): See if we really need
174 // rtp_header_extensions_set() and remove it if we don't.
175 if (desc->rtp_header_extensions_set()) {
176 params->extensions = desc->rtp_header_extensions();
177 }
178 }
179
180 template <class Codec, class Options>
181 void RtpSendParametersFromMediaDescription(
182 const MediaContentDescriptionImpl<Codec>* desc,
183 RtpSendParameters<Codec, Options>* send_params) {
184 RtpParametersFromMediaDescription(desc, send_params);
185 send_params->max_bandwidth_bps = desc->bandwidth();
186 }
187
153 BaseChannel::BaseChannel(rtc::Thread* thread, 188 BaseChannel::BaseChannel(rtc::Thread* thread,
154 MediaEngineInterface* media_engine, 189 MediaEngineInterface* media_engine,
155 MediaChannel* media_channel, BaseSession* session, 190 MediaChannel* media_channel, BaseSession* session,
156 const std::string& content_name, bool rtcp) 191 const std::string& content_name, bool rtcp)
157 : worker_thread_(thread), 192 : worker_thread_(thread),
158 media_engine_(media_engine), 193 media_engine_(media_engine),
159 session_(session), 194 session_(session),
160 media_channel_(media_channel), 195 media_channel_(media_channel),
161 content_name_(content_name), 196 content_name_(content_name),
162 rtcp_(rtcp), 197 rtcp_(rtcp),
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 if (!writable_) 927 if (!writable_)
893 return; 928 return;
894 929
895 LOG(LS_INFO) << "Channel socket not writable (" 930 LOG(LS_INFO) << "Channel socket not writable ("
896 << transport_channel_->content_name() << ", " 931 << transport_channel_->content_name() << ", "
897 << transport_channel_->component() << ")"; 932 << transport_channel_->component() << ")";
898 writable_ = false; 933 writable_ = false;
899 ChangeState(); 934 ChangeState();
900 } 935 }
901 936
937 bool BaseChannel::SetRtpTransportParameters_w(
938 const MediaContentDescription* content,
939 ContentAction action,
940 ContentSource src,
941 std::string* error_desc) {
942 if (action == CA_UPDATE) {
943 // These parameters never get changed by a CA_UDPATE.
944 return true;
945 }
946
947 // Cache secure_required_ for belt and suspenders check on SendPacket
948 set_secure_required(content->crypto_required() != CT_NONE);
949 if (!SetSrtp_w(content->cryptos(), action, src, error_desc)) {
950 return false;
951 }
952
953 if (!SetRtcpMux_w(content->rtcp_mux(), action, src, error_desc)) {
954 return false;
955 }
956
957 return true;
958 }
959
902 // |dtls| will be set to true if DTLS is active for transport channel and 960 // |dtls| will be set to true if DTLS is active for transport channel and
903 // crypto is empty. 961 // crypto is empty.
904 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos, 962 bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos,
905 bool* dtls, 963 bool* dtls,
906 std::string* error_desc) { 964 std::string* error_desc) {
907 *dtls = transport_channel_->IsDtlsActive(); 965 *dtls = transport_channel_->IsDtlsActive();
908 if (*dtls && !cryptos.empty()) { 966 if (*dtls && !cryptos.empty()) {
909 SafeSetError("Cryptos must be empty when DTLS is active.", 967 SafeSetError("Cryptos must be empty when DTLS is active.",
910 error_desc); 968 error_desc);
911 return false; 969 return false;
912 } 970 }
913 return true; 971 return true;
914 } 972 }
915 973
916 bool BaseChannel::SetRecvRtpHeaderExtensions_w(
917 const MediaContentDescription* content,
918 MediaChannel* media_channel,
919 std::string* error_desc) {
920 if (content->rtp_header_extensions_set()) {
921 if (!media_channel->SetRecvRtpHeaderExtensions(
922 content->rtp_header_extensions())) {
923 std::ostringstream desc;
924 desc << "Failed to set receive rtp header extensions for "
925 << MediaTypeToString(content->type()) << " content.";
926 SafeSetError(desc.str(), error_desc);
927 return false;
928 }
929 }
930 return true;
931 }
932
933 bool BaseChannel::SetSendRtpHeaderExtensions_w(
934 const MediaContentDescription* content,
935 MediaChannel* media_channel,
936 std::string* error_desc) {
937 if (content->rtp_header_extensions_set()) {
938 if (!media_channel->SetSendRtpHeaderExtensions(
939 content->rtp_header_extensions())) {
940 std::ostringstream desc;
941 desc << "Failed to set send rtp header extensions for "
942 << MediaTypeToString(content->type()) << " content.";
943 SafeSetError(desc.str(), error_desc);
944 return false;
945 } else {
946 MaybeCacheRtpAbsSendTimeHeaderExtension(content->rtp_header_extensions());
947 }
948 }
949 return true;
950 }
951
952 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos, 974 bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos,
953 ContentAction action, 975 ContentAction action,
954 ContentSource src, 976 ContentSource src,
955 std::string* error_desc) { 977 std::string* error_desc) {
956 if (action == CA_UPDATE) { 978 if (action == CA_UPDATE) {
957 // no crypto params. 979 // no crypto params.
958 return true; 980 return true;
959 } 981 }
960 bool ret = false; 982 bool ret = false;
961 bool dtls = false; 983 bool dtls = false;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 desc << "Failed to add remote stream ssrc: " << it->first_ssrc(); 1225 desc << "Failed to add remote stream ssrc: " << it->first_ssrc();
1204 SafeSetError(desc.str(), error_desc); 1226 SafeSetError(desc.str(), error_desc);
1205 ret = false; 1227 ret = false;
1206 } 1228 }
1207 } 1229 }
1208 } 1230 }
1209 remote_streams_ = streams; 1231 remote_streams_ = streams;
1210 return ret; 1232 return ret;
1211 } 1233 }
1212 1234
1213 bool BaseChannel::SetBaseLocalContent_w(const MediaContentDescription* content,
1214 ContentAction action,
1215 std::string* error_desc) {
1216 // Cache secure_required_ for belt and suspenders check on SendPacket
1217 secure_required_ = content->crypto_required() != CT_NONE;
1218 // Set local RTP header extensions.
1219 bool ret = SetRecvRtpHeaderExtensions_w(content, media_channel(), error_desc);
1220 // Set local SRTP parameters (what we will encrypt with).
1221 ret &= SetSrtp_w(content->cryptos(), action, CS_LOCAL, error_desc);
1222 // Set local RTCP mux parameters.
1223 ret &= SetRtcpMux_w(content->rtcp_mux(), action, CS_LOCAL, error_desc);
1224
1225 // Call UpdateLocalStreams_w last to make sure as many settings as possible
1226 // are already set when creating streams.
1227 ret &= UpdateLocalStreams_w(content->streams(), action, error_desc);
1228 set_local_content_direction(content->direction());
1229 return ret;
1230 }
1231
1232 bool BaseChannel::SetBaseRemoteContent_w(const MediaContentDescription* content,
1233 ContentAction action,
1234 std::string* error_desc) {
1235 // Set remote RTP header extensions.
1236 bool ret = SetSendRtpHeaderExtensions_w(content, media_channel(), error_desc);
1237 // Set remote SRTP parameters (what the other side will encrypt with).
1238 ret &= SetSrtp_w(content->cryptos(), action, CS_REMOTE, error_desc);
1239 // Set remote RTCP mux parameters.
1240 ret &= SetRtcpMux_w(content->rtcp_mux(), action, CS_REMOTE, error_desc);
1241 if (!media_channel()->SetMaxSendBandwidth(content->bandwidth())) {
1242 std::ostringstream desc;
1243 desc << "Failed to set max send bandwidth for "
1244 << MediaTypeToString(content->type()) << " content.";
1245 SafeSetError(desc.str(), error_desc);
1246 ret = false;
1247 }
1248
1249 // Call UpdateRemoteStreams_w last to make sure as many settings as possible
1250 // are already set when creating streams.
1251 ret &= UpdateRemoteStreams_w(content->streams(), action, error_desc);
1252 set_remote_content_direction(content->direction());
1253 return ret;
1254 }
1255
1256 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension( 1235 void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension(
1257 const std::vector<RtpHeaderExtension>& extensions) { 1236 const std::vector<RtpHeaderExtension>& extensions) {
1258 const RtpHeaderExtension* send_time_extension = 1237 const RtpHeaderExtension* send_time_extension =
1259 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension); 1238 FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension);
1260 rtp_abs_sendtime_extn_id_ = 1239 rtp_abs_sendtime_extn_id_ =
1261 send_time_extension ? send_time_extension->id : -1; 1240 send_time_extension ? send_time_extension->id : -1;
1262 } 1241 }
1263 1242
1264 void BaseChannel::OnMessage(rtc::Message *pmsg) { 1243 void BaseChannel::OnMessage(rtc::Message *pmsg) {
1265 switch (pmsg->message_id) { 1244 switch (pmsg->message_id) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 LOG(LS_INFO) << "Setting local voice description"; 1474 LOG(LS_INFO) << "Setting local voice description";
1496 1475
1497 const AudioContentDescription* audio = 1476 const AudioContentDescription* audio =
1498 static_cast<const AudioContentDescription*>(content); 1477 static_cast<const AudioContentDescription*>(content);
1499 ASSERT(audio != NULL); 1478 ASSERT(audio != NULL);
1500 if (!audio) { 1479 if (!audio) {
1501 SafeSetError("Can't find audio content in local description.", error_desc); 1480 SafeSetError("Can't find audio content in local description.", error_desc);
1502 return false; 1481 return false;
1503 } 1482 }
1504 1483
1505 bool ret = SetBaseLocalContent_w(content, action, error_desc); 1484 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) {
1506 // Set local audio codecs (what we want to receive). 1485 return false;
1507 // TODO(whyuan): Change action != CA_UPDATE to !audio->partial() when partial
1508 // is set properly.
1509 if (action != CA_UPDATE || audio->has_codecs()) {
1510 if (!media_channel()->SetRecvCodecs(audio->codecs())) {
1511 SafeSetError("Failed to set audio receive codecs.", error_desc);
1512 ret = false;
1513 }
1514 } 1486 }
1515 1487
1516 // If everything worked, see if we can start receiving. 1488 AudioRecvParameters recv_params = last_recv_params_;
1517 if (ret) { 1489 RtpParametersFromMediaDescription(audio, &recv_params);
1518 std::vector<AudioCodec>::const_iterator it = audio->codecs().begin(); 1490 if (!media_channel()->SetRecvParameters(recv_params)) {
1519 for (; it != audio->codecs().end(); ++it) { 1491 SafeSetError("Failed to set local video description recv parameters.",
1520 bundle_filter()->AddPayloadType(it->id); 1492 error_desc);
1521 } 1493 return false;
1522 ChangeState();
1523 } else {
1524 LOG(LS_WARNING) << "Failed to set local voice description";
1525 } 1494 }
1526 return ret; 1495 for (const AudioCodec& codec : audio->codecs()) {
1496 bundle_filter()->AddPayloadType(codec.id);
1497 }
1498 last_recv_params_ = recv_params;
1499
1500 // TODO(pthatcher): Move local streams into AudioSendParameters, and
1501 // only give it to the media channel once we have a remote
1502 // description too (without a remote description, we won't be able
1503 // to send them anyway).
1504 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) {
1505 SafeSetError("Failed to set local audio description streams.", error_desc);
1506 return false;
1507 }
1508
1509 set_local_content_direction(content->direction());
1510 ChangeState();
1511 return true;
1527 } 1512 }
1528 1513
1529 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, 1514 bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content,
1530 ContentAction action, 1515 ContentAction action,
1531 std::string* error_desc) { 1516 std::string* error_desc) {
1532 ASSERT(worker_thread() == rtc::Thread::Current()); 1517 ASSERT(worker_thread() == rtc::Thread::Current());
1533 LOG(LS_INFO) << "Setting remote voice description"; 1518 LOG(LS_INFO) << "Setting remote voice description";
1534 1519
1535 const AudioContentDescription* audio = 1520 const AudioContentDescription* audio =
1536 static_cast<const AudioContentDescription*>(content); 1521 static_cast<const AudioContentDescription*>(content);
1537 ASSERT(audio != NULL); 1522 ASSERT(audio != NULL);
1538 if (!audio) { 1523 if (!audio) {
1539 SafeSetError("Can't find audio content in remote description.", error_desc); 1524 SafeSetError("Can't find audio content in remote description.", error_desc);
1540 return false; 1525 return false;
1541 } 1526 }
1542 1527
1543 bool ret = true; 1528 if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
1544 // Set remote video codecs (what the other side wants to receive). 1529 return false;
1545 if (action != CA_UPDATE || audio->has_codecs()) {
1546 if (!media_channel()->SetSendCodecs(audio->codecs())) {
1547 SafeSetError("Failed to set audio send codecs.", error_desc);
1548 ret = false;
1549 }
1550 } 1530 }
1551 1531
1552 ret &= SetBaseRemoteContent_w(content, action, error_desc); 1532 AudioSendParameters send_params = last_send_params_;
1533 RtpSendParametersFromMediaDescription(audio, &send_params);
1534 if (audio->conference_mode()) {
1535 send_params.options.conference_mode.Set(true);
1536 }
1537 if (audio->agc_minus_10db()) {
1538 send_params.options.adjust_agc_delta.Set(kAgcMinus10db);
1539 }
1540 if (!media_channel()->SetSendParameters(send_params)) {
1541 SafeSetError("Failed to set remote audio description send parameters.",
1542 error_desc);
1543 return false;
1544 }
1545 last_send_params_ = send_params;
1553 1546
1554 if (action != CA_UPDATE) { 1547 // TODO(pthatcher): Move remote streams into AudioRecvParameters,
1555 // Tweak our audio processing settings, if needed. 1548 // and only give it to the media channel once we have a local
1556 AudioOptions audio_options; 1549 // description too (without a local description, we won't be able to
1557 if (!media_channel()->GetOptions(&audio_options)) { 1550 // recv them anyway).
1558 LOG(LS_WARNING) << "Can not set audio options from on remote content."; 1551 if (!UpdateRemoteStreams_w(audio->streams(), action, error_desc)) {
1559 } else { 1552 LOG(LS_WARNING) << "Failed to set remote audio description receive streams";
1560 if (audio->conference_mode()) { 1553 return false;
1561 audio_options.conference_mode.Set(true);
1562 }
1563 if (audio->agc_minus_10db()) {
1564 audio_options.adjust_agc_delta.Set(kAgcMinus10db);
1565 }
1566 if (!media_channel()->SetOptions(audio_options)) {
1567 // Log an error on failure, but don't abort the call.
1568 LOG(LS_ERROR) << "Failed to set voice channel options";
1569 }
1570 }
1571 } 1554 }
1572 1555
1573 // If everything worked, see if we can start sending. 1556 set_remote_content_direction(content->direction());
1574 if (ret) { 1557 ChangeState();
1575 ChangeState(); 1558 return true;
1576 } else {
1577 LOG(LS_WARNING) << "Failed to set remote voice description";
1578 }
1579 return ret;
1580 } 1559 }
1581 1560
1582 bool VoiceChannel::SetRingbackTone_w(const void* buf, int len) { 1561 bool VoiceChannel::SetRingbackTone_w(const void* buf, int len) {
1583 ASSERT(worker_thread() == rtc::Thread::Current()); 1562 ASSERT(worker_thread() == rtc::Thread::Current());
1584 return media_channel()->SetRingbackTone(static_cast<const char*>(buf), len); 1563 return media_channel()->SetRingbackTone(static_cast<const char*>(buf), len);
1585 } 1564 }
1586 1565
1587 bool VoiceChannel::PlayRingbackTone_w(uint32 ssrc, bool play, bool loop) { 1566 bool VoiceChannel::PlayRingbackTone_w(uint32 ssrc, bool play, bool loop) {
1588 ASSERT(worker_thread() == rtc::Thread::Current()); 1567 ASSERT(worker_thread() == rtc::Thread::Current());
1589 if (play) { 1568 if (play) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 LOG(LS_INFO) << "Setting local video description"; 1818 LOG(LS_INFO) << "Setting local video description";
1840 1819
1841 const VideoContentDescription* video = 1820 const VideoContentDescription* video =
1842 static_cast<const VideoContentDescription*>(content); 1821 static_cast<const VideoContentDescription*>(content);
1843 ASSERT(video != NULL); 1822 ASSERT(video != NULL);
1844 if (!video) { 1823 if (!video) {
1845 SafeSetError("Can't find video content in local description.", error_desc); 1824 SafeSetError("Can't find video content in local description.", error_desc);
1846 return false; 1825 return false;
1847 } 1826 }
1848 1827
1849 bool ret = SetBaseLocalContent_w(content, action, error_desc); 1828 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) {
1850 // Set local video codecs (what we want to receive). 1829 return false;
1851 if (action != CA_UPDATE || video->has_codecs()) {
1852 if (!media_channel()->SetRecvCodecs(video->codecs())) {
1853 SafeSetError("Failed to set video receive codecs.", error_desc);
1854 ret = false;
1855 }
1856 } 1830 }
1857 1831
1858 if (action != CA_UPDATE) { 1832 VideoRecvParameters recv_params = last_recv_params_;
1859 VideoOptions video_options; 1833 RtpParametersFromMediaDescription(video, &recv_params);
1860 media_channel()->GetOptions(&video_options); 1834 if (!media_channel()->SetRecvParameters(recv_params)) {
1861 video_options.buffered_mode_latency.Set(video->buffered_mode_latency()); 1835 SafeSetError("Failed to set local video description recv parameters.",
1836 error_desc);
1837 return false;
1838 }
1839 for (const VideoCodec& codec : video->codecs()) {
1840 bundle_filter()->AddPayloadType(codec.id);
1841 }
1842 last_recv_params_ = recv_params;
1862 1843
1863 if (!media_channel()->SetOptions(video_options)) { 1844 // TODO(pthatcher): Move local streams into VideoSendParameters, and
1864 // Log an error on failure, but don't abort the call. 1845 // only give it to the media channel once we have a remote
1865 LOG(LS_ERROR) << "Failed to set video channel options"; 1846 // description too (without a remote description, we won't be able
1866 } 1847 // to send them anyway).
1848 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) {
1849 SafeSetError("Failed to set local video description streams.", error_desc);
1850 return false;
1867 } 1851 }
1868 1852
1869 // If everything worked, see if we can start receiving. 1853 set_local_content_direction(content->direction());
1870 if (ret) { 1854 ChangeState();
1871 std::vector<VideoCodec>::const_iterator it = video->codecs().begin(); 1855 return true;
1872 for (; it != video->codecs().end(); ++it) {
1873 bundle_filter()->AddPayloadType(it->id);
1874 }
1875 ChangeState();
1876 } else {
1877 LOG(LS_WARNING) << "Failed to set local video description";
1878 }
1879 return ret;
1880 } 1856 }
1881 1857
1882 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, 1858 bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content,
1883 ContentAction action, 1859 ContentAction action,
1884 std::string* error_desc) { 1860 std::string* error_desc) {
1885 ASSERT(worker_thread() == rtc::Thread::Current()); 1861 ASSERT(worker_thread() == rtc::Thread::Current());
1886 LOG(LS_INFO) << "Setting remote video description"; 1862 LOG(LS_INFO) << "Setting remote video description";
1887 1863
1888 const VideoContentDescription* video = 1864 const VideoContentDescription* video =
1889 static_cast<const VideoContentDescription*>(content); 1865 static_cast<const VideoContentDescription*>(content);
1890 ASSERT(video != NULL); 1866 ASSERT(video != NULL);
1891 if (!video) { 1867 if (!video) {
1892 SafeSetError("Can't find video content in remote description.", error_desc); 1868 SafeSetError("Can't find video content in remote description.", error_desc);
1893 return false; 1869 return false;
1894 } 1870 }
1895 1871
1896 bool ret = true; 1872
1897 // Set remote video codecs (what the other side wants to receive). 1873 if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
1898 if (action != CA_UPDATE || video->has_codecs()) { 1874 return false;
1899 if (!media_channel()->SetSendCodecs(video->codecs())) {
1900 SafeSetError("Failed to set video send codecs.", error_desc);
1901 ret = false;
1902 }
1903 } 1875 }
1904 1876
1905 ret &= SetBaseRemoteContent_w(content, action, error_desc); 1877 VideoSendParameters send_params = last_send_params_;
1878 RtpSendParametersFromMediaDescription(video, &send_params);
1879 if (video->conference_mode()) {
1880 send_params.options.conference_mode.Set(true);
1881 }
1882 if (!media_channel()->SetSendParameters(send_params)) {
1883 SafeSetError("Failed to set remote video description send parameters.",
1884 error_desc);
1885 return false;
1886 }
1887 last_send_params_ = send_params;
1906 1888
1907 if (action != CA_UPDATE) { 1889 // TODO(pthatcher): Move remote streams into VideoRecvParameters,
1908 // Tweak our video processing settings, if needed. 1890 // and only give it to the media channel once we have a local
1909 VideoOptions video_options; 1891 // description too (without a local description, we won't be able to
1910 media_channel()->GetOptions(&video_options); 1892 // recv them anyway).
1911 if (video->conference_mode()) { 1893 if (!UpdateRemoteStreams_w(video->streams(), action, error_desc)) {
1912 video_options.conference_mode.Set(true); 1894 LOG(LS_WARNING) << "Failed to set remote video description receive streams";
1913 } 1895 return false;
1914 video_options.buffered_mode_latency.Set(video->buffered_mode_latency());
1915
1916 if (!media_channel()->SetOptions(video_options)) {
1917 // Log an error on failure, but don't abort the call.
1918 LOG(LS_ERROR) << "Failed to set video channel options";
1919 }
1920 } 1896 }
1921 1897
1922 // If everything worked, see if we can start sending. 1898 if (video->rtp_header_extensions_set()) {
1923 if (ret) { 1899 MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions());
1924 ChangeState();
1925 } else {
1926 LOG(LS_WARNING) << "Failed to set remote video description";
1927 } 1900 }
1928 return ret; 1901
1902 set_remote_content_direction(content->direction());
1903 ChangeState();
1904 return true;
1929 } 1905 }
1930 1906
1931 bool VideoChannel::ApplyViewRequest_w(const ViewRequest& request) { 1907 bool VideoChannel::ApplyViewRequest_w(const ViewRequest& request) {
1932 bool ret = true; 1908 bool ret = true;
1933 // Set the send format for each of the local streams. If the view request 1909 // Set the send format for each of the local streams. If the view request
1934 // does not contain a local stream, set its send format to 0x0, which will 1910 // does not contain a local stream, set its send format to 0x0, which will
1935 // drop all frames. 1911 // drop all frames.
1936 for (std::vector<StreamParams>::const_iterator it = local_streams().begin(); 1912 for (std::vector<StreamParams>::const_iterator it = local_streams().begin();
1937 it != local_streams().end(); ++it) { 1913 it != local_streams().end(); ++it) {
1938 VideoFormat format(0, 0, 0, cricket::FOURCC_I420); 1914 VideoFormat format(0, 0, 0, cricket::FOURCC_I420);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 LOG(LS_INFO) << "Setting local data description"; 2199 LOG(LS_INFO) << "Setting local data description";
2224 2200
2225 const DataContentDescription* data = 2201 const DataContentDescription* data =
2226 static_cast<const DataContentDescription*>(content); 2202 static_cast<const DataContentDescription*>(content);
2227 ASSERT(data != NULL); 2203 ASSERT(data != NULL);
2228 if (!data) { 2204 if (!data) {
2229 SafeSetError("Can't find data content in local description.", error_desc); 2205 SafeSetError("Can't find data content in local description.", error_desc);
2230 return false; 2206 return false;
2231 } 2207 }
2232 2208
2233 bool ret = false;
2234 if (!SetDataChannelTypeFromContent(data, error_desc)) { 2209 if (!SetDataChannelTypeFromContent(data, error_desc)) {
2235 return false; 2210 return false;
2236 } 2211 }
2237 2212
2238 if (data_channel_type_ == DCT_SCTP) { 2213 if (data_channel_type_ == DCT_RTP) {
2239 // SCTP data channels don't need the rest of the stuff. 2214 if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) {
2240 ret = UpdateLocalStreams_w(data->streams(), action, error_desc); 2215 return false;
2241 if (ret) {
2242 set_local_content_direction(content->direction());
2243 // As in SetRemoteContent_w, make sure we set the local SCTP port
2244 // number as specified in our DataContentDescription.
2245 if (!media_channel()->SetRecvCodecs(data->codecs())) {
2246 SafeSetError("Failed to set data receive codecs.", error_desc);
2247 ret = false;
2248 }
2249 }
2250 } else {
2251 ret = SetBaseLocalContent_w(content, action, error_desc);
2252 if (action != CA_UPDATE || data->has_codecs()) {
2253 if (!media_channel()->SetRecvCodecs(data->codecs())) {
2254 SafeSetError("Failed to set data receive codecs.", error_desc);
2255 ret = false;
2256 }
2257 } 2216 }
2258 } 2217 }
2259 2218
2260 // If everything worked, see if we can start receiving. 2219 // FYI: We send the SCTP port number (not to be confused with the
2261 if (ret) { 2220 // underlying UDP port number) as a codec parameter. So even SCTP
2262 std::vector<DataCodec>::const_iterator it = data->codecs().begin(); 2221 // data channels need codecs.
2263 for (; it != data->codecs().end(); ++it) { 2222 DataRecvParameters recv_params = last_recv_params_;
2264 bundle_filter()->AddPayloadType(it->id); 2223 RtpParametersFromMediaDescription(data, &recv_params);
2224 if (!media_channel()->SetRecvParameters(recv_params)) {
2225 SafeSetError("Failed to set remote data description recv parameters.",
2226 error_desc);
2227 return false;
2228 }
2229 if (data_channel_type_ == DCT_RTP) {
2230 for (const DataCodec& codec : data->codecs()) {
2231 bundle_filter()->AddPayloadType(codec.id);
2265 } 2232 }
2266 ChangeState();
2267 } else {
2268 LOG(LS_WARNING) << "Failed to set local data description";
2269 } 2233 }
2270 return ret; 2234 last_recv_params_ = recv_params;
2235
2236 // TODO(pthatcher): Move local streams into DataSendParameters, and
2237 // only give it to the media channel once we have a remote
2238 // description too (without a remote description, we won't be able
2239 // to send them anyway).
2240 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) {
2241 SafeSetError("Failed to set local data description streams.", error_desc);
2242 return false;
2243 }
2244
2245 set_local_content_direction(content->direction());
2246 ChangeState();
2247 return true;
2271 } 2248 }
2272 2249
2273 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content, 2250 bool DataChannel::SetRemoteContent_w(const MediaContentDescription* content,
2274 ContentAction action, 2251 ContentAction action,
2275 std::string* error_desc) { 2252 std::string* error_desc) {
2276 ASSERT(worker_thread() == rtc::Thread::Current()); 2253 ASSERT(worker_thread() == rtc::Thread::Current());
2277 2254
2278 const DataContentDescription* data = 2255 const DataContentDescription* data =
2279 static_cast<const DataContentDescription*>(content); 2256 static_cast<const DataContentDescription*>(content);
2280 ASSERT(data != NULL); 2257 ASSERT(data != NULL);
2281 if (!data) { 2258 if (!data) {
2282 SafeSetError("Can't find data content in remote description.", error_desc); 2259 SafeSetError("Can't find data content in remote description.", error_desc);
2283 return false; 2260 return false;
2284 } 2261 }
2285 2262
2286 bool ret = true; 2263 // If the remote data doesn't have codecs and isn't an update, it
2264 // must be empty, so ignore it.
2265 if (!data->has_codecs() && action != CA_UPDATE) {
2266 return true;
2267 }
2268
2287 if (!SetDataChannelTypeFromContent(data, error_desc)) { 2269 if (!SetDataChannelTypeFromContent(data, error_desc)) {
2288 return false; 2270 return false;
2289 } 2271 }
2290 2272
2291 if (data_channel_type_ == DCT_SCTP) { 2273 LOG(LS_INFO) << "Setting remote data description";
2292 LOG(LS_INFO) << "Setting SCTP remote data description"; 2274 if (data_channel_type_ == DCT_RTP &&
2293 // SCTP data channels don't need the rest of the stuff. 2275 !SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
2294 ret = UpdateRemoteStreams_w(content->streams(), action, error_desc); 2276 return false;
2295 if (ret) {
2296 set_remote_content_direction(content->direction());
2297 // We send the SCTP port number (not to be confused with the underlying
2298 // UDP port number) as a codec parameter. Make sure it gets there.
2299 if (!media_channel()->SetSendCodecs(data->codecs())) {
2300 SafeSetError("Failed to set data send codecs.", error_desc);
2301 ret = false;
2302 }
2303 }
2304 } else {
2305 // If the remote data doesn't have codecs and isn't an update, it
2306 // must be empty, so ignore it.
2307 if (action != CA_UPDATE && !data->has_codecs()) {
2308 return true;
2309 }
2310 LOG(LS_INFO) << "Setting remote data description";
2311
2312 // Set remote video codecs (what the other side wants to receive).
2313 if (action != CA_UPDATE || data->has_codecs()) {
2314 if (!media_channel()->SetSendCodecs(data->codecs())) {
2315 SafeSetError("Failed to set data send codecs.", error_desc);
2316 ret = false;
2317 }
2318 }
2319
2320 if (ret) {
2321 ret &= SetBaseRemoteContent_w(content, action, error_desc);
2322 }
2323
2324 if (action != CA_UPDATE) {
2325 int bandwidth_bps = data->bandwidth();
2326 if (!media_channel()->SetMaxSendBandwidth(bandwidth_bps)) {
2327 std::ostringstream desc;
2328 desc << "Failed to set max send bandwidth for data content.";
2329 SafeSetError(desc.str(), error_desc);
2330 ret = false;
2331 }
2332 }
2333 } 2277 }
2334 2278
2335 // If everything worked, see if we can start sending. 2279
2336 if (ret) { 2280 DataSendParameters send_params = last_send_params_;
2337 ChangeState(); 2281 RtpSendParametersFromMediaDescription<DataCodec>(data, &send_params);
2338 } else { 2282 if (!media_channel()->SetSendParameters(send_params)) {
2339 LOG(LS_WARNING) << "Failed to set remote data description"; 2283 SafeSetError("Failed to set remote data description send parameters.",
2284 error_desc);
2285 return false;
2340 } 2286 }
2341 return ret; 2287 last_send_params_ = send_params;
2288
2289 // TODO(pthatcher): Move remote streams into DataRecvParameters,
2290 // and only give it to the media channel once we have a local
2291 // description too (without a local description, we won't be able to
2292 // recv them anyway).
2293 if (!UpdateRemoteStreams_w(data->streams(), action, error_desc)) {
2294 SafeSetError("Failed to set remote data description streams.",
2295 error_desc);
2296 return false;
2297 }
2298
2299 set_remote_content_direction(content->direction());
2300 ChangeState();
2301 return true;
2342 } 2302 }
2343 2303
2344 void DataChannel::ChangeState() { 2304 void DataChannel::ChangeState() {
2345 // Render incoming data if we're the active call, and we have the local 2305 // Render incoming data if we're the active call, and we have the local
2346 // content. We receive data on the default channel and multiplexed streams. 2306 // content. We receive data on the default channel and multiplexed streams.
2347 bool recv = IsReadyToReceive(); 2307 bool recv = IsReadyToReceive();
2348 if (!media_channel()->SetReceive(recv)) { 2308 if (!media_channel()->SetReceive(recv)) {
2349 LOG(LS_ERROR) << "Failed to SetReceive on data channel"; 2309 LOG(LS_ERROR) << "Failed to SetReceive on data channel";
2350 } 2310 }
2351 2311
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2479 return (data_channel_type_ == DCT_RTP); 2439 return (data_channel_type_ == DCT_RTP);
2480 } 2440 }
2481 2441
2482 void DataChannel::OnStreamClosedRemotely(uint32 sid) { 2442 void DataChannel::OnStreamClosedRemotely(uint32 sid) {
2483 rtc::TypedMessageData<uint32>* message = 2443 rtc::TypedMessageData<uint32>* message =
2484 new rtc::TypedMessageData<uint32>(sid); 2444 new rtc::TypedMessageData<uint32>(sid);
2485 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); 2445 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message);
2486 } 2446 }
2487 2447
2488 } // namespace cricket 2448 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698