Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2017-06-21 08:44:55 +0300
committerHendrik Leppkes <h.leppkes@gmail.com>2017-06-21 08:44:55 +0300
commited90cc4273670c6e3933b6a812ea55e2ad06a9aa (patch)
treef8721297d246cd0e0ec6be6cd19306ee4560d5b2
parent75ad60266cf5acb576e92bca85c53a4daa44f8b9 (diff)
avcodec: pad incoming data before parsing, if required
This was lost in the recent decoding loop rework and causes issues with some source filters.
-rw-r--r--decoder/LAVVideo/decoders/avcodec.cpp22
-rw-r--r--decoder/LAVVideo/decoders/avcodec.h4
2 files changed, 18 insertions, 8 deletions
diff --git a/decoder/LAVVideo/decoders/avcodec.cpp b/decoder/LAVVideo/decoders/avcodec.cpp
index 918b6f0b..81429d30 100644
--- a/decoder/LAVVideo/decoders/avcodec.cpp
+++ b/decoder/LAVVideo/decoders/avcodec.cpp
@@ -482,7 +482,7 @@ STDMETHODIMP CDecAvcodec::InitDecoder(AVCodecID codec, const CMediaType *pmt)
LAVPinInfo lavPinInfo = {0};
BOOL bLAVInfoValid = SUCCEEDED(m_pCallback->GetLAVPinInfo(lavPinInfo));
- m_bInputPadded = (dwDecFlags & LAV_VIDEO_DEC_FLAG_LAVSPLITTER) && (m_pParser == nullptr);
+ m_bInputPadded = (dwDecFlags & LAV_VIDEO_DEC_FLAG_LAVSPLITTER);
// Setup codec-specific timing logic
@@ -641,9 +641,6 @@ STDMETHODIMP CDecAvcodec::DestroyDecoder()
av_freep(&m_pFFBuffer);
m_nFFBufferSize = 0;
- av_freep(&m_pFFBuffer2);
- m_nFFBufferSize2 = 0;
-
if (m_pSwsContext) {
sws_freeContext(m_pSwsContext);
m_pSwsContext = nullptr;
@@ -668,7 +665,7 @@ static void avpacket_mediasample_free(void *opaque, uint8_t *buffer)
STDMETHODIMP CDecAvcodec::FillAVPacketData(AVPacket *avpkt, const uint8_t *buffer, int buflen, IMediaSample *pSample, bool bRefCounting)
{
- if (m_bInputPadded)
+ if (m_bInputPadded && (m_pParser == nullptr))
{
avpkt->data = (uint8_t *)buffer;
avpkt->size = buflen;
@@ -782,6 +779,21 @@ STDMETHODIMP CDecAvcodec::ParsePacket(const BYTE *buffer, int buflen, REFERENCE_
uint8_t *pDataBuffer = (uint8_t *)buffer;
HRESULT hr = S_OK;
+ // re-allocate with padding, if needed
+ if (m_bInputPadded == false && buflen > 0) {
+ // re-allocate buffer to have enough space
+ BYTE *pBuf = (BYTE *)av_fast_realloc(m_pFFBuffer, &m_nFFBufferSize, buflen + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!pBuf)
+ return E_FAIL;
+
+ m_pFFBuffer = pBuf;
+
+ // copy data to buffer
+ memcpy(m_pFFBuffer, buffer, buflen);
+ memset(m_pFFBuffer + buflen, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+ pDataBuffer = m_pFFBuffer;
+ }
+
// loop over the data buffer until the parser has consumed all data
while (buflen > 0 || bFlush) {
REFERENCE_TIME rtStart = rtStartIn, rtStop = rtStopIn;
diff --git a/decoder/LAVVideo/decoders/avcodec.h b/decoder/LAVVideo/decoders/avcodec.h
index 084a21b8..7a3d50a7 100644
--- a/decoder/LAVVideo/decoders/avcodec.h
+++ b/decoder/LAVVideo/decoders/avcodec.h
@@ -74,9 +74,7 @@ private:
AVCodecParserContext *m_pParser = nullptr;
BYTE *m_pFFBuffer = nullptr;
- int m_nFFBufferSize = 0;
- BYTE *m_pFFBuffer2 = nullptr;
- int m_nFFBufferSize2 = 0;
+ unsigned int m_nFFBufferSize = 0;
SwsContext *m_pSwsContext = nullptr;