diff options
| author | 2024-01-20 18:45:29 -0500 | |
|---|---|---|
| committer | 2024-01-20 18:45:29 -0500 | |
| commit | 88ea5bdca85fc0954d1dd64309a308199c1af4a8 (patch) | |
| tree | ef9dc778b9c42ab2fecce8810f777ccc133cebef /src/codec/libav | |
| parent | b79f074a86525ece1394af7bc5870516a8c38ba9 (diff) | |
| download | camu-88ea5bdca85fc0954d1dd64309a308199c1af4a8.tar.gz camu-88ea5bdca85fc0954d1dd64309a308199c1af4a8.tar.bz2 camu-88ea5bdca85fc0954d1dd64309a308199c1af4a8.zip | |
wip
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/codec/libav')
| -rw-r--r-- | src/codec/libav/decoder.c | 2 | ||||
| -rw-r--r-- | src/codec/libav/demuxer.c | 4 | ||||
| -rw-r--r-- | src/codec/libav/resampler.c | 53 | ||||
| -rw-r--r-- | src/codec/libav/resampler.h | 6 |
4 files changed, 32 insertions, 33 deletions
diff --git a/src/codec/libav/decoder.c b/src/codec/libav/decoder.c index ebdcb03..3a6ac06 100644 --- a/src/codec/libav/decoder.c +++ b/src/codec/libav/decoder.c @@ -38,11 +38,13 @@ static bool lav_decoder_init(struct camu_decoder *dec, struct camu_renderer *ren goto err; } + /* s32 cpus = av_cpu_count(); cpus = (cpus > 16) ? 4 : cpus / 4; if (cpus == 0) cpus = 1; av->codec_context->thread_count = cpus; al_log_debug("lav_decoder", "Using %i threads for decoder.", cpus); + */ (void)renderer; /* diff --git a/src/codec/libav/demuxer.c b/src/codec/libav/demuxer.c index 18b9020..fb05ec8 100644 --- a/src/codec/libav/demuxer.c +++ b/src/codec/libav/demuxer.c @@ -83,9 +83,7 @@ static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *hand } al_log_info("lav_demux", "Setting stream #%i to a duration of %.3fs.", i, stream->duration * av_q2d(stream->time_base)); } - if (stream->start_time < 0) { - al_log_warn("lav_demux", "Stream has a negative start_time (%ld).", stream->start_time); - } + if (stream->start_time < 0) stream->start_time = 0; s64 duration = av_rescale_q(stream->duration, stream->time_base, AV_TIME_BASE_Q); al_assert(duration >= 0); if ((u64)duration > av->duration) av->duration = (u64)duration; diff --git a/src/codec/libav/resampler.c b/src/codec/libav/resampler.c index ba700f4..229c68c 100644 --- a/src/codec/libav/resampler.c +++ b/src/codec/libav/resampler.c @@ -8,40 +8,38 @@ #include "resampler.h" -static bool in_req_match(struct camu_lav_resample_fmt *fmt) +static bool in_req_matches(struct camu_lav_resample_fmt *fmt) { - return (av_channel_layout_compare(&fmt->in_channel_layout, &fmt->req_channel_layout) == 0) && - (fmt->in_format == fmt->req_format) && (fmt->in_sample_rate == fmt->req_sample_rate); + return (fmt->in_format == fmt->req_format) && + (av_channel_layout_compare(&fmt->in_channel_layout, &fmt->req_channel_layout) == 0) && + (fmt->in_sample_rate == fmt->req_sample_rate); } bool camu_lav_resampler_init(struct camu_lav_resampler *resamp, struct camu_lav_resample_fmt *fmt) { al_memset(resamp, 0, sizeof(struct camu_lav_resampler)); - fmt->resampler_needed = !in_req_match(fmt); + fmt->resampler_needed = !in_req_matches(fmt); + if (!fmt->resampler_needed) return true; camu_lav_resample_fmt_copy(&resamp->fmt, fmt); - if (!fmt->resampler_needed) { - return true; - } - - resamp->resample_context = swr_alloc(); + SwrContext *ctx = NULL; + s32 ret = swr_alloc_set_opts2(&ctx, + &fmt->req_channel_layout, + fmt->req_format, + fmt->req_sample_rate, + &fmt->in_channel_layout, + fmt->in_format, + fmt->in_sample_rate, + 0, + NULL); - SwrContext *ctx = resamp->resample_context; - - if (!ctx) { - al_log_error("lav_resampler", "Failed to create resampler context."); + if (ret != 0) { + al_log_error("lav_resampler", "Failed to configure resampler context."); return false; } - av_opt_set_chlayout(ctx, "in_chlayout", &fmt->in_channel_layout, 0); - av_opt_set_chlayout(ctx, "out_chlayout", &fmt->req_channel_layout, 0); - av_opt_set_int(ctx, "in_sample_rate", fmt->in_sample_rate, 0); - av_opt_set_int(ctx, "out_sample_rate", fmt->req_sample_rate, 0); - av_opt_set_sample_fmt(ctx, "in_sample_fmt", fmt->in_format, 0); - 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); @@ -51,13 +49,16 @@ bool camu_lav_resampler_init(struct camu_lav_resampler *resamp, struct camu_lav_ return false; } + resamp->resample_context = ctx; + return true; } s32 camu_lav_resampler_sample_count(struct camu_lav_resampler *resamp, s32 in_samples) { - al_assert(resamp->fmt.resampler_needed); return swr_get_out_samples(resamp->resample_context, in_samples); + //return av_rescale_rnd(swr_get_delay(resamp->resample_context, resamp->fmt.req_sample_rate) + + // in_samples, resamp->fmt.in_sample_rate, resamp->fmt.req_sample_rate, AV_ROUND_UP); } static inline void free_sample_data(struct camu_lav_resampler *resamp) @@ -70,15 +71,14 @@ static inline void alloc_sample_data(struct camu_lav_resampler *resamp, s32 samp if (resamp->sample_count >= sample_count) return; free_sample_data(resamp); s32 nb_channels = resamp->fmt.req_channel_layout.nb_channels; - av_samples_alloc(resamp->data, NULL, nb_channels, sample_count, resamp->fmt.req_format, 0); + av_samples_alloc(resamp->data, NULL, nb_channels, sample_count, resamp->fmt.req_format, 32); resamp->sample_count = sample_count; } s32 camu_lav_resampler_convert(struct camu_lav_resampler *resamp, const u8 **in_data, s32 in_samples) { - al_assert(resamp->fmt.resampler_needed); - s32 max_resample_count = in_samples ? - camu_lav_resampler_sample_count(resamp, in_samples) : resamp->sample_count; + al_assert(in_samples > 0); + s32 max_resample_count = camu_lav_resampler_sample_count(resamp, in_samples); alloc_sample_data(resamp, max_resample_count); s32 resample_count = swr_convert(resamp->resample_context, resamp->data, max_resample_count, in_data, in_samples); @@ -95,7 +95,6 @@ u8 **camu_lav_resampler_get_data(struct camu_lav_resampler *resamp) void camu_lav_resampler_close(struct camu_lav_resampler *resamp) { - al_assert(resamp->fmt.resampler_needed); if (resamp->resample_context) { swr_close(resamp->resample_context); swr_free(&resamp->resample_context); @@ -105,13 +104,13 @@ void camu_lav_resampler_close(struct camu_lav_resampler *resamp) void camu_lav_resample_fmt_copy(struct camu_lav_resample_fmt *dest, struct camu_lav_resample_fmt *src) { + dest->resampler_needed = src->resampler_needed; dest->in_format = src->in_format; av_channel_layout_copy(&dest->in_channel_layout, &src->in_channel_layout); dest->in_sample_rate = src->in_sample_rate; dest->req_format = src->req_format; av_channel_layout_copy(&dest->req_channel_layout, &src->req_channel_layout); dest->req_sample_rate = src->req_sample_rate; - dest->resampler_needed = src->resampler_needed; } size_t camu_lav_resample_fmt_bytes_per_sample(struct camu_lav_resample_fmt *fmt) diff --git a/src/codec/libav/resampler.h b/src/codec/libav/resampler.h index 703d9a7..92525b2 100644 --- a/src/codec/libav/resampler.h +++ b/src/codec/libav/resampler.h @@ -5,15 +5,15 @@ #include <al/types.h> struct camu_lav_resample_fmt { + bool resampler_needed; + enum AVSampleFormat in_format; + enum AVSampleFormat req_format; s32 in_channel_count; s32 req_channel_count; AVChannelLayout in_channel_layout; AVChannelLayout req_channel_layout; s32 in_sample_rate; s32 req_sample_rate; - enum AVSampleFormat in_format; - enum AVSampleFormat req_format; - bool resampler_needed; }; struct camu_lav_resampler { |