diff options
-rw-r--r-- | content/media/DecoderTraits.cpp | 4 | ||||
-rw-r--r-- | content/media/webm/WebMReader.cpp | 30 | ||||
-rw-r--r-- | content/media/webm/WebMReader.h | 4 | ||||
-rw-r--r-- | layout/media/symbols.def.in | 2 |
4 files changed, 29 insertions, 11 deletions
diff --git a/content/media/DecoderTraits.cpp b/content/media/DecoderTraits.cpp index 90d3f4fec..930944889 100644 --- a/content/media/DecoderTraits.cpp +++ b/content/media/DecoderTraits.cpp @@ -158,9 +158,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 diff --git a/content/media/webm/WebMReader.cpp b/content/media/webm/WebMReader.cpp index d2ca2edff..079d9616f 100644 --- a/content/media/webm/WebMReader.cpp +++ b/content/media/webm/WebMReader.cpp @@ -185,7 +185,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)); @@ -199,7 +199,7 @@ WebMReader::~WebMReader() mVideoPackets.Reset(); mAudioPackets.Reset(); - vpx_codec_destroy(&mVP8); + vpx_codec_destroy(&mVPX); vorbis_block_clear(&mVorbisBlock); vorbis_dsp_clear(&mVorbisDsp); @@ -216,10 +216,6 @@ WebMReader::~WebMReader() nsresult WebMReader::Init(MediaDecoderReader* aCloneDonor) { - if (vpx_codec_dec_init(&mVP8, vpx_codec_vp8_dx(), NULL, 0)) { - return NS_ERROR_FAILURE; - } - vorbis_info_init(&mVorbisInfo); vorbis_comment_init(&mVorbisComment); memset(&mVorbisDsp, 0, sizeof(vorbis_dsp_state)); @@ -330,6 +326,18 @@ nsresult WebMReader::ReadMetadata(VideoInfo* 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, @@ -1048,7 +1056,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. @@ -1059,7 +1071,7 @@ bool WebMReader::DecodeVideoFrame(bool &aKeyframeSkip, aKeyframeSkip = false; } - if (vpx_codec_decode(&mVP8, data, length, NULL, 0)) { + if (vpx_codec_decode(&mVPX, data, length, NULL, 0)) { return false; } @@ -1074,7 +1086,7 @@ bool WebMReader::DecodeVideoFrame(bool &aKeyframeSkip, vpx_codec_iter_t iter = NULL; 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 diff --git a/content/media/webm/WebMReader.h b/content/media/webm/WebMReader.h index 83823cc8b..344e55f30 100644 --- a/content/media/webm/WebMReader.h +++ b/content/media/webm/WebMReader.h @@ -271,7 +271,7 @@ private: nestegg* mContext; // VP8 decoder state - vpx_codec_ctx_t mVP8; + vpx_codec_ctx_t mVPX; // Vorbis decoder state vorbis_info mVorbisInfo; @@ -324,6 +324,8 @@ private: // Codec ID of audio track int mAudioCodec; + // Codec ID of video track + int mVideoCodec; #ifdef MOZ_DASH // Byte range for initialisation data; e.g. specified in DASH manifest. diff --git a/layout/media/symbols.def.in b/layout/media/symbols.def.in index d0ccc49a8..e41166e6a 100644 --- a/layout/media/symbols.def.in +++ b/layout/media/symbols.def.in @@ -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 |