History

avformat: add WavArc demuxer

Paul B Mahol committed 3 years ago

Commit 4e3e70c1 parent 651da916 files · +131 −2Browse files

Showing the changes to libavformat (4 of 6 files). Show all

Unified · Split

4 files
  1. libavformat/Makefile +1 −0
  2. libavformat/allformats.c +1 −0
  3. libavformat/version.h +1 −1
  4. libavformat/wavarc.c +126 −0
libavformat/Makefile+1−0
@@ -598,6 +598,7 @@ OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o · 597 unmodified lines
598OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o598OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o
599OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o599OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
600OBJS-$(CONFIG_WADY_DEMUXER) += wady.o pcm.o600OBJS-$(CONFIG_WADY_DEMUXER) += wady.o pcm.o
601OBJS-$(CONFIG_WAVARC_DEMUXER) += wavarc.o rawdec.o
601OBJS-$(CONFIG_WAV_DEMUXER) += wavdec.o pcm.o602OBJS-$(CONFIG_WAV_DEMUXER) += wavdec.o pcm.o
602OBJS-$(CONFIG_WAV_MUXER) += wavenc.o603OBJS-$(CONFIG_WAV_MUXER) += wavenc.o
603OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o604OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o
libavformat/allformats.c+1−0
@@ -480,6 +480,7 @@ extern const AVInputFormat ff_vqf_demuxer; · 479 unmodified lines
480extern const AVInputFormat ff_w64_demuxer;480extern const AVInputFormat ff_w64_demuxer;
481extern const AVOutputFormat ff_w64_muxer;481extern const AVOutputFormat ff_w64_muxer;
482extern const AVInputFormat ff_wady_demuxer;482extern const AVInputFormat ff_wady_demuxer;
483extern const AVInputFormat ff_wavarc_demuxer;
483extern const AVInputFormat ff_wav_demuxer;484extern const AVInputFormat ff_wav_demuxer;
484extern const AVOutputFormat ff_wav_muxer;485extern const AVOutputFormat ff_wav_muxer;
485extern const AVInputFormat ff_wc3_demuxer;486extern const AVInputFormat ff_wc3_demuxer;
libavformat/version.h+1−1
@@ -31,7 +31,7 @@ · 30 unmodified lines
31 31
32#include "version_major.h"32#include "version_major.h"
33 33
34#define LIBAVFORMAT_VERSION_MINOR 3734#define LIBAVFORMAT_VERSION_MINOR 38
35#define LIBAVFORMAT_VERSION_MICRO 10035#define LIBAVFORMAT_VERSION_MICRO 100
36 36
37#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \37#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
libavformat/wavarc.c+126−0
@@ -0,0 +1,126 @@
1/*
2 * WavArc demuxer
3 * Copyright (c) 2023 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "libavutil/channel_layout.h"
23#include "libavutil/intreadwrite.h"
24#include "avformat.h"
25#include "demux.h"
26#include "internal.h"
27#include "rawdec.h"
28
29static int wavarc_probe(const AVProbeData *p)
30{
31 int len = p->buf[0];
32 uint32_t id;
33
34 if (len == 0 || len + 6 >= p->buf_size)
35 return 0;
36
37 if (p->buf[len + 1] != 0)
38 return 0;
39
40 id = AV_RL32(p->buf + len + 2);
41 if (id != MKTAG('1','D','I','F') &&
42 id != MKTAG('2','S','L','P') &&
43 id != MKTAG('3','N','L','P') &&
44 id != MKTAG('4','A','L','P') &&
45 id != MKTAG('5','E','L','P'))
46 return 0;
47
48 return AVPROBE_SCORE_MAX / 3 * 2;
49}
50
51static int wavarc_read_header(AVFormatContext *s)
52{
53 AVIOContext *pb = s->pb;
54 AVCodecParameters *par;
55 int filename_len, fmt_len, ret;
56 uint8_t data[36];
57 AVStream *st;
58 uint32_t id;
59
60 filename_len = avio_r8(pb);
61 if (filename_len == 0)
62 return AVERROR_INVALIDDATA;
63 avio_skip(pb, filename_len);
64 if (avio_r8(pb))
65 return AVERROR_INVALIDDATA;
66 id = avio_rl32(pb);
67 if (avio_read(pb, data, sizeof(data)) != sizeof(data))
68 return AVERROR(EIO);
69 fmt_len = AV_RL32(data + 32);
70 if (fmt_len < 12)
71 return AVERROR_INVALIDDATA;
72
73 st = avformat_new_stream(s, NULL);
74 if (!st)
75 return AVERROR(ENOMEM);
76 par = st->codecpar;
77
78 ret = ff_alloc_extradata(par, fmt_len + sizeof(data));
79 if (ret < 0)
80 return ret;
81 memcpy(par->extradata, data, sizeof(data));
82 avio_read(pb, par->extradata + sizeof(data), fmt_len);
83
84 par->codec_type = AVMEDIA_TYPE_AUDIO;
85 par->codec_id = AV_CODEC_ID_WAVARC;
86 par->codec_tag = id;
87
88 do {
89 id = avio_rl32(pb);
90 if (id != MKTAG('d','a','t','a'))
91 avio_skip(pb, avio_rl32(pb));
92 } while (id != MKTAG('d','a','t','a'));
93 avio_skip(pb, 4);
94
95 if (AV_RL32(par->extradata + 16) != MKTAG('R','I','F','F'))
96 return AVERROR_INVALIDDATA;
97 if (AV_RL32(par->extradata + 24) != MKTAG('W','A','V','E'))
98 return AVERROR_INVALIDDATA;
99 if (AV_RL32(par->extradata + 28) != MKTAG('f','m','t',' '))
100 return AVERROR_INVALIDDATA;
101
102 av_channel_layout_default(&par->ch_layout, AV_RL16(par->extradata + 38));
103 par->sample_rate = AV_RL32(par->extradata + 40);
104 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
105 st->start_time = 0;
106
107 switch (par->extradata[36]) {
108 case 0: par->format = AV_SAMPLE_FMT_U8P; break;
109 case 1: par->format = AV_SAMPLE_FMT_S16P; break;
110 }
111
112 return 0;
113}
114
115const AVInputFormat ff_wavarc_demuxer = {
116 .name = "wavarc",
117 .long_name = NULL_IF_CONFIG_SMALL("Waveform Archiver"),
118 .read_probe = wavarc_probe,
119 .read_packet = ff_raw_read_partial_packet,
120 .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
121 .read_header = wavarc_read_header,
122 .extensions = "wa",
123 .raw_codec_id = AV_CODEC_ID_WAVARC,
124 .priv_data_size = sizeof(FFRawDemuxerContext),
125 .priv_class = &ff_raw_demuxer_class,
126};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t