Home | History | Annotate | Download | only in media
      1 // libjingle
      2 // Copyright 2009 Google Inc.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are met:
      6 //
      7 //  1. Redistributions of source code must retain the above copyright notice,
      8 //     this list of conditions and the following disclaimer.
      9 //  2. Redistributions in binary form must reproduce the above copyright notice,
     10 //     this list of conditions and the following disclaimer in the documentation
     11 //     and/or other materials provided with the distribution.
     12 //  3. The name of the author may not be used to endorse or promote products
     13 //     derived from this software without specific prior written permission.
     14 //
     15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
     18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 
     26 #include "talk/base/fileutils.h"
     27 #include "talk/base/gunit.h"
     28 #include "talk/base/helpers.h"
     29 #include "talk/base/logging.h"
     30 #include "talk/base/pathutils.h"
     31 #include "talk/base/signalthread.h"
     32 #include "talk/base/ssladapter.h"
     33 #include "talk/base/sslidentity.h"
     34 #include "talk/base/window.h"
     35 #include "talk/media/base/fakemediaengine.h"
     36 #include "talk/media/base/fakertp.h"
     37 #include "talk/media/base/fakevideocapturer.h"
     38 #include "talk/media/base/mediachannel.h"
     39 #include "talk/media/base/rtpdump.h"
     40 #include "talk/media/base/screencastid.h"
     41 #include "talk/media/base/testutils.h"
     42 #include "talk/p2p/base/fakesession.h"
     43 #include "talk/session/media/channel.h"
     44 #include "talk/session/media/mediamessages.h"
     45 #include "talk/session/media/mediarecorder.h"
     46 #include "talk/session/media/mediasessionclient.h"
     47 #include "talk/session/media/typingmonitor.h"
     48 
     49 #define MAYBE_SKIP_TEST(feature)                    \
     50   if (!(talk_base::SSLStreamAdapter::feature())) {  \
     51     LOG(LS_INFO) << "Feature disabled... skipping"; \
     52     return;                                         \
     53   }
     54 
     55 using cricket::CA_OFFER;
     56 using cricket::CA_PRANSWER;
     57 using cricket::CA_ANSWER;
     58 using cricket::CA_UPDATE;
     59 using cricket::FakeVoiceMediaChannel;
     60 using cricket::ScreencastId;
     61 using cricket::StreamParams;
     62 using cricket::TransportChannel;
     63 using talk_base::WindowId;
     64 
     65 static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
     66 static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
     67 static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
     68 static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
     69 static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
     70 static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
     71 static const uint32 kSsrc1 = 0x1111;
     72 static const uint32 kSsrc2 = 0x2222;
     73 static const uint32 kSsrc3 = 0x3333;
     74 static const char kCName[] = "a (at) b.com";
     75 
     76 template<class ChannelT,
     77          class MediaChannelT,
     78          class ContentT,
     79          class CodecT,
     80          class MediaInfoT>
     81 class Traits {
     82  public:
     83   typedef ChannelT Channel;
     84   typedef MediaChannelT MediaChannel;
     85   typedef ContentT Content;
     86   typedef CodecT Codec;
     87   typedef MediaInfoT MediaInfo;
     88 };
     89 
     90 class FakeScreenCaptureFactory
     91     : public cricket::VideoChannel::ScreenCapturerFactory,
     92       public sigslot::has_slots<> {
     93  public:
     94   FakeScreenCaptureFactory()
     95       : window_capturer_(NULL),
     96         capture_state_(cricket::CS_STOPPED) {}
     97 
     98   virtual cricket::VideoCapturer* CreateScreenCapturer(
     99       const ScreencastId& window) {
    100     if (window_capturer_ != NULL) {
    101       // Class is only designed to handle one fake screencapturer.
    102       ADD_FAILURE();
    103       return NULL;
    104     }
    105     window_capturer_ = new cricket::FakeVideoCapturer;
    106     window_capturer_->SignalDestroyed.connect(
    107         this,
    108         &FakeScreenCaptureFactory::OnWindowCapturerDestroyed);
    109     window_capturer_->SignalStateChange.connect(
    110         this,
    111         &FakeScreenCaptureFactory::OnStateChange);
    112     return window_capturer_;
    113   }
    114 
    115   cricket::FakeVideoCapturer* window_capturer() { return window_capturer_; }
    116 
    117   cricket::CaptureState capture_state() { return capture_state_; }
    118 
    119  private:
    120   void OnWindowCapturerDestroyed(cricket::FakeVideoCapturer* capturer) {
    121     if (capturer == window_capturer_) {
    122       window_capturer_ = NULL;
    123     }
    124   }
    125   void OnStateChange(cricket::VideoCapturer*, cricket::CaptureState state) {
    126     capture_state_ = state;
    127   }
    128 
    129   cricket::FakeVideoCapturer* window_capturer_;
    130   cricket::CaptureState capture_state_;
    131 };
    132 
    133 // Controls how long we wait for a session to send messages that we
    134 // expect, in milliseconds.  We put it high to avoid flaky tests.
    135 static const int kEventTimeout = 5000;
    136 
    137 class VoiceTraits : public Traits<cricket::VoiceChannel,
    138                                   cricket::FakeVoiceMediaChannel,
    139                                   cricket::AudioContentDescription,
    140                                   cricket::AudioCodec,
    141                                   cricket::VoiceMediaInfo> {
    142 };
    143 
    144 class VideoTraits : public Traits<cricket::VideoChannel,
    145                                   cricket::FakeVideoMediaChannel,
    146                                   cricket::VideoContentDescription,
    147                                   cricket::VideoCodec,
    148                                   cricket::VideoMediaInfo> {
    149 };
    150 
    151 class DataTraits : public Traits<cricket::DataChannel,
    152                                  cricket::FakeDataMediaChannel,
    153                                  cricket::DataContentDescription,
    154                                  cricket::DataCodec,
    155                                  cricket::DataMediaInfo> {
    156 };
    157 
    158 
    159 talk_base::StreamInterface* Open(const std::string& path) {
    160   return talk_base::Filesystem::OpenFile(
    161       talk_base::Pathname(path), "wb");
    162 }
    163 
    164 // Base class for Voice/VideoChannel tests
    165 template<class T>
    166 class ChannelTest : public testing::Test, public sigslot::has_slots<> {
    167  public:
    168   enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
    169                DTLS = 0x10 };
    170 
    171   ChannelTest(const uint8* rtp_data, int rtp_len,
    172               const uint8* rtcp_data, int rtcp_len)
    173       : session1_(true),
    174         session2_(false),
    175         media_channel1_(NULL),
    176         media_channel2_(NULL),
    177         rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
    178         rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
    179         media_info_callbacks1_(),
    180         media_info_callbacks2_(),
    181         mute_callback_recved_(false),
    182         mute_callback_value_(false),
    183         ssrc_(0),
    184         error_(T::MediaChannel::ERROR_NONE) {
    185   }
    186 
    187   static void SetUpTestCase() {
    188     talk_base::InitializeSSL();
    189   }
    190 
    191   static void TearDownTestCase() {
    192     talk_base::CleanupSSL();
    193   }
    194 
    195   void CreateChannels(int flags1, int flags2) {
    196     CreateChannels(new typename T::MediaChannel(NULL),
    197                    new typename T::MediaChannel(NULL),
    198                    flags1, flags2, talk_base::Thread::Current());
    199   }
    200   void CreateChannels(int flags) {
    201      CreateChannels(new typename T::MediaChannel(NULL),
    202                     new typename T::MediaChannel(NULL),
    203                     flags, talk_base::Thread::Current());
    204   }
    205   void CreateChannels(int flags1, int flags2,
    206                       talk_base::Thread* thread) {
    207     CreateChannels(new typename T::MediaChannel(NULL),
    208                    new typename T::MediaChannel(NULL),
    209                    flags1, flags2, thread);
    210   }
    211   void CreateChannels(int flags,
    212                       talk_base::Thread* thread) {
    213     CreateChannels(new typename T::MediaChannel(NULL),
    214                    new typename T::MediaChannel(NULL),
    215                    flags, thread);
    216   }
    217   void CreateChannels(
    218       typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
    219       int flags1, int flags2, talk_base::Thread* thread) {
    220     media_channel1_ = ch1;
    221     media_channel2_ = ch2;
    222     channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
    223                                   (flags1 & RTCP) != 0));
    224     channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
    225                                   (flags2 & RTCP) != 0));
    226     channel1_->SignalMediaMonitor.connect(
    227         this, &ChannelTest<T>::OnMediaMonitor);
    228     channel2_->SignalMediaMonitor.connect(
    229         this, &ChannelTest<T>::OnMediaMonitor);
    230     channel1_->SignalMediaError.connect(
    231         this, &ChannelTest<T>::OnMediaChannelError);
    232     channel2_->SignalMediaError.connect(
    233         this, &ChannelTest<T>::OnMediaChannelError);
    234     channel1_->SignalAutoMuted.connect(
    235         this, &ChannelTest<T>::OnMediaMuted);
    236     CreateContent(flags1, kPcmuCodec, kH264Codec,
    237                   &local_media_content1_);
    238     CreateContent(flags2, kPcmuCodec, kH264Codec,
    239                   &local_media_content2_);
    240     CopyContent(local_media_content1_, &remote_media_content1_);
    241     CopyContent(local_media_content2_, &remote_media_content2_);
    242 
    243     if (flags1 & DTLS) {
    244       identity1_.reset(talk_base::SSLIdentity::Generate("session1"));
    245       session1_.set_ssl_identity(identity1_.get());
    246     }
    247     if (flags2 & DTLS) {
    248       identity2_.reset(talk_base::SSLIdentity::Generate("session2"));
    249       session2_.set_ssl_identity(identity2_.get());
    250     }
    251 
    252     // Add stream information (SSRC) to the local content but not to the remote
    253     // content. This means that we per default know the SSRC of what we send but
    254     // not what we receive.
    255     AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
    256     AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
    257 
    258     // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
    259     if (flags1 & SSRC_MUX) {
    260       AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
    261     }
    262     if (flags2 & SSRC_MUX) {
    263       AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
    264     }
    265   }
    266 
    267   void CreateChannels(
    268       typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
    269       int flags, talk_base::Thread* thread) {
    270     media_channel1_ = ch1;
    271     media_channel2_ = ch2;
    272 
    273     channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
    274                                   (flags & RTCP) != 0));
    275     channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
    276                                   (flags & RTCP) != 0));
    277     channel1_->SignalMediaMonitor.connect(
    278         this, &ChannelTest<T>::OnMediaMonitor);
    279     channel2_->SignalMediaMonitor.connect(
    280         this, &ChannelTest<T>::OnMediaMonitor);
    281     channel2_->SignalMediaError.connect(
    282         this, &ChannelTest<T>::OnMediaChannelError);
    283     CreateContent(flags, kPcmuCodec, kH264Codec,
    284                   &local_media_content1_);
    285     CreateContent(flags, kPcmuCodec, kH264Codec,
    286                   &local_media_content2_);
    287     CopyContent(local_media_content1_, &remote_media_content1_);
    288     CopyContent(local_media_content2_, &remote_media_content2_);
    289     // Add stream information (SSRC) to the local content but not to the remote
    290     // content. This means that we per default know the SSRC of what we send but
    291     // not what we receive.
    292     AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
    293     AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
    294 
    295     // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
    296     if (flags & SSRC_MUX) {
    297       AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
    298       AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
    299     }
    300   }
    301 
    302   typename T::Channel* CreateChannel(talk_base::Thread* thread,
    303                                      cricket::MediaEngineInterface* engine,
    304                                      typename T::MediaChannel* ch,
    305                                      cricket::BaseSession* session,
    306                                      bool rtcp) {
    307     typename T::Channel* channel = new typename T::Channel(
    308         thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
    309     if (!channel->Init()) {
    310       delete channel;
    311       channel = NULL;
    312     }
    313     return channel;
    314   }
    315 
    316   bool SendInitiate() {
    317     bool result = channel1_->SetLocalContent(&local_media_content1_, CA_OFFER);
    318     if (result) {
    319       channel1_->Enable(true);
    320       result = channel2_->SetRemoteContent(&remote_media_content1_, CA_OFFER);
    321       if (result) {
    322         session1_.Connect(&session2_);
    323 
    324         result = channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER);
    325       }
    326     }
    327     return result;
    328   }
    329 
    330   bool SendAccept() {
    331     channel2_->Enable(true);
    332     return channel1_->SetRemoteContent(&remote_media_content2_, CA_ANSWER);
    333   }
    334 
    335   bool SendOffer() {
    336     bool result = channel1_->SetLocalContent(&local_media_content1_, CA_OFFER);
    337     if (result) {
    338       channel1_->Enable(true);
    339       result = channel2_->SetRemoteContent(&remote_media_content1_, CA_OFFER);
    340     }
    341     return result;
    342   }
    343 
    344   bool SendProvisionalAnswer() {
    345     bool result = channel2_->SetLocalContent(&local_media_content2_,
    346                                              CA_PRANSWER);
    347     if (result) {
    348       channel2_->Enable(true);
    349       result = channel1_->SetRemoteContent(&remote_media_content2_,
    350                                            CA_PRANSWER);
    351       session1_.Connect(&session2_);
    352     }
    353     return result;
    354   }
    355 
    356   bool SendFinalAnswer() {
    357     bool result = channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER);
    358     if (result)
    359       result = channel1_->SetRemoteContent(&remote_media_content2_, CA_ANSWER);
    360     return result;
    361   }
    362 
    363   bool SendTerminate() {
    364     channel1_.reset();
    365     channel2_.reset();
    366     return true;
    367   }
    368 
    369   bool AddStream1(int id) {
    370     return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
    371   }
    372   bool RemoveStream1(int id) {
    373     return channel1_->RemoveRecvStream(id);
    374   }
    375 
    376   cricket::FakeTransport* GetTransport1() {
    377     return session1_.GetTransport(channel1_->content_name());
    378   }
    379   cricket::FakeTransport* GetTransport2() {
    380     return session2_.GetTransport(channel2_->content_name());
    381   }
    382 
    383   bool SendRtp1() {
    384     return media_channel1_->SendRtp(rtp_packet_.c_str(),
    385                                     static_cast<int>(rtp_packet_.size()));
    386   }
    387   bool SendRtp2() {
    388     return media_channel2_->SendRtp(rtp_packet_.c_str(),
    389                                     static_cast<int>(rtp_packet_.size()));
    390   }
    391   bool SendRtcp1() {
    392     return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
    393                                      static_cast<int>(rtcp_packet_.size()));
    394   }
    395   bool SendRtcp2() {
    396     return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
    397                                      static_cast<int>(rtcp_packet_.size()));
    398   }
    399   // Methods to send custom data.
    400   bool SendCustomRtp1(uint32 ssrc, int sequence_number) {
    401     std::string data(CreateRtpData(ssrc, sequence_number));
    402     return media_channel1_->SendRtp(data.c_str(),
    403                                     static_cast<int>(data.size()));
    404   }
    405   bool SendCustomRtp2(uint32 ssrc, int sequence_number) {
    406     std::string data(CreateRtpData(ssrc, sequence_number));
    407     return media_channel2_->SendRtp(data.c_str(),
    408                                     static_cast<int>(data.size()));
    409   }
    410   bool SendCustomRtcp1(uint32 ssrc) {
    411     std::string data(CreateRtcpData(ssrc));
    412     return media_channel1_->SendRtcp(data.c_str(),
    413                                      static_cast<int>(data.size()));
    414   }
    415   bool SendCustomRtcp2(uint32 ssrc) {
    416     std::string data(CreateRtcpData(ssrc));
    417     return media_channel2_->SendRtcp(data.c_str(),
    418                                      static_cast<int>(data.size()));
    419   }
    420   bool CheckRtp1() {
    421     return media_channel1_->CheckRtp(rtp_packet_.c_str(),
    422                                      static_cast<int>(rtp_packet_.size()));
    423   }
    424   bool CheckRtp2() {
    425     return media_channel2_->CheckRtp(rtp_packet_.c_str(),
    426                                      static_cast<int>(rtp_packet_.size()));
    427   }
    428   bool CheckRtcp1() {
    429     return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
    430                                       static_cast<int>(rtcp_packet_.size()));
    431   }
    432   bool CheckRtcp2() {
    433     return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
    434                                       static_cast<int>(rtcp_packet_.size()));
    435   }
    436   // Methods to check custom data.
    437   bool CheckCustomRtp1(uint32 ssrc, int sequence_number) {
    438     std::string data(CreateRtpData(ssrc, sequence_number));
    439     return media_channel1_->CheckRtp(data.c_str(),
    440                                      static_cast<int>(data.size()));
    441   }
    442   bool CheckCustomRtp2(uint32 ssrc, int sequence_number) {
    443     std::string data(CreateRtpData(ssrc, sequence_number));
    444     return media_channel2_->CheckRtp(data.c_str(),
    445                                      static_cast<int>(data.size()));
    446   }
    447   bool CheckCustomRtcp1(uint32 ssrc) {
    448     std::string data(CreateRtcpData(ssrc));
    449     return media_channel1_->CheckRtcp(data.c_str(),
    450                                       static_cast<int>(data.size()));
    451   }
    452   bool CheckCustomRtcp2(uint32 ssrc) {
    453     std::string data(CreateRtcpData(ssrc));
    454     return media_channel2_->CheckRtcp(data.c_str(),
    455                                       static_cast<int>(data.size()));
    456   }
    457   std::string CreateRtpData(uint32 ssrc, int sequence_number) {
    458     std::string data(rtp_packet_);
    459     // Set SSRC in the rtp packet copy.
    460     talk_base::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
    461     talk_base::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
    462     return data;
    463   }
    464   std::string CreateRtcpData(uint32 ssrc) {
    465     std::string data(rtcp_packet_);
    466     // Set SSRC in the rtcp packet copy.
    467     talk_base::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
    468     return data;
    469   }
    470 
    471   bool CheckNoRtp1() {
    472     return media_channel1_->CheckNoRtp();
    473   }
    474   bool CheckNoRtp2() {
    475     return media_channel2_->CheckNoRtp();
    476   }
    477   bool CheckNoRtcp1() {
    478     return media_channel1_->CheckNoRtcp();
    479   }
    480   bool CheckNoRtcp2() {
    481     return media_channel2_->CheckNoRtcp();
    482   }
    483 
    484   void CreateContent(int flags,
    485                      const cricket::AudioCodec& audio_codec,
    486                      const cricket::VideoCodec& video_codec,
    487                      typename T::Content* content) {
    488     // overridden in specialized classes
    489   }
    490   void CopyContent(const typename T::Content& source,
    491                    typename T::Content* content) {
    492     // overridden in specialized classes
    493   }
    494 
    495   void SetOptimisticDataSend(bool optimistic_data_send) {
    496     channel1_->set_optimistic_data_send(optimistic_data_send);
    497     channel2_->set_optimistic_data_send(optimistic_data_send);
    498   }
    499 
    500   // Creates a cricket::SessionDescription with one MediaContent and one stream.
    501   // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
    502   cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
    503      typename T::Content content;
    504      cricket::SessionDescription* sdesc = new cricket::SessionDescription();
    505      CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
    506      AddLegacyStreamInContent(ssrc, 0, &content);
    507      sdesc->AddContent("DUMMY_CONTENT_NAME",
    508                        cricket::NS_JINGLE_RTP, content.Copy());
    509      return sdesc;
    510   }
    511 
    512   class CallThread : public talk_base::SignalThread {
    513    public:
    514     typedef bool (ChannelTest<T>::*Method)();
    515     CallThread(ChannelTest<T>* obj, Method method, bool* result)
    516         : obj_(obj),
    517           method_(method),
    518           result_(result) {
    519       *result = false;
    520     }
    521     virtual void DoWork() {
    522       bool result = (*obj_.*method_)();
    523       if (result_) {
    524         *result_ = result;
    525       }
    526     }
    527    private:
    528     ChannelTest<T>* obj_;
    529     Method method_;
    530     bool* result_;
    531   };
    532   void CallOnThread(typename CallThread::Method method, bool* result) {
    533     CallThread* thread = new CallThread(this, method, result);
    534     thread->Start();
    535     thread->Release();
    536   }
    537 
    538   void CallOnThreadAndWaitForDone(typename CallThread::Method method,
    539                                   bool* result) {
    540     CallThread* thread = new CallThread(this, method, result);
    541     thread->Start();
    542     thread->Destroy(true);
    543   }
    544 
    545   bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
    546     return false;  // overridden in specialized classes
    547   }
    548 
    549   void OnMediaMonitor(typename T::Channel* channel,
    550                       const typename T::MediaInfo& info) {
    551     if (channel == channel1_.get()) {
    552       media_info_callbacks1_++;
    553     } else if (channel == channel2_.get()) {
    554       media_info_callbacks2_++;
    555     }
    556   }
    557 
    558   void OnMediaChannelError(typename T::Channel* channel,
    559                            uint32 ssrc,
    560                            typename T::MediaChannel::Error error) {
    561     ssrc_ = ssrc;
    562     error_ = error;
    563   }
    564 
    565   void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
    566     mute_callback_recved_ = true;
    567     mute_callback_value_ = muted;
    568   }
    569 
    570   void AddLegacyStreamInContent(uint32 ssrc, int flags,
    571                         typename T::Content* content) {
    572     // Base implementation.
    573   }
    574 
    575   // Tests that can be used by derived classes.
    576 
    577   // Basic sanity check.
    578   void TestInit() {
    579     CreateChannels(0, 0);
    580     EXPECT_FALSE(channel1_->secure());
    581     EXPECT_FALSE(media_channel1_->sending());
    582     EXPECT_FALSE(media_channel1_->playout());
    583     EXPECT_TRUE(media_channel1_->codecs().empty());
    584     EXPECT_TRUE(media_channel1_->recv_streams().empty());
    585     EXPECT_TRUE(media_channel1_->rtp_packets().empty());
    586     EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
    587   }
    588 
    589   // Test that SetLocalContent and SetRemoteContent properly configure
    590   // the codecs.
    591   void TestSetContents() {
    592     CreateChannels(0, 0);
    593     typename T::Content content;
    594     CreateContent(0, kPcmuCodec, kH264Codec, &content);
    595     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
    596     EXPECT_EQ(0U, media_channel1_->codecs().size());
    597     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
    598     ASSERT_EQ(1U, media_channel1_->codecs().size());
    599     EXPECT_TRUE(CodecMatches(content.codecs()[0],
    600                              media_channel1_->codecs()[0]));
    601   }
    602 
    603   // Test that SetLocalContent and SetRemoteContent properly deals
    604   // with an empty offer.
    605   void TestSetContentsNullOffer() {
    606     CreateChannels(0, 0);
    607     typename T::Content content;
    608     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
    609     CreateContent(0, kPcmuCodec, kH264Codec, &content);
    610     EXPECT_EQ(0U, media_channel1_->codecs().size());
    611     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
    612     ASSERT_EQ(1U, media_channel1_->codecs().size());
    613     EXPECT_TRUE(CodecMatches(content.codecs()[0],
    614                              media_channel1_->codecs()[0]));
    615   }
    616 
    617   // Test that SetLocalContent and SetRemoteContent properly set RTCP
    618   // mux.
    619   void TestSetContentsRtcpMux() {
    620     CreateChannels(RTCP, RTCP);
    621     EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
    622     EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
    623     typename T::Content content;
    624     CreateContent(0, kPcmuCodec, kH264Codec, &content);
    625     // Both sides agree on mux. Should no longer be a separate RTCP channel.
    626     content.set_rtcp_mux(true);
    627     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
    628     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
    629     EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
    630     // Only initiator supports mux. Should still have a separate RTCP channel.
    631     EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER));
    632     content.set_rtcp_mux(false);
    633     EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER));
    634     EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
    635   }
    636 
    637   // Test that SetLocalContent and SetRemoteContent properly set RTCP
    638   // mux when a provisional answer is received.
    639   void TestSetContentsRtcpMuxWithPrAnswer() {
    640     CreateChannels(RTCP, RTCP);
    641     EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
    642     EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
    643     typename T::Content content;
    644     CreateContent(0, kPcmuCodec, kH264Codec, &content);
    645     content.set_rtcp_mux(true);
    646     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
    647     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER));
    648     EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
    649     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
    650     // Both sides agree on mux. Should no longer be a separate RTCP channel.
    651     EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
    652     // Only initiator supports mux. Should still have a separate RTCP channel.
    653     EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER));
    654     content.set_rtcp_mux(false);
    655     EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER));
    656     EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER));
    657     EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
    658   }
    659 
    660   // Test that SetLocalContent and SetRemoteContent properly set
    661   // video options to the media channel.
    662   void TestSetContentsVideoOptions() {
    663     CreateChannels(0, 0);
    664     typename T::Content content;
    665     CreateContent(0, kPcmuCodec, kH264Codec, &content);
    666     content.set_buffered_mode_latency(101);
    667     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
    668     EXPECT_EQ(0U, media_channel1_->codecs().size());
    669     cricket::VideoOptions options;
    670     ASSERT_TRUE(media_channel1_->GetOptions(&options));
    671     int latency = 0;
    672     EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
    673     EXPECT_EQ(101, latency);
    674     content.set_buffered_mode_latency(102);
    675     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
    676     ASSERT_EQ(1U, media_channel1_->codecs().size());
    677     EXPECT_TRUE(CodecMatches(content.codecs()[0],
    678                              media_channel1_->codecs()[0]));
    679     ASSERT_TRUE(media_channel1_->GetOptions(&options));
    680     EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
    681     EXPECT_EQ(102, latency);
    682   }
    683 
    684   // Test that SetRemoteContent properly deals with a content update.
    685   void TestSetRemoteContentUpdate() {
    686     CreateChannels(0, 0);
    687     typename T::Content content;
    688     CreateContent(RTCP | RTCP_MUX | SECURE,
    689                   kPcmuCodec, kH264Codec,
    690                   &content);
    691     EXPECT_EQ(0U, media_channel1_->codecs().size());
    692     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
    693     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
    694     ASSERT_EQ(1U, media_channel1_->codecs().size());
    695     EXPECT_TRUE(CodecMatches(content.codecs()[0],
    696                              media_channel1_->codecs()[0]));
    697     // Now update with other codecs.
    698     typename T::Content update_content;
    699     update_content.set_partial(true);
    700     CreateContent(0, kIsacCodec, kH264SvcCodec,
    701                   &update_content);
    702     EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE));
    703     ASSERT_EQ(1U, media_channel1_->codecs().size());
    704     EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
    705                              media_channel1_->codecs()[0]));
    706     // Now update without any codecs. This is ignored.
    707     typename T::Content empty_content;
    708     empty_content.set_partial(true);
    709     EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE));
    710     ASSERT_EQ(1U, media_channel1_->codecs().size());
    711     EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
    712                              media_channel1_->codecs()[0]));
    713   }
    714 
    715   // Test that Add/RemoveStream properly forward to the media channel.
    716   void TestStreams() {
    717     CreateChannels(0, 0);
    718     EXPECT_TRUE(AddStream1(1));
    719     EXPECT_TRUE(AddStream1(2));
    720     EXPECT_EQ(2U, media_channel1_->recv_streams().size());
    721     EXPECT_TRUE(RemoveStream1(2));
    722     EXPECT_EQ(1U, media_channel1_->recv_streams().size());
    723     EXPECT_TRUE(RemoveStream1(1));
    724     EXPECT_EQ(0U, media_channel1_->recv_streams().size());
    725   }
    726 
    727   // Test that SetLocalContent properly handles adding and removing StreamParams
    728   // to the local content description.
    729   // This test uses the CA_UPDATE action that don't require a full
    730   // MediaContentDescription to do an update.
    731   void TestUpdateStreamsInLocalContent() {
    732     cricket::StreamParams stream1;
    733     stream1.groupid = "group1";
    734     stream1.id = "stream1";
    735     stream1.ssrcs.push_back(kSsrc1);
    736     stream1.cname = "stream1_cname";
    737 
    738     cricket::StreamParams stream2;
    739     stream2.groupid = "group2";
    740     stream2.id = "stream2";
    741     stream2.ssrcs.push_back(kSsrc2);
    742     stream2.cname = "stream2_cname";
    743 
    744     cricket::StreamParams stream3;
    745     stream3.groupid = "group3";
    746     stream3.id = "stream3";
    747     stream3.ssrcs.push_back(kSsrc3);
    748     stream3.cname = "stream3_cname";
    749 
    750     CreateChannels(0, 0);
    751     typename T::Content content1;
    752     CreateContent(0, kPcmuCodec, kH264Codec, &content1);
    753     content1.AddStream(stream1);
    754     EXPECT_EQ(0u, media_channel1_->send_streams().size());
    755     EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER));
    756 
    757     ASSERT_EQ(1u, media_channel1_->send_streams().size());
    758     EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
    759 
    760     // Update the local streams by adding another sending stream.
    761     // Use a partial updated session description.
    762     typename T::Content content2;
    763     content2.AddStream(stream2);
    764     content2.AddStream(stream3);
    765     content2.set_partial(true);
    766     EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE));
    767     ASSERT_EQ(3u, media_channel1_->send_streams().size());
    768     EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
    769     EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
    770     EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
    771 
    772     // Update the local streams by removing the first sending stream.
    773     // This is done by removing all SSRCS for this particular stream.
    774     typename T::Content content3;
    775     stream1.ssrcs.clear();
    776     content3.AddStream(stream1);
    777     content3.set_partial(true);
    778     EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE));
    779     ASSERT_EQ(2u, media_channel1_->send_streams().size());
    780     EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
    781     EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
    782 
    783     // Update the local streams with a stream that does not change.
    784     // THe update is ignored.
    785     typename T::Content content4;
    786     content4.AddStream(stream2);
    787     content4.set_partial(true);
    788     EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE));
    789     ASSERT_EQ(2u, media_channel1_->send_streams().size());
    790     EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
    791     EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
    792   }
    793 
    794   // Test that SetRemoteContent properly handles adding and removing
    795   // StreamParams to the remote content description.
    796   // This test uses the CA_UPDATE action that don't require a full
    797   // MediaContentDescription to do an update.
    798   void TestUpdateStreamsInRemoteContent() {
    799     cricket::StreamParams stream1;
    800     stream1.id = "Stream1";
    801     stream1.groupid = "1";
    802     stream1.ssrcs.push_back(kSsrc1);
    803     stream1.cname = "stream1_cname";
    804 
    805     cricket::StreamParams stream2;
    806     stream2.id = "Stream2";
    807     stream2.groupid = "2";
    808     stream2.ssrcs.push_back(kSsrc2);
    809     stream2.cname = "stream2_cname";
    810 
    811     cricket::StreamParams stream3;
    812     stream3.id = "Stream3";
    813     stream3.groupid = "3";
    814     stream3.ssrcs.push_back(kSsrc3);
    815     stream3.cname = "stream3_cname";
    816 
    817     CreateChannels(0, 0);
    818     typename T::Content content1;
    819     CreateContent(0, kPcmuCodec, kH264Codec, &content1);
    820     content1.AddStream(stream1);
    821     EXPECT_EQ(0u, media_channel1_->recv_streams().size());
    822     EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER));
    823 
    824     ASSERT_EQ(1u, media_channel1_->codecs().size());
    825     ASSERT_EQ(1u, media_channel1_->recv_streams().size());
    826     EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
    827 
    828     // Update the remote streams by adding another sending stream.
    829     // Use a partial updated session description.
    830     typename T::Content content2;
    831     content2.AddStream(stream2);
    832     content2.AddStream(stream3);
    833     content2.set_partial(true);
    834     EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE));
    835     ASSERT_EQ(3u, media_channel1_->recv_streams().size());
    836     EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
    837     EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
    838     EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
    839 
    840     // Update the remote streams by removing the first stream.
    841     // This is done by removing all SSRCS for this particular stream.
    842     typename T::Content content3;
    843     stream1.ssrcs.clear();
    844     content3.AddStream(stream1);
    845     content3.set_partial(true);
    846     EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE));
    847     ASSERT_EQ(2u, media_channel1_->recv_streams().size());
    848     EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
    849     EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
    850 
    851     // Update the remote streams with a stream that does not change.
    852     // The update is ignored.
    853     typename T::Content content4;
    854     content4.AddStream(stream2);
    855     content4.set_partial(true);
    856     EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE));
    857     ASSERT_EQ(2u, media_channel1_->recv_streams().size());
    858     EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
    859     EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
    860   }
    861 
    862   // Test that SetLocalContent and SetRemoteContent properly
    863   // handles adding and removing StreamParams when the action is a full
    864   // CA_OFFER / CA_ANSWER.
    865   void TestChangeStreamParamsInContent() {
    866     cricket::StreamParams stream1;
    867     stream1.groupid = "group1";
    868     stream1.id = "stream1";
    869     stream1.ssrcs.push_back(kSsrc1);
    870     stream1.cname = "stream1_cname";
    871 
    872     cricket::StreamParams stream2;
    873     stream2.groupid = "group1";
    874     stream2.id = "stream2";
    875     stream2.ssrcs.push_back(kSsrc2);
    876     stream2.cname = "stream2_cname";
    877 
    878     // Setup a call where channel 1 send |stream1| to channel 2.
    879     CreateChannels(0, 0);
    880     typename T::Content content1;
    881     CreateContent(0, kPcmuCodec, kH264Codec, &content1);
    882     content1.AddStream(stream1);
    883     EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER));
    884     EXPECT_TRUE(channel1_->Enable(true));
    885     EXPECT_EQ(1u, media_channel1_->send_streams().size());
    886 
    887     EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER));
    888     EXPECT_EQ(1u, media_channel2_->recv_streams().size());
    889     session1_.Connect(&session2_);
    890 
    891     // Channel 2 do not send anything.
    892     typename T::Content content2;
    893     CreateContent(0, kPcmuCodec, kH264Codec, &content2);
    894     EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER));
    895     EXPECT_EQ(0u, media_channel1_->recv_streams().size());
    896     EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER));
    897     EXPECT_TRUE(channel2_->Enable(true));
    898     EXPECT_EQ(0u, media_channel2_->send_streams().size());
    899 
    900     EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
    901     EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
    902 
    903     // Let channel 2 update the content by sending |stream2| and enable SRTP.
    904     typename T::Content content3;
    905     CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
    906     content3.AddStream(stream2);
    907     EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER));
    908     ASSERT_EQ(1u, media_channel2_->send_streams().size());
    909     EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
    910 
    911     EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER));
    912     ASSERT_EQ(1u, media_channel1_->recv_streams().size());
    913     EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
    914 
    915     // Channel 1 replies but stop sending stream1.
    916     typename T::Content content4;
    917     CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
    918     EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER));
    919     EXPECT_EQ(0u, media_channel1_->send_streams().size());
    920 
    921     EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER));
    922     EXPECT_EQ(0u, media_channel2_->recv_streams().size());
    923 
    924     EXPECT_TRUE(channel1_->secure());
    925     EXPECT_TRUE(channel2_->secure());
    926     EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
    927     EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
    928   }
    929 
    930   // Test that we only start playout and sending at the right times.
    931   void TestPlayoutAndSendingStates() {
    932     CreateChannels(0, 0);
    933     EXPECT_FALSE(media_channel1_->playout());
    934     EXPECT_FALSE(media_channel1_->sending());
    935     EXPECT_FALSE(media_channel2_->playout());
    936     EXPECT_FALSE(media_channel2_->sending());
    937     EXPECT_TRUE(channel1_->Enable(true));
    938     EXPECT_FALSE(media_channel1_->playout());
    939     EXPECT_FALSE(media_channel1_->sending());
    940     EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_, CA_OFFER));
    941     EXPECT_TRUE(media_channel1_->playout());
    942     EXPECT_FALSE(media_channel1_->sending());
    943     EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_, CA_OFFER));
    944     EXPECT_FALSE(media_channel2_->playout());
    945     EXPECT_FALSE(media_channel2_->sending());
    946     EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER));
    947     EXPECT_FALSE(media_channel2_->playout());
    948     EXPECT_FALSE(media_channel2_->sending());
    949     session1_.Connect(&session2_);
    950     EXPECT_TRUE(media_channel1_->playout());
    951     EXPECT_FALSE(media_channel1_->sending());
    952     EXPECT_FALSE(media_channel2_->playout());
    953     EXPECT_FALSE(media_channel2_->sending());
    954     EXPECT_TRUE(channel2_->Enable(true));
    955     EXPECT_TRUE(media_channel2_->playout());
    956     EXPECT_TRUE(media_channel2_->sending());
    957     EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_, CA_ANSWER));
    958     EXPECT_TRUE(media_channel1_->playout());
    959     EXPECT_TRUE(media_channel1_->sending());
    960   }
    961 
    962   void TestMuteStream() {
    963     CreateChannels(0, 0);
    964     // Test that we can Mute the default channel even though the sending SSRC is
    965     // unknown.
    966     EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
    967     EXPECT_TRUE(channel1_->MuteStream(0, true));
    968     EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
    969     EXPECT_TRUE(channel1_->MuteStream(0, false));
    970     EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
    971 
    972     // Test that we can not mute an unknown SSRC.
    973     EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
    974 
    975     SendInitiate();
    976     // After the local session description has been set, we can mute a stream
    977     // with its SSRC.
    978     EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
    979     EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
    980     EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
    981     EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
    982   }
    983 
    984   // Test that changing the MediaContentDirection in the local and remote
    985   // session description start playout and sending at the right time.
    986   void TestMediaContentDirection() {
    987     CreateChannels(0, 0);
    988     typename T::Content content1;
    989     CreateContent(0, kPcmuCodec, kH264Codec, &content1);
    990     typename T::Content content2;
    991     CreateContent(0, kPcmuCodec, kH264Codec, &content2);
    992     // Set |content2| to be InActive.
    993     content2.set_direction(cricket::MD_INACTIVE);
    994 
    995     EXPECT_TRUE(channel1_->Enable(true));
    996     EXPECT_TRUE(channel2_->Enable(true));
    997     EXPECT_FALSE(media_channel1_->playout());
    998     EXPECT_FALSE(media_channel1_->sending());
    999     EXPECT_FALSE(media_channel2_->playout());
   1000     EXPECT_FALSE(media_channel2_->sending());
   1001 
   1002     EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER));
   1003     EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER));
   1004     EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER));
   1005     EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER));
   1006     session1_.Connect(&session2_);
   1007 
   1008     EXPECT_TRUE(media_channel1_->playout());
   1009     EXPECT_FALSE(media_channel1_->sending());  // remote InActive
   1010     EXPECT_FALSE(media_channel2_->playout());  // local InActive
   1011     EXPECT_FALSE(media_channel2_->sending());  // local InActive
   1012 
   1013     // Update |content2| to be RecvOnly.
   1014     content2.set_direction(cricket::MD_RECVONLY);
   1015     EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER));
   1016     EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER));
   1017 
   1018     EXPECT_TRUE(media_channel1_->playout());
   1019     EXPECT_TRUE(media_channel1_->sending());
   1020     EXPECT_TRUE(media_channel2_->playout());  // local RecvOnly
   1021     EXPECT_FALSE(media_channel2_->sending());  // local RecvOnly
   1022 
   1023     // Update |content2| to be SendRecv.
   1024     content2.set_direction(cricket::MD_SENDRECV);
   1025     EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER));
   1026     EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER));
   1027 
   1028     EXPECT_TRUE(media_channel1_->playout());
   1029     EXPECT_TRUE(media_channel1_->sending());
   1030     EXPECT_TRUE(media_channel2_->playout());
   1031     EXPECT_TRUE(media_channel2_->sending());
   1032   }
   1033 
   1034   // Test setting up a call.
   1035   void TestCallSetup() {
   1036     CreateChannels(0, 0);
   1037     EXPECT_FALSE(channel1_->secure());
   1038     EXPECT_TRUE(SendInitiate());
   1039     EXPECT_TRUE(media_channel1_->playout());
   1040     EXPECT_FALSE(media_channel1_->sending());
   1041     EXPECT_TRUE(SendAccept());
   1042     EXPECT_FALSE(channel1_->secure());
   1043     EXPECT_TRUE(media_channel1_->sending());
   1044     EXPECT_EQ(1U, media_channel1_->codecs().size());
   1045     EXPECT_TRUE(media_channel2_->playout());
   1046     EXPECT_TRUE(media_channel2_->sending());
   1047     EXPECT_EQ(1U, media_channel2_->codecs().size());
   1048   }
   1049 
   1050   // Test that we don't crash if packets are sent during call teardown
   1051   // when RTCP mux is enabled. This is a regression test against a specific
   1052   // race condition that would only occur when a RTCP packet was sent during
   1053   // teardown of a channel on which RTCP mux was enabled.
   1054   void TestCallTeardownRtcpMux() {
   1055     class LastWordMediaChannel : public T::MediaChannel {
   1056      public:
   1057       LastWordMediaChannel() : T::MediaChannel(NULL) {}
   1058       ~LastWordMediaChannel() {
   1059         T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
   1060         T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
   1061       }
   1062     };
   1063     CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
   1064                    RTCP | RTCP_MUX, RTCP | RTCP_MUX,
   1065                    talk_base::Thread::Current());
   1066     EXPECT_TRUE(SendInitiate());
   1067     EXPECT_TRUE(SendAccept());
   1068     EXPECT_TRUE(SendTerminate());
   1069   }
   1070 
   1071   // Send voice RTP data to the other side and ensure it gets there.
   1072   void SendRtpToRtp() {
   1073     CreateChannels(0, 0);
   1074     EXPECT_TRUE(SendInitiate());
   1075     EXPECT_TRUE(SendAccept());
   1076     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1077     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1078     EXPECT_TRUE(SendRtp1());
   1079     EXPECT_TRUE(SendRtp2());
   1080     EXPECT_TRUE(CheckRtp1());
   1081     EXPECT_TRUE(CheckRtp2());
   1082     EXPECT_TRUE(CheckNoRtp1());
   1083     EXPECT_TRUE(CheckNoRtp2());
   1084   }
   1085 
   1086   // Check that RTCP is not transmitted if both sides don't support RTCP.
   1087   void SendNoRtcpToNoRtcp() {
   1088     CreateChannels(0, 0);
   1089     EXPECT_TRUE(SendInitiate());
   1090     EXPECT_TRUE(SendAccept());
   1091     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1092     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1093     EXPECT_FALSE(SendRtcp1());
   1094     EXPECT_FALSE(SendRtcp2());
   1095     EXPECT_TRUE(CheckNoRtcp1());
   1096     EXPECT_TRUE(CheckNoRtcp2());
   1097   }
   1098 
   1099   // Check that RTCP is not transmitted if the callee doesn't support RTCP.
   1100   void SendNoRtcpToRtcp() {
   1101     CreateChannels(0, RTCP);
   1102     EXPECT_TRUE(SendInitiate());
   1103     EXPECT_TRUE(SendAccept());
   1104     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1105     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1106     EXPECT_FALSE(SendRtcp1());
   1107     EXPECT_FALSE(SendRtcp2());
   1108     EXPECT_TRUE(CheckNoRtcp1());
   1109     EXPECT_TRUE(CheckNoRtcp2());
   1110   }
   1111 
   1112   // Check that RTCP is not transmitted if the caller doesn't support RTCP.
   1113   void SendRtcpToNoRtcp() {
   1114     CreateChannels(RTCP, 0);
   1115     EXPECT_TRUE(SendInitiate());
   1116     EXPECT_TRUE(SendAccept());
   1117     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1118     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1119     EXPECT_FALSE(SendRtcp1());
   1120     EXPECT_FALSE(SendRtcp2());
   1121     EXPECT_TRUE(CheckNoRtcp1());
   1122     EXPECT_TRUE(CheckNoRtcp2());
   1123   }
   1124 
   1125   // Check that RTCP is transmitted if both sides support RTCP.
   1126   void SendRtcpToRtcp() {
   1127     CreateChannels(RTCP, RTCP);
   1128     EXPECT_TRUE(SendInitiate());
   1129     EXPECT_TRUE(SendAccept());
   1130     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1131     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1132     EXPECT_TRUE(SendRtcp1());
   1133     EXPECT_TRUE(SendRtcp2());
   1134     EXPECT_TRUE(CheckRtcp1());
   1135     EXPECT_TRUE(CheckRtcp2());
   1136     EXPECT_TRUE(CheckNoRtcp1());
   1137     EXPECT_TRUE(CheckNoRtcp2());
   1138   }
   1139 
   1140   // Check that RTCP is transmitted if only the initiator supports mux.
   1141   void SendRtcpMuxToRtcp() {
   1142     CreateChannels(RTCP | RTCP_MUX, RTCP);
   1143     EXPECT_TRUE(SendInitiate());
   1144     EXPECT_TRUE(SendAccept());
   1145     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1146     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1147     EXPECT_TRUE(SendRtcp1());
   1148     EXPECT_TRUE(SendRtcp2());
   1149     EXPECT_TRUE(CheckRtcp1());
   1150     EXPECT_TRUE(CheckRtcp2());
   1151     EXPECT_TRUE(CheckNoRtcp1());
   1152     EXPECT_TRUE(CheckNoRtcp2());
   1153   }
   1154 
   1155   // Check that RTP and RTCP are transmitted ok when both sides support mux.
   1156   void SendRtcpMuxToRtcpMux() {
   1157     CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
   1158     EXPECT_TRUE(SendInitiate());
   1159     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1160     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1161     EXPECT_TRUE(SendAccept());
   1162     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1163     EXPECT_TRUE(SendRtp1());
   1164     EXPECT_TRUE(SendRtp2());
   1165     EXPECT_TRUE(SendRtcp1());
   1166     EXPECT_TRUE(SendRtcp2());
   1167     EXPECT_TRUE(CheckRtp1());
   1168     EXPECT_TRUE(CheckRtp2());
   1169     EXPECT_TRUE(CheckNoRtp1());
   1170     EXPECT_TRUE(CheckNoRtp2());
   1171     EXPECT_TRUE(CheckRtcp1());
   1172     EXPECT_TRUE(CheckRtcp2());
   1173     EXPECT_TRUE(CheckNoRtcp1());
   1174     EXPECT_TRUE(CheckNoRtcp2());
   1175   }
   1176 
   1177   // Check that RTCP data sent by the initiator before the accept is not muxed.
   1178   void SendEarlyRtcpMuxToRtcp() {
   1179     CreateChannels(RTCP | RTCP_MUX, RTCP);
   1180     EXPECT_TRUE(SendInitiate());
   1181     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1182     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1183 
   1184     // RTCP can be sent before the call is accepted, if the transport is ready.
   1185     // It should not be muxed though, as the remote side doesn't support mux.
   1186     EXPECT_TRUE(SendRtcp1());
   1187     EXPECT_TRUE(CheckNoRtp2());
   1188     EXPECT_TRUE(CheckRtcp2());
   1189 
   1190     // Send RTCP packet from callee and verify that it is received.
   1191     EXPECT_TRUE(SendRtcp2());
   1192     EXPECT_TRUE(CheckNoRtp1());
   1193     EXPECT_TRUE(CheckRtcp1());
   1194 
   1195     // Complete call setup and ensure everything is still OK.
   1196     EXPECT_TRUE(SendAccept());
   1197     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1198     EXPECT_TRUE(SendRtcp1());
   1199     EXPECT_TRUE(CheckRtcp2());
   1200     EXPECT_TRUE(SendRtcp2());
   1201     EXPECT_TRUE(CheckRtcp1());
   1202   }
   1203 
   1204 
   1205   // Check that RTCP data is not muxed until both sides have enabled muxing,
   1206   // but that we properly demux before we get the accept message, since there
   1207   // is a race between RTP data and the jingle accept.
   1208   void SendEarlyRtcpMuxToRtcpMux() {
   1209     CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
   1210     EXPECT_TRUE(SendInitiate());
   1211     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1212     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1213 
   1214     // RTCP can't be sent yet, since the RTCP transport isn't writable, and
   1215     // we haven't yet received the accept that says we should mux.
   1216     EXPECT_FALSE(SendRtcp1());
   1217 
   1218     // Send muxed RTCP packet from callee and verify that it is received.
   1219     EXPECT_TRUE(SendRtcp2());
   1220     EXPECT_TRUE(CheckNoRtp1());
   1221     EXPECT_TRUE(CheckRtcp1());
   1222 
   1223     // Complete call setup and ensure everything is still OK.
   1224     EXPECT_TRUE(SendAccept());
   1225     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1226     EXPECT_TRUE(SendRtcp1());
   1227     EXPECT_TRUE(CheckRtcp2());
   1228     EXPECT_TRUE(SendRtcp2());
   1229     EXPECT_TRUE(CheckRtcp1());
   1230   }
   1231 
   1232   // Test that we properly send SRTP with RTCP in both directions.
   1233   // You can pass in DTLS and/or RTCP_MUX as flags.
   1234   void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
   1235     ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
   1236     ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
   1237 
   1238     int flags1 = RTCP | SECURE | flags1_in;
   1239     int flags2 = RTCP | SECURE | flags2_in;
   1240     bool dtls1 = !!(flags1_in & DTLS);
   1241     bool dtls2 = !!(flags2_in & DTLS);
   1242     CreateChannels(flags1, flags2);
   1243     EXPECT_FALSE(channel1_->secure());
   1244     EXPECT_FALSE(channel2_->secure());
   1245     EXPECT_TRUE(SendInitiate());
   1246     EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
   1247     EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
   1248     EXPECT_TRUE(SendAccept());
   1249     EXPECT_TRUE(channel1_->secure());
   1250     EXPECT_TRUE(channel2_->secure());
   1251     EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
   1252     EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
   1253     EXPECT_TRUE(SendRtp1());
   1254     EXPECT_TRUE(SendRtp2());
   1255     EXPECT_TRUE(SendRtcp1());
   1256     EXPECT_TRUE(SendRtcp2());
   1257     EXPECT_TRUE(CheckRtp1());
   1258     EXPECT_TRUE(CheckRtp2());
   1259     EXPECT_TRUE(CheckNoRtp1());
   1260     EXPECT_TRUE(CheckNoRtp2());
   1261     EXPECT_TRUE(CheckRtcp1());
   1262     EXPECT_TRUE(CheckRtcp2());
   1263     EXPECT_TRUE(CheckNoRtcp1());
   1264     EXPECT_TRUE(CheckNoRtcp2());
   1265   }
   1266 
   1267   // Test that we properly handling SRTP negotiating down to RTP.
   1268   void SendSrtpToRtp() {
   1269     CreateChannels(RTCP | SECURE, RTCP);
   1270     EXPECT_FALSE(channel1_->secure());
   1271     EXPECT_FALSE(channel2_->secure());
   1272     EXPECT_TRUE(SendInitiate());
   1273     EXPECT_TRUE(SendAccept());
   1274     EXPECT_FALSE(channel1_->secure());
   1275     EXPECT_FALSE(channel2_->secure());
   1276     EXPECT_TRUE(SendRtp1());
   1277     EXPECT_TRUE(SendRtp2());
   1278     EXPECT_TRUE(SendRtcp1());
   1279     EXPECT_TRUE(SendRtcp2());
   1280     EXPECT_TRUE(CheckRtp1());
   1281     EXPECT_TRUE(CheckRtp2());
   1282     EXPECT_TRUE(CheckNoRtp1());
   1283     EXPECT_TRUE(CheckNoRtp2());
   1284     EXPECT_TRUE(CheckRtcp1());
   1285     EXPECT_TRUE(CheckRtcp2());
   1286     EXPECT_TRUE(CheckNoRtcp1());
   1287     EXPECT_TRUE(CheckNoRtcp2());
   1288   }
   1289 
   1290   // Test that we can send and receive early media when a provisional answer is
   1291   // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
   1292   void SendEarlyMediaUsingRtcpMuxSrtp() {
   1293       int sequence_number1_1 = 0, sequence_number2_2 = 0;
   1294 
   1295       CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
   1296                      SSRC_MUX | RTCP | RTCP_MUX | SECURE);
   1297       EXPECT_TRUE(SendOffer());
   1298       EXPECT_TRUE(SendProvisionalAnswer());
   1299       EXPECT_TRUE(channel1_->secure());
   1300       EXPECT_TRUE(channel2_->secure());
   1301       EXPECT_EQ(2U, GetTransport1()->channels().size());
   1302       EXPECT_EQ(2U, GetTransport2()->channels().size());
   1303       EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
   1304       EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
   1305       EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
   1306       EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
   1307 
   1308       // Send packets from callee and verify that it is received.
   1309       EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
   1310       EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
   1311       EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
   1312       EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
   1313 
   1314       // Complete call setup and ensure everything is still OK.
   1315       EXPECT_TRUE(SendFinalAnswer());
   1316       EXPECT_EQ(1U, GetTransport1()->channels().size());
   1317       EXPECT_EQ(1U, GetTransport2()->channels().size());
   1318       EXPECT_TRUE(channel1_->secure());
   1319       EXPECT_TRUE(channel2_->secure());
   1320       EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
   1321       EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
   1322       EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
   1323       EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
   1324       EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
   1325       EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
   1326       EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
   1327       EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
   1328   }
   1329 
   1330   // Test that we properly send RTP without SRTP from a thread.
   1331   void SendRtpToRtpOnThread() {
   1332     bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
   1333     CreateChannels(RTCP, RTCP);
   1334     EXPECT_TRUE(SendInitiate());
   1335     EXPECT_TRUE(SendAccept());
   1336     CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
   1337     CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
   1338     CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
   1339     CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
   1340     EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
   1341     EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
   1342     EXPECT_TRUE_WAIT(sent_rtp1, 1000);
   1343     EXPECT_TRUE_WAIT(sent_rtp2, 1000);
   1344     EXPECT_TRUE(CheckNoRtp1());
   1345     EXPECT_TRUE(CheckNoRtp2());
   1346     EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
   1347     EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
   1348     EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
   1349     EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
   1350     EXPECT_TRUE(CheckNoRtcp1());
   1351     EXPECT_TRUE(CheckNoRtcp2());
   1352   }
   1353 
   1354   // Test that we properly send SRTP with RTCP from a thread.
   1355   void SendSrtpToSrtpOnThread() {
   1356     bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
   1357     CreateChannels(RTCP | SECURE, RTCP | SECURE);
   1358     EXPECT_TRUE(SendInitiate());
   1359     EXPECT_TRUE(SendAccept());
   1360     CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
   1361     CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
   1362     CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
   1363     CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
   1364     EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
   1365     EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
   1366     EXPECT_TRUE_WAIT(sent_rtp1, 1000);
   1367     EXPECT_TRUE_WAIT(sent_rtp2, 1000);
   1368     EXPECT_TRUE(CheckNoRtp1());
   1369     EXPECT_TRUE(CheckNoRtp2());
   1370     EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
   1371     EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
   1372     EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
   1373     EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
   1374     EXPECT_TRUE(CheckNoRtcp1());
   1375     EXPECT_TRUE(CheckNoRtcp2());
   1376   }
   1377 
   1378   // Test that the mediachannel retains its sending state after the transport
   1379   // becomes non-writable.
   1380   void SendWithWritabilityLoss() {
   1381     CreateChannels(0, 0);
   1382     EXPECT_TRUE(SendInitiate());
   1383     EXPECT_TRUE(SendAccept());
   1384     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1385     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1386     EXPECT_TRUE(SendRtp1());
   1387     EXPECT_TRUE(SendRtp2());
   1388     EXPECT_TRUE(CheckRtp1());
   1389     EXPECT_TRUE(CheckRtp2());
   1390     EXPECT_TRUE(CheckNoRtp1());
   1391     EXPECT_TRUE(CheckNoRtp2());
   1392 
   1393     // Lose writability, with optimistic send
   1394     SetOptimisticDataSend(true);
   1395     GetTransport1()->SetWritable(false);
   1396     EXPECT_TRUE(media_channel1_->sending());
   1397     EXPECT_TRUE(SendRtp1());
   1398     EXPECT_TRUE(SendRtp2());
   1399     EXPECT_TRUE(CheckRtp1());
   1400     EXPECT_TRUE(CheckRtp2());
   1401     EXPECT_TRUE(CheckNoRtp1());
   1402     EXPECT_TRUE(CheckNoRtp2());
   1403 
   1404     // Check again with optimistic send off, which should fail.
   1405     SetOptimisticDataSend(false);
   1406     EXPECT_FALSE(SendRtp1());
   1407     EXPECT_TRUE(SendRtp2());
   1408     EXPECT_TRUE(CheckRtp1());
   1409     EXPECT_TRUE(CheckNoRtp2());
   1410 
   1411     // Regain writability
   1412     GetTransport1()->SetWritable(true);
   1413     EXPECT_TRUE(media_channel1_->sending());
   1414     EXPECT_TRUE(SendRtp1());
   1415     EXPECT_TRUE(SendRtp2());
   1416     EXPECT_TRUE(CheckRtp1());
   1417     EXPECT_TRUE(CheckRtp2());
   1418     EXPECT_TRUE(CheckNoRtp1());
   1419     EXPECT_TRUE(CheckNoRtp2());
   1420 
   1421     // Lose writability completely
   1422     GetTransport1()->SetDestination(NULL);
   1423     EXPECT_TRUE(media_channel1_->sending());
   1424 
   1425     // Should fail regardless of optimistic send at this point.
   1426     SetOptimisticDataSend(true);
   1427     EXPECT_FALSE(SendRtp1());
   1428     EXPECT_TRUE(SendRtp2());
   1429     EXPECT_TRUE(CheckRtp1());
   1430     EXPECT_TRUE(CheckNoRtp2());
   1431     SetOptimisticDataSend(false);
   1432     EXPECT_FALSE(SendRtp1());
   1433     EXPECT_TRUE(SendRtp2());
   1434     EXPECT_TRUE(CheckRtp1());
   1435     EXPECT_TRUE(CheckNoRtp2());
   1436 
   1437     // Gain writability back
   1438     GetTransport1()->SetDestination(GetTransport2());
   1439     EXPECT_TRUE(media_channel1_->sending());
   1440     EXPECT_TRUE(SendRtp1());
   1441     EXPECT_TRUE(SendRtp2());
   1442     EXPECT_TRUE(CheckRtp1());
   1443     EXPECT_TRUE(CheckRtp2());
   1444     EXPECT_TRUE(CheckNoRtp1());
   1445     EXPECT_TRUE(CheckNoRtp2());
   1446   }
   1447 
   1448   void SendSsrcMuxToSsrcMuxWithRtcpMux() {
   1449     int sequence_number1_1 = 0, sequence_number2_2 = 0;
   1450     CreateChannels(SSRC_MUX | RTCP | RTCP_MUX, SSRC_MUX | RTCP | RTCP_MUX);
   1451     EXPECT_TRUE(SendInitiate());
   1452     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1453     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1454     EXPECT_TRUE(SendAccept());
   1455     EXPECT_EQ(1U, GetTransport1()->channels().size());
   1456     EXPECT_EQ(1U, GetTransport2()->channels().size());
   1457     EXPECT_TRUE(channel1_->ssrc_filter()->IsActive());
   1458     // channel1 - should have media_content2 as remote. i.e. kSsrc2
   1459     EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2));
   1460     EXPECT_TRUE(channel2_->ssrc_filter()->IsActive());
   1461     // channel2 - should have media_content1 as remote. i.e. kSsrc1
   1462     EXPECT_TRUE(channel2_->ssrc_filter()->FindStream(kSsrc1));
   1463     EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
   1464     EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
   1465     EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
   1466     EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
   1467     EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
   1468     EXPECT_TRUE(CheckNoRtp1());
   1469     EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
   1470     EXPECT_TRUE(CheckNoRtp2());
   1471     EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
   1472     EXPECT_TRUE(CheckNoRtcp1());
   1473     EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
   1474     EXPECT_TRUE(CheckNoRtcp2());
   1475   }
   1476 
   1477   void SendSsrcMuxToSsrcMux() {
   1478     int sequence_number1_1 = 0, sequence_number2_2 = 0;
   1479     CreateChannels(SSRC_MUX | RTCP, SSRC_MUX | RTCP);
   1480     EXPECT_TRUE(SendInitiate());
   1481     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1482     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1483     EXPECT_TRUE(SendAccept());
   1484     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1485     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1486     EXPECT_TRUE(channel1_->ssrc_filter()->IsActive());
   1487     // channel1 - should have media_content2 as remote. i.e. kSsrc2
   1488     EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2));
   1489     EXPECT_TRUE(channel2_->ssrc_filter()->IsActive());
   1490     // channel2 - should have media_content1 as remote. i.e. kSsrc1
   1491     EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
   1492     EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
   1493     EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
   1494     EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
   1495     EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
   1496     EXPECT_FALSE(CheckCustomRtp1(kSsrc1, sequence_number2_2));
   1497     EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
   1498     EXPECT_FALSE(CheckCustomRtp2(kSsrc2, sequence_number1_1));
   1499     EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
   1500     EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
   1501     EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
   1502     EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
   1503   }
   1504 
   1505   // Test that the media monitor can be run and gives timely callbacks.
   1506   void TestMediaMonitor() {
   1507     static const int kTimeout = 500;
   1508     CreateChannels(0, 0);
   1509     EXPECT_TRUE(SendInitiate());
   1510     EXPECT_TRUE(SendAccept());
   1511     channel1_->StartMediaMonitor(100);
   1512     channel2_->StartMediaMonitor(100);
   1513     // Ensure we get callbacks and stop.
   1514     EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
   1515     EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
   1516     channel1_->StopMediaMonitor();
   1517     channel2_->StopMediaMonitor();
   1518     // Ensure a restart of a stopped monitor works.
   1519     channel1_->StartMediaMonitor(100);
   1520     EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
   1521     channel1_->StopMediaMonitor();
   1522     // Ensure stopping a stopped monitor is OK.
   1523     channel1_->StopMediaMonitor();
   1524   }
   1525 
   1526   void TestMediaSinks() {
   1527     CreateChannels(0, 0);
   1528     EXPECT_TRUE(SendInitiate());
   1529     EXPECT_TRUE(SendAccept());
   1530     EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
   1531     EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
   1532     EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
   1533     EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
   1534 
   1535     talk_base::Pathname path;
   1536     EXPECT_TRUE(talk_base::Filesystem::GetTemporaryFolder(path, true, NULL));
   1537     path.SetFilename("sink-test.rtpdump");
   1538     talk_base::scoped_ptr<cricket::RtpDumpSink> sink(
   1539         new cricket::RtpDumpSink(Open(path.pathname())));
   1540     sink->set_packet_filter(cricket::PF_ALL);
   1541     EXPECT_TRUE(sink->Enable(true));
   1542     channel1_->RegisterSendSink(
   1543         sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
   1544     EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
   1545     EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
   1546     EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
   1547     EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
   1548 
   1549     // The first packet is recorded with header + data.
   1550     EXPECT_TRUE(SendRtp1());
   1551     // The second packet is recorded with header only.
   1552     sink->set_packet_filter(cricket::PF_RTPHEADER);
   1553     EXPECT_TRUE(SendRtp1());
   1554     // The third packet is not recorded since sink is disabled.
   1555     EXPECT_TRUE(sink->Enable(false));
   1556     EXPECT_TRUE(SendRtp1());
   1557      // The fourth packet is not recorded since sink is unregistered.
   1558     EXPECT_TRUE(sink->Enable(true));
   1559     channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
   1560     EXPECT_TRUE(SendRtp1());
   1561     sink.reset();  // This will close the file.
   1562 
   1563     // Read the recorded file and verify two packets.
   1564     talk_base::scoped_ptr<talk_base::StreamInterface> stream(
   1565         talk_base::Filesystem::OpenFile(path, "rb"));
   1566 
   1567     cricket::RtpDumpReader reader(stream.get());
   1568     cricket::RtpDumpPacket packet;
   1569     EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
   1570     std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
   1571         packet.data.size());
   1572     EXPECT_EQ(rtp_packet_, read_packet);
   1573 
   1574     EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
   1575     size_t len = 0;
   1576     packet.GetRtpHeaderLen(&len);
   1577     EXPECT_EQ(len, packet.data.size());
   1578     EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
   1579 
   1580     EXPECT_EQ(talk_base::SR_EOS, reader.ReadPacket(&packet));
   1581 
   1582     // Delete the file for media recording.
   1583     stream.reset();
   1584     EXPECT_TRUE(talk_base::Filesystem::DeleteFile(path));
   1585   }
   1586 
   1587   void TestSetContentFailure() {
   1588     CreateChannels(0, 0);
   1589     typename T::Content content;
   1590     cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
   1591     cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
   1592 
   1593     // Set up the session description.
   1594     CreateContent(0, kPcmuCodec, kH264Codec, &content);
   1595     sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
   1596                           new cricket::AudioContentDescription());
   1597     sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
   1598                           new cricket::VideoContentDescription());
   1599     EXPECT_TRUE(session1_.set_local_description(sdesc_loc));
   1600     sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
   1601                           new cricket::AudioContentDescription());
   1602     sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
   1603                           new cricket::VideoContentDescription());
   1604     EXPECT_TRUE(session1_.set_remote_description(sdesc_rem));
   1605 
   1606     // Test failures in SetLocalContent.
   1607     media_channel1_->set_fail_set_recv_codecs(true);
   1608     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1609     session1_.SetState(cricket::Session::STATE_SENTINITIATE);
   1610     EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
   1611     media_channel1_->set_fail_set_recv_codecs(true);
   1612     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1613     session1_.SetState(cricket::Session::STATE_SENTACCEPT);
   1614     EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
   1615 
   1616     // Test failures in SetRemoteContent.
   1617     media_channel1_->set_fail_set_send_codecs(true);
   1618     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1619     session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
   1620     EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
   1621     media_channel1_->set_fail_set_send_codecs(true);
   1622     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1623     session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
   1624     EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
   1625   }
   1626 
   1627   void TestSendTwoOffers() {
   1628     CreateChannels(0, 0);
   1629 
   1630     // Set up the initial session description.
   1631     cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
   1632     EXPECT_TRUE(session1_.set_local_description(sdesc));
   1633 
   1634     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1635     session1_.SetState(cricket::Session::STATE_SENTINITIATE);
   1636     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1637     EXPECT_TRUE(media_channel1_->HasSendStream(1));
   1638 
   1639     // Update the local description and set the state again.
   1640     sdesc = CreateSessionDescriptionWithStream(2);
   1641     EXPECT_TRUE(session1_.set_local_description(sdesc));
   1642 
   1643     session1_.SetState(cricket::Session::STATE_SENTINITIATE);
   1644     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1645     EXPECT_FALSE(media_channel1_->HasSendStream(1));
   1646     EXPECT_TRUE(media_channel1_->HasSendStream(2));
   1647   }
   1648 
   1649   void TestReceiveTwoOffers() {
   1650     CreateChannels(0, 0);
   1651 
   1652     // Set up the initial session description.
   1653     cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
   1654     EXPECT_TRUE(session1_.set_remote_description(sdesc));
   1655 
   1656     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1657     session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
   1658     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1659     EXPECT_TRUE(media_channel1_->HasRecvStream(1));
   1660 
   1661     sdesc = CreateSessionDescriptionWithStream(2);
   1662     EXPECT_TRUE(session1_.set_remote_description(sdesc));
   1663     session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
   1664     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1665     EXPECT_FALSE(media_channel1_->HasRecvStream(1));
   1666     EXPECT_TRUE(media_channel1_->HasRecvStream(2));
   1667   }
   1668 
   1669   void TestSendPrAnswer() {
   1670     CreateChannels(0, 0);
   1671 
   1672     // Set up the initial session description.
   1673     cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
   1674     EXPECT_TRUE(session1_.set_remote_description(sdesc));
   1675 
   1676     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1677     session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
   1678     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1679     EXPECT_TRUE(media_channel1_->HasRecvStream(1));
   1680 
   1681     // Send PRANSWER
   1682     sdesc = CreateSessionDescriptionWithStream(2);
   1683     EXPECT_TRUE(session1_.set_local_description(sdesc));
   1684 
   1685     session1_.SetState(cricket::Session::STATE_SENTPRACCEPT);
   1686     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1687     EXPECT_TRUE(media_channel1_->HasRecvStream(1));
   1688     EXPECT_TRUE(media_channel1_->HasSendStream(2));
   1689 
   1690     // Send ACCEPT
   1691     sdesc = CreateSessionDescriptionWithStream(3);
   1692     EXPECT_TRUE(session1_.set_local_description(sdesc));
   1693 
   1694     session1_.SetState(cricket::Session::STATE_SENTACCEPT);
   1695     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1696     EXPECT_TRUE(media_channel1_->HasRecvStream(1));
   1697     EXPECT_FALSE(media_channel1_->HasSendStream(2));
   1698     EXPECT_TRUE(media_channel1_->HasSendStream(3));
   1699   }
   1700 
   1701   void TestReceivePrAnswer() {
   1702     CreateChannels(0, 0);
   1703 
   1704     // Set up the initial session description.
   1705     cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
   1706     EXPECT_TRUE(session1_.set_local_description(sdesc));
   1707 
   1708     session1_.SetError(cricket::BaseSession::ERROR_NONE);
   1709     session1_.SetState(cricket::Session::STATE_SENTINITIATE);
   1710     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1711     EXPECT_TRUE(media_channel1_->HasSendStream(1));
   1712 
   1713     // Receive PRANSWER
   1714     sdesc = CreateSessionDescriptionWithStream(2);
   1715     EXPECT_TRUE(session1_.set_remote_description(sdesc));
   1716 
   1717     session1_.SetState(cricket::Session::STATE_RECEIVEDPRACCEPT);
   1718     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1719     EXPECT_TRUE(media_channel1_->HasSendStream(1));
   1720     EXPECT_TRUE(media_channel1_->HasRecvStream(2));
   1721 
   1722     // Receive ACCEPT
   1723     sdesc = CreateSessionDescriptionWithStream(3);
   1724     EXPECT_TRUE(session1_.set_remote_description(sdesc));
   1725 
   1726     session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
   1727     EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
   1728     EXPECT_TRUE(media_channel1_->HasSendStream(1));
   1729     EXPECT_FALSE(media_channel1_->HasRecvStream(2));
   1730     EXPECT_TRUE(media_channel1_->HasRecvStream(3));
   1731   }
   1732 
   1733   void TestFlushRtcp() {
   1734     bool send_rtcp1;
   1735 
   1736     CreateChannels(RTCP, RTCP);
   1737     EXPECT_TRUE(SendInitiate());
   1738     EXPECT_TRUE(SendAccept());
   1739     EXPECT_EQ(2U, GetTransport1()->channels().size());
   1740     EXPECT_EQ(2U, GetTransport2()->channels().size());
   1741 
   1742     // Send RTCP1 from a different thread.
   1743     CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
   1744     EXPECT_TRUE(send_rtcp1);
   1745     // The sending message is only posted.  channel2_ should be empty.
   1746     EXPECT_TRUE(CheckNoRtcp2());
   1747 
   1748     // When channel1_ is deleted, the RTCP packet should be sent out to
   1749     // channel2_.
   1750     channel1_.reset();
   1751     EXPECT_TRUE(CheckRtcp2());
   1752   }
   1753 
   1754   void TestChangeStateError() {
   1755     CreateChannels(RTCP, RTCP);
   1756     EXPECT_TRUE(SendInitiate());
   1757     media_channel2_->set_fail_set_send(true);
   1758     EXPECT_TRUE(channel2_->Enable(true));
   1759     EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
   1760               error_);
   1761   }
   1762 
   1763   void TestSrtpError() {
   1764     static const unsigned char kBadPacket[] = {
   1765       0x84, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
   1766     };
   1767     CreateChannels(RTCP | SECURE, RTCP | SECURE);
   1768     EXPECT_FALSE(channel1_->secure());
   1769     EXPECT_FALSE(channel2_->secure());
   1770     EXPECT_TRUE(SendInitiate());
   1771     EXPECT_TRUE(SendAccept());
   1772     EXPECT_TRUE(channel1_->secure());
   1773     EXPECT_TRUE(channel2_->secure());
   1774     channel2_->set_srtp_signal_silent_time(200);
   1775 
   1776     // Testing failures in sending packets.
   1777     EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
   1778     // The first failure will trigger an error.
   1779     EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
   1780     error_ = T::MediaChannel::ERROR_NONE;
   1781     // The next 1 sec failures will not trigger an error.
   1782     EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
   1783     // Wait for a while to ensure no message comes in.
   1784     talk_base::Thread::Current()->ProcessMessages(210);
   1785     EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
   1786     // The error will be triggered again.
   1787     EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
   1788     EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
   1789 
   1790     // Testing failures in receiving packets.
   1791     error_ = T::MediaChannel::ERROR_NONE;
   1792     cricket::TransportChannel* transport_channel =
   1793         channel2_->transport_channel();
   1794     transport_channel->SignalReadPacket(
   1795         transport_channel, reinterpret_cast<const char*>(kBadPacket),
   1796         sizeof(kBadPacket), 0);
   1797     EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_AUTH_FAILED, error_, 500);
   1798   }
   1799 
   1800   void TestOnReadyToSend() {
   1801     CreateChannels(RTCP, RTCP);
   1802     TransportChannel* rtp = channel1_->transport_channel();
   1803     TransportChannel* rtcp = channel1_->rtcp_transport_channel();
   1804     EXPECT_FALSE(media_channel1_->ready_to_send());
   1805     rtp->SignalReadyToSend(rtp);
   1806     EXPECT_FALSE(media_channel1_->ready_to_send());
   1807     rtcp->SignalReadyToSend(rtcp);
   1808     // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
   1809     // channel are ready to send.
   1810     EXPECT_TRUE(media_channel1_->ready_to_send());
   1811 
   1812     // rtp channel becomes not ready to send will be propagated to mediachannel
   1813     channel1_->SetReadyToSend(rtp, false);
   1814     EXPECT_FALSE(media_channel1_->ready_to_send());
   1815     channel1_->SetReadyToSend(rtp, true);
   1816     EXPECT_TRUE(media_channel1_->ready_to_send());
   1817 
   1818     // rtcp channel becomes not ready to send will be propagated to mediachannel
   1819     channel1_->SetReadyToSend(rtcp, false);
   1820     EXPECT_FALSE(media_channel1_->ready_to_send());
   1821     channel1_->SetReadyToSend(rtcp, true);
   1822     EXPECT_TRUE(media_channel1_->ready_to_send());
   1823   }
   1824 
   1825   void TestOnReadyToSendWithRtcpMux() {
   1826     CreateChannels(RTCP, RTCP);
   1827     typename T::Content content;
   1828     CreateContent(0, kPcmuCodec, kH264Codec, &content);
   1829     // Both sides agree on mux. Should no longer be a separate RTCP channel.
   1830     content.set_rtcp_mux(true);
   1831     EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
   1832     EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
   1833     EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
   1834     TransportChannel* rtp = channel1_->transport_channel();
   1835     EXPECT_FALSE(media_channel1_->ready_to_send());
   1836     // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
   1837     // should trigger the MediaChannel's OnReadyToSend.
   1838     rtp->SignalReadyToSend(rtp);
   1839     EXPECT_TRUE(media_channel1_->ready_to_send());
   1840     channel1_->SetReadyToSend(rtp, false);
   1841     EXPECT_FALSE(media_channel1_->ready_to_send());
   1842   }
   1843 
   1844  protected:
   1845   cricket::FakeSession session1_;
   1846   cricket::FakeSession session2_;
   1847   cricket::FakeMediaEngine media_engine_;
   1848   // The media channels are owned by the voice channel objects below.
   1849   typename T::MediaChannel* media_channel1_;
   1850   typename T::MediaChannel* media_channel2_;
   1851   talk_base::scoped_ptr<typename T::Channel> channel1_;
   1852   talk_base::scoped_ptr<typename T::Channel> channel2_;
   1853   typename T::Content local_media_content1_;
   1854   typename T::Content local_media_content2_;
   1855   typename T::Content remote_media_content1_;
   1856   typename T::Content remote_media_content2_;
   1857   talk_base::scoped_ptr<talk_base::SSLIdentity> identity1_;
   1858   talk_base::scoped_ptr<talk_base::SSLIdentity> identity2_;
   1859   // The RTP and RTCP packets to send in the tests.
   1860   std::string rtp_packet_;
   1861   std::string rtcp_packet_;
   1862   int media_info_callbacks1_;
   1863   int media_info_callbacks2_;
   1864   bool mute_callback_recved_;
   1865   bool mute_callback_value_;
   1866 
   1867   uint32 ssrc_;
   1868   typename T::MediaChannel::Error error_;
   1869 };
   1870 
   1871 
   1872 template<>
   1873 void ChannelTest<VoiceTraits>::CreateContent(
   1874     int flags,
   1875     const cricket::AudioCodec& audio_codec,
   1876     const cricket::VideoCodec& video_codec,
   1877     cricket::AudioContentDescription* audio) {
   1878   audio->AddCodec(audio_codec);
   1879   audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
   1880   if (flags & SECURE) {
   1881     audio->AddCrypto(cricket::CryptoParams(
   1882         1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
   1883         "inline:" + talk_base::CreateRandomString(40), ""));
   1884   }
   1885 }
   1886 
   1887 template<>
   1888 void ChannelTest<VoiceTraits>::CopyContent(
   1889     const cricket::AudioContentDescription& source,
   1890     cricket::AudioContentDescription* audio) {
   1891   *audio = source;
   1892 }
   1893 
   1894 template<>
   1895 bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
   1896                                             const cricket::AudioCodec& c2) {
   1897   return c1.name == c2.name && c1.clockrate == c2.clockrate &&
   1898       c1.bitrate == c2.bitrate && c1.channels == c2.channels;
   1899 }
   1900 
   1901 template<>
   1902 void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
   1903     uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
   1904   audio->AddLegacyStream(ssrc);
   1905 }
   1906 
   1907 class VoiceChannelTest
   1908     : public ChannelTest<VoiceTraits> {
   1909  public:
   1910   typedef ChannelTest<VoiceTraits>
   1911   Base;
   1912   VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
   1913                             kRtcpReport, sizeof(kRtcpReport)) {
   1914   }
   1915 
   1916   void TestSetChannelOptions() {
   1917     CreateChannels(0, 0);
   1918 
   1919     cricket::AudioOptions options1;
   1920     options1.echo_cancellation.Set(false);
   1921     cricket::AudioOptions options2;
   1922     options2.echo_cancellation.Set(true);
   1923 
   1924     channel1_->SetChannelOptions(options1);
   1925     channel2_->SetChannelOptions(options1);
   1926     cricket::AudioOptions actual_options;
   1927     ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
   1928     EXPECT_EQ(options1, actual_options);
   1929     ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
   1930     EXPECT_EQ(options1, actual_options);
   1931 
   1932     channel1_->SetChannelOptions(options2);
   1933     channel2_->SetChannelOptions(options2);
   1934     ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
   1935     EXPECT_EQ(options2, actual_options);
   1936     ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
   1937     EXPECT_EQ(options2, actual_options);
   1938   }
   1939 };
   1940 
   1941 // override to add NULL parameter
   1942 template<>
   1943 cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
   1944     talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
   1945     cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
   1946     bool rtcp) {
   1947   cricket::VideoChannel* channel = new cricket::VideoChannel(
   1948       thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL);
   1949   if (!channel->Init()) {
   1950     delete channel;
   1951     channel = NULL;
   1952   }
   1953   return channel;
   1954 }
   1955 
   1956 // override to add 0 parameter
   1957 template<>
   1958 bool ChannelTest<VideoTraits>::AddStream1(int id) {
   1959   return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
   1960 }
   1961 
   1962 template<>
   1963 void ChannelTest<VideoTraits>::CreateContent(
   1964     int flags,
   1965     const cricket::AudioCodec& audio_codec,
   1966     const cricket::VideoCodec& video_codec,
   1967     cricket::VideoContentDescription* video) {
   1968   video->AddCodec(video_codec);
   1969   video->set_rtcp_mux((flags & RTCP_MUX) != 0);
   1970   if (flags & SECURE) {
   1971     video->AddCrypto(cricket::CryptoParams(
   1972         1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
   1973         "inline:" + talk_base::CreateRandomString(40), ""));
   1974   }
   1975 }
   1976 
   1977 template<>
   1978 void ChannelTest<VideoTraits>::CopyContent(
   1979     const cricket::VideoContentDescription& source,
   1980     cricket::VideoContentDescription* video) {
   1981   *video = source;
   1982 }
   1983 
   1984 template<>
   1985 bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
   1986                                             const cricket::VideoCodec& c2) {
   1987   return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
   1988       c1.framerate == c2.framerate;
   1989 }
   1990 
   1991 template<>
   1992 void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
   1993     uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
   1994   video->AddLegacyStream(ssrc);
   1995 }
   1996 
   1997 class VideoChannelTest
   1998     : public ChannelTest<VideoTraits> {
   1999  public:
   2000   typedef ChannelTest<VideoTraits>
   2001   Base;
   2002   VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
   2003                             kRtcpReport, sizeof(kRtcpReport)) {
   2004   }
   2005 
   2006   void TestSetChannelOptions() {
   2007     CreateChannels(0, 0);
   2008 
   2009     cricket::VideoOptions o1, o2;
   2010     o1.video_noise_reduction.Set(true);
   2011 
   2012     channel1_->SetChannelOptions(o1);
   2013     channel2_->SetChannelOptions(o1);
   2014     EXPECT_TRUE(media_channel1_->GetOptions(&o2));
   2015     EXPECT_EQ(o1, o2);
   2016     EXPECT_TRUE(media_channel2_->GetOptions(&o2));
   2017     EXPECT_EQ(o1, o2);
   2018 
   2019     o1.video_leaky_bucket.Set(true);
   2020     channel1_->SetChannelOptions(o1);
   2021     channel2_->SetChannelOptions(o1);
   2022     EXPECT_TRUE(media_channel1_->GetOptions(&o2));
   2023     EXPECT_EQ(o1, o2);
   2024     EXPECT_TRUE(media_channel2_->GetOptions(&o2));
   2025     EXPECT_EQ(o1, o2);
   2026   }
   2027 };
   2028 
   2029 
   2030 // VoiceChannelTest
   2031 
   2032 TEST_F(VoiceChannelTest, TestInit) {
   2033   Base::TestInit();
   2034   EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
   2035   EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
   2036 }
   2037 
   2038 TEST_F(VoiceChannelTest, TestSetContents) {
   2039   Base::TestSetContents();
   2040 }
   2041 
   2042 TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
   2043   Base::TestSetContentsNullOffer();
   2044 }
   2045 
   2046 TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
   2047   Base::TestSetContentsRtcpMux();
   2048 }
   2049 
   2050 TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
   2051   Base::TestSetContentsRtcpMux();
   2052 }
   2053 
   2054 TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
   2055   Base::TestSetRemoteContentUpdate();
   2056 }
   2057 
   2058 TEST_F(VoiceChannelTest, TestStreams) {
   2059   Base::TestStreams();
   2060 }
   2061 
   2062 TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
   2063   Base::TestUpdateStreamsInLocalContent();
   2064 }
   2065 
   2066 TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
   2067   Base::TestUpdateStreamsInRemoteContent();
   2068 }
   2069 
   2070 TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
   2071   Base::TestChangeStreamParamsInContent();
   2072 }
   2073 
   2074 TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
   2075   Base::TestPlayoutAndSendingStates();
   2076 }
   2077 
   2078 TEST_F(VoiceChannelTest, TestMuteStream) {
   2079   Base::TestMuteStream();
   2080 }
   2081 
   2082 TEST_F(VoiceChannelTest, TestMediaContentDirection) {
   2083   Base::TestMediaContentDirection();
   2084 }
   2085 
   2086 TEST_F(VoiceChannelTest, TestCallSetup) {
   2087   Base::TestCallSetup();
   2088 }
   2089 
   2090 TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
   2091   Base::TestCallTeardownRtcpMux();
   2092 }
   2093 
   2094 TEST_F(VoiceChannelTest, SendRtpToRtp) {
   2095   Base::SendRtpToRtp();
   2096 }
   2097 
   2098 TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
   2099   Base::SendNoRtcpToNoRtcp();
   2100 }
   2101 
   2102 TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
   2103   Base::SendNoRtcpToRtcp();
   2104 }
   2105 
   2106 TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
   2107   Base::SendRtcpToNoRtcp();
   2108 }
   2109 
   2110 TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
   2111   Base::SendRtcpToRtcp();
   2112 }
   2113 
   2114 TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
   2115   Base::SendRtcpMuxToRtcp();
   2116 }
   2117 
   2118 TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
   2119   Base::SendRtcpMuxToRtcpMux();
   2120 }
   2121 
   2122 TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
   2123   Base::SendEarlyRtcpMuxToRtcp();
   2124 }
   2125 
   2126 TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
   2127   Base::SendEarlyRtcpMuxToRtcpMux();
   2128 }
   2129 
   2130 TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
   2131   Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
   2132 }
   2133 
   2134 TEST_F(VoiceChannelTest, SendSrtpToRtp) {
   2135   Base::SendSrtpToSrtp();
   2136 }
   2137 
   2138 TEST_F(VoiceChannelTest, SendSrtcpMux) {
   2139   Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
   2140 }
   2141 
   2142 TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
   2143   MAYBE_SKIP_TEST(HaveDtlsSrtp);
   2144   Base::SendSrtpToSrtp(DTLS, 0);
   2145 }
   2146 
   2147 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
   2148   MAYBE_SKIP_TEST(HaveDtlsSrtp);
   2149   Base::SendSrtpToSrtp(DTLS, DTLS);
   2150 }
   2151 
   2152 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
   2153   MAYBE_SKIP_TEST(HaveDtlsSrtp);
   2154   Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
   2155 }
   2156 
   2157 TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
   2158   Base::SendEarlyMediaUsingRtcpMuxSrtp();
   2159 }
   2160 
   2161 TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
   2162   Base::SendRtpToRtpOnThread();
   2163 }
   2164 
   2165 TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
   2166   Base::SendSrtpToSrtpOnThread();
   2167 }
   2168 
   2169 TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
   2170   Base::SendWithWritabilityLoss();
   2171 }
   2172 
   2173 TEST_F(VoiceChannelTest, TestMediaMonitor) {
   2174   Base::TestMediaMonitor();
   2175 }
   2176 
   2177 // Test that MuteStream properly forwards to the media channel and does
   2178 // not signal.
   2179 TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
   2180   CreateChannels(0, 0);
   2181   EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
   2182   EXPECT_FALSE(mute_callback_recved_);
   2183   EXPECT_TRUE(channel1_->MuteStream(0, true));
   2184   EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
   2185   EXPECT_FALSE(mute_callback_recved_);
   2186   EXPECT_TRUE(channel1_->MuteStream(0, false));
   2187   EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
   2188   EXPECT_FALSE(mute_callback_recved_);
   2189 }
   2190 
   2191 // Test that keyboard automute works correctly and signals upwards.
   2192 TEST_F(VoiceChannelTest, TestKeyboardMute) {
   2193   CreateChannels(0, 0);
   2194   EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
   2195   EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
   2196 
   2197   cricket::VoiceMediaChannel::Error e =
   2198       cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
   2199 
   2200   // Typing doesn't mute automatically unless typing monitor has been installed
   2201   media_channel1_->TriggerError(0, e);
   2202   talk_base::Thread::Current()->ProcessMessages(0);
   2203   EXPECT_EQ(e, error_);
   2204   EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
   2205   EXPECT_FALSE(mute_callback_recved_);
   2206 
   2207   cricket::TypingMonitorOptions o = {0};
   2208   o.mute_period = 1500;
   2209   channel1_->StartTypingMonitor(o);
   2210   media_channel1_->TriggerError(0, e);
   2211   talk_base::Thread::Current()->ProcessMessages(0);
   2212   EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
   2213   EXPECT_TRUE(mute_callback_recved_);
   2214 }
   2215 
   2216 // Test that PressDTMF properly forwards to the media channel.
   2217 TEST_F(VoiceChannelTest, TestDtmf) {
   2218   CreateChannels(0, 0);
   2219   EXPECT_TRUE(SendInitiate());
   2220   EXPECT_TRUE(SendAccept());
   2221   EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
   2222 
   2223   EXPECT_TRUE(channel1_->PressDTMF(1, true));
   2224   EXPECT_TRUE(channel1_->PressDTMF(8, false));
   2225 
   2226   ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
   2227   EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
   2228                               0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
   2229   EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
   2230                               0, 8, 160, cricket::DF_SEND));
   2231 }
   2232 
   2233 // Test that InsertDtmf properly forwards to the media channel.
   2234 TEST_F(VoiceChannelTest, TestInsertDtmf) {
   2235   CreateChannels(0, 0);
   2236   EXPECT_TRUE(SendInitiate());
   2237   EXPECT_TRUE(SendAccept());
   2238   EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
   2239 
   2240   EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
   2241   EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
   2242   EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
   2243                                     cricket::DF_PLAY | cricket::DF_SEND));
   2244 
   2245   ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
   2246   EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
   2247                               1, 3, 100, cricket::DF_SEND));
   2248   EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
   2249                               2, 5, 110, cricket::DF_PLAY));
   2250   EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
   2251                               3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
   2252 }
   2253 
   2254 TEST_F(VoiceChannelTest, TestMediaSinks) {
   2255   Base::TestMediaSinks();
   2256 }
   2257 
   2258 TEST_F(VoiceChannelTest, TestSetContentFailure) {
   2259   Base::TestSetContentFailure();
   2260 }
   2261 
   2262 TEST_F(VoiceChannelTest, TestSendTwoOffers) {
   2263   Base::TestSendTwoOffers();
   2264 }
   2265 
   2266 TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
   2267   Base::TestReceiveTwoOffers();
   2268 }
   2269 
   2270 TEST_F(VoiceChannelTest, TestSendPrAnswer) {
   2271   Base::TestSendPrAnswer();
   2272 }
   2273 
   2274 TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
   2275   Base::TestReceivePrAnswer();
   2276 }
   2277 
   2278 TEST_F(VoiceChannelTest, TestFlushRtcp) {
   2279   Base::TestFlushRtcp();
   2280 }
   2281 
   2282 TEST_F(VoiceChannelTest, TestChangeStateError) {
   2283   Base::TestChangeStateError();
   2284 }
   2285 
   2286 TEST_F(VoiceChannelTest, TestSrtpError) {
   2287   Base::TestSrtpError();
   2288 }
   2289 
   2290 TEST_F(VoiceChannelTest, TestOnReadyToSend) {
   2291   Base::TestOnReadyToSend();
   2292 }
   2293 
   2294 TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
   2295   Base::TestOnReadyToSendWithRtcpMux();
   2296 }
   2297 
   2298 // Test that we can play a ringback tone properly.
   2299 TEST_F(VoiceChannelTest, TestRingbackTone) {
   2300   CreateChannels(RTCP, RTCP);
   2301   EXPECT_FALSE(media_channel1_->ringback_tone_play());
   2302   EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
   2303   EXPECT_TRUE(SendInitiate());
   2304   EXPECT_TRUE(SendAccept());
   2305   // Play ringback tone, no loop.
   2306   EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
   2307   EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
   2308   EXPECT_TRUE(media_channel1_->ringback_tone_play());
   2309   EXPECT_FALSE(media_channel1_->ringback_tone_loop());
   2310   // Stop the ringback tone.
   2311   EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
   2312   EXPECT_FALSE(media_channel1_->ringback_tone_play());
   2313   // Add a stream.
   2314   EXPECT_TRUE(AddStream1(1));
   2315   // Play ringback tone, looping, on the new stream.
   2316   EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
   2317   EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
   2318   EXPECT_TRUE(media_channel1_->ringback_tone_play());
   2319   EXPECT_TRUE(media_channel1_->ringback_tone_loop());
   2320   // Stop the ringback tone.
   2321   EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
   2322   EXPECT_FALSE(media_channel1_->ringback_tone_play());
   2323 }
   2324 
   2325 // Test that we can scale the output volume properly for 1:1 calls.
   2326 TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
   2327   CreateChannels(RTCP, RTCP);
   2328   EXPECT_TRUE(SendInitiate());
   2329   EXPECT_TRUE(SendAccept());
   2330   double left, right;
   2331 
   2332   // Default is (1.0, 1.0).
   2333   EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
   2334   EXPECT_DOUBLE_EQ(1.0, left);
   2335   EXPECT_DOUBLE_EQ(1.0, right);
   2336   // invalid ssrc.
   2337   EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
   2338 
   2339   // Set scale to (1.5, 0.5).
   2340   EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
   2341   EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
   2342   EXPECT_DOUBLE_EQ(1.5, left);
   2343   EXPECT_DOUBLE_EQ(0.5, right);
   2344 
   2345   // Set scale to (0, 0).
   2346   EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
   2347   EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
   2348   EXPECT_DOUBLE_EQ(0.0, left);
   2349   EXPECT_DOUBLE_EQ(0.0, right);
   2350 }
   2351 
   2352 // Test that we can scale the output volume properly for multiway calls.
   2353 TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
   2354   CreateChannels(RTCP, RTCP);
   2355   EXPECT_TRUE(SendInitiate());
   2356   EXPECT_TRUE(SendAccept());
   2357   EXPECT_TRUE(AddStream1(1));
   2358   EXPECT_TRUE(AddStream1(2));
   2359 
   2360   double left, right;
   2361   // Default is (1.0, 1.0).
   2362   EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
   2363   EXPECT_DOUBLE_EQ(1.0, left);
   2364   EXPECT_DOUBLE_EQ(1.0, right);
   2365   EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
   2366   EXPECT_DOUBLE_EQ(1.0, left);
   2367   EXPECT_DOUBLE_EQ(1.0, right);
   2368   EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
   2369   EXPECT_DOUBLE_EQ(1.0, left);
   2370   EXPECT_DOUBLE_EQ(1.0, right);
   2371   // invalid ssrc.
   2372   EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
   2373 
   2374   // Set scale to (1.5, 0.5) for ssrc = 1.
   2375   EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
   2376   EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
   2377   EXPECT_DOUBLE_EQ(1.5, left);
   2378   EXPECT_DOUBLE_EQ(0.5, right);
   2379   EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
   2380   EXPECT_DOUBLE_EQ(1.0, left);
   2381   EXPECT_DOUBLE_EQ(1.0, right);
   2382   EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
   2383   EXPECT_DOUBLE_EQ(1.0, left);
   2384   EXPECT_DOUBLE_EQ(1.0, right);
   2385 
   2386   // Set scale to (0, 0) for all ssrcs.
   2387   EXPECT_TRUE(channel1_->SetOutputScaling(0,  0.0, 0.0));
   2388   EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
   2389   EXPECT_DOUBLE_EQ(0.0, left);
   2390   EXPECT_DOUBLE_EQ(0.0, right);
   2391   EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
   2392   EXPECT_DOUBLE_EQ(0.0, left);
   2393   EXPECT_DOUBLE_EQ(0.0, right);
   2394   EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
   2395   EXPECT_DOUBLE_EQ(0.0, left);
   2396   EXPECT_DOUBLE_EQ(0.0, right);
   2397 }
   2398 
   2399 TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMux) {
   2400   Base::SendSsrcMuxToSsrcMux();
   2401 }
   2402 
   2403 TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) {
   2404   Base::SendSsrcMuxToSsrcMuxWithRtcpMux();
   2405 }
   2406 
   2407 TEST_F(VoiceChannelTest, TestSetChannelOptions) {
   2408   TestSetChannelOptions();
   2409 }
   2410 
   2411 // VideoChannelTest
   2412 TEST_F(VideoChannelTest, TestInit) {
   2413   Base::TestInit();
   2414 }
   2415 
   2416 TEST_F(VideoChannelTest, TestSetContents) {
   2417   Base::TestSetContents();
   2418 }
   2419 
   2420 TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
   2421   Base::TestSetContentsNullOffer();
   2422 }
   2423 
   2424 TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
   2425   Base::TestSetContentsRtcpMux();
   2426 }
   2427 
   2428 TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
   2429   Base::TestSetContentsRtcpMux();
   2430 }
   2431 
   2432 TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
   2433   Base::TestSetContentsVideoOptions();
   2434 }
   2435 
   2436 TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
   2437   Base::TestSetRemoteContentUpdate();
   2438 }
   2439 
   2440 TEST_F(VideoChannelTest, TestStreams) {
   2441   Base::TestStreams();
   2442 }
   2443 
   2444 TEST_F(VideoChannelTest, TestScreencastEvents) {
   2445   const int kTimeoutMs = 500;
   2446   TestInit();
   2447   FakeScreenCaptureFactory* screencapture_factory =
   2448       new FakeScreenCaptureFactory();
   2449   channel1_->SetScreenCaptureFactory(screencapture_factory);
   2450   cricket::ScreencastEventCatcher catcher;
   2451   channel1_->SignalScreencastWindowEvent.connect(
   2452       &catcher,
   2453       &cricket::ScreencastEventCatcher::OnEvent);
   2454   EXPECT_TRUE(channel1_->AddScreencast(0, ScreencastId(WindowId(0))) != NULL);
   2455   ASSERT_TRUE(screencapture_factory->window_capturer() != NULL);
   2456   EXPECT_EQ_WAIT(cricket::CS_STOPPED, screencapture_factory->capture_state(),
   2457                  kTimeoutMs);
   2458   screencapture_factory->window_capturer()->SignalStateChange(
   2459       screencapture_factory->window_capturer(), cricket::CS_PAUSED);
   2460   EXPECT_EQ_WAIT(talk_base::WE_MINIMIZE, catcher.event(), kTimeoutMs);
   2461   screencapture_factory->window_capturer()->SignalStateChange(
   2462       screencapture_factory->window_capturer(), cricket::CS_RUNNING);
   2463   EXPECT_EQ_WAIT(talk_base::WE_RESTORE, catcher.event(), kTimeoutMs);
   2464   screencapture_factory->window_capturer()->SignalStateChange(
   2465       screencapture_factory->window_capturer(), cricket::CS_STOPPED);
   2466   EXPECT_EQ_WAIT(talk_base::WE_CLOSE, catcher.event(), kTimeoutMs);
   2467   EXPECT_TRUE(channel1_->RemoveScreencast(0));
   2468   ASSERT_TRUE(screencapture_factory->window_capturer() == NULL);
   2469 }
   2470 
   2471 TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
   2472   Base::TestUpdateStreamsInLocalContent();
   2473 }
   2474 
   2475 TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
   2476   Base::TestUpdateStreamsInRemoteContent();
   2477 }
   2478 
   2479 TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
   2480   Base::TestChangeStreamParamsInContent();
   2481 }
   2482 
   2483 TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
   2484   Base::TestPlayoutAndSendingStates();
   2485 }
   2486 
   2487 TEST_F(VideoChannelTest, TestMuteStream) {
   2488   Base::TestMuteStream();
   2489 }
   2490 
   2491 TEST_F(VideoChannelTest, TestMediaContentDirection) {
   2492   Base::TestMediaContentDirection();
   2493 }
   2494 
   2495 TEST_F(VideoChannelTest, TestCallSetup) {
   2496   Base::TestCallSetup();
   2497 }
   2498 
   2499 TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
   2500   Base::TestCallTeardownRtcpMux();
   2501 }
   2502 
   2503 TEST_F(VideoChannelTest, SendRtpToRtp) {
   2504   Base::SendRtpToRtp();
   2505 }
   2506 
   2507 TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
   2508   Base::SendNoRtcpToNoRtcp();
   2509 }
   2510 
   2511 TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
   2512   Base::SendNoRtcpToRtcp();
   2513 }
   2514 
   2515 TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
   2516   Base::SendRtcpToNoRtcp();
   2517 }
   2518 
   2519 TEST_F(VideoChannelTest, SendRtcpToRtcp) {
   2520   Base::SendRtcpToRtcp();
   2521 }
   2522 
   2523 TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
   2524   Base::SendRtcpMuxToRtcp();
   2525 }
   2526 
   2527 TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
   2528   Base::SendRtcpMuxToRtcpMux();
   2529 }
   2530 
   2531 TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
   2532   Base::SendEarlyRtcpMuxToRtcp();
   2533 }
   2534 
   2535 TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
   2536   Base::SendEarlyRtcpMuxToRtcpMux();
   2537 }
   2538 
   2539 TEST_F(VideoChannelTest, SendSrtpToSrtp) {
   2540   Base::SendSrtpToSrtp();
   2541 }
   2542 
   2543 TEST_F(VideoChannelTest, SendSrtpToRtp) {
   2544   Base::SendSrtpToSrtp();
   2545 }
   2546 
   2547 TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
   2548   MAYBE_SKIP_TEST(HaveDtlsSrtp);
   2549   Base::SendSrtpToSrtp(DTLS, 0);
   2550 }
   2551 
   2552 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
   2553   MAYBE_SKIP_TEST(HaveDtlsSrtp);
   2554   Base::SendSrtpToSrtp(DTLS, DTLS);
   2555 }
   2556 
   2557 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
   2558   MAYBE_SKIP_TEST(HaveDtlsSrtp);
   2559   Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
   2560 }
   2561 
   2562 TEST_F(VideoChannelTest, SendSrtcpMux) {
   2563   Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
   2564 }
   2565 
   2566 TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
   2567   Base::SendEarlyMediaUsingRtcpMuxSrtp();
   2568 }
   2569 
   2570 TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
   2571   Base::SendRtpToRtpOnThread();
   2572 }
   2573 
   2574 TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
   2575   Base::SendSrtpToSrtpOnThread();
   2576 }
   2577 
   2578 TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
   2579   Base::SendWithWritabilityLoss();
   2580 }
   2581 
   2582 TEST_F(VideoChannelTest, TestMediaMonitor) {
   2583   Base::TestMediaMonitor();
   2584 }
   2585 
   2586 TEST_F(VideoChannelTest, TestMediaSinks) {
   2587   Base::TestMediaSinks();
   2588 }
   2589 
   2590 TEST_F(VideoChannelTest, TestSetContentFailure) {
   2591   Base::TestSetContentFailure();
   2592 }
   2593 
   2594 TEST_F(VideoChannelTest, TestSendTwoOffers) {
   2595   Base::TestSendTwoOffers();
   2596 }
   2597 
   2598 TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
   2599   Base::TestReceiveTwoOffers();
   2600 }
   2601 
   2602 TEST_F(VideoChannelTest, TestSendPrAnswer) {
   2603   Base::TestSendPrAnswer();
   2604 }
   2605 
   2606 TEST_F(VideoChannelTest, TestReceivePrAnswer) {
   2607   Base::TestReceivePrAnswer();
   2608 }
   2609 
   2610 TEST_F(VideoChannelTest, TestFlushRtcp) {
   2611   Base::TestFlushRtcp();
   2612 }
   2613 
   2614 TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMux) {
   2615   Base::SendSsrcMuxToSsrcMux();
   2616 }
   2617 
   2618 TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) {
   2619   Base::SendSsrcMuxToSsrcMuxWithRtcpMux();
   2620 }
   2621 
   2622 // TODO(gangji): Add VideoChannelTest.TestChangeStateError.
   2623 
   2624 TEST_F(VideoChannelTest, TestSrtpError) {
   2625   Base::TestSrtpError();
   2626 }
   2627 
   2628 TEST_F(VideoChannelTest, TestOnReadyToSend) {
   2629   Base::TestOnReadyToSend();
   2630 }
   2631 
   2632 TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
   2633   Base::TestOnReadyToSendWithRtcpMux();
   2634 }
   2635 
   2636 TEST_F(VideoChannelTest, TestApplyViewRequest) {
   2637   CreateChannels(0, 0);
   2638   cricket::StreamParams stream2;
   2639   stream2.id = "stream2";
   2640   stream2.ssrcs.push_back(2222);
   2641   local_media_content1_.AddStream(stream2);
   2642 
   2643   EXPECT_TRUE(SendInitiate());
   2644   EXPECT_TRUE(SendAccept());
   2645 
   2646   cricket::VideoFormat send_format;
   2647   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
   2648   EXPECT_EQ(640, send_format.width);
   2649   EXPECT_EQ(400, send_format.height);
   2650   EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
   2651 
   2652   cricket::ViewRequest request;
   2653   // stream1: 320x200x15; stream2: 0x0x0
   2654   request.static_video_views.push_back(cricket::StaticVideoView(
   2655       cricket::StreamSelector(kSsrc1), 320, 200, 15));
   2656   EXPECT_TRUE(channel1_->ApplyViewRequest(request));
   2657   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
   2658   EXPECT_EQ(320, send_format.width);
   2659   EXPECT_EQ(200, send_format.height);
   2660   EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
   2661   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
   2662   EXPECT_EQ(0, send_format.width);
   2663   EXPECT_EQ(0, send_format.height);
   2664 
   2665   // stream1: 160x100x8; stream2: 0x0x0
   2666   request.static_video_views.clear();
   2667   request.static_video_views.push_back(cricket::StaticVideoView(
   2668       cricket::StreamSelector(kSsrc1), 160, 100, 8));
   2669   EXPECT_TRUE(channel1_->ApplyViewRequest(request));
   2670   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
   2671   EXPECT_EQ(160, send_format.width);
   2672   EXPECT_EQ(100, send_format.height);
   2673   EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
   2674 
   2675   // stream1: 0x0x0; stream2: 640x400x30
   2676   request.static_video_views.clear();
   2677   request.static_video_views.push_back(cricket::StaticVideoView(
   2678       cricket::StreamSelector("", stream2.id), 640, 400, 30));
   2679   EXPECT_TRUE(channel1_->ApplyViewRequest(request));
   2680   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
   2681   EXPECT_EQ(0, send_format.width);
   2682   EXPECT_EQ(0, send_format.height);
   2683   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
   2684   EXPECT_EQ(640, send_format.width);
   2685   EXPECT_EQ(400, send_format.height);
   2686   EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
   2687 
   2688   // stream1: 0x0x0; stream2: 0x0x0
   2689   request.static_video_views.clear();
   2690   EXPECT_TRUE(channel1_->ApplyViewRequest(request));
   2691   EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
   2692   EXPECT_EQ(0, send_format.width);
   2693   EXPECT_EQ(0, send_format.height);
   2694 }
   2695 
   2696 TEST_F(VideoChannelTest, TestSetChannelOptions) {
   2697   TestSetChannelOptions();
   2698 }
   2699 
   2700 
   2701 // DataChannelTest
   2702 
   2703 class DataChannelTest
   2704     : public ChannelTest<DataTraits> {
   2705  public:
   2706   typedef ChannelTest<DataTraits>
   2707   Base;
   2708   DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
   2709                            kRtcpReport, sizeof(kRtcpReport)) {
   2710   }
   2711 };
   2712 
   2713 // Override to avoid engine channel parameter.
   2714 template<>
   2715 cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
   2716     talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
   2717     cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
   2718     bool rtcp) {
   2719   cricket::DataChannel* channel = new cricket::DataChannel(
   2720       thread, ch, session, cricket::CN_DATA, rtcp);
   2721   if (!channel->Init()) {
   2722     delete channel;
   2723     channel = NULL;
   2724   }
   2725   return channel;
   2726 }
   2727 
   2728 template<>
   2729 void ChannelTest<DataTraits>::CreateContent(
   2730     int flags,
   2731     const cricket::AudioCodec& audio_codec,
   2732     const cricket::VideoCodec& video_codec,
   2733     cricket::DataContentDescription* data) {
   2734   data->AddCodec(kGoogleDataCodec);
   2735   data->set_rtcp_mux((flags & RTCP_MUX) != 0);
   2736   if (flags & SECURE) {
   2737     data->AddCrypto(cricket::CryptoParams(
   2738         1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
   2739         "inline:" + talk_base::CreateRandomString(40), ""));
   2740   }
   2741 }
   2742 
   2743 template<>
   2744 void ChannelTest<DataTraits>::CopyContent(
   2745     const cricket::DataContentDescription& source,
   2746     cricket::DataContentDescription* data) {
   2747   *data = source;
   2748 }
   2749 
   2750 template<>
   2751 bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
   2752                                            const cricket::DataCodec& c2) {
   2753   return c1.name == c2.name;
   2754 }
   2755 
   2756 template<>
   2757 void ChannelTest<DataTraits>::AddLegacyStreamInContent(
   2758     uint32 ssrc, int flags, cricket::DataContentDescription* data) {
   2759   data->AddLegacyStream(ssrc);
   2760 }
   2761 
   2762 TEST_F(DataChannelTest, TestInit) {
   2763   Base::TestInit();
   2764   EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
   2765 }
   2766 
   2767 TEST_F(DataChannelTest, TestSetContents) {
   2768   Base::TestSetContents();
   2769 }
   2770 
   2771 TEST_F(DataChannelTest, TestSetContentsNullOffer) {
   2772   Base::TestSetContentsNullOffer();
   2773 }
   2774 
   2775 TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
   2776   Base::TestSetContentsRtcpMux();
   2777 }
   2778 
   2779 TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
   2780   Base::TestSetRemoteContentUpdate();
   2781 }
   2782 
   2783 TEST_F(DataChannelTest, TestStreams) {
   2784   Base::TestStreams();
   2785 }
   2786 
   2787 TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
   2788   Base::TestUpdateStreamsInLocalContent();
   2789 }
   2790 
   2791 TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
   2792   Base::TestUpdateStreamsInRemoteContent();
   2793 }
   2794 
   2795 TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
   2796   Base::TestChangeStreamParamsInContent();
   2797 }
   2798 
   2799 TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
   2800   Base::TestPlayoutAndSendingStates();
   2801 }
   2802 
   2803 TEST_F(DataChannelTest, TestMediaContentDirection) {
   2804   Base::TestMediaContentDirection();
   2805 }
   2806 
   2807 TEST_F(DataChannelTest, TestCallSetup) {
   2808   Base::TestCallSetup();
   2809 }
   2810 
   2811 TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
   2812   Base::TestCallTeardownRtcpMux();
   2813 }
   2814 
   2815 TEST_F(DataChannelTest, TestOnReadyToSend) {
   2816   Base::TestOnReadyToSend();
   2817 }
   2818 
   2819 TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
   2820   Base::TestOnReadyToSendWithRtcpMux();
   2821 }
   2822 
   2823 TEST_F(DataChannelTest, SendRtpToRtp) {
   2824   Base::SendRtpToRtp();
   2825 }
   2826 
   2827 TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
   2828   Base::SendNoRtcpToNoRtcp();
   2829 }
   2830 
   2831 TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
   2832   Base::SendNoRtcpToRtcp();
   2833 }
   2834 
   2835 TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
   2836   Base::SendRtcpToNoRtcp();
   2837 }
   2838 
   2839 TEST_F(DataChannelTest, SendRtcpToRtcp) {
   2840   Base::SendRtcpToRtcp();
   2841 }
   2842 
   2843 TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
   2844   Base::SendRtcpMuxToRtcp();
   2845 }
   2846 
   2847 TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
   2848   Base::SendRtcpMuxToRtcpMux();
   2849 }
   2850 
   2851 TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
   2852   Base::SendEarlyRtcpMuxToRtcp();
   2853 }
   2854 
   2855 TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
   2856   Base::SendEarlyRtcpMuxToRtcpMux();
   2857 }
   2858 
   2859 TEST_F(DataChannelTest, SendSrtpToSrtp) {
   2860   Base::SendSrtpToSrtp();
   2861 }
   2862 
   2863 TEST_F(DataChannelTest, SendSrtpToRtp) {
   2864   Base::SendSrtpToSrtp();
   2865 }
   2866 
   2867 TEST_F(DataChannelTest, SendSrtcpMux) {
   2868   Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
   2869 }
   2870 
   2871 TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
   2872   Base::SendRtpToRtpOnThread();
   2873 }
   2874 
   2875 TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
   2876   Base::SendSrtpToSrtpOnThread();
   2877 }
   2878 
   2879 TEST_F(DataChannelTest, SendWithWritabilityLoss) {
   2880   Base::SendWithWritabilityLoss();
   2881 }
   2882 
   2883 TEST_F(DataChannelTest, TestMediaMonitor) {
   2884   Base::TestMediaMonitor();
   2885 }
   2886 
   2887 TEST_F(DataChannelTest, TestSendData) {
   2888   CreateChannels(0, 0);
   2889   EXPECT_TRUE(SendInitiate());
   2890   EXPECT_TRUE(SendAccept());
   2891 
   2892   cricket::SendDataParams params;
   2893   params.ssrc = 42;
   2894   unsigned char data[] = {
   2895     'f', 'o', 'o'
   2896   };
   2897   talk_base::Buffer payload(data, 3);
   2898   cricket::SendDataResult result;
   2899   ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
   2900   EXPECT_EQ(params.ssrc,
   2901             media_channel1_->last_sent_data_params().ssrc);
   2902   EXPECT_EQ("foo", media_channel1_->last_sent_data());
   2903 }
   2904 
   2905 // TODO(pthatcher): TestSetReceiver?
   2906