mirror of
https://github.com/termux/termux-packages.git
synced 2025-05-11 10:55:36 +00:00
Replace the use of `frame->channels` with the hardcoded `channels` global variable the app has, and replace the use of `swr_alloc_set_opts()` with calls to `av_channel_layout_default()` and `swr_alloc_set_opts2()`
63 lines
2.1 KiB
Diff
63 lines
2.1 KiB
Diff
This makes oshu build and run with sound with ffmpeg 7 as a dependency.
|
|
|
|
--- a/lib/audio/stream.cc
|
|
+++ b/lib/audio/stream.cc
|
|
@@ -115,13 +115,14 @@ static int next_frame(oshu::stream *stream)
|
|
*/
|
|
static int convert_frame(struct SwrContext *converter, AVFrame *frame, int index, float *samples, int wanted)
|
|
{
|
|
- const uint8_t *data[frame->channels];
|
|
+ // use two channels
|
|
+ const uint8_t *data[channels];
|
|
int sample_size = av_get_bytes_per_sample((AVSampleFormat) frame->format);
|
|
if (av_sample_fmt_is_planar((AVSampleFormat) frame->format)) {
|
|
- for (int c = 0; c < frame->channels; ++c)
|
|
+ for (int c = 0; c < channels; ++c)
|
|
data[c] = frame->data[c] + index * sample_size;
|
|
} else {
|
|
- data[0] = frame->data[0] + index * sample_size * frame->channels;
|
|
+ data[0] = frame->data[0] + index * sample_size * channels;
|
|
}
|
|
|
|
int left = frame->nb_samples - index;
|
|
@@ -236,8 +237,7 @@ static int open_decoder(oshu::stream *stream)
|
|
oshu_log_error("error opening the codec");
|
|
goto fail;
|
|
}
|
|
- if (!stream->decoder->channel_layout)
|
|
- stream->decoder->channel_layout = av_get_default_channel_layout(stream->decoder->channels);
|
|
+
|
|
stream->frame = av_frame_alloc();
|
|
if (stream->frame == NULL) {
|
|
oshu_log_error("could not allocate the codec frame");
|
|
@@ -257,19 +257,25 @@ fail:
|
|
*/
|
|
static int open_converter(oshu::stream *stream)
|
|
{
|
|
+ // get channel layout in an ffmpeg-7-compatible way
|
|
+ AVChannelLayout input_channel_layout, output_channel_layout;
|
|
+ av_channel_layout_default(&input_channel_layout, channels);
|
|
+ av_channel_layout_default(&output_channel_layout, channels);
|
|
assert (channels == 2);
|
|
- stream->converter = swr_alloc_set_opts(
|
|
- stream->converter,
|
|
+ swr_alloc_set_opts2(
|
|
+ &stream->converter,
|
|
/* output */
|
|
- AV_CH_LAYOUT_STEREO,
|
|
+ &output_channel_layout,
|
|
AV_SAMPLE_FMT_FLT,
|
|
stream->sample_rate,
|
|
/* input */
|
|
- stream->decoder->channel_layout,
|
|
+ &input_channel_layout,
|
|
stream->decoder->sample_fmt,
|
|
stream->decoder->sample_rate,
|
|
0, NULL
|
|
);
|
|
+ av_channel_layout_uninit(&input_channel_layout);
|
|
+ av_channel_layout_uninit(&output_channel_layout);
|
|
if (!stream->converter) {
|
|
oshu_log_error("error allocating the audio resampler");
|
|
return -1;
|