Bug 833023 - Enable VP9 playback in HTML media elements. r=kinetik

This commit is contained in:
Jan Gerber 2013-12-03 16:21:00 -08:00
parent 31fca20085
commit 5651a2f1d2
4 changed files with 29 additions and 10 deletions

View File

@ -171,9 +171,11 @@ static const char* const gWebMTypes[3] = {
nullptr
};
static char const *const gWebMCodecs[5] = {
static char const *const gWebMCodecs[7] = {
"vp8",
"vp8.0",
"vp9",
"vp9.0",
"vorbis",
"opus",
nullptr

View File

@ -163,7 +163,7 @@ WebMReader::WebMReader(AbstractMediaDecoder* aDecoder)
#endif
// Zero these member vars to avoid crashes in VP8 destroy and Vorbis clear
// functions when destructor is called before |Init|.
memset(&mVP8, 0, sizeof(vpx_codec_ctx_t));
memset(&mVPX, 0, sizeof(vpx_codec_ctx_t));
memset(&mVorbisBlock, 0, sizeof(vorbis_block));
memset(&mVorbisDsp, 0, sizeof(vorbis_dsp_state));
memset(&mVorbisInfo, 0, sizeof(vorbis_info));
@ -177,7 +177,7 @@ WebMReader::~WebMReader()
mVideoPackets.Reset();
mAudioPackets.Reset();
vpx_codec_destroy(&mVP8);
vpx_codec_destroy(&mVPX);
vorbis_block_clear(&mVorbisBlock);
vorbis_dsp_clear(&mVorbisDsp);
@ -194,9 +194,6 @@ WebMReader::~WebMReader()
nsresult WebMReader::Init(MediaDecoderReader* aCloneDonor)
{
if (vpx_codec_dec_init(&mVP8, vpx_codec_vp8_dx(), nullptr, 0)) {
return NS_ERROR_FAILURE;
}
vorbis_info_init(&mVorbisInfo);
vorbis_comment_init(&mVorbisComment);
@ -285,6 +282,18 @@ nsresult WebMReader::ReadMetadata(MediaInfo* aInfo,
return NS_ERROR_FAILURE;
}
vpx_codec_iface_t* dx = nullptr;
mVideoCodec = nestegg_track_codec_id(mContext, track);
if (mVideoCodec == NESTEGG_CODEC_VP8) {
dx = vpx_codec_vp8_dx();
} else if (mVideoCodec == NESTEGG_CODEC_VP9) {
dx = vpx_codec_vp9_dx();
}
if (!dx || vpx_codec_dec_init(&mVPX, dx, nullptr, 0)) {
Cleanup();
return NS_ERROR_FAILURE;
}
// Picture region, taking into account cropping, before scaling
// to the display size.
nsIntRect pictureRect(params.crop_left,
@ -868,7 +877,11 @@ bool WebMReader::DecodeVideoFrame(bool &aKeyframeSkip,
vpx_codec_stream_info_t si;
memset(&si, 0, sizeof(si));
si.sz = sizeof(si);
vpx_codec_peek_stream_info(vpx_codec_vp8_dx(), data, length, &si);
if (mVideoCodec == NESTEGG_CODEC_VP8) {
vpx_codec_peek_stream_info(vpx_codec_vp8_dx(), data, length, &si);
} else if (mVideoCodec == NESTEGG_CODEC_VP9) {
vpx_codec_peek_stream_info(vpx_codec_vp9_dx(), data, length, &si);
}
if (aKeyframeSkip && (!si.is_kf || tstamp_usecs < aTimeThreshold)) {
// Skipping to next keyframe...
parsed++; // Assume 1 frame per chunk.
@ -879,7 +892,7 @@ bool WebMReader::DecodeVideoFrame(bool &aKeyframeSkip,
aKeyframeSkip = false;
}
if (vpx_codec_decode(&mVP8, data, length, nullptr, 0)) {
if (vpx_codec_decode(&mVPX, data, length, nullptr, 0)) {
return false;
}
@ -894,7 +907,7 @@ bool WebMReader::DecodeVideoFrame(bool &aKeyframeSkip,
vpx_codec_iter_t iter = nullptr;
vpx_image_t *img;
while ((img = vpx_codec_get_frame(&mVP8, &iter))) {
while ((img = vpx_codec_get_frame(&mVPX, &iter))) {
NS_ASSERTION(img->fmt == IMG_FMT_I420, "WebM image format is not I420");
// Chroma shifts are rounded down as per the decoding examples in the VP8 SDK

View File

@ -181,7 +181,7 @@ private:
nestegg* mContext;
// VP8 decoder state
vpx_codec_ctx_t mVP8;
vpx_codec_ctx_t mVPX;
// Vorbis decoder state
vorbis_info mVorbisInfo;
@ -234,6 +234,8 @@ private:
// Codec ID of audio track
int mAudioCodec;
// Codec ID of video track
int mVideoCodec;
};

View File

@ -38,11 +38,13 @@ vpx_codec_destroy
vpx_codec_get_frame
vpx_codec_peek_stream_info
vpx_codec_vp8_dx
vpx_codec_vp9_dx
vpx_img_free
vpx_codec_enc_config_set
vpx_codec_enc_init_ver
#ifdef MOZ_VP8_ENCODER
vpx_codec_vp8_cx
vpx_codec_vp9_cx
#endif
vpx_img_set_rect
vpx_img_wrap