[FFmpeg-devel] [PATCH 1/2] osx: detect version of mac os

Paul B Mahol onemda at gmail.com
Thu Aug 23 12:49:05 CEST 2012


On 8/23/12, Xidorn Quan <quanxunzhen at gmail.com> wrote:
> ---
>  configure          |  2 ++
>  libavutil/Makefile |  4 +++
>  libavutil/osx.c    | 87
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavutil/osx.h    | 34 +++++++++++++++++++++
>  4 files changed, 127 insertions(+)
>  create mode 100644 libavutil/osx.c
>  create mode 100644 libavutil/osx.h
>
> diff --git a/configure b/configure
> index 0b95927..16d7b4e 100755
> --- a/configure
> +++ b/configure
> @@ -1234,6 +1234,7 @@ HAVE_LIST="
>      cmov
>      cpuid
>      cpunop
> +    CoreFoundation_CoreFoundation_h
>      dcbzl
>      dev_bktr_ioctl_bt848_h
>      dev_bktr_ioctl_meteor_h
> @@ -3382,6 +3383,7 @@ check_header vdpau/vdpau_x11.h
>  check_header windows.h
>  check_header X11/extensions/XvMClib.h
>  check_header asm/types.h
> +check_header CoreFoundation/CoreFoundation.h
>
>  disabled  zlib || check_lib   zlib.h      zlibVersion -lz   || disable
> zlib
>  disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable
> bzlib
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index ef1f658..88f1fb1 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -119,6 +119,10 @@ TESTPROGS = adler32
>                 \
>              tree                                                        \
>              xtea                                                        \
>
> +HEADERS-$(HAVE_COREFOUNDATION_COREFOUNDATION_H) += osx.h
> +
> +OBJS-$(HAVE_COREFOUNDATION_COREFOUNDATION_H) += osx.o
> +
>  TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
>
>  TOOLS = ffeval
> diff --git a/libavutil/osx.c b/libavutil/osx.c
> new file mode 100644
> index 0000000..ea85c3c
> --- /dev/null
> +++ b/libavutil/osx.c
> @@ -0,0 +1,87 @@
> +/*
> + * Copyright (c) 2012, Xidorn Quan
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +#include <stdio.h>
> +#include <CoreFoundation/CoreFoundation.h>
> +
> +#include "osx.h"
> +#include "mem.h"
> +
> +int av_get_osx_version(int *major, int *minor, int *bugfix)
> +{
> +    static int s_major = 0, s_minor = 0, s_bugfix = 0;
> +    CFURLRef versionPath;
> +    CFDataRef data;
> +    SInt32 errorCode;
> +    CFDictionaryRef dict;
> +    CFStringRef versionStr;
> +    CFIndex length;
> +    char *version;
> +
> +    if (s_major) {
> +        *major = s_major;
> +        *minor = s_minor;
> +        *bugfix = s_bugfix;
> +        return 0;
> +    }
> +
> +    versionPath = CFURLCreateWithFileSystemPath(NULL,
> +            CFSTR("/System/Library/CoreServices/SystemVersion.plist"),
> +            kCFURLPOSIXPathStyle, false);
> +    if (!CFURLCreateDataAndPropertiesFromResource(
> +                NULL, versionPath, &data, NULL, NULL, &errorCode))
> +        goto release_path;
> +
> +    dict = CFPropertyListCreateWithData(
> +            NULL, data, kCFPropertyListImmutable, NULL, NULL);
> +    if (!dict)
> +        goto release_data;
> +
> +    versionStr = CFDictionaryGetValue(dict, CFSTR("ProductVersion"));
> +    if (!versionStr)
> +        goto release_dict;
> +
> +    length = CFStringGetLength(versionStr) + 1;
> +    version = av_malloc(length);
> +    if (!version)
> +        goto release_dict;
> +
> +    if (!CFStringGetCString(versionStr,
> +            version, length, kCFStringEncodingUTF8))
> +        goto release_version;
> +
> +    sscanf(version, "%d.%d.%d", &s_major, &s_minor, &s_bugfix);
> +    *major = s_major;
> +    *minor = s_minor;
> +    *bugfix = s_bugfix;
> +
> +release_version:
> +    av_free(version);
> +
> +release_dict:
> +    CFRelease(dict);
> +
> +release_data:
> +    CFRelease(data);
> +
> +release_path:
> +    CFRelease(versionPath);
> +    return s_major ? 0 : -1;
> +}
> diff --git a/libavutil/osx.h b/libavutil/osx.h
> new file mode 100644
> index 0000000..afd6c4e
> --- /dev/null
> +++ b/libavutil/osx.h
> @@ -0,0 +1,34 @@
> +/*
> + * Copyright (c) 2012, Xidorn Quan
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +#ifndef AVUTIL_OSX_H
> +#define AVUTIL_OSX_H
> +
> +/**
> + * Get version of Mac OS X
> + *
> + * @param major  pointer to store major version
> + * @param minor  pointer to store minor version
> + * @param bugfix pointer to store bugfix version
> + * @return       zero if succeed, -1 otherwise
> + */
> +int av_get_osx_version(int *major, int *minor, int *bugfix);
> +
> +#endif /* AVUTIL_OSX_H */

I dislike such approach.


More information about the ffmpeg-devel mailing list