diff options
Diffstat (limited to 'content/media/webm/WebMReader.cpp')
-rw-r--r-- | content/media/webm/WebMReader.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
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 |