Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 463237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:09:19+00:00 2026-05-12T23:09:19+00:00

I’m writing some C# bindings for the C library controlling the pulseaudio sound server,

  • 0

I’m writing some C# bindings for the C library controlling the pulseaudio sound server, and I’m unsure how to idiomatically bind some potentially transient objects exposed: particularly sinks.

pulseaudio has the concept of an audio sink – the hardware a given audio stream is getting played to. This would naturally map to a Sink class, with some obvious properties – volume and such. The problem is hotplug – audio hardware can come and go during runtime, and so such Sink objects can end up as zombies referring to non-existent hardware, and all operations performed on them will fail. Worse, the C library doesn’t offer unique handles to sinks, so a sequence of hotplug events could change the hardware a given Sink instance actually controls without the code noticing.

Both of these problems smell. I want to provide some Sink abstraction, but I’m not sure how to avoid these problems.

How have others in a similar situation handled this sort of problem?

EDIT: in the C library it appears you just hope no hotplug events happen between querying the sinks and trying to change their properties. Sinks are identified in the API by an index, but this isn’t stable. Each sink also has an identifier string which is, I think, unique, at least for each run.

There is an API to get callbacks on various interesting events, such as hotplug, so it would be possible to hook up each Sink to that and at least get notified of when it goes away.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:09:19+00:00Added an answer on May 12, 2026 at 11:09 pm

    I think you should try to communicate this behaviour of the C library to the user of your C# library.

    I’m not familiar with pulseaudio, but basing on the information on unique identifiers you gave, a possible design for a Sink class could look like this:

    /// <summary>
    /// Represents a sink. May refer to different hardware.
    /// </summary>
    public class Sink
    {
        public static IEnumerable<string> GetCurrentIdentifiers() { ... }
    
        public static Sink GetSinkForIdentifier(string identifier) { ... }
    
        private Sink() { ... }
    }
    

    Interesting read: The Law of Leaky Abstractions

    So my recommendation would be not to try to create a (leaky) abstraction but simply to expose the concepts of pulseaudio.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.