Add libsimplewebm and libwebm thirdparty libraries

This commit is contained in:
Błażej Szczygieł 2016-10-17 17:13:34 +02:00
parent c4b7c7d81b
commit 2d77a6f5d3
16 changed files with 10124 additions and 0 deletions

View File

@ -95,6 +95,12 @@ Files extracted from upstream source:
- `scripts/pnglibconf.h.prebuilt` as `pnglibconf.h`
## libsimplewebm
- Upstream: https://github.com/zaps166/libsimplewebm
- License: MIT, BSD-3-Clause
## libvorbis
- Upstream: https://www.xiph.org/vorbis

21
thirdparty/libsimplewebm/LICENSE vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,224 @@
/*
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "OpusVorbisDecoder.hpp"
#include <vorbis/codec.h>
#include <opus/opus.h>
#include <string.h>
struct VorbisDecoder
{
vorbis_info info;
vorbis_dsp_state dspState;
vorbis_block block;
ogg_packet op;
bool hasDSPState, hasBlock;
};
/**/
OpusVorbisDecoder::OpusVorbisDecoder(const WebMDemuxer &demuxer) :
m_vorbis(NULL), m_opus(NULL),
m_numSamples(0),
m_channels(demuxer.getChannels())
{
switch (demuxer.getAudioCodec())
{
case WebMDemuxer::AUDIO_VORBIS:
if (openVorbis(demuxer))
return;
break;
case WebMDemuxer::AUDIO_OPUS:
if (openOpus(demuxer))
return;
break;
default:
return;
}
close();
}
OpusVorbisDecoder::~OpusVorbisDecoder()
{
close();
}
bool OpusVorbisDecoder::isOpen() const
{
return (m_vorbis || m_opus);
}
bool OpusVorbisDecoder::getPCMS16(WebMFrame &frame, short *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)
{
int sample = samples[i] * 32767.0f;
if (sample > 32767)
sample = 32767;
else if (sample < -32768)
sample = -32768;
buffer[count + j] = sample;
}
}
vorbis_synthesis_read(&m_vorbis->dspState, toConvert);
count += toConvert;
}
numOutSamples = count;
return true;
}
else if (m_opus)
{
const int samples = opus_decode(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;
const unsigned char *extradata = demuxer.getAudioExtradata(extradataSize);
if (extradataSize < 3 || !extradata || extradata[0] != 2)
return false;
size_t headerSize[3] = {0};
size_t offset = 1;
/* Calculate three headers sizes */
for (int i = 0; i < 2; ++i)
{
for (;;)
{
if (offset >= extradataSize)
return false;
headerSize[i] += extradata[offset];
if (extradata[offset++] < 0xFF)
break;
}
}
headerSize[2] = extradataSize - (headerSize[0] + headerSize[1] + offset);
if (headerSize[0] + headerSize[1] + headerSize[2] + offset != extradataSize)
return false;
ogg_packet op[3];
memset(op, 0, sizeof op);
op[0].packet = (unsigned char *)extradata + offset;
op[0].bytes = headerSize[0];
op[0].b_o_s = 1;
op[1].packet = (unsigned char *)extradata + offset + headerSize[0];
op[1].bytes = headerSize[1];
op[2].packet = (unsigned char *)extradata + offset + headerSize[0] + headerSize[1];
op[2].bytes = headerSize[2];
m_vorbis = new VorbisDecoder;
m_vorbis->hasDSPState = m_vorbis->hasBlock = false;
vorbis_info_init(&m_vorbis->info);
/* Upload three Vorbis headers into libvorbis */
vorbis_comment vc;
vorbis_comment_init(&vc);
for (int i = 0; i < 3; ++i)
{
if (vorbis_synthesis_headerin(&m_vorbis->info, &vc, &op[i]))
{
vorbis_comment_clear(&vc);
return false;
}
}
vorbis_comment_clear(&vc);
if (vorbis_synthesis_init(&m_vorbis->dspState, &m_vorbis->info))
return false;
m_vorbis->hasDSPState = true;
if (m_vorbis->info.channels != m_channels || m_vorbis->info.rate != demuxer.getSampleRate())
return false;
if (vorbis_block_init(&m_vorbis->dspState, &m_vorbis->block))
return false;
m_vorbis->hasBlock = true;
memset(&m_vorbis->op, 0, sizeof m_vorbis->op);
m_numSamples = 4096 / m_channels;
return true;
}
bool OpusVorbisDecoder::openOpus(const WebMDemuxer &demuxer)
{
int opusErr = 0;
m_opus = opus_decoder_create(demuxer.getSampleRate(), m_channels, &opusErr);
if (!opusErr)
{
m_numSamples = demuxer.getSampleRate() * 0.06 + 0.5; //Maximum frame size (for 60 ms frame)
return true;
}
return false;
}
void OpusVorbisDecoder::close()
{
if (m_vorbis)
{
if (m_vorbis->hasBlock)
vorbis_block_clear(&m_vorbis->block);
if (m_vorbis->hasDSPState)
vorbis_dsp_clear(&m_vorbis->dspState);
vorbis_info_clear(&m_vorbis->info);
delete m_vorbis;
}
if (m_opus)
opus_decoder_destroy(m_opus);
}

View File

@ -0,0 +1,63 @@
/*
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef OPUSVORBISDECODER_HPP
#define OPUSVORBISDECODER_HPP
#include "WebMDemuxer.hpp"
struct VorbisDecoder;
struct OpusDecoder;
class OpusVorbisDecoder
{
OpusVorbisDecoder(const OpusVorbisDecoder &);
void operator =(const OpusVorbisDecoder &);
public:
OpusVorbisDecoder(const WebMDemuxer &demuxer);
~OpusVorbisDecoder();
bool isOpen() const;
inline int getBufferSamples() const
{
return m_numSamples;
}
bool getPCMS16(WebMFrame &frame, short *buffer, int &numOutSamples);
private:
bool openVorbis(const WebMDemuxer &demuxer);
bool openOpus(const WebMDemuxer &demuxer);
void close();
VorbisDecoder *m_vorbis;
OpusDecoder *m_opus;
int m_numSamples;
int m_channels;
};
#endif // OPUSVORBISDECODER_HPP

142
thirdparty/libsimplewebm/VPXDecoder.cpp vendored Normal file
View File

@ -0,0 +1,142 @@
/*
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "VPXDecoder.hpp"
#include <vpx/vpx_decoder.h>
#include <vpx/vp8dx.h>
#include <stdlib.h>
#include <string.h>
VPXDecoder::VPXDecoder(const WebMDemuxer &demuxer, unsigned threads) :
m_ctx(NULL),
m_iter(NULL),
m_delay(0)
{
if (threads > 8)
threads = 8;
else if (threads < 1)
threads = 1;
const vpx_codec_dec_cfg_t codecCfg = {
threads,
0,
0
};
vpx_codec_iface_t *codecIface = NULL;
switch (demuxer.getVideoCodec())
{
case WebMDemuxer::VIDEO_VP8:
codecIface = vpx_codec_vp8_dx();
break;
case WebMDemuxer::VIDEO_VP9:
codecIface = vpx_codec_vp9_dx();
m_delay = threads - 1;
break;
default:
return;
}
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))
{
delete m_ctx;
m_ctx = NULL;
}
}
VPXDecoder::~VPXDecoder()
{
if (m_ctx)
{
vpx_codec_destroy(m_ctx);
delete m_ctx;
}
}
bool VPXDecoder::decode(const WebMFrame &frame)
{
m_iter = NULL;
return !vpx_codec_decode(m_ctx, frame.buffer, frame.bufferSize, NULL, 0);
}
VPXDecoder::IMAGE_ERROR VPXDecoder::getImage(Image &image)
{
IMAGE_ERROR err = NO_FRAME;
if (vpx_image_t *img = vpx_codec_get_frame(m_ctx, &m_iter))
{
if ((img->fmt & VPX_IMG_FMT_PLANAR) && !(img->fmt & (VPX_IMG_FMT_HAS_ALPHA | VPX_IMG_FMT_HIGHBITDEPTH)))
{
if (img->stride[0] && img->stride[1] && img->stride[2])
{
const int uPlane = !!(img->fmt & VPX_IMG_FMT_UV_FLIP) + 1;
const int vPlane = !(img->fmt & VPX_IMG_FMT_UV_FLIP) + 1;
image.w = img->d_w;
image.h = img->d_h;
image.chromaShiftW = img->x_chroma_shift;
image.chromaShiftH = img->y_chroma_shift;
image.planes[0] = img->planes[0];
image.planes[1] = img->planes[uPlane];
image.planes[2] = img->planes[vPlane];
image.linesize[0] = img->stride[0];
image.linesize[1] = img->stride[uPlane];
image.linesize[2] = img->stride[vPlane];
err = NO_ERROR;
}
}
else
{
err = UNSUPPORTED_FRAME;
}
}
return err;
}
/**/
#if 0
static inline int ceilRshift(int val, int shift)
{
return (val + (1 << shift) - 1) >> shift;
}
int VPXDecoder::Image::getWidth(int plane) const
{
if (!plane)
return w;
return ceilRshift(w, chromaShiftW);
}
int VPXDecoder::Image::getHeight(int plane) const
{
if (!plane)
return h;
return ceilRshift(h, chromaShiftH);
}
#endif

80
thirdparty/libsimplewebm/VPXDecoder.hpp vendored Normal file
View File

@ -0,0 +1,80 @@
/*
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef VPXDECODER_HPP
#define VPXDECODER_HPP
#include "WebMDemuxer.hpp"
struct vpx_codec_ctx;
class VPXDecoder
{
VPXDecoder(const VPXDecoder &);
void operator =(const VPXDecoder &);
public:
class Image
{
public:
#if 0
int getWidth(int plane) const;
int getHeight(int plane) const;
#endif
int w, h;
int chromaShiftW, chromaShiftH;
unsigned char *planes[3];
int linesize[3];
};
enum IMAGE_ERROR
{
UNSUPPORTED_FRAME = -1,
NO_ERROR,
NO_FRAME
};
VPXDecoder(const WebMDemuxer &demuxer, unsigned threads = 1);
~VPXDecoder();
inline bool isOpen() const
{
return (bool)m_ctx;
}
inline int getFramesDelay() const
{
return m_delay;
}
bool decode(const WebMFrame &frame);
IMAGE_ERROR getImage(Image &image); //The data is NOT copied! Only 3-plane, 8-bit images are supported.
private:
vpx_codec_ctx *m_ctx;
const void *m_iter;
int m_delay;
};
#endif // VPXDECODER_HPP

241
thirdparty/libsimplewebm/WebMDemuxer.cpp vendored Normal file
View File

@ -0,0 +1,241 @@
/*
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "WebMDemuxer.hpp"
#include "mkvparser/mkvparser.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
WebMFrame::WebMFrame() :
bufferSize(0), bufferCapacity(0),
buffer(NULL),
time(0),
key(false)
{}
WebMFrame::~WebMFrame()
{
free(buffer);
}
/**/
WebMDemuxer::WebMDemuxer(mkvparser::IMkvReader *reader, int videoTrack, int audioTrack) :
m_reader(reader),
m_segment(NULL),
m_cluster(NULL), m_block(NULL), m_blockEntry(NULL),
m_blockFrameIndex(0),
m_videoTrack(NULL), m_vCodec(NO_VIDEO),
m_audioTrack(NULL), m_aCodec(NO_AUDIO),
m_isOpen(false),
m_eos(false)
{
long long pos = 0;
if (mkvparser::EBMLHeader().Parse(m_reader, pos))
return;
if (mkvparser::Segment::CreateInstance(m_reader, pos, m_segment))
return;
if (m_segment->Load() < 0)
return;
const mkvparser::Tracks *tracks = m_segment->GetTracks();
const unsigned long tracksCount = tracks->GetTracksCount();
int currVideoTrack = -1, currAudioTrack = -1;
for (unsigned long i = 0; i < tracksCount; ++i)
{
const mkvparser::Track *track = tracks->GetTrackByIndex(i);
if (const char *codecId = track->GetCodecId())
{
if ((!m_videoTrack || currVideoTrack != videoTrack) && track->GetType() == mkvparser::Track::kVideo)
{
if (!strcmp(codecId, "V_VP8"))
m_vCodec = VIDEO_VP8;
else if (!strcmp(codecId, "V_VP9"))
m_vCodec = VIDEO_VP9;
if (m_vCodec != NO_VIDEO)
m_videoTrack = static_cast<const mkvparser::VideoTrack *>(track);
++currVideoTrack;
}
if ((!m_audioTrack || currAudioTrack != audioTrack) && track->GetType() == mkvparser::Track::kAudio)
{
if (!strcmp(codecId, "A_VORBIS"))
m_aCodec = AUDIO_VORBIS;
else if (!strcmp(codecId, "A_OPUS"))
m_aCodec = AUDIO_OPUS;
if (m_aCodec != NO_AUDIO)
m_audioTrack = static_cast<const mkvparser::AudioTrack *>(track);
++currAudioTrack;
}
}
}
if (!m_videoTrack && !m_audioTrack)
return;
m_isOpen = true;
}
WebMDemuxer::~WebMDemuxer()
{
delete m_segment;
delete m_reader;
}
double WebMDemuxer::getLength() const
{
return m_segment->GetDuration() / 1e9;
}
WebMDemuxer::VIDEO_CODEC WebMDemuxer::getVideoCodec() const
{
return m_vCodec;
}
int WebMDemuxer::getWidth() const
{
return m_videoTrack->GetWidth();
}
int WebMDemuxer::getHeight() const
{
return m_videoTrack->GetHeight();
}
WebMDemuxer::AUDIO_CODEC WebMDemuxer::getAudioCodec() const
{
return m_aCodec;
}
const unsigned char *WebMDemuxer::getAudioExtradata(size_t &size) const
{
return m_audioTrack->GetCodecPrivate(size);
}
double WebMDemuxer::getSampleRate() const
{
return m_audioTrack->GetSamplingRate();
}
int WebMDemuxer::getChannels() const
{
return m_audioTrack->GetChannels();
}
int WebMDemuxer::getAudioDepth() const
{
return m_audioTrack->GetBitDepth();
}
bool WebMDemuxer::readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame)
{
const long videoTrackNumber = (videoFrame && m_videoTrack) ? m_videoTrack->GetNumber() : 0;
const long audioTrackNumber = (audioFrame && m_audioTrack) ? m_audioTrack->GetNumber() : 0;
bool blockEntryEOS = false;
if (videoFrame)
videoFrame->bufferSize = 0;
if (audioFrame)
audioFrame->bufferSize = 0;
if (videoTrackNumber == 0 && audioTrackNumber == 0)
return false;
if (m_eos)
return false;
if (!m_cluster)
m_cluster = m_segment->GetFirst();
do
{
bool getNewBlock = false;
long status = 0;
if (!m_blockEntry && !blockEntryEOS)
{
status = m_cluster->GetFirst(m_blockEntry);
getNewBlock = true;
}
else if (blockEntryEOS || m_blockEntry->EOS())
{
m_cluster = m_segment->GetNext(m_cluster);
if (!m_cluster || m_cluster->EOS())
{
m_eos = true;
return false;
}
status = m_cluster->GetFirst(m_blockEntry);
blockEntryEOS = false;
getNewBlock = true;
}
else if (!m_block || m_blockFrameIndex == m_block->GetFrameCount() || notSupportedTrackNumber(videoTrackNumber, audioTrackNumber))
{
status = m_cluster->GetNext(m_blockEntry, m_blockEntry);
if (!m_blockEntry || m_blockEntry->EOS())
{
blockEntryEOS = true;
continue;
}
getNewBlock = true;
}
if (status || !m_blockEntry)
return false;
if (getNewBlock)
{
m_block = m_blockEntry->GetBlock();
m_blockFrameIndex = 0;
}
} while (blockEntryEOS || notSupportedTrackNumber(videoTrackNumber, audioTrackNumber));
WebMFrame *frame = NULL;
const long trackNumber = m_block->GetTrackNumber();
if (trackNumber == videoTrackNumber)
frame = videoFrame;
else if (trackNumber == audioTrackNumber)
frame = audioFrame;
else
{
//Should not be possible
assert(trackNumber == videoTrackNumber || trackNumber == audioTrackNumber);
return false;
}
const mkvparser::Block::Frame &blockFrame = m_block->GetFrame(m_blockFrameIndex++);
if (blockFrame.len > frame->bufferCapacity)
{
unsigned char *newBuff = (unsigned char *)realloc(frame->buffer, frame->bufferCapacity = blockFrame.len);
if (newBuff)
frame->buffer = newBuff;
else // Out of memory
return false;
}
frame->bufferSize = blockFrame.len;
frame->time = m_block->GetTime(m_cluster) / 1e9;
frame->key = m_block->IsKey();
return !blockFrame.Read(m_reader, frame->buffer);
}
inline bool WebMDemuxer::notSupportedTrackNumber(long videoTrackNumber, long audioTrackNumber) const
{
const long trackNumber = m_block->GetTrackNumber();
return (trackNumber != videoTrackNumber && trackNumber != audioTrackNumber);
}

125
thirdparty/libsimplewebm/WebMDemuxer.hpp vendored Normal file
View File

@ -0,0 +1,125 @@
/*
MIT License
Copyright (c) 2016 Błażej Szczygieł
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef WEBMDEMUXER_HPP
#define WEBMDEMUXER_HPP
#include <stddef.h>
namespace mkvparser {
class IMkvReader;
class Segment;
class Cluster;
class Block;
class BlockEntry;
class VideoTrack;
class AudioTrack;
}
class WebMFrame
{
WebMFrame(const WebMFrame &);
void operator =(const WebMFrame &);
public:
WebMFrame();
~WebMFrame();
inline bool isValid() const
{
return bufferSize > 0;
}
long bufferSize, bufferCapacity;
unsigned char *buffer;
double time;
bool key;
};
class WebMDemuxer
{
WebMDemuxer(const WebMDemuxer &);
void operator =(const WebMDemuxer &);
public:
enum VIDEO_CODEC
{
NO_VIDEO,
VIDEO_VP8,
VIDEO_VP9
};
enum AUDIO_CODEC
{
NO_AUDIO,
AUDIO_VORBIS,
AUDIO_OPUS
};
WebMDemuxer(mkvparser::IMkvReader *reader, int videoTrack = 0, int audioTrack = 0);
~WebMDemuxer();
inline bool isOpen() const
{
return m_isOpen;
}
inline bool isEOS() const
{
return m_eos;
}
double getLength() const;
VIDEO_CODEC getVideoCodec() const;
int getWidth() const;
int getHeight() const;
AUDIO_CODEC getAudioCodec() const;
const unsigned char *getAudioExtradata(size_t &size) const; // Needed for Vorbis
double getSampleRate() const;
int getChannels() const;
int getAudioDepth() const;
bool readFrame(WebMFrame *videoFrame, WebMFrame *audioFrame);
private:
inline bool notSupportedTrackNumber(long videoTrackNumber, long audioTrackNumber) const;
mkvparser::IMkvReader *m_reader;
mkvparser::Segment *m_segment;
const mkvparser::Cluster *m_cluster;
const mkvparser::Block *m_block;
const mkvparser::BlockEntry *m_blockEntry;
int m_blockFrameIndex;
const mkvparser::VideoTrack *m_videoTrack;
VIDEO_CODEC m_vCodec;
const mkvparser::AudioTrack *m_audioTrack;
AUDIO_CODEC m_aCodec;
bool m_isOpen;
bool m_eos;
};
#endif // WEBMDEMUXER_HPP

View File

@ -0,0 +1,4 @@
# Names should be added to this file like so:
# Name or Organization <email address>
Google Inc.

View File

@ -0,0 +1,30 @@
Copyright (c) 2010, Google Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Google nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,23 @@
Additional IP Rights Grant (Patents)
------------------------------------
"These implementations" means the copyrightable works that implement the WebM
codecs distributed by Google as part of the WebM Project.
Google hereby grants to you a perpetual, worldwide, non-exclusive, no-charge,
royalty-free, irrevocable (except as stated in this section) patent license to
make, have made, use, offer to sell, sell, import, transfer, and otherwise
run, modify and propagate the contents of these implementations of WebM, where
such license applies only to those patent claims, both currently owned by
Google and acquired in the future, licensable by Google that are necessarily
infringed by these implementations of WebM. This grant does not include claims
that would be infringed only as a consequence of further modification of these
implementations. If you or your agent or exclusive licensee institute or order
or agree to the institution of patent litigation or any other patent
enforcement activity against any entity (including a cross-claim or
counterclaim in a lawsuit) alleging that any of these implementations of WebM
or any code incorporated within any of these implementations of WebM
constitute direct or contributory patent infringement, or inducement of
patent infringement, then any patent rights granted to you under this License
for these implementations of WebM shall terminate as of the date such
litigation is filed.

View File

@ -0,0 +1,11 @@
URL: https://chromium.googlesource.com/webm/libwebm
Version: 32d5ac49414a8914ec1e1f285f3f927c6e8ec29d
License: BSD
License File: LICENSE.txt
Description:
libwebm is used to handle WebM container I/O.
Local Changes:
* Removed: "mkvmuxer", "hdr_util", "file_util", "mkv_reader".
* Make "~IMkvRerader()" public.

View File

@ -0,0 +1,184 @@
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#ifndef COMMON_WEBMIDS_H_
#define COMMON_WEBMIDS_H_
namespace libwebm {
enum MkvId {
kMkvEBML = 0x1A45DFA3,
kMkvEBMLVersion = 0x4286,
kMkvEBMLReadVersion = 0x42F7,
kMkvEBMLMaxIDLength = 0x42F2,
kMkvEBMLMaxSizeLength = 0x42F3,
kMkvDocType = 0x4282,
kMkvDocTypeVersion = 0x4287,
kMkvDocTypeReadVersion = 0x4285,
kMkvVoid = 0xEC,
kMkvSignatureSlot = 0x1B538667,
kMkvSignatureAlgo = 0x7E8A,
kMkvSignatureHash = 0x7E9A,
kMkvSignaturePublicKey = 0x7EA5,
kMkvSignature = 0x7EB5,
kMkvSignatureElements = 0x7E5B,
kMkvSignatureElementList = 0x7E7B,
kMkvSignedElement = 0x6532,
// segment
kMkvSegment = 0x18538067,
// Meta Seek Information
kMkvSeekHead = 0x114D9B74,
kMkvSeek = 0x4DBB,
kMkvSeekID = 0x53AB,
kMkvSeekPosition = 0x53AC,
// Segment Information
kMkvInfo = 0x1549A966,
kMkvTimecodeScale = 0x2AD7B1,
kMkvDuration = 0x4489,
kMkvDateUTC = 0x4461,
kMkvTitle = 0x7BA9,
kMkvMuxingApp = 0x4D80,
kMkvWritingApp = 0x5741,
// Cluster
kMkvCluster = 0x1F43B675,
kMkvTimecode = 0xE7,
kMkvPrevSize = 0xAB,
kMkvBlockGroup = 0xA0,
kMkvBlock = 0xA1,
kMkvBlockDuration = 0x9B,
kMkvReferenceBlock = 0xFB,
kMkvLaceNumber = 0xCC,
kMkvSimpleBlock = 0xA3,
kMkvBlockAdditions = 0x75A1,
kMkvBlockMore = 0xA6,
kMkvBlockAddID = 0xEE,
kMkvBlockAdditional = 0xA5,
kMkvDiscardPadding = 0x75A2,
// Track
kMkvTracks = 0x1654AE6B,
kMkvTrackEntry = 0xAE,
kMkvTrackNumber = 0xD7,
kMkvTrackUID = 0x73C5,
kMkvTrackType = 0x83,
kMkvFlagEnabled = 0xB9,
kMkvFlagDefault = 0x88,
kMkvFlagForced = 0x55AA,
kMkvFlagLacing = 0x9C,
kMkvDefaultDuration = 0x23E383,
kMkvMaxBlockAdditionID = 0x55EE,
kMkvName = 0x536E,
kMkvLanguage = 0x22B59C,
kMkvCodecID = 0x86,
kMkvCodecPrivate = 0x63A2,
kMkvCodecName = 0x258688,
kMkvCodecDelay = 0x56AA,
kMkvSeekPreRoll = 0x56BB,
// video
kMkvVideo = 0xE0,
kMkvFlagInterlaced = 0x9A,
kMkvStereoMode = 0x53B8,
kMkvAlphaMode = 0x53C0,
kMkvPixelWidth = 0xB0,
kMkvPixelHeight = 0xBA,
kMkvPixelCropBottom = 0x54AA,
kMkvPixelCropTop = 0x54BB,
kMkvPixelCropLeft = 0x54CC,
kMkvPixelCropRight = 0x54DD,
kMkvDisplayWidth = 0x54B0,
kMkvDisplayHeight = 0x54BA,
kMkvDisplayUnit = 0x54B2,
kMkvAspectRatioType = 0x54B3,
kMkvFrameRate = 0x2383E3,
// end video
// colour
kMkvColour = 0x55B0,
kMkvMatrixCoefficients = 0x55B1,
kMkvBitsPerChannel = 0x55B2,
kMkvChromaSubsamplingHorz = 0x55B3,
kMkvChromaSubsamplingVert = 0x55B4,
kMkvCbSubsamplingHorz = 0x55B5,
kMkvCbSubsamplingVert = 0x55B6,
kMkvChromaSitingHorz = 0x55B7,
kMkvChromaSitingVert = 0x55B8,
kMkvRange = 0x55B9,
kMkvTransferCharacteristics = 0x55BA,
kMkvPrimaries = 0x55BB,
kMkvMaxCLL = 0x55BC,
kMkvMaxFALL = 0x55BD,
// mastering metadata
kMkvMasteringMetadata = 0x55D0,
kMkvPrimaryRChromaticityX = 0x55D1,
kMkvPrimaryRChromaticityY = 0x55D2,
kMkvPrimaryGChromaticityX = 0x55D3,
kMkvPrimaryGChromaticityY = 0x55D4,
kMkvPrimaryBChromaticityX = 0x55D5,
kMkvPrimaryBChromaticityY = 0x55D6,
kMkvWhitePointChromaticityX = 0x55D7,
kMkvWhitePointChromaticityY = 0x55D8,
kMkvLuminanceMax = 0x55D9,
kMkvLuminanceMin = 0x55DA,
// end mastering metadata
// end colour
// audio
kMkvAudio = 0xE1,
kMkvSamplingFrequency = 0xB5,
kMkvOutputSamplingFrequency = 0x78B5,
kMkvChannels = 0x9F,
kMkvBitDepth = 0x6264,
// end audio
// ContentEncodings
kMkvContentEncodings = 0x6D80,
kMkvContentEncoding = 0x6240,
kMkvContentEncodingOrder = 0x5031,
kMkvContentEncodingScope = 0x5032,
kMkvContentEncodingType = 0x5033,
kMkvContentCompression = 0x5034,
kMkvContentCompAlgo = 0x4254,
kMkvContentCompSettings = 0x4255,
kMkvContentEncryption = 0x5035,
kMkvContentEncAlgo = 0x47E1,
kMkvContentEncKeyID = 0x47E2,
kMkvContentSignature = 0x47E3,
kMkvContentSigKeyID = 0x47E4,
kMkvContentSigAlgo = 0x47E5,
kMkvContentSigHashAlgo = 0x47E6,
kMkvContentEncAESSettings = 0x47E7,
kMkvAESSettingsCipherMode = 0x47E8,
kMkvAESSettingsCipherInitData = 0x47E9,
// end ContentEncodings
// Cueing Data
kMkvCues = 0x1C53BB6B,
kMkvCuePoint = 0xBB,
kMkvCueTime = 0xB3,
kMkvCueTrackPositions = 0xB7,
kMkvCueTrack = 0xF7,
kMkvCueClusterPosition = 0xF1,
kMkvCueBlockNumber = 0x5378,
// Chapters
kMkvChapters = 0x1043A770,
kMkvEditionEntry = 0x45B9,
kMkvChapterAtom = 0xB6,
kMkvChapterUID = 0x73C4,
kMkvChapterStringUID = 0x5654,
kMkvChapterTimeStart = 0x91,
kMkvChapterTimeEnd = 0x92,
kMkvChapterDisplay = 0x80,
kMkvChapString = 0x85,
kMkvChapLanguage = 0x437C,
kMkvChapCountry = 0x437E,
// Tags
kMkvTags = 0x1254C367,
kMkvTag = 0x7373,
kMkvSimpleTag = 0x67C8,
kMkvTagName = 0x45A3,
kMkvTagString = 0x4487
};
} // namespace libwebm
#endif // COMMON_WEBMIDS_H_

View File

@ -0,0 +1,28 @@
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#ifndef MKVMUXER_MKVMUXERTYPES_H_
#define MKVMUXER_MKVMUXERTYPES_H_
namespace mkvmuxer {
typedef unsigned char uint8;
typedef short int16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
} // namespace mkvmuxer
// Copied from Chromium basictypes.h
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define LIBWEBM_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#endif // MKVMUXER_MKVMUXERTYPES_HPP_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff