summaryrefslogtreecommitdiff
path: root/src/codec
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-01-24 18:14:52 -0500
committerAndrew Opalach <andrew@akon.city> 2025-01-24 18:14:52 -0500
commitf638237a6b4f3d3edf9bdd995c15df537f8d7e7c (patch)
tree44efce6d912c43f67548690256879d036e22e742 /src/codec
parent2daa31c0629f2eb4af84d6f4fed8ac89813de056 (diff)
downloadcamu-f638237a6b4f3d3edf9bdd995c15df537f8d7e7c.tar.gz
camu-f638237a6b4f3d3edf9bdd995c15df537f8d7e7c.tar.bz2
camu-f638237a6b4f3d3edf9bdd995c15df537f8d7e7c.zip
Fix multiple bugs encountered during stress test
- Basic server resource cleanup Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/ffmpeg/decoder.c16
-rw-r--r--src/codec/ffmpeg/demuxer.c22
-rw-r--r--src/codec/ffmpeg/demuxer.h1
-rw-r--r--src/codec/ffmpeg/meson.build11
4 files changed, 28 insertions, 22 deletions
diff --git a/src/codec/ffmpeg/decoder.c b/src/codec/ffmpeg/decoder.c
index 5ff99d7..0462090 100644
--- a/src/codec/ffmpeg/decoder.c
+++ b/src/codec/ffmpeg/decoder.c
@@ -147,14 +147,16 @@ static bool ff_decoder_init(struct camu_decoder *dec, struct camu_renderer *rend
av->codec_context = NULL;
AVCodecParameters *codecpar = stream->av.stream->codecpar;
- void *state = NULL;
const AVCodec *codec;
+#ifdef CAMU_FF_DECODER_HWACCEL
+ void *state = NULL;
al_array_init(av->supported_hw_codecs);
while ((codec = av_codec_iterate(&state))) {
if (codec->capabilities & (AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_HYBRID)) {
al_array_push(av->supported_hw_codecs, codec);
}
}
+#endif
codec = avcodec_find_decoder(codecpar->codec_id);
if (!codec) {
@@ -313,15 +315,21 @@ static s32 receive_frames(struct camu_ff_decoder *av)
struct camu_codec_frame *frame = al_alloc_object(struct camu_codec_frame);
frame->mode = CAMU_FFMPEG_COMPAT;
frame->av.frame = av_frame_alloc();
- ret = avcodec_receive_frame(av->codec_context, frame->av.frame);
+ AVFrame *avframe = frame->av.frame;
+ ret = avcodec_receive_frame(av->codec_context, avframe);
if (ret < 0) {
- av_frame_free(&frame->av.frame);
+ av_frame_free(&avframe);
al_free(frame);
// Checking for EAGAIN should prevent an infinite loop.
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break;
continue;
}
- al_assert(frame->av.frame->best_effort_timestamp != AV_NOPTS_VALUE);
+ 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);
+ avframe->best_effort_timestamp = 0;
+ }
av->callback(av->userdata, frame);
}
return ret;
diff --git a/src/codec/ffmpeg/demuxer.c b/src/codec/ffmpeg/demuxer.c
index 1e92186..5c37f1a 100644
--- a/src/codec/ffmpeg/demuxer.c
+++ b/src/codec/ffmpeg/demuxer.c
@@ -73,30 +73,30 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
}
#define GUESS_STREAM_IS_IMAGE(stream) \
- (stream->duration >= 0L && stream->nb_frames <= 1L && (stream->avg_frame_rate.den == 0 && stream->r_frame_rate.den > 0))
+ (stream->duration >= 0 && stream->nb_frames <= 1 && (stream->avg_frame_rate.den == 0 && stream->r_frame_rate.den > 0))
- s64 default_duration = av->format_context->duration < 0L ? 0L : av->format_context->duration;
- av->duration = 0Lu;
+ s64 default_duration = av->format_context->duration < 0 ? 0 : av->format_context->duration;
+ av->duration = 0;
for (u32 i = 0; i < av->format_context->nb_streams; i++) {
AVStream *stream = av->format_context->streams[i];
enum AVMediaType type = stream->codecpar->codec_type;
- u64 duration = 0Lu;
+ u64 duration = 0;
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);
} else {
- if (stream->duration < 0L) {
+ if (stream->duration < 0) {
stream->duration = av_rescale_q(default_duration, AV_TIME_BASE_Q, stream->time_base);
- al_assert(stream->duration >= 0L);
+ al_assert(stream->duration >= 0);
al_log_info("ff_demuxer", "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);
if (duration > av->duration) av->duration = duration;
}
- if (stream->start_time == AV_NOPTS_VALUE) stream->start_time = 0L;
+ if (stream->start_time == AV_NOPTS_VALUE) stream->start_time = 0;
} else if (type != AVMEDIA_TYPE_ATTACHMENT) {
continue;
}
@@ -112,7 +112,6 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
//av_dump_format(av->format_context, 0, "", 0);
- av->seeked = false;
av->eof = false;
return true;
@@ -123,7 +122,7 @@ err:
static bool subscribed_to_index(struct camu_demuxer *demux, s32 index)
{
- return ((demux->subscribed >> index) & 1);
+ return (demux->subscribed >> index) & 1;
}
static s32 ff_demuxer_get_packet(struct camu_demuxer *demux, struct camu_codec_packet *packet)
@@ -146,7 +145,6 @@ static s32 ff_demuxer_get_packet(struct camu_demuxer *demux, struct camu_codec_p
av_packet_unref(pkt);
continue;
}
- if (pkt->pts == AV_NOPTS_VALUE) pkt->pts = 0L;
break;
}
return ret;
@@ -164,14 +162,14 @@ static bool ff_demuxer_seek(struct camu_demuxer *demux, u64 pos)
al_assert(pos <= INT64_MAX);
if (pos > av->duration) pos = av->duration;
if (av->eof) {
+ avio_flush(av->io_context);
+ avformat_flush(av->format_context);
av->eof = false;
}
- avformat_flush(av->format_context);
s64 ts = (s64)pos;
if (avformat_seek_file(av->format_context, -1, INT64_MIN, ts, ts, 0) < 0) {
return false;
}
- av->seeked = true;
return true;
}
diff --git a/src/codec/ffmpeg/demuxer.h b/src/codec/ffmpeg/demuxer.h
index 68ad03e..8066513 100644
--- a/src/codec/ffmpeg/demuxer.h
+++ b/src/codec/ffmpeg/demuxer.h
@@ -12,7 +12,6 @@ struct camu_ff_demuxer {
AVIOContext *io_context;
AVFormatContext *format_context;
u64 duration;
- bool seeked;
bool eof;
};
diff --git a/src/codec/ffmpeg/meson.build b/src/codec/ffmpeg/meson.build
index fc0bc91..cba033c 100644
--- a/src/codec/ffmpeg/meson.build
+++ b/src/codec/ffmpeg/meson.build
@@ -48,14 +48,15 @@ if not (libavutil.found() and libavformat.found() and libavcodec.found() and lib
# Android MediaCodec HW decoding.
ffmpeg_client_deps += [compiler.find_library('mediandk')]
endif
- soxr = compiler.find_library('soxr', required: false)
- if soxr.found()
- ffmpeg_client_deps += [soxr]
- ffmpeg_args += ['-DCAMU_HAVE_SOXR']
- endif
endif
endif
+soxr = compiler.find_library('soxr', required: false)
+if soxr.found()
+ ffmpeg_client_deps += [soxr]
+ ffmpeg_args += ['-DCAMU_HAVE_SOXR']
+endif
+
if libavutil.found() and libavformat.found() and libavcodec.found() and libswresample.found() and libswscale.found()
ffmpeg_server_deps += [libavutil, libavformat, libavcodec]
ffmpeg_client_deps += [libavutil, libavformat, libavcodec, libswresample, libswscale]