Skip to content

Commit 38e8775

Browse files
committed
[3PP] Upgrade to latest FFmpeg (for real this time)
1 parent c83292f commit 38e8775

File tree

12 files changed

+86
-57
lines changed

12 files changed

+86
-57
lines changed

src/xenia/apu/audio_media_player.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ ProcessAudioResult ProcessAudioLoop(AudioMediaPlayer* player,
134134
break;
135135
}
136136

137-
ConvertAudioFrame(frame, avctx->channels, &frameBuffer);
137+
ConvertAudioFrame(frame, avctx->ch_layout.nb_channels, &frameBuffer);
138138
player->ProcessAudioBuffer(&frameBuffer);
139139
}
140140
}
@@ -234,7 +234,8 @@ void AudioMediaPlayer::Play() {
234234
AVCodecContext* codecContext = nullptr;
235235
InitializeAndOpenAvCodec(song_buffer, formatContext, codecContext);
236236

237-
if (!SetupDriver(codecContext->sample_rate, codecContext->channels)) {
237+
if (!SetupDriver(codecContext->sample_rate,
238+
codecContext->ch_layout.nb_channels)) {
238239
XELOGE("Driver initialization failed!");
239240
avcodec_free_context(&codecContext);
240241
av_freep(&formatContext->pb->buffer);

src/xenia/apu/xma_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void XmaContext::DumpRaw(AVFrame* frame, int id) {
4949
}
5050
size_t data_size = sizeof(float);
5151
for (int i = 0; i < frame->nb_samples; i++) {
52-
for (int ch = 0; ch < frame->channels; ch++) {
52+
for (int ch = 0; ch < frame->ch_layout.nb_channels; ch++) {
5353
fwrite(frame->data[ch] + data_size * i, 1, data_size, outfile);
5454
}
5555
}

src/xenia/apu/xma_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class XmaContext {
266266

267267
// ffmpeg structures
268268
AVPacket* av_packet_ = nullptr;
269-
AVCodec* av_codec_ = nullptr;
269+
const AVCodec* av_codec_ = nullptr;
270270
AVCodecContext* av_context_ = nullptr;
271271
AVFrame* av_frame_ = nullptr;
272272
};

src/xenia/apu/xma_context_master.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#pragma warning(disable : 4101 4244 5033)
2626
#endif
2727
#include "third_party/FFmpeg/libavcodec/avcodec.h"
28+
#include "third_party/FFmpeg/libavutil/channel_layout.h"
2829
#if XE_COMPILER_MSVC
2930
#pragma warning(pop)
3031
#endif
@@ -40,10 +41,7 @@ XmaContextMaster::XmaContextMaster() = default;
4041

4142
XmaContextMaster::~XmaContextMaster() {
4243
if (av_context_) {
43-
if (avcodec_is_open(av_context_)) {
44-
avcodec_close(av_context_);
45-
}
46-
av_free(av_context_);
44+
avcodec_free_context(&av_context_);
4745
}
4846
if (av_frame_) {
4947
av_frame_free(&av_frame_);
@@ -78,7 +76,7 @@ int XmaContextMaster::Setup(uint32_t id, Memory* memory, uint32_t guest_ptr) {
7876
}
7977

8078
// Initialize these to 0. They'll actually be set later.
81-
av_context_->channels = 0;
79+
av_context_->ch_layout = AVChannelLayout{};
8280
av_context_->sample_rate = 0;
8381

8482
av_frame_ = av_frame_alloc();
@@ -814,13 +812,14 @@ int XmaContextMaster::PrepareDecoder(uint8_t* packet, int sample_rate,
814812
// Re-initialize the context with new sample rate and channels.
815813
uint32_t channels = is_two_channel ? 2 : 1;
816814
if (av_context_->sample_rate != sample_rate ||
817-
av_context_->channels != channels) {
818-
// We have to reopen the codec so it'll realloc whatever data it needs.
819-
// TODO(DrChat): Find a better way.
820-
avcodec_close(av_context_);
815+
av_context_->ch_layout.nb_channels != (int)channels) {
816+
// We have to recreate the codec context so it'll realloc whatever data it
817+
// needs.
818+
avcodec_free_context(&av_context_);
819+
av_context_ = avcodec_alloc_context3(av_codec_);
821820

822821
av_context_->sample_rate = sample_rate;
823-
av_context_->channels = channels;
822+
av_channel_layout_default(&av_context_->ch_layout, channels);
824823

825824
if (avcodec_open2(av_context_, av_codec_, NULL) < 0) {
826825
XELOGE("XmaContext: Failed to reopen FFmpeg context");

src/xenia/apu/xma_context_new.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern "C" {
2020
#pragma warning(disable : 4101 4244 5033)
2121
#endif
2222
#include "third_party/FFmpeg/libavcodec/avcodec.h"
23+
#include "third_party/FFmpeg/libavutil/channel_layout.h"
2324
#if XE_COMPILER_MSVC
2425
#pragma warning(pop)
2526
#endif
@@ -35,10 +36,7 @@ XmaContextNew::XmaContextNew() = default;
3536

3637
XmaContextNew::~XmaContextNew() {
3738
if (av_context_) {
38-
if (avcodec_is_open(av_context_)) {
39-
avcodec_close(av_context_);
40-
}
41-
av_free(av_context_);
39+
avcodec_free_context(&av_context_);
4240
}
4341
if (av_frame_) {
4442
av_frame_free(&av_frame_);
@@ -69,7 +67,7 @@ int XmaContextNew::Setup(uint32_t id, Memory* memory, uint32_t guest_ptr) {
6967
}
7068

7169
// Initialize these to 0. They'll actually be set later.
72-
av_context_->channels = 0;
70+
av_context_->ch_layout = AVChannelLayout{};
7371
av_context_->sample_rate = 0;
7472

7573
av_frame_ = av_frame_alloc();
@@ -683,13 +681,14 @@ int XmaContextNew::PrepareDecoder(int sample_rate, bool is_two_channel) {
683681
// Re-initialize the context with new sample rate and channels.
684682
uint32_t channels = is_two_channel ? 2 : 1;
685683
if (av_context_->sample_rate != sample_rate ||
686-
av_context_->channels != channels) {
687-
// We have to reopen the codec so it'll realloc whatever data it needs.
688-
// TODO(DrChat): Find a better way.
689-
avcodec_close(av_context_);
684+
av_context_->ch_layout.nb_channels != (int)channels) {
685+
// We have to recreate the codec context so it'll realloc whatever data it
686+
// needs.
687+
avcodec_free_context(&av_context_);
688+
av_context_ = avcodec_alloc_context3(av_codec_);
690689

691690
av_context_->sample_rate = sample_rate;
692-
av_context_->channels = channels;
691+
av_channel_layout_default(&av_context_->ch_layout, channels);
693692

694693
if (avcodec_open2(av_context_, av_codec_, NULL) < 0) {
695694
XELOGE("XmaContext: Failed to reopen FFmpeg context");

src/xenia/apu/xma_context_old.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#pragma warning(disable : 4101 4244 5033)
2626
#endif
2727
#include "third_party/FFmpeg/libavcodec/avcodec.h"
28+
#include "third_party/FFmpeg/libavutil/channel_layout.h"
2829
#if XE_COMPILER_MSVC
2930
#pragma warning(pop)
3031
#endif
@@ -40,10 +41,7 @@ XmaContextOld::XmaContextOld() = default;
4041

4142
XmaContextOld::~XmaContextOld() {
4243
if (av_context_) {
43-
if (avcodec_is_open(av_context_)) {
44-
avcodec_close(av_context_);
45-
}
46-
av_free(av_context_);
44+
avcodec_free_context(&av_context_);
4745
}
4846
if (av_frame_) {
4947
av_frame_free(&av_frame_);
@@ -78,7 +76,7 @@ int XmaContextOld::Setup(uint32_t id, Memory* memory, uint32_t guest_ptr) {
7876
}
7977

8078
// Initialize these to 0. They'll actually be set later.
81-
av_context_->channels = 0;
79+
av_context_->ch_layout = AVChannelLayout{};
8280
av_context_->sample_rate = 0;
8381

8482
av_frame_ = av_frame_alloc();
@@ -653,7 +651,8 @@ void XmaContextOld::Decode(XMA_CONTEXT_DATA* data) {
653651

654652
// dump_raw(av_frame_, id());
655653
ConvertFrame(reinterpret_cast<const uint8_t**>(&av_frame_->data),
656-
bool(av_frame_->channels > 1), raw_frame_.data());
654+
bool(av_frame_->ch_layout.nb_channels > 1),
655+
raw_frame_.data());
657656
// decoded_consumed_samples_ += kSamplesPerFrame;
658657

659658
auto byte_count = kBytesPerFrameChannel << data->is_stereo;
@@ -917,13 +916,14 @@ int XmaContextOld::PrepareDecoder(uint8_t* packet, int sample_rate,
917916
// Re-initialize the context with new sample rate and channels.
918917
uint32_t channels = is_two_channel ? 2 : 1;
919918
if (av_context_->sample_rate != sample_rate ||
920-
av_context_->channels != channels) {
921-
// We have to reopen the codec so it'll realloc whatever data it needs.
922-
// TODO(DrChat): Find a better way.
923-
avcodec_close(av_context_);
919+
av_context_->ch_layout.nb_channels != (int)channels) {
920+
// We have to recreate the codec context so it'll realloc whatever data it
921+
// needs.
922+
avcodec_free_context(&av_context_);
923+
av_context_ = avcodec_alloc_context3(av_codec_);
924924

925925
av_context_->sample_rate = sample_rate;
926-
av_context_->channels = channels;
926+
av_channel_layout_default(&av_context_->ch_layout, channels);
927927

928928
if (avcodec_open2(av_context_, av_codec_, NULL) < 0) {
929929
XELOGE("XmaContext: Failed to reopen FFmpeg context");

third_party/FFmpeg

Submodule FFmpeg updated 7579 files
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* FFmpeg component configuration for xenia.
3+
* In upstream FFmpeg this is generated by configure separately from config.h.
4+
* For xenia all CONFIG_* component defines live in config.h, so we just
5+
* include that.
6+
*/
7+
#ifndef FFMPEG_CONFIG_COMPONENTS_H
8+
#define FFMPEG_CONFIG_COMPONENTS_H
9+
10+
#include "config.h"
11+
12+
#endif /* FFMPEG_CONFIG_COMPONENTS_H */

third_party/ffmpeg-xenia/libavcodec/premake5.lua

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ project("libavcodec")
1212
"libavutil",
1313
})
1414

15+
-- Needed for files in subdirectories (e.g. bsf/null.c) that include
16+
-- headers relative to libavcodec/.
17+
includedirs({
18+
"../../FFmpeg/libavcodec",
19+
})
20+
1521
-- libavcodec/Makefile:
1622
-- HEADERS:
1723
files({
1824
"../../FFmpeg/libavcodec/ac3_parser.h",
1925
"../../FFmpeg/libavcodec/adts_parser.h",
2026
"../../FFmpeg/libavcodec/avcodec.h",
2127
"../../FFmpeg/libavcodec/avdct.h",
22-
"../../FFmpeg/libavcodec/avfft.h",
2328
"../../FFmpeg/libavcodec/bsf.h",
2429
"../../FFmpeg/libavcodec/codec.h",
2530
"../../FFmpeg/libavcodec/codec_desc.h",
@@ -33,12 +38,10 @@ project("libavcodec")
3338
"../../FFmpeg/libavcodec/mediacodec.h",
3439
"../../FFmpeg/libavcodec/packet.h",
3540
"../../FFmpeg/libavcodec/qsv.h",
36-
"../../FFmpeg/libavcodec/vaapi.h",
3741
"../../FFmpeg/libavcodec/vdpau.h",
3842
"../../FFmpeg/libavcodec/version.h",
3943
"../../FFmpeg/libavcodec/videotoolbox.h",
4044
"../../FFmpeg/libavcodec/vorbis_parser.h",
41-
"../../FFmpeg/libavcodec/xvmc.h",
4245
})
4346
-- OBJS:
4447
files({
@@ -47,10 +50,8 @@ project("libavcodec")
4750
"../../FFmpeg/libavcodec/allcodecs.c",
4851
"../../FFmpeg/libavcodec/avcodec.c",
4952
"../../FFmpeg/libavcodec/avdct.c",
50-
"../../FFmpeg/libavcodec/avpacket.c",
51-
"../../FFmpeg/libavcodec/avpicture.c",
53+
"../../FFmpeg/libavcodec/packet.c",
5254
"../../FFmpeg/libavcodec/bitstream.c",
53-
"../../FFmpeg/libavcodec/bitstream_filter.c",
5455
"../../FFmpeg/libavcodec/bitstream_filters.c",
5556
"../../FFmpeg/libavcodec/bsf.c",
5657
"../../FFmpeg/libavcodec/codec_desc.c",
@@ -74,7 +75,6 @@ project("libavcodec")
7475
"../../FFmpeg/libavcodec/utils.c",
7576
"../../FFmpeg/libavcodec/vorbis_parser.c",
7677
"../../FFmpeg/libavcodec/xiph.c",
77-
"../../FFmpeg/libavcodec/dct.c",
7878
"../../FFmpeg/libavcodec/dct32_fixed.c",
7979
"../../FFmpeg/libavcodec/dct32_float.c",
8080
"../../FFmpeg/libavcodec/faandct.c",
@@ -85,8 +85,6 @@ project("libavcodec")
8585
"../../FFmpeg/libavcodec/idctdsp.c",
8686
"../../FFmpeg/libavcodec/simple_idct.c",
8787
"../../FFmpeg/libavcodec/jrevdct.c",
88-
"../../FFmpeg/libavcodec/mdct_float.c",
89-
"../../FFmpeg/libavcodec/mdct_fixed_32.c",
9088
"../../FFmpeg/libavcodec/mpegaudio.c",
9189
"../../FFmpeg/libavcodec/mpegaudiodec_common.c",
9290
"../../FFmpeg/libavcodec/mpegaudiodsp.c",
@@ -95,7 +93,6 @@ project("libavcodec")
9593
"../../FFmpeg/libavcodec/mpegaudiodsp_float.c",
9694
"../../FFmpeg/libavcodec/mpegaudiodecheader.c",
9795
"../../FFmpeg/libavcodec/mpegaudiodata.c",
98-
"../../FFmpeg/libavcodec/rdft.c",
9996
"../../FFmpeg/libavcodec/sinewin.c",
10097
"../../FFmpeg/libavcodec/wma_freqs.c",
10198
"../../FFmpeg/libavcodec/mpegaudiodec_fixed.c",
@@ -106,14 +103,16 @@ project("libavcodec")
106103
"../../FFmpeg/libavcodec/wmadec.c",
107104
"../../FFmpeg/libavcodec/aactab.c",
108105
"../../FFmpeg/libavcodec/mpegaudio_parser.c",
109-
"../../FFmpeg/libavcodec/null_bsf.c",
110106
"../../FFmpeg/libavcodec/pthread.c",
111107
"../../FFmpeg/libavcodec/pthread_slice.c",
112108
"../../FFmpeg/libavcodec/pthread_frame.c",
113-
"../../FFmpeg/libavcodec/avfft.c",
114-
"../../FFmpeg/libavcodec/fft_float.c",
115-
"../../FFmpeg/libavcodec/fft_fixed_32.c",
116-
"../../FFmpeg/libavcodec/fft_init_table.c",
109+
"../../FFmpeg/libavcodec/get_buffer.c",
110+
"../../FFmpeg/libavcodec/vlc.c",
111+
"../../FFmpeg/libavcodec/threadprogress.c",
112+
"../../FFmpeg/libavcodec/bsf/null.c",
113+
"../../FFmpeg/libavcodec/exif.c",
114+
"../../FFmpeg/libavcodec/mpegaudiotabs.c",
115+
"../../FFmpeg/libavcodec/tiff_common.c",
117116
})
118117
filter({"platforms:Windows"})
119118
files({
@@ -125,7 +124,6 @@ project("libavcodec")
125124
-- OBJS:
126125
filter({"platforms:Android-ARM64"})
127126
files({
128-
"../../FFmpeg/libavcodec/aarch64/fft_init_aarch64.c",
129127
"../../FFmpeg/libavcodec/aarch64/idctdsp_init_aarch64.c",
130128
"../../FFmpeg/libavcodec/aarch64/mpegaudiodsp_init.c",
131129
})
@@ -145,9 +143,7 @@ project("libavcodec")
145143
filter({"platforms:Android-x86_64 or platforms:Linux or platforms:Windows"})
146144
files({
147145
"../../FFmpeg/libavcodec/x86/constants.c",
148-
"../../FFmpeg/libavcodec/x86/dct_init.c",
149146
"../../FFmpeg/libavcodec/x86/fdctdsp_init.c",
150-
"../../FFmpeg/libavcodec/x86/fft_init.c",
151147
"../../FFmpeg/libavcodec/x86/idctdsp_init.c",
152148
"../../FFmpeg/libavcodec/x86/mpegaudiodsp.c",
153149
})

third_party/ffmpeg-xenia/libavformat/premake5.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ project("libavformat")
4646
"../../FFmpeg/libavformat/mp3dec.c",
4747
"../../FFmpeg/libavformat/replaygain.c",
4848
"../../FFmpeg/libavformat/file.c",
49+
"../../FFmpeg/libavformat/demux.c",
50+
"../../FFmpeg/libavformat/avformat.c",
51+
"../../FFmpeg/libavformat/seek.c",
52+
"../../FFmpeg/libavformat/demux_utils.c",
53+
"../../FFmpeg/libavformat/urldecode.c",
54+
"../../FFmpeg/libavformat/asf_tags.c",
55+
"../../FFmpeg/libavformat/to_upper4.c",
4956
})
5057
filter({"platforms:Windows"})
5158
files({

0 commit comments

Comments
 (0)