Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc

Issue 2833493003: Don't re-randomize picture_id/tl0_pic_idx when re-initializing internal encoders. (Closed)
Patch Set: Change back TimeMills() -> TimeMicros(). Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 */
11 11
12 #include "webrtc/modules/video_coding/codecs/vp9/vp9_impl.h" 12 #include "webrtc/modules/video_coding/codecs/vp9/vp9_impl.h"
13 13
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 #include <time.h> 16 #include <time.h>
17 #include <vector> 17 #include <vector>
18 18
19 #include "vpx/vpx_encoder.h" 19 #include "vpx/vpx_encoder.h"
20 #include "vpx/vpx_decoder.h" 20 #include "vpx/vpx_decoder.h"
21 #include "vpx/vp8cx.h" 21 #include "vpx/vp8cx.h"
22 #include "vpx/vp8dx.h" 22 #include "vpx/vp8dx.h"
23 23
24 #include "webrtc/base/checks.h" 24 #include "webrtc/base/checks.h"
25 #include "webrtc/base/timeutils.h"
26 #include "webrtc/base/keep_ref_until_done.h" 25 #include "webrtc/base/keep_ref_until_done.h"
27 #include "webrtc/base/logging.h" 26 #include "webrtc/base/logging.h"
27 #include "webrtc/base/random.h"
28 #include "webrtc/base/timeutils.h"
28 #include "webrtc/base/trace_event.h" 29 #include "webrtc/base/trace_event.h"
29 #include "webrtc/common_video/include/video_frame_buffer.h" 30 #include "webrtc/common_video/include/video_frame_buffer.h"
30 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 31 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
31 #include "webrtc/modules/include/module_common_types.h" 32 #include "webrtc/modules/include/module_common_types.h"
32 #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" 33 #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h"
33 34
34 namespace webrtc { 35 namespace webrtc {
35 36
36 // Only positive speeds, range for real-time coding currently is: 5 - 8. 37 // Only positive speeds, range for real-time coding currently is: 5 - 8.
37 // Lower means slower/better quality, higher means fastest/lower quality. 38 // Lower means slower/better quality, higher means fastest/lower quality.
(...skipping 22 matching lines...) Expand all
60 void* user_data) { 61 void* user_data) {
61 VP9EncoderImpl* enc = static_cast<VP9EncoderImpl*>(user_data); 62 VP9EncoderImpl* enc = static_cast<VP9EncoderImpl*>(user_data);
62 enc->GetEncodedLayerFrame(pkt); 63 enc->GetEncodedLayerFrame(pkt);
63 } 64 }
64 65
65 VP9EncoderImpl::VP9EncoderImpl() 66 VP9EncoderImpl::VP9EncoderImpl()
66 : encoded_image_(), 67 : encoded_image_(),
67 encoded_complete_callback_(NULL), 68 encoded_complete_callback_(NULL),
68 inited_(false), 69 inited_(false),
69 timestamp_(0), 70 timestamp_(0),
70 picture_id_(0),
71 cpu_speed_(3), 71 cpu_speed_(3),
72 rc_max_intra_target_(0), 72 rc_max_intra_target_(0),
73 encoder_(NULL), 73 encoder_(NULL),
74 config_(NULL), 74 config_(NULL),
75 raw_(NULL), 75 raw_(NULL),
76 input_image_(NULL), 76 input_image_(NULL),
77 tl0_pic_idx_(0),
78 frames_since_kf_(0), 77 frames_since_kf_(0),
79 num_temporal_layers_(0), 78 num_temporal_layers_(0),
80 num_spatial_layers_(0), 79 num_spatial_layers_(0),
81 is_flexible_mode_(false), 80 is_flexible_mode_(false),
82 frames_encoded_(0), 81 frames_encoded_(0),
83 // Use two spatial when screensharing with flexible mode. 82 // Use two spatial when screensharing with flexible mode.
84 spatial_layer_(new ScreenshareLayersVP9(2)) { 83 spatial_layer_(new ScreenshareLayersVP9(2)) {
85 memset(&codec_, 0, sizeof(codec_)); 84 memset(&codec_, 0, sizeof(codec_));
86 memset(&svc_params_, 0, sizeof(vpx_svc_extra_cfg_t)); 85 memset(&svc_params_, 0, sizeof(vpx_svc_extra_cfg_t));
87 uint32_t seed = rtc::Time32(); 86
88 srand(seed); 87 Random random(rtc::TimeMicros());
88 picture_id_ = random.Rand<uint16_t>() & 0x7FFF;
89 tl0_pic_idx_ = random.Rand<uint8_t>();
89 } 90 }
90 91
91 VP9EncoderImpl::~VP9EncoderImpl() { 92 VP9EncoderImpl::~VP9EncoderImpl() {
92 Release(); 93 Release();
93 } 94 }
94 95
95 int VP9EncoderImpl::Release() { 96 int VP9EncoderImpl::Release() {
96 if (encoded_image_._buffer != NULL) { 97 if (encoded_image_._buffer != NULL) {
97 delete[] encoded_image_._buffer; 98 delete[] encoded_image_._buffer;
98 encoded_image_._buffer = NULL; 99 encoded_image_._buffer = NULL;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (inst->VP9().numberOfSpatialLayers > 3) { 256 if (inst->VP9().numberOfSpatialLayers > 3) {
256 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 257 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
257 } 258 }
258 259
259 int ret_val = Release(); 260 int ret_val = Release();
260 if (ret_val < 0) { 261 if (ret_val < 0) {
261 return ret_val; 262 return ret_val;
262 } 263 }
263 if (encoder_ == NULL) { 264 if (encoder_ == NULL) {
264 encoder_ = new vpx_codec_ctx_t; 265 encoder_ = new vpx_codec_ctx_t;
265 // Only randomize pid/tl0 the first time the encoder is initialized
266 // in order to not make random jumps mid-stream.
267 picture_id_ = static_cast<uint16_t>(rand()) & 0x7FFF; // NOLINT
268 tl0_pic_idx_ = static_cast<uint8_t>(rand()); // NOLINT
269 } 266 }
270 if (config_ == NULL) { 267 if (config_ == NULL) {
271 config_ = new vpx_codec_enc_cfg_t; 268 config_ = new vpx_codec_enc_cfg_t;
272 } 269 }
273 timestamp_ = 0; 270 timestamp_ = 0;
274 if (&codec_ != inst) { 271 if (&codec_ != inst) {
275 codec_ = *inst; 272 codec_ = *inst;
276 } 273 }
277 274
278 num_spatial_layers_ = inst->VP9().numberOfSpatialLayers; 275 num_spatial_layers_ = inst->VP9().numberOfSpatialLayers;
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 frame_buffer_pool_.ClearPool(); 1006 frame_buffer_pool_.ClearPool();
1010 inited_ = false; 1007 inited_ = false;
1011 return WEBRTC_VIDEO_CODEC_OK; 1008 return WEBRTC_VIDEO_CODEC_OK;
1012 } 1009 }
1013 1010
1014 const char* VP9DecoderImpl::ImplementationName() const { 1011 const char* VP9DecoderImpl::ImplementationName() const {
1015 return "libvpx"; 1012 return "libvpx";
1016 } 1013 }
1017 1014
1018 } // namespace webrtc 1015 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698