Skip to content

Commit

Permalink
[ios/VideoToolbox] - dyload VideoToolbox framework and dependend on t…
Browse files Browse the repository at this point in the history
…he runtime ios version either load it from private or public frameworks path
  • Loading branch information
Memphiz committed Oct 19, 2015
1 parent 1bf674b commit 0af7a90
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 82 deletions.
2 changes: 2 additions & 0 deletions Kodi.xcodeproj/project.pbxproj
Expand Up @@ -3718,6 +3718,7 @@
DFBB4307178B574E006CC20A /* AddonCallbacksCodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddonCallbacksCodec.h; sourceTree = "<group>"; };
DFBB4317178B5E6F006CC20A /* CompileInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompileInfo.cpp; sourceTree = "<group>"; };
DFBB4318178B5E6F006CC20A /* CompileInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompileInfo.h; sourceTree = "<group>"; };
DFBD336A1BD531CB001A8FEE /* DllVideoToolBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DllVideoToolBox.h; sourceTree = "<group>"; };
DFBE803D15F7D72100D7D102 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
DFC6F4AD1AFF7CB10039A7FA /* _kiss_fft_guts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _kiss_fft_guts.h; sourceTree = "<group>"; };
DFC6F4AF1AFF7CB10039A7FA /* kiss_fft.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = kiss_fft.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7610,6 +7611,7 @@
children = (
E38E15430D25F9F900618676 /* libmpeg2 */,
E38E153B0D25F9F900618676 /* DllLibMpeg2.h */,
DFBD336A1BD531CB001A8FEE /* DllVideoToolBox.h */,
F597B05A18A804E0005AADAE /* DVDVideoCodec.cpp */,
E38E153C0D25F9F900618676 /* DVDVideoCodec.h */,
E38E153D0D25F9F900618676 /* DVDVideoCodecFFmpeg.cpp */,
Expand Down
2 changes: 1 addition & 1 deletion tools/darwin/Configurations/App-iOS.xcconfig
Expand Up @@ -40,7 +40,7 @@ COPY_PHASE_STRIP = NO
DEAD_CODE_STRIPPING = NO
OTHER_CPLUSPLUSFLAGS = $(inherited) $(OTHER_CFLAGS) -Wreorder

OTHER_LDFLAGS = $(XBMC_OTHER_LDFLAGS_COMMON) -weak_framework VideoToolbox -Wl,-segalign,4000
OTHER_LDFLAGS = $(XBMC_OTHER_LDFLAGS_COMMON)

GCC_PREPROCESSOR_DEFINITIONS = TARGET_DARWIN_IOS $(inherited)

Expand Down
6 changes: 0 additions & 6 deletions tools/darwin/Support/copyframeworks-ios.command
Expand Up @@ -75,12 +75,6 @@ chmod u+w "$TARGET_FRAMEWORKS/$(basename $a)"
install_name_tool -change "$a" "$DYLIB_NAMEPATH/$(basename $a)" "$TARGET_BINARY"
done

echo "Fixing $TARGET_BINARY VideoToolbox dylib name"
VTB_SDK6=/System/Library/Frameworks/VideoToolbox.framework/VideoToolbox
VTB_SDK5=/System/Library/PrivateFrameworks/VideoToolbox.framework/VideoToolbox
install_name_tool -change "$VTB_SDK6" "$VTB_SDK5" "$TARGET_BINARY"


echo "Package $EXTERNAL_LIBS/lib/python2.6"
mkdir -p "$TARGET_CONTENTS/Frameworks/lib"
PYTHONSYNC="rsync -aq --exclude .DS_Store --exclude *.a --exclude *.exe --exclude test --exclude tests"
Expand Down
135 changes: 60 additions & 75 deletions xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVideoToolBox.cpp
Expand Up @@ -38,80 +38,14 @@ extern "C" {
#include "libavformat/avformat.h"
}

#include "DllVideoToolBox.h"

#if defined(__cplusplus)
extern "C"
{
#endif

#pragma pack(push, 4)

//-----------------------------------------------------------------------------------
// /System/Library/PrivateFrameworks/VideoToolbox.framework
enum VTFormat {
kVTFormatJPEG = 'jpeg', // kCMVideoCodecType_JPEG
kVTFormatH264 = 'avc1', // kCMVideoCodecType_H264 (MPEG-4 Part 10))
kVTFormatMPEG4Video = 'mp4v', // kCMVideoCodecType_MPEG4Video (MPEG-4 Part 2)
kVTFormatMPEG2Video = 'mp2v' // kCMVideoCodecType_MPEG2Video
};
enum {
kVTDecoderNoErr = 0,
kVTDecoderHardwareNotSupportedErr = -12470,
kVTDecoderFormatNotSupportedErr = -12471,
kVTDecoderConfigurationError = -12472,
kVTDecoderDecoderFailedErr = -12473,
};
enum {
kVTDecodeInfo_Asynchronous = 1UL << 0,
kVTDecodeInfo_FrameDropped = 1UL << 1
};
enum {
// tells the decoder not to bother returning a CVPixelBuffer
// in the outputCallback. The output callback will still be called.
kVTDecoderDecodeFlags_DontEmitFrame = 1 << 1,
};
enum {
// decode and return buffers for all frames currently in flight.
kVTDecoderFlush_EmitFrames = 1 << 0
};

typedef UInt32 VTFormatId;
typedef CFTypeRef VTDecompressionSessionRef;

typedef void (*VTDecompressionOutputCallbackFunc)(
void *refCon,
CFDictionaryRef frameInfo,
OSStatus status,
UInt32 infoFlags,
CVBufferRef imageBuffer);

typedef struct _VTDecompressionOutputCallback VTDecompressionOutputCallback;
struct _VTDecompressionOutputCallback {
VTDecompressionOutputCallbackFunc callback;
void *refcon;
};

extern CFStringRef kVTVideoDecoderSpecification_EnableSandboxedVideoDecoder;

extern OSStatus VTDecompressionSessionCreate(
CFAllocatorRef allocator,
CMFormatDescriptionRef videoFormatDescription,
CFTypeRef sessionOptions,
CFDictionaryRef destinationPixelBufferAttributes,
VTDecompressionOutputCallback *outputCallback,
VTDecompressionSessionRef *session);

extern OSStatus VTDecompressionSessionDecodeFrame(
VTDecompressionSessionRef session, CMSampleBufferRef sbuf,
uint32_t decoderFlags, CFDictionaryRef frameInfo, uint32_t unk1);

extern OSStatus VTDecompressionSessionCopyProperty(VTDecompressionSessionRef session, CFTypeRef key, void* unk, CFTypeRef * value);
extern OSStatus VTDecompressionSessionCopySupportedPropertyDictionary(VTDecompressionSessionRef session, CFDictionaryRef * dict);
extern OSStatus VTDecompressionSessionSetProperty(VTDecompressionSessionRef session, CFStringRef propName, CFTypeRef propValue);
extern void VTDecompressionSessionInvalidate(VTDecompressionSessionRef session);
extern void VTDecompressionSessionRelease(VTDecompressionSessionRef session);
extern VTDecompressionSessionRef VTDecompressionSessionRetain(VTDecompressionSessionRef session);
extern OSStatus VTDecompressionSessionWaitForAsynchronousFrames(VTDecompressionSessionRef session);

//-----------------------------------------------------------------------------------
// /System/Library/Frameworks/CoreMedia.framework
union
Expand Down Expand Up @@ -202,7 +136,7 @@ vtdec_session_dump_property(CFStringRef prop_name, CFDictionaryRef prop_attrs, V
free(attrs_str);
}

status = VTDecompressionSessionCopyProperty(dpc->session, prop_name, NULL, &prop_value);
status = CDVDVideoCodecVideoToolBox::GetDllImpl()->VTDecompressionSessionCopyProperty(dpc->session, prop_name, NULL, &prop_value);
if (status == kVTDecoderNoErr)
{
char *value_str;
Expand Down Expand Up @@ -230,7 +164,7 @@ void vtdec_session_dump_properties(VTDecompressionSessionRef session)
CFDictionaryRef dict;
OSStatus status;

status = VTDecompressionSessionCopySupportedPropertyDictionary(session, &dict);
status = CDVDVideoCodecVideoToolBox::GetDllImpl()->VTDecompressionSessionCopySupportedPropertyDictionary(session, &dict);
if (status != kVTDecoderNoErr)
goto error;
CFDictionaryApplyFunction(dict, (CFDictionaryApplierFunction)vtdec_session_dump_property, &dpc);
Expand Down Expand Up @@ -1037,6 +971,8 @@ bool validate_avcC_spc(uint8_t *extradata, uint32_t extrasize, int32_t *max_ref_

//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
DllVideoToolBoxInterface *CDVDVideoCodecVideoToolBox::m_pLibVTB = NULL;

CDVDVideoCodecVideoToolBox::CDVDVideoCodecVideoToolBox() : CDVDVideoCodec()
{
m_fmt_desc = NULL;
Expand All @@ -1053,14 +989,60 @@ CDVDVideoCodecVideoToolBox::CDVDVideoCodecVideoToolBox() : CDVDVideoCodec()
memset(&m_videobuffer, 0, sizeof(DVDVideoPicture));
m_DropPictures = false;
m_sort_time_offset = 0.0;

if (m_pLibVTB == NULL)
{
if (CDarwinUtils::GetIOSVersion() < 6.0)
{
m_pLibVTB = new DllVideoToolBoxPrivate();
}
else
{
m_pLibVTB = new DllVideoToolBoxPublic();// todo - load the public version
}
}
}

CDVDVideoCodecVideoToolBox::~CDVDVideoCodecVideoToolBox()
{
Dispose();
pthread_mutex_destroy(&m_queue_mutex);
if (m_pLibVTB != NULL)
{
delete m_pLibVTB;
m_pLibVTB = NULL; // its a static!
}
}

bool CDVDVideoCodecVideoToolBox::HandleDyLoad()
{
bool ret = true;
if (CDarwinUtils::GetIOSVersion() < 6.0)
{
if(!((DllVideoToolBoxPrivate *)m_pLibVTB)->IsLoaded())
{
if(!((DllVideoToolBoxPrivate *)m_pLibVTB)->Load())
{
CLog::Log(LOGERROR,"VideoToolBox: Error loading private VideoToolBox framework (%s).",__FUNCTION__);
ret = false; //fatal
}
}
}
else
{
if(!((DllVideoToolBoxPublic *)m_pLibVTB)->IsLoaded())
{
if(!((DllVideoToolBoxPublic *)m_pLibVTB)->Load())
{
CLog::Log(LOGERROR,"VideoToolBox: Error loading public VideoToolBox framework (%s).",__FUNCTION__);
ret = false; //fatal
}
}
}
return ret;
}


bool CDVDVideoCodecVideoToolBox::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
{
if (CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEVIDEOTOOLBOX) && !hints.software)
Expand All @@ -1074,6 +1056,9 @@ bool CDVDVideoCodecVideoToolBox::Open(CDVDStreamInfo &hints, CDVDCodecOptions &o
unsigned int extrasize = hints.extrasize; // extra data for codec to use
uint8_t *extradata = (uint8_t*)hints.extradata; // size of extra data

if (!HandleDyLoad())
return false;

switch(profile)
{
case FF_PROFILE_H264_HIGH_10:
Expand Down Expand Up @@ -1387,7 +1372,7 @@ int CDVDVideoCodecVideoToolBox::Decode(uint8_t* pData, int iSize, double dts, do
}

// submit for decoding
status = VTDecompressionSessionDecodeFrame(m_vt_session, sampleBuff, decoderFlags, frameInfo, 0);
status = GetDllImpl()->VTDecompressionSessionDecodeFrame(m_vt_session, sampleBuff, decoderFlags, frameInfo, 0);
if (status != kVTDecoderNoErr)
{
CLog::Log(LOGNOTICE, "%s - VTDecompressionSessionDecodeFrame returned(%d)",
Expand All @@ -1404,7 +1389,7 @@ int CDVDVideoCodecVideoToolBox::Decode(uint8_t* pData, int iSize, double dts, do
}

// wait for decoding to finish
status = VTDecompressionSessionWaitForAsynchronousFrames(m_vt_session);
status = GetDllImpl()->VTDecompressionSessionWaitForAsynchronousFrames(m_vt_session);
if (status != kVTDecoderNoErr)
{
CLog::Log(LOGNOTICE, "%s - VTDecompressionSessionWaitForAsynchronousFrames returned(%d)",
Expand Down Expand Up @@ -1433,7 +1418,7 @@ int CDVDVideoCodecVideoToolBox::Decode(uint8_t* pData, int iSize, double dts, do
void CDVDVideoCodecVideoToolBox::Reset(void)
{
// flush decoder
VTDecompressionSessionWaitForAsynchronousFrames(m_vt_session);
GetDllImpl()->VTDecompressionSessionWaitForAsynchronousFrames(m_vt_session);

while (m_queue_depth)
DisplayQueuePop();
Expand Down Expand Up @@ -1569,7 +1554,7 @@ CDVDVideoCodecVideoToolBox::CreateVTSession(int width, int height, CMFormatDescr
outputCallback.callback = VTDecoderCallback;
outputCallback.refcon = this;

status = VTDecompressionSessionCreate(
status = GetDllImpl()->VTDecompressionSessionCreate(
NULL, // CFAllocatorRef allocator
fmt_desc,
NULL, // CFTypeRef sessionOptions
Expand All @@ -1595,7 +1580,7 @@ CDVDVideoCodecVideoToolBox::DestroyVTSession(void)
{
if (m_vt_session)
{
VTDecompressionSessionInvalidate((VTDecompressionSessionRef)m_vt_session);
GetDllImpl()->VTDecompressionSessionInvalidate((VTDecompressionSessionRef)m_vt_session);
CFRelease((VTDecompressionSessionRef)m_vt_session);
m_vt_session = NULL;
}
Expand Down
Expand Up @@ -27,6 +27,8 @@
#include <CoreVideo/CoreVideo.h>
#include <CoreMedia/CoreMedia.h>

class DllVideoToolBoxInterface;

// tracks a frame in and output queue in display order
typedef struct frame_queue {
double dts;
Expand All @@ -45,6 +47,8 @@ class CDVDVideoCodecVideoToolBox : public CDVDVideoCodec
CDVDVideoCodecVideoToolBox();
virtual ~CDVDVideoCodecVideoToolBox();

static DllVideoToolBoxInterface *GetDllImpl() { return m_pLibVTB; }

// Required overrides
virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options);
virtual void Dispose(void);
Expand All @@ -56,6 +60,7 @@ class CDVDVideoCodecVideoToolBox : public CDVDVideoCodec
virtual const char* GetName(void) { return (const char*)m_pFormatName; }

protected:
bool HandleDyLoad();
void DisplayQueuePop(void);
void CreateVTSession(int width, int height, CMFormatDescriptionRef fmt_desc);
void DestroyVTSession(void);
Expand All @@ -78,6 +83,7 @@ class CDVDVideoCodecVideoToolBox : public CDVDVideoCodec

bool m_convert_bytestream;
bool m_convert_3byteTo4byteNALSize;
static DllVideoToolBoxInterface *m_pLibVTB;//the framework
};

#endif

0 comments on commit 0af7a90

Please sign in to comment.