* [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants
@ 2022-10-11 13:13 Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private Andreas Rheinhardt
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2022-10-11 13:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1.h | 7 +++++++
libavcodec/svq1enc.c | 13 +++++--------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/libavcodec/svq1.h b/libavcodec/svq1.h
index 0ebc73a933..af8a7dfa04 100644
--- a/libavcodec/svq1.h
+++ b/libavcodec/svq1.h
@@ -42,6 +42,13 @@
#define SVQ1_BLOCK_INTER_4V 2
#define SVQ1_BLOCK_INTRA 3
+#define SVQ1_BLOCK_SKIP_CODE 1
+#define SVQ1_BLOCK_SKIP_LEN 1
+#define SVQ1_BLOCK_INTER_CODE 1
+#define SVQ1_BLOCK_INTER_LEN 2
+#define SVQ1_BLOCK_INTRA_CODE 0
+#define SVQ1_BLOCK_INTRA_LEN 3
+
extern const int8_t *const ff_svq1_inter_codebooks[6];
extern const int8_t *const ff_svq1_intra_codebooks[6];
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index ef6655c2f7..79e9e578ac 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -390,9 +390,8 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i],
7 * 32);
if (s->pict_type == AV_PICTURE_TYPE_P) {
- const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
- put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
- score[0] = vlc[1] * lambda;
+ put_bits(&s->reorder_pb[5], SVQ1_BLOCK_INTRA_LEN, SVQ1_BLOCK_INTRA_CODE);
+ score[0] = SVQ1_BLOCK_INTRA_LEN * lambda;
}
score[0] += encode_block(s, src + 16 * x, NULL, temp, stride,
5, 64, lambda, 1);
@@ -406,7 +405,6 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
best = 0;
if (s->pict_type == AV_PICTURE_TYPE_P) {
- const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER];
int mx, my, pred_x, pred_y, dxy;
int16_t *motion_ptr;
@@ -417,7 +415,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i],
7 * 32);
- put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
+ put_bits(&s->reorder_pb[5], SVQ1_BLOCK_INTER_LEN, SVQ1_BLOCK_INTER_CODE);
s->m.pb = s->reorder_pb[5];
mx = motion_ptr[0];
@@ -442,14 +440,13 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
decoded, stride, 5, 64, lambda, 0);
best = score[1] <= score[0];
- vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
score[2] = s->mecc.sse[0](NULL, src + 16 * x, ref,
stride, 16);
- score[2] += vlc[1] * lambda;
+ score[2] += SVQ1_BLOCK_SKIP_LEN * lambda;
if (score[2] < score[best] && mx == 0 && my == 0) {
best = 2;
s->hdsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
- put_bits(&s->pb, vlc[1], vlc[0]);
+ put_bits(&s->pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
}
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private
2022-10-11 13:13 [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
@ 2022-10-11 13:18 ` Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 3/4] avcodec/svq1: Set hidden visibility Andreas Rheinhardt
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2022-10-11 13:18 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Currently, SVQ1EncContext is defined in a header that is also
included by the arch-specific code that initializes the one
and only dsp function that this encoder uses directly.
But the arch-specific functions to set this dsp function
do not need anything from SVQ1EncContext. This commit therefore
adds a small SVQ1EncDSPContext whose only member is said
function pointer and renames svq1enc.h to svq1encdsp.h
to avoid exposing unnecessary internals to these init
functions (and the whole mpegvideo with it).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ppc/svq1enc_altivec.c | 4 +-
libavcodec/svq1enc.c | 60 ++++++++++++++++++++--
libavcodec/svq1enc.h | 86 --------------------------------
libavcodec/svq1encdsp.h | 34 +++++++++++++
libavcodec/x86/svq1enc_init.c | 4 +-
5 files changed, 93 insertions(+), 95 deletions(-)
delete mode 100644 libavcodec/svq1enc.h
create mode 100644 libavcodec/svq1encdsp.h
diff --git a/libavcodec/ppc/svq1enc_altivec.c b/libavcodec/ppc/svq1enc_altivec.c
index aa66b40996..5721bede34 100644
--- a/libavcodec/ppc/svq1enc_altivec.c
+++ b/libavcodec/ppc/svq1enc_altivec.c
@@ -27,7 +27,7 @@
#include "libavutil/ppc/cpu.h"
#include "libavutil/ppc/util_altivec.h"
-#include "libavcodec/svq1enc.h"
+#include "libavcodec/svq1encdsp.h"
#if HAVE_ALTIVEC
static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2,
@@ -71,7 +71,7 @@ static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2,
}
#endif /* HAVE_ALTIVEC */
-av_cold void ff_svq1enc_init_ppc(SVQ1EncContext *c)
+av_cold void ff_svq1enc_init_ppc(SVQ1EncDSPContext *c)
{
#if HAVE_ALTIVEC
if (!PPC_ALTIVEC(av_get_cpu_flags()))
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 79e9e578ac..67a6de5cc0 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -37,11 +37,61 @@
#include "internal.h"
#include "mpegutils.h"
#include "packet_internal.h"
+#include "put_bits.h"
#include "svq1.h"
-#include "svq1enc.h"
+#include "svq1encdsp.h"
#include "svq1enc_cb.h"
+
#include "libavutil/avassert.h"
+#include "libavutil/frame.h"
+#include "libavutil/mem_internal.h"
+
+typedef struct SVQ1EncContext {
+ /* FIXME: Needed for motion estimation, should not be used for anything
+ * else, the idea is to make the motion estimation eventually independent
+ * of MpegEncContext, so this will be removed then. */
+ MpegEncContext m;
+ AVCodecContext *avctx;
+ MECmpContext mecc;
+ HpelDSPContext hdsp;
+ AVFrame *current_picture;
+ AVFrame *last_picture;
+ PutBitContext pb;
+
+ /* Some compression statistics */
+ enum AVPictureType pict_type;
+ int quality;
+
+ /* why ooh why this sick breadth first order,
+ * everything is slower and more complex */
+ PutBitContext reorder_pb[6];
+
+ int frame_width;
+ int frame_height;
+
+ /* Y plane block dimensions */
+ int y_block_width;
+ int y_block_height;
+
+ /* U & V plane (C planes) block dimensions */
+ int c_block_width;
+ int c_block_height;
+
+ DECLARE_ALIGNED(16, int16_t, encoded_block_levels)[6][7][256];
+
+ uint16_t *mb_type;
+ uint32_t *dummy;
+ int16_t (*motion_val8[3])[2];
+ int16_t (*motion_val16[3])[2];
+
+ int64_t rd_total;
+
+ uint8_t *scratchbuf;
+
+ int motion_est;
+ SVQ1EncDSPContext svq1encdsp;
+} SVQ1EncContext;
static void svq1_write_header(SVQ1EncContext *s, int frame_type)
{
@@ -154,7 +204,7 @@ static int encode_block(SVQ1EncContext *s, uint8_t *src, uint8_t *ref,
int sqr, diff, score;
vector = codebook + stage * size * 16 + i * size;
- sqr = s->ssd_int8_vs_int16(vector, block[stage], size);
+ sqr = s->svq1encdsp.ssd_int8_vs_int16(vector, block[stage], size);
diff = block_sum[stage] - sum;
score = sqr - (diff * (int64_t)diff >> (level + 3)); // FIXME: 64 bits slooow
if (score < best_vector_score) {
@@ -558,7 +608,7 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
s->y_block_height * sizeof(int16_t));
s->dummy = av_mallocz((s->y_block_width + 1) *
s->y_block_height * sizeof(int32_t));
- s->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
+ s->svq1encdsp.ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
if (!s->m.me.temp || !s->m.me.scratchpad || !s->m.me.map ||
!s->m.me.score_map || !s->mb_type || !s->dummy) {
@@ -566,9 +616,9 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
}
#if ARCH_PPC
- ff_svq1enc_init_ppc(s);
+ ff_svq1enc_init_ppc(&s->svq1encdsp);
#elif ARCH_X86
- ff_svq1enc_init_x86(s);
+ ff_svq1enc_init_x86(&s->svq1encdsp);
#endif
ff_h263_encode_init(&s->m); // mv_penalty
diff --git a/libavcodec/svq1enc.h b/libavcodec/svq1enc.h
deleted file mode 100644
index bb6af082d5..0000000000
--- a/libavcodec/svq1enc.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * SVQ1 encoder
- *
- * 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
- */
-
-#ifndef AVCODEC_SVQ1ENC_H
-#define AVCODEC_SVQ1ENC_H
-
-#include <stdint.h>
-
-#include "libavutil/frame.h"
-#include "libavutil/mem_internal.h"
-
-#include "avcodec.h"
-#include "hpeldsp.h"
-#include "me_cmp.h"
-#include "mpegvideo.h"
-#include "put_bits.h"
-
-typedef struct SVQ1EncContext {
- /* FIXME: Needed for motion estimation, should not be used for anything
- * else, the idea is to make the motion estimation eventually independent
- * of MpegEncContext, so this will be removed then. */
- MpegEncContext m;
- AVCodecContext *avctx;
- MECmpContext mecc;
- HpelDSPContext hdsp;
- AVFrame *current_picture;
- AVFrame *last_picture;
- PutBitContext pb;
-
- /* Some compression statistics */
- enum AVPictureType pict_type;
- int quality;
-
- /* why ooh why this sick breadth first order,
- * everything is slower and more complex */
- PutBitContext reorder_pb[6];
-
- int frame_width;
- int frame_height;
-
- /* Y plane block dimensions */
- int y_block_width;
- int y_block_height;
-
- /* U & V plane (C planes) block dimensions */
- int c_block_width;
- int c_block_height;
-
- DECLARE_ALIGNED(16, int16_t, encoded_block_levels)[6][7][256];
-
- uint16_t *mb_type;
- uint32_t *dummy;
- int16_t (*motion_val8[3])[2];
- int16_t (*motion_val16[3])[2];
-
- int64_t rd_total;
-
- uint8_t *scratchbuf;
-
- int motion_est;
-
- int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
- intptr_t size);
-} SVQ1EncContext;
-
-void ff_svq1enc_init_ppc(SVQ1EncContext *c);
-void ff_svq1enc_init_x86(SVQ1EncContext *c);
-
-#endif /* AVCODEC_SVQ1ENC_H */
diff --git a/libavcodec/svq1encdsp.h b/libavcodec/svq1encdsp.h
new file mode 100644
index 0000000000..91b36735d7
--- /dev/null
+++ b/libavcodec/svq1encdsp.h
@@ -0,0 +1,34 @@
+/*
+ * SVQ1 encoder DSP
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_SVQ1ENCDSP_H
+#define AVCODEC_SVQ1ENCDSP_H
+
+#include <stdint.h>
+
+typedef struct SVQ1EncDSPContext {
+ int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2,
+ intptr_t size);
+} SVQ1EncDSPContext;
+
+void ff_svq1enc_init_ppc(SVQ1EncDSPContext *c);
+void ff_svq1enc_init_x86(SVQ1EncDSPContext *c);
+
+#endif /* AVCODEC_SVQ1ENCDSP_H */
diff --git a/libavcodec/x86/svq1enc_init.c b/libavcodec/x86/svq1enc_init.c
index 787a5245f3..daf573beba 100644
--- a/libavcodec/x86/svq1enc_init.c
+++ b/libavcodec/x86/svq1enc_init.c
@@ -22,12 +22,12 @@
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
-#include "libavcodec/svq1enc.h"
+#include "libavcodec/svq1encdsp.h"
int ff_ssd_int8_vs_int16_sse2(const int8_t *pix1, const int16_t *pix2,
intptr_t size);
-av_cold void ff_svq1enc_init_x86(SVQ1EncContext *c)
+av_cold void ff_svq1enc_init_x86(SVQ1EncDSPContext *c)
{
int cpu_flags = av_get_cpu_flags();
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 3/4] avcodec/svq1: Set hidden visibility
2022-10-11 13:13 [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private Andreas Rheinhardt
@ 2022-10-11 13:18 ` Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 4/4] avcodec/svq1enc: Move PutBitContext from context to stack Andreas Rheinhardt
2022-10-13 17:25 ` [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2022-10-11 13:18 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The encoder uses ff_svq1_inter_mean_vlc + 256 and setting
hidden visibility allows to bake this "+ 256" into the
general offset of ff_svq1_inter_mean_vlc and the code
accessing it.
For certain arches, this is also required for the compiler
to not produce overtly pessimistic code that can't be fixed
up by the linker lateron.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libavcodec/svq1.h b/libavcodec/svq1.h
index af8a7dfa04..0ccf17c253 100644
--- a/libavcodec/svq1.h
+++ b/libavcodec/svq1.h
@@ -37,6 +37,8 @@
#include <stdint.h>
+#include "libavutil/attributes_internal.h"
+
#define SVQ1_BLOCK_SKIP 0
#define SVQ1_BLOCK_INTER 1
#define SVQ1_BLOCK_INTER_4V 2
@@ -49,6 +51,7 @@
#define SVQ1_BLOCK_INTRA_CODE 0
#define SVQ1_BLOCK_INTRA_LEN 3
+FF_VISIBILITY_PUSH_HIDDEN
extern const int8_t *const ff_svq1_inter_codebooks[6];
extern const int8_t *const ff_svq1_intra_codebooks[6];
@@ -59,5 +62,6 @@ extern const uint16_t ff_svq1_intra_mean_vlc[256][2];
extern const uint16_t ff_svq1_inter_mean_vlc[512][2];
extern const uint16_t ff_svq1_frame_size_table[7][2];
+FF_VISIBILITY_POP_HIDDEN
#endif /* AVCODEC_SVQ1_H */
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] avcodec/svq1enc: Move PutBitContext from context to stack
2022-10-11 13:13 [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 3/4] avcodec/svq1: Set hidden visibility Andreas Rheinhardt
@ 2022-10-11 13:18 ` Andreas Rheinhardt
2022-10-13 17:25 ` [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2022-10-11 13:18 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is more natural, because said context is only used
for the duration of one call to svq1_encode_frame().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/svq1enc.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 67a6de5cc0..75adbe7ea0 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -56,7 +56,6 @@ typedef struct SVQ1EncContext {
HpelDSPContext hdsp;
AVFrame *current_picture;
AVFrame *last_picture;
- PutBitContext pb;
/* Some compression statistics */
enum AVPictureType pict_type;
@@ -93,38 +92,38 @@ typedef struct SVQ1EncContext {
SVQ1EncDSPContext svq1encdsp;
} SVQ1EncContext;
-static void svq1_write_header(SVQ1EncContext *s, int frame_type)
+static void svq1_write_header(SVQ1EncContext *s, PutBitContext *pb, int frame_type)
{
int i;
/* frame code */
- put_bits(&s->pb, 22, 0x20);
+ put_bits(pb, 22, 0x20);
/* temporal reference (sure hope this is a "don't care") */
- put_bits(&s->pb, 8, 0x00);
+ put_bits(pb, 8, 0x00);
/* frame type */
- put_bits(&s->pb, 2, frame_type - 1);
+ put_bits(pb, 2, frame_type - 1);
if (frame_type == AV_PICTURE_TYPE_I) {
/* no checksum since frame code is 0x20 */
/* no embedded string either */
/* output 5 unknown bits (2 + 2 + 1) */
- put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */
+ put_bits(pb, 5, 2); /* 2 needed by quicktime decoder */
i = ff_match_2uint16((void*)ff_svq1_frame_size_table,
FF_ARRAY_ELEMS(ff_svq1_frame_size_table),
s->frame_width, s->frame_height);
- put_bits(&s->pb, 3, i);
+ put_bits(pb, 3, i);
if (i == 7) {
- put_bits(&s->pb, 12, s->frame_width);
- put_bits(&s->pb, 12, s->frame_height);
+ put_bits(pb, 12, s->frame_width);
+ put_bits(pb, 12, s->frame_height);
}
}
/* no checksum or extra data (next 2 bits get 0) */
- put_bits(&s->pb, 2, 0);
+ put_bits(pb, 2, 0);
}
#define QUALITY_THRESHOLD 100
@@ -298,6 +297,7 @@ static void init_block_index(MpegEncContext *s){
}
static int svq1_encode_plane(SVQ1EncContext *s, int plane,
+ PutBitContext *pb,
const unsigned char *src_plane,
unsigned char *ref_plane,
unsigned char *decoded_plane,
@@ -425,7 +425,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
int score[4] = { 0, 0, 0, 0 }, best;
uint8_t *temp = s->scratchbuf;
- if (put_bytes_left(&s->pb, 0) < 3000) { // FIXME: check size
+ if (put_bytes_left(pb, 0) < 3000) { // FIXME: check size
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
@@ -496,7 +496,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
if (score[2] < score[best] && mx == 0 && my == 0) {
best = 2;
s->hdsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
- put_bits(&s->pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
+ put_bits(pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
}
}
@@ -521,7 +521,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
if (best != 2)
for (i = 5; i >= 0; i--)
- ff_copy_bits(&s->pb, reorder_buffer[best][i],
+ ff_copy_bits(pb, reorder_buffer[best][i],
count[best][i]);
if (best == 0)
s->hdsp.put_pixels_tab[0][0](decoded, temp, stride, 16);
@@ -630,6 +630,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *pict, int *got_packet)
{
SVQ1EncContext *const s = avctx->priv_data;
+ PutBitContext pb;
int i, ret;
ret = ff_alloc_packet(avctx, pkt, s->y_block_width * s->y_block_height *
@@ -660,8 +661,6 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
FFSWAP(AVFrame*, s->current_picture, s->last_picture);
- init_put_bits(&s->pb, pkt->data, pkt->size);
-
if (avctx->gop_size && (avctx->frame_number % avctx->gop_size))
s->pict_type = AV_PICTURE_TYPE_P;
else
@@ -670,9 +669,10 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
ff_side_data_set_encoder_stats(pkt, pict->quality, NULL, 0, s->pict_type);
- svq1_write_header(s, s->pict_type);
+ init_put_bits(&pb, pkt->data, pkt->size);
+ svq1_write_header(s, &pb, s->pict_type);
for (i = 0; i < 3; i++) {
- int ret = svq1_encode_plane(s, i,
+ int ret = svq1_encode_plane(s, i, &pb,
pict->data[i],
s->last_picture->data[i],
s->current_picture->data[i],
@@ -692,13 +692,13 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}
}
- // align_put_bits(&s->pb);
- while (put_bits_count(&s->pb) & 31)
- put_bits(&s->pb, 1, 0);
+ // align_put_bits(&pb);
+ while (put_bits_count(&pb) & 31)
+ put_bits(&pb, 1, 0);
- flush_put_bits(&s->pb);
+ flush_put_bits(&pb);
- pkt->size = put_bytes_output(&s->pb);
+ pkt->size = put_bytes_output(&pb);
if (s->pict_type == AV_PICTURE_TYPE_I)
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants
2022-10-11 13:13 [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
` (2 preceding siblings ...)
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 4/4] avcodec/svq1enc: Move PutBitContext from context to stack Andreas Rheinhardt
@ 2022-10-13 17:25 ` Andreas Rheinhardt
3 siblings, 0 replies; 5+ messages in thread
From: Andreas Rheinhardt @ 2022-10-13 17:25 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/svq1.h | 7 +++++++
> libavcodec/svq1enc.c | 13 +++++--------
> 2 files changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/libavcodec/svq1.h b/libavcodec/svq1.h
> index 0ebc73a933..af8a7dfa04 100644
> --- a/libavcodec/svq1.h
> +++ b/libavcodec/svq1.h
> @@ -42,6 +42,13 @@
> #define SVQ1_BLOCK_INTER_4V 2
> #define SVQ1_BLOCK_INTRA 3
>
> +#define SVQ1_BLOCK_SKIP_CODE 1
> +#define SVQ1_BLOCK_SKIP_LEN 1
> +#define SVQ1_BLOCK_INTER_CODE 1
> +#define SVQ1_BLOCK_INTER_LEN 2
> +#define SVQ1_BLOCK_INTRA_CODE 0
> +#define SVQ1_BLOCK_INTRA_LEN 3
> +
> extern const int8_t *const ff_svq1_inter_codebooks[6];
> extern const int8_t *const ff_svq1_intra_codebooks[6];
>
> diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
> index ef6655c2f7..79e9e578ac 100644
> --- a/libavcodec/svq1enc.c
> +++ b/libavcodec/svq1enc.c
> @@ -390,9 +390,8 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
> init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i],
> 7 * 32);
> if (s->pict_type == AV_PICTURE_TYPE_P) {
> - const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA];
> - put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
> - score[0] = vlc[1] * lambda;
> + put_bits(&s->reorder_pb[5], SVQ1_BLOCK_INTRA_LEN, SVQ1_BLOCK_INTRA_CODE);
> + score[0] = SVQ1_BLOCK_INTRA_LEN * lambda;
> }
> score[0] += encode_block(s, src + 16 * x, NULL, temp, stride,
> 5, 64, lambda, 1);
> @@ -406,7 +405,6 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
> best = 0;
>
> if (s->pict_type == AV_PICTURE_TYPE_P) {
> - const uint8_t *vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER];
> int mx, my, pred_x, pred_y, dxy;
> int16_t *motion_ptr;
>
> @@ -417,7 +415,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
> init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i],
> 7 * 32);
>
> - put_bits(&s->reorder_pb[5], vlc[1], vlc[0]);
> + put_bits(&s->reorder_pb[5], SVQ1_BLOCK_INTER_LEN, SVQ1_BLOCK_INTER_CODE);
>
> s->m.pb = s->reorder_pb[5];
> mx = motion_ptr[0];
> @@ -442,14 +440,13 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
> decoded, stride, 5, 64, lambda, 0);
> best = score[1] <= score[0];
>
> - vlc = ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP];
> score[2] = s->mecc.sse[0](NULL, src + 16 * x, ref,
> stride, 16);
> - score[2] += vlc[1] * lambda;
> + score[2] += SVQ1_BLOCK_SKIP_LEN * lambda;
> if (score[2] < score[best] && mx == 0 && my == 0) {
> best = 2;
> s->hdsp.put_pixels_tab[0][0](decoded, ref, stride, 16);
> - put_bits(&s->pb, vlc[1], vlc[0]);
> + put_bits(&s->pb, SVQ1_BLOCK_SKIP_LEN, SVQ1_BLOCK_SKIP_CODE);
> }
> }
>
Will apply this patchset tomorrow unless there are objections.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-13 17:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11 13:13 [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 2/4] avcodec/svq1enc: Add SVQ1EncDSPContext, make codec context private Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 3/4] avcodec/svq1: Set hidden visibility Andreas Rheinhardt
2022-10-11 13:18 ` [FFmpeg-devel] [PATCH 4/4] avcodec/svq1enc: Move PutBitContext from context to stack Andreas Rheinhardt
2022-10-13 17:25 ` [FFmpeg-devel] [PATCH 1/4] avcodec/svq1enc: Inline constants Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git