Re: [FFmpeg-devel] [PATCH 01/11] avformat/dashenc: renamed 'min_seg_duration' to 'seg_duration'

2018-03-23 Thread Aurelien Jacobs
On Fri, Mar 23, 2018 at 02:32:30PM +0800, Steven Liu wrote:
> 
> 
> > On 23 Mar 2018, at 13:20, vdi...@akamai.com wrote:
> > 
> > From: Vishwanath Dixit 
> > 
> > ---
> > doc/muxers.texi   |  2 +-
> > libavformat/dashenc.c | 10 +-
> > 2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index cb75c26..65eec92 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -225,7 +225,7 @@ ffmpeg -re -i  -map 0 -map 0 -c:a libfdk_aac 
> > -c:v libx264
> > @end example
> > 
> > @table @option
> > -@item -min_seg_duration @var{microseconds}
> > +@item -seg_duration @var{microseconds}
> > Set the segment length in microseconds.
> > @item -window_size @var{size}
> > Set the maximum number of segments kept in the manifest.
> > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> > index bdf8c8d..bdd5b56 100644
> > --- a/libavformat/dashenc.c
> > +++ b/libavformat/dashenc.c
> > @@ -94,7 +94,7 @@ typedef struct DASHContext {
> > int nb_as;
> > int window_size;
> > int extra_window_size;
> > -int min_seg_duration;
> > +int seg_duration;
> > int remove_at_exit;
> > int use_template;
> > int use_timeline;
> > @@ -974,7 +974,7 @@ static int dash_init(AVFormatContext *s)
> > else
> > av_dict_set(, "movflags", 
> > "frag_custom+dash+delay_moov", 0);
> > } else {
> > -av_dict_set_int(, "cluster_time_limit", 
> > c->min_seg_duration / 1000, 0);
> > +av_dict_set_int(, "cluster_time_limit", c->seg_duration / 
> > 1000, 0);
> > av_dict_set_int(, "cluster_size_limit", 5 * 1024 * 1024, 
> > 0); // set a large cluster size limit
> > av_dict_set_int(, "dash", 1, 0);
> > av_dict_set_int(, "dash_track_number", i + 1, 0);
> > @@ -1020,7 +1020,7 @@ static int dash_init(AVFormatContext *s)
> > os->segment_index = 1;
> > }
> > 
> > -if (!c->has_video && c->min_seg_duration <= 0) {
> > +if (!c->has_video && c->seg_duration <= 0) {
> > av_log(s, AV_LOG_WARNING, "no video stream and no min seg duration 
> > set\n");
> > return AVERROR(EINVAL);
> > }
> > @@ -1287,7 +1287,7 @@ static int dash_write_packet(AVFormatContext *s, 
> > AVPacket *pkt)
> > if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
> > pkt->flags & AV_PKT_FLAG_KEY && os->packets_written &&
> > av_compare_ts(pkt->pts - os->start_pts, st->time_base,
> > -  c->min_seg_duration, AV_TIME_BASE_Q) >= 0) {
> > +  c->seg_duration, AV_TIME_BASE_Q) >= 0) {
> > int64_t prev_duration = c->last_duration;
> > 
> > c->last_duration = av_rescale_q(pkt->pts - os->start_pts,
> > @@ -1427,7 +1427,7 @@ static const AVOption options[] = {
> > { "adaptation_sets", "Adaptation sets. Syntax: id=0,streams=0,1,2 
> > id=1,streams=3,4 and so on", OFFSET(adaptation_sets), AV_OPT_TYPE_STRING, { 
> > 0 }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
> > { "window_size", "number of segments kept in the manifest", 
> > OFFSET(window_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, E },
> > { "extra_window_size", "number of segments kept outside of the manifest 
> > before removing from disk", OFFSET(extra_window_size), AV_OPT_TYPE_INT, { 
> > .i64 = 5 }, 0, INT_MAX, E },
> > -{ "min_seg_duration", "minimum segment duration (in microseconds)", 
> > OFFSET(min_seg_duration), AV_OPT_TYPE_INT, { .i64 = 500 }, 0, INT_MAX, 
> > E },
> > +{ "seg_duration", "minimum segment duration (in microseconds)", 
> > OFFSET(seg_duration), AV_OPT_TYPE_INT, { .i64 = 500 }, 0, INT_MAX, E },
> 
> No, you can make the min_seg_duration deprecated, leave a warning message, 
> update the info into the document, and add set_duration here, bump the 
> version.
> So that can give the user some time to change the options from 
> min_seg_duration to seg_duration.

This is probably also a good oportunity to change seg_duration to
AV_OPT_TYPE_DURATION.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add hrtfm filter

2018-03-23 Thread Aurelien Jacobs
On Fri, Mar 23, 2018 at 10:18:47AM +0100, Paul B Mahol wrote:
> On 3/22/18, Aurelien Jacobs <au...@gnuage.org> wrote:
> > On Mon, Mar 19, 2018 at 10:49:28PM -0800, Lou Logan wrote:
> >> On Fri, Mar 16, 2018, at 11:44 AM, Paul B Mahol wrote:
> >> > Signed-off-by: Paul B Mahol <one...@gmail.com>
> >> > ---
> >> >  doc/filters.texi |  60 ++
> >> >  libavfilter/Makefile |   1 +
> >> >  libavfilter/af_hrtfm.c   | 486
> >> >  +++>
> >> > libavfilter/allfilters.c |   1 +
> >> >  4 files changed, 548 insertions(+)
> >> >  create mode 100644 libavfilter/af_hrtfm.c
> >> >
> >> > diff --git a/doc/filters.texi b/doc/filters.texi
> >> > index bd43a7ac6e..c298054325 100644
> >> > --- a/doc/filters.texi
> >> > +++ b/doc/filters.texi
> >> > @@ -3218,6 +3218,66 @@ Change highpass width.
> >> >  Syntax for the command is : "@var{width}"
> >> >  @end table
> >> >
> >> > +@section hrtfm
> >> > +
> >> > +Apply simple Head Related Transfer Function Model to audio stream.
> >> > +
> >> > +hrtfm filter creates virtual loudspeakers around the user for
> >> > binaural> +listening via headphones (audio formats up to 9 channels
> >> > supported).> +
> >> > +This is very simple implementation which does not use any HRIRs.
> >> > +
> >> > +It accepts the following parameters:
> >> > +
> >> > +@table @option
> >> > +@item hradius
> >>
> >> You didn't like the head_radius option name suggestion?
> >>
> >> > +Set head radius of listener. In meters. Default value is
> >> > @code{0.0891}.
> >> Why meters instead of cm?
> >
> > Because if you want to specify centimeters, you can use the option
> > like this: -hradius 8.91c
> 
> Shouldn't it be 8.91cm?

Ideally it should yes.
But currently the option system does not support units. It would be
great to specify that this option is representing a length so that the
parser could validate the unit and take it into account.
But for now, options are unit-less numbers.
You can't use "-bitrate 128kb/s", but you are instead limited to
"-bitrate 128k" without specifying unit. Same for hradius for which
you can use 8.91c but not 8.91cm.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavc/cfhd: added alpha decompanding in rgba12

2018-03-22 Thread Aurelien Jacobs
On Wed, Mar 21, 2018 at 10:19:58PM +0530, Gagandeep Singh wrote:
> alpha decompanding curve added to post process the decoded alpha channel
> ---
>  libavcodec/cfhd.c | 19 +++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
> index fd834b..e35732df45 100644
> --- a/libavcodec/cfhd.c
> +++ b/libavcodec/cfhd.c
> @@ -37,6 +37,9 @@
>  #include "thread.h"
>  #include "cfhd.h"
>  
> +#define ALPHA_COMPAND_DC_OFFSET 256
> +#define ALPHA_COMPAND_GAIN 9400
> +
>  enum CFHDParam {
>  ChannelCount =  12,
>  SubbandCount =  14,
> @@ -94,6 +97,20 @@ static inline int dequant_and_decompand(int level, int 
> quantisation)
> FFSIGN(level) * quantisation;
>  }
>  
> +static inline void process_alpha(int16_t *alpha, int width)
> +{
> +int i, channel;
> +for (i = 0; i < width; i++) {
> +channel   = alpha[i];
> +channel  -= ALPHA_COMPAND_DC_OFFSET;
> +channel <<= 3;
> +channel  *= ALPHA_COMPAND_GAIN;

Any reason why you can't merge the << 3 (ie. * 8) with the
* ALPHA_COMPAND_GAIN ?

> +channel >>= 16;

> +channel   = av_clip_uintp2(channel, 12);
> +alpha[i]  = channel;

Here you should affect the result of av_clip_uintp2 directly to alpha[i].

Actually, I think it would be more readable by dropping the channel
intermediate variable entirely. You could write this function like this
(untested):

static inline void process_alpha(int16_t *alpha, int width)
{
for (int i = 0; i < width; i++)
alpha[i] = av_clip_uintp2(((alpha[i] - 256) * 75200) >> 16, 12);
}

Of course, you can use DC_OFFSET and GAIN constants in there if you
think it is more readable.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add hrtfm filter

2018-03-22 Thread Aurelien Jacobs
On Mon, Mar 19, 2018 at 10:49:28PM -0800, Lou Logan wrote:
> On Fri, Mar 16, 2018, at 11:44 AM, Paul B Mahol wrote:
> > Signed-off-by: Paul B Mahol 
> > ---
> >  doc/filters.texi |  60 ++
> >  libavfilter/Makefile |   1 +
> >  libavfilter/af_hrtfm.c   | 486
> >  +++>  libavfilter/allfilters.c 
> > |   1 +
> >  4 files changed, 548 insertions(+)
> >  create mode 100644 libavfilter/af_hrtfm.c
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index bd43a7ac6e..c298054325 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -3218,6 +3218,66 @@ Change highpass width.
> >  Syntax for the command is : "@var{width}"
> >  @end table
> > 
> > +@section hrtfm
> > +
> > +Apply simple Head Related Transfer Function Model to audio stream.
> > +
> > +hrtfm filter creates virtual loudspeakers around the user for
> > binaural> +listening via headphones (audio formats up to 9 channels 
> > supported).> +
> > +This is very simple implementation which does not use any HRIRs.
> > +
> > +It accepts the following parameters:
> > +
> > +@table @option
> > +@item hradius
> 
> You didn’t like the head_radius option name suggestion?
> 
> > +Set head radius of listener. In meters. Default value is
> > @code{0.0891}.
> Why meters instead of cm? 

Because if you want to specify centimeters, you can use the option
like this: -hradius 8.91c
The only way for SI prefix to make sense is to have the options
expressed in the base unit.
So I think hradius should be expressed in meters and every new options
should always be expressed in their base unit.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/parseutils: only accept full us duration, do not accept mss duration

2018-03-07 Thread Aurelien Jacobs
On Thu, Mar 08, 2018 at 12:14:00AM +0100, Hendrik Leppkes wrote:
> On Thu, Mar 8, 2018 at 12:05 AM, Aurelien Jacobs <au...@gnuage.org> wrote:
> > On Wed, Mar 07, 2018 at 11:45:03PM +0100, Marton Balint wrote:
> >>
> >>
> >> On Wed, 7 Mar 2018, Aurelien Jacobs wrote:
> >>
> >> > On Tue, Mar 06, 2018 at 01:02:48AM +0100, Marton Balint wrote:
> >> > > Accepting 'u' suffix for a time specification is neither intuitive nor
> >> > > consistent (now that we don't accept m).
> >> >
> >> > The 'm' SI prefix is still accepted in various time options, and the 'u'
> >> > prefix is still accepted in those options even after your patch, so you
> >> > can't really argue that this patch improve consistency.
> >> > (eg. -black_min_duration 5ms is still accepted).
> >> > So this will surprise nobody that I don't like this patch.
> >>
> >> This really is a cursed topic, I am not sure I follow, after the patch:
> >>
> >> 5ms is accepted
> >> 5us is accepted
> >> 5m is not accepted
> >> 5u is not accepted
> >
> > That is only for AV_OPT_TYPE_DURATION.
> > All other numeric options type still accept SI prefix without unit.
> > This include various time options such as black_min_duration.
> > So after the patch, for black_min_duration:
> >
> > 5m is accepted
> > 5u is accepted
> >
> 
> Because those use AV_OPT_TYPE_DOUBLE, a generic type without any
> possiblity of a unit.

Of course, I know this.

> Ideally those should all be transitioned to AV_OPT_TYPE_DURATION if
> they refer to a time for consistency,

Of course that's what we ideally want in the end.
But it is not that trivial to do. To avoid breaking ABI we can't just
replace numeric options by AV_OPT_TYPE_DURATION. For each one we need
to introduce a new option name using AV_OPT_TYPE_DURATION and deprecate
the old numeric option.

The point is, as long has this transition isn't fully done, end users
have to deal with various time related options, some of which are
AV_OPT_TYPE_DURATION and some AV_OPT_TYPE_DOUBLE or AV_OPT_TYPE_INT64...
Right now, we can use '5u' with both black_min_duration and sbc_delay.
If this patch is applied, users will have to know that
black_min_duration is AV_OPT_TYPE_DOUBLE so they must use '5u' and
that sbc_delay is AV_OPT_TYPE_DURATION so they must use '5us'.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/parseutils: only accept full us duration, do not accept mss duration

2018-03-07 Thread Aurelien Jacobs
On Wed, Mar 07, 2018 at 11:45:03PM +0100, Marton Balint wrote:
> 
> 
> On Wed, 7 Mar 2018, Aurelien Jacobs wrote:
> 
> > On Tue, Mar 06, 2018 at 01:02:48AM +0100, Marton Balint wrote:
> > > Accepting 'u' suffix for a time specification is neither intuitive nor
> > > consistent (now that we don't accept m).
> > 
> > The 'm' SI prefix is still accepted in various time options, and the 'u'
> > prefix is still accepted in those options even after your patch, so you
> > can't really argue that this patch improve consistency.
> > (eg. -black_min_duration 5ms is still accepted).
> > So this will surprise nobody that I don't like this patch.
> 
> This really is a cursed topic, I am not sure I follow, after the patch:
> 
> 5ms is accepted
> 5us is accepted
> 5m is not accepted
> 5u is not accepted

That is only for AV_OPT_TYPE_DURATION.
All other numeric options type still accept SI prefix without unit.
This include various time options such as black_min_duration.
So after the patch, for black_min_duration:

5m is accepted
5u is accepted

> You really insist on accepting '5u'?

I'm not insisting on this (even if I prefer it), but I'm saying that
your patch is *not* removing '5u' support at least for *some* time
options, so it is actually decreasing consistency.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/parseutils: only accept full us duration, do not accept mss duration

2018-03-07 Thread Aurelien Jacobs
On Tue, Mar 06, 2018 at 01:02:48AM +0100, Marton Balint wrote:
> Accepting 'u' suffix for a time specification is neither intuitive nor
> consistent (now that we don't accept m).

The 'm' SI prefix is still accepted in various time options, and the 'u'
prefix is still accepted in those options even after your patch, so you
can't really argue that this patch improve consistency.
(eg. -black_min_duration 5ms is still accepted).
So this will surprise nobody that I don't like this patch.

> Also there was a bug in the code
> accepting an extra 's' even after 'ms'.

Indeed, removing support for the 'm' prefix alone introduced this bug
and that needs to be fixed.
___
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-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 <au...@gnuage.org> wrote:
> 
> > On Thu, Mar 01, 2018 at 10:46:07PM +, Rostislav Pehlivanov wrote:
> > > On 1 March 2018 at 20:45, Aurelien Jacobs <au...@gnuage.org> 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] parseutils: accept only full "ms" and "us" prefixes

2018-03-05 Thread Aurelien Jacobs
On Sat, Mar 03, 2018 at 08:19:43PM +, Rostislav Pehlivanov wrote:
> The commit which added those was pushed prematurely before anyone could object
> to illogical suffixes like just m for milliseconds.

What you call illogical is following the same convention as pretty much
all numeric parameters in ffmpeg. (bitrate, bufsize, framerate...)
So it is at least consistent.

> Without this, we'd be locked
> into never being able to implement the "m" suffix for minutes.

I will always be against using "m" for minute, but you can use "min" if
you want.

> Signed-off-by: Rostislav Pehlivanov 
> ---
>  libavutil/parseutils.c | 10 --
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
> index 44c845577a..1b81757aab 100644
> --- a/libavutil/parseutils.c
> +++ b/libavutil/parseutils.c
> @@ -689,17 +689,15 @@ int av_parse_time(int64_t *timeval, const char 
> *timestr, int duration)
>  
>  if (duration) {
>  t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
> -if (*q == 'm') {
> +if (q[0] == 'm' && q[1] == 's') {
>  suffix = 1000;
>  microseconds /= 1000;
> -q++;
> -} else if (*q == 'u') {
> +q += 2;
> +} else if (q[0] == 'u' && q[1] == 's') {
>  suffix = 1;
>  microseconds = 0;
> -q++;
> +q += 2;
>  }
> -if (*q == 's')
> -q++;
>  } else {
>  int is_utc = *q == 'Z' || *q == 'z';
>  int tzoffset = 0;

Why do you remove support for using just 's' as a unit without prefix ?
I've seen no one complaining about it and I can't see any issue with it.

Also I don't like that this patch makes AV_OPT_TYPE_DURATION
inconsistant with every other numeric parameters, that all accept a SI
prefix without unit.
(that include opus_delay for which "3.5" and "3500m" are equivalent)
___
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 <au...@gnuage.org> 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] parseutils: add support for ms and us suffix for AV_OPT_TYPE_DURATION

2018-03-03 Thread Aurelien Jacobs
On Fri, Mar 02, 2018 at 11:59:33PM +0100, Marton Balint wrote:
> 
> On Fri, 2 Mar 2018, Hendrik Leppkes wrote:
> 
> > On Fri, Mar 2, 2018 at 11:19 PM, Aurelien Jacobs <au...@gnuage.org> wrote:
> > > On Fri, Mar 02, 2018 at 10:02:58PM +, Rostislav Pehlivanov wrote:
> > > > On 2 March 2018 at 21:57, Aurelien Jacobs <au...@gnuage.org> wrote:
> > > > 
> > > > > On Fri, Mar 02, 2018 at 09:39:48PM +0100, Michael Niedermayer wrote:
> > > > > > On Thu, Mar 01, 2018 at 09:41:20PM +0100, Aurelien Jacobs wrote:
> > > > > > > supported suffixes are:
> > > > > > > - s: seconds (default when no suffix specified)
> > > > > > > - m or ms: milliseconds
> > > > > > > - u or us: microseconds
> 
> I don't see much benefit in accepting the SI prefixes without actual
> unit,

Maybe for conciseness... And because the unit is already implied by the
option name. When setting a time the unit is second, when setting a
bitrate the unit is bit per seconds so specifying the unit after the
prefix might be considered redundant.
Not that I personnaly really care. I wouldn't mind writting 128kb/s
rather than 128k.

> the purpose of this whoule patch is intuitive and readable command line, and
> an SI prefix alone, without a unit is not intuitive. So I'd drop the
> SI-prefix-only variants.

I mostly agree, but I allowed the use of SI prefix alone for consistency
with other options (bitrate for example).
I would suggest that all examples in documentations or tutorials should
use full SI prefix + unit for improved readability.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] parseutils: add support for ms and us suffix for AV_OPT_TYPE_DURATION

2018-03-03 Thread Aurelien Jacobs
On Fri, Mar 02, 2018 at 11:28:29PM +0100, Hendrik Leppkes wrote:
> On Fri, Mar 2, 2018 at 11:19 PM, Aurelien Jacobs <au...@gnuage.org> wrote:
> > On Fri, Mar 02, 2018 at 10:02:58PM +, Rostislav Pehlivanov wrote:
> >> On 2 March 2018 at 21:57, Aurelien Jacobs <au...@gnuage.org> wrote:
> >>
> >> > On Fri, Mar 02, 2018 at 09:39:48PM +0100, Michael Niedermayer wrote:
> >> > > On Thu, Mar 01, 2018 at 09:41:20PM +0100, Aurelien Jacobs wrote:
> >> > > > supported suffixes are:
> >> > > > - s: seconds (default when no suffix specified)
> >> > > > - m or ms: milliseconds
> >> > > > - u or us: microseconds
> >> > > > ---
> >> > > >  libavutil/parseutils.c | 15 +--
> >> > > >  1 file changed, 13 insertions(+), 2 deletions(-)
> >> > >
> >> > > can some of this and the si_prefixes related code in eval.c be
> >> > > factored ?
> >> >
> >> > I've had a look at this, but this would increase code complexity
> >> > in both eval.c and parseutils.c with no advantage, so I deceided not to.
> >> > Anyway, 'u' and 'm' SI prefix are the only ones that make any sense for
> >> > AV_OPT_TYPE_DURATION and supporting more prefix than those "thanks" to
> >> > common code, might add confusion for end user.
> >> >
> >> > BTW, while looking at si_prefixes, I noticed that both 'k' and 'K' are
> >> > supported for meaning "kilo", which is wrong in the SI. Only 'k' is
> >> > a prefix for "kilo", 'K' is a unit for "Kelvin".
> >> > Not sure if there is actually a good reason for having 'K', if it is
> >> > needed for backward compatibility, or if it should be removed...
> >> >
> >> > > either way this LGTM
> >> >
> >> > Great. Applied.
> >>
> >> I think that was a bit premature, I really think "m" should be for minutes
> >> while "ms" should be for milliseconds.
> >
> > What you (or I) think is not relevant here. We are simply implementing
> > an internationnal standard that define precisely what those letters mean
> > so that people all around the world can communicate without ambiguity.
> >
> 
> Why is it not relevant what we think?

Because what is relevant is what the majority of users will understand
the best, whatever their language, culture or education is.

> Who said this has to follow strict SI rules?

Nobody said this, but the fact the SI rules are already used in other
parts of ffmpeg and that nobody suggested any other widely accepted
rules is already a good start.
The fact that SI rules is by far the most widely used unit and prefix
system around the world, and that it is unambiguously defined, makes
it a strong contender I think.

> It should use postfixes which are the most logical and intuitive,

Provided that you can strictly define "logical" and "intuitive" in a
worldwide context...

> when someone reads "5m" he is the most likely to assume minutes, not
> milliseconds.

Not sure what makes you able to know what everybody is gonna assume ?
Personnaly when I read "5m" out of context, I read 5 meters.
With ffmpeg, when I first set SBC delay, I used 0.005 but right after
this I tried 5m by analogy with -b:a 128k where we only use the SI
prefix without unit (ie. we don't write -b:a 128kb/s).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] parseutils: add support for ms and us suffix for AV_OPT_TYPE_DURATION

2018-03-02 Thread Aurelien Jacobs
On Fri, Mar 02, 2018 at 10:02:58PM +, Rostislav Pehlivanov wrote:
> On 2 March 2018 at 21:57, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > On Fri, Mar 02, 2018 at 09:39:48PM +0100, Michael Niedermayer wrote:
> > > On Thu, Mar 01, 2018 at 09:41:20PM +0100, Aurelien Jacobs wrote:
> > > > supported suffixes are:
> > > > - s: seconds (default when no suffix specified)
> > > > - m or ms: milliseconds
> > > > - u or us: microseconds
> > > > ---
> > > >  libavutil/parseutils.c | 15 +--
> > > >  1 file changed, 13 insertions(+), 2 deletions(-)
> > >
> > > can some of this and the si_prefixes related code in eval.c be
> > > factored ?
> >
> > I've had a look at this, but this would increase code complexity
> > in both eval.c and parseutils.c with no advantage, so I deceided not to.
> > Anyway, 'u' and 'm' SI prefix are the only ones that make any sense for
> > AV_OPT_TYPE_DURATION and supporting more prefix than those "thanks" to
> > common code, might add confusion for end user.
> >
> > BTW, while looking at si_prefixes, I noticed that both 'k' and 'K' are
> > supported for meaning "kilo", which is wrong in the SI. Only 'k' is
> > a prefix for "kilo", 'K' is a unit for "Kelvin".
> > Not sure if there is actually a good reason for having 'K', if it is
> > needed for backward compatibility, or if it should be removed...
> >
> > > either way this LGTM
> >
> > Great. Applied.
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> I think that was a bit premature, I really think "m" should be for minutes
> while "ms" should be for milliseconds.

What you (or I) think is not relevant here. We are simply implementing
an internationnal standard that define precisely what those letters mean
so that people all around the world can communicate without ambiguity.

Minute is not an SI unit but still accepted for use along with SI units,
and the standard symbol for minutes is 'min'.
'm' is the prefix for milli and nothing else.

This is detailed here:
https://www.bipm.org/en/publications/si-brochure/table6.html

If you think having support for minute is really useful, I can have a
look at supporting 'min'.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] parseutils: add support for ms and us suffix for AV_OPT_TYPE_DURATION

2018-03-02 Thread Aurelien Jacobs
On Fri, Mar 02, 2018 at 09:39:48PM +0100, Michael Niedermayer wrote:
> On Thu, Mar 01, 2018 at 09:41:20PM +0100, Aurelien Jacobs wrote:
> > supported suffixes are:
> > - s: seconds (default when no suffix specified)
> > - m or ms: milliseconds
> > - u or us: microseconds
> > ---
> >  libavutil/parseutils.c | 15 +--
> >  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> can some of this and the si_prefixes related code in eval.c be
> factored ?

I've had a look at this, but this would increase code complexity
in both eval.c and parseutils.c with no advantage, so I deceided not to.
Anyway, 'u' and 'm' SI prefix are the only ones that make any sense for
AV_OPT_TYPE_DURATION and supporting more prefix than those "thanks" to
common code, might add confusion for end user.

BTW, while looking at si_prefixes, I noticed that both 'k' and 'K' are
supported for meaning "kilo", which is wrong in the SI. Only 'k' is
a prefix for "kilo", 'K' is a unit for "Kelvin".
Not sure if there is actually a good reason for having 'K', if it is
needed for backward compatibility, or if it should be removed...

> either way this LGTM

Great. Applied.
___
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 <au...@gnuage.org> wrote:
> 
> > On Wed, Feb 28, 2018 at 12:59:40AM +, Rostislav Pehlivanov wrote:
> > > On 27 February 2018 at 23:56, Aurelien Jacobs <au...@gnuage.org> 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


[FFmpeg-devel] [PATCH] parseutils: add support for ms and us suffix for AV_OPT_TYPE_DURATION

2018-03-01 Thread Aurelien Jacobs
supported suffixes are:
- s: seconds (default when no suffix specified)
- m or ms: milliseconds
- u or us: microseconds
---
 libavutil/parseutils.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 7ca07b37a1..44c845577a 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -590,7 +590,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, 
int duration)
 int64_t t, now64;
 time_t now;
 struct tm dt = { 0 }, tmbuf;
-int today = 0, negative = 0, microseconds = 0;
+int today = 0, negative = 0, microseconds = 0, suffix = 100;
 int i;
 static const char * const date_fmt[] = {
 "%Y - %m - %d",
@@ -689,6 +689,17 @@ int av_parse_time(int64_t *timeval, const char *timestr, 
int duration)
 
 if (duration) {
 t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
+if (*q == 'm') {
+suffix = 1000;
+microseconds /= 1000;
+q++;
+} else if (*q == 'u') {
+suffix = 1;
+microseconds = 0;
+q++;
+}
+if (*q == 's')
+q++;
 } else {
 int is_utc = *q == 'Z' || *q == 'z';
 int tzoffset = 0;
@@ -724,7 +735,7 @@ int av_parse_time(int64_t *timeval, const char *timestr, 
int duration)
 if (*q)
 return AVERROR(EINVAL);
 
-t *= 100;
+t *= suffix;
 t += microseconds;
 *timeval = negative ? -t : t;
 return 0;
-- 
2.16.2

___
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 <au...@gnuage.org> 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 <au...@gnuage.org>
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 }, IN

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 <au...@gnuage.org> wrote:
> 
> > On Thu, Feb 22, 2018 at 06:18:48PM +, Rostislav Pehlivanov wrote:
> > > On 21 February 2018 at 22:37, Aurelien Jacobs <au...@gnuage.org> 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" settin

Re: [FFmpeg-devel] [PATCH 7/9] sbcenc: add MMX optimizations

2018-02-24 Thread Aurelien Jacobs
On Thu, Feb 22, 2018 at 05:21:57PM +, Rostislav Pehlivanov wrote:
> On 21 February 2018 at 22:37, Aurelien Jacobs <au...@gnuage.org> wrote:
> [...]
> > +;***
> > +;void ff_sbc_analyze_4(const int16_t *in, int32_t *out, const int16_t
> > *consts);
> > +;***
> > +INIT_MMX mmx
> > +cglobal sbc_analyze_4, 3, 3, 4, in, out, consts
> > +movq  m0, [inq]
> > +movq  m1, [inq+8]
> > +pmaddwd   m0, [constsq]
> > +pmaddwd   m1, [constsq+8]
> > +paddd m0, [scale_mask]
> > +paddd m1, [scale_mask]
> > +
> > +movq  m2, [inq+16]
> > +movq  m3, [inq+24]
> > +pmaddwd   m2, [constsq+16]
> > +pmaddwd   m3, [constsq+24]
> > +paddd m0, m2
> > +paddd m1, m3
> > +
> > +movq  m2, [inq+32]
> > +movq  m3, [inq+40]
> > +pmaddwd   m2, [constsq+32]
> > +pmaddwd   m3, [constsq+40]
> > +paddd m0, m2
> > +paddd m1, m3
> > +
> > +movq  m2, [inq+48]
> > +movq  m3, [inq+56]
> > +pmaddwd   m2, [constsq+48]
> > +pmaddwd   m3, [constsq+56]
> > +paddd m0, m2
> > +paddd m1, m3
> > +
> > +movq  m2, [inq+64]
> > +movq  m3, [inq+72]
> > +pmaddwd   m2, [constsq+64]
> > +pmaddwd   m3, [constsq+72]
> > +paddd m0, m2
> > +paddd m1, m3
> >
> 
> You can macro the top 3 blocks
> 
> [...]
> > +;***
> > +;void ff_sbc_analyze_8(const int16_t *in, int32_t *out, const int16_t
> > *consts);
> > +;***
> > +INIT_MMX mmx
> > +cglobal sbc_analyze_8, 3, 3, 4, in, out, consts
> > +movq  m0, [inq]
> > +movq  m1, [inq+8]
> > +movq  m2, [inq+16]
> > +movq  m3, [inq+24]
> > +pmaddwd   m0, [constsq]
> > +pmaddwd   m1, [constsq+8]
> > +pmaddwd   m2, [constsq+16]
> > +pmaddwd   m3, [constsq+24]
> > +paddd m0, [scale_mask]
> > +paddd m1, [scale_mask]
> > +paddd m2, [scale_mask]
> > +paddd m3, [scale_mask]
> > +
> > +movq  m4, [inq+32]
> > +movq  m5, [inq+40]
> > +movq  m6, [inq+48]
> > +movq  m7, [inq+56]
> > +pmaddwd   m4, [constsq+32]
> > +pmaddwd   m5, [constsq+40]
> > +pmaddwd   m6, [constsq+48]
> > +pmaddwd   m7, [constsq+56]
> > +paddd m0, m4
> > +paddd m1, m5
> > +paddd m2, m6
> > +paddd m3, m7
> > +
> > +movq  m4, [inq+64]
> > +movq  m5, [inq+72]
> > +movq  m6, [inq+80]
> > +movq  m7, [inq+88]
> > +pmaddwd   m4, [constsq+64]
> > +pmaddwd   m5, [constsq+72]
> > +pmaddwd   m6, [constsq+80]
> > +pmaddwd   m7, [constsq+88]
> > +paddd m0, m4
> > +paddd m1, m5
> > +paddd m2, m6
> > +paddd m3, m7
> > +
> > +movq  m4, [inq+96]
> > +movq  m5, [inq+104]
> > +movq  m6, [inq+112]
> > +movq  m7, [inq+120]
> > +pmaddwd   m4, [constsq+96]
> > +pmaddwd   m5, [constsq+104]
> > +pmaddwd   m6, [constsq+112]
> > +pmaddwd   m7, [constsq+120]
> > +paddd m0, m4
> > +paddd m1, m5
> > +paddd m2, m6
> > +paddd m3, m7
> > +
> > +movq  m4, [inq+128]
> > +movq  m5, [inq+136]
> > +movq  m6, [inq+144]
> > +movq  m7, [inq+152]
> > +pmaddwd   m4, [constsq+128]
> > +pmaddwd   m5, [constsq+136]
> > +pmaddwd   m6, [constsq+144]
> > +pmaddwd   m7, [constsq+152]
> > +paddd m0, m4
> > +paddd m1, m5
> > +paddd m2, m6
> > +paddd m3, m7
> >
> 
> And those 5 blocks
> 
> 
> > +
> > +psrad m0, 16; SBC_PROTO_FIXED_SCALE
> > +psrad m1, 16; SBC_PROTO_FIXED_SCALE
> > + 

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 <au...@gnuage.org> 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 <au...@gnuage.org>
Date: S

[FFmpeg-devel] [PATCH 9/9] Changelog: list the new SBC codec

2018-02-21 Thread Aurelien Jacobs
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index 2acdbbea30..163cc77880 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
+- native SBC encoder and decoder
 
 
 version 3.4:
-- 
2.16.1

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


[FFmpeg-devel] [PATCH 6/9] sbc: add raw muxer for SBC

2018-02-21 Thread Aurelien Jacobs
---
 doc/general.texi |  2 +-
 libavformat/Makefile |  1 +
 libavformat/allformats.c |  1 +
 libavformat/rawenc.c | 13 +
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/doc/general.texi b/doc/general.texi
index bf62288f64..118bfd8bd9 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -479,7 +479,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
-@item raw SBC   @tab   @tab X
+@item raw SBC   @tab X @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 1efa3a54f8..8f3272efdf 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -449,6 +449,7 @@ OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o 
subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
 OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
+OBJS-$(CONFIG_SBC_MUXER) += rawenc.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 04164607ce..05894094a7 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -351,6 +351,7 @@ extern AVInputFormat  ff_sami_demuxer;
 extern AVInputFormat  ff_sap_demuxer;
 extern AVOutputFormat ff_sap_muxer;
 extern AVInputFormat  ff_sbc_demuxer;
+extern AVOutputFormat ff_sbc_muxer;
 extern AVInputFormat  ff_sbg_demuxer;
 extern AVInputFormat  ff_scc_demuxer;
 extern AVOutputFormat ff_scc_muxer;
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index dcf880d17e..caf4607dde 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -439,6 +439,19 @@ AVOutputFormat ff_rawvideo_muxer = {
 };
 #endif
 
+#if CONFIG_SBC_MUXER
+AVOutputFormat ff_sbc_muxer = {
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
+.mime_type = "audio/x-sbc",
+.extensions= "sbc,msbc",
+.audio_codec   = AV_CODEC_ID_SBC,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_TRUEHD_MUXER
 AVOutputFormat ff_truehd_muxer = {
 .name  = "truehd",
-- 
2.16.1

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


[FFmpeg-devel] [PATCH 7/9] sbcenc: add MMX optimizations

2018-02-21 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.

Rough speed test:
C version:speed= 592x
MMX version:  speed= 785x
---
 libavcodec/sbcdsp.c  |   3 +
 libavcodec/sbcdsp.h  |   2 +
 libavcodec/x86/Makefile  |   2 +
 libavcodec/x86/sbcdsp.asm| 285 +++
 libavcodec/x86/sbcdsp_init.c |  51 
 5 files changed, 343 insertions(+)
 create mode 100644 libavcodec/x86/sbcdsp.asm
 create mode 100644 libavcodec/x86/sbcdsp_init.c

diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
index e155387f0d..2d0addcf28 100644
--- a/libavcodec/sbcdsp.c
+++ b/libavcodec/sbcdsp.c
@@ -379,4 +379,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
 /* Default implementation for scale factors calculation */
 s->sbc_calc_scalefactors = sbc_calc_scalefactors;
 s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
+
+if (ARCH_X86)
+ff_sbcdsp_init_x86(s);
 }
diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
index 66ed7d324e..127e6a8a11 100644
--- a/libavcodec/sbcdsp.h
+++ b/libavcodec/sbcdsp.h
@@ -80,4 +80,6 @@ struct sbc_dsp_context {
  */
 void ff_sbcdsp_init(SBCDSPContext *s);
 
+void ff_sbcdsp_init_x86(SBCDSPContext *s);
+
 #endif /* AVCODEC_SBCDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a805cd37b4..2350c8bbee 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_DECODER)  += x86/proresdsp_init.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp_init.o
 OBJS-$(CONFIG_RV40_DECODER)+= x86/rv40dsp_init.o
+OBJS-$(CONFIG_SBC_ENCODER) += x86/sbcdsp_init.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= x86/svq1enc_init.o
 OBJS-$(CONFIG_TAK_DECODER) += x86/takdsp_init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)  += x86/mlpdsp_init.o
@@ -172,6 +173,7 @@ X86ASM-OBJS-$(CONFIG_PNG_DECODER)  += x86/pngdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_DECODER)   += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o
+X86ASM-OBJS-$(CONFIG_SBC_ENCODER)  += x86/sbcdsp.o
 X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER) += x86/svq1enc.o
 X86ASM-OBJS-$(CONFIG_TAK_DECODER)  += x86/takdsp.o
 X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
diff --git a/libavcodec/x86/sbcdsp.asm b/libavcodec/x86/sbcdsp.asm
new file mode 100644
index 00..4e02263a63
--- /dev/null
+++ b/libavcodec/x86/sbcdsp.asm
@@ -0,0 +1,285 @@
+;**
+;* SIMD optimized SBC encoder DSP functions
+;*
+;* Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+;* Copyright (C) 2008-2010  Nokia Corporation
+;* Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+;* Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+;* Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+;*
+;* 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
+;**
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+scale_mask: times 2 dd 0x8000; 1 << (SBC_PROTO_FIXED_SCALE - 1)
+
+SECTION .text
+
+;***
+;void ff_sbc_analyze_4(const int16_t *in, int32_t *out, const int16_t *consts);
+;***
+INIT_MMX mmx
+cglobal sbc_analyze_4, 3, 3, 4, in, out, consts
+movq  m0, [inq]
+movq  m1, [inq+8]
+pmaddwd   m0, [constsq]
+pmaddwd   m1, [constsq+8]
+paddd m0, [scale_mask]
+paddd m1, [scale_mask]
+
+movq  m2, [inq+16]
+movq  m3, [inq+24]
+pmaddwd   m2, [constsq+16]
+pmaddwd   m3, [constsq+24]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+32]
+movq  m3, [inq+40]
+pmaddwd   m2, [constsq+32]
+pmaddwd   m3, [constsq+40]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+48]
+mo

[FFmpeg-devel] [PATCH 3/9] sbc: add parser for SBC

2018-02-21 Thread Aurelien Jacobs
---
 libavcodec/Makefile |   1 +
 libavcodec/parser.c |   1 +
 libavcodec/sbc_parser.c | 124 
 3 files changed, 126 insertions(+)
 create mode 100644 libavcodec/sbc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e2a87e404c..53d199201b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1014,6 +1014,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_SBC_PARSER)  += sbc_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  \
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 0c66e80b96..f43b197d5e 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -65,6 +65,7 @@ extern AVCodecParser ff_png_parser;
 extern AVCodecParser ff_pnm_parser;
 extern AVCodecParser ff_rv30_parser;
 extern AVCodecParser ff_rv40_parser;
+extern AVCodecParser ff_sbc_parser;
 extern AVCodecParser ff_sipr_parser;
 extern AVCodecParser ff_tak_parser;
 extern AVCodecParser ff_vc1_parser;
diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
new file mode 100644
index 00..4633196d3f
--- /dev/null
+++ b/libavcodec/sbc_parser.c
@@ -0,0 +1,124 @@
+/*
+ * SBC parser
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "sbc.h"
+#include "parser.h"
+
+typedef struct SBCParseContext {
+ParseContext pc;
+uint8_t header[3];
+int header_size;
+int buffered_size;
+} SBCParseContext;
+
+static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
+const uint8_t *data, size_t len)
+{
+static const int sample_rates[4] = { 16000, 32000, 44100, 48000 };
+int sr, blocks, mode, subbands, bitpool, channels, joint;
+int length;
+
+if (len < 3)
+return -1;
+
+if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
+avctx->channels = 1;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = 16000;
+avctx->frame_size = 120;
+s->duration = avctx->frame_size;
+return 57;
+}
+
+if (data[0] != SBC_SYNCWORD)
+return -2;
+
+sr   =   (data[1] >> 6) & 0x03;
+blocks   = (((data[1] >> 4) & 0x03) + 1) << 2;
+mode =   (data[1] >> 2) & 0x03;
+subbands = (((data[1] >> 0) & 0x01) + 1) << 2;
+bitpool  = data[2];
+
+channels = mode == SBC_MODE_MONO ? 1 : 2;
+joint= mode == SBC_MODE_JOINT_STEREO;
+
+length = 4 + (subbands * channels) / 2;
+if (channels == 1 || mode == SBC_MODE_DUAL_CHANNEL)
+length += ((channels * blocks * bitpool) + 7) / 8;
+else
+length += (((joint ? subbands : 0) + blocks * bitpool) + 7) / 8;
+
+avctx->channels = channels;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = sample_rates[sr];
+avctx->frame_size = subbands * blocks;
+s->duration = avctx->frame_size;
+return length;
+}
+
+static int sbc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+SBCParseContext *pc = s->priv_data;
+int next;
+
+if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+next = buf_size;
+} else {
+if (pc->header_size) {
+memcpy(pc->header + pc->header_size, buf,
+   sizeof(pc->header) - pc->header_size);
+next = sbc_parse_header(s, avctx, pc->header, sizeof(pc->header))
+ - pc->buffered_size;
+pc->header_size = 0;
+} else {
+next = sbc_parse_header(s, avctx, buf, buf_size);
+if (next >= buf_size)
+next = -1;
+  

[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 <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 

[FFmpeg-devel] [PATCH 8/9] sbcenc: add armv6 and neon asm optimizations

2018-02-21 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 libavcodec/arm/Makefile  |   3 +
 libavcodec/arm/sbcdsp_armv6.S| 245 ++
 libavcodec/arm/sbcdsp_init_arm.c | 105 ++
 libavcodec/arm/sbcdsp_neon.S | 714 +++
 libavcodec/sbcdsp.c  |   2 +
 libavcodec/sbcdsp.h  |   1 +
 6 files changed, 1070 insertions(+)
 create mode 100644 libavcodec/arm/sbcdsp_armv6.S
 create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
 create mode 100644 libavcodec/arm/sbcdsp_neon.S

diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index 1eeac5449e..fd2401f4e5 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -42,6 +42,7 @@ OBJS-$(CONFIG_DCA_DECODER) += 
arm/synth_filter_init_arm.o
 OBJS-$(CONFIG_HEVC_DECODER)+= arm/hevcdsp_init_arm.o
 OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_init_arm.o
 OBJS-$(CONFIG_RV40_DECODER)+= arm/rv40dsp_init_arm.o
+OBJS-$(CONFIG_SBC_ENCODER) += arm/sbcdsp_init_arm.o
 OBJS-$(CONFIG_VORBIS_DECODER)  += arm/vorbisdsp_init_arm.o
 OBJS-$(CONFIG_VP6_DECODER) += arm/vp6dsp_init_arm.o
 OBJS-$(CONFIG_VP9_DECODER) += arm/vp9dsp_init_10bpp_arm.o   \
@@ -81,6 +82,7 @@ ARMV6-OBJS-$(CONFIG_VP8DSP)+= arm/vp8_armv6.o 
  \
 
 # decoders/encoders
 ARMV6-OBJS-$(CONFIG_MLP_DECODER)   += arm/mlpdsp_armv6.o
+ARMV6-OBJS-$(CONFIG_SBC_ENCODER)   += arm/sbcdsp_armv6.o
 
 
 # VFP optimizations
@@ -140,6 +142,7 @@ NEON-OBJS-$(CONFIG_HEVC_DECODER)   += 
arm/hevcdsp_init_neon.o   \
 NEON-OBJS-$(CONFIG_RV30_DECODER)   += arm/rv34dsp_neon.o
 NEON-OBJS-$(CONFIG_RV40_DECODER)   += arm/rv34dsp_neon.o\
   arm/rv40dsp_neon.o
+NEON-OBJS-$(CONFIG_SBC_ENCODER)+= arm/sbcdsp_neon.o
 NEON-OBJS-$(CONFIG_VORBIS_DECODER) += arm/vorbisdsp_neon.o
 NEON-OBJS-$(CONFIG_VP6_DECODER)+= arm/vp6dsp_neon.o
 NEON-OBJS-$(CONFIG_VP9_DECODER)+= arm/vp9itxfm_16bpp_neon.o \
diff --git a/libavcodec/arm/sbcdsp_armv6.S b/libavcodec/arm/sbcdsp_armv6.S
new file mode 100644
index 00..f1ff845798
--- /dev/null
+++ b/libavcodec/arm/sbcdsp_armv6.S
@@ -0,0 +1,245 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 ARMv6 optimizations. The instructions are scheduled for ARM11 pipeline.
+ */
+
+#include "libavutil/arm/asm.S"
+
+function ff_sbc_analyze_4_armv6, export=1
+@ r0 = in, r1 = out, r2 = consts
+push{r1, r3-r7, lr}
+push{r8-r12, r14}
+ldrdr4,  r5,  [r0, #0]
+ldrdr6,  r7,  [r2, #0]
+ldrdr8,  r9,  [r0, #16]
+ldrdr10, r11, [r2, #16]
+mov r14, #0x8000
+smlad   r3,  r4,  r6,  r14
+smlad   r12, r5,  r7,  r14
+ldrdr4,  r5,  [r0, #32]
+ldrdr6,  r7,  [r2, #32]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #48]
+ldrdr10, r11, [r2, #48]
+smlad   r3,  r4,  r6,  r3
+smlad   r12, r5,  r7,  r12
+ldrdr4,  r5,  [r0, #64]
+ldrdr6,  r7,  [r2, #64]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #8]
+ldrdr10, r11, [r2, #8]
+smlad   r3,  r4,  r6,  r3@ t1[0] is done
+smlad   r12, r5,  r7,  r12   @ t1[1] is done
+ldrdr4,  r5,  [r0, #24]
+ldrdr6,  r7,  [r2, #24]
+pkhtb   r3,  r12, r3, asr #16@ comb

[FFmpeg-devel] [PATCH 4/9] sbc: add raw demuxer for SBC

2018-02-21 Thread Aurelien Jacobs
---
 doc/general.texi |  1 +
 libavformat/Makefile |  1 +
 libavformat/allformats.c |  1 +
 libavformat/sbcdec.c | 33 +
 4 files changed, 36 insertions(+)
 create mode 100644 libavformat/sbcdec.c

diff --git a/doc/general.texi b/doc/general.texi
index 1b009a4b89..930c1e8bf2 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -479,6 +479,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
+@item raw SBC   @tab   @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 7ac1ba95ad..1efa3a54f8 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -448,6 +448,7 @@ OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
+OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index e75cd917e4..04164607ce 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -350,6 +350,7 @@ extern AVInputFormat  ff_s337m_demuxer;
 extern AVInputFormat  ff_sami_demuxer;
 extern AVInputFormat  ff_sap_demuxer;
 extern AVOutputFormat ff_sap_muxer;
+extern AVInputFormat  ff_sbc_demuxer;
 extern AVInputFormat  ff_sbg_demuxer;
 extern AVInputFormat  ff_scc_demuxer;
 extern AVOutputFormat ff_scc_muxer;
diff --git a/libavformat/sbcdec.c b/libavformat/sbcdec.c
new file mode 100644
index 00..ae74a220dc
--- /dev/null
+++ b/libavformat/sbcdec.c
@@ -0,0 +1,33 @@
+/*
+ * RAW SBC demuxer
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rawdec.h"
+
+AVInputFormat ff_sbc_demuxer = {
+.name   = "sbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw SBC (low-complexity subband 
codec)"),
+.extensions = "sbc,msbc",
+.raw_codec_id   = AV_CODEC_ID_SBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
-- 
2.16.1

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


[FFmpeg-devel] [PATCH 2/9] sbc: implement SBC decoder (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/avcodec.h |   1 +
 libavcodec/codec_desc.c  |   7 +
 libavcodec/sbc.c | 271 +++
 libavcodec/sbc.h | 121 ++
 libavcodec/sbcdec.c  | 411 +++
 libavcodec/sbcdec_data.c | 127 +++
 libavcodec/sbcdec_data.h |  44 +
 10 files changed, 986 insertions(+)
 create mode 100644 libavcodec/sbc.c
 create mode 100644 libavcodec/sbc.h
 create mode 100644 libavcodec/sbcdec.c
 create mode 100644 libavcodec/sbcdec_data.c
 create mode 100644 libavcodec/sbcdec_data.h

diff --git a/doc/general.texi b/doc/general.texi
index 9ddcccf041..1b009a4b89 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1117,6 +1117,8 @@ 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
+@tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
 @tab Used in Sierra VMD files.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3d4b738e0b..e2a87e404c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -583,6 +583,7 @@ OBJS-$(CONFIG_SUBVIEWER_DECODER)   += subviewerdec.o 
ass.o
 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_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 774b78ef09..7d9097dcf7 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_decoder;
 extern AVCodec ff_shorten_decoder;
 extern AVCodec ff_sipr_decoder;
 extern AVCodec ff_smackaud_decoder;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bc0eacd66b..ae84ba7212 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -635,6 +635,7 @@ enum AVCodecID {
 AV_CODEC_ID_DOLBY_E,
 AV_CODEC_ID_APTX,
 AV_CODEC_ID_APTX_HD,
+AV_CODEC_ID_SBC,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 44a54a31c9..b5d495c5d4 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2863,6 +2863,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("aptX HD (Audio Processing 
Technology for Bluetooth)"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_SBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband 
codec)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/sbc.c b/libavcodec/sbc.c
new file mode 100644
index 00..f7dba79f4f
--- /dev/null
+++ b/libavcodec/sbc.c
@@ -0,0 +1,271 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2008  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 common functions for the e

[FFmpeg-devel] [PATCH 1/9] crc: add AV_CRC_8_SBC as a 8 bits CRC with polynomial 0x1D

2018-02-21 Thread Aurelien Jacobs
---
 libavutil/crc.c   | 26 ++
 libavutil/crc.h   |  1 +
 libavutil/tests/crc.c |  7 ---
 tests/ref/fate/crc|  1 +
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/libavutil/crc.c b/libavutil/crc.c
index d44550c9c0..c45ea63a62 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -52,6 +52,30 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
 0xFA, 0xFD, 0xF4, 0xF3, 0x01
 },
+[AV_CRC_8_EBU] = {
+0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF,
+0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E,
+0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76, 0x87, 0x9A, 0xBD, 0xA0,
+0xF3, 0xEE, 0xC9, 0xD4, 0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 0x3C,
+0x4A, 0x57, 0x70, 0x6D, 0x3E, 0x23, 0x04, 0x19, 0xA2, 0xBF, 0x98, 0x85,
+0xD6, 0xCB, 0xEC, 0xF1, 0x13, 0x0E, 0x29, 0x34, 0x67, 0x7A, 0x5D, 0x40,
+0xFB, 0xE6, 0xC1, 0xDC, 0x8F, 0x92, 0xB5, 0xA8, 0xDE, 0xC3, 0xE4, 0xF9,
+0xAA, 0xB7, 0x90, 0x8D, 0x36, 0x2B, 0x0C, 0x11, 0x42, 0x5F, 0x78, 0x65,
+0x94, 0x89, 0xAE, 0xB3, 0xE0, 0xFD, 0xDA, 0xC7, 0x7C, 0x61, 0x46, 0x5B,
+0x08, 0x15, 0x32, 0x2F, 0x59, 0x44, 0x63, 0x7E, 0x2D, 0x30, 0x17, 0x0A,
+0xB1, 0xAC, 0x8B, 0x96, 0xC5, 0xD8, 0xFF, 0xE2, 0x26, 0x3B, 0x1C, 0x01,
+0x52, 0x4F, 0x68, 0x75, 0xCE, 0xD3, 0xF4, 0xE9, 0xBA, 0xA7, 0x80, 0x9D,
+0xEB, 0xF6, 0xD1, 0xCC, 0x9F, 0x82, 0xA5, 0xB8, 0x03, 0x1E, 0x39, 0x24,
+0x77, 0x6A, 0x4D, 0x50, 0xA1, 0xBC, 0x9B, 0x86, 0xD5, 0xC8, 0xEF, 0xF2,
+0x49, 0x54, 0x73, 0x6E, 0x3D, 0x20, 0x07, 0x1A, 0x6C, 0x71, 0x56, 0x4B,
+0x18, 0x05, 0x22, 0x3F, 0x84, 0x99, 0xBE, 0xA3, 0xF0, 0xED, 0xCA, 0xD7,
+0x35, 0x28, 0x0F, 0x12, 0x41, 0x5C, 0x7B, 0x66, 0xDD, 0xC0, 0xE7, 0xFA,
+0xA9, 0xB4, 0x93, 0x8E, 0xF8, 0xE5, 0xC2, 0xDF, 0x8C, 0x91, 0xB6, 0xAB,
+0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95,
+0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
+0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0,
+0xE3, 0xFE, 0xD9, 0xC4, 0x01
+},
 [AV_CRC_16_ANSI] = {
 0x, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
 0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
@@ -305,6 +329,7 @@ static void id ## _init_table_once(void)
 #define CRC_INIT_TABLE_ONCE(id) ff_thread_once( ## _once_control, id ## 
_init_table_once)
 
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM,  0,  8,   0x07)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_EBU,  0,  8,   0x1D)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI,0, 16, 0x8005)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT,   0, 16, 0x1021)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE,0, 24,   0x864CFB)
@@ -351,6 +376,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id)
 #if !CONFIG_HARDCODED_TABLES
 switch (crc_id) {
 case AV_CRC_8_ATM:  CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM); break;
+case AV_CRC_8_EBU:  CRC_INIT_TABLE_ONCE(AV_CRC_8_EBU); break;
 case AV_CRC_16_ANSI:CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI); break;
 case AV_CRC_16_CCITT:   CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT); break;
 case AV_CRC_24_IEEE:CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE); break;
diff --git a/libavutil/crc.h b/libavutil/crc.h
index fe9a7c8fcb..47e22b4c78 100644
--- a/libavutil/crc.h
+++ b/libavutil/crc.h
@@ -54,6 +54,7 @@ typedef enum {
 AV_CRC_32_IEEE_LE,  /*< reversed bitorder version of AV_CRC_32_IEEE */
 AV_CRC_16_ANSI_LE,  /*< reversed bitorder version of AV_CRC_16_ANSI */
 AV_CRC_24_IEEE,
+AV_CRC_8_EBU,
 AV_CRC_MAX, /*< Not part of public API! Do not use outside 
libavutil. */
 }AVCRCId;
 
diff --git a/libavutil/tests/crc.c b/libavutil/tests/crc.c
index 9825d6bec9..413aada8a2 100644
--- a/libavutil/tests/crc.c
+++ b/libavutil/tests/crc.c
@@ -25,20 +25,21 @@ int main(void)
 {
 uint8_t buf[1999];
 int i;
-static const unsigned p[6][3] = {
+static const unsigned p[7][3] = {
 { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
 { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
 { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
 { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 },
 { AV_CRC_16_ANSI   , 0x8005, 0x1FBB },
-{ AV_CRC_8_ATM , 0x07  , 0xE3   }
+{ AV_CRC_8_ATM , 0x07  , 0xE3   },
+{ AV_CRC_8_EBU , 0x1D  , 0xD6   },
 };
 const AVCRC *ctx;
 
 for (i = 0; i < sizeof(buf); i++)
 buf[i] = i + i * i;
 
-for (i = 0; i < 6; i++) {
+for (i = 0; i < 7; i++) {
 ctx = av_crc_get_table(p[i][0]);
 printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
 }
diff --git a/tests/ref/fate/crc b/tests/ref/fate/crc

[FFmpeg-devel] SBC codec reworked

2018-02-21 Thread Aurelien Jacobs
Hi,

I finnally came back to this SBC codec patchset.
I made the changes to only have one CODEC_ID for both sbc and msbc.
I think I took care of all the remarks from previous review.
Any more comments ?

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


Re: [FFmpeg-devel] [PATCH] MAINTAINERS: add myself for aptx.c

2018-02-10 Thread Aurelien Jacobs
On Fri, Feb 09, 2018 at 10:27:39PM +0100, Aurelien Jacobs wrote:
> ---
>  MAINTAINERS | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index ba7a7284eb..b691bd56ec 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -139,6 +139,7 @@ Codecs:
>aacenc*, aaccoder.c   Rostislav Pehlivanov
>alacenc.c Jaikrishnan Menon
>alsdec.c  Thilo Borgmann, Umair Khan
> +  aptx.c    Aurelien Jacobs
>ass*      Aurelien Jacobs
>asv*  Michael Niedermayer
>atrac3plus*   Maxim Poliakovski

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


[FFmpeg-devel] [PATCH] MAINTAINERS: add myself for aptx.c

2018-02-09 Thread Aurelien Jacobs
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index ba7a7284eb..b691bd56ec 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -139,6 +139,7 @@ Codecs:
   aacenc*, aaccoder.c   Rostislav Pehlivanov
   alacenc.c Jaikrishnan Menon
   alsdec.c  Thilo Borgmann, Umair Khan
+  aptx.cAurelien Jacobs
   ass*  Aurelien Jacobs
   asv*  Michael Niedermayer
   atrac3plus*   Maxim Poliakovski
-- 
2.16.1

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


Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-02-09 Thread Aurelien Jacobs
On Mon, Feb 05, 2018 at 12:27:20AM +0100, Michael Niedermayer wrote:
> On Sun, Feb 04, 2018 at 04:07:26PM +0100, Aurelien Jacobs wrote:
> > On Sat, Jan 20, 2018 at 11:20:22PM +, Rostislav Pehlivanov wrote:
> > > On 20 January 2018 at 17:26, Aurelien Jacobs <au...@gnuage.org> wrote:
> > > 
> > > > On Sun, Jan 14, 2018 at 10:54:34PM +0100, Carl Eugen Hoyos wrote:
> > > > > 2018-01-14 14:06 GMT+01:00 Aurelien Jacobs <au...@gnuage.org>:
> > > > >
> > > > > > Well, here is an updated patch which uses codec tags for the decoder
> > > > and
> > > > > > profile for the encoder.
> > > > >
> > > > > Sorry but I object to this patch:
> > > > > We should not invent codec_tags.
> > > >
> > > > OK, I understand, and I agree.
> > > >
> > > > But now we are in an interlocking situation.
> > > > We have 2 solutions to handle aptX vs. aptX HD but those 2 solutions 
> > > > have
> > > > been rejected by 2 different person.
> > > >
> > > > Do anybody have a 3rd solution, that everyone would accept ?
> > > >
> > > > And if not, how do we resolve this ?
> > > > Is there any policy nowadays to handle this kind of interlocking ?
> > > >
> > > 
> > > Fine, I see no choice but to use multiple codec IDs for aptxhd since the
> > > format really provides you with nothing bitstream wise to determine what 
> > > it
> > > is. Even game codecs have a bit or two for version.
> > 
> > OK. Good.
> 
> > Now, will someone push the original patchset ?
> 
> I think you should be able to push it yourself if there are no review
> comments remaining
> you are listed in MAINTAINERS for some parts and i see a "ajacobs" for ffmpeg
> so you should have git write access

OK. Well I digged out my ssh key from old laptop, an I pushed it myself.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-02-04 Thread Aurelien Jacobs
On Sat, Jan 20, 2018 at 11:20:22PM +, Rostislav Pehlivanov wrote:
> On 20 January 2018 at 17:26, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > On Sun, Jan 14, 2018 at 10:54:34PM +0100, Carl Eugen Hoyos wrote:
> > > 2018-01-14 14:06 GMT+01:00 Aurelien Jacobs <au...@gnuage.org>:
> > >
> > > > Well, here is an updated patch which uses codec tags for the decoder
> > and
> > > > profile for the encoder.
> > >
> > > Sorry but I object to this patch:
> > > We should not invent codec_tags.
> >
> > OK, I understand, and I agree.
> >
> > But now we are in an interlocking situation.
> > We have 2 solutions to handle aptX vs. aptX HD but those 2 solutions have
> > been rejected by 2 different person.
> >
> > Do anybody have a 3rd solution, that everyone would accept ?
> >
> > And if not, how do we resolve this ?
> > Is there any policy nowadays to handle this kind of interlocking ?
> >
> 
> Fine, I see no choice but to use multiple codec IDs for aptxhd since the
> format really provides you with nothing bitstream wise to determine what it
> is. Even game codecs have a bit or two for version.

OK. Good.
Now, will someone push the original patchset ?
Or should I rebase it and submt it again ?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-20 Thread Aurelien Jacobs
On Sun, Jan 14, 2018 at 10:54:34PM +0100, Carl Eugen Hoyos wrote:
> 2018-01-14 14:06 GMT+01:00 Aurelien Jacobs <au...@gnuage.org>:
> 
> > Well, here is an updated patch which uses codec tags for the decoder and
> > profile for the encoder.
> 
> Sorry but I object to this patch:
> We should not invent codec_tags.

OK, I understand, and I agree.

But now we are in an interlocking situation.
We have 2 solutions to handle aptX vs. aptX HD but those 2 solutions have
been rejected by 2 different person.

Do anybody have a 3rd solution, that everyone would accept ?

And if not, how do we resolve this ?
Is there any policy nowadays to handle this kind of interlocking ?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-20 Thread Aurelien Jacobs
On Sun, Jan 14, 2018 at 05:19:12PM +, Rostislav Pehlivanov wrote:
> On 14 January 2018 at 13:06, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > On Tue, Jan 09, 2018 at 02:21:02PM +, Rostislav Pehlivanov wrote:
> > > On 9 January 2018 at 14:07, Rostislav Pehlivanov <atomnu...@gmail.com>
> > > wrote:
> > >
> > > >
> > > >
> > > > On 9 January 2018 at 09:00, Hendrik Leppkes <h.lepp...@gmail.com>
> > wrote:
> > > >
> > > >> On Tue, Jan 9, 2018 at 9:33 AM, Hendrik Leppkes <h.lepp...@gmail.com>
> > > >> wrote:
> > > >> > On Tue, Jan 9, 2018 at 5:07 AM, Rostislav Pehlivanov
> > > >> > <atomnu...@gmail.com> wrote:
> > > >> >>
> > > >> >>> Anyway, all this discussion is moot as Hendrik pointed out that
> > > >> profile
> > > >> >>> can't be set outside of lavc to determine a decoder behavior.
> > > >> >>>
> > > >> >>
> > > >> >> What, based on a comment in lavc? Comments there describe the api
> > but
> > > >> they
> > > >> >> rarely define it. We're free to adjust them if need be and in this
> > > >> case,
> > > >> >> since the codec profile may not be set, the API user is forced to
> > deal
> > > >> with
> > > >> >> the lack of such set. Hence, we can clarify that it may be set by
> > lavf
> > > >> as
> > > >> >> well as lavc as well as not being set at all. And the decoder may
> > use
> > > >> it.
> > > >> >> I maintain that adding a new codec ID for this is unacceptable.
> > > >> >>
> > > >> >
> > > >> > We already have established methods to select codec sub-variants, we
> > > >> > don't need to invent a new one just because you feel like it.
> > > >> >
> > > >>
> > > >> On that note, we also have cases where the same codec has different
> > > >> codec ids based on popular known names.
> > > >> For example wmv3/vc1 - wmv3 is simple/main profile, vc1 is advanced
> > > >> profile, different codec ids, same implementation.
> > > >>
> > > >> Re-defining public API is what is unacceptable, it requires every
> > > >> caller of lavc to suddenly start handling one more field for no real
> > > >> reason.
> > > >>
> > > >
> > > > Then its a good thing I suggested something that doesn't involve having
> > > > every caller of lavc to handle another field.
> > > >
> > > >
> > > >
> > > >> Either use a separate codec ID if there is sufficient reason for that
> > > >> (mostly driven by external factors, if its handled as different codecs
> > > >> everywhere else, not only in marketing but actual (reference)
> > > >> implementations), or use a codec_tag if one is available (the codec id
> > > >> field from a2dp for example)
> > > >
> > > > I'd be fine with using codec tags, but not with codec IDs.
> > >
> > > Though for encoding using profiles would be best.
> >
> > Well, here is an updated patch which uses codec tags for the decoder and
> > profile for the encoder.
> >
> > I still maintain that this solution is worse than using separate
> > codec IDs.
> > It is worse for developper / maintainer as it adds a bit of compexity to
> > the code.
> >
> > It is worse for user as it requires adding a mandatory parameter for
> > encoding to aptX HD:
> >   ffmpeg -i sample.wav -profile:a 1 sample.aptxhd
> >
> 
> As opposed to having a mandatory parameter for encoder like -c:a
> aptx_hd?

No. As opposed to:
ffmpeg -i sample.wav sample.aptxhd

> Perhaps we should encode everything to aptx hd by default to not have to
> mess about by confusing users with these codecs or profiles things.

?
It is sensible to use the aptxhd encoder by default when muxing to raw
aptxhd. And it is sensible to use the aptx encoder by default when
muxing to raw aptx.
Or do you disagree about this ?

> > Without this -profile parameter, the encoding will just fail but user
> > will have to guess how to fix it.
> >
> 
> Here's how you could fix it: don't have separate muxers for aptx and
> aptxhd. Make the aptx muxer handle both .aptx and .aptxhd extensions and
> the code

Re: [FFmpeg-devel] [PATCH 5/5] aptx: add raw muxer and demuxer for aptX HD

2018-01-14 Thread Aurelien Jacobs
On Sun, Jan 07, 2018 at 04:55:43PM +0100, Aurelien Jacobs wrote:
> On Sun, Jan 07, 2018 at 12:53:27AM +0100, Michael Niedermayer wrote:
> > On Sat, Jan 06, 2018 at 05:48:08PM +0100, Aurelien Jacobs wrote:
> > > ---
> > >  Changelog|  2 +-
> > >  libavformat/Makefile |  2 ++
> > >  libavformat/allformats.c |  1 +
> > >  libavformat/aptxdec.c| 51 
> > > 
> > >  libavformat/rawenc.c | 13 
> > >  5 files changed, 64 insertions(+), 5 deletions(-)
> > [...]
> > > @@ -66,6 +94,7 @@ static const AVClass aptx_demuxer_class = {
> > >  .version= LIBAVUTIL_VERSION_INT,
> > >  };
> > >  
> > > +#if CONFIG_APTX_MUXER
> > >  AVInputFormat ff_aptx_demuxer = {
> > >  .name   = "aptx",
> > >  .long_name  = NULL_IF_CONFIG_SMALL("raw aptX"),
> > > @@ -76,3 +105,17 @@ AVInputFormat ff_aptx_demuxer = {
> > >  .flags  = AVFMT_GENERIC_INDEX,
> > 
> > >  .priv_class = _demuxer_class,
> > [...]
> > > +.priv_class = _demuxer_class,
> > 
> > this cause the code (for example fate) to infinite loop
> 
> Oh, indeed, it seems 2 demuxers can't share the same priv_class.
> Here is an updated patch.

Here is an updated version to match the single codec ID version of the
encoder / decoder, by using codec_tag.
>From a63645428b4d8332f5389dfe0f66229a5bfe8058 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sat, 6 Jan 2018 17:33:01 +0100
Subject: [PATCH 5/5] aptx: add raw muxer and demuxer for aptX HD

---
 Changelog|  2 +-
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  1 +
 libavformat/aptxdec.c| 68 +---
 libavformat/rawenc.c | 33 ++-
 5 files changed, 100 insertions(+), 6 deletions(-)

diff --git a/Changelog b/Changelog
index 9349bf1e8d..3a97b0b02e 100644
--- a/Changelog
+++ b/Changelog
@@ -12,7 +12,7 @@ version :
 - Intel QSV-accelerated MJPEG encoding
 - PCE support for extended channel layouts in the AAC encoder
 - native aptX and aptX HD encoder and decoder
-- Raw aptX muxer and demuxer
+- Raw aptX and aptX HD muxer and demuxer
 - NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding
 - Intel QSV-accelerated overlay filter
 - mcompand audio filter
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..dbe2890297 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -96,6 +96,8 @@ OBJS-$(CONFIG_APNG_DEMUXER)  += apngdec.o
 OBJS-$(CONFIG_APNG_MUXER)+= apngenc.o
 OBJS-$(CONFIG_APTX_DEMUXER)  += aptxdec.o rawdec.o
 OBJS-$(CONFIG_APTX_MUXER)+= rawenc.o
+OBJS-$(CONFIG_APTX_HD_DEMUXER)   += aptxdec.o rawdec.o
+OBJS-$(CONFIG_APTX_HD_MUXER) += rawenc.o
 OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
 OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
 avlanguage.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..b70b7463b9 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -70,6 +70,7 @@ static void register_all(void)
 REGISTER_DEMUXER (APE,  ape);
 REGISTER_MUXDEMUX(APNG, apng);
 REGISTER_MUXDEMUX(APTX, aptx);
+REGISTER_MUXDEMUX(APTX_HD,  aptx_hd);
 REGISTER_DEMUXER (AQTITLE,  aqtitle);
 REGISTER_MUXDEMUX(ASF,  asf);
 REGISTER_DEMUXER (ASF_O,asf_o);
diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
index 3b8fae1b55..dfa07337b6 100644
--- a/libavformat/aptxdec.c
+++ b/libavformat/aptxdec.c
@@ -26,26 +26,59 @@
 #define APTX_BLOCK_SIZE   4
 #define APTX_PACKET_SIZE  (256*APTX_BLOCK_SIZE)
 
+#define APTX_HD_BLOCK_SIZE   6
+#define APTX_HD_PACKET_SIZE  (256*APTX_HD_BLOCK_SIZE)
+
+#define A2DP_VENDOR_ID_APT  0x004F
+#define A2DP_APT_CODEC_ID_APTX  0x0001
+
+#define A2DP_VENDOR_ID_QUALCOMM 0x00D7
+#define A2DP_QUALCOMM_CODEC_ID_APTX_HD  0x0024
+
 typedef struct AptXDemuxerContext {
 AVClass *class;
 int sample_rate;
 } AptXDemuxerContext;
 
-static int aptx_read_header(AVFormatContext *s)
+static AVStream *aptx_read_header_common(AVFormatContext *s)
 {
 AptXDemuxerContext *s1 = s->priv_data;
 AVStream *st = avformat_new_stream(s, NULL);
 if (!st)
-return AVERROR(ENOMEM);
+return NULL;
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_APTX;
 st->codecpar->format = AV_SAMPLE_FMT_S32P;
 st->codecpar->

Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-14 Thread Aurelien Jacobs
On Tue, Jan 09, 2018 at 02:21:02PM +, Rostislav Pehlivanov wrote:
> On 9 January 2018 at 14:07, Rostislav Pehlivanov <atomnu...@gmail.com>
> wrote:
> 
> >
> >
> > On 9 January 2018 at 09:00, Hendrik Leppkes <h.lepp...@gmail.com> wrote:
> >
> >> On Tue, Jan 9, 2018 at 9:33 AM, Hendrik Leppkes <h.lepp...@gmail.com>
> >> wrote:
> >> > On Tue, Jan 9, 2018 at 5:07 AM, Rostislav Pehlivanov
> >> > <atomnu...@gmail.com> wrote:
> >> >>
> >> >>> Anyway, all this discussion is moot as Hendrik pointed out that
> >> profile
> >> >>> can't be set outside of lavc to determine a decoder behavior.
> >> >>>
> >> >>
> >> >> What, based on a comment in lavc? Comments there describe the api but
> >> they
> >> >> rarely define it. We're free to adjust them if need be and in this
> >> case,
> >> >> since the codec profile may not be set, the API user is forced to deal
> >> with
> >> >> the lack of such set. Hence, we can clarify that it may be set by lavf
> >> as
> >> >> well as lavc as well as not being set at all. And the decoder may use
> >> it.
> >> >> I maintain that adding a new codec ID for this is unacceptable.
> >> >>
> >> >
> >> > We already have established methods to select codec sub-variants, we
> >> > don't need to invent a new one just because you feel like it.
> >> >
> >>
> >> On that note, we also have cases where the same codec has different
> >> codec ids based on popular known names.
> >> For example wmv3/vc1 - wmv3 is simple/main profile, vc1 is advanced
> >> profile, different codec ids, same implementation.
> >>
> >> Re-defining public API is what is unacceptable, it requires every
> >> caller of lavc to suddenly start handling one more field for no real
> >> reason.
> >>
> >
> > Then its a good thing I suggested something that doesn't involve having
> > every caller of lavc to handle another field.
> >
> >
> >
> >> Either use a separate codec ID if there is sufficient reason for that
> >> (mostly driven by external factors, if its handled as different codecs
> >> everywhere else, not only in marketing but actual (reference)
> >> implementations), or use a codec_tag if one is available (the codec id
> >> field from a2dp for example)
> >
> > I'd be fine with using codec tags, but not with codec IDs.
>
> Though for encoding using profiles would be best.

Well, here is an updated patch which uses codec tags for the decoder and
profile for the encoder.

I still maintain that this solution is worse than using separate
codec IDs.
It is worse for developper / maintainer as it adds a bit of compexity to
the code.
It is worse for user as it requires adding a mandatory parameter for
encoding to aptX HD:
  ffmpeg -i sample.wav -profile:a 1 sample.aptxhd
Without this -profile parameter, the encoding will just fail but user
will have to guess how to fix it.
And the reported stream is much less explicit:
  Stream #0:0: Audio: aptx ([36][0][215][0] / 0xD70024), 48000 Hz, 2 channels, 
s32p
vs.
  Stream #0:0: Audio: aptx_hd, 48000 Hz, 2 channels, s32p

So for the good of users and maintainers, I suggest to follow the
wmv3/vc1 example, that is to acknowledge that aptX and aptX HD are
commonly used as 2 separate codecs (search for
libaptX-1.0.0-rel-Android21-ARMv7A.so and
libaptXHD-1.0.0-rel-Android21-ARMv7A.so for example) and use the
original patch with 2 codec IDs.
But anyway, if there is a consensus for using a single codec ID, this
new patch can be applied.
>From bdf5d5f4a3724a70efe0cad76179a57619c6fad0 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sat, 6 Jan 2018 17:11:48 +0100
Subject: [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

---
 Changelog |   2 +-
 libavcodec/Makefile   |   2 +
 libavcodec/aptx.c | 352 +-
 libavcodec/avcodec.h  |   3 +
 libavcodec/profiles.c |   6 +
 libavcodec/profiles.h |   1 +
 6 files changed, 336 insertions(+), 30 deletions(-)

diff --git a/Changelog b/Changelog
index 3d966c202b..9349bf1e8d 100644
--- a/Changelog
+++ b/Changelog
@@ -11,7 +11,7 @@ version :
 - TiVo ty/ty+ demuxer
 - Intel QSV-accelerated MJPEG encoding
 - PCE support for extended channel layouts in the AAC encoder
-- native aptX encoder and decoder
+- native aptX and aptX HD encoder and decoder
 - Raw aptX muxer and demuxer
 - NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding
 - Intel QSV-accelera

Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-08 Thread Aurelien Jacobs
On Mon, Jan 08, 2018 at 12:38:19AM +, Rostislav Pehlivanov wrote:
> On 7 January 2018 at 22:54, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > On Sun, Jan 07, 2018 at 05:23:24PM +, Rostislav Pehlivanov wrote:
> > > On 6 January 2018 at 16:48, Aurelien Jacobs <au...@gnuage.org> wrote:
> > >
> > > > ---
> > > >  Changelog   |   2 +-
> > > >  configure   |   2 +
> > > >  libavcodec/Makefile |   2 +
> > > >  libavcodec/allcodecs.c  |   1 +
> > > >  libavcodec/aptx.c   | 352 ++
> > > > ++
> > > >  libavcodec/avcodec.h|   1 +
> > > >  libavcodec/codec_desc.c |   7 +
> > > >  7 files changed, 339 insertions(+), 28 deletions(-)
> > >
> > >
> > > No, don't add a new codec ID for what is very obviously a profile.
> > >
> [...]
> > Anyway, I do understand how I could use a profile instead of a new codec
> > ID, but I really don't understand what advantage it would bring ?
> >
> > For a codec known with one name, but supporting a lot of different
> > profiles with flags in the bitstream so that the decoder can adapt
> > itself to any profile, that makes a lot of sense. But for aptX and
> > aptX HD it doesn't make any sense to me.
> >
> 
> It makes sense - HD is just a flavor of aptx. You can't call this a brand
> new codec - it just changes some tables and the way codewords are written
> (1 function).

Of course it does make sense to us, the few people who are touching
codecs source code, that they are both flavors of the same code.

> The only people who would call that brand new are in
> marketing and they're wrong.

Of course calling aptX and aptX HD different codecs is pretty much
marketting bullshit.

But that's not the point here.
We are not talking about some internal implementation details.
We are talking about ffmpeg's end user interface. So what we do
has to make sense to end user. And end users "knows very well" that
aptX and aptX HD are 2 different codecs (they are used for exemple
to install 2 differents libs on android to support both).

> > I don't think it would make the code simpler.
> > The decoder itself has no flag in the bitstream to adapt to the correct
> > "profile".
> >
> And I think it would be confusing for end user. aptX HD is publicly know
> > as a different codec than aptX. A user looking at the list of supported
> > codec would probably conclude that aptX is supported but not aptX HD.
> >
> > Also, the closest thing I can think as a standard container for aptX
> > is the bluetooth A2DP protocol. And in this protocol, aptX and aptX HD
> > are differentiated with a different codec ID, just the same way they
> > are differentiated from SBC or LDAC.
> >
> > So in the end, using different codec ID seems pretty natural, while
> > using different profiles seems akward and doesn't seem to bring any
> > advantage.
> >
> > Can you give any technical reason why think using profile would be
> > better ?
> >
> 
> Yes, a big one - we don't bloat the already humongous API. You might say:
> "Well, we have hundreds of codec IDs, what's one more?". If we had a new
> codec ID for every flavor of every codec, we'd have thousands.

So what ? It won't increase binary bloat unless we ever reach more
than 2^32 codecs.
And regarding public API bloat, the 2 options are:
 1) define 2 codec ID consts
 2) define 1 codec ID const and 2 profile consts
Which one is bloating the public API more ?

> The profile systems allows us to discern between actually marketed variants
> of one codec with the same name, for example AAC-LC with AAC-LTP.

Do you really think that AAC-LTP is marketed as a unique codec to end
users ? I've never stumbled on this.

Anyway, all this discussion is moot as Hendrik pointed out that profile
can't be set outside of lavc to determine a decoder behavior.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-08 Thread Aurelien Jacobs
On Mon, Jan 08, 2018 at 01:27:16PM +0100, Carl Eugen Hoyos wrote:
> 2018-01-08 11:32 GMT+01:00 Hendrik Leppkes :
> > On Mon, Jan 8, 2018 at 1:38 AM, Rostislav Pehlivanov
> >  wrote:
> >>
> >> That's okay - for encoding switch the profile depending on both the
> >> avctx->profile setting and the samplerate and list all supported
> >> samplerates for all profiles in the AVCodec structure. We do something
> >> similar in the AAC encoder where we pick different settings depending on
> >> the profile and change the profile depending on the settings listed.
> >> If there's an overlap, pick a sane default unless the user forces a profile
> >> using profile:a. If forced and the samplerate isn't supported - error out
> >> and let the user know.
> >> For decoding set the profile via the demuxer. There doesn't have to be just
> >> one demuxer for a codec. If there are major changes in how you parse
> >> profiles go ahead and make a new one which sets the codec ID and the
> >> profile.
> >>
> >
> > I don't think there is any precedent for "profile" being mandatory for
> > a decoder to work, so that might be iffy. Decoders usually set
> > profile, don't require it.
> > ie. from the docs:
> > * - decoding: Set by libavcodec.

Oh, very true. I guess that settles it for "profile". Public API do not
allows using profile to select the appropriate decoder.

> > There is plenty precedent for using "codec_tag" however, so that may
> > be a better choice - and can hold the tag from the "container" as-is
> > as well.
> 
> While I don't understand why even having more than one codec_id for
> the same codec (which afaiu isn't the case here) would be an issue,

Same for me, I don't understand why adding a codec_id would be an issue.

> I don't think we should invent codec_tags unless necessary.

I agree. And I don't think there is a container used for aptX or aptX HD
in the wild with some kind of codec_tag. So this is probably not an
option either.

I maintain that using 2 codec IDs is the most appropriate in this
specific case.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-07 Thread Aurelien Jacobs
On Sun, Jan 07, 2018 at 05:23:24PM +, Rostislav Pehlivanov wrote:
> On 6 January 2018 at 16:48, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > ---
> >  Changelog   |   2 +-
> >  configure   |   2 +
> >  libavcodec/Makefile |   2 +
> >  libavcodec/allcodecs.c  |   1 +
> >  libavcodec/aptx.c   | 352 ++
> > ++
> >  libavcodec/avcodec.h|   1 +
> >  libavcodec/codec_desc.c |   7 +
> >  7 files changed, 339 insertions(+), 28 deletions(-)
> >
> > diff --git a/Changelog b/Changelog
> > index 3d966c202b..9349bf1e8d 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -11,7 +11,7 @@ version :
> >  - TiVo ty/ty+ demuxer
> >  - Intel QSV-accelerated MJPEG encoding
> >  - PCE support for extended channel layouts in the AAC encoder
> > -- native aptX encoder and decoder
> > +- native aptX and aptX HD encoder and decoder
> >  - Raw aptX muxer and demuxer
> >  - NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel
> > decoding
> >  - Intel QSV-accelerated overlay filter
> > diff --git a/configure b/configure
> > index 1d2fffa132..c496346a06 100755
> > --- a/configure
> > +++ b/configure
> > @@ -2459,6 +2459,8 @@ apng_encoder_deps="zlib"
> >  apng_encoder_select="llvidencdsp"
> >  aptx_decoder_select="audio_frame_queue"
> >  aptx_encoder_select="audio_frame_queue"
> > +aptx_hd_decoder_select="audio_frame_queue"
> > +aptx_hd_encoder_select="audio_frame_queue"
> >  asv1_decoder_select="blockdsp bswapdsp idctdsp"
> >  asv1_encoder_select="bswapdsp fdctdsp pixblockdsp"
> >  asv2_decoder_select="blockdsp bswapdsp idctdsp"
> > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > index cfacd6b70c..a9ecf7ea5e 100644
> > --- a/libavcodec/Makefile
> > +++ b/libavcodec/Makefile
> > @@ -190,6 +190,8 @@ OBJS-$(CONFIG_ANSI_DECODER)+= ansi.o
> > cga_data.o
> >  OBJS-$(CONFIG_APE_DECODER) += apedec.o
> >  OBJS-$(CONFIG_APTX_DECODER)+= aptx.o
> >  OBJS-$(CONFIG_APTX_ENCODER)+= aptx.o
> > +OBJS-$(CONFIG_APTX_HD_DECODER) += aptx.o
> > +OBJS-$(CONFIG_APTX_HD_ENCODER) += aptx.o
> >  OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o pngdsp.o
> >  OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
> >  OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
> > diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> > index ed1e7ab06e..93d31f8688 100644
> > --- a/libavcodec/allcodecs.c
> > +++ b/libavcodec/allcodecs.c
> > [...]
> > @@ -844,6 +1105,24 @@ AVCodec ff_aptx_decoder = {
> >  };
> >  #endif
> >
> > +#if CONFIG_APTX_HD_DECODER
> > +AVCodec ff_aptx_hd_decoder = {
> > +.name  = "aptx_hd",
> > +.long_name = NULL_IF_CONFIG_SMALL("aptX HD (Audio
> > Processing Technology for Bluetooth)"),
> > +.type  = AVMEDIA_TYPE_AUDIO,
> > +.id= AV_CODEC_ID_APTX_HD,
> > +.priv_data_size= sizeof(AptXContext),
> > +.init  = aptx_init,
> > +.decode= aptx_decode_frame,
> > +.close = aptx_close,
> > +.capabilities  = AV_CODEC_CAP_DR1,
> > +.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
> > +.channel_layouts   = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
> > +.sample_fmts   = (const enum AVSampleFormat[]) {
> > AV_SAMPLE_FMT_S32P,
> > +
> >  AV_SAMPLE_FMT_NONE },
> > +};
> > +#endif
> > +
> >  #if CONFIG_APTX_ENCODER
> >  AVCodec ff_aptx_encoder = {
> >  .name  = "aptx",
> > @@ -862,3 +1141,22 @@ AVCodec ff_aptx_encoder = {
> >  .supported_samplerates = (const int[]) {8000, 16000, 24000, 32000,
> > 44100, 48000, 0},
> >  };
> >  #endif
> > +
> > +#if CONFIG_APTX_HD_ENCODER
> > +AVCodec ff_aptx_hd_encoder = {
> > +.name  = "aptx_hd",
> > +.long_name = NULL_IF_CONFIG_SMALL("aptX HD (Audio
> > Processing Technology for Bluetooth)"),
> > +.type  = AVMEDIA_TYPE_AUDIO,
> > +.id= AV_CODEC_ID_APTX_HD,
> > +.priv_data_size= sizeof(AptXContext),
> > +.init  = aptx_init,
> > +.encode2

Re: [FFmpeg-devel] [PATCH 5/5] aptx: add raw muxer and demuxer for aptX HD

2018-01-07 Thread Aurelien Jacobs
On Sun, Jan 07, 2018 at 12:53:27AM +0100, Michael Niedermayer wrote:
> On Sat, Jan 06, 2018 at 05:48:08PM +0100, Aurelien Jacobs wrote:
> > ---
> >  Changelog|  2 +-
> >  libavformat/Makefile |  2 ++
> >  libavformat/allformats.c |  1 +
> >  libavformat/aptxdec.c| 51 
> > 
> >  libavformat/rawenc.c | 13 
> >  5 files changed, 64 insertions(+), 5 deletions(-)
> [...]
> > @@ -66,6 +94,7 @@ static const AVClass aptx_demuxer_class = {
> >  .version= LIBAVUTIL_VERSION_INT,
> >  };
> >  
> > +#if CONFIG_APTX_MUXER
> >  AVInputFormat ff_aptx_demuxer = {
> >  .name   = "aptx",
> >  .long_name  = NULL_IF_CONFIG_SMALL("raw aptX"),
> > @@ -76,3 +105,17 @@ AVInputFormat ff_aptx_demuxer = {
> >  .flags  = AVFMT_GENERIC_INDEX,
> 
> >  .priv_class = _demuxer_class,
> [...]
> > +.priv_class = _demuxer_class,
> 
> this cause the code (for example fate) to infinite loop

Oh, indeed, it seems 2 demuxers can't share the same priv_class.
Here is an updated patch.
>From 319e203fc6ec9ae7b17d28ac63b658a63c933176 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sat, 6 Jan 2018 17:33:01 +0100
Subject: [PATCH 5/5] aptx: add raw muxer and demuxer for aptX HD

---
 Changelog|  2 +-
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  1 +
 libavformat/aptxdec.c| 58 
 libavformat/rawenc.c | 13 +++
 5 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/Changelog b/Changelog
index 9349bf1e8d..3a97b0b02e 100644
--- a/Changelog
+++ b/Changelog
@@ -12,7 +12,7 @@ version :
 - Intel QSV-accelerated MJPEG encoding
 - PCE support for extended channel layouts in the AAC encoder
 - native aptX and aptX HD encoder and decoder
-- Raw aptX muxer and demuxer
+- Raw aptX and aptX HD muxer and demuxer
 - NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding
 - Intel QSV-accelerated overlay filter
 - mcompand audio filter
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..dbe2890297 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -96,6 +96,8 @@ OBJS-$(CONFIG_APNG_DEMUXER)  += apngdec.o
 OBJS-$(CONFIG_APNG_MUXER)+= apngenc.o
 OBJS-$(CONFIG_APTX_DEMUXER)  += aptxdec.o rawdec.o
 OBJS-$(CONFIG_APTX_MUXER)+= rawenc.o
+OBJS-$(CONFIG_APTX_HD_DEMUXER)   += aptxdec.o rawdec.o
+OBJS-$(CONFIG_APTX_HD_MUXER) += rawenc.o
 OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
 OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
 avlanguage.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..b70b7463b9 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -70,6 +70,7 @@ static void register_all(void)
 REGISTER_DEMUXER (APE,  ape);
 REGISTER_MUXDEMUX(APNG, apng);
 REGISTER_MUXDEMUX(APTX, aptx);
+REGISTER_MUXDEMUX(APTX_HD,  aptx_hd);
 REGISTER_DEMUXER (AQTITLE,  aqtitle);
 REGISTER_MUXDEMUX(ASF,  asf);
 REGISTER_DEMUXER (ASF_O,asf_o);
diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
index 3b8fae1b55..467bc3fd5a 100644
--- a/libavformat/aptxdec.c
+++ b/libavformat/aptxdec.c
@@ -26,26 +26,49 @@
 #define APTX_BLOCK_SIZE   4
 #define APTX_PACKET_SIZE  (256*APTX_BLOCK_SIZE)
 
+#define APTX_HD_BLOCK_SIZE   6
+#define APTX_HD_PACKET_SIZE  (256*APTX_HD_BLOCK_SIZE)
+
 typedef struct AptXDemuxerContext {
 AVClass *class;
 int sample_rate;
 } AptXDemuxerContext;
 
-static int aptx_read_header(AVFormatContext *s)
+static AVStream *aptx_read_header_common(AVFormatContext *s)
 {
 AptXDemuxerContext *s1 = s->priv_data;
 AVStream *st = avformat_new_stream(s, NULL);
 if (!st)
-return AVERROR(ENOMEM);
+return NULL;
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_APTX;
 st->codecpar->format = AV_SAMPLE_FMT_S32P;
 st->codecpar->channels = 2;
 st->codecpar->sample_rate = s1->sample_rate;
+st->start_time = 0;
+return st;
+}
+
+static int aptx_read_header(AVFormatContext *s)
+{
+AVStream *st = aptx_read_header_common(s);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar->codec_id = AV_CODEC_ID_APTX;
 st->codecpar->bits_per_coded_sample = 4;
 st->codecpar->block_align = APTX_BLOCK_SIZE;
 st->codecpar->frame_size = APTX_PACKET_SIZE;
-st->start_time = 0;
+return 0;
+}
+
+static int 

[FFmpeg-devel] [PATCH 5/5] aptx: add raw muxer and demuxer for aptX HD

2018-01-06 Thread Aurelien Jacobs
---
 Changelog|  2 +-
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  1 +
 libavformat/aptxdec.c| 51 
 libavformat/rawenc.c | 13 
 5 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/Changelog b/Changelog
index 9349bf1e8d..3a97b0b02e 100644
--- a/Changelog
+++ b/Changelog
@@ -12,7 +12,7 @@ version :
 - Intel QSV-accelerated MJPEG encoding
 - PCE support for extended channel layouts in the AAC encoder
 - native aptX and aptX HD encoder and decoder
-- Raw aptX muxer and demuxer
+- Raw aptX and aptX HD muxer and demuxer
 - NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding
 - Intel QSV-accelerated overlay filter
 - mcompand audio filter
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..dbe2890297 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -96,6 +96,8 @@ OBJS-$(CONFIG_APNG_DEMUXER)  += apngdec.o
 OBJS-$(CONFIG_APNG_MUXER)+= apngenc.o
 OBJS-$(CONFIG_APTX_DEMUXER)  += aptxdec.o rawdec.o
 OBJS-$(CONFIG_APTX_MUXER)+= rawenc.o
+OBJS-$(CONFIG_APTX_HD_DEMUXER)   += aptxdec.o rawdec.o
+OBJS-$(CONFIG_APTX_HD_MUXER) += rawenc.o
 OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
 OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
 avlanguage.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..b70b7463b9 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -70,6 +70,7 @@ static void register_all(void)
 REGISTER_DEMUXER (APE,  ape);
 REGISTER_MUXDEMUX(APNG, apng);
 REGISTER_MUXDEMUX(APTX, aptx);
+REGISTER_MUXDEMUX(APTX_HD,  aptx_hd);
 REGISTER_DEMUXER (AQTITLE,  aqtitle);
 REGISTER_MUXDEMUX(ASF,  asf);
 REGISTER_DEMUXER (ASF_O,asf_o);
diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
index 3b8fae1b55..18c2d76b71 100644
--- a/libavformat/aptxdec.c
+++ b/libavformat/aptxdec.c
@@ -26,26 +26,49 @@
 #define APTX_BLOCK_SIZE   4
 #define APTX_PACKET_SIZE  (256*APTX_BLOCK_SIZE)
 
+#define APTX_HD_BLOCK_SIZE   6
+#define APTX_HD_PACKET_SIZE  (256*APTX_HD_BLOCK_SIZE)
+
 typedef struct AptXDemuxerContext {
 AVClass *class;
 int sample_rate;
 } AptXDemuxerContext;
 
-static int aptx_read_header(AVFormatContext *s)
+static AVStream *aptx_read_header_common(AVFormatContext *s)
 {
 AptXDemuxerContext *s1 = s->priv_data;
 AVStream *st = avformat_new_stream(s, NULL);
 if (!st)
-return AVERROR(ENOMEM);
+return NULL;
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-st->codecpar->codec_id = AV_CODEC_ID_APTX;
 st->codecpar->format = AV_SAMPLE_FMT_S32P;
 st->codecpar->channels = 2;
 st->codecpar->sample_rate = s1->sample_rate;
+st->start_time = 0;
+return st;
+}
+
+static int aptx_read_header(AVFormatContext *s)
+{
+AVStream *st = aptx_read_header_common(s);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar->codec_id = AV_CODEC_ID_APTX;
 st->codecpar->bits_per_coded_sample = 4;
 st->codecpar->block_align = APTX_BLOCK_SIZE;
 st->codecpar->frame_size = APTX_PACKET_SIZE;
-st->start_time = 0;
+return 0;
+}
+
+static int aptx_hd_read_header(AVFormatContext *s)
+{
+AVStream *st = aptx_read_header_common(s);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar->codec_id = AV_CODEC_ID_APTX_HD;
+st->codecpar->bits_per_coded_sample = 6;
+st->codecpar->block_align = APTX_HD_BLOCK_SIZE;
+st->codecpar->frame_size = APTX_HD_PACKET_SIZE;
 return 0;
 }
 
@@ -54,6 +77,11 @@ static int aptx_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
 }
 
+static int aptx_hd_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+return av_get_packet(s->pb, pkt, APTX_HD_PACKET_SIZE);
+}
+
 static const AVOption aptx_options[] = {
 { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), 
AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
 { NULL },
@@ -66,6 +94,7 @@ static const AVClass aptx_demuxer_class = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
+#if CONFIG_APTX_MUXER
 AVInputFormat ff_aptx_demuxer = {
 .name   = "aptx",
 .long_name  = NULL_IF_CONFIG_SMALL("raw aptX"),
@@ -76,3 +105,17 @@ AVInputFormat ff_aptx_demuxer = {
 .flags  = AVFMT_GENERIC_INDEX,
 .priv_class = _demuxer_class,
 };
+#endif
+
+#if CONFIG_APTX_HD_DEMUXER
+AVInputFormat ff_aptx_hd_demuxer = {
+.name   = "aptx_hd",
+.long_name  = NULL_IF_CONFIG_SMALL("raw aptX HD"),
+.extensions = "aptxhd",
+.priv_data_size = sizeof(AptXDemuxerContext),
+.read_header= aptx_hd_read_header,
+.read_packet 

[FFmpeg-devel] [PATCH 2/5] aptx: factorize FFABS calculation

2018-01-06 Thread Aurelien Jacobs
---
 libavcodec/aptx.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index 7b9556ce42..64a63a7d5b 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -462,10 +462,12 @@ static void aptx_quantize_difference(Quantize *quantize,
 {
 const int32_t *intervals = tables->quantize_intervals;
 int32_t quantized_sample, dithered_sample, parity_change;
-int32_t d, mean, interval, inv;
+int32_t d, mean, interval, inv, sample_difference_abs;
 int64_t error;
 
-quantized_sample = aptx_bin_search(FFABS(sample_difference) >> 4,
+sample_difference_abs = FFABS(sample_difference);
+
+quantized_sample = aptx_bin_search(sample_difference_abs >> 4,
quantization_factor,
intervals, tables->tables_size);
 
@@ -477,7 +479,7 @@ static void aptx_quantize_difference(Quantize *quantize,
 interval = (intervals[1] - intervals[0]) * (-(sample_difference < 0) | 1);
 
 dithered_sample = rshift64_clip24(MUL64(dither, interval) + 
((int64_t)(mean + d) << 32), 32);
-error = ((int64_t)FFABS(sample_difference) << 20) - MUL64(dithered_sample, 
quantization_factor);
+error = ((int64_t)sample_difference_abs << 20) - MUL64(dithered_sample, 
quantization_factor);
 quantize->error = FFABS(rshift64(error, 23));
 
 parity_change = quantized_sample;
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 4/5] aptx: implement the aptX HD bluetooth codec

2018-01-06 Thread Aurelien Jacobs
---
 Changelog   |   2 +-
 configure   |   2 +
 libavcodec/Makefile |   2 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/aptx.c   | 352 
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 +
 7 files changed, 339 insertions(+), 28 deletions(-)

diff --git a/Changelog b/Changelog
index 3d966c202b..9349bf1e8d 100644
--- a/Changelog
+++ b/Changelog
@@ -11,7 +11,7 @@ version :
 - TiVo ty/ty+ demuxer
 - Intel QSV-accelerated MJPEG encoding
 - PCE support for extended channel layouts in the AAC encoder
-- native aptX encoder and decoder
+- native aptX and aptX HD encoder and decoder
 - Raw aptX muxer and demuxer
 - NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding
 - Intel QSV-accelerated overlay filter
diff --git a/configure b/configure
index 1d2fffa132..c496346a06 100755
--- a/configure
+++ b/configure
@@ -2459,6 +2459,8 @@ apng_encoder_deps="zlib"
 apng_encoder_select="llvidencdsp"
 aptx_decoder_select="audio_frame_queue"
 aptx_encoder_select="audio_frame_queue"
+aptx_hd_decoder_select="audio_frame_queue"
+aptx_hd_encoder_select="audio_frame_queue"
 asv1_decoder_select="blockdsp bswapdsp idctdsp"
 asv1_encoder_select="bswapdsp fdctdsp pixblockdsp"
 asv2_decoder_select="blockdsp bswapdsp idctdsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfacd6b70c..a9ecf7ea5e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -190,6 +190,8 @@ OBJS-$(CONFIG_ANSI_DECODER)+= ansi.o cga_data.o
 OBJS-$(CONFIG_APE_DECODER) += apedec.o
 OBJS-$(CONFIG_APTX_DECODER)+= aptx.o
 OBJS-$(CONFIG_APTX_ENCODER)+= aptx.o
+OBJS-$(CONFIG_APTX_HD_DECODER) += aptx.o
+OBJS-$(CONFIG_APTX_HD_ENCODER) += aptx.o
 OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index ed1e7ab06e..93d31f8688 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -333,6 +333,7 @@ static void register_all(void)
 REGISTER_DECODER(AMRWB, amrwb);
 REGISTER_DECODER(APE,   ape);
 REGISTER_ENCDEC (APTX,  aptx);
+REGISTER_ENCDEC (APTX_HD,   aptx_hd);
 REGISTER_DECODER(ATRAC1,atrac1);
 REGISTER_DECODER(ATRAC3,atrac3);
 REGISTER_DECODER(ATRAC3AL,  atrac3al);
diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index 4173402d03..6c0f3d35a9 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -89,6 +89,8 @@ typedef struct {
 } Channel;
 
 typedef struct {
+int hd;
+int block_size;
 int32_t sync_idx;
 Channel channels[NB_CHANNELS];
 AudioFrameQueue afq;
@@ -182,6 +184,205 @@ static const int16_t quantize_factor_select_offset_HF[5] 
= {
 0, -8, 33, 95, 262,
 };
 
+
+static const int32_t hd_quantize_intervals_LF[257] = {
+  -2436,2436,7308,   12180,   17054,   21930,   26806,   31686,
+  36566,   41450,   46338,   51230,   56124,   61024,   65928,   70836,
+  75750,   80670,   85598,   90530,   95470,  100418,  105372,  110336,
+ 115308,  120288,  125278,  130276,  135286,  140304,  145334,  150374,
+ 155426,  160490,  165566,  170654,  175756,  180870,  185998,  191138,
+ 196294,  201466,  206650,  211850,  217068,  222300,  227548,  232814,
+ 238096,  243396,  248714,  254050,  259406,  264778,  270172,  275584,
+ 281018,  286470,  291944,  297440,  302956,  308496,  314056,  319640,
+ 325248,  330878,  336532,  342212,  347916,  353644,  359398,  365178,
+ 370986,  376820,  382680,  388568,  394486,  400430,  406404,  412408,
+ 418442,  424506,  430600,  436726,  442884,  449074,  455298,  461554,
+ 467844,  474168,  480528,  486922,  493354,  499820,  506324,  512866,
+ 519446,  526064,  532722,  539420,  546160,  552940,  559760,  566624,
+ 573532,  580482,  587478,  594520,  601606,  608740,  615920,  623148,
+ 630426,  637754,  645132,  652560,  660042,  667576,  675164,  682808,
+ 690506,  698262,  706074,  713946,  721876,  729868,  737920,  746036,
+ 754216,  762460,  770770,  779148,  787594,  796108,  804694,  813354,
+ 822086,  830892,  839774,  848736,  857776,  866896,  876100,  885386,
+ 894758,  904218,  913766,  923406,  933138,  942964,  952886,  962908,
+ 973030,  983254,  993582, 1004020, 1014566, 1025224, 1035996, 1046886,
+1057894, 1069026, 1080284, 1091670, 1103186, 1114838, 1126628, 1138558,
+1150634, 1162858, 1175236, 1187768, 1200462, 1213320, 1226346, 1239548,
+1252928, 1266490, 1280242, 1294188, 1308334, 1322688, 1337252, 1352034,
+1367044, 1382284, 1397766, 1413494, 1429478, 1445728, 1462252, 1479058,
+1496158, 1513562, 1531280, 1549326, 1567710, 1586446, 1605550, 1625034,
+1644914, 1665208, 1685932, 

[FFmpeg-devel] [PATCH 3/5] aptx: do some clipping to match original codec in extreme cases

2018-01-06 Thread Aurelien Jacobs
---
 libavcodec/aptx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index 64a63a7d5b..4173402d03 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -466,6 +466,7 @@ static void aptx_quantize_difference(Quantize *quantize,
 int64_t error;
 
 sample_difference_abs = FFABS(sample_difference);
+sample_difference_abs = FFMIN(sample_difference_abs, (1 << 23) - 1);
 
 quantized_sample = aptx_bin_search(sample_difference_abs >> 4,
quantization_factor,
@@ -478,7 +479,7 @@ static void aptx_quantize_difference(Quantize *quantize,
 mean = (intervals[1] + intervals[0]) / 2;
 interval = (intervals[1] - intervals[0]) * (-(sample_difference < 0) | 1);
 
-dithered_sample = rshift64_clip24(MUL64(dither, interval) + 
((int64_t)(mean + d) << 32), 32);
+dithered_sample = rshift64_clip24(MUL64(dither, interval) + 
((int64_t)av_clip_intp2(mean + d, 23) << 32), 32);
 error = ((int64_t)sample_difference_abs << 20) - MUL64(dithered_sample, 
quantization_factor);
 quantize->error = FFABS(rshift64(error, 23));
 
-- 
2.15.1

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


[FFmpeg-devel] (no subject)

2018-01-06 Thread Aurelien Jacobs
This patchset add support for the aptX HD codec.

This codec is a variation of the aptX codec using less aggressive
quantization and thus producing higher bitrate and higher quality.

The first 3 patches are simple cleanup / preparatory work.

[PATCH 1/5] aptx: simplify by pre-calculating factor_max
[PATCH 2/5] aptx: factorize FFABS calculation
[PATCH 3/5] aptx: do some clipping to match original codec in extreme cases
[PATCH 4/5] aptx: implement the aptX HD bluetooth codec
[PATCH 5/5] aptx: add raw muxer and demuxer for aptX HD
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/5] aptx: simplify by pre-calculating factor_max

2018-01-06 Thread Aurelien Jacobs
---
 libavcodec/aptx.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index a35d2861c1..7b9556ce42 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -188,7 +188,7 @@ typedef const struct {
 const int32_t *quantize_dither_factors;
 const int16_t *quantize_factor_select_offset;
 int tables_size;
-int32_t quantized_bits;
+int32_t factor_max;
 int32_t prediction_order;
 } ConstTables;
 
@@ -198,25 +198,25 @@ static ConstTables tables[NB_SUBBANDS] = {
   quantize_dither_factors_LF,
   quantize_factor_select_offset_LF,
   FF_ARRAY_ELEMS(quantize_intervals_LF),
-  7, 24 },
+  0x11FF, 24 },
 [MLF] = { quantize_intervals_MLF,
   invert_quantize_dither_factors_MLF,
   quantize_dither_factors_MLF,
   quantize_factor_select_offset_MLF,
   FF_ARRAY_ELEMS(quantize_intervals_MLF),
-  4, 12 },
+  0x14FF, 12 },
 [MHF] = { quantize_intervals_MHF,
   invert_quantize_dither_factors_MHF,
   quantize_dither_factors_MHF,
   quantize_factor_select_offset_MHF,
   FF_ARRAY_ELEMS(quantize_intervals_MHF),
-  2, 6 },
+  0x16FF, 6 },
 [HF]  = { quantize_intervals_HF,
   invert_quantize_dither_factors_HF,
   quantize_dither_factors_HF,
   quantize_factor_select_offset_HF,
   FF_ARRAY_ELEMS(quantize_intervals_HF),
-  3, 12 },
+  0x15FF, 12 },
 };
 
 static const int16_t quantization_factors[32] = {
@@ -530,16 +530,14 @@ static void aptx_invert_quantization(InvertQuantize 
*invert_quantize,
 qr = rshift64_clip24(((int64_t)qr<<32) + MUL64(dither, 
tables->invert_quantize_dither_factors[idx]), 32);
 invert_quantize->reconstructed_difference = 
MUL64(invert_quantize->quantization_factor, qr) >> 19;
 
-shift = 24 - tables->quantized_bits;
-
 /* update factor_select */
 factor_select = 32620 * invert_quantize->factor_select;
 factor_select = rshift32(factor_select + 
(tables->quantize_factor_select_offset[idx] << 15), 15);
-invert_quantize->factor_select = av_clip(factor_select, 0, (shift << 8) | 
0xFF);
+invert_quantize->factor_select = av_clip(factor_select, 0, 
tables->factor_max);
 
 /* update quantization factor */
 idx = (invert_quantize->factor_select & 0xFF) >> 3;
-shift -= invert_quantize->factor_select >> 8;
+shift = (tables->factor_max - invert_quantize->factor_select) >> 8;
 invert_quantize->quantization_factor = (quantization_factors[idx] << 11) 
>> shift;
 }
 
-- 
2.15.1

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


Re: [FFmpeg-devel] [PATCH 6/9] sbc: add raw muxer for SBC

2017-12-26 Thread Aurelien Jacobs
On Mon, Dec 25, 2017 at 12:43:18PM +, Rostislav Pehlivanov wrote:
> On 23 December 2017 at 18:01, Aurelien Jacobs <au...@gnuage.org> wrote:
>
> > ---
> >  doc/general.texi |  2 +-
> >  libavformat/Makefile |  2 ++
> >  libavformat/allformats.c |  4 ++--
> >  libavformat/rawenc.c | 28 
> >  4 files changed, 33 insertions(+), 3 deletions(-)
> >
> > diff --git a/doc/general.texi b/doc/general.texi
> > index e5669b0e93..560465a4b8 100644
> > --- a/doc/general.texi
> > +++ b/doc/general.texi
> > @@ -466,7 +466,7 @@ library:
> >  @item raw NULL  @tab X @tab
> >  @item raw video @tab X @tab X
> >  @item raw id RoQ@tab X @tab
> > -@item raw SBC   @tab   @tab X
> > +@item raw SBC   @tab X @tab X
> >  @item raw Shorten   @tab   @tab X
> >  @item raw TAK   @tab   @tab X
> >  @item raw TrueHD@tab X @tab X
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index 6270c28a8a..689fc6b23f 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -448,7 +448,9 @@ OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o
> > subtitles.o
> >  OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
> >  OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
> >  OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
> > +OBJS-$(CONFIG_SBC_MUXER) += rawenc.o
> >  OBJS-$(CONFIG_MSBC_DEMUXER)  += sbcdec.o rawdec.o
> > +OBJS-$(CONFIG_MSBC_MUXER)+= rawenc.o
> >  OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
> >  OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
> >  OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index a6b72715bd..eb1d17d38c 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -211,7 +211,7 @@ static void register_all(void)
> >  REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
> >  REGISTER_DEMUXER (MPL2, mpl2);
> >  REGISTER_DEMUXER (MPSUB,mpsub);
> > -REGISTER_DEMUXER (MSBC, msbc);
> > +REGISTER_MUXDEMUX(MSBC, msbc);
> >  REGISTER_DEMUXER (MSF,  msf);
> >  REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
> >  REGISTER_DEMUXER (MTAF, mtaf);
> > @@ -278,7 +278,7 @@ static void register_all(void)
> >  REGISTER_DEMUXER (S337M,s337m);
> >  REGISTER_DEMUXER (SAMI, sami);
> >  REGISTER_MUXDEMUX(SAP,  sap);
> > -REGISTER_DEMUXER (SBC,  sbc);
> > +REGISTER_MUXDEMUX(SBC,  sbc);
> >  REGISTER_DEMUXER (SBG,  sbg);
> >  REGISTER_MUXDEMUX(SCC,  scc);
> >  REGISTER_DEMUXER (SDP,  sdp);
> > diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
> > index aa3ef76fbf..e27b280014 100644
> > --- a/libavformat/rawenc.c
> > +++ b/libavformat/rawenc.c
> > @@ -426,6 +426,34 @@ AVOutputFormat ff_rawvideo_muxer = {
> >  };
> >  #endif
> >
> > +#if CONFIG_SBC_MUXER
> > +AVOutputFormat ff_sbc_muxer = {
> > +.name  = "sbc",
> > +.long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
> > +.mime_type = "audio/x-sbc",
> > +.extensions= "sbc",
> > +.audio_codec   = AV_CODEC_ID_SBC,
> > +.video_codec   = AV_CODEC_ID_NONE,
> > +.write_header  = force_one_stream,
> > +.write_packet  = ff_raw_write_packet,
> > +.flags = AVFMT_NOTIMESTAMPS,
> > +};
> > +#endif
> > +
> > +#if CONFIG_MSBC_MUXER
> > +AVOutputFormat ff_msbc_muxer = {
> > +.name  = "msbc",
> > +.long_name = NULL_IF_CONFIG_SMALL("raw mSBC"),
> > +.mime_type = "audio/x-msbc",
> > +.extensions= "msbc",
> > +.audio_codec   = AV_CODEC_ID_MSBC,
> > +.video_codec   = AV_CODEC_ID_NONE,
> > +.write_header  = force_one_stream,
> > +.write_packet  = ff_raw_write_packet,
> > +.flags = AVFMT_NOTIMESTAMPS,
> > +};
> > +#endif
> > +
> >  #if CONFIG_TRUEHD_MUXER
> >  AVOutputFormat ff_truehd_muxer = {
> >  .name  = "truehd",
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
>
> What happened with the profiles idea? Are the 2 variants different enough
> to need 2 CODEC_IDs?

Repeating what I wrote in the other thread:

SBC support various samplerates while mSBC is limited to 16 kHz.
I think the only way to declare this properly and to get automatic
conversion to 16 kHz when encoding to mSBC is to have 2 separate
codec ID.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 7/9] sbcenc: add MMX optimizations

2017-12-23 Thread Aurelien Jacobs
On Sat, Dec 23, 2017 at 09:52:11PM +0100, Aurelien Jacobs wrote:
> On Sat, Dec 23, 2017 at 05:47:04PM -0300, James Almer wrote:
> > On 12/23/2017 5:44 PM, Aurelien Jacobs wrote:
> > > On Sat, Dec 23, 2017 at 03:35:28PM -0300, James Almer wrote:
> > >> On 12/23/2017 3:01 PM, Aurelien Jacobs wrote:
> > >>> This was originally based on libsbc, and was fully integrated into 
> > >>> ffmpeg.
> > >>>
> > >>> Rough speed test:
> > >>> C version:speed= 592x
> > >>> MMX version:  speed= 785x
> > >>> ---
> > >>>  libavcodec/sbcdsp.c  |   3 +
> > >>>  libavcodec/sbcdsp.h  |   2 +
> > >>>  libavcodec/x86/Makefile  |   2 +
> > >>>  libavcodec/x86/sbcdsp.asm| 284 
> > >>> +++
> > >>>  libavcodec/x86/sbcdsp_init.c |  51 
> > >>>  5 files changed, 342 insertions(+)
> > >>>  create mode 100644 libavcodec/x86/sbcdsp.asm
> > >>>  create mode 100644 libavcodec/x86/sbcdsp_init.c
> > >>
> > >> [...]
> > >>
> > >>> +;***
> > >>> +;void ff_sbc_calc_scalefactors(int32_t sb_sample_f[16][2][8],
> > >>> +;  uint32_t scale_factor[2][8],
> > >>> +;  int blocks, int channels, int subbands)
> > >>> +;***
> > >>> +INIT_MMX mmx
> > >>> +cglobal sbc_calc_scalefactors, 5, 7, 3, sb_sample_f, scale_factor, 
> > >>> blocks, channels, subbands, ptr, blk
> > >>> +; subbands = 4 * subbands * channels
> > >>> +shl  subbandsd, 2
> > >>> +cmp  channelsd, 2
> > >>> +jl   .loop_1
> > >>> +shl  subbandsd, 1
> > >>> +
> > >>> +.loop_1:
> > >>> +sub   subbandsq, 8
> > >>> +lea   ptrq, [sb_sample_fq + subbandsq]
> > >>> +
> > >>> +; blk = (blocks - 1) * 64;
> > >>> +lea   blkq, [blocksq - 1]
> > >>> +shl   blkd, 6
> > >>> +
> > >>> +movq  m0, [scale_mask]
> > >>
> > >> I insist, this can be easily loaded outside the loop. You have enough
> > >> spare regs to store a copy.
> > > 
> > > Oh, I forgot to reply to this. There isn't any register left available
> > > on x86_32, hence why I kept those load inside the loop.
> > 
> > You're not using a gprs to store the mask nor need to. You're using mmx
> > regs and have 5 left.
> 
> Oh, indeed ! Not sure why it didn't even cross my mind...
> I will have a look at this.

Here it is with the scale_mask load out of the loop.

>From 5c8ac4e2d23c0ebf27d6592645d53b60d07d47ef Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sun, 17 Dec 2017 20:07:33 +0100
Subject: [PATCH 7/9] sbcenc: add MMX optimizations

This was originally based on libsbc, and was fully integrated into ffmpeg.

Rough speed test:
C version:speed= 592x
MMX version:  speed= 785x
---
 libavcodec/sbcdsp.c  |   3 +
 libavcodec/sbcdsp.h  |   2 +
 libavcodec/x86/Makefile  |   2 +
 libavcodec/x86/sbcdsp.asm| 285 +++
 libavcodec/x86/sbcdsp_init.c |  51 
 5 files changed, 343 insertions(+)
 create mode 100644 libavcodec/x86/sbcdsp.asm
 create mode 100644 libavcodec/x86/sbcdsp_init.c

diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
index e155387f0d..2d0addcf28 100644
--- a/libavcodec/sbcdsp.c
+++ b/libavcodec/sbcdsp.c
@@ -379,4 +379,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
 /* Default implementation for scale factors calculation */
 s->sbc_calc_scalefactors = sbc_calc_scalefactors;
 s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
+
+if (ARCH_X86)
+ff_sbcdsp_init_x86(s);
 }
diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
index 66ed7d324e..127e6a8a11 100644
--- a/libavcodec/sbcdsp.h
+++ b/libavcodec/sbcdsp.h
@@ -80,4 +80,6 @@ struct sbc_dsp_context {
  */
 void ff_sbcdsp_init(SBCDSPContext *s);
 
+void ff_sbcdsp_init_x86(SBCDSPContext *s);
+
 #endif /* AVCODEC_SBCDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a805cd37b4..2350c8bbee 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_

Re: [FFmpeg-devel] [PATCH 7/9] sbcenc: add MMX optimizations

2017-12-23 Thread Aurelien Jacobs
On Sat, Dec 23, 2017 at 05:47:04PM -0300, James Almer wrote:
> On 12/23/2017 5:44 PM, Aurelien Jacobs wrote:
> > On Sat, Dec 23, 2017 at 03:35:28PM -0300, James Almer wrote:
> >> On 12/23/2017 3:01 PM, Aurelien Jacobs wrote:
> >>> This was originally based on libsbc, and was fully integrated into ffmpeg.
> >>>
> >>> Rough speed test:
> >>> C version:speed= 592x
> >>> MMX version:  speed= 785x
> >>> ---
> >>>  libavcodec/sbcdsp.c  |   3 +
> >>>  libavcodec/sbcdsp.h  |   2 +
> >>>  libavcodec/x86/Makefile  |   2 +
> >>>  libavcodec/x86/sbcdsp.asm| 284 
> >>> +++
> >>>  libavcodec/x86/sbcdsp_init.c |  51 
> >>>  5 files changed, 342 insertions(+)
> >>>  create mode 100644 libavcodec/x86/sbcdsp.asm
> >>>  create mode 100644 libavcodec/x86/sbcdsp_init.c
> >>
> >> [...]
> >>
> >>> +;***
> >>> +;void ff_sbc_calc_scalefactors(int32_t sb_sample_f[16][2][8],
> >>> +;  uint32_t scale_factor[2][8],
> >>> +;  int blocks, int channels, int subbands)
> >>> +;***
> >>> +INIT_MMX mmx
> >>> +cglobal sbc_calc_scalefactors, 5, 7, 3, sb_sample_f, scale_factor, 
> >>> blocks, channels, subbands, ptr, blk
> >>> +; subbands = 4 * subbands * channels
> >>> +shl  subbandsd, 2
> >>> +cmp  channelsd, 2
> >>> +jl   .loop_1
> >>> +shl  subbandsd, 1
> >>> +
> >>> +.loop_1:
> >>> +sub   subbandsq, 8
> >>> +lea   ptrq, [sb_sample_fq + subbandsq]
> >>> +
> >>> +; blk = (blocks - 1) * 64;
> >>> +lea   blkq, [blocksq - 1]
> >>> +shl   blkd, 6
> >>> +
> >>> +movq  m0, [scale_mask]
> >>
> >> I insist, this can be easily loaded outside the loop. You have enough
> >> spare regs to store a copy.
> > 
> > Oh, I forgot to reply to this. There isn't any register left available
> > on x86_32, hence why I kept those load inside the loop.
> 
> You're not using a gprs to store the mask nor need to. You're using mmx
> regs and have 5 left.

Oh, indeed ! Not sure why it didn't even cross my mind...
I will have a look at this.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 7/9] sbcenc: add MMX optimizations

2017-12-23 Thread Aurelien Jacobs
On Sat, Dec 23, 2017 at 03:35:28PM -0300, James Almer wrote:
> On 12/23/2017 3:01 PM, Aurelien Jacobs wrote:
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > 
> > Rough speed test:
> > C version:speed= 592x
> > MMX version:  speed= 785x
> > ---
> >  libavcodec/sbcdsp.c  |   3 +
> >  libavcodec/sbcdsp.h  |   2 +
> >  libavcodec/x86/Makefile  |   2 +
> >  libavcodec/x86/sbcdsp.asm| 284 
> > +++
> >  libavcodec/x86/sbcdsp_init.c |  51 
> >  5 files changed, 342 insertions(+)
> >  create mode 100644 libavcodec/x86/sbcdsp.asm
> >  create mode 100644 libavcodec/x86/sbcdsp_init.c
> 
> [...]
> 
> > +;***
> > +;void ff_sbc_calc_scalefactors(int32_t sb_sample_f[16][2][8],
> > +;  uint32_t scale_factor[2][8],
> > +;  int blocks, int channels, int subbands)
> > +;***
> > +INIT_MMX mmx
> > +cglobal sbc_calc_scalefactors, 5, 7, 3, sb_sample_f, scale_factor, blocks, 
> > channels, subbands, ptr, blk
> > +; subbands = 4 * subbands * channels
> > +shl  subbandsd, 2
> > +cmp  channelsd, 2
> > +jl   .loop_1
> > +shl  subbandsd, 1
> > +
> > +.loop_1:
> > +sub   subbandsq, 8
> > +lea   ptrq, [sb_sample_fq + subbandsq]
> > +
> > +; blk = (blocks - 1) * 64;
> > +lea   blkq, [blocksq - 1]
> > +shl   blkd, 6
> > +
> > +movq  m0, [scale_mask]
> 
> I insist, this can be easily loaded outside the loop. You have enough
> spare regs to store a copy.

Oh, I forgot to reply to this. There isn't any register left available
on x86_32, hence why I kept those load inside the loop.
___
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)

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 <au...@gnuage.org>
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 <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 
+#includ

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

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

>From c168e5e7b288edc2730a4a14614ead5c22d67289 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sun, 17 Dec 2017 19:53:35 +0100
Subject: [PATCH 2/9] sbc: implement SBC decoder (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   |   2 +
 libavcodec/avcodec.h |   2 +
 libavcodec/codec_desc.c  |  14 ++
 libavcodec/sbc.c | 280 
 libavcodec/sbc.h | 121 
 libavcodec/sbcdec.c  | 466 +++
 libavcodec/sbcdec_data.c | 127 +
 libavcodec/sbcdec_data.h |  44 +
 10 files changed, 1060 insertions(+)
 create mode 100644 libavcodec/sbc.c
 create mode 100644 libavcodec/sbc.h
 create mode 100644 libavcodec/sbcdec.c
 create mode 100644 libavcodec/sbcdec_data.c
 create mode 100644 libavcodec/sbcdec_data.h

diff --git a/doc/general.texi b/doc/general.texi
index 26919c9287..ed137f999f 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1102,6 +1102,8 @@ 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
+@tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
 @tab Used in Sierra VMD files.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ca72138c02..c46d102227 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -581,6 +581,8 @@ OBJS-$(CONFIG_SUBVIEWER_DECODER)   += subviewerdec.o ass.o
 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_MSBC_DECODER)+= sbcdec.o sbcdec_data.o sbc.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 ed1e7ab06e..9e2480d2d4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -379,6 +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 (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
 REGISTER_ENCDEC (OPUS,  opus);
@@ -392,6 +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 (SONIC, sonic);
 REGISTER_ENCODER(SONIC_LS,  sonic_ls);
 REGISTER_DECODER(TAK,   tak);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ce089b7c4a..5b7ec8541d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -634,6 +634,8 @@ enum AVCodecID {
 AV_CODEC_ID_ATRAC3PAL,
 AV_CODEC_ID_DOLBY_E,
 AV_CODEC_ID_APTX,
+AV_CODEC_ID_SBC,
+AV_CODEC_ID_MSBC,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at the start of subtitle codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index c3688de1d6..a69897d379 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2866,6 +2866,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("aptX (Audio Processing Technology for Bluetooth)"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_SBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband codec)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
+.id= AV_CODEC_ID_MSBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("mSBC (wideband speech mono SBC)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/sbc.c b/libavcodec/sbc.c
new file mode 100644
index 00..af3e9a3fa8
--- /dev/null
+++ b/libavcodec/sbc.c
@@ -0,0 +1,280 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <

Re: [FFmpeg-devel] [PATCH 1/9] crc: add AV_CRC_8_SBC as a 8 bits CRC with polynomial 0x1D

2017-12-23 Thread Aurelien Jacobs
On Sat, Dec 23, 2017 at 04:32:26PM -0300, James Almer wrote:
> On 12/23/2017 3:01 PM, Aurelien Jacobs wrote:
> > ---
> >  libavutil/crc.c   | 26 ++
> >  libavutil/crc.h   |  1 +
> >  libavutil/tests/crc.c |  7 ---
> >  tests/ref/fate/crc|  1 +
> >  4 files changed, 32 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavutil/crc.c b/libavutil/crc.c
> > index d44550c9c0..8e44a76ec8 100644
> > --- a/libavutil/crc.c
> > +++ b/libavutil/crc.c
> > @@ -52,6 +52,30 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
> >  0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 
> > 0xEF,
> >  0xFA, 0xFD, 0xF4, 0xF3, 0x01
> >  },
> > +[AV_CRC_8_SBC] = {
> > +0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 
> > 0xCF,
> > +0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 
> > 0x9E,
> > +0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76, 0x87, 0x9A, 0xBD, 
> > 0xA0,
> > +0xF3, 0xEE, 0xC9, 0xD4, 0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 
> > 0x3C,
> > +0x4A, 0x57, 0x70, 0x6D, 0x3E, 0x23, 0x04, 0x19, 0xA2, 0xBF, 0x98, 
> > 0x85,
> > +0xD6, 0xCB, 0xEC, 0xF1, 0x13, 0x0E, 0x29, 0x34, 0x67, 0x7A, 0x5D, 
> > 0x40,
> > +0xFB, 0xE6, 0xC1, 0xDC, 0x8F, 0x92, 0xB5, 0xA8, 0xDE, 0xC3, 0xE4, 
> > 0xF9,
> > +0xAA, 0xB7, 0x90, 0x8D, 0x36, 0x2B, 0x0C, 0x11, 0x42, 0x5F, 0x78, 
> > 0x65,
> > +0x94, 0x89, 0xAE, 0xB3, 0xE0, 0xFD, 0xDA, 0xC7, 0x7C, 0x61, 0x46, 
> > 0x5B,
> > +0x08, 0x15, 0x32, 0x2F, 0x59, 0x44, 0x63, 0x7E, 0x2D, 0x30, 0x17, 
> > 0x0A,
> > +0xB1, 0xAC, 0x8B, 0x96, 0xC5, 0xD8, 0xFF, 0xE2, 0x26, 0x3B, 0x1C, 
> > 0x01,
> > +0x52, 0x4F, 0x68, 0x75, 0xCE, 0xD3, 0xF4, 0xE9, 0xBA, 0xA7, 0x80, 
> > 0x9D,
> > +0xEB, 0xF6, 0xD1, 0xCC, 0x9F, 0x82, 0xA5, 0xB8, 0x03, 0x1E, 0x39, 
> > 0x24,
> > +0x77, 0x6A, 0x4D, 0x50, 0xA1, 0xBC, 0x9B, 0x86, 0xD5, 0xC8, 0xEF, 
> > 0xF2,
> > +0x49, 0x54, 0x73, 0x6E, 0x3D, 0x20, 0x07, 0x1A, 0x6C, 0x71, 0x56, 
> > 0x4B,
> > +0x18, 0x05, 0x22, 0x3F, 0x84, 0x99, 0xBE, 0xA3, 0xF0, 0xED, 0xCA, 
> > 0xD7,
> > +0x35, 0x28, 0x0F, 0x12, 0x41, 0x5C, 0x7B, 0x66, 0xDD, 0xC0, 0xE7, 
> > 0xFA,
> > +0xA9, 0xB4, 0x93, 0x8E, 0xF8, 0xE5, 0xC2, 0xDF, 0x8C, 0x91, 0xB6, 
> > 0xAB,
> > +0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 
> > 0x95,
> > +0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 
> > 0x09,
> > +0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 
> > 0xB0,
> > +0xE3, 0xFE, 0xD9, 0xC4, 0x01
> > +},
> >  [AV_CRC_16_ANSI] = {
> >  0x, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
> >  0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
> > @@ -305,6 +329,7 @@ static void id ## _init_table_once(void)
> >  #define CRC_INIT_TABLE_ONCE(id) ff_thread_once( ## _once_control, id ## 
> > _init_table_once)
> >  
> >  DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM,  0,  8,       0x07)
> > +DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_SBC,  0,  8,   0x1D)
> 
> The polynomial 0x1D seems to be used in a couple standards, including
> one defined by the European Broadcasting Union, so instead of _SBC which
> is a codec using the CRC, I'd use _EBU for the enum constant.

Agreed. Here is an updated patch.

>From 652900498e94f843d09d868809e452d9ef0fc8a3 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Wed, 20 Dec 2017 01:29:05 +0100
Subject: [PATCH 1/9] crc: add AV_CRC_8_SBC as a 8 bits CRC with polynomial
 0x1D

---
 libavutil/crc.c   | 26 ++
 libavutil/crc.h   |  1 +
 libavutil/tests/crc.c |  7 ---
 tests/ref/fate/crc|  1 +
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/libavutil/crc.c b/libavutil/crc.c
index d44550c9c0..c45ea63a62 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -52,6 +52,30 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
 0xFA, 0xFD, 0xF4, 0xF3, 0x01
 },
+[AV_CRC_8_EBU] = {
+0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF,
+0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E,
+0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76, 0x87, 0x9A, 0xBD, 0xA0,
+0xF3, 0xEE, 0xC9, 0xD4, 0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 0x3C,
+0

[FFmpeg-devel] [PATCH 8/9] sbcenc: add armv6 and neon asm optimizations

2017-12-23 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 libavcodec/arm/Makefile  |   3 +
 libavcodec/arm/sbcdsp_armv6.S| 245 ++
 libavcodec/arm/sbcdsp_init_arm.c | 105 ++
 libavcodec/arm/sbcdsp_neon.S | 714 +++
 libavcodec/sbcdsp.c  |   2 +
 libavcodec/sbcdsp.h  |   1 +
 6 files changed, 1070 insertions(+)
 create mode 100644 libavcodec/arm/sbcdsp_armv6.S
 create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
 create mode 100644 libavcodec/arm/sbcdsp_neon.S

diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index 1eeac5449e..fd2401f4e5 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -42,6 +42,7 @@ OBJS-$(CONFIG_DCA_DECODER) += 
arm/synth_filter_init_arm.o
 OBJS-$(CONFIG_HEVC_DECODER)+= arm/hevcdsp_init_arm.o
 OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_init_arm.o
 OBJS-$(CONFIG_RV40_DECODER)+= arm/rv40dsp_init_arm.o
+OBJS-$(CONFIG_SBC_ENCODER) += arm/sbcdsp_init_arm.o
 OBJS-$(CONFIG_VORBIS_DECODER)  += arm/vorbisdsp_init_arm.o
 OBJS-$(CONFIG_VP6_DECODER) += arm/vp6dsp_init_arm.o
 OBJS-$(CONFIG_VP9_DECODER) += arm/vp9dsp_init_10bpp_arm.o   \
@@ -81,6 +82,7 @@ ARMV6-OBJS-$(CONFIG_VP8DSP)+= arm/vp8_armv6.o 
  \
 
 # decoders/encoders
 ARMV6-OBJS-$(CONFIG_MLP_DECODER)   += arm/mlpdsp_armv6.o
+ARMV6-OBJS-$(CONFIG_SBC_ENCODER)   += arm/sbcdsp_armv6.o
 
 
 # VFP optimizations
@@ -140,6 +142,7 @@ NEON-OBJS-$(CONFIG_HEVC_DECODER)   += 
arm/hevcdsp_init_neon.o   \
 NEON-OBJS-$(CONFIG_RV30_DECODER)   += arm/rv34dsp_neon.o
 NEON-OBJS-$(CONFIG_RV40_DECODER)   += arm/rv34dsp_neon.o\
   arm/rv40dsp_neon.o
+NEON-OBJS-$(CONFIG_SBC_ENCODER)+= arm/sbcdsp_neon.o
 NEON-OBJS-$(CONFIG_VORBIS_DECODER) += arm/vorbisdsp_neon.o
 NEON-OBJS-$(CONFIG_VP6_DECODER)+= arm/vp6dsp_neon.o
 NEON-OBJS-$(CONFIG_VP9_DECODER)+= arm/vp9itxfm_16bpp_neon.o \
diff --git a/libavcodec/arm/sbcdsp_armv6.S b/libavcodec/arm/sbcdsp_armv6.S
new file mode 100644
index 00..f1ff845798
--- /dev/null
+++ b/libavcodec/arm/sbcdsp_armv6.S
@@ -0,0 +1,245 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 ARMv6 optimizations. The instructions are scheduled for ARM11 pipeline.
+ */
+
+#include "libavutil/arm/asm.S"
+
+function ff_sbc_analyze_4_armv6, export=1
+@ r0 = in, r1 = out, r2 = consts
+push{r1, r3-r7, lr}
+push{r8-r12, r14}
+ldrdr4,  r5,  [r0, #0]
+ldrdr6,  r7,  [r2, #0]
+ldrdr8,  r9,  [r0, #16]
+ldrdr10, r11, [r2, #16]
+mov r14, #0x8000
+smlad   r3,  r4,  r6,  r14
+smlad   r12, r5,  r7,  r14
+ldrdr4,  r5,  [r0, #32]
+ldrdr6,  r7,  [r2, #32]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #48]
+ldrdr10, r11, [r2, #48]
+smlad   r3,  r4,  r6,  r3
+smlad   r12, r5,  r7,  r12
+ldrdr4,  r5,  [r0, #64]
+ldrdr6,  r7,  [r2, #64]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #8]
+ldrdr10, r11, [r2, #8]
+smlad   r3,  r4,  r6,  r3@ t1[0] is done
+smlad   r12, r5,  r7,  r12   @ t1[1] is done
+ldrdr4,  r5,  [r0, #24]
+ldrdr6,  r7,  [r2, #24]
+pkhtb   r3,  r12, r3, asr #16@ comb

[FFmpeg-devel] [PATCH 7/9] sbcenc: add MMX optimizations

2017-12-23 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.

Rough speed test:
C version:speed= 592x
MMX version:  speed= 785x
---
 libavcodec/sbcdsp.c  |   3 +
 libavcodec/sbcdsp.h  |   2 +
 libavcodec/x86/Makefile  |   2 +
 libavcodec/x86/sbcdsp.asm| 284 +++
 libavcodec/x86/sbcdsp_init.c |  51 
 5 files changed, 342 insertions(+)
 create mode 100644 libavcodec/x86/sbcdsp.asm
 create mode 100644 libavcodec/x86/sbcdsp_init.c

diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
index e155387f0d..2d0addcf28 100644
--- a/libavcodec/sbcdsp.c
+++ b/libavcodec/sbcdsp.c
@@ -379,4 +379,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
 /* Default implementation for scale factors calculation */
 s->sbc_calc_scalefactors = sbc_calc_scalefactors;
 s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
+
+if (ARCH_X86)
+ff_sbcdsp_init_x86(s);
 }
diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
index 66ed7d324e..127e6a8a11 100644
--- a/libavcodec/sbcdsp.h
+++ b/libavcodec/sbcdsp.h
@@ -80,4 +80,6 @@ struct sbc_dsp_context {
  */
 void ff_sbcdsp_init(SBCDSPContext *s);
 
+void ff_sbcdsp_init_x86(SBCDSPContext *s);
+
 #endif /* AVCODEC_SBCDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a805cd37b4..2350c8bbee 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_DECODER)  += x86/proresdsp_init.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp_init.o
 OBJS-$(CONFIG_RV40_DECODER)+= x86/rv40dsp_init.o
+OBJS-$(CONFIG_SBC_ENCODER) += x86/sbcdsp_init.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= x86/svq1enc_init.o
 OBJS-$(CONFIG_TAK_DECODER) += x86/takdsp_init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)  += x86/mlpdsp_init.o
@@ -172,6 +173,7 @@ X86ASM-OBJS-$(CONFIG_PNG_DECODER)  += x86/pngdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_DECODER)   += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o
+X86ASM-OBJS-$(CONFIG_SBC_ENCODER)  += x86/sbcdsp.o
 X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER) += x86/svq1enc.o
 X86ASM-OBJS-$(CONFIG_TAK_DECODER)  += x86/takdsp.o
 X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
diff --git a/libavcodec/x86/sbcdsp.asm b/libavcodec/x86/sbcdsp.asm
new file mode 100644
index 00..0538705fb7
--- /dev/null
+++ b/libavcodec/x86/sbcdsp.asm
@@ -0,0 +1,284 @@
+;**
+;* SIMD optimized SBC encoder DSP functions
+;*
+;* Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+;* Copyright (C) 2008-2010  Nokia Corporation
+;* Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+;* Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+;* Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+;*
+;* 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
+;**
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+scale_mask: times 2 dd 0x8000; 1 << (SBC_PROTO_FIXED_SCALE - 1)
+
+SECTION .text
+
+;***
+;void ff_sbc_analyze_4(const int16_t *in, int32_t *out, const int16_t *consts);
+;***
+INIT_MMX mmx
+cglobal sbc_analyze_4, 3, 3, 4, in, out, consts
+movq  m0, [inq]
+movq  m1, [inq+8]
+pmaddwd   m0, [constsq]
+pmaddwd   m1, [constsq+8]
+paddd m0, [scale_mask]
+paddd m1, [scale_mask]
+
+movq  m2, [inq+16]
+movq  m3, [inq+24]
+pmaddwd   m2, [constsq+16]
+pmaddwd   m3, [constsq+24]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+32]
+movq  m3, [inq+40]
+pmaddwd   m2, [constsq+32]
+pmaddwd   m3, [constsq+40]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+48]
+mo

[FFmpeg-devel] [PATCH 9/9] Changelog: list the new SBC codec

2017-12-23 Thread Aurelien Jacobs
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index ee48876128..4a98884a3c 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - video setrange filter
 - nsp demuxer
 - support LibreSSL (via libtls)
+- native SBC and mSBC encoder and decoder
 
 
 version 3.4:
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 6/9] sbc: add raw muxer for SBC

2017-12-23 Thread Aurelien Jacobs
---
 doc/general.texi |  2 +-
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  4 ++--
 libavformat/rawenc.c | 28 
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/general.texi b/doc/general.texi
index e5669b0e93..560465a4b8 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,7 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
-@item raw SBC   @tab   @tab X
+@item raw SBC   @tab X @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6270c28a8a..689fc6b23f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -448,7 +448,9 @@ OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o 
subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
 OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
+OBJS-$(CONFIG_SBC_MUXER) += rawenc.o
 OBJS-$(CONFIG_MSBC_DEMUXER)  += sbcdec.o rawdec.o
+OBJS-$(CONFIG_MSBC_MUXER)+= rawenc.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index a6b72715bd..eb1d17d38c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,7 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
-REGISTER_DEMUXER (MSBC, msbc);
+REGISTER_MUXDEMUX(MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -278,7 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
-REGISTER_DEMUXER (SBC,  sbc);
+REGISTER_MUXDEMUX(SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index aa3ef76fbf..e27b280014 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -426,6 +426,34 @@ AVOutputFormat ff_rawvideo_muxer = {
 };
 #endif
 
+#if CONFIG_SBC_MUXER
+AVOutputFormat ff_sbc_muxer = {
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
+.mime_type = "audio/x-sbc",
+.extensions= "sbc",
+.audio_codec   = AV_CODEC_ID_SBC,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
+#if CONFIG_MSBC_MUXER
+AVOutputFormat ff_msbc_muxer = {
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw mSBC"),
+.mime_type = "audio/x-msbc",
+.extensions= "msbc",
+.audio_codec   = AV_CODEC_ID_MSBC,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_TRUEHD_MUXER
 AVOutputFormat ff_truehd_muxer = {
 .name  = "truehd",
-- 
2.15.1

___
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)

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 <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 tabl

[FFmpeg-devel] [PATCH 3/9] sbc: add parser for SBC

2017-12-23 Thread Aurelien Jacobs
---
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/sbc_parser.c | 124 
 3 files changed, 126 insertions(+)
 create mode 100644 libavcodec/sbc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c46d102227..58c8c6e499 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1012,6 +1012,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_SBC_PARSER)  += sbc_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  \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 9e2480d2d4..3e3b37f638 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -653,6 +653,7 @@ static void register_all(void)
 REGISTER_PARSER(PNM,pnm);
 REGISTER_PARSER(RV30,   rv30);
 REGISTER_PARSER(RV40,   rv40);
+REGISTER_PARSER(SBC,sbc);
 REGISTER_PARSER(SIPR,   sipr);
 REGISTER_PARSER(TAK,tak);
 REGISTER_PARSER(VC1,vc1);
diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
new file mode 100644
index 00..032f72cf2b
--- /dev/null
+++ b/libavcodec/sbc_parser.c
@@ -0,0 +1,124 @@
+/*
+ * SBC parser
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "sbc.h"
+#include "parser.h"
+
+typedef struct SBCParseContext {
+ParseContext pc;
+uint8_t header[3];
+int header_size;
+int buffered_size;
+} SBCParseContext;
+
+static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
+const uint8_t *data, size_t len)
+{
+static const int sample_rates[4] = { 16000, 32000, 44100, 48000 };
+int sr, blocks, mode, subbands, bitpool, channels, joint;
+int length;
+
+if (len < 3)
+return -1;
+
+if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
+avctx->channels = 1;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = 16000;
+avctx->frame_size = 120;
+s->duration = avctx->frame_size;
+return 57;
+}
+
+if (data[0] != SBC_SYNCWORD)
+return -2;
+
+sr   =   (data[1] >> 6) & 0x03;
+blocks   = (((data[1] >> 4) & 0x03) + 1) << 2;
+mode =   (data[1] >> 2) & 0x03;
+subbands = (((data[1] >> 0) & 0x01) + 1) << 2;
+bitpool  = data[2];
+
+channels = mode == SBC_MODE_MONO ? 1 : 2;
+joint= mode == SBC_MODE_JOINT_STEREO;
+
+length = 4 + (subbands * channels) / 2;
+if (channels == 1 || mode == SBC_MODE_DUAL_CHANNEL)
+length += ((channels * blocks * bitpool) + 7) / 8;
+else
+length += (((joint ? subbands : 0) + blocks * bitpool) + 7) / 8;
+
+avctx->channels = channels;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = sample_rates[sr];
+avctx->frame_size = subbands * blocks;
+s->duration = avctx->frame_size;
+return length;
+}
+
+static int sbc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+SBCParseContext *pc = s->priv_data;
+int next;
+
+if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+next = buf_size;
+} else {
+if (pc->header_size) {
+memcpy(pc->header + pc->header_size, buf,
+   sizeof(pc->header) - pc->header_size);
+next = sbc_parse_header(s, avctx, pc->header, sizeof(pc->header))
+ - pc->buffered_size;
+pc->header_size = 0;
+} else {
+next = sbc_parse_header(s, avctx, buf, buf_siz

[FFmpeg-devel] [PATCH 4/9] sbc: add raw demuxer for SBC

2017-12-23 Thread Aurelien Jacobs
---
 doc/general.texi |  1 +
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  2 ++
 libavformat/sbcdec.c | 47 +++
 4 files changed, 52 insertions(+)
 create mode 100644 libavformat/sbcdec.c

diff --git a/doc/general.texi b/doc/general.texi
index ed137f999f..65aee47f2a 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,6 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
+@item raw SBC   @tab   @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..6270c28a8a 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -447,6 +447,8 @@ OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
+OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
+OBJS-$(CONFIG_MSBC_DEMUXER)  += sbcdec.o rawdec.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..a6b72715bd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,6 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
+REGISTER_DEMUXER (MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -277,6 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
+REGISTER_DEMUXER (SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/sbcdec.c b/libavformat/sbcdec.c
new file mode 100644
index 00..a04a7c4328
--- /dev/null
+++ b/libavformat/sbcdec.c
@@ -0,0 +1,47 @@
+/*
+ * RAW SBC demuxer
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rawdec.h"
+
+#if CONFIG_SBC_DEMUXER
+AVInputFormat ff_sbc_demuxer = {
+.name   = "sbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw SBC (low-complexity subband 
codec)"),
+.extensions = "sbc",
+.raw_codec_id   = AV_CODEC_ID_SBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
+#endif
+
+#if CONFIG_MSBC_DEMUXER
+AVInputFormat ff_msbc_demuxer = {
+.name   = "msbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw mSBC (wideband speech mono 
SBC)"),
+.extensions = "msbc",
+.raw_codec_id   = AV_CODEC_ID_MSBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
+#endif
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 2/9] sbc: implement SBC decoder (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   |   2 +
 libavcodec/avcodec.h |   2 +
 libavcodec/codec_desc.c  |  14 ++
 libavcodec/sbc.c | 280 
 libavcodec/sbc.h | 121 
 libavcodec/sbcdec.c  | 466 +++
 libavcodec/sbcdec_data.c | 127 +
 libavcodec/sbcdec_data.h |  44 +
 10 files changed, 1060 insertions(+)
 create mode 100644 libavcodec/sbc.c
 create mode 100644 libavcodec/sbc.h
 create mode 100644 libavcodec/sbcdec.c
 create mode 100644 libavcodec/sbcdec_data.c
 create mode 100644 libavcodec/sbcdec_data.h

diff --git a/doc/general.texi b/doc/general.texi
index 26919c9287..ed137f999f 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1102,6 +1102,8 @@ 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
+@tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
 @tab Used in Sierra VMD files.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ca72138c02..c46d102227 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -581,6 +581,8 @@ OBJS-$(CONFIG_SUBVIEWER_DECODER)   += subviewerdec.o 
ass.o
 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_MSBC_DECODER)+= sbcdec.o sbcdec_data.o sbc.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 ed1e7ab06e..9e2480d2d4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -379,6 +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 (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
 REGISTER_ENCDEC (OPUS,  opus);
@@ -392,6 +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 (SONIC, sonic);
 REGISTER_ENCODER(SONIC_LS,  sonic_ls);
 REGISTER_DECODER(TAK,   tak);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ce089b7c4a..5b7ec8541d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -634,6 +634,8 @@ enum AVCodecID {
 AV_CODEC_ID_ATRAC3PAL,
 AV_CODEC_ID_DOLBY_E,
 AV_CODEC_ID_APTX,
+AV_CODEC_ID_SBC,
+AV_CODEC_ID_MSBC,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index c3688de1d6..a69897d379 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2866,6 +2866,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("aptX (Audio Processing Technology 
for Bluetooth)"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_SBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband 
codec)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
+.id= AV_CODEC_ID_MSBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("mSBC (wideband speech mono SBC)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/sbc.c b/libavcodec/sbc.c
new file mode 100644
index 00..af3e9a3fa8
--- /dev/null
+++ b/libavcodec/sbc.c
@@ -0,0 +1,280 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2008  B

[FFmpeg-devel] [PATCH 1/9] crc: add AV_CRC_8_SBC as a 8 bits CRC with polynomial 0x1D

2017-12-23 Thread Aurelien Jacobs
---
 libavutil/crc.c   | 26 ++
 libavutil/crc.h   |  1 +
 libavutil/tests/crc.c |  7 ---
 tests/ref/fate/crc|  1 +
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/libavutil/crc.c b/libavutil/crc.c
index d44550c9c0..8e44a76ec8 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -52,6 +52,30 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
 0xFA, 0xFD, 0xF4, 0xF3, 0x01
 },
+[AV_CRC_8_SBC] = {
+0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF,
+0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E,
+0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76, 0x87, 0x9A, 0xBD, 0xA0,
+0xF3, 0xEE, 0xC9, 0xD4, 0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 0x3C,
+0x4A, 0x57, 0x70, 0x6D, 0x3E, 0x23, 0x04, 0x19, 0xA2, 0xBF, 0x98, 0x85,
+0xD6, 0xCB, 0xEC, 0xF1, 0x13, 0x0E, 0x29, 0x34, 0x67, 0x7A, 0x5D, 0x40,
+0xFB, 0xE6, 0xC1, 0xDC, 0x8F, 0x92, 0xB5, 0xA8, 0xDE, 0xC3, 0xE4, 0xF9,
+0xAA, 0xB7, 0x90, 0x8D, 0x36, 0x2B, 0x0C, 0x11, 0x42, 0x5F, 0x78, 0x65,
+0x94, 0x89, 0xAE, 0xB3, 0xE0, 0xFD, 0xDA, 0xC7, 0x7C, 0x61, 0x46, 0x5B,
+0x08, 0x15, 0x32, 0x2F, 0x59, 0x44, 0x63, 0x7E, 0x2D, 0x30, 0x17, 0x0A,
+0xB1, 0xAC, 0x8B, 0x96, 0xC5, 0xD8, 0xFF, 0xE2, 0x26, 0x3B, 0x1C, 0x01,
+0x52, 0x4F, 0x68, 0x75, 0xCE, 0xD3, 0xF4, 0xE9, 0xBA, 0xA7, 0x80, 0x9D,
+0xEB, 0xF6, 0xD1, 0xCC, 0x9F, 0x82, 0xA5, 0xB8, 0x03, 0x1E, 0x39, 0x24,
+0x77, 0x6A, 0x4D, 0x50, 0xA1, 0xBC, 0x9B, 0x86, 0xD5, 0xC8, 0xEF, 0xF2,
+0x49, 0x54, 0x73, 0x6E, 0x3D, 0x20, 0x07, 0x1A, 0x6C, 0x71, 0x56, 0x4B,
+0x18, 0x05, 0x22, 0x3F, 0x84, 0x99, 0xBE, 0xA3, 0xF0, 0xED, 0xCA, 0xD7,
+0x35, 0x28, 0x0F, 0x12, 0x41, 0x5C, 0x7B, 0x66, 0xDD, 0xC0, 0xE7, 0xFA,
+0xA9, 0xB4, 0x93, 0x8E, 0xF8, 0xE5, 0xC2, 0xDF, 0x8C, 0x91, 0xB6, 0xAB,
+0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95,
+0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
+0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0,
+0xE3, 0xFE, 0xD9, 0xC4, 0x01
+},
 [AV_CRC_16_ANSI] = {
 0x, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
 0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
@@ -305,6 +329,7 @@ static void id ## _init_table_once(void)
 #define CRC_INIT_TABLE_ONCE(id) ff_thread_once( ## _once_control, id ## 
_init_table_once)
 
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM,  0,  8,   0x07)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_SBC,  0,  8,   0x1D)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI,0, 16, 0x8005)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT,   0, 16, 0x1021)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE,0, 24,   0x864CFB)
@@ -351,6 +376,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id)
 #if !CONFIG_HARDCODED_TABLES
 switch (crc_id) {
 case AV_CRC_8_ATM:  CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM); break;
+case AV_CRC_8_SBC:  CRC_INIT_TABLE_ONCE(AV_CRC_8_SBC); break;
 case AV_CRC_16_ANSI:CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI); break;
 case AV_CRC_16_CCITT:   CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT); break;
 case AV_CRC_24_IEEE:CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE); break;
diff --git a/libavutil/crc.h b/libavutil/crc.h
index fe9a7c8fcb..e57a1af903 100644
--- a/libavutil/crc.h
+++ b/libavutil/crc.h
@@ -54,6 +54,7 @@ typedef enum {
 AV_CRC_32_IEEE_LE,  /*< reversed bitorder version of AV_CRC_32_IEEE */
 AV_CRC_16_ANSI_LE,  /*< reversed bitorder version of AV_CRC_16_ANSI */
 AV_CRC_24_IEEE,
+AV_CRC_8_SBC,
 AV_CRC_MAX, /*< Not part of public API! Do not use outside 
libavutil. */
 }AVCRCId;
 
diff --git a/libavutil/tests/crc.c b/libavutil/tests/crc.c
index 9825d6bec9..3fdc335cc3 100644
--- a/libavutil/tests/crc.c
+++ b/libavutil/tests/crc.c
@@ -25,20 +25,21 @@ int main(void)
 {
 uint8_t buf[1999];
 int i;
-static const unsigned p[6][3] = {
+static const unsigned p[7][3] = {
 { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
 { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
 { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
 { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 },
 { AV_CRC_16_ANSI   , 0x8005, 0x1FBB },
-{ AV_CRC_8_ATM , 0x07  , 0xE3   }
+{ AV_CRC_8_ATM , 0x07  , 0xE3   },
+{ AV_CRC_8_SBC , 0x1D  , 0xD6   },
 };
 const AVCRC *ctx;
 
 for (i = 0; i < sizeof(buf); i++)
 buf[i] = i + i * i;
 
-for (i = 0; i < 6; i++) {
+for (i = 0; i < 7; i++) {
 ctx = av_crc_get_table(p[i][0]);
 printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
 }
diff --git a/tests/ref/fate/crc b/tests/ref/fate/crc

Re: [FFmpeg-devel] [PATCH 02/10] crc: add av_crc_bits() to compute CRC on block with bit boundary

2017-12-23 Thread Aurelien Jacobs
On Thu, Dec 21, 2017 at 11:39:02AM +, Rostislav Pehlivanov wrote:
> On 20 December 2017 at 19:58, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > ---
> >  libavutil/crc.c | 20 
> >  libavutil/crc.h | 12 
> >  2 files changed, 32 insertions(+)
> >
> > diff --git a/libavutil/crc.c b/libavutil/crc.c
> > index 8e44a76ec8..cb26a09a20 100644
> > --- a/libavutil/crc.c
> > +++ b/libavutil/crc.c
> > @@ -413,3 +413,23 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
> >
> >  return crc;
> >  }
> > +
> > +uint32_t av_crc_bits(const AVCRC *ctx, uint32_t crc,
> > + const uint8_t *buffer, size_t length)
> > +{
> > +size_t byte_length = length >> 3;
> > +int bit_length = length & 7;
> > +
> > +crc = av_crc(ctx, crc, buffer, byte_length);
> > +
> > +if (bit_length) {
> > +uint8_t bits = buffer[byte_length];
> > +while (bit_length--) {
> > +int8_t mask = (bits ^ crc);
> > +crc = (crc << 1) ^ (ctx[1] & (mask >> 7));
> > +bits <<= 1;
> > +}
> > +}
> > +
> > +return crc;
> > +}
> > diff --git a/libavutil/crc.h b/libavutil/crc.h
> > index e57a1af903..bde31f858a 100644
> > --- a/libavutil/crc.h
> > +++ b/libavutil/crc.h
> > @@ -86,6 +86,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id);
> >  /**
> >   * Calculate the CRC of a block.
> >   * @param crc CRC of previous blocks if any or initial value for CRC
> > + * @param length number of bytes in the given block
> >   * @return CRC updated with the data from the given block
> >   *
> >   * @see av_crc_init() "le" parameter
> > @@ -93,6 +94,17 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id);
> >  uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
> >  const uint8_t *buffer, size_t length) av_pure;
> >
> > +/**
> > + * Calculate the CRC of a block with bits boundary.
> > + * @param crc CRC of previous blocks if any or initial value for CRC
> > + * @param length number of bits in the given block
> > + * @return CRC updated with the data from the given block
> > + *
> > + * @see av_crc_init() "le" parameter
> > + */
> > +uint32_t av_crc_bits(const AVCRC *ctx, uint32_t crc,
> > + const uint8_t *buffer, size_t length) av_pure;
> > +
> >  /**
> >   * @}
> >   */
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> 
> Sorry, I didn't see that sbc does fucked up crc on 7 bits.

Well, it is not on 7 bits. That actual data length is a multiple of
4 bits.

> In that case could you submit a new version of just the sbc patch which
> adds this back in the decoder?

I moved the function back to sbc, but I keept its usage of av_crc() for
the whole buffer except for the last bits that don't form a full byte.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 08/10] sbcenc: add MMX optimizations

2017-12-23 Thread Aurelien Jacobs
On Wed, Dec 20, 2017 at 10:22:54PM -0300, James Almer wrote:
> On 12/20/2017 4:58 PM, Aurelien Jacobs wrote:
> > +;***
> > +;void ff_sbc_calc_scalefactors(int32_t sb_sample_f[16][2][8],
> > +;  uint32_t scale_factor[2][8],
> > +;  int blocks, int channels, int subbands)
> > +;***
> > +INIT_MMX mmx
> > +cglobal sbc_calc_scalefactors, 5, 7, 3, sb_sample_f, scale_factor, blocks, 
> > channels, subbands, ptr, blk
> > +; subbands = 4 * subbands * channels
> > +shl  subbandsq, 2
> 
> Again, shl  subbandsd, 2

OK, good catch ! Fixed in upcoming patch.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 01/10] crc: add AV_CRC_8_SBC as a 8 bits CRC with polynomial 0x1D

2017-12-23 Thread Aurelien Jacobs
On Thu, Dec 21, 2017 at 02:12:26AM +0100, Michael Niedermayer wrote:
> On Wed, Dec 20, 2017 at 08:58:05PM +0100, Aurelien Jacobs wrote:
> > ---
> >  libavutil/crc.c   | 26 ++
> >  libavutil/crc.h   |  1 +
> >  libavutil/tests/crc.c |  7 ---
> >  3 files changed, 31 insertions(+), 3 deletions(-)
> 
> This needs a update for 
> tests/ref/fate/crc

Oh, indeed, fixed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 6/8] sbcenc: add MMX optimizations

2017-12-20 Thread Aurelien Jacobs
On Wed, Dec 20, 2017 at 03:47:35PM -0300, James Almer wrote:
> On 12/17/2017 6:47 PM, Aurelien Jacobs wrote:
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> >  libavcodec/sbcdsp.c  |   3 +
> >  libavcodec/sbcdsp.h  |   2 +
> >  libavcodec/x86/Makefile  |   2 +
> >  libavcodec/x86/sbcdsp.asm| 284 
> > +++
> >  libavcodec/x86/sbcdsp_init.c |  51 
> >  5 files changed, 342 insertions(+)
> >  create mode 100644 libavcodec/x86/sbcdsp.asm
> >  create mode 100644 libavcodec/x86/sbcdsp_init.c
> > 
> > diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
> > index 16faf5ba9b..9bb60cdd5e 100644
> > --- a/libavcodec/sbcdsp.c
> > +++ b/libavcodec/sbcdsp.c
> > @@ -387,4 +387,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
> >  /* Default implementation for scale factors calculation */
> >  s->sbc_calc_scalefactors = sbc_calc_scalefactors;
> >  s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
> > +
> > +if (ARCH_X86)
> > +ff_sbcdsp_init_x86(s);
> >  }
> > diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
> > index 66ed7d324e..127e6a8a11 100644
> > --- a/libavcodec/sbcdsp.h
> > +++ b/libavcodec/sbcdsp.h
> > @@ -80,4 +80,6 @@ struct sbc_dsp_context {
> >   */
> >  void ff_sbcdsp_init(SBCDSPContext *s);
> >  
> > +void ff_sbcdsp_init_x86(SBCDSPContext *s);
> > +
> >  #endif /* AVCODEC_SBCDSP_H */
> > diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
> > index a805cd37b4..2350c8bbee 100644
> > --- a/libavcodec/x86/Makefile
> > +++ b/libavcodec/x86/Makefile
> > @@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += 
> > x86/pngdsp_init.o
> >  OBJS-$(CONFIG_PRORES_DECODER)  += x86/proresdsp_init.o
> >  OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp_init.o
> >  OBJS-$(CONFIG_RV40_DECODER)+= x86/rv40dsp_init.o
> > +OBJS-$(CONFIG_SBC_ENCODER) += x86/sbcdsp_init.o
> >  OBJS-$(CONFIG_SVQ1_ENCODER)+= x86/svq1enc_init.o
> >  OBJS-$(CONFIG_TAK_DECODER) += x86/takdsp_init.o
> >  OBJS-$(CONFIG_TRUEHD_DECODER)  += x86/mlpdsp_init.o
> > @@ -172,6 +173,7 @@ X86ASM-OBJS-$(CONFIG_PNG_DECODER)  += x86/pngdsp.o
> >  X86ASM-OBJS-$(CONFIG_PRORES_DECODER)   += x86/proresdsp.o
> >  X86ASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
> >  X86ASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o
> > +X86ASM-OBJS-$(CONFIG_SBC_ENCODER)  += x86/sbcdsp.o
> >  X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER) += x86/svq1enc.o
> >  X86ASM-OBJS-$(CONFIG_TAK_DECODER)  += x86/takdsp.o
> >  X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
> > diff --git a/libavcodec/x86/sbcdsp.asm b/libavcodec/x86/sbcdsp.asm
> > new file mode 100644
> > index 00..00b48a821b
> > --- /dev/null
> > +++ b/libavcodec/x86/sbcdsp.asm
> > @@ -0,0 +1,284 @@
> > +;**
> > +;* SIMD optimized SBC encoder DSP functions
> > +;*
> > +;* Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
> > +;* Copyright (C) 2008-2010  Nokia Corporation
> > +;* Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
> > +;* Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
> > +;* Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
> > +;*
> > +;* 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
> > +;**
> > +
> > +%include "libavutil/x86/x86util.asm"
> > +
> > +SECTION_RODATA
> > +
> > +scale_mask

[FFmpeg-devel] [PATCH 10/10] Changelog: list the new SBC codec

2017-12-20 Thread Aurelien Jacobs
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index ee48876128..4a98884a3c 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - video setrange filter
 - nsp demuxer
 - support LibreSSL (via libtls)
+- native SBC and mSBC encoder and decoder
 
 
 version 3.4:
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 09/10] sbcenc: add armv6 and neon asm optimizations

2017-12-20 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 libavcodec/arm/Makefile  |   3 +
 libavcodec/arm/sbcdsp_armv6.S| 245 ++
 libavcodec/arm/sbcdsp_init_arm.c | 105 ++
 libavcodec/arm/sbcdsp_neon.S | 714 +++
 libavcodec/sbcdsp.c  |   2 +
 libavcodec/sbcdsp.h  |   1 +
 6 files changed, 1070 insertions(+)
 create mode 100644 libavcodec/arm/sbcdsp_armv6.S
 create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
 create mode 100644 libavcodec/arm/sbcdsp_neon.S

diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index 1eeac5449e..fd2401f4e5 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -42,6 +42,7 @@ OBJS-$(CONFIG_DCA_DECODER) += 
arm/synth_filter_init_arm.o
 OBJS-$(CONFIG_HEVC_DECODER)+= arm/hevcdsp_init_arm.o
 OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_init_arm.o
 OBJS-$(CONFIG_RV40_DECODER)+= arm/rv40dsp_init_arm.o
+OBJS-$(CONFIG_SBC_ENCODER) += arm/sbcdsp_init_arm.o
 OBJS-$(CONFIG_VORBIS_DECODER)  += arm/vorbisdsp_init_arm.o
 OBJS-$(CONFIG_VP6_DECODER) += arm/vp6dsp_init_arm.o
 OBJS-$(CONFIG_VP9_DECODER) += arm/vp9dsp_init_10bpp_arm.o   \
@@ -81,6 +82,7 @@ ARMV6-OBJS-$(CONFIG_VP8DSP)+= arm/vp8_armv6.o 
  \
 
 # decoders/encoders
 ARMV6-OBJS-$(CONFIG_MLP_DECODER)   += arm/mlpdsp_armv6.o
+ARMV6-OBJS-$(CONFIG_SBC_ENCODER)   += arm/sbcdsp_armv6.o
 
 
 # VFP optimizations
@@ -140,6 +142,7 @@ NEON-OBJS-$(CONFIG_HEVC_DECODER)   += 
arm/hevcdsp_init_neon.o   \
 NEON-OBJS-$(CONFIG_RV30_DECODER)   += arm/rv34dsp_neon.o
 NEON-OBJS-$(CONFIG_RV40_DECODER)   += arm/rv34dsp_neon.o\
   arm/rv40dsp_neon.o
+NEON-OBJS-$(CONFIG_SBC_ENCODER)+= arm/sbcdsp_neon.o
 NEON-OBJS-$(CONFIG_VORBIS_DECODER) += arm/vorbisdsp_neon.o
 NEON-OBJS-$(CONFIG_VP6_DECODER)+= arm/vp6dsp_neon.o
 NEON-OBJS-$(CONFIG_VP9_DECODER)+= arm/vp9itxfm_16bpp_neon.o \
diff --git a/libavcodec/arm/sbcdsp_armv6.S b/libavcodec/arm/sbcdsp_armv6.S
new file mode 100644
index 00..f1ff845798
--- /dev/null
+++ b/libavcodec/arm/sbcdsp_armv6.S
@@ -0,0 +1,245 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 ARMv6 optimizations. The instructions are scheduled for ARM11 pipeline.
+ */
+
+#include "libavutil/arm/asm.S"
+
+function ff_sbc_analyze_4_armv6, export=1
+@ r0 = in, r1 = out, r2 = consts
+push{r1, r3-r7, lr}
+push{r8-r12, r14}
+ldrdr4,  r5,  [r0, #0]
+ldrdr6,  r7,  [r2, #0]
+ldrdr8,  r9,  [r0, #16]
+ldrdr10, r11, [r2, #16]
+mov r14, #0x8000
+smlad   r3,  r4,  r6,  r14
+smlad   r12, r5,  r7,  r14
+ldrdr4,  r5,  [r0, #32]
+ldrdr6,  r7,  [r2, #32]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #48]
+ldrdr10, r11, [r2, #48]
+smlad   r3,  r4,  r6,  r3
+smlad   r12, r5,  r7,  r12
+ldrdr4,  r5,  [r0, #64]
+ldrdr6,  r7,  [r2, #64]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #8]
+ldrdr10, r11, [r2, #8]
+smlad   r3,  r4,  r6,  r3@ t1[0] is done
+smlad   r12, r5,  r7,  r12   @ t1[1] is done
+ldrdr4,  r5,  [r0, #24]
+ldrdr6,  r7,  [r2, #24]
+pkhtb   r3,  r12, r3, asr #16@ comb

[FFmpeg-devel] [PATCH 08/10] sbcenc: add MMX optimizations

2017-12-20 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.

Rough speed test:
C version:speed= 592x
MMX version:  speed= 785x
---
 libavcodec/sbcdsp.c  |   3 +
 libavcodec/sbcdsp.h  |   2 +
 libavcodec/x86/Makefile  |   2 +
 libavcodec/x86/sbcdsp.asm| 284 +++
 libavcodec/x86/sbcdsp_init.c |  51 
 5 files changed, 342 insertions(+)
 create mode 100644 libavcodec/x86/sbcdsp.asm
 create mode 100644 libavcodec/x86/sbcdsp_init.c

diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
index e155387f0d..2d0addcf28 100644
--- a/libavcodec/sbcdsp.c
+++ b/libavcodec/sbcdsp.c
@@ -379,4 +379,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
 /* Default implementation for scale factors calculation */
 s->sbc_calc_scalefactors = sbc_calc_scalefactors;
 s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
+
+if (ARCH_X86)
+ff_sbcdsp_init_x86(s);
 }
diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
index 66ed7d324e..127e6a8a11 100644
--- a/libavcodec/sbcdsp.h
+++ b/libavcodec/sbcdsp.h
@@ -80,4 +80,6 @@ struct sbc_dsp_context {
  */
 void ff_sbcdsp_init(SBCDSPContext *s);
 
+void ff_sbcdsp_init_x86(SBCDSPContext *s);
+
 #endif /* AVCODEC_SBCDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a805cd37b4..2350c8bbee 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_DECODER)  += x86/proresdsp_init.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp_init.o
 OBJS-$(CONFIG_RV40_DECODER)+= x86/rv40dsp_init.o
+OBJS-$(CONFIG_SBC_ENCODER) += x86/sbcdsp_init.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= x86/svq1enc_init.o
 OBJS-$(CONFIG_TAK_DECODER) += x86/takdsp_init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)  += x86/mlpdsp_init.o
@@ -172,6 +173,7 @@ X86ASM-OBJS-$(CONFIG_PNG_DECODER)  += x86/pngdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_DECODER)   += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o
+X86ASM-OBJS-$(CONFIG_SBC_ENCODER)  += x86/sbcdsp.o
 X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER) += x86/svq1enc.o
 X86ASM-OBJS-$(CONFIG_TAK_DECODER)  += x86/takdsp.o
 X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
diff --git a/libavcodec/x86/sbcdsp.asm b/libavcodec/x86/sbcdsp.asm
new file mode 100644
index 00..00b48a821b
--- /dev/null
+++ b/libavcodec/x86/sbcdsp.asm
@@ -0,0 +1,284 @@
+;**
+;* SIMD optimized SBC encoder DSP functions
+;*
+;* Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+;* Copyright (C) 2008-2010  Nokia Corporation
+;* Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+;* Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+;* Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+;*
+;* 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
+;**
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+scale_mask: times 2 dd 0x8000; 1 << (SBC_PROTO_FIXED_SCALE - 1)
+
+SECTION .text
+
+;***
+;void ff_sbc_analyze_4(const int16_t *in, int32_t *out, const int16_t *consts);
+;***
+INIT_MMX mmx
+cglobal sbc_analyze_4, 3, 3, 4, in, out, consts
+movq  m0, [inq]
+movq  m1, [inq+8]
+pmaddwd   m0, [constsq]
+pmaddwd   m1, [constsq+8]
+paddd m0, [scale_mask]
+paddd m1, [scale_mask]
+
+movq  m2, [inq+16]
+movq  m3, [inq+24]
+pmaddwd   m2, [constsq+16]
+pmaddwd   m3, [constsq+24]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+32]
+movq  m3, [inq+40]
+pmaddwd   m2, [constsq+32]
+pmaddwd   m3, [constsq+40]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+48]
+mo

[FFmpeg-devel] [PATCH 07/10] sbc: add raw muxer for SBC

2017-12-20 Thread Aurelien Jacobs
---
 doc/general.texi |  2 +-
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  4 ++--
 libavformat/rawenc.c | 28 
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/general.texi b/doc/general.texi
index e5669b0e93..560465a4b8 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,7 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
-@item raw SBC   @tab   @tab X
+@item raw SBC   @tab X @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 88d2cbd2b3..9002808ac1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -448,7 +448,9 @@ OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o 
subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
 OBJS-$(CONFIG_SBC_DEMUXER)   += rawdec.o
+OBJS-$(CONFIG_SBC_MUXER) += rawenc.o
 OBJS-$(CONFIG_MSBC_DEMUXER)  += rawdec.o
+OBJS-$(CONFIG_MSBC_MUXER)+= rawenc.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index a6b72715bd..eb1d17d38c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,7 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
-REGISTER_DEMUXER (MSBC, msbc);
+REGISTER_MUXDEMUX(MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -278,7 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
-REGISTER_DEMUXER (SBC,  sbc);
+REGISTER_MUXDEMUX(SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index aa3ef76fbf..e27b280014 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -426,6 +426,34 @@ AVOutputFormat ff_rawvideo_muxer = {
 };
 #endif
 
+#if CONFIG_SBC_MUXER
+AVOutputFormat ff_sbc_muxer = {
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
+.mime_type = "audio/x-sbc",
+.extensions= "sbc",
+.audio_codec   = AV_CODEC_ID_SBC,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
+#if CONFIG_MSBC_MUXER
+AVOutputFormat ff_msbc_muxer = {
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw mSBC"),
+.mime_type = "audio/x-msbc",
+.extensions= "msbc",
+.audio_codec   = AV_CODEC_ID_MSBC,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_TRUEHD_MUXER
 AVOutputFormat ff_truehd_muxer = {
 .name  = "truehd",
-- 
2.15.1

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


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

2017-12-20 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 <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 tabl

[FFmpeg-devel] [PATCH 05/10] sbc: add raw demuxer for SBC

2017-12-20 Thread Aurelien Jacobs
---
 doc/general.texi |  1 +
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  2 ++
 libavformat/rawdec.c | 24 
 4 files changed, 29 insertions(+)

diff --git a/doc/general.texi b/doc/general.texi
index ed137f999f..65aee47f2a 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,6 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
+@item raw SBC   @tab   @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..88d2cbd2b3 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -447,6 +447,8 @@ OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
+OBJS-$(CONFIG_SBC_DEMUXER)   += rawdec.o
+OBJS-$(CONFIG_MSBC_DEMUXER)  += rawdec.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..a6b72715bd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,6 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
+REGISTER_DEMUXER (MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -277,6 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
+REGISTER_DEMUXER (SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index e926549a60..d94f4972cb 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -191,3 +191,27 @@ static int mjpeg_probe(AVProbeData *p)
 
 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg, "raw MJPEG video", mjpeg_probe, 
"mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS)
 #endif
+
+#if CONFIG_SBC_DEMUXER
+AVInputFormat ff_sbc_demuxer = {
+.name   = "sbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw SBC (low-complexity subband 
codec)"),
+.extensions = "sbc",
+.raw_codec_id   = AV_CODEC_ID_SBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
+#endif
+
+#if CONFIG_MSBC_DEMUXER
+AVInputFormat ff_msbc_demuxer = {
+.name   = "msbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw mSBC (wideband speech mono 
SBC)"),
+.extensions = "msbc",
+.raw_codec_id   = AV_CODEC_ID_MSBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
+#endif
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 04/10] sbc: add parser for SBC

2017-12-20 Thread Aurelien Jacobs
---
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/sbc_parser.c | 124 
 3 files changed, 126 insertions(+)
 create mode 100644 libavcodec/sbc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c46d102227..58c8c6e499 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1012,6 +1012,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_SBC_PARSER)  += sbc_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  \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 9e2480d2d4..3e3b37f638 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -653,6 +653,7 @@ static void register_all(void)
 REGISTER_PARSER(PNM,pnm);
 REGISTER_PARSER(RV30,   rv30);
 REGISTER_PARSER(RV40,   rv40);
+REGISTER_PARSER(SBC,sbc);
 REGISTER_PARSER(SIPR,   sipr);
 REGISTER_PARSER(TAK,tak);
 REGISTER_PARSER(VC1,vc1);
diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
new file mode 100644
index 00..032f72cf2b
--- /dev/null
+++ b/libavcodec/sbc_parser.c
@@ -0,0 +1,124 @@
+/*
+ * SBC parser
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "sbc.h"
+#include "parser.h"
+
+typedef struct SBCParseContext {
+ParseContext pc;
+uint8_t header[3];
+int header_size;
+int buffered_size;
+} SBCParseContext;
+
+static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
+const uint8_t *data, size_t len)
+{
+static const int sample_rates[4] = { 16000, 32000, 44100, 48000 };
+int sr, blocks, mode, subbands, bitpool, channels, joint;
+int length;
+
+if (len < 3)
+return -1;
+
+if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
+avctx->channels = 1;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = 16000;
+avctx->frame_size = 120;
+s->duration = avctx->frame_size;
+return 57;
+}
+
+if (data[0] != SBC_SYNCWORD)
+return -2;
+
+sr   =   (data[1] >> 6) & 0x03;
+blocks   = (((data[1] >> 4) & 0x03) + 1) << 2;
+mode =   (data[1] >> 2) & 0x03;
+subbands = (((data[1] >> 0) & 0x01) + 1) << 2;
+bitpool  = data[2];
+
+channels = mode == SBC_MODE_MONO ? 1 : 2;
+joint= mode == SBC_MODE_JOINT_STEREO;
+
+length = 4 + (subbands * channels) / 2;
+if (channels == 1 || mode == SBC_MODE_DUAL_CHANNEL)
+length += ((channels * blocks * bitpool) + 7) / 8;
+else
+length += (((joint ? subbands : 0) + blocks * bitpool) + 7) / 8;
+
+avctx->channels = channels;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = sample_rates[sr];
+avctx->frame_size = subbands * blocks;
+s->duration = avctx->frame_size;
+return length;
+}
+
+static int sbc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+SBCParseContext *pc = s->priv_data;
+int next;
+
+if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+next = buf_size;
+} else {
+if (pc->header_size) {
+memcpy(pc->header + pc->header_size, buf,
+   sizeof(pc->header) - pc->header_size);
+next = sbc_parse_header(s, avctx, pc->header, sizeof(pc->header))
+ - pc->buffered_size;
+pc->header_size = 0;
+} else {
+next = sbc_parse_header(s, avctx, buf, buf_siz

[FFmpeg-devel] [PATCH 03/10] sbc: implement SBC decoder (low-complexity subband codec)

2017-12-20 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   |   2 +
 libavcodec/avcodec.h |   2 +
 libavcodec/codec_desc.c  |  14 ++
 libavcodec/sbc.c | 257 ++
 libavcodec/sbc.h | 120 
 libavcodec/sbcdec.c  | 466 +++
 libavcodec/sbcdec_data.c | 127 +
 libavcodec/sbcdec_data.h |  44 +
 10 files changed, 1036 insertions(+)
 create mode 100644 libavcodec/sbc.c
 create mode 100644 libavcodec/sbc.h
 create mode 100644 libavcodec/sbcdec.c
 create mode 100644 libavcodec/sbcdec_data.c
 create mode 100644 libavcodec/sbcdec_data.h

diff --git a/doc/general.texi b/doc/general.texi
index 26919c9287..ed137f999f 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1102,6 +1102,8 @@ 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
+@tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
 @tab Used in Sierra VMD files.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ca72138c02..c46d102227 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -581,6 +581,8 @@ OBJS-$(CONFIG_SUBVIEWER_DECODER)   += subviewerdec.o 
ass.o
 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_MSBC_DECODER)+= sbcdec.o sbcdec_data.o sbc.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 ed1e7ab06e..9e2480d2d4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -379,6 +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 (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
 REGISTER_ENCDEC (OPUS,  opus);
@@ -392,6 +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 (SONIC, sonic);
 REGISTER_ENCODER(SONIC_LS,  sonic_ls);
 REGISTER_DECODER(TAK,   tak);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ce089b7c4a..5b7ec8541d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -634,6 +634,8 @@ enum AVCodecID {
 AV_CODEC_ID_ATRAC3PAL,
 AV_CODEC_ID_DOLBY_E,
 AV_CODEC_ID_APTX,
+AV_CODEC_ID_SBC,
+AV_CODEC_ID_MSBC,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index c3688de1d6..a69897d379 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2866,6 +2866,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("aptX (Audio Processing Technology 
for Bluetooth)"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_SBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband 
codec)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
+.id= AV_CODEC_ID_MSBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("mSBC (wideband speech mono SBC)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/sbc.c b/libavcodec/sbc.c
new file mode 100644
index 00..61bc27da6e
--- /dev/null
+++ b/libavcodec/sbc.c
@@ -0,0 +1,257 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2008  Brad Midgley <

[FFmpeg-devel] [PATCH 02/10] crc: add av_crc_bits() to compute CRC on block with bit boundary

2017-12-20 Thread Aurelien Jacobs
---
 libavutil/crc.c | 20 
 libavutil/crc.h | 12 
 2 files changed, 32 insertions(+)

diff --git a/libavutil/crc.c b/libavutil/crc.c
index 8e44a76ec8..cb26a09a20 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -413,3 +413,23 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
 
 return crc;
 }
+
+uint32_t av_crc_bits(const AVCRC *ctx, uint32_t crc,
+ const uint8_t *buffer, size_t length)
+{
+size_t byte_length = length >> 3;
+int bit_length = length & 7;
+
+crc = av_crc(ctx, crc, buffer, byte_length);
+
+if (bit_length) {
+uint8_t bits = buffer[byte_length];
+while (bit_length--) {
+int8_t mask = (bits ^ crc);
+crc = (crc << 1) ^ (ctx[1] & (mask >> 7));
+bits <<= 1;
+}
+}
+
+return crc;
+}
diff --git a/libavutil/crc.h b/libavutil/crc.h
index e57a1af903..bde31f858a 100644
--- a/libavutil/crc.h
+++ b/libavutil/crc.h
@@ -86,6 +86,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id);
 /**
  * Calculate the CRC of a block.
  * @param crc CRC of previous blocks if any or initial value for CRC
+ * @param length number of bytes in the given block
  * @return CRC updated with the data from the given block
  *
  * @see av_crc_init() "le" parameter
@@ -93,6 +94,17 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id);
 uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
 const uint8_t *buffer, size_t length) av_pure;
 
+/**
+ * Calculate the CRC of a block with bits boundary.
+ * @param crc CRC of previous blocks if any or initial value for CRC
+ * @param length number of bits in the given block
+ * @return CRC updated with the data from the given block
+ *
+ * @see av_crc_init() "le" parameter
+ */
+uint32_t av_crc_bits(const AVCRC *ctx, uint32_t crc,
+ const uint8_t *buffer, size_t length) av_pure;
+
 /**
  * @}
  */
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 01/10] crc: add AV_CRC_8_SBC as a 8 bits CRC with polynomial 0x1D

2017-12-20 Thread Aurelien Jacobs
---
 libavutil/crc.c   | 26 ++
 libavutil/crc.h   |  1 +
 libavutil/tests/crc.c |  7 ---
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/libavutil/crc.c b/libavutil/crc.c
index d44550c9c0..8e44a76ec8 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -52,6 +52,30 @@ static const AVCRC av_crc_table[AV_CRC_MAX][257] = {
 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF,
 0xFA, 0xFD, 0xF4, 0xF3, 0x01
 },
+[AV_CRC_8_SBC] = {
+0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53, 0xE8, 0xF5, 0xD2, 0xCF,
+0x9C, 0x81, 0xA6, 0xBB, 0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E,
+0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76, 0x87, 0x9A, 0xBD, 0xA0,
+0xF3, 0xEE, 0xC9, 0xD4, 0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 0x3C,
+0x4A, 0x57, 0x70, 0x6D, 0x3E, 0x23, 0x04, 0x19, 0xA2, 0xBF, 0x98, 0x85,
+0xD6, 0xCB, 0xEC, 0xF1, 0x13, 0x0E, 0x29, 0x34, 0x67, 0x7A, 0x5D, 0x40,
+0xFB, 0xE6, 0xC1, 0xDC, 0x8F, 0x92, 0xB5, 0xA8, 0xDE, 0xC3, 0xE4, 0xF9,
+0xAA, 0xB7, 0x90, 0x8D, 0x36, 0x2B, 0x0C, 0x11, 0x42, 0x5F, 0x78, 0x65,
+0x94, 0x89, 0xAE, 0xB3, 0xE0, 0xFD, 0xDA, 0xC7, 0x7C, 0x61, 0x46, 0x5B,
+0x08, 0x15, 0x32, 0x2F, 0x59, 0x44, 0x63, 0x7E, 0x2D, 0x30, 0x17, 0x0A,
+0xB1, 0xAC, 0x8B, 0x96, 0xC5, 0xD8, 0xFF, 0xE2, 0x26, 0x3B, 0x1C, 0x01,
+0x52, 0x4F, 0x68, 0x75, 0xCE, 0xD3, 0xF4, 0xE9, 0xBA, 0xA7, 0x80, 0x9D,
+0xEB, 0xF6, 0xD1, 0xCC, 0x9F, 0x82, 0xA5, 0xB8, 0x03, 0x1E, 0x39, 0x24,
+0x77, 0x6A, 0x4D, 0x50, 0xA1, 0xBC, 0x9B, 0x86, 0xD5, 0xC8, 0xEF, 0xF2,
+0x49, 0x54, 0x73, 0x6E, 0x3D, 0x20, 0x07, 0x1A, 0x6C, 0x71, 0x56, 0x4B,
+0x18, 0x05, 0x22, 0x3F, 0x84, 0x99, 0xBE, 0xA3, 0xF0, 0xED, 0xCA, 0xD7,
+0x35, 0x28, 0x0F, 0x12, 0x41, 0x5C, 0x7B, 0x66, 0xDD, 0xC0, 0xE7, 0xFA,
+0xA9, 0xB4, 0x93, 0x8E, 0xF8, 0xE5, 0xC2, 0xDF, 0x8C, 0x91, 0xB6, 0xAB,
+0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95,
+0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
+0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0,
+0xE3, 0xFE, 0xD9, 0xC4, 0x01
+},
 [AV_CRC_16_ANSI] = {
 0x, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180,
 0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200,
@@ -305,6 +329,7 @@ static void id ## _init_table_once(void)
 #define CRC_INIT_TABLE_ONCE(id) ff_thread_once( ## _once_control, id ## 
_init_table_once)
 
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM,  0,  8,   0x07)
+DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_8_SBC,  0,  8,   0x1D)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI,0, 16, 0x8005)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT,   0, 16, 0x1021)
 DECLARE_CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE,0, 24,   0x864CFB)
@@ -351,6 +376,7 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id)
 #if !CONFIG_HARDCODED_TABLES
 switch (crc_id) {
 case AV_CRC_8_ATM:  CRC_INIT_TABLE_ONCE(AV_CRC_8_ATM); break;
+case AV_CRC_8_SBC:  CRC_INIT_TABLE_ONCE(AV_CRC_8_SBC); break;
 case AV_CRC_16_ANSI:CRC_INIT_TABLE_ONCE(AV_CRC_16_ANSI); break;
 case AV_CRC_16_CCITT:   CRC_INIT_TABLE_ONCE(AV_CRC_16_CCITT); break;
 case AV_CRC_24_IEEE:CRC_INIT_TABLE_ONCE(AV_CRC_24_IEEE); break;
diff --git a/libavutil/crc.h b/libavutil/crc.h
index fe9a7c8fcb..e57a1af903 100644
--- a/libavutil/crc.h
+++ b/libavutil/crc.h
@@ -54,6 +54,7 @@ typedef enum {
 AV_CRC_32_IEEE_LE,  /*< reversed bitorder version of AV_CRC_32_IEEE */
 AV_CRC_16_ANSI_LE,  /*< reversed bitorder version of AV_CRC_16_ANSI */
 AV_CRC_24_IEEE,
+AV_CRC_8_SBC,
 AV_CRC_MAX, /*< Not part of public API! Do not use outside 
libavutil. */
 }AVCRCId;
 
diff --git a/libavutil/tests/crc.c b/libavutil/tests/crc.c
index 9825d6bec9..3fdc335cc3 100644
--- a/libavutil/tests/crc.c
+++ b/libavutil/tests/crc.c
@@ -25,20 +25,21 @@ int main(void)
 {
 uint8_t buf[1999];
 int i;
-static const unsigned p[6][3] = {
+static const unsigned p[7][3] = {
 { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 },
 { AV_CRC_32_IEEE   , 0x04C11DB7, 0xC0F5BAE0 },
 { AV_CRC_24_IEEE   , 0x864CFB  , 0xB704CE   },
 { AV_CRC_16_ANSI_LE, 0xA001, 0xBFD8 },
 { AV_CRC_16_ANSI   , 0x8005, 0x1FBB },
-{ AV_CRC_8_ATM , 0x07  , 0xE3   }
+{ AV_CRC_8_ATM , 0x07  , 0xE3   },
+{ AV_CRC_8_SBC , 0x1D  , 0xD6   },
 };
 const AVCRC *ctx;
 
 for (i = 0; i < sizeof(buf); i++)
 buf[i] = i + i * i;
 
-for (i = 0; i < 6; i++) {
+for (i = 0; i < 7; i++) {
 ctx = av_crc_get_table(p[i][0]);
 printf("crc %08X = %X\n", p[i][1], av_crc(ctx, 0, buf, sizeof(buf)));
 }
-- 
2.15.1

___
ffmpeg-devel mailing list

Re: [FFmpeg-devel] [PATCH 1/8] sbc: implement SBC decoder (low-complexity subband codec)

2017-12-20 Thread Aurelien Jacobs
On Mon, Dec 18, 2017 at 01:05:39AM +, Rostislav Pehlivanov wrote:
> On 17 December 2017 at 21:47, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> >  doc/general.texi |   2 +
> >  libavcodec/Makefile  |   2 +
> >  libavcodec/allcodecs.c   |   2 +
> >  libavcodec/avcodec.h |   2 +
> >  libavcodec/codec_desc.c  |  14 ++
> >  libavcodec/sbc.c | 316 
> >  libavcodec/sbc.h | 118 
> >  libavcodec/sbcdec.c  | 464 ++
> > +
> >  libavcodec/sbcdec_data.c | 127 +
> >  libavcodec/sbcdec_data.h |  44 +
> >  10 files changed, 1091 insertions(+)
> >  create mode 100644 libavcodec/sbc.c
> >  create mode 100644 libavcodec/sbc.h
> >  create mode 100644 libavcodec/sbcdec.c
> >  create mode 100644 libavcodec/sbcdec_data.c
> >  create mode 100644 libavcodec/sbcdec_data.h
> >
> >
> > +
> > +/*
> > + * Calculates the CRC-8 of the first len bits in data
> > + */
> > +static const uint8_t crc_table[256] = {
> > +0x00, 0x1D, 0x3A, 0x27, 0x74, 0x69, 0x4E, 0x53,
> > +0xE8, 0xF5, 0xD2, 0xCF, 0x9C, 0x81, 0xA6, 0xBB,
> > +0xCD, 0xD0, 0xF7, 0xEA, 0xB9, 0xA4, 0x83, 0x9E,
> > +0x25, 0x38, 0x1F, 0x02, 0x51, 0x4C, 0x6B, 0x76,
> > +0x87, 0x9A, 0xBD, 0xA0, 0xF3, 0xEE, 0xC9, 0xD4,
> > +0x6F, 0x72, 0x55, 0x48, 0x1B, 0x06, 0x21, 0x3C,
> > +0x4A, 0x57, 0x70, 0x6D, 0x3E, 0x23, 0x04, 0x19,
> > +0xA2, 0xBF, 0x98, 0x85, 0xD6, 0xCB, 0xEC, 0xF1,
> > +0x13, 0x0E, 0x29, 0x34, 0x67, 0x7A, 0x5D, 0x40,
> > +0xFB, 0xE6, 0xC1, 0xDC, 0x8F, 0x92, 0xB5, 0xA8,
> > +0xDE, 0xC3, 0xE4, 0xF9, 0xAA, 0xB7, 0x90, 0x8D,
> > +0x36, 0x2B, 0x0C, 0x11, 0x42, 0x5F, 0x78, 0x65,
> > +0x94, 0x89, 0xAE, 0xB3, 0xE0, 0xFD, 0xDA, 0xC7,
> > +0x7C, 0x61, 0x46, 0x5B, 0x08, 0x15, 0x32, 0x2F,
> > +0x59, 0x44, 0x63, 0x7E, 0x2D, 0x30, 0x17, 0x0A,
> > +0xB1, 0xAC, 0x8B, 0x96, 0xC5, 0xD8, 0xFF, 0xE2,
> > +0x26, 0x3B, 0x1C, 0x01, 0x52, 0x4F, 0x68, 0x75,
> > +0xCE, 0xD3, 0xF4, 0xE9, 0xBA, 0xA7, 0x80, 0x9D,
> > +0xEB, 0xF6, 0xD1, 0xCC, 0x9F, 0x82, 0xA5, 0xB8,
> > +0x03, 0x1E, 0x39, 0x24, 0x77, 0x6A, 0x4D, 0x50,
> > +0xA1, 0xBC, 0x9B, 0x86, 0xD5, 0xC8, 0xEF, 0xF2,
> > +0x49, 0x54, 0x73, 0x6E, 0x3D, 0x20, 0x07, 0x1A,
> > +0x6C, 0x71, 0x56, 0x4B, 0x18, 0x05, 0x22, 0x3F,
> > +0x84, 0x99, 0xBE, 0xA3, 0xF0, 0xED, 0xCA, 0xD7,
> > +0x35, 0x28, 0x0F, 0x12, 0x41, 0x5C, 0x7B, 0x66,
> > +0xDD, 0xC0, 0xE7, 0xFA, 0xA9, 0xB4, 0x93, 0x8E,
> > +0xF8, 0xE5, 0xC2, 0xDF, 0x8C, 0x91, 0xB6, 0xAB,
> > +0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43,
> > +0xB2, 0xAF, 0x88, 0x95, 0xC6, 0xDB, 0xFC, 0xE1,
> > +0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
> > +0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C,
> > +0x97, 0x8A, 0xAD, 0xB0, 0xE3, 0xFE, 0xD9, 0xC4
> > +};
> > +
> > +uint8_t ff_sbc_crc8(const uint8_t *data, size_t len)
> > +{
> > +uint8_t crc = 0x0f;
> > +size_t i;
> > +uint8_t octet;
> > +
> > +for (i = 0; i < len / 8; i++)
> > +crc = crc_table[crc ^ data[i]];
> > +
> > +octet = data[i];
> > +for (i = 0; i < len % 8; i++) {
> > +char bit = ((octet ^ crc) & 0x80) >> 7;
> > +
> > +crc = ((crc & 0x7f) << 1) ^ (bit ? 0x1d : 0);
> > +
> > +octet = octet << 1;
> > +}
> > +
> > +return crc;
> > +}
> >
> 
> 
> Yeah, no, I absolutely insist on using av_crc. The init function can handle
> any byte-length CRC method as its done here.

The issue is that this function is using a non multiple of 8 number of
input bits, while av_crc is only working on bytes buffer.
Nevertheless, I switched to using av_crc, but I've added an
av_crc_bits() function which is not limited to bytes boundaries.
New patchset upcoming.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2017-12-20 Thread Aurelien Jacobs
On Mon, Dec 18, 2017 at 12:45:12PM +0100, Michael Niedermayer wrote:
> On Sun, Dec 17, 2017 at 10:47:16PM +0100, Aurelien Jacobs wrote:
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> [...]
> > +static inline void sbc_analyze_4b_4s_simd(SBCDSPContext *s,
> > +  int16_t *x, int32_t *out, int 
> > out_stride)
> > +{
> > +/* Analyze blocks */
> > +s->sbc_analyze_4(x + 12, out, 
> > ff_sbcdsp_analysis_consts_fixed4_simd_odd);
> > +out += out_stride;
> > +s->sbc_analyze_4(x + 8, out, 
> > ff_sbcdsp_analysis_consts_fixed4_simd_even);
> > +out += out_stride;
> > +s->sbc_analyze_4(x + 4, out, 
> > ff_sbcdsp_analysis_consts_fixed4_simd_odd);
> > +out += out_stride;
> > +s->sbc_analyze_4(x + 0, out, 
> > ff_sbcdsp_analysis_consts_fixed4_simd_even);
> > +
> > +emms_c();
> > +}
> > +
> > +static inline void sbc_analyze_4b_8s_simd(SBCDSPContext *s,
> > +  int16_t *x, int32_t *out, int 
> > out_stride)
> > +{
> > +/* Analyze blocks */
> > +s->sbc_analyze_8(x + 24, out, 
> > ff_sbcdsp_analysis_consts_fixed8_simd_odd);
> > +out += out_stride;
> > +s->sbc_analyze_8(x + 16, out, 
> > ff_sbcdsp_analysis_consts_fixed8_simd_even);
> > +out += out_stride;
> > +s->sbc_analyze_8(x + 8, out, 
> > ff_sbcdsp_analysis_consts_fixed8_simd_odd);
> > +out += out_stride;
> > +s->sbc_analyze_8(x + 0, out, 
> > ff_sbcdsp_analysis_consts_fixed8_simd_even);
> > +
> > +emms_c();
> > +}
> > +
> > +static inline void sbc_analyze_1b_8s_simd_even(SBCDSPContext *s,
> > +   int16_t *x, int32_t *out,
> > +   int out_stride);
> > +
> > +static inline void sbc_analyze_1b_8s_simd_odd(SBCDSPContext *s,
> > +  int16_t *x, int32_t *out,
> > +  int out_stride)
> > +{
> > +s->sbc_analyze_8(x, out, ff_sbcdsp_analysis_consts_fixed8_simd_odd);
> > +s->sbc_analyze_8s = sbc_analyze_1b_8s_simd_even;
> > +
> > +emms_c();
> > +}
> > +
> > +static inline void sbc_analyze_1b_8s_simd_even(SBCDSPContext *s,
> > +   int16_t *x, int32_t *out,
> > +   int out_stride)
> > +{
> > +s->sbc_analyze_8(x, out, ff_sbcdsp_analysis_consts_fixed8_simd_even);
> > +s->sbc_analyze_8s = sbc_analyze_1b_8s_simd_odd;
> > +
> > +emms_c();
> > +}
> 
> at least some of the functions are always called in a loop, the emms_c() could
> be called after the loop

Ok, I moved all those emms_c() out of the loop.

> [...]
> > diff --git a/libavcodec/sbcdsp_data.c b/libavcodec/sbcdsp_data.c
> > new file mode 100644
> > index 00..1e19b9d9d1
> > --- /dev/null
> > +++ b/libavcodec/sbcdsp_data.c
> > @@ -0,0 +1,329 @@
> > +/*
> > + * Bluetooth low-complexity, subband codec (SBC)
> > + *
> > + * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
> > + * Copyright (C) 2008-2010  Nokia Corporation
> > + * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
> > + * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
> > + * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
> > + *
> > + * 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
> > + * miscellaneous SBC tables
> > + */
> > +
> > +#include "sbcdsp_data.h"
> > +
> > +#define F_PROTO(x) (int32_t) ((x * 2) * ((int32_t) 1 << 15) + 0.5)
> > +#define F_COS(x)   (int32_t) ((x) * ((int32_t) 1 << 15) + 0.5)
> 
> this needs more () to protect the argument x and the whole expression
> for example F_PROTO(1+1) would produce unexpected results

Indeed. Fixed in upcomming updated patch set.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 8/8] Changelog: list the new SBC features

2017-12-17 Thread Aurelien Jacobs
On Mon, Dec 18, 2017 at 12:22:27AM +0100, Carl Eugen Hoyos wrote:
> 2017-12-17 22:47 GMT+01:00 Aurelien Jacobs <au...@gnuage.org>:
> > ---
> >  Changelog | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/Changelog b/Changelog
> > index ee48876128..8eebcd810c 100644
> > --- a/Changelog
> > +++ b/Changelog
> > @@ -27,6 +27,8 @@ version :
> >  - video setrange filter
> >  - nsp demuxer
> >  - support LibreSSL (via libtls)
> > +- native SBC and mSBC encoder and decoder
> 
> > +- Raw SBC and mSBC muxer and demuxer
> 
> Imo, codec is enough, no need to mention a raw
> (de)muxer for a codec that has no other usage.

OK, there it is.>From de4d68b738cbb3598614831b181048591395840f Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sun, 17 Dec 2017 20:27:04 +0100
Subject: [PATCH 8/8] Changelog: list the new SBC codec

---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index ee48876128..4a98884a3c 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - video setrange filter
 - nsp demuxer
 - support LibreSSL (via libtls)
+- native SBC and mSBC encoder and decoder
 
 
 version 3.4:
-- 
2.15.1

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


Re: [FFmpeg-devel] [PATCH 6/8] sbcenc: add MMX optimizations

2017-12-17 Thread Aurelien Jacobs
On Mon, Dec 18, 2017 at 12:21:00AM +0100, Carl Eugen Hoyos wrote:
> 2017-12-17 22:47 GMT+01:00 Aurelien Jacobs <au...@gnuage.org>:
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> 
> Very rough numbers are useful in the commit message.

Here you go.>From 2227f8d8302fe37da00f34efacdf6b4941220330 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sun, 17 Dec 2017 20:07:33 +0100
Subject: [PATCH 6/8] sbcenc: add MMX optimizations

This was originally based on libsbc, and was fully integrated into ffmpeg.

Rough speed test:
C version:speed= 592x
MMX version:  speed= 785x
---
 libavcodec/sbcdsp.c  |   3 +
 libavcodec/sbcdsp.h  |   2 +
 libavcodec/x86/Makefile  |   2 +
 libavcodec/x86/sbcdsp.asm| 284 +++
 libavcodec/x86/sbcdsp_init.c |  51 
 5 files changed, 342 insertions(+)
 create mode 100644 libavcodec/x86/sbcdsp.asm
 create mode 100644 libavcodec/x86/sbcdsp_init.c

diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
index 16faf5ba9b..9bb60cdd5e 100644
--- a/libavcodec/sbcdsp.c
+++ b/libavcodec/sbcdsp.c
@@ -387,4 +387,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
 /* Default implementation for scale factors calculation */
 s->sbc_calc_scalefactors = sbc_calc_scalefactors;
 s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
+
+if (ARCH_X86)
+ff_sbcdsp_init_x86(s);
 }
diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
index 66ed7d324e..127e6a8a11 100644
--- a/libavcodec/sbcdsp.h
+++ b/libavcodec/sbcdsp.h
@@ -80,4 +80,6 @@ struct sbc_dsp_context {
  */
 void ff_sbcdsp_init(SBCDSPContext *s);
 
+void ff_sbcdsp_init_x86(SBCDSPContext *s);
+
 #endif /* AVCODEC_SBCDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a805cd37b4..2350c8bbee 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_DECODER)  += x86/proresdsp_init.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp_init.o
 OBJS-$(CONFIG_RV40_DECODER)+= x86/rv40dsp_init.o
+OBJS-$(CONFIG_SBC_ENCODER) += x86/sbcdsp_init.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= x86/svq1enc_init.o
 OBJS-$(CONFIG_TAK_DECODER) += x86/takdsp_init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)  += x86/mlpdsp_init.o
@@ -172,6 +173,7 @@ X86ASM-OBJS-$(CONFIG_PNG_DECODER)  += x86/pngdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_DECODER)   += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o
+X86ASM-OBJS-$(CONFIG_SBC_ENCODER)  += x86/sbcdsp.o
 X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER) += x86/svq1enc.o
 X86ASM-OBJS-$(CONFIG_TAK_DECODER)  += x86/takdsp.o
 X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
diff --git a/libavcodec/x86/sbcdsp.asm b/libavcodec/x86/sbcdsp.asm
new file mode 100644
index 00..00b48a821b
--- /dev/null
+++ b/libavcodec/x86/sbcdsp.asm
@@ -0,0 +1,284 @@
+;**
+;* SIMD optimized SBC encoder DSP functions
+;*
+;* Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+;* Copyright (C) 2008-2010  Nokia Corporation
+;* Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+;* Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+;* Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+;*
+;* 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
+;**
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+scale_mask: times 2 dd 0x8000; 1 << (SBC_PROTO_FIXED_SCALE - 1)
+
+SECTION .text
+
+;***
+;void ff_sbc_analyze_4(const int16_t *in, int32_t *out, const int16_t *consts);
+;***
+INIT_MMX mmx
+cglobal sbc_analyze_4, 3, 3, 4, in, out, consts
+movq  m0, [inq]
+movq  m1, [inq+8]
+pmaddwd   m0, [constsq]
+pmaddwd

Re: [FFmpeg-devel] [PATCH 3/8] sbc: add raw demuxer for SBC

2017-12-17 Thread Aurelien Jacobs
On Mon, Dec 18, 2017 at 12:19:06AM +0100, Carl Eugen Hoyos wrote:
> 2017-12-17 22:47 GMT+01:00 Aurelien Jacobs <au...@gnuage.org>:
> 
> > +#if CONFIG_SBC_DEMUXER
> > +AVInputFormat ff_sbc_demuxer = {
> > +.name   = "sbc",
> > +.long_name  = NULL_IF_CONFIG_SMALL("raw SBC (low-complexity 
> > subband codec)"),
> > +.extensions = "sbc",
> > +.raw_codec_id   = AV_CODEC_ID_SBC,
> > +.read_header= ff_raw_audio_read_header,
> > +.read_packet= ff_raw_read_partial_packet,
> > +.flags  = AVFMT_GENERIC_INDEX,
> > +};
> > +#endif
> > +
> > +#if CONFIG_MSBC_DEMUXER
> > +AVInputFormat ff_msbc_demuxer = {
> > +.name   = "msbc",
> > +.long_name  = NULL_IF_CONFIG_SMALL("raw mSBC (wideband speech mono 
> > SBC)"),
> > +.extensions = "msbc",
> > +.raw_codec_id   = AV_CODEC_ID_MSBC,
> > +.read_header= ff_raw_audio_read_header,
> > +.read_packet= ff_raw_read_partial_packet,
> > +.flags  = AVFMT_GENERIC_INDEX,
> > +};
> 
> If auto-detection is impossible, this could be moved into
> libavformat/rawdec.c.

I'm not really fond of this, but OK.

> > +#endif
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index 84e49208b8..860fbc30c9 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -336,6 +336,7 @@ static int set_codec_from_probe_data(AVFormatContext 
> > *s, AVStream *st,
> >  { "mjpeg_2000",AV_CODEC_ID_JPEG2000,   AVMEDIA_TYPE_VIDEO },
> >  { "mp3",   AV_CODEC_ID_MP3,AVMEDIA_TYPE_AUDIO },
> >  { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
> 
> > +{ "sbc",   AV_CODEC_ID_SBC,AVMEDIA_TYPE_AUDIO },
> 
> I believe this line should not be added.

Indeed, this is not needed anymore.

Here is an updated patch.>From a0613dfc9df64b8d8c71af48bb5c6fdd8bf8c212 Mon Sep 17 00:00:00 2001
From: Aurelien Jacobs <au...@gnuage.org>
Date: Sun, 17 Dec 2017 20:23:25 +0100
Subject: [PATCH 3/8] sbc: add raw demuxer for SBC

---
 doc/general.texi |  1 +
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  2 ++
 libavformat/rawdec.c | 24 
 4 files changed, 29 insertions(+)

diff --git a/doc/general.texi b/doc/general.texi
index ed137f999f..65aee47f2a 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,6 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
+@item raw SBC   @tab   @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..88d2cbd2b3 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -447,6 +447,8 @@ OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
+OBJS-$(CONFIG_SBC_DEMUXER)   += rawdec.o
+OBJS-$(CONFIG_MSBC_DEMUXER)  += rawdec.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..a6b72715bd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,6 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
+REGISTER_DEMUXER (MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -277,6 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
+REGISTER_DEMUXER (SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index e926549a60..d94f4972cb 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -191,3 +191,27 @@ static int mjpeg_probe(AVProbeData *p)
 
 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg, "raw MJPEG video", mjp

[FFmpeg-devel] [PATCH] aptx: add codec cap SMALL_LAST_FRAME and INIT_THREADSAFE as appropriate

2017-12-17 Thread Aurelien Jacobs
---
 libavcodec/aptx.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index d09ce8f838..a35d2861c1 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -836,6 +836,7 @@ AVCodec ff_aptx_decoder = {
 .decode= aptx_decode_frame,
 .close = aptx_close,
 .capabilities  = AV_CODEC_CAP_DR1,
+.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
 .channel_layouts   = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
 .sample_fmts   = (const enum AVSampleFormat[]) { 
AV_SAMPLE_FMT_S32P,
  
AV_SAMPLE_FMT_NONE },
@@ -852,6 +853,8 @@ AVCodec ff_aptx_encoder = {
 .init  = aptx_init,
 .encode2   = aptx_encode_frame,
 .close = aptx_close,
+.capabilities  = AV_CODEC_CAP_SMALL_LAST_FRAME,
+.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
 .channel_layouts   = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
 .sample_fmts   = (const enum AVSampleFormat[]) { 
AV_SAMPLE_FMT_S32P,
  
AV_SAMPLE_FMT_NONE },
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 8/8] Changelog: list the new SBC features

2017-12-17 Thread Aurelien Jacobs
---
 Changelog | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Changelog b/Changelog
index ee48876128..8eebcd810c 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,8 @@ version :
 - video setrange filter
 - nsp demuxer
 - support LibreSSL (via libtls)
+- native SBC and mSBC encoder and decoder
+- Raw SBC and mSBC muxer and demuxer
 
 
 version 3.4:
-- 
2.15.1

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


[FFmpeg-devel] [PATCH 7/8] sbcenc: add armv6 and neon asm optimizations

2017-12-17 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 libavcodec/arm/Makefile  |   3 +
 libavcodec/arm/sbcdsp_armv6.S| 245 ++
 libavcodec/arm/sbcdsp_init_arm.c | 105 ++
 libavcodec/arm/sbcdsp_neon.S | 714 +++
 libavcodec/sbcdsp.c  |   2 +
 libavcodec/sbcdsp.h  |   1 +
 6 files changed, 1070 insertions(+)
 create mode 100644 libavcodec/arm/sbcdsp_armv6.S
 create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
 create mode 100644 libavcodec/arm/sbcdsp_neon.S

diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index 1eeac5449e..fd2401f4e5 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -42,6 +42,7 @@ OBJS-$(CONFIG_DCA_DECODER) += 
arm/synth_filter_init_arm.o
 OBJS-$(CONFIG_HEVC_DECODER)+= arm/hevcdsp_init_arm.o
 OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_init_arm.o
 OBJS-$(CONFIG_RV40_DECODER)+= arm/rv40dsp_init_arm.o
+OBJS-$(CONFIG_SBC_ENCODER) += arm/sbcdsp_init_arm.o
 OBJS-$(CONFIG_VORBIS_DECODER)  += arm/vorbisdsp_init_arm.o
 OBJS-$(CONFIG_VP6_DECODER) += arm/vp6dsp_init_arm.o
 OBJS-$(CONFIG_VP9_DECODER) += arm/vp9dsp_init_10bpp_arm.o   \
@@ -81,6 +82,7 @@ ARMV6-OBJS-$(CONFIG_VP8DSP)+= arm/vp8_armv6.o 
  \
 
 # decoders/encoders
 ARMV6-OBJS-$(CONFIG_MLP_DECODER)   += arm/mlpdsp_armv6.o
+ARMV6-OBJS-$(CONFIG_SBC_ENCODER)   += arm/sbcdsp_armv6.o
 
 
 # VFP optimizations
@@ -140,6 +142,7 @@ NEON-OBJS-$(CONFIG_HEVC_DECODER)   += 
arm/hevcdsp_init_neon.o   \
 NEON-OBJS-$(CONFIG_RV30_DECODER)   += arm/rv34dsp_neon.o
 NEON-OBJS-$(CONFIG_RV40_DECODER)   += arm/rv34dsp_neon.o\
   arm/rv40dsp_neon.o
+NEON-OBJS-$(CONFIG_SBC_ENCODER)+= arm/sbcdsp_neon.o
 NEON-OBJS-$(CONFIG_VORBIS_DECODER) += arm/vorbisdsp_neon.o
 NEON-OBJS-$(CONFIG_VP6_DECODER)+= arm/vp6dsp_neon.o
 NEON-OBJS-$(CONFIG_VP9_DECODER)+= arm/vp9itxfm_16bpp_neon.o \
diff --git a/libavcodec/arm/sbcdsp_armv6.S b/libavcodec/arm/sbcdsp_armv6.S
new file mode 100644
index 00..f1ff845798
--- /dev/null
+++ b/libavcodec/arm/sbcdsp_armv6.S
@@ -0,0 +1,245 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 ARMv6 optimizations. The instructions are scheduled for ARM11 pipeline.
+ */
+
+#include "libavutil/arm/asm.S"
+
+function ff_sbc_analyze_4_armv6, export=1
+@ r0 = in, r1 = out, r2 = consts
+push{r1, r3-r7, lr}
+push{r8-r12, r14}
+ldrdr4,  r5,  [r0, #0]
+ldrdr6,  r7,  [r2, #0]
+ldrdr8,  r9,  [r0, #16]
+ldrdr10, r11, [r2, #16]
+mov r14, #0x8000
+smlad   r3,  r4,  r6,  r14
+smlad   r12, r5,  r7,  r14
+ldrdr4,  r5,  [r0, #32]
+ldrdr6,  r7,  [r2, #32]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #48]
+ldrdr10, r11, [r2, #48]
+smlad   r3,  r4,  r6,  r3
+smlad   r12, r5,  r7,  r12
+ldrdr4,  r5,  [r0, #64]
+ldrdr6,  r7,  [r2, #64]
+smlad   r3,  r8,  r10, r3
+smlad   r12, r9,  r11, r12
+ldrdr8,  r9,  [r0, #8]
+ldrdr10, r11, [r2, #8]
+smlad   r3,  r4,  r6,  r3@ t1[0] is done
+smlad   r12, r5,  r7,  r12   @ t1[1] is done
+ldrdr4,  r5,  [r0, #24]
+ldrdr6,  r7,  [r2, #24]
+pkhtb   r3,  r12, r3, asr #16@ comb

[FFmpeg-devel] [PATCH 6/8] sbcenc: add MMX optimizations

2017-12-17 Thread Aurelien Jacobs
This was originally based on libsbc, and was fully integrated into ffmpeg.
---
 libavcodec/sbcdsp.c  |   3 +
 libavcodec/sbcdsp.h  |   2 +
 libavcodec/x86/Makefile  |   2 +
 libavcodec/x86/sbcdsp.asm| 284 +++
 libavcodec/x86/sbcdsp_init.c |  51 
 5 files changed, 342 insertions(+)
 create mode 100644 libavcodec/x86/sbcdsp.asm
 create mode 100644 libavcodec/x86/sbcdsp_init.c

diff --git a/libavcodec/sbcdsp.c b/libavcodec/sbcdsp.c
index 16faf5ba9b..9bb60cdd5e 100644
--- a/libavcodec/sbcdsp.c
+++ b/libavcodec/sbcdsp.c
@@ -387,4 +387,7 @@ av_cold void ff_sbcdsp_init(SBCDSPContext *s)
 /* Default implementation for scale factors calculation */
 s->sbc_calc_scalefactors = sbc_calc_scalefactors;
 s->sbc_calc_scalefactors_j = sbc_calc_scalefactors_j;
+
+if (ARCH_X86)
+ff_sbcdsp_init_x86(s);
 }
diff --git a/libavcodec/sbcdsp.h b/libavcodec/sbcdsp.h
index 66ed7d324e..127e6a8a11 100644
--- a/libavcodec/sbcdsp.h
+++ b/libavcodec/sbcdsp.h
@@ -80,4 +80,6 @@ struct sbc_dsp_context {
  */
 void ff_sbcdsp_init(SBCDSPContext *s);
 
+void ff_sbcdsp_init_x86(SBCDSPContext *s);
+
 #endif /* AVCODEC_SBCDSP_H */
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index a805cd37b4..2350c8bbee 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -63,6 +63,7 @@ OBJS-$(CONFIG_PNG_DECODER) += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_DECODER)  += x86/proresdsp_init.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp_init.o
 OBJS-$(CONFIG_RV40_DECODER)+= x86/rv40dsp_init.o
+OBJS-$(CONFIG_SBC_ENCODER) += x86/sbcdsp_init.o
 OBJS-$(CONFIG_SVQ1_ENCODER)+= x86/svq1enc_init.o
 OBJS-$(CONFIG_TAK_DECODER) += x86/takdsp_init.o
 OBJS-$(CONFIG_TRUEHD_DECODER)  += x86/mlpdsp_init.o
@@ -172,6 +173,7 @@ X86ASM-OBJS-$(CONFIG_PNG_DECODER)  += x86/pngdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_DECODER)   += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o
 X86ASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv40dsp.o
+X86ASM-OBJS-$(CONFIG_SBC_ENCODER)  += x86/sbcdsp.o
 X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER) += x86/svq1enc.o
 X86ASM-OBJS-$(CONFIG_TAK_DECODER)  += x86/takdsp.o
 X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
diff --git a/libavcodec/x86/sbcdsp.asm b/libavcodec/x86/sbcdsp.asm
new file mode 100644
index 00..00b48a821b
--- /dev/null
+++ b/libavcodec/x86/sbcdsp.asm
@@ -0,0 +1,284 @@
+;**
+;* SIMD optimized SBC encoder DSP functions
+;*
+;* Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+;* Copyright (C) 2008-2010  Nokia Corporation
+;* Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+;* Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+;* Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+;*
+;* 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
+;**
+
+%include "libavutil/x86/x86util.asm"
+
+SECTION_RODATA
+
+scale_mask: times 2 dd 0x8000; 1 << (SBC_PROTO_FIXED_SCALE - 1)
+
+SECTION .text
+
+;***
+;void ff_sbc_analyze_4(const int16_t *in, int32_t *out, const int16_t *consts);
+;***
+INIT_MMX mmx
+cglobal sbc_analyze_4, 3, 3, 4, in, out, consts
+movq  m0, [inq]
+movq  m1, [inq+8]
+pmaddwd   m0, [constsq]
+pmaddwd   m1, [constsq+8]
+paddd m0, [scale_mask]
+paddd m1, [scale_mask]
+
+movq  m2, [inq+16]
+movq  m3, [inq+24]
+pmaddwd   m2, [constsq+16]
+pmaddwd   m3, [constsq+24]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+32]
+movq  m3, [inq+40]
+pmaddwd   m2, [constsq+32]
+pmaddwd   m3, [constsq+40]
+paddd m0, m2
+paddd m1, m3
+
+movq  m2, [inq+48]
+movq  m3, [inq+56]
+pmaddwd   m2, [constsq+48]
+pmaddwd   

[FFmpeg-devel] [PATCH 1/8] sbc: implement SBC decoder (low-complexity subband codec)

2017-12-17 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   |   2 +
 libavcodec/avcodec.h |   2 +
 libavcodec/codec_desc.c  |  14 ++
 libavcodec/sbc.c | 316 
 libavcodec/sbc.h | 118 
 libavcodec/sbcdec.c  | 464 +++
 libavcodec/sbcdec_data.c | 127 +
 libavcodec/sbcdec_data.h |  44 +
 10 files changed, 1091 insertions(+)
 create mode 100644 libavcodec/sbc.c
 create mode 100644 libavcodec/sbc.h
 create mode 100644 libavcodec/sbcdec.c
 create mode 100644 libavcodec/sbcdec_data.c
 create mode 100644 libavcodec/sbcdec_data.h

diff --git a/doc/general.texi b/doc/general.texi
index 26919c9287..ed137f999f 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1102,6 +1102,8 @@ 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
+@tab Used in Bluetooth A2DP
 @item Shorten@tab @tab  X
 @item Sierra VMD audio   @tab @tab  X
 @tab Used in Sierra VMD files.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ca72138c02..c46d102227 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -581,6 +581,8 @@ OBJS-$(CONFIG_SUBVIEWER_DECODER)   += subviewerdec.o 
ass.o
 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_MSBC_DECODER)+= sbcdec.o sbcdec_data.o sbc.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 ed1e7ab06e..9e2480d2d4 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -379,6 +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 (NELLYMOSER,nellymoser);
 REGISTER_DECODER(ON2AVC,on2avc);
 REGISTER_ENCDEC (OPUS,  opus);
@@ -392,6 +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 (SONIC, sonic);
 REGISTER_ENCODER(SONIC_LS,  sonic_ls);
 REGISTER_DECODER(TAK,   tak);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ce089b7c4a..5b7ec8541d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -634,6 +634,8 @@ enum AVCodecID {
 AV_CODEC_ID_ATRAC3PAL,
 AV_CODEC_ID_DOLBY_E,
 AV_CODEC_ID_APTX,
+AV_CODEC_ID_SBC,
+AV_CODEC_ID_MSBC,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index c3688de1d6..a69897d379 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -2866,6 +2866,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("aptX (Audio Processing Technology 
for Bluetooth)"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_SBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband 
codec)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
+{
+.id= AV_CODEC_ID_MSBC,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("mSBC (wideband speech mono SBC)"),
+.props = AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/sbc.c b/libavcodec/sbc.c
new file mode 100644
index 00..99d02cc56a
--- /dev/null
+++ b/libavcodec/sbc.c
@@ -0,0 +1,316 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2008  B

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

2017-12-17 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  | 390 +
 libavcodec/sbcdsp.h  |  83 +
 libavcodec/sbcdsp_data.c | 329 +++
 libavcodec/sbcdsp_data.h |  55 ++
 libavcodec/sbcenc.c  | 440 +++
 8 files changed, 1302 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..16faf5ba9b
--- /dev/null
+++ b/libavcodec/sbcdsp.c
@@ -0,0 +1,390 @@
+/*
+ * Bluetooth low-complexity, subband codec (SBC)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ * Copyright (C) 2012-2013  Intel Corporation
+ * Copyright (C) 2008-2010  Nokia Corporation
+ * Copyright (C) 2004-2010  Marcel Holtmann <mar...@holtmann.org>
+ * Copyright (C) 2004-2005  Henryk Ploetz <hen...@ploetzli.ch>
+ * Copyright (C) 2005-2006  Brad Midgley <bmidg...@xmission.com>
+ *
+ * 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 tabl

[FFmpeg-devel] [PATCH 2/8] sbc: add parser for SBC

2017-12-17 Thread Aurelien Jacobs
---
 libavcodec/Makefile |   1 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/sbc_parser.c | 124 
 3 files changed, 126 insertions(+)
 create mode 100644 libavcodec/sbc_parser.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c46d102227..58c8c6e499 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1012,6 +1012,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_SBC_PARSER)  += sbc_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  \
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 9e2480d2d4..3e3b37f638 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -653,6 +653,7 @@ static void register_all(void)
 REGISTER_PARSER(PNM,pnm);
 REGISTER_PARSER(RV30,   rv30);
 REGISTER_PARSER(RV40,   rv40);
+REGISTER_PARSER(SBC,sbc);
 REGISTER_PARSER(SIPR,   sipr);
 REGISTER_PARSER(TAK,tak);
 REGISTER_PARSER(VC1,vc1);
diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
new file mode 100644
index 00..032f72cf2b
--- /dev/null
+++ b/libavcodec/sbc_parser.c
@@ -0,0 +1,124 @@
+/*
+ * SBC parser
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "sbc.h"
+#include "parser.h"
+
+typedef struct SBCParseContext {
+ParseContext pc;
+uint8_t header[3];
+int header_size;
+int buffered_size;
+} SBCParseContext;
+
+static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
+const uint8_t *data, size_t len)
+{
+static const int sample_rates[4] = { 16000, 32000, 44100, 48000 };
+int sr, blocks, mode, subbands, bitpool, channels, joint;
+int length;
+
+if (len < 3)
+return -1;
+
+if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
+avctx->channels = 1;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = 16000;
+avctx->frame_size = 120;
+s->duration = avctx->frame_size;
+return 57;
+}
+
+if (data[0] != SBC_SYNCWORD)
+return -2;
+
+sr   =   (data[1] >> 6) & 0x03;
+blocks   = (((data[1] >> 4) & 0x03) + 1) << 2;
+mode =   (data[1] >> 2) & 0x03;
+subbands = (((data[1] >> 0) & 0x01) + 1) << 2;
+bitpool  = data[2];
+
+channels = mode == SBC_MODE_MONO ? 1 : 2;
+joint= mode == SBC_MODE_JOINT_STEREO;
+
+length = 4 + (subbands * channels) / 2;
+if (channels == 1 || mode == SBC_MODE_DUAL_CHANNEL)
+length += ((channels * blocks * bitpool) + 7) / 8;
+else
+length += (((joint ? subbands : 0) + blocks * bitpool) + 7) / 8;
+
+avctx->channels = channels;
+avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+avctx->sample_rate = sample_rates[sr];
+avctx->frame_size = subbands * blocks;
+s->duration = avctx->frame_size;
+return length;
+}
+
+static int sbc_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+ const uint8_t **poutbuf, int *poutbuf_size,
+ const uint8_t *buf, int buf_size)
+{
+SBCParseContext *pc = s->priv_data;
+int next;
+
+if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+next = buf_size;
+} else {
+if (pc->header_size) {
+memcpy(pc->header + pc->header_size, buf,
+   sizeof(pc->header) - pc->header_size);
+next = sbc_parse_header(s, avctx, pc->header, sizeof(pc->header))
+ - pc->buffered_size;
+pc->header_size = 0;
+} else {
+next = sbc_parse_header(s, avctx, buf, buf_siz

[FFmpeg-devel] [PATCH 3/8] sbc: add raw demuxer for SBC

2017-12-17 Thread Aurelien Jacobs
---
 doc/general.texi |  1 +
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  2 ++
 libavformat/sbcdec.c | 47 +++
 libavformat/utils.c  |  1 +
 5 files changed, 53 insertions(+)
 create mode 100644 libavformat/sbcdec.c

diff --git a/doc/general.texi b/doc/general.texi
index ed137f999f..65aee47f2a 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,6 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
+@item raw SBC   @tab   @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index cb70eac920..6270c28a8a 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -447,6 +447,8 @@ OBJS-$(CONFIG_S337M_DEMUXER) += s337m.o spdif.o
 OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
+OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
+OBJS-$(CONFIG_MSBC_DEMUXER)  += sbcdec.o rawdec.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6a9b9883c9..a6b72715bd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,6 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
+REGISTER_DEMUXER (MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -277,6 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
+REGISTER_DEMUXER (SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/sbcdec.c b/libavformat/sbcdec.c
new file mode 100644
index 00..a04a7c4328
--- /dev/null
+++ b/libavformat/sbcdec.c
@@ -0,0 +1,47 @@
+/*
+ * RAW SBC demuxer
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rawdec.h"
+
+#if CONFIG_SBC_DEMUXER
+AVInputFormat ff_sbc_demuxer = {
+.name   = "sbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw SBC (low-complexity subband 
codec)"),
+.extensions = "sbc",
+.raw_codec_id   = AV_CODEC_ID_SBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
+#endif
+
+#if CONFIG_MSBC_DEMUXER
+AVInputFormat ff_msbc_demuxer = {
+.name   = "msbc",
+.long_name  = NULL_IF_CONFIG_SMALL("raw mSBC (wideband speech mono 
SBC)"),
+.extensions = "msbc",
+.raw_codec_id   = AV_CODEC_ID_MSBC,
+.read_header= ff_raw_audio_read_header,
+.read_packet= ff_raw_read_partial_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+};
+#endif
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 84e49208b8..860fbc30c9 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -336,6 +336,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, 
AVStream *st,
 { "mjpeg_2000",AV_CODEC_ID_JPEG2000,   AVMEDIA_TYPE_VIDEO },
 { "mp3",   AV_CODEC_ID_MP3,AVMEDIA_TYPE_AUDIO },
 { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
+{ "sbc",   AV_CODEC_ID_SBC,AVMEDIA_TYPE_AUDIO },
 { "truehd",AV_CO

[FFmpeg-devel] [PATCH 5/8] sbc: add raw muxer for SBC

2017-12-17 Thread Aurelien Jacobs
---
 doc/general.texi |  2 +-
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  4 ++--
 libavformat/rawenc.c | 28 
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/general.texi b/doc/general.texi
index e5669b0e93..560465a4b8 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -466,7 +466,7 @@ library:
 @item raw NULL  @tab X @tab
 @item raw video @tab X @tab X
 @item raw id RoQ@tab X @tab
-@item raw SBC   @tab   @tab X
+@item raw SBC   @tab X @tab X
 @item raw Shorten   @tab   @tab X
 @item raw TAK   @tab   @tab X
 @item raw TrueHD@tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6270c28a8a..689fc6b23f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -448,7 +448,9 @@ OBJS-$(CONFIG_SAMI_DEMUXER)  += samidec.o 
subtitles.o
 OBJS-$(CONFIG_SAP_DEMUXER)   += sapdec.o
 OBJS-$(CONFIG_SAP_MUXER) += sapenc.o
 OBJS-$(CONFIG_SBC_DEMUXER)   += sbcdec.o rawdec.o
+OBJS-$(CONFIG_SBC_MUXER) += rawenc.o
 OBJS-$(CONFIG_MSBC_DEMUXER)  += sbcdec.o rawdec.o
+OBJS-$(CONFIG_MSBC_MUXER)+= rawenc.o
 OBJS-$(CONFIG_SBG_DEMUXER)   += sbgdec.o
 OBJS-$(CONFIG_SCC_DEMUXER)   += sccdec.o subtitles.o
 OBJS-$(CONFIG_SCC_MUXER) += sccenc.o subtitles.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index a6b72715bd..eb1d17d38c 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -211,7 +211,7 @@ static void register_all(void)
 REGISTER_MUXDEMUX(MPJPEG,   mpjpeg);
 REGISTER_DEMUXER (MPL2, mpl2);
 REGISTER_DEMUXER (MPSUB,mpsub);
-REGISTER_DEMUXER (MSBC, msbc);
+REGISTER_MUXDEMUX(MSBC, msbc);
 REGISTER_DEMUXER (MSF,  msf);
 REGISTER_DEMUXER (MSNWC_TCP,msnwc_tcp);
 REGISTER_DEMUXER (MTAF, mtaf);
@@ -278,7 +278,7 @@ static void register_all(void)
 REGISTER_DEMUXER (S337M,s337m);
 REGISTER_DEMUXER (SAMI, sami);
 REGISTER_MUXDEMUX(SAP,  sap);
-REGISTER_DEMUXER (SBC,  sbc);
+REGISTER_MUXDEMUX(SBC,  sbc);
 REGISTER_DEMUXER (SBG,  sbg);
 REGISTER_MUXDEMUX(SCC,  scc);
 REGISTER_DEMUXER (SDP,  sdp);
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index aa3ef76fbf..e27b280014 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -426,6 +426,34 @@ AVOutputFormat ff_rawvideo_muxer = {
 };
 #endif
 
+#if CONFIG_SBC_MUXER
+AVOutputFormat ff_sbc_muxer = {
+.name  = "sbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
+.mime_type = "audio/x-sbc",
+.extensions= "sbc",
+.audio_codec   = AV_CODEC_ID_SBC,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
+#if CONFIG_MSBC_MUXER
+AVOutputFormat ff_msbc_muxer = {
+.name  = "msbc",
+.long_name = NULL_IF_CONFIG_SMALL("raw mSBC"),
+.mime_type = "audio/x-msbc",
+.extensions= "msbc",
+.audio_codec   = AV_CODEC_ID_MSBC,
+.video_codec   = AV_CODEC_ID_NONE,
+.write_header  = force_one_stream,
+.write_packet  = ff_raw_write_packet,
+.flags = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_TRUEHD_MUXER
 AVOutputFormat ff_truehd_muxer = {
 .name  = "truehd",
-- 
2.15.1

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


Re: [FFmpeg-devel] [PATCH 1/3] sbc: implement SBC codec (low-complexity subband codec)

2017-12-17 Thread Aurelien Jacobs
On Mon, Nov 06, 2017 at 12:53:38PM -0300, James Almer wrote:
> On 11/5/2017 8:35 PM, Aurelien Jacobs wrote:
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> >  doc/general.texi |   2 +
> >  libavcodec/Makefile  |   4 +
> >  libavcodec/allcodecs.c   |   2 +
> >  libavcodec/arm/Makefile  |   3 +
> >  libavcodec/arm/sbcdsp_armv6.S| 245 ++
> >  libavcodec/arm/sbcdsp_init_arm.c | 105 ++
> >  libavcodec/arm/sbcdsp_neon.S | 714 
> > +++
> >  libavcodec/avcodec.h |   2 +
> >  libavcodec/codec_desc.c  |  12 +
> >  libavcodec/sbc.c | 316 +
> >  libavcodec/sbc.h | 121 +++
> >  libavcodec/sbcdec.c  | 469 +
> >  libavcodec/sbcdec_data.c | 127 +++
> >  libavcodec/sbcdec_data.h |  44 +++
> >  libavcodec/sbcdsp.c  | 569 +++
> >  libavcodec/sbcdsp.h  |  86 +
> >  libavcodec/sbcdsp_data.c | 335 ++
> >  libavcodec/sbcdsp_data.h |  57 
> >  libavcodec/sbcenc.c  | 461 +
> >  libavcodec/x86/Makefile  |   2 +
> >  libavcodec/x86/sbcdsp.asm| 290 
> >  libavcodec/x86/sbcdsp_init.c |  51 +++
> >  22 files changed, 4017 insertions(+)
> >  create mode 100644 libavcodec/arm/sbcdsp_armv6.S
> >  create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
> >  create mode 100644 libavcodec/arm/sbcdsp_neon.S
> >  create mode 100644 libavcodec/sbc.c
> >  create mode 100644 libavcodec/sbc.h
> >  create mode 100644 libavcodec/sbcdec.c
> >  create mode 100644 libavcodec/sbcdec_data.c
> >  create mode 100644 libavcodec/sbcdec_data.h
> >  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
> >  create mode 100644 libavcodec/x86/sbcdsp.asm
> >  create mode 100644 libavcodec/x86/sbcdsp_init.c
> 
> This needs to be split into at least four patches.
> One to add the decoder (plus codec ID, descriptor and such things), one
> to add the encoder (and the dsp framework), one to add the x86 assembly
> optimizations for the encoder, and one for the arm optimizations.

OK. New patchset is split this way.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/3] sbc: implement SBC codec (low-complexity subband codec)

2017-12-17 Thread Aurelien Jacobs
On Mon, Nov 06, 2017 at 04:40:56AM +, Rostislav Pehlivanov wrote:
> On 5 November 2017 at 23:35, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> >  doc/general.texi |   2 +
> >  libavcodec/Makefile  |   4 +
> >  libavcodec/allcodecs.c   |   2 +
> >  libavcodec/arm/Makefile  |   3 +
> >  libavcodec/arm/sbcdsp_armv6.S| 245 ++
> >  libavcodec/arm/sbcdsp_init_arm.c | 105 ++
> >  libavcodec/arm/sbcdsp_neon.S | 714 ++
> > +
> >  libavcodec/avcodec.h |   2 +
> >  libavcodec/codec_desc.c  |  12 +
> >  libavcodec/sbc.c | 316 +
> >  libavcodec/sbc.h | 121 +++
> >  libavcodec/sbcdec.c  | 469 +
> >  libavcodec/sbcdec_data.c | 127 +++
> >  libavcodec/sbcdec_data.h |  44 +++
> >  libavcodec/sbcdsp.c  | 569 +++
> >  libavcodec/sbcdsp.h  |  86 +
> >  libavcodec/sbcdsp_data.c | 335 ++
> >  libavcodec/sbcdsp_data.h |  57 
> >  libavcodec/sbcenc.c  | 461 +
> >  libavcodec/x86/Makefile  |   2 +
> >  libavcodec/x86/sbcdsp.asm| 290 
> >  libavcodec/x86/sbcdsp_init.c |  51 +++
> >  22 files changed, 4017 insertions(+)
> >  create mode 100644 libavcodec/arm/sbcdsp_armv6.S
> >  create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
> >  create mode 100644 libavcodec/arm/sbcdsp_neon.S
> >  create mode 100644 libavcodec/sbc.c
> >  create mode 100644 libavcodec/sbc.h
> >  create mode 100644 libavcodec/sbcdec.c
> >  create mode 100644 libavcodec/sbcdec_data.c
> >  create mode 100644 libavcodec/sbcdec_data.h
> >  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
> >  create mode 100644 libavcodec/x86/sbcdsp.asm
> >  create mode 100644 libavcodec/x86/sbcdsp_init.c
> >
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index c4134424f0..2d541bf64a 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -632,6 +632,8 @@ enum AVCodecID {
> >  AV_CODEC_ID_ATRAC3AL,
> >  AV_CODEC_ID_ATRAC3PAL,
> >  AV_CODEC_ID_DOLBY_E,
> > +AV_CODEC_ID_SBC,
> > +AV_CODEC_ID_MSBC,
> >
> >
> See below.
> 
> 
> >  /* subtitle codecs */
> >  AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID
> > pointing at the start of subtitle codecs.
> > diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> > index 92bf1d2681..8d613507e0 100644
> > --- a/libavcodec/codec_desc.c
> > +++ b/libavcodec/codec_desc.c
> > @@ -2859,6 +2859,18 @@ static const AVCodecDescriptor codec_descriptors[]
> > = {
> >  .long_name = NULL_IF_CONFIG_SMALL("ADPCM MTAF"),
> >  .props = AV_CODEC_PROP_LOSSY,
> >  },
> > +{
> > +.id= AV_CODEC_ID_SBC,
> > +.type  = AVMEDIA_TYPE_AUDIO,
> > +.name  = "sbc",
> > +.long_name = NULL_IF_CONFIG_SMALL("SBC (low-complexity subband
> > codec)"),
> > +},
> > +{
> > +.id= AV_CODEC_ID_MSBC,
> > +.type  = AVMEDIA_TYPE_AUDIO,
> > +.name  = "msbc",
> > +.long_name = NULL_IF_CONFIG_SMALL("mSBC (wideband speech mono
> > SBC)"),
> > +},
> >
> 
> Is there a bitstream difference between the two? I don't think so, so you
> should instead define FF_PROFILE_SBC_WB and use a single codec ID.

SBC support various samplerates while mSBC is limited to 16 kHz.
I think the only way to declare this properly and to get automatic
conversion to 16 kHz when encoding to mSBC is to have 2 separate
codec ID.
So I kept the 2 separate codec ID.

> > diff --git a/libavcodec/sbc.c b/libavcodec/sbc.c
> > new file mode 100644
> > index 00..99d02cc56a
> > --- /dev/null
> > +++ b/libavcodec/sbc.c
> > @@ -0,0 +1,316 @@
> > +/*
> > + * Bluetooth low-complexity, subband codec (SBC)
> > + *
> > + * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
> > + * Copyright (C) 2012-2013  Intel Corporat

Re: [FFmpeg-devel] [PATCH 1/3] sbc: implement SBC codec (low-complexity subband codec)

2017-12-17 Thread Aurelien Jacobs
On Mon, Nov 06, 2017 at 04:22:30AM +0100, Michael Niedermayer wrote:
> Hi 
> 
> On Mon, Nov 06, 2017 at 12:35:18AM +0100, Aurelien Jacobs wrote:
> > This was originally based on libsbc, and was fully integrated into ffmpeg.
> > ---
> >  doc/general.texi |   2 +
> >  libavcodec/Makefile  |   4 +
> >  libavcodec/allcodecs.c   |   2 +
> >  libavcodec/arm/Makefile  |   3 +
> >  libavcodec/arm/sbcdsp_armv6.S| 245 ++
> >  libavcodec/arm/sbcdsp_init_arm.c | 105 ++
> >  libavcodec/arm/sbcdsp_neon.S | 714 
> > +++
> >  libavcodec/avcodec.h |   2 +
> >  libavcodec/codec_desc.c  |  12 +
> >  libavcodec/sbc.c | 316 +
> >  libavcodec/sbc.h | 121 +++
> >  libavcodec/sbcdec.c  | 469 +
> >  libavcodec/sbcdec_data.c | 127 +++
> >  libavcodec/sbcdec_data.h |  44 +++
> >  libavcodec/sbcdsp.c  | 569 +++
> >  libavcodec/sbcdsp.h  |  86 +
> >  libavcodec/sbcdsp_data.c | 335 ++
> >  libavcodec/sbcdsp_data.h |  57 
> >  libavcodec/sbcenc.c  | 461 +
> >  libavcodec/x86/Makefile  |   2 +
> >  libavcodec/x86/sbcdsp.asm| 290 
> >  libavcodec/x86/sbcdsp_init.c |  51 +++
> >  22 files changed, 4017 insertions(+)
> >  create mode 100644 libavcodec/arm/sbcdsp_armv6.S
> >  create mode 100644 libavcodec/arm/sbcdsp_init_arm.c
> >  create mode 100644 libavcodec/arm/sbcdsp_neon.S
> >  create mode 100644 libavcodec/sbc.c
> >  create mode 100644 libavcodec/sbc.h
> >  create mode 100644 libavcodec/sbcdec.c
> >  create mode 100644 libavcodec/sbcdec_data.c
> >  create mode 100644 libavcodec/sbcdec_data.h
> >  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
> >  create mode 100644 libavcodec/x86/sbcdsp.asm
> >  create mode 100644 libavcodec/x86/sbcdsp_init.c
> 
> this seems to fail to build on x86-32

Ooops... Haven't use x86-32 for so long that it didn't even occured to
me to test it.

> libavcodec/x86/sbcdsp_init.o
> src/libavcodec/x86/sbcdsp.asm:251: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:264: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:267: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:269: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:270: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:271: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:273: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:274: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:275: error: invalid operands in non-64-bit mode
> src/libavcodec/x86/sbcdsp.asm:276: error: invalid operands in non-64-bit mode
> STRIP   libavcodec/x86/opus_pvq_search.o

Fixed in upcoming patchset.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] adding bluetooth SBC codec

2017-12-03 Thread Aurelien Jacobs
On Sun, Dec 03, 2017 at 10:57:59AM +, Rostislav Pehlivanov wrote:
> On 5 November 2017 at 23:35, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > Hello everyone,
> >
> > Long time no see !
> >
> > I'm glad to see ffmpeg still strong.
> >
> > I'm curently playing with bluetooth audio (A2DP) and I wanted to
> > use lavc to do the encoding/decoding, so I added some codecs that
> > I need to ffmpeg.
> >
> > Here is the result for the SBC codec.
> >
> > [PATCH 1/3] sbc: implement SBC codec (low-complexity subband codec)
> > [PATCH 2/3] sbc: add parser for SBC
> > [PATCH 3/3] sbc: add raw muxer and demuxer for SBC
> >
> > Note that this is based on libsbc, and that I have a repository with full
> > history of the modifications I applied on top of libsbc:
> >   https://gitlab.com/aurelj/ffmpeg/commits/bluetooth_sbc
> > If anyone would prefer me to submit all the patches with full history
> > on this mailing list, just say so. (I just think the squashed
> > version makes more sense to review)
> >
> > Thanks everyone for all your efforts to keep ffmpeg going.
> >
> 
> 
> Ping, there isn't much to do to this patch, just what was mentioned plus
> some of the stuff you did for the aptx patchset.

Yes, I'm just very busy lately. But I will clean this up it eventually.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] aptx: add raw muxer and demuxer for aptX

2017-11-10 Thread Aurelien Jacobs
---
 doc/general.texi |  1 +
 libavformat/Makefile |  2 ++
 libavformat/allformats.c |  1 +
 libavformat/aptxdec.c| 78 
 libavformat/rawenc.c | 13 
 libavformat/utils.c  |  1 +
 6 files changed, 96 insertions(+)
 create mode 100644 libavformat/aptxdec.c

diff --git a/doc/general.texi b/doc/general.texi
index de4efee913..efd4a92495 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -441,6 +441,7 @@ library:
 @item raw AC-3  @tab X @tab X
 @item raw AMR-NB@tab   @tab X
 @item raw AMR-WB@tab   @tab X
+@item raw aptX  @tab X @tab X
 @item raw Chinese AVS video @tab X @tab X
 @item raw CRI ADX   @tab X @tab X
 @item raw Dirac @tab X @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 146a4656f2..b1e7b193f4 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -94,6 +94,8 @@ OBJS-$(CONFIG_APC_DEMUXER)   += apc.o
 OBJS-$(CONFIG_APE_DEMUXER)   += ape.o apetag.o img2.o
 OBJS-$(CONFIG_APNG_DEMUXER)  += apngdec.o
 OBJS-$(CONFIG_APNG_MUXER)+= apngenc.o
+OBJS-$(CONFIG_APTX_DEMUXER)  += aptxdec.o rawdec.o
+OBJS-$(CONFIG_APTX_MUXER)+= rawenc.o
 OBJS-$(CONFIG_AQTITLE_DEMUXER)   += aqtitledec.o subtitles.o
 OBJS-$(CONFIG_ASF_DEMUXER)   += asfdec_f.o asf.o asfcrypt.o \
 avlanguage.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1896d50e9e..9213af9301 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -69,6 +69,7 @@ static void register_all(void)
 REGISTER_DEMUXER (APC,  apc);
 REGISTER_DEMUXER (APE,  ape);
 REGISTER_MUXDEMUX(APNG, apng);
+REGISTER_MUXDEMUX(APTX, aptx);
 REGISTER_DEMUXER (AQTITLE,  aqtitle);
 REGISTER_MUXDEMUX(ASF,  asf);
 REGISTER_DEMUXER (ASF_O,asf_o);
diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
new file mode 100644
index 00..3b8fae1b55
--- /dev/null
+++ b/libavformat/aptxdec.c
@@ -0,0 +1,78 @@
+/*
+ * RAW aptX demuxer
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rawdec.h"
+
+#define APTX_BLOCK_SIZE   4
+#define APTX_PACKET_SIZE  (256*APTX_BLOCK_SIZE)
+
+typedef struct AptXDemuxerContext {
+AVClass *class;
+int sample_rate;
+} AptXDemuxerContext;
+
+static int aptx_read_header(AVFormatContext *s)
+{
+AptXDemuxerContext *s1 = s->priv_data;
+AVStream *st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+st->codecpar->codec_id = AV_CODEC_ID_APTX;
+st->codecpar->format = AV_SAMPLE_FMT_S32P;
+st->codecpar->channels = 2;
+st->codecpar->sample_rate = s1->sample_rate;
+st->codecpar->bits_per_coded_sample = 4;
+st->codecpar->block_align = APTX_BLOCK_SIZE;
+st->codecpar->frame_size = APTX_PACKET_SIZE;
+st->start_time = 0;
+return 0;
+}
+
+static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE);
+}
+
+static const AVOption aptx_options[] = {
+{ "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), 
AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+{ NULL },
+};
+
+static const AVClass aptx_demuxer_class = {
+.class_name = "aptx demuxer",
+.item_name  = av_default_item_name,
+.option = aptx_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
+AVInputFormat ff_aptx_demuxer = {
+.name   = "aptx",
+.long_name  = NULL_IF_CONFIG_SMALL("raw aptX"),
+.extensions = "aptx",
+.priv_data_size = sizeof(AptXDemuxerContext),
+.read_header= aptx_read_header,
+.read_packet= aptx_read_packet,
+.flags  = AVFMT_GENERIC_INDEX,
+.p

Re: [FFmpeg-devel] [PATCH 1/2] aptx: implement the aptX bluetooth codec

2017-11-10 Thread Aurelien Jacobs
On Fri, Nov 10, 2017 at 12:25:12AM +, Rostislav Pehlivanov wrote:
> On 9 November 2017 at 22:48, Aurelien Jacobs <au...@gnuage.org> wrote:
> 
> > On Thu, Nov 09, 2017 at 02:32:44PM +, Rostislav Pehlivanov wrote:
> > > On 9 November 2017 at 13:37, Aurelien Jacobs <au...@gnuage.org> wrote:
> > >
> > > > On Thu, Nov 09, 2017 at 12:52:34AM +, Rostislav Pehlivanov wrote:
> > > > > On 8 November 2017 at 22:41, Aurelien Jacobs <au...@gnuage.org>
> > wrote:
> > > > >
> > > > > > On Wed, Nov 08, 2017 at 06:26:03PM +0100, Michael Niedermayer
> > wrote:
> > > > > > > On Wed, Nov 08, 2017 at 02:06:09PM +0100, Aurelien Jacobs wrote:
> > > > > > > [...]
> > > > > > > > +}
> > > > > > > > +
> > > > > > > > +/*
> > > > > > > > + * Compute the convolution of the signal with the
> > coefficients,
> > > > and
> > > > > > reduce
> > > > > > > > + * to 24 bits by applying the specified right shifting.
> > > > > > > > + */
> > > > > > > > +av_always_inline
> > > > > > > > +static int32_t aptx_qmf_convolution(FilterSignal *signal,
> > > > > > > > +const int32_t
> > > > coeffs[FILTER_TAPS],
> > > > > > > > +int shift)
> > > > > > > > +{
> > > > > > > > +int32_t *sig = >buffer[signal->pos];
> > > > > > > > +int64_t e = 0;
> > > > > > > > +
> > > > > > >
> > > > > > > > +for (int i = 0; i < FILTER_TAPS; i++)
> > > > > > >
> > > > > > > "for (int" is something we avoided as some comilers didnt like
> > it,
> > > > > > > iam not sure if this is still true but there are none in the
> > codebase
> > > > > >
> > > > > > If you insist on this I will of course change it, but hey, we
> > require
> > > > > > a C99 compiler since a long time and we use so many features of C99
> > > > > > that I really don't get why we couldn't use "for (int".
> > > > > > I can't imagine that any relevant C compiler would not support this
> > > > > > nowadays !
> > > > > > What I propose is to get this in as is, and see if anyone encounter
> > > > > > issue with any compiler. If any issue arise, I will of course send
> > a
> > > > > > patch to fix it.
> > > > > >
> > > > > > Here is an updated patch.
> > > > > >
> > > > > >
> > > > > Send another patch because some people are beyond convincing and its
> > > > really
> > > > > pissing me off. Really. In particular maybe those compiler writers at
> > > > > Microsoft who seem to think shipping something that doesn't support
> > such
> > > > a
> > > > > simple yet important feature is important.
> > > > > Or maybe users who don't want to update a 6 year old version of msvc.
> > > > > Or maybe us because we support compiling with msvc at all when its
> > > > clearly
> > > > > _not_ a C compiler and this project is written in C.
> > > >
> > > > Here you go.
> > > >
> > > > Just for reference, splitting the déclaration out of the for loop added
> > > > 19 lines in this file, which is a 2.3 % increase of the line count.
> > > > (I'm not sure this file is representative of the rest of the code base)
> > > >
> > > > ___
> > > > ffmpeg-devel mailing list
> > > > ffmpeg-devel@ffmpeg.org
> > > > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > > >
> > > >
> > > Still some issues:
> > >
> > > 1.) You need to set AVCodec->supported_samplerates for the encoder, since
> > > in the raw aptx muxer you always set the samplerate as 44100. Does the
> > > codec/container support other samplerates?
> >
> > The codec is actually samplerate agnostic.
> > It only convert each group of 4 samples to a 16 bit integer.
> > There is no other information than the samples themselves in the
> > encod

[FFmpeg-devel] [PATCH 1/2] aptx: implement the aptX bluetooth codec

2017-11-10 Thread Aurelien Jacobs
The encoder was reverse engineered from binary library and from
EP0398973B1 patent (long expired).
The decoder was simply deduced from the encoder.
---
 doc/general.texi|   2 +
 libavcodec/Makefile |   2 +
 libavcodec/allcodecs.c  |   1 +
 libavcodec/aptx.c   | 860 
 libavcodec/avcodec.h|   1 +
 libavcodec/codec_desc.c |   7 +
 6 files changed, 873 insertions(+)
 create mode 100644 libavcodec/aptx.c

diff --git a/doc/general.texi b/doc/general.texi
index e6ae277d23..de4efee913 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -993,6 +993,8 @@ following image formats are supported:
 @item Amazing Studio PAF Audio @tab @tab  X
 @item Apple lossless audio   @tab  X  @tab  X
 @tab QuickTime fourcc 'alac'
+@item aptX   @tab  X  @tab  X
+@tab Used in Bluetooth A2DP
 @item ATRAC1 @tab @tab  X
 @item ATRAC3 @tab @tab  X
 @item ATRAC3+@tab @tab  X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 45f4db5939..95c843dee7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -188,6 +188,8 @@ OBJS-$(CONFIG_AMV_ENCODER) += mjpegenc.o 
mjpegenc_common.o \
 OBJS-$(CONFIG_ANM_DECODER) += anm.o
 OBJS-$(CONFIG_ANSI_DECODER)+= ansi.o cga_data.o
 OBJS-$(CONFIG_APE_DECODER) += apedec.o
+OBJS-$(CONFIG_APTX_DECODER)+= aptx.o
+OBJS-$(CONFIG_APTX_ENCODER)+= aptx.o
 OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d96e499ba7..463f7ed64e 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -406,6 +406,7 @@ static void register_all(void)
 REGISTER_DECODER(AMRNB, amrnb);
 REGISTER_DECODER(AMRWB, amrwb);
 REGISTER_DECODER(APE,   ape);
+REGISTER_ENCDEC (APTX,  aptx);
 REGISTER_DECODER(ATRAC1,atrac1);
 REGISTER_DECODER(ATRAC3,atrac3);
 REGISTER_DECODER(ATRAC3AL,  atrac3al);
diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
new file mode 100644
index 00..d09ce8f838
--- /dev/null
+++ b/libavcodec/aptx.c
@@ -0,0 +1,860 @@
+/*
+ * Audio Processing Technology codec for Bluetooth (aptX)
+ *
+ * Copyright (C) 2017  Aurelien Jacobs <au...@gnuage.org>
+ *
+ * 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
+ */
+
+#include "libavutil/intreadwrite.h"
+#include "avcodec.h"
+#include "internal.h"
+#include "mathops.h"
+#include "audio_frame_queue.h"
+
+
+enum channels {
+LEFT,
+RIGHT,
+NB_CHANNELS
+};
+
+enum subbands {
+LF,  // Low Frequency (0-5.5 kHz)
+MLF, // Medium-Low Frequency (5.5-11kHz)
+MHF, // Medium-High Frequency (11-16.5kHz)
+HF,  // High Frequency (16.5-22kHz)
+NB_SUBBANDS
+};
+
+#define NB_FILTERS 2
+#define FILTER_TAPS 16
+
+typedef struct {
+int pos;
+int32_t buffer[2*FILTER_TAPS];
+} FilterSignal;
+
+typedef struct {
+FilterSignal outer_filter_signal[NB_FILTERS];
+FilterSignal inner_filter_signal[NB_FILTERS][NB_FILTERS];
+} QMFAnalysis;
+
+typedef struct {
+int32_t quantized_sample;
+int32_t quantized_sample_parity_change;
+int32_t error;
+} Quantize;
+
+typedef struct {
+int32_t quantization_factor;
+int32_t factor_select;
+int32_t reconstructed_difference;
+} InvertQuantize;
+
+typedef struct {
+int32_t prev_sign[2];
+int32_t s_weight[2];
+int32_t d_weight[24];
+int32_t pos;
+int32_t reconstructed_differences[48];
+int32_t previous_reconstructed_sample;
+int32_t predicted_difference;
+int32_t predicted_sample;
+} Prediction;
+
+typedef struct {
+int32_t codeword_history;
+int32_t dither_parity;
+int32_t dither[NB_SUBBANDS];
+
+QMFAnalysis qmf;
+Quantize quantize[NB_SUBBANDS];
+InvertQuantize invert_quantize[NB_SUBBANDS];
+Prediction prediction[NB_SUBBANDS];
+} Channel;
+
+typedef struct {
+int32_t sync_idx;
+Channel channels[NB_CHANNELS];
+AudioF

Re: [FFmpeg-devel] [PATCH] doc/developer: update style guidelines to include for loops with declarations

2017-11-09 Thread Aurelien Jacobs
On Thu, Nov 09, 2017 at 04:56:07PM -0300, James Almer wrote:
> On 11/9/2017 2:46 PM, Clément Bœsch wrote:
> > On Wed, Nov 08, 2017 at 09:26:13PM +, Rostislav Pehlivanov wrote:
> >> Signed-off-by: Rostislav Pehlivanov 
> >> ---
> >>  doc/developer.texi | 3 +++
> >>  1 file changed, 3 insertions(+)
> >>
> >> diff --git a/doc/developer.texi b/doc/developer.texi
> >> index a7b4f1d737..de7d887451 100644
> >> --- a/doc/developer.texi
> >> +++ b/doc/developer.texi
> >> @@ -132,6 +132,9 @@ designated struct initializers (@samp{struct s x = @{ 
> >> .i = 17 @};});
> >>  @item
> >>  compound literals (@samp{x = (struct s) @{ 17, 23 @};}).
> >>  
> >> +@item
> >> +for loops with variable definition (@samp{for (int i = 0; i < 8; i++)});
> >> +
> > 
> > I'm fine with this and would be happy to update all the code I maintain in
> > FFmpeg to follow this pattern. But I have a few questions/reservations:
> > 
> > - what does it imply for mixed statements and declarations?

Nothing at all. It is unrelated to mixed statements and declarations.

> >   If we still do not allow them, how are you going to make the compiler
> >   reject them but not the for (int ... ) form?

By not changing anything at all. That is already what happens right now.

> No way to do that i guess. If we remove the warning, it will never catch
> any kind of mixed declarations and statements anymore.

No need to remove any warning. The -Wdeclaration-after-statement does
not emit warnings regarding for loops with declarations.

> >   Also, allowing this but not the mixed statements and declarations means
> >   this is a style decision and not a technical one anymore.

Allowing limiting the scope of a variable to a loop seems like a
technical decision to me, but I understand that some consider it more
of a style decision.

> > [...]
> > 
> > Overall, I'd enjoy this change being accepted (even along mixed statements
> > and declarations).

Just for the record, I would enjoy it as well.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


  1   2   >