pbos@webrtc.org | f577ae9 | 2014-03-19 08:43:57 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | #include "webrtc/test/encoder_settings.h" |
| 11 | |
| 12 | #include <assert.h> |
| 13 | #include <string.h> |
| 14 | |
| 15 | #include "webrtc/video_engine/vie_defines.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | namespace test { |
| 19 | VideoSendStream::Config::EncoderSettings CreateEncoderSettings( |
| 20 | VideoEncoder* encoder, |
| 21 | const char* payload_name, |
| 22 | int payload_type, |
| 23 | size_t num_streams) { |
| 24 | assert(num_streams > 0); |
| 25 | |
| 26 | // Add more streams to the settings above with reasonable values if required. |
| 27 | static const size_t kNumSettings = 3; |
| 28 | assert(num_streams <= kNumSettings); |
| 29 | |
| 30 | VideoStream stream_settings[kNumSettings]; |
| 31 | |
| 32 | stream_settings[0].width = 320; |
| 33 | stream_settings[0].height = 180; |
| 34 | stream_settings[0].max_framerate = 30; |
| 35 | stream_settings[0].min_bitrate_bps = 50000; |
| 36 | stream_settings[0].target_bitrate_bps = stream_settings[0].max_bitrate_bps = |
| 37 | 150000; |
| 38 | stream_settings[0].max_qp = 56; |
| 39 | |
| 40 | stream_settings[1].width = 640; |
| 41 | stream_settings[1].height = 360; |
| 42 | stream_settings[1].max_framerate = 30; |
| 43 | stream_settings[1].min_bitrate_bps = 200000; |
| 44 | stream_settings[1].target_bitrate_bps = stream_settings[1].max_bitrate_bps = |
| 45 | 450000; |
| 46 | stream_settings[1].max_qp = 56; |
| 47 | |
| 48 | stream_settings[2].width = 1280; |
| 49 | stream_settings[2].height = 720; |
| 50 | stream_settings[2].max_framerate = 30; |
| 51 | stream_settings[2].min_bitrate_bps = 700000; |
| 52 | stream_settings[2].target_bitrate_bps = stream_settings[2].max_bitrate_bps = |
| 53 | 1500000; |
| 54 | stream_settings[2].max_qp = 56; |
| 55 | |
| 56 | VideoSendStream::Config::EncoderSettings settings; |
| 57 | |
| 58 | for (size_t i = 0; i < num_streams; ++i) |
| 59 | settings.streams.push_back(stream_settings[i]); |
| 60 | |
| 61 | settings.encoder = encoder; |
| 62 | settings.payload_name = payload_name; |
| 63 | settings.payload_type = payload_type; |
| 64 | return settings; |
| 65 | } |
| 66 | |
| 67 | VideoCodec CreateDecoderVideoCodec( |
| 68 | const VideoSendStream::Config::EncoderSettings& settings) { |
| 69 | assert(settings.streams.size() > 0); |
| 70 | VideoCodec codec; |
| 71 | memset(&codec, 0, sizeof(codec)); |
| 72 | |
| 73 | codec.plType = settings.payload_type; |
| 74 | strcpy(codec.plName, settings.payload_name.c_str()); |
| 75 | codec.codecType = |
| 76 | (settings.payload_name == "VP8" ? kVideoCodecVP8 : kVideoCodecGeneric); |
| 77 | |
| 78 | if (codec.codecType == kVideoCodecVP8) { |
| 79 | codec.codecSpecific.VP8.resilience = kResilientStream; |
| 80 | codec.codecSpecific.VP8.numberOfTemporalLayers = 1; |
| 81 | codec.codecSpecific.VP8.denoisingOn = true; |
| 82 | codec.codecSpecific.VP8.errorConcealmentOn = false; |
| 83 | codec.codecSpecific.VP8.automaticResizeOn = false; |
| 84 | codec.codecSpecific.VP8.frameDroppingOn = true; |
| 85 | codec.codecSpecific.VP8.keyFrameInterval = 3000; |
| 86 | } |
| 87 | |
| 88 | codec.minBitrate = settings.streams[0].min_bitrate_bps / 1000; |
| 89 | for (size_t i = 0; i < settings.streams.size(); ++i) { |
| 90 | const VideoStream& stream = settings.streams[i]; |
| 91 | if (stream.width > codec.width) |
| 92 | codec.width = static_cast<unsigned short>(stream.width); |
| 93 | if (stream.height > codec.height) |
| 94 | codec.height = static_cast<unsigned short>(stream.height); |
| 95 | if (static_cast<unsigned int>(stream.min_bitrate_bps / 1000) < |
| 96 | codec.minBitrate) |
| 97 | codec.minBitrate = |
| 98 | static_cast<unsigned int>(stream.min_bitrate_bps / 1000); |
| 99 | codec.maxBitrate += stream.max_bitrate_bps / 1000; |
| 100 | if (static_cast<unsigned int>(stream.max_qp) > codec.qpMax) |
| 101 | codec.qpMax = static_cast<unsigned int>(stream.max_qp); |
| 102 | } |
| 103 | |
| 104 | if (codec.minBitrate < kViEMinCodecBitrate) |
| 105 | codec.minBitrate = kViEMinCodecBitrate; |
| 106 | if (codec.maxBitrate < kViEMinCodecBitrate) |
| 107 | codec.maxBitrate = kViEMinCodecBitrate; |
| 108 | |
| 109 | codec.startBitrate = 300; |
| 110 | |
| 111 | if (codec.startBitrate < codec.minBitrate) |
| 112 | codec.startBitrate = codec.minBitrate; |
| 113 | if (codec.startBitrate > codec.maxBitrate) |
| 114 | codec.startBitrate = codec.maxBitrate; |
| 115 | |
| 116 | return codec; |
| 117 | } |
| 118 | |
| 119 | } // namespace test |
| 120 | } // namespace webrtc |