diff options
author | Paul B Mahol <onemda@gmail.com> | 2013-09-18 11:04:11 +0000 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2013-09-18 11:05:27 +0000 |
commit | 8302abf84499f949a7f5b5e78a37cc05c24a6545 (patch) | |
tree | 885bc544a1a64dc06cb391cb5d88f643ed32b728 /libavfilter | |
parent | 66e199bd7532a8b497e4ab8611768099c8f8daf8 (diff) | |
download | ffmpeg-8302abf84499f949a7f5b5e78a37cc05c24a6545.tar.gz |
lavfi/mp: remove mp=pullup
The filter was ported to a native libavfilter filter.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/Makefile | 2 | ||||
-rw-r--r-- | libavfilter/libmpcodecs/pullup.c | 823 | ||||
-rw-r--r-- | libavfilter/libmpcodecs/pullup.h | 102 | ||||
-rw-r--r-- | libavfilter/libmpcodecs/vf_pullup.c | 316 | ||||
-rw-r--r-- | libavfilter/version.h | 2 | ||||
-rw-r--r-- | libavfilter/vf_mp.c | 2 |
6 files changed, 1 insertions, 1246 deletions
diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 78b5f17abb..198bf4c444 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -231,11 +231,9 @@ OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq.o OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pp7.o -OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pullup.o OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_qp.o OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softpulldown.o OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_uspp.o -OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/pullup.o # multimedia filters OBJS-$(CONFIG_AVECTORSCOPE_FILTER) += avf_avectorscope.o diff --git a/libavfilter/libmpcodecs/pullup.c b/libavfilter/libmpcodecs/pullup.c deleted file mode 100644 index b5fae9ba61..0000000000 --- a/libavfilter/libmpcodecs/pullup.c +++ /dev/null @@ -1,823 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "libavutil/x86/asm.h" -#include "config.h" -#include "pullup.h" - - - -#if ARCH_X86 -#if HAVE_MMX -static int diff_y_mmx(unsigned char *a, unsigned char *b, int s) -{ - int ret; - __asm__ volatile ( - "movl $4, %%ecx \n\t" - "pxor %%mm4, %%mm4 \n\t" - "pxor %%mm7, %%mm7 \n\t" - - "1: \n\t" - - "movq (%%"REG_S"), %%mm0 \n\t" - "movq (%%"REG_S"), %%mm2 \n\t" - "add %%"REG_a", %%"REG_S" \n\t" - "movq (%%"REG_D"), %%mm1 \n\t" - "add %%"REG_a", %%"REG_D" \n\t" - "psubusb %%mm1, %%mm2 \n\t" - "psubusb %%mm0, %%mm1 \n\t" - "movq %%mm2, %%mm0 \n\t" - "movq %%mm1, %%mm3 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "punpckhbw %%mm7, %%mm2 \n\t" - "punpckhbw %%mm7, %%mm3 \n\t" - "paddw %%mm0, %%mm4 \n\t" - "paddw %%mm1, %%mm4 \n\t" - "paddw %%mm2, %%mm4 \n\t" - "paddw %%mm3, %%mm4 \n\t" - - "decl %%ecx \n\t" - "jnz 1b \n\t" - - "movq %%mm4, %%mm3 \n\t" - "punpcklwd %%mm7, %%mm4 \n\t" - "punpckhwd %%mm7, %%mm3 \n\t" - "paddd %%mm4, %%mm3 \n\t" - "movd %%mm3, %%eax \n\t" - "psrlq $32, %%mm3 \n\t" - "movd %%mm3, %%edx \n\t" - "addl %%edx, %%eax \n\t" - "emms \n\t" - : "=a" (ret) - : "S" (a), "D" (b), "a" (s) - : "%ecx", "%edx" - ); - return ret; -} - -static int licomb_y_mmx(unsigned char *a, unsigned char *b, int s) -{ - int ret; - __asm__ volatile ( - "movl $4, %%ecx \n\t" - "pxor %%mm6, %%mm6 \n\t" - "pxor %%mm7, %%mm7 \n\t" - "sub %%"REG_a", %%"REG_D" \n\t" - - "2: \n\t" - - "movq (%%"REG_D"), %%mm0 \n\t" - "movq (%%"REG_D"), %%mm1 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "paddw %%mm0, %%mm0 \n\t" - "paddw %%mm2, %%mm1 \n\t" - "movq %%mm0, %%mm2 \n\t" - "psubusw %%mm1, %%mm0 \n\t" - "psubusw %%mm2, %%mm1 \n\t" - "paddw %%mm0, %%mm6 \n\t" - "paddw %%mm1, %%mm6 \n\t" - - "movq (%%"REG_S"), %%mm0 \n\t" - "movq (%%"REG_D"), %%mm1 \n\t" - "punpckhbw %%mm7, %%mm0 \n\t" - "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t" - "punpckhbw %%mm7, %%mm1 \n\t" - "punpckhbw %%mm7, %%mm2 \n\t" - "paddw %%mm0, %%mm0 \n\t" - "paddw %%mm2, %%mm1 \n\t" - "movq %%mm0, %%mm2 \n\t" - "psubusw %%mm1, %%mm0 \n\t" - "psubusw %%mm2, %%mm1 \n\t" - "paddw %%mm0, %%mm6 \n\t" - "paddw %%mm1, %%mm6 \n\t" - - "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t" - "movq (%%"REG_S"), %%mm1 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "paddw %%mm0, %%mm0 \n\t" - "paddw %%mm2, %%mm1 \n\t" - "movq %%mm0, %%mm2 \n\t" - "psubusw %%mm1, %%mm0 \n\t" - "psubusw %%mm2, %%mm1 \n\t" - "paddw %%mm0, %%mm6 \n\t" - "paddw %%mm1, %%mm6 \n\t" - - "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t" - "movq (%%"REG_S"), %%mm1 \n\t" - "punpckhbw %%mm7, %%mm0 \n\t" - "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t" - "punpckhbw %%mm7, %%mm1 \n\t" - "punpckhbw %%mm7, %%mm2 \n\t" - "paddw %%mm0, %%mm0 \n\t" - "paddw %%mm2, %%mm1 \n\t" - "movq %%mm0, %%mm2 \n\t" - "psubusw %%mm1, %%mm0 \n\t" - "psubusw %%mm2, %%mm1 \n\t" - "paddw %%mm0, %%mm6 \n\t" - "paddw %%mm1, %%mm6 \n\t" - - "add %%"REG_a", %%"REG_S" \n\t" - "add %%"REG_a", %%"REG_D" \n\t" - "decl %%ecx \n\t" - "jnz 2b \n\t" - - "movq %%mm6, %%mm5 \n\t" - "punpcklwd %%mm7, %%mm6 \n\t" - "punpckhwd %%mm7, %%mm5 \n\t" - "paddd %%mm6, %%mm5 \n\t" - "movd %%mm5, %%eax \n\t" - "psrlq $32, %%mm5 \n\t" - "movd %%mm5, %%edx \n\t" - "addl %%edx, %%eax \n\t" - - "emms \n\t" - : "=a" (ret) - : "S" (a), "D" (b), "a" (s) - : "%ecx", "%edx" - ); - return ret; -} - -static int var_y_mmx(unsigned char *a, unsigned char *b, int s) -{ - int ret; - __asm__ volatile ( - "movl $3, %%ecx \n\t" - "pxor %%mm4, %%mm4 \n\t" - "pxor %%mm7, %%mm7 \n\t" - - "1: \n\t" - - "movq (%%"REG_S"), %%mm0 \n\t" - "movq (%%"REG_S"), %%mm2 \n\t" - "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t" - "add %%"REG_a", %%"REG_S" \n\t" - "psubusb %%mm1, %%mm2 \n\t" - "psubusb %%mm0, %%mm1 \n\t" - "movq %%mm2, %%mm0 \n\t" - "movq %%mm1, %%mm3 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "punpckhbw %%mm7, %%mm2 \n\t" - "punpckhbw %%mm7, %%mm3 \n\t" - "paddw %%mm0, %%mm4 \n\t" - "paddw %%mm1, %%mm4 \n\t" - "paddw %%mm2, %%mm4 \n\t" - "paddw %%mm3, %%mm4 \n\t" - - "decl %%ecx \n\t" - "jnz 1b \n\t" - - "movq %%mm4, %%mm3 \n\t" - "punpcklwd %%mm7, %%mm4 \n\t" - "punpckhwd %%mm7, %%mm3 \n\t" - "paddd %%mm4, %%mm3 \n\t" - "movd %%mm3, %%eax \n\t" - "psrlq $32, %%mm3 \n\t" - "movd %%mm3, %%edx \n\t" - "addl %%edx, %%eax \n\t" - "emms \n\t" - : "=a" (ret) - : "S" (a), "a" (s) - : "%ecx", "%edx" - ); - return 4*ret; -} -#endif -#endif - -#define ABS(a) (((a)^((a)>>31))-((a)>>31)) - -static int diff_y(unsigned char *a, unsigned char *b, int s) -{ - int i, j, diff=0; - for (i=4; i; i--) { - for (j=0; j<8; j++) diff += ABS(a[j]-b[j]); - a+=s; b+=s; - } - return diff; -} - -static int licomb_y(unsigned char *a, unsigned char *b, int s) -{ - int i, j, diff=0; - for (i=4; i; i--) { - for (j=0; j<8; j++) - diff += ABS((a[j]<<1) - b[j-s] - b[j]) - + ABS((b[j]<<1) - a[j] - a[j+s]); - a+=s; b+=s; - } - return diff; -} - -#if 0 -static int qpcomb_y(unsigned char *a, unsigned char *b, int s) -{ - int i, j, diff=0; - for (i=4; i; i--) { - for (j=0; j<8; j++) - diff += ABS(a[j] - 3*b[j-s] + 3*a[j+s] - b[j]); - a+=s; b+=s; - } - return diff; -} - -static int licomb_y_test(unsigned char *a, unsigned char *b, int s) -{ - int c = licomb_y(a,b,s); - int m = licomb_y_mmx(a,b,s); - if (c != m) printf("%d != %d\n", c, m); - return m; -} -#endif - -static int var_y(unsigned char *a, unsigned char *b, int s) -{ - int i, j, var=0; - for (i=3; i; i--) { - for (j=0; j<8; j++) { - var += ABS(a[j]-a[j+s]); - } - a+=s; b+=s; - } - return 4*var; /* match comb scaling */ -} - - - - - - - - - -static void alloc_buffer(struct pullup_context *c, struct pullup_buffer *b) -{ - int i; - if (b->planes) return; - b->planes = calloc(c->nplanes, sizeof(unsigned char *)); - for (i = 0; i < c->nplanes; i++) { - b->planes[i] = malloc(c->h[i]*c->stride[i]); - /* Deal with idiotic 128=0 for chroma: */ - memset(b->planes[i], c->background[i], c->h[i]*c->stride[i]); - } -} - -struct pullup_buffer *ff_pullup_lock_buffer(struct pullup_buffer *b, int parity) -{ - if (!b) return 0; - if ((parity+1) & 1) b->lock[0]++; - if ((parity+1) & 2) b->lock[1]++; - return b; -} - -void ff_pullup_release_buffer(struct pullup_buffer *b, int parity) -{ - if (!b) return; - if ((parity+1) & 1) b->lock[0]--; - if ((parity+1) & 2) b->lock[1]--; -} - -struct pullup_buffer *ff_pullup_get_buffer(struct pullup_context *c, int parity) -{ - int i; - - /* Try first to get the sister buffer for the previous field */ - if (parity < 2 && c->last && parity != c->last->parity - && !c->last->buffer->lock[parity]) { - alloc_buffer(c, c->last->buffer); - return ff_pullup_lock_buffer(c->last->buffer, parity); - } - - /* Prefer a buffer with both fields open */ - for (i = 0; i < c->nbuffers; i++) { - if (c->buffers[i].lock[0]) continue; - if (c->buffers[i].lock[1]) continue; - alloc_buffer(c, &c->buffers[i]); - return ff_pullup_lock_buffer(&c->buffers[i], parity); - } - - if (parity == 2) return 0; - - /* Search for any half-free buffer */ - for (i = 0; i < c->nbuffers; i++) { - if (((parity+1) & 1) && c->buffers[i].lock[0]) continue; - if (((parity+1) & 2) && c->buffers[i].lock[1]) continue; - alloc_buffer(c, &c->buffers[i]); - return ff_pullup_lock_buffer(&c->buffers[i], parity); - } - - return 0; -} - - - - - - -static void compute_metric(struct pullup_context *c, - struct pullup_field *fa, int pa, - struct pullup_field *fb, int pb, - int (*func)(unsigned char *, unsigned char *, int), int *dest) -{ - unsigned char *a, *b; - int x, y; - int mp = c->metric_plane; - int xstep = c->bpp[mp]; - int ystep = c->stride[mp]<<3; - int s = c->stride[mp]<<1; /* field stride */ - int w = c->metric_w*xstep; - - if (!fa->buffer || !fb->buffer) return; - - /* Shortcut for duplicate fields (e.g. from RFF flag) */ - if (fa->buffer == fb->buffer && pa == pb) { - memset(dest, 0, c->metric_len * sizeof(int)); - return; - } - - a = fa->buffer->planes[mp] + pa * c->stride[mp] + c->metric_offset; - b = fb->buffer->planes[mp] + pb * c->stride[mp] + c->metric_offset; - - for (y = c->metric_h; y; y--) { - for (x = 0; x < w; x += xstep) { - *dest++ = func(a + x, b + x, s); - } - a += ystep; b += ystep; - } -} - - - - - -static void alloc_metrics(struct pullup_context *c, struct pullup_field *f) -{ - f->diffs = calloc(c->metric_len, sizeof(int)); - f->comb = calloc(c->metric_len, sizeof(int)); - f->var = calloc(c->metric_len, sizeof(int)); - /* add more metrics here as needed */ -} - -static struct pullup_field *make_field_queue(struct pullup_context *c, int len) -{ - struct pullup_field *head, *f; - f = head = calloc(1, sizeof(struct pullup_field)); - alloc_metrics(c, f); - for (; len > 0; len--) { - f->next = calloc(1, sizeof(struct pullup_field)); - f->next->prev = f; - f = f->next; - alloc_metrics(c, f); - } - f->next = head; - head->prev = f; - return head; -} - -static void check_field_queue(struct pullup_context *c) -{ - if (c->head->next == c->first) { - struct pullup_field *f = calloc(1, sizeof(struct pullup_field)); - alloc_metrics(c, f); - f->prev = c->head; - f->next = c->first; - c->head->next = f; - c->first->prev = f; - } -} - -void ff_pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity) -{ - struct pullup_field *f; - - /* Grow the circular list if needed */ - check_field_queue(c); - - /* Cannot have two fields of same parity in a row; drop the new one */ - if (c->last && c->last->parity == parity) return; - - f = c->head; - f->parity = parity; - f->buffer = ff_pullup_lock_buffer(b, parity); - f->flags = 0; - f->breaks = 0; - f->affinity = 0; - - compute_metric(c, f, parity, f->prev->prev, parity, c->diff, f->diffs); - compute_metric(c, parity?f->prev:f, 0, parity?f:f->prev, 1, c->comb, f->comb); - compute_metric(c, f, parity, f, -1, c->var, f->var); - - /* Advance the circular list */ - if (!c->first) c->first = c->head; - c->last = c->head; - c->head = c->head->next; -} - -void ff_pullup_flush_fields(struct pullup_context *c) -{ - struct pullup_field *f; - - for (f = c->first; f && f != c->head; f = f->next) { - ff_pullup_release_buffer(f->buffer, f->parity); - f->buffer = 0; - } - c->first = c->last = 0; -} - - - - - - - - -#define F_HAVE_BREAKS 1 -#define F_HAVE_AFFINITY 2 - - -#define BREAK_LEFT 1 -#define BREAK_RIGHT 2 - - - - -static int queue_length(struct pullup_field *begin, struct pullup_field *end) -{ - int count = 1; - struct pullup_field *f; - - if (!begin || !end) return 0; - for (f = begin; f != end; f = f->next) count++; - return count; -} - -static int find_first_break(struct pullup_field *f, int max) -{ - int i; - for (i = 0; i < max; i++) { - if (f->breaks & BREAK_RIGHT || f->next->breaks & BREAK_LEFT) - return i+1; - f = f->next; - } - return 0; -} - -static void compute_breaks(struct pullup_context *c, struct pullup_field *f0) -{ - int i; - struct pullup_field *f1 = f0->next; - struct pullup_field *f2 = f1->next; - struct pullup_field *f3 = f2->next; - int l, max_l=0, max_r=0; - //struct pullup_field *ff; - //for (i=0, ff=c->first; ff != f0; i++, ff=ff->next); - - if (f0->flags & F_HAVE_BREAKS) return; - //printf("\n%d: ", i); - f0->flags |= F_HAVE_BREAKS; - - /* Special case when fields are 100% identical */ - if (f0->buffer == f2->buffer && f1->buffer != f3->buffer) { - f2->breaks |= BREAK_RIGHT; - return; - } - if (f0->buffer != f2->buffer && f1->buffer == f3->buffer) { - f1->breaks |= BREAK_LEFT; - return; - } - - for (i = 0; i < c->metric_len; i++) { - l = f2->diffs[i] - f3->diffs[i]; - if (l > max_l) max_l = l; - if (-l > max_r) max_r = -l; - } - /* Don't get tripped up when differences are mostly quant error */ - //printf("%d %d\n", max_l, max_r); - if (max_l + max_r < 128) return; - if (max_l > 4*max_r) f1->breaks |= BREAK_LEFT; - if (max_r > 4*max_l) f2->breaks |= BREAK_RIGHT; -} - -static void compute_affinity(struct pullup_context *c, struct pullup_field *f) -{ - int i; - int max_l=0, max_r=0, l; - if (f->flags & F_HAVE_AFFINITY) return; - f->flags |= F_HAVE_AFFINITY; - if (f->buffer == f->next->next->buffer) { - f->affinity = 1; - f->next->affinity = 0; - f->next->next->affinity = -1; - f->next->flags |= F_HAVE_AFFINITY; - f->next->next->flags |= F_HAVE_AFFINITY; - return; - } - if (1) { - for (i = 0; i < c->metric_len; i++) { - int lv = f->prev->var[i]; - int rv = f->next->var[i]; - int v = f->var[i]; - int lc = f->comb[i] - (v+lv) + ABS(v-lv); - int rc = f->next->comb[i] - (v+rv) + ABS(v-rv); - lc = lc>0 ? lc : 0; - rc = rc>0 ? rc : 0; - l = lc - rc; - if (l > max_l) max_l = l; - if (-l > max_r) max_r = -l; - } - if (max_l + max_r < 64) return; - if (max_r > 6*max_l) f->affinity = -1; - else if (max_l > 6*max_r) f->affinity = 1; - } else { - for (i = 0; i < c->metric_len; i++) { - l = f->comb[i] - f->next->comb[i]; - if (l > max_l) max_l = l; - if (-l > max_r) max_r = -l; - } - if (max_l + max_r < 64) return; - if (max_r > 2*max_l) f->affinity = -1; - else if (max_l > 2*max_r) f->affinity = 1; - } -} - -static void foo(struct pullup_context *c) -{ - struct pullup_field *f = c->first; - int i, n = queue_length(f, c->last); - for (i = 0; i < n-1; i++) { - if (i < n-3) compute_breaks(c, f); - compute_affinity(c, f); - f = f->next; - } -} - -static int decide_frame_length(struct pullup_context *c) -{ - struct pullup_field *f0 = c->first; - struct pullup_field *f1 = f0->next; - struct pullup_field *f2 = f1->next; - int l; - - if (queue_length(c->first, c->last) < 4) return 0; - foo(c); - - if (f0->affinity == -1) return 1; - - l = find_first_break(f0, 3); - if (l == 1 && c->strict_breaks < 0) l = 0; - - switch (l) { - case 1: - if (c->strict_breaks < 1 && f0->affinity == 1 && f1->affinity == -1) - return 2; - else return 1; - case 2: - /* FIXME: strictly speaking, f0->prev is no longer valid... :) */ - if (c->strict_pairs - && (f0->prev->breaks & BREAK_RIGHT) && (f2->breaks & BREAK_LEFT) - && (f0->affinity != 1 || f1->affinity != -1) ) - return 1; - if (f1->affinity == 1) return 1; - else return 2; - case 3: - if (f2->affinity == 1) return 2; - else return 3; - default: - /* 9 possibilities covered before switch */ - if (f1->affinity == 1) return 1; /* covers 6 */ - else if (f1->affinity == -1) return 2; /* covers 6 */ - else if (f2->affinity == -1) { /* covers 2 */ - if (f0->affinity == 1) return 3; - else return 1; - } - else return 2; /* the remaining 6 */ - } -} - - -static void print_aff_and_breaks(struct pullup_context *c, struct pullup_field *f) -{ - int i; - struct pullup_field *f0 = f; - const char aff_l[] = "+..", aff_r[] = "..+"; - printf("\naffinity: "); - for (i = 0; i < 4; i++) { - printf("%c%d%c", aff_l[1+f->affinity], i, aff_r[1+f->affinity]); - f = f->next; - } - f = f0; - printf("\nbreaks: "); - for (i=0; i<4; i++) { - printf("%c%d%c", f->breaks & BREAK_LEFT ? '|' : '.', i, f->breaks & BREAK_RIGHT ? '|' : '.'); - f = f->next; - } - printf("\n"); -} - - - - - -struct pullup_frame *ff_pullup_get_frame(struct pullup_context *c) -{ - int i; - struct pullup_frame *fr = c->frame; - int n = decide_frame_length(c); - int aff = c->first->next->affinity; - - if (!n) return 0; - if (fr->lock) return 0; - - if (c->verbose) { - print_aff_and_breaks(c, c->first); - printf("duration: %d \n", n); - } - - fr->lock++; - fr->length = n; - fr->parity = c->first->parity; - fr->buffer = 0; - for (i = 0; i < n; i++) { - /* We cheat and steal the buffer without release+relock */ - fr->ifields[i] = c->first->buffer; - c->first->buffer = 0; - c->first = c->first->next; - } - - if (n == 1) { - fr->ofields[fr->parity] = fr->ifields[0]; - fr->ofields[fr->parity^1] = 0; - } else if (n == 2) { - fr->ofields[fr->parity] = fr->ifields[0]; - fr->ofields[fr->parity^1] = fr->ifields[1]; - } else if (n == 3) { - if (aff == 0) - aff = (fr->ifields[0] == fr->ifields[1]) ? -1 : 1; - /* else if (c->verbose) printf("forced aff: %d \n", aff); */ - fr->ofields[fr->parity] = fr->ifields[1+aff]; - fr->ofields[fr->parity^1] = fr->ifields[1]; - } - ff_pullup_lock_buffer(fr->ofields[0], 0); - ff_pullup_lock_buffer(fr->ofields[1], 1); - - if (fr->ofields[0] == fr->ofields[1]) { - fr->buffer = fr->ofields[0]; - ff_pullup_lock_buffer(fr->buffer, 2); - return fr; - } - return fr; -} - -static void copy_field(struct pullup_context *c, struct pullup_buffer *dest, - struct pullup_buffer *src, int parity) -{ - int i, j; - unsigned char *d, *s; - for (i = 0; i < c->nplanes; i++) { - s = src->planes[i] + parity*c->stride[i]; - d = dest->planes[i] + parity*c->stride[i]; - for (j = c->h[i]>>1; j; j--) { - memcpy(d, s, c->stride[i]); - s += c->stride[i]<<1; - d += c->stride[i]<<1; - } - } -} - -void ff_pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr) -{ - int i; - if (fr->buffer) return; - if (fr->length < 2) return; /* FIXME: deal with this */ - for (i = 0; i < 2; i++) - { - if (fr->ofields[i]->lock[i^1]) continue; - fr->buffer = fr->ofields[i]; - ff_pullup_lock_buffer(fr->buffer, 2); - copy_field(c, fr->buffer, fr->ofields[i^1], i^1); - return; - } - fr->buffer = ff_pullup_get_buffer(c, 2); - copy_field(c, fr->buffer, fr->ofields[0], 0); - copy_field(c, fr->buffer, fr->ofields[1], 1); -} - -void ff_pullup_release_frame(struct pullup_frame *fr) -{ - int i; - for (i = 0; i < fr->length; i++) - ff_pullup_release_buffer(fr->ifields[i], fr->parity ^ (i&1)); - ff_pullup_release_buffer(fr->ofields[0], 0); - ff_pullup_release_buffer(fr->ofields[1], 1); - if (fr->buffer) ff_pullup_release_buffer(fr->buffer, 2); - fr->lock--; -} - - - - - - -struct pullup_context *ff_pullup_alloc_context(void) -{ - struct pullup_context *c; - - c = calloc(1, sizeof(struct pullup_context)); - - return c; -} - -void ff_pullup_preinit_context(struct pullup_context *c) -{ - c->bpp = calloc(c->nplanes, sizeof(int)); - c->w = calloc(c->nplanes, sizeof(int)); - c->h = calloc(c->nplanes, sizeof(int)); - c->stride = calloc(c->nplanes, sizeof(int)); - c->background = calloc(c->nplanes, sizeof(int)); -} - -void ff_pullup_init_context(struct pullup_context *c) -{ - int mp = c->metric_plane; - if (c->nbuffers < 10) c->nbuffers = 10; - c->buffers = calloc(c->nbuffers, sizeof (struct pullup_buffer)); - - c->metric_w = (c->w[mp] - ((c->junk_left + c->junk_right) << 3)) >> 3; - c->metric_h = (c->h[mp] - ((c->junk_top + c->junk_bottom) << 1)) >> 3; - c->metric_offset = c->junk_left*c->bpp[mp] + (c->junk_top<<1)*c->stride[mp]; - c->metric_len = c->metric_w * c->metric_h; - - c->head = make_field_queue(c, 8); - - c->frame = calloc(1, sizeof (struct pullup_frame)); - c->frame->ifields = calloc(3, sizeof (struct pullup_buffer *)); - - switch(c->format) { - case PULLUP_FMT_Y: - c->diff = diff_y; - c->comb = licomb_y; - c->var = var_y; -#if ARCH_X86 -#if HAVE_MMX - if (c->cpu & PULLUP_CPU_MMX) { - c->diff = diff_y_mmx; - c->comb = licomb_y_mmx; - c->var = var_y_mmx; - } -#endif -#endif - /* c->comb = qpcomb_y; */ - break; -#if 0 - case PULLUP_FMT_YUY2: - c->diff = diff_yuy2; - break; - case PULLUP_FMT_RGB32: - c->diff = diff_rgb32; - break; -#endif - } -} - -void ff_pullup_free_context(struct pullup_context *c) -{ - struct pullup_field *f; - free(c->buffers); - f = c->head; - do { - if (!f) break; - free(f->diffs); - free(f->comb); - f = f->next; - free(f->prev); - } while (f != c->head); - free(c->frame); - free(c); -} diff --git a/libavfilter/libmpcodecs/pullup.h b/libavfilter/libmpcodecs/pullup.h deleted file mode 100644 index cd6ec00168..0000000000 --- a/libavfilter/libmpcodecs/pullup.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_PULLUP_H -#define MPLAYER_PULLUP_H - -#define PULLUP_CPU_MMX 1 -#define PULLUP_CPU_MMX2 2 -#define PULLUP_CPU_3DNOW 4 -#define PULLUP_CPU_3DNOWEXT 8 -#define PULLUP_CPU_SSE 16 -#define PULLUP_CPU_SSE2 32 - -#define PULLUP_FMT_Y 1 -#define PULLUP_FMT_YUY2 2 -#define PULLUP_FMT_UYVY 3 -#define PULLUP_FMT_RGB32 4 - -struct pullup_buffer -{ - int lock[2]; - unsigned char **planes; -}; - -struct pullup_field -{ - int parity; - struct pullup_buffer *buffer; - unsigned int flags; - int breaks; - int affinity; - int *diffs; - int *comb; - int *var; - struct pullup_field *prev, *next; -}; - -struct pullup_frame -{ - int lock; - int length; - int parity; - struct pullup_buffer **ifields, *ofields[2]; - struct pullup_buffer *buffer; -}; - -struct pullup_context -{ - /* Public interface */ - int format; - int nplanes; - int *bpp, *w, *h, *stride, *background; - unsigned int cpu; - int junk_left, junk_right, junk_top, junk_bottom; - int verbose; - int metric_plane; - int strict_breaks; - int strict_pairs; - /* Internal data */ - struct pullup_field *first, *last, *head; - struct pullup_buffer *buffers; - int nbuffers; - int (*diff)(unsigned char *, unsigned char *, int); - int (*comb)(unsigned char *, unsigned char *, int); - int (*var)(unsigned char *, unsigned char *, int); - int metric_w, metric_h, metric_len, metric_offset; - struct pullup_frame *frame; -}; - - -struct pullup_buffer *ff_pullup_lock_buffer(struct pullup_buffer *b, int parity); -void ff_pullup_release_buffer(struct pullup_buffer *b, int parity); -struct pullup_buffer *ff_pullup_get_buffer(struct pullup_context *c, int parity); - -void ff_pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity); -void ff_pullup_flush_fields(struct pullup_context *c); - -struct pullup_frame *ff_pullup_get_frame(struct pullup_context *c); -void ff_pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr); -void ff_pullup_release_frame(struct pullup_frame *fr); - -struct pullup_context *ff_pullup_alloc_context(void); -void ff_pullup_preinit_context(struct pullup_context *c); -void ff_pullup_init_context(struct pullup_context *c); -void ff_pullup_free_context(struct pullup_context *c); - -#endif /* MPLAYER_PULLUP_H */ diff --git a/libavfilter/libmpcodecs/vf_pullup.c b/libavfilter/libmpcodecs/vf_pullup.c deleted file mode 100644 index e4a28c46d5..0000000000 --- a/libavfilter/libmpcodecs/vf_pullup.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "config.h" -#include "mp_msg.h" -#include "cpudetect.h" - -#include "img_format.h" -#include "mp_image.h" -#include "vf.h" - -#include "libvo/fastmemcpy.h" - -#include "pullup.h" - -#undef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) - -struct vf_priv_s { - struct pullup_context *ctx; - int init; - int fakecount; - char *qbuf; -}; - -static void init_pullup(struct vf_instance *vf, mp_image_t *mpi) -{ - struct pullup_context *c = vf->priv->ctx; - - if (mpi->flags & MP_IMGFLAG_PLANAR) { - c->format = PULLUP_FMT_Y; - c->nplanes = 4; - ff_pullup_preinit_context(c); - c->bpp[0] = c->bpp[1] = c->bpp[2] = 8; - c->w[0] = mpi->w; - c->h[0] = mpi->h; - c->w[1] = c->w[2] = mpi->chroma_width; - c->h[1] = c->h[2] = mpi->chroma_height; - c->w[3] = ((mpi->w+15)/16) * ((mpi->h+15)/16); - c->h[3] = 2; - c->stride[0] = mpi->width; - c->stride[1] = c->stride[2] = mpi->chroma_width; - c->stride[3] = c->w[3]; - c->background[1] = c->background[2] = 128; - } - - if (ff_gCpuCaps.hasMMX) c->cpu |= PULLUP_CPU_MMX; - if (ff_gCpuCaps.hasMMX2) c->cpu |= PULLUP_CPU_MMX2; - if (ff_gCpuCaps.has3DNow) c->cpu |= PULLUP_CPU_3DNOW; - if (ff_gCpuCaps.has3DNowExt) c->cpu |= PULLUP_CPU_3DNOWEXT; - if (ff_gCpuCaps.hasSSE) c->cpu |= PULLUP_CPU_SSE; - if (ff_gCpuCaps.hasSSE2) c->cpu |= PULLUP_CPU_SSE2; - - ff_pullup_init_context(c); - - vf->priv->init = 1; - vf->priv->qbuf = malloc(c->w[3]); -} - - -#if 0 -static void get_image(struct vf_instance *vf, mp_image_t *mpi) -{ - struct pullup_context *c = vf->priv->ctx; - struct pullup_buffer *b; - - if (mpi->type == MP_IMGTYPE_STATIC) return; - - if (!vf->priv->init) init_pullup(vf, mpi); - - b = ff_pullup_get_buffer(c, 2); - if (!b) return; /* shouldn't happen... */ - - mpi->priv = b; - - mpi->planes[0] = b->planes[0]; - mpi->planes[1] = b->planes[1]; - mpi->planes[2] = b->planes[2]; - mpi->stride[0] = c->stride[0]; - mpi->stride[1] = c->stride[1]; - mpi->stride[2] = c->stride[2]; - - mpi->flags |= MP_IMGFLAG_DIRECT; - mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; -} -#endif - -static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) -{ - struct pullup_context *c = vf->priv->ctx; - struct pullup_buffer *b; - struct pullup_frame *f; - mp_image_t *dmpi; - int ret; - int p; - int i; - - if (!vf->priv->init) init_pullup(vf, mpi); - - if (mpi->flags & MP_IMGFLAG_DIRECT) { - b = mpi->priv; - mpi->priv = 0; - } else { - b = ff_pullup_get_buffer(c, 2); - if (!b) { - ff_mp_msg(MSGT_VFILTER,MSGL_ERR,"Could not get buffer from pullup!\n"); - f = ff_pullup_get_frame(c); - ff_pullup_release_frame(f); - return 0; - } - memcpy_pic(b->planes[0], mpi->planes[0], mpi->w, mpi->h, - c->stride[0], mpi->stride[0]); - if (mpi->flags & MP_IMGFLAG_PLANAR) { - memcpy_pic(b->planes[1], mpi->planes[1], - mpi->chroma_width, mpi->chroma_height, - c->stride[1], mpi->stride[1]); - memcpy_pic(b->planes[2], mpi->planes[2], - mpi->chroma_width, mpi->chroma_height, - c->stride[2], mpi->stride[2]); - } - } - if (mpi->qscale) { - fast_memcpy(b->planes[3], mpi->qscale, c->w[3]); - fast_memcpy(b->planes[3]+c->w[3], mpi->qscale, c->w[3]); - } - - p = mpi->fields & MP_IMGFIELD_TOP_FIRST ? 0 : - (mpi->fields & MP_IMGFIELD_ORDERED ? 1 : 0); - ff_pullup_submit_field(c, b, p); - ff_pullup_submit_field(c, b, p^1); - if (mpi->fields & MP_IMGFIELD_REPEAT_FIRST) - ff_pullup_submit_field(c, b, p); - - ff_pullup_release_buffer(b, 2); - - f = ff_pullup_get_frame(c); - - /* Fake yes for first few frames (buffer depth) to keep from - * breaking A/V sync with G1's bad architecture... */ - if (!f) return vf->priv->fakecount ? (--vf->priv->fakecount,1) : 0; - - if (f->length < 2) { - ff_pullup_release_frame(f); - f = ff_pullup_get_frame(c); - if (!f) return 0; - if (f->length < 2) { - ff_pullup_release_frame(f); - if (!(mpi->fields & MP_IMGFIELD_REPEAT_FIRST)) - return 0; - f = ff_pullup_get_frame(c); - if (!f) return 0; - if (f->length < 2) { - ff_pullup_release_frame(f); - return 0; - } - } - } - -#if 0 - /* Average qscale tables from both frames. */ - if (mpi->qscale) { - for (i=0; i<c->w[3]; i++) { - vf->priv->qbuf[i] = (f->ofields[0]->planes[3][i] - + f->ofields[1]->planes[3][i+c->w[3]])>>1; - } - } -#else - /* Take worst of qscale tables from both frames. */ - if (mpi->qscale) { - for (i=0; i<c->w[3]; i++) { - vf->priv->qbuf[i] = MAX(f->ofields[0]->planes[3][i], f->ofields[1]->planes[3][i+c->w[3]]); - } - } -#endif - - /* If the frame isn't already exportable... */ - while (!f->buffer) { - dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, - MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, - mpi->width, mpi->height); - /* FIXME: Is it ok to discard dmpi if it's not direct? */ - if (!(dmpi->flags & MP_IMGFLAG_DIRECT)) { - ff_pullup_pack_frame(c, f); - break; - } - /* Direct render fields into output buffer */ - my_memcpy_pic(dmpi->planes[0], f->ofields[0]->planes[0], - mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2); - my_memcpy_pic(dmpi->planes[0] + dmpi->stride[0], - f->ofields[1]->planes[0] + c->stride[0], - mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2); - if (mpi->flags & MP_IMGFLAG_PLANAR) { - my_memcpy_pic(dmpi->planes[1], f->ofields[0]->planes[1], - mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[1]*2, c->stride[1]*2); - my_memcpy_pic(dmpi->planes[1] + dmpi->stride[1], - f->ofields[1]->planes[1] + c->stride[1], - mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[1]*2, c->stride[1]*2); - my_memcpy_pic(dmpi->planes[2], f->ofields[0]->planes[2], - mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[2]*2, c->stride[2]*2); - my_memcpy_pic(dmpi->planes[2] + dmpi->stride[2], - f->ofields[1]->planes[2] + c->stride[2], - mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[2]*2, c->stride[2]*2); - } - ff_pullup_release_frame(f); - if (mpi->qscale) { - dmpi->qscale = vf->priv->qbuf; - dmpi->qstride = mpi->qstride; - dmpi->qscale_type = mpi->qscale_type; - } - return ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); - } - dmpi = ff_vf_get_image(vf->next, mpi->imgfmt, - MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, - mpi->width, mpi->height); - - dmpi->planes[0] = f->buffer->planes[0]; - dmpi->planes[1] = f->buffer->planes[1]; - dmpi->planes[2] = f->buffer->planes[2]; - - dmpi->stride[0] = c->stride[0]; - dmpi->stride[1] = c->stride[1]; - dmpi->stride[2] = c->stride[2]; - - if (mpi->qscale) { - dmpi->qscale = vf->priv->qbuf; - dmpi->qstride = mpi->qstride; - dmpi->qscale_type = mpi->qscale_type; - } - ret = ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); - ff_pullup_release_frame(f); - return ret; -} - -static int query_format(struct vf_instance *vf, unsigned int fmt) -{ - /* FIXME - support more formats */ - switch (fmt) { - case IMGFMT_YV12: - case IMGFMT_IYUV: - case IMGFMT_I420: - return ff_vf_next_query_format(vf, fmt); - } - return 0; -} - -static int config(struct vf_instance *vf, - int width, int height, int d_width, int d_height, - unsigned int flags, unsigned int outfmt) -{ - if (height&3) { - ff_mp_msg(MSGT_VFILTER, MSGL_ERR, "height must be divisible by four\n"); - return 0; - } - return ff_vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); -} - -static void uninit(struct vf_instance *vf) -{ - ff_pullup_free_context(vf->priv->ctx); - free(vf->priv); -} - -static int vf_open(vf_instance_t *vf, char *args) -{ - struct vf_priv_s *p; - struct pullup_context *c; - //vf->get_image = get_image; - vf->put_image = put_image; - vf->config = config; - vf->query_format = query_format; - vf->uninit = uninit; - vf->default_reqs = VFCAP_ACCEPT_STRIDE; - vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); - p->ctx = c = ff_pullup_alloc_context(); - p->fakecount = 1; - c->junk_left = c->junk_right = 1; - c->junk_top = c->junk_bottom = 4; - c->strict_breaks = 0; - c->metric_plane = 0; - if (args) { - sscanf(args, "%d:%d:%d:%d:%d:%d", &c->junk_left, &c->junk_right, &c->junk_top, &c->junk_bottom, &c->strict_breaks, &c->metric_plane); - } - return 1; -} - -const vf_info_t ff_vf_info_pullup = { - "pullup (from field sequence to frames)", - "pullup", - "Rich Felker", - "", - vf_open, - NULL -}; diff --git a/libavfilter/version.h b/libavfilter/version.h index 20c15f6d24..87f029ecde 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -31,7 +31,7 @@ #define LIBAVFILTER_VERSION_MAJOR 3 #define LIBAVFILTER_VERSION_MINOR 86 -#define LIBAVFILTER_VERSION_MICRO 100 +#define LIBAVFILTER_VERSION_MICRO 101 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c index c5133abae6..099175495b 100644 --- a/libavfilter/vf_mp.c +++ b/libavfilter/vf_mp.c @@ -127,7 +127,6 @@ extern const vf_info_t ff_vf_info_eq; extern const vf_info_t ff_vf_info_fspp; extern const vf_info_t ff_vf_info_ilpack; extern const vf_info_t ff_vf_info_pp7; -extern const vf_info_t ff_vf_info_pullup; extern const vf_info_t ff_vf_info_qp; extern const vf_info_t ff_vf_info_softpulldown; extern const vf_info_t ff_vf_info_uspp; @@ -139,7 +138,6 @@ static const vf_info_t* const filters[]={ &ff_vf_info_fspp, &ff_vf_info_ilpack, &ff_vf_info_pp7, - &ff_vf_info_pullup, &ff_vf_info_qp, &ff_vf_info_softpulldown, &ff_vf_info_uspp, |