diff mbox

[FFmpeg-devel] avcodec: add SIPR parser

Message ID 20170114145751.20114-1-onemda@gmail.com
State Accepted
Headers show

Commit Message

Paul B Mahol Jan. 14, 2017, 2:57 p.m. UTC
Fixes #2056.

Signed-off-by: Paul B Mahol <onemda@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

Comments

Michael Niedermayer Jan. 16, 2017, 12:57 a.m. UTC | #1
On Sat, Jan 14, 2017 at 03:57:51PM +0100, Paul B Mahol wrote:
> Fixes #2056.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavcodec/Makefile      |  1 +
>  libavcodec/allcodecs.c   |  1 +

>  libavcodec/sipr_parser.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++

can you add a fate test for this ?


[...]
Paul B Mahol Jan. 16, 2017, 8:30 a.m. UTC | #2
On 1/16/17, Michael Niedermayer <michaelni@gmx.at> wrote:
> On Sat, Jan 14, 2017 at 03:57:51PM +0100, Paul B Mahol wrote:
>> Fixes #2056.
>>
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>  libavcodec/Makefile      |  1 +
>>  libavcodec/allcodecs.c   |  1 +
>
>>  libavcodec/sipr_parser.c | 74
>> ++++++++++++++++++++++++++++++++++++++++++++++++
>
> can you add a fate test for this ?

I could. Need uploading aa sample. Do you have time to do that?

>
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Concerning the gods, I have no means of knowing whether they exist or not
> or of what sort they may be, because of the obscurity of the subject, and
> the brevity of human life -- Protagoras
>
Michael Niedermayer Jan. 16, 2017, 11:27 a.m. UTC | #3
On Mon, Jan 16, 2017 at 09:30:18AM +0100, Paul B Mahol wrote:
> On 1/16/17, Michael Niedermayer <michaelni@gmx.at> wrote:
> > On Sat, Jan 14, 2017 at 03:57:51PM +0100, Paul B Mahol wrote:
> >> Fixes #2056.
> >>
> >> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> >> ---
> >>  libavcodec/Makefile      |  1 +
> >>  libavcodec/allcodecs.c   |  1 +
> >
> >>  libavcodec/sipr_parser.c | 74
> >> ++++++++++++++++++++++++++++++++++++++++++++++++
> >
> > can you add a fate test for this ?
> 
> I could. Need uploading aa sample. Do you have time to do that?

sure, which (small) sample needs uploading ?

[...]
Paul B Mahol Jan. 16, 2017, 12:16 p.m. UTC | #4
On 1/16/17, Michael Niedermayer <michaelni@gmx.at> wrote:
> On Mon, Jan 16, 2017 at 09:30:18AM +0100, Paul B Mahol wrote:
>> On 1/16/17, Michael Niedermayer <michaelni@gmx.at> wrote:
>> > On Sat, Jan 14, 2017 at 03:57:51PM +0100, Paul B Mahol wrote:
>> >> Fixes #2056.
>> >>
>> >> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> >> ---
>> >>  libavcodec/Makefile      |  1 +
>> >>  libavcodec/allcodecs.c   |  1 +
>> >
>> >>  libavcodec/sipr_parser.c | 74
>> >> ++++++++++++++++++++++++++++++++++++++++++++++++
>> >
>> > can you add a fate test for this ?
>>
>> I could. Need uploading aa sample. Do you have time to do that?
>
> sure, which (small) sample needs uploading ?

http://ffmpeg.org/trac/ffmpeg/raw-attachment/ticket/2052/RA5.0_16kbps_voice_wideband.ra

You could cut it even more.
Michael Niedermayer Jan. 17, 2017, 12:35 a.m. UTC | #5
On Mon, Jan 16, 2017 at 01:16:32PM +0100, Paul B Mahol wrote:
> On 1/16/17, Michael Niedermayer <michaelni@gmx.at> wrote:
> > On Mon, Jan 16, 2017 at 09:30:18AM +0100, Paul B Mahol wrote:
> >> On 1/16/17, Michael Niedermayer <michaelni@gmx.at> wrote:
> >> > On Sat, Jan 14, 2017 at 03:57:51PM +0100, Paul B Mahol wrote:
> >> >> Fixes #2056.
> >> >>
> >> >> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> >> >> ---
> >> >>  libavcodec/Makefile      |  1 +
> >> >>  libavcodec/allcodecs.c   |  1 +
> >> >
> >> >>  libavcodec/sipr_parser.c | 74
> >> >> ++++++++++++++++++++++++++++++++++++++++++++++++
> >> >
> >> > can you add a fate test for this ?
> >>
> >> I could. Need uploading aa sample. Do you have time to do that?
> >
> > sure, which (small) sample needs uploading ?
> 
> http://ffmpeg.org/trac/ffmpeg/raw-attachment/ticket/2052/RA5.0_16kbps_voice_wideband.ra
> 
> You could cut it even more.

uploaded to realaudio/RA5.0_16kbps_voice_wideband.ra

should be available in all fate clients in 24h

[...]

thx
diff mbox

Patch

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");