From 6f72441120098d0adaca1e063b62bcf4e83f0d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 11 Dec 2012 16:03:33 +0200 Subject: [PATCH 1/3] rtpdec_vp8: Request a keyframe if RTP packets are lost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtpdec_vp8.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c index 13efa54421..96a1a3407e 100644 --- a/libavformat/rtpdec_vp8.c +++ b/libavformat/rtpdec_vp8.c @@ -35,11 +35,21 @@ struct PayloadContext { AVIOContext *data; uint32_t timestamp; int is_keyframe; + /* If sequence_ok is set, we keep returning data (even if we might have + * lost some data, but we haven't lost any too critical data that would + * cause the decoder to desynchronize and output random garbage). + */ int sequence_ok; int first_part_size; uint16_t prev_seq; int prev_pictureid; int broken_frame; + /* If sequence_dirty is set, we have lost some data (critical or + * non-critical) and decoding will have some sort of artefacts, and + * we thus should request a new keyframe. + */ + int sequence_dirty; + int got_keyframe; }; static void vp8_free_buffer(PayloadContext *vp8) @@ -141,11 +151,15 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, vp8_free_buffer(vp8); // Keyframe, decoding ok again vp8->sequence_ok = 1; + vp8->sequence_dirty = 0; + vp8->got_keyframe = 1; } else { int can_continue = vp8->data && !vp8->is_keyframe && avio_tell(vp8->data) >= vp8->first_part_size; if (!vp8->sequence_ok) return AVERROR(EAGAIN); + if (!vp8->got_keyframe) + return vp8_broken_sequence(ctx, vp8, "Keyframe missing\n"); if (pictureid >= 0) { if (pictureid != ((vp8->prev_pictureid + 1) & pictureid_mask)) { return vp8_broken_sequence(ctx, vp8, @@ -179,6 +193,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, } } if (vp8->data) { + vp8->sequence_dirty = 1; if (avio_tell(vp8->data) >= vp8->first_part_size) { int ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index); if (ret < 0) @@ -220,6 +235,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, "Missed part of a keyframe, sequence broken\n"); } else if (vp8->data && avio_tell(vp8->data) >= vp8->first_part_size) { vp8->broken_frame = 1; + vp8->sequence_dirty = 1; } else { return vp8_broken_sequence(ctx, vp8, "Missed part of the first partition, sequence broken\n"); @@ -253,7 +269,11 @@ static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, static PayloadContext *vp8_new_context(void) { - return av_mallocz(sizeof(PayloadContext)); + PayloadContext *vp8 = av_mallocz(sizeof(PayloadContext)); + if (!vp8) + return NULL; + vp8->sequence_ok = 1; + return vp8; } static void vp8_free_context(PayloadContext *vp8) @@ -262,6 +282,11 @@ static void vp8_free_context(PayloadContext *vp8) av_free(vp8); } +static int vp8_need_keyframe(PayloadContext *vp8) +{ + return vp8->sequence_dirty || !vp8->sequence_ok; +} + RTPDynamicProtocolHandler ff_vp8_dynamic_handler = { .enc_name = "VP8", .codec_type = AVMEDIA_TYPE_VIDEO, @@ -269,4 +294,5 @@ RTPDynamicProtocolHandler ff_vp8_dynamic_handler = { .alloc = vp8_new_context, .free = vp8_free_context, .parse_packet = vp8_handle_packet, + .need_keyframe = vp8_need_keyframe, }; From 142c39097c306d84624107070622f78c61981fc6 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 7 Jan 2013 22:04:30 -0500 Subject: [PATCH 2/3] doc/APIchanges: fill in missing dates and hashes. --- doc/APIchanges | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 5076e5d813..6e212dacfa 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,35 +13,35 @@ libavutil: 2012-10-22 API changes, most recent first: -2013-xx-xx - xxxxxxx - lavr 1.1.0 +2013-01-07 - 074a00d - lavr 1.1.0 Add avresample_set_channel_mapping() for input channel reordering, duplication, and silencing. -2012-xx-xx - xxxxxxx - lavu 52.2.1 - avstring.h +2012-12-29 - d8fd06c - lavu 52.2.1 - avstring.h Add av_basename() and av_dirname(). -2012-xx-xx - xxxxxxx - lavu 52.2.0 - audioconvert.h +2012-11-11 - 5980f5d - lavu 52.2.0 - audioconvert.h Rename audioconvert.h to channel_layout.h. audioconvert.h is now deprecated. -2012-xx-xx - xxxxxxx - lavu 52.1.0 - intmath.h +2012-11-05 - dfde8a3 - lavu 52.1.0 - intmath.h Add av_ctz() for trailing zero bit count -2012-10-18 - xxxxxxx - lavu 51.45.0 - error.h +2012-10-21 - a893655 - lavu 51.45.0 - error.h Add AVERROR_EXPERIMENTAL -2012-10-12 - xxxxxxx - lavu 51.44.0 - pixdesc.h +2012-10-12 - d2fcb35 - lavu 51.44.0 - pixdesc.h Add functions for accessing pixel format descriptors. Accessing the av_pix_fmt_descriptors array directly is now deprecated. -2012-10-xx - xxxxxxx - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h +2012-10-11 - 9a92aea - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h Add functions for allocating the opaque contexts for the algorithms, deprecate the context size variables. -2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h +2012-10-10 - b522000 - lavf 54.18.0 - avio.h Add avio_closep to complement avio_close. -2012-10-xx - xxxxxxx - lavu 51.42.0 - pixfmt.h +2012-10-08 - 78071a1 - lavu 51.42.0 - pixfmt.h Rename PixelFormat to AVPixelFormat and all PIX_FMT_* to AV_PIX_FMT_*. To provide backwards compatibility, PixelFormat is now #defined as AVPixelFormat. From 1fb8f6a44f06e48386450fe0363aefc02583d24a Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 31 Oct 2012 15:40:12 -0400 Subject: [PATCH 3/3] x86: lavr: add SSE2 quantize() for dithering --- libavresample/dither.c | 3 ++ libavresample/dither.h | 5 ++++ libavresample/x86/Makefile | 2 ++ libavresample/x86/dither.asm | 53 +++++++++++++++++++++++++++++++++ libavresample/x86/dither_init.c | 39 ++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 libavresample/x86/dither.asm create mode 100644 libavresample/x86/dither_init.c diff --git a/libavresample/dither.c b/libavresample/dither.c index dfff03e756..f24bf5c765 100644 --- a/libavresample/dither.c +++ b/libavresample/dither.c @@ -336,6 +336,9 @@ static void dither_init(DitherDSPContext *ddsp, ddsp->dither_int_to_float = dither_int_to_float_rectangular_c; else ddsp->dither_int_to_float = dither_int_to_float_triangular_c; + + if (ARCH_X86) + ff_dither_init_x86(ddsp, method); } DitherContext *ff_dither_alloc(AVAudioResampleContext *avr, diff --git a/libavresample/dither.h b/libavresample/dither.h index d6a7d3ea8d..8db37146fa 100644 --- a/libavresample/dither.h +++ b/libavresample/dither.h @@ -85,4 +85,9 @@ void ff_dither_free(DitherContext **c); */ int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src); +/* arch-specific initialization functions */ + +void ff_dither_init_x86(DitherDSPContext *ddsp, + enum AVResampleDitherMethod method); + #endif /* AVRESAMPLE_DITHER_H */ diff --git a/libavresample/x86/Makefile b/libavresample/x86/Makefile index 65bed899ba..2e8786fb90 100644 --- a/libavresample/x86/Makefile +++ b/libavresample/x86/Makefile @@ -1,5 +1,7 @@ OBJS += x86/audio_convert_init.o \ x86/audio_mix_init.o \ + x86/dither_init.o \ YASM-OBJS += x86/audio_convert.o \ x86/audio_mix.o \ + x86/dither.o \ diff --git a/libavresample/x86/dither.asm b/libavresample/x86/dither.asm new file mode 100644 index 0000000000..34e7924291 --- /dev/null +++ b/libavresample/x86/dither.asm @@ -0,0 +1,53 @@ +;****************************************************************************** +;* x86 optimized dithering format conversion +;* Copyright (c) 2012 Justin Ruggles +;* +;* This file is part of Libav. +;* +;* Libav 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. +;* +;* Libav 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 Libav; if not, write to the Free Software +;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +;****************************************************************************** + +%include "libavutil/x86/x86util.asm" + +SECTION_RODATA 32 + +pf_s16_scale: times 4 dd 32753.0 + +SECTION_TEXT + +;------------------------------------------------------------------------------ +; void ff_quantize(int16_t *dst, float *src, float *dither, int len); +;------------------------------------------------------------------------------ + +INIT_XMM sse2 +cglobal quantize, 4,4,3, dst, src, dither, len + lea lenq, [2*lend] + add dstq, lenq + lea srcq, [srcq+2*lenq] + lea ditherq, [ditherq+2*lenq] + neg lenq + mova m2, [pf_s16_scale] +.loop: + mulps m0, m2, [srcq+2*lenq] + mulps m1, m2, [srcq+2*lenq+mmsize] + addps m0, [ditherq+2*lenq] + addps m1, [ditherq+2*lenq+mmsize] + cvtps2dq m0, m0 + cvtps2dq m1, m1 + packssdw m0, m1 + mova [dstq+lenq], m0 + add lenq, mmsize + jl .loop + REP_RET diff --git a/libavresample/x86/dither_init.c b/libavresample/x86/dither_init.c new file mode 100644 index 0000000000..1e20c1194a --- /dev/null +++ b/libavresample/x86/dither_init.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2012 Justin Ruggles + * + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "libavutil/cpu.h" +#include "libavutil/x86/cpu.h" +#include "libavresample/dither.h" + +extern void ff_quantize_sse2(int16_t *dst, const float *src, float *dither, + int len); + +av_cold void ff_dither_init_x86(DitherDSPContext *ddsp, + enum AVResampleDitherMethod method) +{ + int mm_flags = av_get_cpu_flags(); + + if (EXTERNAL_SSE2(mm_flags)) { + ddsp->quantize = ff_quantize_sse2; + ddsp->ptr_align = 16; + ddsp->samples_align = 8; + } +}