Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-02-24 Thread Tomas Härdin
ons 2018-02-14 klockan 10:20 +0100 skrev Tomas Härdin:
> tis 2018-02-13 klockan 11:48 +0100 skrev Tomas Härdin:
> > fre 2018-02-09 klockan 11:29 +0100 skrev Carl Eugen Hoyos:
> > > 2018-01-15 22:36 GMT+01:00 Tomas Härdin :
> > > 
> > > > > +if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
> > > > > AVPROBE_SCORE_MAX/5;
> > > > > +if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
> > > > > AVPROBE_SCORE_MAX/5;
> > > > > +if (p->buf[6] != 0) score -=
> > > > > AVPROBE_SCORE_MAX/5;
> > > > > +return score;
> > > > > 
> > > > > Imo, this is too complicated:
> > > > > If the first 32bit are correct, return MAX/2, for 24bit,
> > > > > return
> > > > > less
> > > 
> > > This should have been AVPROBE_SCORE_EXTENSION + 1,
> > > sorry about my mistake.
> > 
> > Done.
> > 
> > > Please threaten to push this and push after a few days.
> > 
> > Alright, rebased. I'll push on Sunday if there's no objections
> > 
> > /Tomas
> 
> Aaaand a set that actually passes FATE this time :)

Pushed

/Tomas

signature.asc
Description: This is a digitally signed message part
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-02-14 Thread Tomas Härdin
tis 2018-02-13 klockan 11:48 +0100 skrev Tomas Härdin:
> fre 2018-02-09 klockan 11:29 +0100 skrev Carl Eugen Hoyos:
> > 2018-01-15 22:36 GMT+01:00 Tomas Härdin :
> > 
> > > > +if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
> > > > AVPROBE_SCORE_MAX/5;
> > > > +if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
> > > > AVPROBE_SCORE_MAX/5;
> > > > +if (p->buf[6] != 0) score -=
> > > > AVPROBE_SCORE_MAX/5;
> > > > +return score;
> > > > 
> > > > Imo, this is too complicated:
> > > > If the first 32bit are correct, return MAX/2, for 24bit, return
> > > > less
> > 
> > This should have been AVPROBE_SCORE_EXTENSION + 1,
> > sorry about my mistake.
> 
> Done.
> 
> > Please threaten to push this and push after a few days.
> 
> Alright, rebased. I'll push on Sunday if there's no objections
> 
> /Tomas

Aaaand a set that actually passes FATE this time :)

/TomasFrom 857d988892a028b7a273f70fc51770d4d0fbf08d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 8 Aug 2017 15:27:27 +0200
Subject: [PATCH 1/4] Add libcodec2 en/decoder

---
 Changelog|   1 +
 configure|   5 ++
 doc/general.texi |  20 +
 libavcodec/Makefile  |   2 +
 libavcodec/allcodecs.c   |   2 +
 libavcodec/avcodec.h |   1 +
 libavcodec/codec2utils.c |  80 ++
 libavcodec/codec2utils.h |  82 ++
 libavcodec/codec_desc.c  |   7 ++
 libavcodec/libcodec2.c   | 213 +++
 libavcodec/version.h |   4 +-
 11 files changed, 415 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/codec2utils.c
 create mode 100644 libavcodec/codec2utils.h
 create mode 100644 libavcodec/libcodec2.c

diff --git a/Changelog b/Changelog
index 2acdbbea30..4ca137c0ce 100644
--- a/Changelog
+++ b/Changelog
@@ -39,6 +39,7 @@ version :
 - Removed the ffmenc and ffmdec muxer and demuxer
 - VideoToolbox HEVC encoder and hwaccel
 - VAAPI-accelerated ProcAmp (color balance), denoise and sharpness filters
+- codec2 en/decoding via libcodec2
 
 
 version 3.4:
diff --git a/configure b/configure
index 99c53d482a..cad9d35457 100755
--- a/configure
+++ b/configure
@@ -224,6 +224,7 @@ External library support:
   --enable-libcaca enable textual display using libcaca [no]
   --enable-libcelt enable CELT decoding via libcelt [no]
   --enable-libcdio enable audio CD grabbing with libcdio [no]
+  --enable-libcodec2   enable codec2 en/decoding using libcodec2 [no]
   --enable-libdc1394   enable IIDC-1394 grabbing using libdc1394
and libraw1394 [no]
   --enable-libfdk-aac  enable AAC de/encoding via libfdk-aac [no]
@@ -1603,6 +1604,7 @@ EXTERNAL_LIBRARY_LIST="
 libbs2b
 libcaca
 libcelt
+libcodec2
 libdc1394
 libdrm
 libflite
@@ -2940,6 +2942,8 @@ h264_videotoolbox_encoder_select="videotoolbox_encoder"
 hevc_videotoolbox_encoder_deps="pthreads"
 hevc_videotoolbox_encoder_select="videotoolbox_encoder"
 libcelt_decoder_deps="libcelt"
+libcodec2_decoder_deps="libcodec2"
+libcodec2_encoder_deps="libcodec2"
 libfdk_aac_decoder_deps="libfdk_aac"
 libfdk_aac_encoder_deps="libfdk_aac"
 libfdk_aac_encoder_select="audio_frame_queue"
@@ -5865,6 +5869,7 @@ enabled libcelt   && require libcelt celt/celt.h celt_decode -lcelt0 &&
  { check_lib libcelt celt/celt.h celt_decoder_create_custom -lcelt0 ||
die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
 enabled libcaca   && require_pkg_config libcaca caca caca.h caca_create_canvas
+enabled libcodec2 && require libcodec2 codec2/codec2.h codec2_create -lcodec2
 enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new
 enabled libdrm&& require_pkg_config libdrm libdrm xf86drm.h drmGetVersion
 enabled libfdk_aac&& { check_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen ||
diff --git a/doc/general.texi b/doc/general.texi
index 9ddcccf041..63722f272d 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -85,6 +85,24 @@ Go to @url{http://www.twolame.org/} and follow the
 instructions for installing the library.
 Then pass @code{--enable-libtwolame} to configure to enable it.
 
+@section libcodec2 / codec2 general
+
+FFmpeg can make use of libcodec2 for codec2 encoding and decoding.
+There is currently no native decoder, so libcodec2 must be used for decoding.
+
+Go to @url{http://freedv.org/}, download "Codec 2 source archive".
+Build and install using CMake. Debian users can install the libcodec2-dev package instead.
+Once libcodec2 is installed you can pass @code{--enable-libcodec2} to configure to enable it.
+
+The easiest way to use codec2 is with .c2 files, since they contain the mode information required for decoding.
+To encode such a file, use 

Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-02-13 Thread Tomas Härdin
fre 2018-02-09 klockan 11:29 +0100 skrev Carl Eugen Hoyos:
> 2018-01-15 22:36 GMT+01:00 Tomas Härdin :
> 
> > > +if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
> > > AVPROBE_SCORE_MAX/5;
> > > +if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
> > > AVPROBE_SCORE_MAX/5;
> > > +if (p->buf[6] != 0) score -=
> > > AVPROBE_SCORE_MAX/5;
> > > +return score;
> > > 
> > > Imo, this is too complicated:
> > > If the first 32bit are correct, return MAX/2, for 24bit, return
> > > less
> 
> This should have been AVPROBE_SCORE_EXTENSION + 1,
> sorry about my mistake.

Done.

> Please threaten to push this and push after a few days.

Alright, rebased. I'll push on Sunday if there's no objections

/TomasFrom 454d629bde4f167ad16b735956371f3980ce0e92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
Date: Tue, 8 Aug 2017 15:27:27 +0200
Subject: [PATCH 1/4] Add libcodec2 en/decoder

---
 Changelog|   1 +
 configure|   5 ++
 doc/general.texi |  20 +
 libavcodec/Makefile  |   2 +
 libavcodec/allcodecs.c   |   2 +
 libavcodec/avcodec.h |   1 +
 libavcodec/codec2utils.c |  80 ++
 libavcodec/codec2utils.h |  82 ++
 libavcodec/codec_desc.c  |   7 ++
 libavcodec/libcodec2.c   | 213 +++
 libavcodec/version.h |   4 +-
 11 files changed, 415 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/codec2utils.c
 create mode 100644 libavcodec/codec2utils.h
 create mode 100644 libavcodec/libcodec2.c

diff --git a/Changelog b/Changelog
index 2acdbbea30..4ca137c0ce 100644
--- a/Changelog
+++ b/Changelog
@@ -39,6 +39,7 @@ version :
 - Removed the ffmenc and ffmdec muxer and demuxer
 - VideoToolbox HEVC encoder and hwaccel
 - VAAPI-accelerated ProcAmp (color balance), denoise and sharpness filters
+- codec2 en/decoding via libcodec2
 
 
 version 3.4:
diff --git a/configure b/configure
index 99c53d482a..cad9d35457 100755
--- a/configure
+++ b/configure
@@ -224,6 +224,7 @@ External library support:
   --enable-libcaca enable textual display using libcaca [no]
   --enable-libcelt enable CELT decoding via libcelt [no]
   --enable-libcdio enable audio CD grabbing with libcdio [no]
+  --enable-libcodec2   enable codec2 en/decoding using libcodec2 [no]
   --enable-libdc1394   enable IIDC-1394 grabbing using libdc1394
and libraw1394 [no]
   --enable-libfdk-aac  enable AAC de/encoding via libfdk-aac [no]
@@ -1603,6 +1604,7 @@ EXTERNAL_LIBRARY_LIST="
 libbs2b
 libcaca
 libcelt
+libcodec2
 libdc1394
 libdrm
 libflite
@@ -2940,6 +2942,8 @@ h264_videotoolbox_encoder_select="videotoolbox_encoder"
 hevc_videotoolbox_encoder_deps="pthreads"
 hevc_videotoolbox_encoder_select="videotoolbox_encoder"
 libcelt_decoder_deps="libcelt"
+libcodec2_decoder_deps="libcodec2"
+libcodec2_encoder_deps="libcodec2"
 libfdk_aac_decoder_deps="libfdk_aac"
 libfdk_aac_encoder_deps="libfdk_aac"
 libfdk_aac_encoder_select="audio_frame_queue"
@@ -5865,6 +5869,7 @@ enabled libcelt   && require libcelt celt/celt.h celt_decode -lcelt0 &&
  { check_lib libcelt celt/celt.h celt_decoder_create_custom -lcelt0 ||
die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
 enabled libcaca   && require_pkg_config libcaca caca caca.h caca_create_canvas
+enabled libcodec2 && require libcodec2 codec2/codec2.h codec2_create -lcodec2
 enabled libdc1394 && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new
 enabled libdrm&& require_pkg_config libdrm libdrm xf86drm.h drmGetVersion
 enabled libfdk_aac&& { check_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen ||
diff --git a/doc/general.texi b/doc/general.texi
index 9ddcccf041..63722f272d 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -85,6 +85,24 @@ Go to @url{http://www.twolame.org/} and follow the
 instructions for installing the library.
 Then pass @code{--enable-libtwolame} to configure to enable it.
 
+@section libcodec2 / codec2 general
+
+FFmpeg can make use of libcodec2 for codec2 encoding and decoding.
+There is currently no native decoder, so libcodec2 must be used for decoding.
+
+Go to @url{http://freedv.org/}, download "Codec 2 source archive".
+Build and install using CMake. Debian users can install the libcodec2-dev package instead.
+Once libcodec2 is installed you can pass @code{--enable-libcodec2} to configure to enable it.
+
+The easiest way to use codec2 is with .c2 files, since they contain the mode information required for decoding.
+To encode such a file, use a .c2 file extension and give the libcodec2 encoder the -mode option:
+@code{ffmpeg -i input.wav -mode 700C output.c2}.
+Playback is as simple as @code{ffplay 

Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-02-09 Thread Tomas Härdin

On 2018-02-09 11:29, Carl Eugen Hoyos wrote:

2018-01-15 22:36 GMT+01:00 Tomas Härdin :


+if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
AVPROBE_SCORE_MAX/5;
+if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
AVPROBE_SCORE_MAX/5;
+if (p->buf[6] != 0) score -=
AVPROBE_SCORE_MAX/5;
+return score;

Imo, this is too complicated:
If the first 32bit are correct, return MAX/2, for 24bit, return less

This should have been AVPROBE_SCORE_EXTENSION + 1,
sorry about my mistake.


Alright. A documentation update may be in order unless already done


Please threaten to push this and push after a few days.


Don't have ssh access, but I believe Michael has offered to add me 
several times. I'll email him a GPG signed copy of a public SSH key when 
I get home


/Tomas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-02-09 Thread Carl Eugen Hoyos
2018-01-15 22:36 GMT+01:00 Tomas Härdin :

>> +if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
>> AVPROBE_SCORE_MAX/5;
>> +if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
>> AVPROBE_SCORE_MAX/5;
>> +if (p->buf[6] != 0) score -=
>> AVPROBE_SCORE_MAX/5;
>> +return score;
>>
>> Imo, this is too complicated:
>> If the first 32bit are correct, return MAX/2, for 24bit, return less

This should have been AVPROBE_SCORE_EXTENSION + 1,
sorry about my mistake.

Please threaten to push this and push after a few days.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-02-09 Thread Tomas Härdin
Ping? I'd maintain this of course. Plus I'd like to add some tests, but 
I need to know if this looks OK to everyone first


/Tomas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-01-15 Thread Tomas Härdin
fre 2018-01-12 klockan 21:21 +0100 skrev Michael Niedermayer:
> On Sat, Dec 23, 2017 at 11:15:35PM +0100, Tomas Härdin wrote:
> > 
> 
> [...]
> > +static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
> > +{
> > +int mode = avpriv_codec2_mode_from_extradata(st->codecpar->extradata);
> > +
> > +st->codecpar->codec_type= AVMEDIA_TYPE_AUDIO;
> > +st->codecpar->codec_id  = AV_CODEC_ID_CODEC2;
> > +st->codecpar->sample_rate   = 8000;
> > +st->codecpar->channels  = 1;
> > +st->codecpar->format= AV_SAMPLE_FMT_S16;
> > +st->codecpar->channel_layout= AV_CH_LAYOUT_MONO;
> > +st->codecpar->bit_rate  = avpriv_codec2_mode_bit_rate(s, mode);
> > +st->codecpar->frame_size= avpriv_codec2_mode_frame_size(s, 
> > mode);
> > +st->codecpar->block_align   = avpriv_codec2_mode_block_align(s, 
> > mode);
> > +
> > +if (st->codecpar->bit_rate <= 0 ||
> > +st->codecpar->frame_size <= 0 ||
> > +st->codecpar->block_align <= 0) {
> > +return AVERROR(EINVAL);
> > +}
> 
> This should be AVERROR_INVALIDDATA i think

OK, seem reasonable. It will typically be triggered by invalid mode

> > +
> > +avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
> > +
> > +//replicating estimate_timings_from_bit_rate() in utils.c to avoid 
> > warnings
> > +if (s->pb && st->codecpar->bit_rate > 0) {
> > +int64_t filesize = avio_size(s->pb);
> > +if (filesize > s->internal->data_offset) {
> > +filesize -= s->internal->data_offset;
> > +st->duration = av_rescale(8 * filesize,
> > +  st->time_base.den,
> > +  st->codecpar->bit_rate * (int64_t) 
> > st->time_base.num);
> > +}
> > +}
> 
> Is this exact ?
> or is a calculation from frame_size / block_align more accurate ?
> the most accurate one should be used

bit_rate is derived from block_align and frame_size in codec2utils.c so
either would be fine.

It strikes me that a better solution would be to suppress the
"Estimating duration from bitrate, this may be inaccurate" warning for
CBR formats. Removed this hunk for now.

> > +static int codec2_read_header(AVFormatContext *s)
> > +{
> > +[...]
> > +avio_read(s->pb, st->codecpar->extradata, 
> > AVPRIV_CODEC2_EXTRADATA_SIZE);
> 
> The return codes from avio_read and not checked

Replaced with ffio_read_size() and checking for AVERROR

mån 2018-01-15 klockan 00:32 +0100 skrev Carl Eugen Hoyos:
> > 2017-12-23 23:15 GMT+01:00 Tomas Härdin :
> 
> > +//check for 0xC0DEC2, return non-zero if it doesn't match
> > +static int check_magic(uint8_t *ptr) {
> > +return memcmp(ptr, avpriv_codec2_magic, 3);
> 
> AV_RB24(), or do I miss something?

Good idea. Replaced some of the related read/write functions with
avio_rb24/wb24 too

> 
> > +static int codec2_probe(AVProbeData *p)
> > +{
> > +int score;
> > +
> > +//must be at least 7 bytes and start wih 0xC0DEC2
> > +if (p->buf_size < AVPRIV_CODEC2_HEADER_SIZE ||
> 
> This check is unneeded.

Good, removed

> > check_magic(p->buf)) {
> 
> +return 0;
> +}
> +
> +//no .c2 files prior to 0.8
> 
> +if (p->buf[3] == 0 && p->buf[4] < 8) {
> 
> You chose to define the versions, please use the defines here.

Fixed

> +return 0;
> +}
> +
> +//give a poor score if major version doesn't match
> +//this allows such files to be detected at least, even if we
> can't do much with them
> +if (p->buf[3] != EXPECTED_CODEC2_MAJOR_VERSION) {
> +return AVPROBE_SCORE_MAX/10;
> +}
> 
> That may be ok.

Actually, I feel like being more strict and coordinating future format
changes with the FreeDV folks. Changed this to rejecting major != 0.

> +//if the minor version is known, no unknown mode is used and no
> flags are set then -> max score,
> +//else penalize 20% for each byte outside of expectations
> +//this way if only the first four bytes are OK then we're
> slightly less than AVPROBE_SCORE_MAX/2
> +//cap score at max-1 unless file extension is .c2
> +score = AVPROBE_SCORE_MAX;
> 
> +if (!av_match_ext(p->filename, "c2"))   score -= 1;
> 
> We don't do this for any other demuxer, if this makes sense, it should
> be done in general code, not for a specific demuxer imo.

Removed it, see below.

> +if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
> AVPROBE_SCORE_MAX/5;
> +if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
> AVPROBE_SCORE_MAX/5;
> +if (p->buf[6] != 0) score -=
> AVPROBE_SCORE_MAX/5;
> +return score;
> 
> Imo, this is too complicated:
> If the first 32bit are correct, return MAX/2, for 24bit, return less
> 
> Returning MAX for less than 64bit seems wrong to me.

I think my reasoning was that if everything is within what the FreeDV
tools are currently 

Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-01-14 Thread Carl Eugen Hoyos
2017-12-23 23:15 GMT+01:00 Tomas Härdin :

> +//check for 0xC0DEC2, return non-zero if it doesn't match
> +static int check_magic(uint8_t *ptr) {

> +return memcmp(ptr, avpriv_codec2_magic, 3);

AV_RB24(), or do I miss something?

> +static int codec2_probe(AVProbeData *p)
> +{
> +int score;
> +
> +//must be at least 7 bytes and start wih 0xC0DEC2

> +if (p->buf_size < AVPRIV_CODEC2_HEADER_SIZE ||

This check is unneeded.

> check_magic(p->buf)) {
+return 0;
+}
+
+//no .c2 files prior to 0.8

+if (p->buf[3] == 0 && p->buf[4] < 8) {

You chose to define the versions, please use the defines here.

+return 0;
+}
+
+//give a poor score if major version doesn't match
+//this allows such files to be detected at least, even if we
can't do much with them
+if (p->buf[3] != EXPECTED_CODEC2_MAJOR_VERSION) {
+return AVPROBE_SCORE_MAX/10;
+}

That may be ok.

+//if the minor version is known, no unknown mode is used and no
flags are set then -> max score,
+//else penalize 20% for each byte outside of expectations
+//this way if only the first four bytes are OK then we're
slightly less than AVPROBE_SCORE_MAX/2
+//cap score at max-1 unless file extension is .c2
+score = AVPROBE_SCORE_MAX;

+if (!av_match_ext(p->filename, "c2"))   score -= 1;

We don't do this for any other demuxer, if this makes sense, it should
be done in general code, not for a specific demuxer imo.

+if (p->buf[4] >  EXPECTED_CODEC2_MINOR_VERSION) score -=
AVPROBE_SCORE_MAX/5;
+if (p->buf[5] >  AVPRIV_CODEC2_MODE_MAX)score -=
AVPROBE_SCORE_MAX/5;
+if (p->buf[6] != 0) score -=
AVPROBE_SCORE_MAX/5;
+return score;

Imo, this is too complicated:
If the first 32bit are correct, return MAX/2, for 24bit, return less

Returning MAX for less than 64bit seems wrong to me.

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/3] Add muxer/demuxer for raw codec2 and .c2 files

2018-01-12 Thread Michael Niedermayer
On Sat, Dec 23, 2017 at 11:15:35PM +0100, Tomas Härdin wrote:
> 

[...]
> +static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
> +{
> +int mode = avpriv_codec2_mode_from_extradata(st->codecpar->extradata);
> +
> +st->codecpar->codec_type= AVMEDIA_TYPE_AUDIO;
> +st->codecpar->codec_id  = AV_CODEC_ID_CODEC2;
> +st->codecpar->sample_rate   = 8000;
> +st->codecpar->channels  = 1;
> +st->codecpar->format= AV_SAMPLE_FMT_S16;
> +st->codecpar->channel_layout= AV_CH_LAYOUT_MONO;
> +st->codecpar->bit_rate  = avpriv_codec2_mode_bit_rate(s, mode);
> +st->codecpar->frame_size= avpriv_codec2_mode_frame_size(s, mode);
> +st->codecpar->block_align   = avpriv_codec2_mode_block_align(s, 
> mode);
> +

> +if (st->codecpar->bit_rate <= 0 ||
> +st->codecpar->frame_size <= 0 ||
> +st->codecpar->block_align <= 0) {
> +return AVERROR(EINVAL);
> +}

This should be AVERROR_INVALIDDATA i think


> +
> +avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
> +
> +//replicating estimate_timings_from_bit_rate() in utils.c to avoid 
> warnings
> +if (s->pb && st->codecpar->bit_rate > 0) {
> +int64_t filesize = avio_size(s->pb);
> +if (filesize > s->internal->data_offset) {
> +filesize -= s->internal->data_offset;
> +st->duration = av_rescale(8 * filesize,
> +  st->time_base.den,
> +  st->codecpar->bit_rate * (int64_t) 
> st->time_base.num);
> +}
> +}

Is this exact ?
or is a calculation from frame_size / block_align more accurate ?
the most accurate one should be used


> +
> +return 0;
> +}
> +
> +static int codec2_read_header(AVFormatContext *s)
> +{
> +AVStream *st = avformat_new_stream(s, NULL);
> +int ret, version;
> +uint8_t magic[3];
> +
> +if (!st) {
> +return AVERROR(ENOMEM);
> +}
> +

> +avio_read(s->pb, magic, 3);
> +if (check_magic(magic)) {
> +av_log(s, AV_LOG_ERROR, "not a .c2 file\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +ret = ff_alloc_extradata(st->codecpar, AVPRIV_CODEC2_EXTRADATA_SIZE);
> +if (ret) {
> +return ret;
> +}
> +
> +avio_read(s->pb, st->codecpar->extradata, AVPRIV_CODEC2_EXTRADATA_SIZE);

The return codes from avio_read and not checked

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel