diff options
| author | 2024-04-09 11:24:01 -0400 | |
|---|---|---|
| committer | 2024-04-09 11:24:01 -0400 | |
| commit | 02f3d3565602146bbbfce85b2719246f24036cb9 (patch) | |
| tree | c6588ffe297b777e36260effa4fa42b958ca6ba3 /src/codec | |
| parent | bbf3314165182e402ff25acccddc004a87f81ef0 (diff) | |
| download | camu-02f3d3565602146bbbfce85b2719246f24036cb9.tar.gz camu-02f3d3565602146bbbfce85b2719246f24036cb9.tar.bz2 camu-02f3d3565602146bbbfce85b2719246f24036cb9.zip | |
Massive restructure and many changes
- The server-side list concept is still a wip
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/codec')
| -rw-r--r-- | src/codec/codec.h | 22 | ||||
| -rw-r--r-- | src/codec/common.h | 4 | ||||
| -rw-r--r-- | src/codec/ffmpeg/avio.c (renamed from src/codec/libav/avio.c) | 2 | ||||
| -rw-r--r-- | src/codec/ffmpeg/avio.h (renamed from src/codec/libav/avio.h) | 4 | ||||
| -rw-r--r-- | src/codec/ffmpeg/common.c | 6 | ||||
| -rw-r--r-- | src/codec/ffmpeg/common.h | 6 | ||||
| -rw-r--r-- | src/codec/ffmpeg/decoder.c (renamed from src/codec/libav/decoder.c) | 67 | ||||
| -rw-r--r-- | src/codec/ffmpeg/decoder.h (renamed from src/codec/libav/decoder.h) | 4 | ||||
| -rw-r--r-- | src/codec/ffmpeg/demuxer.c (renamed from src/codec/libav/demuxer.c) | 73 | ||||
| -rw-r--r-- | src/codec/ffmpeg/demuxer.h (renamed from src/codec/libav/demuxer.h) | 5 | ||||
| -rw-r--r-- | src/codec/ffmpeg/encoder.c (renamed from src/codec/libav/encoder.c) | 32 | ||||
| -rw-r--r-- | src/codec/ffmpeg/encoder.h | 26 | ||||
| -rw-r--r-- | src/codec/ffmpeg/packet_ext.c (renamed from src/codec/libav/packet_ext.c) | 0 | ||||
| -rw-r--r-- | src/codec/ffmpeg/packet_ext.h (renamed from src/codec/libav/packet_ext.h) | 0 | ||||
| -rw-r--r-- | src/codec/ffmpeg/resampler.c (renamed from src/codec/libav/resampler.c) | 55 | ||||
| -rw-r--r-- | src/codec/ffmpeg/resampler.h | 40 | ||||
| -rw-r--r-- | src/codec/ffmpeg/scaler.c (renamed from src/codec/libav/scaler.c) | 18 | ||||
| -rw-r--r-- | src/codec/ffmpeg/scaler.h | 24 | ||||
| -rw-r--r-- | src/codec/libav/common.c | 6 | ||||
| -rw-r--r-- | src/codec/libav/common.h | 6 | ||||
| -rw-r--r-- | src/codec/libav/encoder.h | 26 | ||||
| -rw-r--r-- | src/codec/libav/resampler.h | 40 | ||||
| -rw-r--r-- | src/codec/libav/scaler.h | 24 | ||||
| -rw-r--r-- | src/codec/meson.build | 86 |
24 files changed, 298 insertions, 278 deletions
diff --git a/src/codec/codec.h b/src/codec/codec.h index f9ba660..fd847b8 100644 --- a/src/codec/codec.h +++ b/src/codec/codec.h @@ -6,12 +6,12 @@ #include "../cache/handle.h" -#ifdef HAVE_FFMPEG +#ifdef CAMU_HAVE_FFMPEG #include <libavutil/pixdesc.h> #include <libavformat/avformat.h> #endif -#ifdef HAVE_FFMPEG +#ifdef CAMU_HAVE_FFMPEG enum { CAMU_OK = 0, CAMU_ERR_EOF = AVERROR_EOF, @@ -42,7 +42,7 @@ enum { enum { CAMU_NORMAL = 0, -#ifdef HAVE_FFMPEG +#ifdef CAMU_HAVE_FFMPEG CAMU_FFMPEG_COMPAT #endif }; @@ -62,7 +62,7 @@ struct camu_stream { struct camu_icc_profile icc; } video; //struct { } audio; -#ifdef HAVE_FFMPEG +#ifdef CAMU_HAVE_FFMPEG struct { AVStream *stream; AVFormatContext *format_context; @@ -73,7 +73,7 @@ struct camu_stream { struct camu_packet { u8 type; struct aki_buffer *buffer; -#ifdef HAVE_FFMPEG +#ifdef CAMU_HAVE_FFMPEG struct { AVPacket *pkt; } av; #endif }; @@ -86,7 +86,7 @@ struct camu_frame { s32 width; s32 height; f64 pts; -#ifdef HAVE_FFMPEG +#ifdef CAMU_HAVE_FFMPEG struct { AVFrame *frame; } av; #endif void *opaque; @@ -113,3 +113,13 @@ struct camu_decoder { void (*free)(struct camu_decoder **); struct camu_stream *stream; }; + +static inline void camu_frame_discard(struct camu_frame *frame) +{ +#ifdef CAMU_HAVE_FFMPEG + if (frame->type == CAMU_FFMPEG_COMPAT) { + av_frame_free(&frame->av.frame); + } +#endif + al_free(frame); +} diff --git a/src/codec/common.h b/src/codec/common.h index f3db182..adf503d 100644 --- a/src/codec/common.h +++ b/src/codec/common.h @@ -4,7 +4,7 @@ static inline void *camu_page_alloc(size_t size) { -#ifdef HAVE_POSIX_MEMALIGN +#ifdef AL_HAVE_POSIX_MEMALIGN void *ptr = NULL; al_posix_memalign(&ptr, al_page_size, size); return ptr; @@ -15,7 +15,7 @@ static inline void *camu_page_alloc(size_t size) static inline void *camu_page_realloc(void *ptr, size_t old_size, size_t size) { -#ifdef HAVE_POSIX_MEMALIGN +#ifdef AL_HAVE_POSIX_MEMALIGN void *old_ptr = ptr; al_posix_memalign(&ptr, al_page_size, size); if (old_ptr) { diff --git a/src/codec/libav/avio.c b/src/codec/ffmpeg/avio.c index 97f66da..12dd468 100644 --- a/src/codec/libav/avio.c +++ b/src/codec/ffmpeg/avio.c @@ -1,5 +1,7 @@ #include "avio.h" +#include "../cache/handle.h" + s32 camu_avio_read(void *data, u8 *buf, s32 buf_size) { struct cch_handle *handle = (struct cch_handle *)data; diff --git a/src/codec/libav/avio.h b/src/codec/ffmpeg/avio.h index 09df4ec..b57cbcf 100644 --- a/src/codec/libav/avio.h +++ b/src/codec/ffmpeg/avio.h @@ -1,10 +1,8 @@ #pragma once +#include <al/types.h> #include <libavutil/error.h> #include <libavformat/avio.h> -#include "../../codec/codec.h" -#include "../../cache/handle.h" - s32 camu_avio_read(void *data, u8 *buf, s32 buf_size); s64 camu_avio_seek(void *data, s64 offset, s32 whence); diff --git a/src/codec/ffmpeg/common.c b/src/codec/ffmpeg/common.c new file mode 100644 index 0000000..57caff7 --- /dev/null +++ b/src/codec/ffmpeg/common.c @@ -0,0 +1,6 @@ +#include "common.h" + +void camu_ff_set_log_callback(void (*callback)(void *, int, const char *, va_list)) +{ + av_log_set_callback(callback); +} diff --git a/src/codec/ffmpeg/common.h b/src/codec/ffmpeg/common.h new file mode 100644 index 0000000..ded7b35 --- /dev/null +++ b/src/codec/ffmpeg/common.h @@ -0,0 +1,6 @@ +#pragma once + +#include <al/types.h> +#include <libavutil/log.h> + +void camu_ff_set_log_callback(void (*callback)(void *, int, const char *, va_list)); diff --git a/src/codec/libav/decoder.c b/src/codec/ffmpeg/decoder.c index e732be9..e5236b5 100644 --- a/src/codec/libav/decoder.c +++ b/src/codec/ffmpeg/decoder.c @@ -6,35 +6,32 @@ #include "decoder.h" -static void close_internal(struct camu_lav_decoder *av) +static void close_internal(struct camu_ff_decoder *av) { - if (av->codec_context) { - avcodec_close(av->codec_context); - avcodec_free_context(&av->codec_context); - } + if (av->codec_context) avcodec_free_context(&av->codec_context); } -static bool lav_decoder_init(struct camu_decoder *dec, struct camu_renderer *renderer, struct camu_stream *stream) +static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *renderer, struct camu_stream *stream) { - struct camu_lav_decoder *av = (struct camu_lav_decoder *)dec; + struct camu_ff_decoder *av = (struct camu_ff_decoder *)dec; AVCodecParameters *codecpar = stream->av.stream->codecpar; const AVCodec *codec = avcodec_find_decoder(codecpar->codec_id); if (!codec) { - al_log_error("lav_decoder", "Failed to find decoder."); + al_log_error("ff_decoder", "Failed to find decoder."); goto err; } av->codec_context = avcodec_alloc_context3(codec); if (!av->codec_context) { - al_log_error("lav_decoder", "Failed to alloc codec context."); + al_log_error("ff_decoder", "Failed to alloc codec context."); goto err; } if (avcodec_parameters_to_context(av->codec_context, codecpar) < 0) { - al_log_error("lav_decoder", "Failed to copy codec parameters."); + al_log_error("ff_decoder", "Failed to copy codec parameters."); goto err; } @@ -43,7 +40,7 @@ static bool lav_decoder_init(struct camu_decoder *dec, struct camu_renderer *ren 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); + al_log_debug("ff_decoder", "Using %i threads for decoder.", cpus); */ (void)renderer; @@ -55,11 +52,11 @@ static bool lav_decoder_init(struct camu_decoder *dec, struct camu_renderer *ren */ if (avcodec_open2(av->codec_context, codec, NULL) < 0) { - al_log_error("lav_decoder", "Failed to open codec (%s).", codec->name); + al_log_error("ff_decoder", "Failed to open codec (%s).", codec->name); goto err; } - al_log_info("lav_decoder", "Codec: %s (%s) %ldkbps.", codec->name, codec->long_name, codecpar->bit_rate / 1000); + al_log_info("ff_decoder", "Codec: %s (%s) %ldkbps.", codec->name, codec->long_name, codecpar->bit_rate / 1000); av->time_base = stream->av.stream->time_base; av->last_pts = 0; @@ -72,14 +69,14 @@ err: return false; } -static void lav_decoder_set_callback(struct camu_decoder *dec, void (*callback)(void *, struct camu_frame *), void *userdata) +static void ff_decoder_set_callback(struct camu_decoder *dec, void (*callback)(void *, struct camu_frame *), void *userdata) { - struct camu_lav_decoder *av = (struct camu_lav_decoder *)dec; + struct camu_ff_decoder *av = (struct camu_ff_decoder *)dec; av->callback = callback; av->userdata = userdata; } -static s32 send_packet(struct camu_lav_decoder *av, AVPacket *pkt) +static s32 send_packet(struct camu_ff_decoder *av, AVPacket *pkt) { /* if (pkt && av->seek_pos >= 0 && pkt->pts + pkt->duration < av->seek_pos) { @@ -91,25 +88,25 @@ static s32 send_packet(struct camu_lav_decoder *av, AVPacket *pkt) s32 ret = avcodec_send_packet(av->codec_context, pkt); if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - al_log_error("lav_decoder", "Error sending packet to decoder: (%s).", av_err2str(ret)); + al_log_error("ff_decoder", "Error sending packet to decoder: (%s).", av_err2str(ret)); } return ret; } -static s32 lav_decoder_push(struct camu_decoder *dec, struct camu_packet *packet) +static s32 ff_decoder_push(struct camu_decoder *dec, struct camu_packet *packet) { - struct camu_lav_decoder *av = (struct camu_lav_decoder *)dec; + struct camu_ff_decoder *av = (struct camu_ff_decoder *)dec; return send_packet(av, (packet) ? packet->av.pkt : NULL); } -static void lav_decoder_flush(struct camu_decoder *dec) +static void ff_decoder_flush(struct camu_decoder *dec) { - struct camu_lav_decoder *av = (struct camu_lav_decoder *)dec; + struct camu_ff_decoder *av = (struct camu_ff_decoder *)dec; avcodec_flush_buffers(av->codec_context); } -static s32 receive_frames(struct camu_lav_decoder *av) +static s32 receive_frames(struct camu_ff_decoder *av) { s32 ret; do { @@ -121,7 +118,7 @@ static s32 receive_frames(struct camu_lav_decoder *av) av_frame_free(&frame->av.frame); al_free(frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break; - al_log_error("lav_decoder", "Error receiving packet from decoder: (%s).", av_err2str(ret)); + al_log_error("ff_decoder", "Error receiving packet from decoder: (%s).", av_err2str(ret)); continue; } // Track pts and duration of the previous frame so we can handle multiple frames @@ -139,28 +136,28 @@ static s32 receive_frames(struct camu_lav_decoder *av) return ret; } -static s32 lav_decoder_process(struct camu_decoder *dec) +static s32 ff_decoder_process(struct camu_decoder *dec) { - struct camu_lav_decoder *av = (struct camu_lav_decoder *)dec; + struct camu_ff_decoder *av = (struct camu_ff_decoder *)dec; return receive_frames(av); } -static void lav_decoder_free(struct camu_decoder **dec) +static void ff_decoder_free(struct camu_decoder **dec) { - struct camu_lav_decoder *av = (struct camu_lav_decoder *)*dec; + struct camu_ff_decoder *av = (struct camu_ff_decoder *)*dec; close_internal(av); al_free(av); *dec = NULL; } -struct camu_decoder *camu_lav_decoder_create(void) +struct camu_decoder *camu_ff_decoder_create(void) { - struct camu_lav_decoder *av = al_alloc_object(struct camu_lav_decoder); - av->dec.init = lav_decoder_init; - av->dec.set_callback = lav_decoder_set_callback; - av->dec.push = lav_decoder_push; - av->dec.process = lav_decoder_process; - av->dec.flush = lav_decoder_flush; - av->dec.free = lav_decoder_free; + struct camu_ff_decoder *av = al_alloc_object(struct camu_ff_decoder); + av->dec.init = ff_decoder_init; + av->dec.set_callback = ff_decoder_set_callback; + av->dec.push = ff_decoder_push; + av->dec.process = ff_decoder_process; + av->dec.flush = ff_decoder_flush; + av->dec.free = ff_decoder_free; return (struct camu_decoder *)av; } diff --git a/src/codec/libav/decoder.h b/src/codec/ffmpeg/decoder.h index 44105ce..45cca00 100644 --- a/src/codec/libav/decoder.h +++ b/src/codec/ffmpeg/decoder.h @@ -6,7 +6,7 @@ #include "../codec.h" -struct camu_lav_decoder { +struct camu_ff_decoder { struct camu_decoder dec; AVCodecContext *codec_context; AVRational time_base; @@ -17,4 +17,4 @@ struct camu_lav_decoder { void *userdata; }; -struct camu_decoder *camu_lav_decoder_create(void); +struct camu_decoder *camu_ff_decoder_create(void); diff --git a/src/codec/libav/demuxer.c b/src/codec/ffmpeg/demuxer.c index 2169816..9b26596 100644 --- a/src/codec/libav/demuxer.c +++ b/src/codec/ffmpeg/demuxer.c @@ -5,7 +5,7 @@ #define BUF_SIZE 16384 -static void close_internal(struct camu_lav_demuxer *av) +static void close_internal(struct camu_ff_demuxer *av) { if (av->io_context) { av_free(av->io_context->buffer); @@ -18,20 +18,20 @@ static void close_internal(struct camu_lav_demuxer *av) } } -static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handle) +static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handle) { - struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)demux; + struct camu_ff_demuxer *av = (struct camu_ff_demuxer *)demux; av->format_context = avformat_alloc_context(); if (!av->format_context) { - al_log_error("lav_demuxer", "Failed to create format context."); + al_log_error("ff_demuxer", "Failed to create format context."); goto err; } u8 *buf = (u8 *)av_malloc(BUF_SIZE); av->io_context = avio_alloc_context(buf, BUF_SIZE, 0, handle, camu_avio_read, NULL, camu_avio_seek); if (!av->io_context) { - al_log_error("lav_demuxer", "Failed to create custom io context."); + al_log_error("ff_demuxer", "Failed to create custom io context."); goto err; } @@ -48,17 +48,17 @@ static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *hand av->format_context->flags |= AVFMT_FLAG_CUSTOM_IO; if (avformat_open_input(&av->format_context, "", 0, 0) < 0) { - al_log_error("lav_demuxer", "Failed to open input."); + al_log_error("ff_demuxer", "Failed to open input."); goto err; } if (avformat_find_stream_info(av->format_context, 0) < 0) { - al_log_error("lav_demux", "Failed to find stream info."); + al_log_error("ff_demuxer", "Failed to find stream info."); goto err; } if (!av->format_context->nb_streams) { - al_log_error("lav_demux", "No streams found."); + al_log_error("ff_demuxer", "No streams found."); goto err; } @@ -72,16 +72,16 @@ static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *hand enum AVMediaType type = stream->codecpar->codec_type; // Try to detect attached images. if (type == AVMEDIA_TYPE_VIDEO && GUESS_STREAM_IS_IMAGE(stream)) { - al_log_info("lav_demux", "Guessing that stream #%u is an image.", i); + al_log_info("ff_demuxer", "Guessing that stream #%u is an image.", i); stream->duration = 0; } else if (stream->duration < 0) { - al_log_warn("lav_demux", "Stream #%u has an invalid duration (%ld).", i, stream->duration); + al_log_warn("ff_demuxer", "Stream #%u has an invalid duration (%ld).", i, stream->duration); if (av->format_context->duration < 0) { stream->duration = 0; } else { stream->duration = av_rescale_q(av->format_context->duration, AV_TIME_BASE_Q, stream->time_base); } - al_log_info("lav_demux", "Setting stream #%u to a duration of %.3fs.", i, stream->duration * av_q2d(stream->time_base)); + al_log_info("ff_demuxer", "Setting stream #%u to a duration of %.3fs.", i, stream->duration * av_q2d(stream->time_base)); } if (stream->start_time < 0) stream->start_time = 0; s64 duration = av_rescale_q(stream->duration, stream->time_base, AV_TIME_BASE_Q); @@ -97,6 +97,7 @@ static bool lav_demuxer_init(struct camu_demuxer *demux, struct cch_handle *hand //av_dump_format(av->format_context, 0, "", 0); + av->seeked = false; av->eof = false; return true; @@ -105,6 +106,17 @@ err: return false; } +/* +static AVStream *av_stream_at_index(struct camu_ff_demuxer *av, s32 index) +{ + struct camu_stream *stream; + al_array_foreach_ptr(av->demux.streams, i, stream) { + if (stream->av.stream->index == index) return stream->av.stream; + } + return NULL; +} +*/ + static bool subscribed_to_index(struct camu_demuxer *demux, s32 index) { s32 subscribed; @@ -114,9 +126,9 @@ static bool subscribed_to_index(struct camu_demuxer *demux, s32 index) return false; } -static s32 lav_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet *packet) +static s32 ff_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet *packet) { - struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)demux; + struct camu_ff_demuxer *av = (struct camu_ff_demuxer *)demux; packet->type = CAMU_FFMPEG_COMPAT; s32 ret = 0; do { @@ -126,7 +138,7 @@ static s32 lav_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet break; } if (ret < 0) { - al_log_error("lav_demuxer", "Failed to read frame (%s).", av_err2str(ret)); + al_log_error("ff_demuxer", "Failed to read frame (%s).", av_err2str(ret)); continue; } if (!subscribed_to_index(demux, packet->av.pkt->stream_index)) { @@ -138,46 +150,47 @@ static s32 lav_demuxer_get_packet(struct camu_demuxer *demux, struct camu_packet return ret; } -static u64 lav_demuxer_get_duration(struct camu_demuxer *demux) +static u64 ff_demuxer_get_duration(struct camu_demuxer *demux) { - struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)demux; + struct camu_ff_demuxer *av = (struct camu_ff_demuxer *)demux; return av->duration; } -static bool lav_demuxer_seek(struct camu_demuxer *demux, u64 pos) +static bool ff_demuxer_seek(struct camu_demuxer *demux, u64 pos) { - struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)demux; + struct camu_ff_demuxer *av = (struct camu_ff_demuxer *)demux; 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; } - if (avformat_seek_file(av->format_context, -1, INT64_MIN, ts, ts, AVSEEK_FLAG_BACKWARD) >= 0) { - return true; + if (avformat_seek_file(av->format_context, -1, INT64_MIN, ts, ts, AVSEEK_FLAG_BACKWARD) < 0) { + return false; } - return false; + av->seeked = true; + return true; } -static void lav_demuxer_free(struct camu_demuxer **demux) +static void ff_demuxer_free(struct camu_demuxer **demux) { - struct camu_lav_demuxer *av = (struct camu_lav_demuxer *)*demux; + struct camu_ff_demuxer *av = (struct camu_ff_demuxer *)*demux; close_internal(av); al_array_free(av->demux.streams); al_free(av); *demux = NULL; } -struct camu_demuxer *camu_lav_demuxer_create(void) +struct camu_demuxer *camu_ff_demuxer_create(void) { - struct camu_lav_demuxer *av = al_alloc_object(struct camu_lav_demuxer); + struct camu_ff_demuxer *av = al_alloc_object(struct camu_ff_demuxer); av->demux.type = CAMU_FFMPEG_COMPAT; al_array_init(av->demux.streams); al_array_init(av->demux.subscribed); - av->demux.init = lav_demuxer_init; - av->demux.get_packet = lav_demuxer_get_packet; - av->demux.get_duration = lav_demuxer_get_duration; - av->demux.seek = lav_demuxer_seek; - av->demux.free = lav_demuxer_free; + av->demux.init = ff_demuxer_init; + av->demux.get_packet = ff_demuxer_get_packet; + av->demux.get_duration = ff_demuxer_get_duration; + av->demux.seek = ff_demuxer_seek; + av->demux.free = ff_demuxer_free; return (struct camu_demuxer *)av; } diff --git a/src/codec/libav/demuxer.h b/src/codec/ffmpeg/demuxer.h index 9b2d093..8327534 100644 --- a/src/codec/libav/demuxer.h +++ b/src/codec/ffmpeg/demuxer.h @@ -8,12 +8,13 @@ #include "../codec.h" -struct camu_lav_demuxer { +struct camu_ff_demuxer { struct camu_demuxer demux; AVIOContext *io_context; AVFormatContext *format_context; u64 duration; + bool seeked; bool eof; }; -struct camu_demuxer *camu_lav_demuxer_create(void); +struct camu_demuxer *camu_ff_demuxer_create(void); diff --git a/src/codec/libav/encoder.c b/src/codec/ffmpeg/encoder.c index 4f3fa80..9ceaa99 100644 --- a/src/codec/libav/encoder.c +++ b/src/codec/ffmpeg/encoder.c @@ -15,21 +15,21 @@ #define FRAME_SIZE 20 #define CHANNELS 2 -bool camu_lav_encoder_init(struct camu_lav_encoder *enc, char *encoder_name, char *ext) +bool camu_ff_encoder_init(struct camu_ff_encoder *enc, char *encoder_name, char *ext) { - al_memset(enc, 0, sizeof(struct camu_lav_encoder)); + al_memset(enc, 0, sizeof(struct camu_ff_encoder)); const AVCodec *codec = avcodec_find_encoder_by_name(encoder_name); if (!codec) { - al_log_error("lav_encoder", "Failed to find codec with name: %s.", encoder_name); + al_log_error("ff_encoder", "Failed to find codec with name: %s.", encoder_name); goto err; } enc->codec_context = avcodec_alloc_context3(codec); if (!enc->codec_context) { - al_log_error("lav_encoder", "Failed to alloc codec context."); + al_log_error("ff_encoder", "Failed to alloc codec context."); goto err; } @@ -54,7 +54,7 @@ bool camu_lav_encoder_init(struct camu_lav_encoder *enc, char *encoder_name, cha av_dict_set(&opts, "application", "audio", 0); if (avcodec_open2(enc->codec_context, codec, &opts) < 0) { - al_log_error("lav_encoder", "Failed to open codec."); + al_log_error("ff_encoder", "Failed to open codec."); av_dict_free(&opts); goto err; } @@ -71,7 +71,7 @@ bool camu_lav_encoder_init(struct camu_lav_encoder *enc, char *encoder_name, cha enc->fmt.req_channel_layout.nb_channels, 1); if (!enc->audio_fifo) { - al_log_error("lav_encoder", "Failed to alloc fifo."); + al_log_error("ff_encoder", "Failed to alloc fifo."); goto err; } @@ -84,11 +84,11 @@ bool camu_lav_encoder_init(struct camu_lav_encoder *enc, char *encoder_name, cha return true; err: - camu_lav_encoder_close(enc); + camu_ff_encoder_close(enc); return false; } -void camu_lav_encoder_push(struct camu_lav_encoder *enc, u8 **data, s32 sample_count) +void camu_ff_encoder_push(struct camu_ff_encoder *enc, u8 **data, s32 sample_count) { s32 alloc_size = av_audio_fifo_size(enc->audio_fifo) + sample_count; if (av_audio_fifo_space(enc->audio_fifo) < alloc_size) { @@ -99,12 +99,12 @@ void camu_lav_encoder_push(struct camu_lav_encoder *enc, u8 **data, s32 sample_c av_audio_fifo_write(enc->audio_fifo, (void **)data, sample_count); } -static void free_frame_data(struct camu_lav_encoder *enc) +static void free_frame_data(struct camu_ff_encoder *enc) { if (enc->frame && enc->frame->nb_samples > 0) av_freep(&enc->frame->data[0]); } -static void alloc_frame_data(struct camu_lav_encoder *enc, s32 frame_size) +static void alloc_frame_data(struct camu_ff_encoder *enc, s32 frame_size) { if (enc->frame->nb_samples >= frame_size) return; free_frame_data(enc); @@ -113,7 +113,7 @@ static void alloc_frame_data(struct camu_lav_encoder *enc, s32 frame_size) enc->frame->nb_samples = frame_size; } -static bool receive_packets(struct camu_lav_encoder *enc) +static bool receive_packets(struct camu_ff_encoder *enc) { s32 ret; AVPacket pkt = { 0 }; @@ -125,23 +125,23 @@ static bool receive_packets(struct camu_lav_encoder *enc) } while (1); if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - al_log_error("lav_encoder", "Error receiving packet from encoder: (%s).", av_err2str(ret)); + al_log_error("ff_encoder", "Error receiving packet from encoder: (%s).", av_err2str(ret)); return false; } return true; } -static s32 send_frame(struct camu_lav_encoder *enc, AVFrame *in_frame) +static s32 send_frame(struct camu_ff_encoder *enc, AVFrame *in_frame) { s32 ret = avcodec_send_frame(enc->codec_context, in_frame); if (ret < 0 && ret != AVERROR_EOF) { - al_log_error("lav_encoder", "Error sending frame to encoder: (%s).", av_err2str(ret)); + al_log_error("ff_encoder", "Error sending frame to encoder: (%s).", av_err2str(ret)); } return ret; } -bool camu_lav_encoder_process(struct camu_lav_encoder *enc, bool flush) +bool camu_ff_encoder_process(struct camu_ff_encoder *enc, bool flush) { s32 samples_available = av_audio_fifo_size(enc->audio_fifo); @@ -177,7 +177,7 @@ bool camu_lav_encoder_process(struct camu_lav_encoder *enc, bool flush) return ret == 0; } -void camu_lav_encoder_close(struct camu_lav_encoder *enc) +void camu_ff_encoder_close(struct camu_ff_encoder *enc) { if (enc->codec_context) avcodec_free_context(&enc->codec_context); if (enc->audio_fifo) av_audio_fifo_free(enc->audio_fifo); diff --git a/src/codec/ffmpeg/encoder.h b/src/codec/ffmpeg/encoder.h new file mode 100644 index 0000000..6cba9ac --- /dev/null +++ b/src/codec/ffmpeg/encoder.h @@ -0,0 +1,26 @@ +#pragma once + +#include <libavcodec/avcodec.h> +#include <libavformat/avformat.h> +#include <libavutil/audio_fifo.h> +#include <libavutil/rational.h> + +#include "resampler.h" + +struct camu_ff_encoder { + AVCodecContext *codec_context; + const AVOutputFormat *output_format; + + struct camu_ff_resample_fmt fmt; + + AVFrame *frame; + AVAudioFifo *audio_fifo; + + void (*callback)(void *, AVPacket *); + void *userdata; +}; + +bool camu_ff_encoder_init(struct camu_ff_encoder *enc, char *encoder_name, char *ext); +void camu_ff_encoder_push(struct camu_ff_encoder *enc, u8 **data, s32 sample_count); +bool camu_ff_encoder_process(struct camu_ff_encoder *enc, bool flush); +void camu_ff_encoder_close(struct camu_ff_encoder *enc); diff --git a/src/codec/libav/packet_ext.c b/src/codec/ffmpeg/packet_ext.c index 8fe4c39..8fe4c39 100644 --- a/src/codec/libav/packet_ext.c +++ b/src/codec/ffmpeg/packet_ext.c diff --git a/src/codec/libav/packet_ext.h b/src/codec/ffmpeg/packet_ext.h index ff6e337..ff6e337 100644 --- a/src/codec/libav/packet_ext.h +++ b/src/codec/ffmpeg/packet_ext.h diff --git a/src/codec/libav/resampler.c b/src/codec/ffmpeg/resampler.c index 229c68c..d4b281a 100644 --- a/src/codec/libav/resampler.c +++ b/src/codec/ffmpeg/resampler.c @@ -8,21 +8,21 @@ #include "resampler.h" -static bool in_req_matches(struct camu_lav_resample_fmt *fmt) +static bool in_req_matches(struct camu_ff_resample_fmt *fmt) { 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) +bool camu_ff_resampler_init(struct camu_ff_resampler *resamp, struct camu_ff_resample_fmt *fmt) { - al_memset(resamp, 0, sizeof(struct camu_lav_resampler)); + al_memset(resamp, 0, sizeof(struct camu_ff_resampler)); fmt->resampler_needed = !in_req_matches(fmt); if (!fmt->resampler_needed) return true; - camu_lav_resample_fmt_copy(&resamp->fmt, fmt); + camu_ff_resample_fmt_copy(&resamp->fmt, fmt); SwrContext *ctx = NULL; s32 ret = swr_alloc_set_opts2(&ctx, @@ -54,19 +54,19 @@ bool camu_lav_resampler_init(struct camu_lav_resampler *resamp, struct camu_lav_ return true; } -s32 camu_lav_resampler_sample_count(struct camu_lav_resampler *resamp, s32 in_samples) +s32 camu_ff_resampler_sample_count(struct camu_ff_resampler *resamp, s32 in_samples) { 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) +static inline void free_sample_data(struct camu_ff_resampler *resamp) { if (resamp->data[0]) av_freep(&resamp->data[0]); } -static inline void alloc_sample_data(struct camu_lav_resampler *resamp, s32 sample_count) +static inline void alloc_sample_data(struct camu_ff_resampler *resamp, s32 sample_count) { if (resamp->sample_count >= sample_count) return; free_sample_data(resamp); @@ -75,10 +75,10 @@ static inline void alloc_sample_data(struct camu_lav_resampler *resamp, s32 samp resamp->sample_count = sample_count; } -s32 camu_lav_resampler_convert(struct camu_lav_resampler *resamp, const u8 **in_data, s32 in_samples) +s32 camu_ff_resampler_convert(struct camu_ff_resampler *resamp, const u8 **in_data, s32 in_samples) { al_assert(in_samples > 0); - s32 max_resample_count = camu_lav_resampler_sample_count(resamp, in_samples); + s32 max_resample_count = camu_ff_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); @@ -88,12 +88,12 @@ s32 camu_lav_resampler_convert(struct camu_lav_resampler *resamp, const u8 **in_ return resample_count; } -u8 **camu_lav_resampler_get_data(struct camu_lav_resampler *resamp) +u8 **camu_ff_resampler_get_data(struct camu_ff_resampler *resamp) { return (u8 **)resamp->data; } -void camu_lav_resampler_close(struct camu_lav_resampler *resamp) +void camu_ff_resampler_close(struct camu_ff_resampler *resamp) { if (resamp->resample_context) { swr_close(resamp->resample_context); @@ -102,7 +102,7 @@ void camu_lav_resampler_close(struct camu_lav_resampler *resamp) free_sample_data(resamp); } -void camu_lav_resample_fmt_copy(struct camu_lav_resample_fmt *dest, struct camu_lav_resample_fmt *src) +void camu_ff_resample_fmt_copy(struct camu_ff_resample_fmt *dest, struct camu_ff_resample_fmt *src) { dest->resampler_needed = src->resampler_needed; dest->in_format = src->in_format; @@ -113,50 +113,49 @@ void camu_lav_resample_fmt_copy(struct camu_lav_resample_fmt *dest, struct camu_ dest->req_sample_rate = src->req_sample_rate; } -size_t camu_lav_resample_fmt_bytes_per_sample(struct camu_lav_resample_fmt *fmt) +size_t camu_ff_resample_fmt_bytes_per_sample(struct camu_ff_resample_fmt *fmt) { return (size_t)av_get_bytes_per_sample(fmt->req_format); } -size_t camu_lav_resample_fmt_samples_to_bytes(struct camu_lav_resample_fmt *fmt, size_t samples) +size_t camu_ff_resample_fmt_samples_to_bytes(struct camu_ff_resample_fmt *fmt, size_t samples) { - s32 size, nb_channels = fmt->req_channel_layout.nb_channels; - if (av_samples_get_buffer_size(&size, nb_channels, (s32)samples, fmt->req_format, 1) < 0) { - return 0; - } + s32 size; + s32 ret = av_samples_get_buffer_size(&size, fmt->req_channel_layout.nb_channels, (s32)samples, fmt->req_format, 1); + al_assert(ret >= 0); return (size_t)size; } -size_t camu_lav_resample_fmt_samples_to_usec(struct camu_lav_resample_fmt *fmt, size_t samples) +size_t camu_ff_resample_fmt_samples_to_usec(struct camu_ff_resample_fmt *fmt, size_t samples) { return samples / (fmt->req_sample_rate / 1000000.0); } -f64 camu_lav_resample_fmt_samples_to_sec(struct camu_lav_resample_fmt *fmt, size_t samples) +f64 camu_ff_resample_fmt_samples_to_sec(struct camu_ff_resample_fmt *fmt, size_t samples) { return samples / (f64)fmt->req_sample_rate; } -size_t camu_lav_resample_fmt_usec_to_bytes(struct camu_lav_resample_fmt *fmt, size_t usec) +size_t camu_ff_resample_fmt_usec_to_bytes(struct camu_ff_resample_fmt *fmt, size_t usec) { size_t samples = usec * (fmt->req_sample_rate / 1000000.0); - return samples * (camu_lav_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); + return samples * (camu_ff_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); } -size_t camu_lav_resample_fmt_sec_to_bytes(struct camu_lav_resample_fmt *fmt, f64 sec) +size_t camu_ff_resample_fmt_sec_to_bytes(struct camu_ff_resample_fmt *fmt, f64 sec) { size_t samples = sec * fmt->req_sample_rate; - return samples * (camu_lav_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); + return samples * (camu_ff_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); } -size_t camu_lav_resample_fmt_bytes_to_usec(struct camu_lav_resample_fmt *fmt, size_t bytes) +size_t camu_ff_resample_fmt_bytes_to_usec(struct camu_ff_resample_fmt *fmt, size_t bytes) { - size_t samples = bytes / (camu_lav_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); + size_t samples = bytes / (camu_ff_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); return samples / (fmt->req_sample_rate / 1000000.0); } -f64 camu_lav_resample_fmt_bytes_to_sec(struct camu_lav_resample_fmt *fmt, size_t bytes) +f64 camu_ff_resample_fmt_bytes_to_sec(struct camu_ff_resample_fmt *fmt, size_t bytes) { - size_t samples = bytes / (camu_lav_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); + size_t samples = bytes / (camu_ff_resample_fmt_bytes_per_sample(fmt) * fmt->req_channel_layout.nb_channels); return samples / ((f64)fmt->req_sample_rate); } diff --git a/src/codec/ffmpeg/resampler.h b/src/codec/ffmpeg/resampler.h new file mode 100644 index 0000000..4f7b07d --- /dev/null +++ b/src/codec/ffmpeg/resampler.h @@ -0,0 +1,40 @@ +#pragma once + +#include <libswresample/swresample.h> +#include <libavutil/opt.h> +#include <al/types.h> + +struct camu_ff_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; +}; + +struct camu_ff_resampler { + SwrContext *resample_context; + struct camu_ff_resample_fmt fmt; + u8 *data[AV_NUM_DATA_POINTERS]; + s32 sample_count; +}; + +bool camu_ff_resampler_init(struct camu_ff_resampler *resamp, struct camu_ff_resample_fmt *fmt); +s32 camu_ff_resampler_sample_count(struct camu_ff_resampler *resamp, s32 in_samples); +s32 camu_ff_resampler_convert(struct camu_ff_resampler *resamp, const u8 **in_data, s32 in_samples); +u8 **camu_ff_resampler_get_data(struct camu_ff_resampler *resamp); +void camu_ff_resampler_close(struct camu_ff_resampler *resamp); + +void camu_ff_resample_fmt_copy(struct camu_ff_resample_fmt *dest, struct camu_ff_resample_fmt *src); +size_t camu_ff_resample_fmt_bytes_per_sample(struct camu_ff_resample_fmt *fmt); +size_t camu_ff_resample_fmt_samples_to_bytes(struct camu_ff_resample_fmt *fmt, size_t samples); +size_t camu_ff_resample_fmt_samples_to_usec(struct camu_ff_resample_fmt *fmt, size_t samples); +f64 camu_ff_resample_fmt_samples_to_sec(struct camu_ff_resample_fmt *fmt, size_t samples); +size_t camu_ff_resample_fmt_usec_to_bytes(struct camu_ff_resample_fmt *fmt, size_t usec); +size_t camu_ff_resample_fmt_sec_to_bytes(struct camu_ff_resample_fmt *fmt, f64 sec); +size_t camu_ff_resample_fmt_bytes_to_usec(struct camu_ff_resample_fmt *fmt, size_t bytes); +f64 camu_ff_resample_fmt_bytes_to_sec(struct camu_ff_resample_fmt *fmt, size_t bytes); diff --git a/src/codec/libav/scaler.c b/src/codec/ffmpeg/scaler.c index 882116f..9b5c5e0 100644 --- a/src/codec/libav/scaler.c +++ b/src/codec/ffmpeg/scaler.c @@ -11,7 +11,7 @@ static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, s32 width, s32 height) if (!frame) return NULL; s32 ret = av_image_alloc(frame->data, frame->linesize, width, height, pix_fmt, 32); if (ret < 0) { - al_log_error("lav_scaler", "Failed to allocate picture buffer (%s).", av_err2str(ret)); + al_log_error("ff_scaler", "Failed to allocate picture buffer (%s).", av_err2str(ret)); return NULL; } /* @@ -23,7 +23,7 @@ static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, s32 width, s32 height) } s32 ret = av_image_fill_arrays(frame->data, frame->linesize, buffer, pix_fmt, width, height, 1); if (ret < 0) { - al_log_error("lav_scaler", "Failed to allocate picture buffer (%s).", av_err2str(ret)); + al_log_error("ff_scaler", "Failed to allocate picture buffer (%s).", av_err2str(ret)); av_free(frame); return NULL; } @@ -34,9 +34,9 @@ static AVFrame *alloc_picture(enum AVPixelFormat pix_fmt, s32 width, s32 height) return frame; } -bool camu_lav_scaler_init(struct camu_lav_scaler *scale, struct camu_lav_scale_fmt *fmt) +bool camu_ff_scaler_init(struct camu_ff_scaler *scale, struct camu_ff_scale_fmt *fmt) { - al_memset(scale, 0, sizeof(struct camu_lav_scaler)); + al_memset(scale, 0, sizeof(struct camu_ff_scaler)); if (fmt->in_width == fmt->req_width && fmt->in_height == fmt->req_height && fmt->in_format == fmt->req_format) { @@ -48,13 +48,13 @@ bool camu_lav_scaler_init(struct camu_lav_scaler *scale, struct camu_lav_scale_f scale->scaler_context = sws_getContext(fmt->in_width, fmt->in_height, fmt->in_format, fmt->req_width, fmt->req_height, fmt->req_format, flags, NULL, NULL, NULL); if (!scale->scaler_context) { - al_log_error("lav_scaler", "Failed to create scaler context."); + al_log_error("ff_scaler", "Failed to create scaler context."); return false; } scale->frame = alloc_picture(fmt->req_format, fmt->req_width, fmt->req_height); if (!scale->frame) { - al_log_error("lav_scaler", "Failed to allocate frame."); + al_log_error("ff_scaler", "Failed to allocate frame."); return false; } @@ -65,18 +65,18 @@ bool camu_lav_scaler_init(struct camu_lav_scaler *scale, struct camu_lav_scale_f return true; } -bool camu_lav_scaler_scale(struct camu_lav_scaler *scale, const u8 **in_slice, s32 *in_strides) +bool camu_ff_scaler_scale(struct camu_ff_scaler *scale, const u8 **in_slice, s32 *in_strides) { s32 ret = sws_scale(scale->scaler_context, in_slice, in_strides, 0, scale->fmt.in_height, scale->frame->data, scale->frame->linesize); if (ret != scale->fmt.req_height) { - al_log_error("lav_scaler", "Failed to scale frame (%s).", av_err2str(ret)); + al_log_error("ff_scaler", "Failed to scale frame (%s).", av_err2str(ret)); return false; } return true; } -void camu_lav_scaler_close(struct camu_lav_scaler *scale) +void camu_ff_scaler_close(struct camu_ff_scaler *scale) { av_freep(&scale->frame->data[0]); av_frame_free(&scale->frame); diff --git a/src/codec/ffmpeg/scaler.h b/src/codec/ffmpeg/scaler.h new file mode 100644 index 0000000..3e53fbb --- /dev/null +++ b/src/codec/ffmpeg/scaler.h @@ -0,0 +1,24 @@ +#pragma once + +#include <libswscale/swscale.h> +#include <al/types.h> + +struct camu_ff_scale_fmt { + s32 in_width; + s32 in_height; + enum AVPixelFormat in_format; + s32 req_width; + s32 req_height; + enum AVPixelFormat req_format; + bool scaler_needed; +}; + +struct camu_ff_scaler { + struct SwsContext *scaler_context; + struct camu_ff_scale_fmt fmt; + AVFrame *frame; +}; + +bool camu_ff_scaler_init(struct camu_ff_scaler *scale, struct camu_ff_scale_fmt *fmt); +bool camu_ff_scaler_scale(struct camu_ff_scaler *scale, const u8 **in_slice, s32 *in_strides); +void camu_ff_scaler_close(struct camu_ff_scaler *scale); diff --git a/src/codec/libav/common.c b/src/codec/libav/common.c deleted file mode 100644 index 8ce6667..0000000 --- a/src/codec/libav/common.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "common.h" - -void camu_lav_set_log_callback(void (*callback)(void *, int, const char *, va_list)) -{ - av_log_set_callback(callback); -} diff --git a/src/codec/libav/common.h b/src/codec/libav/common.h deleted file mode 100644 index 854e4c7..0000000 --- a/src/codec/libav/common.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include <al/types.h> -#include <libavutil/log.h> - -void camu_lav_set_log_callback(void (*callback)(void *, int, const char *, va_list)); diff --git a/src/codec/libav/encoder.h b/src/codec/libav/encoder.h deleted file mode 100644 index b5a707a..0000000 --- a/src/codec/libav/encoder.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include <libavcodec/avcodec.h> -#include <libavformat/avformat.h> -#include <libavutil/audio_fifo.h> -#include <libavutil/rational.h> - -#include "resampler.h" - -struct camu_lav_encoder { - AVCodecContext *codec_context; - const AVOutputFormat *output_format; - - struct camu_lav_resample_fmt fmt; - - AVFrame *frame; - AVAudioFifo *audio_fifo; - - void (*callback)(void *, AVPacket *); - void *userdata; -}; - -bool camu_lav_encoder_init(struct camu_lav_encoder *enc, char *encoder_name, char *ext); -void camu_lav_encoder_push(struct camu_lav_encoder *enc, u8 **data, s32 sample_count); -bool camu_lav_encoder_process(struct camu_lav_encoder *enc, bool flush); -void camu_lav_encoder_close(struct camu_lav_encoder *enc); diff --git a/src/codec/libav/resampler.h b/src/codec/libav/resampler.h deleted file mode 100644 index 92525b2..0000000 --- a/src/codec/libav/resampler.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include <libswresample/swresample.h> -#include <libavutil/opt.h> -#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; -}; - -struct camu_lav_resampler { - SwrContext *resample_context; - struct camu_lav_resample_fmt fmt; - u8 *data[AV_NUM_DATA_POINTERS]; - s32 sample_count; -}; - -bool camu_lav_resampler_init(struct camu_lav_resampler *resamp, struct camu_lav_resample_fmt *fmt); -s32 camu_lav_resampler_sample_count(struct camu_lav_resampler *resamp, s32 in_samples); -s32 camu_lav_resampler_convert(struct camu_lav_resampler *resamp, const u8 **in_data, s32 in_samples); -u8 **camu_lav_resampler_get_data(struct camu_lav_resampler *resamp); -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); -size_t camu_lav_resample_fmt_bytes_per_sample(struct camu_lav_resample_fmt *fmt); -size_t camu_lav_resample_fmt_samples_to_bytes(struct camu_lav_resample_fmt *fmt, size_t samples); -size_t camu_lav_resample_fmt_samples_to_usec(struct camu_lav_resample_fmt *fmt, size_t samples); -f64 camu_lav_resample_fmt_samples_to_sec(struct camu_lav_resample_fmt *fmt, size_t samples); -size_t camu_lav_resample_fmt_usec_to_bytes(struct camu_lav_resample_fmt *fmt, size_t usec); -size_t camu_lav_resample_fmt_sec_to_bytes(struct camu_lav_resample_fmt *fmt, f64 sec); -size_t camu_lav_resample_fmt_bytes_to_usec(struct camu_lav_resample_fmt *fmt, size_t bytes); -f64 camu_lav_resample_fmt_bytes_to_sec(struct camu_lav_resample_fmt *fmt, size_t bytes); diff --git a/src/codec/libav/scaler.h b/src/codec/libav/scaler.h deleted file mode 100644 index 4d54085..0000000 --- a/src/codec/libav/scaler.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <libswscale/swscale.h> -#include <al/types.h> - -struct camu_lav_scale_fmt { - s32 in_width; - s32 in_height; - enum AVPixelFormat in_format; - s32 req_width; - s32 req_height; - enum AVPixelFormat req_format; - bool scaler_needed; -}; - -struct camu_lav_scaler { - struct SwsContext *scaler_context; - struct camu_lav_scale_fmt fmt; - AVFrame *frame; -}; - -bool camu_lav_scaler_init(struct camu_lav_scaler *scale, struct camu_lav_scale_fmt *fmt); -bool camu_lav_scaler_scale(struct camu_lav_scaler *scale, const u8 **in_slice, s32 *in_strides); -void camu_lav_scaler_close(struct camu_lav_scaler *scale); diff --git a/src/codec/meson.build b/src/codec/meson.build index 4ca9c53..f3b604f 100644 --- a/src/codec/meson.build +++ b/src/codec/meson.build @@ -1,26 +1,26 @@ -av_src = [ - 'libav/common.c', - 'libav/packet_ext.c' +ffmpeg_src = [ + 'ffmpeg/common.c', + 'ffmpeg/packet_ext.c' ] -av_server_src = [ - av_src, - 'libav/demuxer.c', - 'libav/encoder.c', - 'libav/avio.c' +ffmpeg_server_src = [ + ffmpeg_src, + 'ffmpeg/demuxer.c', + 'ffmpeg/encoder.c', + 'ffmpeg/avio.c' ] -av_client_src = [ - av_src, - 'libav/decoder.c', - 'libav/resampler.c' +ffmpeg_client_src = [ + ffmpeg_src, + 'ffmpeg/decoder.c', + 'ffmpeg/resampler.c' ] -av_inc = [] -av_args = [] -av_server_deps = [] -av_client_deps = [] -av_client_use_scaler = false +ffmpeg_inc = [] +ffmpeg_args = [] +ffmpeg_server_deps = [] +ffmpeg_client_deps = [] +ffmpeg_client_use_scaler = false -if av_client_use_scaler - av_client_src += ['libav/scaler.c'] +if ffmpeg_client_use_scaler + ffmpeg_client_src += ['ffmpeg/scaler.c'] endif libavutil = dependency('libavutil', required: false) @@ -29,40 +29,40 @@ libavcodec = dependency('libavcodec', required: false) libswresample = dependency('libswresample', required: false) libswscale = dependency('libswscale', required: false) if not (libavutil.found() and libavformat.found() and libavcodec.found() and libswresample.found() and libswscale.found()) - av_proj = subproject('ffmpeg', required: false) - if av_proj.found() - libavutil = av_proj.get_variable('avutil') - libavformat = av_proj.get_variable('avformat') - libavcodec = av_proj.get_variable('avcodec') - libswresample = av_proj.get_variable('swresample') - libswscale = av_proj.get_variable('swscale') - # Only used to set include dirs for libav. - av_inc_dep = av_proj.get_variable('av_inc_dep') - av_server_deps += [av_inc_dep] - av_client_deps += [av_inc_dep, dependency('zlib')] + ffmpeg_proj = subproject('ffmpeg', required: false) + if ffmpeg_proj.found() + libavutil = ffmpeg_proj.get_variable('avutil') + libavformat = ffmpeg_proj.get_variable('avformat') + libavcodec = ffmpeg_proj.get_variable('avcodec') + libswresample = ffmpeg_proj.get_variable('swresample') + libswscale = ffmpeg_proj.get_variable('swscale') + # Only used to set include dirs for ffmpeg. + ffmpeg_inc_dep = ffmpeg_proj.get_variable('ffmpeg_inc_dep') + ffmpeg_server_deps += [ffmpeg_inc_dep] + ffmpeg_client_deps += [ffmpeg_inc_dep, dependency('zlib')] soxr = compiler.find_library('soxr', required: false) if soxr.found() - av_client_deps += [soxr] + ffmpeg_client_deps += [soxr] endif - av_client_deps += [compiler.find_library('bcrypt')] + ffmpeg_client_deps += [compiler.find_library('bcrypt')] endif endif if libavutil.found() and libavformat.found() and libavcodec.found() and libswresample.found() and libswscale.found() - av_args += ['-DHAVE_FFMPEG'] - av_server_deps += [libavutil, libavformat, libavcodec] - av_client_deps += [libavutil, libavformat, libavcodec, libswresample] - if av_client_use_scaler - av_client_deps += [libswscale] + ffmpeg_args += ['-DCAMU_HAVE_FFMPEG'] + ffmpeg_server_deps += [libavutil, libavformat, libavcodec] + ffmpeg_client_deps += [libavutil, libavformat, libavcodec, libswresample] + if ffmpeg_client_use_scaler + ffmpeg_client_deps += [libswscale] endif - av_server = declare_dependency(sources: av_server_src, dependencies: av_server_deps, - include_directories: av_inc, compile_args: av_args) - av_client = declare_dependency(sources: av_client_src, dependencies: av_client_deps, - include_directories: av_inc, compile_args: av_args) + ffmpeg_server = declare_dependency(sources: ffmpeg_server_src, + dependencies: ffmpeg_server_deps, include_directories: ffmpeg_inc, compile_args: ffmpeg_args) + ffmpeg_client = declare_dependency(sources: ffmpeg_client_src, + dependencies: ffmpeg_client_deps, include_directories: ffmpeg_inc, compile_args: ffmpeg_args) endif -stb_image = declare_dependency(sources: ['stb_image/impl.c'], - dependencies: subproject('stb').get_variable('stb')) +#stb_image = declare_dependency(sources: ['stb_image/impl.c'], +# dependencies: subproject('stb').get_variable('stb')) #wuffs = declare_dependency(sources: ['wuffs/impl.c'], # dependencies: subproject('wuffs').get_variable('wuffs')) |