Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-03-07 Thread Aurelien Jacobs
On Mon, Mar 05, 2018 at 08:46:43PM +, Rostislav Pehlivanov wrote:
> On 3 March 2018 at 16:20, Aurelien Jacobs  wrote:
> 
> > On Thu, Mar 01, 2018 at 10:46:07PM +, Rostislav Pehlivanov wrote:
> > > On 1 March 2018 at 20:45, Aurelien Jacobs  wrote
> > >
> > > >
> > > > So what I propose is to rename sbc_delay to sbc_latency (for example),
> > > > and to add a opus_latecy using AV_OPT_TYPE_DURATION that will deprecate
> > > > opus_delay. I think that's the best way forward if you care about
> > > > consistency.
> > > >
> > >
> > > Yeah, that's great as long as that patch gets accepted.
> >
> > Any other issue left ?
> > If not, I will apply this patch series in a few days.
> >
> 
> Go ahead, everything seems fine now.

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


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-03-05 Thread Rostislav Pehlivanov
On 3 March 2018 at 16:20, Aurelien Jacobs  wrote:

> On Thu, Mar 01, 2018 at 10:46:07PM +, Rostislav Pehlivanov wrote:
> > On 1 March 2018 at 20:45, Aurelien Jacobs  wrote
> >
> > >
> > > So what I propose is to rename sbc_delay to sbc_latency (for example),
> > > and to add a opus_latecy using AV_OPT_TYPE_DURATION that will deprecate
> > > opus_delay. I think that's the best way forward if you care about
> > > consistency.
> > >
> >
> > Yeah, that's great as long as that patch gets accepted.
>
> Any other issue left ?
> If not, I will apply this patch series in a few days.
>

Go ahead, everything seems fine now.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-03-03 Thread Aurelien Jacobs
On Thu, Mar 01, 2018 at 10:46:07PM +, Rostislav Pehlivanov wrote:
> On 1 March 2018 at 20:45, Aurelien Jacobs  wrote
> 
> >
> > So what I propose is to rename sbc_delay to sbc_latency (for example),
> > and to add a opus_latecy using AV_OPT_TYPE_DURATION that will deprecate
> > opus_delay. I think that's the best way forward if you care about
> > consistency.
> >
> 
> Yeah, that's great as long as that patch gets accepted.

Any other issue left ?
If not, I will apply this patch series in a few days.

> "unlike everything else" ???
> > What is everything else ?
> > Do you have codecs example other than Opus that use foat milliseconds ?
> >
> 
> I didn't mention they had to allow configuring the latency, I was referring
> to audio codecs in general. So that leaves, like I said, pretty much all
> audio codecs made since ever. Suprisingly including bluetooth ones. Given
> how much of a pain they are you'd think they use beardseconds.

Oh, I initially thought you where talking specificially about codec
private options. If you where talking about the fact that most audio
codecs have a latency expressed in few milliseconds I of course agree.
And I also agree it is a good thing for end users to be able to express
these latency options in milliseconds.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-03-01 Thread Rostislav Pehlivanov
On 1 March 2018 at 20:45, Aurelien Jacobs  wrote

>
> So what I propose is to rename sbc_delay to sbc_latency (for example),
> and to add a opus_latecy using AV_OPT_TYPE_DURATION that will deprecate
> opus_delay. I think that's the best way forward if you care about
> consistency.
>

Yeah, that's great as long as that patch gets accepted.


"unlike everything else" ???
> What is everything else ?
> Do you have codecs example other than Opus that use foat milliseconds ?
>

I didn't mention they had to allow configuring the latency, I was referring
to audio codecs in general. So that leaves, like I said, pretty much all
audio codecs made since ever. Suprisingly including bluetooth ones. Given
how much of a pain they are you'd think they use beardseconds.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-03-01 Thread Aurelien Jacobs
On Thu, Mar 01, 2018 at 01:27:06AM +, Rostislav Pehlivanov wrote:
> On 28 February 2018 at 23:34, Aurelien Jacobs  wrote:
> 
> > On Wed, Feb 28, 2018 at 12:59:40AM +, Rostislav Pehlivanov wrote:
> > > On 27 February 2018 at 23:56, Aurelien Jacobs  wrote:
> > >
> > > >
> > > > So I've updated the patch with only a msbc and a delay option and
> > > > I've added some sane parameters decisions, mainly based on the
> > following
> > > > study :
> > > > https://pdfs.semanticscholar.org/1f19/561d03bc88b67728375566c95bbf77
> > > > e730d5.pdf
> > > > This seems to give pretty good results.
> > > >
> > > >
> > > I think you ought to use a float for this, like:
> > >
> > > >{ "sbc_delay", "Maximum delay in milliseconds", offsetof(,
> > > ), AV_OPT_TYPE_FLOAT, { .dbl =  },
> > ,
> > > , ,  },
> >
> > Why would I want to use float for this ??
> > AV_OPT_TYPE_DURATION is more appropriate for this. It has microsecond
> > precision which is more than enough, and you can still use a "float"
> > string as a parameter (eg. -sbc_delay 0.0035 for a 3.5 ms maximum delay).
> >
> >
> The unit is the issue. AV_OPT_TYPE_DURATION expects a duration in seconds,
> but all codecs (except .ape) have frame sizes expressible in a (near)
> integer amount of milliseconds, this included.

AV_OPT_TYPE_DURATION supports various input format. There is no reason
it can't support milliseconds or microseconds input.
I've just sent a patch to implement exactly this.

> Take a look at both Opus
> encoders, they both use a unit of milliseconds in their avopts to set frame
> durations. Having a codec which uses seconds unlike everything else isn't
> right (and we the same issue just a month ago with a timeout option).
> You don't have to use a float, you can use an int as well as long as frame
> sizes are an integer number of milliseconds.

"unlike everything else" ???
What is everything else ?
Do you have codecs example other than Opus that use foat milliseconds ?

I don't see much in avcodec, but in avformat there are various similar
examples:
- http: reconnect_delay_max (INT in seconds)
- gifdec: min_delay, max_gif_delay... (INT in hundredths of seconds)
- mpegenc: preload (INT in microseconds)

That's what happens when each codec/muxer uses a simple number type
(INT or FLOAT) and picks it's prefered unit. Total inconsistency !

That's what AV_OPT_TYPE_DURATION avoids, by preventing each codec to
pick a unit (it gives microseconds to everyone which should fit pretty
much all situations) and by allowing users to enter parameters in a
convinient way whatever the most appropiate unit is.
Consitency across the codebase using a common parameter parser and
a common internal unit (microsecond).

So what I propose is to rename sbc_delay to sbc_latency (for example),
and to add a opus_latecy using AV_OPT_TYPE_DURATION that will deprecate
opus_delay. I think that's the best way forward if you care about
consistency.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-28 Thread Rostislav Pehlivanov
On 28 February 2018 at 23:34, Aurelien Jacobs  wrote:

> On Wed, Feb 28, 2018 at 12:59:40AM +, Rostislav Pehlivanov wrote:
> > On 27 February 2018 at 23:56, Aurelien Jacobs  wrote:
> >
> > >
> > > So I've updated the patch with only a msbc and a delay option and
> > > I've added some sane parameters decisions, mainly based on the
> following
> > > study :
> > > https://pdfs.semanticscholar.org/1f19/561d03bc88b67728375566c95bbf77
> > > e730d5.pdf
> > > This seems to give pretty good results.
> > >
> > >
> > I think you ought to use a float for this, like:
> >
> > >{ "sbc_delay", "Maximum delay in milliseconds", offsetof(,
> > ), AV_OPT_TYPE_FLOAT, { .dbl =  },
> ,
> > , ,  },
>
> Why would I want to use float for this ??
> AV_OPT_TYPE_DURATION is more appropriate for this. It has microsecond
> precision which is more than enough, and you can still use a "float"
> string as a parameter (eg. -sbc_delay 0.0035 for a 3.5 ms maximum delay).
>
>
The unit is the issue. AV_OPT_TYPE_DURATION expects a duration in seconds,
but all codecs (except .ape) have frame sizes expressible in a (near)
integer amount of milliseconds, this included. Take a look at both Opus
encoders, they both use a unit of milliseconds in their avopts to set frame
durations. Having a codec which uses seconds unlike everything else isn't
right (and we the same issue just a month ago with a timeout option).
You don't have to use a float, you can use an int as well as long as frame
sizes are an integer number of milliseconds.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-28 Thread Aurelien Jacobs
On Wed, Feb 28, 2018 at 12:59:40AM +, Rostislav Pehlivanov wrote:
> On 27 February 2018 at 23:56, Aurelien Jacobs  wrote:
> 
> >
> > So I've updated the patch with only a msbc and a delay option and
> > I've added some sane parameters decisions, mainly based on the following
> > study :
> > https://pdfs.semanticscholar.org/1f19/561d03bc88b67728375566c95bbf77
> > e730d5.pdf
> > This seems to give pretty good results.
> >
> >
> I think you ought to use a float for this, like:
> 
> >{ "sbc_delay", "Maximum delay in milliseconds", offsetof(,
> ), AV_OPT_TYPE_FLOAT, { .dbl =  }, ,
> , ,  },

Why would I want to use float for this ??
AV_OPT_TYPE_DURATION is more appropriate for this. It has microsecond
precision which is more than enough, and you can still use a "float"
string as a parameter (eg. -sbc_delay 0.0035 for a 3.5 ms maximum delay).

> Apart from that, what's up with the weird if (!sbc->init) { } block in the
> main encoding function? Shouldn't that be done in sbc_encode_init()?

I seem to remember there was a good reason for this initially, but the
code went thru quite some refactoring since then, and there is no good
reason for this anymore.
I've now cleaned up and simplified this init code.
>From 64ee3867bf8f90d51734d1ee2de4b09f471308b4 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs 
Date: Sun, 17 Dec 2017 19:59:30 +0100
Subject: [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 doc/general.texi   |   2 +-
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/avcodec.h   |   2 +
 libavcodec/options_table.h |   1 +
 libavcodec/profiles.c  |   5 +
 libavcodec/profiles.h  |   1 +
 libavcodec/sbcdsp.c| 382 +
 libavcodec/sbcdsp.h|  83 ++
 libavcodec/sbcdsp_data.c   | 329 ++
 libavcodec/sbcdsp_data.h   |  55 +++
 libavcodec/sbcenc.c| 361 ++
 12 files changed, 1222 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/sbcdsp.c
 create mode 100644 libavcodec/sbcdsp.h
 create mode 100644 libavcodec/sbcdsp_data.c
 create mode 100644 libavcodec/sbcdsp_data.h
 create mode 100644 libavcodec/sbcenc.c

diff --git a/doc/general.texi b/doc/general.texi
index 5827af3841..de13a7695e 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1142,7 +1142,7 @@ following image formats are supported:
 @tab Real low bitrate AC-3 codec
 @item RealAudio Lossless @tab @tab  X
 @item RealAudio SIPR / ACELP.NET @tab @tab  X
-@item SBC (low-complexity subband codec) @tab @tab  X
+@item SBC (low-complexity subband codec) @tab  X  @tab  X
 @tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 01bc15d9b7..ff6c9f8b2c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -588,6 +588,7 @@ OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER) += sunrastenc.o
 OBJS-$(CONFIG_LIBRSVG_DECODER) += librsvgdec.o
 OBJS-$(CONFIG_SBC_DECODER) += sbcdec.o sbcdec_data.o sbc.o
+OBJS-$(CONFIG_SBC_ENCODER) += sbcenc.o sbc.o sbcdsp.o sbcdsp_data.o
 OBJS-$(CONFIG_SVQ1_DECODER)+= svq1dec.o svq1.o svq13.o h263data.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= svq1enc.o svq1.o  h263data.o  \
   h263.o ituh263enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4ddf92f006..71719595c6 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -453,6 +453,7 @@ extern AVCodec ff_ra_144_encoder;
 extern AVCodec ff_ra_144_decoder;
 extern AVCodec ff_ra_288_decoder;
 extern AVCodec ff_ralf_decoder;
+extern AVCodec ff_sbc_encoder;
 extern AVCodec ff_sbc_decoder;
 extern AVCodec ff_shorten_decoder;
 extern AVCodec ff_sipr_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 769f210c07..a8322fb62a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2926,6 +2926,8 @@ typedef struct AVCodecContext {
 #define FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS0xc3
 #define FF_PROFILE_MJPEG_JPEG_LS 0xf7
 
+#define FF_PROFILE_SBC_MSBC 1
+
 /**
  * level
  * - encoding: Set by user.
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index ac9ce4b301..5a5eae65fb 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -300,6 +300,7 @@ static const AVOption avcodec_options[] = {
 {"mpeg4_main", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_MAIN }, INT_MIN, INT_MAX, V|E, "profile"},
 {"mpeg4_asp",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_PROFILE_MPEG4_ADVANCED_SIMPLE }, INT_MIN, INT_MAX, V|E, 

Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-27 Thread Rostislav Pehlivanov
On 27 February 2018 at 23:56, Aurelien Jacobs  wrote:

>
> So I've updated the patch with only a msbc and a delay option and
> I've added some sane parameters decisions, mainly based on the following
> study :
> https://pdfs.semanticscholar.org/1f19/561d03bc88b67728375566c95bbf77
> e730d5.pdf
> This seems to give pretty good results.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
I think you ought to use a float for this, like:

>{ "sbc_delay", "Maximum delay in milliseconds", offsetof(,
), AV_OPT_TYPE_FLOAT, { .dbl =  }, ,
, ,  },

Apart from that, what's up with the weird if (!sbc->init) { } block in the
main encoding function? Shouldn't that be done in sbc_encode_init()?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-27 Thread Aurelien Jacobs
On Sat, Feb 24, 2018 at 09:31:30PM +, Rostislav Pehlivanov wrote:
> On 24 February 2018 at 12:01, Aurelien Jacobs  wrote:
> 
> > On Thu, Feb 22, 2018 at 06:18:48PM +, Rostislav Pehlivanov wrote:
> > > On 21 February 2018 at 22:37, Aurelien Jacobs  wrote:
> > >
> > > > This was originally based on libsbc, and was fully integrated into
> > ffmpeg.
> > > > ---
> > > >  doc/general.texi |   2 +-
> > > >  libavcodec/Makefile  |   1 +
> > > >  libavcodec/allcodecs.c   |   1 +
> > > >  libavcodec/sbcdsp.c  | 382 ++
> > > > +
> > > >  libavcodec/sbcdsp.h  |  83 ++
> > > >  libavcodec/sbcdsp_data.c | 329 +
> > > >  libavcodec/sbcdsp_data.h |  55 +++
> > > >  libavcodec/sbcenc.c  | 411 ++
> > > > +
> > > >  8 files changed, 1263 insertions(+), 1 deletion(-)
> > > >  create mode 100644 libavcodec/sbcdsp.c
> > > >  create mode 100644 libavcodec/sbcdsp.h
> > > >  create mode 100644 libavcodec/sbcdsp_data.c
> > > >  create mode 100644 libavcodec/sbcdsp_data.h
> > > >  create mode 100644 libavcodec/sbcenc.c
> > > >
> > > > +
> > > > +#define OFFSET(x) offsetof(SBCEncContext, x)
> > > > +#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> > > > +static const AVOption options[] = {
> > > > +{ "joint_stereo", "use joint stereo",
> > > > +  OFFSET(joint_stereo), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1,
> > AE },
> > > >
> > > +{ "dual_channel", "use dual channel",
> > > > +  OFFSET(dual_channel), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1,
> > AE },
> > > >
> > >
> > > Erm those 2 things should be decided by the encoder, not by exposing them
> > > to the user. The encoder should decide which mode has lower distortion
> > for
> > > a given signal.
> >
> > See bellow.
> >
> > > > +{ "subbands", "number of subbands (4 or 8)",
> > > > +  OFFSET(subbands), AV_OPT_TYPE_INT,  { .i64 =  8 }, 4,   8,
> > AE },
> > > >
> > >
> > > The encoder doesn't check if the value isn't 4 or 8 so 5, 6 and 7 are all
> > > accepted. Similar issue to the previous option too.
> >
> > OK, fixed.
> >
> > > > +{ "bitpool",  "bitpool value",
> > > > +  OFFSET(bitpool),  AV_OPT_TYPE_INT,  { .i64 = 32 }, 0, 255,
> > AE },
> > > >
> > >
> > > This should be controlled by the bitrate setting. Either have a function
> > to
> > > translate bitrate to bitpool value or a table which approximately maps
> > > bitrate values supplied to bitpools. You could expose it directly as well
> > > as mapping it to a bitrate value by using the global_quality setting so
> > it
> > > shouldn't be a custom encoder option.
> >
> > Indeed, this is better this way, thanks for the suggestion.
> >
> > > > +{ "blocks",   "number of blocks (4, 8, 12 or 16)",
> > > > +  OFFSET(blocks),   AV_OPT_TYPE_INT,  { .i64 = 16 }, 4,  16,
> > AE },
> > > > +{ "snr",  "use SNR mode (instead of loudness)",
> > > > +  OFFSET(allocation),   AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1,
> > AE },
> > > >
> > >
> > > SNR mode too needs to be decided by the encoder rather than exposing it
> > as
> > > a setting.
> >
> > See bellow.
> >
> > > > +{ "msbc", "use mSBC mode (wideband speech mono SBC)",
> > > >
> > >
> > > Add a profile fallback setting for this as well, like in aac where
> > -aac_ltp
> > > turns LTP mode on and -profile:a aac_ltp does the same.
> >
> > Not sure of the benefits of having 2 redundant way to do this, but OK.
> >
> > > You don't have to make the encoder decide which stereo coupling mode or
> > > snr/loudness setting to use, you can implement that with a later patch.
> > > I think you should remove the "blocks" and "subbands" settings as well
> > and
> > > instead replace those with a single "latency" setting like the native
> > Opus
> > > encoder in milliseconds which would adjust both of them on init to set
> > the
> > > frame size. This would also allow the encoder to change them. Again, you
> > > don't have to do this now, you can send a patch which adds a "latency"
> > > option later.
> >
> > I can see the value in what you propose, and I think that indeed, it
> > would be great for the encoder to choose by itself the most appropriate
> > parameters by default.
> > But on the other hand, we are talking about a codec targetting some
> > hardware decoders (blutetooth speakers, headsets...), and all those
> > parameters have to be negotiated between the encoder and the hardware
> > decoder. So I think it is mandatory to keep all those parameters
> > accessible to be able to setup the encoder according to the target
> > hardware capabilities.
> >
> >
> Hardware isn't as limited as you might think it is, and there's also no
> negotiation happening between encoders and decoders IRL (except for modern
> streaming protocols which suck). While its true that we've had some issues
> with 

Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-24 Thread Rostislav Pehlivanov
On 24 February 2018 at 12:01, Aurelien Jacobs  wrote:

> On Thu, Feb 22, 2018 at 06:18:48PM +, Rostislav Pehlivanov wrote:
> > On 21 February 2018 at 22:37, Aurelien Jacobs  wrote:
> >
> > > This was originally based on libsbc, and was fully integrated into
> ffmpeg.
> > > ---
> > >  doc/general.texi |   2 +-
> > >  libavcodec/Makefile  |   1 +
> > >  libavcodec/allcodecs.c   |   1 +
> > >  libavcodec/sbcdsp.c  | 382 ++
> > > +
> > >  libavcodec/sbcdsp.h  |  83 ++
> > >  libavcodec/sbcdsp_data.c | 329 +
> > >  libavcodec/sbcdsp_data.h |  55 +++
> > >  libavcodec/sbcenc.c  | 411 ++
> > > +
> > >  8 files changed, 1263 insertions(+), 1 deletion(-)
> > >  create mode 100644 libavcodec/sbcdsp.c
> > >  create mode 100644 libavcodec/sbcdsp.h
> > >  create mode 100644 libavcodec/sbcdsp_data.c
> > >  create mode 100644 libavcodec/sbcdsp_data.h
> > >  create mode 100644 libavcodec/sbcenc.c
> > >
> > > +
> > > +#define OFFSET(x) offsetof(SBCEncContext, x)
> > > +#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> > > +static const AVOption options[] = {
> > > +{ "joint_stereo", "use joint stereo",
> > > +  OFFSET(joint_stereo), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1,
> AE },
> > >
> > +{ "dual_channel", "use dual channel",
> > > +  OFFSET(dual_channel), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1,
> AE },
> > >
> >
> > Erm those 2 things should be decided by the encoder, not by exposing them
> > to the user. The encoder should decide which mode has lower distortion
> for
> > a given signal.
>
> See bellow.
>
> > > +{ "subbands", "number of subbands (4 or 8)",
> > > +  OFFSET(subbands), AV_OPT_TYPE_INT,  { .i64 =  8 }, 4,   8,
> AE },
> > >
> >
> > The encoder doesn't check if the value isn't 4 or 8 so 5, 6 and 7 are all
> > accepted. Similar issue to the previous option too.
>
> OK, fixed.
>
> > > +{ "bitpool",  "bitpool value",
> > > +  OFFSET(bitpool),  AV_OPT_TYPE_INT,  { .i64 = 32 }, 0, 255,
> AE },
> > >
> >
> > This should be controlled by the bitrate setting. Either have a function
> to
> > translate bitrate to bitpool value or a table which approximately maps
> > bitrate values supplied to bitpools. You could expose it directly as well
> > as mapping it to a bitrate value by using the global_quality setting so
> it
> > shouldn't be a custom encoder option.
>
> Indeed, this is better this way, thanks for the suggestion.
>
> > > +{ "blocks",   "number of blocks (4, 8, 12 or 16)",
> > > +  OFFSET(blocks),   AV_OPT_TYPE_INT,  { .i64 = 16 }, 4,  16,
> AE },
> > > +{ "snr",  "use SNR mode (instead of loudness)",
> > > +  OFFSET(allocation),   AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1,
> AE },
> > >
> >
> > SNR mode too needs to be decided by the encoder rather than exposing it
> as
> > a setting.
>
> See bellow.
>
> > > +{ "msbc", "use mSBC mode (wideband speech mono SBC)",
> > >
> >
> > Add a profile fallback setting for this as well, like in aac where
> -aac_ltp
> > turns LTP mode on and -profile:a aac_ltp does the same.
>
> Not sure of the benefits of having 2 redundant way to do this, but OK.
>
> > You don't have to make the encoder decide which stereo coupling mode or
> > snr/loudness setting to use, you can implement that with a later patch.
> > I think you should remove the "blocks" and "subbands" settings as well
> and
> > instead replace those with a single "latency" setting like the native
> Opus
> > encoder in milliseconds which would adjust both of them on init to set
> the
> > frame size. This would also allow the encoder to change them. Again, you
> > don't have to do this now, you can send a patch which adds a "latency"
> > option later.
>
> I can see the value in what you propose, and I think that indeed, it
> would be great for the encoder to choose by itself the most appropriate
> parameters by default.
> But on the other hand, we are talking about a codec targetting some
> hardware decoders (blutetooth speakers, headsets...), and all those
> parameters have to be negotiated between the encoder and the hardware
> decoder. So I think it is mandatory to keep all those parameters
> accessible to be able to setup the encoder according to the target
> hardware capabilities.
>
>
Hardware isn't as limited as you might think it is, and there's also no
negotiation happening between encoders and decoders IRL (except for modern
streaming protocols which suck). While its true that we've had some issues
with hardware decoders not supporting rarely used features we wait for
users to report them and don't assume that all hardware violates the specs.
And looking at the code, only 2 settings strike out as being able to cause
issues: the frame size, controlled by subbands and blocks and the msbc
mode. There's no way in 

Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-24 Thread Aurelien Jacobs
On Thu, Feb 22, 2018 at 06:18:48PM +, Rostislav Pehlivanov wrote:
> On 21 February 2018 at 22:37, Aurelien Jacobs  wrote:
> 
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> >  doc/general.texi |   2 +-
> >  libavcodec/Makefile  |   1 +
> >  libavcodec/allcodecs.c   |   1 +
> >  libavcodec/sbcdsp.c  | 382 ++
> > +
> >  libavcodec/sbcdsp.h  |  83 ++
> >  libavcodec/sbcdsp_data.c | 329 +
> >  libavcodec/sbcdsp_data.h |  55 +++
> >  libavcodec/sbcenc.c  | 411 ++
> > +
> >  8 files changed, 1263 insertions(+), 1 deletion(-)
> >  create mode 100644 libavcodec/sbcdsp.c
> >  create mode 100644 libavcodec/sbcdsp.h
> >  create mode 100644 libavcodec/sbcdsp_data.c
> >  create mode 100644 libavcodec/sbcdsp_data.h
> >  create mode 100644 libavcodec/sbcenc.c
> >
> > +
> > +#define OFFSET(x) offsetof(SBCEncContext, x)
> > +#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> > +static const AVOption options[] = {
> > +{ "joint_stereo", "use joint stereo",
> > +  OFFSET(joint_stereo), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1, AE },
> >
> +{ "dual_channel", "use dual channel",
> > +  OFFSET(dual_channel), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1, AE },
> >
> 
> Erm those 2 things should be decided by the encoder, not by exposing them
> to the user. The encoder should decide which mode has lower distortion for
> a given signal.

See bellow.

> > +{ "subbands", "number of subbands (4 or 8)",
> > +  OFFSET(subbands), AV_OPT_TYPE_INT,  { .i64 =  8 }, 4,   8, AE },
> >
> 
> The encoder doesn't check if the value isn't 4 or 8 so 5, 6 and 7 are all
> accepted. Similar issue to the previous option too.

OK, fixed.

> > +{ "bitpool",  "bitpool value",
> > +  OFFSET(bitpool),  AV_OPT_TYPE_INT,  { .i64 = 32 }, 0, 255, AE },
> >
> 
> This should be controlled by the bitrate setting. Either have a function to
> translate bitrate to bitpool value or a table which approximately maps
> bitrate values supplied to bitpools. You could expose it directly as well
> as mapping it to a bitrate value by using the global_quality setting so it
> shouldn't be a custom encoder option.

Indeed, this is better this way, thanks for the suggestion.

> > +{ "blocks",   "number of blocks (4, 8, 12 or 16)",
> > +  OFFSET(blocks),   AV_OPT_TYPE_INT,  { .i64 = 16 }, 4,  16, AE },
> > +{ "snr",  "use SNR mode (instead of loudness)",
> > +  OFFSET(allocation),   AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1, AE },
> >
> 
> SNR mode too needs to be decided by the encoder rather than exposing it as
> a setting.

See bellow.

> > +{ "msbc", "use mSBC mode (wideband speech mono SBC)",
> >
> 
> Add a profile fallback setting for this as well, like in aac where -aac_ltp
> turns LTP mode on and -profile:a aac_ltp does the same.

Not sure of the benefits of having 2 redundant way to do this, but OK.

> You don't have to make the encoder decide which stereo coupling mode or
> snr/loudness setting to use, you can implement that with a later patch.
> I think you should remove the "blocks" and "subbands" settings as well and
> instead replace those with a single "latency" setting like the native Opus
> encoder in milliseconds which would adjust both of them on init to set the
> frame size. This would also allow the encoder to change them. Again, you
> don't have to do this now, you can send a patch which adds a "latency"
> option later.

I can see the value in what you propose, and I think that indeed, it
would be great for the encoder to choose by itself the most appropriate
parameters by default.
But on the other hand, we are talking about a codec targetting some
hardware decoders (blutetooth speakers, headsets...), and all those
parameters have to be negotiated between the encoder and the hardware
decoder. So I think it is mandatory to keep all those parameters
accessible to be able to setup the encoder according to the target
hardware capabilities.

> Apart from that, I tested the encoder, valgrind looks clean, the SIMD is
> bitexact and all advertised samplerates are supported.

Great.

Updated patch attached.>From e0fa5e81606047e31c4f9d0c7773f82a044473f3 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs 
Date: Sun, 17 Dec 2017 19:59:30 +0100
Subject: [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 doc/general.texi   |   2 +-
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/avcodec.h   |   2 +
 libavcodec/options_table.h |   1 +
 libavcodec/profiles.c  |   5 +
 libavcodec/profiles.h  |   1 +
 libavcodec/sbcdsp.c| 382 +++
 libavcodec/sbcdsp.h

Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-22 Thread Rostislav Pehlivanov
On 21 February 2018 at 22:37, Aurelien Jacobs  wrote:

> This was originally based on libsbc, and was fully integrated into ffmpeg.
> ---
>  doc/general.texi |   2 +-
>  libavcodec/Makefile  |   1 +
>  libavcodec/allcodecs.c   |   1 +
>  libavcodec/sbcdsp.c  | 382 ++
> +
>  libavcodec/sbcdsp.h  |  83 ++
>  libavcodec/sbcdsp_data.c | 329 +
>  libavcodec/sbcdsp_data.h |  55 +++
>  libavcodec/sbcenc.c  | 411 ++
> +
>  8 files changed, 1263 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/sbcdsp.c
>  create mode 100644 libavcodec/sbcdsp.h
>  create mode 100644 libavcodec/sbcdsp_data.c
>  create mode 100644 libavcodec/sbcdsp_data.h
>  create mode 100644 libavcodec/sbcenc.c
>
> +
> +#define OFFSET(x) offsetof(SBCEncContext, x)
> +#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> +static const AVOption options[] = {
> +{ "joint_stereo", "use joint stereo",
> +  OFFSET(joint_stereo), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1, AE },
>
+{ "dual_channel", "use dual channel",
> +  OFFSET(dual_channel), AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1, AE },
>

Erm those 2 things should be decided by the encoder, not by exposing them
to the user. The encoder should decide which mode has lower distortion for
a given signal.



> +{ "subbands", "number of subbands (4 or 8)",
> +  OFFSET(subbands), AV_OPT_TYPE_INT,  { .i64 =  8 }, 4,   8, AE },
>

The encoder doesn't check if the value isn't 4 or 8 so 5, 6 and 7 are all
accepted. Similar issue to the previous option too.



> +{ "bitpool",  "bitpool value",
> +  OFFSET(bitpool),  AV_OPT_TYPE_INT,  { .i64 = 32 }, 0, 255, AE },
>

This should be controlled by the bitrate setting. Either have a function to
translate bitrate to bitpool value or a table which approximately maps
bitrate values supplied to bitpools. You could expose it directly as well
as mapping it to a bitrate value by using the global_quality setting so it
shouldn't be a custom encoder option.



> +{ "blocks",   "number of blocks (4, 8, 12 or 16)",
> +  OFFSET(blocks),   AV_OPT_TYPE_INT,  { .i64 = 16 }, 4,  16, AE },
> +{ "snr",  "use SNR mode (instead of loudness)",
> +  OFFSET(allocation),   AV_OPT_TYPE_BOOL, { .i64 =  0 }, 0,   1, AE },
>

SNR mode too needs to be decided by the encoder rather than exposing it as
a setting.



> +{ "msbc", "use mSBC mode (wideband speech mono SBC)",
>

Add a profile fallback setting for this as well, like in aac where -aac_ltp
turns LTP mode on and -profile:a aac_ltp does the same.


You don't have to make the encoder decide which stereo coupling mode or
snr/loudness setting to use, you can implement that with a later patch.
I think you should remove the "blocks" and "subbands" settings as well and
instead replace those with a single "latency" setting like the native Opus
encoder in milliseconds which would adjust both of them on init to set the
frame size. This would also allow the encoder to change them. Again, you
don't have to do this now, you can send a patch which adds a "latency"
option later.
So in total, only 2 options would be needed, "msbc" as an additional way to
use msbc and "latency", which can be added later. For now you should set
all unexposed options to do something safe by default.

Apart from that, I tested the encoder, valgrind looks clean, the SIMD is
bitexact and all advertised samplerates are supported.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2018-02-21 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 doc/general.texi |   2 +-
 libavcodec/Makefile  |   1 +
 libavcodec/allcodecs.c   |   1 +
 libavcodec/sbcdsp.c  | 382 +++
 libavcodec/sbcdsp.h  |  83 ++
 libavcodec/sbcdsp_data.c | 329 +
 libavcodec/sbcdsp_data.h |  55 +++
 libavcodec/sbcenc.c  | 411 +++
 8 files changed, 1263 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/sbcdsp.c
 create mode 100644 libavcodec/sbcdsp.h
 create mode 100644 libavcodec/sbcdsp_data.c
 create mode 100644 libavcodec/sbcdsp_data.h
 create mode 100644 libavcodec/sbcenc.c

diff --git a/doc/general.texi b/doc/general.texi
index 930c1e8bf2..bf62288f64 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1118,7 +1118,7 @@ following image formats are supported:
 @tab Real low bitrate AC-3 codec
 @item RealAudio Lossless @tab @tab  X
 @item RealAudio SIPR / ACELP.NET @tab @tab  X
-@item SBC (low-complexity subband codec) @tab @tab  X
+@item SBC (low-complexity subband codec) @tab  X  @tab  X
 @tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 53d199201b..ddae75bb9a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -584,6 +584,7 @@ OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER) += sunrastenc.o
 OBJS-$(CONFIG_LIBRSVG_DECODER) += librsvgdec.o
 OBJS-$(CONFIG_SBC_DECODER) += sbcdec.o sbcdec_data.o sbc.o
+OBJS-$(CONFIG_SBC_ENCODER) += sbcenc.o sbc.o sbcdsp.o sbcdsp_data.o
 OBJS-$(CONFIG_SVQ1_DECODER)+= svq1dec.o svq1.o svq13.o h263data.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= svq1enc.o svq1.o  h263data.o  \
   h263.o ituh263enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 7d9097dcf7..de3bea8bc0 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -453,6 +453,7 @@ extern AVCodec ff_ra_144_encoder;
 extern AVCodec ff_ra_144_decoder;
 extern AVCodec ff_ra_288_decoder;
 extern AVCodec ff_ralf_decoder;
+extern AVCodec ff_sbc_encoder;
 extern AVCodec ff_sbc_decoder;
 extern AVCodec ff_shorten_decoder;
 extern AVCodec ff_sipr_decoder;
diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
new file mode 100644
index 00..e155387f0d
--- /dev/null
+++ b/libavcodec/sbcdsp.c
@@ -0,0 +1,382 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs 
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann 
+ * Copyright (C) 2004-2005  Henryk Ploetz 
+ * Copyright (C) 2005-2006  Brad Midgley 
+ *
+ * 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
+ * SBC basic "building bricks"
+ */
+
+#include 
+#include 
+#include 
+#include "libavutil/common.h"
+#include "libavutil/intmath.h"
+#include "libavutil/intreadwrite.h"
+#include "sbc.h"
+#include "sbcdsp.h"
+#include "sbcdsp_data.h"
+
+/*
+ * A reference C code of analysis filter with SIMD-friendly tables
+ * reordering and code layout. This code can be used to develop platform
+ * specific SIMD optimizations. Also it may be used as some kind of test
+ * for compiler autovectorization capabilities (who knows, if the compiler
+ * is very good at this stuff, hand optimized assembly may be not strictly
+ * needed for some platform).
+ *
+ * Note: It is also possible to make a simple variant of analysis filter,
+ * which needs only a single constants table without taking care about
+ * even/odd cases. This simple variant of filter can be implemented without
+ * input data permutation. The only thing that would be lost is the
+ * possibility to use pairwise SIMD multiplications. But for some simple
+ * CPU cores without SIMD extensions it can be useful. If anybody is
+ * interested in implementing such variant of a filter, sourcecode from
+ * 

Re: [FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2017-12-23 Thread Aurelien Jacobs
Updated to match new identifier for CRC (AV_CRC_8_EBU).

>From 380c36ec392b066d4b70b0f9fd4957a595294f5a Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs 
Date: Sun, 17 Dec 2017 19:59:30 +0100
Subject: [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 doc/general.texi |   2 +-
 libavcodec/Makefile  |   2 +
 libavcodec/allcodecs.c   |   4 +-
 libavcodec/sbcdsp.c  | 382 
 libavcodec/sbcdsp.h  |  83 +
 libavcodec/sbcdsp_data.c | 329 +++
 libavcodec/sbcdsp_data.h |  55 ++
 libavcodec/sbcenc.c  | 443 +++
 8 files changed, 1297 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/sbcdsp.c
 create mode 100644 libavcodec/sbcdsp.h
 create mode 100644 libavcodec/sbcdsp_data.c
 create mode 100644 libavcodec/sbcdsp_data.h
 create mode 100644 libavcodec/sbcenc.c

diff --git a/doc/general.texi b/doc/general.texi
index 65aee47f2a..e5669b0e93 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1103,7 +1103,7 @@ following image formats are supported:
 @tab Real low bitrate AC-3 codec
 @item RealAudio Lossless @tab @tab  X
 @item RealAudio SIPR / ACELP.NET @tab @tab  X
-@item SBC (low-complexity subband codec) @tab @tab  X
+@item SBC (low-complexity subband codec) @tab  X  @tab  X
 @tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 58c8c6e499..d237deeefc 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -582,7 +582,9 @@ OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER) += sunrastenc.o
 OBJS-$(CONFIG_LIBRSVG_DECODER) += librsvgdec.o
 OBJS-$(CONFIG_SBC_DECODER) += sbcdec.o sbcdec_data.o sbc.o
+OBJS-$(CONFIG_SBC_ENCODER) += sbcenc.o sbc.o sbcdsp.o sbcdsp_data.o
 OBJS-$(CONFIG_MSBC_DECODER)+= sbcdec.o sbcdec_data.o sbc.o
+OBJS-$(CONFIG_MSBC_ENCODER)+= sbcenc.o sbc.o sbcdsp.o sbcdsp_data.o
 OBJS-$(CONFIG_SVQ1_DECODER)+= svq1dec.o svq1.o svq13.o h263data.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= svq1enc.o svq1.o  h263data.o  \
   h263.o ituh263enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 3e3b37f638..e5b3c20ec7 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -379,7 +379,7 @@ static void register_all(void)
 REGISTER_DECODER(MP3ON4FLOAT,   mp3on4float);
 REGISTER_DECODER(MPC7,  mpc7);
 REGISTER_DECODER(MPC8,  mpc8);
-REGISTER_DECODER(MSBC,  msbc);
+REGISTER_ENCDEC (MSBC,  msbc);
 REGISTER_ENCDEC (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
 REGISTER_ENCDEC (OPUS,  opus);
@@ -393,7 +393,7 @@ static void register_all(void)
 REGISTER_DECODER(SHORTEN,   shorten);
 REGISTER_DECODER(SIPR,  sipr);
 REGISTER_DECODER(SMACKAUD,  smackaud);
-REGISTER_DECODER(SBC,   sbc);
+REGISTER_ENCDEC (SBC,   sbc);
 REGISTER_ENCDEC (SONIC, sonic);
 REGISTER_ENCODER(SONIC_LS,  sonic_ls);
 REGISTER_DECODER(TAK,   tak);
diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
new file mode 100644
index 00..e155387f0d
--- /dev/null
+++ b/libavcodec/sbcdsp.c
@@ -0,0 +1,382 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs 
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann 
+ * Copyright (C) 2004-2005  Henryk Ploetz 
+ * Copyright (C) 2005-2006  Brad Midgley 
+ *
+ * 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
+ * SBC basic "building bricks"
+ */
+
+#include 
+#include 
+#include 
+#include "libavutil/common.h"
+#include 

[FFmpeg-devel] [PATCH 5/9] sbc: implement SBC encoder (low-complexity subband codec)

2017-12-23 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 doc/general.texi |   2 +-
 libavcodec/Makefile  |   2 +
 libavcodec/allcodecs.c   |   4 +-
 libavcodec/sbcdsp.c  | 382 
 libavcodec/sbcdsp.h  |  83 +
 libavcodec/sbcdsp_data.c | 329 +++
 libavcodec/sbcdsp_data.h |  55 ++
 libavcodec/sbcenc.c  | 443 +++
 8 files changed, 1297 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/sbcdsp.c
 create mode 100644 libavcodec/sbcdsp.h
 create mode 100644 libavcodec/sbcdsp_data.c
 create mode 100644 libavcodec/sbcdsp_data.h
 create mode 100644 libavcodec/sbcenc.c

diff --git a/doc/general.texi b/doc/general.texi
index 65aee47f2a..e5669b0e93 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1103,7 +1103,7 @@ following image formats are supported:
 @tab Real low bitrate AC-3 codec
 @item RealAudio Lossless @tab @tab  X
 @item RealAudio SIPR / ACELP.NET @tab @tab  X
-@item SBC (low-complexity subband codec) @tab @tab  X
+@item SBC (low-complexity subband codec) @tab  X  @tab  X
 @tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 58c8c6e499..d237deeefc 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -582,7 +582,9 @@ OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER) += sunrastenc.o
 OBJS-$(CONFIG_LIBRSVG_DECODER) += librsvgdec.o
 OBJS-$(CONFIG_SBC_DECODER) += sbcdec.o sbcdec_data.o sbc.o
+OBJS-$(CONFIG_SBC_ENCODER) += sbcenc.o sbc.o sbcdsp.o sbcdsp_data.o
 OBJS-$(CONFIG_MSBC_DECODER)+= sbcdec.o sbcdec_data.o sbc.o
+OBJS-$(CONFIG_MSBC_ENCODER)+= sbcenc.o sbc.o sbcdsp.o sbcdsp_data.o
 OBJS-$(CONFIG_SVQ1_DECODER)+= svq1dec.o svq1.o svq13.o h263data.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= svq1enc.o svq1.o  h263data.o  \
   h263.o ituh263enc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 3e3b37f638..e5b3c20ec7 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -379,7 +379,7 @@ static void register_all(void)
 REGISTER_DECODER(MP3ON4FLOAT,   mp3on4float);
 REGISTER_DECODER(MPC7,  mpc7);
 REGISTER_DECODER(MPC8,  mpc8);
-REGISTER_DECODER(MSBC,  msbc);
+REGISTER_ENCDEC (MSBC,  msbc);
 REGISTER_ENCDEC (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
 REGISTER_ENCDEC (OPUS,  opus);
@@ -393,7 +393,7 @@ static void register_all(void)
 REGISTER_DECODER(SHORTEN,   shorten);
 REGISTER_DECODER(SIPR,  sipr);
 REGISTER_DECODER(SMACKAUD,  smackaud);
-REGISTER_DECODER(SBC,   sbc);
+REGISTER_ENCDEC (SBC,   sbc);
 REGISTER_ENCDEC (SONIC, sonic);
 REGISTER_ENCODER(SONIC_LS,  sonic_ls);
 REGISTER_DECODER(TAK,   tak);
diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
new file mode 100644
index 00..e155387f0d
--- /dev/null
+++ b/libavcodec/sbcdsp.c
@@ -0,0 +1,382 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs 
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann 
+ * Copyright (C) 2004-2005  Henryk Ploetz 
+ * Copyright (C) 2005-2006  Brad Midgley 
+ *
+ * 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
+ * SBC basic "building bricks"
+ */
+
+#include 
+#include 
+#include 
+#include "libavutil/common.h"
+#include "libavutil/intmath.h"
+#include "libavutil/intreadwrite.h"
+#include "sbc.h"
+#include "sbcdsp.h"
+#include "sbcdsp_data.h"
+
+/*
+ * A reference C code of analysis filter with SIMD-friendly tables
+ * reordering and code layout. This code can be used to develop platform
+ * specific SIMD