From 863eda6c45a0ed0bf5f460dde6177c257d57cff8 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 15 Jan 2024 20:52:07 -0500 Subject: Major build improvments (Windows sink) - This commit won't run correctly because the signedness change is not handled by bimu server yet. Signed-off-by: Andrew Opalach --- src/codec/codec.h | 4 ++-- src/codec/libav/demuxer.c | 17 +++++++++-------- src/codec/libav/demuxer.h | 4 +--- src/codec/libav/resampler.c | 2 +- src/codec/meson.build | 17 +++++------------ src/codec/spng/impl.c | 4 ++-- src/codec/stb_image/impl.c | 4 ++-- src/codec/wuffs/impl.c | 4 ++-- 8 files changed, 24 insertions(+), 32 deletions(-) (limited to 'src/codec') diff --git a/src/codec/codec.h b/src/codec/codec.h index 1309210..f9ba660 100644 --- a/src/codec/codec.h +++ b/src/codec/codec.h @@ -96,8 +96,8 @@ struct camu_demuxer { u8 type; bool (*init)(struct camu_demuxer *, struct cch_handle *); s32 (*get_packet)(struct camu_demuxer *, struct camu_packet *); - s64 (*get_duration)(struct camu_demuxer *); - bool (*seek)(struct camu_demuxer *, s64); + u64 (*get_duration)(struct camu_demuxer *); + bool (*seek)(struct camu_demuxer *, u64); void (*free)(struct camu_demuxer **); array(struct camu_stream) streams; array(s32) subscribed; diff --git a/src/codec/libav/demuxer.c b/src/codec/libav/demuxer.c index d823d23..18b9020 100644 --- a/src/codec/libav/demuxer.c +++ b/src/codec/libav/demuxer.c @@ -1,8 +1,7 @@ #include -#include "../common.h" - #include "demuxer.h" +#include "avio.h" #define BUF_SIZE 16384 @@ -63,11 +62,11 @@ static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *hand goto err; } - av->duration = 0; - #define GUESS_STREAM_IS_IMAGE(stream) \ (stream->duration >= 0 && stream->nb_frames <= 1 && (stream->avg_frame_rate.den == 0 && stream->r_frame_rate.den > 0)) + av->duration = 0; + for (u32 i = 0; i < av->format_context->nb_streams; i++) { AVStream *stream = av->format_context->streams[i]; enum AVMediaType type = stream->codecpar->codec_type; @@ -88,7 +87,8 @@ static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *hand al_log_warn("lav_demux", "Stream has a negative start_time (%ld).", stream->start_time); } s64 duration = av_rescale_q(stream->duration, stream->time_base, AV_TIME_BASE_Q); - if (duration > av->duration) av->duration = duration; + al_assert(duration >= 0); + if ((u64)duration > av->duration) av->duration = (u64)duration; al_array_push(av->demux.streams, ((struct camu_stream){ .type = CAMU_FFMPEG_COMPAT, .av.stream = stream @@ -140,16 +140,17 @@ static s32 lav_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet return ret; } -static s64 lav_demuxer_get_duration(struct camu_demuxer *demux) +static u64 lav_demuxer_get_duration(struct camu_demuxer *demux) { struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)demux; return av->duration; } -static bool lav_demuxer_seek(struct camu_demuxer *demux, s64 pos) +static bool lav_demuxer_seek(struct camu_demuxer *demux, u64 pos) { struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)demux; - s64 ts = av_rescale_q(pos, (AVRational){ 1, 1000000 }, AV_TIME_BASE_Q); + if (pos > av->duration) pos = av->duration; + s64 ts = av_rescale_q((s64)pos, (AVRational){ 1, 1000000 }, AV_TIME_BASE_Q); if (av->eof) { avformat_flush(av->format_context); av->eof = false; diff --git a/src/codec/libav/demuxer.h b/src/codec/libav/demuxer.h index a9d8c5c..9b2d093 100644 --- a/src/codec/libav/demuxer.h +++ b/src/codec/libav/demuxer.h @@ -8,13 +8,11 @@ #include "../codec.h" -#include "avio.h" - struct camu_lav_demuxer { struct camu_demuxer demux; AVIOContext *io_context; AVFormatContext *format_context; - s64 duration; + u64 duration; bool eof; }; diff --git a/src/codec/libav/resampler.c b/src/codec/libav/resampler.c index 3dcb6d4..ba700f4 100644 --- a/src/codec/libav/resampler.c +++ b/src/codec/libav/resampler.c @@ -43,7 +43,7 @@ bool camu_lav_resampler_init(struct camu_lav_resampler *resamp, struct camu_lav_ av_opt_set_sample_fmt(ctx, "out_sample_fmt", fmt->req_format, 0); // Slower but more accurate resampler. - av_opt_set_int(ctx, "resampler", SWR_ENGINE_SOXR, 0); + //av_opt_set_int(ctx, "resampler", SWR_ENGINE_SOXR, 0); if (swr_init(ctx) != 0) { swr_free(&ctx); diff --git a/src/codec/meson.build b/src/codec/meson.build index a3951f0..676be1c 100644 --- a/src/codec/meson.build +++ b/src/codec/meson.build @@ -9,6 +9,7 @@ av_src = [ 'libav/avio.c' ] av_inc = [] +av_ldflags = [] av_deps = [] libavutil = dependency('libavutil', required: false) @@ -24,28 +25,20 @@ if not (libavutil.found() and libavformat.found() and libavcodec.found() and lib libavcodec = av_proj.get_variable('avcodec') libswresample = av_proj.get_variable('swresample') libswscale = av_proj.get_variable('swscale') - #libdir = av_proj.get_variable('libdir') - #libavutil = compiler.find_library('avutil', dirs: libdir) - #libavformat = compiler.find_library('avformat', dirs: libdir) - #libavcodec = compiler.find_library('avcodec', dirs: libdir) - #libswresample = compiler.find_library('swresample', dirs: libdir) - #libswscale = compiler.find_library('swscale', dirs: libdir) - zlib = compiler.find_library('z', required: false) - if zlib.found() - av_deps += [zlib] - endif + av_inc += [av_proj.get_variable('inc')] + av_ldflags += ['-L' + av_proj.get_variable('libdir')] + av_deps += [dependency('zlib')] soxr = compiler.find_library('soxr', required: false) if soxr.found() av_deps += [soxr] endif av_deps += [compiler.find_library('bcrypt')] - av_inc += [av_proj.get_variable('inc')] endif endif if libavutil.found() and libavformat.found() and libavcodec.found() and libswresample.found() and libswscale.found() av_deps += [libavutil, libavformat, libavcodec, libswresample, libswscale] - av = declare_dependency(sources: av_src, dependencies: av_deps, include_directories: av_inc) + av = declare_dependency(sources: av_src, dependencies: av_deps, include_directories: av_inc, link_args: av_ldflags) add_project_arguments('-DHAVE_FFMPEG', language: ['c', 'cpp']) endif diff --git a/src/codec/spng/impl.c b/src/codec/spng/impl.c index d090bdc..9089e99 100644 --- a/src/codec/spng/impl.c +++ b/src/codec/spng/impl.c @@ -53,13 +53,13 @@ static s32 spng_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packe return CAMU_OK; } -static s64 spng_demuxer_get_duration(struct camu_demuxer *demux) +static u64 spng_demuxer_get_duration(struct camu_demuxer *demux) { (void)demux; return 0; } -static bool spng_demuxer_seek(struct camu_demuxer *demux, s64 pos) +static bool spng_demuxer_seek(struct camu_demuxer *demux, u64 pos) { (void)demux; (void)pos; diff --git a/src/codec/stb_image/impl.c b/src/codec/stb_image/impl.c index b7ed928..6058ff2 100644 --- a/src/codec/stb_image/impl.c +++ b/src/codec/stb_image/impl.c @@ -51,13 +51,13 @@ static s32 stbi_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packe return CAMU_OK; } -static s64 stbi_demuxer_get_duration(struct camu_demuxer *demux) +static u64 stbi_demuxer_get_duration(struct camu_demuxer *demux) { (void)demux; return 0; } -static bool stbi_demuxer_seek(struct camu_demuxer *demux, s64 pos) +static bool stbi_demuxer_seek(struct camu_demuxer *demux, u64 pos) { (void)demux; (void)pos; diff --git a/src/codec/wuffs/impl.c b/src/codec/wuffs/impl.c index a1e58e4..26e9011 100644 --- a/src/codec/wuffs/impl.c +++ b/src/codec/wuffs/impl.c @@ -72,13 +72,13 @@ static s32 wuffs_demuxer_get_packet(struct camu_demuxer *demux, struct camu_pack return CAMU_OK; } -static s64 wuffs_demuxer_get_duration(struct camu_demuxer *demux) +static u64 wuffs_demuxer_get_duration(struct camu_demuxer *demux) { (void)demux; return 0; } -static bool wuffs_demuxer_seek(struct camu_demuxer *demux, s64 pos) +static bool wuffs_demuxer_seek(struct camu_demuxer *demux, u64 pos) { (void)demux; (void)pos; -- cgit v1.2.3-101-g0448