aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorBen Avison <bavison@riscosopen.org>2014-07-21 16:25:48 +0100
committerLuca Barbato <lu_zero@gentoo.org>2014-08-04 22:22:54 +0200
commitdb7f1c7c5a1d37e7f4da64a79a97bea1c4b6e9f8 (patch)
treed5d872aa5916ca99645f2373f053c15a773af30a /libavcodec
parenteee813eec7d3c0b0689f80665d3f796401742935 (diff)
downloadffmpeg-db7f1c7c5a1d37e7f4da64a79a97bea1c4b6e9f8.tar.gz
h264: Move start code search functions into separate source files.
This permits re-use with parsers for codecs which use similar start codes. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/arm/Makefile2
-rw-r--r--libavcodec/arm/h264dsp_init_arm.c5
-rw-r--r--libavcodec/arm/startcode.h26
-rw-r--r--libavcodec/arm/startcode_armv6.S (renamed from libavcodec/arm/h264dsp_armv6.S)4
-rw-r--r--libavcodec/h264_parser.c2
-rw-r--r--libavcodec/h264dsp.c31
-rw-r--r--libavcodec/h264dsp.h2
-rw-r--r--libavcodec/startcode.c57
-rw-r--r--libavcodec/startcode.h26
10 files changed, 119 insertions, 37 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a088a68fd4..7d19e6ed67 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -79,6 +79,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 742c3ee726..6c2eb997c9 100644
--- a/libavcodec/arm/Makefile
+++ b/libavcodec/arm/Makefile
@@ -53,7 +53,6 @@ ARMV5TE-OBJS-$(CONFIG_VIDEODSP) += arm/videodsp_init_armv5te.o \
ARMV5TE-OBJS-$(CONFIG_MLP_DECODER) += arm/mlpdsp_armv5te.o
ARMV6-OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_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 \
@@ -65,6 +64,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 7cb1312c2b..7afd350890 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);
@@ -105,7 +104,7 @@ av_cold void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth,
int cpu_flags = av_get_cpu_flags();
if (have_setend(cpu_flags))
- c->h264_find_start_code_candidate = ff_h264_find_start_code_candidate_armv6;
+ 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/libavcodec/arm/startcode.h b/libavcodec/arm/startcode.h
new file mode 100644
index 0000000000..d7996c1a4b
--- /dev/null
+++ b/libavcodec/arm/startcode.h
@@ -0,0 +1,26 @@
+/*
+ * 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
+ */
+
+#ifndef AVCODEC_ARM_STARTCODE_H
+#define AVCODEC_ARM_STARTCODE_H
+
+#include <stdint.h>
+
+int ff_startcode_find_candidate_armv6(const uint8_t *buf, int size);
+
+#endif /* AVCODEC_ARM_STARTCODE_H */
diff --git a/libavcodec/arm/h264dsp_armv6.S b/libavcodec/arm/startcode_armv6.S
index 384ed86765..64078b2898 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 795a2339a3..8ced0b811d 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 a5b1591482..c8edbd08eb 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 9c41336092..c4be235519 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 0000000000..d34981e67d
--- /dev/null
+++ b/libavcodec/startcode.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2003-2010 Michael Niedermayer <michaelni@gmx.at>
+ *
+ * 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 <michaelni@gmx.at>
+ */
+
+#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/libavcodec/startcode.h b/libavcodec/startcode.h
new file mode 100644
index 0000000000..f38ce54d6d
--- /dev/null
+++ b/libavcodec/startcode.h
@@ -0,0 +1,26 @@
+/*
+ * 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
+ */
+
+#ifndef AVCODEC_STARTCODE_H
+#define AVCODEC_STARTCODE_H
+
+#include <stdint.h>
+
+int ff_startcode_find_candidate_c(const uint8_t *buf, int size);
+
+#endif /* AVCODEC_STARTCODE_H */