diff --git a/dom/media/platforms/EncoderConfig.h b/dom/media/platforms/EncoderConfig.h index 26030d90df54e..fb0fefc7f6569 100644 --- a/dom/media/platforms/EncoderConfig.h +++ b/dom/media/platforms/EncoderConfig.h @@ -303,6 +303,26 @@ aFormat } } ; +enum +class +OpusBitstreamFormat +{ +Opus +OGG +} +; +/ +/ +The +default +values +come +from +the +Web +Codecs +specification +. struct OpusSpecific final @@ -311,26 +331,65 @@ enum class Application { +Unspecified Voip Audio RestricedLowDelay } ; -enum -class -OpusBitstreamFormat -{ -Opus -OGG -} +Application +mApplication += +Application +: +: +Unspecified ; -enum -class +uint64_t +mFrameDuration += +20000 +; +/ +/ +microseconds +uint8_t +mComplexity += +10 +; +/ +/ +0 +- +10 OpusBitstreamFormat -{ +mFormat += +OpusBitstreamFormat +: +: Opus -OGG -} +; +uint64_t +mPacketLossPerc += +0 +; +/ +/ +0 +- +100 +bool +mUseInBandFEC += +false +; +bool +mUseDTX += +false ; } ; diff --git a/dom/media/platforms/ffmpeg/FFmpegAudioEncoder.cpp b/dom/media/platforms/ffmpeg/FFmpegAudioEncoder.cpp index d08157e191c12..9243f21d6c7c1 100644 --- a/dom/media/platforms/ffmpeg/FFmpegAudioEncoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegAudioEncoder.cpp @@ -913,6 +913,356 @@ off ) ; } +if +( +mConfig +. +mCodecSpecific +. +isSome +( +) +) +{ +MOZ_ASSERT +( +mConfig +. +mCodecSpecific +- +> +is +< +OpusSpecific +> +( +) +) +; +const +OpusSpecific +& +specific += +mConfig +. +mCodecSpecific +- +> +as +< +OpusSpecific +> +( +) +; +/ +/ +This +attribute +maps +directly +to +complexity +mCodecContext +- +> +compression_level += +specific +. +mComplexity +; +FFMPEG_LOG +( +" +Opus +complexity +set +to +% +d +" +specific +. +mComplexity +) +; +float +frameDurationMs += +AssertedCast +< +float +> +( +specific +. +mFrameDuration +) +/ +1000 +. +f +; +if +( +mLib +- +> +av_opt_set_double +( +mCodecContext +- +> +priv_data +" +frame_duration +" +frameDurationMs +0 +) +) +{ +FFMPEG_LOG +( +" +Error +setting +the +frame +duration +on +Opus +encoder +" +) +; +return +NS_ERROR_FAILURE +; +} +FFMPEG_LOG +( +" +Opus +frame +duration +set +to +% +0 +. +2f +" +frameDurationMs +) +; +if +( +specific +. +mPacketLossPerc +) +{ +if +( +mLib +- +> +av_opt_set_int +( +mCodecContext +- +> +priv_data +" +packet_loss +" +AssertedCast +< +int64_t +> +( +specific +. +mPacketLossPerc +) +0 +) +) +{ +FFMPEG_LOG +( +" +Error +setting +the +packet +loss +percentage +to +% +" +PRIu64 +" +on +Opus +encoder +" +specific +. +mPacketLossPerc +) +; +return +NS_ERROR_FAILURE +; +} +FFMPEG_LOGV +( +" +Packet +loss +set +to +% +d +% +% +in +Opus +encoder +" +AssertedCast +< +int +> +( +specific +. +mPacketLossPerc +) +) +; +} +if +( +specific +. +mUseInBandFEC +) +{ +if +( +mLib +- +> +av_opt_set +( +mCodecContext +- +> +priv_data +" +fec +" +" +on +" +0 +) +) +{ +FFMPEG_LOG +( +" +Error +% +s +FEC +on +Opus +encoder +" +specific +. +mUseInBandFEC +? +" +enabling +" +: +" +disabling +" +) +; +return +NS_ERROR_FAILURE +; +} +FFMPEG_LOGV +( +" +In +- +band +FEC +enabled +for +Opus +encoder +. +" +) +; +} +/ +/ +TODO +: +DTX +format +/ +/ +https +: +/ +/ +bugzilla +. +mozilla +. +org +/ +show_bug +. +cgi +? +id += +1876064 +/ +/ +https +: +/ +/ +bugzilla +. +mozilla +. +org +/ +show_bug +. +cgi +? +id += +1876066 +} } / / @@ -951,27 +1301,6 @@ mCodecContext sample_rate } ; -/ -/ -Apply -codec -specific -settings -. -nsAutoCString -codecSpecificLog -; -if -( -mConfig -. -mCodecSpecific -) -{ -/ -/ -TODO -} MediaResult rv = @@ -2697,13 +3026,6 @@ mSampleRate ; / / -Add -here -the -new -rate -/ -/ Handle encoder delay