[FFmpeg-devel] [PATCH] avcodec: add SIPR parser

Paul B Mahol onemda at gmail.com
Sat Jan 14 16:57:51 EET 2017


Fixes #2056.

Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavcodec/Makefile      |  1 +
 libavcodec/allcodecs.c   |  1 +
 libavcodec/sipr_parser.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/aadec.c      |  2 ++
 libavformat/rmdec.c      |  1 +
 5 files changed, 79 insertions(+)
 create mode 100644 libavcodec/sipr_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4494f26..f5735d0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -943,6 +943,7 @@ OBJS-$(CONFIG_PNG_PARSER)              += png_parser.o
 OBJS-$(CONFIG_PNM_PARSER)              += pnm_parser.o pnm.o
 OBJS-$(CONFIG_RV30_PARSER)             += rv34_parser.o
 OBJS-$(CONFIG_RV40_PARSER)             += rv34_parser.o
+OBJS-$(CONFIG_SIPR_PARSER)             += sipr_parser.o
 OBJS-$(CONFIG_TAK_PARSER)              += tak_parser.o tak.o
 OBJS-$(CONFIG_VC1_PARSER)              += vc1_parser.o vc1.o vc1data.o  \
                                           simple_idct.o wmv2data.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 22a93f3..703c552 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -702,6 +702,7 @@ void avcodec_register_all(void)
     REGISTER_PARSER(PNM,                pnm);
     REGISTER_PARSER(RV30,               rv30);
     REGISTER_PARSER(RV40,               rv40);
+    REGISTER_PARSER(SIPR,               sipr);
     REGISTER_PARSER(TAK,                tak);
     REGISTER_PARSER(VC1,                vc1);
     REGISTER_PARSER(VORBIS,             vorbis);
diff --git a/libavcodec/sipr_parser.c b/libavcodec/sipr_parser.c
new file mode 100644
index 0000000..fba25e1
--- /dev/null
+++ b/libavcodec/sipr_parser.c
@@ -0,0 +1,74 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Sipr audio parser
+ */
+
+#include "parser.h"
+
+typedef struct SiprParserContext{
+    ParseContext pc;
+} SiprParserContext;
+
+static int sipr_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
+{
+    int next;
+
+    switch (avctx->block_align) {
+    case 20:
+    case 19:
+    case 29:
+    case 37: next = avctx->block_align; break;
+    default:
+        if      (avctx->bit_rate > 12200) next = 20;
+        else if (avctx->bit_rate > 7500 ) next = 19;
+        else if (avctx->bit_rate > 5750 ) next = 29;
+        else                              next = 37;
+    }
+
+    return FFMIN(next, buf_size);
+}
+
+static int sipr_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
+                      const uint8_t **poutbuf, int *poutbuf_size,
+                      const uint8_t *buf, int buf_size)
+{
+    SiprParserContext *s = s1->priv_data;
+    ParseContext *pc = &s->pc;
+    int next;
+
+    next = sipr_split(avctx, buf, buf_size);
+    if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
+        *poutbuf = NULL;
+        *poutbuf_size = 0;
+        return buf_size;
+    }
+
+    *poutbuf      = buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
+AVCodecParser ff_sipr_parser = {
+    .codec_ids      = { AV_CODEC_ID_SIPR },
+    .priv_data_size = sizeof(SiprParserContext),
+    .parser_parse   = sipr_parse,
+    .parser_close   = ff_parse_close,
+};
diff --git a/libavformat/aadec.c b/libavformat/aadec.c
index cf5f3d1..0f4ec20 100644
--- a/libavformat/aadec.c
+++ b/libavformat/aadec.c
@@ -184,11 +184,13 @@ static int aa_read_header(AVFormatContext *s)
         st->codecpar->block_align = 19;
         st->codecpar->channels = 1;
         st->codecpar->sample_rate = 8500;
+        st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
     } else if (!strcmp(codec_name, "acelp16")) {
         st->codecpar->codec_id = AV_CODEC_ID_SIPR;
         st->codecpar->block_align = 20;
         st->codecpar->channels = 1;
         st->codecpar->sample_rate = 16000;
+        st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
     }
 
     /* determine, and jump to audio start offset */
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 4d56529..c803588 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -236,6 +236,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
                     return -1;
                 }
                 st->codecpar->block_align = ff_sipr_subpk_size[flavor];
+                st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
             } else {
                 if(sub_packet_size <= 0){
                     av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n");
-- 
2.9.3



More information about the ffmpeg-devel mailing list