Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Support WebM seeking operation #57744

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/webm/video_stream_webm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion thirdparty/libsimplewebm/VPXDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also here where chromium removed the flag: https://bugs.chromium.org/p/webm/issues/detail?id=1395

// 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;
Expand Down
30 changes: 29 additions & 1 deletion thirdparty/libsimplewebm/WebMDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions thirdparty/libsimplewebm/WebMDemuxer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class WebMDemuxer
int getChannels() const;
int getAudioDepth() const;

float seek(float p_time);
bool readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame);

private:
Expand All @@ -120,6 +121,8 @@ class WebMDemuxer

bool m_isOpen;
bool m_eos;
bool m_isSeek;
float m_seekTime;
};

#endif // WEBMDEMUXER_HPP
1 change: 1 addition & 0 deletions thirdparty/libvpx/vp8/decoder/decodeframe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down