modules/video_coding/codec_database.cc
// Assuming only one registered encoder - since only one used, no need for more.
Assuming only one registered encoder - since only one used, no need for more.
Assuming only one registered encoder - since only one used no need for more .
bool VCMCodecDataBase::SetSendCodec(const VideoCodec* send_codec,
                                    int number_of_cores,
                                    size_t max_payload_size) {
  RTC_DCHECK(send_codec);
  if (max_payload_size == 0) {
    max_payload_size = kDefaultPayloadSize;
  }
  RTC_DCHECK_GE(number_of_cores, 1);
  RTC_DCHECK_GE(send_codec->plType, 1);
  RTC_DCHECK_LE(send_codec->startBitrate, 1000000u);
  RTC_DCHECK(send_codec->codecType != kVideoCodecUnknown);
  bool reset_required = pending_encoder_reset_;
  if (number_of_cores_ != number_of_cores) {
    number_of_cores_ = number_of_cores;
    reset_required = true;
  }
  if (max_payload_size_ != max_payload_size) {
    max_payload_size_ = max_payload_size;
    reset_required = true;
  }
  VideoCodec new_send_codec;
  memcpy(&new_send_codec, send_codec, sizeof(new_send_codec));
  if (new_send_codec.maxBitrate == 0) {
    new_send_codec.maxBitrate = (static_cast<int>(send_codec->height) *
        static_cast<int>(send_codec->width) *
        static_cast<int>(send_codec->maxFramerate)) / 1000;
    if (send_codec->startBitrate > new_send_codec.maxBitrate) {
      new_send_codec.maxBitrate = send_codec->startBitrate;
    }
  }
  if (new_send_codec.startBitrate > new_send_codec.maxBitrate)
    new_send_codec.startBitrate = new_send_codec.maxBitrate;
  if (!reset_required) {
    reset_required = RequiresEncoderReset(new_send_codec);
  }
  memcpy(&send_codec_, &new_send_codec, sizeof(send_codec_));
  if (!reset_required) {
    encoded_frame_callback_->SetPayloadType(send_codec_.plType);
    return true;
  }
  DeleteEncoder();
  RTC_DCHECK_EQ(encoder_payload_type_, send_codec_.plType)
      << "Encoder not registered for payload type " << send_codec_.plType;
  ptr_encoder_.reset(
      new VCMGenericEncoder(external_encoder_, encoder_rate_observer_,
                            encoded_frame_callback_, internal_source_));
  encoded_frame_callback_->SetPayloadType(send_codec_.plType);
  encoded_frame_callback_->SetInternalSource(internal_source_);
  if (ptr_encoder_->InitEncode(&send_codec_, number_of_cores_,
                               max_payload_size_) < 0) {
    LOG(LS_ERROR) << "Failed to initialize video encoder.";
    DeleteEncoder();
    return false;
  }
  ptr_encoder_->SetPeriodicKeyFrames(periodic_key_frames_);
  pending_encoder_reset_ = false;
  return true;
}
bool VCMCodecDataBase :: SetSendCodec ( const VideoCodec * send_codec , int number_of_cores , size_t max_payload_size ) { RTC_DCHECK ( send_codec ) ; if ( max_payload_size == 0 ) { max_payload_size = kDefaultPayloadSize ; } RTC_DCHECK_GE ( number_of_cores , 1 ) ; RTC_DCHECK_GE ( send_codec -> plType , 1 ) ; RTC_DCHECK_LE ( send_codec -> startBitrate , 1000000u ) ; RTC_DCHECK ( send_codec -> codecType != kVideoCodecUnknown ) ; bool reset_required = pending_encoder_reset_ ; if ( number_of_cores_ != number_of_cores ) { number_of_cores_ = number_of_cores ; reset_required = true ; } if ( max_payload_size_ != max_payload_size ) { max_payload_size_ = max_payload_size ; reset_required = true ; } VideoCodec new_send_codec ; memcpy ( & new_send_codec , send_codec , sizeof ( new_send_codec ) ) ; if ( new_send_codec . maxBitrate == 0 ) { new_send_codec . maxBitrate = ( static_cast < int > ( send_codec -> height ) * static_cast < int > ( send_codec -> width ) * static_cast < int > ( send_codec -> maxFramerate ) ) / 1000 ; if ( send_codec -> startBitrate > new_send_codec . maxBitrate ) { new_send_codec . maxBitrate = send_codec -> startBitrate ; } } if ( new_send_codec . startBitrate > new_send_codec . maxBitrate ) new_send_codec . startBitrate = new_send_codec . maxBitrate ; if ( ! reset_required ) { reset_required = RequiresEncoderReset ( new_send_codec ) ; } memcpy ( & send_codec_ , & new_send_codec , sizeof ( send_codec_ ) ) ; if ( ! reset_required ) { encoded_frame_callback_ -> SetPayloadType ( send_codec_ . plType ) ; return true ; } DeleteEncoder ( ) ; RTC_DCHECK_EQ ( encoder_payload_type_ , send_codec_ . plType ) << " " << send_codec_ . plType ; ptr_encoder_ . reset ( new VCMGenericEncoder ( external_encoder_ , encoder_rate_observer_ , encoded_frame_callback_ , internal_source_ ) ) ; encoded_frame_callback_ -> SetPayloadType ( send_codec_ . plType ) ; encoded_frame_callback_ -> SetInternalSource ( internal_source_ ) ; if ( ptr_encoder_ -> InitEncode ( & send_codec_ , number_of_cores_ , max_payload_size_ ) < 0 ) { LOG ( LS_ERROR ) << " " ; DeleteEncoder ( ) ; return false ; } ptr_encoder_ -> SetPeriodicKeyFrames ( periodic_key_frames_ ) ; pending_encoder_reset_ = false ; return true ; }
Assuming only one registered encoder - since only one used, no need for more.
Assuming only one registered encoder - since only one used no need for more .
// Make sure the start bit rate is sane... // max is one bit per pixel // But if the user tries to set a higher start bit rate we will // increase the max accordingly. // If encoder exists, will destroy it and create new one. // Intentionally don't check return value since the encoder registration // shouldn't fail because the codec doesn't support changing the periodic key // frame setting.