Skip to content

Commit

Permalink
Video: Support Dolby Vision downgrade playback for MSE
Browse files Browse the repository at this point in the history
For now, if Chrome wants to implement Dolby Vision support, platform
decoders like `D3D11VideoDecoder` or `VideoToolboxVideoDecoder` won't
work. On macOS AVFoundation is required and on Windows MediaFoundation
is required to support such format from what I understand.

Regarding the above issues, as Dolby Vision contents usually
encoded with H.264/5 codecs, then as long as device supports H.264/5 codec and `dv_bl_signal_compatibility_id` equals to 1,2,4 (HDR10,
SDR,HLG compatible), then a downgrade should be performed and let
these videos at least able to playback normally as H.264/5 codec
contents as long as developer `addSourceBuffer` with mimetype
looks like `hev1.2.4.L120.90` or `avc1.4d4015`.

Note that when `addSourceBuffer` with mimetype looks like `dvh1.08.07`,
then dolby vision contents will always be treated as dolby vision,
the playback may still fails as expected if browser doesn't
support dolby vision on the current platform.

For web developers, the logic will be something like below:

```
if (isTypeSupported('video/mp4;codecs="dvh1.08.07"')) {
  if (use_rpu) {
    // Should be success and rendered with RPU meta.
    source.addSourceBuffer('video/mp4;codecs="dvh1.08.07"');
    ...
  } else if (dvcc.dv_bl_signal_compatibility_id === 1 ||
             dvcc.dv_bl_signal_compatibility_id === 2 ||
             dvcc.dv_bl_signal_compatibility_id === 4) {
    // Should be success and rendered without RPU meta as
    // normal HLG/HDR10/SDR contents.
    source.addSourceBuffer('video/mp4;codecs="hev1.2.4.L120.90"');
    ...
  } else {
    // Downgrade is not allowed, playback fails.
  }
} else if (isTypeSupported('video/mp4;codecs="hev1.2.4.L120.90"')) {
  if (dvcc.dv_bl_signal_compatibility_id === 1 ||
      dvcc.dv_bl_signal_compatibility_id === 2 ||
      dvcc.dv_bl_signal_compatibility_id === 4) {
    // Should be success and rendered without RPU meta as
    // normal HLG/HDR10/SDR contents.
    source.addSourceBuffer('video/mp4;codecs="hev1.2.4.L120.90"');
    ...
  } else {
    // Downgrade is not allowed, playback fails.
  }
} else {
  // HEVC is not supported, playback fails.
}
```

Bug: 1507390
Bug: 1500635
Change-Id: I6de0c11454ede30a8fc7838e164abc2d00822a48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5058372
Commit-Queue: 朱思达 <zhusida@bytedance.com>
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1233339}
  • Loading branch information
StaZhu authored and Chromium LUCI CQ committed Dec 5, 2023
1 parent e2e0f97 commit b888a20
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 150 deletions.
5 changes: 2 additions & 3 deletions media/base/supported_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ bool IsSupportedHdrMetadata(const VideoType& type) {
return type.color_space.transfer ==
VideoColorSpace::TransferID::SMPTEST2084;

// 2094-10 SEI metadata is not the same as Dolby Vision RPU metadata, Dolby
// Vision decoders on each platform only support Dolby Vision RPU metadata.
case gfx::HdrMetadataType::kSmpteSt2094_10:
#if BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
return type.codec == VideoCodec::kDolbyVision;
#endif
case gfx::HdrMetadataType::kSmpteSt2094_40:
return false;
}
Expand Down
10 changes: 1 addition & 9 deletions media/base/supported_types_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,10 @@ TEST(SupportedTypesTest, IsSupportedVideoTypeWithHdrMetadataBasics) {
IsSupportedVideoType({VideoCodec::kVP8, VP8PROFILE_ANY, kUnspecifiedLevel,
color_space, gfx::HdrMetadataType::kSmpteSt2086}));

// Dolby vision metadata is not supported if the codec is not dolby vision.
EXPECT_FALSE(IsSupportedVideoType({VideoCodec::kVP8, VP8PROFILE_ANY,
kUnspecifiedLevel, color_space,
gfx::HdrMetadataType::kSmpteSt2094_10}));

#if !BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
// Dolby vision metadata maybe is supported if buildflag is enabled and
// platform declare it's support.
// ST2094-10 metadata is not supported even if the codec is dolby vision.
EXPECT_FALSE(IsSupportedVideoType(
{VideoCodec::kDolbyVision, DOLBYVISION_PROFILE5, kUnspecifiedLevel,
color_space, gfx::HdrMetadataType::kSmpteSt2094_10}));
#endif // !BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)

EXPECT_FALSE(IsSupportedVideoType({VideoCodec::kVP8, VP8PROFILE_ANY,
kUnspecifiedLevel, color_space,
Expand Down
6 changes: 3 additions & 3 deletions media/ffmpeg/ffmpeg_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
type.codec = VideoCodec::kDolbyVision;
type.level = dovi->dv_level;
type.color_space = color_space;
type.hdr_metadata_type = gfx::HdrMetadataType::kSmpteSt2094_10;
type.hdr_metadata_type = gfx::HdrMetadataType::kNone;
switch (dovi->dv_profile) {
case 0:
type.profile = VideoCodecProfile::DOLBYVISION_PROFILE0;
Expand Down Expand Up @@ -796,8 +796,8 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
break;
}
#endif // BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
default:
break;
default:
break;
}
}

Expand Down
16 changes: 15 additions & 1 deletion media/filters/stream_parser_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ static StreamParser* BuildMP4Parser(base::span<const std::string> codecs,
MediaLog* media_log) {
std::set<int> audio_object_types;
bool has_sbr = false;
bool has_dv = false;

// The draft version 0.0.4 FLAC-in-ISO spec
// (https://github.com/xiph/flac/blob/master/doc/isoflac.txt) does not define
Expand Down Expand Up @@ -401,6 +402,18 @@ static StreamParser* BuildMP4Parser(base::span<const std::string> codecs,
has_sbr = true;
break;
}
#if BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
} else if (base::MatchPattern(codec_id,
kDolbyVisionAVCCodecInfo1.pattern) ||
base::MatchPattern(codec_id, kDolbyVisionAVCCodecInfo2.pattern)
#if BUILDFLAG(ENABLE_PLATFORM_HEVC)
|| base::MatchPattern(codec_id,
kDolbyVisionHEVCCodecInfo1.pattern) ||
base::MatchPattern(codec_id, kDolbyVisionHEVCCodecInfo2.pattern)
#endif // BUILDFLAG(ENABLE_PLATFORM_HEVC)
) {
has_dv = true;
#endif // BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
#if BUILDFLAG(ENABLE_PLATFORM_AC3_EAC3_AUDIO)
} else if (base::MatchPattern(codec_id, kAC3CodecInfo1.pattern) ||
base::MatchPattern(codec_id, kAC3CodecInfo2.pattern) ||
Expand Down Expand Up @@ -438,7 +451,8 @@ static StreamParser* BuildMP4Parser(base::span<const std::string> codecs,
}
}

return new mp4::MP4StreamParser(audio_object_types, has_sbr, has_flac);
return new mp4::MP4StreamParser(audio_object_types, has_sbr, has_flac,
has_dv);
}
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
static const CodecInfo kADTSCodecInfo = {nullptr, CodecInfo::AUDIO, nullptr,
Expand Down
14 changes: 3 additions & 11 deletions media/formats/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ source_set("formats") {
"mp4/aac.h",
"mp4/avc.cc",
"mp4/avc.h",
"mp4/dolby_vision.cc",
"mp4/dolby_vision.h",
"mp4/h264_annex_b_to_avc_bitstream_converter.cc",
"mp4/h264_annex_b_to_avc_bitstream_converter.h",
"mp4/mp4_status.h",
Expand Down Expand Up @@ -128,13 +130,6 @@ source_set("formats") {
}
}

if (proprietary_codecs && enable_platform_dolby_vision) {
sources += [
"mp4/dolby_vision.cc",
"mp4/dolby_vision.h",
]
}

if (enable_platform_dts_audio) {
sources += [
"dts/dts_stream_parser.cc",
Expand Down Expand Up @@ -313,6 +308,7 @@ source_set("unit_tests") {
"mp4/aac_unittest.cc",
"mp4/avc_unittest.cc",
"mp4/box_reader_unittest.cc",
"mp4/dolby_vision_unittest.cc",
"mp4/es_descriptor_unittest.cc",
"mp4/h264_annex_b_to_avc_bitstream_converter_unittest.cc",
"mp4/mp4_stream_parser_unittest.cc",
Expand Down Expand Up @@ -353,10 +349,6 @@ source_set("unit_tests") {
]
}

if (enable_platform_dolby_vision) {
sources += [ "mp4/dolby_vision_unittest.cc" ]
}

if (enable_platform_hevc) {
sources += [ "mp4/hevc_unittest.cc" ]

Expand Down
Loading

0 comments on commit b888a20

Please sign in to comment.