File: pulse_backend.go

package info (click to toggle)
go-dlib 5.6.0.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,740 kB
  • sloc: ansic: 4,664; xml: 1,456; makefile: 20; sh: 15
file content (39 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package sound_effect

import (
	"unsafe"

	paSimple "pkg.deepin.io/lib/pulse/simple"
)

type PulseAudioPlayBackend struct {
	conn paSimple.Conn
}

func newPulseAudioPlayBackend(event, device string, sampleSpec *SampleSpec) (PlayBackend, error) {
	paConn, err := paSimple.NewConn("", "com.deepin.SoundEffect",
		paSimple.StreamDirectionPlayback, device, event, sampleSpec.GetPaSampleSpec())

	if err != nil {
		return nil, err
	}

	return &PulseAudioPlayBackend{
		conn: paConn,
	}, nil
}

func (pb *PulseAudioPlayBackend) Write(data []byte) error {
	_, err := pb.conn.Write(unsafe.Pointer(&data[0]), uint(len(data)))
	return err
}

func (pb *PulseAudioPlayBackend) Drain() error {
	_, err := pb.conn.Drain()
	return err
}

func (pb *PulseAudioPlayBackend) Close() error {
	pb.conn.Free()
	return nil
}