ba13db2
diff -Nrup -U 8 a/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc b/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc
ba13db2
--- a/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc	2020-02-18 02:37:58.000000000 +0300
ba13db2
+++ b/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.cc	2020-03-02 00:34:19.000000000 +0300
ba13db2
@@ -79,17 +79,19 @@ VP9EncoderImpl::VP9EncoderImpl()
ba13db2
       num_temporal_layers_(0),
ba13db2
       num_spatial_layers_(0),
ba13db2
       num_cores_(0),
ba13db2
       is_flexible_mode_(false),
ba13db2
       frames_encoded_(0),
ba13db2
       // Use two spatial when screensharing with flexible mode.
ba13db2
       spatial_layer_(new ScreenshareLayersVP9(2)) {
ba13db2
   memset(&codec_, 0, sizeof(codec_));
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   memset(&svc_params_, 0, sizeof(vpx_svc_extra_cfg_t));
ba13db2
+#endif
ba13db2
   uint32_t seed = rtc::Time32();
ba13db2
   srand(seed);
ba13db2
 }
ba13db2
 
ba13db2
 VP9EncoderImpl::~VP9EncoderImpl() {
ba13db2
   Release();
ba13db2
 }
ba13db2
 
ba13db2
@@ -115,55 +117,66 @@ int VP9EncoderImpl::Release() {
ba13db2
   }
ba13db2
   inited_ = false;
ba13db2
   return WEBRTC_VIDEO_CODEC_OK;
ba13db2
 }
ba13db2
 
ba13db2
 bool VP9EncoderImpl::ExplicitlyConfiguredSpatialLayers() const {
ba13db2
   // We check target_bitrate_bps of the 0th layer to see if the spatial layers
ba13db2
   // (i.e. bitrates) were explicitly configured.
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   return num_spatial_layers_ > 1 &&
ba13db2
          codec_.spatialLayers[0].target_bitrate_bps > 0;
ba13db2
+#else
ba13db2
+  return false;
ba13db2
+#endif
ba13db2
 }
ba13db2
 
ba13db2
 bool VP9EncoderImpl::SetSvcRates() {
ba13db2
   uint8_t i = 0;
ba13db2
 
ba13db2
   if (ExplicitlyConfiguredSpatialLayers()) {
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
     if (num_temporal_layers_ > 1) {
ba13db2
       LOG(LS_ERROR) << "Multiple temporal layers when manually specifying "
ba13db2
                        "spatial layers not implemented yet!";
ba13db2
       return false;
ba13db2
     }
ba13db2
     int total_bitrate_bps = 0;
ba13db2
     for (i = 0; i < num_spatial_layers_; ++i)
ba13db2
       total_bitrate_bps += codec_.spatialLayers[i].target_bitrate_bps;
ba13db2
     // If total bitrate differs now from what has been specified at the
ba13db2
     // beginning, update the bitrates in the same ratio as before.
ba13db2
     for (i = 0; i < num_spatial_layers_; ++i) {
ba13db2
       config_->ss_target_bitrate[i] = config_->layer_target_bitrate[i] =
ba13db2
           static_cast<int>(static_cast<int64_t>(config_->rc_target_bitrate) *
ba13db2
                            codec_.spatialLayers[i].target_bitrate_bps /
ba13db2
                            total_bitrate_bps);
ba13db2
     }
ba13db2
+#endif
ba13db2
   } else {
ba13db2
     float rate_ratio[VPX_MAX_LAYERS] = {0};
ba13db2
     float total = 0;
ba13db2
 
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
     for (i = 0; i < num_spatial_layers_; ++i) {
ba13db2
       if (svc_params_.scaling_factor_num[i] <= 0 ||
ba13db2
           svc_params_.scaling_factor_den[i] <= 0) {
ba13db2
         LOG(LS_ERROR) << "Scaling factors not specified!";
ba13db2
         return false;
ba13db2
       }
ba13db2
       rate_ratio[i] =
ba13db2
           static_cast<float>(svc_params_.scaling_factor_num[i]) /
ba13db2
           svc_params_.scaling_factor_den[i];
ba13db2
       total += rate_ratio[i];
ba13db2
     }
ba13db2
+#else
ba13db2
+    rate_ratio[0] = 1;
ba13db2
+    total = 1;
ba13db2
+#endif
ba13db2
 
ba13db2
     for (i = 0; i < num_spatial_layers_; ++i) {
ba13db2
       config_->ss_target_bitrate[i] = static_cast<unsigned int>(
ba13db2
           config_->rc_target_bitrate * rate_ratio[i] / total);
ba13db2
       if (num_temporal_layers_ == 1) {
ba13db2
         config_->layer_target_bitrate[i] = config_->ss_target_bitrate[i];
ba13db2
       } else if (num_temporal_layers_ == 2) {
ba13db2
         config_->layer_target_bitrate[i * num_temporal_layers_] =
ba13db2
@@ -390,16 +403,17 @@ int VP9EncoderImpl::NumberOfThreads(int
ba13db2
     return 2;
ba13db2
   } else {
ba13db2
     // 1 thread less than VGA.
ba13db2
     return 1;
ba13db2
   }
ba13db2
 }
ba13db2
 
ba13db2
 int VP9EncoderImpl::InitAndSetControlSettings(const VideoCodec* inst) {
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   // Set QP-min/max per spatial and temporal layer.
ba13db2
   int tot_num_layers = num_spatial_layers_ * num_temporal_layers_;
ba13db2
   for (int i = 0; i < tot_num_layers; ++i) {
ba13db2
     svc_params_.max_quantizers[i] = config_->rc_max_quantizer;
ba13db2
     svc_params_.min_quantizers[i] = config_->rc_min_quantizer;
ba13db2
   }
ba13db2
   config_->ss_number_layers = num_spatial_layers_;
ba13db2
   if (ExplicitlyConfiguredSpatialLayers()) {
ba13db2
@@ -413,37 +427,41 @@ int VP9EncoderImpl::InitAndSetControlSet
ba13db2
     for (int i = num_spatial_layers_ - 1; i >= 0; --i) {
ba13db2
       // 1:2 scaling in each dimension.
ba13db2
       svc_params_.scaling_factor_num[i] = scaling_factor_num;
ba13db2
       svc_params_.scaling_factor_den[i] = 256;
ba13db2
       if (codec_.mode != kScreensharing)
ba13db2
         scaling_factor_num /= 2;
ba13db2
     }
ba13db2
   }
ba13db2
+#endif
ba13db2
 
ba13db2
   if (!SetSvcRates()) {
ba13db2
     return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
ba13db2
   }
ba13db2
 
ba13db2
   if (vpx_codec_enc_init(encoder_, vpx_codec_vp9_cx(), config_, 0)) {
ba13db2
     return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
ba13db2
   }
ba13db2
   vpx_codec_control(encoder_, VP8E_SET_CPUUSED, cpu_speed_);
ba13db2
   vpx_codec_control(encoder_, VP8E_SET_MAX_INTRA_BITRATE_PCT,
ba13db2
                     rc_max_intra_target_);
ba13db2
   vpx_codec_control(encoder_, VP9E_SET_AQ_MODE,
ba13db2
                     inst->VP9().adaptiveQpMode ? 3 : 0);
ba13db2
 
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   vpx_codec_control(
ba13db2
       encoder_, VP9E_SET_SVC,
ba13db2
       (num_temporal_layers_ > 1 || num_spatial_layers_ > 1) ? 1 : 0);
ba13db2
   if (num_temporal_layers_ > 1 || num_spatial_layers_ > 1) {
ba13db2
     vpx_codec_control(encoder_, VP9E_SET_SVC_PARAMETERS,
ba13db2
                       &svc_params_);
ba13db2
   }
ba13db2
+#endif
ba13db2
+
ba13db2
   // Register callback for getting each spatial layer.
ba13db2
   vpx_codec_priv_output_cx_pkt_cb_pair_t cbp = {
ba13db2
       VP9EncoderImpl::EncoderOutputCodedPacketCallback,
ba13db2
       reinterpret_cast<void*>(this)};
ba13db2
   vpx_codec_control(encoder_, VP9E_REGISTER_CX_CALLBACK,
ba13db2
                     reinterpret_cast<void*>(&cbp));
ba13db2
 
ba13db2
   // Control function to set the number of column tiles in encoding a frame, in
ba13db2
@@ -527,16 +545,17 @@ int VP9EncoderImpl::Encode(const VideoFr
ba13db2
 
ba13db2
   vpx_enc_frame_flags_t flags = 0;
ba13db2
   bool send_keyframe = (frame_type == kVideoFrameKey);
ba13db2
   if (send_keyframe) {
ba13db2
     // Key frame request from caller.
ba13db2
     flags = VPX_EFLAG_FORCE_KF;
ba13db2
   }
ba13db2
 
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   if (is_flexible_mode_) {
ba13db2
     SuperFrameRefSettings settings;
ba13db2
 
ba13db2
     // These structs are copied when calling vpx_codec_control,
ba13db2
     // therefore it is ok for them to go out of scope.
ba13db2
     vpx_svc_ref_frame_config enc_layer_conf;
ba13db2
     vpx_svc_layer_id layer_id;
ba13db2
 
ba13db2
@@ -548,16 +567,17 @@ int VP9EncoderImpl::Encode(const VideoFr
ba13db2
                                                        send_keyframe);
ba13db2
     }
ba13db2
     enc_layer_conf = GenerateRefsAndFlags(settings);
ba13db2
     layer_id.temporal_layer_id = 0;
ba13db2
     layer_id.spatial_layer_id = settings.start_layer;
ba13db2
     vpx_codec_control(encoder_, VP9E_SET_SVC_LAYER_ID, &layer_id);
ba13db2
     vpx_codec_control(encoder_, VP9E_SET_SVC_REF_FRAME_CONFIG, &enc_layer_conf);
ba13db2
   }
ba13db2
+#endif
ba13db2
 
ba13db2
   assert(codec_.maxFramerate > 0);
ba13db2
   uint32_t duration = 90000 / codec_.maxFramerate;
ba13db2
   if (vpx_codec_encode(encoder_, raw_, timestamp_, duration, flags,
ba13db2
                        VPX_DL_REALTIME)) {
ba13db2
     return WEBRTC_VIDEO_CODEC_ERROR;
ba13db2
   }
ba13db2
   timestamp_ += duration;
ba13db2
@@ -686,29 +706,31 @@ void VP9EncoderImpl::PopulateCodecSpecif
ba13db2
       vp9_info->p_diff[i] = p_diff_[layer_id.spatial_layer_id][i];
ba13db2
     }
ba13db2
   } else {
ba13db2
     vp9_info->gof_idx =
ba13db2
         static_cast<uint8_t>(frames_since_kf_ % gof_.num_frames_in_gof);
ba13db2
     vp9_info->temporal_up_switch = gof_.temporal_up_switch[vp9_info->gof_idx];
ba13db2
   }
ba13db2
 
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   if (vp9_info->ss_data_available) {
ba13db2
     vp9_info->spatial_layer_resolution_present = true;
ba13db2
     for (size_t i = 0; i < vp9_info->num_spatial_layers; ++i) {
ba13db2
       vp9_info->width[i] = codec_.width *
ba13db2
                            svc_params_.scaling_factor_num[i] /
ba13db2
                            svc_params_.scaling_factor_den[i];
ba13db2
       vp9_info->height[i] = codec_.height *
ba13db2
                             svc_params_.scaling_factor_num[i] /
ba13db2
                             svc_params_.scaling_factor_den[i];
ba13db2
     }
ba13db2
-    if (!vp9_info->flexible_mode) {
ba13db2
-      vp9_info->gof.CopyGofInfoVP9(gof_);
ba13db2
-    }
ba13db2
+  }
ba13db2
+#endif
ba13db2
+  if (!vp9_info->flexible_mode) {
ba13db2
+    vp9_info->gof.CopyGofInfoVP9(gof_);
ba13db2
   }
ba13db2
 }
ba13db2
 
ba13db2
 int VP9EncoderImpl::GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt) {
ba13db2
   RTC_DCHECK_EQ(pkt->kind, VPX_CODEC_CX_FRAME_PKT);
ba13db2
 
ba13db2
   if (pkt->data.frame.sz > encoded_image_._size) {
ba13db2
     delete[] encoded_image_._buffer;
ba13db2
@@ -756,16 +778,17 @@ int VP9EncoderImpl::GetEncodedLayerFrame
ba13db2
     vpx_codec_control(encoder_, VP8E_GET_LAST_QUANTIZER, &qp);
ba13db2
     encoded_image_.qp_ = qp;
ba13db2
     encoded_complete_callback_->OnEncodedImage(encoded_image_, &codec_specific,
ba13db2
                                                &frag_info);
ba13db2
   }
ba13db2
   return WEBRTC_VIDEO_CODEC_OK;
ba13db2
 }
ba13db2
 
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
 vpx_svc_ref_frame_config VP9EncoderImpl::GenerateRefsAndFlags(
ba13db2
     const SuperFrameRefSettings& settings) {
ba13db2
   static const vpx_enc_frame_flags_t kAllFlags =
ba13db2
       VP8_EFLAG_NO_REF_ARF | VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_LAST |
ba13db2
       VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_GF;
ba13db2
   vpx_svc_ref_frame_config sf_conf = {};
ba13db2
   if (settings.is_keyframe) {
ba13db2
     // Used later on to make sure we don't make any invalid references.
ba13db2
@@ -857,16 +880,17 @@ vpx_svc_ref_frame_config VP9EncoderImpl:
ba13db2
         buffer_updated_at_frame_[updated_buffer] = frames_encoded_;
ba13db2
         sf_conf.frame_flags[layer_idx] = layer_flags;
ba13db2
       }
ba13db2
     }
ba13db2
   }
ba13db2
   ++frames_encoded_;
ba13db2
   return sf_conf;
ba13db2
 }
ba13db2
+#endif
ba13db2
 
ba13db2
 int VP9EncoderImpl::SetChannelParameters(uint32_t packet_loss, int64_t rtt) {
ba13db2
   return WEBRTC_VIDEO_CODEC_OK;
ba13db2
 }
ba13db2
 
ba13db2
 int VP9EncoderImpl::RegisterEncodeCompleteCallback(
ba13db2
     EncodedImageCallback* callback) {
ba13db2
   encoded_complete_callback_ = callback;
ba13db2
diff -Nrup -U 8 a/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.h b/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.h
ba13db2
--- a/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.h	2020-02-18 02:37:58.000000000 +0300
ba13db2
+++ b/media/webrtc/trunk/webrtc/modules/video_coding/codecs/vp9/vp9_impl.h	2020-03-02 00:32:05.000000000 +0300
ba13db2
@@ -77,24 +77,26 @@ class VP9EncoderImpl : public VP9Encoder
ba13db2
 
ba13db2
   void PopulateCodecSpecific(CodecSpecificInfo* codec_specific,
ba13db2
                              const vpx_codec_cx_pkt& pkt,
ba13db2
                              uint32_t timestamp);
ba13db2
 
ba13db2
   bool ExplicitlyConfiguredSpatialLayers() const;
ba13db2
   bool SetSvcRates();
ba13db2
 
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   // Used for flexible mode to set the flags and buffer references used
ba13db2
   // by the encoder. Also calculates the references used by the RTP
ba13db2
   // packetizer.
ba13db2
   //
ba13db2
   // Has to be called for every frame (keyframes included) to update the
ba13db2
   // state used to calculate references.
ba13db2
   vpx_svc_ref_frame_config GenerateRefsAndFlags(
ba13db2
       const SuperFrameRefSettings& settings);
ba13db2
+#endif
ba13db2
 
ba13db2
   virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt);
ba13db2
 
ba13db2
   // Callback function for outputting packets per spatial layer.
ba13db2
   static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt,
ba13db2
                                                void* user_data);
ba13db2
 
ba13db2
   // Determine maximum target for Intra frames
ba13db2
@@ -111,17 +113,19 @@ class VP9EncoderImpl : public VP9Encoder
ba13db2
   bool inited_;
ba13db2
   int64_t timestamp_;
ba13db2
   uint16_t picture_id_;
ba13db2
   int cpu_speed_;
ba13db2
   uint32_t rc_max_intra_target_;
ba13db2
   vpx_codec_ctx_t* encoder_;
ba13db2
   vpx_codec_enc_cfg_t* config_;
ba13db2
   vpx_image_t* raw_;
ba13db2
+#ifdef LIBVPX_SVC
ba13db2
   vpx_svc_extra_cfg_t svc_params_;
ba13db2
+#endif
ba13db2
   const VideoFrame* input_image_;
ba13db2
   GofInfoVP9 gof_;       // Contains each frame's temporal information for
ba13db2
                          // non-flexible mode.
ba13db2
   uint8_t tl0_pic_idx_;  // Only used in non-flexible mode.
ba13db2
   size_t frames_since_kf_;
ba13db2
   uint8_t num_temporal_layers_;
ba13db2
   uint8_t num_spatial_layers_;
ba13db2
   uint8_t num_cores_;