Skip to content

Commit

Permalink
Video: Enable HEVC bitstream converter for Media Foundation for clear
Browse files Browse the repository at this point in the history
By default, bitstream converter(to Annex-B) is not enabled for HEVC when
use media foundation for clear, but it's reqiurenment of HEVC deocder in
MediaFoundation.
Refer to detail in this page:
https://learn.microsoft.com/en-us/windows/win32/medfound/h-265---hevc-video-decoder

This change only affect ffmpeg_demuxer used case.

Bug: 1465217
Change-Id: Ie8f44aea08cd2fe7d2e0d98e84f177e7abc375bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4688957
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
Commit-Queue: 朱思达 <zhusida@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#1173613}
  • Loading branch information
Jiawei Chen authored and Chromium LUCI CQ committed Jul 21, 2023
1 parent 6ec547d commit 614d48f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
40 changes: 35 additions & 5 deletions media/renderers/win/media_foundation_renderer_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@

#include "base/win/windows_version.h"
#include "media/base/media_util.h"
#include "media/base/supported_types.h"
#include "media/test/pipeline_integration_test_base.h"
#include "media/test/test_media_source.h"

namespace media {

namespace {

using VideoCodecMap = base::flat_map<VideoCodec, GUID>;

const VideoCodecMap& GetVideoCodecsMap() {
static const base::NoDestructor<VideoCodecMap> AllVideoCodecsMap(
{{VideoCodec::kVP9, MFVideoFormat_VP90},
{VideoCodec::kHEVC, MFVideoFormat_HEVC}});
return *AllVideoCodecsMap;
}

// TODO(xhwang): Generalize this to support more codecs, or use CanPlay() or
// IsTypeSupported() which can take mime types directly.
bool CanDecodeVp9() {
MFT_REGISTER_TYPE_INFO input_type = {MFMediaType_Video, MFVideoFormat_VP90};
bool CanDecodeVideoCodec(VideoCodec codec) {
auto codecs = GetVideoCodecsMap();
MFT_REGISTER_TYPE_INFO input_type = {MFMediaType_Video, codecs[codec]};
IMFActivate** activates = nullptr;
UINT32 count = 0;

Expand All @@ -38,7 +49,7 @@ bool CanDecodeVp9() {
CoTaskMemFree(activates);

if (count == 0) {
LOG(WARNING) << "No decoder for VP9";
LOG(WARNING) << "No decoder for " << media::GetCodecName(codec);
return false;
}

Expand Down Expand Up @@ -80,8 +91,9 @@ TEST_F(MediaFoundationRendererIntegrationTest, BasicPlayback) {
base::win::Version::WIN10_20H2) {
GTEST_SKIP() << "Skipping test for WIN10_20H2 and greater";
}
if (!CanDecodeVp9())
if (!CanDecodeVideoCodec(VideoCodec::kVP9)) {
return;
}

ASSERT_EQ(PIPELINE_OK, Start("bear-vp9.webm"));
Play();
Expand All @@ -94,8 +106,9 @@ TEST_F(MediaFoundationRendererIntegrationTest, BasicPlayback_MediaSource) {
base::win::Version::WIN10_20H2) {
GTEST_SKIP() << "Skipping test for WIN10_20H2 and greater";
}
if (!CanDecodeVp9())
if (!CanDecodeVideoCodec(VideoCodec::kVP9)) {
return;
}

TestMediaSource source("bear-vp9.webm", 67504);
EXPECT_EQ(PIPELINE_OK, StartPipelineWithMediaSource(&source));
Expand All @@ -107,4 +120,21 @@ TEST_F(MediaFoundationRendererIntegrationTest, BasicPlayback_MediaSource) {
Stop();
}

TEST_F(MediaFoundationRendererIntegrationTest,
HEVCPlayback_with_FFMpegDemuxer) {
if (!CanDecodeVideoCodec(VideoCodec::kHEVC)) {
return;
}

// FFMpegDemuxer will verify if video codec is supported internally, add HEVC
// profile here to let demuxer initialization successfully.
media::UpdateDefaultSupportedVideoProfiles(
{media::VideoCodecProfile::HEVCPROFILE_MAIN});

ASSERT_EQ(PIPELINE_OK, Start("bear-3840x2160-hevc.mp4", kUnreliableDuration));
Play();
ASSERT_TRUE(WaitUntilOnEnded());
Stop();
}

} // namespace media
8 changes: 8 additions & 0 deletions media/renderers/win/media_foundation_video_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ bool MediaFoundationH264VideoStream::AreFormatChangesEnabled() {
#endif // BUILDFLAG(USE_PROPRIETARY_CODECS)

#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
HRESULT MediaFoundationHEVCVideoStream::GetMediaType(
IMFMediaType** media_type_out) {
RETURN_IF_FAILED(MediaFoundationVideoStream::GetMediaType(media_type_out));
// Enable conversion to Annex-B
demuxer_stream_->EnableBitstreamConverter();
return S_OK;
}

bool MediaFoundationHEVCVideoStream::AreFormatChangesEnabled() {
// Disable explicit format change event for HEVC to allow switching to the
// new stream without a full re-create, which will be much faster. This is
Expand Down
1 change: 1 addition & 0 deletions media/renderers/win/media_foundation_video_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MediaFoundationH264VideoStream : public MediaFoundationVideoStream {
// The HEVC specific video stream.
class MediaFoundationHEVCVideoStream : public MediaFoundationVideoStream {
protected:
HRESULT GetMediaType(IMFMediaType** media_type_out) override;
bool AreFormatChangesEnabled() override;
};
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC) ||
Expand Down
6 changes: 6 additions & 0 deletions media/test/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,12 @@ HEVC video stream with HDR10 metadata included, generated with
ffmpeg -i bear-1280x720.mp4 -vcodec libx265 -x265-params colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,500)":max-cll=1000,400 -pix_fmt yuv420p10le bear-1280x720-hevc-10bit-hdr10.mp4 // nocheck
````

#### bear-3840x2160-hevc.mp4
HEVC video stream with 8-bit main profile, generated with
```
ffmpeg -i bear-1280x720.mp4 -vf "scale=3840:2160,setpts=4*PTS" -c:v libx265 -crf 28 -c:a copy bear-3840x2160-hevc.mp4
```

### Multi-track MP4 file

(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org
Expand Down
Binary file added media/test/data/bear-3840x2160-hevc.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions media/test/media_bundle_data.filelist
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ data/bear-320x240-video-only.webm
data/bear-320x240-vp9_profile2.webm
data/bear-320x240.webm
data/bear-320x240_corrupted_after_init_segment.webm
data/bear-3840x2160-hevc.mp4
data/bear-640x360-a_frag-cbcs.mp4
data/bear-640x360-a_frag-cenc-key_rotation.mp4
data/bear-640x360-a_frag-cenc.mp4
Expand Down
1 change: 1 addition & 0 deletions media/unit_tests_bundle_data.filelist
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
//media/test/data/bear-320x240-vp9_profile2.webm
//media/test/data/bear-320x240.webm
//media/test/data/bear-320x240_corrupted_after_init_segment.webm
//media/test/data/bear-3840x2160-hevc.mp4
//media/test/data/bear-640x360-a_frag-cbcs.mp4
//media/test/data/bear-640x360-a_frag-cenc-key_rotation.mp4
//media/test/data/bear-640x360-a_frag-cenc.mp4
Expand Down

0 comments on commit 614d48f

Please sign in to comment.