1 // SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2021 kXuan. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6 * following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11 * following disclaimer in the documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <vlc/plugins/vlc_common.h>
33 #include <vlc/plugins/vlc_stream.h>
35 static void *load_sym(void *override_func
, const char *name
)
37 void *ptr
= dlsym(RTLD_NEXT
, name
);
39 fprintf(stderr
, "Cannot load symbol '%s' %s. Please report bug on AUR.\n", name
, dlerror());
42 if (ptr
== override_func
) {
43 fprintf(stderr
, "circular reference '%s'. Please report bug on AUR.\n", name
);
49 static int is_flac(const char *url
)
51 static const char suffix
[] = ".flac";
55 size_t len
= strlen(url
);
56 if (len
< sizeof(suffix
)) {
60 return strcasecmp(url
+ len
- sizeof(suffix
) + 1, suffix
) == 0;
64 * The netease cloud music server set the Content-Type of .flac format to mpeg/audio, which results vlc unable to decode
67 * To make vlc works correctly, we rewrite the Content-Type to audio/flac.
74 int vlc_stream_vaControl(stream_t
*s
, int query
, va_list args
)
76 static typeof(vlc_stream_vaControl
) *orig_fn
;
77 if (orig_fn
== NULL
) {
78 orig_fn
= load_sym(vlc_stream_vaControl
, __func__
);
80 if (query
== STREAM_GET_CONTENT_TYPE
&& is_flac(s
->psz_url
)) {
81 *va_arg(args
, char **) = strdup("audio/flac");
84 return orig_fn(s
, query
, args
);
88 struct string_with_len
{
92 #define STRING_WITH_LEN_INIT(s) {s, sizeof(s)-1}
95 * drop all library fixes.
97 * Library fixes should only be applied to the netease-cloud-music main process. Sometime, netease-cloud-music execute
98 * external program, such as `xdg-open`, `kde-open5`. Those external programs use newer version qt and other new
99 * libraries. If we don't drop these environment variables, those programs may not work, because some symbol may not
100 * exist in the bundled old library.
107 int execve(const char *path
, char *const argv
[], char *const envp
[])
109 static typeof(execve
) *orig_fn
;
110 if (orig_fn
== NULL
) {
111 orig_fn
= load_sym(execve
, "execve");
114 static struct string_with_len drop_env
[] = {
115 STRING_WITH_LEN_INIT("LD_LIBRARY_PATH="),
116 STRING_WITH_LEN_INIT("LD_PRELOAD="),
117 STRING_WITH_LEN_INIT("QT_PLUGIN_PATH="),
118 STRING_WITH_LEN_INIT("QT_QPA_PLATFORM_PLUGIN_PATH="),
119 STRING_WITH_LEN_INIT("QT_QPA_PLATFORM="),
123 for (nenv
= 0; envp
[nenv
]; nenv
++);
125 char *new_envp
[nenv
+ 1];
126 char *const *src
= envp
;
127 char **dst
= new_envp
;
130 for (int i
= 0; i
< sizeof(drop_env
) / sizeof(*drop_env
); ++i
) {
131 if (strncmp(drop_env
[i
].s
, *src
, drop_env
[i
].len
) == 0) {
142 return orig_fn(path
, argv
, new_envp
);