| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 const float kSpatialLow = 0.01f; | 25 const float kSpatialLow = 0.01f; |
| 26 const float kSpatialMedium = 0.03f; | 26 const float kSpatialMedium = 0.03f; |
| 27 const float kSpatialHigh = 0.1f; | 27 const float kSpatialHigh = 0.1f; |
| 28 const float kTemporalLow = 0.01f; | 28 const float kTemporalLow = 0.01f; |
| 29 const float kTemporalMedium = 0.06f; | 29 const float kTemporalMedium = 0.06f; |
| 30 const float kTemporalHigh = 0.1f; | 30 const float kTemporalHigh = 0.1f; |
| 31 | 31 |
| 32 class QmSelectTest : public ::testing::Test { | 32 class QmSelectTest : public ::testing::Test { |
| 33 protected: | 33 protected: |
| 34 QmSelectTest() | 34 QmSelectTest() |
| 35 : qm_resolution_(new VCMQmResolution()), | 35 : qm_resolution_(new VCMQmResolution()), |
| 36 content_metrics_(new VideoContentMetrics()), | 36 content_metrics_(new VideoContentMetrics()), |
| 37 qm_scale_(NULL) { | 37 qm_scale_(NULL) {} |
| 38 } | |
| 39 VCMQmResolution* qm_resolution_; | 38 VCMQmResolution* qm_resolution_; |
| 40 VideoContentMetrics* content_metrics_; | 39 VideoContentMetrics* content_metrics_; |
| 41 VCMResolutionScale* qm_scale_; | 40 VCMResolutionScale* qm_scale_; |
| 42 | 41 |
| 43 void InitQmNativeData(float initial_bit_rate, | 42 void InitQmNativeData(float initial_bit_rate, |
| 44 int user_frame_rate, | 43 int user_frame_rate, |
| 45 int native_width, | 44 int native_width, |
| 46 int native_height, | 45 int native_height, |
| 47 int num_layers); | 46 int num_layers); |
| 48 | 47 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 EXPECT_EQ(-4, qm_resolution_->Initialize(1000, 30, 0, 480, 1)); | 79 EXPECT_EQ(-4, qm_resolution_->Initialize(1000, 30, 0, 480, 1)); |
| 81 | 80 |
| 82 // Expect uninitialized error.: No valid initialization before selection. | 81 // Expect uninitialized error.: No valid initialization before selection. |
| 83 EXPECT_EQ(-7, qm_resolution_->SelectResolution(&qm_scale_)); | 82 EXPECT_EQ(-7, qm_resolution_->SelectResolution(&qm_scale_)); |
| 84 | 83 |
| 85 VideoContentMetrics* content_metrics = NULL; | 84 VideoContentMetrics* content_metrics = NULL; |
| 86 EXPECT_EQ(0, qm_resolution_->Initialize(1000, 30, 640, 480, 1)); | 85 EXPECT_EQ(0, qm_resolution_->Initialize(1000, 30, 640, 480, 1)); |
| 87 qm_resolution_->UpdateContent(content_metrics); | 86 qm_resolution_->UpdateContent(content_metrics); |
| 88 // Content metrics are NULL: Expect success and no down-sampling action. | 87 // Content metrics are NULL: Expect success and no down-sampling action. |
| 89 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 88 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 90 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0, 1.0, 1.0, 640, 480, | 89 EXPECT_TRUE( |
| 91 30.0f)); | 90 IsSelectedActionCorrect(qm_scale_, 1.0, 1.0, 1.0, 640, 480, 30.0f)); |
| 92 } | 91 } |
| 93 | 92 |
| 94 // TODO(marpan): Add a test for number of temporal layers > 1. | 93 // TODO(marpan): Add a test for number of temporal layers > 1. |
| 95 | 94 |
| 96 // No down-sampling action at high rates. | 95 // No down-sampling action at high rates. |
| 97 TEST_F(QmSelectTest, NoActionHighRate) { | 96 TEST_F(QmSelectTest, NoActionHighRate) { |
| 98 // Initialize with bitrate, frame rate, native system width/height, and | 97 // Initialize with bitrate, frame rate, native system width/height, and |
| 99 // number of temporal layers. | 98 // number of temporal layers. |
| 100 InitQmNativeData(800, 30, 640, 480, 1); | 99 InitQmNativeData(800, 30, 640, 480, 1); |
| 101 | 100 |
| 102 // Update with encoder frame size. | 101 // Update with encoder frame size. |
| 103 uint16_t codec_width = 640; | 102 uint16_t codec_width = 640; |
| 104 uint16_t codec_height = 480; | 103 uint16_t codec_height = 480; |
| 105 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 104 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 106 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 105 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 107 | 106 |
| 108 // Update rates for a sequence of intervals. | 107 // Update rates for a sequence of intervals. |
| 109 int target_rate[] = {800, 800, 800}; | 108 int target_rate[] = {800, 800, 800}; |
| 110 int encoder_sent_rate[] = {800, 800, 800}; | 109 int encoder_sent_rate[] = {800, 800, 800}; |
| 111 int incoming_frame_rate[] = {30, 30, 30}; | 110 int incoming_frame_rate[] = {30, 30, 30}; |
| 112 uint8_t fraction_lost[] = {10, 10, 10}; | 111 uint8_t fraction_lost[] = {10, 10, 10}; |
| 113 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 112 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 114 fraction_lost, 3); | 113 fraction_lost, 3); |
| 115 | 114 |
| 116 // Update content: motion level, and 3 spatial prediction errors. | 115 // Update content: motion level, and 3 spatial prediction errors. |
| 117 UpdateQmContentData(kTemporalLow, kSpatialLow, kSpatialLow, kSpatialLow); | 116 UpdateQmContentData(kTemporalLow, kSpatialLow, kSpatialLow, kSpatialLow); |
| 118 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 117 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 119 EXPECT_EQ(0, qm_resolution_->ComputeContentClass()); | 118 EXPECT_EQ(0, qm_resolution_->ComputeContentClass()); |
| 120 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 119 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 121 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 120 EXPECT_TRUE( |
| 122 30.0f)); | 121 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 30.0f)); |
| 123 } | 122 } |
| 124 | 123 |
| 125 // Rate is well below transition, down-sampling action is taken, | 124 // Rate is well below transition, down-sampling action is taken, |
| 126 // depending on the content state. | 125 // depending on the content state. |
| 127 TEST_F(QmSelectTest, DownActionLowRate) { | 126 TEST_F(QmSelectTest, DownActionLowRate) { |
| 128 // Initialize with bitrate, frame rate, native system width/height, and | 127 // Initialize with bitrate, frame rate, native system width/height, and |
| 129 // number of temporal layers. | 128 // number of temporal layers. |
| 130 InitQmNativeData(50, 30, 640, 480, 1); | 129 InitQmNativeData(50, 30, 640, 480, 1); |
| 131 | 130 |
| 132 // Update with encoder frame size. | 131 // Update with encoder frame size. |
| 133 uint16_t codec_width = 640; | 132 uint16_t codec_width = 640; |
| 134 uint16_t codec_height = 480; | 133 uint16_t codec_height = 480; |
| 135 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 134 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 136 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 135 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 137 | 136 |
| 138 // Update rates for a sequence of intervals. | 137 // Update rates for a sequence of intervals. |
| 139 int target_rate[] = {50, 50, 50}; | 138 int target_rate[] = {50, 50, 50}; |
| 140 int encoder_sent_rate[] = {50, 50, 50}; | 139 int encoder_sent_rate[] = {50, 50, 50}; |
| 141 int incoming_frame_rate[] = {30, 30, 30}; | 140 int incoming_frame_rate[] = {30, 30, 30}; |
| 142 uint8_t fraction_lost[] = {10, 10, 10}; | 141 uint8_t fraction_lost[] = {10, 10, 10}; |
| 143 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 142 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 144 fraction_lost, 3); | 143 fraction_lost, 3); |
| 145 | 144 |
| 146 // Update content: motion level, and 3 spatial prediction errors. | 145 // Update content: motion level, and 3 spatial prediction errors. |
| 147 // High motion, low spatial: 2x2 spatial expected. | 146 // High motion, low spatial: 2x2 spatial expected. |
| 148 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 147 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 149 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 148 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 150 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 149 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 151 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 150 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 152 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 151 EXPECT_TRUE( |
| 153 30.0f)); | 152 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 154 | 153 |
| 155 qm_resolution_->ResetDownSamplingState(); | 154 qm_resolution_->ResetDownSamplingState(); |
| 156 // Low motion, low spatial: 2/3 temporal is expected. | 155 // Low motion, low spatial: 2/3 temporal is expected. |
| 157 UpdateQmContentData(kTemporalLow, kSpatialLow, kSpatialLow, kSpatialLow); | 156 UpdateQmContentData(kTemporalLow, kSpatialLow, kSpatialLow, kSpatialLow); |
| 158 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 157 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 159 EXPECT_EQ(0, qm_resolution_->ComputeContentClass()); | 158 EXPECT_EQ(0, qm_resolution_->ComputeContentClass()); |
| 160 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, | 159 EXPECT_TRUE( |
| 161 20.5f)); | 160 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, 20.5f)); |
| 162 | 161 |
| 163 qm_resolution_->ResetDownSamplingState(); | 162 qm_resolution_->ResetDownSamplingState(); |
| 164 // Medium motion, low spatial: 2x2 spatial expected. | 163 // Medium motion, low spatial: 2x2 spatial expected. |
| 165 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); | 164 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); |
| 166 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 165 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 167 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); | 166 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); |
| 168 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 167 EXPECT_TRUE( |
| 169 30.0f)); | 168 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 170 | 169 |
| 171 qm_resolution_->ResetDownSamplingState(); | 170 qm_resolution_->ResetDownSamplingState(); |
| 172 // High motion, high spatial: 2/3 temporal expected. | 171 // High motion, high spatial: 2/3 temporal expected. |
| 173 UpdateQmContentData(kTemporalHigh, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 172 UpdateQmContentData(kTemporalHigh, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 174 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 173 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 175 EXPECT_EQ(4, qm_resolution_->ComputeContentClass()); | 174 EXPECT_EQ(4, qm_resolution_->ComputeContentClass()); |
| 176 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, | 175 EXPECT_TRUE( |
| 177 20.5f)); | 176 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, 20.5f)); |
| 178 | 177 |
| 179 qm_resolution_->ResetDownSamplingState(); | 178 qm_resolution_->ResetDownSamplingState(); |
| 180 // Low motion, high spatial: 1/2 temporal expected. | 179 // Low motion, high spatial: 1/2 temporal expected. |
| 181 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 180 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 182 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 181 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 183 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 182 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 184 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, | 183 EXPECT_TRUE( |
| 185 15.5f)); | 184 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, 15.5f)); |
| 186 | 185 |
| 187 qm_resolution_->ResetDownSamplingState(); | 186 qm_resolution_->ResetDownSamplingState(); |
| 188 // Medium motion, high spatial: 1/2 temporal expected. | 187 // Medium motion, high spatial: 1/2 temporal expected. |
| 189 UpdateQmContentData(kTemporalMedium, kSpatialHigh, kSpatialHigh, | 188 UpdateQmContentData(kTemporalMedium, kSpatialHigh, kSpatialHigh, |
| 190 kSpatialHigh); | 189 kSpatialHigh); |
| 191 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 190 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 192 EXPECT_EQ(7, qm_resolution_->ComputeContentClass()); | 191 EXPECT_EQ(7, qm_resolution_->ComputeContentClass()); |
| 193 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, | 192 EXPECT_TRUE( |
| 194 15.5f)); | 193 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, 15.5f)); |
| 195 | 194 |
| 196 qm_resolution_->ResetDownSamplingState(); | 195 qm_resolution_->ResetDownSamplingState(); |
| 197 // High motion, medium spatial: 2x2 spatial expected. | 196 // High motion, medium spatial: 2x2 spatial expected. |
| 198 UpdateQmContentData(kTemporalHigh, kSpatialMedium, kSpatialMedium, | 197 UpdateQmContentData(kTemporalHigh, kSpatialMedium, kSpatialMedium, |
| 199 kSpatialMedium); | 198 kSpatialMedium); |
| 200 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 199 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 201 EXPECT_EQ(5, qm_resolution_->ComputeContentClass()); | 200 EXPECT_EQ(5, qm_resolution_->ComputeContentClass()); |
| 202 // Target frame rate for frame dropper should be the same as previous == 15. | 201 // Target frame rate for frame dropper should be the same as previous == 15. |
| 203 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 202 EXPECT_TRUE( |
| 204 30.0f)); | 203 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 205 | 204 |
| 206 qm_resolution_->ResetDownSamplingState(); | 205 qm_resolution_->ResetDownSamplingState(); |
| 207 // Low motion, medium spatial: high frame rate, so 1/2 temporal expected. | 206 // Low motion, medium spatial: high frame rate, so 1/2 temporal expected. |
| 208 UpdateQmContentData(kTemporalLow, kSpatialMedium, kSpatialMedium, | 207 UpdateQmContentData(kTemporalLow, kSpatialMedium, kSpatialMedium, |
| 209 kSpatialMedium); | 208 kSpatialMedium); |
| 210 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 209 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 211 EXPECT_EQ(2, qm_resolution_->ComputeContentClass()); | 210 EXPECT_EQ(2, qm_resolution_->ComputeContentClass()); |
| 212 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, | 211 EXPECT_TRUE( |
| 213 15.5f)); | 212 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, 15.5f)); |
| 214 | 213 |
| 215 qm_resolution_->ResetDownSamplingState(); | 214 qm_resolution_->ResetDownSamplingState(); |
| 216 // Medium motion, medium spatial: high frame rate, so 2/3 temporal expected. | 215 // Medium motion, medium spatial: high frame rate, so 2/3 temporal expected. |
| 217 UpdateQmContentData(kTemporalMedium, kSpatialMedium, kSpatialMedium, | 216 UpdateQmContentData(kTemporalMedium, kSpatialMedium, kSpatialMedium, |
| 218 kSpatialMedium); | 217 kSpatialMedium); |
| 219 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 218 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 220 EXPECT_EQ(8, qm_resolution_->ComputeContentClass()); | 219 EXPECT_EQ(8, qm_resolution_->ComputeContentClass()); |
| 221 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, | 220 EXPECT_TRUE( |
| 222 20.5f)); | 221 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, 20.5f)); |
| 223 } | 222 } |
| 224 | 223 |
| 225 // Rate mis-match is high, and we have over-shooting. | 224 // Rate mis-match is high, and we have over-shooting. |
| 226 // since target rate is below max for down-sampling, down-sampling is selected. | 225 // since target rate is below max for down-sampling, down-sampling is selected. |
| 227 TEST_F(QmSelectTest, DownActionHighRateMMOvershoot) { | 226 TEST_F(QmSelectTest, DownActionHighRateMMOvershoot) { |
| 228 // Initialize with bitrate, frame rate, native system width/height, and | 227 // Initialize with bitrate, frame rate, native system width/height, and |
| 229 // number of temporal layers. | 228 // number of temporal layers. |
| 230 InitQmNativeData(300, 30, 640, 480, 1); | 229 InitQmNativeData(300, 30, 640, 480, 1); |
| 231 | 230 |
| 232 // Update with encoder frame size. | 231 // Update with encoder frame size. |
| 233 uint16_t codec_width = 640; | 232 uint16_t codec_width = 640; |
| 234 uint16_t codec_height = 480; | 233 uint16_t codec_height = 480; |
| 235 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 234 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 236 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 235 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 237 | 236 |
| 238 // Update rates for a sequence of intervals. | 237 // Update rates for a sequence of intervals. |
| 239 int target_rate[] = {300, 300, 300}; | 238 int target_rate[] = {300, 300, 300}; |
| 240 int encoder_sent_rate[] = {900, 900, 900}; | 239 int encoder_sent_rate[] = {900, 900, 900}; |
| 241 int incoming_frame_rate[] = {30, 30, 30}; | 240 int incoming_frame_rate[] = {30, 30, 30}; |
| 242 uint8_t fraction_lost[] = {10, 10, 10}; | 241 uint8_t fraction_lost[] = {10, 10, 10}; |
| 243 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 242 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 244 fraction_lost, 3); | 243 fraction_lost, 3); |
| 245 | 244 |
| 246 // Update content: motion level, and 3 spatial prediction errors. | 245 // Update content: motion level, and 3 spatial prediction errors. |
| 247 // High motion, low spatial. | 246 // High motion, low spatial. |
| 248 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 247 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 249 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 248 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 250 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 249 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 251 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); | 250 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); |
| 252 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, | 251 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, 1.0f, |
| 253 1.0f, 480, 360, 30.0f)); | 252 480, 360, 30.0f)); |
| 254 | 253 |
| 255 qm_resolution_->ResetDownSamplingState(); | 254 qm_resolution_->ResetDownSamplingState(); |
| 256 // Low motion, high spatial | 255 // Low motion, high spatial |
| 257 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 256 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 258 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 257 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 259 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 258 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 260 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, | 259 EXPECT_TRUE( |
| 261 20.5f)); | 260 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, 20.5f)); |
| 262 } | 261 } |
| 263 | 262 |
| 264 // Rate mis-match is high, target rate is below max for down-sampling, | 263 // Rate mis-match is high, target rate is below max for down-sampling, |
| 265 // but since we have consistent under-shooting, no down-sampling action. | 264 // but since we have consistent under-shooting, no down-sampling action. |
| 266 TEST_F(QmSelectTest, NoActionHighRateMMUndershoot) { | 265 TEST_F(QmSelectTest, NoActionHighRateMMUndershoot) { |
| 267 // Initialize with bitrate, frame rate, native system width/height, and | 266 // Initialize with bitrate, frame rate, native system width/height, and |
| 268 // number of temporal layers. | 267 // number of temporal layers. |
| 269 InitQmNativeData(300, 30, 640, 480, 1); | 268 InitQmNativeData(300, 30, 640, 480, 1); |
| 270 | 269 |
| 271 // Update with encoder frame size. | 270 // Update with encoder frame size. |
| 272 uint16_t codec_width = 640; | 271 uint16_t codec_width = 640; |
| 273 uint16_t codec_height = 480; | 272 uint16_t codec_height = 480; |
| 274 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 273 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 275 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 274 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 276 | 275 |
| 277 // Update rates for a sequence of intervals. | 276 // Update rates for a sequence of intervals. |
| 278 int target_rate[] = {300, 300, 300}; | 277 int target_rate[] = {300, 300, 300}; |
| 279 int encoder_sent_rate[] = {100, 100, 100}; | 278 int encoder_sent_rate[] = {100, 100, 100}; |
| 280 int incoming_frame_rate[] = {30, 30, 30}; | 279 int incoming_frame_rate[] = {30, 30, 30}; |
| 281 uint8_t fraction_lost[] = {10, 10, 10}; | 280 uint8_t fraction_lost[] = {10, 10, 10}; |
| 282 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 281 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 283 fraction_lost, 3); | 282 fraction_lost, 3); |
| 284 | 283 |
| 285 // Update content: motion level, and 3 spatial prediction errors. | 284 // Update content: motion level, and 3 spatial prediction errors. |
| 286 // High motion, low spatial. | 285 // High motion, low spatial. |
| 287 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 286 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 288 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 287 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 289 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 288 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 290 EXPECT_EQ(kEasyEncoding, qm_resolution_->GetEncoderState()); | 289 EXPECT_EQ(kEasyEncoding, qm_resolution_->GetEncoderState()); |
| 291 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 290 EXPECT_TRUE( |
| 292 30.0f)); | 291 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 30.0f)); |
| 293 | 292 |
| 294 qm_resolution_->ResetDownSamplingState(); | 293 qm_resolution_->ResetDownSamplingState(); |
| 295 // Low motion, high spatial | 294 // Low motion, high spatial |
| 296 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 295 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 297 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 296 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 298 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 297 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 299 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 298 EXPECT_TRUE( |
| 300 30.0f)); | 299 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 30.0f)); |
| 301 } | 300 } |
| 302 | 301 |
| 303 // Buffer is underflowing, and target rate is below max for down-sampling, | 302 // Buffer is underflowing, and target rate is below max for down-sampling, |
| 304 // so action is taken. | 303 // so action is taken. |
| 305 TEST_F(QmSelectTest, DownActionBufferUnderflow) { | 304 TEST_F(QmSelectTest, DownActionBufferUnderflow) { |
| 306 // Initialize with bitrate, frame rate, native system width/height, and | 305 // Initialize with bitrate, frame rate, native system width/height, and |
| 307 // number of temporal layers. | 306 // number of temporal layers. |
| 308 InitQmNativeData(300, 30, 640, 480, 1); | 307 InitQmNativeData(300, 30, 640, 480, 1); |
| 309 | 308 |
| 310 // Update with encoder frame size. | 309 // Update with encoder frame size. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 325 uint8_t fraction_lost[] = {10, 10, 10}; | 324 uint8_t fraction_lost[] = {10, 10, 10}; |
| 326 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 325 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 327 fraction_lost, 3); | 326 fraction_lost, 3); |
| 328 | 327 |
| 329 // Update content: motion level, and 3 spatial prediction errors. | 328 // Update content: motion level, and 3 spatial prediction errors. |
| 330 // High motion, low spatial. | 329 // High motion, low spatial. |
| 331 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 330 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 332 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 331 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 333 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 332 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 334 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); | 333 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); |
| 335 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, | 334 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, 1.0f, |
| 336 1.0f, 480, 360, 30.0f)); | 335 480, 360, 30.0f)); |
| 337 | 336 |
| 338 qm_resolution_->ResetDownSamplingState(); | 337 qm_resolution_->ResetDownSamplingState(); |
| 339 // Low motion, high spatial | 338 // Low motion, high spatial |
| 340 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 339 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 341 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 340 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 342 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 341 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 343 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, | 342 EXPECT_TRUE( |
| 344 20.5f)); | 343 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 640, 480, 20.5f)); |
| 345 } | 344 } |
| 346 | 345 |
| 347 // Target rate is below max for down-sampling, but buffer level is stable, | 346 // Target rate is below max for down-sampling, but buffer level is stable, |
| 348 // so no action is taken. | 347 // so no action is taken. |
| 349 TEST_F(QmSelectTest, NoActionBufferStable) { | 348 TEST_F(QmSelectTest, NoActionBufferStable) { |
| 350 // Initialize with bitrate, frame rate, native system width/height, and | 349 // Initialize with bitrate, frame rate, native system width/height, and |
| 351 // number of temporal layers. | 350 // number of temporal layers. |
| 352 InitQmNativeData(350, 30, 640, 480, 1); | 351 InitQmNativeData(350, 30, 640, 480, 1); |
| 353 | 352 |
| 354 // Update with encoder frame size. | 353 // Update with encoder frame size. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 369 uint8_t fraction_lost[] = {10, 10, 10}; | 368 uint8_t fraction_lost[] = {10, 10, 10}; |
| 370 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 369 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 371 fraction_lost, 3); | 370 fraction_lost, 3); |
| 372 | 371 |
| 373 // Update content: motion level, and 3 spatial prediction errors. | 372 // Update content: motion level, and 3 spatial prediction errors. |
| 374 // High motion, low spatial. | 373 // High motion, low spatial. |
| 375 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 374 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 376 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 375 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 377 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 376 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 378 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 377 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 379 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 378 EXPECT_TRUE( |
| 380 30.0f)); | 379 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 30.0f)); |
| 381 | 380 |
| 382 qm_resolution_->ResetDownSamplingState(); | 381 qm_resolution_->ResetDownSamplingState(); |
| 383 // Low motion, high spatial | 382 // Low motion, high spatial |
| 384 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 383 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 385 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 384 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 386 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 385 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 387 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 386 EXPECT_TRUE( |
| 388 30.0f)); | 387 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 30.0f)); |
| 389 } | 388 } |
| 390 | 389 |
| 391 // Very low rate, but no spatial down-sampling below some size (QCIF). | 390 // Very low rate, but no spatial down-sampling below some size (QCIF). |
| 392 TEST_F(QmSelectTest, LimitDownSpatialAction) { | 391 TEST_F(QmSelectTest, LimitDownSpatialAction) { |
| 393 // Initialize with bitrate, frame rate, native system width/height, and | 392 // Initialize with bitrate, frame rate, native system width/height, and |
| 394 // number of temporal layers. | 393 // number of temporal layers. |
| 395 InitQmNativeData(10, 30, 176, 144, 1); | 394 InitQmNativeData(10, 30, 176, 144, 1); |
| 396 | 395 |
| 397 // Update with encoder frame size. | 396 // Update with encoder frame size. |
| 398 uint16_t codec_width = 176; | 397 uint16_t codec_width = 176; |
| 399 uint16_t codec_height = 144; | 398 uint16_t codec_height = 144; |
| 400 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 399 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 401 EXPECT_EQ(0, qm_resolution_->GetImageType(codec_width, codec_height)); | 400 EXPECT_EQ(0, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 402 | 401 |
| 403 // Update rates for a sequence of intervals. | 402 // Update rates for a sequence of intervals. |
| 404 int target_rate[] = {10, 10, 10}; | 403 int target_rate[] = {10, 10, 10}; |
| 405 int encoder_sent_rate[] = {10, 10, 10}; | 404 int encoder_sent_rate[] = {10, 10, 10}; |
| 406 int incoming_frame_rate[] = {30, 30, 30}; | 405 int incoming_frame_rate[] = {30, 30, 30}; |
| 407 uint8_t fraction_lost[] = {10, 10, 10}; | 406 uint8_t fraction_lost[] = {10, 10, 10}; |
| 408 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 407 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 409 fraction_lost, 3); | 408 fraction_lost, 3); |
| 410 | 409 |
| 411 // Update content: motion level, and 3 spatial prediction errors. | 410 // Update content: motion level, and 3 spatial prediction errors. |
| 412 // High motion, low spatial. | 411 // High motion, low spatial. |
| 413 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 412 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 414 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 413 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 415 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 414 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 416 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 415 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 417 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 176, 144, | 416 EXPECT_TRUE( |
| 418 30.0f)); | 417 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 176, 144, 30.0f)); |
| 419 } | 418 } |
| 420 | 419 |
| 421 // Very low rate, but no frame reduction below some frame_rate (8fps). | 420 // Very low rate, but no frame reduction below some frame_rate (8fps). |
| 422 TEST_F(QmSelectTest, LimitDownTemporalAction) { | 421 TEST_F(QmSelectTest, LimitDownTemporalAction) { |
| 423 // Initialize with bitrate, frame rate, native system width/height, and | 422 // Initialize with bitrate, frame rate, native system width/height, and |
| 424 // number of temporal layers. | 423 // number of temporal layers. |
| 425 InitQmNativeData(10, 8, 640, 480, 1); | 424 InitQmNativeData(10, 8, 640, 480, 1); |
| 426 | 425 |
| 427 // Update with encoder frame size. | 426 // Update with encoder frame size. |
| 428 uint16_t codec_width = 640; | 427 uint16_t codec_width = 640; |
| 429 uint16_t codec_height = 480; | 428 uint16_t codec_height = 480; |
| 430 qm_resolution_->UpdateCodecParameters(8.0f, codec_width, codec_height); | 429 qm_resolution_->UpdateCodecParameters(8.0f, codec_width, codec_height); |
| 431 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 430 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 432 | 431 |
| 433 // Update rates for a sequence of intervals. | 432 // Update rates for a sequence of intervals. |
| 434 int target_rate[] = {10, 10, 10}; | 433 int target_rate[] = {10, 10, 10}; |
| 435 int encoder_sent_rate[] = {10, 10, 10}; | 434 int encoder_sent_rate[] = {10, 10, 10}; |
| 436 int incoming_frame_rate[] = {8, 8, 8}; | 435 int incoming_frame_rate[] = {8, 8, 8}; |
| 437 uint8_t fraction_lost[] = {10, 10, 10}; | 436 uint8_t fraction_lost[] = {10, 10, 10}; |
| 438 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 437 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 439 fraction_lost, 3); | 438 fraction_lost, 3); |
| 440 | 439 |
| 441 // Update content: motion level, and 3 spatial prediction errors. | 440 // Update content: motion level, and 3 spatial prediction errors. |
| 442 // Low motion, medium spatial. | 441 // Low motion, medium spatial. |
| 443 UpdateQmContentData(kTemporalLow, kSpatialMedium, kSpatialMedium, | 442 UpdateQmContentData(kTemporalLow, kSpatialMedium, kSpatialMedium, |
| 444 kSpatialMedium); | 443 kSpatialMedium); |
| 445 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 444 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 446 EXPECT_EQ(2, qm_resolution_->ComputeContentClass()); | 445 EXPECT_EQ(2, qm_resolution_->ComputeContentClass()); |
| 447 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 446 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 448 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 447 EXPECT_TRUE( |
| 449 8.0f)); | 448 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 8.0f)); |
| 450 } | 449 } |
| 451 | 450 |
| 452 // Two stages: spatial down-sample and then back up spatially, | 451 // Two stages: spatial down-sample and then back up spatially, |
| 453 // as rate as increased. | 452 // as rate as increased. |
| 454 TEST_F(QmSelectTest, 2StageDownSpatialUpSpatial) { | 453 TEST_F(QmSelectTest, 2StageDownSpatialUpSpatial) { |
| 455 // Initialize with bitrate, frame rate, native system width/height, and | 454 // Initialize with bitrate, frame rate, native system width/height, and |
| 456 // number of temporal layers. | 455 // number of temporal layers. |
| 457 InitQmNativeData(50, 30, 640, 480, 1); | 456 InitQmNativeData(50, 30, 640, 480, 1); |
| 458 | 457 |
| 459 // Update with encoder frame size. | 458 // Update with encoder frame size. |
| 460 uint16_t codec_width = 640; | 459 uint16_t codec_width = 640; |
| 461 uint16_t codec_height = 480; | 460 uint16_t codec_height = 480; |
| 462 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 461 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 463 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 462 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 464 | 463 |
| 465 // Update rates for a sequence of intervals. | 464 // Update rates for a sequence of intervals. |
| 466 int target_rate[] = {50, 50, 50}; | 465 int target_rate[] = {50, 50, 50}; |
| 467 int encoder_sent_rate[] = {50, 50, 50}; | 466 int encoder_sent_rate[] = {50, 50, 50}; |
| 468 int incoming_frame_rate[] = {30, 30, 30}; | 467 int incoming_frame_rate[] = {30, 30, 30}; |
| 469 uint8_t fraction_lost[] = {10, 10, 10}; | 468 uint8_t fraction_lost[] = {10, 10, 10}; |
| 470 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 469 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 471 fraction_lost, 3); | 470 fraction_lost, 3); |
| 472 | 471 |
| 473 // Update content: motion level, and 3 spatial prediction errors. | 472 // Update content: motion level, and 3 spatial prediction errors. |
| 474 // High motion, low spatial. | 473 // High motion, low spatial. |
| 475 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 474 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 476 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 475 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 477 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 476 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 478 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 477 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 479 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 478 EXPECT_TRUE( |
| 480 30.0f)); | 479 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 481 | 480 |
| 482 // Reset and go up in rate: expected to go back up, in 2 stages of 3/4. | 481 // Reset and go up in rate: expected to go back up, in 2 stages of 3/4. |
| 483 qm_resolution_->ResetRates(); | 482 qm_resolution_->ResetRates(); |
| 484 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); | 483 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); |
| 485 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); | 484 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); |
| 486 // Update rates for a sequence of intervals. | 485 // Update rates for a sequence of intervals. |
| 487 int target_rate2[] = {400, 400, 400, 400, 400}; | 486 int target_rate2[] = {400, 400, 400, 400, 400}; |
| 488 int encoder_sent_rate2[] = {400, 400, 400, 400, 400}; | 487 int encoder_sent_rate2[] = {400, 400, 400, 400, 400}; |
| 489 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 488 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 490 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 489 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 491 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 490 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 492 fraction_lost2, 5); | 491 fraction_lost2, 5); |
| 493 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 492 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 494 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 493 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 495 float scale = (4.0f / 3.0f) / 2.0f; | 494 float scale = (4.0f / 3.0f) / 2.0f; |
| 496 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, scale, scale, 1.0f, 480, 360, | 495 EXPECT_TRUE( |
| 497 30.0f)); | 496 IsSelectedActionCorrect(qm_scale_, scale, scale, 1.0f, 480, 360, 30.0f)); |
| 498 | 497 |
| 499 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 498 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 500 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 499 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 501 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 500 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 502 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, | 501 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, |
| 503 640, 480, 30.0f)); | 502 640, 480, 30.0f)); |
| 504 } | 503 } |
| 505 | 504 |
| 506 // Two stages: spatial down-sample and then back up spatially, since encoder | 505 // Two stages: spatial down-sample and then back up spatially, since encoder |
| 507 // is under-shooting target even though rate has not increased much. | 506 // is under-shooting target even though rate has not increased much. |
| 508 TEST_F(QmSelectTest, 2StageDownSpatialUpSpatialUndershoot) { | 507 TEST_F(QmSelectTest, 2StageDownSpatialUpSpatialUndershoot) { |
| 509 // Initialize with bitrate, frame rate, native system width/height, and | 508 // Initialize with bitrate, frame rate, native system width/height, and |
| 510 // number of temporal layers. | 509 // number of temporal layers. |
| 511 InitQmNativeData(50, 30, 640, 480, 1); | 510 InitQmNativeData(50, 30, 640, 480, 1); |
| 512 | 511 |
| 513 // Update with encoder frame size. | 512 // Update with encoder frame size. |
| 514 uint16_t codec_width = 640; | 513 uint16_t codec_width = 640; |
| 515 uint16_t codec_height = 480; | 514 uint16_t codec_height = 480; |
| 516 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 515 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 517 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 516 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 518 | 517 |
| 519 // Update rates for a sequence of intervals. | 518 // Update rates for a sequence of intervals. |
| 520 int target_rate[] = {50, 50, 50}; | 519 int target_rate[] = {50, 50, 50}; |
| 521 int encoder_sent_rate[] = {50, 50, 50}; | 520 int encoder_sent_rate[] = {50, 50, 50}; |
| 522 int incoming_frame_rate[] = {30, 30, 30}; | 521 int incoming_frame_rate[] = {30, 30, 30}; |
| 523 uint8_t fraction_lost[] = {10, 10, 10}; | 522 uint8_t fraction_lost[] = {10, 10, 10}; |
| 524 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 523 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 525 fraction_lost, 3); | 524 fraction_lost, 3); |
| 526 | 525 |
| 527 // Update content: motion level, and 3 spatial prediction errors. | 526 // Update content: motion level, and 3 spatial prediction errors. |
| 528 // High motion, low spatial. | 527 // High motion, low spatial. |
| 529 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 528 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 530 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 529 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 531 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 530 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 532 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 531 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 533 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 532 EXPECT_TRUE( |
| 534 30.0f)); | 533 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 535 | 534 |
| 536 // Reset rates and simulate under-shooting scenario.: expect to go back up. | 535 // Reset rates and simulate under-shooting scenario.: expect to go back up. |
| 537 // Goes up spatially in two stages for 1/2x1/2 down-sampling. | 536 // Goes up spatially in two stages for 1/2x1/2 down-sampling. |
| 538 qm_resolution_->ResetRates(); | 537 qm_resolution_->ResetRates(); |
| 539 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); | 538 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); |
| 540 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); | 539 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); |
| 541 // Update rates for a sequence of intervals. | 540 // Update rates for a sequence of intervals. |
| 542 int target_rate2[] = {200, 200, 200, 200, 200}; | 541 int target_rate2[] = {200, 200, 200, 200, 200}; |
| 543 int encoder_sent_rate2[] = {50, 50, 50, 50, 50}; | 542 int encoder_sent_rate2[] = {50, 50, 50, 50, 50}; |
| 544 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 543 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 545 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 544 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 546 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 545 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 547 fraction_lost2, 5); | 546 fraction_lost2, 5); |
| 548 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 547 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 549 EXPECT_EQ(kEasyEncoding, qm_resolution_->GetEncoderState()); | 548 EXPECT_EQ(kEasyEncoding, qm_resolution_->GetEncoderState()); |
| 550 float scale = (4.0f / 3.0f) / 2.0f; | 549 float scale = (4.0f / 3.0f) / 2.0f; |
| 551 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, scale, scale, 1.0f, 480, 360, | 550 EXPECT_TRUE( |
| 552 30.0f)); | 551 IsSelectedActionCorrect(qm_scale_, scale, scale, 1.0f, 480, 360, 30.0f)); |
| 553 | 552 |
| 554 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 553 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 555 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 554 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 556 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 555 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 557 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, | 556 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, |
| 558 640, 480, 30.0f)); | 557 640, 480, 30.0f)); |
| 559 } | 558 } |
| 560 | 559 |
| 561 // Two stages: spatial down-sample and then no action to go up, | 560 // Two stages: spatial down-sample and then no action to go up, |
| 562 // as encoding rate mis-match is too high. | 561 // as encoding rate mis-match is too high. |
| 563 TEST_F(QmSelectTest, 2StageDownSpatialNoActionUp) { | 562 TEST_F(QmSelectTest, 2StageDownSpatialNoActionUp) { |
| 564 // Initialize with bitrate, frame rate, native system width/height, and | 563 // Initialize with bitrate, frame rate, native system width/height, and |
| 565 // number of temporal layers. | 564 // number of temporal layers. |
| 566 InitQmNativeData(50, 30, 640, 480, 1); | 565 InitQmNativeData(50, 30, 640, 480, 1); |
| 567 | 566 |
| 568 // Update with encoder frame size. | 567 // Update with encoder frame size. |
| 569 uint16_t codec_width = 640; | 568 uint16_t codec_width = 640; |
| 570 uint16_t codec_height = 480; | 569 uint16_t codec_height = 480; |
| 571 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 570 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 572 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 571 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 573 | 572 |
| 574 // Update rates for a sequence of intervals. | 573 // Update rates for a sequence of intervals. |
| 575 int target_rate[] = {50, 50, 50}; | 574 int target_rate[] = {50, 50, 50}; |
| 576 int encoder_sent_rate[] = {50, 50, 50}; | 575 int encoder_sent_rate[] = {50, 50, 50}; |
| 577 int incoming_frame_rate[] = {30, 30, 30}; | 576 int incoming_frame_rate[] = {30, 30, 30}; |
| 578 uint8_t fraction_lost[] = {10, 10, 10}; | 577 uint8_t fraction_lost[] = {10, 10, 10}; |
| 579 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 578 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 580 fraction_lost, 3); | 579 fraction_lost, 3); |
| 581 | 580 |
| 582 // Update content: motion level, and 3 spatial prediction errors. | 581 // Update content: motion level, and 3 spatial prediction errors. |
| 583 // High motion, low spatial. | 582 // High motion, low spatial. |
| 584 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 583 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 585 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 584 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 586 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 585 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 587 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 586 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 588 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 587 EXPECT_TRUE( |
| 589 30.0f)); | 588 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 590 | 589 |
| 591 // Reset and simulate large rate mis-match: expect no action to go back up. | 590 // Reset and simulate large rate mis-match: expect no action to go back up. |
| 592 qm_resolution_->ResetRates(); | 591 qm_resolution_->ResetRates(); |
| 593 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); | 592 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); |
| 594 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); | 593 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); |
| 595 // Update rates for a sequence of intervals. | 594 // Update rates for a sequence of intervals. |
| 596 int target_rate2[] = {400, 400, 400, 400, 400}; | 595 int target_rate2[] = {400, 400, 400, 400, 400}; |
| 597 int encoder_sent_rate2[] = {1000, 1000, 1000, 1000, 1000}; | 596 int encoder_sent_rate2[] = {1000, 1000, 1000, 1000, 1000}; |
| 598 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 597 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 599 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 598 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 600 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 599 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 601 fraction_lost2, 5); | 600 fraction_lost2, 5); |
| 602 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 601 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 603 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); | 602 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); |
| 604 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 320, 240, | 603 EXPECT_TRUE( |
| 605 30.0f)); | 604 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 320, 240, 30.0f)); |
| 606 } | 605 } |
| 607 | 606 |
| 608 // Two stages: temporally down-sample and then back up temporally, | 607 // Two stages: temporally down-sample and then back up temporally, |
| 609 // as rate as increased. | 608 // as rate as increased. |
| 610 TEST_F(QmSelectTest, 2StatgeDownTemporalUpTemporal) { | 609 TEST_F(QmSelectTest, 2StatgeDownTemporalUpTemporal) { |
| 611 // Initialize with bitrate, frame rate, native system width/height, and | 610 // Initialize with bitrate, frame rate, native system width/height, and |
| 612 // number of temporal layers. | 611 // number of temporal layers. |
| 613 InitQmNativeData(50, 30, 640, 480, 1); | 612 InitQmNativeData(50, 30, 640, 480, 1); |
| 614 | 613 |
| 615 // Update with encoder frame size. | 614 // Update with encoder frame size. |
| 616 uint16_t codec_width = 640; | 615 uint16_t codec_width = 640; |
| 617 uint16_t codec_height = 480; | 616 uint16_t codec_height = 480; |
| 618 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 617 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 619 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 618 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 620 | 619 |
| 621 // Update rates for a sequence of intervals. | 620 // Update rates for a sequence of intervals. |
| 622 int target_rate[] = {50, 50, 50}; | 621 int target_rate[] = {50, 50, 50}; |
| 623 int encoder_sent_rate[] = {50, 50, 50}; | 622 int encoder_sent_rate[] = {50, 50, 50}; |
| 624 int incoming_frame_rate[] = {30, 30, 30}; | 623 int incoming_frame_rate[] = {30, 30, 30}; |
| 625 uint8_t fraction_lost[] = {10, 10, 10}; | 624 uint8_t fraction_lost[] = {10, 10, 10}; |
| 626 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 625 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 627 fraction_lost, 3); | 626 fraction_lost, 3); |
| 628 | 627 |
| 629 // Update content: motion level, and 3 spatial prediction errors. | 628 // Update content: motion level, and 3 spatial prediction errors. |
| 630 // Low motion, high spatial. | 629 // Low motion, high spatial. |
| 631 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 630 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 632 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 631 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 633 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 632 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 634 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 633 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 635 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, | 634 EXPECT_TRUE( |
| 636 15.5f)); | 635 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, 15.5f)); |
| 637 | 636 |
| 638 // Reset rates and go up in rate: expect to go back up. | 637 // Reset rates and go up in rate: expect to go back up. |
| 639 qm_resolution_->ResetRates(); | 638 qm_resolution_->ResetRates(); |
| 640 // Update rates for a sequence of intervals. | 639 // Update rates for a sequence of intervals. |
| 641 int target_rate2[] = {400, 400, 400, 400, 400}; | 640 int target_rate2[] = {400, 400, 400, 400, 400}; |
| 642 int encoder_sent_rate2[] = {400, 400, 400, 400, 400}; | 641 int encoder_sent_rate2[] = {400, 400, 400, 400, 400}; |
| 643 int incoming_frame_rate2[] = {15, 15, 15, 15, 15}; | 642 int incoming_frame_rate2[] = {15, 15, 15, 15, 15}; |
| 644 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 643 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 645 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 644 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 646 fraction_lost2, 5); | 645 fraction_lost2, 5); |
| 647 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 646 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 648 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 647 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 649 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 0.5f, 640, 480, | 648 EXPECT_TRUE( |
| 650 30.0f)); | 649 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 0.5f, 640, 480, 30.0f)); |
| 651 } | 650 } |
| 652 | 651 |
| 653 // Two stages: temporal down-sample and then back up temporally, since encoder | 652 // Two stages: temporal down-sample and then back up temporally, since encoder |
| 654 // is under-shooting target even though rate has not increased much. | 653 // is under-shooting target even though rate has not increased much. |
| 655 TEST_F(QmSelectTest, 2StatgeDownTemporalUpTemporalUndershoot) { | 654 TEST_F(QmSelectTest, 2StatgeDownTemporalUpTemporalUndershoot) { |
| 656 // Initialize with bitrate, frame rate, native system width/height, and | 655 // Initialize with bitrate, frame rate, native system width/height, and |
| 657 // number of temporal layers. | 656 // number of temporal layers. |
| 658 InitQmNativeData(50, 30, 640, 480, 1); | 657 InitQmNativeData(50, 30, 640, 480, 1); |
| 659 | 658 |
| 660 // Update with encoder frame size. | 659 // Update with encoder frame size. |
| 661 uint16_t codec_width = 640; | 660 uint16_t codec_width = 640; |
| 662 uint16_t codec_height = 480; | 661 uint16_t codec_height = 480; |
| 663 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 662 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 664 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 663 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 665 | 664 |
| 666 // Update rates for a sequence of intervals. | 665 // Update rates for a sequence of intervals. |
| 667 int target_rate[] = {50, 50, 50}; | 666 int target_rate[] = {50, 50, 50}; |
| 668 int encoder_sent_rate[] = {50, 50, 50}; | 667 int encoder_sent_rate[] = {50, 50, 50}; |
| 669 int incoming_frame_rate[] = {30, 30, 30}; | 668 int incoming_frame_rate[] = {30, 30, 30}; |
| 670 uint8_t fraction_lost[] = {10, 10, 10}; | 669 uint8_t fraction_lost[] = {10, 10, 10}; |
| 671 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 670 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 672 fraction_lost, 3); | 671 fraction_lost, 3); |
| 673 | 672 |
| 674 // Update content: motion level, and 3 spatial prediction errors. | 673 // Update content: motion level, and 3 spatial prediction errors. |
| 675 // Low motion, high spatial. | 674 // Low motion, high spatial. |
| 676 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 675 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 677 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 676 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 678 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 677 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 679 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 678 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 680 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, | 679 EXPECT_TRUE( |
| 681 15.5f)); | 680 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 2.0f, 640, 480, 15.5f)); |
| 682 | 681 |
| 683 // Reset rates and simulate under-shooting scenario.: expect to go back up. | 682 // Reset rates and simulate under-shooting scenario.: expect to go back up. |
| 684 qm_resolution_->ResetRates(); | 683 qm_resolution_->ResetRates(); |
| 685 // Update rates for a sequence of intervals. | 684 // Update rates for a sequence of intervals. |
| 686 int target_rate2[] = {150, 150, 150, 150, 150}; | 685 int target_rate2[] = {150, 150, 150, 150, 150}; |
| 687 int encoder_sent_rate2[] = {50, 50, 50, 50, 50}; | 686 int encoder_sent_rate2[] = {50, 50, 50, 50, 50}; |
| 688 int incoming_frame_rate2[] = {15, 15, 15, 15, 15}; | 687 int incoming_frame_rate2[] = {15, 15, 15, 15, 15}; |
| 689 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 688 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 690 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 689 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 691 fraction_lost2, 5); | 690 fraction_lost2, 5); |
| 692 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 691 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 693 EXPECT_EQ(kEasyEncoding, qm_resolution_->GetEncoderState()); | 692 EXPECT_EQ(kEasyEncoding, qm_resolution_->GetEncoderState()); |
| 694 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 0.5f, 640, 480, | 693 EXPECT_TRUE( |
| 695 30.0f)); | 694 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 0.5f, 640, 480, 30.0f)); |
| 696 } | 695 } |
| 697 | 696 |
| 698 // Two stages: temporal down-sample and then no action to go up, | 697 // Two stages: temporal down-sample and then no action to go up, |
| 699 // as encoding rate mis-match is too high. | 698 // as encoding rate mis-match is too high. |
| 700 TEST_F(QmSelectTest, 2StageDownTemporalNoActionUp) { | 699 TEST_F(QmSelectTest, 2StageDownTemporalNoActionUp) { |
| 701 // Initialize with bitrate, frame rate, native system width/height, and | 700 // Initialize with bitrate, frame rate, native system width/height, and |
| 702 // number of temporal layers. | 701 // number of temporal layers. |
| 703 InitQmNativeData(50, 30, 640, 480, 1); | 702 InitQmNativeData(50, 30, 640, 480, 1); |
| 704 | 703 |
| 705 // Update with encoder frame size. | 704 // Update with encoder frame size. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 729 qm_resolution_->ResetRates(); | 728 qm_resolution_->ResetRates(); |
| 730 // Update rates for a sequence of intervals. | 729 // Update rates for a sequence of intervals. |
| 731 int target_rate2[] = {600, 600, 600, 600, 600}; | 730 int target_rate2[] = {600, 600, 600, 600, 600}; |
| 732 int encoder_sent_rate2[] = {1000, 1000, 1000, 1000, 1000}; | 731 int encoder_sent_rate2[] = {1000, 1000, 1000, 1000, 1000}; |
| 733 int incoming_frame_rate2[] = {15, 15, 15, 15, 15}; | 732 int incoming_frame_rate2[] = {15, 15, 15, 15, 15}; |
| 734 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 733 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 735 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 734 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 736 fraction_lost2, 5); | 735 fraction_lost2, 5); |
| 737 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 736 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 738 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); | 737 EXPECT_EQ(kStressedEncoding, qm_resolution_->GetEncoderState()); |
| 739 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, | 738 EXPECT_TRUE( |
| 740 15.0f)); | 739 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 640, 480, 15.0f)); |
| 741 } | 740 } |
| 742 // 3 stages: spatial down-sample, followed by temporal down-sample, | 741 // 3 stages: spatial down-sample, followed by temporal down-sample, |
| 743 // and then go up to full state, as encoding rate has increased. | 742 // and then go up to full state, as encoding rate has increased. |
| 744 TEST_F(QmSelectTest, 3StageDownSpatialTemporlaUpSpatialTemporal) { | 743 TEST_F(QmSelectTest, 3StageDownSpatialTemporlaUpSpatialTemporal) { |
| 745 // Initialize with bitrate, frame rate, native system width/height, and | 744 // Initialize with bitrate, frame rate, native system width/height, and |
| 746 // number of temporal layers. | 745 // number of temporal layers. |
| 747 InitQmNativeData(80, 30, 640, 480, 1); | 746 InitQmNativeData(80, 30, 640, 480, 1); |
| 748 | 747 |
| 749 // Update with encoder frame size. | 748 // Update with encoder frame size. |
| 750 uint16_t codec_width = 640; | 749 uint16_t codec_width = 640; |
| 751 uint16_t codec_height = 480; | 750 uint16_t codec_height = 480; |
| 752 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 751 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 753 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 752 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 754 | 753 |
| 755 // Update rates for a sequence of intervals. | 754 // Update rates for a sequence of intervals. |
| 756 int target_rate[] = {80, 80, 80}; | 755 int target_rate[] = {80, 80, 80}; |
| 757 int encoder_sent_rate[] = {80, 80, 80}; | 756 int encoder_sent_rate[] = {80, 80, 80}; |
| 758 int incoming_frame_rate[] = {30, 30, 30}; | 757 int incoming_frame_rate[] = {30, 30, 30}; |
| 759 uint8_t fraction_lost[] = {10, 10, 10}; | 758 uint8_t fraction_lost[] = {10, 10, 10}; |
| 760 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 759 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 761 fraction_lost, 3); | 760 fraction_lost, 3); |
| 762 | 761 |
| 763 // Update content: motion level, and 3 spatial prediction errors. | 762 // Update content: motion level, and 3 spatial prediction errors. |
| 764 // High motion, low spatial. | 763 // High motion, low spatial. |
| 765 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 764 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 766 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 765 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 767 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 766 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 768 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 767 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 769 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 768 EXPECT_TRUE( |
| 770 30.0f)); | 769 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 771 | 770 |
| 772 // Change content data: expect temporal down-sample. | 771 // Change content data: expect temporal down-sample. |
| 773 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); | 772 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); |
| 774 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); | 773 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); |
| 775 | 774 |
| 776 // Reset rates and go lower in rate. | 775 // Reset rates and go lower in rate. |
| 777 qm_resolution_->ResetRates(); | 776 qm_resolution_->ResetRates(); |
| 778 int target_rate2[] = {40, 40, 40, 40, 40}; | 777 int target_rate2[] = {40, 40, 40, 40, 40}; |
| 779 int encoder_sent_rate2[] = {40, 40, 40, 40, 40}; | 778 int encoder_sent_rate2[] = {40, 40, 40, 40, 40}; |
| 780 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 779 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 781 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 780 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 782 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 781 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 783 fraction_lost2, 5); | 782 fraction_lost2, 5); |
| 784 | 783 |
| 785 // Update content: motion level, and 3 spatial prediction errors. | 784 // Update content: motion level, and 3 spatial prediction errors. |
| 786 // Low motion, high spatial. | 785 // Low motion, high spatial. |
| 787 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 786 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 788 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 787 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 789 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 788 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 790 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 789 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 791 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 320, 240, | 790 EXPECT_TRUE( |
| 792 20.5f)); | 791 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 320, 240, 20.5f)); |
| 793 | 792 |
| 794 // Reset rates and go high up in rate: expect to go back up both spatial | 793 // Reset rates and go high up in rate: expect to go back up both spatial |
| 795 // and temporally. The 1/2x1/2 spatial is undone in two stages. | 794 // and temporally. The 1/2x1/2 spatial is undone in two stages. |
| 796 qm_resolution_->ResetRates(); | 795 qm_resolution_->ResetRates(); |
| 797 // Update rates for a sequence of intervals. | 796 // Update rates for a sequence of intervals. |
| 798 int target_rate3[] = {1000, 1000, 1000, 1000, 1000}; | 797 int target_rate3[] = {1000, 1000, 1000, 1000, 1000}; |
| 799 int encoder_sent_rate3[] = {1000, 1000, 1000, 1000, 1000}; | 798 int encoder_sent_rate3[] = {1000, 1000, 1000, 1000, 1000}; |
| 800 int incoming_frame_rate3[] = {20, 20, 20, 20, 20}; | 799 int incoming_frame_rate3[] = {20, 20, 20, 20, 20}; |
| 801 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; | 800 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; |
| 802 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, | 801 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, |
| 803 fraction_lost3, 5); | 802 fraction_lost3, 5); |
| 804 | 803 |
| 805 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 804 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 806 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 805 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 807 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 806 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 808 float scale = (4.0f / 3.0f) / 2.0f; | 807 float scale = (4.0f / 3.0f) / 2.0f; |
| 809 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, scale, scale, 2.0f / 3.0f, | 808 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, scale, scale, 2.0f / 3.0f, 480, |
| 810 480, 360, 30.0f)); | 809 360, 30.0f)); |
| 811 | 810 |
| 812 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 811 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 813 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 812 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 814 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 813 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 815 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, | 814 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, |
| 816 640, 480, 30.0f)); | 815 640, 480, 30.0f)); |
| 817 } | 816 } |
| 818 | 817 |
| 819 // No down-sampling below some total amount. | 818 // No down-sampling below some total amount. |
| 820 TEST_F(QmSelectTest, NoActionTooMuchDownSampling) { | 819 TEST_F(QmSelectTest, NoActionTooMuchDownSampling) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 835 uint8_t fraction_lost[] = {10, 10, 10}; | 834 uint8_t fraction_lost[] = {10, 10, 10}; |
| 836 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 835 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 837 fraction_lost, 3); | 836 fraction_lost, 3); |
| 838 | 837 |
| 839 // Update content: motion level, and 3 spatial prediction errors. | 838 // Update content: motion level, and 3 spatial prediction errors. |
| 840 // High motion, low spatial. | 839 // High motion, low spatial. |
| 841 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 840 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 842 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 841 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 843 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 842 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 844 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 843 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 845 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 640, 360, | 844 EXPECT_TRUE( |
| 846 30.0f)); | 845 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 640, 360, 30.0f)); |
| 847 | 846 |
| 848 // Reset and lower rates to get another spatial action (3/4x3/4). | 847 // Reset and lower rates to get another spatial action (3/4x3/4). |
| 849 // Lower the frame rate for spatial to be selected again. | 848 // Lower the frame rate for spatial to be selected again. |
| 850 qm_resolution_->ResetRates(); | 849 qm_resolution_->ResetRates(); |
| 851 qm_resolution_->UpdateCodecParameters(10.0f, 640, 360); | 850 qm_resolution_->UpdateCodecParameters(10.0f, 640, 360); |
| 852 EXPECT_EQ(4, qm_resolution_->GetImageType(640, 360)); | 851 EXPECT_EQ(4, qm_resolution_->GetImageType(640, 360)); |
| 853 // Update rates for a sequence of intervals. | 852 // Update rates for a sequence of intervals. |
| 854 int target_rate2[] = {70, 70, 70, 70, 70}; | 853 int target_rate2[] = {70, 70, 70, 70, 70}; |
| 855 int encoder_sent_rate2[] = {70, 70, 70, 70, 70}; | 854 int encoder_sent_rate2[] = {70, 70, 70, 70, 70}; |
| 856 int incoming_frame_rate2[] = {10, 10, 10, 10, 10}; | 855 int incoming_frame_rate2[] = {10, 10, 10, 10, 10}; |
| 857 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 856 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 858 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 857 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 859 fraction_lost2, 5); | 858 fraction_lost2, 5); |
| 860 | 859 |
| 861 // Update content: motion level, and 3 spatial prediction errors. | 860 // Update content: motion level, and 3 spatial prediction errors. |
| 862 // High motion, medium spatial. | 861 // High motion, medium spatial. |
| 863 UpdateQmContentData(kTemporalHigh, kSpatialMedium, kSpatialMedium, | 862 UpdateQmContentData(kTemporalHigh, kSpatialMedium, kSpatialMedium, |
| 864 kSpatialMedium); | 863 kSpatialMedium); |
| 865 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 864 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 866 EXPECT_EQ(5, qm_resolution_->ComputeContentClass()); | 865 EXPECT_EQ(5, qm_resolution_->ComputeContentClass()); |
| 867 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 866 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 868 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, | 867 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, 1.0f, |
| 869 1.0f, 480, 270, 10.0f)); | 868 480, 270, 10.0f)); |
| 870 | 869 |
| 871 // Reset and go to very low rate: no action should be taken, | 870 // Reset and go to very low rate: no action should be taken, |
| 872 // we went down too much already. | 871 // we went down too much already. |
| 873 qm_resolution_->ResetRates(); | 872 qm_resolution_->ResetRates(); |
| 874 qm_resolution_->UpdateCodecParameters(10.0f, 480, 270); | 873 qm_resolution_->UpdateCodecParameters(10.0f, 480, 270); |
| 875 EXPECT_EQ(3, qm_resolution_->GetImageType(480, 270)); | 874 EXPECT_EQ(3, qm_resolution_->GetImageType(480, 270)); |
| 876 // Update rates for a sequence of intervals. | 875 // Update rates for a sequence of intervals. |
| 877 int target_rate3[] = {10, 10, 10, 10, 10}; | 876 int target_rate3[] = {10, 10, 10, 10, 10}; |
| 878 int encoder_sent_rate3[] = {10, 10, 10, 10, 10}; | 877 int encoder_sent_rate3[] = {10, 10, 10, 10, 10}; |
| 879 int incoming_frame_rate3[] = {10, 10, 10, 10, 10}; | 878 int incoming_frame_rate3[] = {10, 10, 10, 10, 10}; |
| 880 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; | 879 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; |
| 881 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, | 880 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, |
| 882 fraction_lost3, 5); | 881 fraction_lost3, 5); |
| 883 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 882 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 884 EXPECT_EQ(5, qm_resolution_->ComputeContentClass()); | 883 EXPECT_EQ(5, qm_resolution_->ComputeContentClass()); |
| 885 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 884 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 886 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 480, 270, | 885 EXPECT_TRUE( |
| 887 10.0f)); | 886 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.0f, 480, 270, 10.0f)); |
| 888 } | 887 } |
| 889 | 888 |
| 890 // Multiple down-sampling stages and then undo all of them. | 889 // Multiple down-sampling stages and then undo all of them. |
| 891 // Spatial down-sample 3/4x3/4, followed by temporal down-sample 2/3, | 890 // Spatial down-sample 3/4x3/4, followed by temporal down-sample 2/3, |
| 892 // followed by spatial 3/4x3/4. Then go up to full state, | 891 // followed by spatial 3/4x3/4. Then go up to full state, |
| 893 // as encoding rate has increased. | 892 // as encoding rate has increased. |
| 894 TEST_F(QmSelectTest, MultipleStagesCheckActionHistory1) { | 893 TEST_F(QmSelectTest, MultipleStagesCheckActionHistory1) { |
| 895 // Initialize with bitrate, frame rate, native system width/height, and | 894 // Initialize with bitrate, frame rate, native system width/height, and |
| 896 // number of temporal layers. | 895 // number of temporal layers. |
| 897 InitQmNativeData(150, 30, 640, 480, 1); | 896 InitQmNativeData(150, 30, 640, 480, 1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 910 uint8_t fraction_lost[] = {10, 10, 10}; | 909 uint8_t fraction_lost[] = {10, 10, 10}; |
| 911 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 910 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 912 fraction_lost, 3); | 911 fraction_lost, 3); |
| 913 | 912 |
| 914 // Update content: motion level, and 3 spatial prediction errors. | 913 // Update content: motion level, and 3 spatial prediction errors. |
| 915 // Medium motion, low spatial. | 914 // Medium motion, low spatial. |
| 916 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); | 915 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); |
| 917 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 916 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 918 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); | 917 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); |
| 919 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 918 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 920 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, | 919 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, 1.0f, |
| 921 1.0f, 480, 360, 30.0f)); | 920 480, 360, 30.0f)); |
| 922 // Go down 2/3 temporal. | 921 // Go down 2/3 temporal. |
| 923 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 922 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 924 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 923 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 925 qm_resolution_->ResetRates(); | 924 qm_resolution_->ResetRates(); |
| 926 int target_rate2[] = {100, 100, 100, 100, 100}; | 925 int target_rate2[] = {100, 100, 100, 100, 100}; |
| 927 int encoder_sent_rate2[] = {100, 100, 100, 100, 100}; | 926 int encoder_sent_rate2[] = {100, 100, 100, 100, 100}; |
| 928 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 927 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 929 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 928 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 930 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 929 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 931 fraction_lost2, 5); | 930 fraction_lost2, 5); |
| 932 | 931 |
| 933 // Update content: motion level, and 3 spatial prediction errors. | 932 // Update content: motion level, and 3 spatial prediction errors. |
| 934 // Low motion, high spatial. | 933 // Low motion, high spatial. |
| 935 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 934 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 936 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 935 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 937 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 936 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 938 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 937 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 939 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 480, 360, | 938 EXPECT_TRUE( |
| 940 20.5f)); | 939 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 480, 360, 20.5f)); |
| 941 | 940 |
| 942 // Go down 3/4x3/4 spatial: | 941 // Go down 3/4x3/4 spatial: |
| 943 qm_resolution_->UpdateCodecParameters(20.0f, 480, 360); | 942 qm_resolution_->UpdateCodecParameters(20.0f, 480, 360); |
| 944 qm_resolution_->ResetRates(); | 943 qm_resolution_->ResetRates(); |
| 945 int target_rate3[] = {80, 80, 80, 80, 80}; | 944 int target_rate3[] = {80, 80, 80, 80, 80}; |
| 946 int encoder_sent_rate3[] = {80, 80, 80, 80, 80}; | 945 int encoder_sent_rate3[] = {80, 80, 80, 80, 80}; |
| 947 int incoming_frame_rate3[] = {20, 20, 20, 20, 20}; | 946 int incoming_frame_rate3[] = {20, 20, 20, 20, 20}; |
| 948 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; | 947 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; |
| 949 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, | 948 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, |
| 950 fraction_lost3, 5); | 949 fraction_lost3, 5); |
| 951 | 950 |
| 952 // Update content: motion level, and 3 spatial prediction errors. | 951 // Update content: motion level, and 3 spatial prediction errors. |
| 953 // High motion, low spatial. | 952 // High motion, low spatial. |
| 954 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); | 953 UpdateQmContentData(kTemporalHigh, kSpatialLow, kSpatialLow, kSpatialLow); |
| 955 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 954 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 956 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); | 955 EXPECT_EQ(3, qm_resolution_->ComputeContentClass()); |
| 957 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 956 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 958 // The two spatial actions of 3/4x3/4 are converted to 1/2x1/2, | 957 // The two spatial actions of 3/4x3/4 are converted to 1/2x1/2, |
| 959 // so scale factor is 2.0. | 958 // so scale factor is 2.0. |
| 960 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 959 EXPECT_TRUE( |
| 961 20.0f)); | 960 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 20.0f)); |
| 962 | 961 |
| 963 // Reset rates and go high up in rate: expect to go up: | 962 // Reset rates and go high up in rate: expect to go up: |
| 964 // 1/2x1x2 spatial and 1/2 temporally. | 963 // 1/2x1x2 spatial and 1/2 temporally. |
| 965 | 964 |
| 966 // Go up 1/2x1/2 spatially and 1/2 temporally. Spatial is done in 2 stages. | 965 // Go up 1/2x1/2 spatially and 1/2 temporally. Spatial is done in 2 stages. |
| 967 qm_resolution_->UpdateCodecParameters(15.0f, 320, 240); | 966 qm_resolution_->UpdateCodecParameters(15.0f, 320, 240); |
| 968 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); | 967 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); |
| 969 qm_resolution_->ResetRates(); | 968 qm_resolution_->ResetRates(); |
| 970 // Update rates for a sequence of intervals. | 969 // Update rates for a sequence of intervals. |
| 971 int target_rate4[] = {1000, 1000, 1000, 1000, 1000}; | 970 int target_rate4[] = {1000, 1000, 1000, 1000, 1000}; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 uint8_t fraction_lost[] = {10, 10, 10}; | 1010 uint8_t fraction_lost[] = {10, 10, 10}; |
| 1012 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 1011 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 1013 fraction_lost, 3); | 1012 fraction_lost, 3); |
| 1014 | 1013 |
| 1015 // Update content: motion level, and 3 spatial prediction errors. | 1014 // Update content: motion level, and 3 spatial prediction errors. |
| 1016 // Medium motion, low spatial. | 1015 // Medium motion, low spatial. |
| 1017 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); | 1016 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); |
| 1018 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1017 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1019 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); | 1018 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); |
| 1020 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1019 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1021 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 1020 EXPECT_TRUE( |
| 1022 30.0f)); | 1021 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 1023 | 1022 |
| 1024 // Go down 2/3 temporal. | 1023 // Go down 2/3 temporal. |
| 1025 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); | 1024 qm_resolution_->UpdateCodecParameters(30.0f, 320, 240); |
| 1026 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); | 1025 EXPECT_EQ(2, qm_resolution_->GetImageType(320, 240)); |
| 1027 qm_resolution_->ResetRates(); | 1026 qm_resolution_->ResetRates(); |
| 1028 int target_rate2[] = {40, 40, 40, 40, 40}; | 1027 int target_rate2[] = {40, 40, 40, 40, 40}; |
| 1029 int encoder_sent_rate2[] = {40, 40, 40, 40, 40}; | 1028 int encoder_sent_rate2[] = {40, 40, 40, 40, 40}; |
| 1030 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 1029 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 1031 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 1030 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 1032 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 1031 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 1033 fraction_lost2, 5); | 1032 fraction_lost2, 5); |
| 1034 | 1033 |
| 1035 // Update content: motion level, and 3 spatial prediction errors. | 1034 // Update content: motion level, and 3 spatial prediction errors. |
| 1036 // Medium motion, high spatial. | 1035 // Medium motion, high spatial. |
| 1037 UpdateQmContentData(kTemporalMedium, kSpatialHigh, kSpatialHigh, | 1036 UpdateQmContentData(kTemporalMedium, kSpatialHigh, kSpatialHigh, |
| 1038 kSpatialHigh); | 1037 kSpatialHigh); |
| 1039 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1038 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1040 EXPECT_EQ(7, qm_resolution_->ComputeContentClass()); | 1039 EXPECT_EQ(7, qm_resolution_->ComputeContentClass()); |
| 1041 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1040 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1042 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 320, 240, | 1041 EXPECT_TRUE( |
| 1043 20.5f)); | 1042 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 320, 240, 20.5f)); |
| 1044 | 1043 |
| 1045 // Go up 2/3 temporally. | 1044 // Go up 2/3 temporally. |
| 1046 qm_resolution_->UpdateCodecParameters(20.0f, 320, 240); | 1045 qm_resolution_->UpdateCodecParameters(20.0f, 320, 240); |
| 1047 qm_resolution_->ResetRates(); | 1046 qm_resolution_->ResetRates(); |
| 1048 // Update rates for a sequence of intervals. | 1047 // Update rates for a sequence of intervals. |
| 1049 int target_rate3[] = {150, 150, 150, 150, 150}; | 1048 int target_rate3[] = {150, 150, 150, 150, 150}; |
| 1050 int encoder_sent_rate3[] = {150, 150, 150, 150, 150}; | 1049 int encoder_sent_rate3[] = {150, 150, 150, 150, 150}; |
| 1051 int incoming_frame_rate3[] = {20, 20, 20, 20, 20}; | 1050 int incoming_frame_rate3[] = {20, 20, 20, 20, 20}; |
| 1052 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; | 1051 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; |
| 1053 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, | 1052 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1069 uint8_t fraction_lost4[] = {10, 10, 10, 10, 10}; | 1068 uint8_t fraction_lost4[] = {10, 10, 10, 10, 10}; |
| 1070 UpdateQmRateData(target_rate4, encoder_sent_rate4, incoming_frame_rate4, | 1069 UpdateQmRateData(target_rate4, encoder_sent_rate4, incoming_frame_rate4, |
| 1071 fraction_lost4, 5); | 1070 fraction_lost4, 5); |
| 1072 | 1071 |
| 1073 // Update content: motion level, and 3 spatial prediction errors. | 1072 // Update content: motion level, and 3 spatial prediction errors. |
| 1074 // Low motion, high spatial. | 1073 // Low motion, high spatial. |
| 1075 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 1074 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 1076 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1075 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1077 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 1076 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 1078 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1077 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1079 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 320, 240, | 1078 EXPECT_TRUE( |
| 1080 20.5f)); | 1079 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 320, 240, 20.5f)); |
| 1081 | 1080 |
| 1082 // Go up spatial and temporal. Spatial undoing is done in 2 stages. | 1081 // Go up spatial and temporal. Spatial undoing is done in 2 stages. |
| 1083 qm_resolution_->UpdateCodecParameters(20.5f, 320, 240); | 1082 qm_resolution_->UpdateCodecParameters(20.5f, 320, 240); |
| 1084 qm_resolution_->ResetRates(); | 1083 qm_resolution_->ResetRates(); |
| 1085 // Update rates for a sequence of intervals. | 1084 // Update rates for a sequence of intervals. |
| 1086 int target_rate5[] = {1000, 1000, 1000, 1000, 1000}; | 1085 int target_rate5[] = {1000, 1000, 1000, 1000, 1000}; |
| 1087 int encoder_sent_rate5[] = {1000, 1000, 1000, 1000, 1000}; | 1086 int encoder_sent_rate5[] = {1000, 1000, 1000, 1000, 1000}; |
| 1088 int incoming_frame_rate5[] = {20, 20, 20, 20, 20}; | 1087 int incoming_frame_rate5[] = {20, 20, 20, 20, 20}; |
| 1089 uint8_t fraction_lost5[] = {10, 10, 10, 10, 10}; | 1088 uint8_t fraction_lost5[] = {10, 10, 10, 10, 10}; |
| 1090 UpdateQmRateData(target_rate5, encoder_sent_rate5, incoming_frame_rate5, | 1089 UpdateQmRateData(target_rate5, encoder_sent_rate5, incoming_frame_rate5, |
| 1091 fraction_lost5, 5); | 1090 fraction_lost5, 5); |
| 1092 | 1091 |
| 1093 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1092 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1094 float scale = (4.0f / 3.0f) / 2.0f; | 1093 float scale = (4.0f / 3.0f) / 2.0f; |
| 1095 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, scale, scale, 2.0f / 3.0f, | 1094 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, scale, scale, 2.0f / 3.0f, 480, |
| 1096 480, 360, 30.0f)); | 1095 360, 30.0f)); |
| 1097 | 1096 |
| 1098 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 1097 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 1099 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 1098 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 1100 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1099 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1101 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, | 1100 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, |
| 1102 640, 480, 30.0f)); | 1101 640, 480, 30.0f)); |
| 1103 } | 1102 } |
| 1104 | 1103 |
| 1105 // Multiple down-sampling and up-sample stages, with partial undoing. | 1104 // Multiple down-sampling and up-sample stages, with partial undoing. |
| 1106 // Spatial down-sample 3/4x3/4, followed by temporal down-sample 2/3, | 1105 // Spatial down-sample 3/4x3/4, followed by temporal down-sample 2/3, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1124 uint8_t fraction_lost[] = {10, 10, 10}; | 1123 uint8_t fraction_lost[] = {10, 10, 10}; |
| 1125 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 1124 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 1126 fraction_lost, 3); | 1125 fraction_lost, 3); |
| 1127 | 1126 |
| 1128 // Update content: motion level, and 3 spatial prediction errors. | 1127 // Update content: motion level, and 3 spatial prediction errors. |
| 1129 // Medium motion, low spatial. | 1128 // Medium motion, low spatial. |
| 1130 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); | 1129 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); |
| 1131 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1130 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1132 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); | 1131 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); |
| 1133 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1132 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1134 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, | 1133 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, 1.0f, |
| 1135 1.0f, 480, 360, 30.0f)); | 1134 480, 360, 30.0f)); |
| 1136 | 1135 |
| 1137 // Go down 2/3 temporal. | 1136 // Go down 2/3 temporal. |
| 1138 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 1137 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 1139 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 1138 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 1140 qm_resolution_->ResetRates(); | 1139 qm_resolution_->ResetRates(); |
| 1141 int target_rate2[] = {100, 100, 100, 100, 100}; | 1140 int target_rate2[] = {100, 100, 100, 100, 100}; |
| 1142 int encoder_sent_rate2[] = {100, 100, 100, 100, 100}; | 1141 int encoder_sent_rate2[] = {100, 100, 100, 100, 100}; |
| 1143 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 1142 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 1144 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 1143 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 1145 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 1144 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 1146 fraction_lost2, 5); | 1145 fraction_lost2, 5); |
| 1147 | 1146 |
| 1148 // Update content: motion level, and 3 spatial prediction errors. | 1147 // Update content: motion level, and 3 spatial prediction errors. |
| 1149 // Low motion, high spatial. | 1148 // Low motion, high spatial. |
| 1150 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); | 1149 UpdateQmContentData(kTemporalLow, kSpatialHigh, kSpatialHigh, kSpatialHigh); |
| 1151 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1150 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1152 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); | 1151 EXPECT_EQ(1, qm_resolution_->ComputeContentClass()); |
| 1153 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1152 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1154 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 480, 360, | 1153 EXPECT_TRUE( |
| 1155 20.5f)); | 1154 IsSelectedActionCorrect(qm_scale_, 1.0f, 1.0f, 1.5f, 480, 360, 20.5f)); |
| 1156 | 1155 |
| 1157 // Go up 2/3 temporal. | 1156 // Go up 2/3 temporal. |
| 1158 qm_resolution_->UpdateCodecParameters(20.5f, 480, 360); | 1157 qm_resolution_->UpdateCodecParameters(20.5f, 480, 360); |
| 1159 qm_resolution_->ResetRates(); | 1158 qm_resolution_->ResetRates(); |
| 1160 // Update rates for a sequence of intervals. | 1159 // Update rates for a sequence of intervals. |
| 1161 int target_rate3[] = {250, 250, 250, 250, 250}; | 1160 int target_rate3[] = {250, 250, 250, 250, 250}; |
| 1162 int encoder_sent_rate3[] = {250, 250, 250, 250, 250}; | 1161 int encoder_sent_rate3[] = {250, 250, 250, 250, 250}; |
| 1163 int incoming_frame_rate3[] = {20, 20, 20, 20, 120}; | 1162 int incoming_frame_rate3[] = {20, 20, 20, 20, 120}; |
| 1164 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; | 1163 uint8_t fraction_lost3[] = {10, 10, 10, 10, 10}; |
| 1165 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, | 1164 UpdateQmRateData(target_rate3, encoder_sent_rate3, incoming_frame_rate3, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1177 qm_resolution_->ResetRates(); | 1176 qm_resolution_->ResetRates(); |
| 1178 int target_rate4[] = {500, 500, 500, 500, 500}; | 1177 int target_rate4[] = {500, 500, 500, 500, 500}; |
| 1179 int encoder_sent_rate4[] = {500, 500, 500, 500, 500}; | 1178 int encoder_sent_rate4[] = {500, 500, 500, 500, 500}; |
| 1180 int incoming_frame_rate4[] = {30, 30, 30, 30, 30}; | 1179 int incoming_frame_rate4[] = {30, 30, 30, 30, 30}; |
| 1181 uint8_t fraction_lost4[] = {30, 30, 30, 30, 30}; | 1180 uint8_t fraction_lost4[] = {30, 30, 30, 30, 30}; |
| 1182 UpdateQmRateData(target_rate4, encoder_sent_rate4, incoming_frame_rate4, | 1181 UpdateQmRateData(target_rate4, encoder_sent_rate4, incoming_frame_rate4, |
| 1183 fraction_lost4, 5); | 1182 fraction_lost4, 5); |
| 1184 | 1183 |
| 1185 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1184 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1186 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1185 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1187 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, | 1186 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 3.0f / 4.0f, 3.0f / 4.0f, 1.0f, |
| 1188 1.0f, 640, 480, 30.0f)); | 1187 640, 480, 30.0f)); |
| 1189 } | 1188 } |
| 1190 | 1189 |
| 1191 // Two stages of 3/4x3/4 converted to one stage of 1/2x1/2. | 1190 // Two stages of 3/4x3/4 converted to one stage of 1/2x1/2. |
| 1192 TEST_F(QmSelectTest, ConvertThreeQuartersToOneHalf) { | 1191 TEST_F(QmSelectTest, ConvertThreeQuartersToOneHalf) { |
| 1193 // Initialize with bitrate, frame rate, native system width/height, and | 1192 // Initialize with bitrate, frame rate, native system width/height, and |
| 1194 // number of temporal layers. | 1193 // number of temporal layers. |
| 1195 InitQmNativeData(150, 30, 640, 480, 1); | 1194 InitQmNativeData(150, 30, 640, 480, 1); |
| 1196 | 1195 |
| 1197 // Update with encoder frame size. | 1196 // Update with encoder frame size. |
| 1198 uint16_t codec_width = 640; | 1197 uint16_t codec_width = 640; |
| 1199 uint16_t codec_height = 480; | 1198 uint16_t codec_height = 480; |
| 1200 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); | 1199 qm_resolution_->UpdateCodecParameters(30.0f, codec_width, codec_height); |
| 1201 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); | 1200 EXPECT_EQ(5, qm_resolution_->GetImageType(codec_width, codec_height)); |
| 1202 | 1201 |
| 1203 // Go down 3/4x3/4 spatial. | 1202 // Go down 3/4x3/4 spatial. |
| 1204 // Update rates for a sequence of intervals. | 1203 // Update rates for a sequence of intervals. |
| 1205 int target_rate[] = {150, 150, 150}; | 1204 int target_rate[] = {150, 150, 150}; |
| 1206 int encoder_sent_rate[] = {150, 150, 150}; | 1205 int encoder_sent_rate[] = {150, 150, 150}; |
| 1207 int incoming_frame_rate[] = {30, 30, 30}; | 1206 int incoming_frame_rate[] = {30, 30, 30}; |
| 1208 uint8_t fraction_lost[] = {10, 10, 10}; | 1207 uint8_t fraction_lost[] = {10, 10, 10}; |
| 1209 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, | 1208 UpdateQmRateData(target_rate, encoder_sent_rate, incoming_frame_rate, |
| 1210 fraction_lost, 3); | 1209 fraction_lost, 3); |
| 1211 | 1210 |
| 1212 // Update content: motion level, and 3 spatial prediction errors. | 1211 // Update content: motion level, and 3 spatial prediction errors. |
| 1213 // Medium motion, low spatial. | 1212 // Medium motion, low spatial. |
| 1214 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); | 1213 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); |
| 1215 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1214 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1216 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); | 1215 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); |
| 1217 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1216 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1218 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, | 1217 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 4.0f / 3.0f, 4.0f / 3.0f, 1.0f, |
| 1219 1.0f, 480, 360, 30.0f)); | 1218 480, 360, 30.0f)); |
| 1220 | 1219 |
| 1221 // Set rates to go down another 3/4 spatial. Should be converted ton 1/2. | 1220 // Set rates to go down another 3/4 spatial. Should be converted ton 1/2. |
| 1222 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); | 1221 qm_resolution_->UpdateCodecParameters(30.0f, 480, 360); |
| 1223 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); | 1222 EXPECT_EQ(4, qm_resolution_->GetImageType(480, 360)); |
| 1224 qm_resolution_->ResetRates(); | 1223 qm_resolution_->ResetRates(); |
| 1225 int target_rate2[] = {100, 100, 100, 100, 100}; | 1224 int target_rate2[] = {100, 100, 100, 100, 100}; |
| 1226 int encoder_sent_rate2[] = {100, 100, 100, 100, 100}; | 1225 int encoder_sent_rate2[] = {100, 100, 100, 100, 100}; |
| 1227 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; | 1226 int incoming_frame_rate2[] = {30, 30, 30, 30, 30}; |
| 1228 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; | 1227 uint8_t fraction_lost2[] = {10, 10, 10, 10, 10}; |
| 1229 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, | 1228 UpdateQmRateData(target_rate2, encoder_sent_rate2, incoming_frame_rate2, |
| 1230 fraction_lost2, 5); | 1229 fraction_lost2, 5); |
| 1231 | 1230 |
| 1232 // Update content: motion level, and 3 spatial prediction errors. | 1231 // Update content: motion level, and 3 spatial prediction errors. |
| 1233 // Medium motion, low spatial. | 1232 // Medium motion, low spatial. |
| 1234 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); | 1233 UpdateQmContentData(kTemporalMedium, kSpatialLow, kSpatialLow, kSpatialLow); |
| 1235 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); | 1234 EXPECT_EQ(0, qm_resolution_->SelectResolution(&qm_scale_)); |
| 1236 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); | 1235 EXPECT_EQ(6, qm_resolution_->ComputeContentClass()); |
| 1237 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); | 1236 EXPECT_EQ(kStableEncoding, qm_resolution_->GetEncoderState()); |
| 1238 EXPECT_TRUE(IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, | 1237 EXPECT_TRUE( |
| 1239 30.0f)); | 1238 IsSelectedActionCorrect(qm_scale_, 2.0f, 2.0f, 1.0f, 320, 240, 30.0f)); |
| 1240 } | 1239 } |
| 1241 | 1240 |
| 1242 void QmSelectTest::InitQmNativeData(float initial_bit_rate, | 1241 void QmSelectTest::InitQmNativeData(float initial_bit_rate, |
| 1243 int user_frame_rate, | 1242 int user_frame_rate, |
| 1244 int native_width, | 1243 int native_width, |
| 1245 int native_height, | 1244 int native_height, |
| 1246 int num_layers) { | 1245 int num_layers) { |
| 1247 EXPECT_EQ(0, qm_resolution_->Initialize(initial_bit_rate, | 1246 EXPECT_EQ( |
| 1248 user_frame_rate, | 1247 0, qm_resolution_->Initialize(initial_bit_rate, user_frame_rate, |
| 1249 native_width, | 1248 native_width, native_height, num_layers)); |
| 1250 native_height, | |
| 1251 num_layers)); | |
| 1252 } | 1249 } |
| 1253 | 1250 |
| 1254 void QmSelectTest::UpdateQmContentData(float motion_metric, | 1251 void QmSelectTest::UpdateQmContentData(float motion_metric, |
| 1255 float spatial_metric, | 1252 float spatial_metric, |
| 1256 float spatial_metric_horiz, | 1253 float spatial_metric_horiz, |
| 1257 float spatial_metric_vert) { | 1254 float spatial_metric_vert) { |
| 1258 content_metrics_->motion_magnitude = motion_metric; | 1255 content_metrics_->motion_magnitude = motion_metric; |
| 1259 content_metrics_->spatial_pred_err = spatial_metric; | 1256 content_metrics_->spatial_pred_err = spatial_metric; |
| 1260 content_metrics_->spatial_pred_err_h = spatial_metric_horiz; | 1257 content_metrics_->spatial_pred_err_h = spatial_metric_horiz; |
| 1261 content_metrics_->spatial_pred_err_v = spatial_metric_vert; | 1258 content_metrics_->spatial_pred_err_v = spatial_metric_vert; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1274 void QmSelectTest::UpdateQmRateData(int* target_rate, | 1271 void QmSelectTest::UpdateQmRateData(int* target_rate, |
| 1275 int* encoder_sent_rate, | 1272 int* encoder_sent_rate, |
| 1276 int* incoming_frame_rate, | 1273 int* incoming_frame_rate, |
| 1277 uint8_t* fraction_lost, | 1274 uint8_t* fraction_lost, |
| 1278 int num_updates) { | 1275 int num_updates) { |
| 1279 for (int i = 0; i < num_updates; ++i) { | 1276 for (int i = 0; i < num_updates; ++i) { |
| 1280 float target_rate_update = target_rate[i]; | 1277 float target_rate_update = target_rate[i]; |
| 1281 float encoder_sent_rate_update = encoder_sent_rate[i]; | 1278 float encoder_sent_rate_update = encoder_sent_rate[i]; |
| 1282 float incoming_frame_rate_update = incoming_frame_rate[i]; | 1279 float incoming_frame_rate_update = incoming_frame_rate[i]; |
| 1283 uint8_t fraction_lost_update = fraction_lost[i]; | 1280 uint8_t fraction_lost_update = fraction_lost[i]; |
| 1284 qm_resolution_->UpdateRates(target_rate_update, | 1281 qm_resolution_->UpdateRates(target_rate_update, encoder_sent_rate_update, |
| 1285 encoder_sent_rate_update, | |
| 1286 incoming_frame_rate_update, | 1282 incoming_frame_rate_update, |
| 1287 fraction_lost_update); | 1283 fraction_lost_update); |
| 1288 } | 1284 } |
| 1289 } | 1285 } |
| 1290 | 1286 |
| 1291 // Check is the selected action from the QmResolution class is the same | 1287 // Check is the selected action from the QmResolution class is the same |
| 1292 // as the expected scales from |fac_width|, |fac_height|, |fac_temp|. | 1288 // as the expected scales from |fac_width|, |fac_height|, |fac_temp|. |
| 1293 bool QmSelectTest::IsSelectedActionCorrect(VCMResolutionScale* qm_scale, | 1289 bool QmSelectTest::IsSelectedActionCorrect(VCMResolutionScale* qm_scale, |
| 1294 float fac_width, | 1290 float fac_width, |
| 1295 float fac_height, | 1291 float fac_height, |
| 1296 float fac_temp, | 1292 float fac_temp, |
| 1297 uint16_t new_width, | 1293 uint16_t new_width, |
| 1298 uint16_t new_height, | 1294 uint16_t new_height, |
| 1299 float new_frame_rate) { | 1295 float new_frame_rate) { |
| 1300 if (qm_scale->spatial_width_fact == fac_width && | 1296 if (qm_scale->spatial_width_fact == fac_width && |
| 1301 qm_scale->spatial_height_fact == fac_height && | 1297 qm_scale->spatial_height_fact == fac_height && |
| 1302 qm_scale->temporal_fact == fac_temp && | 1298 qm_scale->temporal_fact == fac_temp && |
| 1303 qm_scale->codec_width == new_width && | 1299 qm_scale->codec_width == new_width && |
| 1304 qm_scale->codec_height == new_height && | 1300 qm_scale->codec_height == new_height && |
| 1305 qm_scale->frame_rate == new_frame_rate) { | 1301 qm_scale->frame_rate == new_frame_rate) { |
| 1306 return true; | 1302 return true; |
| 1307 } else { | 1303 } else { |
| 1308 return false; | 1304 return false; |
| 1309 } | 1305 } |
| 1310 } | 1306 } |
| 1311 } // namespace webrtc | 1307 } // namespace webrtc |
| OLD | NEW |