summaryrefslogtreecommitdiff
path: root/src/codec/ffmpeg
diff options
context:
space:
mode:
Diffstat (limited to 'src/codec/ffmpeg')
-rw-r--r--src/codec/ffmpeg/demuxer.c31
-rw-r--r--src/codec/ffmpeg/packet_ext.c2
2 files changed, 21 insertions, 12 deletions
diff --git a/src/codec/ffmpeg/demuxer.c b/src/codec/ffmpeg/demuxer.c
index e5aa2f6..32068f3 100644
--- a/src/codec/ffmpeg/demuxer.c
+++ b/src/codec/ffmpeg/demuxer.c
@@ -89,6 +89,7 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
// @TODO:
// - 1 frame .gif.
// - No-duration video. (ex: data/test_resources/no_duration.mkv)
+ // - Incomplete video files with no duration. .temp.webm.
#define GUESS_STREAM_IS_IMAGE(stream) \
((stream->duration >= 0 && stream->nb_frames <= 1 && \
(stream->avg_frame_rate.den == 0 && stream->r_frame_rate.den > 0)) || \
@@ -105,6 +106,7 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
#endif
enum AVMediaType type = stream->codecpar->codec_type;
u64 duration = 0;
+ u8 mapped_type;
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)) {
@@ -117,15 +119,24 @@ static bool ff_demuxer_init(struct camu_demuxer *demux, struct cch_handle *handl
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 (duration > av->duration) {
+ av->duration = duration;
+ }
+ }
+ if (stream->start_time == AV_NOPTS_VALUE) {
+ stream->start_time = 0;
}
- if (stream->start_time == AV_NOPTS_VALUE) stream->start_time = 0;
- } else if (type != AVMEDIA_TYPE_ATTACHMENT) {
- type = AVMEDIA_TYPE_UNKNOWN; // Mapped to CAMU_STREAM_UNKNOWN.
+ mapped_type = type;
+ } else if (type == AVMEDIA_TYPE_ATTACHMENT) {
+ mapped_type = CAMU_STREAM_ATTACHMENT;
+ } else {
+ // CAMU_STREAM_UNKNOWN(7) is a different value than AVMEDIA_TYPE_UNKNOWN(-1) because
+ // we don't support negative stream types.
+ mapped_type = CAMU_STREAM_UNKNOWN;
}
al_array_push(av->demux.streams, ((struct camu_codec_stream){
.mode = CAMU_FFMPEG_COMPAT,
- .type = type,
+ .type = mapped_type,
.duration = duration,
.index = stream->index,
.av.stream = stream
@@ -184,12 +195,10 @@ static u64 ff_demuxer_get_duration(struct camu_demuxer *demux)
static bool ff_demuxer_seek(struct camu_demuxer *demux, u64 pos, bool bytes)
{
struct camu_ff_demuxer *av = (struct camu_ff_demuxer *)demux;
- if (av->eof) {
- // avio_flush() here probably does nothing.
- avio_flush(av->io_context);
- avformat_flush(av->format_context);
- av->eof = false;
- }
+ // avio_flush() here probably does nothing.
+ avio_flush(av->io_context);
+ avformat_flush(av->format_context);
+ if (av->eof) av->eof = false;
al_assert(pos <= INT64_MAX);
al_assert(!(bytes && av->format_context->flags & AVFMT_NO_BYTE_SEEK));
if (!bytes && pos > av->duration) pos = av->duration;
diff --git a/src/codec/ffmpeg/packet_ext.c b/src/codec/ffmpeg/packet_ext.c
index 6b66dd1..68f1b4c 100644
--- a/src/codec/ffmpeg/packet_ext.c
+++ b/src/codec/ffmpeg/packet_ext.c
@@ -221,7 +221,7 @@ void nn_packet_read_av_packet(struct nn_packet *packet, AVPacket *pkt)
enum AVPacketSideDataType type;
s64 storage_for_size;
NNWT_PACKET_READ_TYPE(packet, s64, storage_for_size);
- al_assert((sizeof(size_t) > 4 || storage_for_size <= INT32_MAX));
+ al_assert(sizeof(size_t) > 4 || storage_for_size <= INT32_MAX);
size_t size = (size_t)storage_for_size;
NNWT_PACKET_READ_DATA(packet, size, data);
NNWT_PACKET_READ_TYPE(packet, enum AVPacketSideDataType, type);