Skip to content

Commit

Permalink
Bug 1868403 - Set H264 profile r=media-playback-reviewers,padenot
Browse files Browse the repository at this point in the history
Depends on D196251

Differential Revision: https://phabricator.services.mozilla.com/D196252
  • Loading branch information
ChunMinChang committed Dec 18, 2023
1 parent 6ecda12 commit d9d08a5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dom/media/platforms/ffmpeg/FFmpegEncoderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ bool FFmpegEncoderModule<V>::Supports(const EncoderConfig& aConfig) const {
return false;
}
if (specific.mProfile != H264_PROFILE_BASE &&
specific.mProfile != H264_PROFILE_MAIN) {
specific.mProfile != H264_PROFILE_MAIN &&
specific.mProfile != H264_PROFILE_HIGH) {
return false;
}
if (width > 4096 || height > 4096) {
Expand Down
51 changes: 51 additions & 0 deletions dom/media/platforms/ffmpeg/FFmpegVideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ using FFmpegBitRate = int;
constexpr size_t FFmpegErrorMaxStringSize = 64;
#endif

struct H264Profile {
int mValue;
const char* mString;
};

static const H264Profile H264Profiles[]{{FF_PROFILE_H264_BASELINE, "baseline"},
{FF_PROFILE_H264_MAIN, "main"},
{FF_PROFILE_H264_EXTENDED, nullptr},
{FF_PROFILE_H264_HIGH, "high"}};

static mozilla::Maybe<H264Profile> GetH264Profile(
const mozilla::H264_PROFILE& aProfile) {
switch (aProfile) {
case mozilla::H264_PROFILE::H264_PROFILE_UNKNOWN:
return mozilla::Nothing();
case mozilla::H264_PROFILE::H264_PROFILE_BASE:
return mozilla::Some(H264Profiles[0]);
case mozilla::H264_PROFILE::H264_PROFILE_MAIN:
return mozilla::Some(H264Profiles[1]);
case mozilla::H264_PROFILE::H264_PROFILE_EXTENDED:
return mozilla::Some(H264Profiles[2]);
case mozilla::H264_PROFILE::H264_PROFILE_HIGH:
return mozilla::Some(H264Profiles[3]);
default:
break;
}
MOZ_ASSERT_UNREACHABLE("undefined profile");
return mozilla::Nothing();
}

#if LIBAVCODEC_VERSION_MAJOR < 54
using FFmpegPixelFormat = enum PixelFormat;
const FFmpegPixelFormat FFMPEG_PIX_FMT_NONE = FFmpegPixelFormat::PIX_FMT_NONE;
Expand Down Expand Up @@ -391,6 +421,27 @@ MediaResult FFmpegVideoEncoder<LIBAV_VER>::InitInternal() {
// lookahead purposes.
mLib->av_opt_set(mCodecContext->priv_data, "lag-in-frames", "0", 0);
}
if (mConfig.mCodecSpecific) {
if (mConfig.mCodecSpecific->is<H264Specific>()) {
const H264Specific& specific = mConfig.mCodecSpecific->as<H264Specific>();

// Set profile.
Maybe<ffmpeg::H264Profile> profile =
ffmpeg::GetH264Profile(specific.mProfile);
if (!profile) {
FFMPEGV_LOG("failed to get h264 profile");
return MediaResult(NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR,
RESULT_DETAIL("H264 profile is unknown"));
}
mCodecContext->profile = profile->mValue;
if (profile->mString) {
mLib->av_opt_set(mCodecContext->priv_data, "profile", profile->mString,
0);
}

// TODO: Set level.
}
}
// TODO: keyint_min, max_b_frame?
// TODO: VPX specific settings
// - if mConfig.mDenoising is set: av_opt_set_int(mCodecContext->priv_data,
Expand Down

0 comments on commit d9d08a5

Please sign in to comment.