summaryrefslogtreecommitdiff
path: root/src/codec
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/codec.h10
-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
-rw-r--r--src/codec/stb_image/client.c7
-rw-r--r--src/codec/stb_image/server.c4
9 files changed, 41 insertions, 20 deletions
diff --git a/src/codec/codec.h b/src/codec/codec.h
index af824d7..e8d2b6d 100644
--- a/src/codec/codec.h
+++ b/src/codec/codec.h
@@ -120,8 +120,8 @@ struct camu_audio_format {
};
struct camu_video_format {
- s32 width;
- s32 height;
+ u32 width;
+ u32 height;
s32 format;
};
@@ -158,8 +158,8 @@ struct camu_codec_frame {
s32 format;
f64 pts;
struct {
- s32 width;
- s32 height;
+ u32 width;
+ u32 height;
} video;
struct {
u32 sample_count;
@@ -177,7 +177,7 @@ struct camu_demuxer {
bool (*seek)(struct camu_demuxer *, u64);
void (*free)(struct camu_demuxer **);
array(struct camu_codec_stream) streams;
- s32 subscribed;
+ u32 subscribed;
};
struct camu_renderer;
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;
}
diff --git a/src/codec/stb_image/client.c b/src/codec/stb_image/client.c
index 3742def..250876f 100644
--- a/src/codec/stb_image/client.c
+++ b/src/codec/stb_image/client.c
@@ -22,15 +22,16 @@ static s32 stbi_decoder_push(struct camu_decoder *dec, struct camu_codec_packet
u8 *data = nn_buffer_get_ptr(packet->buffer, 0);
u8 *pixels = stbi_load_from_memory(data, packet->buffer->size, &w, &h, &channels, 0);
if (!pixels) return CAMU_ERR_ERROR;
+
struct camu_video_format *fmt = &stb->stream->video.fmt;
- al_assert(w == fmt->width && h == fmt->height);
+ al_assert(w > 0 && h > 0 && (u32)w == fmt->width && (u32)h == fmt->height);
struct camu_codec_frame *frame = al_alloc_object(struct camu_codec_frame);
frame->mode = CAMU_NORMAL;
frame->flags = 0;
frame->data = pixels;
- frame->video.width = w;
- frame->video.height = h;
+ frame->video.width = (u32)w;
+ frame->video.height = (u32)h;
frame->format = camu_pixel_format_from_channels(channels);
al_assert(frame->format == fmt->format);
frame->pts = 0.0;
diff --git a/src/codec/stb_image/server.c b/src/codec/stb_image/server.c
index 3642a64..79327d0 100644
--- a/src/codec/stb_image/server.c
+++ b/src/codec/stb_image/server.c
@@ -28,8 +28,8 @@ static bool stbi_demuxer_init(struct camu_demuxer *demux, struct cch_handle *han
stream.mode = CAMU_NORMAL;
stream.type = CAMU_STREAM_VIDEO;
struct camu_video_format *fmt = &stream.video.fmt;
- fmt->width = w;
- fmt->height = h;
+ fmt->width = (u32)w;
+ fmt->height = (u32)h;
fmt->format = camu_pixel_format_from_channels(channels);
al_array_push(stb->demux.streams, stream);