diff options
| author | Matt Hughes | 2017-09-14 15:45:02 -0500 |
|---|---|---|
| committer | Hiroshi Ogawa | 2017-10-14 23:20:39 +0900 |
| commit | 3edd3cd377511b4cef27478be24f7562273d69ce (patch) | |
| tree | 204fcdded3bc7b46a6b559a5e5a44eba4244f25b /thirdparty/libsimplewebm/OpusVorbisDecoder.cpp | |
| parent | e8f8359b2edd583480218b7348cdbe43e959a16e (diff) | |
| download | godot-3edd3cd377511b4cef27478be24f7562273d69ce.tar.gz godot-3edd3cd377511b4cef27478be24f7562273d69ce.tar.zst godot-3edd3cd377511b4cef27478be24f7562273d69ce.zip | |
Fix video playback
This adds support to
- VideoPlayer
- VideoStreamWebm
- VideoStreamTheora
Diffstat (limited to 'thirdparty/libsimplewebm/OpusVorbisDecoder.cpp')
| -rw-r--r-- | thirdparty/libsimplewebm/OpusVorbisDecoder.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/thirdparty/libsimplewebm/OpusVorbisDecoder.cpp b/thirdparty/libsimplewebm/OpusVorbisDecoder.cpp index 06447aca5..c9e71eb73 100644 --- a/thirdparty/libsimplewebm/OpusVorbisDecoder.cpp +++ b/thirdparty/libsimplewebm/OpusVorbisDecoder.cpp @@ -122,6 +122,43 @@ bool OpusVorbisDecoder::getPCMS16(WebMFrame &frame, short *buffer, int &numOutSa return false; } +bool OpusVorbisDecoder::getPCMF(WebMFrame &frame, float *buffer, int &numOutSamples) { + if (m_vorbis) { + m_vorbis->op.packet = frame.buffer; + m_vorbis->op.bytes = frame.bufferSize; + + if (vorbis_synthesis(&m_vorbis->block, &m_vorbis->op)) + return false; + if (vorbis_synthesis_blockin(&m_vorbis->dspState, &m_vorbis->block)) + return false; + + const int maxSamples = getBufferSamples(); + int samplesCount, count = 0; + float **pcm; + while ((samplesCount = vorbis_synthesis_pcmout(&m_vorbis->dspState, &pcm))) { + const int toConvert = samplesCount <= maxSamples ? samplesCount : maxSamples; + for (int c = 0; c < m_channels; ++c) { + float *samples = pcm[c]; + for (int i = 0, j = c; i < toConvert; ++i, j += m_channels) { + buffer[count + j] = samples[i]; + } + } + vorbis_synthesis_read(&m_vorbis->dspState, toConvert); + count += toConvert; + } + + numOutSamples = count; + return true; + } else if (m_opus) { + const int samples = opus_decode_float(m_opus, frame.buffer, frame.bufferSize, buffer, m_numSamples, 0); + if (samples >= 0) { + numOutSamples = samples; + return true; + } + } + return false; +} + bool OpusVorbisDecoder::openVorbis(const WebMDemuxer &demuxer) { size_t extradataSize = 0; |
