Home | History | Annotate | Download | only in testbed
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/video_engine/test/libvietest/include/tb_video_channel.h"
     12 
     13 #include "testing/gtest/include/gtest/gtest.h"
     14 #include "webrtc/test/channel_transport/include/channel_transport.h"
     15 
     16 TbVideoChannel::TbVideoChannel(TbInterfaces& Engine,
     17                                webrtc::VideoCodecType sendCodec, int width,
     18                                int height, int frameRate, int startBitrate)
     19     : videoChannel(-1),
     20       ViE(Engine) {
     21   EXPECT_EQ(0, ViE.base->CreateChannel(videoChannel));
     22   channel_transport_.reset(new webrtc::test::VideoChannelTransport(
     23       ViE.network, videoChannel));
     24 
     25   webrtc::VideoCodec videoCodec;
     26   memset(&videoCodec, 0, sizeof(webrtc::VideoCodec));
     27   bool sendCodecSet = false;
     28   for (int idx = 0; idx < ViE.codec->NumberOfCodecs(); idx++) {
     29     EXPECT_EQ(0, ViE.codec->GetCodec(idx, videoCodec));
     30     videoCodec.width = width;
     31     videoCodec.height = height;
     32     videoCodec.maxFramerate = frameRate;
     33 
     34     if (videoCodec.codecType == sendCodec && sendCodecSet == false) {
     35       if (videoCodec.codecType != webrtc::kVideoCodecI420) {
     36         videoCodec.startBitrate = startBitrate;
     37         videoCodec.maxBitrate = startBitrate * 3;
     38       }
     39       EXPECT_EQ(0, ViE.codec->SetSendCodec(videoChannel, videoCodec));
     40       sendCodecSet = true;
     41     }
     42     if (videoCodec.codecType == webrtc::kVideoCodecVP8) {
     43       videoCodec.width = 352;
     44       videoCodec.height = 288;
     45     }
     46     EXPECT_EQ(0, ViE.codec->SetReceiveCodec(videoChannel, videoCodec));
     47   }
     48   EXPECT_TRUE(sendCodecSet);
     49 }
     50 
     51 TbVideoChannel::~TbVideoChannel() {
     52   EXPECT_EQ(0, ViE.base->DeleteChannel(videoChannel));
     53 }
     54 
     55 void TbVideoChannel::StartSend(const unsigned short rtp_port,
     56                                const char* ip_address) {
     57   EXPECT_EQ(0, channel_transport_->SetSendDestination(ip_address, rtp_port));
     58   EXPECT_EQ(0, ViE.base->StartSend(videoChannel));
     59 }
     60 
     61 void TbVideoChannel::SetFrameSettings(int width, int height, int frameRate) {
     62   webrtc::VideoCodec videoCodec;
     63   EXPECT_EQ(0, ViE.codec->GetSendCodec(videoChannel, videoCodec));
     64   videoCodec.width = width;
     65   videoCodec.height = height;
     66   videoCodec.maxFramerate = frameRate;
     67 
     68   EXPECT_EQ(0, ViE.codec->SetSendCodec(videoChannel, videoCodec));
     69   EXPECT_EQ(0, ViE.codec->SetReceiveCodec(videoChannel, videoCodec));
     70 }
     71 
     72 void TbVideoChannel::StopSend() {
     73   EXPECT_EQ(0, ViE.base->StopSend(videoChannel));
     74 }
     75 
     76 void TbVideoChannel::StartReceive(unsigned short rtp_port) {
     77   EXPECT_EQ(0, channel_transport_->SetLocalReceiver(rtp_port));
     78   EXPECT_EQ(0, ViE.base->StartReceive(videoChannel));
     79 }
     80 
     81 void TbVideoChannel::StopReceive() {
     82   EXPECT_EQ(0, ViE.base->StopReceive(videoChannel));
     83 }
     84