From 0c58454dac266d888211443321ed41020f9ff1a8 Mon Sep 17 00:00:00 2001 From: John-gdi Date: Mon, 7 Feb 2022 16:34:26 +0800 Subject: [PATCH 1/2] Support WebM seeking operation on 3.x --- modules/webm/video_stream_webm.cpp | 5 +++- thirdparty/libsimplewebm/WebMDemuxer.cpp | 30 +++++++++++++++++++++++- thirdparty/libsimplewebm/WebMDemuxer.hpp | 3 +++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index d7aba4e5ea60..5339c1db25d9 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -205,7 +205,10 @@ float VideoStreamPlaybackWebm::get_playback_position() const { return video_pos; } void VideoStreamPlaybackWebm::seek(float p_time) { - WARN_PRINT_ONCE("Seeking in Theora and WebM videos is not implemented yet (it's only supported for GDNative-provided video streams)."); + if (webm) { + time = webm->seek(p_time); + video_pos = time; + } } void VideoStreamPlaybackWebm::set_audio_track(int p_idx) { diff --git a/thirdparty/libsimplewebm/WebMDemuxer.cpp b/thirdparty/libsimplewebm/WebMDemuxer.cpp index cb63deccd5d0..6d4e67c58898 100644 --- a/thirdparty/libsimplewebm/WebMDemuxer.cpp +++ b/thirdparty/libsimplewebm/WebMDemuxer.cpp @@ -50,6 +50,8 @@ WebMDemuxer::WebMDemuxer(mkvparser::IMkvReader *reader, int videoTrack, int audi m_blockFrameIndex(0), m_videoTrack(NULL), m_vCodec(NO_VIDEO), m_audioTrack(NULL), m_aCodec(NO_AUDIO), + m_seekTime(0.0f), + m_isSeek(false), m_isOpen(false), m_eos(false) { @@ -143,6 +145,23 @@ int WebMDemuxer::getAudioDepth() const return m_audioTrack->GetBitDepth(); } +float WebMDemuxer::seek(float p_time){ + + if(p_time < 0) + return 0.0f; + + m_seekTime = p_time; + m_isSeek = true; + + const mkvparser::BlockEntry *blockEntry = NULL; + m_videoTrack->Seek(m_seekTime * 1e9, blockEntry); + + if(!blockEntry || !blockEntry->GetBlock() || !blockEntry->GetCluster()) + return 0.0f; + + return blockEntry->GetBlock()->GetTime(blockEntry->GetCluster()) / 1e9; +} + bool WebMDemuxer::readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame) { const long videoTrackNumber = (videoFrame && m_videoTrack) ? m_videoTrack->GetNumber() : 0; @@ -186,7 +205,16 @@ bool WebMDemuxer::readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame) } else if (!m_block || m_blockFrameIndex == m_block->GetFrameCount() || notSupportedTrackNumber(videoTrackNumber, audioTrackNumber)) { - status = m_cluster->GetNext(m_blockEntry, m_blockEntry); + if(m_isSeek) + { + m_videoTrack->Seek(m_seekTime * 1e9, m_blockEntry); + m_cluster = m_blockEntry->GetCluster(); + m_isSeek = false; + } + else + { + status = m_cluster->GetNext(m_blockEntry, m_blockEntry); + } if (!m_blockEntry || m_blockEntry->EOS()) { blockEntryEOS = true; diff --git a/thirdparty/libsimplewebm/WebMDemuxer.hpp b/thirdparty/libsimplewebm/WebMDemuxer.hpp index a45ddb3f26b9..0250dd1b2bc5 100644 --- a/thirdparty/libsimplewebm/WebMDemuxer.hpp +++ b/thirdparty/libsimplewebm/WebMDemuxer.hpp @@ -98,6 +98,7 @@ class WebMDemuxer int getChannels() const; int getAudioDepth() const; + float seek(float p_time); bool readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame); private: @@ -120,6 +121,8 @@ class WebMDemuxer bool m_isOpen; bool m_eos; + bool m_isSeek; + float m_seekTime; }; #endif // WEBMDEMUXER_HPP From 1ede4ca4bdc5ae39081bb199541594054fbda161 Mon Sep 17 00:00:00 2001 From: zhangjianguo Date: Thu, 10 Mar 2022 14:49:40 +0800 Subject: [PATCH 2/2] make the attached vp8 and vp9 webm file plays properly --- thirdparty/libsimplewebm/VPXDecoder.cpp | 6 +++++- thirdparty/libvpx/vp8/decoder/decodeframe.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/thirdparty/libsimplewebm/VPXDecoder.cpp b/thirdparty/libsimplewebm/VPXDecoder.cpp index e2606f83ba09..e036009dd91a 100644 --- a/thirdparty/libsimplewebm/VPXDecoder.cpp +++ b/thirdparty/libsimplewebm/VPXDecoder.cpp @@ -62,7 +62,11 @@ VPXDecoder::VPXDecoder(const WebMDemuxer &demuxer, unsigned threads) : } m_ctx = new vpx_codec_ctx_t; - if (vpx_codec_dec_init(m_ctx, codecIface, &codecCfg, m_delay > 0 ? VPX_CODEC_USE_FRAME_THREADING : 0)) + + // disable multi thread for decoder to make some vp8 and vp9 video files work properly + // refertence url https://github.com/dimiaa/WebM-Video-Player/blob/main/src/WebMVideoDecoder.cpp + int codecFlags = 0; + if (vpx_codec_dec_init(m_ctx, codecIface, &codecCfg, codecFlags)) { delete m_ctx; m_ctx = NULL; diff --git a/thirdparty/libvpx/vp8/decoder/decodeframe.c b/thirdparty/libvpx/vp8/decoder/decodeframe.c index 51acdbb9c8a0..6e355f300dc2 100644 --- a/thirdparty/libvpx/vp8/decoder/decodeframe.c +++ b/thirdparty/libvpx/vp8/decoder/decodeframe.c @@ -548,6 +548,7 @@ static void decode_mb_rows(VP8D_COMP *pbi) if(pc->filter_level) vp8_loop_filter_frame_init(pc, xd, pc->filter_level); + pc->filter_level = 0; vp8_setup_intra_recon_top_line(yv12_fb_new); /* Decode the individual macro block */