Skip to content

Commit

Permalink
Add wrapper class to media for support of VP9 video, and add a comman…
Browse files Browse the repository at this point in the history
…d line flag to enable the support.

This initial version of the wrapper provides support for decoding VP9 video in WebM container files, and is disabled by default.

New flag added: --enable-vp9-playback

TBR=brettw,scherkus,xhwang
BUG=166094
TEST=VP9 video in WebM containers plays back in <video> elements when --enable-vp9-playback is specified on the command line.

Review URL: https://codereview.chromium.org/11644078

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174488 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tomfinegan@chromium.org committed Dec 22, 2012
1 parent 668719e commit e17c547
Show file tree
Hide file tree
Showing 13 changed files with 506 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vars = {

"libjingle_revision": "251",
"libphonenumber_revision": "456",
"libvpx_revision": "173187",
"libvpx_revision": "174463",
"lss_revision": "17",

# These two FFmpeg variables must be updated together. One is used for SVN
Expand Down
6 changes: 6 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -6628,6 +6628,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_ENABLE_OPUS_PLAYBACK_DESCRIPTION" desc="Description for the flag to enable Opus playback in &lt;video&gt; elements.">
Enable experimental Opus playback in the video element.
</message>
<message name="IDS_FLAGS_ENABLE_VP9_PLAYBACK_NAME" desc="Title for the flag to enable VP9 playback in &lt;video&gt; elements.">
Enable VP9 playback in &lt;video&gt; elements.
</message>
<message name="IDS_FLAGS_ENABLE_VP9_PLAYBACK_DESCRIPTION" desc="Description for the flag to enable VP9 playback in &lt;video&gt; elements.">
Enable experimental VP9 playback in the video element.
</message>
<message name="IDS_FLAGS_AURA_TRANSLUCENT_FRAMES_NAME" desc="Title for the flag to enable fancy translucent windows.">
Translucent windows
</message>
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ const Experiment kExperiments[] = {
kOsAll,
SINGLE_VALUE_TYPE(switches::kEnableOpusPlayback)
},
{
"enable-vp9-playback",
IDS_FLAGS_ENABLE_VP9_PLAYBACK_NAME,
IDS_FLAGS_ENABLE_VP9_PLAYBACK_DESCRIPTION,
kOsAll,
SINGLE_VALUE_TYPE(switches::kEnableVp9Playback)
},
#if defined(USE_ASH)
{
"ash-disable-auto-window-placement",
Expand Down
1 change: 1 addition & 0 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
switches::kDisableTouchAdjustment,
switches::kEnableViewport,
switches::kEnableOpusPlayback,
switches::kEnableVp9Playback,
switches::kForceDeviceScaleFactor,
switches::kFullMemoryCrashReport,
#if !defined (GOOGLE_CHROME_BUILD)
Expand Down
1 change: 1 addition & 0 deletions media/DEPS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include_rules = [
"+jni",
"+third_party/ffmpeg",
"+third_party/libvpx",
"+third_party/openmax",
"+third_party/opus",
"+third_party/skia",
Expand Down
3 changes: 3 additions & 0 deletions media/base/media_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ const char kEnableEncryptedMedia[] = "enable-encrypted-media";
// Enables Opus playback in media elements.
const char kEnableOpusPlayback[] = "enable-opus-playback";

// Enables VP9 playback in media elements.
const char kEnableVp9Playback[] = "enable-vp9-playback";

} // namespace switches
2 changes: 2 additions & 0 deletions media/base/media_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ MEDIA_EXPORT extern const char kEnableEncryptedMedia[];

MEDIA_EXPORT extern const char kEnableOpusPlayback[];

MEDIA_EXPORT extern const char kEnableVp9Playback[];

} // namespace switches

#endif // MEDIA_BASE_MEDIA_SWITCHES_H_
8 changes: 6 additions & 2 deletions media/base/video_decoder_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ enum VideoCodec {
kCodecMPEG4,
kCodecTheora,
kCodecVP8,
kCodecVP9,
// DO NOT ADD RANDOM VIDEO CODECS!
//
// The only acceptable time to add a new codec is if there is production code
// that uses said codec in the same CL.

kVideoCodecMax = kCodecVP8 // Must equal the last "real" codec above.
kVideoCodecMax = kCodecVP9 // Must equal the last "real" codec above.
};

// Video stream profile. This *must* match PP_VideoDecoder_Profile.
Expand All @@ -58,7 +59,10 @@ enum VideoCodecProfile {
VP8PROFILE_MIN = 11,
VP8PROFILE_MAIN = VP8PROFILE_MIN,
VP8PROFILE_MAX = VP8PROFILE_MAIN,
VIDEO_CODEC_PROFILE_MAX = VP8PROFILE_MAX,
VP9PROFILE_MIN = 12,
VP9PROFILE_MAIN = VP9PROFILE_MIN,
VP9PROFILE_MAX = VP9PROFILE_MAIN,
VIDEO_CODEC_PROFILE_MAX = VP9PROFILE_MAX,
};

class MEDIA_EXPORT VideoDecoderConfig {
Expand Down
34 changes: 31 additions & 3 deletions media/ffmpeg/ffmpeg_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "media/base/video_frame.h"
#include "media/base/video_util.h"

// TODO(tomfinegan): Remove this once FFmpeg rolls for M25. The VP9 patch is in
// tree, but this is required until the roll happens.
#define AV_CODEC_ID_VP9 170

namespace media {

// Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are
Expand Down Expand Up @@ -149,6 +153,11 @@ VideoCodec CodecIDToVideoCodec(CodecID codec_id) {
case CODEC_ID_VP8:
return kCodecVP8;
default:
if (codec_id == AV_CODEC_ID_VP9) {
// TODO(tomfinegan): Remove this once FFmpeg rolls for M25, and
// AV_CODEC_ID_VP9 is part of CodecID.
return kCodecVP9;
}
DVLOG(1) << "Unknown video CodecID: " << codec_id;
}
return kUnknownVideoCodec;
Expand All @@ -168,6 +177,10 @@ static CodecID VideoCodecToCodecID(VideoCodec video_codec) {
return CODEC_ID_MPEG4;
case kCodecVP8:
return CODEC_ID_VP8;
case kCodecVP9:
// TODO(tomfinegan): Remove this cast once FFmpeg rolls for M25, and the
// local define for AV_CODEC_ID_VP9 is removed.
return static_cast<CodecID>(AV_CODEC_ID_VP9);
default:
DVLOG(1) << "Unknown VideoCodec: " << video_codec;
}
Expand Down Expand Up @@ -311,13 +324,28 @@ void AVStreamToVideoDecoderConfig(
aspect_ratio = stream->codec->sample_aspect_ratio;

VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id);
VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN :
ProfileIDToVideoCodecProfile(stream->codec->profile);

VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
if (codec == kCodecVP8)
profile = VP8PROFILE_MAIN;
else if (codec == kCodecVP9)
profile = VP9PROFILE_MAIN;
else
profile = ProfileIDToVideoCodecProfile(stream->codec->profile);

gfx::Size natural_size = GetNaturalSize(
visible_rect.size(), aspect_ratio.num, aspect_ratio.den);

VideoFrame::Format format = PixelFormatToVideoFormat(stream->codec->pix_fmt);
if (codec == kCodecVP9) {
// TODO(tomfinegan): libavcodec doesn't know about VP9.
format = VideoFrame::YV12;
coded_size = natural_size;
}

config->Initialize(codec,
profile,
PixelFormatToVideoFormat(stream->codec->pix_fmt),
format,
coded_size, visible_rect, natural_size,
stream->codec->extradata, stream->codec->extradata_size,
false, // Not encrypted.
Expand Down
Loading

0 comments on commit e17c547

Please sign in to comment.