Bug 1068597 - Enable h264 video decoder on 10.6. r=rillian

This commit is contained in:
Jean-Yves Avenard 2014-09-18 11:08:33 +10:00
parent 39150e62ac
commit eccd74dd03
4 changed files with 51 additions and 22 deletions

View File

@ -6,7 +6,7 @@
// Construct references to each of the CoreMedia symbols we use.
LINK_FUNC(CMVideoFormatDescriptionCreate)
LINK_FUNC(CMBlockBufferCreateWithMemoryBlock)
LINK_FUNC(CMSampleBufferCreate)
LINK_FUNC(CMTimeMake)
LINK_FUNC(VideoFormatDescriptionCreate)
LINK_FUNC(BlockBufferCreateWithMemoryBlock)
LINK_FUNC(SampleBufferCreate)
LINK_FUNC(TimeMake)

View File

@ -8,6 +8,7 @@
#include "AppleCMLinker.h"
#include "MainThreadUtils.h"
#include "nsCocoaFeatures.h"
#include "nsDebug.h"
#ifdef PR_LOGGING
@ -27,7 +28,7 @@ nsrefcnt AppleCMLinker::sRefCount = 0;
CFStringRef AppleCMLinker::skPropExtensionAtoms = nullptr;
CFStringRef AppleCMLinker::skPropFullRangeVideo = nullptr;
#define LINK_FUNC(func) typeof(func) func;
#define LINK_FUNC(func) typeof(CM ## func) CM ## func;
#include "AppleCMFunctions.h"
#undef LINK_FUNC
@ -44,30 +45,56 @@ AppleCMLinker::Link()
return sLinkStatus == LinkStatus_SUCCEEDED;
}
const char* dlname =
"/System/Library/Frameworks/CoreMedia.framework/CoreMedia";
if (!(sLink = dlopen(dlname, RTLD_NOW | RTLD_LOCAL))) {
const char* dlnames[] =
{ "/System/Library/Frameworks/CoreMedia.framework/CoreMedia",
"/System/Library/PrivateFrameworks/CoreMedia.framework/CoreMedia" };
bool dlfound = false;
for (size_t i = 0; i < ArrayLength(dlnames); i++) {
if ((sLink = dlopen(dlnames[i], RTLD_NOW | RTLD_LOCAL))) {
dlfound = true;
break;
}
}
if (!dlfound) {
NS_WARNING("Couldn't load CoreMedia framework");
goto fail;
}
#define LINK_FUNC(func) \
if (nsCocoaFeatures::OnLionOrLater()) {
#define LINK_FUNC2(func) \
func = (typeof(func))dlsym(sLink, #func); \
if (!func) { \
NS_WARNING("Couldn't load CoreMedia function " #func ); \
NS_WARNING("Couldn't load CoreMedia function " #func ); \
goto fail; \
}
#define LINK_FUNC(func) LINK_FUNC2(CM ## func)
#include "AppleCMFunctions.h"
#undef LINK_FUNC
#undef LINK_FUNC2
// Will only resolve in 10.7 and later.
skPropExtensionAtoms =
GetIOConst("kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms");
skPropExtensionAtoms =
GetIOConst("kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms");
skPropFullRangeVideo =
GetIOConst("kCMFormatDescriptionExtension_FullRangeVideo");
skPropFullRangeVideo =
GetIOConst("kCMFormatDescriptionExtension_FullRangeVideo");
if (!skPropExtensionAtoms || !skPropFullRangeVideo) {
} else {
#define LINK_FUNC2(cm, fig) \
cm = (typeof(cm))dlsym(sLink, #fig); \
if (!cm) { \
NS_WARNING("Couldn't load CoreMedia function " #fig ); \
goto fail; \
}
#define LINK_FUNC(func) LINK_FUNC2(CM ## func, Fig ## func)
#include "AppleCMFunctions.h"
#undef LINK_FUNC
#undef LINK_FUNC2
skPropExtensionAtoms =
GetIOConst("kFigFormatDescriptionExtension_SampleDescriptionExtensionAtoms");
}
if (!skPropExtensionAtoms) {
goto fail;
}

View File

@ -38,7 +38,7 @@ private:
static CFStringRef GetIOConst(const char* symbol);
};
#define LINK_FUNC(func) extern typeof(func)* func;
#define LINK_FUNC(func) extern typeof(CM ## func)* CM ## func;
#include "AppleCMFunctions.h"
#undef LINK_FUNC

View File

@ -322,21 +322,23 @@ AppleVTDecoder::CreateDecoderExtensions()
const void* extensionKeys[] =
{ kCVImageBufferChromaLocationBottomFieldKey,
kCVImageBufferChromaLocationTopFieldKey,
AppleCMLinker::skPropFullRangeVideo,
AppleCMLinker::skPropExtensionAtoms };
AppleCMLinker::skPropExtensionAtoms,
AppleCMLinker::skPropFullRangeVideo /* Not defined in 10.6 */ };
const void* extensionValues[] =
{ kCVImageBufferChromaLocation_Left,
kCVImageBufferChromaLocation_Left,
kCFBooleanTrue,
atoms };
atoms,
kCFBooleanTrue };
static_assert(ArrayLength(extensionKeys) == ArrayLength(extensionValues),
"Non matching keys/values array size");
return CFDictionaryCreate(kCFAllocatorDefault,
extensionKeys,
extensionValues,
ArrayLength(extensionKeys),
AppleCMLinker::skPropFullRangeVideo ?
ArrayLength(extensionKeys) :
ArrayLength(extensionKeys) - 1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}