⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 279101 in webkit


Ignore:
Timestamp:
Jun 21, 2021, 7:15:51 PM (5 years ago)
Author:
eric.carlson@apple.com
Message:

[Mac] libwebrtc CMBaseClass objects need alignment fixup
https://bugs.webkit.org/show_bug.cgi?id=227137
<rdar://problem/79464124>

Reviewed by Youenn Fablet.

  • Source/webrtc/sdk/WebKit/WebKitDecoder.h: Define CMBASE_OBJECT_NEEDS_ALIGNMENT.
  • Source/webrtc/sdk/WebKit/WebKitVP8Decoder.cpp:

(webrtc::createWebKitVP8Decoder): Add padding to the CMBaseClass object on Mac and
Mac Catalyst when building for x86_64 so function pointers are naturally aligned.
Add static_asserts to ensure alignment and sizes are correct.

  • Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp:

(webrtc::createWebKitVP9Decoder): Ditto.

Location:
trunk/Source/ThirdParty/libwebrtc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/ThirdParty/libwebrtc/ChangeLog

    r279065 r279101  
     12021-06-21  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Mac] libwebrtc CMBaseClass objects need alignment fixup
     4        https://bugs.webkit.org/show_bug.cgi?id=227137
     5        <rdar://problem/79464124>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * Source/webrtc/sdk/WebKit/WebKitDecoder.h: Define CMBASE_OBJECT_NEEDS_ALIGNMENT.
     10
     11        * Source/webrtc/sdk/WebKit/WebKitVP8Decoder.cpp:
     12        (webrtc::createWebKitVP8Decoder): Add padding to the CMBaseClass object on Mac and
     13        Mac Catalyst when building for x86_64 so function pointers are naturally aligned.
     14        Add static_asserts to ensure alignment and sizes are correct.
     15
     16        * Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp:
     17        (webrtc::createWebKitVP9Decoder): Ditto.
     18
    1192021-06-21  Philippe Normand  <pnormand@igalia.com>
    220
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitDecoder.h

    r278701 r279101  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#include <Availability.h>
    2829#include "WebKitUtilities.h"
    2930#include "api/video/encoded_image.h"
     
    3435
    3536namespace webrtc {
     37
     38#if (TARGET_OS_OSX || TARGET_OS_MACCATALYST) && TARGET_CPU_X86_64
     39    #define CMBASE_OBJECT_NEEDS_ALIGNMENT 1
     40#else
     41    #define CMBASE_OBJECT_NEEDS_ALIGNMENT 0
     42#endif
    3643
    3744struct SdpVideoFormat;
     
    4855std::unique_ptr<webrtc::VideoDecoderFactory> createWebKitDecoderFactory(WebKitH265, WebKitVP9, WebKitVP9VTB);
    4956void videoDecoderTaskComplete(void* callback, uint32_t timeStamp, CVPixelBufferRef, uint32_t timeStampRTP);
    50 
    5157
    5258using LocalDecoder = void*;
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitVP8Decoder.cpp

    r279023 r279101  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4949static CFStringRef copyVP8DecoderDebugDescription(CMBaseObjectRef);
    5050
    51 static const CMBaseClass WebKitVP8Decoder_BaseClass =
    52 {
    53     kCMBaseObject_ClassVersion_1,
    54     sizeof(WebKitVP8Decoder),
    55     nullptr, // Comparison by pointer equality
    56     invalidateVP8Decoder,
    57     finalizeVP8Decoder,
    58     copyVP8DecoderDebugDescription,
    59     nullptr, // CopyProperty
    60     nullptr, // SetProperty
    61     nullptr,
    62     nullptr
    63 };
     51#if defined(CMBASE_OBJECT_NEEDS_ALIGNMENT) && CMBASE_OBJECT_NEEDS_ALIGNMENT
     52    constexpr size_t padSize = 4;
     53#else
     54    constexpr size_t padSize = 0;
     55#endif
     56
     57#pragma pack(push, 4)
     58struct DecoderClass {
     59    uint8_t pad[padSize];
     60    CMBaseClass alignedClass;
     61};
     62
     63static const DecoderClass WebKitVP8Decoder_BaseClass {
     64    { },
     65    {
     66        kCMBaseObject_ClassVersion_1,
     67        sizeof(WebKitVP8Decoder),
     68        nullptr, // Comparison by pointer equality
     69        invalidateVP8Decoder,
     70        finalizeVP8Decoder,
     71        copyVP8DecoderDebugDescription,
     72        nullptr, // CopyProperty
     73        nullptr, // SetProperty
     74        nullptr,
     75        nullptr
     76    }
     77};
     78#pragma pack(pop)
     79
     80#if defined(CMBASE_OBJECT_NEEDS_ALIGNMENT) && CMBASE_OBJECT_NEEDS_ALIGNMENT
     81    static_assert(sizeof(WebKitVP8Decoder_BaseClass.alignedClass.version) == sizeof(uint32_t), "CMBaseClass fixup is required!");
     82#else
     83    static_assert(sizeof(WebKitVP8Decoder_BaseClass.alignedClass.version) == sizeof(uintptr_t), "CMBaseClass fixup is not required!");
     84#endif
     85static_assert(offsetof(DecoderClass, alignedClass) == padSize, "CMBaseClass offset is incorrect!");
     86static_assert(alignof(DecoderClass) == 4, "CMBaseClass must have 4 byte alignment");
    6487
    6588static OSStatus startVP8DecoderSession(VTVideoDecoderRef, VTVideoDecoderSession, CMVideoFormatDescriptionRef);
     
    83106static const VTVideoDecoderVTable WebKitVP8DecoderVTable =
    84107{
    85     { nullptr, &WebKitVP8Decoder_BaseClass },
     108    { nullptr, &WebKitVP8Decoder_BaseClass.alignedClass },
    86109    &WebKitVP8Decoder_VideoDecoderClass
    87110};
  • trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp

    r279023 r279101  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4949static CFStringRef copyVP9DecoderDebugDescription(CMBaseObjectRef);
    5050
    51 static const CMBaseClass WebKitVP9Decoder_BaseClass =
    52 {
    53     kCMBaseObject_ClassVersion_1,
    54     sizeof(WebKitVP9Decoder),
    55     nullptr, // Comparison by pointer equality
    56     invalidateVP9Decoder,
    57     finalizeVP9Decoder,
    58     copyVP9DecoderDebugDescription,
    59     nullptr, // CopyProperty
    60     nullptr, // SetProperty
    61     nullptr,
    62     nullptr
    63 };
     51#if defined(CMBASE_OBJECT_NEEDS_ALIGNMENT) && CMBASE_OBJECT_NEEDS_ALIGNMENT
     52    constexpr size_t padSize = 4;
     53#else
     54    constexpr size_t padSize = 0;
     55#endif
     56
     57#pragma pack(push, 4)
     58struct DecoderClass {
     59    uint8_t pad[padSize];
     60    CMBaseClass alignedClass;
     61};
     62
     63static const DecoderClass WebKitVP9Decoder_BaseClass {
     64    { },
     65    {
     66        kCMBaseObject_ClassVersion_1,
     67        sizeof(WebKitVP9Decoder),
     68        nullptr, // Comparison by pointer equality
     69        invalidateVP9Decoder,
     70        finalizeVP9Decoder,
     71        copyVP9DecoderDebugDescription,
     72        nullptr, // CopyProperty
     73        nullptr, // SetProperty
     74        nullptr,
     75        nullptr
     76    }
     77};
     78#pragma pack(pop)
     79
     80#if defined(CMBASE_OBJECT_NEEDS_ALIGNMENT) && CMBASE_OBJECT_NEEDS_ALIGNMENT
     81    static_assert(sizeof(WebKitVP9Decoder_BaseClass.alignedClass.version) == sizeof(uint32_t), "CMBaseClass fixup is required!");
     82#else
     83    static_assert(sizeof(WebKitVP9Decoder_BaseClass.alignedClass.version) == sizeof(uintptr_t), "CMBaseClass fixup is not required!");
     84#endif
     85static_assert(offsetof(DecoderClass, alignedClass) == padSize, "CMBaseClass offset is incorrect!");
     86static_assert(alignof(DecoderClass) == 4, "CMBaseClass must have 4 byte alignment");
    6487
    6588static OSStatus startVP9DecoderSession(VTVideoDecoderRef, VTVideoDecoderSession, CMVideoFormatDescriptionRef);
     
    83106static const VTVideoDecoderVTable WebKitVP9DecoderVTable =
    84107{
    85     { nullptr, &WebKitVP9Decoder_BaseClass },
     108    { nullptr, &WebKitVP9Decoder_BaseClass.alignedClass },
    86109    &WebKitVP9Decoder_VideoDecoderClass
    87110};
Note: See TracChangeset for help on using the changeset viewer.