Hi On Thu, Mar 26, 2026 at 04:06:04PM -0500, Alstruit via ffmpeg-devel wrote: [...]
> +static int mohawk_read_header(AVFormatContext *s)
> +{
> + MohawkContext *c = s->priv_data;
> + AVIOContext *pb = s->pb;
> + AVStream *st;
> + uint32_t chunk_id, chunk_size, magic;
> + uint32_t sample_rate, num_samples, loop_start = 0, loop_end = 0;
> + uint16_t format, loop_flag;
> + int channels;
> +
> + magic = avio_rb32(pb);
> + if (magic != MKTAG_MHWK)
> + return AVERROR_INVALIDDATA;
> +
> + /* Skip file size (4 bytes) */
> + avio_skip(pb, 4);
> +
> + /* Check WAVE tag */
> + if (avio_rb32(pb) != MKTAG_WAVE) {
> + av_log(s, AV_LOG_ERROR, "WAVE tag not found.\n");
> + return AVERROR_INVALIDDATA;
> + }
> +
> + /* Chunk traversal */
> + while (!avio_feof(pb)) {
> + chunk_id = avio_rb32(pb);
> + chunk_size = avio_rb32(pb);
> +
> + av_log(s, AV_LOG_DEBUG, "Chunk: 0x%08x Size: %u\n", chunk_id,
> chunk_size);
> +
> + if (chunk_id == MKTAG_DATA) {
> + if (chunk_size < MOHAWK_DATA_HEADER_SIZE) {
> + av_log(s, AV_LOG_ERROR, "Data chunk too small: %u\n",
> chunk_size);
> + return AVERROR_INVALIDDATA;
> + }
> + c->remaining_size = chunk_size - MOHAWK_DATA_HEADER_SIZE;
> + break;
> + } else if (chunk_id == MKTAG_CUE || chunk_id == MKTAG_ADPC) {
> + avio_skip(pb, chunk_size);
> + } else {
> + int64_t file_size = avio_size(pb);
> + if (file_size > 0 && chunk_size > file_size) {
> + av_log(s, AV_LOG_WARNING, "Impossible chunk size: %u >
> %"PRId64".\n", chunk_size, file_size);
> + return AVERROR_INVALIDDATA;
> + }
why is this but the other above not checked against filesize ?
also remining size != file size
> + avio_skip(pb, chunk_size);
> + }
> + }
> +
> + if (chunk_id != MKTAG_DATA) {
> + av_log(s, AV_LOG_ERROR, "Data chunk not found.\n");
> + return AVERROR_INVALIDDATA;
> + }
> +
> + /* Data Chunk Header - 20 bytes - Always Big Endian */
> + sample_rate = avio_rb16(pb);
> + num_samples = avio_rb32(pb);
> + avio_r8(pb); /* Skip sample width (Unused) 0x06 */
> + channels = avio_r8(pb); /* 0x07 */
> + format = avio_rb16(pb); /* 0x08 */
> + loop_flag = avio_rb16(pb); /* 0x0A */
> +
> + av_log(s, AV_LOG_DEBUG, "Format: 0x%04x | Rate: %u | Channels: %d | Loop
> Flag: 0x%04x\n",
> + format, sample_rate, channels, loop_flag);
> +
> + if (loop_flag == 0xFFFF) {
> + loop_start = avio_rb32(pb);
> + loop_end = avio_rb32(pb);
> + } else {
> + avio_skip(pb, 8);
> + }
> +
> + st = avformat_new_stream(s, NULL);
> + if (!st)
> + return AVERROR(ENOMEM);
> +
> + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
> + st->codecpar->sample_rate = sample_rate;
> +
> + if (channels <= 0) {
> + av_log(s, AV_LOG_WARNING, "Invalid channel count %d, defaulting to
> Mono.\n", channels);
> + channels = 1;
> + }
why ?
is this needed for some samples ?
is sample_rate == 0 allowed ?
> +
> + av_channel_layout_default(&st->codecpar->ch_layout, channels);
> +
> + /* Codec Mapping */
> + switch (format) {
> + case 0x0000: /* 8-bit unsigned PCM */
> + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
> + break;
> + case 0x0001: /* ADPCM APC */
> + /* Use ADPCM_IMA_APC (Cryo APC).
> + * Properties:
> + * 1. Raw stream (no block headers)
> + * 2. High-Low nibble order -> Fixes "hissing" seen with Low-High
> decoders like WS.
> + */
> + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_APC;
> + st->codecpar->bits_per_coded_sample = 4;
> + st->codecpar->block_align = 0;
Is this always IMA_APC ?
[...]
> +static int mohawk_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> + MohawkContext *c = s->priv_data;
> + int ret;
> + int64_t size_to_read;
> +
> + if (c->remaining_size <= 0)
> + return AVERROR_EOF;
> +
> + size_to_read = FFMIN(MOHAWK_PACKET_SIZE, c->remaining_size);
> +
> + ret = av_get_packet(s->pb, pkt, size_to_read);
> + if (ret < 0)
> + return ret;
> +
> + c->remaining_size -= ret;
> + pkt->stream_index = 0;
> + pkt->pts = AV_NOPTS_VALUE;
> + pkt->dts = AV_NOPTS_VALUE;
redundant
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
signature.asc
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
