Bug 134946

Summary: [Win] Fix Assert when handling Legible Output callbacks
Product: WebKit Reporter: Brent Fulgham <bfulgham>
Component: MediaAssignee: Brent Fulgham <bfulgham>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, commit-queue, dbates, eric.carlson, glenn, jer.noble, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 135173    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Ignore. Accidental merge of two patches.
none
Patch
none
Add struct declarations to support building on EWS bots none

Description Brent Fulgham 2014-07-15 15:37:32 PDT
The changes in Bug 134178 introduced a Debug Assert in Windows, because the new InbandTextTrackPrivateAVF::processNativeSamples method is called on Windows, but is stubbed out as an 'ASSERT_NOT_REACHED'.

This code should not have been excluded on Windows. This patch allows Windows to use the same code path as Mac/iOS, and prevents the assertion from firing.
Comment 1 Radar WebKit Bug Importer 2014-07-15 15:40:50 PDT
<rdar://problem/17687098>
Comment 2 Brent Fulgham 2014-07-15 15:41:12 PDT
Created attachment 234960 [details]
Patch
Comment 3 Brent Fulgham 2014-07-15 15:42:10 PDT
Created attachment 234961 [details]
Patch
Comment 4 Eric Carlson 2014-07-15 20:05:29 PDT
Comment on attachment 234961 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=234961&action=review

Thanks Brent!

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1534
> +    RetainPtr<CFArrayRef> subtypes = createLegibleOutputSubtypes();

I think you want to adoptCF(createLegibleOutputSubtypes()) because the array already has a ref count of 1.
Comment 5 Darin Adler 2014-07-16 18:06:08 PDT
Comment on attachment 234961 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=234961&action=review

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1495
> +    formatTypes[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &webvtt);

This CFNumber leaks. I suggest this instead:

    int webVTTInt = kCMSubtitleFormatType_WebVTT;
    RetainPtr<CFNumberRef> webVTTNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &webVTTInt));
    CFTypeRef formatTypes[] = { webVTTNumber.get(); };
    return adoptCF(CFArrayCreate(0, formatTypes, WTF_ARRAY_LENGT(formatTypes), &kCFTypeArrayCallBacks));

>> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1534
>> +    RetainPtr<CFArrayRef> subtypes = createLegibleOutputSubtypes();
> 
> I think you want to adoptCF(createLegibleOutputSubtypes()) because the array already has a ref count of 1.

That’s right, but it’s also better to have that function return a RetainPtr so the adoptCF is right next to the CFArrayCreate.
Comment 6 Brent Fulgham 2014-07-17 15:18:16 PDT
Comment on attachment 234961 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=234961&action=review

>> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1495
>> +    formatTypes[0] = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &webvtt);
> 
> This CFNumber leaks. I suggest this instead:
> 
>     int webVTTInt = kCMSubtitleFormatType_WebVTT;
>     RetainPtr<CFNumberRef> webVTTNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &webVTTInt));
>     CFTypeRef formatTypes[] = { webVTTNumber.get(); };
>     return adoptCF(CFArrayCreate(0, formatTypes, WTF_ARRAY_LENGT(formatTypes), &kCFTypeArrayCallBacks));

Done!

>>> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1534
>>> +    RetainPtr<CFArrayRef> subtypes = createLegibleOutputSubtypes();
>> 
>> I think you want to adoptCF(createLegibleOutputSubtypes()) because the array already has a ref count of 1.
> 
> That’s right, but it’s also better to have that function return a RetainPtr so the adoptCF is right next to the CFArrayCreate.

Done.
Comment 7 Brent Fulgham 2014-07-17 15:20:57 PDT
Created attachment 235094 [details]
Patch
Comment 8 Darin Adler 2014-07-19 23:25:27 PDT
Comment on attachment 235094 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=235094&action=review

> Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:77
> +SOFT_LINK_DLL_IMPORT(CoreMedia, CMSampleBufferGetDataBuffer, CMBlockBufferRef, __cdecl, (CMSampleBufferRef sbuf), (sbuf))

This change isn’t mentioned explicitly in the change log, but it’s not yet compiling on EWS:

     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2143: syntax error : missing ';' before '__cdecl'
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2065: 'CMSampleBufferRef' : undeclared identifier
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2146: syntax error : missing ')' before identifier 'sbuf'
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): warning C4229: anachronism used : modifiers on data are ignored
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2059: syntax error : ')'
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2059: syntax error : '__cdecl'
     1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2086: 'int CMBlockBufferRef' : redefinition

Maybe they don’t have the correct version of CoreMedia.h?
Comment 9 Darin Adler 2014-07-19 23:26:54 PDT
Comment on attachment 235094 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=235094&action=review

review+ if you can get it to compile on EWS and bots and such

> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1533
> +    RetainPtr<CFArrayRef> subtypes = createLegibleOutputSubtypes();
> +    m_legibleOutput = adoptCF(AVCFPlayerItemLegibleOutputCreateWithMediaSubtypesForNativeRepresentation(kCFAllocatorDefault, subtypes.get()));

Not sure you really even need the local variable here. Putting createLegibleOutputSubtypes right into the expression might make the line excessively long, but otherwise it seems like an improvement.
Comment 10 Brent Fulgham 2014-07-21 16:05:22 PDT
Created attachment 235251 [details]
Ignore. Accidental merge of two patches.
Comment 11 Brent Fulgham 2014-07-22 12:41:52 PDT
Comment on attachment 235094 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=235094&action=review

>> Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:77
>> +SOFT_LINK_DLL_IMPORT(CoreMedia, CMSampleBufferGetDataBuffer, CMBlockBufferRef, __cdecl, (CMSampleBufferRef sbuf), (sbuf))
> 
> This change isn’t mentioned explicitly in the change log, but it’s not yet compiling on EWS:
> 
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2143: syntax error : missing ';' before '__cdecl'
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2065: 'CMSampleBufferRef' : undeclared identifier
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2146: syntax error : missing ')' before identifier 'sbuf'
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): warning C4229: anachronism used : modifiers on data are ignored
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2059: syntax error : ')'
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2059: syntax error : '__cdecl'
>      1>..\platform\graphics\avfoundation\InbandTextTrackPrivateAVF.cpp(77): error C2086: 'int CMBlockBufferRef' : redefinition
> 
> Maybe they don’t have the correct version of CoreMedia.h?

Yes, it looks like the EWS bots are set up with an old set of headers. I'm trying to get confirmation on how these machines are configured.

>> Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:1533
>> +    m_legibleOutput = adoptCF(AVCFPlayerItemLegibleOutputCreateWithMediaSubtypesForNativeRepresentation(kCFAllocatorDefault, subtypes.get()));
> 
> Not sure you really even need the local variable here. Putting createLegibleOutputSubtypes right into the expression might make the line excessively long, but otherwise it seems like an improvement.

Sounds good to me!
Comment 12 Brent Fulgham 2014-07-22 12:55:19 PDT
Created attachment 235307 [details]
Patch
Comment 13 Brent Fulgham 2014-07-22 13:00:50 PDT
Committed r171357: <http://trac.webkit.org/changeset/171357>
Comment 14 WebKit Commit Bot 2014-07-22 13:24:59 PDT
Re-opened since this is blocked by bug 135173
Comment 15 Brent Fulgham 2014-07-22 13:50:26 PDT
Created attachment 235312 [details]
Add struct declarations to support building on EWS bots
Comment 16 Brent Fulgham 2014-07-23 08:50:26 PDT
Change landed as follows:

1. Bulk of change (building locally): <http://trac.webkit.org/changeset/171385>
2. Attempt forward declaration: <http://trac.webkit.org/changeset/171388>
3. Provide struct definition: <http://trac.webkit.org/changeset/171392>
4. Provide missing constant declaration: <http://trac.webkit.org/changeset/171404>

Changes are in place and working on all bots.