* qatar/master: (24 commits) flvdec: remove incomplete, disabled seeking code mem: add support for _aligned_malloc() as found on Windows lavc: Extend the documentation for avcodec_init_packet flvdec: remove incomplete, disabled seeking code http: replace atoll() with strtoll() mpegts: remove unused/incomplete/broken seeking code af_amix: allow float planar sample format as input af_amix: use AVFloatDSPContext.vector_fmac_scalar() float_dsp: add x86-optimized functions for vector_fmac_scalar() float_dsp: Move vector_fmac_scalar() from libavcodec to libavutil lavr: Add x86-optimized function for flt to s32 conversion lavr: Add x86-optimized function for flt to s16 conversion lavr: Add x86-optimized functions for s32 to flt conversion lavr: Add x86-optimized functions for s32 to s16 conversion lavr: Add x86-optimized functions for s16 to flt conversion lavr: Add x86-optimized function for s16 to s32 conversion rtpenc: Support packetizing iLBC rtpdec: Add a depacketizer for iLBC Implement the iLBC storage file format mov: Support muxing/demuxing iLBC ... Conflicts: Changelog configure libavcodec/avcodec.h libavcodec/dsputil.c libavcodec/version.h libavformat/movenc.c libavformat/mpegts.c libavformat/version.h libavutil/mem.c
Unified · Split
| @@ -10,6 +10,7 @@ version next: · 9 unmodified lines | ||
| 10 | 10 | - atempo filter |
| 11 | 11 | - ffprobe -show_data option |
| 12 | 12 | - RTMPT protocol support |
| 13 | +- iLBC encoding/decoding via libilbc | |
| 13 | 14 | |
| 14 | 15 | |
| 15 | 16 | version 0.11: |
| @@ -180,6 +180,7 @@ External library support: · 179 unmodified lines | ||
| 180 | 180 | --enable-libfaac enable FAAC support via libfaac [no] |
| 181 | 181 | --enable-libfreetype enable libfreetype [no] |
| 182 | 182 | --enable-libgsm enable GSM support via libgsm [no] |
| 183 | + --enable-libilbc enable iLBC de/encoding via libilbc [no] | |
| 183 | 184 | --enable-libmodplug enable ModPlug via libmodplug [no] |
| 184 | 185 | --enable-libmp3lame enable MP3 encoding via libmp3lame [no] |
| 185 | 186 | --enable-libnut enable NUT (de)muxing via libnut, |
| @@ -1051,6 +1052,7 @@ CONFIG_LIST=" · 865 unmodified lines | ||
| 1051 | 1052 | libfaac |
| 1052 | 1053 | libfreetype |
| 1053 | 1054 | libgsm |
| 1055 | + libilbc | |
| 1054 | 1056 | libmodplug |
| 1055 | 1057 | libmp3lame |
| 1056 | 1058 | libnut |
| @@ -1168,6 +1170,7 @@ HAVE_LIST=" · 111 unmodified lines | ||
| 1168 | 1170 | $ARCH_EXT_LIST |
| 1169 | 1171 | $HAVE_LIST_PUB |
| 1170 | 1172 | $THREADS_LIST |
| 1173 | + aligned_malloc | |
| 1171 | 1174 | aligned_stack |
| 1172 | 1175 | alsa_asoundlib_h |
| 1173 | 1176 | altivec_h |
| @@ -1588,6 +1591,8 @@ libgsm_decoder_deps="libgsm" · 414 unmodified lines | ||
| 1588 | 1591 | libgsm_encoder_deps="libgsm" |
| 1589 | 1592 | libgsm_ms_decoder_deps="libgsm" |
| 1590 | 1593 | libgsm_ms_encoder_deps="libgsm" |
| 1594 | +libilbc_decoder_deps="libilbc" | |
| 1595 | +libilbc_encoder_deps="libilbc" | |
| 1591 | 1596 | libmodplug_demuxer_deps="libmodplug" |
| 1592 | 1597 | libmp3lame_encoder_deps="libmp3lame" |
| 1593 | 1598 | libopencore_amrnb_decoder_deps="libopencore_amrnb" |
| @@ -3144,6 +3149,7 @@ check_func ${malloc_prefix}memalign && enable memalign · 1550 unmodified lines | ||
| 3144 | 3149 | check_func mkstemp |
| 3145 | 3150 | check_func mmap |
| 3146 | 3151 | check_func ${malloc_prefix}posix_memalign && enable posix_memalign |
| 3152 | +check_func_headers malloc.h _aligned_malloc && enable aligned_malloc | |
| 3147 | 3153 | check_func setrlimit |
| 3148 | 3154 | check_func strerror_r |
| 3149 | 3155 | check_func strptime |
| @@ -3254,6 +3260,7 @@ enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0 && · 104 unmodified lines | ||
| 3254 | 3260 | enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac |
| 3255 | 3261 | enabled libfreetype && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType |
| 3256 | 3262 | enabled libgsm && require libgsm gsm/gsm.h gsm_create -lgsm |
| 3263 | +enabled libilbc && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc | |
| 3257 | 3264 | enabled libmodplug && require libmodplug libmodplug/modplug.h ModPlug_Load -lmodplug |
| 3258 | 3265 | enabled libmp3lame && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame |
| 3259 | 3266 | enabled libnut && require libnut libnut.h nut_demuxer_init -lnut |
| @@ -3522,7 +3529,7 @@ if test $target_os = "haiku"; then · 262 unmodified lines | ||
| 3522 | 3529 | disable posix_memalign |
| 3523 | 3530 | fi |
| 3524 | 3531 | |
| 3525 | −! enabled_any memalign posix_memalign && | |
| 3532 | +! enabled_any memalign posix_memalign aligned_malloc && | |
| 3526 | 3533 | enabled_any $need_memalign && enable memalign_hack |
| 3527 | 3534 | |
| 3528 | 3535 | # add_dep lib dep |
| @@ -3628,6 +3635,7 @@ echo "libcelt enabled ${libcelt-no}" · 99 unmodified lines | ||
| 3628 | 3635 | echo "libdc1394 support ${libdc1394-no}" |
| 3629 | 3636 | echo "libfaac enabled ${libfaac-no}" |
| 3630 | 3637 | echo "libgsm enabled ${libgsm-no}" |
| 3638 | +echo "libilbc enabled ${libilbc-no}" | |
| 3631 | 3639 | echo "libmodplug enabled ${libmodplug-no}" |
| 3632 | 3640 | echo "libmp3lame enabled ${libmp3lame-no}" |
| 3633 | 3641 | echo "libnut enabled ${libnut-no}" |
| @@ -93,6 +93,17 @@ x264 is under the GNU Public License Version 2 or later · 92 unmodified lines | ||
| 93 | 93 | details), you must upgrade FFmpeg's license to GPL in order to use it. |
| 94 | 94 | @end float |
| 95 | 95 | |
| 96 | +@section libilbc | |
| 97 | + | |
| 98 | +iLBC is a narrowband speech codec that has been made freely available | |
| 99 | +by Google as part of the WebRTC project. libilbc is a packaging friendly | |
| 100 | +copy of the iLBC codec. Libav can make use of the libilbc library for | |
| 101 | +iLBC encoding and decoding. | |
| 102 | + | |
| 103 | +Go to @url{https://github.com/dekkers/libilbc} and follow the instructions for | |
| 104 | +installing the library. Then pass @code{--enable-libilbc} to configure to | |
| 105 | +enable it. | |
| 106 | + | |
| 96 | 107 | |
| 97 | 108 | |
| 98 | 109 | @chapter Supported File Formats, Codecs or Features |
| @@ -191,6 +202,7 @@ library: · 92 unmodified lines | ||
| 191 | 202 | @item IEC61937 encapsulation @tab X @tab X |
| 192 | 203 | @item IFF @tab @tab X |
| 193 | 204 | @tab Interchange File Format |
| 205 | +@item iLBC @tab X @tab X | |
| 194 | 206 | @item Interplay MVE @tab @tab X |
| 195 | 207 | @tab Format used in various Interplay computer games. |
| 196 | 208 | @item IV8 @tab @tab X |
| @@ -749,6 +761,8 @@ following image formats are supported: · 552 unmodified lines | ||
| 749 | 761 | @item GSM Microsoft variant @tab E @tab X |
| 750 | 762 | @tab encoding supported through external library libgsm |
| 751 | 763 | @item IAC (Indeo Audio Coder) @tab @tab X |
| 764 | +@item iLBC (Internet Low Bitrate Codec) @tab E @tab E | |
| 765 | + @tab encoding and decoding supported through external library libilbc | |
| 752 | 766 | @item IMC (Intel Music Coder) @tab @tab X |
| 753 | 767 | @item MACE (Macintosh Audio Compression/Expansion) 3:1 @tab @tab X |
| 754 | 768 | @item MACE (Macintosh Audio Compression/Expansion) 6:1 @tab @tab X |
| @@ -247,6 +247,10 @@ times to construct arbitrary AMF sequences. · 246 unmodified lines | ||
| 247 | 247 | Version of the Flash plugin used to run the SWF player. The default |
| 248 | 248 | is LNX 9,0,124,2. |
| 249 | 249 | |
| 250 | +@item rtmp_flush_interval | |
| 251 | +Number of packets flushed in the same request (RTMPT only). The default | |
| 252 | +is 10. | |
| 253 | + | |
| 250 | 254 | @item rtmp_live |
| 251 | 255 | Specify that the media is a live stream. No resuming or seeking in |
| 252 | 256 | live streams is possible. The default value is @code{any}, which means the |
| @@ -659,6 +659,8 @@ OBJS-$(CONFIG_LIBGSM_DECODER) += libgsm.o · 658 unmodified lines | ||
| 659 | 659 | OBJS-$(CONFIG_LIBGSM_ENCODER) += libgsm.o |
| 660 | 660 | OBJS-$(CONFIG_LIBGSM_MS_DECODER) += libgsm.o |
| 661 | 661 | OBJS-$(CONFIG_LIBGSM_MS_ENCODER) += libgsm.o |
| 662 | +OBJS-$(CONFIG_LIBILBC_DECODER) += libilbc.o | |
| 663 | +OBJS-$(CONFIG_LIBILBC_ENCODER) += libilbc.o | |
| 662 | 664 | OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o mpegaudiodecheader.o \ |
| 663 | 665 | audio_frame_queue.o |
| 664 | 666 | OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o \ |
| @@ -410,6 +410,7 @@ void avcodec_register_all(void) · 409 unmodified lines | ||
| 410 | 410 | REGISTER_ENCODER (LIBFAAC, libfaac); |
| 411 | 411 | REGISTER_ENCDEC (LIBGSM, libgsm); |
| 412 | 412 | REGISTER_ENCDEC (LIBGSM_MS, libgsm_ms); |
| 413 | + REGISTER_ENCDEC (LIBILBC, libilbc); | |
| 413 | 414 | REGISTER_ENCODER (LIBMP3LAME, libmp3lame); |
| 414 | 415 | REGISTER_ENCDEC (LIBOPENCORE_AMRNB, libopencore_amrnb); |
| 415 | 416 | REGISTER_DECODER (LIBOPENCORE_AMRWB, libopencore_amrwb); |
| @@ -154,8 +154,6 @@ void ff_vector_fmul_window_neon(float *dst, const float *src0, · 153 unmodified lines | ||
| 154 | 154 | const float *src1, const float *win, int len); |
| 155 | 155 | void ff_vector_fmul_scalar_neon(float *dst, const float *src, float mul, |
| 156 | 156 | int len); |
| 157 | −void ff_vector_fmac_scalar_neon(float *dst, const float *src, float mul, | |
| 158 | − int len); | |
| 159 | 157 | void ff_butterflies_float_neon(float *v1, float *v2, int len); |
| 160 | 158 | float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len); |
| 161 | 159 | void ff_vector_fmul_reverse_neon(float *dst, const float *src0, |
| @@ -329,7 +327,6 @@ void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx) · 167 unmodified lines | ||
| 329 | 327 | |
| 330 | 328 | c->vector_fmul_window = ff_vector_fmul_window_neon; |
| 331 | 329 | c->vector_fmul_scalar = ff_vector_fmul_scalar_neon; |
| 332 | − c->vector_fmac_scalar = ff_vector_fmac_scalar_neon; | |
| 333 | 330 | c->butterflies_float = ff_butterflies_float_neon; |
| 334 | 331 | c->scalarproduct_float = ff_scalarproduct_float_neon; |
| 335 | 332 | c->vector_fmul_reverse = ff_vector_fmul_reverse_neon; |
| @@ -682,54 +682,6 @@ NOVFP vdup.32 q8, r2 · 681 unmodified lines | ||
| 682 | 682 | .unreq len |
| 683 | 683 | endfunc |
| 684 | 684 | |
| 685 | −function ff_vector_fmac_scalar_neon, export=1 | |
| 686 | −VFP len .req r2 | |
| 687 | −VFP acc .req r3 | |
| 688 | −NOVFP len .req r3 | |
| 689 | −NOVFP acc .req r2 | |
| 690 | −VFP vdup.32 q15, d0[0] | |
| 691 | −NOVFP vdup.32 q15, r2 | |
| 692 | − bics r12, len, #15 | |
| 693 | − mov acc, r0 | |
| 694 | − beq 3f | |
| 695 | − vld1.32 {q0}, [r1,:128]! | |
| 696 | − vld1.32 {q8}, [acc,:128]! | |
| 697 | − vld1.32 {q1}, [r1,:128]! | |
| 698 | − vld1.32 {q9}, [acc,:128]! | |
| 699 | −1: vmla.f32 q8, q0, q15 | |
| 700 | − vld1.32 {q2}, [r1,:128]! | |
| 701 | − vld1.32 {q10}, [acc,:128]! | |
| 702 | − vmla.f32 q9, q1, q15 | |
| 703 | − vld1.32 {q3}, [r1,:128]! | |
| 704 | − vld1.32 {q11}, [acc,:128]! | |
| 705 | − vmla.f32 q10, q2, q15 | |
| 706 | − vst1.32 {q8}, [r0,:128]! | |
| 707 | − vmla.f32 q11, q3, q15 | |
| 708 | − vst1.32 {q9}, [r0,:128]! | |
| 709 | − subs r12, r12, #16 | |
| 710 | − beq 2f | |
| 711 | − vld1.32 {q0}, [r1,:128]! | |
| 712 | − vld1.32 {q8}, [acc,:128]! | |
| 713 | − vst1.32 {q10}, [r0,:128]! | |
| 714 | − vld1.32 {q1}, [r1,:128]! | |
| 715 | − vld1.32 {q9}, [acc,:128]! | |
| 716 | − vst1.32 {q11}, [r0,:128]! | |
| 717 | − b 1b | |
| 718 | −2: vst1.32 {q10}, [r0,:128]! | |
| 719 | − vst1.32 {q11}, [r0,:128]! | |
| 720 | − ands len, len, #15 | |
| 721 | − it eq | |
| 722 | − bxeq lr | |
| 723 | −3: vld1.32 {q0}, [r1,:128]! | |
| 724 | − vld1.32 {q8}, [acc,:128]! | |
| 725 | − vmla.f32 q8, q0, q15 | |
| 726 | − vst1.32 {q8}, [r0,:128]! | |
| 727 | − subs len, len, #4 | |
| 728 | − bgt 3b | |
| 729 | − bx lr | |
| 730 | − .unreq len | |
| 731 | −endfunc | |
| 732 | − | |
| 733 | 685 | function ff_butterflies_float_neon, export=1 |
| 734 | 686 | 1: vld1.32 {q0},[r0,:128] |
| 735 | 687 | vld1.32 {q1},[r1,:128] |
| @@ -407,6 +407,7 @@ enum CodecID { · 406 unmodified lines | ||
| 407 | 407 | CODEC_ID_BMV_AUDIO, |
| 408 | 408 | CODEC_ID_RALF, |
| 409 | 409 | CODEC_ID_IAC, |
| 410 | + CODEC_ID_ILBC, | |
| 410 | 411 | CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'), |
| 411 | 412 | CODEC_ID_8SVX_RAW = MKBETAG('8','S','V','X'), |
| 412 | 413 | CODEC_ID_SONIC = MKBETAG('S','O','N','C'), |
| @@ -3470,6 +3471,9 @@ void av_destruct_packet(AVPacket *pkt); · 3057 unmodified lines | ||
| 3470 | 3471 | /** |
| 3471 | 3472 | * Initialize optional fields of a packet with default values. |
| 3472 | 3473 | * |
| 3474 | + * Note, this does not touch the data and size members, which have to be | |
| 3475 | + * initialized separately. | |
| 3476 | + * | |
| 3473 | 3477 | * @param pkt packet |
| 3474 | 3478 | */ |
| 3475 | 3479 | void av_init_packet(AVPacket *pkt); |
| @@ -27,6 +27,7 @@ · 26 unmodified lines | ||
| 27 | 27 | #include <stdio.h> |
| 28 | 28 | |
| 29 | 29 | #include "libavutil/common.h" |
| 30 | +#include "libavutil/float_dsp.h" | |
| 30 | 31 | #include "libavutil/intmath.h" |
| 31 | 32 | #include "libavutil/intreadwrite.h" |
| 32 | 33 | #include "libavutil/mathematics.h" |
| @@ -384,7 +385,7 @@ typedef struct { · 351 unmodified lines | ||
| 384 | 385 | int profile; |
| 385 | 386 | |
| 386 | 387 | int debug_flag; ///< used for suppressing repeated error messages output |
| 387 | − DSPContext dsp; | |
| 388 | + AVFloatDSPContext fdsp; | |
| 388 | 389 | FFTContext imdct; |
| 389 | 390 | SynthFilterContext synth; |
| 390 | 391 | DCADSPContext dcadsp; |
| @@ -2042,8 +2043,8 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data, · 1651 unmodified lines | ||
| 2042 | 2043 | float *back_chan = s->samples + s->channel_order_tab[s->xch_base_channel] * 256; |
| 2043 | 2044 | float *lt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 2] * 256; |
| 2044 | 2045 | float *rt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 1] * 256; |
| 2045 | − s->dsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256); | |
| 2046 | − s->dsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256); | |
| 2046 | + s->fdsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256); | |
| 2047 | + s->fdsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256); | |
| 2047 | 2048 | } |
| 2048 | 2049 | |
| 2049 | 2050 | if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { |
| @@ -2085,7 +2086,7 @@ static av_cold int dca_decode_init(AVCodecContext *avctx) · 35 unmodified lines | ||
| 2085 | 2086 | s->avctx = avctx; |
| 2086 | 2087 | dca_init_vlcs(); |
| 2087 | 2088 | |
| 2088 | − ff_dsputil_init(&s->dsp, avctx); | |
| 2089 | + avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); | |
| 2089 | 2090 | ff_mdct_init(&s->imdct, 6, 1, 1.0); |
| 2090 | 2091 | ff_synth_filter_init(&s->synth); |
| 2091 | 2092 | ff_dcadsp_init(&s->dcadsp); |
| @@ -127,7 +127,7 @@ static const enum PixelFormat dirac_pix_fmt[2][3] = { · 126 unmodified lines | ||
| 127 | 127 | static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, |
| 128 | 128 | dirac_source_params *source) |
| 129 | 129 | { |
| 130 | − AVRational frame_rate = (AVRational){0,0}; | |
| 130 | + AVRational frame_rate = {0,0}; | |
| 131 | 131 | unsigned luma_depth = 8, luma_offset = 16; |
| 132 | 132 | int idx; |
| 133 | 133 | |
| @@ -2509,14 +2509,6 @@ static void vector_fmul_scalar_c(float *dst, const float *src, float mul, · 2508 unmodified lines | ||
| 2509 | 2509 | dst[i] = src[i] * mul; |
| 2510 | 2510 | } |
| 2511 | 2511 | |
| 2512 | −static void vector_fmac_scalar_c(float *dst, const float *src, float mul, | |
| 2513 | − int len) | |
| 2514 | −{ | |
| 2515 | − int i; | |
| 2516 | − for (i = 0; i < len; i++) | |
| 2517 | − dst[i] += src[i] * mul; | |
| 2518 | −} | |
| 2519 | − | |
| 2520 | 2512 | static void butterflies_float_c(float *av_restrict v1, float *av_restrict v2, |
| 2521 | 2513 | int len) |
| 2522 | 2514 | { |
| @@ -3060,7 +3052,6 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) · 537 unmodified lines | ||
| 3060 | 3052 | c->butterflies_float = butterflies_float_c; |
| 3061 | 3053 | c->butterflies_float_interleave = butterflies_float_interleave_c; |
| 3062 | 3054 | c->vector_fmul_scalar = vector_fmul_scalar_c; |
| 3063 | − c->vector_fmac_scalar = vector_fmac_scalar_c; | |
| 3064 | 3055 | |
| 3065 | 3056 | c->shrink[0]= av_image_copy_plane; |
| 3066 | 3057 | c->shrink[1]= ff_shrink22; |
| @@ -420,17 +420,6 @@ typedef struct DSPContext { · 419 unmodified lines | ||
| 420 | 420 | */ |
| 421 | 421 | void (*vector_fmul_scalar)(float *dst, const float *src, float mul, |
| 422 | 422 | int len); |
| 423 | − /** | |
| 424 | − * Multiply a vector of floats by a scalar float and add to | |
| 425 | − * destination vector. Source and destination vectors must | |
| 426 | − * overlap exactly or not at all. | |
| 427 | − * @param dst result vector, 16-byte aligned | |
| 428 | − * @param src input vector, 16-byte aligned | |
| 429 | − * @param mul scalar value | |
| 430 | − * @param len length of vector, multiple of 4 | |
| 431 | − */ | |
| 432 | − void (*vector_fmac_scalar)(float *dst, const float *src, float mul, | |
| 433 | − int len); | |
| 434 | 423 | /** |
| 435 | 424 | * Calculate the scalar product of two vectors of floats. |
| 436 | 425 | * @param v1 first vector, 16-byte aligned |
| @@ -0,0 +1,209 @@ | ||
| 1 | +/* | |
| 2 | + * iLBC decoder/encoder stub | |
| 3 | + * Copyright (c) 2012 Martin Storsjo | |
| 4 | + * | |
| 5 | + * This file is part of FFmpeg. | |
| 6 | + * | |
| 7 | + * FFmpeg is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public | |
| 9 | + * License as published by the Free Software Foundation; either | |
| 10 | + * version 2.1 of the License, or (at your option) any later version. | |
| 11 | + * | |
| 12 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | + * Lesser General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU Lesser General Public | |
| 18 | + * License along with FFmpeg; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + */ | |
| 21 | + | |
| 22 | +#include <ilbc.h> | |
| 23 | + | |
| 24 | +#include "avcodec.h" | |
| 25 | +#include "libavutil/opt.h" | |
| 26 | +#include "internal.h" | |
| 27 | + | |
| 28 | +static int get_mode(AVCodecContext *avctx) | |
| 29 | +{ | |
| 30 | + if (avctx->block_align == 38) | |
| 31 | + return 20; | |
| 32 | + else if (avctx->block_align == 50) | |
| 33 | + return 30; | |
| 34 | + else if (avctx->bit_rate > 0) | |
| 35 | + return avctx->bit_rate <= 14000 ? 30 : 20; | |
| 36 | + else | |
| 37 | + return -1; | |
| 38 | +} | |
| 39 | + | |
| 40 | +typedef struct ILBCDecContext { | |
| 41 | + const AVClass *class; | |
| 42 | + AVFrame frame; | |
| 43 | + iLBC_Dec_Inst_t decoder; | |
| 44 | + int enhance; | |
| 45 | +} ILBCDecContext; | |
| 46 | + | |
| 47 | +static const AVOption ilbc_dec_options[] = { | |
| 48 | + { "enhance", "Enhance the decoded audio (adds delay)", offsetof(ILBCDecContext, enhance), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM }, | |
| 49 | + { NULL } | |
| 50 | +}; | |
| 51 | + | |
| 52 | +static const AVClass ilbc_dec_class = { | |
| 53 | + "libilbc", av_default_item_name, ilbc_dec_options, LIBAVUTIL_VERSION_INT | |
| 54 | +}; | |
| 55 | + | |
| 56 | +static av_cold int ilbc_decode_init(AVCodecContext *avctx) | |
| 57 | +{ | |
| 58 | + ILBCDecContext *s = avctx->priv_data; | |
| 59 | + int mode; | |
| 60 | + | |
| 61 | + if ((mode = get_mode(avctx)) < 0) { | |
| 62 | + av_log(avctx, AV_LOG_ERROR, "iLBC frame mode not indicated\n"); | |
| 63 | + return AVERROR(EINVAL); | |
| 64 | + } | |
| 65 | + | |
| 66 | + WebRtcIlbcfix_InitDecode(&s->decoder, mode, s->enhance); | |
| 67 | + avcodec_get_frame_defaults(&s->frame); | |
| 68 | + avctx->coded_frame = &s->frame; | |
| 69 | + | |
| 70 | + avctx->channels = 1; | |
| 71 | + avctx->sample_rate = 8000; | |
| 72 | + avctx->sample_fmt = AV_SAMPLE_FMT_S16; | |
| 73 | + | |
| 74 | + return 0; | |
| 75 | +} | |
| 76 | + | |
| 77 | +static int ilbc_decode_frame(AVCodecContext *avctx, void *data, | |
| 78 | + int *got_frame_ptr, AVPacket *avpkt) | |
| 79 | +{ | |
| 80 | + const uint8_t *buf = avpkt->data; | |
| 81 | + int buf_size = avpkt->size; | |
| 82 | + ILBCDecContext *s = avctx->priv_data; | |
| 83 | + int ret; | |
| 84 | + | |
| 85 | + if (s->decoder.no_of_bytes > buf_size) { | |
| 86 | + av_log(avctx, AV_LOG_ERROR, "iLBC frame too short (%u, should be %u)\n", | |
| 87 | + buf_size, s->decoder.no_of_bytes); | |
| 88 | + return AVERROR_INVALIDDATA; | |
| 89 | + } | |
| 90 | + | |
| 91 | + s->frame.nb_samples = s->decoder.blockl; | |
| 92 | + if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { | |
| 93 | + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
| 94 | + return ret; | |
| 95 | + } | |
| 96 | + | |
| 97 | + WebRtcIlbcfix_DecodeImpl((WebRtc_Word16*) s->frame.data[0], | |
| 98 | + (const WebRtc_UWord16*) buf, &s->decoder, 1); | |
| 99 | + | |
| 100 | + *got_frame_ptr = 1; | |
| 101 | + *(AVFrame *)data = s->frame; | |
| 102 | + | |
| 103 | + return s->decoder.no_of_bytes; | |
| 104 | +} | |
| 105 | + | |
| 106 | +AVCodec ff_libilbc_decoder = { | |
| 107 | + .name = "libilbc", | |
| 108 | + .type = AVMEDIA_TYPE_AUDIO, | |
| 109 | + .id = CODEC_ID_ILBC, | |
| 110 | + .priv_data_size = sizeof(ILBCDecContext), | |
| 111 | + .init = ilbc_decode_init, | |
| 112 | + .decode = ilbc_decode_frame, | |
| 113 | + .capabilities = CODEC_CAP_DR1, | |
| 114 | + .long_name = NULL_IF_CONFIG_SMALL("Internet Low Bitrate Codec (iLBC)"), | |
| 115 | + .priv_class = &ilbc_dec_class, | |
| 116 | +}; | |
| 117 | + | |
| 118 | +typedef struct ILBCEncContext { | |
| 119 | + const AVClass *class; | |
| 120 | + iLBC_Enc_Inst_t encoder; | |
| 121 | + int mode; | |
| 122 | +} ILBCEncContext; | |
| 123 | + | |
| 124 | +static const AVOption ilbc_enc_options[] = { | |
| 125 | + { "mode", "iLBC mode (20 or 30 ms frames)", offsetof(ILBCEncContext, mode), AV_OPT_TYPE_INT, { 20 }, 20, 30, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, | |
| 126 | + { NULL } | |
| 127 | +}; | |
| 128 | + | |
| 129 | +static const AVClass ilbc_enc_class = { | |
| 130 | + "libilbc", av_default_item_name, ilbc_enc_options, LIBAVUTIL_VERSION_INT | |
| 131 | +}; | |
| 132 | + | |
| 133 | +static av_cold int ilbc_encode_init(AVCodecContext *avctx) | |
| 134 | +{ | |
| 135 | + ILBCEncContext *s = avctx->priv_data; | |
| 136 | + int mode; | |
| 137 | + | |
| 138 | + if (avctx->sample_rate != 8000) { | |
| 139 | + av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); | |
| 140 | + return AVERROR(EINVAL); | |
| 141 | + } | |
| 142 | + | |
| 143 | + if (avctx->channels != 1) { | |
| 144 | + av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); | |
| 145 | + return AVERROR(EINVAL); | |
| 146 | + } | |
| 147 | + | |
| 148 | + if ((mode = get_mode(avctx)) > 0) | |
| 149 | + s->mode = mode; | |
| 150 | + else | |
| 151 | + s->mode = s->mode != 30 ? 20 : 30; | |
| 152 | + WebRtcIlbcfix_InitEncode(&s->encoder, s->mode); | |
| 153 | + | |
| 154 | + avctx->block_align = s->encoder.no_of_bytes; | |
| 155 | + avctx->frame_size = s->encoder.blockl; | |
| 156 | +#if FF_API_OLD_ENCODE_AUDIO | |
| 157 | + avctx->coded_frame = avcodec_alloc_frame(); | |
| 158 | + if (!avctx->coded_frame) | |
| 159 | + return AVERROR(ENOMEM); | |
| 160 | +#endif | |
| 161 | + | |
| 162 | + return 0; | |
| 163 | +} | |
| 164 | + | |
| 165 | +static av_cold int ilbc_encode_close(AVCodecContext *avctx) | |
| 166 | +{ | |
| 167 | +#if FF_API_OLD_ENCODE_AUDIO | |
| 168 | + av_freep(&avctx->coded_frame); | |
| 169 | +#endif | |
| 170 | + return 0; | |
| 171 | +} | |
| 172 | + | |
| 173 | +static int ilbc_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, | |
| 174 | + const AVFrame *frame, int *got_packet_ptr) | |
| 175 | +{ | |
| 176 | + ILBCEncContext *s = avctx->priv_data; | |
| 177 | + int ret; | |
| 178 | + | |
| 179 | + if ((ret = ff_alloc_packet(avpkt, 50))) { | |
| 180 | + av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); | |
| 181 | + return ret; | |
| 182 | + } | |
| 183 | + | |
| 184 | + WebRtcIlbcfix_EncodeImpl((WebRtc_UWord16*) avpkt->data, (const WebRtc_Word16*) frame->data[0], &s->encoder); | |
| 185 | + | |
| 186 | + avpkt->size = s->encoder.no_of_bytes; | |
| 187 | + *got_packet_ptr = 1; | |
| 188 | + return 0; | |
| 189 | +} | |
| 190 | + | |
| 191 | +static const AVCodecDefault ilbc_encode_defaults[] = { | |
| 192 | + { "b", "0" }, | |
| 193 | + { NULL } | |
| 194 | +}; | |
| 195 | + | |
| 196 | +AVCodec ff_libilbc_encoder = { | |
| 197 | + .name = "libilbc", | |
| 198 | + .type = AVMEDIA_TYPE_AUDIO, | |
| 199 | + .id = CODEC_ID_ILBC, | |
| 200 | + .priv_data_size = sizeof(ILBCEncContext), | |
| 201 | + .init = ilbc_encode_init, | |
| 202 | + .encode2 = ilbc_encode_frame, | |
| 203 | + .close = ilbc_encode_close, | |
| 204 | + .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, | |
| 205 | + AV_SAMPLE_FMT_NONE }, | |
| 206 | + .long_name = NULL_IF_CONFIG_SMALL("Internet Low Bitrate Codec (iLBC)"), | |
| 207 | + .defaults = ilbc_encode_defaults, | |
| 208 | + .priv_class = &ilbc_enc_class, | |
| 209 | +}; | |
| @@ -514,14 +514,6 @@ static double predict_size(Predictor *p, double q, double var) · 513 unmodified lines | ||
| 514 | 514 | return p->coeff*var / (q*p->count); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | −/* | |
| 518 | −static double predict_qp(Predictor *p, double size, double var) | |
| 519 | −{ | |
| 520 | −//printf("coeff:%f, count:%f, var:%f, size:%f//\n", p->coeff, p->count, var, size); | |
| 521 | − return p->coeff*var / (size*p->count); | |
| 522 | −} | |
| 523 | −*/ | |
| 524 | − | |
| 525 | 517 | static void update_predictor(Predictor *p, double q, double var, double size) |
| 526 | 518 | { |
| 527 | 519 | double new_coeff= size*q / (var + 1); |
| @@ -561,10 +553,6 @@ static void adaptive_quantization(MpegEncContext *s, double q){ · 33 unmodified lines | ||
| 561 | 553 | int mb_y = mb_xy / s->mb_stride; |
| 562 | 554 | int mb_distance; |
| 563 | 555 | float mb_factor = 0.0; |
| 564 | −#if 0 | |
| 565 | − if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune | |
| 566 | − if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune | |
| 567 | −#endif | |
| 568 | 556 | if(spat_cplx < 4) spat_cplx= 4; //FIXME finetune |
| 569 | 557 | if(temp_cplx < 4) temp_cplx= 4; //FIXME finetune |
| 570 | 558 | |
| @@ -2138,6 +2138,11 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) · 2137 unmodified lines | ||
| 2138 | 2138 | case 29: return 288; |
| 2139 | 2139 | case 37: return 480; |
| 2140 | 2140 | } |
| 2141 | + } else if (id == CODEC_ID_ILBC) { | |
| 2142 | + switch (ba) { | |
| 2143 | + case 38: return 160; | |
| 2144 | + case 50: return 240; | |
| 2145 | + } | |
| 2141 | 2146 | } |
| 2142 | 2147 | } |
| 2143 | 2148 | |
| @@ -27,7 +27,7 @@ · 26 unmodified lines | ||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | #define LIBAVCODEC_VERSION_MAJOR 54 |
| 30 | −#define LIBAVCODEC_VERSION_MINOR 25 | |
| 30 | +#define LIBAVCODEC_VERSION_MINOR 26 | |
| 31 | 31 | #define LIBAVCODEC_VERSION_MICRO 100 |
| 32 | 32 | |
| 33 | 33 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | ||
| 32 | 32 | #include "libavutil/audio_fifo.h" |
| 33 | 33 | #include "libavutil/avassert.h" |
| 34 | 34 | #include "libavutil/avstring.h" |
| 35 | +#include "libavutil/float_dsp.h" | |
| 35 | 36 | #include "libavutil/mathematics.h" |
| 36 | 37 | #include "libavutil/opt.h" |
| 37 | 38 | #include "libavutil/samplefmt.h" |
| @@ -152,6 +153,7 @@ static int frame_list_add_frame(FrameList *frame_list, int nb_samples, int64_t p · 114 unmodified lines | ||
| 152 | 153 | |
| 153 | 154 | typedef struct MixContext { |
| 154 | 155 | const AVClass *class; /**< class for AVOptions */ |
| 156 | + AVFloatDSPContext fdsp; | |
| 155 | 157 | |
| 156 | 158 | int nb_inputs; /**< number of inputs */ |
| 157 | 159 | int active_inputs; /**< number of input currently active */ |
| @@ -160,6 +162,7 @@ typedef struct MixContext { · 2 unmodified lines | ||
| 160 | 162 | |
| 161 | 163 | int nb_channels; /**< number of channels */ |
| 162 | 164 | int sample_rate; /**< sample rate */ |
| 165 | + int planar; | |
| 163 | 166 | AVAudioFifo **fifos; /**< audio fifo for each input */ |
| 164 | 167 | uint8_t *input_state; /**< current state of each input */ |
| 165 | 168 | float *input_scale; /**< mixing scale factor for each input */ |
| @@ -224,6 +227,7 @@ static int config_output(AVFilterLink *outlink) · 58 unmodified lines | ||
| 224 | 227 | int i; |
| 225 | 228 | char buf[64]; |
| 226 | 229 | |
| 230 | + s->planar = av_sample_fmt_is_planar(outlink->format); | |
| 227 | 231 | s->sample_rate = outlink->sample_rate; |
| 228 | 232 | outlink->time_base = (AVRational){ 1, outlink->sample_rate }; |
| 229 | 233 | s->next_pts = AV_NOPTS_VALUE; |
| @@ -264,14 +268,6 @@ static int config_output(AVFilterLink *outlink) · 34 unmodified lines | ||
| 264 | 268 | return 0; |
| 265 | 269 | } |
| 266 | 270 | |
| 267 | −/* TODO: move optimized version from DSPContext to libavutil */ | |
| 268 | −static void vector_fmac_scalar(float *dst, const float *src, float mul, int len) | |
| 269 | −{ | |
| 270 | − int i; | |
| 271 | − for (i = 0; i < len; i++) | |
| 272 | − dst[i] += src[i] * mul; | |
| 273 | −} | |
| 274 | − | |
| 275 | 271 | /** |
| 276 | 272 | * Read samples from the input FIFOs, mix, and write to the output link. |
| 277 | 273 | */ |
| @@ -294,11 +290,20 @@ static int output_frame(AVFilterLink *outlink, int nb_samples) · 16 unmodified lines | ||
| 294 | 290 | |
| 295 | 291 | for (i = 0; i < s->nb_inputs; i++) { |
| 296 | 292 | if (s->input_state[i] == INPUT_ON) { |
| 293 | + int planes, plane_size, p; | |
| 294 | + | |
| 297 | 295 | av_audio_fifo_read(s->fifos[i], (void **)in_buf->extended_data, |
| 298 | 296 | nb_samples); |
| 299 | − vector_fmac_scalar((float *)out_buf->extended_data[0], | |
| 300 | − (float *) in_buf->extended_data[0], | |
| 301 | − s->input_scale[i], nb_samples * s->nb_channels); | |
| 297 | + | |
| 298 | + planes = s->planar ? s->nb_channels : 1; | |
| 299 | + plane_size = nb_samples * (s->planar ? 1 : s->nb_channels); | |
| 300 | + plane_size = FFALIGN(plane_size, 16); | |
| 301 | + | |
| 302 | + for (p = 0; p < planes; p++) { | |
| 303 | + s->fdsp.vector_fmac_scalar((float *)out_buf->extended_data[p], | |
| 304 | + (float *) in_buf->extended_data[p], | |
| 305 | + s->input_scale[i], plane_size); | |
| 306 | + } | |
| 302 | 307 | } |
| 303 | 308 | } |
| 304 | 309 | avfilter_unref_buffer(in_buf); |
| @@ -501,6 +506,8 @@ static int init(AVFilterContext *ctx, const char *args, void *opaque) · 196 unmodified lines | ||
| 501 | 506 | ff_insert_inpad(ctx, i, &pad); |
| 502 | 507 | } |
| 503 | 508 | |
| 509 | + avpriv_float_dsp_init(&s->fdsp, 0); | |
| 510 | + | |
| 504 | 511 | return 0; |
| 505 | 512 | } |
| 506 | 513 | |
| @@ -527,6 +534,7 @@ static int query_formats(AVFilterContext *ctx) · 20 unmodified lines | ||
| 527 | 534 | { |
| 528 | 535 | AVFilterFormats *formats = NULL; |
| 529 | 536 | ff_add_format(&formats, AV_SAMPLE_FMT_FLT); |
| 537 | + ff_add_format(&formats, AV_SAMPLE_FMT_FLTP); | |
| 530 | 538 | ff_set_common_formats(ctx, formats); |
| 531 | 539 | ff_set_common_channel_layouts(ctx, ff_all_channel_layouts()); |
| 532 | 540 | ff_set_common_samplerates(ctx, ff_all_samplerates()); |
| @@ -123,6 +123,8 @@ OBJS-$(CONFIG_ICO_DEMUXER) += icodec.o · 122 unmodified lines | ||
| 123 | 123 | OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o |
| 124 | 124 | OBJS-$(CONFIG_IDF_DEMUXER) += bintext.o |
| 125 | 125 | OBJS-$(CONFIG_IFF_DEMUXER) += iff.o |
| 126 | +OBJS-$(CONFIG_ILBC_DEMUXER) += ilbc.o | |
| 127 | +OBJS-$(CONFIG_ILBC_MUXER) += ilbc.o | |
| 126 | 128 | OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2dec.o img2.o |
| 127 | 129 | OBJS-$(CONFIG_IMAGE2_MUXER) += img2enc.o img2.o |
| 128 | 130 | OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER) += img2dec.o img2.o |
| @@ -281,6 +283,7 @@ OBJS-$(CONFIG_RTPDEC) += rdt.o \ · 152 unmodified lines | ||
| 281 | 283 | rtpdec_h263.o \ |
| 282 | 284 | rtpdec_h263_rfc2190.o \ |
| 283 | 285 | rtpdec_h264.o \ |
| 286 | + rtpdec_ilbc.o \ | |
| 284 | 287 | rtpdec_latm.o \ |
| 285 | 288 | rtpdec_mpeg4.o \ |
| 286 | 289 | rtpdec_qcelp.o \ |
| @@ -116,6 +116,7 @@ void av_register_all(void) · 115 unmodified lines | ||
| 116 | 116 | REGISTER_DEMUXER (IDCIN, idcin); |
| 117 | 117 | REGISTER_DEMUXER (IDF, idf); |
| 118 | 118 | REGISTER_DEMUXER (IFF, iff); |
| 119 | + REGISTER_MUXDEMUX (ILBC, ilbc); | |
| 119 | 120 | REGISTER_MUXDEMUX (IMAGE2, image2); |
| 120 | 121 | REGISTER_MUXDEMUX (IMAGE2PIPE, image2pipe); |
| 121 | 122 | REGISTER_DEMUXER (INGENIENT, ingenient); |
| @@ -759,33 +759,6 @@ static int flv_read_seek(AVFormatContext *s, int stream_index, · 758 unmodified lines | ||
| 759 | 759 | return avio_seek_time(s->pb, stream_index, ts, flags); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | −#if 0 /* don't know enough to implement this */ | |
| 763 | −static int flv_read_seek2(AVFormatContext *s, int stream_index, | |
| 764 | − int64_t min_ts, int64_t ts, int64_t max_ts, int flags) | |
| 765 | −{ | |
| 766 | − int ret = AVERROR(ENOSYS); | |
| 767 | − | |
| 768 | − if (ts - min_ts > (uint64_t)(max_ts - ts)) flags |= AVSEEK_FLAG_BACKWARD; | |
| 769 | − | |
| 770 | − if (!s->pb->seekable) { | |
| 771 | − if (stream_index < 0) { | |
| 772 | − stream_index = av_find_default_stream_index(s); | |
| 773 | − if (stream_index < 0) | |
| 774 | − return -1; | |
| 775 | − | |
| 776 | − /* timestamp for default must be expressed in AV_TIME_BASE units */ | |
| 777 | − ts = av_rescale_rnd(ts, 1000, AV_TIME_BASE, | |
| 778 | − flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP); | |
| 779 | − } | |
| 780 | − ret = avio_seek_time(s->pb, stream_index, ts, flags); | |
| 781 | − } | |
| 782 | − | |
| 783 | − if (ret == AVERROR(ENOSYS)) | |
| 784 | − ret = av_seek_frame(s, stream_index, ts, flags); | |
| 785 | − return ret; | |
| 786 | −} | |
| 787 | −#endif | |
| 788 | − | |
| 789 | 762 | AVInputFormat ff_flv_demuxer = { |
| 790 | 763 | .name = "flv", |
| 791 | 764 | .long_name = NULL_IF_CONFIG_SMALL("FLV format"), |
| @@ -794,9 +767,6 @@ AVInputFormat ff_flv_demuxer = { · 2 unmodified lines | ||
| 794 | 767 | .read_header = flv_read_header, |
| 795 | 768 | .read_packet = flv_read_packet, |
| 796 | 769 | .read_seek = flv_read_seek, |
| 797 | −#if 0 | |
| 798 | − .read_seek2 = flv_read_seek2, | |
| 799 | −#endif | |
| 800 | 770 | .read_close = flv_read_close, |
| 801 | 771 | .extensions = "flv", |
| 802 | 772 | }; |
| @@ -308,15 +308,15 @@ static int process_line(URLContext *h, char *line, int line_count, · 307 unmodified lines | ||
| 308 | 308 | strcpy(s->location, p); |
| 309 | 309 | *new_location = 1; |
| 310 | 310 | } else if (!av_strcasecmp (tag, "Content-Length") && s->filesize == -1) { |
| 311 | − s->filesize = atoll(p); | |
| 311 | + s->filesize = strtoll(p, NULL, 10); | |
| 312 | 312 | } else if (!av_strcasecmp (tag, "Content-Range")) { |
| 313 | 313 | /* "bytes $from-$to/$document_size" */ |
| 314 | 314 | const char *slash; |
| 315 | 315 | if (!strncmp (p, "bytes ", 6)) { |
| 316 | 316 | p += 6; |
| 317 | − s->off = atoll(p); | |
| 317 | + s->off = strtoll(p, NULL, 10); | |
| 318 | 318 | if ((slash = strchr(p, '/')) && strlen(slash) > 0) |
| 319 | − s->filesize = atoll(slash+1); | |
| 319 | + s->filesize = strtoll(slash+1, NULL, 10); | |
| 320 | 320 | } |
| 321 | 321 | h->is_streamed = 0; /* we _can_ in fact seek */ |
| 322 | 322 | } else if (!av_strcasecmp(tag, "Accept-Ranges") && !strncmp(p, "bytes", 5)) { |
| @@ -0,0 +1,141 @@ | ||
| 1 | +/* | |
| 2 | + * iLBC storage file format | |
| 3 | + * Copyright (c) 2012 Martin Storsjo | |
| 4 | + * | |
| 5 | + * This file is part of FFmpeg. | |
| 6 | + * | |
| 7 | + * FFmpeg is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public | |
| 9 | + * License as published by the Free Software Foundation; either | |
| 10 | + * version 2.1 of the License, or (at your option) any later version. | |
| 11 | + * | |
| 12 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | + * Lesser General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU Lesser General Public | |
| 18 | + * License along with FFmpeg; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + */ | |
| 21 | + | |
| 22 | +#include "avformat.h" | |
| 23 | +#include "internal.h" | |
| 24 | + | |
| 25 | +static const char mode20_header[] = "#!iLBC20\n"; | |
| 26 | +static const char mode30_header[] = "#!iLBC30\n"; | |
| 27 | + | |
| 28 | +static int ilbc_write_header(AVFormatContext *s) | |
| 29 | +{ | |
| 30 | + AVIOContext *pb = s->pb; | |
| 31 | + AVCodecContext *enc; | |
| 32 | + | |
| 33 | + if (s->nb_streams != 1) { | |
| 34 | + av_log(s, AV_LOG_ERROR, "Unsupported number of streams\n"); | |
| 35 | + return AVERROR(EINVAL); | |
| 36 | + } | |
| 37 | + enc = s->streams[0]->codec; | |
| 38 | + | |
| 39 | + if (enc->codec_id != CODEC_ID_ILBC) { | |
| 40 | + av_log(s, AV_LOG_ERROR, "Unsupported codec\n"); | |
| 41 | + return AVERROR(EINVAL); | |
| 42 | + } | |
| 43 | + | |
| 44 | + if (enc->block_align == 50) { | |
| 45 | + avio_write(pb, mode30_header, sizeof(mode30_header) - 1); | |
| 46 | + } else if (enc->block_align == 38) { | |
| 47 | + avio_write(pb, mode20_header, sizeof(mode20_header) - 1); | |
| 48 | + } else { | |
| 49 | + av_log(s, AV_LOG_ERROR, "Unsupported mode\n"); | |
| 50 | + return AVERROR(EINVAL); | |
| 51 | + } | |
| 52 | + avio_flush(pb); | |
| 53 | + return 0; | |
| 54 | +} | |
| 55 | + | |
| 56 | +static int ilbc_write_packet(AVFormatContext *s, AVPacket *pkt) | |
| 57 | +{ | |
| 58 | + avio_write(s->pb, pkt->data, pkt->size); | |
| 59 | + avio_flush(s->pb); | |
| 60 | + return 0; | |
| 61 | +} | |
| 62 | + | |
| 63 | +static int ilbc_probe(AVProbeData *p) | |
| 64 | +{ | |
| 65 | + // Only check for "#!iLBC" which matches both formats | |
| 66 | + if (!memcmp(p->buf, mode20_header, 6)) | |
| 67 | + return AVPROBE_SCORE_MAX; | |
| 68 | + else | |
| 69 | + return 0; | |
| 70 | +} | |
| 71 | + | |
| 72 | +static int ilbc_read_header(AVFormatContext *s) | |
| 73 | +{ | |
| 74 | + AVIOContext *pb = s->pb; | |
| 75 | + AVStream *st; | |
| 76 | + uint8_t header[9]; | |
| 77 | + | |
| 78 | + avio_read(pb, header, 9); | |
| 79 | + | |
| 80 | + st = avformat_new_stream(s, NULL); | |
| 81 | + if (!st) | |
| 82 | + return AVERROR(ENOMEM); | |
| 83 | + st->codec->codec_id = CODEC_ID_ILBC; | |
| 84 | + st->codec->sample_rate = 8000; | |
| 85 | + st->codec->channels = 1; | |
| 86 | + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 87 | + st->start_time = 0; | |
| 88 | + avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); | |
| 89 | + if (!memcmp(header, mode20_header, sizeof(mode20_header) - 1)) { | |
| 90 | + st->codec->block_align = 38; | |
| 91 | + st->codec->bit_rate = 15200; | |
| 92 | + } else if (!memcmp(header, mode30_header, sizeof(mode30_header) - 1)) { | |
| 93 | + st->codec->block_align = 50; | |
| 94 | + st->codec->bit_rate = 13333; | |
| 95 | + } else { | |
| 96 | + av_log(s, AV_LOG_ERROR, "Unrecognized iLBC file header\n"); | |
| 97 | + return AVERROR_INVALIDDATA; | |
| 98 | + } | |
| 99 | + | |
| 100 | + return 0; | |
| 101 | +} | |
| 102 | + | |
| 103 | +static int ilbc_read_packet(AVFormatContext *s, | |
| 104 | + AVPacket *pkt) | |
| 105 | +{ | |
| 106 | + AVCodecContext *enc = s->streams[0]->codec; | |
| 107 | + int ret; | |
| 108 | + | |
| 109 | + if ((ret = av_new_packet(pkt, enc->block_align)) < 0) | |
| 110 | + return ret; | |
| 111 | + | |
| 112 | + pkt->stream_index = 0; | |
| 113 | + pkt->pos = avio_tell(s->pb); | |
| 114 | + pkt->duration = enc->block_align == 38 ? 160 : 240; | |
| 115 | + if ((ret = avio_read(s->pb, pkt->data, enc->block_align)) != enc->block_align) { | |
| 116 | + av_free_packet(pkt); | |
| 117 | + return ret < 0 ? ret : AVERROR(EIO); | |
| 118 | + } | |
| 119 | + | |
| 120 | + return 0; | |
| 121 | +} | |
| 122 | + | |
| 123 | +AVInputFormat ff_ilbc_demuxer = { | |
| 124 | + .name = "ilbc", | |
| 125 | + .long_name = NULL_IF_CONFIG_SMALL("iLBC storage file format"), | |
| 126 | + .read_probe = ilbc_probe, | |
| 127 | + .read_header = ilbc_read_header, | |
| 128 | + .read_packet = ilbc_read_packet, | |
| 129 | + .flags = AVFMT_GENERIC_INDEX, | |
| 130 | +}; | |
| 131 | + | |
| 132 | +AVOutputFormat ff_ilbc_muxer = { | |
| 133 | + .name = "ilbc", | |
| 134 | + .long_name = NULL_IF_CONFIG_SMALL("iLBC storage file format"), | |
| 135 | + .mime_type = "audio/iLBC", | |
| 136 | + .extensions = "lbc", | |
| 137 | + .audio_codec = CODEC_ID_ILBC, | |
| 138 | + .write_header = ilbc_write_header, | |
| 139 | + .write_packet = ilbc_write_packet, | |
| 140 | + .flags = AVFMT_NOTIMESTAMPS, | |
| 141 | +}; | |
| @@ -259,6 +259,7 @@ const AVCodecTag ff_codec_movaudio_tags[] = { · 258 unmodified lines | ||
| 259 | 259 | { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') }, |
| 260 | 260 | { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') }, |
| 261 | 261 | { CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') }, |
| 262 | + { CODEC_ID_ILBC, MKTAG('i', 'l', 'b', 'c') }, | |
| 262 | 263 | { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, |
| 263 | 264 | { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, |
| 264 | 265 | { CODEC_ID_MP1, MKTAG('.', 'm', 'p', '1') }, |
| @@ -1540,6 +1540,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) · 1539 unmodified lines | ||
| 1540 | 1540 | case CODEC_ID_GSM: |
| 1541 | 1541 | case CODEC_ID_ADPCM_MS: |
| 1542 | 1542 | case CODEC_ID_ADPCM_IMA_WAV: |
| 1543 | + case CODEC_ID_ILBC: | |
| 1543 | 1544 | st->codec->block_align = sc->bytes_per_frame; |
| 1544 | 1545 | break; |
| 1545 | 1546 | case CODEC_ID_ALAC: |
| @@ -3371,7 +3371,8 @@ static int mov_write_header(AVFormatContext *s) · 3370 unmodified lines | ||
| 3371 | 3371 | av_log(s, AV_LOG_WARNING, "track %d: codec frame size is not set\n", i); |
| 3372 | 3372 | track->audio_vbr = 1; |
| 3373 | 3373 | }else if(st->codec->codec_id == CODEC_ID_ADPCM_MS || |
| 3374 | − st->codec->codec_id == CODEC_ID_ADPCM_IMA_WAV){ | |
| 3374 | + st->codec->codec_id == CODEC_ID_ADPCM_IMA_WAV || | |
| 3375 | + st->codec->codec_id == CODEC_ID_ILBC){ | |
| 3375 | 3376 | if (!st->codec->block_align) { |
| 3376 | 3377 | av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i); |
| 3377 | 3378 | goto error; |
| @@ -19,8 +19,6 @@ · 18 unmodified lines | ||
| 19 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | −//#define USE_SYNCPOINT_SEARCH | |
| 23 | − | |
| 24 | 22 | #include "libavutil/crc.h" |
| 25 | 23 | #include "libavutil/intreadwrite.h" |
| 26 | 24 | #include "libavutil/log.h" |
| @@ -2161,92 +2159,6 @@ static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, · 2134 unmodified lines | ||
| 2161 | 2159 | return AV_NOPTS_VALUE; |
| 2162 | 2160 | } |
| 2163 | 2161 | |
| 2164 | −#ifdef USE_SYNCPOINT_SEARCH | |
| 2165 | − | |
| 2166 | −static int read_seek2(AVFormatContext *s, | |
| 2167 | − int stream_index, | |
| 2168 | − int64_t min_ts, | |
| 2169 | − int64_t target_ts, | |
| 2170 | − int64_t max_ts, | |
| 2171 | − int flags) | |
| 2172 | −{ | |
| 2173 | − int64_t pos; | |
| 2174 | − | |
| 2175 | − int64_t ts_ret, ts_adj; | |
| 2176 | − int stream_index_gen_search; | |
| 2177 | − AVStream *st; | |
| 2178 | − AVParserState *backup; | |
| 2179 | − | |
| 2180 | − backup = ff_store_parser_state(s); | |
| 2181 | − | |
| 2182 | − // detect direction of seeking for search purposes | |
| 2183 | − flags |= (target_ts - min_ts > (uint64_t)(max_ts - target_ts)) ? | |
| 2184 | − AVSEEK_FLAG_BACKWARD : 0; | |
| 2185 | − | |
| 2186 | − if (flags & AVSEEK_FLAG_BYTE) { | |
| 2187 | − // use position directly, we will search starting from it | |
| 2188 | − pos = target_ts; | |
| 2189 | − } else { | |
| 2190 | − // search for some position with good timestamp match | |
| 2191 | − if (stream_index < 0) { | |
| 2192 | − stream_index_gen_search = av_find_default_stream_index(s); | |
| 2193 | − if (stream_index_gen_search < 0) { | |
| 2194 | − ff_restore_parser_state(s, backup); | |
| 2195 | − return -1; | |
| 2196 | − } | |
| 2197 | − | |
| 2198 | − st = s->streams[stream_index_gen_search]; | |
| 2199 | − // timestamp for default must be expressed in AV_TIME_BASE units | |
| 2200 | − ts_adj = av_rescale(target_ts, | |
| 2201 | − st->time_base.den, | |
| 2202 | − AV_TIME_BASE * (int64_t)st->time_base.num); | |
| 2203 | − } else { | |
| 2204 | − ts_adj = target_ts; | |
| 2205 | − stream_index_gen_search = stream_index; | |
| 2206 | − } | |
| 2207 | − pos = ff_gen_search(s, stream_index_gen_search, ts_adj, | |
| 2208 | − 0, INT64_MAX, -1, | |
| 2209 | − AV_NOPTS_VALUE, | |
| 2210 | − AV_NOPTS_VALUE, | |
| 2211 | − flags, &ts_ret, mpegts_get_pcr); | |
| 2212 | − if (pos < 0) { | |
| 2213 | − ff_restore_parser_state(s, backup); | |
| 2214 | − return -1; | |
| 2215 | − } | |
| 2216 | − } | |
| 2217 | − | |
| 2218 | − // search for actual matching keyframe/starting position for all streams | |
| 2219 | − if (ff_gen_syncpoint_search(s, stream_index, pos, | |
| 2220 | − min_ts, target_ts, max_ts, | |
| 2221 | − flags) < 0) { | |
| 2222 | − ff_restore_parser_state(s, backup); | |
| 2223 | − return -1; | |
| 2224 | − } | |
| 2225 | − | |
| 2226 | − ff_free_parser_state(s, backup); | |
| 2227 | − return 0; | |
| 2228 | −} | |
| 2229 | − | |
| 2230 | −static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags) | |
| 2231 | −{ | |
| 2232 | − int ret; | |
| 2233 | − if (flags & AVSEEK_FLAG_BACKWARD) { | |
| 2234 | − flags &= ~AVSEEK_FLAG_BACKWARD; | |
| 2235 | − ret = read_seek2(s, stream_index, INT64_MIN, target_ts, target_ts, flags); | |
| 2236 | − if (ret < 0) | |
| 2237 | − // for compatibility reasons, seek to the best-fitting timestamp | |
| 2238 | − ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags); | |
| 2239 | − } else { | |
| 2240 | − ret = read_seek2(s, stream_index, target_ts, target_ts, INT64_MAX, flags); | |
| 2241 | − if (ret < 0) | |
| 2242 | − // for compatibility reasons, seek to the best-fitting timestamp | |
| 2243 | − ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags); | |
| 2244 | − } | |
| 2245 | − return ret; | |
| 2246 | −} | |
| 2247 | − | |
| 2248 | −#endif | |
| 2249 | − | |
| 2250 | 2162 | /**************************************************************/ |
| 2251 | 2163 | /* parsing functions - called from other demuxers such as RTP */ |
| 2252 | 2164 | |
| @@ -2313,9 +2225,6 @@ AVInputFormat ff_mpegts_demuxer = { · 60 unmodified lines | ||
| 2313 | 2225 | .read_close = mpegts_read_close, |
| 2314 | 2226 | .read_timestamp = mpegts_get_dts, |
| 2315 | 2227 | .flags = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT, |
| 2316 | −#ifdef USE_SYNCPOINT_SEARCH | |
| 2317 | − .read_seek2 = read_seek2, | |
| 2318 | −#endif | |
| 2319 | 2228 | }; |
| 2320 | 2229 | |
| 2321 | 2230 | AVInputFormat ff_mpegtsraw_demuxer = { |
| @@ -2327,8 +2236,5 @@ AVInputFormat ff_mpegtsraw_demuxer = { · 5 unmodified lines | ||
| 2327 | 2236 | .read_close = mpegts_read_close, |
| 2328 | 2237 | .read_timestamp = mpegts_get_dts, |
| 2329 | 2238 | .flags = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT, |
| 2330 | −#ifdef USE_SYNCPOINT_SEARCH | |
| 2331 | − .read_seek2 = read_seek2, | |
| 2332 | −#endif | |
| 2333 | 2239 | .priv_class = &mpegtsraw_class, |
| 2334 | 2240 | }; |
| @@ -76,6 +76,7 @@ typedef struct RTMPContext { · 75 unmodified lines | ||
| 76 | 76 | uint8_t* flv_data; ///< buffer with data for demuxer |
| 77 | 77 | int flv_size; ///< current buffer size |
| 78 | 78 | int flv_off; ///< number of bytes read from current buffer |
| 79 | + int flv_nb_packets; ///< number of flv packets published | |
| 79 | 80 | RTMPPacket out_pkt; ///< rtmp packet, created from flv a/v or metadata (for output) |
| 80 | 81 | uint32_t client_report_size; ///< number of bytes after which client should report to server |
| 81 | 82 | uint32_t bytes_read; ///< number of bytes read from server |
| @@ -90,6 +91,7 @@ typedef struct RTMPContext { · 8 unmodified lines | ||
| 90 | 91 | char* swfurl; ///< url of the swf player |
| 91 | 92 | int server_bw; ///< server bandwidth |
| 92 | 93 | int client_buffer_time; ///< client buffer time in ms |
| 94 | + int flush_interval; ///< number of packets flushed in the same request (RTMPT only) | |
| 93 | 95 | } RTMPContext; |
| 94 | 96 | |
| 95 | 97 | #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing |
| @@ -1361,9 +1363,14 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) · 1265 unmodified lines | ||
| 1361 | 1363 | rt->flv_size = 0; |
| 1362 | 1364 | rt->flv_off = 0; |
| 1363 | 1365 | rt->flv_header_bytes = 0; |
| 1366 | + rt->flv_nb_packets++; | |
| 1364 | 1367 | } |
| 1365 | 1368 | } while (buf_temp - buf < size); |
| 1366 | 1369 | |
| 1370 | + if (rt->flv_nb_packets < rt->flush_interval) | |
| 1371 | + return size; | |
| 1372 | + rt->flv_nb_packets = 0; | |
| 1373 | + | |
| 1367 | 1374 | /* set stream into nonblocking mode */ |
| 1368 | 1375 | rt->stream->flags |= AVIO_FLAG_NONBLOCK; |
| 1369 | 1376 | |
| @@ -1404,6 +1411,7 @@ static const AVOption rtmp_options[] = { · 34 unmodified lines | ||
| 1404 | 1411 | {"rtmp_buffer", "Set buffer time in milliseconds. The default is 3000.", OFFSET(client_buffer_time), AV_OPT_TYPE_INT, {3000}, 0, INT_MAX, DEC|ENC}, |
| 1405 | 1412 | {"rtmp_conn", "Append arbitrary AMF data to the Connect message", OFFSET(conn), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, |
| 1406 | 1413 | {"rtmp_flashver", "Version of the Flash plugin used to run the SWF player.", OFFSET(flashver), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, |
| 1414 | + {"rtmp_flush_interval", "Number of packets flushed in the same request (RTMPT only).", OFFSET(flush_interval), AV_OPT_TYPE_INT, {10}, 0, INT_MAX, ENC}, | |
| 1407 | 1415 | {"rtmp_live", "Specify that the media is a live stream.", OFFSET(live), AV_OPT_TYPE_INT, {-2}, INT_MIN, INT_MAX, DEC, "rtmp_live"}, |
| 1408 | 1416 | {"any", "both", 0, AV_OPT_TYPE_CONST, {-2}, 0, 0, DEC, "rtmp_live"}, |
| 1409 | 1417 | {"live", "live stream", 0, AV_OPT_TYPE_CONST, {-1}, 0, 0, DEC, "rtmp_live"}, |
| @@ -68,6 +68,7 @@ void av_register_rtp_dynamic_payload_handlers(void) · 67 unmodified lines | ||
| 68 | 68 | ff_register_dynamic_payload_handler(&ff_h263_2000_dynamic_handler); |
| 69 | 69 | ff_register_dynamic_payload_handler(&ff_h263_rfc2190_dynamic_handler); |
| 70 | 70 | ff_register_dynamic_payload_handler(&ff_h264_dynamic_handler); |
| 71 | + ff_register_dynamic_payload_handler(&ff_ilbc_dynamic_handler); | |
| 71 | 72 | ff_register_dynamic_payload_handler(&ff_vorbis_dynamic_handler); |
| 72 | 73 | ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler); |
| 73 | 74 | ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler); |
| @@ -45,6 +45,7 @@ extern RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler; · 44 unmodified lines | ||
| 45 | 45 | extern RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler; |
| 46 | 46 | extern RTPDynamicProtocolHandler ff_h263_rfc2190_dynamic_handler; |
| 47 | 47 | extern RTPDynamicProtocolHandler ff_h264_dynamic_handler; |
| 48 | +extern RTPDynamicProtocolHandler ff_ilbc_dynamic_handler; | |
| 48 | 49 | extern RTPDynamicProtocolHandler ff_mp4a_latm_dynamic_handler; |
| 49 | 50 | extern RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler; |
| 50 | 51 | extern RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler; |
| @@ -0,0 +1,73 @@ | ||
| 1 | +/* | |
| 2 | + * RTP iLBC Depacketizer, RFC 3952 | |
| 3 | + * Copyright (c) 2012 Martin Storsjo | |
| 4 | + * | |
| 5 | + * This file is part of FFmpeg. | |
| 6 | + * | |
| 7 | + * FFmpeg is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public | |
| 9 | + * License as published by the Free Software Foundation; either | |
| 10 | + * version 2.1 of the License, or (at your option) any later version. | |
| 11 | + * | |
| 12 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | + * Lesser General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU Lesser General Public | |
| 18 | + * License along with FFmpeg; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + */ | |
| 21 | + | |
| 22 | +#include "avformat.h" | |
| 23 | +#include "rtpdec_formats.h" | |
| 24 | +#include "libavutil/avstring.h" | |
| 25 | + | |
| 26 | +static int ilbc_parse_fmtp(AVStream *stream, PayloadContext *data, | |
| 27 | + char *attr, char *value) | |
| 28 | +{ | |
| 29 | + if (!strcmp(attr, "mode")) { | |
| 30 | + int mode = atoi(value); | |
| 31 | + switch (mode) { | |
| 32 | + case 20: | |
| 33 | + stream->codec->block_align = 38; | |
| 34 | + break; | |
| 35 | + case 30: | |
| 36 | + stream->codec->block_align = 50; | |
| 37 | + break; | |
| 38 | + default: | |
| 39 | + av_log(NULL, AV_LOG_ERROR, "Unsupported iLBC mode %d\n", mode); | |
| 40 | + return AVERROR(EINVAL); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + return 0; | |
| 44 | +} | |
| 45 | + | |
| 46 | +static int ilbc_parse_sdp_line(AVFormatContext *s, int st_index, | |
| 47 | + PayloadContext *data, const char *line) | |
| 48 | +{ | |
| 49 | + const char *p; | |
| 50 | + AVStream *st; | |
| 51 | + | |
| 52 | + if (st_index < 0) | |
| 53 | + return 0; | |
| 54 | + st = s->streams[st_index]; | |
| 55 | + | |
| 56 | + if (av_strstart(line, "fmtp:", &p)) { | |
| 57 | + int ret = ff_parse_fmtp(st, data, p, ilbc_parse_fmtp); | |
| 58 | + if (ret < 0) | |
| 59 | + return ret; | |
| 60 | + if (!st->codec->block_align) { | |
| 61 | + av_log(s, AV_LOG_ERROR, "No iLBC mode set\n"); | |
| 62 | + return AVERROR(EINVAL); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + return 0; | |
| 66 | +} | |
| 67 | + | |
| 68 | +RTPDynamicProtocolHandler ff_ilbc_dynamic_handler = { | |
| 69 | + .enc_name = "iLBC", | |
| 70 | + .codec_type = AVMEDIA_TYPE_AUDIO, | |
| 71 | + .codec_id = CODEC_ID_ILBC, | |
| 72 | + .parse_sdp_a_line = ilbc_parse_sdp_line, | |
| 73 | +}; | |
| @@ -74,6 +74,7 @@ static int is_supported(enum CodecID id) · 73 unmodified lines | ||
| 74 | 74 | case CODEC_ID_VP8: |
| 75 | 75 | case CODEC_ID_ADPCM_G722: |
| 76 | 76 | case CODEC_ID_ADPCM_G726: |
| 77 | + case CODEC_ID_ILBC: | |
| 77 | 78 | return 1; |
| 78 | 79 | default: |
| 79 | 80 | return 0; |
| @@ -187,6 +188,16 @@ static int rtp_write_header(AVFormatContext *s1) · 107 unmodified lines | ||
| 187 | 188 | * 8000, even if the sample rate is 16000. See RFC 3551. */ |
| 188 | 189 | avpriv_set_pts_info(st, 32, 1, 8000); |
| 189 | 190 | break; |
| 191 | + case CODEC_ID_ILBC: | |
| 192 | + if (st->codec->block_align != 38 && st->codec->block_align != 50) { | |
| 193 | + av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n"); | |
| 194 | + goto fail; | |
| 195 | + } | |
| 196 | + if (!s->max_frames_per_packet) | |
| 197 | + s->max_frames_per_packet = 1; | |
| 198 | + s->max_frames_per_packet = FFMIN(s->max_frames_per_packet, | |
| 199 | + s->max_payload_size / st->codec->block_align); | |
| 200 | + goto defaultcase; | |
| 190 | 201 | case CODEC_ID_AMR_NB: |
| 191 | 202 | case CODEC_ID_AMR_WB: |
| 192 | 203 | if (!s->max_frames_per_packet) |
| @@ -395,6 +406,36 @@ static void rtp_send_mpegts_raw(AVFormatContext *s1, · 202 unmodified lines | ||
| 395 | 406 | } |
| 396 | 407 | } |
| 397 | 408 | |
| 409 | +static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size) | |
| 410 | +{ | |
| 411 | + RTPMuxContext *s = s1->priv_data; | |
| 412 | + AVStream *st = s1->streams[0]; | |
| 413 | + int frame_duration = av_get_audio_frame_duration(st->codec, 0); | |
| 414 | + int frame_size = st->codec->block_align; | |
| 415 | + int frames = size / frame_size; | |
| 416 | + | |
| 417 | + while (frames > 0) { | |
| 418 | + int n = FFMIN(s->max_frames_per_packet - s->num_frames, frames); | |
| 419 | + | |
| 420 | + if (!s->num_frames) { | |
| 421 | + s->buf_ptr = s->buf; | |
| 422 | + s->timestamp = s->cur_timestamp; | |
| 423 | + } | |
| 424 | + memcpy(s->buf_ptr, buf, n * frame_size); | |
| 425 | + frames -= n; | |
| 426 | + s->num_frames += n; | |
| 427 | + s->buf_ptr += n * frame_size; | |
| 428 | + buf += n * frame_size; | |
| 429 | + s->cur_timestamp += n * frame_duration; | |
| 430 | + | |
| 431 | + if (s->num_frames == s->max_frames_per_packet) { | |
| 432 | + ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1); | |
| 433 | + s->num_frames = 0; | |
| 434 | + } | |
| 435 | + } | |
| 436 | + return 0; | |
| 437 | +} | |
| 438 | + | |
| 398 | 439 | static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) |
| 399 | 440 | { |
| 400 | 441 | RTPMuxContext *s = s1->priv_data; |
| @@ -483,6 +524,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) · 82 unmodified lines | ||
| 483 | 524 | case CODEC_ID_VP8: |
| 484 | 525 | ff_rtp_send_vp8(s1, pkt->data, size); |
| 485 | 526 | break; |
| 527 | + case CODEC_ID_ILBC: | |
| 528 | + rtp_send_ilbc(s1, pkt->data, size); | |
| 529 | + break; | |
| 486 | 530 | default: |
| 487 | 531 | /* better than nothing : send the codec raw data */ |
| 488 | 532 | rtp_send_raw(s1, pkt->data, size); |
| @@ -1279,7 +1279,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 1278 unmodified lines | ||
| 1279 | 1279 | "%s/UDP;multicast", trans_pref); |
| 1280 | 1280 | } |
| 1281 | 1281 | if (s->oformat) { |
| 1282 | − av_strlcat(transport, ";mode=receive", sizeof(transport)); | |
| 1282 | + av_strlcat(transport, ";mode=record", sizeof(transport)); | |
| 1283 | 1283 | } else if (rt->server_type == RTSP_SERVER_REAL || |
| 1284 | 1284 | rt->server_type == RTSP_SERVER_WMS) |
| 1285 | 1285 | av_strlcat(transport, ";mode=play", sizeof(transport)); |
| @@ -549,6 +549,12 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, · 548 unmodified lines | ||
| 549 | 549 | c->sample_rate); |
| 550 | 550 | break; |
| 551 | 551 | } |
| 552 | + case CODEC_ID_ILBC: | |
| 553 | + av_strlcatf(buff, size, "a=rtpmap:%d iLBC/%d\r\n" | |
| 554 | + "a=fmtp:%d mode=%d\r\n", | |
| 555 | + payload_type, c->sample_rate, | |
| 556 | + payload_type, c->block_align == 38 ? 20 : 30); | |
| 557 | + break; | |
| 552 | 558 | default: |
| 553 | 559 | /* Nothing special to do here... */ |
| 554 | 560 | break; |
| @@ -30,7 +30,7 @@ · 29 unmodified lines | ||
| 30 | 30 | #include "libavutil/avutil.h" |
| 31 | 31 | |
| 32 | 32 | #define LIBAVFORMAT_VERSION_MAJOR 54 |
| 33 | −#define LIBAVFORMAT_VERSION_MINOR 8 | |
| 33 | +#define LIBAVFORMAT_VERSION_MINOR 9 | |
| 34 | 34 | #define LIBAVFORMAT_VERSION_MICRO 100 |
| 35 | 35 | |
| 36 | 36 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | ;****************************************************************************** |
| 2 | 2 | ;* x86 optimized Format Conversion Utils |
| 3 | 3 | ;* Copyright (c) 2008 Loren Merritt |
| 4 | +;* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com> | |
| 4 | 5 | ;* |
| 5 | 6 | ;* This file is part of Libav. |
| 6 | 7 | ;* |
| @@ -21,9 +22,217 @@ · 14 unmodified lines | ||
| 21 | 22 | |
| 22 | 23 | %include "x86inc.asm" |
| 23 | 24 | %include "x86util.asm" |
| 25 | +%include "util.asm" | |
| 26 | + | |
| 27 | +SECTION_RODATA 32 | |
| 28 | + | |
| 29 | +pf_s32_inv_scale: times 8 dd 0x30000000 | |
| 30 | +pf_s32_scale: times 8 dd 0x4f000000 | |
| 31 | +pf_s16_inv_scale: times 4 dd 0x38000000 | |
| 32 | +pf_s16_scale: times 4 dd 0x47000000 | |
| 24 | 33 | |
| 25 | 34 | SECTION_TEXT |
| 26 | 35 | |
| 36 | +;------------------------------------------------------------------------------ | |
| 37 | +; void ff_conv_s16_to_s32(int32_t *dst, const int16_t *src, int len); | |
| 38 | +;------------------------------------------------------------------------------ | |
| 39 | + | |
| 40 | +INIT_XMM sse2 | |
| 41 | +cglobal conv_s16_to_s32, 3,3,3, dst, src, len | |
| 42 | + lea lenq, [2*lend] | |
| 43 | + lea dstq, [dstq+2*lenq] | |
| 44 | + add srcq, lenq | |
| 45 | + neg lenq | |
| 46 | +.loop: | |
| 47 | + mova m2, [srcq+lenq] | |
| 48 | + pxor m0, m0 | |
| 49 | + pxor m1, m1 | |
| 50 | + punpcklwd m0, m2 | |
| 51 | + punpckhwd m1, m2 | |
| 52 | + mova [dstq+2*lenq ], m0 | |
| 53 | + mova [dstq+2*lenq+mmsize], m1 | |
| 54 | + add lenq, mmsize | |
| 55 | + jl .loop | |
| 56 | + REP_RET | |
| 57 | + | |
| 58 | +;------------------------------------------------------------------------------ | |
| 59 | +; void ff_conv_s16_to_flt(float *dst, const int16_t *src, int len); | |
| 60 | +;------------------------------------------------------------------------------ | |
| 61 | + | |
| 62 | +%macro CONV_S16_TO_FLT 0 | |
| 63 | +cglobal conv_s16_to_flt, 3,3,3, dst, src, len | |
| 64 | + lea lenq, [2*lend] | |
| 65 | + add srcq, lenq | |
| 66 | + lea dstq, [dstq + 2*lenq] | |
| 67 | + neg lenq | |
| 68 | + mova m2, [pf_s16_inv_scale] | |
| 69 | + ALIGN 16 | |
| 70 | +.loop: | |
| 71 | + mova m0, [srcq+lenq] | |
| 72 | + S16_TO_S32_SX 0, 1 | |
| 73 | + cvtdq2ps m0, m0 | |
| 74 | + cvtdq2ps m1, m1 | |
| 75 | + mulps m0, m2 | |
| 76 | + mulps m1, m2 | |
| 77 | + mova [dstq+2*lenq ], m0 | |
| 78 | + mova [dstq+2*lenq+mmsize], m1 | |
| 79 | + add lenq, mmsize | |
| 80 | + jl .loop | |
| 81 | + REP_RET | |
| 82 | +%endmacro | |
| 83 | + | |
| 84 | +INIT_XMM sse2 | |
| 85 | +CONV_S16_TO_FLT | |
| 86 | +INIT_XMM sse4 | |
| 87 | +CONV_S16_TO_FLT | |
| 88 | + | |
| 89 | +;------------------------------------------------------------------------------ | |
| 90 | +; void ff_conv_s32_to_s16(int16_t *dst, const int32_t *src, int len); | |
| 91 | +;------------------------------------------------------------------------------ | |
| 92 | + | |
| 93 | +%macro CONV_S32_TO_S16 0 | |
| 94 | +cglobal conv_s32_to_s16, 3,3,4, dst, src, len | |
| 95 | + lea lenq, [2*lend] | |
| 96 | + lea srcq, [srcq+2*lenq] | |
| 97 | + add dstq, lenq | |
| 98 | + neg lenq | |
| 99 | +.loop: | |
| 100 | + mova m0, [srcq+2*lenq ] | |
| 101 | + mova m1, [srcq+2*lenq+ mmsize] | |
| 102 | + mova m2, [srcq+2*lenq+2*mmsize] | |
| 103 | + mova m3, [srcq+2*lenq+3*mmsize] | |
| 104 | + psrad m0, 16 | |
| 105 | + psrad m1, 16 | |
| 106 | + psrad m2, 16 | |
| 107 | + psrad m3, 16 | |
| 108 | + packssdw m0, m1 | |
| 109 | + packssdw m2, m3 | |
| 110 | + mova [dstq+lenq ], m0 | |
| 111 | + mova [dstq+lenq+mmsize], m2 | |
| 112 | + add lenq, mmsize*2 | |
| 113 | + jl .loop | |
| 114 | +%if mmsize == 8 | |
| 115 | + emms | |
| 116 | + RET | |
| 117 | +%else | |
| 118 | + REP_RET | |
| 119 | +%endif | |
| 120 | +%endmacro | |
| 121 | + | |
| 122 | +INIT_MMX mmx | |
| 123 | +CONV_S32_TO_S16 | |
| 124 | +INIT_XMM sse2 | |
| 125 | +CONV_S32_TO_S16 | |
| 126 | + | |
| 127 | +;------------------------------------------------------------------------------ | |
| 128 | +; void ff_conv_s32_to_flt(float *dst, const int32_t *src, int len); | |
| 129 | +;------------------------------------------------------------------------------ | |
| 130 | + | |
| 131 | +%macro CONV_S32_TO_FLT 0 | |
| 132 | +cglobal conv_s32_to_flt, 3,3,3, dst, src, len | |
| 133 | + lea lenq, [4*lend] | |
| 134 | + add srcq, lenq | |
| 135 | + add dstq, lenq | |
| 136 | + neg lenq | |
| 137 | + mova m0, [pf_s32_inv_scale] | |
| 138 | + ALIGN 16 | |
| 139 | +.loop: | |
| 140 | + cvtdq2ps m1, [srcq+lenq ] | |
| 141 | + cvtdq2ps m2, [srcq+lenq+mmsize] | |
| 142 | + mulps m1, m1, m0 | |
| 143 | + mulps m2, m2, m0 | |
| 144 | + mova [dstq+lenq ], m1 | |
| 145 | + mova [dstq+lenq+mmsize], m2 | |
| 146 | + add lenq, mmsize*2 | |
| 147 | + jl .loop | |
| 148 | +%if mmsize == 32 | |
| 149 | + vzeroupper | |
| 150 | + RET | |
| 151 | +%else | |
| 152 | + REP_RET | |
| 153 | +%endif | |
| 154 | +%endmacro | |
| 155 | + | |
| 156 | +INIT_XMM sse2 | |
| 157 | +CONV_S32_TO_FLT | |
| 158 | +%if HAVE_AVX | |
| 159 | +INIT_YMM avx | |
| 160 | +CONV_S32_TO_FLT | |
| 161 | +%endif | |
| 162 | + | |
| 163 | +;------------------------------------------------------------------------------ | |
| 164 | +; void ff_conv_flt_to_s16(int16_t *dst, const float *src, int len); | |
| 165 | +;------------------------------------------------------------------------------ | |
| 166 | + | |
| 167 | +INIT_XMM sse2 | |
| 168 | +cglobal conv_flt_to_s16, 3,3,5, dst, src, len | |
| 169 | + lea lenq, [2*lend] | |
| 170 | + lea srcq, [srcq+2*lenq] | |
| 171 | + add dstq, lenq | |
| 172 | + neg lenq | |
| 173 | + mova m4, [pf_s16_scale] | |
| 174 | +.loop: | |
| 175 | + mova m0, [srcq+2*lenq ] | |
| 176 | + mova m1, [srcq+2*lenq+1*mmsize] | |
| 177 | + mova m2, [srcq+2*lenq+2*mmsize] | |
| 178 | + mova m3, [srcq+2*lenq+3*mmsize] | |
| 179 | + mulps m0, m4 | |
| 180 | + mulps m1, m4 | |
| 181 | + mulps m2, m4 | |
| 182 | + mulps m3, m4 | |
| 183 | + cvtps2dq m0, m0 | |
| 184 | + cvtps2dq m1, m1 | |
| 185 | + cvtps2dq m2, m2 | |
| 186 | + cvtps2dq m3, m3 | |
| 187 | + packssdw m0, m1 | |
| 188 | + packssdw m2, m3 | |
| 189 | + mova [dstq+lenq ], m0 | |
| 190 | + mova [dstq+lenq+mmsize], m2 | |
| 191 | + add lenq, mmsize*2 | |
| 192 | + jl .loop | |
| 193 | + REP_RET | |
| 194 | + | |
| 195 | +;------------------------------------------------------------------------------ | |
| 196 | +; void ff_conv_flt_to_s32(int32_t *dst, const float *src, int len); | |
| 197 | +;------------------------------------------------------------------------------ | |
| 198 | + | |
| 199 | +%macro CONV_FLT_TO_S32 0 | |
| 200 | +cglobal conv_flt_to_s32, 3,3,5, dst, src, len | |
| 201 | + lea lenq, [lend*4] | |
| 202 | + add srcq, lenq | |
| 203 | + add dstq, lenq | |
| 204 | + neg lenq | |
| 205 | + mova m4, [pf_s32_scale] | |
| 206 | +.loop: | |
| 207 | + mulps m0, m4, [srcq+lenq ] | |
| 208 | + mulps m1, m4, [srcq+lenq+1*mmsize] | |
| 209 | + mulps m2, m4, [srcq+lenq+2*mmsize] | |
| 210 | + mulps m3, m4, [srcq+lenq+3*mmsize] | |
| 211 | + cvtps2dq m0, m0 | |
| 212 | + cvtps2dq m1, m1 | |
| 213 | + cvtps2dq m2, m2 | |
| 214 | + cvtps2dq m3, m3 | |
| 215 | + mova [dstq+lenq ], m0 | |
| 216 | + mova [dstq+lenq+1*mmsize], m1 | |
| 217 | + mova [dstq+lenq+2*mmsize], m2 | |
| 218 | + mova [dstq+lenq+3*mmsize], m3 | |
| 219 | + add lenq, mmsize*4 | |
| 220 | + jl .loop | |
| 221 | +%if mmsize == 32 | |
| 222 | + vzeroupper | |
| 223 | + RET | |
| 224 | +%else | |
| 225 | + REP_RET | |
| 226 | +%endif | |
| 227 | +%endmacro | |
| 228 | + | |
| 229 | +INIT_XMM sse2 | |
| 230 | +CONV_FLT_TO_S32 | |
| 231 | +%if HAVE_AVX | |
| 232 | +INIT_YMM avx | |
| 233 | +CONV_FLT_TO_S32 | |
| 234 | +%endif | |
| 235 | + | |
| 27 | 236 | ;----------------------------------------------------------------------------- |
| 28 | 237 | ; void ff_conv_fltp_to_flt_6ch(float *dst, float *const *src, int len, |
| 29 | 238 | ; int channels); |
| @@ -22,6 +22,22 @@ · 21 unmodified lines | ||
| 22 | 22 | #include "libavutil/cpu.h" |
| 23 | 23 | #include "libavresample/audio_convert.h" |
| 24 | 24 | |
| 25 | +extern void ff_conv_s16_to_s32_sse2(int16_t *dst, const int32_t *src, int len); | |
| 26 | + | |
| 27 | +extern void ff_conv_s16_to_flt_sse2(float *dst, const int16_t *src, int len); | |
| 28 | +extern void ff_conv_s16_to_flt_sse4(float *dst, const int16_t *src, int len); | |
| 29 | + | |
| 30 | +extern void ff_conv_s32_to_s16_mmx (int16_t *dst, const int32_t *src, int len); | |
| 31 | +extern void ff_conv_s32_to_s16_sse2(int16_t *dst, const int32_t *src, int len); | |
| 32 | + | |
| 33 | +extern void ff_conv_s32_to_flt_sse2(float *dst, const int32_t *src, int len); | |
| 34 | +extern void ff_conv_s32_to_flt_avx (float *dst, const int32_t *src, int len); | |
| 35 | + | |
| 36 | +extern void ff_conv_flt_to_s16_sse2(int16_t *dst, const float *src, int len); | |
| 37 | + | |
| 38 | +extern void ff_conv_flt_to_s32_sse2(int32_t *dst, const float *src, int len); | |
| 39 | +extern void ff_conv_flt_to_s32_avx (int32_t *dst, const float *src, int len); | |
| 40 | + | |
| 25 | 41 | extern void ff_conv_fltp_to_flt_6ch_mmx (float *dst, float *const *src, int len); |
| 26 | 42 | extern void ff_conv_fltp_to_flt_6ch_sse4(float *dst, float *const *src, int len); |
| 27 | 43 | extern void ff_conv_fltp_to_flt_6ch_avx (float *dst, float *const *src, int len); |
| @@ -32,6 +48,8 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac) · 4 unmodified lines | ||
| 32 | 48 | int mm_flags = av_get_cpu_flags(); |
| 33 | 49 | |
| 34 | 50 | if (mm_flags & AV_CPU_FLAG_MMX && HAVE_MMX) { |
| 51 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, | |
| 52 | + 0, 1, 8, "MMX", ff_conv_s32_to_s16_mmx); | |
| 35 | 53 | ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, |
| 36 | 54 | 6, 1, 4, "MMX", ff_conv_fltp_to_flt_6ch_mmx); |
| 37 | 55 | } |
| @@ -43,5 +61,31 @@ av_cold void ff_audio_convert_init_x86(AudioConvert *ac) · 5 unmodified lines | ||
| 43 | 61 | ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, |
| 44 | 62 | 6, 16, 4, "AVX", ff_conv_fltp_to_flt_6ch_avx); |
| 45 | 63 | } |
| 64 | + if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) { | |
| 65 | + if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) { | |
| 66 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, | |
| 67 | + 0, 16, 16, "SSE2", ff_conv_s32_to_s16_sse2); | |
| 68 | + } | |
| 69 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16, | |
| 70 | + 0, 16, 8, "SSE2", ff_conv_s16_to_s32_sse2); | |
| 71 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, | |
| 72 | + 0, 16, 8, "SSE2", ff_conv_s16_to_flt_sse2); | |
| 73 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32, | |
| 74 | + 0, 16, 8, "SSE2", ff_conv_s32_to_flt_sse2); | |
| 75 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT, | |
| 76 | + 0, 16, 16, "SSE2", ff_conv_flt_to_s16_sse2); | |
| 77 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT, | |
| 78 | + 0, 16, 16, "SSE2", ff_conv_flt_to_s32_sse2); | |
| 79 | + } | |
| 80 | + if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) { | |
| 81 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, | |
| 82 | + 0, 16, 8, "SSE4", ff_conv_s16_to_flt_sse4); | |
| 83 | + } | |
| 84 | + if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) { | |
| 85 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32, | |
| 86 | + 0, 32, 16, "AVX", ff_conv_s32_to_flt_avx); | |
| 87 | + ff_audio_convert_set_func(ac, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT, | |
| 88 | + 0, 32, 32, "AVX", ff_conv_flt_to_s32_avx); | |
| 89 | + } | |
| 46 | 90 | #endif |
| 47 | 91 | } |
| @@ -26,7 +26,11 @@ · 25 unmodified lines | ||
| 26 | 26 | |
| 27 | 27 | void ff_vector_fmul_neon(float *dst, const float *src0, const float *src1, int len); |
| 28 | 28 | |
| 29 | +void ff_vector_fmac_scalar_neon(float *dst, const float *src, float mul, | |
| 30 | + int len); | |
| 31 | + | |
| 29 | 32 | void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp) |
| 30 | 33 | { |
| 31 | 34 | fdsp->vector_fmul = ff_vector_fmul_neon; |
| 35 | + fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_neon; | |
| 32 | 36 | } |
| @@ -62,3 +62,51 @@ function ff_vector_fmul_neon, export=1 · 61 unmodified lines | ||
| 62 | 62 | 3: vst1.32 {d16-d19},[r0,:128]! |
| 63 | 63 | bx lr |
| 64 | 64 | endfunc |
| 65 | + | |
| 66 | +function ff_vector_fmac_scalar_neon, export=1 | |
| 67 | +VFP len .req r2 | |
| 68 | +VFP acc .req r3 | |
| 69 | +NOVFP len .req r3 | |
| 70 | +NOVFP acc .req r2 | |
| 71 | +VFP vdup.32 q15, d0[0] | |
| 72 | +NOVFP vdup.32 q15, r2 | |
| 73 | + bics r12, len, #15 | |
| 74 | + mov acc, r0 | |
| 75 | + beq 3f | |
| 76 | + vld1.32 {q0}, [r1,:128]! | |
| 77 | + vld1.32 {q8}, [acc,:128]! | |
| 78 | + vld1.32 {q1}, [r1,:128]! | |
| 79 | + vld1.32 {q9}, [acc,:128]! | |
| 80 | +1: vmla.f32 q8, q0, q15 | |
| 81 | + vld1.32 {q2}, [r1,:128]! | |
| 82 | + vld1.32 {q10}, [acc,:128]! | |
| 83 | + vmla.f32 q9, q1, q15 | |
| 84 | + vld1.32 {q3}, [r1,:128]! | |
| 85 | + vld1.32 {q11}, [acc,:128]! | |
| 86 | + vmla.f32 q10, q2, q15 | |
| 87 | + vst1.32 {q8}, [r0,:128]! | |
| 88 | + vmla.f32 q11, q3, q15 | |
| 89 | + vst1.32 {q9}, [r0,:128]! | |
| 90 | + subs r12, r12, #16 | |
| 91 | + beq 2f | |
| 92 | + vld1.32 {q0}, [r1,:128]! | |
| 93 | + vld1.32 {q8}, [acc,:128]! | |
| 94 | + vst1.32 {q10}, [r0,:128]! | |
| 95 | + vld1.32 {q1}, [r1,:128]! | |
| 96 | + vld1.32 {q9}, [acc,:128]! | |
| 97 | + vst1.32 {q11}, [r0,:128]! | |
| 98 | + b 1b | |
| 99 | +2: vst1.32 {q10}, [r0,:128]! | |
| 100 | + vst1.32 {q11}, [r0,:128]! | |
| 101 | + ands len, len, #15 | |
| 102 | + it eq | |
| 103 | + bxeq lr | |
| 104 | +3: vld1.32 {q0}, [r1,:128]! | |
| 105 | + vld1.32 {q8}, [acc,:128]! | |
| 106 | + vmla.f32 q8, q0, q15 | |
| 107 | + vst1.32 {q8}, [r0,:128]! | |
| 108 | + subs len, len, #4 | |
| 109 | + bgt 3b | |
| 110 | + bx lr | |
| 111 | + .unreq len | |
| 112 | +endfunc | |
| @@ -31,9 +31,18 @@ static void vector_fmul_c(float *dst, const float *src0, const float *src1, · 30 unmodified lines | ||
| 31 | 31 | dst[i] = src0[i] * src1[i]; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | +static void vector_fmac_scalar_c(float *dst, const float *src, float mul, | |
| 35 | + int len) | |
| 36 | +{ | |
| 37 | + int i; | |
| 38 | + for (i = 0; i < len; i++) | |
| 39 | + dst[i] += src[i] * mul; | |
| 40 | +} | |
| 41 | + | |
| 34 | 42 | void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact) |
| 35 | 43 | { |
| 36 | 44 | fdsp->vector_fmul = vector_fmul_c; |
| 45 | + fdsp->vector_fmac_scalar = vector_fmac_scalar_c; | |
| 37 | 46 | |
| 38 | 47 | #if ARCH_ARM |
| 39 | 48 | ff_float_dsp_init_arm(fdsp); |
| @@ -35,6 +35,22 @@ typedef struct AVFloatDSPContext { · 34 unmodified lines | ||
| 35 | 35 | */ |
| 36 | 36 | void (*vector_fmul)(float *dst, const float *src0, const float *src1, |
| 37 | 37 | int len); |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Multiply a vector of floats by a scalar float and add to | |
| 41 | + * destination vector. Source and destination vectors must | |
| 42 | + * overlap exactly or not at all. | |
| 43 | + * | |
| 44 | + * @param dst result vector | |
| 45 | + * constraints: 32-byte aligned | |
| 46 | + * @param src input vector | |
| 47 | + * constraints: 32-byte aligned | |
| 48 | + * @param mul scalar value | |
| 49 | + * @param len length of vector | |
| 50 | + * constraints: multiple of 16 | |
| 51 | + */ | |
| 52 | + void (*vector_fmac_scalar)(float *dst, const float *src, float mul, | |
| 53 | + int len); | |
| 38 | 54 | } AVFloatDSPContext; |
| 39 | 55 | |
| 40 | 56 | /** |
| @@ -94,6 +94,8 @@ void *av_malloc(size_t size) · 93 unmodified lines | ||
| 94 | 94 | if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation |
| 95 | 95 | if (posix_memalign(&ptr,ALIGN,size)) |
| 96 | 96 | ptr = NULL; |
| 97 | +#elif HAVE_ALIGNED_MALLOC | |
| 98 | + ptr = _aligned_malloc(size, ALIGN); | |
| 97 | 99 | #elif HAVE_MEMALIGN |
| 98 | 100 | ptr = memalign(ALIGN,size); |
| 99 | 101 | /* Why 64? |
| @@ -145,6 +147,8 @@ void *av_realloc(void *ptr, size_t size) · 45 unmodified lines | ||
| 145 | 147 | ptr= realloc((char*)ptr - diff, size + diff); |
| 146 | 148 | if(ptr) ptr = (char*)ptr + diff; |
| 147 | 149 | return ptr; |
| 150 | +#elif HAVE_ALIGNED_MALLOC | |
| 151 | + return _aligned_realloc(ptr, size + !size, ALIGN); | |
| 148 | 152 | #else |
| 149 | 153 | return realloc(ptr, size + !size); |
| 150 | 154 | #endif |
| @@ -170,6 +174,8 @@ void av_free(void *ptr) · 19 unmodified lines | ||
| 170 | 174 | #if CONFIG_MEMALIGN_HACK |
| 171 | 175 | if (ptr) |
| 172 | 176 | free((char*)ptr - ((char*)ptr)[-1]); |
| 177 | +#elif HAVE_ALIGNED_MALLOC | |
| 178 | + _aligned_free(ptr); | |
| 173 | 179 | #else |
| 174 | 180 | free(ptr); |
| 175 | 181 | #endif |
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | ;****************************************************************************** |
| 22 | 22 | |
| 23 | 23 | %include "x86inc.asm" |
| 24 | +%include "x86util.asm" | |
| 24 | 25 | |
| 25 | 26 | SECTION .text |
| 26 | 27 | |
| @@ -55,3 +56,49 @@ VECTOR_FMUL · 28 unmodified lines | ||
| 55 | 56 | INIT_YMM avx |
| 56 | 57 | VECTOR_FMUL |
| 57 | 58 | %endif |
| 59 | + | |
| 60 | +;------------------------------------------------------------------------------ | |
| 61 | +; void ff_vector_fmac_scalar(float *dst, const float *src, float mul, int len) | |
| 62 | +;------------------------------------------------------------------------------ | |
| 63 | + | |
| 64 | +%macro VECTOR_FMAC_SCALAR 0 | |
| 65 | +%if UNIX64 | |
| 66 | +cglobal vector_fmac_scalar, 3,3,3, dst, src, len | |
| 67 | +%else | |
| 68 | +cglobal vector_fmac_scalar, 4,4,3, dst, src, mul, len | |
| 69 | +%endif | |
| 70 | +%if WIN64 | |
| 71 | + SWAP 0, 2 | |
| 72 | +%endif | |
| 73 | +%if ARCH_X86_32 | |
| 74 | + VBROADCASTSS m0, mulm | |
| 75 | +%else | |
| 76 | + shufps xmm0, xmm0, 0 | |
| 77 | +%if cpuflag(avx) | |
| 78 | + vinsertf128 m0, m0, xmm0, 1 | |
| 79 | +%endif | |
| 80 | +%endif | |
| 81 | + lea lenq, [lend*4-2*mmsize] | |
| 82 | +.loop | |
| 83 | + mulps m1, m0, [srcq+lenq ] | |
| 84 | + mulps m2, m0, [srcq+lenq+mmsize] | |
| 85 | + addps m1, m1, [dstq+lenq ] | |
| 86 | + addps m2, m2, [dstq+lenq+mmsize] | |
| 87 | + mova [dstq+lenq ], m1 | |
| 88 | + mova [dstq+lenq+mmsize], m2 | |
| 89 | + sub lenq, 2*mmsize | |
| 90 | + jge .loop | |
| 91 | +%if mmsize == 32 | |
| 92 | + vzeroupper | |
| 93 | + RET | |
| 94 | +%else | |
| 95 | + REP_RET | |
| 96 | +%endif | |
| 97 | +%endmacro | |
| 98 | + | |
| 99 | +INIT_XMM sse | |
| 100 | +VECTOR_FMAC_SCALAR | |
| 101 | +%if HAVE_AVX | |
| 102 | +INIT_YMM avx | |
| 103 | +VECTOR_FMAC_SCALAR | |
| 104 | +%endif | |
| @@ -26,6 +26,11 @@ extern void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1, · 25 unmodified lines | ||
| 26 | 26 | extern void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1, |
| 27 | 27 | int len); |
| 28 | 28 | |
| 29 | +extern void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul, | |
| 30 | + int len); | |
| 31 | +extern void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul, | |
| 32 | + int len); | |
| 33 | + | |
| 29 | 34 | void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp) |
| 30 | 35 | { |
| 31 | 36 | #if HAVE_YASM |
| @@ -33,9 +38,11 @@ void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp) · 1 unmodified line | ||
| 33 | 38 | |
| 34 | 39 | if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) { |
| 35 | 40 | fdsp->vector_fmul = ff_vector_fmul_sse; |
| 41 | + fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse; | |
| 36 | 42 | } |
| 37 | 43 | if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) { |
| 38 | 44 | fdsp->vector_fmul = ff_vector_fmul_avx; |
| 45 | + fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx; | |
| 39 | 46 | } |
| 40 | 47 | #endif |
| 41 | 48 | } |