Repository navigation
[video_player_platform_interface] Add VideoDrmConfiguration - #13318
nateshmbhat wants to merge 7 commits into
Conversation
Adds a VideoDrmConfiguration base class and DataSource.drmConfiguration so platform implementations can accept DRM configuration for network sources. Split out of flutter#11115 per the federated plugin change process.
There was a problem hiding this comment.
Code Review
This pull request introduces VideoDrmConfiguration and adds a drmConfiguration property to DataSource in the video_player_platform_interface package to support DRM configurations for network sources. The feedback suggests enforcing the restriction that DRM configurations are only supported for network data sources by adding an assertion to the DataSource constructor, along with a corresponding unit test to verify this behavior.
| this.drmConfiguration, | ||
| }); |
There was a problem hiding this comment.
Since the documentation explicitly states that drmConfiguration is only supported for DataSourceType.network videos, we should enforce this invariant at the platform interface level using an assertion. This ensures consistent behavior across all platform implementations and catches misconfigurations early during development.
| this.drmConfiguration, | |
| }); | |
| this.drmConfiguration, | |
| }) : assert( | |
| drmConfiguration == null || sourceType == DataSourceType.network, | |
| 'DRM configurations are only supported for network data sources.', | |
| ); |
| expect(dataSource.drmConfiguration, same(configuration)); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Add a unit test to verify that constructing a DataSource with a DRM configuration for a non-network source type throws an assertion error, ensuring the new assertion behaves as expected.
| expect(dataSource.drmConfiguration, same(configuration)); | |
| }); | |
| } | |
| expect(dataSource.drmConfiguration, same(configuration)); | |
| }); | |
| test('DataSource throws assertion error if DRM configuration is provided for non-network source', () { | |
| expect( | |
| () => DataSource( | |
| sourceType: DataSourceType.asset, | |
| asset: 'assets/video.mp4', | |
| drmConfiguration: const _FakeDrmConfiguration(), | |
| ), | |
| throwsAssertionError, | |
| ); | |
| }); | |
| } |
References
- Code should be tested. Changes to plugin packages should have appropriate tests. (link)
…the platform interface Widevine is supported on more platforms than Android, so its configuration now lives alongside VideoDrmConfiguration where any implementation can recognize it.
Widevine is supported on more platforms than Android, so its configuration now lives in video_player_platform_interface (matching flutter#13318) instead of video_player_android. video_player re-exports it, so apps no longer need to depend on video_player_android directly to use Widevine.
|
@tarrinneal have updated the pr as suggested by @loic-sharma |
| /// Widevine is not tied to a single platform, so this configuration is shared | ||
| /// by every platform implementation that supports it. Implementations that do | ||
| /// not support Widevine reject it like any other unsupported | ||
| /// [VideoDrmConfiguration]. |
There was a problem hiding this comment.
Nit: Consider normative wording (Implementations that do not support Widevine should reject it...) to match [VideoDrmConfiguration] and [DataSource.drmConfiguration], since un-updated third-party implementations—and video_player_web unless updated in a follow-up PR—will ignore drmConfiguration until updated.
There was a problem hiding this comment.
Done, reworded to "should reject".
| /// Only supported for [DataSourceType.network] videos. Implementations | ||
| /// should throw an [ArgumentError] if a configuration is provided for | ||
| /// another source type, or if it is a subclass of [VideoDrmConfiguration] | ||
| /// that the implementation does not support. |
There was a problem hiding this comment.
In newer flutter/packages platform interfaces (e.g. path_provider_platform_interface, google_sign_in_platform_interface), unsupported platform capabilities throw [UnsupportedError] while invalid parameter combinations throw [ArgumentError]. Should an unsupported [VideoDrmConfiguration] subclass (or a platform without DRM support, such as video_player_web in the follow-up PRs) throw [UnsupportedError] rather than [ArgumentError]?
There was a problem hiding this comment.
Agreed. Unsupported subclasses now throw UnsupportedError; a DRM config on a non-network source is still an ArgumentError. Android and AVFoundation are updated to match in #11115.
…atform_interface # Conflicts: # packages/video_player/video_player_platform_interface/CHANGELOG.md
…orted DRM systems Unsupported DRM systems now throw UnsupportedError instead of ArgumentError, matching other platform interfaces. Also uses normative wording for implementations that don't support Widevine.
| /// The license exchange itself is performed by the platform implementation, | ||
| /// using [licenseUri] and [licenseHeaders]. | ||
| @immutable | ||
| class WidevineDrmConfiguration extends VideoDrmConfiguration { |
There was a problem hiding this comment.
note to self: If we get more shared drm configs, we should move them to a new sub directory to keep things organized.
There was a problem hiding this comment.
You can do it now if you want, but I won't prevent this from landing over it
There was a problem hiding this comment.
Done, moved both into lib/src/drm/ (exported from the main library).
tarrinneal
left a comment
There was a problem hiding this comment.
A couple things. If you feel differently about these, I'm open to hearing it
| @immutable | ||
| abstract class VideoDrmConfiguration { | ||
| /// Allows subclasses to be const constructed. | ||
| const VideoDrmConfiguration(); | ||
| } | ||
|
|
||
| /// Configuration for playing Widevine-protected content. | ||
| /// | ||
| /// Widevine is not tied to a single platform, so this configuration is shared | ||
| /// by every platform implementation that supports it. Implementations that do | ||
| /// not support Widevine should reject it like any other unsupported | ||
| /// [VideoDrmConfiguration]. | ||
| /// | ||
| /// The license exchange itself is performed by the platform implementation, | ||
| /// using [licenseUri] and [licenseHeaders]. | ||
| @immutable | ||
| class WidevineDrmConfiguration extends VideoDrmConfiguration { | ||
| /// Creates a configuration for Widevine playback. | ||
| const WidevineDrmConfiguration({ | ||
| required this.licenseUri, | ||
| this.licenseHeaders = const <String, String>{}, | ||
| }); | ||
|
|
||
| /// The license acquisition URL of the Widevine license server. | ||
| final Uri licenseUri; | ||
|
|
||
| /// Headers to attach to each license request sent to [licenseUri]. | ||
| /// | ||
| /// This is typically where provider-specific authorization tokens go. | ||
| final Map<String, String> licenseHeaders; | ||
| } |
There was a problem hiding this comment.
This class (VideoDrmConfiguration) should probably be abstract base (and WidevineDrmConfiguration) so external code can't implements it, keeping future additive changes non-breaking.
There was a problem hiding this comment.
Done: VideoDrmConfiguration is now abstract base and WidevineDrmConfiguration is base.
VideoDrmConfiguration is now abstract base and WidevineDrmConfiguration is base, so external code can't implement them and members can be added later without a breaking change. Both move to lib/src/drm/ and are exported from the main library.
Platform interface part of #11115 (DRM support for
video_player), split out now that the combined PR is approved, per the federated plugin change process. This is the interface code that was reviewed there, plusWidevineDrmConfiguration, which moved here fromvideo_player_androidper this request since Widevine isn't Android-only.Part of flutter/flutter#24923
Summary
VideoDrmConfigurationis the common type carried onDataSource.WidevineDrmConfigurationlives here because Widevine can be supported on several platforms (Android today; iOS, Linux, macOS and Windows are possible). Implementations that support it recognize it; others reject it like any unsupported configuration. FairPlay is Apple-only, soFairPlayDrmConfigurationstays invideo_player_avfoundation. The implementation changes follow in the next PRs once this is published.The pending
## NEXTchangelog entry (minimum SDK bump) is folded into 6.10.0.Evidence
Run locally with the CI-pinned Flutter (
.ci/flutter_master.version) using the repo's CI task scripts:video_player,_android,_avfoundation,_web)New tests in
test/drm_configuration_test.dart:Merge Danger
Door: two-way
Additive only: two new classes and a new optional, nullable constructor parameter. No existing signature changes.
Blast Radius: minimal
Implementations that ignore
drmConfigurationbehave exactly as before.Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2