__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
-- WirePlumber
--
-- Copyright © 2024 Collabora Ltd.
--    @author Ashok Sidipotu <[email protected]>
--
-- SPDX-License-Identifier: MIT

lutils = require("linking-utils")
cutils = require("common-utils")
log = Log.open_topic("s-linking")

function restoreVolume (om, link)
  setVolume(om, link, 1.0)
end

function duckVolume (om, link)
  setVolume(om, link, Settings.get_float("linking.role-based.duck-level"))
end

function setVolume (om, link, level)
  local lprops = link.properties
  local media_role_si_id = nil
  local dir = lprops ["item.node.direction"]

  if dir == "output" then
    media_role_si_id = lprops ["out.item.id"]
  else
    media_role_si_id = lprops ["in.item.id"]
  end

  local media_role_lnkbl = om:lookup {
    type = "SiLinkable",
    Constraint { "item.factory.name", "c", "si-audio-adapter", "si-node" },
    Constraint { "id", "=", media_role_si_id, type = "gobject" },
  }

  -- apply volume control on the stream node of the loopback module, instead of
  -- the sink/source node as it simplifies the volume ducking and
  -- restoration.
  local media_role_other_lnkbl = om:lookup {
    type = "SiLinkable",
    Constraint { "item.factory.name", "c", "si-audio-adapter", "si-node" },
    Constraint { "node.link-group", "=", media_role_lnkbl.properties ["node.link-group"] },
    Constraint { "id", "!", media_role_lnkbl.id, type = "gobject" },
  }

  if media_role_other_lnkbl then
    local n = media_role_other_lnkbl:get_associated_proxy("node")
    if n then
      log:info(string.format(".. %s volume of media role node \"%s(%d)\" to %f",
        level < 1.0 and "duck" or "restore", n.properties ["node.name"],
        n ["bound-id"], level))

      local props = {
        "Spa:Pod:Object:Param:Props",
        "Props",
        volume = level,
      }

      local param = Pod.Object(props)
      n:set_param("Props", param)
    end
  end
end

function getSuspendPlaybackFromMetadata (om)
  local suspend = false
  local metadata = om:lookup {
    type = "metadata",
    Constraint { "metadata.name", "=", "default" },
  }
  if metadata then
    local value = metadata:find(0, "suspend.playback")
    if value then
      suspend = value == "1" and true or false
    end
  end
  return suspend
end

AsyncEventHook {
  name = "linking/rescan-media-role-links",
  interests = {
    EventInterest {
      -- on media client link added and removed
      Constraint { "event.type", "c", "session-item-added", "session-item-removed" },
      Constraint { "event.session-item.interface", "=", "link" },
      Constraint { "is.role.policy.link", "=", true },
    },
    EventInterest {
      -- on default metadata suspend.playback changed
      Constraint { "event.type", "=", "metadata-changed" },
      Constraint { "metadata.name", "=", "default" },
      Constraint { "event.subject.key", "=", "suspend.playback" },
    }
  },
  steps = {
    start = {
      next = "none",
      execute = function(event, transition)
        local source, om, _, si_props, _, _ =
            lutils:unwrap_select_target_event(event)

        local metadata_om = source:call("get-object-manager", "metadata")
        local suspend = getSuspendPlaybackFromMetadata(metadata_om)
        local pending_activations = 0
        local mc = si_props ["target.media.class"]
        local pmrl_active = nil
        pmrl = lutils.getPriorityMediaRoleLink(mc)

        log:debug("Rescanning media role links...")

        local function onMediaRoleLinkActivated (l, e)
          local si_id = tonumber(l.properties ["main.item.id"])
          local target_id = tonumber(l.properties ["target.item.id"])
          local si_flags = lutils:get_flags(si_id)

          if e then
            log:warning(l, "failed to activate media role link: " .. e)
            if si_flags ~= nil then
              si_flags.peer_id = nil
            end
            l:remove()
          else
            log:info(l, "media role link activated successfully")
            si_flags.failed_peer_id = nil
            if si_flags.peer_id == nil then
              si_flags.peer_id = target_id
            end
            si_flags.failed_count = 0
          end

          -- advance only when all pending activations are completed
          pending_activations = pending_activations - 1
          if pending_activations <= 0 then
            log:info("All media role links activated")
            transition:advance()
          end
        end

        for link in om:iterate {
          type = "SiLink",
          Constraint { "is.role.policy.link", "=", true },
          Constraint { "target.media.class", "=", mc },
        } do
          -- deactivate all links if suspend playback metadata is present
          if suspend then
            link:deactivate(Feature.SessionItem.ACTIVE)
          end

          local active = ((link:get_active_features() & Feature.SessionItem.ACTIVE) ~= 0)

          log:debug(string.format(" .. looking at link(%d) active %s pmrl %s", link.id, tostring(active),
            tostring(link == pmrl)))

          if link == pmrl then
            pmrl_active = active
            restoreVolume(om, pmrl)
            goto continue
          end

          local action = lutils.getAction(pmrl, link)

          log:debug(string.format(" .. apply action(%s) on link(%d)", action, link.id, tostring(active)))

          if action == "cork" then
            if active then
              link:deactivate(Feature.SessionItem.ACTIVE)
            end
          elseif action == "mix" then
            if not active and not suspend then
              pending_activations = pending_activations + 1
              link:activate(Feature.SessionItem.ACTIVE, onMediaRoleLinkActivated)
            end
            restoreVolume(om, link)
          elseif action == "duck" then
            if not active and not suspend then
              pending_activations = pending_activations + 1
              link:activate(Feature.SessionItem.ACTIVE, onMediaRoleLinkActivated)
            end
            duckVolume(om, link)
          else
            log:warning("Unknown action: " .. action)
          end

          ::continue::
        end

        if pmrl and not pmrl_active then
          pending_activations = pending_activations + 1
          pmrl:activate(Feature.SessionItem.ACTIVE, onMediaRoleLinkActivated)
          restoreVolume(om, pmrl)
        end

        -- just advance transition if no pending activations are needed
        if pending_activations <= 0 then
          log:debug("All media role links rescanned")
          transition:advance()
        end
      end,
    },
  },
}:register()

Filemanager

Name Type Size Permission Actions
find-best-target.lua File 3.97 KB 0644
find-default-target.lua File 1.65 KB 0644
find-defined-target.lua File 4.25 KB 0644
find-filter-target.lua File 2.9 KB 0644
find-media-role-target.lua File 1.92 KB 0644
find-user-target.lua.example File 925 B 0644
get-filter-from-target.lua File 3.33 KB 0644
link-target.lua File 5.23 KB 0644
prepare-link.lua File 3.79 KB 0644
rescan-media-role-links.lua File 6.46 KB 0644
rescan.lua File 8.35 KB 0644
Filemanager