summaryrefslogtreecommitdiff
path: root/src/codec/ffmpeg
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec/ffmpeg')
-rw-r--r--src/codec/ffmpeg/common.c10
-rw-r--r--src/codec/ffmpeg/common.h5
-rw-r--r--src/codec/ffmpeg/decoder.c5
-rw-r--r--src/codec/ffmpeg/packet_ext.c6
-rw-r--r--src/codec/ffmpeg/resampler.c8
-rw-r--r--src/codec/ffmpeg/scaler.c6
6 files changed, 30 insertions, 10 deletions
diff --git a/src/codec/ffmpeg/common.c b/src/codec/ffmpeg/common.c
index 95bf247..c5fe7cd 100644
--- a/src/codec/ffmpeg/common.c
+++ b/src/codec/ffmpeg/common.c
@@ -4,6 +4,15 @@
#include "common.h"
+s64 camu_ff_frame_duration(AVFrame *frame)
+{
+#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 30, 100)
+ return frame->duration;
+#else
+ return frame->pkt_duration;
+#endif
+}
+
void camu_ff_set_log_callback(void (*callback)(void *, s32, const char *, va_list))
{
av_log_set_callback(callback);
@@ -15,6 +24,7 @@ static size_t pos = 0;
// If a line takes more than 2 steps to print, make sure we stay within AL_LOG_MESSAGE_SIZE.
#define CHUNK_SIZE (AL_LOG_MESSAGE_SIZE / 2u)
+// @TODO: thread-saftey.
static void av_log_callback(void *userdata, s32 level, const char *fmt, va_list args)
{
(void)userdata;
diff --git a/src/codec/ffmpeg/common.h b/src/codec/ffmpeg/common.h
index 229ffb0..885dd4d 100644
--- a/src/codec/ffmpeg/common.h
+++ b/src/codec/ffmpeg/common.h
@@ -2,6 +2,11 @@
#include <al/types.h>
#include <al/log.h>
+#include <libavutil/frame.h>
+
+void camu_ff_common_init(void);
+
+s64 camu_ff_frame_duration(AVFrame *frame);
// userdata, level, fmt, args
void camu_ff_set_log_callback(void (*callback)(void *, int, const char *, va_list));
diff --git a/src/codec/ffmpeg/decoder.c b/src/codec/ffmpeg/decoder.c
index d3c9f41..dd0cc0b 100644
--- a/src/codec/ffmpeg/decoder.c
+++ b/src/codec/ffmpeg/decoder.c
@@ -326,9 +326,8 @@ static s32 receive_frames(struct camu_ff_decoder *av)
continue;
}
if (avframe->best_effort_timestamp == AV_NOPTS_VALUE) {
- // This trips under what I think are normal conditions,
- // more testing is needed.
- al_assert(avframe->duration == 0);
+ // This trips under what I think are normal conditions, more testing is needed.
+ //al_assert(avframe->duration == 0);
avframe->best_effort_timestamp = 0;
}
av->callback(av->userdata, frame);
diff --git a/src/codec/ffmpeg/packet_ext.c b/src/codec/ffmpeg/packet_ext.c
index 2ff425e..f3704f2 100644
--- a/src/codec/ffmpeg/packet_ext.c
+++ b/src/codec/ffmpeg/packet_ext.c
@@ -16,7 +16,9 @@ void nn_packet_write_av_codec_parameters(struct nn_packet *packet, AVCodecParame
NNWT_PACKET_WRITE_TYPE(packet, s32, codecpar->width);
NNWT_PACKET_WRITE_TYPE(packet, s32, codecpar->height);
NNWT_PACKET_WRITE_TYPE(packet, AVRational, codecpar->sample_aspect_ratio);
+#if LIBAVCODEC_VERSION_INT >= 60
NNWT_PACKET_WRITE_TYPE(packet, AVRational, codecpar->framerate);
+#endif
NNWT_PACKET_WRITE_TYPE(packet, enum AVFieldOrder, codecpar->field_order);
NNWT_PACKET_WRITE_TYPE(packet, enum AVColorRange, codecpar->color_range);
NNWT_PACKET_WRITE_TYPE(packet, enum AVColorPrimaries, codecpar->color_primaries);
@@ -43,7 +45,7 @@ void nn_packet_write_av_dictionary(struct nn_packet *packet, AVDictionary *dict)
s32 count = av_dict_count(dict);
NNWT_PACKET_WRITE_TYPE(packet, s32, count);
const AVDictionaryEntry *entry = NULL;
- while ((entry = av_dict_iterate(dict, entry))) {
+ while ((entry = av_dict_get(dict, "", entry, AV_DICT_IGNORE_SUFFIX))) {
size_t len = al_strlen(entry->key);
al_assert(len <= UINT32_MAX);
NNWT_PACKET_WRITE_TYPE(packet, u32, len);
@@ -112,7 +114,9 @@ void nn_packet_read_av_codec_parameters(struct nn_packet *packet, AVCodecParamet
NNWT_PACKET_READ_TYPE(packet, s32, codecpar->width);
NNWT_PACKET_READ_TYPE(packet, s32, codecpar->height);
NNWT_PACKET_READ_TYPE(packet, AVRational, codecpar->sample_aspect_ratio);
+#if LIBAVCODEC_VERSION_INT >= 60
NNWT_PACKET_READ_TYPE(packet, AVRational, codecpar->framerate);
+#endif
NNWT_PACKET_READ_TYPE(packet, enum AVFieldOrder, codecpar->field_order);
NNWT_PACKET_READ_TYPE(packet, enum AVColorRange, codecpar->color_range);
NNWT_PACKET_READ_TYPE(packet, enum AVColorPrimaries, codecpar->color_primaries);
diff --git a/src/codec/ffmpeg/resampler.c b/src/codec/ffmpeg/resampler.c
index 4f5a2ab..d2c8f62 100644
--- a/src/codec/ffmpeg/resampler.c
+++ b/src/codec/ffmpeg/resampler.c
@@ -19,7 +19,7 @@ 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("lav_resampler", "Failed to configure resampler context.");
+ al_log_error("ff_resampler", "Failed to configure resampler context.");
return false;
}
@@ -30,7 +30,7 @@ static bool ff_resampler_init(struct camu_resampler *resamp, struct camu_resampl
if (swr_init(av->resample_context) != 0) {
swr_free(&av->resample_context);
- al_log_error("lav_resampler", "Failed to init resampler context.");
+ al_log_error("ff_resampler", "Failed to init resampler context.");
return false;
}
@@ -60,7 +60,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("lav_resampler", "Failed to convert samples (%d).", resample_count);
+ al_log_error("ff_resampler", "Failed to convert samples (%d).", resample_count);
}
return resample_count;
}
@@ -72,7 +72,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("lav_resampler", "Failed to re-init resampler context after flush.");
+ al_log_error("ff_resampler", "Failed to re-init resampler context after flush.");
return -1;
}
return resample_count;
diff --git a/src/codec/ffmpeg/scaler.c b/src/codec/ffmpeg/scaler.c
index bc8d41b..a76c0a5 100644
--- a/src/codec/ffmpeg/scaler.c
+++ b/src/codec/ffmpeg/scaler.c
@@ -63,9 +63,11 @@ static bool ff_scaler_scale(struct camu_scaler *scale, const u8 **in_slice, s32
{
struct camu_ff_scaler *av = (struct camu_ff_scaler *)scale;
AVFrame *frame = av->frame.av.frame;
+ struct camu_scaler_format *fmt = &av->fmt;
+ s32 slice_height = (s32)fmt->in.height;
s32 ret = sws_scale(av->scaler_context, in_slice, in_strides, 0,
- av->fmt.in.height, frame->data, frame->linesize);
- if (ret != av->fmt.req.height) {
+ 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));
return false;
}