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>2016-07-11 12:42:51 +0300
committerHendrik Leppkes <h.leppkes@gmail.com>2016-07-11 12:56:46 +0300
commita1f280ecae1f8dc200f8007ba07aeba85f89cc73 (patch)
tree44b1e09d7207606075f8fa6ad20f9e3752511bf3 /decoder
parentae1f01fedee935731bf3e7c1c0f5844ab03ca6af (diff)
Forward FFMpeg side-data to the decoders
Diffstat (limited to 'decoder')
-rw-r--r--decoder/LAVAudio/LAVAudio.cpp38
-rw-r--r--decoder/LAVAudio/LAVAudio.h4
-rw-r--r--decoder/LAVAudio/dllmain.cpp1
-rw-r--r--decoder/LAVVideo/decoders/avcodec.cpp17
-rw-r--r--decoder/LAVVideo/dllmain.cpp1
5 files changed, 52 insertions, 9 deletions
diff --git a/decoder/LAVAudio/LAVAudio.cpp b/decoder/LAVAudio/LAVAudio.cpp
index e14a34e1..6d94f08d 100644
--- a/decoder/LAVAudio/LAVAudio.cpp
+++ b/decoder/LAVAudio/LAVAudio.cpp
@@ -26,6 +26,8 @@
#include "moreuuids.h"
#include "DShowUtil.h"
+#include "IMediaSideData.h"
+#include "IMediaSideDataFFmpeg.h"
#include "AudioSettingsProp.h"
@@ -1505,8 +1507,8 @@ HRESULT CLAVAudio::EndOfStream()
CAutoLock cAutoLock(&m_csReceive);
// Flush the last data out of the parser
- ProcessBuffer();
- ProcessBuffer(TRUE);
+ ProcessBuffer(nullptr);
+ ProcessBuffer(nullptr, TRUE);
FlushOutput(TRUE);
return __super::EndOfStream();
@@ -1701,7 +1703,7 @@ HRESULT CLAVAudio::Receive(IMediaSample *pIn)
m_buff.Allocate(bufflen + len + FF_INPUT_BUFFER_PADDING_SIZE);
m_buff.Append(pDataIn, len);
- hr = ProcessBuffer();
+ hr = ProcessBuffer(pIn);
if (FAILED(hr))
return hr;
@@ -1775,7 +1777,7 @@ HRESULT CLAVAudio::ResyncMPEGAudio()
return S_FALSE;
}
-HRESULT CLAVAudio::ProcessBuffer(BOOL bEOF)
+HRESULT CLAVAudio::ProcessBuffer(IMediaSample *pMediaSample, BOOL bEOF)
{
HRESULT hr = S_OK, hr2 = S_OK;
@@ -1851,7 +1853,7 @@ HRESULT CLAVAudio::ProcessBuffer(BOOL bEOF)
return S_FALSE;
m_bMPEGAudioResync = FALSE;
- return ProcessBuffer(FALSE);
+ return ProcessBuffer(pMediaSample, FALSE);
}
} else {
if (!m_bFindDTSInPCM) {
@@ -1880,7 +1882,7 @@ HRESULT CLAVAudio::ProcessBuffer(BOOL bEOF)
if (m_pDTSDecoderContext)
hr2 = DecodeDTS(p, buffer_size, consumed, &hr);
else
- hr2 = Decode(p, buffer_size, consumed, &hr);
+ hr2 = Decode(p, buffer_size, consumed, &hr, pMediaSample);
// FAILED - throw away the data
if (FAILED(hr2)) {
DbgLog((LOG_TRACE, 10, L"Dropped invalid sample in ProcessBuffer"));
@@ -1925,7 +1927,7 @@ static DWORD get_lav_channel_layout(uint64_t layout)
return (DWORD)layout;
}
-HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed, HRESULT *hrDeliver)
+HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed, HRESULT *hrDeliver, IMediaSample *pMediaSample)
{
int got_frame = 0;
BYTE *tmpProcessBuf = nullptr;
@@ -1937,6 +1939,7 @@ HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed,
av_init_packet(&avpkt);
BufferDetails out;
+ const MediaSideDataFFMpeg *pFFSideData = nullptr;
if (!bFlush && (m_raData.deint_id == MKBETAG('g', 'e', 'n', 'r') || m_raData.deint_id == MKBETAG('s', 'i', 'p', 'r'))) {
int w = m_raData.audio_framesize;
@@ -1979,6 +1982,18 @@ HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed,
}
#endif
+ if (pMediaSample) {
+ IMediaSideData *pSideData = nullptr;
+ if (SUCCEEDED(pMediaSample->QueryInterface(&pSideData))) {
+ size_t nFFSideDataSize = 0;
+ if (FAILED(pSideData->GetSideData(IID_MediaSideDataFFMpeg, (const BYTE **)&pFFSideData, &nFFSideDataSize)) || nFFSideDataSize != sizeof(MediaSideDataFFMpeg)) {
+ pFFSideData = nullptr;
+ }
+
+ SafeRelease(&pSideData);
+ }
+ }
+
consumed = 0;
while (buffsize > 0 || bFlush) {
got_frame = 0;
@@ -2016,10 +2031,13 @@ HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed,
avpkt.size = pOut_size;
avpkt.dts = m_rtStartInputCache;
+ CopyMediaSideDataFF(&avpkt, &pFFSideData);
+
int ret2 = avcodec_decode_audio4(m_pAVCtx, m_pFrame, &got_frame, &avpkt);
if (ret2 < 0) {
DbgLog((LOG_TRACE, 50, L"::Decode() - decoding failed despite successfull parsing"));
m_bQueueResync = TRUE;
+ av_packet_unref(&avpkt);
continue;
}
@@ -2039,12 +2057,16 @@ HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed,
avpkt.size = buffsize;
avpkt.dts = m_rtStartInput;
+ CopyMediaSideDataFF(&avpkt, &pFFSideData);
+
int used_bytes = avcodec_decode_audio4(m_pAVCtx, m_pFrame, &got_frame, &avpkt);
if(used_bytes < 0) {
+ av_packet_unref(&avpkt);
goto fail;
} else if(used_bytes == 0 && !got_frame) {
DbgLog((LOG_TRACE, 50, L"::Decode() - could not process buffer, starving?"));
+ av_packet_unref(&avpkt);
break;
}
buffsize -= used_bytes;
@@ -2056,6 +2078,8 @@ HRESULT CLAVAudio::Decode(const BYTE * pDataBuffer, int buffsize, int &consumed,
m_rtStartInput = AV_NOPTS_VALUE;
}
+ av_packet_unref(&avpkt);
+
// Channel re-mapping and sample format conversion
if (got_frame) {
ASSERT(m_pFrame->nb_samples > 0);
diff --git a/decoder/LAVAudio/LAVAudio.h b/decoder/LAVAudio/LAVAudio.h
index 906114fd..4f19f85d 100644
--- a/decoder/LAVAudio/LAVAudio.h
+++ b/decoder/LAVAudio/LAVAudio.h
@@ -187,8 +187,8 @@ private:
CMediaType CreateMediaType(LAVAudioSampleFormat outputFormat, DWORD nSamplesPerSec, WORD nChannels, DWORD dwChannelMask, WORD wBitsPerSample = 0) const;
HRESULT ReconnectOutput(long cbBuffer, CMediaType& mt);
- HRESULT ProcessBuffer(BOOL bEOF = FALSE);
- HRESULT Decode(const BYTE *p, int buffsize, int &consumed, HRESULT *hrDeliver);
+ HRESULT ProcessBuffer(IMediaSample *pMediaSample, BOOL bEOF = FALSE);
+ HRESULT Decode(const BYTE *p, int buffsize, int &consumed, HRESULT *hrDeliver, IMediaSample *pMediaSample);
HRESULT PostProcess(BufferDetails *buffer);
HRESULT GetDeliveryBuffer(IMediaSample **pSample, BYTE **pData);
diff --git a/decoder/LAVAudio/dllmain.cpp b/decoder/LAVAudio/dllmain.cpp
index a75842cb..458fd004 100644
--- a/decoder/LAVAudio/dllmain.cpp
+++ b/decoder/LAVAudio/dllmain.cpp
@@ -34,6 +34,7 @@
#include "LAVAudio.h"
#include "AudioSettingsProp.h"
#include "moreuuids.h"
+#include "IMediaSideDataFFmpeg.h"
#include "registry.h"
diff --git a/decoder/LAVVideo/decoders/avcodec.cpp b/decoder/LAVVideo/decoders/avcodec.cpp
index 7f51357b..3bb1910a 100644
--- a/decoder/LAVVideo/decoders/avcodec.cpp
+++ b/decoder/LAVVideo/decoders/avcodec.cpp
@@ -27,6 +27,7 @@
#include "Media.h"
#include "IMediaSideData.h"
+#include "IMediaSideDataFFmpeg.h"
#include "ByteParser.h"
#ifdef DEBUG
@@ -645,6 +646,7 @@ STDMETHODIMP CDecAvcodec::Decode(const BYTE *buffer, int buflen, REFERENCE_TIME
int used_bytes = 0;
BOOL bFlush = (buffer == nullptr);
BOOL bEndOfSequence = FALSE;
+ const MediaSideDataFFMpeg *pFFSideData = nullptr;
AVPacket avpkt;
av_init_packet(&avpkt);
@@ -693,6 +695,19 @@ STDMETHODIMP CDecAvcodec::Decode(const BYTE *buffer, int buflen, REFERENCE_TIME
}
}
+
+ if (pSample) {
+ IMediaSideData *pSideData = nullptr;
+ if (SUCCEEDED(pSample->QueryInterface(&pSideData))) {
+ size_t nFFSideDataSize = 0;
+ if (FAILED(pSideData->GetSideData(IID_MediaSideDataFFMpeg, (const BYTE **)&pFFSideData, &nFFSideDataSize)) || nFFSideDataSize != sizeof(MediaSideDataFFMpeg)) {
+ pFFSideData = nullptr;
+ }
+
+ SafeRelease(&pSideData);
+ }
+ }
+
while (buflen > 0 || bFlush) {
REFERENCE_TIME rtStart = rtStartIn, rtStop = rtStopIn;
@@ -706,6 +721,8 @@ STDMETHODIMP CDecAvcodec::Decode(const BYTE *buffer, int buflen, REFERENCE_TIME
avpkt.duration = 0;
avpkt.flags = AV_PKT_FLAG_KEY;
+ CopyMediaSideDataFF(&avpkt, &pFFSideData);
+
if (m_bHasPalette) {
m_bHasPalette = FALSE;
uint32_t *pal = (uint32_t *)av_packet_new_side_data(&avpkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
diff --git a/decoder/LAVVideo/dllmain.cpp b/decoder/LAVVideo/dllmain.cpp
index 20c7cf8a..a09ee877 100644
--- a/decoder/LAVVideo/dllmain.cpp
+++ b/decoder/LAVVideo/dllmain.cpp
@@ -35,6 +35,7 @@
#include "LAVVideo.h"
#include "VideoSettingsProp.h"
#include "moreuuids.h"
+#include "IMediaSideDataFFmpeg.h"
#include "registry.h"