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/auto_test/primitives/general_primitives.h" 12 13 #include "webrtc/modules/video_capture/include/video_capture_factory.h" 14 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest.h" 15 #include "webrtc/video_engine/test/auto_test/interface/vie_autotest_defines.h" 16 #include "webrtc/video_engine/test/libvietest/include/vie_to_file_renderer.h" 17 18 void FindCaptureDeviceOnSystem(webrtc::ViECapture* capture, 19 char* device_name, 20 unsigned int device_name_length, 21 int* device_id, 22 webrtc::VideoCaptureModule** device_video) { 23 24 bool capture_device_set = false; 25 webrtc::VideoCaptureModule::DeviceInfo *dev_info = 26 webrtc::VideoCaptureFactory::CreateDeviceInfo(0); 27 28 const unsigned int kMaxUniqueIdLength = 256; 29 char unique_id[kMaxUniqueIdLength]; 30 memset(unique_id, 0, kMaxUniqueIdLength); 31 32 for (unsigned int i = 0; i < dev_info->NumberOfDevices(); i++) { 33 EXPECT_EQ(0, dev_info->GetDeviceName(i, device_name, device_name_length, 34 unique_id, kMaxUniqueIdLength)); 35 36 *device_video = webrtc::VideoCaptureFactory::Create(4571, unique_id); 37 EXPECT_TRUE(*device_video != NULL); 38 39 if (*device_video) { 40 (*device_video)->AddRef(); 41 42 int error = capture->AllocateCaptureDevice(**device_video, *device_id); 43 if (error == 0) { 44 ViETest::Log("Using capture device: %s, captureId: %d.", 45 device_name, *device_id); 46 capture_device_set = true; 47 break; 48 } else { 49 (*device_video)->Release(); 50 (*device_video) = NULL; 51 } 52 } 53 } 54 delete dev_info; 55 EXPECT_TRUE(capture_device_set) << "Found no suitable camera on your system."; 56 } 57 58 void RenderInWindow(webrtc::ViERender* video_render_interface, 59 int frame_provider_id, 60 void* os_window, 61 float z_index) { 62 EXPECT_EQ(0, 63 video_render_interface->AddRenderer(frame_provider_id, os_window, 64 z_index, 0.0, 0.0, 1.0, 1.0)); 65 EXPECT_EQ(0, video_render_interface->StartRender(frame_provider_id)); 66 } 67 68 void RenderToFile(webrtc::ViERender* renderer_interface, 69 int frame_provider_id, 70 ViEToFileRenderer *to_file_renderer) { 71 EXPECT_EQ(0, renderer_interface->AddRenderer( 72 frame_provider_id, webrtc::kVideoI420, to_file_renderer)); 73 EXPECT_EQ(0, renderer_interface->StartRender(frame_provider_id)); 74 } 75 76 void ConfigureRtpRtcp(webrtc::ViERTP_RTCP* rtcp_interface, 77 ProtectionMethod protection_method, 78 int video_channel) { 79 EXPECT_EQ(0, rtcp_interface->SetRTCPStatus(video_channel, 80 webrtc::kRtcpCompound_RFC4585)); 81 EXPECT_EQ(0, rtcp_interface->SetKeyFrameRequestMethod( 82 video_channel, webrtc::kViEKeyFrameRequestPliRtcp)); 83 EXPECT_EQ(0, rtcp_interface->SetTMMBRStatus(video_channel, true)); 84 switch (protection_method) { 85 case kNack: 86 EXPECT_EQ(0, rtcp_interface->SetNACKStatus(video_channel, true)); 87 break; 88 case kHybridNackFec: 89 const int kRedPayloadType = 96; 90 const int kUlpFecPayloadType = 97; 91 EXPECT_EQ(0, rtcp_interface->SetHybridNACKFECStatus(video_channel, 92 true, 93 kRedPayloadType, 94 kUlpFecPayloadType)); 95 break; 96 } 97 } 98 99 bool FindSpecificCodec(webrtc::VideoCodecType of_type, 100 webrtc::ViECodec* codec_interface, 101 webrtc::VideoCodec* result) { 102 103 memset(result, 0, sizeof(webrtc::VideoCodec)); 104 105 for (int i = 0; i < codec_interface->NumberOfCodecs(); i++) { 106 webrtc::VideoCodec codec; 107 memset(&codec, 0, sizeof(webrtc::VideoCodec)); 108 if (codec_interface->GetCodec(i, codec) != 0) { 109 return false; 110 } 111 if (codec.codecType == of_type) { 112 // Done 113 *result = codec; 114 return true; 115 } 116 } 117 // Didn't find it 118 return false; 119 } 120 121 void SetSuitableResolution(webrtc::VideoCodec* video_codec, 122 int forced_codec_width, 123 int forced_codec_height) { 124 if (forced_codec_width != kDoNotForceResolution && 125 forced_codec_height != kDoNotForceResolution) { 126 video_codec->width = forced_codec_width; 127 video_codec->height = forced_codec_height; 128 } else if (video_codec->codecType == webrtc::kVideoCodecI420) { 129 // I420 is very bandwidth heavy, so limit it here. 130 video_codec->width = 176; 131 video_codec->height = 144; 132 } else { 133 // Otherwise go with 640x480. 134 video_codec->width = 640; 135 video_codec->height = 480; 136 } 137 } 138