static gboolean webkitMediaCommonEncryptionDecryptSinkEventHandler(GstBaseTransform* trans, GstEvent* event)
{
    WebKitMediaCommonEncryptionDecrypt* self = WEBKIT_MEDIA_CENC_DECRYPT(trans);
    WebKitMediaCommonEncryptionDecryptPrivate* priv = WEBKIT_MEDIA_CENC_DECRYPT_GET_PRIVATE(self);
    WebKitMediaCommonEncryptionDecryptClass* klass = WEBKIT_MEDIA_CENC_DECRYPT_GET_CLASS(self);
    gboolean result = FALSE;

    switch (GST_EVENT_TYPE(event)) {
    case GST_EVENT_PROTECTION: {
        const char* systemId;
        const char* origin;
        GstBuffer* initDataBuffer;

        GST_DEBUG_OBJECT(self, "received protection event");
        gst_event_parse_protection(event, &systemId, &initDataBuffer, &origin);
        GST_DEBUG_OBJECT(self, "systemId: %s", systemId);

        if (!g_str_equal(systemId, klass->protectionSystemId)) {
            gst_event_unref(event);
            result = TRUE;
            break;
        }

        // Keep the event ref around so that the parsed event data
        // remains valid until the drm-key-need message has been sent.
        priv->protectionEvent = event;
        RunLoop::main().dispatch([self, initDataBuffer] {
            if (self) {
                WebKitMediaCommonEncryptionDecryptClass* klass = WEBKIT_MEDIA_CENC_DECRYPT_GET_CLASS(self);
                klass->requestDecryptionKey(self, initDataBuffer);
                if (self->priv->protectionEvent) {
                    gst_event_unref(self->priv->protectionEvent);
                    self->priv->protectionEvent = nullptr;
                }
            }});

        result = TRUE;
        break;
    }
    case GST_EVENT_CUSTOM_DOWNSTREAM_OOB: {
        if (klass->handleKeyResponse(self, event)) {
            GST_DEBUG_OBJECT(self, "key received");
            priv->keyReceived = true;
            priv->condition.notifyOne();
        }

        gst_event_unref(event);
        result = TRUE;
        break;
    }
    default:
        result = GST_BASE_TRANSFORM_CLASS(parent_class)->sink_event(trans, event);
        break;
    }

    return result;
}
static gboolean webkitMediaPlayReadyDecryptSinkEventHandler(GstBaseTransform* trans, GstEvent* event)
{
    gboolean result = FALSE;
    WebKitMediaPlayReadyDecrypt* self = WEBKIT_MEDIA_PLAYREADY_DECRYPT(trans);

    switch (GST_EVENT_TYPE(event)) {
    case GST_EVENT_PROTECTION: {
        const gchar* systemId;
        const gchar* origin;
        GstBuffer* initdatabuffer;

        GST_INFO_OBJECT(self, "received protection event");
        gst_event_parse_protection(event, &systemId, &initdatabuffer, &origin);
        GST_DEBUG_OBJECT(self, "systemId: %s", systemId);

        // Ignore protection events about content we cannot handle.
        if (!g_str_equal(systemId, PLAYREADY_PROTECTION_SYSTEM_ID)) {
            gst_event_unref(event);
            result = TRUE;
            break;
        }

        // Keep the event ref around so that the parsed event data
        // remains valid until the drm-key-need message has been sent.
        self->protectionEvent = event;
        self->initDataBuffer = initdatabuffer;
        g_timeout_add(0, requestKey, self);

        result = TRUE;
        break;
    }
    case GST_EVENT_CUSTOM_DOWNSTREAM_OOB: {
        GST_INFO_OBJECT(self, "received OOB event");
        g_mutex_lock(&self->mutex);
        const GstStructure* structure = gst_event_get_structure(event);
        if (gst_structure_has_name(structure, "dxdrm-session")) {
            GST_INFO_OBJECT(self, "received dxdrm session");

            const GValue* value = gst_structure_get_value(structure, "session");
            self->sessionMetaData = reinterpret_cast<WebCore::DiscretixSession*>(g_value_get_pointer(value));
            self->streamReceived = TRUE;
            g_cond_signal(&self->condition);
        }

        g_mutex_unlock(&self->mutex);
        gst_event_unref(event);
        result = TRUE;
        break;
    }
    default:
        result = GST_BASE_TRANSFORM_CLASS(parent_class)->sink_event(trans, event);
        break;
    }

    return result;
}
Example #3
0
static gboolean
gst_cenc_decrypt_sink_event_handler (GstBaseTransform * trans, GstEvent * event)
{
  gboolean ret = TRUE;
  const gchar *system_id;
  GstBuffer *pssi = NULL;
  const gchar *loc;
  GstCencDecrypt *self = GST_CENC_DECRYPT (trans);

  switch (GST_EVENT_TYPE (event)) {
    case GST_EVENT_PROTECTION:
        GST_DEBUG_OBJECT (self, "received protection event");
        gst_event_parse_protection (event, &system_id, &pssi, &loc);
        GST_DEBUG_OBJECT (self, "system_id: %s  loc: %s", system_id, loc);
        if(g_ascii_strcasecmp(loc, "dash/mpd")==0 && g_ascii_strcasecmp(system_id, M_MPD_PROTECTION_ID)==0){
            GST_DEBUG_OBJECT (self, "event carries MPD pssi data");
            self->drm_type = GST_DRM_MARLIN;
            gst_cenc_decrypt_parse_content_protection_element (self, pssi);
        }
        else if(g_ascii_strcasecmp(loc, "dash/mpd")==0 && g_ascii_strcasecmp(system_id, M_MPD_PROTECTION_ID)==0){
          GST_DEBUG_OBJECT (self, "event carries MPD clearkey data");
          self->drm_type = GST_DRM_CLEARKEY;
          /* TODO: parse clearkey:Laurl element */
        }
        else if(g_str_has_prefix (loc, "isobmff/") && g_ascii_strcasecmp(system_id, M_PSSH_PROTECTION_ID)==0){
          GST_DEBUG_OBJECT (self, "event carries pssh data from qtdemux");
          self->drm_type = GST_DRM_MARLIN;
          gst_cenc_decrypt_parse_pssh_box (self, pssi);
        }
        gst_event_unref (event);
      break;

    default:
      ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
      break;
  }

  return ret;
}