summaryrefslogtreecommitdiff
path: root/src/codec
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/ffmpeg/avio.h2
-rw-r--r--src/codec/ffmpeg/common.c9
-rw-r--r--src/codec/ffmpeg/common.h1
-rw-r--r--src/codec/ffmpeg/decoder.c26
-rw-r--r--src/codec/ffmpeg/decoder.h1
-rw-r--r--src/codec/ffmpeg/demuxer.c18
-rw-r--r--src/codec/ffmpeg/demuxer.h3
-rw-r--r--src/codec/ffmpeg/encoder.c21
-rw-r--r--src/codec/ffmpeg/encoder.h2
-rw-r--r--src/codec/ffmpeg/resampler.c17
-rw-r--r--src/codec/ffmpeg/resampler.h1
-rw-r--r--src/codec/ffmpeg/scaler.c14
-rw-r--r--src/codec/ffmpeg/scaler.h1
13 files changed, 49 insertions, 67 deletions
diff --git a/src/codec/ffmpeg/avio.h b/src/codec/ffmpeg/avio.h
index b57cbcf..04aeeb4 100644
--- a/src/codec/ffmpeg/avio.h
+++ b/src/codec/ffmpeg/avio.h
@@ -1,8 +1,6 @@
#pragma once
#include <al/types.h>
-#include <libavutil/error.h>
-#include <libavformat/avio.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
index 044908c..d96dc76 100644
--- a/src/codec/ffmpeg/common.c
+++ b/src/codec/ffmpeg/common.c
@@ -1,5 +1,6 @@
-#include <al/lib.h>
+#define AL_LOG_SECTION "ff"
#include <al/log.h>
+#include <al/lib.h>
#include <libavutil/log.h>
#include "common.h"
@@ -38,9 +39,9 @@ static void av_log_callback(void *userdata, s32 level, const char *fmt, va_list
if ((log_context.pos > 0 && *(offset - 1) == '\n') || log_context.pos >= AV_LOG_MAX_CHUNK) {
if (level <= AV_LOG_INFO) {
- al_log_info("ff", log_context.buf);
+ log_info(log_context.buf);
} else {
- al_log_debug("ff", log_context.buf);
+ log_debug(log_context.buf);
}
log_context.pos = 0;
}
@@ -53,6 +54,6 @@ void camu_ff_set_log_callback(void (*callback)(void *, s32, const char *, va_lis
void camu_ff_common_init(void)
{
- al_log_info("ff", "Using FFmpeg version "FFMPEG_VERSION".");
+ log_info("Using FFmpeg version "FFMPEG_VERSION".");
camu_ff_set_log_callback(av_log_callback);
}
diff --git a/src/codec/ffmpeg/common.h b/src/codec/ffmpeg/common.h
index 944f915..639ca38 100644
--- a/src/codec/ffmpeg/common.h
+++ b/src/codec/ffmpeg/common.h
@@ -1,7 +1,6 @@
#pragma once
#include <al/types.h>
-#include <al/log.h>
#include <libavutil/frame.h>
s64 camu_ff_frame_duration(AVFrame *frame);
diff --git a/src/codec/ffmpeg/decoder.c b/src/codec/ffmpeg/decoder.c
index 17be6cc..1675433 100644
--- a/src/codec/ffmpeg/decoder.c
+++ b/src/codec/ffmpeg/decoder.c
@@ -31,7 +31,7 @@ static s32 init_hwframe_context(struct camu_ff_decoder *av, AVCodecContext *cont
{
AVBufferRef *hw_frames_ref;
if (!(hw_frames_ref = av_hwframe_ctx_alloc(hw_device_context))) {
- error("Failed to create hardware frame context.");
+ log_error("Failed to create hardware frame context.");
return -1;
}
@@ -45,7 +45,7 @@ static s32 init_hwframe_context(struct camu_ff_decoder *av, AVCodecContext *cont
s32 ret = av_hwframe_ctx_init(hw_frames_ref);
if (ret < 0) {
- error("Failed to initialize hardware frame context (%s).", av_err2str(ret));
+ log_error("Failed to initialize hardware frame context (%s).", av_err2str(ret));
av_buffer_unref(&hw_frames_ref);
return ret;
}
@@ -71,7 +71,7 @@ static enum AVPixelFormat get_hw_format(AVCodecContext *context, const enum AVPi
}
}
- error("Failed to get HW surface format.");
+ log_error("Failed to get HW surface format.");
return avcodec_default_get_format(context, pix_fmts);
}
@@ -82,7 +82,7 @@ static s32 init_hwdevice_context(struct camu_ff_decoder *av, AVCodecContext *con
s32 ret = av_hwdevice_ctx_create(&av->hw_context, av->hw_device_type, NULL, NULL, 0);
if (ret < 0) {
- error("Failed to create specified HW device.");
+ log_error("Failed to create specified HW device.");
return ret;
}
@@ -90,7 +90,7 @@ static s32 init_hwdevice_context(struct camu_ff_decoder *av, AVCodecContext *con
// Note that context->extra_hw_frames has the ability to cause corruption.
context->extra_hw_frames = 18;
- info("Using %s hardware decoding.", av_hwdevice_get_type_name(av->hw_device_type));
+ log_info("Using %s hardware decoding.", av_hwdevice_get_type_name(av->hw_device_type));
return ret;
}
@@ -182,7 +182,7 @@ static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *rend
AVCodecParameters *codecpar = stream->av.stream->codecpar;
const AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
if (!codec) {
- error("Failed to find decoder.");
+ log_error("Failed to find decoder.");
goto err;
}
@@ -216,19 +216,19 @@ static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *rend
}
if (av->hw_device_type == AV_HWDEVICE_TYPE_NONE) {
- warn("Hardware accelerated video decoding of %s not supported.", codec->name);
+ log_warn("Hardware accelerated video decoding of %s not supported.", codec->name);
}
}
#endif
av->codec_context = avcodec_alloc_context3(codec);
if (!av->codec_context) {
- error("Failed to alloc codec context.");
+ log_error("Failed to alloc codec context.");
goto err;
}
if (avcodec_parameters_to_context(av->codec_context, codecpar) < 0) {
- error("Failed to copy codec parameters.");
+ log_error("Failed to copy codec parameters.");
goto err;
}
@@ -262,20 +262,20 @@ static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *rend
av->codec_context->thread_count = cpus;
// FF_THREAD_FRAME or FF_THREAD_SLICE.
av->codec_context->thread_type = FF_THREAD_FRAME;
- info("Using %i threads for decoder.", cpus);
+ log_info("Using %i threads for decoder.", cpus);
}
}
AVDictionary *opts = NULL;
s32 ret = avcodec_open2(av->codec_context, codec, &opts);
if (ret < 0) {
- error("Failed to open codec %s (%s).", codec->name, av_err2str(ret));
+ log_error("Failed to open codec %s (%s).", codec->name, av_err2str(ret));
goto err;
}
const char *long_name = codec->long_name ? codec->long_name : codec->name;
s64 kbps = (codecpar->bit_rate > 0) ? codecpar->bit_rate / 1000 : 0;
- info("Codec: %s (%s) %lldkbps.", codec->name, long_name, kbps);
+ log_info("Codec: %s (%s) %lldkbps.", codec->name, long_name, kbps);
av->callback = callback;
av->userdata = userdata;
@@ -290,7 +290,7 @@ static s32 send_packet(struct camu_ff_decoder *av, AVPacket *pkt)
{
s32 ret = avcodec_send_packet(av->codec_context, pkt);
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
- error("Error sending packet to the decoder (%s).", av_err2str(ret));
+ log_error("Error sending packet to the decoder (%s).", av_err2str(ret));
}
return ret;
}
diff --git a/src/codec/ffmpeg/decoder.h b/src/codec/ffmpeg/decoder.h
index c6fb5fc..ab60ef3 100644
--- a/src/codec/ffmpeg/decoder.h
+++ b/src/codec/ffmpeg/decoder.h
@@ -1,6 +1,5 @@
#pragma once
-#include <al/types.h>
#include <libavcodec/avcodec.h>
#include "../codec.h"
diff --git a/src/codec/ffmpeg/demuxer.c b/src/codec/ffmpeg/demuxer.c
index b612b2d..cb2ed91 100644
--- a/src/codec/ffmpeg/demuxer.c
+++ b/src/codec/ffmpeg/demuxer.c
@@ -1,4 +1,6 @@
+#define AL_LOG_SECTION "ff_demuxer"
#include <al/log.h>
+#include <al/lib.h>
#include "demuxer.h"
#include "avio.h"
@@ -24,14 +26,14 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
av->format_context = avformat_alloc_context();
if (!av->format_context) {
- al_log_error("ff_demuxer", "Failed to create format context.");
+ log_error("Failed to create format context.");
goto err;
}
u8 *buf = (u8 *)av_malloc(DEMUX_BUFFER_SIZE);
av->io_context = avio_alloc_context(buf, DEMUX_BUFFER_SIZE, 0, handle, camu_avio_read, NULL, camu_avio_seek);
if (!av->io_context) {
- al_log_error("ff_demuxer", "Failed to create custom io context.");
+ log_error("Failed to create custom io context.");
goto err;
}
@@ -56,7 +58,7 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
// network streams sounds like something we want.
s32 ret = avformat_open_input(&av->format_context, "file:", NULL, &opts);
if (ret < 0) {
- al_log_error("ff_demuxer", "Failed to open input (%s).", av_err2str(ret));
+ log_error("Failed to open input (%s).", av_err2str(ret));
av_dict_free(&opts);
goto err;
}
@@ -64,12 +66,12 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
av_dict_free(&opts);
if (avformat_find_stream_info(av->format_context, NULL) < 0) {
- al_log_error("ff_demuxer", "Failed to find stream info.");
+ log_error("Failed to find stream info.");
goto err;
}
if (!av->format_context->nb_streams) {
- al_log_error("ff_demuxer", "No streams found.");
+ log_error("No streams found.");
goto err;
}
@@ -86,12 +88,12 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
if (type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_SUBTITLE) {
// Try to detect attached images.
if (type == AVMEDIA_TYPE_VIDEO && GUESS_STREAM_IS_IMAGE(stream)) {
- al_log_info("ff_demuxer", "Assuming stream #%u is an image.", i);
+ log_info("Assuming stream #%u is an image.", i);
} else {
if (stream->duration < 0) {
stream->duration = av_rescale_q(default_duration, AV_TIME_BASE_Q, stream->time_base);
al_assert(stream->duration >= 0);
- al_log_info("ff_demuxer", "Stream #%u has an invalid duration, defaulting to %.3fs.",
+ log_info("Stream #%u has an invalid duration, defaulting to %.3fs.",
i, stream->duration * av_q2d(stream->time_base));
}
duration = (u64)av_rescale_q(stream->duration, stream->time_base, AV_TIME_BASE_Q);
@@ -140,7 +142,7 @@ static s32 ff_demuxer_get_packet(struct camu_demuxer *demux, struct camu_codec_p
break;
}
if (ret < 0) {
- al_log_error("ff_demuxer", "Failed to read frame (%s).", av_err2str(ret));
+ log_error("Failed to read frame (%s).", av_err2str(ret));
break;
}
if (!subscribed_to_index(demux, pkt->stream_index)) {
diff --git a/src/codec/ffmpeg/demuxer.h b/src/codec/ffmpeg/demuxer.h
index 8066513..378c5bb 100644
--- a/src/codec/ffmpeg/demuxer.h
+++ b/src/codec/ffmpeg/demuxer.h
@@ -1,8 +1,5 @@
#pragma once
-#include <al/types.h>
-#include <al/lib.h>
-#include <al/array.h>
#include <libavformat/avformat.h>
#include "../codec.h"
diff --git a/src/codec/ffmpeg/encoder.c b/src/codec/ffmpeg/encoder.c
index 0577ae9..50e80e4 100644
--- a/src/codec/ffmpeg/encoder.c
+++ b/src/codec/ffmpeg/encoder.c
@@ -1,13 +1,6 @@
-#include <al/lib.h>
+#define AL_LOG_SECTION "ff_encoder"
#include <al/log.h>
-#include <libavcodec/avcodec.h>
-#include <libavcodec/codec.h>
-#include <libavformat/avformat.h>
-#include <libavutil/audio_fifo.h>
-#include <libavutil/channel_layout.h>
-#include <libavutil/error.h>
-#include <libavutil/frame.h>
-#include <libavutil/samplefmt.h>
+#include <al/lib.h>
#include "encoder.h"
@@ -27,14 +20,14 @@ bool camu_ff_encoder_init(struct camu_ff_encoder *enc, char *encoder_name, char
const AVCodec *codec = avcodec_find_encoder_by_name(encoder_name);
if (!codec) {
- al_log_error("ff_encoder", "Failed to find codec by name %s.", encoder_name);
+ log_error("Failed to find codec by name %s.", encoder_name);
goto err;
}
enc->codec_context = avcodec_alloc_context3(codec);
if (!enc->codec_context) {
- al_log_error("ff_encoder", "Failed to alloc codec context.");
+ log_error("Failed to alloc codec context.");
goto err;
}
@@ -61,7 +54,7 @@ bool camu_ff_encoder_init(struct camu_ff_encoder *enc, char *encoder_name, char
av_dict_set(&opts, "application", "audio", 0);
if (avcodec_open2(enc->codec_context, codec, &opts) < 0) {
- al_log_error("ff_encoder", "Failed to open codec.");
+ log_error("Failed to open codec.");
av_dict_free(&opts);
goto err;
}
@@ -95,7 +88,7 @@ void camu_ff_encoder_push(struct camu_ff_encoder *enc, u8 **data, s32 sample_cou
enc->frame->data[0] = data[0];
s32 ret = avcodec_send_frame(enc->codec_context, enc->frame);
if (ret < 0 && ret != AVERROR_EOF) {
- al_log_error("ff_encoder", "Error sending frame to the encoder (%s).", av_err2str(ret));
+ log_error("Error sending frame to the encoder (%s).", av_err2str(ret));
return;
}
AVPacket pkt = { 0 };
@@ -103,7 +96,7 @@ void camu_ff_encoder_push(struct camu_ff_encoder *enc, u8 **data, s32 sample_cou
ret = avcodec_receive_packet(enc->codec_context, &pkt);
if (ret < 0) {
if (!(ret = AVERROR_EOF || ret == AVERROR(EAGAIN))) {
- al_log_error("ff_encoder", "Error receiving packet from the encoder (%s).", av_err2str(ret));
+ log_error("Error receiving packet from the encoder (%s).", av_err2str(ret));
}
return;
}
diff --git a/src/codec/ffmpeg/encoder.h b/src/codec/ffmpeg/encoder.h
index 238403f..5f7d06f 100644
--- a/src/codec/ffmpeg/encoder.h
+++ b/src/codec/ffmpeg/encoder.h
@@ -2,8 +2,6 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
-#include <libavutil/audio_fifo.h>
-#include <libavutil/rational.h>
#include "../codec.h"
diff --git a/src/codec/ffmpeg/resampler.c b/src/codec/ffmpeg/resampler.c
index 61e8c9e..eacc75b 100644
--- a/src/codec/ffmpeg/resampler.c
+++ b/src/codec/ffmpeg/resampler.c
@@ -1,10 +1,7 @@
-#include <al/lib.h>
+#define AL_LOG_SECTION "ff_resampler"
#include <al/log.h>
-#include <libavutil/channel_layout.h>
-#include <libavutil/frame.h>
-#include <libavutil/samplefmt.h>
+#include <al/lib.h>
#include <libavutil/opt.h>
-#include <libswresample/swresample.h>
#include "resampler.h"
@@ -19,19 +16,19 @@ static bool ff_resampler_init(struct camu_resampler *resamp, struct camu_resampl
&fmt->req.channel_layout, fmt->req.format, fmt->req.sample_rate,
&fmt->in.channel_layout, fmt->in.format, fmt->in.sample_rate, 0, NULL);
if (ret != 0) {
- al_log_error("ff_resampler", "Failed to configure resampler context.");
+ log_error("Failed to configure resampler context.");
return false;
}
#ifdef CAMU_HAVE_SOXR
// Slower but more accurate resampler.
av_opt_set_int(av->resample_context, "resampler", SWR_ENGINE_SOXR, 0);
- al_log_info("ff_resampler", "Using SoX resampler.");
+ log_info("Using SoX resampler.");
#endif
if (swr_init(av->resample_context) != 0) {
swr_free(&av->resample_context);
- al_log_error("ff_resampler", "Failed to init resampler context.");
+ log_error("Failed to init resampler context.");
return false;
}
@@ -61,7 +58,7 @@ static s32 ff_resampler_convert(struct camu_resampler *resamp, const u8 **in_dat
s32 resample_count = swr_convert(av->resample_context, av->data,
out_resample_count, in_data, in_samples);
if (resample_count < 0) {
- al_log_error("ff_resampler", "Failed to convert samples (%d).", resample_count);
+ log_error("Failed to convert samples (%d).", resample_count);
}
return resample_count;
}
@@ -73,7 +70,7 @@ static s32 ff_resampler_flush(struct camu_resampler *resamp)
av->sample_count, NULL, 0);
if (swr_init(av->resample_context) != 0) {
swr_free(&av->resample_context);
- al_log_error("ff_resampler", "Failed to re-init resampler context after flush.");
+ log_error("Failed to re-init resampler context after flush.");
return -1;
}
return resample_count;
diff --git a/src/codec/ffmpeg/resampler.h b/src/codec/ffmpeg/resampler.h
index 35e1158..fc89cb4 100644
--- a/src/codec/ffmpeg/resampler.h
+++ b/src/codec/ffmpeg/resampler.h
@@ -1,6 +1,5 @@
#pragma once
-#include <al/types.h>
#include <libswresample/swresample.h>
#include "../codec.h"
diff --git a/src/codec/ffmpeg/scaler.c b/src/codec/ffmpeg/scaler.c
index a76c0a5..93bbac6 100644
--- a/src/codec/ffmpeg/scaler.c
+++ b/src/codec/ffmpeg/scaler.c
@@ -1,7 +1,7 @@
-#include <al/lib.h>
+#define AL_LOG_SECTION "ff_scaler"
#include <al/log.h>
+#include <al/lib.h>
#include <libavutil/imgutils.h>
-#include <libavcodec/avcodec.h>
#include "scaler.h"
@@ -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("ff_scaler", "Failed to allocate picture buffer (%s).", av_err2str(ret));
+ log_error("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("ff_scaler", "Failed to allocate picture buffer (%s).", av_err2str(ret));
+ log_error("Failed to allocate picture buffer (%s).", av_err2str(ret));
av_free(frame);
return NULL;
}
@@ -45,14 +45,14 @@ static bool ff_scaler_init(struct camu_scaler *scale, struct camu_scaler_format
av->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 (!av->scaler_context) {
- al_log_error("ff_scaler", "Failed to create scaler context.");
+ log_error("Failed to create scaler context.");
return false;
}
struct camu_codec_frame *frame = &av->frame;
frame->av.frame = alloc_picture(fmt->req.format, fmt->req.width, fmt->req.height);
if (!frame->av.frame) {
- al_log_error("ff_scaler", "Failed to allocate frame.");
+ log_error("Failed to allocate frame.");
return false;
}
@@ -68,7 +68,7 @@ static bool ff_scaler_scale(struct camu_scaler *scale, const u8 **in_slice, s32
s32 ret = sws_scale(av->scaler_context, in_slice, in_strides, 0,
slice_height, frame->data, frame->linesize);
if (ret != (s32)fmt->req.height) {
- al_log_error("ff_scaler", "Failed to scale frame (%s).", av_err2str(ret));
+ log_error("Failed to scale frame (%s).", av_err2str(ret));
return false;
}
return true;
diff --git a/src/codec/ffmpeg/scaler.h b/src/codec/ffmpeg/scaler.h
index f01f3fd..afd6aaf 100644
--- a/src/codec/ffmpeg/scaler.h
+++ b/src/codec/ffmpeg/scaler.h
@@ -1,6 +1,5 @@
#pragma once
-#include <al/types.h>
#include <libswscale/swscale.h>
#include "../codec.h"