mirror of
https://github.com/mpv-player/mpv
synced 2024-12-24 15:52:25 +00:00
removed our native svq1 and huffyuv implementation as libavcodec's implementations are much better
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10419 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
8dbd85b924
commit
5b89123809
@ -325,14 +325,9 @@ MPlayer supports decoding all versions of RealVideo:
|
||||
following decoders:</P>
|
||||
|
||||
<UL>
|
||||
<LI>Sorenson 1 (fourcc <I>SVQ1</I>) - decoding supported by <B>native
|
||||
codecs</B><BR>
|
||||
Actually there are two (nearly equal) decoders for SVQ1: one is built in
|
||||
MPlayer, the other is in libavcodec. You can invoke each of them with the
|
||||
<CODE>-vc svq1</CODE> and <CODE>-vc ffsvq1</CODE> options respectively.
|
||||
Some files may work with one of them, and not with the other, so test
|
||||
both decoders.</LI>
|
||||
<LI>Sorenson 3 (fourcc <I>SVQ3</I>) - decoding supported by <B>native
|
||||
<LI>Sorenson Video v1 (fourcc <I>SVQ1</I>) - decoding supported by <B>native
|
||||
codec</B> (<A HREF="#libavcodec">libavcodec</A>)</LI>
|
||||
<LI>Sorenson Video v3 (fourcc <I>SVQ3</I>) - decoding supported by <B>native
|
||||
codec</B> (<A HREF="#libavcodec">libavcodec</A>)</LI>
|
||||
</UL>
|
||||
|
||||
|
@ -285,11 +285,9 @@ static short get_driver(char *s,int audioflag)
|
||||
"qtrpza",
|
||||
"mpng",
|
||||
"ijpg",
|
||||
"huffyuv",
|
||||
"zlib",
|
||||
"mpegpes",
|
||||
"realvid",
|
||||
"svq1",
|
||||
"xvid",
|
||||
"libdv",
|
||||
NULL
|
||||
|
@ -209,13 +209,6 @@ videocodec huffyuv
|
||||
|
||||
;NATIVE:
|
||||
|
||||
videocodec svq1
|
||||
info "Sorenson v1 (native codec)"
|
||||
status buggy
|
||||
fourcc SVQ1
|
||||
driver svq1
|
||||
out YVU9
|
||||
|
||||
videocodec video1
|
||||
info "Microsoft Video 1 (native codec)"
|
||||
status working
|
||||
@ -234,14 +227,6 @@ videocodec cvid
|
||||
out YUY2
|
||||
out BGR32,BGR24
|
||||
|
||||
videocodec mphuffyuv
|
||||
info "HuffYUV (native codec)"
|
||||
status working
|
||||
fourcc HFYU
|
||||
driver huffyuv
|
||||
out YUY2
|
||||
out BGR32,BGR24
|
||||
|
||||
videocodec mpmszh
|
||||
info "AVImszh (native codec)"
|
||||
status working
|
||||
@ -270,8 +255,8 @@ videocodec cvidxa
|
||||
; ff* is fastest...
|
||||
|
||||
videocodec ffhuffyuv
|
||||
info "FFHuffYUV"
|
||||
status untested
|
||||
info "FFmpeg HuffYUV"
|
||||
status working
|
||||
fourcc HFYU
|
||||
driver ffmpeg
|
||||
dll huffyuv
|
||||
@ -279,7 +264,7 @@ videocodec ffhuffyuv
|
||||
out BGR32,BGR24
|
||||
|
||||
videocodec ffv1
|
||||
info "FFV1"
|
||||
info "FFV1 (lossless codec)"
|
||||
status working
|
||||
fourcc FFV1
|
||||
driver ffmpeg
|
||||
@ -287,7 +272,7 @@ videocodec ffv1
|
||||
out 411P,444P,422P,YV12,I420,IYUV,YVU9
|
||||
|
||||
videocodec ffasv1
|
||||
info "ASUS V1"
|
||||
info "FFmpeg ASUS V1"
|
||||
status working
|
||||
fourcc ASV1
|
||||
driver ffmpeg
|
||||
@ -295,7 +280,7 @@ videocodec ffasv1
|
||||
out YV12,I420,IYUV
|
||||
|
||||
videocodec ffsvq1
|
||||
info "FFmpeg Sorenson Video v1"
|
||||
info "FFmpeg Sorenson Video v1 (SVQ1)"
|
||||
status working
|
||||
fourcc SVQ1
|
||||
driver ffmpeg
|
||||
@ -361,7 +346,7 @@ videocodec ffh264
|
||||
out YV12,I420,IYUV
|
||||
|
||||
videocodec ffsvq3
|
||||
info "FFmpeg SVQ3"
|
||||
info "FFmpeg Sorenson Video v3 (SVQ3)"
|
||||
status working
|
||||
fourcc SVQ3
|
||||
driver ffmpeg
|
||||
@ -387,7 +372,7 @@ videocodec ffodivx
|
||||
out YV12,I420,IYUV
|
||||
|
||||
videocodec xvid
|
||||
info "Xvid (MPEG-4)"
|
||||
info "XviD (MPEG-4)"
|
||||
status working
|
||||
fourcc DIVX,divx
|
||||
fourcc xvid,XVID,XviD
|
||||
|
@ -10,7 +10,7 @@ AUDIO_SRCS_OPT=ad_acm.c ad_dshow.c ad_dmo.c ad_qtaudio.c ad_ffmpeg.c ad_faad.c a
|
||||
AUDIO_SRCS=dec_audio.c ad.c $(AUDIO_SRCS_LIB) $(AUDIO_SRCS_NAT) $(AUDIO_SRCS_OPT)
|
||||
|
||||
VIDEO_SRCS_LIB=vd_libmpeg2.c vd_nuv.c vd_lzo.c
|
||||
VIDEO_SRCS_NAT=vd_null.c vd_cinepak.c vd_qtrpza.c vd_raw.c vd_hmblck.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_msrle.c vd_huffyuv.c vd_mpegpes.c vd_svq1.c vd_lcl.c vd_mtga.c vd_sgi.c
|
||||
VIDEO_SRCS_NAT=vd_null.c vd_cinepak.c vd_qtrpza.c vd_raw.c vd_hmblck.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_msrle.c vd_mpegpes.c vd_lcl.c vd_mtga.c vd_sgi.c
|
||||
VIDEO_SRCS_OPT=vd_realvid.c vd_ffmpeg.c vd_dshow.c vd_dmo.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_xanim.c vd_xvid.c vd_libdv.c vd_qtvideo.c vd_theora.c
|
||||
VIDEO_SRCS=dec_video.c vd.c $(VIDEO_SRCS_NAT) $(VIDEO_SRCS_LIB) $(VIDEO_SRCS_OPT)
|
||||
|
||||
|
@ -1,799 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2002 the xine project
|
||||
*
|
||||
* This file is part of xine, a unix video player.
|
||||
*
|
||||
* xine 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.
|
||||
*
|
||||
* xine 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../config.h"
|
||||
|
||||
#ifdef USE_SVQ1
|
||||
|
||||
#include "bswap.h"
|
||||
|
||||
/* variable length (bit) code */
|
||||
typedef struct vlc_code_s {
|
||||
int16_t value :10,
|
||||
length :6;
|
||||
} vlc_code_t;
|
||||
|
||||
#define VIDEOBUFSIZE 1280 * 1024
|
||||
|
||||
//char temp_buf[VIDEOBUFSIZE];
|
||||
|
||||
#define MEDIAN(a,b,c) (((a < b) != (b >= c)) ? b : (((a < c) != (c > b)) ? c : a))
|
||||
|
||||
#include "svq1.h"
|
||||
#include "svq1_cb.h"
|
||||
|
||||
#ifdef USE_LIBAVCODEC
|
||||
typedef void (*op_pixels_func)(unsigned char *block, const unsigned char *pixels, int line_size, int h);
|
||||
extern op_pixels_func put_pixels_tab[4];
|
||||
extern op_pixels_func put_no_rnd_pixels_tab[4];
|
||||
//#define HAVE_AV_CONFIG_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_AV_CONFIG_H
|
||||
// use libavcodec's get_bits():
|
||||
//#define ALT_BITSTREAM_READER
|
||||
//#define ALIGNED_BITSTREAM
|
||||
#include "../../libavcodec/common.h"
|
||||
#define bit_buffer_t GetBitContext
|
||||
#define get_bit_cache(buf) (show_bits(buf,24)<<8)
|
||||
//#define get_bit_cache(buf) show_bits(buf,32)
|
||||
#else
|
||||
// use built-in version:
|
||||
|
||||
/* memory bit stream */
|
||||
typedef struct bit_buffer_s {
|
||||
uint8_t *buffer;
|
||||
uint32_t bitpos;
|
||||
} bit_buffer_t;
|
||||
|
||||
static inline void skip_bits(bit_buffer_t *bitbuf, int n){
|
||||
bitbuf->bitpos+=n;
|
||||
}
|
||||
|
||||
static void init_get_bits(bit_buffer_t *bitbuf,
|
||||
unsigned char *buffer, int buffer_size){
|
||||
bitbuf->buffer=buffer;
|
||||
bitbuf->bitpos=0;
|
||||
}
|
||||
|
||||
static inline uint32_t get_bits (bit_buffer_t *bitbuf, int count) {
|
||||
uint32_t result;
|
||||
|
||||
/* load 32 bits of data (byte-aligned) */
|
||||
result = be2me_32 (*((uint32_t *) &bitbuf->buffer[bitbuf->bitpos >> 3]));
|
||||
|
||||
/* compensate for sub-byte offset */
|
||||
result <<= (bitbuf->bitpos & 0x7);
|
||||
|
||||
/* flush num bits */
|
||||
bitbuf->bitpos += count;
|
||||
|
||||
/* return num bits */
|
||||
return result >> (32 - count);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return next 32 bits (left aligned).
|
||||
*/
|
||||
static inline uint32_t get_bit_cache(bit_buffer_t *bitbuf) {
|
||||
uint32_t result;
|
||||
|
||||
/* load 32 bits of data (byte-aligned) */
|
||||
result = be2me_32 (*((uint32_t *) &bitbuf->buffer[bitbuf->bitpos >> 3]));
|
||||
|
||||
/* compensate for sub-byte offset */
|
||||
result <<= (bitbuf->bitpos & 0x7);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int decode_svq1_block (bit_buffer_t *bitbuf, uint8_t *pixels, int pitch, int intra) {
|
||||
uint32_t bit_cache;
|
||||
vlc_code_t *vlc;
|
||||
uint8_t *list[63];
|
||||
uint32_t *dst;
|
||||
uint32_t *codebook;
|
||||
int entries[6];
|
||||
int i, j, m, n;
|
||||
int mean, stages;
|
||||
int x, y, width, height, level;
|
||||
uint32_t n1, n2, n3, n4;
|
||||
|
||||
/* initialize list for breadth first processing of vectors */
|
||||
list[0] = pixels;
|
||||
|
||||
/* recursively process vector */
|
||||
for (i=0, m=1, n=1, level=5; i < n; i++) {
|
||||
for (; level > 0; i++) {
|
||||
|
||||
/* process next depth */
|
||||
if (i == m) {
|
||||
m = n;
|
||||
|
||||
if (--level == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* divide block if next bit set */
|
||||
if (get_bits (bitbuf, 1) == 0)
|
||||
break;
|
||||
|
||||
/* add child nodes */
|
||||
list[n++] = list[i];
|
||||
list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
|
||||
}
|
||||
|
||||
/* destination address and vector size */
|
||||
dst = (uint32_t *) list[i];
|
||||
width = 1 << ((4 + level) /2);
|
||||
height = 1 << ((3 + level) /2);
|
||||
|
||||
/* get number of stages (-1 skips vector, 0 for mean only) */
|
||||
bit_cache = get_bit_cache (bitbuf);
|
||||
|
||||
if (intra)
|
||||
vlc = &intra_vector_tables[level][bit_cache >> (32 - 7)];
|
||||
else
|
||||
vlc = &inter_vector_tables[level][bit_cache >> (32 - 6)];
|
||||
|
||||
/* flush bits */
|
||||
stages = vlc->value;
|
||||
skip_bits(bitbuf,vlc->length);
|
||||
|
||||
if (stages == -1) {
|
||||
if (intra) {
|
||||
for (y=0; y < height; y++) {
|
||||
memset (&dst[y*(pitch / 4)], 0, width);
|
||||
}
|
||||
}
|
||||
continue; /* skip vector */
|
||||
}
|
||||
|
||||
if ((stages > 0) && (level >= 4)) {
|
||||
return -1; /* invalid vector */
|
||||
}
|
||||
|
||||
/* get mean value for vector */
|
||||
bit_cache = get_bit_cache (bitbuf);
|
||||
|
||||
if (intra) {
|
||||
if (bit_cache >= 0x25000000)
|
||||
vlc = &intra_mean_table_0[(bit_cache >> (32 - 8)) - 37];
|
||||
else if (bit_cache >= 0x03400000)
|
||||
vlc = &intra_mean_table_1[(bit_cache >> (32 - 10)) - 13];
|
||||
else if (bit_cache >= 0x00040000)
|
||||
vlc = &intra_mean_table_2[(bit_cache >> (32 - 14)) - 1];
|
||||
else
|
||||
vlc = &intra_mean_table_3[bit_cache >> (32 - 20)];
|
||||
} else {
|
||||
if (bit_cache >= 0x0B000000)
|
||||
vlc = &inter_mean_table_0[(bit_cache >> (32 - 8)) - 11];
|
||||
else if (bit_cache >= 0x01200000)
|
||||
vlc = &inter_mean_table_1[(bit_cache >> (32 - 12)) - 18];
|
||||
else if (bit_cache >= 0x002E0000)
|
||||
vlc = &inter_mean_table_2[(bit_cache >> (32 - 15)) - 23];
|
||||
else if (bit_cache >= 0x00094000)
|
||||
vlc = &inter_mean_table_3[(bit_cache >> (32 - 18)) - 37];
|
||||
else if (bit_cache >= 0x00049000)
|
||||
vlc = &inter_mean_table_4[(bit_cache >> (32 - 20)) - 73];
|
||||
else
|
||||
vlc = &inter_mean_table_5[bit_cache >> (32 - 22)];
|
||||
}
|
||||
|
||||
/* flush bits */
|
||||
mean = vlc->value;
|
||||
skip_bits(bitbuf,vlc->length);
|
||||
|
||||
if (intra && stages == 0) {
|
||||
for (y=0; y < height; y++) {
|
||||
memset (&dst[y*(pitch / 4)], mean, width);
|
||||
}
|
||||
} else {
|
||||
codebook = (uint32_t *) (intra ? intra_codebooks[level] : inter_codebooks[level]);
|
||||
bit_cache = get_bits (bitbuf, 4*stages);
|
||||
|
||||
/* calculate codebook entries for this vector */
|
||||
for (j=0; j < stages; j++) {
|
||||
entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);
|
||||
}
|
||||
|
||||
mean -= (stages * 128);
|
||||
n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
|
||||
|
||||
for (y=0; y < height; y++) {
|
||||
for (x=0; x < (width / 4); x++, codebook++) {
|
||||
if (intra) {
|
||||
n1 = n4;
|
||||
n2 = n4;
|
||||
} else {
|
||||
n3 = dst[x];
|
||||
|
||||
/* add mean value to vector */
|
||||
n1 = ((n3 & 0xFF00FF00) >> 8) + n4;
|
||||
n2 = (n3 & 0x00FF00FF) + n4;
|
||||
}
|
||||
|
||||
/* add codebook entries to vector */
|
||||
for (j=0; j < stages; j++) {
|
||||
n3 = codebook[entries[j]] ^ 0x80808080;
|
||||
n1 += ((n3 & 0xFF00FF00) >> 8);
|
||||
n2 += (n3 & 0x00FF00FF);
|
||||
}
|
||||
|
||||
/* clip to [0..255] */
|
||||
if (n1 & 0xFF00FF00) {
|
||||
n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
|
||||
n1 += 0x7F007F00;
|
||||
n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
|
||||
n1 &= (n3 & 0x00FF00FF);
|
||||
}
|
||||
|
||||
if (n2 & 0xFF00FF00) {
|
||||
n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
|
||||
n2 += 0x7F007F00;
|
||||
n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
|
||||
n2 &= (n3 & 0x00FF00FF);
|
||||
}
|
||||
|
||||
/* store result */
|
||||
dst[x] = (n1 << 8) | n2;
|
||||
}
|
||||
|
||||
dst += (pitch / 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decode_motion_vector (bit_buffer_t *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) {
|
||||
uint32_t bit_cache;
|
||||
vlc_code_t *vlc;
|
||||
int diff, sign;
|
||||
int i;
|
||||
|
||||
for (i=0; i < 2; i++) {
|
||||
|
||||
/* get motion code */
|
||||
bit_cache = get_bit_cache (bitbuf);
|
||||
|
||||
if (!(bit_cache & 0xFFE00000))
|
||||
return -1; /* invalid vlc code */
|
||||
|
||||
if (bit_cache & 0x80000000) {
|
||||
diff = 0;
|
||||
|
||||
/* flush bit */
|
||||
skip_bits(bitbuf,1);
|
||||
|
||||
} else {
|
||||
if (bit_cache >= 0x06000000) {
|
||||
vlc = &motion_table_0[(bit_cache >> (32 - 7)) - 3];
|
||||
} else {
|
||||
vlc = &motion_table_1[(bit_cache >> (32 - 12)) - 2];
|
||||
}
|
||||
|
||||
/* decode motion vector differential */
|
||||
sign = (int) (bit_cache << (vlc->length - 1)) >> 31;
|
||||
diff = (vlc->value ^ sign) - sign;
|
||||
|
||||
/* flush bits */
|
||||
skip_bits(bitbuf,vlc->length);
|
||||
}
|
||||
|
||||
/* add median of motion vector predictors and clip result */
|
||||
if (i == 1)
|
||||
mv->y = ((diff + MEDIAN(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
|
||||
else
|
||||
mv->x = ((diff + MEDIAN(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) {
|
||||
uint8_t *src;
|
||||
uint8_t *dst;
|
||||
int i;
|
||||
|
||||
src = &previous[x + y*pitch];
|
||||
dst = current;
|
||||
|
||||
for (i=0; i < 16; i++) {
|
||||
memcpy (dst, src, 16);
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
}
|
||||
|
||||
static int motion_inter_block (bit_buffer_t *bitbuf,
|
||||
uint8_t *current, uint8_t *previous, int pitch,
|
||||
svq1_pmv_t *motion, int x, int y) {
|
||||
uint8_t *src;
|
||||
uint8_t *dst;
|
||||
svq1_pmv_t mv;
|
||||
svq1_pmv_t *pmv[3];
|
||||
int sx, sy;
|
||||
int result;
|
||||
|
||||
/* predict and decode motion vector */
|
||||
pmv[0] = &motion[0];
|
||||
pmv[1] = &motion[(x / 8) + 2];
|
||||
pmv[2] = &motion[(x / 8) + 4];
|
||||
|
||||
if (y == 0) {
|
||||
pmv[1] = pmv[0];
|
||||
pmv[2] = pmv[0];
|
||||
}
|
||||
|
||||
result = decode_motion_vector (bitbuf, &mv, pmv);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
motion[0].x = mv.x;
|
||||
motion[0].y = mv.y;
|
||||
motion[(x / 8) + 2].x = mv.x;
|
||||
motion[(x / 8) + 2].y = mv.y;
|
||||
motion[(x / 8) + 3].x = mv.x;
|
||||
motion[(x / 8) + 3].y = mv.y;
|
||||
|
||||
src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
|
||||
dst = current;
|
||||
|
||||
#ifdef USE_LIBAVCODEC
|
||||
put_pixels_tab[((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
|
||||
put_pixels_tab[((mv.y & 1) << 1) | (mv.x & 1)](dst+8,src+8,pitch,16);
|
||||
#else
|
||||
/* form prediction */
|
||||
if (mv.y & 0x1) {
|
||||
if (mv.x & 0x1) {
|
||||
for (sy=0; sy < 16; sy++) {
|
||||
for (sx=0; sx < 16; sx++) {
|
||||
dst[sx] = (src[sx] + src[sx + 1] + src[sx + pitch] + src[sx + pitch + 1] + 2) >> 2;
|
||||
}
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
} else {
|
||||
for (sy=0; sy < 16; sy++) {
|
||||
for (sx=0; sx < 16; sx++) {
|
||||
dst[sx] = (src[sx] + src[sx + pitch] + 1) >> 1;
|
||||
}
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mv.x & 0x1) {
|
||||
for (sy=0; sy < 16; sy++) {
|
||||
for (sx=0; sx < 16; sx++) {
|
||||
dst[sx] = (src[sx] + src[sx + 1] + 1) >> 1;
|
||||
}
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
} else {
|
||||
for (sy=0; sy < 16; sy++) {
|
||||
memcpy (dst, src, 16);
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int motion_inter_4v_block (bit_buffer_t *bitbuf,
|
||||
uint8_t *current, uint8_t *previous, int pitch,
|
||||
svq1_pmv_t *motion,int x, int y) {
|
||||
uint8_t *src;
|
||||
uint8_t *dst;
|
||||
svq1_pmv_t mv;
|
||||
svq1_pmv_t *pmv[4];
|
||||
int sx, sy;
|
||||
int i, result;
|
||||
|
||||
/* predict and decode motion vector (0) */
|
||||
pmv[0] = &motion[0];
|
||||
pmv[1] = &motion[(x / 8) + 2];
|
||||
pmv[2] = &motion[(x / 8) + 4];
|
||||
|
||||
if (y == 0) {
|
||||
pmv[1] = pmv[0];
|
||||
pmv[2] = pmv[0];
|
||||
}
|
||||
|
||||
result = decode_motion_vector (bitbuf, &mv, pmv);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
/* predict and decode motion vector (1) */
|
||||
pmv[0] = &mv;
|
||||
pmv[1] = &motion[(x / 8) + 3];
|
||||
|
||||
if (y == 0) {
|
||||
pmv[1] = pmv[0];
|
||||
pmv[2] = pmv[0];
|
||||
}
|
||||
|
||||
result = decode_motion_vector (bitbuf, &motion[0], pmv);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
/* predict and decode motion vector (2) */
|
||||
pmv[1] = &motion[0];
|
||||
pmv[2] = &motion[(x / 8) + 1];
|
||||
|
||||
result = decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
/* predict and decode motion vector (3) */
|
||||
pmv[2] = &motion[(x / 8) + 2];
|
||||
pmv[3] = &motion[(x / 8) + 3];
|
||||
|
||||
result = decode_motion_vector (bitbuf, pmv[3], pmv);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
/* form predictions */
|
||||
for (i=0; i < 4; i++) {
|
||||
src = &previous[(x + (pmv[i]->x >> 1)) + (y + (pmv[i]->y >> 1))*pitch];
|
||||
dst = current;
|
||||
|
||||
#ifdef USE_LIBAVCODEC
|
||||
put_pixels_tab[((pmv[i]->y & 1) << 1) | (pmv[i]->x & 1)](dst,src,pitch,8);
|
||||
#else
|
||||
if (pmv[i]->y & 0x1) {
|
||||
if (pmv[i]->x & 0x1) {
|
||||
for (sy=0; sy < 8; sy++) {
|
||||
for (sx=0; sx < 8; sx++) {
|
||||
dst[sx] = (src[sx] + src[sx + 1] + src[sx + pitch] + src[sx + pitch + 1] + 2) >> 2;
|
||||
}
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
} else {
|
||||
for (sy=0; sy < 8; sy++) {
|
||||
for (sx=0; sx < 8; sx++) {
|
||||
dst[sx] = (src[sx] + src[sx + pitch] + 1) >> 1;
|
||||
}
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (pmv[i]->x & 0x1) {
|
||||
for (sy=0; sy < 8; sy++) {
|
||||
for (sx=0; sx < 8; sx++) {
|
||||
dst[sx] = (src[sx] + src[sx + 1] + 1) >> 1;
|
||||
}
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
} else {
|
||||
for (sy=0; sy < 8; sy++) {
|
||||
memcpy (dst, src, 8);
|
||||
src += pitch;
|
||||
dst += pitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* select next block */
|
||||
if (i & 1) {
|
||||
current += 8*(pitch - 1);
|
||||
previous += 8*(pitch - 1);
|
||||
} else {
|
||||
current += 8;
|
||||
previous += 8;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decode_delta_block (bit_buffer_t *bitbuf,
|
||||
uint8_t *current, uint8_t *previous, int pitch,
|
||||
svq1_pmv_t *motion, int x, int y) {
|
||||
uint32_t bit_cache;
|
||||
uint32_t block_type;
|
||||
int result = 0;
|
||||
|
||||
/* get block type */
|
||||
bit_cache = get_bit_cache (bitbuf);
|
||||
|
||||
bit_cache >>= (32 - 3);
|
||||
block_type = block_type_table[bit_cache].value;
|
||||
skip_bits(bitbuf,block_type_table[bit_cache].length);
|
||||
|
||||
/* reset motion vectors */
|
||||
if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
|
||||
motion[0].x = 0;
|
||||
motion[0].y = 0;
|
||||
motion[(x / 8) + 2].x = 0;
|
||||
motion[(x / 8) + 2].y = 0;
|
||||
motion[(x / 8) + 3].x = 0;
|
||||
motion[(x / 8) + 3].y = 0;
|
||||
}
|
||||
|
||||
switch (block_type) {
|
||||
case SVQ1_BLOCK_SKIP:
|
||||
skip_block (current, previous, pitch, x, y);
|
||||
break;
|
||||
|
||||
case SVQ1_BLOCK_INTER:
|
||||
result = motion_inter_block (bitbuf, current, previous, pitch, motion, x, y);
|
||||
|
||||
if (result != 0)
|
||||
break;
|
||||
|
||||
result = decode_svq1_block (bitbuf, current, pitch, 0);
|
||||
break;
|
||||
|
||||
case SVQ1_BLOCK_INTER_4V:
|
||||
result = motion_inter_4v_block (bitbuf, current, previous, pitch, motion, x, y);
|
||||
|
||||
if (result != 0)
|
||||
break;
|
||||
|
||||
result = decode_svq1_block (bitbuf, current, pitch, 0);
|
||||
break;
|
||||
|
||||
case SVQ1_BLOCK_INTRA:
|
||||
result = decode_svq1_block (bitbuf, current, pitch, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* standard video sizes */
|
||||
static struct { int width; int height; } frame_size_table[8] = {
|
||||
{ 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 },
|
||||
{ 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 }
|
||||
};
|
||||
|
||||
static int decode_frame_header (bit_buffer_t *bitbuf, svq1_t *svq1) {
|
||||
int frame_size_code;
|
||||
|
||||
/* unknown field */
|
||||
get_bits (bitbuf, 8);
|
||||
|
||||
/* frame type */
|
||||
svq1->frame_type = get_bits (bitbuf, 2);
|
||||
|
||||
if (svq1->frame_type == 3)
|
||||
return -1;
|
||||
|
||||
if (svq1->frame_type == SVQ1_FRAME_INTRA) {
|
||||
|
||||
/* unknown fields */
|
||||
if (svq1->frame_code == 0x50 || svq1->frame_code == 0x60) {
|
||||
get_bits (bitbuf, 16);
|
||||
}
|
||||
|
||||
if ((svq1->frame_code ^ 0x10) >= 0x50) {
|
||||
skip_bits(bitbuf,8*get_bits (bitbuf, 8));
|
||||
}
|
||||
|
||||
get_bits (bitbuf, 2);
|
||||
get_bits (bitbuf, 2);
|
||||
get_bits (bitbuf, 1);
|
||||
|
||||
/* load frame size */
|
||||
frame_size_code = get_bits (bitbuf, 3);
|
||||
|
||||
if (frame_size_code == 7) {
|
||||
/* load width, height (12 bits each) */
|
||||
svq1->frame_width = get_bits (bitbuf, 12);
|
||||
svq1->frame_height = get_bits (bitbuf, 12);
|
||||
|
||||
if (!svq1->frame_width || !svq1->frame_height)
|
||||
return -1;
|
||||
} else {
|
||||
/* get width, height from table */
|
||||
svq1->frame_width = frame_size_table[frame_size_code].width;
|
||||
svq1->frame_height = frame_size_table[frame_size_code].height;
|
||||
}
|
||||
}
|
||||
|
||||
/* unknown fields */
|
||||
if (get_bits (bitbuf, 1) == 1) {
|
||||
get_bits (bitbuf, 1);
|
||||
get_bits (bitbuf, 1);
|
||||
|
||||
if (get_bits (bitbuf, 2) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (get_bits (bitbuf, 1) == 1) {
|
||||
get_bits (bitbuf, 1);
|
||||
get_bits (bitbuf, 4);
|
||||
get_bits (bitbuf, 1);
|
||||
get_bits (bitbuf, 2);
|
||||
|
||||
while (get_bits (bitbuf, 1) == 1) {
|
||||
get_bits (bitbuf, 8);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int svq1_decode_frame (svq1_t *svq1, uint8_t *buffer,int buffer_len) {
|
||||
bit_buffer_t bitbuf;
|
||||
uint8_t *current, *previous;
|
||||
int result, i, x, y, width, height;
|
||||
int luma_size, chroma_size;
|
||||
|
||||
// memcpy(temp_buf,buffer,buffer_len); buffer=temp_buf;
|
||||
|
||||
/* initialize bit buffer */
|
||||
init_get_bits(&bitbuf,buffer,buffer_len);
|
||||
|
||||
/* decode frame header */
|
||||
svq1->frame_code = get_bits (&bitbuf, 22);
|
||||
|
||||
if ((svq1->frame_code & ~0x70) || !(svq1->frame_code & 0x60))
|
||||
return -1;
|
||||
|
||||
/* swap some header bytes (why?) */
|
||||
if (svq1->frame_code != 0x20) {
|
||||
uint32_t *src = (uint32_t *) (buffer + 4);
|
||||
|
||||
for (i=0; i < 4; i++) {
|
||||
src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
|
||||
}
|
||||
}
|
||||
|
||||
result = decode_frame_header (&bitbuf, svq1);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
/* check frame size (changed?) */
|
||||
if (((svq1->frame_width + 3) & ~0x3) != svq1->width ||
|
||||
((svq1->frame_height + 3) & ~0x3) != svq1->height) {
|
||||
|
||||
/* free current buffers */
|
||||
free (svq1->current);
|
||||
free (svq1->previous);
|
||||
free (svq1->motion);
|
||||
|
||||
svq1->width = (svq1->frame_width + 3) & ~0x3;
|
||||
svq1->height = (svq1->frame_height + 3) & ~0x3;
|
||||
svq1->luma_width = (svq1->width + 15) & ~0xF;
|
||||
svq1->luma_height = (svq1->height + 15) & ~0xF;
|
||||
svq1->chroma_width = ((svq1->width / 4) + 15) & ~0xF;
|
||||
svq1->chroma_height = ((svq1->height / 4) + 15) & ~0xF;
|
||||
|
||||
/* allocate new pixel and motion buffers for updated frame size */
|
||||
luma_size = svq1->luma_width * svq1->luma_height;
|
||||
chroma_size = svq1->chroma_width * svq1->chroma_height;
|
||||
|
||||
svq1->motion = (svq1_pmv_t *) malloc (((svq1->luma_width / 8) + 3) * sizeof(svq1_pmv_t));
|
||||
svq1->current = (uint8_t *) malloc (luma_size + 2*chroma_size);
|
||||
svq1->previous = (uint8_t *) malloc (luma_size + 2*chroma_size);
|
||||
svq1->offsets[0] = 0;
|
||||
svq1->offsets[1] = luma_size;
|
||||
svq1->offsets[2] = luma_size + chroma_size;
|
||||
|
||||
for (i=0; i < 3; i++) {
|
||||
svq1->base[i] = svq1->current + svq1->offsets[i];
|
||||
}
|
||||
|
||||
svq1->reference_frame = 0;
|
||||
}
|
||||
|
||||
/* delta frame requires reference frame */
|
||||
if (svq1->frame_type != SVQ1_FRAME_INTRA && !svq1->reference_frame)
|
||||
return -1;
|
||||
|
||||
/* decode y, u and v components */
|
||||
for (i=0; i < 3; i++) {
|
||||
if (i == 0) {
|
||||
width = svq1->luma_width;
|
||||
height = svq1->luma_height;
|
||||
} else {
|
||||
width = svq1->chroma_width;
|
||||
height = svq1->chroma_height;
|
||||
}
|
||||
|
||||
current = svq1->current + svq1->offsets[i];
|
||||
previous = svq1->previous + svq1->offsets[i];
|
||||
|
||||
if (svq1->frame_type == SVQ1_FRAME_INTRA) {
|
||||
/* keyframe */
|
||||
for (y=0; y < height; y+=16) {
|
||||
for (x=0; x < width; x+=16) {
|
||||
result = decode_svq1_block (&bitbuf, ¤t[x], width, 1);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
}
|
||||
|
||||
current += 16*width;
|
||||
}
|
||||
} else {
|
||||
/* delta frame */
|
||||
memset (svq1->motion, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t));
|
||||
|
||||
for (y=0; y < height; y+=16) {
|
||||
for (x=0; x < width; x+=16) {
|
||||
result = decode_delta_block (&bitbuf, ¤t[x], previous,
|
||||
width, svq1->motion, x, y);
|
||||
|
||||
if (result != 0)
|
||||
return result;
|
||||
}
|
||||
|
||||
svq1->motion[0].x = 0;
|
||||
svq1->motion[0].y = 0;
|
||||
|
||||
current += 16*width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* update pixel buffers for frame copy */
|
||||
for (i=0; i < 3; i++) {
|
||||
svq1->base[i] = svq1->current + svq1->offsets[i];
|
||||
}
|
||||
|
||||
/* update backward reference frame */
|
||||
if (svq1->frame_type != SVQ1_FRAME_DROPPABLE) {
|
||||
uint8_t *tmp = svq1->previous;
|
||||
svq1->previous = svq1->current;
|
||||
svq1->current = tmp;
|
||||
svq1->reference_frame = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void svq1_free (svq1_t *svq1){
|
||||
if (svq1) {
|
||||
free (svq1->current);
|
||||
free (svq1->previous);
|
||||
free (svq1->motion);
|
||||
free (svq1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
|
||||
#define SVQ1_BLOCK_SKIP 0
|
||||
#define SVQ1_BLOCK_INTER 1
|
||||
#define SVQ1_BLOCK_INTER_4V 2
|
||||
#define SVQ1_BLOCK_INTRA 3
|
||||
|
||||
#define SVQ1_FRAME_INTRA 0
|
||||
#define SVQ1_FRAME_INTER 1
|
||||
#define SVQ1_FRAME_DROPPABLE 2
|
||||
|
||||
/* motion vector (prediction) */
|
||||
typedef struct svq1_pmv_s {
|
||||
int x;
|
||||
int y;
|
||||
} svq1_pmv_t;
|
||||
|
||||
typedef struct svq1_s {
|
||||
int frame_code;
|
||||
int frame_type;
|
||||
int frame_width;
|
||||
int frame_height;
|
||||
int luma_width;
|
||||
int luma_height;
|
||||
int chroma_width;
|
||||
int chroma_height;
|
||||
svq1_pmv_t *motion;
|
||||
uint8_t *current;
|
||||
uint8_t *previous;
|
||||
int offsets[3];
|
||||
int reference_frame;
|
||||
|
||||
uint8_t *base[3];
|
||||
int width;
|
||||
int height;
|
||||
} svq1_t;
|
||||
|
||||
int svq1_decode_frame (svq1_t *svq1, uint8_t *buffer, int buffer_size);
|
||||
void svq1_free (svq1_t *svq1);
|
File diff suppressed because it is too large
Load Diff
@ -54,10 +54,8 @@ extern vd_functions_t mpcodecs_vd_ijpg;
|
||||
extern vd_functions_t mpcodecs_vd_mtga;
|
||||
extern vd_functions_t mpcodecs_vd_sgi;
|
||||
extern vd_functions_t mpcodecs_vd_libmpeg2;
|
||||
extern vd_functions_t mpcodecs_vd_huffyuv;
|
||||
extern vd_functions_t mpcodecs_vd_mpegpes;
|
||||
extern vd_functions_t mpcodecs_vd_realvid;
|
||||
extern vd_functions_t mpcodecs_vd_svq1;
|
||||
extern vd_functions_t mpcodecs_vd_xvid;
|
||||
extern vd_functions_t mpcodecs_vd_libdv;
|
||||
extern vd_functions_t mpcodecs_vd_lcl;
|
||||
@ -113,14 +111,10 @@ vd_functions_t* mpcodecs_vd_drivers[] = {
|
||||
#ifdef USE_LIBMPEG2
|
||||
&mpcodecs_vd_libmpeg2,
|
||||
#endif
|
||||
&mpcodecs_vd_huffyuv,
|
||||
&mpcodecs_vd_mpegpes,
|
||||
#ifdef USE_REALCODECS
|
||||
&mpcodecs_vd_realvid,
|
||||
#endif
|
||||
#ifdef USE_SVQ1
|
||||
&mpcodecs_vd_svq1,
|
||||
#endif
|
||||
#ifdef HAVE_XVID
|
||||
&mpcodecs_vd_xvid,
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,90 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "config.h"
|
||||
#ifdef USE_SVQ1
|
||||
|
||||
#include "mp_msg.h"
|
||||
|
||||
#include "vd_internal.h"
|
||||
|
||||
static vd_info_t info = {
|
||||
"SVQ1 (Sorenson v1) Video decoder",
|
||||
"svq1",
|
||||
"A'rpi",
|
||||
"XINE team",
|
||||
"native codec"
|
||||
};
|
||||
|
||||
LIBVD_EXTERN(svq1)
|
||||
|
||||
#ifdef USE_LIBAVCODEC
|
||||
#ifdef USE_LIBAVCODEC_SO
|
||||
#include <ffmpeg/avcodec.h>
|
||||
#else
|
||||
#include "libavcodec/avcodec.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "native/svq1.h"
|
||||
|
||||
// to set/get/query special features/parameters
|
||||
static int control(sh_video_t *sh,int cmd,void* arg,...){
|
||||
return CONTROL_UNKNOWN;
|
||||
}
|
||||
|
||||
extern int avcodec_inited;
|
||||
|
||||
// init driver
|
||||
static int init(sh_video_t *sh){
|
||||
|
||||
#ifdef USE_LIBAVCODEC
|
||||
if(!avcodec_inited){
|
||||
avcodec_init();
|
||||
avcodec_register_all();
|
||||
avcodec_inited=1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YVU9)) return 0;
|
||||
|
||||
sh->context=malloc(sizeof(svq1_t));
|
||||
memset(sh->context,0,sizeof(svq1_t));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// uninit driver
|
||||
static void uninit(sh_video_t *sh){
|
||||
svq1_free(sh->context);
|
||||
sh->context=NULL;
|
||||
}
|
||||
|
||||
// decode a frame
|
||||
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
||||
mp_image_t* mpi;
|
||||
svq1_t* svq1=sh->context;
|
||||
int ret;
|
||||
|
||||
if(len<=0) return NULL; // skipped frame
|
||||
|
||||
ret=svq1_decode_frame(svq1,data,len);
|
||||
if (ret != 0)
|
||||
return NULL;
|
||||
|
||||
mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
|
||||
sh->disp_w, sh->disp_h);
|
||||
if(!mpi) return NULL;
|
||||
|
||||
mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"SVQ1: ret=%d wh=%dx%d p=%p \n",ret,svq1->width,svq1->height,svq1->current);
|
||||
|
||||
mpi->planes[0]=svq1->base[0];
|
||||
mpi->planes[1]=svq1->base[1];
|
||||
mpi->planes[2]=svq1->base[2];
|
||||
mpi->stride[0]=svq1->luma_width;
|
||||
mpi->stride[1]=mpi->stride[2]=svq1->chroma_width;
|
||||
|
||||
return mpi;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user