[FFmpeg-cvslog] x86inc: Add some additional cpuflag relations

2017-06-12 Thread Henrik Gramner
ffmpeg | branch: master | Henrik Gramner  | Sat May  6 
12:26:56 2017 +0200| [aad1b6786e73ebbf908c98099a23e4b061678c4b] | committer: 
James Darnley

x86inc: Add some additional cpuflag relations

Simplifies writing assembly code that depends on available instructions.

LZCNT implies SSE2
BMI1 implies AVX+LZCNT
AVX2 implies BMI2

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aad1b6786e73ebbf908c98099a23e4b061678c4b
---

 libavutil/x86/x86inc.asm | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavutil/x86/x86inc.asm b/libavutil/x86/x86inc.asm
index 5aee264f1e..fa826e6d85 100644
--- a/libavutil/x86/x86inc.asm
+++ b/libavutil/x86/x86inc.asm
@@ -788,25 +788,25 @@ BRANCH_INSTR jz, je, jnz, jne, jl, jle, jnl, jnle, jg, 
jge, jng, jnge, ja, jae,
 %assign cpuflags_sse  (1<<4) | cpuflags_mmx2
 %assign cpuflags_sse2 (1<<5) | cpuflags_sse
 %assign cpuflags_sse2slow (1<<6) | cpuflags_sse2
-%assign cpuflags_sse3 (1<<7) | cpuflags_sse2
-%assign cpuflags_ssse3(1<<8) | cpuflags_sse3
-%assign cpuflags_sse4 (1<<9) | cpuflags_ssse3
-%assign cpuflags_sse42(1<<10)| cpuflags_sse4
-%assign cpuflags_avx  (1<<11)| cpuflags_sse42
-%assign cpuflags_xop  (1<<12)| cpuflags_avx
-%assign cpuflags_fma4 (1<<13)| cpuflags_avx
-%assign cpuflags_fma3 (1<<14)| cpuflags_avx
-%assign cpuflags_avx2 (1<<15)| cpuflags_fma3
-
-%assign cpuflags_cache32  (1<<16)
-%assign cpuflags_cache64  (1<<17)
-%assign cpuflags_slowctz  (1<<18)
-%assign cpuflags_lzcnt(1<<19)
-%assign cpuflags_aligned  (1<<20) ; not a cpu feature, but a function variant
-%assign cpuflags_atom (1<<21)
-%assign cpuflags_bmi1 (1<<22)|cpuflags_lzcnt
-%assign cpuflags_bmi2 (1<<23)|cpuflags_bmi1
-%assign cpuflags_aesni(1<<24)|cpuflags_sse42
+%assign cpuflags_lzcnt(1<<7) | cpuflags_sse2
+%assign cpuflags_sse3 (1<<8) | cpuflags_sse2
+%assign cpuflags_ssse3(1<<9) | cpuflags_sse3
+%assign cpuflags_sse4 (1<<10)| cpuflags_ssse3
+%assign cpuflags_sse42(1<<11)| cpuflags_sse4
+%assign cpuflags_aesni(1<<12)| cpuflags_sse42
+%assign cpuflags_avx  (1<<13)| cpuflags_sse42
+%assign cpuflags_xop  (1<<14)| cpuflags_avx
+%assign cpuflags_fma4 (1<<15)| cpuflags_avx
+%assign cpuflags_fma3 (1<<16)| cpuflags_avx
+%assign cpuflags_bmi1 (1<<17)| cpuflags_avx|cpuflags_lzcnt
+%assign cpuflags_bmi2 (1<<18)| cpuflags_bmi1
+%assign cpuflags_avx2 (1<<19)| cpuflags_fma3|cpuflags_bmi2
+
+%assign cpuflags_cache32  (1<<20)
+%assign cpuflags_cache64  (1<<21)
+%assign cpuflags_slowctz  (1<<22)
+%assign cpuflags_aligned  (1<<23) ; not a cpu feature, but a function variant
+%assign cpuflags_atom (1<<24)
 
 ; Returns a boolean value expressing whether or not the specified cpuflag is 
enabled.
 %definecpuflag(x) (cpuflags & (cpuflags_ %+ x)) ^ (cpuflags_ %+ x)) - 
1) >> 31) & 1)

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


[FFmpeg-cvslog] avfilter: add native headphone spatialization filter

2017-06-12 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Wed Jun  7 21:23:14 
2017 +0200| [d4d1fc823f99ab9cf13067fdd31b02c2c7fc4e2b] | committer: Paul B Mahol

avfilter: add native headphone spatialization filter

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d4d1fc823f99ab9cf13067fdd31b02c2c7fc4e2b
---

 Changelog  |   1 +
 doc/filters.texi   |  43 +++
 libavfilter/Makefile   |   1 +
 libavfilter/af_headphone.c | 811 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/version.h  |   2 +-
 6 files changed, 858 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index cf0adc90e4..cd91f63cb3 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ version :
 - surround audio filter
 - sofalizer filter switched to libmysofa
 - Gremlin Digital Video demuxer and decoder
+- headphone audio filter
 
 version 3.3:
 - CrystalHD decoder moved to new decode API
diff --git a/doc/filters.texi b/doc/filters.texi
index 9cc356b4df..023096f4e0 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2789,6 +2789,49 @@ Samples where the target gain does not match between 
channels
 @end table
 @end table
 
+@section headphone
+
+Apply head-related transfer functions (HRTFs) to create virtual
+loudspeakers around the user for binaural listening via headphones.
+The HRIRs are provided via additional streams, for each channel
+one stereo input stream is needed.
+
+The filter accepts the following options:
+
+@table @option
+@item map
+Set mapping of input streams for convolution.
+The argument is a '|'-separated list of channel names in order as they
+are given as additional stream inputs for filter.
+This also specify number of input streams. Number of input streams
+must be not less than number of channels in first stream plus one.
+
+@item gain
+Set gain applied to audio. Value is in dB. Default is 0.
+
+@item type
+Set processing type. Can be @var{time} or @var{freq}. @var{time} is
+processing audio in time domain which is slow.
+@var{freq} is processing audio in frequency domain which is fast.
+Default is @var{freq}.
+
+@item lfe
+Set custom gain for LFE channels. Value is in dB. Default is 0.
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Full example using wav files as coefficients with amovie filters for 7.1 
downmix,
+each amovie filter use stereo file with IR coefficients as input.
+The files give coefficients for each position of virtual loudspeaker:
+@example
+ffmpeg -i input.wav -lavfi-complex 
"amovie=azi_270_ele_0_DFC.wav[sr],amovie=azi_90_ele_0_DFC.wav[sl],amovie=azi_225_ele_0_DFC.wav[br],amovie=azi_135_ele_0_DFC.wav[bl],amovie=azi_0_ele_0_DFC.wav,asplit[fc][lfe],amovie=azi_35_ele_0_DFC.wav[fl],amovie=azi_325_ele_0_DFC.wav[fr],[a:0][fl][fr][fc][lfe][bl][br][sl][sr]headphone=FL|FR|FC|LFE|BL|BR|SL|SR"
+output.wav
+@end example
+@end itemize
+
 @section highpass
 
 Apply a high-pass filter with 3dB point frequency.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index c88dfb3264..04ec9b8b8f 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -92,6 +92,7 @@ OBJS-$(CONFIG_EXTRASTEREO_FILTER)+= 
af_extrastereo.o
 OBJS-$(CONFIG_FIREQUALIZER_FILTER)   += af_firequalizer.o
 OBJS-$(CONFIG_FLANGER_FILTER)+= af_flanger.o 
generate_wave_table.o
 OBJS-$(CONFIG_HDCD_FILTER)   += af_hdcd.o
+OBJS-$(CONFIG_HEADPHONE_FILTER)  += af_headphone.o
 OBJS-$(CONFIG_HIGHPASS_FILTER)   += af_biquads.o
 OBJS-$(CONFIG_JOIN_FILTER)   += af_join.o
 OBJS-$(CONFIG_LADSPA_FILTER) += af_ladspa.o
diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
new file mode 100644
index 00..3dd5a0c396
--- /dev/null
+++ b/libavfilter/af_headphone.c
@@ -0,0 +1,811 @@
+/*
+ * Copyright (C) 2017 Paul B Mahol
+ * Copyright (C) 2013-2015 Andreas Fuchs, Wolfgang Hrauda
+ * 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 
+
+#include "libavutil/audio_fifo.h"
+#include "libavutil/avstring.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/float_dsp.h"
+#include "libavutil/intmath.h"
+#include "libavutil/opt.h"
+#include "libavcodec/avfft.h"
+
+#include "avfilte

[FFmpeg-cvslog] tools: add sofa2wavs

2017-06-12 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Fri Jun  9 13:18:31 
2017 +0200| [1a30bf60be9243830b68e8fe2e20539f08a85926] | committer: Paul B Mahol

tools: add sofa2wavs

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1a30bf60be9243830b68e8fe2e20539f08a85926
---

 Makefile  |  1 +
 tools/Makefile|  1 +
 tools/sofa2wavs.c | 79 +++
 3 files changed, 81 insertions(+)

diff --git a/Makefile b/Makefile
index 685b613a1c..a2df8b9d8d 100644
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,7 @@ target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o 
$(FF_DEP_LIBS)
$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) 
$(LIBFUZZER_PATH)
 
 tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
+tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS)
 tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/target_dec_%_fuzzer$(EXESUF): $(FF_DEP_LIBS)
diff --git a/tools/Makefile b/tools/Makefile
index 3ebd3619ca..3909e7cfdd 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -1,4 +1,5 @@
 TOOLS = qt-faststart trasher uncoded_frame
+TOOLS-$(CONFIG_LIBMYSOFA) += sofa2wavs
 TOOLS-$(CONFIG_ZLIB) += cws2fws
 
 tools/target_dec_%_fuzzer.o: tools/target_dec_fuzzer.c
diff --git a/tools/sofa2wavs.c b/tools/sofa2wavs.c
new file mode 100644
index 00..f85e54f771
--- /dev/null
+++ b/tools/sofa2wavs.c
@@ -0,0 +1,79 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int main(int argc, char **argv)
+{
+struct MYSOFA_HRTF *hrtf;
+int sample_rate;
+int err, i, j;
+
+if (argc < 3) {
+printf("usage: %s input_SOFA_file output_directory\n", argv[0]);
+return 1;
+}
+
+hrtf = mysofa_load(argv[1], &err);
+if (!hrtf || err) {
+printf("invalid input SOFA file: %s\n", argv[1]);
+return 1;
+}
+
+if (hrtf->DataSamplingRate.elements != 1)
+goto fail;
+sample_rate = hrtf->DataSamplingRate.values[0];
+
+err = mkdir(argv[2], 0744);
+if (err)
+goto fail;
+
+err = chdir(argv[2]);
+if (err)
+goto fail;
+
+for (i = 0; i < hrtf->M; i++) {
+FILE *file;
+int bps = 32;
+int blkalign = 8;
+int bytespersec = blkalign * sample_rate;
+char filename[1024];
+int azi = hrtf->SourcePosition.values[i * 3];
+int ele = hrtf->SourcePosition.values[i * 3 + 1];
+int dis = hrtf->SourcePosition.values[i * 3 + 2];
+int size = 8 * hrtf->N;
+int offset = i * 2 * hrtf->N;
+
+snprintf(filename, sizeof(filename), "azi_%d_ele_%d_dis_%d.wav", azi, 
ele, dis);
+file = fopen(filename, "w+");
+fwrite("RIFF", 4, 1, file);
+fwrite("\xFF\xFF\xFF\xFF", 4, 1, file);
+fwrite("WAVE", 4, 1, file);
+fwrite("fmt ", 4, 1, file);
+fwrite("\x10\x00\00\00", 4, 1, file);
+fwrite("\x03\x00", 2, 1, file);
+fwrite("\x02\x00", 2, 1, file);
+fwrite(&sample_rate, 4, 1, file);
+fwrite(&bytespersec, 4, 1, file);
+fwrite(&blkalign, 2, 1, file);
+fwrite(&bps, 2, 1, file);
+fwrite("data", 4, 1, file);
+fwrite(&size, 4, 1, file);
+
+for (j = 0; j < hrtf->N; j++) {
+float l, r;
+
+l = hrtf->DataIR.values[offset + j];
+r = hrtf->DataIR.values[offset + j + hrtf->N];
+fwrite(&l, 4, 1, file);
+fwrite(&r, 4, 1, file);
+}
+fclose(file);
+}
+
+fail:
+mysofa_free(hrtf);
+
+return 0;
+}

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


[FFmpeg-cvslog] avcodec/vp9: ipred_dr_16x16_16 avx2 implementation

2017-06-12 Thread Ilia Valiakhmetov
ffmpeg | branch: master | Ilia Valiakhmetov  | Sat Jun 10 
17:01:12 2017 +0700| [81fc617c125734aa6f3b3d938af75fef6db750e7] | committer: 
Ronald S. Bultje

avcodec/vp9: ipred_dr_16x16_16 avx2 implementation

Signed-off-by: Ilia Valiakhmetov 
Signed-off-by: Ronald S. Bultje 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=81fc617c125734aa6f3b3d938af75fef6db750e7
---

 libavcodec/x86/vp9dsp_init_16bpp.c|  2 ++
 libavcodec/x86/vp9intrapred_16bpp.asm | 56 +++
 2 files changed, 58 insertions(+)

diff --git a/libavcodec/x86/vp9dsp_init_16bpp.c 
b/libavcodec/x86/vp9dsp_init_16bpp.c
index d1b8fcdaef..8d1aa1368a 100644
--- a/libavcodec/x86/vp9dsp_init_16bpp.c
+++ b/libavcodec/x86/vp9dsp_init_16bpp.c
@@ -52,6 +52,7 @@ decl_ipred_fns(dc,  16, mmxext, sse2);
 decl_ipred_fns(dc_top,  16, mmxext, sse2);
 decl_ipred_fns(dc_left, 16, mmxext, sse2);
 decl_ipred_fn(dl,   16, 16, avx2);
+decl_ipred_fn(dr,   16, 16, avx2);
 decl_ipred_fn(dl,   32, 16, avx2);
 
 #define decl_ipred_dir_funcs(type) \
@@ -136,6 +137,7 @@ av_cold void ff_vp9dsp_init_16bpp_x86(VP9DSPContext *dsp)
 init_fpel_func(1, 1,  64, avg, _16, avx2);
 init_fpel_func(0, 1, 128, avg, _16, avx2);
 init_ipred_func(dl, DIAG_DOWN_LEFT, 16, 16, avx2);
+init_ipred_func(dr, DIAG_DOWN_RIGHT, 16, 16, avx2);
 init_ipred_func(dl, DIAG_DOWN_LEFT, 32, 16, avx2);
 }
 
diff --git a/libavcodec/x86/vp9intrapred_16bpp.asm 
b/libavcodec/x86/vp9intrapred_16bpp.asm
index 92333bce20..764f7041d3 100644
--- a/libavcodec/x86/vp9intrapred_16bpp.asm
+++ b/libavcodec/x86/vp9intrapred_16bpp.asm
@@ -1170,6 +1170,62 @@ DR_FUNCS 2
 INIT_XMM avx
 DR_FUNCS 2
 
+%if HAVE_AVX2_EXTERNAL
+INIT_YMM avx2
+cglobal vp9_ipred_dr_16x16_16, 4, 5, 6, dst, stride, l, a
+movam0, [lq]   ; klmnopqrstuvwxyz
+movum1, [aq-2] ; *abcdefghijklmno
+movam2, [aq]   ; abcdefghijklmnop
+vperm2i128  m4, m2, m2, q2001  ; ijklmnop
+vpalignrm5, m4, m2, 2  ; bcdefghijklmnop.
+vperm2i128  m3, m0, m1, q0201  ; stuvwxyz*abcdefg
+LOWPASS  1,  2,  5 ; ABCDEFGHIJKLMNO.
+vpalignrm4, m3, m0, 2  ; lmnopqrstuvwxyz*
+vpalignrm5, m3, m0, 4  ; mnopqrstuvwxyz*a
+LOWPASS  0,  4,  5 ; LMNOPQRSTUVWXYZ#
+vperm2i128  m5, m0, m1, q0201  ; TUVWXYZ#ABCDEFGH
+DEFINE_ARGS dst, stride, stride3, stride5, dst3
+lea  dst3q, [dstq+strideq*4]
+lea   stride3q, [strideq*3]
+lea   stride5q, [stride3q+strideq*2]
+
+vpalignrm3, m5, m0, 2
+vpalignrm4, m1, m5, 2
+mova[dst3q+stride5q*2], m3 ; 14
+mova[ dstq+stride3q*2], m4 ; 6
+vpalignrm3, m5, m0, 4
+vpalignrm4, m1, m5, 4
+sub  dst3q, strideq
+mova[dst3q+stride5q*2], m3 ; 13
+mova[dst3q+strideq*2 ], m4 ; 5
+mova[dst3q+stride3q*4], m0 ; 15
+vpalignrm3, m5, m0, 6
+vpalignrm4, m1, m5, 6
+mova [dstq+stride3q*4], m3 ; 12
+mova [dst3q+strideq*1], m4 ; 4
+vpalignrm3, m5, m0, 8
+vpalignrm4, m1, m5, 8
+mova [dst3q+strideq*8], m3 ; 11
+mova [dst3q+strideq*0], m4 ; 3
+vpalignrm3, m5, m0, 10
+vpalignrm4, m1, m5, 10
+mova [dstq+stride5q*2], m3 ; 10
+mova [dstq+strideq*2 ], m4 ; 2
+vpalignrm3, m5, m0, 12
+vpalignrm4, m1, m5, 12
+mova[dst3q+stride3q*2], m3 ; 9
+mova [dstq+strideq*1 ], m4 ; 1
+vpalignrm3, m5, m0, 14
+vpalignrm4, m1, m5, 14
+mova  [dstq+strideq*8], m3 ; 8
+mova  [dstq+strideq*0], m4 ; 0
+sub   dstq, strideq
+mova [dst3q+strideq*4], m5 ; 7
+mova [ dstq+strideq*0], m1 ; -1
+RET
+%endif
+
+
 %macro VL_FUNCS 1 ; stack_mem_for_32x32_32bit_function
 cglobal vp9_ipred_vl_4x4_16, 2, 4, 3, dst, stride, l, a
 movifnidn   aq, amp

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


[FFmpeg-cvslog] tools/sofa2wavs: add license header

2017-06-12 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Mon Jun 12 22:13:09 
2017 +0200| [6e09e12641169da102853d944d7416e68a89d039] | committer: Paul B Mahol

tools/sofa2wavs: add license header

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6e09e12641169da102853d944d7416e68a89d039
---

 tools/sofa2wavs.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/tools/sofa2wavs.c b/tools/sofa2wavs.c
index f85e54f771..1f1075b22f 100644
--- a/tools/sofa2wavs.c
+++ b/tools/sofa2wavs.c
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2017 Paul B Mahol
+ *
+ * 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 
 #include 
 #include 

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


[FFmpeg-cvslog] avcodec/golomb: Assert that the input is not too large in set_ue_golomb()

2017-06-12 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Jun 13 02:56:58 2017 +0200| [db93fd74e4be68f97efcb958537f46a2a133aa47] | 
committer: Michael Niedermayer

avcodec/golomb: Assert that the input is not too large in set_ue_golomb()

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=db93fd74e4be68f97efcb958537f46a2a133aa47
---

 libavcodec/golomb.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 0833aff468..4f5514795a 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
@@ -463,6 +463,7 @@ static inline int get_te(GetBitContext *s, int r, char 
*file, const char *func,
 static inline void set_ue_golomb(PutBitContext *pb, int i)
 {
 av_assert2(i >= 0);
+av_assert2(i <= 0xFFFE);
 
 if (i < 256)
 put_bits(pb, ff_ue_golomb_len[i], i + 1);

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


[FFmpeg-cvslog] avcodec/put_bits: Implement put_bits32() in a single pass instead of 2 passes writing 16bits each

2017-06-12 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Tue 
Jun 13 03:18:21 2017 +0200| [4f9e958b04c69b1cebdc682b752cf6add75a0693] | 
committer: Michael Niedermayer

avcodec/put_bits: Implement put_bits32() in a single pass instead of 2 passes 
writing 16bits each

820 cpu cycles -> 660 cpu cycles for 100 put_bits32()

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4f9e958b04c69b1cebdc682b752cf6add75a0693
---

 libavcodec/put_bits.h | 34 --
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 68ed391195..9bd45cd8ba 100644
--- a/libavcodec/put_bits.h
+++ b/libavcodec/put_bits.h
@@ -209,15 +209,37 @@ static inline void put_sbits(PutBitContext *pb, int n, 
int32_t value)
  */
 static void av_unused put_bits32(PutBitContext *s, uint32_t value)
 {
-int lo = value & 0x;
-int hi = value >> 16;
+unsigned int bit_buf;
+int bit_left;
+
+bit_buf  = s->bit_buf;
+bit_left = s->bit_left;
+
 #ifdef BITSTREAM_WRITER_LE
-put_bits(s, 16, lo);
-put_bits(s, 16, hi);
+bit_buf |= value << (32 - bit_left);
+if (3 < s->buf_end - s->buf_ptr) {
+AV_WL32(s->buf_ptr, bit_buf);
+s->buf_ptr += 4;
+} else {
+av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too 
small\n");
+av_assert2(0);
+}
+bit_buf = (uint64_t)value >> bit_left;
 #else
-put_bits(s, 16, hi);
-put_bits(s, 16, lo);
+bit_buf = (uint64_t)bit_buf << bit_left;
+bit_buf|= value >> (32 - bit_left);
+if (3 < s->buf_end - s->buf_ptr) {
+AV_WB32(s->buf_ptr, bit_buf);
+s->buf_ptr += 4;
+} else {
+av_log(NULL, AV_LOG_ERROR, "Internal error, put_bits buffer too 
small\n");
+av_assert2(0);
+}
+bit_buf = value;
 #endif
+
+s->bit_buf  = bit_buf;
+s->bit_left = bit_left;
 }
 
 /**

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