Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #else | 32 #else |
| 33 #define ASSERT_CRYPTO(cd, s, cs) \ | 33 #define ASSERT_CRYPTO(cd, s, cs) \ |
| 34 ASSERT_EQ(cricket::CT_NONE, cd->crypto_required()); \ | 34 ASSERT_EQ(cricket::CT_NONE, cd->crypto_required()); \ |
| 35 ASSERT_EQ(0U, cd->cryptos().size()); | 35 ASSERT_EQ(0U, cd->cryptos().size()); |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 typedef std::vector<cricket::Candidate> Candidates; | 38 typedef std::vector<cricket::Candidate> Candidates; |
| 39 | 39 |
| 40 using cricket::MediaContentDescription; | 40 using cricket::MediaContentDescription; |
| 41 using cricket::MediaSessionDescriptionFactory; | 41 using cricket::MediaSessionDescriptionFactory; |
| 42 using cricket::MediaContentDirection; | |
| 42 using cricket::MediaSessionOptions; | 43 using cricket::MediaSessionOptions; |
| 43 using cricket::MediaType; | 44 using cricket::MediaType; |
| 44 using cricket::SessionDescription; | 45 using cricket::SessionDescription; |
| 45 using cricket::SsrcGroup; | 46 using cricket::SsrcGroup; |
| 46 using cricket::StreamParams; | 47 using cricket::StreamParams; |
| 47 using cricket::StreamParamsVec; | 48 using cricket::StreamParamsVec; |
| 48 using cricket::TransportDescription; | 49 using cricket::TransportDescription; |
| 49 using cricket::TransportDescriptionFactory; | 50 using cricket::TransportDescriptionFactory; |
| 50 using cricket::TransportInfo; | 51 using cricket::TransportInfo; |
| 51 using cricket::ContentInfo; | 52 using cricket::ContentInfo; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 codec_names.push_back(codec.name); | 205 codec_names.push_back(codec.name); |
| 205 } | 206 } |
| 206 return codec_names; | 207 return codec_names; |
| 207 } | 208 } |
| 208 | 209 |
| 209 class MediaSessionDescriptionFactoryTest : public testing::Test { | 210 class MediaSessionDescriptionFactoryTest : public testing::Test { |
| 210 public: | 211 public: |
| 211 MediaSessionDescriptionFactoryTest() | 212 MediaSessionDescriptionFactoryTest() |
| 212 : f1_(&tdf1_), | 213 : f1_(&tdf1_), |
| 213 f2_(&tdf2_) { | 214 f2_(&tdf2_) { |
| 214 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1)); | 215 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 216 MAKE_VECTOR(kAudioCodecs1)); | |
| 215 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); | 217 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 216 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); | 218 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
| 217 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2)); | 219 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 220 MAKE_VECTOR(kAudioCodecs2)); | |
| 218 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); | 221 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
| 219 f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); | 222 f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
| 220 tdf1_.set_certificate(rtc::RTCCertificate::Create( | 223 tdf1_.set_certificate(rtc::RTCCertificate::Create( |
| 221 std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); | 224 std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
| 222 tdf2_.set_certificate(rtc::RTCCertificate::Create( | 225 tdf2_.set_certificate(rtc::RTCCertificate::Create( |
| 223 std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); | 226 std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
| 224 } | 227 } |
| 225 | 228 |
| 226 // Create a video StreamParamsVec object with: | 229 // Create a video StreamParamsVec object with: |
| 227 // - one video stream with 3 simulcast streams and FEC, | 230 // - one video stream with 3 simulcast streams and FEC, |
| (...skipping 2160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2388 ASSERT_TRUE(video_content != nullptr); | 2391 ASSERT_TRUE(video_content != nullptr); |
| 2389 ASSERT_TRUE(data_content != nullptr); | 2392 ASSERT_TRUE(data_content != nullptr); |
| 2390 EXPECT_EQ("audio_modified", audio_content->name); | 2393 EXPECT_EQ("audio_modified", audio_content->name); |
| 2391 EXPECT_EQ("video_modified", video_content->name); | 2394 EXPECT_EQ("video_modified", video_content->name); |
| 2392 EXPECT_EQ("data_modified", data_content->name); | 2395 EXPECT_EQ("data_modified", data_content->name); |
| 2393 } | 2396 } |
| 2394 | 2397 |
| 2395 class MediaProtocolTest : public ::testing::TestWithParam<const char*> { | 2398 class MediaProtocolTest : public ::testing::TestWithParam<const char*> { |
| 2396 public: | 2399 public: |
| 2397 MediaProtocolTest() : f1_(&tdf1_), f2_(&tdf2_) { | 2400 MediaProtocolTest() : f1_(&tdf1_), f2_(&tdf2_) { |
| 2398 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1)); | 2401 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 2402 MAKE_VECTOR(kAudioCodecs1)); | |
| 2399 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); | 2403 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 2400 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); | 2404 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
| 2401 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2)); | 2405 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 2406 MAKE_VECTOR(kAudioCodecs2)); | |
| 2402 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); | 2407 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
| 2403 f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); | 2408 f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
| 2404 f1_.set_secure(SEC_ENABLED); | 2409 f1_.set_secure(SEC_ENABLED); |
| 2405 f2_.set_secure(SEC_ENABLED); | 2410 f2_.set_secure(SEC_ENABLED); |
| 2406 tdf1_.set_certificate(rtc::RTCCertificate::Create( | 2411 tdf1_.set_certificate(rtc::RTCCertificate::Create( |
| 2407 rtc::scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); | 2412 rtc::scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
| 2408 tdf2_.set_certificate(rtc::RTCCertificate::Create( | 2413 tdf2_.set_certificate(rtc::RTCCertificate::Create( |
| 2409 rtc::scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); | 2414 rtc::scoped_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id2")))); |
| 2410 tdf1_.set_secure(SEC_ENABLED); | 2415 tdf1_.set_secure(SEC_ENABLED); |
| 2411 tdf2_.set_secure(SEC_ENABLED); | 2416 tdf2_.set_secure(SEC_ENABLED); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2443 EXPECT_EQ(GetParam(), acd->protocol()); | 2448 EXPECT_EQ(GetParam(), acd->protocol()); |
| 2444 EXPECT_EQ(GetParam(), vcd->protocol()); | 2449 EXPECT_EQ(GetParam(), vcd->protocol()); |
| 2445 } | 2450 } |
| 2446 | 2451 |
| 2447 INSTANTIATE_TEST_CASE_P(MediaProtocolPatternTest, | 2452 INSTANTIATE_TEST_CASE_P(MediaProtocolPatternTest, |
| 2448 MediaProtocolTest, | 2453 MediaProtocolTest, |
| 2449 ::testing::ValuesIn(kMediaProtocols)); | 2454 ::testing::ValuesIn(kMediaProtocols)); |
| 2450 INSTANTIATE_TEST_CASE_P(MediaProtocolDtlsPatternTest, | 2455 INSTANTIATE_TEST_CASE_P(MediaProtocolDtlsPatternTest, |
| 2451 MediaProtocolTest, | 2456 MediaProtocolTest, |
| 2452 ::testing::ValuesIn(kMediaProtocolsDtls)); | 2457 ::testing::ValuesIn(kMediaProtocolsDtls)); |
| 2458 | |
| 2459 TEST_F(MediaSessionDescriptionFactoryTest, TestSetAudioCodecs) { | |
| 2460 TransportDescriptionFactory tdf; | |
| 2461 MediaSessionDescriptionFactory sf(&tdf); | |
| 2462 std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); | |
| 2463 std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); | |
| 2464 | |
| 2465 // The merged list of codecs should contain any send codecs that are also | |
| 2466 // nominally in the recieve codecs list. Payload types should be picked from | |
| 2467 // the send codecs and a number-of-channels of 0 and 1 should be equivalent | |
| 2468 // (set to 1). This equals what happens when the send codecs are used in an | |
| 2469 // offer and the receive codecs are used in the following answer. | |
| 2470 const std::vector<AudioCodec> sendrecv_codecs = | |
| 2471 MAKE_VECTOR(kAudioCodecsAnswer); | |
| 2472 const std::vector<AudioCodec> no_codecs; | |
| 2473 | |
| 2474 RTC_CHECK_EQ(send_codecs[1].name, "iLBC") | |
| 2475 << "Please don't change shared test data!"; | |
| 2476 RTC_CHECK_EQ(recv_codecs[2].name, "iLBC") | |
| 2477 << "Please don't change shared test data!"; | |
| 2478 // Alter iLBC send codec to have zero channels, to test that that is handled | |
| 2479 // properly. | |
| 2480 send_codecs[1].channels = 0; | |
| 2481 | |
| 2482 // Alther iLBC receive codec to be lowercase, to test that case conversions | |
| 2483 // are handled properly. | |
| 2484 recv_codecs[2].name = "ilbc"; | |
| 2485 | |
| 2486 // Test proper merge | |
| 2487 sf.set_audio_codecs(send_codecs, recv_codecs); | |
| 2488 EXPECT_TRUE(sf.audio_send_codecs() == send_codecs); | |
| 2489 EXPECT_TRUE(sf.audio_recv_codecs() == recv_codecs); | |
| 2490 EXPECT_TRUE(sf.audio_codecs() == sendrecv_codecs); | |
| 2491 | |
| 2492 // Test empty send codecs list | |
| 2493 sf.set_audio_codecs(no_codecs, recv_codecs); | |
| 2494 EXPECT_TRUE(sf.audio_send_codecs() == no_codecs); | |
| 2495 EXPECT_TRUE(sf.audio_recv_codecs() == recv_codecs); | |
| 2496 EXPECT_TRUE(sf.audio_codecs() == no_codecs); | |
| 2497 | |
| 2498 // Test empty recv codecs list | |
| 2499 sf.set_audio_codecs(send_codecs, no_codecs); | |
| 2500 EXPECT_TRUE(sf.audio_send_codecs() == send_codecs); | |
| 2501 EXPECT_TRUE(sf.audio_recv_codecs() == no_codecs); | |
| 2502 EXPECT_TRUE(sf.audio_codecs() == no_codecs); | |
| 2503 | |
| 2504 // Test all empty codec lists | |
| 2505 sf.set_audio_codecs(no_codecs, no_codecs); | |
| 2506 EXPECT_TRUE(sf.audio_send_codecs() == no_codecs); | |
| 2507 EXPECT_TRUE(sf.audio_recv_codecs() == no_codecs); | |
| 2508 EXPECT_TRUE(sf.audio_codecs() == no_codecs); | |
| 2509 } | |
| 2510 | |
| 2511 namespace { | |
| 2512 void TestAudioCodecsOffer(MediaContentDirection direction, | |
| 2513 bool add_legacy_stream) { | |
| 2514 TransportDescriptionFactory tdf; | |
| 2515 MediaSessionDescriptionFactory sf(&tdf); | |
| 2516 const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); | |
| 2517 const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); | |
| 2518 const std::vector<AudioCodec> sendrecv_codecs = | |
| 2519 MAKE_VECTOR(kAudioCodecsAnswer); | |
| 2520 sf.set_audio_codecs(send_codecs, recv_codecs); | |
| 2521 sf.set_add_legacy_streams(add_legacy_stream); | |
| 2522 | |
| 2523 MediaSessionOptions opts; | |
| 2524 opts.recv_audio = (direction == cricket::MD_RECVONLY || | |
| 2525 direction == cricket::MD_SENDRECV); | |
| 2526 opts.recv_video = false; | |
| 2527 if (direction == cricket::MD_SENDONLY || direction == cricket::MD_SENDRECV) | |
| 2528 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | |
| 2529 | |
| 2530 std::unique_ptr<SessionDescription> offer(sf.CreateOffer(opts, NULL)); | |
| 2531 ASSERT_TRUE(offer.get() != NULL); | |
| 2532 const ContentInfo* ac = offer->GetContentByName("audio"); | |
| 2533 | |
| 2534 // If the factory didn't add any audio content to the offer, we cannot check | |
| 2535 // that the codecs put in are right. This happens when we neither want to send | |
| 2536 // nor receive audio. The checks are still in place if at some point we'd | |
| 2537 // instead create an inactive stream. | |
| 2538 if (ac) { | |
| 2539 AudioContentDescription* acd = | |
| 2540 static_cast<AudioContentDescription*>(ac->description); | |
| 2541 // sendrecv and inactive should both present lists as if the channel was to | |
| 2542 // be used for sending and receiving. Inactive essentially means it might | |
| 2543 // eventually be used anything, but we don't know more at this moment. | |
| 2544 if (acd->direction() == cricket::MD_SENDONLY) { | |
| 2545 EXPECT_TRUE(acd->codecs() == send_codecs); | |
| 2546 } else if (acd->direction() == cricket::MD_RECVONLY) { | |
| 2547 EXPECT_TRUE(acd->codecs() == recv_codecs); | |
| 2548 } else { | |
| 2549 EXPECT_TRUE(acd->codecs() == sendrecv_codecs); | |
| 2550 } | |
| 2551 } | |
| 2552 } | |
| 2553 | |
| 2554 static const AudioCodec kOfferAnswerCodecs[] = { | |
| 2555 AudioCodec(0, "codec0", 16000, -1, 1), | |
| 2556 AudioCodec(1, "codec1", 8000, 13300, 1), | |
| 2557 AudioCodec(2, "codec2", 8000, 64000, 1), | |
| 2558 AudioCodec(3, "codec3", 8000, 64000, 1), | |
| 2559 AudioCodec(4, "codec4", 8000, 0, 2), | |
| 2560 AudioCodec(5, "codec5", 32000, 0, 1), | |
| 2561 AudioCodec(6, "codec6", 48000, 0, 1) | |
| 2562 }; | |
| 2563 | |
| 2564 | |
| 2565 /* The codecs groups below are chosen as per the matrix below. The objective is | |
| 2566 * to have different sets of codecs in the inputs, to get unique sets of codecs | |
| 2567 * after negotiation, depending on offer and answer communication directions. | |
| 2568 * One-way directions in the offer should either result in the opposite | |
| 2569 * direction in the answer, or an inactive answer. Regardless, the choice of | |
| 2570 * codecs should be as if the answer contained the opposite direction. | |
| 2571 * Inactive offers should be treated as sendrecv/sendrecv. | |
| 2572 * | |
| 2573 * | Offer | Answer | Result | |
| 2574 * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr | |
|
ossu
2016/06/10 13:15:19
Cleaned out special handling of the answerer wanti
| |
| 2575 * 0 | x - - | - x - | x - - - - | |
| 2576 * 1 | x x x | - x - | x - - x - | |
| 2577 * 2 | - x - | x - - | - x - - - | |
| 2578 * 3 | x x x | x - - | - x x - - | |
| 2579 * 4 | - x - | x x x | - x - - - | |
| 2580 * 5 | x - - | x x x | x - - - - | |
| 2581 * 6 | x x x | x x x | x x x x x | |
| 2582 */ | |
| 2583 // Codecs used by offerer in the AudioCodecsAnswerTest | |
| 2584 static const int kOfferSendCodecs[] = { 0, 1, 3, 5, 6 }; | |
| 2585 static const int kOfferRecvCodecs[] = { 1, 2, 3, 4, 6 }; | |
| 2586 // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is | |
| 2587 // jumbled to catch the answer not following the order in the offer. | |
| 2588 static const int kAnswerSendCodecs[] = { 6, 5, 2, 3, 4 }; | |
| 2589 static const int kAnswerRecvCodecs[] = { 6, 5, 4, 1, 0 }; | |
| 2590 // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest | |
| 2591 static const int kResultSend_RecvCodecs[] = { 0, 1, 5, 6 }; | |
| 2592 static const int kResultRecv_SendCodecs[] = { 2, 3, 4, 6 }; | |
| 2593 static const int kResultSendrecv_SendCodecs[] = { 3, 6 }; | |
| 2594 static const int kResultSendrecv_RecvCodecs[] = { 1, 6 }; | |
| 2595 static const int kResultSendrecv_SendrecvCodecs[] = { 6 }; | |
| 2596 | |
| 2597 template <typename T, int IDXS> | |
| 2598 std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { | |
| 2599 std::vector<T> out; | |
| 2600 out.reserve(IDXS); | |
| 2601 for (int idx : indices) | |
| 2602 out.push_back(array[idx]); | |
| 2603 | |
| 2604 return out; | |
| 2605 } | |
| 2606 | |
| 2607 void TestAudioCodecsAnswer(MediaContentDirection offer_direction, | |
| 2608 MediaContentDirection answer_direction, | |
| 2609 bool add_legacy_stream) { | |
| 2610 TransportDescriptionFactory offer_tdf; | |
| 2611 TransportDescriptionFactory answer_tdf; | |
| 2612 MediaSessionDescriptionFactory offer_factory(&offer_tdf); | |
| 2613 MediaSessionDescriptionFactory answer_factory(&answer_tdf); | |
| 2614 offer_factory.set_audio_codecs( | |
| 2615 VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs), | |
| 2616 VectorFromIndices(kOfferAnswerCodecs, kOfferRecvCodecs)); | |
| 2617 answer_factory.set_audio_codecs( | |
| 2618 VectorFromIndices(kOfferAnswerCodecs, kAnswerSendCodecs), | |
| 2619 VectorFromIndices(kOfferAnswerCodecs, kAnswerRecvCodecs)); | |
| 2620 | |
| 2621 // Never add a legacy stream to offer - we want to control the offer | |
| 2622 // parameters exactly. | |
| 2623 offer_factory.set_add_legacy_streams(false); | |
| 2624 answer_factory.set_add_legacy_streams(add_legacy_stream); | |
| 2625 MediaSessionOptions offer_opts; | |
| 2626 offer_opts.recv_audio = (offer_direction == cricket::MD_RECVONLY || | |
| 2627 offer_direction == cricket::MD_SENDRECV); | |
| 2628 offer_opts.recv_video = false; | |
| 2629 if (offer_direction == cricket::MD_SENDONLY || | |
| 2630 offer_direction == cricket::MD_SENDRECV) { | |
| 2631 offer_opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | |
| 2632 } | |
| 2633 | |
| 2634 std::unique_ptr<SessionDescription> offer( | |
| 2635 offer_factory.CreateOffer(offer_opts, NULL)); | |
| 2636 ASSERT_TRUE(offer.get() != NULL); | |
| 2637 | |
| 2638 MediaSessionOptions answer_opts; | |
| 2639 answer_opts.recv_audio = (answer_direction == cricket::MD_RECVONLY || | |
| 2640 answer_direction == cricket::MD_SENDRECV); | |
| 2641 answer_opts.recv_video = false; | |
| 2642 if (answer_direction == cricket::MD_SENDONLY || | |
| 2643 answer_direction == cricket::MD_SENDRECV) { | |
| 2644 answer_opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | |
| 2645 } | |
| 2646 std::unique_ptr<SessionDescription> answer( | |
| 2647 answer_factory.CreateAnswer(offer.get(), answer_opts, NULL)); | |
| 2648 const ContentInfo* ac = answer->GetContentByName("audio"); | |
| 2649 | |
| 2650 // If the factory didn't add any audio content to the answer, we cannot check | |
| 2651 // that the codecs put in are right. This happens when we neither want to send | |
| 2652 // nor receive audio. The checks are still in place if at some point we'd | |
| 2653 // instead create an inactive stream. | |
| 2654 if (ac) { | |
| 2655 const AudioContentDescription* acd = | |
| 2656 static_cast<const AudioContentDescription*>(ac->description); | |
| 2657 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | |
| 2658 | |
| 2659 | |
| 2660 std::vector<AudioCodec> target_codecs; | |
| 2661 // For offers with sendrecv or inactive, we should never reply with more | |
| 2662 // codecs than offered, with these codec sets. | |
| 2663 switch (offer_direction) { | |
| 2664 case cricket::MD_INACTIVE: | |
| 2665 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | |
| 2666 kResultSendrecv_SendrecvCodecs); | |
| 2667 break; | |
| 2668 case cricket::MD_SENDONLY: | |
| 2669 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | |
| 2670 kResultSend_RecvCodecs); | |
| 2671 break; | |
| 2672 case cricket::MD_RECVONLY: | |
| 2673 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | |
| 2674 kResultRecv_SendCodecs); | |
| 2675 break; | |
| 2676 case cricket::MD_SENDRECV: | |
| 2677 if (acd->direction() == cricket::MD_SENDONLY) { | |
| 2678 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | |
| 2679 kResultSendrecv_SendCodecs); | |
| 2680 } else if (acd->direction() == cricket::MD_RECVONLY) { | |
| 2681 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | |
| 2682 kResultSendrecv_RecvCodecs); | |
| 2683 } else { | |
| 2684 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | |
| 2685 kResultSendrecv_SendrecvCodecs); | |
| 2686 } | |
| 2687 break; | |
| 2688 } | |
| 2689 | |
| 2690 auto format_codecs = [] (const std::vector<AudioCodec>& codecs) { | |
| 2691 std::stringstream os; | |
| 2692 bool first = true; | |
| 2693 os << "{"; | |
| 2694 for (const auto& c : codecs) { | |
| 2695 os << (first ? " " : ", ") << c.id; | |
| 2696 first = false; | |
| 2697 } | |
| 2698 os << " }"; | |
| 2699 return os.str(); | |
| 2700 }; | |
| 2701 | |
| 2702 EXPECT_TRUE(acd->codecs() == target_codecs) | |
| 2703 << "Expected: " << format_codecs(target_codecs) | |
| 2704 << ", got: " << format_codecs(acd->codecs()) | |
| 2705 << "; Offered: " << MediaContentDirectionToString(offer_direction) | |
| 2706 << ", answerer wants: " | |
| 2707 << MediaContentDirectionToString(answer_direction) | |
| 2708 << "; got: " << MediaContentDirectionToString(acd->direction()); | |
| 2709 } else { | |
| 2710 EXPECT_EQ(offer_direction, cricket::MD_INACTIVE) | |
| 2711 << "Only inactive offers are allowed to not generate any audio content"; | |
| 2712 } | |
| 2713 } | |
| 2714 } | |
| 2715 | |
| 2716 class AudioCodecsOfferTest | |
| 2717 : public ::testing::TestWithParam<std::tr1::tuple<MediaContentDirection, | |
| 2718 bool>> { | |
| 2719 }; | |
| 2720 | |
| 2721 TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { | |
| 2722 TestAudioCodecsOffer(std::tr1::get<0>(GetParam()), | |
| 2723 std::tr1::get<1>(GetParam())); | |
| 2724 } | |
| 2725 | |
| 2726 INSTANTIATE_TEST_CASE_P(MediaSessionDescriptionFactoryTest, | |
| 2727 AudioCodecsOfferTest, | |
| 2728 ::testing::Combine( | |
| 2729 ::testing::Values(cricket::MD_SENDONLY, | |
| 2730 cricket::MD_RECVONLY, | |
| 2731 cricket::MD_SENDRECV, | |
| 2732 cricket::MD_INACTIVE), | |
| 2733 ::testing::Bool())); | |
| 2734 | |
| 2735 class AudioCodecsAnswerTest | |
| 2736 : public ::testing::TestWithParam<std::tr1::tuple<MediaContentDirection, | |
| 2737 MediaContentDirection, | |
| 2738 bool>> { | |
| 2739 }; | |
| 2740 | |
| 2741 TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { | |
| 2742 TestAudioCodecsAnswer(std::tr1::get<0>(GetParam()), | |
| 2743 std::tr1::get<1>(GetParam()), | |
| 2744 std::tr1::get<2>(GetParam())); | |
| 2745 } | |
| 2746 | |
| 2747 INSTANTIATE_TEST_CASE_P(MediaSessionDescriptionFactoryTest, | |
| 2748 AudioCodecsAnswerTest, | |
| 2749 ::testing::Combine( | |
| 2750 ::testing::Values(cricket::MD_SENDONLY, | |
| 2751 cricket::MD_RECVONLY, | |
| 2752 cricket::MD_SENDRECV, | |
| 2753 cricket::MD_INACTIVE), | |
| 2754 ::testing::Values(cricket::MD_SENDONLY, | |
| 2755 cricket::MD_RECVONLY, | |
| 2756 cricket::MD_SENDRECV, | |
| 2757 cricket::MD_INACTIVE), | |
| 2758 ::testing::Bool())); | |
| OLD | NEW |