1
mirror of https://github.com/mpv-player/mpv synced 2025-07-27 19:38:10 +02:00
Files
DOCS
TOOLS
debian
drivers
etc
ffmpeg_files
help
input
liba52
libaf
libao2
libdvdcss
libfaad2
libmenu
libmpcodecs
native
ad.c
ad.h
ad_acm.c
ad_alaw.c
ad_dk3adpcm.c
ad_dmo.c
ad_dshow.c
ad_dvdpcm.c
ad_faad.c
ad_ffmpeg.c
ad_hwac3.c
ad_hwmpa.c
ad_imaadpcm.c
ad_internal.h
ad_liba52.c
ad_libdca.c
ad_libdv.c
ad_libmad.c
ad_libvorbis.c
ad_mp3lib.c
ad_mpc.c
ad_msadpcm.c
ad_msgsm.c
ad_pcm.c
ad_qtaudio.c
ad_realaud.c
ad_sample.c
ad_speex.c
ad_twin.c
ae.c
ae.h
ae_faac.c
ae_faac.h
ae_lame.c
ae_lame.h
ae_lavc.c
ae_lavc.h
ae_pcm.c
ae_pcm.h
ae_toolame.c
ae_toolame.h
ae_twolame.c
ae_twolame.h
cmmx.h
dec_audio.c
dec_audio.h
dec_video.c
dec_video.h
img_format.c
img_format.h
mp_image.c
mp_image.h
mpc_info.h
pullup.c
pullup.h
vd.c
vd.h
vd_dmo.c
vd_dshow.c
vd_ffmpeg.c
vd_hmblck.c
vd_ijpg.c
vd_internal.h
vd_libdv.c
vd_libmpeg2.c
vd_lzo.c
vd_mpegpes.c
vd_mpng.c
vd_mtga.c
vd_null.c
vd_qtvideo.c
vd_raw.c
vd_realvid.c
vd_sgi.c
vd_theora.c
vd_vfw.c
vd_vfwex.c
vd_xanim.c
vd_xvid4.c
vd_zrmjpeg.c
ve.c
ve_lavc.c
ve_libdv.c
ve_nuv.c
ve_qtvideo.c
ve_raw.c
ve_vfw.c
ve_x264.c
ve_xvid4.c
vf.c
vf.h
vf_1bpp.c
vf_2xsai.c
vf_ass.c
vf_blackframe.c
vf_bmovl.c
vf_boxblur.c
vf_crop.c
vf_cropdetect.c
vf_decimate.c
vf_delogo.c
vf_denoise3d.c
vf_detc.c
vf_dint.c
vf_divtc.c
vf_down3dright.c
vf_dsize.c
vf_dvbscale.c
vf_eq.c
vf_eq2.c
vf_expand.c
vf_field.c
vf_fil.c
vf_filmdint.c
vf_flip.c
vf_format.c
vf_framestep.c
vf_fspp.c
vf_geq.c
vf_gradfun.c
vf_halfpack.c
vf_harddup.c
vf_hqdn3d.c
vf_hue.c
vf_il.c
vf_ilpack.c
vf_ivtc.c
vf_kerndeint.c
vf_lavc.c
vf_lavcdeint.c
vf_mcdeint.c
vf_mirror.c
vf_noformat.c
vf_noise.c
vf_ow.c
vf_palette.c
vf_perspective.c
vf_phase.c
vf_pp.c
vf_pp7.c
vf_pullup.c
vf_qp.c
vf_rectangle.c
vf_remove_logo.c
vf_rgb2bgr.c
vf_rgbtest.c
vf_rotate.c
vf_sab.c
vf_scale.c
vf_scale.h
vf_screenshot.c
vf_smartblur.c
vf_softpulldown.c
vf_softskip.c
vf_spp.c
vf_swapuv.c
vf_telecine.c
vf_test.c
vf_tfields.c
vf_tile.c
vf_tinterlace.c
vf_unsharp.c
vf_uspp.c
vf_vo.c
vf_yadif.c
vf_yuvcsp.c
vf_yuy2.c
vf_yvu9.c
vf_zrmjpeg.c
vfcap.h
vqf.h
libmpdemux
libmpeg2
libvo
loader
mp3lib
osdep
rpm
stream
tremor
vidix
.gitignore
AUTHORS
Changelog
Copyright
LICENSE
Makefile
README
access_mpcontext.h
ass_mp.c
ass_mp.h
asxparser.c
asxparser.h
av_opts.c
av_opts.h
cfg-common-opts.h
cfg-common.h
cfg-mencoder.h
cfg-mplayer-def.h
cfg-mplayer.h
codec-cfg.c
codec-cfg.h
command.c
command.h
configure
cpudetect.c
cpudetect.h
cpuinfo.c
defaultopts.c
defaultopts.h
edl.c
edl.h
find_sub.c
fmt-conversion.c
fmt-conversion.h
get_path.c
get_path.h
m_config.c
m_config.h
m_option.c
m_option.h
m_property.c
m_property.h
m_struct.c
m_struct.h
mangle.h
mencoder.c
metadata.h
mixer.c
mixer.h
mp_core.h
mp_fifo.c
mp_fifo.h
mp_msg-mencoder.c
mp_msg.c
mp_msg.h
mp_osd.h
mpbswap.h
mpcommon.c
mpcommon.h
mplayer.c
mplayer.h
options.h
parser-cfg.c
parser-cfg.h
parser-mecmd.c
parser-mecmd.h
parser-mpcmd.c
parser-mpcmd.h
playtree.c
playtree.h
playtreeparser.c
playtreeparser.h
spudec.c
spudec.h
sub_cc.c
sub_cc.h
subopt-helper.c
subopt-helper.h
subreader.c
subreader.h
talloc.c
talloc.h
unrar_exec.c
unrar_exec.h
version.sh
vobsub.c
vobsub.h
xvid_vbr.c
xvid_vbr.h
mpv/libmpcodecs/vd_zrmjpeg.c
2009-07-07 02:34:35 +03:00

250 lines
6.3 KiB
C

/*
* Copyright (C) 2005 Rik Snel <rsnel@cube.dyndns.org>
* - based on vd_mpegpes.c by A'rpi (C) 2002-2003
* - guess_mjpeg_type code stolen from lav_io.c (C) 2000 Rainer Johanni
* <Rainer@Johanni.de> from the mjpegtools package
*
* 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 "config.h"
#include "mp_msg.h"
#include "vfcap.h"
/* some convenient #define's, is this portable enough? */
#define VERBOSE(...) mp_msg(MSGT_DECVIDEO, MSGL_V, "vd_zrmjpeg: " __VA_ARGS__)
#define ERROR(...) mp_msg(MSGT_DECVIDEO, MSGL_ERR, "vd_zrmjpeg: " __VA_ARGS__)
#define WARNING(...) mp_msg(MSGT_DECVIDEO, MSGL_WARN, \
"vd_zrmjpeg: " __VA_ARGS__)
#include "vd_internal.h"
static const vd_info_t info =
{
"Zoran MJPEG Video passthrough",
"zrmjpeg",
"Rik Snel <snel@phys.uu.nl>",
"Rik Snel <snel@phys.uu.nl>",
"for hw decoders (DC10(+)/buz/lml33)"
};
LIBVD_EXTERN(zrmjpeg)
#include "libvo/video_out.h"
typedef struct {
int vo_initialized;
unsigned int preferred_csp;
} vd_zrmjpeg_ctx_t;
static int query_format(sh_video_t *sh, unsigned int format) {
vd_zrmjpeg_ctx_t *ctx = sh->context;
if (format == ctx->preferred_csp) return VFCAP_CSP_SUPPORTED;
return CONTROL_FALSE;
}
// to set/get/query special features/parameters
static int control(sh_video_t *sh, int cmd, void* arg, ...) {
switch (cmd) {
case VDCTRL_QUERY_FORMAT:
return query_format(sh, *((unsigned int*)arg));
}
return CONTROL_UNKNOWN;
}
// init driver
static int init(sh_video_t *sh) {
vd_zrmjpeg_ctx_t *ctx;
VERBOSE("init called\n");
ctx = malloc(sizeof(*ctx));
if (!ctx) return 0;
memset(ctx, 0, sizeof(*ctx));
sh->context = ctx;
/* defer init of vo until the first frame is known */
return 1;
#if 0
return mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_ZRMJPEGIT);
#endif
}
// uninit driver
static void uninit(sh_video_t *sh) {
free(sh->context);
}
/* parts directly stolen from scan_jpg() and lav_open_input_file */
static int get_int2(unsigned char *buf) {
return buf[0]*256 + buf[1];
}
#define M_SOF0 0xC0
#define M_SOF1 0xC1
#define M_DHT 0xC4
#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
#define M_EOI 0xD9 /* End Of Image (end of datastream) */
#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
#define M_DQT 0xDB
#define M_APP0 0xE0
#define M_APP1 0xE1
/* returns 0 in case of failure */
static unsigned int guess_mjpeg_type(unsigned char *data, unsigned int size,
int d_height) {
unsigned int p;
int marker, length, height, i, hf[3], vf[3];
unsigned int app0 = 0, header = 0;
/* The initial marker must be SIO */
if (size < 2) {
ERROR("JPEG data too short (%d bytes)\n", size);
return 0;
}
if (data[0] != 0xFF || data[1] != M_SOI) {
ERROR("JPEG data must start with FFD8, but doesn't\n");
return 0;
}
p = 2; /* pointer within jpeg data */
while (p < size) {
/* search 0xFF */
while(data[p] != 0xFF) {
p++;
if (p >= size) return 0;
}
/* get marker code, skip duplicate FF's */
while(data[p] == 0xFF) {
p++;
if (p >= size) return 0;
}
marker = data[p++];
/* marker may have an associated length */
if (p <= size - 2) length = get_int2(data+p);
else length = 0;
switch (marker) {
case M_SOF0:
case M_SOF1:
header = p-2;
VERBOSE("found offset of header %u\n",
header);
break;
case M_SOS:
size = 0;
continue;
case M_APP0:
app0 = p-2;
VERBOSE("found offset of APP0 %u\n",
app0);
break;
}
/* these markers shouldn't have parameters,
* i.e. we don't need to skip anaything */
if (marker == 0 || marker == 1 ||
(marker >= 0xd0 && marker < 0xd8))
continue;
if (p + length <= size) p += length;
else {
ERROR("input JPEG too short, data missing\n");
return 0;
}
}
if (!header) {
ERROR("JPEG header (with resolution and sampling factors) not found\n");
return 0;
}
if (data[header + 9] != 3) {
ERROR("JPEG has wrong number of components\n");
return 0;
}
/* get the horizontal and vertical sample factors */
for (i = 0; i < 3; i++) {
hf[i] = data[header + 10 + 3*i + 1]>>4;
vf[i] = data[header + 10 + 3*i + 1]&0x0F;
}
if (hf[0] != 2 || hf[1] != 1 || hf[2] != 1 ||
vf[0] != 1 || vf[1] != 1 || vf[2] != 1) {
ERROR("JPEG has wrong internal image format\n");
} else VERBOSE("JPEG has colorspace YUV422 with minimal sampling factors (good)\n");
height = get_int2(data + header + 5);
if (height == d_height) {
VERBOSE("data is non interlaced\n");
return IMGFMT_ZRMJPEGNI;
}
if (2*height != d_height) {
ERROR("something very inconsistent happened\n");
return 0;
}
if (app0 && get_int2(data + app0 + 2) >= 5 &&
strncasecmp((char*)(data + app0 + 4), "AVI1", 4) == 0) {
if (data[app0+8] == 1) {
VERBOSE("data is interlaced, APP0: top-first (1)\n");
return IMGFMT_ZRMJPEGIT;
} else {
VERBOSE("data is interlaced, APP0: bottom-first (%d)\n",
data[app0+8]);
return IMGFMT_ZRMJPEGIB;
}
} else {
VERBOSE("data is interlaced, no (valid) APP0 marker, "
"guessing top-first\n");
return IMGFMT_ZRMJPEGIT;
}
return 0;
}
// decode a frame
static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) {
mp_image_t* mpi;
vd_zrmjpeg_ctx_t *ctx = sh->context;
if (!ctx->vo_initialized) {
ctx->preferred_csp = guess_mjpeg_type(data, len, sh->disp_h);
if (ctx->preferred_csp == 0) return NULL;
mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h,
ctx->preferred_csp);
ctx->vo_initialized = 1;
}
mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
sh->disp_w, sh->disp_h);
/* abuse of mpi */
mpi->planes[0]=(uint8_t*)data;
mpi->planes[1]=(uint8_t*)len;
return mpi;
}