diff options
Diffstat (limited to 'libvo')
-rw-r--r-- | libvo/jpeg_enc.c | 485 | ||||
-rw-r--r-- | libvo/jpeg_enc.h | 52 | ||||
-rw-r--r-- | libvo/video_out.c | 6 | ||||
-rw-r--r-- | libvo/vo_zr.c | 837 | ||||
-rw-r--r-- | libvo/vo_zr.h | 29 | ||||
-rw-r--r-- | libvo/vo_zr2.c | 500 |
6 files changed, 0 insertions, 1909 deletions
diff --git a/libvo/jpeg_enc.c b/libvo/jpeg_enc.c deleted file mode 100644 index 37b5010250..0000000000 --- a/libvo/jpeg_enc.c +++ /dev/null @@ -1,485 +0,0 @@ -/* - * straightforward (to be) optimized JPEG encoder for the YUV422 format - * based on MJPEG code from FFmpeg - * - * For an excellent introduction to the JPEG format, see: - * http://www.ece.purdue.edu/~bouman/grad-labs/lab8/pdf/lab.pdf - * - * Copyright (c) 2002, Rik Snel - * parts from FFmpeg Copyright (c) 2000-2002 Fabrice Bellard - * - * 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 <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "config.h" -#include "mp_msg.h" -/* We need this #define because we need ../libavcodec/common.h to #define - * be2me_32, otherwise the linker will complain that it doesn't exist */ -#define HAVE_AV_CONFIG_H -#include "libavcodec/avcodec.h" -#include "libavcodec/dsputil.h" -#include "libavcodec/mpegvideo.h" -#include "libavcodec/mjpegenc.h" - -#include "libmpcodecs/vd_ffmpeg.h" -#include "jpeg_enc.h" - - -/* Begin excessive code duplication ************************************/ -/* Code coming from mpegvideo.c and mjpeg.c in ../libavcodec ***********/ - -static const unsigned short aanscales[64] = { - /* precomputed values scaled up by 14 bits */ - 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, - 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, - 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, - 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, - 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, - 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, - 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, - 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 -}; - -static void convert_matrix(MpegEncContext *s, int (*qmat)[64], - uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, - int bias, int qmin, int qmax) -{ - int qscale; - - for(qscale=qmin; qscale<=qmax; qscale++){ - int i; - if (s->dsp.fdct == ff_jpeg_fdct_islow) { - for (i = 0; i < 64; i++) { - const int j = s->dsp.idct_permutation[i]; - /* 16 <= qscale * quant_matrix[i] <= 7905 - * 19952 <= aanscales[i] * \ - * qscale * quant_matrix[i] <= 205026 - * (1<<36)/19952 >= (1<<36)/(aanscales[i] * \ - * qscale * quant_matrix[i]) >= (1<<36)/249205025 - * 3444240 >= (1<<36)/(aanscales[i] * - * qscale * quant_matrix[i]) >= 275 */ - qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT-3))/ - (qscale * quant_matrix[j])); - } - } else if (s->dsp.fdct == fdct_ifast) { - for(i=0;i<64;i++) { - const int j = s->dsp.idct_permutation[i]; - /* 16 <= qscale * quant_matrix[i] <= 7905 */ - /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ - /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ - /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ - - qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / - (aanscales[i] * qscale * quant_matrix[j])); - } - } else { - for(i=0;i<64;i++) { - const int j = s->dsp.idct_permutation[i]; - /* We can safely suppose that 16 <= quant_matrix[i] <= 255 - So 16 <= qscale * quant_matrix[i] <= 7905 - so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 - so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 - */ - qmat [qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j])); - qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); - - if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; - qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); - } - } - } -} - -static inline void encode_dc(MpegEncContext *s, int val, - uint8_t *huff_size, uint16_t *huff_code) -{ - int mant, nbits; - - if (val == 0) { - put_bits(&s->pb, huff_size[0], huff_code[0]); - } else { - mant = val; - if (val < 0) { - val = -val; - mant--; - } - - /* compute the log (XXX: optimize) */ - nbits = 0; - while (val != 0) { - val = val >> 1; - nbits++; - } - - put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); - - put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); - } -} - -static void encode_block(MpegEncContext *s, DCTELEM *block, int n) -{ - int mant, nbits, code, i, j; - int component, dc, run, last_index, val; - MJpegContext *m = s->mjpeg_ctx; - uint8_t *huff_size_ac; - uint16_t *huff_code_ac; - - /* DC coef */ - component = (n <= 3 ? 0 : n - 4 + 1); - dc = block[0]; /* overflow is impossible */ - val = dc - s->last_dc[component]; - if (n < 4) { - encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance); - huff_size_ac = m->huff_size_ac_luminance; - huff_code_ac = m->huff_code_ac_luminance; - } else { - encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); - huff_size_ac = m->huff_size_ac_chrominance; - huff_code_ac = m->huff_code_ac_chrominance; - } - s->last_dc[component] = dc; - - /* AC coefs */ - - run = 0; - last_index = s->block_last_index[n]; - for(i=1;i<=last_index;i++) { - j = s->intra_scantable.permutated[i]; - val = block[j]; - if (val == 0) { - run++; - } else { - while (run >= 16) { - put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); - run -= 16; - } - mant = val; - if (val < 0) { - val = -val; - mant--; - } - - /* compute the log (XXX: optimize) */ - nbits = 0; - while (val != 0) { - val = val >> 1; - nbits++; - } - code = (run << 4) | nbits; - - put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); - - put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); - run = 0; - } - } - - /* output EOB only if not already 64 values */ - if (last_index < 63 || run != 0) - put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); -} - -static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) -{ - int i; - const int maxlevel= s->max_qcoeff; - const int minlevel= s->min_qcoeff; - - for(i=0; i<=last_index; i++){ - const int j = s->intra_scantable.permutated[i]; - int level = block[j]; - - if (level>maxlevel) level=maxlevel; - else if(level<minlevel) level=minlevel; - block[j]= level; - } -} - -/* End excessive code duplication **************************************/ - -/* this function is a reproduction of the one in mjpeg, it includes two - * changes, it allows for black&white encoding (it skips the U and V - * macroblocks and it outputs the huffman code for 'no change' (dc) and - * 'all zero' (ac)) and it takes 4 macroblocks (422) instead of 6 (420) */ -static void zr_mjpeg_encode_mb(jpeg_enc_t *j) { - - MJpegContext *m = j->s->mjpeg_ctx; - - encode_block(j->s, j->s->block[0], 0); - encode_block(j->s, j->s->block[1], 1); - if (j->bw) { - /* U */ - put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], - m->huff_code_dc_chrominance[0]); - put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], - m->huff_code_ac_chrominance[0]); - /* V */ - put_bits(&j->s->pb, m->huff_size_dc_chrominance[0], - m->huff_code_dc_chrominance[0]); - put_bits(&j->s->pb, m->huff_size_ac_chrominance[0], - m->huff_code_ac_chrominance[0]); - } else { - /* we trick encode_block here so that it uses - * chrominance huffman tables instead of luminance ones - * (see the effect of second argument of encode_block) */ - encode_block(j->s, j->s->block[2], 4); - encode_block(j->s, j->s->block[3], 5); - } -} - -/* this function can take all kinds of YUV colorspaces - * YV12, YVYU, UYVY. The necesary parameters must be set up by the caller - * y_ps means "y pixel size", y_rs means "y row size". - * For YUYV, for example, is u_buf = y_buf + 1, v_buf = y_buf + 3, - * y_ps = 2, u_ps = 4, v_ps = 4, y_rs = u_rs = v_rs. - * - * The actual buffers must be passed with mjpeg_encode_frame, this is - * to make it possible to call encode on the buffer provided by the - * codec in draw_frame. - * - * The data is straightened out at the moment it is put in DCT - * blocks, there are therefore no spurious memcopies involved */ -/* Notice that w must be a multiple of 16 and h must be a multiple of 8 */ -/* We produce YUV422 jpegs, the colors must be subsampled horizontally, - * if the colors are also subsampled vertically, then this function - * performs cheap upsampling (better solution will be: a DCT that is - * optimized in the case that every two rows are the same) */ -/* cu = 0 means 'No cheap upsampling' - * cu = 1 means 'perform cheap upsampling' */ -/* The encoder doesn't know anything about interlacing, the halve height - * needs to be passed and the double rowstride. Which field gets encoded - * is decided by what buffers are passed to mjpeg_encode_frame */ -jpeg_enc_t *jpeg_enc_init(int w, int h, int y_psize, int y_rsize, - int u_psize, int u_rsize, int v_psize, int v_rsize, - int cu, int q, int b) { - jpeg_enc_t *j; - int i = 0; - mp_msg(MSGT_VO, MSGL_V, "JPEnc init: %dx%d %d %d %d %d %d %d\n", - w, h, y_psize, y_rsize, u_psize, - u_rsize, v_psize, v_rsize); - - j = av_malloc(sizeof(jpeg_enc_t)); - if (j == NULL) return NULL; - - j->s = av_malloc(sizeof(MpegEncContext)); - memset(j->s,0x00,sizeof(MpegEncContext)); - if (j->s == NULL) { - av_free(j); - return NULL; - } - - /* info on how to access the pixels */ - j->y_ps = y_psize; - j->u_ps = u_psize; - j->v_ps = v_psize; - j->y_rs = y_rsize; - j->u_rs = u_rsize; - j->v_rs = v_rsize; - - j->s->width = w; - j->s->height = h; - j->s->qscale = q; - - j->s->out_format = FMT_MJPEG; - j->s->intra_only = 1; - j->s->encoding = 1; - j->s->pict_type = FF_I_TYPE; - j->s->y_dc_scale = 8; - j->s->c_dc_scale = 8; - - //FIXME j->s->mjpeg_write_tables = 1; - j->s->mjpeg_vsample[0] = 1; - j->s->mjpeg_vsample[1] = 1; - j->s->mjpeg_vsample[2] = 1; - j->s->mjpeg_hsample[0] = 2; - j->s->mjpeg_hsample[1] = 1; - j->s->mjpeg_hsample[2] = 1; - - j->cheap_upsample = cu; - j->bw = b; - - init_avcodec(); - - if (ff_mjpeg_encode_init(j->s) < 0) { - av_free(j->s); - av_free(j); - return NULL; - } - - /* alloc bogus avctx to keep MPV_common_init from segfaulting */ - j->s->avctx = calloc(sizeof(*j->s->avctx), 1); - /* Set up to encode mjpeg */ - j->s->avctx->codec_id = CODEC_ID_MJPEG; - - /* make MPV_common_init allocate important buffers, like s->block */ - j->s->avctx->thread_count = 1; - - if (MPV_common_init(j->s) < 0) { - av_free(j->s); - av_free(j); - return NULL; - } - - /* correct the value for sc->mb_height */ - j->s->mb_height = j->s->height/8; - j->s->mb_intra = 1; - - j->s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; - for (i = 1; i < 64; i++) - j->s->intra_matrix[i] = av_clip_uint8( - (ff_mpeg1_default_intra_matrix[i]*j->s->qscale) >> 3); - convert_matrix(j->s, j->s->q_intra_matrix, j->s->q_intra_matrix16, - j->s->intra_matrix, j->s->intra_quant_bias, 8, 8); - return j; -} - -int jpeg_enc_frame(jpeg_enc_t *j, unsigned char *y_data, - unsigned char *u_data, unsigned char *v_data, char *bufr) { - int i, k, mb_x, mb_y, overflow; - short int *dest; - unsigned char *source; - /* initialize the buffer */ - - init_put_bits(&j->s->pb, bufr, 1024*256); - - ff_mjpeg_encode_picture_header(j->s); - - j->s->header_bits = put_bits_count(&j->s->pb); - - j->s->last_dc[0] = 128; - j->s->last_dc[1] = 128; - j->s->last_dc[2] = 128; - - for (mb_y = 0; mb_y < j->s->mb_height; mb_y++) { - for (mb_x = 0; mb_x < j->s->mb_width; mb_x++) { - /* conversion 8 to 16 bit and filling of blocks - * must be mmx optimized */ - /* fill 2 Y macroblocks and one U and one V */ - source = mb_y * 8 * j->y_rs + - 16 * j->y_ps * mb_x + y_data; - dest = j->s->block[0]; - for (i = 0; i < 8; i++) { - for (k = 0; k < 8; k++) { - dest[k] = source[k*j->y_ps]; - } - dest += 8; - source += j->y_rs; - } - source = mb_y * 8 * j->y_rs + - (16*mb_x + 8)*j->y_ps + y_data; - dest = j->s->block[1]; - for (i = 0; i < 8; i++) { - for (k = 0; k < 8; k++) { - dest[k] = source[k*j->y_ps]; - } - dest += 8; - source += j->y_rs; - } - if (!j->bw && j->cheap_upsample) { - source = mb_y*4*j->u_rs + - 8*mb_x*j->u_ps + u_data; - dest = j->s->block[2]; - for (i = 0; i < 4; i++) { - for (k = 0; k < 8; k++) { - dest[k] = source[k*j->u_ps]; - dest[k+8] = source[k*j->u_ps]; - } - dest += 16; - source += j->u_rs; - } - source = mb_y*4*j->v_rs + - 8*mb_x*j->v_ps + v_data; - dest = j->s->block[3]; - for (i = 0; i < 4; i++) { - for (k = 0; k < 8; k++) { - dest[k] = source[k*j->v_ps]; - dest[k+8] = source[k*j->v_ps]; - } - dest += 16; - source += j->u_rs; - } - } else if (!j->bw && !j->cheap_upsample) { - source = mb_y*8*j->u_rs + - 8*mb_x*j->u_ps + u_data; - dest = j->s->block[2]; - for (i = 0; i < 8; i++) { - for (k = 0; k < 8; k++) - dest[k] = source[k*j->u_ps]; - dest += 8; - source += j->u_rs; - } - source = mb_y*8*j->v_rs + - 8*mb_x*j->v_ps + v_data; - dest = j->s->block[3]; - for (i = 0; i < 8; i++) { - for (k = 0; k < 8; k++) - dest[k] = source[k*j->v_ps]; - dest += 8; - source += j->u_rs; - } - } - emms_c(); /* is this really needed? */ - - j->s->block_last_index[0] = - j->s->dct_quantize(j->s, j->s->block[0], - 0, 8, &overflow); - if (overflow) clip_coeffs(j->s, j->s->block[0], - j->s->block_last_index[0]); - j->s->block_last_index[1] = - j->s->dct_quantize(j->s, j->s->block[1], - 1, 8, &overflow); - if (overflow) clip_coeffs(j->s, j->s->block[1], - j->s->block_last_index[1]); - - if (!j->bw) { - j->s->block_last_index[4] = - j->s->dct_quantize(j->s, j->s->block[2], - 4, 8, &overflow); - if (overflow) clip_coeffs(j->s, j->s->block[2], - j->s->block_last_index[2]); - j->s->block_last_index[5] = - j->s->dct_quantize(j->s, j->s->block[3], - 5, 8, &overflow); - if (overflow) clip_coeffs(j->s, j->s->block[3], - j->s->block_last_index[3]); - } - zr_mjpeg_encode_mb(j); - } - } - emms_c(); - ff_mjpeg_encode_picture_trailer(j->s); - flush_put_bits(&j->s->pb); - - //FIXME - //if (j->s->mjpeg_write_tables == 1) - // j->s->mjpeg_write_tables = 0; - - return put_bits_ptr(&(j->s->pb)) - j->s->pb.buf; -} - -void jpeg_enc_uninit(jpeg_enc_t *j) { - ff_mjpeg_encode_close(j->s); - av_free(j->s); - av_free(j); -} diff --git a/libvo/jpeg_enc.h b/libvo/jpeg_enc.h deleted file mode 100644 index c3255ad99d..0000000000 --- a/libvo/jpeg_enc.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * straightforward (to be) optimized JPEG encoder for the YUV422 format - * based on MJPEG code from FFmpeg - * - * For an excellent introduction to the JPEG format, see: - * http://www.ece.purdue.edu/~bouman/grad-labs/lab8/pdf/lab.pdf - * - * Copyright (c) 2002, Rik Snel - * parts from FFmpeg Copyright (c) 2000-2002 Fabrice Bellard - * - * 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_JPEG_ENC_H -#define MPLAYER_JPEG_ENC_H - -typedef struct { - struct MpegEncContext *s; - int cheap_upsample; - int bw; - int y_ps; - int u_ps; - int v_ps; - int y_rs; - int u_rs; - int v_rs; -} jpeg_enc_t; - -jpeg_enc_t *jpeg_enc_init(int w, int h, int y_psize, int y_rsize, - int u_psize, int u_rsize, int v_psize, int v_rsize, - int cu, int q, int b); - -int jpeg_enc_frame(jpeg_enc_t *j, unsigned char *y_data, - unsigned char *u_data, unsigned char *v_data, char *bufr); - -void jpeg_enc_uninit(jpeg_enc_t *j); - -#endif /* MPLAYER_JPEG_ENC_H */ diff --git a/libvo/video_out.c b/libvo/video_out.c index caf916d197..679d111e6f 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -94,8 +94,6 @@ extern struct vo_driver video_out_tdfxfb; extern struct vo_driver video_out_s3fb; extern struct vo_driver video_out_wii; extern struct vo_driver video_out_null; -extern struct vo_driver video_out_zr; -extern struct vo_driver video_out_zr2; extern struct vo_driver video_out_bl; extern struct vo_driver video_out_fbdev; extern struct vo_driver video_out_fbdev2; @@ -217,10 +215,6 @@ const struct vo_driver *video_out_drivers[] = #ifdef CONFIG_V4L2_DECODER &video_out_v4l2, #endif -#ifdef CONFIG_ZR - &video_out_zr, - &video_out_zr2, -#endif #ifdef CONFIG_BL &video_out_bl, #endif diff --git a/libvo/vo_zr.c b/libvo/vo_zr.c deleted file mode 100644 index 4cb1ed0de6..0000000000 --- a/libvo/vo_zr.c +++ /dev/null @@ -1,837 +0,0 @@ -/* - * playback on Zoran cards - * copyright (C) 2001, 2003 Rik Snel - * - * 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. - */ - -/* $Id$ */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/mman.h> -#include <sys/ioctl.h> -#include <linux/types.h> -#include <linux/videodev.h> -#include "config.h" -#include "videodev_mjpeg.h" -#include "video_out.h" -#include "video_out_internal.h" -#include "mp_msg.h" -#include "m_option.h" -#include "fastmemcpy.h" -#include "jpeg_enc.h" -#include "vo_zr.h" - -static const vo_info_t info = -{ - "Zoran ZR360[56]7/ZR36060 Driver (DC10(+)/buz/lml33/MatroxRR)", - "zr", - "Rik Snel <rsnel@cube.dyndns.org>", - "" -}; - -const LIBVO_EXTERN (zr) - -#define ZR_MAX_DEVICES 4 -/* General variables */ - -typedef struct { - int width; - int height; - int xoff; - int yoff; - int set; -} geo_t; - -static int zr_count = 1; -static int zr_parsing = 0; -static int framenum; - -typedef struct { - /* commandline args given for this device (and defaults) */ - int vdec, hdec; /* requested decimation 1,2,4 */ - int fd; /* force decimation */ - int xdoff, ydoff; /* offset from upperleft of screen - * default is 'centered' */ - int quality; /* jpeg quality 1=best, 20=bad */ - geo_t g; /* view window (zrcrop) */ - char *device; /* /dev/video1 */ - int bw; /* if bw == 1, display in black&white */ - int norm; /* PAL/NTSC */ - - /* buffers + pointers + info */ - - unsigned char *image; - int image_width, image_height, size; - int off_y, off_c, stride; /* for use by 'draw slice/frame' */ - - unsigned char *buf; /* the jpeg images will be placed here */ - jpeg_enc_t *j; - unsigned char *y_data, *u_data, *v_data; /* used by the jpeg encoder */ - int y_stride, u_stride, v_stride; /* these point somewhere in image */ - - /* information for (and about) the zoran card */ - - int vdes; /* file descriptor of card */ - int frame, synco, queue; /* buffer management */ - struct mjpeg_sync zs; /* state information */ - struct mjpeg_params p; - struct mjpeg_requestbuffers zrq; - struct video_capability vc; /* max resolution and so on */ - int fields, stretchy; /* must the *image be interlaced - or stretched to fit on the screen? */ -} zr_info_t; - -static zr_info_t zr_info[ZR_MAX_DEVICES] = { - {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0, - 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0, - 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0, - 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, -1, -1, 2, {0, 0, 0, 0, 0}, NULL, 0, VIDEO_MODE_AUTO, NULL, 0, 0, 0, 0, 0, - 0, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; - - - - -#define MJPEG_NBUFFERS 2 -#define MJPEG_SIZE 1024*256 - - -int zoran_getcap(zr_info_t *zr) { - char* dev = NULL; - - if (zr->device) - dev = zr->device; - else { - struct stat vstat; - const char *devs[] = { - "/dev/video", - "/dev/video0", - "/dev/v4l/video0", - "/dev/v4l0", - "/dev/v4l", - NULL - }; - int i = 0; - - do - { - if ((stat(devs[i], &vstat) == 0) && S_ISCHR(vstat.st_mode)) - { - dev = devs[i]; - mp_msg(MSGT_VO, MSGL_V, "zr: found video device %s\n", dev); - break; - } - } while (devs[++i] != NULL); - - if (!dev) - { - mp_msg(MSGT_VO, MSGL_ERR, "zr: unable to find video device\n"); - return 1; - } - } - - zr->vdes = open(dev, O_RDWR); - - if (zr->vdes < 0) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: error opening %s: %s\n", - dev, strerror(errno)); - return 1; - } - - /* before we can ask for the maximum resolution, we must set - * the correct tv norm */ - - if (ioctl(zr->vdes, MJPIOC_G_PARAMS, &zr->p) < 0) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: device at %s is probably not a DC10(+)/buz/lml33\n", dev); - return 1; - } - - if (zr->p.norm != zr->norm && zr->norm != VIDEO_MODE_AUTO) { - /* attempt to set requested norm */ - zr->p.norm = zr->norm; - if (ioctl(zr->vdes, MJPIOC_S_PARAMS, &zr->p) < 0) { - mp_msg(MSGT_VO, MSGL_ERR, - "zr: unable to change video norm, use another program to change it (XawTV)\n"); - return 1; - } - ioctl(zr->vdes, MJPIOC_G_PARAMS, &zr->p); - if (zr->norm != zr->p.norm) { - mp_msg(MSGT_VO, MSGL_ERR, - "zr: unable to change video norm, use another program to change it (XawTV)\n"); - return 1; - } - } - - if (ioctl(zr->vdes, VIDIOCGCAP, &zr->vc) < 0) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: error getting video capabilities from %s\n", dev); - return 1; - } - mp_msg(MSGT_VO, MSGL_V, "zr: MJPEG card reports maxwidth=%d, maxheight=%d\n", zr->vc.maxwidth, zr->vc.maxheight); - - return 0; -} - -int init_zoran(zr_info_t *zr, int stretchx, int stretchy) { - /* center the image, and stretch it as far as possible (try to keep - * aspect) and check if it fits */ - if (zr->image_width > zr->vc.maxwidth) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: movie to be played is too wide, max width currently %d\n", zr->vc.maxwidth); - return 1; - } - - if (zr->image_height > zr->vc.maxheight) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: movie to be played is too high, max height currently %d\n", zr->vc.maxheight); - return 1; - } - - zr->p.decimation = 0; - zr->p.HorDcm = stretchx; - zr->p.VerDcm = stretchy; - zr->p.TmpDcm = 1; - zr->p.field_per_buff = zr->fields; - if (zr->xdoff == -1) { - zr->p.img_x = (zr->vc.maxwidth - - zr->p.HorDcm*(int)zr->image_width/zr->hdec)/2; - } else { - zr->p.img_x = zr->xdoff; - } - if (zr->ydoff == -1) { - zr->p.img_y = (zr->vc.maxheight - zr->p.VerDcm* - (3-zr->fields)*(int)zr->image_height)/4; - } else { - zr->p.img_y = zr->ydoff; - } - zr->p.img_width = zr->p.HorDcm*zr->image_width/zr->hdec; - zr->p.img_height = zr->p.VerDcm*zr->image_height/zr->fields; - mp_msg(MSGT_VO, MSGL_V, "zr: geometry (after 'scaling'): %dx%d+%d+%d fields=%d, w=%d, h=%d\n", zr->p.img_width, (3-zr->fields)*zr->p.img_height, zr->p.img_x, zr->p.img_y, zr->fields, zr->image_width/zr->hdec, zr->image_height); - - if (ioctl(zr->vdes, MJPIOC_S_PARAMS, &zr->p) < 0) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: error setting display parameters\n"); - return 1; - } - - zr->zrq.count = MJPEG_NBUFFERS; - zr->zrq.size = MJPEG_SIZE; - - if (ioctl(zr->vdes, MJPIOC_REQBUFS, &zr->zrq)) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: error requesting %ld buffers of size %ld\n", zr->zrq.count, zr->zrq.size); - return 1; - } - - /* the buffer count allocated may be different to the request */ - zr->buf = (unsigned char*)mmap(0, zr->zrq.count*zr->zrq.size, - PROT_READ|PROT_WRITE, MAP_SHARED, zr->vdes, 0); - - if (zr->buf == MAP_FAILED) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: error requesting %ld buffers of size %ld\n", zr->zrq.count, zr->zrq.size); - return 1; - } - - mp_msg(MSGT_VO, MSGL_V, "zr: got %ld buffers of size %ld (wanted %d buffers of size %d)\n", zr->zrq.count, zr->zrq.size, MJPEG_NBUFFERS, MJPEG_SIZE); - if (zr->zrq.count < MJPEG_NBUFFERS) { - mp_msg(MSGT_VO, MSGL_V, "zr: got not enough buffers\n"); - return 1; - } - - zr->queue = 0; - zr->synco = 0; - - return 0; -} - -void uninit_zoran(zr_info_t *zr) { - free(zr->image); - zr->image=NULL; - while (zr->queue > zr->synco + 1) { - if (ioctl(zr->vdes, MJPIOC_SYNC, &zr->zs) < 0) - mp_msg(MSGT_VO, MSGL_ERR, "zr: error waiting for buffers to become free\n"); - zr->synco++; - } - /* stop streaming */ - zr->frame = -1; - if (ioctl(zr->vdes, MJPIOC_QBUF_PLAY, &zr->frame) < 0) - mp_msg(MSGT_VO, MSGL_ERR, "zr: error stopping playback of last frame\n"); - if (munmap(zr->buf,zr->zrq.count*zr->zrq.size)) - mp_msg(MSGT_VO, MSGL_ERR, "zr: error unmapping buffer\n"); - close(zr->vdes); -} - -int zr_geometry_sane(geo_t *g, unsigned int width, unsigned int height) { - if (g->set) { - if (g->width%2 != 0 || g->height%2 != 0 || - g->xoff%2 != 0 || g->yoff%2 != 0) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: arguments in -zrcrop must be multiples of 2\n"); - return 1; - } - if (g->width <= 0 || g->height <= 0 || - g->xoff < 0 || g->yoff < 0) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: width and height must be positive and offset nonnegative\n"); - return 1; - } - if (g->width + g->xoff > width) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: width+xoffset (%d+%d>%d) is too big\n", g->width, g->xoff, width); - return 1; - } - if (g->height + g->yoff > height) { - mp_msg(MSGT_VO, MSGL_ERR, "zr: height+yoffset (%d+%d>%d) is too big\n", g->height, g->yoff, height); - return 1; - } - } else { - g->width = width; - g->height = height; - g->xoff = 0; - g->yoff = 0; - g->set = 1; - } - return 0; -} - - -static int config(uint32_t width, uint32_t height, uint32_t d_width, - uint32_t d_height, uint32_t flags, char *title, uint32_t format) -{ - int i, tmp, stretchx, stretchy; - framenum = 0; - if (format != IMGFMT_YV12 && format != IMGFMT_YUY2) { - printf("vo_zr called with wrong format"); - return 1; - } - for (i = 0; i < zr_count; i++) { - zr_info_t *zr = &zr_info[i]; - geo_t *g = &zr->g; - - zr->stride = 2*width; - if (zr_geometry_sane(g, width, height)) return 1; - - /* we must know the maximum resolution of the device - * it differs for DC10+ and buz for example */ - zoran_getcap(zr); /*must be called before init_zoran */ - /* make the scaling decision - * we are capable of stretching the image in the horizontal - * direction by factors 1, 2 and 4 - * we can stretch the image in the vertical direction by a - * factor of 1 and 2 AND we must decide about interlacing */ - if (g->width > zr->vc.maxwidth/2 || - g->height > zr->vc.maxheight/2) { - stretchx = 1; - stretchy = 1; - zr->fields = 2; - if (zr->vdec == 2) { - zr->fields = 1; - } else if (zr->vdec == 4) { - zr->fields = 1; - stretchy = 2; - } - stretchx = zr->hdec; - } else if (g->width > zr->vc.maxwidth/4 || - g->height > zr->vc.maxheight/4) { - stretchx = 2; - stretchy = 1; - zr->fields = 1; - if (zr->vdec == 2) { - stretchy = 2; - } else if (zr->vdec == 4) { - if (!zr->fd) { - mp_msg(MSGT_VO, MSGL_WARN, "zr: vertical decimation too high, changing to 2 (use -zrfd to keep vdec=4)\n"); - zr->vdec = 2; - } - stretchy = 2; - } - if (zr->hdec == 2) { - stretchx = 4; - } else if (zr->hdec == 4){ - if (!zr->fd) { - mp_msg(MSGT_VO, MSGL_WARN, "zr: horizontal decimation too high, changing to 2 (use -zrfd to keep hdec=4)\n"); - zr->hdec = 2; - } - stretchx = 4; - } - } else { - /* output image is maximally stretched */ - stretchx = 4; - stretchy = 2; - zr->fields = 1; - if (zr->vdec != 1 && !zr->fd) { - mp_msg(MSGT_VO, MSGL_WARN, "zr: vertical decimation too high, changing to 1 (use -zrfd to keep vdec=%d)\n", zr->vdec); - zr->vdec = 1; - } - if (zr->hdec != 1 && !zr->fd) { - mp_msg(MSGT_VO, MSGL_WARN, "zr: vertical decimation too high, changing to 1 (use -zrfd to keep hdec=%d)\n", zr->hdec); - zr->hdec = 1; - } - } - /* It can be that the original frame was too big for display, - * or that the width of the decimated image (for example) after - * padding up to a multiple of 16 has become too big. (orig - * width 720 (exactly right for the Buz) after decimation 360, - * after padding up to a multiple of 16 368, display 736 -> too - * large). In these situations we auto(re)crop. */ - tmp = 16*((g->width - 1)/(zr->hdec*16) + 1); - if (stretchx*tmp > zr->vc.maxwidth) { - g->xoff += 2*((g->width - zr->hdec*(tmp-16))/4); - /* g->off must be a multiple of 2 */ - g->width = zr->hdec*(tmp - 16); - g->set = 0; /* we abuse this field to - report that g has changed*/ - } - tmp = 8*zr->fields*((g->height - 1)/(zr->vdec*zr->fields*8)+1); - if (stretchy*tmp > zr->vc.maxheight) { - g->yoff += 2*((g->height - zr->vdec* - (tmp - 8*zr->fields))/4); - g->height = zr->vdec*(tmp - 8*zr->fields); - g->set = 0; - } - if (!g->set) - mp_msg(MSGT_VO, MSGL_V, "zr: auto(re)cropping %dx%d+%d+%d to make the image fit on the screen\n", g->width, g->height, g->xoff, g->yoff); - - /* the height must be a multiple of fields*8 and the width - * must be a multiple of 16 */ - /* add some black borders to make it so, and center the image*/ - zr->image_height = zr->fields*8*((g->height/zr->vdec - 1)/ - (zr->fields*8) + 1); - zr->image_width = (zr->hdec*16)*((g->width - 1)/(zr->hdec*16) + 1); - zr->off_y = (zr->image_height - g->height/zr->vdec)/2; - if (zr->off_y%2 != 0) zr->off_y++; - zr->off_y *= zr->image_width; - zr->off_c = zr->off_y/4; - zr->off_y += (zr->image_width - g->width)/2; |