Skip to content

Support for content protection #41

Open

Description

@aboba

I would like to understand how WebCodecs supports content protection. In WebRTC NV Uses Cases, we initially had a use case where Javascript could be trusted with keys used to encrypt or decrypt protected content. That use case was removed after the IESG took objection. So the question is how WebCodecs can address the only remaining use case (untrusted Javascript).

Activity

  1. chcunningham commented on Feb 12, 2020

    @chcunningham
    Collaborator
  2. sandersdan commented on Feb 12, 2020

    @sandersdan
    Contributor

    So far I have been assuming that we will be able to associate a MediaKeys (EME) instance to a VideoDecoder (or AudioDecoder), but lacking a protected video output path it's not yet clear how that will work. It may be possible to plumb a protected picture using a canvas imagebitmap context, but I don't know if that is workable on all platforms. It may be necessary to integrate more directly with <video> than the current proposal.

    I don't know of any way to use an app-supplied decoder with MediaKeys. I don't think there is any path for encoding with MediaKeys.

  3. aboba commented on Apr 10, 2021

    @aboba
    CollaboratorAuthor

    @sandersdan The use cases I'm aware of typically involve decoding rather than encoding. Encoding would be involved in video upload, but typically content protection isn't introduced there. Decode use cases often involve low-latency streaming (over RTCDataChannel or WebTransport), where WebCodecs would provide a higher performance and potentially more interoperable substitute for "low-latency MSE". The events being streamed could be sporting events, musical or theatrical performances, political gatherings, company meetings, games or AR/VR demonstrations.

    Some examples are collected here.

  4. n8o commented on May 11, 2021

    @n8o

    I am also interested in this scenario. Being able to use WebCodecs with DRM (Fairplay, widevine, playready) would be beneficial. We could keep the DRMed elementary stream in the same format to be compatible with CMAF but without the container.

  5. chcunningham commented on May 12, 2021

    @chcunningham
    Collaborator

    triage note: marking 'extension', as the anticipated shape (associating MediaKeys) would be done via new members on the config dict, or new methods on the codec interface. As Dan points out, further extensions to canvas are probably also necessary.

  6. added
    extension
    on May 12, 2021
  7. bobh-dazn commented on Jul 1, 2021

    @bobh-dazn

    There are at least three key parts to a secure video pipeline:

    1. Trusted execution
    2. Secure video pipeline
    3. Secure key exchange

    In the first part you, as the person issuing the protected content, have to trust the client implementation that it won't allow the plaintext elementary streams, or the uncompressed essences out of the system. You can't have an EME pipeline that passes plaintext elementary streams back in a way which can be inspected, modified or diverted. You also cannot have a decode pipeline which allows injection of code, inspection of code or access to the image space by other code. In previous secure implementations I have worked with any transformations of the video were usually done as a separate layer where the underlying software had no actual access to the video frame buffer but it could command the frame buffer to resize, warp, etc. An upper layer image compositor in secure memory space was the final arbiter for the render.

    Secure key exchange doesn't have to be rocket science or proprietary, the principle is well understood, again it's about protected memory that other (untrusted) components of the system cannot access. It's possible to define secure domains of trust where a crypto pipeline could request secrets and not allow them to pass outside of that execution environment.

    If there was a browser implementation of secure execution pipelines which was able to make use of native trusted execution, and in which the browser was effectively able to execute signed code (even if not encrypted / scrambled) against secure memory then there would even not necessarily need to be proprietary DRM implementations. Ultimately it's about not allowing image/video data in memory to be inspected or read, even if being modified, that's the key factor. It's been done before in hardware and it could probably be allowed in software when backed up by a trusted system. But if the render pipeline isn't secured somehow then it's basically not going to get traction with those who care about premium content rights.

  8. padenot commented on Jul 5, 2021

    @padenot
    Collaborator

    Well, that's been shipping for some time already in multiple browser / OS combination.

    This is about extending this for Web Codecs, which means essentially giving a key to a decoder, and then preventing read backs of VideoFrame while allowing its painting. There are talks about write-only drawing primitives already, iirc.

    Essentially do what browsers do when implementing (e.g.) Widevide Level 1 support, but with a bit more flexibility.

  9. dalecurtis commented on Jul 7, 2021

    @dalecurtis
    Contributor

    I agree with Paul. However, I think we could only offer any flexibility with L3 protected content, for L1 the frames never come back from the hardware. For L3, we'd could do something like mark the frames as tainted (VideoFrame would need to grow this) like we do for CORS, so sites can manipulate them via canvas/WebGL, but can't read them back. For L1, probably at most we could allow sites to decode opaque frames and then pass them to a MediaStreamTrackGenerator that goes into a <video src> since they can't be used with canvas or WebGL.

  10. aboba commented on Aug 28, 2021

    @aboba
    CollaboratorAuthor

    One question is how WebCodecs works with SFrame. Is it possible for WebCodecs Decoder to take an SFrame as input directly without exposing the key and cleartext encryptedChunk to Javascript? Similar questions have arisen with WebRTC Encoded Transform.

  11. chcunningham commented on Sep 8, 2021

    @chcunningham
    Collaborator

    My first time really looking at SFrame. At a glance it looks pretty different from EME use cases. As you know, EME inovles license servers, output protection, etc... often removing the UA entirely from roles of decoding and rendering. Whereas IIUC, SFrame is more protecting frames on the wire, but is less concerned with protecting them from javascript. My first thought would be that SFrame encryption/decryption seems like a post-encode/decode step, so it's external post processing outside of WebCodecs. Seem right?

    Noob question: I see lots of discussion on how to prevent JavaScript access to the SFrame keys. Obviously keys are sensitive, but I don't quite follow why they're concerned w/ restricting JS access to the keys if they're not also restricting JS access to the raw media?

  12. aboba commented on Sep 14, 2021

    @aboba
    CollaboratorAuthor

    @chcunningham SFrame is about protecting content from access by untrusted parties. There are use cases where the Javascript may be trusted or untrusted.

    Where the JS is trusted, the application is allowed to access keys as well as raw media (e.g. VideoFrames) but can encrypt the content to prevent access by an untrusted middlebox (e.g. a conference server provided by a CPaaS service). In this use case, the SFrame would be decrypted to yield an encrypted chunk prior to WebCodecs decode, or the encrypted chunk from the WebCodecs encoder would be encrypted prior to transmission. An example of this use case would be a Javascript application written using a Cloud Communications Platform SDK.

    If the JS is untrusted, then the web application should not have access to the keys and operations on the cleartext content should be restricted. For example, the application should not be able to record the content or have access to the raw data in order to transform it (e.g. so as to protect against creation of deep fakes). This use case more resembles an EME use case.

    For example, a sporting event or concert could be streamed in low latency by using WebTransport or RTDataChannel for transport and WebCodecs for decode. Content protection might be desired in this scenario, but without the overhead of containerization.

    In this use case, the content is being played on a Javascript application or device from another vendor (e.g. a concert offered by a streaming service, played on a device like a Roku, AppleTV, etc.).

  13. chcunningham commented on Sep 28, 2021

    @chcunningham
    Collaborator

    What would motivate folks to use sframe in the sporting event example? I definitely follow the use case, but I'd expect they'd essentially want EME for WebCodecs, reusing large parts of the existing EME infrastructure.

  14. chcunningham commented on Oct 1, 2021

    @chcunningham
    Collaborator

    After learning more about the motivations being "untrusted JS", I don't think we should pursue adding SFrame APIs to WebCodecs. JS trust is required for most of the web: authentication, email, banking, shopping, ... The platform increasingly ensures that trust at higher levels (https, cross origin isolation, ...) while exposing more and more power to applications. This runs counter to all of that. The trust isn't perfect, but domain specific (RTC, WebCodecs) solutions add complexity while leaving most of the problem unsolved.

    I'm all for E2E encryption, but having the app manage it.

  15. aboba commented on Oct 1, 2021

    @aboba
    CollaboratorAuthor

    Agree that the goal is probably "EME for WebCodecs". But what does that imply for the format to be transferred over the wire and subsequently fed to WebCodecs decoder? Is protected content transferred the same way it is today? Is the proposal to allow WebCodecs decoder to decode that? If not, what is the alternative? I mentioned SFrame because that is a non-containerized format for encrypted frames.

  16. 6 remaining items

  17. murillo128 commented on Feb 6, 2023

    @murillo128

    After thinking about this, I don't think that there is any use case for supporting DRM in webcodecs for playback. Let me explain.

    If we are going to use WebCodecs with DRM for playback, we will need to use a VideoDecoder to extract the raw audio/video frame, then create a media stream track and playing it on a video element. As we want to use DRM, the decoder will have to decrypt the encrypted frame, but we can't output a raw frame to the media frame to JS, but we would need to pass an opaque handler instead. After that we would need to create the media stream track with the opaque frames for playing back in the video element.

    This is already available in MSE and I don't see any added value from WebCodecs for this use case. The only caveat is that the MSE use "containerized" frames while we want to provide "uncontainerized" ones.

    So wouldn't it just be simpler to extend MSE to accept Encoded(Audio/Video)Chunks instead?

    What functionality would be missing?

  18. aboba commented on Feb 6, 2023

    @aboba
    CollaboratorAuthor

    @murillo128 Finding developers who require DRM support in WebCodecs is a bit like searching for a veterinarian properly trained to care for a unicorn. After a long (and unfruitful) search, you begin to wonder if they exist.

    There are several reasons why developers who were formerly using MSE (and containerization) have been moving to WebCodecs (and raw media transport). Most find that WebCodecs provides decreased latency, partly due to the removal of containerization/decontainerization operations as well as support for workers (which are also now supported by MSEv2). However, one of the other key characteristics of applications that have moved from MSE to WebCodecs is that they do not need DRM.

    So while I could speculate whether it makes sense for WebCodecs to support DRM or whether it would be better for MSEv2 to accept Encoded(Audio/Video)Chunks, it is probably best to wait until we "come across a unicorn that needs a veterinarian".

    Do you know of an application that needs both WebCodecs and DRM?

  19. rayvbr commented on Feb 6, 2023

    @rayvbr

    🦄 present :)

    Jokes aside, if WebCodecs + DRM would exist, I can assure you there would be a market for it. The main reason we use WebCodecs over MSE/EME is not so much the decreased latency but the control it gives us over the rendering process. For our use case, an advanced multiview player, we need frame-level control over the rendering process, with each frame potentially requiring different shader parameters. A MSE-like approach where the output of a decoder is directly rendered to a view simply does not work in our case because of the lack of (control over) the synchronisation between the WebGL pass and the video decoder output. Which is the primary reason that so far we've been limited to ClearKey-like DRM schemes in browsers, while we can offer proper DRM in native applications

  20. n8o commented on Feb 6, 2023

    @n8o
  21. murillo128 commented on Feb 6, 2023

    @murillo128

    @rayvbr wouldn't your use case also require webgl to support DRM'd textures?

  22. rayvbr commented on Feb 6, 2023

    @rayvbr

    @murillo128 yes, that's correct. So having EME/DRM support for WebCodecs would be a necessary although by itself not sufficient setp for enabling our use case.

    I added a more extensive description of our use case here: #483

  23. vitaly-castLabs commented on Aug 22, 2023

    @vitaly-castLabs

    I totally agree with @murillo128 - MSE/EME for non-containerized media makes more sense (better suited for DRM) than EME-for-WebCodecs. I'd use the latter for the lack of better options, although I'm not putting myself on the unicorn vets list as #483 clearly states WebRTC cases are out of the scope.

    At the same time the DRM for WebRTC topic is not getting much love (w3c/webrtc-nv-use-cases#86) even though there's definitely interest from DASH-IF. This is out of the scope of the discussion either, so I'll just wrap it up with stating that the second best (MSE/EME for non-containerized media) will be hugely helpful too.

  24. dalecurtis commented on Oct 13, 2023

    @dalecurtis
    Contributor

    FWIW, I'm prototyping support for EME+MSE+WebCodecs in Chromium at:
    https://bugs.chromium.org/p/chromium/issues/detail?id=1144908

    It's not something we're yet planning to ship, but I did want to flesh it out for folks to test. At this point, I've got clearkey working and tested (Widevine should work as well, but it's untested for now). It's available in Chrome 120.0.6074.0+ behind the --enable-blink-features=MediaSourceExtensionsForWebCodecs flag.

    The new IDL ends up looking like this so far:

    dictionary SubsampleEntry {
      required unsigned long clearBytes;
      required unsigned long cypherBytes;
    };
    
    dictionary EncryptionPattern {
      required unsigned long cryptByteBlock;
      required unsigned long skipByteBlock;
    };
    
    dictionary DecryptConfig {
      required DOMString encryptionScheme;
      required AllowSharedBufferSource keyId;
      required AllowSharedBufferSource initializationVector;
      required sequence<SubsampleEntry> subsampleLayout;
      EncryptionPattern encryptionPattern;
    };
    
    dictionary AudioDecoderConfig {
      // ...
      DOMString encryptionScheme;
    }
    
    dictionary VideoDecoderConfig {
      // ...
      DOMString encryptionScheme;
    }
    
    dictionary EncodedAudioChunkInit {
      // ...
      DecryptConfig decryptConfig;
    }
    
    dictionary EncodedVideoChunkInit {
      // ...
      DecryptConfig decryptConfig;
    }
    
    
  25. vitaly-castLabs commented on Oct 17, 2023

    @vitaly-castLabs

    This is an exciting development, thank you for making this happen!

    We (castLabs) discussed EME/DRM issues with Google folks (Chris, Matt and Harald to name a few) at length, but it did materialize in any tangible action, and then I learned both Chris and Matt were no longer with Google...

    This already looks very promising as a prototype, however I don't fully grasp the IDL you posted. I'd expect (based on my experience working with ISO/IEC 23001-7 compliant media) something like that:

    dictionary SegmentDecryptConfig {
      required DOMString encryptionScheme;
      required AllowSharedBufferSource keyId;
      required-if-encryptionScheme-is-cbc AllowSharedBufferSource initializationVector;
      EncryptionPattern encryptionPattern;
    };
    
    dictionary FrameDecryptConfig {
      required-if-encryptionScheme-is-ctr AllowSharedBufferSource initializationVector;
      required sequence<SubsampleEntry> subsampleLayout;
    };
    

    'Segment' here is a range of consecutive frames sharing the same en/decryption key - if there's no key rotation, then segment is equivalent to the entire media stream.

  26. dalecurtis commented on Oct 17, 2023

    @dalecurtis
    Contributor

    There's no concept of segments w/ decoders, so the client must map the segment config into a per-chunk config.

  27. vitaly-castLabs commented on Oct 18, 2023

    @vitaly-castLabs

    This brings up the question I was going to ask before - what is "chunk"? I don't recall ever seeing "chunks" in any audio/video specs. Does that stand for something usually referred as "frame" or "access unit"?

    WebCodecs spec itself only defines "key chunks": "An encoded chunk that does not depend on any other frames for decoding. Also commonly referred to as a "key frame", and the whole spec feels like an arbitrary mix of "chunk" and "frame" used interchangeably

  28. sandersdan commented on Oct 18, 2023

    @sandersdan
    Contributor

    The definition of "chunk" is codec-specific, see the codec registry https://www.w3.org/TR/webcodecs-codec-registry/.

    As an example, an AVC chunk is an Access Unit.

  29. tidoust commented on Mar 20, 2025

    @tidoust
    Member

    Reviewing this with @chrisn and @marcoscaceres with the goal of possibly updating the draft Media Working Group charter, I'm wondering about implications for still images. Today, EME is purposedly restricted to audio and video content. WebCodecs gives you individual frames that you may render to a canvas.

    Integration of WebCodecs with EME seems to also enable using EME to protect still images rendered in a page, through the following scenario:

    • Embed the still image in a video (server-side)
    • Content protect the video (server-side)
    • Use this proposed WebCodecs/EME integration to get an (opaque) VideoFrame of the still image
    • Render the VideoFrame to a <canvas> element

    I believe that you cannot achieve the same thing with EME and a <video> element today because the element comes with a notion of playback, and playback would likely not start without user action. Or is it already possible to hack a similar mechanism?

    A previous comment suggests that rendering to a canvas wouldn't be possible for L1 content in any case, but would still be possible for L3 content.

  30. thasso commented on Mar 20, 2025

    @thasso

    @tidoust it is possible to do exactly that today. There are not auto-play restrictions if there is not audio or the video element is muted.

  31. dalecurtis commented on Mar 20, 2025

    @dalecurtis
    Contributor

    @thasso is correct. Even if the content isn't muted or playing we'll almost always load the first frame, which would be the only frame in this case.

    The way EME + WebCodecs is currently setup, MSE must be used. Which means there's no new delta of EME functionality that doesn't already exist with MSE. The only thing this proposal allows is skipping the container demuxing steps in MSE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions