From 448d52fa4eec8d603cd9a73d5dcc20b7515308a3 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sat, 27 Jan 2018 13:01:30 +0100 Subject: [PATCH] Remove BGW ATRAC3 mode in FFmpeg in favor of custom streamfiles --- src/coding/ffmpeg_decoder.c | 6 -- src/coding/ffmpeg_decoder_utils.h | 4 -- src/coding/ffmpeg_decoder_utils_bgw_atrac3.c | 58 -------------------- src/libvgmstream.vcproj | 4 -- src/libvgmstream.vcxproj | 1 - src/libvgmstream.vcxproj.filters | 3 - src/vgmstream.h | 2 - 7 files changed, 78 deletions(-) delete mode 100644 src/coding/ffmpeg_decoder_utils_bgw_atrac3.c diff --git a/src/coding/ffmpeg_decoder.c b/src/coding/ffmpeg_decoder.c index ed3c3d7d..0e365262 100644 --- a/src/coding/ffmpeg_decoder.c +++ b/src/coding/ffmpeg_decoder.c @@ -222,7 +222,6 @@ static int ffmpeg_read(void *opaque, uint8_t *buf, int buf_size) { switch(data->config.type) { case FFMPEG_EA_XMA: ret = ffmpeg_custom_read_eaxma(data, buf, buf_size); break; case FFMPEG_SWITCH_OPUS: ret = ffmpeg_custom_read_switch_opus(data, buf, buf_size); break; - case FFMPEG_BGW_ATRAC3: ret = ffmpeg_custom_read_bgw_atrac3(data, buf, buf_size); break; //case FFMPEG_EA_SCHL: ret = ffmpeg_custom_read_ea_schl(data, buf, buf_size); break; //case FFMPEG_SFH: ret = ffmpeg_custom_read_sfh(data, buf, buf_size); break; default: ret = ffmpeg_custom_read_standard(data, buf, buf_size); break; @@ -291,7 +290,6 @@ static int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence) { switch(data->config.type) { case FFMPEG_EA_XMA: offset = ffmpeg_custom_seek_eaxma(data, offset); break; case FFMPEG_SWITCH_OPUS: offset = ffmpeg_custom_seek_switch_opus(data, offset); break; - case FFMPEG_BGW_ATRAC3: offset = ffmpeg_custom_seek_bgw_atrac3(data, offset); break; //case FFMPEG_EA_SCHL: offset = ffmpeg_custom_seek_ea_schl(data, offset); break; //case FFMPEG_SFH: offset = ffmpeg_custom_seek_sfh(data, offset); break; default: offset = ffmpeg_custom_seek_standard(data, offset); break; @@ -309,7 +307,6 @@ static int64_t ffmpeg_size(ffmpeg_codec_data * data) { switch(data->config.type) { case FFMPEG_EA_XMA: bytes = ffmpeg_custom_size_eaxma(data); break; case FFMPEG_SWITCH_OPUS: bytes = ffmpeg_custom_size_switch_opus(data); break; - case FFMPEG_BGW_ATRAC3: bytes = ffmpeg_custom_size_bgw_atrac3(data); break; //case FFMPEG_EA_SCHL: bytes = ffmpeg_custom_size_ea_schl(data); break; //case FFMPEG_SFH: bytes = ffmpeg_custom_size_sfh(data); break; default: bytes = ffmpeg_custom_size_standard(data); break; @@ -806,9 +803,6 @@ void free_ffmpeg(ffmpeg_codec_data *data) { close_streamfile(data->streamfile); data->streamfile = NULL; } - if (data->config.key) { - free(data->config.key); - } free(data); } diff --git a/src/coding/ffmpeg_decoder_utils.h b/src/coding/ffmpeg_decoder_utils.h index a7e12912..64461fe9 100644 --- a/src/coding/ffmpeg_decoder_utils.h +++ b/src/coding/ffmpeg_decoder_utils.h @@ -31,10 +31,6 @@ int ffmpeg_custom_read_switch_opus(ffmpeg_codec_data *data, uint8_t *buf, int bu int64_t ffmpeg_custom_seek_switch_opus(ffmpeg_codec_data *data, int64_t virtual_offset); int64_t ffmpeg_custom_size_switch_opus(ffmpeg_codec_data *data); -int ffmpeg_custom_read_bgw_atrac3(ffmpeg_codec_data *data, uint8_t *buf, int buf_size); -int64_t ffmpeg_custom_seek_bgw_atrac3(ffmpeg_codec_data *data, int64_t virtual_offset); -int64_t ffmpeg_custom_size_bgw_atrac3(ffmpeg_codec_data *data); - //int ffmpeg_custom_read_ea_schl(ffmpeg_codec_data *data, uint8_t *buf, int buf_size); //int64_t ffmpeg_custom_seek_ea_schl(ffmpeg_codec_data *data, int64_t virtual_offset); //int64_t ffmpeg_custom_size_ea_schl(ffmpeg_codec_data *data); diff --git a/src/coding/ffmpeg_decoder_utils_bgw_atrac3.c b/src/coding/ffmpeg_decoder_utils_bgw_atrac3.c deleted file mode 100644 index 5b6bd441..00000000 --- a/src/coding/ffmpeg_decoder_utils_bgw_atrac3.c +++ /dev/null @@ -1,58 +0,0 @@ -#if 1 -#include "coding.h" -#include "ffmpeg_decoder_utils.h" - -#ifdef VGM_USE_FFMPEG - -#define BGM_ATRAC3_FRAME_SIZE 0xC0 - -/** - * Encrypted ATRAC3 used in BGW (Final Fantasy XI PC). - * Info from Moogle Toolbox: https://sourceforge.net/projects/mogbox/ - */ - -int ffmpeg_custom_read_bgw_atrac3(ffmpeg_codec_data *data, uint8_t *buf, int buf_size) { - int i, ch; - size_t bytes; - size_t block_align = BGM_ATRAC3_FRAME_SIZE * data->config.channels; - - - /* init key: first frame + modified channel header */ - if (data->config.key == NULL) { - data->config.key = malloc(block_align); - if (!data->config.key) return 0; - - read_streamfile(data->config.key, data->real_start, block_align, data->streamfile); - for (ch = 0; ch < data->config.channels; ch++) { - uint32_t xor = get_32bitBE(data->config.key + ch*BGM_ATRAC3_FRAME_SIZE); - put_32bitBE(data->config.key + ch*BGM_ATRAC3_FRAME_SIZE, xor ^ 0xA0024E9F); - } - } - - - /* read normally and unXOR the data */ - bytes = read_streamfile(buf, data->real_offset, buf_size, data->streamfile); - for (i = 0; i < bytes; i++) { - int key_pos = (data->real_offset - data->real_start + i) % block_align; - buf[i] = buf[i] ^ data->config.key[key_pos]; - } - - - data->real_offset += bytes; - return bytes; -} - -int64_t ffmpeg_custom_seek_bgw_atrac3(ffmpeg_codec_data *data, int64_t virtual_offset) { - int64_t seek_virtual_offset = virtual_offset - data->header_size; - - data->real_offset = data->real_start + seek_virtual_offset; - return virtual_offset; -} - -int64_t ffmpeg_custom_size_bgw_atrac3(ffmpeg_codec_data *data) { - return data->real_size + data->header_size; -} - - -#endif -#endif diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index fb99c94c..53468d58 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -1482,10 +1482,6 @@ RelativePath=".\coding\ffmpeg_decoder_utils_ea_schl.c" > - - diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 6340a83f..a1539618 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -112,7 +112,6 @@ - diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 1e5f45b7..e0b589c2 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -1222,9 +1222,6 @@ coding\Source Files - - coding\Source Files - coding\Source Files diff --git a/src/vgmstream.h b/src/vgmstream.h index e17dfb10..9b611f88 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -1098,7 +1098,6 @@ typedef enum { FFMPEG_STANDARD, /* default FFmpeg */ FFMPEG_SWITCH_OPUS, /* Opus without Ogg layer */ FFMPEG_EA_XMA, /* XMA with padding removed and custom streams in SNS blocks */ - FFMPEG_BGW_ATRAC3, /* Encrypted raw ATRAC3 */ //FFMPEG_EA_SCHL, /* Normal header+data (ex. ATRAC3) in SCxx blocks */ //FFMPEG_SFH, /* ATRAC3plus header+data in SFH blocks */ //FFMPEG_AWC_XMA, /* XMA data in AWC blocks, 1 streams per channel */ @@ -1116,7 +1115,6 @@ typedef struct { /* internal sequences, when needed */ int sequence; int samples_done; - uint8_t * key; } ffmpeg_custom_config; typedef struct {