diff --git a/webrtc/common_types.cc b/webrtc/common_types.cc index a76175fbd9..82307ce52b 100644 --- a/webrtc/common_types.cc +++ b/webrtc/common_types.cc @@ -132,43 +132,50 @@ static bool CodecNamesEq(const char* name1, const char* name2) { return _stricmp(name1, name2) == 0; } -rtc::Optional CodecTypeToPayloadName(VideoCodecType type) { +const char* CodecTypeToPayloadString(VideoCodecType type) { switch (type) { case kVideoCodecVP8: - return rtc::Optional(kPayloadNameVp8); + return kPayloadNameVp8; case kVideoCodecVP9: - return rtc::Optional(kPayloadNameVp9); + return kPayloadNameVp9; case kVideoCodecH264: - return rtc::Optional(kPayloadNameH264); + return kPayloadNameH264; case kVideoCodecI420: - return rtc::Optional(kPayloadNameI420); + return kPayloadNameI420; case kVideoCodecRED: - return rtc::Optional(kPayloadNameRED); + return kPayloadNameRED; case kVideoCodecULPFEC: - return rtc::Optional(kPayloadNameULPFEC); - case kVideoCodecGeneric: - return rtc::Optional(kPayloadNameGeneric); + return kPayloadNameULPFEC; default: - return rtc::Optional(); + // Unrecognized codecs default to generic. + return kPayloadNameGeneric; } } -rtc::Optional PayloadNameToCodecType(const std::string& name) { +VideoCodecType PayloadStringToCodecType(const std::string& name) { if (CodecNamesEq(name.c_str(), kPayloadNameVp8)) - return rtc::Optional(kVideoCodecVP8); + return kVideoCodecVP8; if (CodecNamesEq(name.c_str(), kPayloadNameVp9)) - return rtc::Optional(kVideoCodecVP9); + return kVideoCodecVP9; if (CodecNamesEq(name.c_str(), kPayloadNameH264)) - return rtc::Optional(kVideoCodecH264); + return kVideoCodecH264; if (CodecNamesEq(name.c_str(), kPayloadNameI420)) - return rtc::Optional(kVideoCodecI420); + return kVideoCodecI420; if (CodecNamesEq(name.c_str(), kPayloadNameRED)) - return rtc::Optional(kVideoCodecRED); + return kVideoCodecRED; if (CodecNamesEq(name.c_str(), kPayloadNameULPFEC)) - return rtc::Optional(kVideoCodecULPFEC); - if (CodecNamesEq(name.c_str(), kPayloadNameGeneric)) - return rtc::Optional(kVideoCodecGeneric); - return rtc::Optional(); + return kVideoCodecULPFEC; + return kVideoCodecGeneric; +} + +// TODO(kthelgason): Remove these methods once upstream projects +// have been updated. +rtc::Optional CodecTypeToPayloadName(VideoCodecType type) { + return rtc::Optional(CodecTypeToPayloadString(type)); +} + +rtc::Optional PayloadNameToCodecType(const std::string& name) { + return rtc::Optional(PayloadStringToCodecType(name)); } const uint32_t BitrateAllocation::kMaxBitrateBps = diff --git a/webrtc/common_types.h b/webrtc/common_types.h index dc62b632a1..ecfa15d2c9 100644 --- a/webrtc/common_types.h +++ b/webrtc/common_types.h @@ -537,6 +537,10 @@ enum VideoCodecType { }; // Translates from name of codec to codec type and vice versa. +const char* CodecTypeToPayloadString(VideoCodecType type); +VideoCodecType PayloadStringToCodecType(const std::string& name); +// TODO(kthelgason): Remove these methods once upstream projects +// have been updated. rtc::Optional CodecTypeToPayloadName(VideoCodecType type); rtc::Optional PayloadNameToCodecType(const std::string& name); diff --git a/webrtc/media/engine/internalencoderfactory.cc b/webrtc/media/engine/internalencoderfactory.cc index a8d4f2d2c2..004db79160 100644 --- a/webrtc/media/engine/internalencoderfactory.cc +++ b/webrtc/media/engine/internalencoderfactory.cc @@ -71,8 +71,7 @@ InternalEncoderFactory::~InternalEncoderFactory() {} webrtc::VideoEncoder* InternalEncoderFactory::CreateVideoEncoder( const cricket::VideoCodec& codec) { const webrtc::VideoCodecType codec_type = - webrtc::PayloadNameToCodecType(codec.name) - .value_or(webrtc::kVideoCodecUnknown); + webrtc::PayloadStringToCodecType(codec.name); switch (codec_type) { case webrtc::kVideoCodecH264: return webrtc::H264Encoder::Create(codec); diff --git a/webrtc/media/engine/videoencodersoftwarefallbackwrapper.cc b/webrtc/media/engine/videoencodersoftwarefallbackwrapper.cc index 540597838a..8dbf5d1837 100644 --- a/webrtc/media/engine/videoencodersoftwarefallbackwrapper.cc +++ b/webrtc/media/engine/videoencodersoftwarefallbackwrapper.cc @@ -27,8 +27,7 @@ bool EnableForcedFallback(const cricket::VideoCodec& codec) { if (!webrtc::field_trial::IsEnabled(kVp8ForceFallbackEncoderFieldTrial)) return false; - return (PayloadNameToCodecType(codec.name).value_or(kVideoCodecUnknown) == - kVideoCodecVP8); + return (PayloadStringToCodecType(codec.name) == kVideoCodecVP8); } bool IsForcedFallbackPossible(const VideoCodec& codec_settings) { diff --git a/webrtc/media/engine/webrtcvideoengine.cc b/webrtc/media/engine/webrtcvideoengine.cc index bf128c87b5..8a23ae8b44 100644 --- a/webrtc/media/engine/webrtcvideoengine.cc +++ b/webrtc/media/engine/webrtcvideoengine.cc @@ -1730,8 +1730,7 @@ void WebRtcVideoChannel::WebRtcVideoSendStream::SetCodec( parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; if (new_encoder.external) { webrtc::VideoCodecType type = - webrtc::PayloadNameToCodecType(codec_settings.codec.name) - .value_or(webrtc::kVideoCodecUnknown); + webrtc::PayloadStringToCodecType(codec_settings.codec.name); parameters_.config.encoder_settings.internal_source = external_encoder_factory_->EncoderTypeHasInternalSource(type); } else { @@ -2175,8 +2174,7 @@ WebRtcVideoChannel::WebRtcVideoReceiveStream::AllocatedDecoder WebRtcVideoChannel::WebRtcVideoReceiveStream::CreateOrReuseVideoDecoder( std::vector* old_decoders, const VideoCodec& codec) { - webrtc::VideoCodecType type = webrtc::PayloadNameToCodecType(codec.name) - .value_or(webrtc::kVideoCodecUnknown); + webrtc::VideoCodecType type = webrtc::PayloadStringToCodecType(codec.name); for (size_t i = 0; i < old_decoders->size(); ++i) { if ((*old_decoders)[i].type == type) { diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc index 52f8d7c225..5ebe836724 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc @@ -49,7 +49,7 @@ std::unique_ptr CreateBitrateAllocator( void PrintCodecSettings(const VideoCodec& codec_settings) { printf(" Codec settings:\n"); printf(" Codec type : %s\n", - CodecTypeToPayloadName(codec_settings.codecType).value_or("Unknown")); + CodecTypeToPayloadString(codec_settings.codecType)); printf(" Start bitrate : %d kbps\n", codec_settings.startBitrate); printf(" Max bitrate : %d kbps\n", codec_settings.maxBitrate); printf(" Min bitrate : %d kbps\n", codec_settings.minBitrate); @@ -189,8 +189,7 @@ void VideoProcessor::Init() { printf(" Decoder implementation name: %s\n", decoder_name); if (strcmp(encoder_name, decoder_name) == 0) { printf(" Codec implementation name : %s_%s\n", - CodecTypeToPayloadName(config_.codec_settings.codecType) - .value_or("Unknown"), + CodecTypeToPayloadString(config_.codec_settings.codecType), encoder_->ImplementationName()); } PrintCodecSettings(config_.codec_settings); diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h index 8bcc53d6d5..e47df371f6 100644 --- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h +++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.h @@ -199,8 +199,7 @@ class VideoProcessorIntegrationTest : public testing::Test { if (visualization_params) { const std::string codec_name = - CodecTypeToPayloadName(config_.codec_settings.codecType) - .value_or("unknown"); + CodecTypeToPayloadString(config_.codec_settings.codecType); const std::string implementation_type = config_.hw_codec ? "hw" : "sw"; // clang-format off const std::string output_filename_base = diff --git a/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc b/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc index 90ddcfee02..48929b9df9 100644 --- a/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc +++ b/webrtc/modules/video_coding/codecs/tools/video_quality_measurement.cc @@ -411,8 +411,7 @@ void PrintPythonOutput(const webrtc::test::TestConfig& config, ExcludeFrameTypesToStr(config.exclude_frame_types), config.frame_length_in_bytes, config.use_single_core ? "True " : "False", config.keyframe_interval, - CodecTypeToPayloadName(config.codec_settings.codecType) - .value_or("Unknown"), + CodecTypeToPayloadString(config.codec_settings.codecType), config.codec_settings.width, config.codec_settings.height, config.codec_settings.startBitrate); printf( diff --git a/webrtc/modules/video_coding/packet.cc b/webrtc/modules/video_coding/packet.cc index 22ef7aeebc..7bc4d94603 100644 --- a/webrtc/modules/video_coding/packet.cc +++ b/webrtc/modules/video_coding/packet.cc @@ -134,6 +134,8 @@ void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader) { codec = kVideoCodecH264; return; case kRtpVideoGeneric: + codec = kVideoCodecGeneric; + return; case kRtpVideoNone: codec = kVideoCodecUnknown; return; diff --git a/webrtc/modules/video_coding/utility/ivf_file_writer.cc b/webrtc/modules/video_coding/utility/ivf_file_writer.cc index ce3919d7ef..78e956aacd 100644 --- a/webrtc/modules/video_coding/utility/ivf_file_writer.cc +++ b/webrtc/modules/video_coding/utility/ivf_file_writer.cc @@ -123,7 +123,7 @@ bool IvfFileWriter::InitFromFirstFrame(const EncodedImage& encoded_image, return false; const char* codec_name = - CodecTypeToPayloadName(codec_type_).value_or("Unknown"); + CodecTypeToPayloadString(codec_type_); LOG(LS_WARNING) << "Created IVF file for codec data of type " << codec_name << " at resolution " << width_ << " x " << height_ << ", using " << (using_capture_timestamps_ ? "1" : "90") diff --git a/webrtc/modules/video_coding/video_codec_initializer.cc b/webrtc/modules/video_coding/video_codec_initializer.cc index df8f136541..d274bf16a7 100644 --- a/webrtc/modules/video_coding/video_codec_initializer.cc +++ b/webrtc/modules/video_coding/video_codec_initializer.cc @@ -104,8 +104,7 @@ VideoCodec VideoCodecInitializer::VideoEncoderConfigToVideoCodec( VideoCodec video_codec; memset(&video_codec, 0, sizeof(video_codec)); - video_codec.codecType = PayloadNameToCodecType(payload_name) - .value_or(VideoCodecType::kVideoCodecGeneric); + video_codec.codecType = PayloadStringToCodecType(payload_name); switch (config.content_type) { case VideoEncoderConfig::ContentType::kRealtimeVideo: diff --git a/webrtc/sdk/android/src/jni/androidmediaencoder_jni.cc b/webrtc/sdk/android/src/jni/androidmediaencoder_jni.cc index 78fd0757e1..0aa5a5112c 100644 --- a/webrtc/sdk/android/src/jni/androidmediaencoder_jni.cc +++ b/webrtc/sdk/android/src/jni/androidmediaencoder_jni.cc @@ -553,8 +553,7 @@ int32_t MediaCodecVideoEncoder::ProcessHWErrorOnEncode() { } VideoCodecType MediaCodecVideoEncoder::GetCodecType() const { - return webrtc::PayloadNameToCodecType(codec_.name) - .value_or(webrtc::kVideoCodecUnknown); + return webrtc::PayloadStringToCodecType(codec_.name); } int32_t MediaCodecVideoEncoder::InitEncodeInternal(int width, diff --git a/webrtc/sdk/android/src/jni/videodecoderfactorywrapper.cc b/webrtc/sdk/android/src/jni/videodecoderfactorywrapper.cc index 678dc3d485..4e825ada10 100644 --- a/webrtc/sdk/android/src/jni/videodecoderfactorywrapper.cc +++ b/webrtc/sdk/android/src/jni/videodecoderfactorywrapper.cc @@ -30,10 +30,8 @@ webrtc::VideoDecoder* VideoDecoderFactoryWrapper::CreateVideoDecoder( webrtc::VideoCodecType type) { JNIEnv* jni = AttachCurrentThreadIfNeeded(); ScopedLocalRefFrame local_ref_frame(jni); - rtc::Optional type_payload = - webrtc::CodecTypeToPayloadName(type); - RTC_DCHECK(type_payload); - jstring name = jni->NewStringUTF(*type_payload); + const char* type_payload = webrtc::CodecTypeToPayloadString(type); + jstring name = jni->NewStringUTF(type_payload); jobject decoder = jni->CallObjectMethod(*decoder_factory_, create_decoder_method_, name); return decoder != nullptr ? new VideoDecoderWrapper(jni, decoder) : nullptr; diff --git a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoEncoderSettings.mm b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoEncoderSettings.mm index af82e0c4f2..0fb8e46f2e 100644 --- a/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoEncoderSettings.mm +++ b/webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCVideoEncoderSettings.mm @@ -30,10 +30,8 @@ - (instancetype)initWithNativeVideoCodec:(const webrtc::VideoCodec *)videoCodec { if (self = [super init]) { if (videoCodec) { - rtc::Optional codecName = CodecTypeToPayloadName(videoCodec->codecType); - if (codecName) { - _name = [NSString stringWithUTF8String:codecName.value()]; - } + const char *codecName = CodecTypeToPayloadString(videoCodec->codecType); + _name = [NSString stringWithUTF8String:codecName]; _width = videoCodec->width; _height = videoCodec->height; diff --git a/webrtc/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm b/webrtc/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm index 5a1a51f3f5..9d4f2b8e0a 100644 --- a/webrtc/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm +++ b/webrtc/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm @@ -104,13 +104,9 @@ id ObjCVideoDecoderFactory::wrapped_decoder_factory() co } VideoDecoder *ObjCVideoDecoderFactory::CreateVideoDecoder(VideoCodecType type) { - const rtc::Optional codec_name = CodecTypeToPayloadName(type); - if (!codec_name) { - LOG(LS_ERROR) << "Invalid codec type: " << type; - return nullptr; - } + const char *codec_name = CodecTypeToPayloadString(type); - NSString *codecName = [NSString stringWithUTF8String:codec_name.value()]; + NSString *codecName = [NSString stringWithUTF8String:codec_name]; for (RTCVideoCodecInfo *codecInfo in decoder_factory_.supportedCodecs) { if ([codecName isEqualToString:codecInfo.name]) { id decoder = [decoder_factory_ createDecoder:codecInfo]; diff --git a/webrtc/video/send_statistics_proxy.cc b/webrtc/video/send_statistics_proxy.cc index a6f421ae04..3b97343522 100644 --- a/webrtc/video/send_statistics_proxy.cc +++ b/webrtc/video/send_statistics_proxy.cc @@ -50,12 +50,8 @@ const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { HistogramCodecType PayloadNameToHistogramCodecType( const std::string& payload_name) { - rtc::Optional codecType = - PayloadNameToCodecType(payload_name); - if (!codecType) { - return kVideoUnknown; - } - switch (*codecType) { + VideoCodecType codecType = PayloadStringToCodecType(payload_name); + switch (codecType) { case kVideoCodecVP8: return kVideoVp8; case kVideoCodecVP9: diff --git a/webrtc/video/video_receive_stream.cc b/webrtc/video/video_receive_stream.cc index 56264d9b1f..ae14634a94 100644 --- a/webrtc/video/video_receive_stream.cc +++ b/webrtc/video/video_receive_stream.cc @@ -47,8 +47,7 @@ VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) { codec.plType = decoder.payload_type; strncpy(codec.plName, decoder.payload_name.c_str(), sizeof(codec.plName)); - codec.codecType = - PayloadNameToCodecType(decoder.payload_name).value_or(kVideoCodecGeneric); + codec.codecType = PayloadStringToCodecType(decoder.payload_name); if (codec.codecType == kVideoCodecVP8) { *(codec.VP8()) = VideoEncoder::GetDefaultVp8Settings(); diff --git a/webrtc/video/video_send_stream.cc b/webrtc/video/video_send_stream.cc index 28ef0038c0..ce1eb2f0fb 100644 --- a/webrtc/video/video_send_stream.cc +++ b/webrtc/video/video_send_stream.cc @@ -148,15 +148,10 @@ std::unique_ptr MaybeCreateFlexfecSender( namespace { bool PayloadTypeSupportsSkippingFecPackets(const std::string& payload_name) { - rtc::Optional codecType = - PayloadNameToCodecType(payload_name); - if (codecType && - (*codecType == kVideoCodecVP8 || *codecType == kVideoCodecVP9)) { + const VideoCodecType codecType = PayloadStringToCodecType(payload_name); + if (codecType == kVideoCodecVP8 || codecType == kVideoCodecVP9) { return true; } - RTC_DCHECK((codecType && *codecType == kVideoCodecH264) || - payload_name == "FAKE") - << "unknown payload_name " << payload_name; return false; } diff --git a/webrtc/video/video_stream_encoder.cc b/webrtc/video/video_stream_encoder.cc index 7e25df09b4..52dcbf0832 100644 --- a/webrtc/video/video_stream_encoder.cc +++ b/webrtc/video/video_stream_encoder.cc @@ -387,8 +387,7 @@ VideoStreamEncoder::VideoStreamEncoder(uint32_t number_of_cores, source_proxy_(new VideoSourceProxy(this)), sink_(nullptr), settings_(settings), - codec_type_(PayloadNameToCodecType(settings.payload_name) - .value_or(VideoCodecType::kVideoCodecUnknown)), + codec_type_(PayloadStringToCodecType(settings.payload_name)), video_sender_(Clock::GetRealTimeClock(), this, this), overuse_detector_( overuse_detector.get()