Skip to content

Commit a053abf

Browse files
committed
ffmpeg: update cellAtracXDec to ffmpeg 7
1 parent e5848f4 commit a053abf

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

rpcs3/Emu/Cell/Modules/cellAtracXdec.cpp

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -111,29 +111,6 @@ void AtracXdecDecoder::alloc_avcodec()
111111
fmt::throw_exception("avcodec_find_decoder() failed");
112112
}
113113

114-
ensure(!(codec->capabilities & AV_CODEC_CAP_SUBFRAMES));
115-
116-
ctx = avcodec_alloc_context3(codec);
117-
if (!ctx)
118-
{
119-
fmt::throw_exception("avcodec_alloc_context3() failed");
120-
}
121-
122-
// Allows FFmpeg to output directly into guest memory
123-
ctx->opaque = this;
124-
ctx->thread_type = FF_THREAD_SLICE; // Silences a warning by FFmpeg about requesting frame threading with a custom get_buffer2(). Default is FF_THREAD_FRAME & FF_THREAD_SLICE
125-
ctx->get_buffer2 = [](AVCodecContext* s, AVFrame* frame, int /*flags*/) -> int
126-
{
127-
for (s32 i = 0; i < frame->ch_layout.nb_channels; i++)
128-
{
129-
frame->data[i] = static_cast<AtracXdecDecoder*>(s->opaque)->work_mem.get_ptr() + ATXDEC_MAX_FRAME_LENGTH + ATXDEC_SAMPLES_PER_FRAME * sizeof(f32) * i;
130-
frame->linesize[i] = ATXDEC_SAMPLES_PER_FRAME * sizeof(f32);
131-
}
132-
133-
frame->buf[0] = av_buffer_create(frame->data[0], ATXDEC_SAMPLES_PER_FRAME * sizeof(f32) * frame->ch_layout.nb_channels, [](void*, uint8_t*){}, nullptr, 0);
134-
return 0;
135-
};
136-
137114
packet = av_packet_alloc();
138115
if (!packet)
139116
{
@@ -149,18 +126,47 @@ void AtracXdecDecoder::alloc_avcodec()
149126

150127
void AtracXdecDecoder::free_avcodec()
151128
{
152-
av_packet_free(&packet);
153-
av_frame_free(&frame);
154-
avcodec_free_context(&ctx);
129+
if (packet)
130+
{
131+
av_packet_free(&packet);
132+
}
133+
if (frame)
134+
{
135+
av_frame_free(&frame);
136+
}
137+
if (ctx)
138+
{
139+
avcodec_free_context(&ctx);
140+
}
155141
}
156142

157143
void AtracXdecDecoder::init_avcodec()
158144
{
159-
if (int err = avcodec_close(ctx); err)
145+
if (ctx)
146+
{
147+
avcodec_free_context(&ctx);
148+
}
149+
150+
ctx = avcodec_alloc_context3(codec);
151+
if (!ctx)
160152
{
161-
fmt::throw_exception("avcodec_close() failed (err=0x%x='%s')", err, utils::av_error_to_string(err));
153+
fmt::throw_exception("avcodec_alloc_context3() failed");
162154
}
163155

156+
// Allows FFmpeg to output directly into guest memory
157+
ctx->opaque = this;
158+
ctx->thread_type = FF_THREAD_SLICE; // Silences a warning by FFmpeg about requesting frame threading with a custom get_buffer2(). Default is FF_THREAD_FRAME & FF_THREAD_SLICE
159+
ctx->get_buffer2 = [](AVCodecContext* s, AVFrame* frame, int /*flags*/) -> int
160+
{
161+
for (s32 i = 0; i < frame->ch_layout.nb_channels; i++)
162+
{
163+
frame->data[i] = static_cast<AtracXdecDecoder*>(s->opaque)->work_mem.get_ptr() + ATXDEC_MAX_FRAME_LENGTH + ATXDEC_SAMPLES_PER_FRAME * sizeof(f32) * i;
164+
frame->linesize[i] = ATXDEC_SAMPLES_PER_FRAME * sizeof(f32);
165+
}
166+
167+
frame->buf[0] = av_buffer_create(frame->data[0], ATXDEC_SAMPLES_PER_FRAME * sizeof(f32) * frame->ch_layout.nb_channels, [](void*, uint8_t*){}, nullptr, 0);
168+
return 0;
169+
};
164170
ctx->block_align = nbytes;
165171
ctx->ch_layout.nb_channels = nch_in;
166172
ctx->sample_rate = sampling_freq;

rpcs3/Emu/Cell/Modules/cellAtracXdec.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ struct AtracXdecDecoder
192192

193193
// HLE exclusive
194194
b8 config_is_set = false; // For savestates
195-
const AVCodec* codec;
196-
AVCodecContext* ctx;
197-
AVPacket* packet;
198-
AVFrame* frame;
195+
const AVCodec* codec = nullptr;
196+
AVCodecContext* ctx = nullptr;
197+
AVPacket* packet = nullptr;
198+
AVFrame* frame = nullptr;
199199

200200
u8 spurs_stuff[84]; // 120 bytes on LLE, pointers to CellSpurs, CellSpursTaskset, etc.
201201

0 commit comments

Comments
 (0)