[FFmpeg-devel] [PATCH]lavf/gsmdec: Add a probe function
Carl Eugen Hoyos
cehoyos at ag.or.at
Sat Apr 2 10:29:20 CEST 2016
Hi!
Attached is a probe function for gsm and a patch for a gsm muxer to allow
testing. The file format is for example supported by sox.
Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c
index 97dd8c5..f6fb08e 100644
--- a/libavformat/gsmdec.c
+++ b/libavformat/gsmdec.c
@@ -34,6 +34,23 @@ typedef struct GSMDemuxerContext {
int sample_rate;
} GSMDemuxerContext;
+static int gsm_probe(AVProbeData *p)
+{
+ int valid = 0, invalid = 1;
+ uint8_t *b = p->buf;
+ while (b < p->buf + p->buf_size - 32) {
+ if ((*b & 0xf0) == 0xd0) {
+ valid++;
+ } else {
+ invalid++;
+ }
+ b += 33;
+ }
+ if (valid >> 5 > invalid)
+ return AVPROBE_SCORE_EXTENSION + 1;
+ return 0;
+}
+
static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, size;
@@ -91,6 +108,7 @@ AVInputFormat ff_gsm_demuxer = {
.name = "gsm",
.long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
.priv_data_size = sizeof(GSMDemuxerContext),
+ .read_probe = gsm_probe,
.read_header = gsm_read_header,
.read_packet = gsm_read_packet,
.flags = AVFMT_GENERIC_INDEX,
-------------- next part --------------
diff --git a/libavformat/Makefile b/libavformat/Makefile
index a54e6cb..77b6730 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -180,6 +180,7 @@ OBJS-$(CONFIG_FSB_DEMUXER) += fsb.o
OBJS-$(CONFIG_GIF_MUXER) += gif.o
OBJS-$(CONFIG_GIF_DEMUXER) += gifdec.o
OBJS-$(CONFIG_GSM_DEMUXER) += gsmdec.o
+OBJS-$(CONFIG_GSM_MUXER) += rawenc.o
OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o
OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o
OBJS-$(CONFIG_G722_DEMUXER) += g722.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 94f258d..bb31865 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -136,6 +136,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX(G722, g722);
REGISTER_MUXDEMUX(G723_1, g723_1);
REGISTER_DEMUXER (G729, g729);
+ REGISTER_MUXDEMUX(GSM, gsm);
REGISTER_DEMUXER (GENH, genh);
REGISTER_MUXDEMUX(GIF, gif);
REGISTER_DEMUXER (GSM, gsm);
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 358ee4e..14ba9fb 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -193,6 +193,20 @@ AVOutputFormat ff_g723_1_muxer = {
};
#endif
+#if CONFIG_GSM_MUXER
+AVOutputFormat ff_gsm_muxer = {
+ .name = "gsm",
+ .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
+ .mime_type = "audio/x-gsm",
+ .extensions = "gsm",
+ .audio_codec = AV_CODEC_ID_GSM,
+ .video_codec = AV_CODEC_ID_NONE,
+ .write_header = force_one_stream,
+ .write_packet = ff_raw_write_packet,
+ .flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
#if CONFIG_H261_MUXER
AVOutputFormat ff_h261_muxer = {
.name = "h261",
More information about the ffmpeg-devel
mailing list