Skip to content

Refactor Voice #37

@nuclearace

Description

@nuclearace

Move away from internal Pipe based encoding, which involves heavy thread use and blocking to one that is more delegate based with DispatchSources and DispatchIO.

From @TellowKrinkle

  • Make two new protocols, DiscordOpusDataSource and DiscordPCMDataSource, which each require a nextAudio (or something, that name sounds kind of bad) method that throws or returns a opus/PCM encoded Data as well as an optional finishEncoding method. These will be identical in requirement, separate only to make it obvious what type of data any given conforming class can give out.
  • Make DiscordOpusEncoder conform to DiscordOpusDataSource and give it an optional DiscordPCMDataSource input
  • Add a (non-iOS) DiscordPipedAudio class which conforms to both DataSources and manages audio from another process, has a convenience init that also includes an ffmpeg instance
  • Make DiscordVoiceEncoder conform to DiscordOpusDataSource, while trying to keep its user-facing features as similar as possible to the old DiscordVoiceEncoder (things like Read will have to go, but hopefully no one wanted to call Read from the client side)
  • Replace the encoder variable in DiscordVoiceEngine with a DiscordOpusDataSource, which will get its nextAudio method called every 20 milliseconds using a Dispatch Timer.
  • Replace callbacks like voiceEngineNeedsEncoder with voiceEngineNeedsDataSource (might as well keep the old one around to reduce change requirements)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions