Bug 187850

Summary: [MediaCapabilities] Platform integration
Product: WebKit Reporter: Philippe Normand <pnormand>
Component: MediaAssignee: Philippe Normand <pnormand>
Status: RESOLVED FIXED    
Severity: Normal CC: eric.carlson, jer.noble, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 186391    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Philippe Normand 2018-07-20 02:21:08 PDT
The current implementation of MediaCapabilities::decodingInfo() and MediaCapabilities::encodingInfo() are incomplete.
I wonder if the platform probing should be done by extending MediaPlayer with new static functions, would that be acceptable or should I implement a new platform abstraction for this?
Comment 1 Jer Noble 2018-07-20 09:23:10 PDT
@Philippe, we've introduced new platform abstractions, even for MediaPlayer-like capabilities, for Modern EME. I think it would be acceptable to introduce a new abstraction rather than re-use MediaPlayer.
Comment 2 Philippe Normand 2018-07-20 09:37:28 PDT
Ok Jer, that totally makes sense indeed. I'll work on a patch in that direction.
Comment 3 Philippe Normand 2018-07-25 05:26:26 PDT
Created attachment 345754 [details]
Patch
Comment 4 Philippe Normand 2018-07-25 05:27:30 PDT
This is my current WIP patch which has a decodingInfo() platform integration and a mock test. Before going further I'd like to gather some initial feedback on the approach taken.
Comment 5 Eric Carlson 2018-07-25 09:03:15 PDT
Comment on attachment 345754 [details]
Patch

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

> Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp:203
> +        auto info = MediaCapabilitiesInfo::create();
> +        auto engineConfiguration = MediaEngineConfigurationFactory::createDecodingConfiguration(configuration);

Nit: I wonder if it would be better to pass a lambda to createDecodingConfiguration in case a platform isn't able to get the platform capabilities synchronously?

> Source/WebCore/platform/mediacapabilities/MediaEngineConfiguration.cpp:42
> +    if (ok)
> +        return;

Shouldn't this be "if (!ok)"?

> Source/WebCore/platform/mediacapabilities/MediaEngineConfiguration.cpp:60
> +    double numerator = frameratePieces[0].toDouble(&ok);
> +    if (!ok)
> +        return;
> +
> +    double denominator = frameratePieces[1].toDouble(&ok);
> +    if (!ok)
> +        return;
> +
> +    if (!std::isfinite(numerator) || !std::isfinite(denominator))
> +        return;
> +
> +    m_framerate = numerator / denominator;

Nit: I think it would be better to store the numerator and denominator in case a platform can use a rational number. You can always keep the frameRate() method and do the division there.

> Source/WebCore/testing/Internals.cpp:512
> +    MediaEngineConfigurationFactory::disableMock();

This will leave GStreamer and AVFoundation disabled.

> Source/WebCore/testing/Internals.cpp:3447
> +#if USE(AVFOUNDATION)
> +    WebCore::DeprecatedGlobalSettings::setAVFoundationEnabled(false);
> +#endif
> +#if USE(GSTREAMER)
> +    WebCore::DeprecatedGlobalSettings::setGStreamerEnabled(false);
> +#endif

Why is this necessary?
Comment 6 Philippe Normand 2018-07-25 09:41:15 PDT
Comment on attachment 345754 [details]
Patch

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

Thanks for the early feedback Eric. I'll update the patch, add audio support to the decoding config, add a mock implementation for the encoding side, add a few more tests and fix EWS

>> Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp:203
>> +        auto engineConfiguration = MediaEngineConfigurationFactory::createDecodingConfiguration(configuration);
> 
> Nit: I wonder if it would be better to pass a lambda to createDecodingConfiguration in case a platform isn't able to get the platform capabilities synchronously?

Good point! The GStreamer implementation shouldn't need this but I can change the code already if the AVF backend will require it.

>> Source/WebCore/platform/mediacapabilities/MediaEngineConfiguration.cpp:42
>> +        return;
> 
> Shouldn't this be "if (!ok)"?

Oh, indeed :)

>> Source/WebCore/platform/mediacapabilities/MediaEngineConfiguration.cpp:60
>> +    m_framerate = numerator / denominator;
> 
> Nit: I think it would be better to store the numerator and denominator in case a platform can use a rational number. You can always keep the frameRate() method and do the division there.

Makes sense!

>> Source/WebCore/testing/Internals.cpp:512
>> +    MediaEngineConfigurationFactory::disableMock();
> 
> This will leave GStreamer and AVFoundation disabled.

Right, but the code below should be removed, as you hinted already.

>> Source/WebCore/testing/Internals.cpp:3447
>> +#endif
> 
> Why is this necessary?

Ah no, it isn't, because the factory checks the mock case first anyway.
Comment 7 Philippe Normand 2018-08-03 07:09:41 PDT
Created attachment 346480 [details]
Patch
Comment 8 Eric Carlson 2018-08-03 07:27:58 PDT
Comment on attachment 346480 [details]
Patch

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

> Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp:202
> +        MediaEngineConfigurationFactory::DecodingConfigurationCallback callback = [promise = WTFMove(promise)] (RefPtr<MediaEngineDecodingConfiguration> engineConfiguration) mutable {

Nit: I think you can use "auto" here.

> Source/WebCore/Modules/mediacapabilities/MediaCapabilities.cpp:252
> +        MediaEngineConfigurationFactory::EncodingConfigurationCallback callback = [promise = WTFMove(promise)] (RefPtr<MediaEngineEncodingConfiguration> engineConfiguration) mutable {

Ditto.

> Source/WebCore/platform/mediacapabilities/MediaEngineConfiguration.cpp:56
> +    double numerator = frameratePieces[0].toDouble(&ok);
> +    if (!ok)
> +        return;
> +
> +    double denominator = frameratePieces[1].toDouble(&ok);
> +    if (!ok)
> +        return;

You should also fail if numerator or denominator is zero.

> Source/WebCore/platform/mock/MediaEngineDecodingConfigurationMock.cpp:43
> +    RefPtr<MediaEngineVideoConfiguration> videoConfig = videoConfiguration();

Nit: you can use "auto" here.

> Source/WebCore/platform/mock/MediaEngineDecodingConfigurationMock.cpp:51
> +    RefPtr<MediaEngineAudioConfiguration> audioConfig = audioConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineDecodingConfigurationMock.cpp:60
> +    RefPtr<MediaEngineVideoConfiguration> videoConfig = videoConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineDecodingConfigurationMock.cpp:66
> +    RefPtr<MediaEngineAudioConfiguration> audioConfig = audioConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineDecodingConfigurationMock.cpp:75
> +    RefPtr<MediaEngineVideoConfiguration> videoConfig = videoConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineDecodingConfigurationMock.cpp:81
> +    RefPtr<MediaEngineAudioConfiguration> audioConfig = audioConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:43
> +    RefPtr<MediaEngineVideoConfiguration> videoConfig = videoConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:51
> +    RefPtr<MediaEngineAudioConfiguration> audioConfig = audioConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:60
> +    RefPtr<MediaEngineVideoConfiguration> videoConfig = videoConfiguration();

Ditto.

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:62
> +    if (videoConfig) {
> +        if (videoConfig->framerate() > 30)

Nit: these two lines can be collapsed.

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:66
> +    RefPtr<MediaEngineAudioConfiguration> audioConfig = audioConfiguration();

"auto".

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:77
> +    RefPtr<MediaEngineVideoConfiguration> videoConfig = videoConfiguration();
> +    if (videoConfig) {
> +        if (videoConfig->contentType().containerType() != "video/mp4")

Ditto the above.

> Source/WebCore/platform/mock/MediaEngineEncodingConfigurationMock.cpp:81
> +    RefPtr<MediaEngineAudioConfiguration> audioConfig = audioConfiguration();

"auto".
Comment 9 Philippe Normand 2018-08-03 07:31:54 PDT
Created attachment 346481 [details]
Patch
Comment 10 Philippe Normand 2018-08-03 07:33:24 PDT
Comment on attachment 346481 [details]
Patch

Ah, sorry I didn't notice your review. This patch was a win EWS build fix attempt. Will update the patch again taking into account your review :) Thanks!
Comment 11 Philippe Normand 2018-08-03 07:58:33 PDT
Created attachment 346484 [details]
Patch
Comment 12 Philippe Normand 2018-08-03 08:56:33 PDT
Created attachment 346492 [details]
Patch
Comment 13 Philippe Normand 2018-08-03 09:32:01 PDT
Created attachment 346498 [details]
Patch
Comment 14 Philippe Normand 2018-08-03 10:29:27 PDT
No idea what's wrong now with the win EWS... Welp :)
Comment 15 Eric Carlson 2018-08-03 11:02:47 PDT
(In reply to Philippe Normand from comment #14)
> No idea what's wrong now with the win EWS... Welp :)

Not likely your fault: "Unable to build without patch"
Comment 16 Philippe Normand 2018-08-05 02:26:30 PDT
Committed r234582: <https://trac.webkit.org/changeset/234582>
Comment 17 Radar WebKit Bug Importer 2018-08-05 02:27:18 PDT
<rdar://problem/42943258>