Re: [FFmpeg-devel] [PATCH 02/11] avutil/mips: header asmdefs.h add some PTR_ macros for loongson

2016-05-13 Thread Michael Niedermayer
On Fri, May 13, 2016 at 06:02:28PM +0800, 周晓勇 wrote:
> From f4c3f97c7dc130433b7acf674ff03d7500c7236a Mon Sep 17 00:00:00 2001
> From: ZhouXiaoyong 
> Date: Sat, 7 May 2016 13:56:17 +0800
> Subject: [PATCH 02/11] avutil/mips: header asmdefs.h add some PTR_ macros for
>  loongson
> 
> 
> ---
>  libavutil/mips/asmdefs.h | 12 
>  1 file changed, 12 insertions(+)

applied

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/avlanguage: deprecate av_convert_lang_to and make it internal

2016-05-13 Thread James Almer
The header was never installed and the function is only used in libavformat

Signed-off-by: James Almer 
---
 libavformat/asfdec_f.c|  2 +-
 libavformat/asfdec_o.c|  2 +-
 libavformat/asfenc.c  |  2 +-
 libavformat/avienc.c  |  2 +-
 libavformat/avlanguage.c  | 11 +--
 libavformat/avlanguage.h  |  7 +++
 libavformat/matroskaenc.c |  2 +-
 7 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c
index 2c81b13..b973eff 100644
--- a/libavformat/asfdec_f.c
+++ b/libavformat/asfdec_f.c
@@ -912,7 +912,7 @@ static int asf_read_header(AVFormatContext *s)
 const char *rfc1766 = 
asf->stream_languages[asf->streams[i].stream_language_index];
 if (rfc1766 && strlen(rfc1766) > 1) {
 const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' 
}; // ignore country code if any
-const char *iso6392   = av_convert_lang_to(primary_tag,
+const char *iso6392   = ff_convert_lang_to(primary_tag,

AV_LANG_ISO639_2_BIBL);
 if (iso6392)
 av_dict_set(>metadata, "language", iso6392, 0);
diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
index 1c564a8..f8caf16 100644
--- a/libavformat/asfdec_o.c
+++ b/libavformat/asfdec_o.c
@@ -829,7 +829,7 @@ static void set_language(AVFormatContext *s, const char 
*rfc1766, AVDictionary *
 // language abbr should contain at least 2 chars
 if (rfc1766 && strlen(rfc1766) > 1) {
 const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // 
ignore country code if any
-const char *iso6392   = av_convert_lang_to(primary_tag,
+const char *iso6392   = ff_convert_lang_to(primary_tag,
AV_LANG_ISO639_2_BIBL);
 if (iso6392)
 if (av_dict_set(met, "language", iso6392, 0) < 0)
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index cfa4fad..93ab167 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -431,7 +431,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t 
file_size,
 
 entry = av_dict_get(s->streams[n]->metadata, "language", NULL, 0);
 if (entry) {
-const char *iso6391lang = av_convert_lang_to(entry->value, 
AV_LANG_ISO639_1);
+const char *iso6391lang = ff_convert_lang_to(entry->value, 
AV_LANG_ISO639_1);
 if (iso6391lang) {
 int i;
 for (i = 0; i < asf->nb_languages; i++) {
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index c908c21..59ad2b2 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -435,7 +435,7 @@ static int avi_write_header(AVFormatContext *s)
 }
 if (par->codec_id == AV_CODEC_ID_XSUB
 && (t = av_dict_get(s->streams[i]->metadata, "language", NULL, 
0))) {
-const char* langstr = av_convert_lang_to(t->value, 
AV_LANG_ISO639_1);
+const char* langstr = ff_convert_lang_to(t->value, 
AV_LANG_ISO639_1);
 t = NULL;
 if (langstr) {
 char* str = av_asprintf("Subtitle - %s-xx;02", langstr);
diff --git a/libavformat/avlanguage.c b/libavformat/avlanguage.c
index 39f2560..f5d2ddf 100644
--- a/libavformat/avlanguage.c
+++ b/libavformat/avlanguage.c
@@ -733,7 +733,7 @@ static int lang_table_compare(const void *lhs, const void 
*rhs)
 return strcmp(lhs, ((const LangEntry *)rhs)->str);
 }
 
-const char *av_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace)
+const char *ff_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace)
 {
 int i;
 const LangEntry *entry = NULL;
@@ -759,7 +759,14 @@ const char *av_convert_lang_to(const char *lang, enum 
AVLangCodespace target_cod
 entry = lang_table + entry->next_equivalent;
 
 if (target_codespace == AV_LANG_ISO639_2_TERM)
-return av_convert_lang_to(lang, AV_LANG_ISO639_2_BIBL);
+return ff_convert_lang_to(lang, AV_LANG_ISO639_2_BIBL);
 
 return NULL;
 }
+
+#if LIBAVFORMAT_VERSION_MAJOR < 58
+const char *av_convert_lang_to(const char *lang, enum AVLangCodespace 
target_codespace)
+{
+return ff_convert_lang_to(lang, target_codespace);
+}
+#endif
diff --git a/libavformat/avlanguage.h b/libavformat/avlanguage.h
index 7fb8968..8b91b2a 100644
--- a/libavformat/avlanguage.h
+++ b/libavformat/avlanguage.h
@@ -21,6 +21,9 @@
 #ifndef AVFORMAT_AVLANGUAGE_H
 #define AVFORMAT_AVLANGUAGE_H
 
+#include "libavutil/attributes.h"
+#include "libavformat/version.h"
+
 /**
  * Known language codespaces
  */
@@ -34,6 +37,10 @@ enum AVLangCodespace {
  * Convert a language code to a target codespace. The source codespace is 
guessed.
  * @return NULL if the provided lang is null or invalid.
  */
+const char 

Re: [FFmpeg-devel] [PATCH] swresample/arm: add ff_resample_common_apply_filter_{x4, x8}_{float, s16}_neon

2016-05-13 Thread Matthieu Bouron
On Thu, May 12, 2016 at 3:50 PM, Benoit Fouet  wrote:

> Hi,
>
>
> On 12/05/2016 15:22, Matthieu Bouron wrote:
>
>> On Thu, May 12, 2016 at 10:01 AM, Benoit Fouet 
>> wrote:
>>
>> Hi,
>>>
>>> I mostly have nits remarks.
>>>
>>> On 11/05/2016 18:39, Matthieu Bouron wrote:
>>>
>>> From: Matthieu Bouron 


 [...]
>>>
>>> diff --git a/libswresample/arm/resample.S b/libswresample/arm/resample.S
>>>
 new file mode 100644
 index 000..13462e3
 --- /dev/null
 +++ b/libswresample/arm/resample.S
 @@ -0,0 +1,77 @@

 [...]

 +function ff_resample_common_apply_filter_x4_float_neon, export=1
 +vmov.f32q0, #0.0
  @
 accumulator
 +1:  vld1.32 {q1}, [r1]!
 @
 src
 +vld1.32 {q2}, [r2]!
 @
 filter
 +vmla.f32q0, q1, q2
  @
 src + {0..3} * filter + {0..3}

 nit: the comment could be "accu += src[0..3] . filter[0..3]"
>>> same for the other ones below
>>>
>>> [...]
>>>
>>> +subsr3, #4 @
>>>
 filter_length -= 4
 +bgt 1b
  @
 loop until filter_length
 +vpadd.f32   d0, d0, d1
  @
 pair adding of the 4x32-bit accumulated values
 +vpadd.f32   d0, d0, d0
  @
 pair adding of the 4x32-bit accumulator values
 +vst1.32 {d0[0]}, [r0]
 @
 write accumulator
 +mov pc, lr
 +endfunc
 +
 +function ff_resample_common_apply_filter_x8_float_neon, export=1
 +vmov.f32q0, #0.0
  @
 accumulator
 +1:  vld1.32 {q1}, [r1]!
 @
 src1
 +vld1.32 {q2}, [r2]!
 @
 filter1
 +vld1.32 {q8}, [r1]!
 @
 src2
 +vld1.32 {q9}, [r2]!
 @
 filter2
 +vmla.f32q0, q1, q2
  @
 src1 + {0..3} * filter1 + {0..3}
 +vmla.f32q0, q8, q9
  @
 src2 + {0..3} * filter2 + {0..3}

 instead of using src1 and src2, you may want to use src[0..3] and
>>> src[4..7]
>>> so, if I reuse the formulation I proposed above:
>>> accu += src[0..3] . filter[0..3]
>>> accu += src[4..7] . filter[4..7]
>>>
>>> Fixed locally (as well as the other case you mentionned) with:
>> -vmla.f32q0, q1, q2 @
>> src1 + {0..3} * filter1 + {0..3}
>> -vmla.f32q0, q8, q9 @
>> src2 + {0..3} * filter2 + {0..3}
>> +vmla.f32q0, q1, q2 @
>> accumulator += src1 + {0..3} * filter1 + {0..3}
>> +vmla.f32q0, q8, q9 @
>> accumulator += src2 + {4..7} * filter2 + {4..7}
>>
>> I prefer to use + {0..3} instead of [0..3] to make the comments consistent
>> with what has been done in swscale/arm.
>>
>>
> Fine for me (I chose the "[]" notation to be consistent with the "."
> notation also, in order to do as if it were a dot product between two
> vectors).
>
>
> +subsr3, #8 @
>>>
 filter_length -= 4

 -= 8
>>>
>>> Fixed locally.
>>
>>
>> [...]
>>>
>>> diff --git a/libswresample/arm/resample_init.c
>>>
 b/libswresample/arm/resample_init.c
 new file mode 100644
 index 000..c817d03
 --- /dev/null
 +++ b/libswresample/arm/resample_init.c

 [...]

 +static int ff_resample_common_##TYPE##_neon(ResampleContext *c, void
 *dest, const void *source,   \
 +int n, int update_ctx)
\
 +{
   \
 +DELEM *dst = dest;
\
 +const DELEM *src = source;
\
 +int dst_index;
\
 +int index= c->index;
\
 +int frac= c->frac;
\
 +int sample_index = index >> c->phase_shift;
   \
 +int x4_aligned_filter_length = c->filter_length & ~3;
   \
 +int x8_aligned_filter_length = c->filter_length & ~7;
   \
 +
\
 +index &= c->phase_mask;
   \
 +for (dst_index = 0; dst_index < n; dst_index++) {
   \
 +FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc *
 index; \
 +
\
 +FELEM2 val=0;
   \
 +int i = 0;
\
 +if (x8_aligned_filter_length >= 8) {
   

Re: [FFmpeg-devel] [PATCH][libavfilter] codecview: improved options

2016-05-13 Thread Davinder Singh
should fix fate :)

On Wed, May 11, 2016 at 6:32 PM Michael Niedermayer 
wrote:

> On Wed, May 11, 2016 at 12:41:43PM +, Davinder Singh wrote:
> > single patch
> >
> > On Sun, May 8, 2016 at 1:18 AM Davinder Singh 
> wrote:
> >
> > > separated motion vector types (forward or backward) from frame picture
> > > types as MVs are associated with picture types only in video coding.
> > >
> > > option `mv` can have two values:
> > > forward predicted or backward predicted.
> > >
> > > option `frames` can have three values:
> > > p-frames, i-frames and b-frames.
> > >
> > > ex:
> > > only forward predicted mvs of all frames:
> > > -vf codecview=mv=fp
> > >
> > > mvs (both forward or backward predicted) of P or B-frames:
> > > -vf codecview=mv=fp+bp:frames=pf+bf
> > >
> > > Regards,
> > > DSM_
> > >
>
> >  doc/filters.texi   |   30 --
> >  libavfilter/vf_codecview.c |   36 ++--
> >  2 files changed, 50 insertions(+), 16 deletions(-)
> > 6168c73a45d4b183a4478909e4f8f3b0e47d1738
> 0001-vf_codecview-improved-filter-options.patch
> > From 0c2c258bd14d5dd58351271cc8c8859cd5edbf26 Mon Sep 17 00:00:00 2001
> > From: dsmudhar 
> > Date: Wed, 11 May 2016 17:57:39 +0530
> > Subject: [PATCH] vf_codecview: improved filter options
>
> this breaks make fate
>
> make fate-filter-codecview-mvs
> TESTfilter-codecview-mvs
> --- ./tests/ref/fate/filter-codecview-mvs   2016-05-11
> 04:21:34.187662201 +0200
> +++ tests/data/fate/filter-codecview-mvs2016-05-11
> 14:58:43.732467592 +0200
> @@ -1,65 +0,0 @@
> -#tb 0: 32768/785647
> -#media_type 0: video
> -#codec_id 0: rawvideo
> -#dimensions 0: 576x320
> -#sar 0: 0/1
> -0,  0,  0,1,   276480, 0x5f7a0d4f
> -0,  1,  1,1,   276480, 0x5f7a0d4f
> -0,  2,  2,1,   276480, 0x5f7a0d4f
> -0,  3,  3,1,   276480, 0x5f7a0d4f
> -0,  4,  4,1,   276480, 0x5f7a0d4f
> -0,  5,  5,1,   276480, 0x5f7a0d4f
> -0,  6,  6,1,   276480, 0x5f7a0d4f
> -0,  7,  7,1,   276480, 0x5f7a0d4f
> -0,  8,  8,1,   276480, 0x5f7a0d4f
> -0,  9,  9,1,   276480, 0x5f7a0d4f
> -0, 10, 10,1,   276480, 0x5f7a0d4f
> -0, 11, 11,1,   276480, 0x5f7a0d4f
> -0, 12, 12,1,   276480, 0x5f7a0d4f
> -0, 13, 13,1,   276480, 0x5f7a0d4f
> -0, 14, 14,1,   276480, 0x5f7a0d4f
> -0, 15, 15,1,   276480, 0x5f7a0d4f
> -0, 16, 16,1,   276480, 0xc3b80edf
> -0, 17, 17,1,   276480, 0x5f7a0d4f
> -0, 18, 18,1,   276480, 0x5f7a0d4f
> -0, 19, 19,1,   276480, 0x5f7a0d4f
> -0, 20, 20,1,   276480, 0xc3b80edf
> -0, 21, 21,1,   276480, 0x5f7a0d4f
> -0, 22, 22,1,   276480, 0x5f7a0d4f
> -0, 23, 23,1,   276480, 0x5f7a0d4f
> -0, 24, 24,1,   276480, 0xc3b80edf
> -0, 25, 25,1,   276480, 0x5f7a0d4f
> -0, 26, 26,1,   276480, 0x5f7a0d4f
> -0, 27, 27,1,   276480, 0x5f7a0d4f
> -0, 28, 28,1,   276480, 0xc3b80edf
> -0, 29, 29,1,   276480, 0x5f7a0d4f
> -0, 30, 30,1,   276480, 0x5f7a0d4f
> -0, 31, 31,1,   276480, 0x5f7a0d4f
> -0, 32, 32,1,   276480, 0xc3b80edf
> -0, 33, 33,1,   276480, 0x75641594
> -0, 34, 34,1,   276480, 0x32ee3526
> -0, 35, 35,1,   276480, 0xcb53479a
> -0, 36, 36,1,   276480, 0xe1be6e26
> -0, 37, 37,1,   276480, 0x5ce39368
> -0, 38, 38,1,   276480, 0x4ec1e418
> -0, 39, 39,1,   276480, 0x23c418ae
> -0, 40, 40,1,   276480, 0x036a5515
> -0, 41, 41,1,   276480, 0x7946efbd
> -0, 42, 42,1,   276480, 0xd9aa1382
> -0, 43, 43,1,   276480, 0x3863f9c8
> -0, 44, 44,1,   276480, 0x33e47330
> -0, 45, 45,1,   276480, 0xff6e8038
> -0, 46, 46,1,   276480, 0xed3ff087
> -0, 47, 47,1,   276480, 0xe7834514
> -0, 48, 48,1,   276480, 0x4d5d909d
> -0, 49, 49,1,   276480, 0x82eea962
> -0, 50, 50,1,   276480, 0x8075bca3
> -0, 51, 51,1,   276480, 0xd5dc3185
> -0, 52, 52,1,   276480, 

[FFmpeg-devel] [PATCH] avformat: Add Pro-MPEG CoP #3-R2 FEC protocol

2016-05-13 Thread Vlad Tarca
Pro-MPEG Code of Practice #3 release 2 forward error correction for rtp_mpegts 
streams

Signed-off-by: Vlad Tarca 
---
 Changelog   |   1 +
 doc/general.texi|   1 +
 doc/protocols.texi  |  38 
 libavformat/Makefile|   1 +
 libavformat/prompeg.c   | 493 
 libavformat/protocols.c |   1 +
 libavformat/rtpproto.c  |  62 +-
 7 files changed, 595 insertions(+), 2 deletions(-)
 create mode 100644 libavformat/prompeg.c

diff --git a/Changelog b/Changelog
index 3f343ce..d6a882f 100644
--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,7 @@ version :
 - DTS Express (LBR) decoder
 - Generic OpenMAX IL encoder with support for Raspberry Pi
 - IFF ANIM demuxer & decoder
+- Pro-MPEG CoP #3-R2 FEC protocol
 
 version 3.0:
 - Common Encryption (CENC) MP4 encoding and decoding support
diff --git a/doc/general.texi b/doc/general.texi
index 59ea4f4..2cbf41c 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -1124,6 +1124,7 @@ performance on systems without hardware floating point 
support).
 @item MMSH @tab X
 @item MMST @tab X
 @item pipe @tab X
+@item Pro-MPEG FEC @tab X
 @item RTMP @tab X
 @item RTMPE@tab X
 @item RTMPS@tab X
diff --git a/doc/protocols.texi b/doc/protocols.texi
index a1084bd..7c19dd8 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -513,6 +513,44 @@ time, which is valuable if data transmission is slow.
 Note that some formats (typically MOV), require the output protocol to
 be seekable, so they will fail with the pipe output protocol.
 
+@section prompeg
+
+Pro-MPEG Code of Practice #3 Release 2 FEC protocol.
+
+The Pro-MPEG CoP#3 FEC is a 2D parity-check forward error correction mechanism
+for MPEG-2 Transport Streams sent over RTP.
+
+This protocol must be used in conjunction with the @code{rtp_mpegts} muxer and
+the @code{rtp} protocol.
+
+The required syntax is:
+@example
+-f rtp_mpegts -fec prompeg=@var{option}=@var{val}... 
rtp://@var{hostname}:@var{port}
+@end example
+
+The destination UDP ports are @code{port + 2} for the column FEC stream
+and @code{port + 4} for the row FEC stream.
+
+This protocol accepts the following options:
+@table @option
+
+@item l=@var{n}
+The number of columns (4-20, LxD <= 100)
+
+@item d=@var{n}
+The number of rows (4-20, LxD <= 100)
+
+@item ttl=@var{n}
+Set the TTL (Time-To-Live) value (for multicast only).
+
+@end table
+
+Example usage:
+
+@example
+-f rtp_mpegts -fec prompeg=l=8:d=4 rtp://@var{hostname}:@var{port}
+@end example
+
 @section rtmp
 
 Real-Time Messaging Protocol.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index abfbc37..b1d6798 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -546,6 +546,7 @@ OBJS-$(CONFIG_MD5_PROTOCOL)  += md5proto.o
 OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o
 OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o
 OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o
+OBJS-$(CONFIG_PROMPEG_PROTOCOL)  += prompeg.o
 OBJS-$(CONFIG_RTMP_PROTOCOL) += rtmpproto.o rtmppkt.o
 OBJS-$(CONFIG_RTMPE_PROTOCOL)+= rtmpproto.o rtmppkt.o
 OBJS-$(CONFIG_RTMPS_PROTOCOL)+= rtmpproto.o rtmppkt.o
diff --git a/libavformat/prompeg.c b/libavformat/prompeg.c
new file mode 100644
index 000..08409d8
--- /dev/null
+++ b/libavformat/prompeg.c
@@ -0,0 +1,493 @@
+/*
+ * Pro-MPEG Code of Practice #3 Release 2 FEC
+ * Copyright (c) 2016 Mobibase, France (http://www.mobibase.com)
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Pro-MPEG Code of Practice #3 Release 2 FEC protocol
+ * @author Vlad Tarca 
+ */
+
+/*
+ * Reminder:
+
+ [RFC 2733] FEC Packet Structure
+
+   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+   | RTP Header|
+   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+   | FEC Header|
+   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+   | FEC Payload   |
+   |   

Re: [FFmpeg-devel] [PATCH] libavcodec/options.c: handle hw_frames_ctx where necessary

2016-05-13 Thread Andrey Turkin
> No: this part of the patch does nothing because it's already unreffed in
the
> avcodec_close() called immediately above.  Maybe the unref should
actually be in
> avcodec_free_context() only (if treating it like rc_override and those
fields),
> but it shouldn't be in both.
I missed that, thank you for pointing it out; so there is no memory leak
then. Whether it should be unrefed on codec close is a matter of opinion;
in my opinion avcodec_close shouldn't touch things that aren't created by
avcodec_open.
However I'm inclined to remove that portion of a patch and let someone else
decide if this behaviour should be changed.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Const src in av_packet_clone declaration

2016-05-13 Thread Michael Niedermayer
On Fri, May 13, 2016 at 03:24:50PM +0300, Andriy Lysnevych wrote:
> > Anyway, example how this change can break:
> >
> > typedef struct AVPacket AVPacket;
> >
> > AVPacket *av_packet_clone_old(AVPacket *src);
> > AVPacket *av_packet_clone_new(const AVPacket *src);
> >
> > AVPacket *(*unsuspecting_api_user)(AVPacket *src);
> >
> > void set(void)
> > {
> > unsuspecting_api_user = av_packet_clone_old;
> >
> > unsuspecting_api_user = av_packet_clone_new;
> > }
> >
> 
> You are right. But is this the only example how this change breakes
> compatibility? I don't think many (if any) C++ projects use
> av_packet_clone this way. Also this incompatibility is very easy to
> fix in any project.

i remember there was one project that used libavcodec through placing
all functions as pointers in a struct or something.

i think the const should just be added under appropriate #if version
its the "proper" way to do it and the #if ill get dropped after the
version is bumped

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Const src in av_packet_clone declaration

2016-05-13 Thread wm4
On Fri, 13 May 2016 15:24:50 +0300
Andriy Lysnevych  wrote:

> > Anyway, example how this change can break:
> >
> > typedef struct AVPacket AVPacket;
> >
> > AVPacket *av_packet_clone_old(AVPacket *src);
> > AVPacket *av_packet_clone_new(const AVPacket *src);
> >
> > AVPacket *(*unsuspecting_api_user)(AVPacket *src);
> >
> > void set(void)
> > {
> > unsuspecting_api_user = av_packet_clone_old;
> >
> > unsuspecting_api_user = av_packet_clone_new;
> > }
> >  
> 
> You are right. But is this the only example how this change breakes
> compatibility? I don't think many (if any) C++ projects use
> av_packet_clone this way. Also this incompatibility is very easy to
> fix in any project.

I know that there are some projects which dlopen libavcodec, but I
don't know if they'd get broken by this. Either way, at this point I
don't care anymore - if others think this potential breakage is ok, I'm
fine with it.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Const src in av_packet_clone declaration

2016-05-13 Thread Andriy Lysnevych
> Anyway, example how this change can break:
>
> typedef struct AVPacket AVPacket;
>
> AVPacket *av_packet_clone_old(AVPacket *src);
> AVPacket *av_packet_clone_new(const AVPacket *src);
>
> AVPacket *(*unsuspecting_api_user)(AVPacket *src);
>
> void set(void)
> {
> unsuspecting_api_user = av_packet_clone_old;
>
> unsuspecting_api_user = av_packet_clone_new;
> }
>

You are right. But is this the only example how this change breakes
compatibility? I don't think many (if any) C++ projects use
av_packet_clone this way. Also this incompatibility is very easy to
fix in any project.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] Respect payload offset in av_grow_packet

2016-05-13 Thread Andriy Lysnevych
The patch fixes the function when used with reference-counted packets
that have payload offset.

Also this function is dangerous for not reference-counted packets
because it just overwrites pkt->data. Probably it is better to
restrict using it with not referenced-counted packets because you
simply don't know how to do grow\realloc in this case.

h264_mp4toannexb and h265_mp4toannexb already call av_grow_packet on
input packets that leads to memory leak in case of not reference
counted packets.

---
 libavcodec/avpacket.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index bcc7c79..327cd41 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -110,24 +110,29 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
 {
 int new_size;
 av_assert0((unsigned)pkt->size <= INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
-if (!pkt->size)
-return av_new_packet(pkt, grow_by);
-if ((unsigned)grow_by >
-INT_MAX - (pkt->size + AV_INPUT_BUFFER_PADDING_SIZE))
-return -1;

 new_size = pkt->size + grow_by + AV_INPUT_BUFFER_PADDING_SIZE;
 if (pkt->buf) {
-int ret = av_buffer_realloc(>buf, new_size);
-if (ret < 0)
-return ret;
+int data_offset = pkt->data - pkt->buf->data;
+if ((unsigned)grow_by >
+INT_MAX - (pkt->size + data_offset + AV_INPUT_BUFFER_PADDING_SIZE))
+return -1;
+if (new_size + data_offset > pkt->buf->size) {
+int ret = av_buffer_realloc(>buf, new_size + data_offset);
+if (ret < 0)
+return ret;
+pkt->data = pkt->buf->data + data_offset;
+}
 } else {
+if ((unsigned)grow_by >
+INT_MAX - (pkt->size + AV_INPUT_BUFFER_PADDING_SIZE))
+return -1;
 pkt->buf = av_buffer_alloc(new_size);
 if (!pkt->buf)
 return AVERROR(ENOMEM);
-memcpy(pkt->buf->data, pkt->data, FFMIN(pkt->size, pkt->size
+ grow_by));
+memcpy(pkt->buf->data, pkt->data, pkt->size);
+pkt->data = pkt->buf->data;
 }
-pkt->data  = pkt->buf->data;
 pkt->size += grow_by;
 memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);

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


[FFmpeg-devel] [PATCH 11/11] avcodec/mips: loongson optimize idctdsp with mmi v2

2016-05-13 Thread 周晓勇
From 37d9b61f529064a6a78c99f86ff371fefa2b357a Mon Sep 17 00:00:00 2001
From: ZhouXiaoyong 
Date: Fri, 13 May 2016 16:51:14 +0800
Subject: [PATCH 11/11] avcodec/mips: loongson optimize idctdsp with mmi v2


---
 libavcodec/mips/idctdsp_mmi.c | 290 ++
 1 file changed, 154 insertions(+), 136 deletions(-)


diff --git a/libavcodec/mips/idctdsp_mmi.c b/libavcodec/mips/idctdsp_mmi.c
index 25476f3..24beb62 100644
--- a/libavcodec/mips/idctdsp_mmi.c
+++ b/libavcodec/mips/idctdsp_mmi.c
@@ -23,63 +23,75 @@
 
 #include "idctdsp_mips.h"
 #include "constants.h"
+#include "libavutil/mips/asmdefs.h"
 
 void ff_put_pixels_clamped_mmi(const int16_t *block,
 uint8_t *av_restrict pixels, ptrdiff_t line_size)
 {
-const int16_t *p;
-uint8_t *pix;
-
-p = block;
-pix = pixels;
+double ftmp[8];
+mips_reg addr[1];
 
 __asm__ volatile (
-"ldc1 $f0, 0+%3 \r\n"
-"ldc1 $f2, 8+%3 \r\n"
-"ldc1 $f4, 16+%3\r\n"
-"ldc1 $f6, 24+%3\r\n"
-"ldc1 $f8, 32+%3\r\n"
-"ldc1 $f10, 40+%3   \r\n"
-"ldc1 $f12, 48+%3   \r\n"
-"ldc1 $f14, 56+%3   \r\n"
-"dadd $10, %0, %1   \r\n"
-"packushb $f0, $f0, $f2 \r\n"
-"packushb $f4, $f4, $f6 \r\n"
-"packushb $f8, $f8, $f10\r\n"
-"packushb $f12, $f12, $f14  \r\n"
-"sdc1 $f0, 0(%0)\r\n"
-"sdc1 $f4, 0($10)   \r\n"
-"gssdxc1 $f8, 0($10, %1)\r\n"
-"gssdxc1 $f12, 0(%0, %2)\r\n"
-::"r"(pix),"r"((int)line_size),
-  "r"((int)line_size*3),"m"(*p)
-: "$10","memory"
+"ldc1   %[ftmp0],   0x00(%[block])  \n\t"
+"ldc1   %[ftmp1],   0x08(%[block])  \n\t"
+"ldc1   %[ftmp2],   0x10(%[block])  \n\t"
+"ldc1   %[ftmp3],   0x18(%[block])  \n\t"
+"ldc1   %[ftmp4],   0x20(%[block])  \n\t"
+"ldc1   %[ftmp5],   0x28(%[block])  \n\t"
+"ldc1   %[ftmp6],   0x30(%[block])  \n\t"
+"ldc1   %[ftmp7],   0x38(%[block])  \n\t"
+PTR_ADDU   "%[addr0],   %[pixels],  %[line_size]\n\t"
+"packushb   %[ftmp0],   %[ftmp0],   %[ftmp1]\n\t"
+"packushb   %[ftmp2],   %[ftmp2],   %[ftmp3]\n\t"
+"packushb   %[ftmp4],   %[ftmp4],   %[ftmp5]\n\t"
+"packushb   %[ftmp6],   %[ftmp6],   %[ftmp7]\n\t"
+"sdc1   %[ftmp0],   0x00(%[pixels]) \n\t"
+"sdc1   %[ftmp2],   0x00(%[addr0])  \n\t"
+"gssdxc1%[ftmp4],   0x00(%[addr0],  %[line_size])   \n\t"
+"gssdxc1%[ftmp6],   0x00(%[pixels], %[line_sizex3]) \n\t"
+: [ftmp0]"="(ftmp[0]),[ftmp1]"="(ftmp[1]),
+  [ftmp2]"="(ftmp[2]),[ftmp3]"="(ftmp[3]),
+  [ftmp4]"="(ftmp[4]),[ftmp5]"="(ftmp[5]),
+  [ftmp6]"="(ftmp[6]),[ftmp7]"="(ftmp[7]),
+  [addr0]"="(addr[0]),
+  [pixels]"+"(pixels)
+: [line_size]"r"((mips_reg)line_size),
+  [line_sizex3]"r"((mips_reg)(line_size*3)),
+  [block]"r"(block)
+: "memory"
 );
 
-pix += line_size*4;
-p += 32;
+pixels += line_size*4;
+block += 32;
 
 __asm__ volatile (
-"ldc1 $f0, 0+%3 \r\n"
-"ldc1 $f2, 8+%3 \r\n"
-"ldc1 $f4, 16+%3\r\n"
-"ldc1 $f6, 24+%3\r\n"
-"ldc1 $f8, 32+%3\r\n"
-"ldc1 $f10, 40+%3   \r\n"
-"ldc1 $f12, 48+%3   \r\n"
-"ldc1 $f14, 56+%3   \r\n"
-"dadd $10, %0, %1   \r\n"
-"packushb $f0, $f0, $f2 \r\n"
-"packushb $f4, $f4, $f6 \r\n"
-"packushb $f8, $f8, $f10\r\n"
-"packushb $f12, $f12, $f14  \r\n"
-"sdc1 $f0, 0(%0)\r\n"
-"sdc1 $f4, 0($10)   \r\n"
-"gssdxc1 $f8, 0($10, %1)\r\n"
-"gssdxc1 $f12, 0(%0, %2)\r\n"
-::"r"(pix),"r"((int)line_size),
-  "r"((int)line_size*3),"m"(*p)
-: "$10","memory"
+"ldc1   %[ftmp0],   0x00(%[block])  \n\t"
+"ldc1   %[ftmp1],   0x08(%[block])  \n\t"
+"ldc1   %[ftmp2],   0x10(%[block])  \n\t"
+"ldc1   %[ftmp3],   0x18(%[block])  \n\t"
+

Re: [FFmpeg-devel] [PATCH] libavcodec/options.c: handle hw_frames_ctx where necessary

2016-05-13 Thread wm4
On Fri, 13 May 2016 10:58:02 +0100
Mark Thompson  wrote:

> On 13/05/16 10:42, wm4 wrote:
> > On Fri, 13 May 2016 10:54:17 +0300
> > Andrey Turkin  wrote:
> >   
> >> 2016-05-13 10:35 GMT+03:00 wm4 :
> >>  
> >>> On Thu, 12 May 2016 22:35:48 +0300
> >>> Andrey Turkin  wrote:
> >>>
>  Few functions didn't handle hw_frames_ctx references causing resources   
>   
> >>> leaks and even crashes.
>  ---
>   libavcodec/options.c | 10 ++
>   1 file changed, 10 insertions(+)
> 
>  diff --git a/libavcodec/options.c b/libavcodec/options.c
>  index ea2563b..8682262 100644
>  --- a/libavcodec/options.c
>  +++ b/libavcodec/options.c
>  @@ -175,6 +175,7 @@ void avcodec_free_context(AVCodecContext **pavctx)
>   av_freep(>intra_matrix);
>   av_freep(>inter_matrix);
>   av_freep(>rc_override);
>  +av_buffer_unref(>hw_frames_ctx);
> 
>   av_freep(pavctx);
>   }
> >>>
> >>> I would have thought this is the responsibility of the API user?
> >>>
> >>>
> >> AVCodecContext documentation says it is set by a user but then managed and
> >> owned by libavcodec (which is a logical thing to do for any shared
> >> reference).  
> > 
> > Even so it's a breaking API change and should be treated as such. An
> > API user could for example have a separate variable with the same
> > buffer ref somewhere, which would lead to a double-free. Even more so
> > because an API user might have noticed the leak, and concluded the ref
> > must be released manually.
> > 
> > Since this looks like an unintentional bug and there's no release with
> > it included yet, we can probably skip major jumps. But it should still
> > be mentioned in APIchanges, and be sent to Libav too.  
> 
> No: this part of the patch does nothing because it's already unreffed in the
> avcodec_close() called immediately above.  Maybe the unref should actually be 
> in
> avcodec_free_context() only (if treating it like rc_override and those 
> fields),
> but it shouldn't be in both.

Oh I see. You could argue that avodec_open() is the thing which takes
over ownership. But the real sketchy thing is that avcodec_close()
unrefs it even if the context was not opened.

This is all such an inconsistent mess.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 09/11] avcodec/mips: loongson optimize blockdsp with mmi v2

2016-05-13 Thread 周晓勇
From 9e5ade4c99eb23f72a89f0054f8b5626c9acceb3 Mon Sep 17 00:00:00 2001
From: ZhouXiaoyong 
Date: Fri, 13 May 2016 14:30:10 +0800
Subject: [PATCH 09/11] avcodec/mips: loongson optimize blockdsp with mmi v2


---
 libavcodec/mips/blockdsp_mmi.c | 195 ++---
 1 file changed, 103 insertions(+), 92 deletions(-)


diff --git a/libavcodec/mips/blockdsp_mmi.c b/libavcodec/mips/blockdsp_mmi.c
index 63eaf69..6eb2bd7 100644
--- a/libavcodec/mips/blockdsp_mmi.c
+++ b/libavcodec/mips/blockdsp_mmi.c
@@ -22,126 +22,137 @@
  */
 
 #include "blockdsp_mips.h"
+#include "libavutil/mips/asmdefs.h"
 
 void ff_fill_block16_mmi(uint8_t *block, uint8_t value, int line_size, int h)
 {
+double ftmp[1];
+
 __asm__ volatile (
-"move $8, %3\r\n"
-"move $9, %0\r\n"
-"dmtc1 %1, $f2  \r\n"
-"punpcklbh $f2, $f2, $f2\r\n"
-"punpcklbh $f2, $f2, $f2\r\n"
-"punpcklbh $f2, $f2, $f2\r\n"
-"1: \r\n"
-"gssdlc1 $f2, 7($9) \r\n"
-"gssdrc1 $f2, 0($9) \r\n"
-"gssdlc1 $f2, 15($9)\r\n"
-"gssdrc1 $f2, 8($9) \r\n"
-"daddi $8, $8, -1   \r\n"
-"daddu $9, $9, %2   \r\n"
-"bnez $8, 1b\r\n"
-::"r"(block),"r"(value),"r"(line_size),"r"(h)
-: "$8","$9"
+"mtc1   %[value],   %[ftmp0]\n\t"
+"punpcklbh  %[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"punpcklbh  %[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"punpcklbh  %[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"1: \n\t"
+"gssdlc1%[ftmp0],   0x07(%[block])  \n\t"
+"gssdrc1%[ftmp0],   0x00(%[block])  \n\t"
+PTR_ADDI"%[h],  %[h],   -0x01   \n\t"
+"gssdlc1%[ftmp0],   0x0f(%[block])  \n\t"
+"gssdrc1%[ftmp0],   0x08(%[block])  \n\t"
+PTR_ADDU   "%[block],   %[block],   %[line_size]\n\t"
+"bnez   %[h],   1b  \n\t"
+: [block]"+"(block),  [h]"+"(h),
+  [ftmp0]"="(ftmp[0])
+: [value]"r"(value),[line_size]"r"((mips_reg)line_size)
+: "memory"
 );
 }
 
 void ff_fill_block8_mmi(uint8_t *block, uint8_t value, int line_size, int h)
 {
+double ftmp0;
+
 __asm__ volatile (
-"move $8, %3\r\n"
-"move $9, %0\r\n"
-"dmtc1 %1, $f2  \r\n"
-"punpcklbh $f2, $f2, $f2\r\n"
-"punpcklbh $f2, $f2, $f2\r\n"
-"punpcklbh $f2, $f2, $f2\r\n"
-"1: \r\n"
-"gssdlc1 $f2, 7($9) \r\n"
-"gssdrc1 $f2, 0($9) \r\n"
-"daddi $8, $8, -1   \r\n"
-"daddu $9, $9, %2   \r\n"
-"bnez $8, 1b\r\n"
-::"r"(block),"r"(value),"r"(line_size),"r"(h)
-: "$8","$9"
+"mtc1   %[value],   %[ftmp0]\n\t"
+"punpcklbh  %[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"punpcklbh  %[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"punpcklbh  %[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"1: \n\t"
+"gssdlc1%[ftmp0],   0x07(%[block])  \n\t"
+"gssdrc1%[ftmp0],   0x00(%[block])  \n\t"
+PTR_ADDI   "%[h],   %[h],   -0x01   \n\t"
+PTR_ADDU   "%[block],   %[block],   %[line_size]\n\t"
+"bnez   %[h],   1b  \n\t"
+: [block]"+"(block),  [h]"+"(h),
+  [ftmp0]"="(ftmp0)
+: [value]"r"(value),[line_size]"r"((mips_reg)line_size)
+: "memory"
 );
 }
 
 void ff_clear_block_mmi(int16_t *block)
 {
+double ftmp[2];
+
 __asm__ volatile (
-"xor $f0, $f0, $f0  \r\n"
-"xor $f2, $f2, $f2  \r\n"
-"gssqc1 $f0, $f2,   0(%0)   \r\n"
-"gssqc1 $f0, $f2,  16(%0)   \r\n"
-"gssqc1 $f0, $f2,  32(%0)   \r\n"
-"gssqc1 $f0, $f2,  48(%0)   \r\n"
-"gssqc1 $f0, $f2,  64(%0)   \r\n"
-"gssqc1 $f0, $f2,  80(%0)   \r\n"
-"gssqc1 $f0, $f2,  96(%0)   \r\n"
-"gssqc1 $f0, $f2, 112(%0)   \r\n"
-::"r"(block)
+"xor%[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"xor

[FFmpeg-devel] [PATCH 05/11] avcodec/mips: loongson optimize mpegvideo with mmi v2

2016-05-13 Thread 周晓勇
From cb8887caf25b300ef2f307f930593e9edf394977 Mon Sep 17 00:00:00 2001
From: Zhou Xiaoyong 
Date: Thu, 12 May 2016 01:48:03 +0800
Subject: [PATCH 05/11] avcodec/mips: loongson optimize mpegvideo with mmi v2


---
 libavcodec/mips/mpegvideo_mmi.c | 667 +---
 1 file changed, 358 insertions(+), 309 deletions(-)


diff --git a/libavcodec/mips/mpegvideo_mmi.c b/libavcodec/mips/mpegvideo_mmi.c
index 94781e6..450a18c 100644
--- a/libavcodec/mips/mpegvideo_mmi.c
+++ b/libavcodec/mips/mpegvideo_mmi.c
@@ -23,11 +23,14 @@
  */
 
 #include "mpegvideo_mips.h"
+#include "libavutil/mips/asmdefs.h"
 
 void ff_dct_unquantize_h263_intra_mmi(MpegEncContext *s, int16_t *block,
 int n, int qscale)
 {
 int64_t level, qmul, qadd, nCoeffs;
+double ftmp[6];
+mips_reg addr[1];
 
 qmul = qscale << 1;
 av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
@@ -49,48 +52,50 @@ void ff_dct_unquantize_h263_intra_mmi(MpegEncContext *s, 
int16_t *block,
 nCoeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
 
 __asm__ volatile (
-"xor $f12, $f12, $f12   \r\n"
-"lwc1 $f12, %1  \n\r"
-"xor $f10, $f10, $f10   \r\n"
-"lwc1 $f10, %2  \r\n"
-"xor $f14, $f14, $f14   \r\n"
-"packsswh $f12, $f12, $f12  \r\n"
-"packsswh $f12, $f12, $f12  \r\n"
-"packsswh $f10, $f10, $f10  \r\n"
-"packsswh $f10, $f10, $f10  \r\n"
-"psubh $f14, $f14, $f10 \r\n"
-"xor $f8, $f8, $f8  \r\n"
-".p2align 4 \r\n"
-"1: \r\n"
-"daddu $8, %0, %3   \r\n"
-"gsldlc1 $f0, 7($8) \r\n"
-"gsldrc1 $f0, 0($8) \r\n"
-"gsldlc1 $f2, 15($8)\r\n"
-"gsldrc1 $f2, 8($8) \r\n"
-"mov.d $f4, $f0 \r\n"
-"mov.d $f6, $f2 \r\n"
-"pmullh $f0, $f0, $f12  \r\n"
-"pmullh $f2, $f2, $f12  \r\n"
-"pcmpgth $f4, $f4, $f8  \r\n"
-"pcmpgth $f6, $f6, $f8  \r\n"
-"xor $f0, $f0, $f4  \r\n"
-"xor $f2, $f2, $f6  \r\n"
-"paddh $f0, $f0, $f14   \r\n"
-"paddh $f2, $f2, $f14   \r\n"
-"xor $f4, $f4, $f0  \r\n"
-"xor $f6, $f6, $f2  \r\n"
-"pcmpeqh $f0, $f0, $f14 \r\n"
-"pcmpeqh $f2, $f2, $f14 \r\n"
-"pandn $f0, $f0, $f4\r\n"
-"pandn $f2, $f2, $f6\r\n"
-"gssdlc1 $f0, 7($8) \r\n"
-"gssdrc1 $f0, 0($8) \r\n"
-"gssdlc1 $f2, 15($8)\r\n"
-"gssdrc1 $f2, 8($8) \r\n"
-"addi %3, %3, 16\r\n"
-"blez %3, 1b\r\n"
-::"r"(block+nCoeffs),"m"(qmul),"m"(qadd),"r"(2*(-nCoeffs))
-:"$8","memory"
+"xor%[ftmp0],   %[ftmp0],   %[ftmp0]\n\t"
+"packsswh   %[qmul],%[qmul],%[qmul] \n\t"
+"packsswh   %[qmul],%[qmul],%[qmul] \n\t"
+"packsswh   %[qadd],%[qadd],%[qadd] \n\t"
+"packsswh   %[qadd],%[qadd],%[qadd] \n\t"
+"psubh  %[ftmp0],   %[ftmp0],   %[qadd] \n\t"
+"xor%[ftmp5],   %[ftmp5],   %[ftmp5]\n\t"
+".p2align   4   \n\t"
+"1: \n\t"
+PTR_ADDU   "%[addr0],   %[block],   %[nCoeffs]  \n\t"
+"gsldlc1%[ftmp1],   0x07(%[addr0])  \n\t"
+"gsldrc1%[ftmp1],   0x00(%[addr0])  \n\t"
+"gsldlc1%[ftmp2],   0x0f(%[addr0])  \n\t"
+"gsldrc1%[ftmp2],   0x08(%[addr0])  \n\t"
+"mov.d  %[ftmp3],   %[ftmp1]\n\t"
+"mov.d  %[ftmp4],   %[ftmp2]\n\t"
+"pmullh %[ftmp1],   %[ftmp1],   %[qmul] \n\t"
+"pmullh %[ftmp2],   %[ftmp2],   %[qmul] \n\t"
+"pcmpgth%[ftmp3],   %[ftmp3],   %[ftmp5]\n\t"
+"pcmpgth%[ftmp4],   %[ftmp4],   %[ftmp5]\n\t"
+"xor%[ftmp1],   %[ftmp1],   %[ftmp3]\n\t"
+"xor%[ftmp2],   %[ftmp2],   %[ftmp4]\n\t"
+"paddh  %[ftmp1],   %[ftmp1],   %[ftmp0]\n\t"
+"paddh  %[ftmp2],   %[ftmp2],   %[ftmp0]\n\t"
+  

[FFmpeg-devel] [PATCH 04/11] avcodec/mips: loongson optimize h264chroma with mmi v2

2016-05-13 Thread 周晓勇
From 157e001724cdb1461ecfff2f02d0a7b0d6335943 Mon Sep 17 00:00:00 2001
From: ZhouXiaoyong 
Date: Sat, 7 May 2016 14:20:49 +0800
Subject: [PATCH 04/11] avcodec/mips: loongson optimize h264chroma with mmi v2


---
 libavcodec/mips/h264chroma_mmi.c | 1123 +-
 1 file changed, 629 insertions(+), 494 deletions(-)


diff --git a/libavcodec/mips/h264chroma_mmi.c b/libavcodec/mips/h264chroma_mmi.c
index ef29476..3dd123d 100644
--- a/libavcodec/mips/h264chroma_mmi.c
+++ b/libavcodec/mips/h264chroma_mmi.c
@@ -23,6 +23,8 @@
  */
 
 #include "h264chroma_mips.h"
+#include "constants.h"
+#include "libavutil/mips/asmdefs.h"
 
 void ff_put_h264_chroma_mc8_mmi(uint8_t *dst, uint8_t *src, int stride,
 int h, int x, int y)
@@ -32,171 +34,177 @@ void ff_put_h264_chroma_mc8_mmi(uint8_t *dst, uint8_t 
*src, int stride,
 const int C = (8 - x) * y;
 const int D = x * y;
 const int E = B + C;
-int i;
-
-av_assert2(x<8 && y<8 && x>=0 && y>=0);
+double ftmp[10];
+uint64_t tmp[1];
+mips_reg addr[1];
 
 if (D) {
-for (i=0; i

[FFmpeg-devel] [PATCH 01/11] configure: remove option -fno-expensive-optimizations for loongson

2016-05-13 Thread 周晓勇
From c0f8c4e1bbe39216ba8f6df118703ad2c72a45e1 Mon Sep 17 00:00:00 2001
From: Zhou Xiaoyong 
Date: Thu, 12 May 2016 17:45:08 +0800
Subject: [PATCH 01/11] configure: remove option -fno-expensive-optimizations
 for loongson


1. gcc-4.9.3-5.fc21.loongson.2.mips64el in Fedora21 for loongson has
fix the bug in commit 2c34389551b6ba3d90f8783806c337e387e603cd.
2. the latest release version of Fedora for loongson is
http://mirror.lemote.com/fedora/live/Fedora-MATE-Live-2.iso
---
 configure | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


diff --git a/configure b/configure
index df82eb2..0b9fdf3 100755
--- a/configure
+++ b/configure
@@ -4292,13 +4292,13 @@ elif enabled mips; then
 disable aligned_stack
 case $cpu in
 loongson3*)
-cpuflags="-march=loongson3a -mhard-float 
-fno-expensive-optimizations"
+cpuflags="-march=loongson3a -mhard-float"
 ;;
 loongson2e)
-cpuflags="-march=loongson2e -mhard-float 
-fno-expensive-optimizations"
+cpuflags="-march=loongson2e -mhard-float"
 ;;
 loongson2f)
-cpuflags="-march=loongson2f -mhard-float 
-fno-expensive-optimizations"
+cpuflags="-march=loongson2f -mhard-float"
 ;;
 esac
 ;;
-- 
2.1.0

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


Re: [FFmpeg-devel] [PATCH 04/10] avcodec/dca: don't set initial sample_fmt

2016-05-13 Thread Hendrik Leppkes
On Fri, May 13, 2016 at 11:48 AM, foo86  wrote:
> Valid sample_fmt will be set by dcadec_decode_frame() based on stream
> type.
> ---
>  libavcodec/dcadec.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
> index e3a4b0d..565242d 100644
> --- a/libavcodec/dcadec.c
> +++ b/libavcodec/dcadec.c
> @@ -374,9 +374,6 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
>  break;
>  }
>
> -avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
> -avctx->bits_per_raw_sample = 24;
> -
>  return 0;
>  }
>

Having an initial format for the most "common" types of streams is
generally sensible.

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


[FFmpeg-devel] [PATCH 06/10] avcodec/dca_parser: improve frame end search

2016-05-13 Thread foo86
Parse core frame size directly when searching for frame end instead of
using value extracted from previous frame.

Account for unused bits when calculating sync word distance for 14-bit
streams to avoid alias sync detection.

Parse EXSS frame size and skip over EXSS frame to avoid alias sync
detection.
---
 libavcodec/dca_parser.c | 94 +
 1 file changed, 80 insertions(+), 14 deletions(-)

diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index bde7dfe..0b09ba5 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -47,6 +47,14 @@ typedef struct DCAParseContext {
 #define CORE_MARKER(state)  ((state >> 16) & 0x)
 #define EXSS_MARKER(state)  (state & 0x)
 
+#define STATE_LE(state) (((state & 0xFF00FF00) >> 8) | ((state & 
0x00FF00FF) << 8))
+#define STATE_14(state) (((state & 0x3FFF) >> 8) | ((state & 
0x3FFF) >> 6))
+
+#define CORE_FRAMESIZE(state)   (((state >> 4) & 0x3FFF) + 1)
+#define EXSS_FRAMESIZE(state)   ((state & 0x20) ? \
+ ((state >>  5) & 0xF) + 1 : \
+ ((state >> 13) & 0x0) + 1)
+
 /**
  * Find the end of the current frame in the bitstream.
  * @return the position of the first byte of the next frame, or -1
@@ -54,12 +62,13 @@ typedef struct DCAParseContext {
 static int dca_find_frame_end(DCAParseContext *pc1, const uint8_t *buf,
   int buf_size)
 {
-int start_found, i;
+int start_found, size, i;
 uint64_t state;
 ParseContext *pc = >pc;
 
 start_found = pc->frame_start_found;
 state   = pc->state64;
+size= pc1->size;
 
 i = 0;
 if (!start_found) {
@@ -80,15 +89,75 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 }
 }
 }
+
 if (start_found) {
 for (; i < buf_size; i++) {
-pc1->size++;
+size++;
 state = (state << 8) | buf[i];
+
+if (start_found == 1) {
+switch (pc1->lastmarker) {
+case DCA_SYNCWORD_CORE_BE:
+if (size == 2) {
+pc1->framesize = CORE_FRAMESIZE(state);
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_CORE_LE:
+if (size == 2) {
+pc1->framesize = CORE_FRAMESIZE(STATE_LE(state));
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_CORE_14B_BE:
+if (size == 4) {
+pc1->framesize = CORE_FRAMESIZE(STATE_14(state)) * 8 / 
14 * 2;
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_CORE_14B_LE:
+if (size == 4) {
+pc1->framesize = 
CORE_FRAMESIZE(STATE_14(STATE_LE(state))) * 8 / 14 * 2;
+start_found= 2;
+}
+break;
+case DCA_SYNCWORD_SUBSTREAM:
+if (size == 6) {
+pc1->framesize = EXSS_FRAMESIZE(state);
+start_found= 2;
+}
+break;
+default:
+av_assert0(0);
+}
+continue;
+}
+
+if (pc1->lastmarker == DCA_SYNCWORD_CORE_BE) {
+if (pc1->framesize > size + 2)
+continue;
+
+if (start_found == 2 && IS_EXSS_MARKER(state)) {
+pc1->framesize = size + 2;
+start_found= 3;
+continue;
+}
+
+if (start_found == 3) {
+if (size == pc1->framesize + 4) {
+pc1->framesize += EXSS_FRAMESIZE(state);
+start_found = 4;
+}
+continue;
+}
+}
+
+if (pc1->framesize > size)
+continue;
+
 if (IS_MARKER(state) &&
 (pc1->lastmarker == CORE_MARKER(state) ||
  pc1->lastmarker == DCA_SYNCWORD_SUBSTREAM)) {
-if (pc1->framesize > pc1->size)
-continue;
 pc->frame_start_found = 0;
 pc->state64   = -1;
 pc1->size = 0;
@@ -96,8 +165,10 @@ static int dca_find_frame_end(DCAParseContext *pc1, const 
uint8_t *buf,
 }
 }
 }
+
 pc->frame_start_found = start_found;
 pc->state64   = state;
+pc1->size = size;
 return END_NOT_FOUND;
 }
 
@@ -110,11 +181,11 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 }
 
 static int 

[FFmpeg-devel] [PATCH 05/10] avcodec/dca: use LUT for LBR frequency ranges

2016-05-13 Thread foo86
Values for unsupported frequencies > 48000 Hz are still included (parser
will make use of them).

Also convert sampling frequencies array to unsigned.
---
 libavcodec/dca_lbr.c | 15 +--
 libavcodec/dcadata.c |  6 +-
 libavcodec/dcadata.h |  3 ++-
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 9a7f4cd..f116ab9 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -1000,15 +1000,15 @@ static int parse_decoder_init(DCALbrDecoder *s, 
GetByteContext *gb)
 int old_band_limit = s->band_limit;
 int old_nchannels = s->nchannels;
 int version, bit_rate_hi;
-unsigned int code;
+unsigned int sr_code;
 
 // Sample rate of LBR audio
-code = bytestream2_get_byte(gb);
-if (code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs)) {
+sr_code = bytestream2_get_byte(gb);
+if (sr_code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs)) {
 av_log(s->avctx, AV_LOG_ERROR, "Invalid LBR sample rate\n");
 return AVERROR_INVALIDDATA;
 }
-s->sample_rate = ff_dca_sampling_freqs[code];
+s->sample_rate = ff_dca_sampling_freqs[sr_code];
 if (s->sample_rate > 48000) {
 avpriv_report_missing_feature(s->avctx, "%d Hz LBR sample rate", 
s->sample_rate);
 return AVERROR_PATCHWELCOME;
@@ -1076,12 +1076,7 @@ static int parse_decoder_init(DCALbrDecoder *s, 
GetByteContext *gb)
 }
 
 // Setup frequency range
-if (s->sample_rate < 14000)
-s->freq_range = 0;
-else if (s->sample_rate < 28000)
-s->freq_range = 1;
-else
-s->freq_range = 2;
+s->freq_range = ff_dca_freq_ranges[sr_code];
 
 // Setup resolution profile
 if (s->bit_rate_orig >= 44000 * (s->nchannels_total + 2))
diff --git a/libavcodec/dcadata.c b/libavcodec/dcadata.c
index 53be01d..2d533d0 100644
--- a/libavcodec/dcadata.c
+++ b/libavcodec/dcadata.c
@@ -8725,11 +8725,15 @@ const int32_t ff_dca_xll_band_coeff[20] = {
  3259333, -5074941,  6928550, -8204883
 };
 
-const int32_t ff_dca_sampling_freqs[16] = {
+const uint32_t ff_dca_sampling_freqs[16] = {
   8000,  16000, 32000, 64000, 128000, 22050,  44100,  88200,
 176400, 352800, 12000, 24000,  48000, 96000, 192000, 384000,
 };
 
+const uint8_t ff_dca_freq_ranges[16] = {
+0, 1, 2, 3, 4, 1, 2, 3, 4, 4, 0, 1, 2, 3, 4, 4
+};
+
 const uint16_t ff_dca_avg_g3_freqs[3] = { 16000, 18000, 24000 };
 
 const uint16_t ff_dca_fst_amp[44] = {
diff --git a/libavcodec/dcadata.h b/libavcodec/dcadata.h
index 0c54225..1ef1342 100644
--- a/libavcodec/dcadata.h
+++ b/libavcodec/dcadata.h
@@ -71,7 +71,8 @@ extern const uint16_t ff_dca_xll_refl_coeff[128];
 
 extern const int32_t ff_dca_xll_band_coeff[20];
 
-extern const int32_t ff_dca_sampling_freqs[16];
+extern const uint32_t ff_dca_sampling_freqs[16];
+extern const uint8_t ff_dca_freq_ranges[16];
 
 extern const uint16_t ff_dca_avg_g3_freqs[3];
 
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 08/10] avcodec/dca: require checked bitstream reader

2016-05-13 Thread foo86
Remove half-working attempt at supporting unchecked bitstream reader by
always copying input data into intermediate buffer with large amount of
padding at the end.

Convert LBR decoder to checked bitstream reader. Convert
dcadec_decode_frame() to parse input data directly if possible.
---
 libavcodec/dca_lbr.c |  1 -
 libavcodec/dca_xll.c |  2 +-
 libavcodec/dcadec.c  | 44 
 libavcodec/dcadec.h  |  2 --
 4 files changed, 17 insertions(+), 32 deletions(-)

diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index f116ab9..342603c 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -18,7 +18,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define UNCHECKED_BITSTREAM_READER  1
 #define BITSTREAM_READER_LE
 
 #include "libavutil/channel_layout.h"
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index e43ee6a..1d616c2 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -1070,7 +1070,7 @@ static int copy_to_pbr(DCAXllDecoder *s, uint8_t *data, 
int size, int delay)
 if (size > DCA_XLL_PBR_BUFFER_MAX)
 return AVERROR(ENOSPC);
 
-if (!s->pbr_buffer && !(s->pbr_buffer = av_malloc(DCA_XLL_PBR_BUFFER_MAX + 
DCA_BUFFER_PADDING_SIZE)))
+if (!s->pbr_buffer && !(s->pbr_buffer = av_malloc(DCA_XLL_PBR_BUFFER_MAX + 
AV_INPUT_BUFFER_PADDING_SIZE)))
 return AVERROR(ENOMEM);
 
 memcpy(s->pbr_buffer, data, size);
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 565242d..4146a85 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -141,22 +141,6 @@ void ff_dca_downmix_to_stereo_float(AVFloatDSPContext 
*fdsp, float **samples,
 }
 }
 
-static int convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, 
int max_size)
-{
-switch (AV_RB32(src)) {
-case DCA_SYNCWORD_CORE_BE:
-case DCA_SYNCWORD_SUBSTREAM:
-memcpy(dst, src, src_size);
-return src_size;
-case DCA_SYNCWORD_CORE_LE:
-case DCA_SYNCWORD_CORE_14B_BE:
-case DCA_SYNCWORD_CORE_14B_LE:
-return avpriv_dca_convert_bitstream(src, src_size, dst, max_size);
-default:
-return AVERROR_INVALIDDATA;
-}
-}
-
 static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
 {
@@ -165,27 +149,31 @@ static int dcadec_decode_frame(AVCodecContext *avctx, 
void *data,
 uint8_t *input = avpkt->data;
 int input_size = avpkt->size;
 int i, ret, prev_packet = s->packet;
+uint32_t mrk;
 
 if (input_size < MIN_PACKET_SIZE || input_size > MAX_PACKET_SIZE) {
 av_log(avctx, AV_LOG_ERROR, "Invalid packet size\n");
 return AVERROR_INVALIDDATA;
 }
 
-av_fast_malloc(>buffer, >buffer_size,
-   FFALIGN(input_size, 4096) + DCA_BUFFER_PADDING_SIZE);
-if (!s->buffer)
-return AVERROR(ENOMEM);
+// Convert input to BE format
+mrk = AV_RB32(input);
+if (mrk != DCA_SYNCWORD_CORE_BE && mrk != DCA_SYNCWORD_SUBSTREAM) {
+av_fast_padded_malloc(>buffer, >buffer_size, input_size);
+if (!s->buffer)
+return AVERROR(ENOMEM);
 
-for (i = 0, ret = AVERROR_INVALIDDATA; i < input_size - MIN_PACKET_SIZE + 
1 && ret < 0; i++)
-ret = convert_bitstream(input + i, input_size - i, s->buffer, 
s->buffer_size);
+for (i = 0, ret = AVERROR_INVALIDDATA; i < input_size - 
MIN_PACKET_SIZE + 1 && ret < 0; i++)
+ret = avpriv_dca_convert_bitstream(input + i, input_size - i, 
s->buffer, s->buffer_size);
 
-if (ret < 0) {
-av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
-return ret;
-}
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
+return ret;
+}
 
-input  = s->buffer;
-input_size = ret;
+input  = s->buffer;
+input_size = ret;
+}
 
 s->packet = 0;
 
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index f52d9f7..0fe4042 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -34,8 +34,6 @@
 #include "dca_xll.h"
 #include "dca_lbr.h"
 
-#define DCA_BUFFER_PADDING_SIZE 1024
-
 #define DCA_PACKET_CORE 0x01
 #define DCA_PACKET_EXSS 0x02
 #define DCA_PACKET_XLL  0x04
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 10/10] avcodec/dca: remove useless debug message

2016-05-13 Thread foo86
Most DTS-in-WAV streams trigger this, making debug output hard to read.
---
 libavcodec/dca_core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index f6c22ca..46825ed 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -1921,10 +1921,8 @@ int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, 
int size)
 return ret;
 
 // Workaround for DTS in WAV
-if (s->frame_size > size && s->frame_size < size + 4) {
-av_log(s->avctx, AV_LOG_DEBUG, "Working around excessive core frame 
size (%d > %d)\n", s->frame_size, size);
+if (s->frame_size > size && s->frame_size < size + 4)
 s->frame_size = size;
-}
 
 if (ff_dca_seek_bits(>gb, s->frame_size * 8)) {
 av_log(s->avctx, AV_LOG_ERROR, "Read past end of core frame\n");
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 07/10] avcodec/dca_parser: set duration for core-less streams

2016-05-13 Thread foo86
This requires parsing EXSS in dca_parse(). Adapt ff_dca_exss_parse()
signature and disable header CRC check when avctx->priv_data is NULL.
---
 libavcodec/dca_exss.c   |  2 +-
 libavcodec/dca_exss.h   |  2 +-
 libavcodec/dca_parser.c | 70 ++---
 libavcodec/dcadec.h |  2 ++
 4 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index 87b2f42..8d0b63f 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -375,7 +375,7 @@ static int set_exss_offsets(DCAExssAsset *asset)
 return 0;
 }
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size)
 {
 int i, ret, offset, wide_hdr, header_size;
 
diff --git a/libavcodec/dca_exss.h b/libavcodec/dca_exss.h
index 323063a..208fae1 100644
--- a/libavcodec/dca_exss.h
+++ b/libavcodec/dca_exss.h
@@ -87,6 +87,6 @@ typedef struct DCAExssParser {
 DCAExssAsset   assets[1];///< Audio asset descriptors
 } DCAExssParser;
 
-int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size);
+int ff_dca_exss_parse(DCAExssParser *s, const uint8_t *data, int size);
 
 #endif
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 0b09ba5..02e8322 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -23,6 +23,8 @@
  */
 
 #include "dca.h"
+#include "dcadata.h"
+#include "dca_exss.h"
 #include "dca_syncwords.h"
 #include "get_bits.h"
 #include "parser.h"
@@ -32,6 +34,8 @@ typedef struct DCAParseContext {
 uint32_t lastmarker;
 int size;
 int framesize;
+DCAExssParser exss;
+unsigned int sr_code;
 } DCAParseContext;
 
 #define IS_CORE_MARKER(state) \
@@ -177,11 +181,12 @@ static av_cold int dca_parse_init(AVCodecParserContext *s)
 DCAParseContext *pc1 = s->priv_data;
 
 pc1->lastmarker = 0;
+pc1->sr_code = -1;
 return 0;
 }
 
-static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
-int *sample_rate)
+static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf,
+int buf_size, int *duration, int *sample_rate)
 {
 GetBitContext gb;
 uint8_t hdr[12 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
@@ -190,6 +195,63 @@ static int dca_parse_params(const uint8_t *buf, int 
buf_size, int *duration,
 if (buf_size < 12)
 return AVERROR_INVALIDDATA;
 
+if (AV_RB32(buf) == DCA_SYNCWORD_SUBSTREAM) {
+DCAExssAsset *asset = >exss.assets[0];
+
+if ((ret = ff_dca_exss_parse(>exss, buf, buf_size)) < 0)
+return ret;
+
+if (asset->extension_mask & DCA_EXSS_LBR) {
+if ((ret = init_get_bits8(, buf + asset->lbr_offset, 
asset->lbr_size)) < 0)
+return ret;
+
+if (get_bits_long(, 32) != DCA_SYNCWORD_LBR)
+return AVERROR_INVALIDDATA;
+
+switch (get_bits(, 8)) {
+case 2:
+pc1->sr_code = get_bits(, 8);
+case 1:
+break;
+default:
+return AVERROR_INVALIDDATA;
+}
+
+if (pc1->sr_code >= FF_ARRAY_ELEMS(ff_dca_sampling_freqs))
+return AVERROR_INVALIDDATA;
+
+*sample_rate = ff_dca_sampling_freqs[pc1->sr_code];
+*duration = 1024 << ff_dca_freq_ranges[pc1->sr_code];
+return 0;
+}
+
+if (asset->extension_mask & DCA_EXSS_XLL) {
+int nsamples_log2;
+
+if ((ret = init_get_bits8(, buf + asset->xll_offset, 
asset->xll_size)) < 0)
+return ret;
+
+if (get_bits_long(, 32) != DCA_SYNCWORD_XLL)
+return AVERROR_INVALIDDATA;
+
+if (get_bits(, 4))
+return AVERROR_INVALIDDATA;
+
+skip_bits(, 8);
+skip_bits_long(, get_bits(, 5) + 1);
+skip_bits(, 4);
+nsamples_log2 = get_bits(, 4) + get_bits(, 4);
+if (nsamples_log2 > 24)
+return AVERROR_INVALIDDATA;
+
+*sample_rate = asset->max_sample_rate;
+*duration = (1 + (*sample_rate > 96000)) << nsamples_log2;
+return 0;
+}
+
+return AVERROR_INVALIDDATA;
+}
+
 if ((ret = avpriv_dca_convert_bitstream(buf, 12, hdr, 12)) < 0)
 return ret;
 
@@ -229,8 +291,10 @@ static int dca_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
 }
 }
 
+pc1->exss.avctx = avctx;
+
 /* read the duration and sample rate from the frame header */
-if (!dca_parse_params(buf, buf_size, , _rate)) {
+if (!dca_parse_params(pc1, buf, buf_size, , _rate)) {
 if (!avctx->sample_rate)
 avctx->sample_rate = sample_rate;
 s->duration = av_rescale(duration, avctx->sample_rate, sample_rate);
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 8528332..f52d9f7 100644
--- 

[FFmpeg-devel] [PATCH 02/10] avcodec/dca: simplify 'residual ok' flag tracking

2016-05-13 Thread foo86
Move this from separate structure field to a packet flag.

Behavior should be equivalent, except that residual flag is now properly
cleared when packet has no core frame at all.

Also print a message when forcing recovery mode due to invalid residual
to make debugging easier.
---
 libavcodec/dcadec.c | 32 ++--
 libavcodec/dcadec.h |  7 ---
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 303b0c2..dac86eb 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -191,10 +191,8 @@ static int dcadec_decode_frame(AVCodecContext *avctx, void 
*data,
 if (AV_RB32(input) == DCA_SYNCWORD_CORE_BE) {
 int frame_size;
 
-if ((ret = ff_dca_core_parse(>core, input, input_size)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_parse(>core, input, input_size)) < 0)
 return ret;
-}
 
 s->packet |= DCA_PACKET_CORE;
 
@@ -263,19 +261,20 @@ static int dcadec_decode_frame(AVCodecContext *avctx, 
void *data,
 if (s->xll.chset[0].freq == 96000 && s->core.sample_rate == 48000)
 x96_synth = 1;
 
-if ((ret = ff_dca_core_filter_fixed(>core, x96_synth)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_filter_fixed(>core, x96_synth)) < 0)
 return ret;
-}
 
 // Force lossy downmixed output on the first core frame filtered.
 // This prevents audible clicks when seeking and is consistent with
 // what reference decoder does when there are multiple channel 
sets.
-if (!s->core_residual_valid) {
-if (s->xll.nreschsets > 0 && s->xll.nchsets > 1)
-s->packet |= DCA_PACKET_RECOVERY;
-s->core_residual_valid = 1;
+if (!(prev_packet & DCA_PACKET_RESIDUAL) && s->xll.nreschsets > 0
+&& s->xll.nchsets > 1) {
+av_log(avctx, AV_LOG_VERBOSE, "Forcing XLL recovery mode\n");
+s->packet |= DCA_PACKET_RECOVERY;
 }
+
+// Set 'residual ok' flag for the next frame
+s->packet |= DCA_PACKET_RESIDUAL;
 }
 
 if ((ret = ff_dca_xll_filter_frame(>xll, frame)) < 0) {
@@ -284,17 +283,14 @@ static int dcadec_decode_frame(AVCodecContext *avctx, 
void *data,
 return ret;
 if (ret != AVERROR_INVALIDDATA || (avctx->err_recognition & 
AV_EF_EXPLODE))
 return ret;
-if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0)
 return ret;
-}
 }
 } else if (s->packet & DCA_PACKET_CORE) {
-if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0) {
-s->core_residual_valid = 0;
+if ((ret = ff_dca_core_filter_frame(>core, frame)) < 0)
 return ret;
-}
-s->core_residual_valid = !!(s->core.filter_mode & 
DCA_FILTER_MODE_FIXED);
+if (s->core.filter_mode & DCA_FILTER_MODE_FIXED)
+s->packet |= DCA_PACKET_RESIDUAL;
 } else {
 return AVERROR_INVALIDDATA;
 }
@@ -312,7 +308,7 @@ static av_cold void dcadec_flush(AVCodecContext *avctx)
 ff_dca_xll_flush(>xll);
 ff_dca_lbr_flush(>lbr);
 
-s->core_residual_valid = 0;
+s->packet &= DCA_PACKET_MASK;
 }
 
 static av_cold int dcadec_close(AVCodecContext *avctx)
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 5e47077..8528332 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -40,7 +40,10 @@
 #define DCA_PACKET_EXSS 0x02
 #define DCA_PACKET_XLL  0x04
 #define DCA_PACKET_LBR  0x08
-#define DCA_PACKET_RECOVERY 0x10
+#define DCA_PACKET_MASK 0x0f
+
+#define DCA_PACKET_RECOVERY 0x10///< Sync error recovery flag
+#define DCA_PACKET_RESIDUAL 0x20///< Core valid for residual decoding
 
 typedef struct DCAContext {
 const AVClass   *class;   ///< class for AVOptions
@@ -60,8 +63,6 @@ typedef struct DCAContext {
 
 int packet; ///< Packet flags
 
-int core_residual_valid;///< Core valid for residual decoding
-
 int request_channel_layout; ///< Converted from 
avctx.request_channel_layout
 int core_only;  ///< Core only decoding flag
 } DCAContext;
-- 
2.8.1

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


[FFmpeg-devel] [PATCH 01/10] avcodec/dca: remove Rice code length limit

2016-05-13 Thread foo86
Limit the maximum length of unary part of Rice code by the number of
available bits instead of using an arbitrary constant that happens to be
just large enough to work.
---
 libavcodec/dca_xll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 316af27..e43ee6a 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -32,7 +32,7 @@ static int get_linear(GetBitContext *gb, int n)
 
 static int get_rice_un(GetBitContext *gb, int k)
 {
-unsigned int v = get_unary(gb, 1, 128);
+unsigned int v = get_unary(gb, 1, get_bits_left(gb));
 return (v << k) | get_bits_long(gb, k);
 }
 
-- 
2.8.1

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


Re: [FFmpeg-devel] [PATCH] libavcodec/options.c: handle hw_frames_ctx where necessary

2016-05-13 Thread Andrey Turkin
2016-05-13 10:35 GMT+03:00 wm4 :

> On Thu, 12 May 2016 22:35:48 +0300
> Andrey Turkin  wrote:
>
> > Few functions didn't handle hw_frames_ctx references causing resources
> leaks and even crashes.
> > ---
> >  libavcodec/options.c | 10 ++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/libavcodec/options.c b/libavcodec/options.c
> > index ea2563b..8682262 100644
> > --- a/libavcodec/options.c
> > +++ b/libavcodec/options.c
> > @@ -175,6 +175,7 @@ void avcodec_free_context(AVCodecContext **pavctx)
> >  av_freep(>intra_matrix);
> >  av_freep(>inter_matrix);
> >  av_freep(>rc_override);
> > +av_buffer_unref(>hw_frames_ctx);
> >
> >  av_freep(pavctx);
> >  }
>
> I would have thought this is the responsibility of the API user?
>
>
AVCodecContext documentation says it is set by a user but then managed and
owned by libavcodec (which is a logical thing to do for any shared
reference).
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavcodec/options.c: handle hw_frames_ctx where necessary

2016-05-13 Thread wm4
On Thu, 12 May 2016 22:35:48 +0300
Andrey Turkin  wrote:

> Few functions didn't handle hw_frames_ctx references causing resources leaks 
> and even crashes.
> ---
>  libavcodec/options.c | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/libavcodec/options.c b/libavcodec/options.c
> index ea2563b..8682262 100644
> --- a/libavcodec/options.c
> +++ b/libavcodec/options.c
> @@ -175,6 +175,7 @@ void avcodec_free_context(AVCodecContext **pavctx)
>  av_freep(>intra_matrix);
>  av_freep(>inter_matrix);
>  av_freep(>rc_override);
> +av_buffer_unref(>hw_frames_ctx);
>  
>  av_freep(pavctx);
>  }

I would have thought this is the responsibility of the API user?

> @@ -197,6 +198,7 @@ int avcodec_copy_context(AVCodecContext *dest, const 
> AVCodecContext *src)
>  av_freep(>inter_matrix);
>  av_freep(>extradata);
>  av_freep(>subtitle_header);
> +av_buffer_unref(>hw_frames_ctx);
>  
>  memcpy(dest, src, sizeof(*dest));
>  av_opt_copy(dest, src);
> @@ -225,6 +227,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  dest->inter_matrix= NULL;
>  dest->rc_override = NULL;
>  dest->subtitle_header = NULL;
> +dest->hw_frames_ctx   = NULL;
>  
>  #define alloc_and_copy_or_fail(obj, size, pad) \
>  if (src->obj && size > 0) { \
> @@ -245,6 +248,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  av_assert0(dest->subtitle_header_size == src->subtitle_header_size);
>  #undef alloc_and_copy_or_fail
>  
> +if (src->hw_frames_ctx) {
> +dest->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);
> +if (!dest->hw_frames_ctx)
> +goto fail;
> +}
> +
>  return 0;
>  
>  fail:
> @@ -255,6 +264,7 @@ fail:
>  av_freep(>subtitle_header);
>  dest->subtitle_header_size = 0;
>  dest->extradata_size = 0;
> +av_buffer_unref(>hw_frames_ctx);
>  av_opt_free(dest);
>  return AVERROR(ENOMEM);
>  }

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