Removed
Link Here
|
1 |
--- src/audio/oss.c.orig 2024-01-01 05:31:28 UTC |
2 |
+++ src/audio/oss.c |
3 |
@@ -0,0 +1,105 @@ |
4 |
+/* |
5 |
+ * This file is part of Moonlight Embedded. |
6 |
+ * |
7 |
+ * Copyright (C) 2015-2017 Iwan Timmer |
8 |
+ * |
9 |
+ * Moonlight is free software; you can redistribute it and/or modify |
10 |
+ * it under the terms of the GNU General Public License as published by |
11 |
+ * the Free Software Foundation; either version 3 of the License, or |
12 |
+ * (at your option) any later version. |
13 |
+ * |
14 |
+ * Moonlight is distributed in the hope that it will be useful, |
15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
+ * GNU General Public License for more details. |
18 |
+ * |
19 |
+ * You should have received a copy of the GNU General Public License |
20 |
+ * along with Moonlight; if not, see <http://www.gnu.org/licenses/>. |
21 |
+ */ |
22 |
+ |
23 |
+#ifdef __FreeBSD__ |
24 |
+#include <sys/soundcard.h> |
25 |
+#include <sys/ioctl.h> |
26 |
+#include "audio.h" |
27 |
+ |
28 |
+#include <opus_multistream.h> |
29 |
+ |
30 |
+#include <errno.h> |
31 |
+#include <fcntl.h> |
32 |
+#include <stdio.h> |
33 |
+#include <stdlib.h> |
34 |
+#include <unistd.h> |
35 |
+ |
36 |
+static OpusMSDecoder* decoder; |
37 |
+static short* pcmBuffer; |
38 |
+static int samplesPerFrame; |
39 |
+static int channelCount; |
40 |
+static int fd = -1; |
41 |
+ |
42 |
+static int oss_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, void* context, int arFlags) { |
43 |
+ int rc; |
44 |
+ decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, opusConfig->mapping, &rc); |
45 |
+ |
46 |
+ channelCount = opusConfig->channelCount; |
47 |
+ samplesPerFrame = opusConfig->samplesPerFrame; |
48 |
+ pcmBuffer = malloc(sizeof(short) * channelCount * samplesPerFrame); |
49 |
+ if (pcmBuffer == NULL) |
50 |
+ return -1; |
51 |
+ |
52 |
+ const char* oss_name = "/dev/dsp"; |
53 |
+ fd = open(oss_name, O_WRONLY); |
54 |
+ if (fd == -1) { |
55 |
+ printf("Open audio device /dev/dsp failed! error %d\n", errno); |
56 |
+ return -1; |
57 |
+ } |
58 |
+ // buffer size for fragment ,selector 12 is 4096;11 is 2048;10 is 1024; 13is 8192 |
59 |
+ int frag = 12; |
60 |
+ if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag) == -1) |
61 |
+ printf("Set fragment for /dev/dsp failed."); |
62 |
+ |
63 |
+ int format = AFMT_S16_LE; |
64 |
+ int channels = opusConfig->channelCount; |
65 |
+ int rate = opusConfig->sampleRate; |
66 |
+ if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) == -1) |
67 |
+ printf("Set format for /dev/dsp failed."); |
68 |
+ if (ioctl(fd, SNDCTL_DSP_CHANNELS, &channels) == -1) |
69 |
+ printf("Set channels for /dev/dsp failed."); |
70 |
+ if (ioctl(fd, SNDCTL_DSP_SPEED, &rate) == -1) |
71 |
+ printf("Set sample rate for /dev/dsp failed."); |
72 |
+ |
73 |
+ return 0; |
74 |
+} |
75 |
+ |
76 |
+static void oss_renderer_cleanup() { |
77 |
+ if (decoder != NULL) { |
78 |
+ opus_multistream_decoder_destroy(decoder); |
79 |
+ decoder = NULL; |
80 |
+ } |
81 |
+ |
82 |
+ if (pcmBuffer != NULL) { |
83 |
+ free(pcmBuffer); |
84 |
+ pcmBuffer = NULL; |
85 |
+ } |
86 |
+ |
87 |
+ if (fd != -1) { |
88 |
+ close(fd); |
89 |
+ fd = -1; |
90 |
+ } |
91 |
+} |
92 |
+ |
93 |
+static void oss_renderer_decode_and_play_sample(char* data, int length) { |
94 |
+ int decodeLen = opus_multistream_decode(decoder, data, length, pcmBuffer, samplesPerFrame, 0); |
95 |
+ if (decodeLen > 0) { |
96 |
+ write(fd, pcmBuffer, decodeLen * channelCount * sizeof(short)); |
97 |
+ } else if (decodeLen < 0) { |
98 |
+ printf("Opus error from decode: %d\n", decodeLen); |
99 |
+ } |
100 |
+} |
101 |
+ |
102 |
+AUDIO_RENDERER_CALLBACKS audio_callbacks_oss = { |
103 |
+ .init = oss_renderer_init, |
104 |
+ .cleanup = oss_renderer_cleanup, |
105 |
+ .decodeAndPlaySample = oss_renderer_decode_and_play_sample, |
106 |
+ .capabilities = CAPABILITY_DIRECT_SUBMIT | CAPABILITY_SUPPORTS_ARBITRARY_AUDIO_DURATION, |
107 |
+}; |
108 |
+#endif |