Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / session / media / mediasession.cc
index ba510b9..8219ec8 100644 (file)
@@ -308,6 +308,20 @@ static void GetCurrentStreamParams(const SessionDescription* sdesc,
   }
 }
 
+// Filters the data codecs for the data channel type.
+void FilterDataCodecs(std::vector<DataCodec>* codecs, bool sctp) {
+  // Filter RTP codec for SCTP and vice versa.
+  int codec_id = sctp ? kGoogleRtpDataCodecId : kGoogleSctpDataCodecId;
+  for (std::vector<DataCodec>::iterator iter = codecs->begin();
+       iter != codecs->end();) {
+    if (iter->id == codec_id) {
+      iter = codecs->erase(iter);
+    } else {
+      ++iter;
+    }
+  }
+}
+
 template <typename IdStruct>
 class UsedIds {
  public:
@@ -398,9 +412,9 @@ class UsedRtpHeaderExtensionIds : public UsedIds<RtpHeaderExtension> {
   }
 
  private:
-  // Min and Max local identifier as specified by RFC5285.
+  // Min and Max local identifier for one-byte header extensions, per RFC5285.
   static const int kLocalIdMin = 1;
-  static const int kLocalIdMax = 255;
+  static const int kLocalIdMax = 14;
 };
 
 static bool IsSctp(const MediaContentDescription* desc) {
@@ -691,7 +705,7 @@ template <class C>
 static bool CreateMediaContentOffer(
     const MediaSessionOptions& options,
     const std::vector<C>& codecs,
-    const SecureMediaPolicy& secure_policy,
+    const SecurePolicy& secure_policy,
     const CryptoParamsVec* current_cryptos,
     const std::vector<std::string>& crypto_suites,
     const RtpHeaderExtensions& rtp_extensions,
@@ -701,7 +715,9 @@ static bool CreateMediaContentOffer(
   offer->AddCodecs(codecs);
   offer->SortCodecs();
 
-  offer->set_crypto_required(secure_policy == SEC_REQUIRED);
+  if (secure_policy == SEC_REQUIRED) {
+    offer->set_crypto_required(CT_SDES);
+  }
   offer->set_rtcp_mux(options.rtcp_mux_enabled);
   offer->set_multistream(options.is_muc);
   offer->set_rtp_header_extensions(rtp_extensions);
@@ -725,7 +741,7 @@ static bool CreateMediaContentOffer(
   }
 #endif
 
-  if (offer->crypto_required() && offer->cryptos().empty()) {
+  if (offer->crypto_required() == CT_SDES && offer->cryptos().empty()) {
     return false;
   }
   return true;
@@ -841,7 +857,7 @@ static bool FindByUri(const RtpHeaderExtensions& extensions,
     // We assume that all URIs are given in a canonical format.
     if (it->uri == ext_to_match.uri) {
       if (found_extension != NULL) {
-        *found_extension= *it;
+        *found_extension = *it;
       }
       return true;
     }
@@ -852,12 +868,16 @@ static bool FindByUri(const RtpHeaderExtensions& extensions,
 static void FindAndSetRtpHdrExtUsed(
   const RtpHeaderExtensions& reference_extensions,
   RtpHeaderExtensions* offered_extensions,
+  const RtpHeaderExtensions& other_extensions,
   UsedRtpHeaderExtensionIds* used_extensions) {
   for (RtpHeaderExtensions::const_iterator it = reference_extensions.begin();
       it != reference_extensions.end(); ++it) {
     if (!FindByUri(*offered_extensions, *it, NULL)) {
-      RtpHeaderExtension ext = *it;
-      used_extensions->FindAndSetIdUsed(&ext);
+      RtpHeaderExtension ext;
+      if (!FindByUri(other_extensions, *it, &ext)) {
+        ext = *it;
+        used_extensions->FindAndSetIdUsed(&ext);
+      }
       offered_extensions->push_back(ext);
     }
   }
@@ -903,7 +923,7 @@ static bool CreateMediaContentAnswer(
     const MediaContentDescriptionImpl<C>* offer,
     const MediaSessionOptions& options,
     const std::vector<C>& local_codecs,
-    const SecureMediaPolicy& sdes_policy,
+    const SecurePolicy& sdes_policy,
     const CryptoParamsVec* current_cryptos,
     const RtpHeaderExtensions& local_rtp_extenstions,
     StreamParamsVec* current_streams,
@@ -934,7 +954,7 @@ static bool CreateMediaContentAnswer(
   }
 
   if (answer->cryptos().empty() &&
-      (offer->crypto_required() || sdes_policy == SEC_REQUIRED)) {
+      (offer->crypto_required() == CT_SDES || sdes_policy == SEC_REQUIRED)) {
     return false;
   }
 
@@ -1024,6 +1044,25 @@ static bool IsDtlsActive(
   return current_tdesc->secure();
 }
 
+std::string MediaTypeToString(MediaType type) {
+  std::string type_str;
+  switch (type) {
+    case MEDIA_TYPE_AUDIO:
+      type_str = "audio";
+      break;
+    case MEDIA_TYPE_VIDEO:
+      type_str = "video";
+      break;
+    case MEDIA_TYPE_DATA:
+      type_str = "data";
+      break;
+    default:
+      ASSERT(false);
+      break;
+  }
+  return type_str;
+}
+
 void MediaSessionOptions::AddStream(MediaType type,
                                     const std::string& id,
                                     const std::string& sync_label) {
@@ -1179,6 +1218,8 @@ SessionDescription* MediaSessionDescriptionFactory::CreateOffer(
     scoped_ptr<DataContentDescription> data(new DataContentDescription());
     bool is_sctp = (options.data_channel_type == DCT_SCTP);
 
+    FilterDataCodecs(&data_codecs, is_sctp);
+
     cricket::SecurePolicy sdes_policy =
         IsDtlsActive(CN_DATA, current_description) ?
             cricket::SEC_DISABLED : secure();
@@ -1372,6 +1413,10 @@ SessionDescription* MediaSessionDescriptionFactory::CreateAnswer(
     if (!data_transport) {
       return NULL;
     }
+    bool is_sctp = (options.data_channel_type == DCT_SCTP);
+    std::vector<DataCodec> data_codecs(data_codecs_);
+    FilterDataCodecs(&data_codecs, is_sctp);
+
     scoped_ptr<DataContentDescription> data_answer(
         new DataContentDescription());
     // Do not require or create SDES cryptos if DTLS is used.
@@ -1488,6 +1533,8 @@ void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer(
     const SessionDescription* current_description,
     RtpHeaderExtensions* audio_extensions,
     RtpHeaderExtensions* video_extensions) const {
+  // All header extensions allocated from the same range to avoid potential
+  // issues when using BUNDLE.
   UsedRtpHeaderExtensionIds used_ids;
   audio_extensions->clear();
   video_extensions->clear();
@@ -1514,9 +1561,9 @@ void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer(
   // Add our default RTP header extensions that are not in
   // |current_description|.
   FindAndSetRtpHdrExtUsed(audio_rtp_header_extensions(), audio_extensions,
-                          &used_ids);
+                          *video_extensions, &used_ids);
   FindAndSetRtpHdrExtUsed(video_rtp_header_extensions(), video_extensions,
-                          &used_ids);
+                          *audio_extensions, &used_ids);
 }
 
 bool MediaSessionDescriptionFactory::AddTransportOffer(