Skip to content

Commit

Permalink
Export FFMpeg sidedata in IMediaSampleSideData
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevcairiel committed Jul 10, 2016
1 parent 45f77f2 commit adad395
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
39 changes: 39 additions & 0 deletions common/includes/IMediaSideDataFFmpeg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2010-2016 Hendrik Leppkes
* http://www.1f0.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Initial design and concept by Gabest and the MPC-HC Team, copyright under GPLv2
* Contributions by Ti-BEN from the XBMC DSPlayer Project, also under GPLv2
*/

#pragma once

// {08FA97DB-392C-4132-9C41-0B6507C3A164}
DEFINE_GUID(IID_MediaSideDataFFMpeg,
0x8fa97db, 0x392c, 0x4132, 0x9c, 0x41, 0xb, 0x65, 0x7, 0xc3, 0xa1, 0x64);

extern "C" {
#include "libavcodec/avcodec.h"
}

#pragma pack(push, 1)
struct MediaSideDataFFMpeg
{
AVPacketSideData *side_data;
int side_data_elems;
};
#pragma pack(pop)
7 changes: 2 additions & 5 deletions demuxer/Demuxers/LAVFDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,8 @@ STDMETHODIMP CLAVFDemuxer::InitAVFormat(LPCOLESTR pszFileName, BOOL bForce)

av_opt_set_int(m_avFormat, "correct_ts_overflow", !m_pBluRay, 0);

// TODO: AVFMT_FLAG_KEEP_SIDE_DATA should be ON for all formats
if (m_bMatroska || m_bMPEGTS)
m_avFormat->flags |= AVFMT_FLAG_KEEP_SIDE_DATA;
else
m_avFormat->flags &= ~AVFMT_FLAG_KEEP_SIDE_DATA;
// preserve side-data in the packets properly
m_avFormat->flags |= AVFMT_FLAG_KEEP_SIDE_DATA;

m_timeOpening = time(nullptr);
int ret = avformat_find_stream_info(m_avFormat, nullptr);
Expand Down
27 changes: 27 additions & 0 deletions demuxer/LAVSplitter/PacketAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ STDMETHODIMP_(ULONG) CMediaPacketSample::Release()
SAFE_DELETE(m_pPacket);
SetPointer(nullptr, 0);

SAFE_DELETE(m_pSideData);

/* This may cause us to be deleted */
// Our refcount is reliably 0 thus no-one will mess with us
m_pAllocator->ReleaseBuffer(this);
Expand All @@ -83,9 +85,34 @@ STDMETHODIMP CMediaPacketSample::SetPacket(Packet *pPacket)
m_pPacket = pPacket;
SetPointer(pPacket->GetData(), (LONG)pPacket->GetDataSize());

SAFE_DELETE(m_pSideData);

if (pPacket->GetNumSideData() > 0) {
m_pSideData = new MediaSideDataFFMpeg();
m_pSideData->side_data = pPacket->GetSideData();
m_pSideData->side_data_elems = pPacket->GetNumSideData();
}

return S_OK;
}

STDMETHODIMP CMediaPacketSample::SetSideData(GUID guidType, const BYTE *pData, size_t size)
{
return E_NOTIMPL;
}

STDMETHODIMP CMediaPacketSample::GetSideData(GUID guidType, const BYTE **pData, size_t *pSize)
{
if (guidType == IID_MediaSideDataFFMpeg && m_pSideData) {
*pData = (const BYTE *)m_pSideData;
*pSize = sizeof(MediaSideDataFFMpeg);

return S_OK;
}

return E_INVALIDARG;
}

CPacketAllocator::CPacketAllocator(LPCTSTR pName, LPUNKNOWN pUnk, HRESULT *phr)
: CBaseAllocator(pName, pUnk, phr, TRUE, TRUE)
{
Expand Down
13 changes: 11 additions & 2 deletions demuxer/LAVSplitter/PacketAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@

#pragma once

#include "IMediaSideData.h"
#include "IMediaSideDataFFmpeg.h"

interface __declspec(uuid("0B2EE323-0ED8-452D-B31E-B9B4DE2C0C39"))
ILAVMediaSample : public IUnknown {
ILAVMediaSample : public IUnknown {
STDMETHOD(SetPacket)(Packet *pPacket) PURE;
};


class CMediaPacketSample : public CMediaSample, public ILAVMediaSample
class CMediaPacketSample : public CMediaSample, public ILAVMediaSample, public IMediaSideData
{
public:
CMediaPacketSample(LPCTSTR pName, CBaseAllocator *pAllocator, HRESULT *phr);
Expand All @@ -38,10 +41,16 @@ class CMediaPacketSample : public CMediaSample, public ILAVMediaSample
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();

// ILAVMediaSamples
STDMETHODIMP SetPacket(Packet *pPacket);

// IMediaSideData
STDMETHODIMP SetSideData(GUID guidType, const BYTE *pData, size_t size);
STDMETHODIMP GetSideData(GUID guidType, const BYTE **pData, size_t *pSize);

protected:
Packet *m_pPacket = nullptr;
MediaSideDataFFMpeg *m_pSideData = nullptr;
};

class CPacketAllocator : public CBaseAllocator
Expand Down
1 change: 1 addition & 0 deletions demuxer/LAVSplitter/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "registry.h"
#include "IGraphRebuildDelegate.h"
#include "IMediaSideDataFFmpeg.h"

// The GUID we use to register the splitter media types
DEFINE_GUID(MEDIATYPE_LAVSplitter,
Expand Down

0 comments on commit adad395

Please sign in to comment.