OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (inst->VP9().numberOfSpatialLayers > 2) { | 249 if (inst->VP9().numberOfSpatialLayers > 2) { |
250 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 250 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
251 } | 251 } |
252 | 252 |
253 int ret_val = Release(); | 253 int ret_val = Release(); |
254 if (ret_val < 0) { | 254 if (ret_val < 0) { |
255 return ret_val; | 255 return ret_val; |
256 } | 256 } |
257 if (encoder_ == NULL) { | 257 if (encoder_ == NULL) { |
258 encoder_ = new vpx_codec_ctx_t; | 258 encoder_ = new vpx_codec_ctx_t; |
| 259 // Only randomize pid/tl0 the first time the encoder is initialized |
| 260 // in order to not make random jumps mid-stream. |
| 261 picture_id_ = static_cast<uint16_t>(rand()) & 0x7FFF; // NOLINT |
| 262 tl0_pic_idx_ = static_cast<uint8_t>(rand()); // NOLINT |
259 } | 263 } |
260 if (config_ == NULL) { | 264 if (config_ == NULL) { |
261 config_ = new vpx_codec_enc_cfg_t; | 265 config_ = new vpx_codec_enc_cfg_t; |
262 } | 266 } |
263 timestamp_ = 0; | 267 timestamp_ = 0; |
264 if (&codec_ != inst) { | 268 if (&codec_ != inst) { |
265 codec_ = *inst; | 269 codec_ = *inst; |
266 } | 270 } |
267 | 271 |
268 num_spatial_layers_ = inst->VP9().numberOfSpatialLayers; | 272 num_spatial_layers_ = inst->VP9().numberOfSpatialLayers; |
269 num_temporal_layers_ = inst->VP9().numberOfTemporalLayers; | 273 num_temporal_layers_ = inst->VP9().numberOfTemporalLayers; |
270 if (num_temporal_layers_ == 0) | 274 if (num_temporal_layers_ == 0) |
271 num_temporal_layers_ = 1; | 275 num_temporal_layers_ = 1; |
272 | 276 |
273 // Random start 16 bits is enough. | |
274 picture_id_ = static_cast<uint16_t>(rand()) & 0x7FFF; // NOLINT | |
275 // Allocate memory for encoded image | 277 // Allocate memory for encoded image |
276 if (encoded_image_._buffer != NULL) { | 278 if (encoded_image_._buffer != NULL) { |
277 delete[] encoded_image_._buffer; | 279 delete[] encoded_image_._buffer; |
278 } | 280 } |
279 encoded_image_._size = CalcBufferSize(kI420, codec_.width, codec_.height); | 281 encoded_image_._size = CalcBufferSize(kI420, codec_.width, codec_.height); |
280 encoded_image_._buffer = new uint8_t[encoded_image_._size]; | 282 encoded_image_._buffer = new uint8_t[encoded_image_._size]; |
281 encoded_image_._completeFrame = true; | 283 encoded_image_._completeFrame = true; |
282 // Creating a wrapper to the image - setting image data to NULL. Actual | 284 // Creating a wrapper to the image - setting image data to NULL. Actual |
283 // pointer will be set in encode. Setting align to 1, as it is meaningless | 285 // pointer will be set in encode. Setting align to 1, as it is meaningless |
284 // (actual memory is not allocated). | 286 // (actual memory is not allocated). |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 config_->ts_rate_decimator[2] = 1; | 361 config_->ts_rate_decimator[2] = 1; |
360 config_->ts_periodicity = 4; | 362 config_->ts_periodicity = 4; |
361 config_->ts_layer_id[0] = 0; | 363 config_->ts_layer_id[0] = 0; |
362 config_->ts_layer_id[1] = 2; | 364 config_->ts_layer_id[1] = 2; |
363 config_->ts_layer_id[2] = 1; | 365 config_->ts_layer_id[2] = 1; |
364 config_->ts_layer_id[3] = 2; | 366 config_->ts_layer_id[3] = 2; |
365 } else { | 367 } else { |
366 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 368 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
367 } | 369 } |
368 | 370 |
369 tl0_pic_idx_ = static_cast<uint8_t>(rand()); // NOLINT | |
370 | |
371 return InitAndSetControlSettings(inst); | 371 return InitAndSetControlSettings(inst); |
372 } | 372 } |
373 | 373 |
374 int VP9EncoderImpl::NumberOfThreads(int width, | 374 int VP9EncoderImpl::NumberOfThreads(int width, |
375 int height, | 375 int height, |
376 int number_of_cores) { | 376 int number_of_cores) { |
377 // Keep the number of encoder threads equal to the possible number of column | 377 // Keep the number of encoder threads equal to the possible number of column |
378 // tiles, which is (1, 2, 4, 8). See comments below for VP9E_SET_TILE_COLUMNS. | 378 // tiles, which is (1, 2, 4, 8). See comments below for VP9E_SET_TILE_COLUMNS. |
379 if (width * height >= 1280 * 720 && number_of_cores > 4) { | 379 if (width * height >= 1280 * 720 && number_of_cores > 4) { |
380 return 4; | 380 return 4; |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 frame_buffer_pool_.ClearPool(); | 994 frame_buffer_pool_.ClearPool(); |
995 inited_ = false; | 995 inited_ = false; |
996 return WEBRTC_VIDEO_CODEC_OK; | 996 return WEBRTC_VIDEO_CODEC_OK; |
997 } | 997 } |
998 | 998 |
999 const char* VP9DecoderImpl::ImplementationName() const { | 999 const char* VP9DecoderImpl::ImplementationName() const { |
1000 return "libvpx"; | 1000 return "libvpx"; |
1001 } | 1001 } |
1002 | 1002 |
1003 } // namespace webrtc | 1003 } // namespace webrtc |
OLD | NEW |