Skip to content

[2.46][CDMProxyThunder] Pass CAPS to decrypt function #1489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: wpe-2.46
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ bool CDMProxyThunder::decrypt(CDMProxyThunder::DecryptionContext& input)

GST_TRACE("decrypting");
// Decrypt cipher.
OpenCDMError errorCode = opencdm_gstreamer_session_decrypt(session->get(), input.dataBuffer, input.subsamplesBuffer, input.numSubsamples,
input.ivBuffer, input.keyIDBuffer, 0);
OpenCDMError errorCode = opencdm_gstreamer_session_decrypt_buffer(session->get(), input.dataBuffer, input.caps.get());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be upstreamed as-is, we would need some kind of Thunder version check and an ifdef here. I'll take a look next week.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try this PR please? WebKit/WebKit#44057

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch fails to detect new API because of missing header. (cmake logs below). It uses C compiler. Replaced with "check_cxx_symbol_exists()" but it failed again with undefined decrypt_buffer() symbol as THUNDER libraries are WebCore local. Otherwise it seems fine, encrypted playback works as expected
Here are my modifications:

include(CheckCXXSymbolExists)
...
    # globaly add thunder libraries:
    set(CMAKE_REQUIRED_LIBRARIES ${THUNDER_LIBRARIES})

    check_cxx_symbol_exists(opencdm_gstreamer_session_decrypt_buffer ${THUNDER_INCLUDE_DIR}/open_cdm_adapter.h HAS_OCDM_DECRYPT_BUFFER)
...

logs:

Determining if the opencdm_gstreamer_session_decrypt_buffer exist failed with the following output:
Change Dir: /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp

Run Build Command(s):ninja cmTC_65fac && [1/2] Building C object CMakeFiles/cmTC_65fac.dir/CheckSymbolExists.c.o
FAILED: CMakeFiles/cmTC_65fac.dir/CheckSymbolExists.c.o
ccache /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot-native/usr/bin/arm-rdk-linux-gnueabi/arm-rdk-linux-gnueabi-gcc -D_GNU_SOURCE=1  -fdiagnostics
In file included from /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot/usr/include/WPEFramework/ocdm/open_cdm_adapter.h:23,
                 from /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:2:
/home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot/usr/include/WPEFramework/ocdm/open_cdm.h:61:10: fatal error: string: No such file or directory
   61 | #include <string>
      |          ^~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.


File /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include </home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot/usr/include/WPEFramework/ocdm/open_cdm_adapter.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef opencdm_gstreamer_session_decrypt_buffer
  return ((int*)(&opencdm_gstreamer_session_decrypt_buffer))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with "check_cxx_symbol_exists()" but it failed again with undefined decrypt_buffer() symbol as THUNDER libraries are WebCore local.

Can you share the log for that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just realized that include is our local modification, there is also a in open_cdm.h but unused so easy to remove.
Without that it hits the same undefined reference as CXX case:

/usr/src/debug/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:13: undefined reference to `opencdm_gstreamer_session_decrypt_buffer'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like thunder include/lib options can be added in the check, https://cmake.org/cmake/help/latest/module/CheckCXXSymbolExists.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got back to C version check_symbol_exists(). We have couple of local modifications that fails with C compiler but we can fix that I think. Or we can go with CXX version that will be easier to maintain

On undefined reference (C version): and Yes, in my case it works with
set(CMAKE_REQUIRED_LIBRARIES ${THUNDER_LIBRARIES})

Determining if the opencdm_gstreamer_session_decrypt_buffer exist failed with the following output:
Change Dir: /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp

Run Build Command(s):ninja cmTC_dbd4f && [1/2] Building C object CMakeFiles/cmTC_dbd4f.dir/CheckSymbolExists.c.o
[2/2] Linking C executable cmTC_dbd4f
FAILED: cmTC_dbd4f
: && /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot-native/usr/bin/arm-rdk-linux-gnueabi/arm-rdk-linux-gnueabi-gcc -fdiagnostics-color=always -Wext
/home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot-native/usr/bin/arm-rdk-linux-gnueabi/../../libexec/arm-rdk-linux-gnueabi/gcc/arm-rdk-linux-gnueabi/1
/usr/src/debug/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:13: undefined reference to `opencdm_gstreamer_session_decrypt_buffer'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.


File /home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include </home/asurdej/work/hisense_25Q2/build-hisense-v2/tmp/work/armv7at2hf-neon-rdk-linux-gnueabi/wpe-webkit/2.46+gitAUTOINC+15440d15c6-r0/recipe-sysroot/usr/include/WPEFramework/ocdm/open_cdm_adapter.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef opencdm_gstreamer_session_decrypt_buffer
  return ((int*)(&opencdm_gstreamer_session_decrypt_buffer))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, iiuc, with set(CMAKE_REQUIRED_LIBRARIES ${THUNDER_LIBRARIES}) and CXX check it works? If so, I don't mind going with that :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s correct. Here is my snippet

include(CheckCXXSymbolExists)
...
    # globaly add thunder libraries:
    set(CMAKE_REQUIRED_LIBRARIES ${THUNDER_LIBRARIES})

    check_cxx_symbol_exists(opencdm_gstreamer_session_decrypt_buffer ${THUNDER_INCLUDE_DIR}/open_cdm_adapter.h HAS_OCDM_DECRYPT_BUFFER)
...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, let's see how the PR review goes. Might not be reviewed until next week due to Easter.

if (errorCode) {
GST_ERROR("decryption failed, error code %X", errorCode);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CDMProxyThunder final : public CDMProxy, public CanMakeWeakPtr<CDMProxyThu
GstBuffer* ivBuffer;
GstBuffer* dataBuffer;
GstBuffer* subsamplesBuffer;
GRefPtr<GstCaps> caps;
size_t numSubsamples;
WeakPtr<CDMProxyDecryptionClient> cdmProxyDecryptionClient;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,21 @@ static bool decrypt(WebKitMediaCommonEncryptionDecrypt* decryptor, GstBuffer* iv
return false;
}

GRefPtr<GstPad> sinkpad = adoptGRef(gst_element_get_static_pad(reinterpret_cast<GstElement*>(self), "sink"));
GRefPtr<GstCaps> caps = adoptGRef(gst_pad_get_current_caps(sinkpad.get()));

GstStructure *capstruct = gst_caps_get_structure(caps.get(), 0);
const gchar* capsinfo = gst_structure_get_string(capstruct, "original-media-type");
GST_DEBUG_OBJECT(self, "CAPS %p - Stream Type = %s", caps.get(), capsinfo);

CDMProxyThunder::DecryptionContext context = { };
context.keyIDBuffer = keyIDBuffer;
context.ivBuffer = ivBuffer;
context.dataBuffer = buffer;
context.numSubsamples = subsampleCount;
context.subsamplesBuffer = subsampleCount ? subsamplesBuffer : nullptr;
context.cdmProxyDecryptionClient = webKitMediaCommonEncryptionDecryptGetCDMProxyDecryptionClient(decryptor);
context.caps = caps;
bool result = priv->cdmProxy->decrypt(context);

return result;
Expand Down