This permits re-use with parsers for codecs which use similar start codes.
---
configure | 3 +-
libavcodec/Makefile | 1 +
libavcodec/arm/Makefile | 2 +-
libavcodec/arm/h264dsp_init_arm.c | 11 +---
libavutil/arm/cpu.h => libavcodec/arm/startcode.h | 20 +++-----
.../arm/{h264dsp_armv6.S => startcode_armv6.S} | 4 +-
libavcodec/h264_parser.c | 2 +-
libavcodec/h264dsp.c | 31 +----------
libavcodec/h264dsp.h | 2 +-
libavcodec/startcode.c | 57 ++++++++++++++++++++
libavutil/arm/cpu.h => libavcodec/startcode.h | 26 +++++----
libavutil/arm/cpu.h | 4 ++
12 files changed, 95 insertions(+), 68 deletions(-)
copy libavutil/arm/cpu.h => libavcodec/arm/startcode.h (62%)
rename libavcodec/arm/{h264dsp_armv6.S => startcode_armv6.S} (98%)
create mode 100644 libavcodec/startcode.c
copy libavutil/arm/cpu.h => libavcodec/startcode.h (62%)
diff --git a/configure b/configure
index 7a29e82..0b9e215 100755
--- a/configure
+++ b/configure
@@ -1566,6 +1566,7 @@ CONFIG_EXTRA="
rtpdec
rtpenc_chain
sinewin
+ startcode
tpeldsp
videodsp
vp3dsp
@@ -1782,7 +1783,7 @@ h263_decoder_select="error_resilience h263_parser h263dsp
mpeg_er mpegvideo qpel
h263_encoder_select="aandcttables h263dsp mpegvideoenc"
h263i_decoder_select="h263_decoder"
h263p_encoder_select="h263_encoder"
-h264_decoder_select="cabac golomb h264chroma h264dsp h264pred h264qpel
videodsp"
+h264_decoder_select="cabac golomb h264chroma h264dsp h264pred h264qpel
startcode videodsp"
h264_decoder_suggest="error_resilience"
hevc_decoder_select="bswapdsp cabac golomb videodsp"
huffyuv_decoder_select="bswapdsp huffyuvdsp"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 632b0da..f25e96f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -78,6 +78,7 @@ OBJS-$(CONFIG_RANGECODER) += rangecoder.o
RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o
OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes)
OBJS-$(CONFIG_SINEWIN) += sinewin.o
+OBJS-$(CONFIG_STARTCODE) += startcode.o
OBJS-$(CONFIG_TPELDSP) += tpeldsp.o
OBJS-$(CONFIG_VAAPI) += vaapi.o
OBJS-$(CONFIG_VDA) += vda.o
diff --git a/libavcodec/arm/Makefile b/libavcodec/arm/Makefile
index 9ba6c20..c8b362c 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -55,7 +55,6 @@ ARMV5TE-OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_armv5te.o
ARMV6-OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_armv6.o
ARMV6-OBJS-$(CONFIG_DSPUTIL) += arm/dsputil_init_armv6.o \
arm/dsputil_armv6.o
-ARMV6-OBJS-$(CONFIG_H264DSP) += arm/h264dsp_armv6.o
ARMV6-OBJS-$(CONFIG_HPELDSP) += arm/hpeldsp_init_armv6.o \
arm/hpeldsp_armv6.o
ARMV6-OBJS-$(CONFIG_IDCTDSP) += arm/idctdsp_init_armv6.o \
@@ -66,6 +65,7 @@ ARMV6-OBJS-$(CONFIG_MPEGVIDEOENC) +=
arm/mpegvideoencdsp_armv6.o
ARMV6-OBJS-$(CONFIG_PIXBLOCKDSP) += arm/pixblockdsp_armv6.o
ARMV6-OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_armv6.o
+ARMV6-OBJS-$(CONFIG_STARTCODE) += arm/startcode_armv6.o
ARMV6-OBJS-$(CONFIG_VP7_DECODER) += arm/vp8_armv6.o \
arm/vp8dsp_init_armv6.o \
arm/vp8dsp_armv6.o
diff --git a/libavcodec/arm/h264dsp_init_arm.c
b/libavcodec/arm/h264dsp_init_arm.c
index f9712d8..7afd350 100644
--- a/libavcodec/arm/h264dsp_init_arm.c
+++ b/libavcodec/arm/h264dsp_init_arm.c
@@ -23,8 +23,7 @@
#include "libavutil/attributes.h"
#include "libavutil/arm/cpu.h"
#include "libavcodec/h264dsp.h"
-
-int ff_h264_find_start_code_candidate_armv6(const uint8_t *buf, int size);
+#include "libavcodec/arm/startcode.h"
void ff_h264_v_loop_filter_luma_neon(uint8_t *pix, int stride, int alpha,
int beta, int8_t *tc0);
@@ -104,12 +103,8 @@ av_cold void ff_h264dsp_init_arm(H264DSPContext *c, const
int bit_depth,
{
int cpu_flags = av_get_cpu_flags();
- if (have_armv6(cpu_flags) && !(have_vfpv3(cpu_flags) ||
have_neon(cpu_flags))) {
- // This function uses the 'setend' instruction which is deprecated
- // on ARMv8. This instruction is serializing on some ARMv7 cores as
- // well. Therefore, only use the function on ARMv6.
- c->h264_find_start_code_candidate =
ff_h264_find_start_code_candidate_armv6;
- }
+ if (have_setend(cpu_flags))
+ c->startcode_find_candidate = ff_startcode_find_candidate_armv6;
if (have_neon(cpu_flags))
h264dsp_init_neon(c, bit_depth, chroma_format_idc);
}
diff --git a/libavutil/arm/cpu.h b/libavcodec/arm/startcode.h
similarity index 62%
copy from libavutil/arm/cpu.h
copy to libavcodec/arm/startcode.h
index 52e839c..948dc48 100644
--- a/libavutil/arm/cpu.h
+++ b/libavcodec/arm/startcode.h
@@ -1,4 +1,7 @@
/*
+ * Copyright (c) 2014 RISC OS Open Ltd
+ * Author: Ben Avison <[email protected]>
+ *
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
@@ -16,18 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef AVUTIL_ARM_CPU_H
-#define AVUTIL_ARM_CPU_H
-
-#include "config.h"
-#include "libavutil/cpu.h"
-#include "libavutil/cpu_internal.h"
+#ifndef AVCODEC_ARM_STARTCODE_H
+#define AVCODEC_ARM_STARTCODE_H
-#define have_armv5te(flags) CPUEXT(flags, ARMV5TE)
-#define have_armv6(flags) CPUEXT(flags, ARMV6)
-#define have_armv6t2(flags) CPUEXT(flags, ARMV6T2)
-#define have_vfp(flags) CPUEXT(flags, VFP)
-#define have_vfpv3(flags) CPUEXT(flags, VFPV3)
-#define have_neon(flags) CPUEXT(flags, NEON)
+int ff_startcode_find_candidate_armv6(const uint8_t *buf, int size);
-#endif /* AVUTIL_ARM_CPU_H */
+#endif /* AVCODEC_ARM_STARTCODE_H */
diff --git a/libavcodec/arm/h264dsp_armv6.S b/libavcodec/arm/startcode_armv6.S
similarity index 98%
rename from libavcodec/arm/h264dsp_armv6.S
rename to libavcodec/arm/startcode_armv6.S
index 384ed86..64078b2 100644
--- a/libavcodec/arm/h264dsp_armv6.S
+++ b/libavcodec/arm/startcode_armv6.S
@@ -69,8 +69,8 @@ TMP3 .req lr
andseq TMP3, TMP3, PATTERN
.endm
-/* int ff_h264_find_start_code_candidate_armv6(const uint8_t *buf, int size) */
-function ff_h264_find_start_code_candidate_armv6, export=1
+/* int ff_startcode_find_candidate_armv6(const uint8_t *buf, int size) */
+function ff_startcode_find_candidate_armv6, export=1
push {v1-v6,lr}
mov PTR, BUF
@ Ensure there are at least (PRELOAD_DISTANCE+2) complete cachelines
to go
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 795a233..8ced0b8 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -48,7 +48,7 @@ static int h264_find_frame_end(H264Context *h, const uint8_t
*buf,
for (i = 0; i < buf_size; i++) {
if (state == 7) {
- i += h->h264dsp.h264_find_start_code_candidate(buf + i, buf_size -
i);
+ i += h->h264dsp.startcode_find_candidate(buf + i, buf_size - i);
if (i < buf_size)
state = 2;
} else if (state <= 2) {
diff --git a/libavcodec/h264dsp.c b/libavcodec/h264dsp.c
index a5b1591..c8edbd0 100644
--- a/libavcodec/h264dsp.c
+++ b/libavcodec/h264dsp.c
@@ -31,6 +31,7 @@
#include "avcodec.h"
#include "h264dsp.h"
#include "h264idct.h"
+#include "startcode.h"
#include "libavutil/common.h"
#define BIT_DEPTH 8
@@ -53,34 +54,6 @@
#include "h264addpx_template.c"
#undef BIT_DEPTH
-static int h264_find_start_code_candidate_c(const uint8_t *buf, int size)
-{
- int i = 0;
-#if HAVE_FAST_UNALIGNED
- /* we check i < size instead of i + 3 / 7 because it is
- * simpler and there must be FF_INPUT_BUFFER_PADDING_SIZE
- * bytes at the end.
- */
-#if HAVE_FAST_64BIT
- while (i < size &&
- !((~*(const uint64_t *)(buf + i) &
- (*(const uint64_t *)(buf + i) - 0x0101010101010101ULL)) &
- 0x8080808080808080ULL))
- i += 8;
-#else
- while (i < size &&
- !((~*(const uint32_t *)(buf + i) &
- (*(const uint32_t *)(buf + i) - 0x01010101U)) &
- 0x80808080U))
- i += 4;
-#endif
-#endif
- for (; i < size; i++)
- if (!buf[i])
- break;
- return i;
-}
-
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth,
const int chroma_format_idc)
{
@@ -161,7 +134,7 @@ av_cold void ff_h264dsp_init(H264DSPContext *c, const int
bit_depth,
H264_DSP(8);
break;
}
- c->h264_find_start_code_candidate = h264_find_start_code_candidate_c;
+ c->startcode_find_candidate = ff_startcode_find_candidate_c;
if (ARCH_AARCH64) ff_h264dsp_init_aarch64(c, bit_depth, chroma_format_idc);
if (ARCH_ARM) ff_h264dsp_init_arm(c, bit_depth, chroma_format_idc);
diff --git a/libavcodec/h264dsp.h b/libavcodec/h264dsp.h
index 9c41336..c4be235 100644
--- a/libavcodec/h264dsp.h
+++ b/libavcodec/h264dsp.h
@@ -113,7 +113,7 @@ typedef struct H264DSPContext {
* one or more further zero bytes and a one byte. Better still, filter
* out any bytes that form the trailing_zero_8bits syntax element too.
*/
- int (*h264_find_start_code_candidate)(const uint8_t *buf, int size);
+ int (*startcode_find_candidate)(const uint8_t *buf, int size);
} H264DSPContext;
void ff_h264dsp_init(H264DSPContext *c, const int bit_depth,
diff --git a/libavcodec/startcode.c b/libavcodec/startcode.c
new file mode 100644
index 0000000..d34981e
--- /dev/null
+++ b/libavcodec/startcode.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2003-2010 Michael Niedermayer <[email protected]>
+ *
+ * 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
+ */
+
+/**
+ * @file
+ * Accelerated start code search function for start codes common to
+ * MPEG-1/2/4 video, VC-1, H.264/5
+ * @author Michael Niedermayer <[email protected]>
+ */
+
+#include "startcode.h"
+#include "config.h"
+
+int ff_startcode_find_candidate_c(const uint8_t *buf, int size)
+{
+ int i = 0;
+#if HAVE_FAST_UNALIGNED
+ /* we check i < size instead of i + 3 / 7 because it is
+ * simpler and there must be FF_INPUT_BUFFER_PADDING_SIZE
+ * bytes at the end.
+ */
+#if HAVE_FAST_64BIT
+ while (i < size &&
+ !((~*(const uint64_t *)(buf + i) &
+ (*(const uint64_t *)(buf + i) - 0x0101010101010101ULL)) &
+ 0x8080808080808080ULL))
+ i += 8;
+#else
+ while (i < size &&
+ !((~*(const uint32_t *)(buf + i) &
+ (*(const uint32_t *)(buf + i) - 0x01010101U)) &
+ 0x80808080U))
+ i += 4;
+#endif
+#endif
+ for (; i < size; i++)
+ if (!buf[i])
+ break;
+ return i;
+}
diff --git a/libavutil/arm/cpu.h b/libavcodec/startcode.h
similarity index 62%
copy from libavutil/arm/cpu.h
copy to libavcodec/startcode.h
index 52e839c..f2be3e5 100644
--- a/libavutil/arm/cpu.h
+++ b/libavcodec/startcode.h
@@ -1,4 +1,6 @@
/*
+ * Copyright (c) 2003-2010 Michael Niedermayer <[email protected]>
+ *
* This file is part of Libav.
*
* Libav is free software; you can redistribute it and/or
@@ -16,18 +18,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef AVUTIL_ARM_CPU_H
-#define AVUTIL_ARM_CPU_H
+/**
+ * @file
+ * Accelerated start code search function for start codes common to
+ * MPEG-1/2/4 video, VC-1, H.264/5
+ * @author Michael Niedermayer <[email protected]>
+ */
+
+#ifndef AVCODEC_STARTCODE_H
+#define AVCODEC_STARTCODE_H
-#include "config.h"
-#include "libavutil/cpu.h"
-#include "libavutil/cpu_internal.h"
+#include <stdint.h>
-#define have_armv5te(flags) CPUEXT(flags, ARMV5TE)
-#define have_armv6(flags) CPUEXT(flags, ARMV6)
-#define have_armv6t2(flags) CPUEXT(flags, ARMV6T2)
-#define have_vfp(flags) CPUEXT(flags, VFP)
-#define have_vfpv3(flags) CPUEXT(flags, VFPV3)
-#define have_neon(flags) CPUEXT(flags, NEON)
+int ff_startcode_find_candidate_c(const uint8_t *buf, int size);
-#endif /* AVUTIL_ARM_CPU_H */
+#endif /* AVCODEC_STARTCODE_H */
diff --git a/libavutil/arm/cpu.h b/libavutil/arm/cpu.h
index 52e839c..05fbbbd 100644
--- a/libavutil/arm/cpu.h
+++ b/libavutil/arm/cpu.h
@@ -29,5 +29,9 @@
#define have_vfp(flags) CPUEXT(flags, VFP)
#define have_vfpv3(flags) CPUEXT(flags, VFPV3)
#define have_neon(flags) CPUEXT(flags, NEON)
+// Some functions use the 'setend' instruction which is deprecated
+// on ARMv8. This instruction is serializing on some ARMv7 cores as
+// well. Use this macro to ensure such functions are only used on ARMv6.
+#define have_setend(flags) (have_armv6(flags) && !(have_vfpv3(flags) ||
have_neon(flags)))
#endif /* AVUTIL_ARM_CPU_H */
--
1.7.5.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel