summaryrefslogtreecommitdiff
path: root/src/codec
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/codec.h6
-rw-r--r--src/codec/ffmpeg/meson.build14
-rw-r--r--src/codec/ffmpeg/packet_ext.c14
-rw-r--r--src/codec/meson.build19
-rw-r--r--src/codec/stb_image.c23
-rw-r--r--src/codec/wuffs.c2
6 files changed, 62 insertions, 16 deletions
diff --git a/src/codec/codec.h b/src/codec/codec.h
index f1c979b..bb54b3b 100644
--- a/src/codec/codec.h
+++ b/src/codec/codec.h
@@ -210,7 +210,7 @@ struct camu_demuxer {
bool (*seek)(struct camu_demuxer *, u64, bool);
void (*free)(struct camu_demuxer **);
array(struct camu_codec_stream) streams;
- // @TODO: .mkv can probably have more than 64 streams.
+ // @TODO: .mkv (at least) can probably have more than 64 streams.
u64 subscribed;
};
@@ -440,7 +440,7 @@ static inline s32 camu_guess_format(str *short_name, str *ext, str *mime_type)
char *c_short_name = short_name ? al_str_to_c_str(short_name) : NULL;
char *c_ext = ext ? al_str_to_c_str(ext) : NULL;
char *c_mime_type = mime_type ? al_str_to_c_str(mime_type) : NULL;
- // Empty short_name to attempt avoiding image2 probing.
+ // Empty short_name to avoid image2 probing.
const AVOutputFormat *fmt = av_guess_format(c_short_name ? c_short_name : "", c_ext, c_mime_type);
if (c_short_name) al_free(c_short_name);
if (c_ext) al_free(c_ext);
@@ -448,5 +448,5 @@ static inline s32 camu_guess_format(str *short_name, str *ext, str *mime_type)
// In FFmpeg AV_CODEC_ID_MJPEG also means "image2".
if (fmt) return (fmt->audio_codec != AV_CODEC_ID_NONE) ? fmt->audio_codec : fmt->video_codec;
#endif
- return -1;
+ return CAMU_CODEC_FALLBACK;
}
diff --git a/src/codec/ffmpeg/meson.build b/src/codec/ffmpeg/meson.build
index e34cc92..1691c29 100644
--- a/src/codec/ffmpeg/meson.build
+++ b/src/codec/ffmpeg/meson.build
@@ -19,15 +19,23 @@ foreach dep: ['ffmpeg', 'libavutil', 'libavformat', 'libavcodec', 'libavdevice',
endif
endforeach
ffmpeg_version_option = get_option('codec-ffmpeg-version')
+if ffmpeg_version_option == 'auto'
+ expect_system = not (is_windows or is_android)
+ if expect_system
+ ffmpeg_version_option = 'system'
+ else # Latest.
+ ffmpeg_version_option = '9'
+ endif
+endif
# Check for FFmpeg version in the environment.
if not ffmpeg_force_fallback
- libavutil_version_map = { '54': '2', '55': '3', '56': '4', '57': '5', '58': '6', '59': '7', '60': '8' }
- libavutil_version_rev = { '2': '54', '3': '55', '4': '56', '5': '57', '6': '58', '7': '59', '8': '60' }
+ libavutil_version_map = { '54': '2', '55': '3', '56': '4', '57': '5', '58': '6', '59': '7', '60': '8', '61': '9' }
+ libavutil_version_rev = { '2': '54', '3': '55', '4': '56', '5': '57', '6': '58', '7': '59', '8': '60', '9': '61' }
if ffmpeg_version_option != 'system'
ffmpeg_version_int = ffmpeg_version_option.to_int()
# Overriding a found dependency will error but overriding a found dependency of the wrong version is allowed.
libavutil_version_request = ['>=' + libavutil_version_rev[(ffmpeg_version_int).to_string()] + '.0.0']
- if ffmpeg_version_int < 8
+ if ffmpeg_version_int < 9
libavutil_version_request += ['<' + libavutil_version_rev[(ffmpeg_version_int + 1).to_string()] + '.0.0']
endif
libavutil = dependency('libavutil', required: false, allow_fallback: false, version: libavutil_version_request)
diff --git a/src/codec/ffmpeg/packet_ext.c b/src/codec/ffmpeg/packet_ext.c
index 6934cfe..8f44caa 100644
--- a/src/codec/ffmpeg/packet_ext.c
+++ b/src/codec/ffmpeg/packet_ext.c
@@ -6,7 +6,9 @@ void nn_packet_write_av_codec_parameters(struct nn_packet *packet, AVCodecParame
NNWT_PACKET_WRITE_TYPE(packet, enum AVCodecID, codecpar->codec_id);
NNWT_PACKET_WRITE_TYPE(packet, u32, codecpar->codec_tag);
NNWT_PACKET_WRITE_TYPE(packet, s32, codecpar->extradata_size);
- NNWT_PACKET_WRITE_DATA(packet, codecpar->extradata, codecpar->extradata_size);
+ if (codecpar->extradata_size) {
+ NNWT_PACKET_WRITE_DATA(packet, codecpar->extradata, codecpar->extradata_size);
+ }
NNWT_PACKET_WRITE_TYPE(packet, s32, codecpar->format);
NNWT_PACKET_WRITE_TYPE(packet, s64, codecpar->bit_rate);
NNWT_PACKET_WRITE_TYPE(packet, s32, codecpar->bits_per_coded_sample);
@@ -118,10 +120,12 @@ void nn_packet_read_av_codec_parameters(struct nn_packet *packet, AVCodecParamet
NNWT_PACKET_READ_TYPE(packet, enum AVCodecID, codecpar->codec_id);
NNWT_PACKET_READ_TYPE(packet, u32, codecpar->codec_tag);
NNWT_PACKET_READ_TYPE(packet, s32, codecpar->extradata_size);
- codecpar->extradata = (u8 *)av_malloc(codecpar->extradata_size);
- u8 *extradata;
- NNWT_PACKET_READ_DATA(packet, codecpar->extradata_size, extradata);
- al_memcpy(codecpar->extradata, extradata, codecpar->extradata_size);
+ if (codecpar->extradata_size > 0) {
+ codecpar->extradata = (u8 *)av_malloc(codecpar->extradata_size);
+ u8 *extradata;
+ NNWT_PACKET_READ_DATA(packet, codecpar->extradata_size, extradata);
+ al_memcpy(codecpar->extradata, extradata, codecpar->extradata_size);
+ }
NNWT_PACKET_READ_TYPE(packet, s32, codecpar->format);
NNWT_PACKET_READ_TYPE(packet, s64, codecpar->bit_rate);
NNWT_PACKET_READ_TYPE(packet, s32, codecpar->bits_per_coded_sample);
diff --git a/src/codec/meson.build b/src/codec/meson.build
index a92a23d..7dfc668 100644
--- a/src/codec/meson.build
+++ b/src/codec/meson.build
@@ -10,12 +10,23 @@ endif
if 'stb_image' in get_option('codecs')
stb = []
stb_args = ['-DCAMU_HAVE_STB_IMAGE']
- if not compiler.check_header('stb/stb_image.h')
- stb = [subproject('stb').get_variable('stb')]
- stb_args += ['-DCAMU_LOCAL_STB']
+ stb_deps = []
+ if get_option('codec-stbi-use-wuffs')
+ stb_args += ['-DCAMU_STBI_USE_WUFFS']
+ if not compiler.check_header('wuffs/wuffs-v0.4.c')
+ wuffs = [subproject('wuffs').get_variable('wuffs')]
+ stb_deps += [wuffs]
+ stb_args += ['-DCAMU_LOCAL_WUFFS']
+ endif
+ else
+ if not compiler.check_header('stb/stb_image.h')
+ stb = [subproject('stb').get_variable('stb')]
+ stb_deps += [stb]
+ stb_args += ['-DCAMU_LOCAL_STB']
+ endif
endif
stb_codec = declare_dependency(sources: ['stb_image.c'],
- dependencies: stb, compile_args: stb_args)
+ dependencies: stb_deps, compile_args: stb_args)
codec_server_deps += [stb_codec]
codec_client_deps += [stb_codec]
endif
diff --git a/src/codec/stb_image.c b/src/codec/stb_image.c
index b37d6da..39b3a13 100644
--- a/src/codec/stb_image.c
+++ b/src/codec/stb_image.c
@@ -1,5 +1,27 @@
#define AL_LOG_SECTION "stb_image"
#include <al/log.h>
+
+#ifdef CAMU_STBI_USE_WUFFS
+#define WUFFS_IMPLEMENTATION
+#define WUFFS_CONFIG__MODULES
+#define WUFFS_CONFIG__MODULE__BASE
+#define WUFFS_CONFIG__MODULE__ADLER32
+#define WUFFS_CONFIG__MODULE__DEFLATE
+#define WUFFS_CONFIG__MODULE__ZLIB
+#define WUFFS_CONFIG__MODULE__CRC32
+#define WUFFS_CONFIG__MODULE__PNG
+#define WUFFS_CONFIG__MODULE__JPEG
+#define WUFFS_CONFIG__MODULE__IMAGE
+#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ENABLE_ALLOWLIST
+#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_Y
+#define WUFFS_CONFIG__DST_PIXEL_FORMAT__ALLOW_RGBA_NONPREMUL
+#define WUFFS_CONFIG__ENABLE_DROP_IN_REPLACEMENT__STB
+#ifdef CAMU_LOCAL_WUFFS
+#include <wuffs-unsupported-snapshot.c>
+#else
+#include <wuffs/wuffs-v0.4.c>
+#endif
+#else
#include "common.h"
#define STBI_MALLOC camu_page_alloc
#define STBI_FREE al_free
@@ -13,6 +35,7 @@
#else
#include <stb/stb_image.h>
#endif
+#endif
#include "stb_image.h"
diff --git a/src/codec/wuffs.c b/src/codec/wuffs.c
index 7050fb4..53d181b 100644
--- a/src/codec/wuffs.c
+++ b/src/codec/wuffs.c
@@ -1,3 +1,4 @@
+#define WUFFS_IMPLEMENTATION
#define WUFFS_CONFIG__MODULES
#define WUFFS_CONFIG__MODULE__BASE
#define WUFFS_CONFIG__MODULE__ADLER32
@@ -7,7 +8,6 @@
#define WUFFS_CONFIG__MODULE__PNG
#define WUFFS_CONFIG__MODULE__JPEG
#define WUFFS_CONFIG__MODULE__IMAGE
-#define WUFFS_IMPLEMENTATION
#ifdef CAMU_LOCAL_WUFFS
#include <wuffs-unsupported-snapshot.c>
#else