@@ -106,11 +106,19 @@ static bool
106
106
sc_audio_player_frame_sink_open (struct sc_frame_sink * sink ,
107
107
const AVCodecContext * ctx ) {
108
108
struct sc_audio_player * ap = DOWNCAST (sink );
109
+ #ifdef SCRCPY_LAVU_HAS_CHLAYOUT
110
+ assert (ctx -> ch_layout .nb_channels > 0 );
111
+ unsigned nb_channels = ctx -> ch_layout .nb_channels ;
112
+ #else
113
+ int tmp = av_get_channel_layout_nb_channels (ctx -> channel_layout );
114
+ assert (tmp > 0 );
115
+ unsigned nb_channels = tmp ;
116
+ #endif
109
117
110
118
SDL_AudioSpec desired = {
111
119
.freq = ctx -> sample_rate ,
112
120
.format = SC_SDL_SAMPLE_FMT ,
113
- .channels = ctx -> ch_layout . nb_channels ,
121
+ .channels = nb_channels ,
114
122
.samples = SC_AUDIO_OUTPUT_BUFFER_SAMPLES ,
115
123
.callback = sc_audio_player_sdl_callback ,
116
124
.userdata = ap ,
@@ -131,13 +139,20 @@ sc_audio_player_frame_sink_open(struct sc_frame_sink *sink,
131
139
ap -> swr_ctx = swr_ctx ;
132
140
133
141
assert (ctx -> sample_rate > 0 );
134
- assert (ctx -> ch_layout .nb_channels > 0 );
135
142
assert (!av_sample_fmt_is_planar (SC_AV_SAMPLE_FMT ));
143
+
136
144
int out_bytes_per_sample = av_get_bytes_per_sample (SC_AV_SAMPLE_FMT );
137
145
assert (out_bytes_per_sample > 0 );
138
146
147
+ #ifdef SCRCPY_LAVU_HAS_CHLAYOUT
139
148
av_opt_set_chlayout (swr_ctx , "in_chlayout" , & ctx -> ch_layout , 0 );
140
149
av_opt_set_chlayout (swr_ctx , "out_chlayout" , & ctx -> ch_layout , 0 );
150
+ #else
151
+ av_opt_set_channel_layout (swr_ctx , "in_channel_layout" ,
152
+ ctx -> channel_layout , 0 );
153
+ av_opt_set_channel_layout (swr_ctx , "out_channel_layout" ,
154
+ ctx -> channel_layout , 0 );
155
+ #endif
141
156
142
157
av_opt_set_int (swr_ctx , "in_sample_rate" , ctx -> sample_rate , 0 );
143
158
av_opt_set_int (swr_ctx , "out_sample_rate" , ctx -> sample_rate , 0 );
@@ -152,7 +167,7 @@ sc_audio_player_frame_sink_open(struct sc_frame_sink *sink,
152
167
}
153
168
154
169
ap -> sample_rate = ctx -> sample_rate ;
155
- ap -> nb_channels = ctx -> ch_layout . nb_channels ;
170
+ ap -> nb_channels = nb_channels ;
156
171
ap -> out_bytes_per_sample = out_bytes_per_sample ;
157
172
158
173
size_t bytebuf_size =
0 commit comments