summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile57
-rw-r--r--cfg-mencoder.h278
-rwxr-xr-xconfigure9
-rw-r--r--libmpcodecs/ae.c116
-rw-r--r--libmpcodecs/ae.h65
-rw-r--r--libmpcodecs/ae_faac.c215
-rw-r--r--libmpcodecs/ae_faac.h27
-rw-r--r--libmpcodecs/ae_lame.c493
-rw-r--r--libmpcodecs/ae_lame.h26
-rw-r--r--libmpcodecs/ae_lavc.c244
-rw-r--r--libmpcodecs/ae_lavc.h26
-rw-r--r--libmpcodecs/ae_pcm.c101
-rw-r--r--libmpcodecs/ae_pcm.h26
-rw-r--r--libmpcodecs/ae_toolame.c236
-rw-r--r--libmpcodecs/ae_toolame.h34
-rw-r--r--libmpcodecs/ae_twolame.c235
-rw-r--r--libmpcodecs/ae_twolame.h32
-rw-r--r--libmpcodecs/native/mmx.h98
-rw-r--r--libmpcodecs/native/rtjpegn.c1758
-rw-r--r--libmpcodecs/native/rtjpegn.h44
-rw-r--r--libmpcodecs/ve.c75
-rw-r--r--libmpcodecs/ve_lavc.c1050
-rw-r--r--libmpcodecs/ve_libdv.c135
-rw-r--r--libmpcodecs/ve_nuv.c255
-rw-r--r--libmpcodecs/ve_qtvideo.c359
-rw-r--r--libmpcodecs/ve_raw.c177
-rw-r--r--libmpcodecs/ve_vfw.c377
-rw-r--r--libmpcodecs/ve_x264.c308
-rw-r--r--libmpcodecs/ve_x264.h26
-rw-r--r--libmpcodecs/ve_xvid4.c1527
-rw-r--r--libmpdemux/muxer.c167
-rw-r--r--libmpdemux/muxer.h143
-rw-r--r--libmpdemux/muxer_avi.c694
-rw-r--r--libmpdemux/muxer_lavf.c408
-rw-r--r--libmpdemux/muxer_mpeg.c2735
-rw-r--r--libmpdemux/muxer_rawaudio.c89
-rw-r--r--libmpdemux/muxer_rawvideo.c92
-rw-r--r--mencoder.c1779
-rw-r--r--parser-mecmd.c169
-rw-r--r--parser-mecmd.h55
-rw-r--r--xvid_vbr.c1648
-rw-r--r--xvid_vbr.h231
42 files changed, 6 insertions, 16613 deletions
diff --git a/Makefile b/Makefile
index 4e40e77332..224dbf33cc 100644
--- a/Makefile
+++ b/Makefile
@@ -642,51 +642,18 @@ SRCS_MPLAYER = command.c \
libvo/vo_null.c \
$(SRCS_MPLAYER-yes)
-
-SRCS_MENCODER-$(FAAC) += libmpcodecs/ae_faac.c
-SRCS_MENCODER-$(LIBAVCODEC) += libmpcodecs/ae_lavc.c libmpcodecs/ve_lavc.c
-SRCS_MENCODER-$(LIBAVFORMAT) += libmpdemux/muxer_lavf.c
-SRCS_MENCODER-$(LIBDV) += libmpcodecs/ve_libdv.c
-SRCS_MENCODER-$(LIBLZO) += libmpcodecs/ve_nuv.c \
- libmpcodecs/native/rtjpegn.c
-SRCS_MENCODER-$(MP3LAME) += libmpcodecs/ae_lame.c
-SRCS_MENCODER-$(QTX_CODECS_WIN32) += libmpcodecs/ve_qtvideo.c
-SRCS_MENCODER-$(TOOLAME) += libmpcodecs/ae_toolame.c
-SRCS_MENCODER-$(TWOLAME) += libmpcodecs/ae_twolame.c
-SRCS_MENCODER-$(WIN32DLL) += libmpcodecs/ve_vfw.c
-SRCS_MENCODER-$(X264) += libmpcodecs/ve_x264.c
-SRCS_MENCODER-$(XVID4) += libmpcodecs/ve_xvid4.c
-
-SRCS_MENCODER = mencoder.c \
- parser-mecmd.c \
- xvid_vbr.c \
- libmpcodecs/ae.c \
- libmpcodecs/ae_pcm.c \
- libmpcodecs/ve.c \
- libmpcodecs/ve_raw.c \
- libmpdemux/muxer.c \
- libmpdemux/muxer_avi.c \
- libmpdemux/muxer_mpeg.c \
- libmpdemux/muxer_rawaudio.c \
- libmpdemux/muxer_rawvideo.c \
- $(SRCS_MENCODER-yes)
-
COMMON_LIBS += $(COMMON_LIBS-yes)
OBJS_COMMON += $(addsuffix .o, $(basename $(SRCS_COMMON)))
-OBJS_MENCODER += $(addsuffix .o, $(basename $(SRCS_MENCODER)))
OBJS_MPLAYER += $(addsuffix .o, $(basename $(SRCS_MPLAYER)))
OBJS_MPLAYER-$(PE_EXECUTABLE) += osdep/mplayer-rc.o
OBJS_MPLAYER += $(OBJS_MPLAYER-yes)
-MENCODER_DEPS = $(OBJS_MENCODER) $(OBJS_COMMON) $(COMMON_LIBS)
MPLAYER_DEPS = $(OBJS_MPLAYER) $(OBJS_COMMON) $(COMMON_LIBS)
-DEPS = $(filter-out %.S,$(patsubst %.cpp,%.d,$(patsubst %.c,%.d,$(SRCS_COMMON) $(SRCS_MPLAYER:.m=.d) $(SRCS_MENCODER))))
+DEPS = $(filter-out %.S,$(patsubst %.cpp,%.d,$(patsubst %.c,%.d,$(SRCS_COMMON) $(SRCS_MPLAYER:.m=.d))))
ALL_PRG-$(MPLAYER) += mplayer$(EXESUF)
-ALL_PRG-$(MENCODER) += mencoder$(EXESUF)
-INSTALL_TARGETS-$(MENCODER) += install-mencoder install-mencoder-man
INSTALL_TARGETS-$(MPLAYER) += install-mplayer \
install-mplayer-man \
install-mplayer-msg
@@ -754,11 +721,9 @@ all: $(ALL_PRG-yes) locales
%-rc.o: %.rc
$(WINDRES) -I. $< $@
-mencoder$(EXESUF): $(MENCODER_DEPS)
-mencoder$(EXESUF): EXTRALIBS += $(EXTRALIBS_MENCODER)
mplayer$(EXESUF): $(MPLAYER_DEPS)
mplayer$(EXESUF): EXTRALIBS += $(EXTRALIBS_MPLAYER)
-mencoder$(EXESUF) mplayer$(EXESUF):
+mplayer$(EXESUF):
$(CC) -o $@ $^ $(EXTRALIBS)
codec-cfg$(EXESUF): codec-cfg.c codec-cfg.h
@@ -848,29 +813,19 @@ install-dirs:
install-%: %$(EXESUF) install-dirs
$(INSTALL) -m 755 $(INSTALLSTRIP) $< $(BINDIR)
-install-mencoder-man: $(foreach lang,$(MAN_LANGS),install-mencoder-man-$(lang))
install-mplayer-man: $(foreach lang,$(MAN_LANGS),install-mplayer-man-$(lang))
install-mplayer-msg: $(foreach lang,$(MSG_LANGS),install-mplayer-msg-$(lang))
-install-mencoder-man-en: install-mplayer-man-en
- cd $(MANDIR)/man1 && ln -sf mplayer.1 mencoder.1
-
install-mplayer-man-en:
if test ! -d $(MANDIR)/man1 ; then $(INSTALL) -d $(MANDIR)/man1 ; fi
$(INSTALL) -m 644 DOCS/man/en/mplayer.1 $(MANDIR)/man1/
-define MENCODER_MAN_RULE
-install-mencoder-man-$(lang): install-mplayer-man-$(lang)
- cd $(MANDIR)/$(lang)/man1 && ln -sf mplayer.1 mencoder.1
-endef
-
define MPLAYER_MAN_RULE
install-mplayer-man-$(lang):
if test ! -d $(MANDIR)/$(lang)/man1 ; then $(INSTALL) -d $(MANDIR)/$(lang)/man1 ; fi
$(INSTALL) -m 644 DOCS/man/$(lang)/mplayer.1 $(MANDIR)/$(lang)/man1/
endef
-$(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(MENCODER_MAN_RULE)))
$(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(MPLAYER_MAN_RULE)))
define MPLAYER_MSG_RULE
@@ -883,17 +838,15 @@ $(foreach lang,$(MSG_LANG_ALL),$(eval $(MPLAYER_MSG_RULE)))
uninstall:
rm -f $(BINDIR)/mplayer$(EXESUF) $(BINDIR)/gmplayer$(EXESUF)
- rm -f $(BINDIR)/mencoder$(EXESUF)
- rm -f $(MANDIR)/man1/mencoder.1 $(MANDIR)/man1/mplayer.1
rm -f $(prefix)/share/pixmaps/mplayer.xpm
rm -f $(prefix)/share/applications/mplayer.desktop
- rm -f $(MANDIR)/man1/mplayer.1 $(MANDIR)/man1/mencoder.1
- rm -f $(foreach lang,$(MAN_LANGS),$(foreach man,mplayer.1 mencoder.1,$(MANDIR)/$(lang)/man1/$(man)))
+ rm -f $(MANDIR)/man1/mplayer.1
+ rm -f $(foreach lang,$(MAN_LANGS),$(foreach man,mplayer.1,$(MANDIR)/$(lang)/man1/$(man)))
rm -f $(foreach lang,$(MSG_LANGS),$(LOCALEDIR)/$(lang)/LC_MESSAGES/mplayer.1)
clean:
-rm -f $(call ADD_ALL_DIRS,/*.o /*.a /*.ho /*~)
- -rm -f $(call ADD_ALL_EXESUFS,mplayer mencoder)
+ -rm -f $(call ADD_ALL_EXESUFS,mplayer)
distclean: clean testsclean toolsclean driversclean dhahelperclean dhahelperwinclean
-rm -rf DOCS/tech/doxygen
diff --git a/cfg-mencoder.h b/cfg-mencoder.h
deleted file mode 100644
index 02473ef00b..0000000000
--- a/cfg-mencoder.h
+++ /dev/null
@@ -1,278 +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_CFG_MENCODER_H
-#define MPLAYER_CFG_MENCODER_H
-
-/*
- * config for cfgparser
- */
-
-#include "libmpcodecs/ve_x264.h"
-#include "cfg-common.h"
-
-extern const m_option_t faacopts_conf[];
-extern const m_option_t lameopts_conf[];
-extern const m_option_t lavcopts_conf[];
-extern const m_option_t lavfopts_conf[];
-extern const m_option_t mpegopts_conf[];
-extern const m_option_t nuvopts_conf[];
-extern const m_option_t toolameopts_conf[];
-extern const m_option_t twolameopts_conf[];
-extern const m_option_t vfwopts_conf[];
-extern const m_option_t xvidencopts_conf[];
-
-const m_option_t ovc_conf[]={
- {"copy", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_COPY, NULL},
- {"frameno", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_FRAMENO, NULL},
- {"lavc", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_LIBAVCODEC, NULL},
-// {"null", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_NULL, NULL},
- {"raw", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_RAW, NULL},
- {"vfw", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_VFW, NULL},
- {"libdv", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_LIBDV, NULL},
- {"xvid", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_XVID, NULL},
- {"qtvideo", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_QTVIDEO, NULL},
- {"nuv", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_NUV, NULL},
- {"x264", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_X264, NULL},
- {"help", "\nAvailable codecs:\n"
- " copy - frame copy, without re-encoding. Doesn't work with filters.\n"
- " frameno - special audio-only file for 3-pass encoding, see DOCS.\n"
- " raw - uncompressed video. Use fourcc option to set format explicitly.\n"
-#ifdef CONFIG_LIBLZO
- " nuv - nuppel video\n"
-#endif
-#ifdef CONFIG_LIBAVCODEC
- " lavc - libavcodec codecs - best quality!\n"
-#endif
-#ifdef CONFIG_WIN32DLL
- " vfw - VfW DLLs, read DOCS/HTML/en/encoding-guide.html.\n"
- " qtvideo - QuickTime DLLs, currently only SVQ1/3 are supported.\n"
-#endif
-#ifdef CONFIG_LIBDV095
- " libdv - DV encoding with libdv v0.9.5\n"
-#endif
-#ifdef CONFIG_XVID4
- " xvid - XviD encoding\n"
-#endif
-#ifdef CONFIG_X264
- " x264 - H.264 encoding\n"
-#endif
- "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-const m_option_t oac_conf[]={
- {"copy", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_COPY, NULL},
- {"pcm", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_PCM, NULL},
-#ifdef CONFIG_MP3LAME
- {"mp3lame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_VBRMP3, NULL},
-#else
- {"mp3lame", "MPlayer was compiled without libmp3lame support.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_MP3LAME */
-#ifdef CONFIG_LIBAVCODEC
- {"lavc", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_LAVC, NULL},
-#else
- {"lavc", "MPlayer was compiled without libavcodec. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_LIBAVCODEC */
-#ifdef CONFIG_TOOLAME
- {"toolame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_TOOLAME, NULL},
-#else
- {"toolame", "MPlayer was compiled without libtoolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_TOOLAME */
-#ifdef CONFIG_TWOLAME
- {"twolame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_TWOLAME, NULL},
-#else
- {"twolame", "MPlayer was compiled without libtwolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_TWOLAME */
-#ifdef CONFIG_FAAC
- {"faac", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_FAAC, NULL},
-#else
- {"faac", "MPlayer was compiled without libfaac. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_FAAC */
- {"help", "\nAvailable codecs:\n"
- " copy - frame copy, without re-encoding (useful for AC3)\n"
- " pcm - uncompressed PCM audio\n"
-#ifdef CONFIG_MP3LAME
- " mp3lame - cbr/abr/vbr MP3 using libmp3lame\n"
-#endif
-#ifdef CONFIG_LIBAVCODEC
- " lavc - FFmpeg audio encoder (MP2, AC3, ...)\n"
-#endif
-#ifdef CONFIG_TOOLAME
- " toolame - Toolame MP2 audio encoder\n"
-#endif
-#ifdef CONFIG_TWOLAME
- " twolame - Twolame MP2 audio encoder\n"
-#endif
-#ifdef CONFIG_FAAC
- " faac - FAAC AAC audio encoder\n"
-#endif
- "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-const m_option_t info_conf[]={
- {"name", &info_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"artist", &info_artist, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"genre", &info_genre, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"subject", &info_subject, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"copyright", &info_copyright, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"srcform", &info_sourceform, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"comment", &info_comment, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"help", "\nAvailable INFO fields:\n"
- " name - title of the work\n"
- " artist - artist or author of the work\n"
- " genre - original work category\n"
- " subject - contents of the work\n"
- " copyright - copyright information\n"
- " srcform - original format of the digitzed material\n"
- " comment - general comments about the work\n"
- "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-const m_option_t of_conf[]={
- {"avi", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_AVI, NULL},
- {"mpeg", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_MPEG, NULL},
-#ifdef CONFIG_LIBAVFORMAT
- {"lavf", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_LAVF, NULL},
-#endif
- {"rawvideo", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_RAWVIDEO, NULL},
- {"rawaudio", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_RAWAUDIO, NULL},
- {"help", "\nAvailable output formats:\n"
- " avi - Microsoft Audio/Video Interleaved\n"
- " mpeg - MPEG-1/2 system stream format\n"
-#ifdef CONFIG_LIBAVFORMAT
- " lavf - FFmpeg libavformat muxers\n"
-#endif
- " rawvideo - (video only, one stream only) raw stream, no muxing\n"
- " rawaudio - (audio only, one stream only) raw stream, no muxing\n"
- "\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-extern float avi_aspect_override; /* defined in libmpdemux/muxer_avi.c */
-extern int write_odml; /* defined in libmpdemux/muxer_avi.c */
-
-const m_option_t mencoder_opts[]={
- /* name, pointer, type, flags, min, max */
-
- {"frameno-file", &frameno_filename, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
-
- {"hr-edl-seek", &edl_seek_type, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nohr-edl-seek", &edl_seek_type, CONF_TYPE_FLAG, 0, 1, 0, NULL},
-
- // set output framerate - recommended for variable-FPS (ASF etc) files
- // and for 29.97FPS progressive MPEG2 streams
- {"ofps", &force_ofps, CONF_TYPE_DOUBLE, CONF_MIN|CONF_GLOBAL, 0, 0, NULL},
- {"o", &out_filename, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
-
- // limit number of skippable frames after a non-skipped one
- {"skiplimit", &skip_limit, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"noskiplimit", &skip_limit, CONF_TYPE_FLAG, 0, 0, -1, NULL},
- {"noskip", &skip_limit, CONF_TYPE_FLAG, 0, 0, 0, NULL},
-
- {"audio-density", &audio_density, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 1, 50, NULL},
- {"audio-preload", &audio_preload, CONF_TYPE_FLOAT, CONF_RANGE|CONF_GLOBAL, 0, 2, NULL},
- {"audio-delay", &audio_delay_fix, CONF_TYPE_FLOAT, CONF_GLOBAL, 0, 0, NULL},
-
- {"x", "-x has been removed, use -vf scale=w:h for scaling.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {"xsize", "-xsize has been removed, use -vf crop=w:h:x:y for cropping.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-
- // output audio/video codec selection
- {"oac", (void *) oac_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
- {"ovc", (void *) ovc_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-
- // output file format
- {"of", (void *) of_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-
- // override audio format tag in output file
- {"fafmttag", &force_audiofmttag, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL},
- // override FOURCC in output file
- {"ffourcc", &force_fourcc, CONF_TYPE_STRING, CONF_GLOBAL, 4, 4, NULL},
-
- // override avi aspect autodetection
- {"force-avi-aspect", &avi_aspect_override, CONF_TYPE_FLOAT, CONF_RANGE|CONF_GLOBAL, 0.2, 3.0, NULL},
-
- {"pass", "-pass has been removed, use -lavcopts vpass=n, -xvidencopts pass=n\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {"passlogfile", &passtmpfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
-
- {"vobsubout", &vobsub_out, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
- {"vobsuboutindex", &vobsub_out_index, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 0, 31, NULL},
- {"vobsuboutid", &vobsub_out_id, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
-
- {"autoexpand", &auto_expand, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"noautoexpand", &auto_expand, CONF_TYPE_FLAG, 0, 1, 0, NULL},
-
- {"encodedups", &encode_duplicates, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"noencodedups", &encode_duplicates, CONF_TYPE_FLAG, 0, 1, 0, NULL},
-
- {"odml", &write_odml, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
- {"noodml", &write_odml, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
-
- // info header strings
- {"info", (void *) info_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-
-#ifdef CONFIG_MP3LAME
- {"lameopts", lameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#endif
-#ifdef CONFIG_LIBAVCODEC
- {"lavcopts", lavcopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#else
- {"lavcopts", "MPlayer was compiled without libavcodec. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_LIBAVCODEC */
-#ifdef CONFIG_TOOLAME
- {"toolameopts", toolameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#else
- {"toolameopts", "MPlayer was compiled without libtoolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_TOOLAME */
-#ifdef CONFIG_TWOLAME
- {"twolameopts", twolameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#else
- {"twolameopts", "MPlayer was compiled without libtwolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_TWOLAME */
-#ifdef CONFIG_FAAC
- {"faacopts", faacopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#else
- {"faacopts", "MPlayer was compiled without libfaac. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif /* CONFIG_FAAC */
-#ifdef CONFIG_WIN32DLL
- {"xvfwopts", vfwopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#endif
-#ifdef CONFIG_XVID4
- {"xvidencopts", xvidencopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#endif
-#if defined(CONFIG_X264)
- {"x264encopts", &x264enc_set_param, CONF_TYPE_FUNC_PARAM, CONF_GLOBAL, 0, 0, NULL},
-#endif
-
-#ifdef CONFIG_LIBLZO
- {"nuvopts", nuvopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#endif
- {"mpegopts", mpegopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#ifdef CONFIG_LIBAVFORMAT
- {"lavfopts", lavfopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
-#endif
-
-// {"-help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-// {"help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-// {"h", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-#endif /* MPLAYER_CFG_MENCODER_H */
diff --git a/configure b/configure
index 176c4d3fc9..0210fa642c 100755
--- a/configure
+++ b/configure
@@ -264,7 +264,6 @@ Installation directories:
--codecsdir=DIR directory for binary codecs [LIBDIR/codecs]
Optional features:
- --disable-mencoder disable MEncoder (A/V encoder) compilation [enable]
--disable-mplayer disable MPlayer compilation [enable]
--disable-largefiles disable support for files > 2GB [enable]
--enable-termcap use termcap database for key codes [autodetect]
@@ -501,7 +500,6 @@ Use these options if autodetection fails:
--extra-ldflags=FLAGS extra LDFLAGS
--extra-libs=FLAGS extra linker flags
--extra-libs-mplayer=FLAGS extra linker flags for MPlayer
- --extra-libs-mencoder=FLAGS extra linker flags for MEncoder
--with-xvmclib=NAME adapter-specific library name (e.g. XvMCNVIDIA)
--with-freetype-config=PATH path to freetype-config
@@ -559,7 +557,7 @@ _libpostproc=auto
_libswscale=auto
_libavcodec_internals=no
_libswscale_internals=no
-_mencoder=yes
+_mencoder=no
_mplayer=yes
_x11=auto
_xshape=auto
@@ -810,9 +808,6 @@ for ac_option do
--extra-libs-mplayer=*)
libs_mplayer=$(echo $ac_option | cut -d '=' -f 2)
;;
- --extra-libs-mencoder=*)
- libs_mencoder=$(echo $ac_option | cut -d '=' -f 2)
- ;;
--target=*)
_target=$(echo $ac_option | cut -d '=' -f 2)
@@ -884,8 +879,6 @@ for ac_option do
--disable-runtime-cpudetection) _runtime_cpudetection=no ;;
--enable-cross-compile) _cross_compile=yes ;;
--disable-cross-compile) _cross_compile=no ;;
- --enable-mencoder) _mencoder=yes ;;
- --disable-mencoder) _mencoder=no ;;
--enable-mplayer) _mplayer=yes ;;
--disable-mplayer) _mplayer=no ;;
--enable-dynamic-plugins) _dynamic_plugins=yes ;;
diff --git a/libmpcodecs/ae.c b/libmpcodecs/ae.c
deleted file mode 100644
index 1669359981..0000000000
--- a/libmpcodecs/ae.c
+++ /dev/null
@@ -1,116 +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 <string.h>
-#include <stdlib.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <math.h>
-#include "config.h"
-#include "libmpdemux/aviheader.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include "ae.h"
-
-#include "ae_pcm.h"
-
-#ifdef CONFIG_TOOLAME
-#include "ae_toolame.h"
-#endif
-
-#ifdef CONFIG_MP3LAME
-#include "ae_lame.h"
-#endif
-
-#ifdef CONFIG_LIBAVCODEC
-#include "ae_lavc.h"
-#endif
-
-#ifdef CONFIG_FAAC
-#include "ae_faac.h"
-#endif
-
-#ifdef CONFIG_TWOLAME
-#include "ae_twolame.h"
-#endif
-
-audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params_t *params)
-{
- int ris;
- audio_encoder_t *encoder;
- if(! params)
- return NULL;
-
- encoder = calloc(1, sizeof(audio_encoder_t));
- memcpy(&encoder->params, params, sizeof(audio_encoding_params_t));
- encoder->stream = stream;
-
- switch(stream->codec)
- {
- case ACODEC_PCM:
- ris = mpae_init_pcm(encoder);
- break;
-#ifdef CONFIG_TOOLAME
- case ACODEC_TOOLAME:
- ris = mpae_init_toolame(encoder);
- break;
-#endif
-#ifdef CONFIG_LIBAVCODEC
- case ACODEC_LAVC:
- ris = mpae_init_lavc(encoder);
- break;
-#endif
-#ifdef CONFIG_MP3LAME
- case ACODEC_VBRMP3:
- ris = mpae_init_lame(encoder);
- break;
-#endif
-#ifdef CONFIG_FAAC
- case ACODEC_FAAC:
- ris = mpae_init_faac(encoder);
- break;
-#endif
-#ifdef CONFIG_TWOLAME
- case ACODEC_TWOLAME:
- ris = mpae_init_twolame(encoder);
- break;
-#endif
- default:
- ris = 0;
- break;
- }
-
- if(! ris)
- {
- free(encoder);
- return NULL;
- }
- encoder->bind(encoder, stream);
- encoder->decode_buffer = malloc(encoder->decode_buffer_size);
- if(! encoder->decode_buffer)
- {
- free(encoder);
- return NULL;
- }
-
- encoder->codec = stream->codec;
- return encoder;
-}
diff --git a/libmpcodecs/ae.h b/libmpcodecs/ae.h
deleted file mode 100644
index 440e4ddf4f..0000000000
--- a/libmpcodecs/ae.h
+++ /dev/null
@@ -1,65 +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_AE_H
-#define MPLAYER_AE_H
-
-#include "libmpdemux/muxer.h"
-
-#define ACODEC_COPY 0
-#define ACODEC_PCM 1
-#define ACODEC_VBRMP3 2
-#define ACODEC_NULL 3
-#define ACODEC_LAVC 4
-#define ACODEC_TOOLAME 5
-#define ACODEC_FAAC 6
-#define ACODEC_TWOLAME 7
-
-#define AE_NEEDS_COMPRESSED_INPUT 1
-
-typedef struct {
- int channels;
- int sample_rate;
- int bitrate;
- int samples_per_frame;
- int audio_preload;
-} audio_encoding_params_t;
-
-typedef struct audio_encoder_s {
- int codec;
- int flags;
- muxer_stream_t *stream;
- audio_encoding_params_t params;
- int audio_preload; //in ms
- int input_format;
- int min_buffer_size, max_buffer_size; //for init_audio_filters
- unsigned char *decode_buffer;
- int decode_buffer_size;
- int decode_buffer_len;
- void *priv;
- int (*bind)(struct audio_encoder_s*, muxer_stream_t*);
- int (*get_frame_size)(struct audio_encoder_s*);
- int (*set_decoded_len)(struct audio_encoder_s *encoder, int len);
- int (*encode)(struct audio_encoder_s *encoder, uint8_t *dest, void *src, int nsamples, int max_size);
- void (*fixup)(struct audio_encoder_s *encoder);
- int (*close)(struct audio_encoder_s *encoder);
-} audio_encoder_t;
-
-audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params_t *params);
-
-#endif /* MPLAYER_AE_H */
diff --git a/libmpcodecs/ae_faac.c b/libmpcodecs/ae_faac.c
deleted file mode 100644
index 63c716378d..0000000000
--- a/libmpcodecs/ae_faac.c
+++ /dev/null
@@ -1,215 +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 <inttypes.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include "m_option.h"
-#include "mp_msg.h"
-#include "libmpdemux/aviheader.h"
-#include "libaf/af_format.h"
-#include "libaf/reorder_ch.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include <faac.h>
-#include "ae.h"
-
-
-static faacEncHandle faac;
-static faacEncConfigurationPtr config = NULL;
-static int
- param_bitrate = 128,
- param_quality = 0,
- param_object_type = 1,
- param_mpeg = 2,
- param_tns = 0,
- param_raw = 0,
- param_cutoff = 0,
- param_format = 16,
- param_debug = 0;
-
-static int enc_frame_size = 0, divisor;
-static unsigned long samples_input, max_bytes_output;
-static unsigned char *decoder_specific_buffer = NULL;
-static unsigned long decoder_specific_len = 0;
-
-const m_option_t faacopts_conf[] = {
- {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"quality", &param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL},
- {"object", &param_object_type, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
- {"mpeg", &param_mpeg, CONF_TYPE_INT, CONF_RANGE, 2, 4, NULL},
- {"tns", &param_tns, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"cutoff", &param_cutoff, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"format", &param_format, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"raw", &param_raw, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-
-static int bind_faac(audio_encoder_t *encoder, muxer_stream_t *mux_a)
-{
- mux_a->wf = calloc(1, sizeof(WAVEFORMATEX) + decoder_specific_len + 256);
- mux_a->wf->wFormatTag = 0x706D;
- mux_a->wf->nChannels = encoder->params.channels;
- mux_a->h.dwSampleSize=0; // VBR
- mux_a->h.dwRate=encoder->params.sample_rate;
- mux_a->h.dwScale=encoder->params.samples_per_frame;
- mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
- mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
-
- mux_a->wf->nBlockAlign = mux_a->h.dwScale;
- mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
- mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
-
- mux_a->wf->cbSize = decoder_specific_len;
- mux_a->wf->wBitsPerSample = 0; /* does not apply */
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
-
- // Fix allocation
- mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
-
- if(config->inputFormat == FAAC_INPUT_FLOAT)
- encoder->input_format = AF_FORMAT_FLOAT_NE;
- else if(config->inputFormat == FAAC_INPUT_32BIT)
- encoder->input_format = AF_FORMAT_S32_NE;
- else
- encoder->input_format = AF_FORMAT_S16_NE;
-
- encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
- encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
-
- if(decoder_specific_buffer && decoder_specific_len)
- memcpy(mux_a->wf + 1, decoder_specific_buffer, decoder_specific_len);
-
- return 1;
-}
-
-static int get_frame_size(audio_encoder_t *encoder)
-{
- int sz = enc_frame_size;
- enc_frame_size = 0;
- return sz;
-}
-
-static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
-{
- if (encoder->params.channels >= 5)
- reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
- AF_CHANNEL_LAYOUT_AAC_DEFAULT,
- encoder->params.channels,
- len / divisor, divisor);
-
- // len is divided by the number of bytes per sample
- enc_frame_size = faacEncEncode(faac, (int32_t*) src, len / divisor, dest, max_size);
-
- return enc_frame_size;
-}
-
-int close_faac(audio_encoder_t *encoder)
-{
- return 1;
-}
-
-int mpae_init_faac(audio_encoder_t *encoder)
-{
- if(encoder->params.channels < 1 || encoder->params.channels > 6 || (param_mpeg != 2 && param_mpeg != 4))
- {
- mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, unsupported number of channels: %d, or mpeg version: %d, exit\n", encoder->params.channels, param_mpeg);
- return 0;
- }
-
- faac = faacEncOpen(encoder->params.sample_rate, encoder->params.channels, &samples_input, &max_bytes_output);
- if(!faac)
- {
- mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't init, exit\n");
- return 0;
- }
- mp_msg(MSGT_MENCODER, MSGL_V, "AE_FAAC, sample_input: %lu, max_bytes_output: %lu\n", samples_input, max_bytes_output);
- config = faacEncGetCurrentConfiguration(faac);
- if(!config)
- {
- mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't get init configuration, exit\n");
- return 0;
- }
-
- param_bitrate *= 1000;
- if(param_quality)
- config->quantqual = param_quality;
- else
- config->bitRate = param_bitrate / encoder->params.channels;
-
- if(param_format==33)
- {
- config->inputFormat = FAAC_INPUT_FLOAT;
- divisor = 4;
- }
- else if(param_format==32)
- {
- config->inputFormat = FAAC_INPUT_32BIT;
- divisor = 4;
- }
- else
- {
- config->inputFormat = FAAC_INPUT_16BIT;
- divisor = 2;
- }
- config->outputFormat = param_raw ? 0 : 1; // 1 is ADTS
- config->aacObjectType = param_object_type;
- if(MAIN==0) config->aacObjectType--;
- config->mpegVersion = (param_mpeg == 4 ? MPEG4 : MPEG2);
- config->useTns = param_tns;
- config->allowMidside = 1;
- config->shortctl = SHORTCTL_NORMAL;
- param_cutoff = param_cutoff ? param_cutoff : encoder->params.sample_rate / 2;
- if(param_cutoff > encoder->params.sample_rate / 2)
- param_cutoff = encoder->params.sample_rate / 2;
- config->bandWidth = param_cutoff;
- if(encoder->params.channels == 6)
- config->useLfe = 1;
-
- if(!faacEncSetConfiguration(faac, config))
- {
- mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, counldn't set specified parameters, exiting\n");
- return 0;
- }
-
- if(param_raw)
- faacEncGetDecoderSpecificInfo(faac, &decoder_specific_buffer, &decoder_specific_len);
- else
- decoder_specific_len = 0;
-
- encoder->params.bitrate = param_bitrate;
- encoder->params.samples_per_frame = 1024;
- encoder->decode_buffer_size = divisor * samples_input; //samples * 16 bits_per_sample
-
- encoder->bind = bind_faac;
- encoder->get_frame_size = get_frame_size;
- encoder->encode = encode_faac;
- encoder->close = close_faac;
-
- return 1;
-}
diff --git a/libmpcodecs/ae_faac.h b/libmpcodecs/ae_faac.h
deleted file mode 100644
index dddc0bf5ad..0000000000
--- a/libmpcodecs/ae_faac.h
+++ /dev/null
@@ -1,27 +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_AE_FAAC_H
-#define MPLAYER_AE_FAAC_H
-
-#include "ae.h"
-#include "libmpdemux/muxer.h"
-
-int mpae_init_faac(audio_encoder_t *encoder);
-
-#endif /* MPLAYER_AE_FAAC_H */
diff --git a/libmpcodecs/ae_lame.c b/libmpcodecs/ae_lame.c
deleted file mode 100644
index 90ed31dfe7..0000000000
--- a/libmpcodecs/ae_lame.c
+++ /dev/null
@@ -1,493 +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 <inttypes.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include "m_option.h"
-#include "mp_msg.h"
-#include "libmpdemux/aviheader.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include "ae_pcm.h"
-#include "libaf/af_format.h"
-#include "libmpdemux/mp3_hdr.h"
-
-#undef CDECL
-#include <lame/lame.h>
-
-lame_global_flags *lame;
-static int lame_param_quality=0; // best
-static int lame_param_algqual=5; // same as old default
-static int lame_param_vbr=vbr_default;
-static int lame_param_mode=-1; // unset
-static int lame_param_padding=-1; // unset
-static int lame_param_br=-1; // unset
-static int lame_param_ratio=-1; // unset
-static float lame_param_scale=-1; // unset
-static int lame_param_lowpassfreq = 0; //auto
-static int lame_param_highpassfreq = 0; //auto
-static int lame_param_free_format = 0; //disabled
-static int lame_param_br_min = 0; //not specified
-static int lame_param_br_max = 0; //not specified
-
-#ifdef CONFIG_MP3LAME_PRESET
-int lame_param_fast=0; // unset
-static char* lame_param_preset=NULL; // unset
-static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name );
-#endif
-
-#define MEncoderMP3LameHelp _("\n\n"\
-" vbr=<0-4> variable bitrate method\n"\
-" 0: cbr (constant bitrate)\n"\
-" 1: mt (Mark Taylor VBR algorithm)\n"\
-" 2: rh (Robert Hegemann VBR algorithm - default)\n"\
-" 3: abr (average bitrate)\n"\
-" 4: mtrh (Mark Taylor Robert Hegemann VBR algorithm)\n"\
-"\n"\
-" abr average bitrate\n"\
-"\n"\
-" cbr constant bitrate\n"\
-" Also forces CBR mode encoding on subsequent ABR presets modes.\n"\
-"\n"\
-" br=<0-1024> specify bitrate in kBit (CBR and ABR only)\n"\
-"\n"\
-" q=<0-9> quality (0-highest, 9-lowest) (only for VBR)\n"\
-"\n"\
-" aq=<0-9> algorithmic quality (0-best/slowest, 9-worst/fastest)\n"\
-"\n"\
-" ratio=<1-100> compression ratio\n"\
-"\n"\
-" vol=<0-10> set audio input gain\n"\
-"\n"\
-" mode=<0-3> (default: auto)\n"\
-" 0: stereo\n"\
-" 1: joint-stereo\n"\
-" 2: dualchannel\n"\
-" 3: mono\n"\
-"\n"\
-" padding=<0-2>\n"\
-" 0: no\n"\
-" 1: all\n"\
-" 2: adjust\n"\
-"\n"\
-" fast Switch on faster encoding on subsequent VBR presets modes,\n"\
-" slightly lower quality and higher bitrates.\n"\
-"\n"\
-" preset=<value> Provide the highest possible quality settings.\n"\
-" medium: VBR encoding, good quality\n"\
-" (150-180 kbps bitrate range)\n"\
-" standard: VBR encoding, high quality\n"\
-" (170-210 kbps bitrate range)\n"\
-" extreme: VBR encoding, very high quality\n"\
-" (200-240 kbps bitrate range)\n"\
-" insane: CBR encoding, highest preset quality\n"\
-" (320 kbps bitrate)\n"\
-" <8-320>: ABR encoding at average given kbps bitrate.\n\n")
-
-
-
-const m_option_t lameopts_conf[] = {
- {"q", &lame_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
- {"aq", &lame_param_algqual, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
- {"vbr", &lame_param_vbr, CONF_TYPE_INT, CONF_RANGE, 0, vbr_max_indicator, NULL},
- {"cbr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, 0, NULL},
- {"abr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, vbr_abr, NULL},
- {"mode", &lame_param_mode, CONF_TYPE_INT, CONF_RANGE, 0, MAX_INDICATOR, NULL},
- {"padding", &lame_param_padding, CONF_TYPE_INT, CONF_RANGE, 0, PAD_MAX_INDICATOR, NULL},
- {"br", &lame_param_br, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
- {"ratio", &lame_param_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"vol", &lame_param_scale, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10, NULL},
- {"lowpassfreq",&lame_param_lowpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
- {"highpassfreq",&lame_param_highpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
- {"nofree", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 0, NULL},
- {"free", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"br_min", &lame_param_br_min, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
- {"br_max", &lame_param_br_max, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
-#ifdef CONFIG_MP3LAME_PRESET
- {"fast", &lame_param_fast, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"preset", &lame_param_preset, CONF_TYPE_STRING, 0, 0, 0, NULL},
-#else
- {"fast", "MPlayer was built without -lameopts fast support (requires libmp3lame >=3.92).\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {"preset", "MPlayer was built without -lameopts preset support (requires libmp3lame >=3.92).\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
-#endif
- {"help", MEncoderMP3LameHelp, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-
-static int bind_lame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
-{
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "MP3 audio selected.\n");
- mux_a->h.dwSampleSize=0; // VBR
- mux_a->h.dwRate=encoder->params.sample_rate;
- mux_a->h.dwScale=encoder->params.samples_per_frame; // samples/frame
- if(sizeof(MPEGLAYER3WAVEFORMAT)!=30) mp_tmsg(MSGT_MENCODER,MSGL_WARN,"sizeof(MPEGLAYER3WAVEFORMAT)==%d!=30, maybe broken C compiler?\n",sizeof(MPEGLAYER3WAVEFORMAT));
- mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30
- mux_a->wf->wFormatTag=0x55; // MP3
- mux_a->wf->nChannels= (lame_param_mode<0) ? encoder->params.channels : ((lame_param_mode==3) ? 1 : 2);
- mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
- if(! lame_param_vbr)
- mux_a->wf->nAvgBytesPerSec=lame_param_br * 125;
- else
- mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME!
- mux_a->wf->nBlockAlign=encoder->params.samples_per_frame; // required for l3codeca.acm + WMP 6.4
- mux_a->wf->wBitsPerSample=0; //16;
- // from NaNdub: (requires for l3codeca.acm)
- mux_a->wf->cbSize=12;
- ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1;
- ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2;
- ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=encoder->params.samples_per_frame; // ???
- ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1;
- ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0;
-
- encoder->input_format = AF_FORMAT_S16_NE;
- encoder->min_buffer_size = 4608;
- encoder->max_buffer_size = mux_a->h.dwRate * mux_a->wf->nChannels * 2;
-
- return 1;
-}
-
-#define min(a, b) ((a) <= (b) ? (a) : (b))
-
-static int get_frame_size(audio_encoder_t *encoder)
-{
- int sz;
- if(encoder->stream->buffer_len < 4)
- return 0;
- sz = mp_decode_mp3_header(encoder->stream->buffer);
- if(sz <= 0)
- return 0;
- return sz;
-}
-
-static int encode_lame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
-{
- int n = 0;
- if(encoder->params.channels == 1)
- n = lame_encode_buffer(lame, (short *)src, (short *)src, len/2, dest, max_size);
- else
- n = lame_encode_buffer_interleaved(lame,(short *)src, len/4, dest, max_size);
-
- return n < 0 ? 0 : n;
-}
-
-
-static int close_lame(audio_encoder_t *encoder)
-{
- return 1;
-}
-
-static void fixup(audio_encoder_t *encoder)
-{
- // fixup CBR mp3 audio header:
- if(!lame_param_vbr) {
- encoder->stream->h.dwSampleSize=1;
- if (encoder->stream->h.dwLength)
- ((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize=
- (encoder->stream->size+(encoder->stream->h.dwLength>>1))/encoder->stream->h.dwLength;
- encoder->stream->h.dwLength=encoder->stream->size;
- encoder->stream->h.dwRate=encoder->stream->wf->nAvgBytesPerSec;
- encoder->stream->h.dwScale=1;
- encoder->stream->wf->nBlockAlign=1;
- mp_tmsg(MSGT_MENCODER, MSGL_V, "\n\nCBR audio: %d bytes/sec, %d bytes/block\n",
- encoder->stream->h.dwRate,((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize);
- }
-}
-
-int mpae_init_lame(audio_encoder_t *encoder)
-{
- encoder->params.bitrate = lame_param_br * 125;
- encoder->params.samples_per_frame = encoder->params.sample_rate < 32000 ? 576 : 1152;
- encoder->decode_buffer_size = 2304;
-
- lame=lame_init();
- lame_set_bWriteVbrTag(lame,0);
- lame_set_in_samplerate(lame,encoder->params.sample_rate);
- //lame_set_in_samplerate(lame,sh_audio->samplerate); // if resampling done by lame
- lame_set_num_channels(lame,encoder->params.channels);
- lame_set_out_samplerate(lame,encoder->params.sample_rate);
- lame_set_quality(lame,lame_param_algqual); // 0 = best q
- if(lame_param_free_format) lame_set_free_format(lame,1);
- if(lame_param_vbr){ // VBR:
- lame_set_VBR(lame,lame_param_vbr); // vbr mode
- lame_set_VBR_q(lame,lame_param_quality); // 0 = best vbr q 5=~128k
- if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br);
- if(lame_param_br_min>0) lame_set_VBR_min_bitrate_kbps(lame,lame_param_br_min);
- if(lame_param_br_max>0) lame_set_VBR_max_bitrate_kbps(lame,lame_param_br_max);
- } else { // CBR:
- if(lame_param_br>0) lame_set_brate(lame,lame_param_br);
- }
- if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st
- if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio);
- if(lame_param_scale>0) {
- mp_tmsg(MSGT_MENCODER, MSGL_V, "Setting audio input gain to %f.\n", lame_param_scale);
- lame_set_scale(lame,lame_param_scale);
- }
- if(lame_param_lowpassfreq>=-1) lame_set_lowpassfreq(lame,lame_param_lowpassfreq);
- if(lame_param_highpassfreq>=-1) lame_set_highpassfreq(lame,lame_param_highpassfreq);
-#ifdef CONFIG_MP3LAME_PRESET
- if(lame_param_preset != NULL) {
- mp_tmsg(MSGT_MENCODER, MSGL_V, "\npreset=%s\n\n",lame_param_preset);
- if(lame_presets_set(lame,lame_param_fast, (lame_param_vbr==0), lame_param_preset) < 0)
- return 0;
- }
-#endif
- if(lame_init_params(lame) == -1) {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL,
- "Cannot set LAME options, check bitrate/samplerate, some very low bitrates\n"\
- "(<32) need lower samplerates (i.e. -srate 8000).\n"\
- "If everything else fails, try a preset.");
- return 0;
- }
- if( mp_msg_test(MSGT_MENCODER,MSGL_V) ) {
- lame_print_config(lame);
- lame_print_internals(lame);
- }
-
- encoder->bind = bind_lame;
- encoder->get_frame_size = get_frame_size;
- encoder->encode = encode_lame;
- encoder->fixup = fixup;
- encoder->close = close_lame;
- return 1;
-}
-
-#ifdef CONFIG_MP3LAME_PRESET
-/* lame_presets_set
- taken out of presets_set in lame-3.93.1/frontend/parse.c and modified */
-static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name )
-{
- int mono = 0;
-
- if (strcmp(preset_name, "help") == 0) {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
-
-#define LamePresetsLongInfo _("\n"\
-"The preset switches are designed to provide the highest possible quality.\n"\
-"\n"\
-"They have for the most part been subjected to and tuned via rigorous double\n"\
-"blind listening tests to verify and achieve this objective.\n"\
-"\n"\
-"These are continually updated to coincide with the latest developments that\n"\
-"occur and as a result should provide you with nearly the best quality\n"\
-"currently possible from LAME.\n"\
-"\n"\
-"To activate these presets:\n"\
-"\n"\
-" For VBR modes (generally highest quality):\n"\
-"\n"\
-" \"preset=standard\" This preset should generally be transparent\n"\
-" to most people on most music and is already\n"\
-" quite high in quality.\n"\
-"\n"\
-" \"preset=extreme\" If you have extremely good hearing and similar\n"\
-" equipment, this preset will generally provide\n"\
-" slightly higher quality than the \"standard\"\n"\
-" mode.\n"\
-"\n"\
-" For CBR 320kbps (highest quality possible from the preset switches):\n"\
-"\n"\
-" \"preset=insane\" This preset will usually be overkill for most\n"\
-" people and most situations, but if you must\n"\
-" have the absolute highest quality with no\n"\
-" regard to filesize, this is the way to go.\n"\
-"\n"\
-" For ABR modes (high quality per given bitrate but not as high as VBR):\n"\
-"\n"\
-" \"preset=<kbps>\" Using this preset will usually give you good\n"\
-" quality at a specified bitrate. Depending on the\n"\
-" bitrate entered, this preset will determine the\n"\
-" optimal settings for that particular situation.\n"\
-" While this approach works, it is not nearly as\n"\
-" flexible as VBR, and usually will not attain the\n"\
-" same level of quality as VBR at higher bitrates.\n"\
-"\n"\
-"The following options are also available for the corresponding profiles:\n"\
-"\n"\
-" <fast> standard\n"\
-" <fast> extreme\n"\
-" insane\n"\
-" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"\
-" simply specify a bitrate. For example:\n"\
-" \"preset=185\" activates this\n"\
-" preset and uses 185 as an average kbps.\n"\
-"\n"\
-" \"fast\" - Enables the new fast VBR for a particular profile. The\n"\
-" disadvantage to the speed switch is that often times the\n"\
-" bitrate will be slightly higher than with the normal mode\n"\
-" and quality may be slightly lower also.\n"\
-" Warning: with the current version fast presets might result in too\n"\
-" high bitrate compared to regular presets.\n"\
-"\n"\
-" \"cbr\" - If you use the ABR mode (read above) with a significant\n"\
-" bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320,\n"\
-" you can use the \"cbr\" option to force CBR mode encoding\n"\
-" instead of the standard abr mode. ABR does provide higher\n"\
-" quality but CBR may be useful in situations such as when\n"\
-" streaming an MP3 over the internet may be important.\n"\
-"\n"\
-" For example:\n"\
-"\n"\
-" \"-lameopts fast:preset=standard \"\n"\
-" or \"-lameopts cbr:preset=192 \"\n"\
-" or \"-lameopts preset=172 \"\n"\
-" or \"-lameopts preset=extreme \"\n"\
-"\n"\
-"\n"\
-"A few aliases are available for ABR mode:\n"\
-"phone => 16kbps/mono phon+/lw/mw-eu/sw => 24kbps/mono\n"\
-"mw-us => 40kbps/mono voice => 56kbps/mono\n"\
-"fm/radio/tape => 112kbps hifi => 160kbps\n"\
-"cd => 192kbps studio => 256kbps")
-
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, LamePresetsLongInfo);
- return -1;
- }
-
- //aliases for compatibility with old presets
-
- if (strcmp(preset_name, "phone") == 0) {
- preset_name = "16";
- mono = 1;
- }
- if ( (strcmp(preset_name, "phon+") == 0) ||
- (strcmp(preset_name, "lw") == 0) ||
- (strcmp(preset_name, "mw-eu") == 0) ||
- (strcmp(preset_name, "sw") == 0)) {
- preset_name = "24";
- mono = 1;
- }
- if (strcmp(preset_name, "mw-us") == 0) {
- preset_name = "40";
- mono = 1;
- }
- if (strcmp(preset_name, "voice") == 0) {
- preset_name = "56";
- mono = 1;
- }
- if (strcmp(preset_name, "fm") == 0) {
- preset_name = "112";
- }
- if ( (strcmp(preset_name, "radio") == 0) ||
- (strcmp(preset_name, "tape") == 0)) {
- preset_name = "112";
- }
- if (strcmp(preset_name, "hifi") == 0) {
- preset_name = "160";
- }
- if (strcmp(preset_name, "cd") == 0) {
- preset_name = "192";
- }
- if (strcmp(preset_name, "studio") == 0) {
- preset_name = "256";
- }
-
-#ifdef CONFIG_MP3LAME_PRESET_MEDIUM
- if (strcmp(preset_name, "medium") == 0) {
- if (fast > 0)
- lame_set_preset(gfp, MEDIUM_FAST);
- else
- lame_set_preset(gfp, MEDIUM);
-
- return 0;
- }
-#endif
-
- if (strcmp(preset_name, "standard") == 0) {
- if (fast > 0)
- lame_set_preset(gfp, STANDARD_FAST);
- else
- lame_set_preset(gfp, STANDARD);
-
- return 0;
- }
-
- else if (strcmp(preset_name, "extreme") == 0){
- if (fast > 0)
- lame_set_preset(gfp, EXTREME_FAST);
- else
- lame_set_preset(gfp, EXTREME);
-
- return 0;
- }
-
- else if (((strcmp(preset_name, "insane") == 0) ||
- (strcmp(preset_name, "320" ) == 0)) && (fast < 1)) {
-
- lame_set_preset(gfp, INSANE);
-
- return 0;
- }
-
- // Generic ABR Preset
- if (((atoi(preset_name)) > 0) && (fast < 1)) {
- if ((atoi(preset_name)) >= 8 && (atoi(preset_name)) <= 320){
- lame_set_preset(gfp, atoi(preset_name));
-
- if (cbr == 1 )
- lame_set_VBR(gfp, vbr_off);
-
- if (mono == 1 ) {
- lame_set_mode(gfp, MONO);
- }
-
- return 0;
-
- }
- else {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL,
- "Error: The bitrate specified is out of the valid range for this preset.\n"\
- "\n"\
- "When using this mode you must enter a value between \"8\" and \"320\".\n"\
- "\n"\
- "For further information try: \"-lameopts preset=help\"\n");
- return -1;
- }
- }
-
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
-#define InvalidLamePresetOptions _("Error: You did not enter a valid profile and/or options with preset.\n"\
-"\n"\
-"Available profiles are:\n"\
-"\n"\
-" <fast> standard\n"\
-" <fast> extreme\n"\
-" insane\n"\
-" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"\
-" simply specify a bitrate. For example:\n"\
-" \"preset=185\" activates this\n"\
-" preset and uses 185 as an average kbps.\n"\
-"\n"\
-" Some examples:\n"\
-"\n"\
-" \"-lameopts fast:preset=standard \"\n"\
-" or \"-lameopts cbr:preset=192 \"\n"\
-" or \"-lameopts preset=172 \"\n"\
-" or \"-lameopts preset=extreme \"\n"\
-"\n"\
-"For further information try: \"-lameopts preset=help\"\n")
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, InvalidLamePresetOptions);
- return -1;
-}
-#endif
diff --git a/libmpcodecs/ae_lame.h b/libmpcodecs/ae_lame.h
deleted file mode 100644
index 861c0d3dc1..0000000000
--- a/libmpcodecs/ae_lame.h
+++ /dev/null
@@ -1,26 +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_AE_LAME_H
-#define MPLAYER_AE_LAME_H
-
-#include "ae.h"
-
-int mpae_init_lame(audio_encoder_t *encoder);
-
-#endif /* MPLAYER_AE_LAME_H */
diff --git a/libmpcodecs/ae_lavc.c b/libmpcodecs/ae_lavc.c
deleted file mode 100644
index 7c584daac3..0000000000
--- a/libmpcodecs/ae_lavc.c
+++ /dev/null
@@ -1,244 +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 <inttypes.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include "config.h"
-#include "m_option.h"
-#include "mp_msg.h"
-#include "libmpdemux/aviheader.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include "ae_lavc.h"
-#include "libaf/af_format.h"
-#include "libaf/reorder_ch.h"
-#include "libavcodec/avcodec.h"
-#include "ffmpeg_files/intreadwrite.h"
-
-static AVCodec *lavc_acodec;
-static AVCodecContext *lavc_actx;
-extern char *lavc_param_acodec;
-extern int lavc_param_abitrate;
-extern int lavc_param_atag;
-extern int lavc_param_audio_global_header;
-extern int avcodec_initialized;
-static int compressed_frame_size = 0;
-#include "libmpdemux/mp_taglists.h"
-
-static int bind_lavc(audio_encoder_t *encoder, muxer_stream_t *mux_a)
-{
- mux_a->wf = malloc(sizeof(WAVEFORMATEX)+lavc_actx->extradata_size+256);
- mux_a->wf->wFormatTag = lavc_param_atag;
- mux_a->wf->nChannels = lavc_actx->channels;
- mux_a->wf->nSamplesPerSec = lavc_actx->sample_rate;
- mux_a->wf->nAvgBytesPerSec = (lavc_actx->bit_rate / 8);
- mux_a->avg_rate= lavc_actx->bit_rate;
- mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
- if(lavc_actx->block_align)
- mux_a->h.dwSampleSize = mux_a->h.dwScale = lavc_actx->block_align;
- else
- {
- mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * lavc_actx->frame_size)/ mux_a->wf->nSamplesPerSec; /* for cbr */
-
- if ((mux_a->wf->nAvgBytesPerSec *
- lavc_actx->frame_size) % mux_a->wf->nSamplesPerSec)
- {
- mux_a->h.dwScale = lavc_actx->frame_size;
- mux_a->h.dwRate = lavc_actx->sample_rate;
- mux_a->h.dwSampleSize = 0; // Blocksize not constant
- }
- else
- mux_a->h.dwSampleSize = 0;
- }
- if(mux_a->h.dwSampleSize)
- mux_a->wf->nBlockAlign = mux_a->h.dwSampleSize;
- else
- mux_a->wf->nBlockAlign = 1;
- mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
- mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
-
- switch(lavc_param_atag)
- {
- case 0x11: /* imaadpcm */
- mux_a->wf->wBitsPerSample = 4;
- mux_a->wf->cbSize = 2;
- AV_WL16(mux_a->wf+1, lavc_actx->frame_size);
- break;
- case 0x55: /* mp3 */
- mux_a->wf->cbSize = 12;
- mux_a->wf->wBitsPerSample = 0; /* does not apply */
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
- break;
- default:
- mux_a->wf->wBitsPerSample = 0; /* Unknown */
- if (lavc_actx->extradata && (lavc_actx->extradata_size > 0))
- {
- memcpy(mux_a->wf+1, lavc_actx->extradata, lavc_actx->extradata_size);
- mux_a->wf->cbSize = lavc_actx->extradata_size;
- }
- else
- mux_a->wf->cbSize = 0;
- break;
- }
-
- // Fix allocation
- mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
-
- encoder->input_format = AF_FORMAT_S16_NE;
- encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
- encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
-
- return 1;
-}
-
-static int encode_lavc(audio_encoder_t *encoder, uint8_t *dest, void *src, int size, int max_size)
-{
- int n;
- if ((encoder->params.channels == 6 || encoder->params.channels == 5) &&
- (!strcmp(lavc_acodec->name,"ac3") ||
- !strcmp(lavc_acodec->name,"libfaac"))) {
- int isac3 = !strcmp(lavc_acodec->name,"ac3");
- reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
- isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT
- : AF_CHANNEL_LAYOUT_AAC_DEFAULT,
- encoder->params.channels,
- size / 2, 2);
- }
- n = avcodec_encode_audio(lavc_actx, dest, size, src);
- compressed_frame_size = n;
- return n;
-}
-
-
-static int close_lavc(audio_encoder_t *encoder)
-{
- compressed_frame_size = 0;
- return 1;
-}
-
-static int get_frame_size(audio_encoder_t *encoder)
-{
- int sz = compressed_frame_size;
- compressed_frame_size = 0;
- return sz;
-}
-
-int mpae_init_lavc(audio_encoder_t *encoder)
-{
- encoder->params.samples_per_frame = encoder->params.sample_rate;
- encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
-
- if(!lavc_param_acodec)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Audio LAVC, Missing codec name!\n");
- return 0;
- }
-
- if(!avcodec_initialized){
- avcodec_init();
- avcodec_register_all();
- avcodec_initialized=1;
- }
-
- lavc_acodec = avcodec_find_encoder_by_name(lavc_param_acodec);
- if (!lavc_acodec)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Audio LAVC, couldn't find encoder for codec %s.\n", lavc_param_acodec);
- return 0;
- }
- if(lavc_param_atag == 0)
- {
- lavc_param_atag = mp_av_codec_get_tag(mp_wav_taglists, lavc_acodec->id);
- if(!lavc_param_atag)
- {
- mp_msg(MSGT_MENCODER, MSGL_FATAL, "Couldn't find wav tag for specified codec, exit\n");
- return 0;
- }
- }
-
- lavc_actx = avcodec_alloc_context();
- if(lavc_actx == NULL)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Audio LAVC, couldn't allocate context!\n");
- return 0;
- }
-
- lavc_actx->codec_type = CODEC_TYPE_AUDIO;
- lavc_actx->codec_id = lavc_acodec->id;
- // put sample parameters
- lavc_actx->channels = encoder->params.channels;
- lavc_actx->sample_rate = encoder->params.sample_rate;
- lavc_actx->time_base.num = 1;
- lavc_actx->time_base.den = encoder->params.sample_rate;
- if(lavc_param_abitrate<1000)
- lavc_actx->bit_rate = encoder->params.bitrate = lavc_param_abitrate * 1000;
- else
- lavc_actx->bit_rate = encoder->params.bitrate = lavc_param_abitrate;
-
-
- /*
- * Special case for adpcm_ima_wav.
- * The bitrate is only dependent on samplerate.
- * We have to known frame_size and block_align in advance,
- * so I just copied the code from libavcodec/adpcm.c
- *
- * However, ms adpcm_ima_wav uses a block_align of 2048,
- * lavc defaults to 1024
- */
- if(lavc_param_atag == 0x11) {
- int blkalign = 2048;
- int framesize = (blkalign - 4 * lavc_actx->channels) * 8 / (4 * lavc_actx->channels) + 1;
- lavc_actx->bit_rate = lavc_actx->sample_rate*8*blkalign/framesize;
- }
- if((lavc_param_audio_global_header&1)
- /*|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))*/){
- lavc_actx->flags |= CODEC_FLAG_GLOBAL_HEADER;
- }
- if(lavc_param_audio_global_header&2){
- lavc_actx->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
- }
-
- if(avcodec_open(lavc_actx, lavc_acodec) < 0)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Couldn't open codec %s, br=%d.\n", lavc_param_acodec, lavc_param_abitrate);
- return 0;
- }
-
- if(lavc_param_atag == 0x11) {
- lavc_actx->block_align = 2048;
- lavc_actx->frame_size = (lavc_actx->block_align - 4 * lavc_actx->channels) * 8 / (4 * lavc_actx->channels) + 1;
- }
-
- encoder->decode_buffer_size = lavc_actx->frame_size * 2 * encoder->params.channels;
- while (encoder->decode_buffer_size < 1024) encoder->decode_buffer_size *= 2;
- encoder->bind = bind_lavc;
- encoder->get_frame_size = get_frame_size;
- encoder->encode = encode_lavc;
- encoder->close = close_lavc;
-
- return 1;
-}
diff --git a/libmpcodecs/ae_lavc.h b/libmpcodecs/ae_lavc.h
deleted file mode 100644
index 0e3f577d9e..0000000000
--- a/libmpcodecs/ae_lavc.h
+++ /dev/null
@@ -1,26 +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_AE_LAVC_H
-#define MPLAYER_AE_LAVC_H
-
-#include "ae.h"
-
-int mpae_init_lavc(audio_encoder_t *encoder);
-
-#endif /* MPLAYER_AE_LAVC_H */
diff --git a/libmpcodecs/ae_pcm.c b/libmpcodecs/ae_pcm.c
deleted file mode 100644
index cbae42dc87..0000000000
--- a/libmpcodecs/ae_pcm.c
+++ /dev/null
@@ -1,101 +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 <inttypes.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include "m_option.h"
-#include "mp_msg.h"
-#include "libmpdemux/aviheader.h"
-#include "libaf/af_format.h"
-#include "libaf/reorder_ch.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include "ae_pcm.h"
-
-
-static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
-{
- mux_a->h.dwScale=1;
- mux_a->h.dwRate=encoder->params.sample_rate;
- mux_a->wf=malloc(sizeof(WAVEFORMATEX));
- mux_a->wf->wFormatTag=0x1; // PCM
- mux_a->wf->nChannels=encoder->params.channels;
- mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
- mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
- mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
- mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
- mux_a->wf->wBitsPerSample=16;
- mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
-
- encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
- encoder->min_buffer_size = 16384;
- encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;
-
- return 1;
-}
-
-static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size)
-{
- max_size = FFMIN(nsamples, max_size);
- if (encoder->params.channels == 5 || encoder->params.channels == 6 ||
- encoder->params.channels == 8) {
- max_size -= max_size % (encoder->params.channels * 2);
- reorder_channel_copy_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
- dest, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
- encoder->params.channels,
- max_size / 2, 2);
- }
- else
- memcpy(dest, src, max_size);
- return max_size;
-}
-
-static int set_decoded_len(audio_encoder_t *encoder, int len)
-{
- return len;
-}
-
-static int close_pcm(audio_encoder_t *encoder)
-{
- return 1;
-}
-
-static int get_frame_size(audio_encoder_t *encoder)
-{
- return 0;
-}
-
-int mpae_init_pcm(audio_encoder_t *encoder)
-{
- encoder->params.samples_per_frame = encoder->params.sample_rate;
- encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
-
- encoder->decode_buffer_size = encoder->params.bitrate / 8;
- encoder->bind = bind_pcm;
- encoder->get_frame_size = get_frame_size;
- encoder->set_decoded_len = set_decoded_len;
- encoder->encode = encode_pcm;
- encoder->close = close_pcm;
-
- return 1;
-}
diff --git a/libmpcodecs/ae_pcm.h b/libmpcodecs/ae_pcm.h
deleted file mode 100644
index 5637891630..0000000000
--- a/libmpcodecs/ae_pcm.h
+++ /dev/null
@@ -1,26 +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_AE_PCM_H
-#define MPLAYER_AE_PCM_H
-
-#include "ae.h"
-
-int mpae_init_pcm(audio_encoder_t *encoder);
-
-#endif /* MPLAYER_AE_PCM_H */
diff --git a/libmpcodecs/ae_toolame.c b/libmpcodecs/ae_toolame.c
deleted file mode 100644
index 077b83d740..0000000000
--- a/libmpcodecs/ae_toolame.c
+++ /dev/null
@@ -1,236 +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 <inttypes.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include "m_option.h"
-#include "mp_msg.h"
-#include "libmpdemux/aviheader.h"
-#include "libaf/af_format.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include "ae_toolame.h"
-#include "libmpdemux/mp3_hdr.h"
-
-
-static int
- param_bitrate = 192,
- param_psy = 3,
- param_maxvbr = 0,
- param_errprot = 0,
- param_debug = 0;
-
-static float param_vbr = 0;
-static char *param_mode = "stereo";
-
-const m_option_t toolameopts_conf[] = {
- {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL},
- {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
- {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
- {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-
-static int bind_toolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
-{
- mpae_toolame_ctx *ctx = (mpae_toolame_ctx *) encoder->priv;
-
- mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
- mux_a->wf->wFormatTag = 0x50;
- mux_a->wf->nChannels = encoder->params.channels;
- mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
- mux_a->wf->nAvgBytesPerSec = 125 * encoder->params.bitrate;
-
- if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
- {
- mux_a->h.dwScale = encoder->params.samples_per_frame;
- mux_a->h.dwRate = encoder->params.sample_rate;
- mux_a->h.dwSampleSize = 0; // Blocksize not constant
- }
- else
- {
- mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
- mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
- mux_a->h.dwSampleSize = mux_a->h.dwScale;
- }
- mux_a->wf->nBlockAlign = mux_a->h.dwScale;
- mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
- mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
-
- mux_a->wf->cbSize = 0; //12;
- mux_a->wf->wBitsPerSample = 0; /* does not apply */
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
-
- // Fix allocation
- mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
-
- encoder->input_format = AF_FORMAT_S16_NE;
- encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
- encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
-
- return 1;
-}
-
-static int encode_toolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
-{
- mpae_toolame_ctx *ctx = (mpae_toolame_ctx *)encoder->priv;
- int ret_size = 0, r2, i, nsamples;
- int16_t *buffer;
-
- nsamples = len / (2*encoder->params.channels);
- buffer = (uint16_t *) src;
- for(i = 0; i < nsamples; i++)
- {
- ctx->left_pcm[i] = buffer[ctx->channels * i];
- ctx->right_pcm[i] = buffer[(ctx->channels * i) + (ctx->channels - 1)];
- }
-
- toolame_encode_buffer(ctx->toolame_ctx, ctx->left_pcm, ctx->right_pcm, nsamples, dest, max_size, &ret_size);
- r2 = mp_decode_mp3_header(dest);
- mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
- if(r2 > 0)
- ret_size = r2;
- return ret_size;
-}
-
-static int close_toolame(audio_encoder_t *encoder)
-{
- free(encoder->priv);
- return 1;
-}
-
-static int get_frame_size(audio_encoder_t *encoder)
-{
- int sz;
- if(encoder->stream->buffer_len < 4)
- return 0;
- sz = mp_decode_mp3_header(encoder->stream->buffer);
- if(sz <= 0)
- return 0;
- return sz;
-}
-
-
-int mpae_init_toolame(audio_encoder_t *encoder)
-{
- int mode;
- mpae_toolame_ctx *ctx = NULL;
-
- if(encoder->params.channels == 1)
- {
- mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_toolame, 1 audio channel, forcing mono mode\n");
- mode = MPG_MD_MONO;
- }
- else if(encoder->params.channels == 2)
- {
- if(! strcasecmp(param_mode, "dual"))
- mode = MPG_MD_DUAL_CHANNEL;
- else if(! strcasecmp(param_mode, "jstereo"))
- mode = MPG_MD_JOINT_STEREO;
- else if(! strcasecmp(param_mode, "stereo"))
- mode = MPG_MD_STEREO;
- else
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, unknown mode %s, exiting\n", param_mode);
- }
- }
- else
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, Toolame can't encode > 2 channels, exiting\n");
-
- ctx = calloc(1, sizeof(mpae_toolame_ctx));
- if(ctx == NULL)
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_toolame_ctx));
- return 0;
- }
-
- ctx->toolame_ctx = toolame_init();
- if(ctx->toolame_ctx == NULL)
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't initial parameters from libtoolame, exiting\n");
- free(ctx);
- return 0;
- }
- ctx->vbr = 0;
- ctx->channels = encoder->params.channels;
- ctx->srate = encoder->params.sample_rate;
-
- if(toolame_setMode(ctx->toolame_ctx, mode) != 0)
- return 0;
-
- if(toolame_setPsymodel(ctx->toolame_ctx, param_psy) != 0)
- return 0;
-
- if(toolame_setSampleFreq(ctx->toolame_ctx, encoder->params.sample_rate) != 0)
- return 0;
-
- if(toolame_setBitrate(ctx->toolame_ctx, param_bitrate) != 0)
- return 0;
-
- if(param_errprot)
- if(toolame_setErrorProtection(ctx->toolame_ctx, TRUE) != 0)
- return 0;
-
- if(param_vbr != 0)
- {
- if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0)
- return 0;
- if(toolame_setVBRLevel(ctx->toolame_ctx, param_vbr) != 0)
- return 0;
- if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0)
- return 0;
- if(param_maxvbr)
- {
- if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0)
- return 0;
- }
- ctx->vbr = 1;
- }
-
- if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0)
- return 0;
-
- if(toolame_init_params(ctx->toolame_ctx) != 0)
- return 0;
-
- ctx->bitrate = param_bitrate;
- encoder->params.bitrate = ctx->bitrate;
- encoder->params.samples_per_frame = 1152;
- encoder->priv = ctx;
- encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
-
- encoder->bind = bind_toolame;
- encoder->get_frame_size = get_frame_size;
- encoder->encode = encode_toolame;
- encoder->close = close_toolame;
-
- return 1;
-}
diff --git a/libmpcodecs/ae_toolame.h b/libmpcodecs/ae_toolame.h
deleted file mode 100644
index b257329843..0000000000
--- a/libmpcodecs/ae_toolame.h
+++ /dev/null
@@ -1,34 +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_AE_TOOLAME_H
-#define MPLAYER_AE_TOOLAME_H
-
-#include "ae.h"
-#include <toolame.h>
-
-typedef struct {
- toolame_options *toolame_ctx;
- int channels, srate, bitrate;
- int vbr;
- int16_t left_pcm[1152], right_pcm[1152];
-} mpae_toolame_ctx;
-
-int mpae_init_toolame(audio_encoder_t *encoder);
-
-#endif /* MPLAYER_AE_TOOLAME_H */
diff --git a/libmpcodecs/ae_twolame.c b/libmpcodecs/ae_twolame.c
deleted file mode 100644
index 52e6ea8417..0000000000
--- a/libmpcodecs/ae_twolame.c
+++ /dev/null
@@ -1,235 +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 <inttypes.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include "m_option.h"
-#include "mp_msg.h"
-#include "libmpdemux/aviheader.h"
-#include "libaf/af_format.h"
-#include "libmpdemux/ms_hdr.h"
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-#include "ae_twolame.h"
-#include "libmpdemux/mp3_hdr.h"
-
-
-static int
- param_bitrate = 192,
- param_psy = 3,
- param_maxvbr = 0,
- param_errprot = 0,
- param_debug = 0;
-
-static float param_vbr = 0;
-static char *param_mode = "stereo";
-
-const m_option_t twolameopts_conf[] = {
- {"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL},
- {"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
- {"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
- {"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-
-static int bind_twolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
-{
- mpae_twolame_ctx *ctx = encoder->priv;
-
- mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
- mux_a->wf->wFormatTag = 0x50;
- mux_a->wf->nChannels = encoder->params.channels;
- mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
- mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
-
- if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
- {
- mux_a->h.dwScale = encoder->params.samples_per_frame;
- mux_a->h.dwRate = encoder->params.sample_rate;
- mux_a->h.dwSampleSize = 0; // Blocksize not constant
- }
- else
- {
- mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
- mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
- mux_a->h.dwSampleSize = mux_a->h.dwScale;
- }
- mux_a->wf->nBlockAlign = mux_a->h.dwScale;
- mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
- mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
-
- mux_a->wf->cbSize = 0; //12;
- mux_a->wf->wBitsPerSample = 0; /* does not apply */
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
- ((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
-
- // Fix allocation
- mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
-
- encoder->input_format = AF_FORMAT_S16_NE;
- encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
- encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
-
- return 1;
-}
-
-static int encode_twolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
-{
- mpae_twolame_ctx *ctx = encoder->priv;
- int ret_size = 0, r2;
-
- len /= (2*encoder->params.channels);
- ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size);
- r2 = mp_decode_mp3_header(dest);
- mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
- if(r2 > 0)
- ret_size = r2;
- return ret_size;
-}
-
-static int close_twolame(audio_encoder_t *encoder)
-{
- free(encoder->priv);
- return 1;
-}
-
-static int get_frame_size(audio_encoder_t *encoder)
-{
- int sz;
- if(encoder->stream->buffer_len < 4)
- return 0;
- sz = mp_decode_mp3_header(encoder->stream->buffer);
- if(sz <= 0)
- return 0;
- return sz;
-}
-
-
-int mpae_init_twolame(audio_encoder_t *encoder)
-{
- int mode;
- mpae_twolame_ctx *ctx = NULL;
-
- if(encoder->params.channels == 1)
- {
- mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_twolame, 1 audio channel, forcing mono mode\n");
- mode = TWOLAME_MONO;
- }
- else if(encoder->params.channels == 2)
- {
- if(! strcasecmp(param_mode, "dual"))
- mode = TWOLAME_DUAL_CHANNEL;
- else if(! strcasecmp(param_mode, "jstereo"))
- mode = TWOLAME_JOINT_STEREO;
- else if(! strcasecmp(param_mode, "stereo"))
- mode = TWOLAME_STEREO;
- else
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, unknown mode %s, exiting\n", param_mode);
- }
- }
- else
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, Twolame can't encode > 2 channels, exiting\n");
-
- ctx = calloc(1, sizeof(mpae_twolame_ctx));
- if(ctx == NULL)
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_twolame_ctx));
- return 0;
- }
-
- ctx->twolame_ctx = twolame_init();
- if(ctx->twolame_ctx == NULL)
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't initial parameters from libtwolame, exiting\n");
- free(ctx);
- return 0;
- }
- ctx->vbr = 0;
-
- if(twolame_set_num_channels(ctx->twolame_ctx, encoder->params.channels) != 0)
- return 0;
- if(twolame_set_mode(ctx->twolame_ctx, mode) != 0)
- return 0;
-
- if(twolame_set_in_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
- return 0;
-
- if(twolame_set_out_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
- return 0;
-
- if(encoder->params.sample_rate < 32000)
- twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG2);
- else
- twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG1);
-
- if(twolame_set_psymodel(ctx->twolame_ctx, param_psy) != 0)
- return 0;
-
- if(twolame_set_bitrate(ctx->twolame_ctx, param_bitrate) != 0)
- return 0;
-
- if(param_errprot)
- if(twolame_set_error_protection(ctx->twolame_ctx, TRUE) != 0)
- return 0;
-
- if(param_vbr != 0)
- {
- if(twolame_set_VBR(ctx->twolame_ctx, TRUE) != 0)
- return 0;
- if(twolame_set_VBR_q(ctx->twolame_ctx, param_vbr) != 0)
- return 0;
- if(twolame_set_padding(ctx->twolame_ctx, FALSE) != 0)
- return 0;
- if(param_maxvbr)
- {
- if(twolame_set_VBR_max_bitrate_kbps(ctx->twolame_ctx, param_maxvbr) != 0)
- return 0;
- }
- ctx->vbr = 1;
- }
-
- if(twolame_set_verbosity(ctx->twolame_ctx, param_debug) != 0)
- return 0;
-
- if(twolame_init_params(ctx->twolame_ctx) != 0)
- return 0;
-
- encoder->params.bitrate = param_bitrate * 1000;
- encoder->params.samples_per_frame = 1152;
- encoder->priv = ctx;
- encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
-
- encoder->bind = bind_twolame;
- encoder->get_frame_size = get_frame_size;
- encoder->encode = encode_twolame;
- encoder->close = close_twolame;
-
- return 1;
-}
diff --git a/libmpcodecs/ae_twolame.h b/libmpcodecs/ae_twolame.h
deleted file mode 100644
index cfea9176bb..0000000000
--- a/libmpcodecs/ae_twolame.h
+++ /dev/null
@@ -1,32 +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_AE_TWOLAME_H
-#define MPLAYER_AE_TWOLAME_H
-
-#include "ae.h"
-#include <twolame.h>
-
-typedef struct {
- twolame_options *twolame_ctx;
- int vbr;
-} mpae_twolame_ctx;
-
-int mpae_init_twolame(audio_encoder_t *encoder);
-
-#endif /* MPLAYER_AE_TWOLAME_H */
diff --git a/libmpcodecs/native/mmx.h b/libmpcodecs/native/mmx.h
deleted file mode 100644
index eb9e95a25d..0000000000
--- a/libmpcodecs/native/mmx.h
+++ /dev/null
@@ -1,98 +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_MMX_H
-#define MPLAYER_MMX_H
-
-typedef union {
- long long q; /* Quadword (64-bit) value */
- unsigned long long uq; /* Unsigned Quadword */
- int d[2]; /* 2 Doubleword (32-bit) values */
- unsigned int ud[2]; /* 2 Unsigned Doubleword */
- short w[4]; /* 4 Word (16-bit) values */
- unsigned short uw[4]; /* 4 Unsigned Word */
- char b[8]; /* 8 Byte (8-bit) values */
- unsigned char ub[8]; /* 8 Unsigned Byte */
- float s[2]; /* Single-precision (32-bit) value */
-} mmx_t; /* On an 8-byte (64-bit) boundary */
-
-
-#define movq_m2r(var, reg) mmx_m2r(movq, var, reg)
-#define movq_r2m(reg, var) mmx_r2m(movq, reg, var)
-#define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd)
-
-#define punpcklwd_m2r(var, reg) mmx_m2r(punpcklwd, var, reg)
-#define punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd)
-
-#define punpckhwd_m2r(var, reg) mmx_m2r(punpckhwd, var, reg)
-#define punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd)
-
-#define punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd)
-#define punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd)
-#define punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd)
-#define punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd)
-
-#define psubw_m2r(var, reg) mmx_m2r(psubw, var, reg)
-#define psubw_r2r(regs, regd) mmx_r2r(psubw, regs, regd)
-#define psubsw_r2r(regs, regd) mmx_r2r(psubsw, regs, regd)
-
-#define pmaddwd_r2r(regs, regd) mmx_r2r(pmaddwd, regs, regd)
-#define paddw_m2r(var, reg) mmx_m2r(paddw, var, reg)
-#define paddw_r2r(regs, regd) mmx_r2r(paddw, regs, regd)
-
-#define psrad_i2r(imm, reg) mmx_i2r(psrad, imm, reg)
-
-#define psllw_i2r(imm, reg) mmx_i2r(psllw, imm, reg)
-
-#define pmulhw_r2r(regs, regd) mmx_r2r(pmulhw, regs, regd)
-#define pmulhw_m2r(var, reg) mmx_m2r(pmulhw, var, reg)
-
-#define psraw_i2r(imm, reg) mmx_i2r(psraw, imm, reg)
-
-#define packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd)
-#define packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd)
-
-#define pxor_r2r(regs, regd) mmx_r2r(pxor, regs, regd)
-
-#define pcmpgtw_r2r(regs, regd) mmx_r2r(pcmpgtw, regs, regd)
-
-#define por_r2r(regs, regd) mmx_r2r(por, regs, regd)
-
-
-#define mmx_i2r(op,imm,reg) \
- __asm__ volatile (#op " %0, %%" #reg \
- : /* nothing */ \
- : "i" (imm) )
-
-#define mmx_m2r(op, mem, reg) \
- __asm__ volatile (#op " %0, %%" #reg \
- : /* nothing */ \
- : "m" (mem))
-
-#define mmx_r2m(op, reg, mem) \
- __asm__ volatile (#op " %%" #reg ", %0" \
- : "=m" (mem) \
- : /* nothing */ )
-
-#define mmx_r2r(op, regs, regd) \
- __asm__ volatile (#op " %" #regs ", %" #regd)
-
-
-#define emms() __asm__ volatile ("emms")
-
-#endif /* MPLAYER_MMX_H */
diff --git a/libmpcodecs/native/rtjpegn.c b/libmpcodecs/native/rtjpegn.c
deleted file mode 100644
index 66089b0ecf..0000000000
--- a/libmpcodecs/native/rtjpegn.c
+++ /dev/null
@@ -1,1758 +0,0 @@
-/*
- RTjpeg (C) Justin Schoeman 1998 (justin@suntiger.ee.up.ac.za)
-
- With modifications by:
- (c) 1998, 1999 by Joerg Walter <trouble@moes.pmnet.uni-oldenburg.de>
- and
- (c) 1999 by Wim Taymans <wim.taymans@tvd.be>
-
- This program 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.
-
- This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "config.h"
-
-#include "mpbswap.h"
-#include "rtjpegn.h"
-
-#if HAVE_MMX
-#include "mmx.h"
-#endif
-
-//#define SHOWBLOCK 1
-#define BETTERCOMPRESSION 1
-
-static const unsigned char RTjpeg_ZZ[64]={
-0,
-8, 1,
-2, 9, 16,
-24, 17, 10, 3,
-4, 11, 18, 25, 32,
-40, 33, 26, 19, 12, 5,
-6, 13, 20, 27, 34, 41, 48,
-56, 49, 42, 35, 28, 21, 14, 7,
-15, 22, 29, 36, 43, 50, 57,
-58, 51, 44, 37, 30, 23,
-31, 38, 45, 52, 59,
-60, 53, 46, 39,
-47, 54, 61,
-62, 55,
-63 };
-
-static const __u64 RTjpeg_aan_tab[64]={
-4294967296ULL, 5957222912ULL, 5611718144ULL, 5050464768ULL, 4294967296ULL, 3374581504ULL, 2324432128ULL, 1184891264ULL,
-5957222912ULL, 8263040512ULL, 7783580160ULL, 7005009920ULL, 5957222912ULL, 4680582144ULL, 3224107520ULL, 1643641088ULL,
-5611718144ULL, 7783580160ULL, 7331904512ULL, 6598688768ULL, 5611718144ULL, 4408998912ULL, 3036936960ULL, 1548224000ULL,
-5050464768ULL, 7005009920ULL, 6598688768ULL, 5938608128ULL, 5050464768ULL, 3968072960ULL, 2733115392ULL, 1393296000ULL,
-4294967296ULL, 5957222912ULL, 5611718144ULL, 5050464768ULL, 4294967296ULL, 3374581504ULL, 2324432128ULL, 1184891264ULL,
-3374581504ULL, 4680582144ULL, 4408998912ULL, 3968072960ULL, 3374581504ULL, 2651326208ULL, 1826357504ULL, 931136000ULL,
-2324432128ULL, 3224107520ULL, 3036936960ULL, 2733115392ULL, 2324432128ULL, 1826357504ULL, 1258030336ULL, 641204288ULL,
-1184891264ULL, 1643641088ULL, 1548224000ULL, 1393296000ULL, 1184891264ULL, 931136000ULL, 641204288ULL, 326894240ULL,
-};
-
-#if !HAVE_MMX
-static __s32 RTjpeg_ws[64+31];
-#endif
-static __u8 RTjpeg_alldata[2*64+4*64+4*64+4*64+4*64+32];
-
-static __s16 *block; // rh
-static __s16 *RTjpeg_block;
-static __s32 *RTjpeg_lqt;
-static __s32 *RTjpeg_cqt;
-static __u32 *RTjpeg_liqt;
-static __u32 *RTjpeg_ciqt;
-
-static unsigned char RTjpeg_lb8;
-static unsigned char RTjpeg_cb8;
-static int RTjpeg_width, RTjpeg_height;
-static int RTjpeg_Ywidth, RTjpeg_Cwidth;
-static int RTjpeg_Ysize, RTjpeg_Csize;
-
-static __s16 *RTjpeg_old=NULL;
-
-#if HAVE_MMX
-static mmx_t RTjpeg_lmask;
-static mmx_t RTjpeg_cmask;
-#else
-static __u16 RTjpeg_lmask;
-static __u16 RTjpeg_cmask;
-#endif
-
-static const unsigned char RTjpeg_lum_quant_tbl[64] = {
- 16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68, 109, 103, 77,
- 24, 35, 55, 64, 81, 104, 113, 92,
- 49, 64, 78, 87, 103, 121, 120, 101,
- 72, 92, 95, 98, 112, 100, 103, 99
- };
-
-static const unsigned char RTjpeg_chrom_quant_tbl[64] = {
- 17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99
- };
-
-#ifdef BETTERCOMPRESSION
-
-/*--------------------------------------------------*/
-/* better encoding, but needs a lot more cpu time */
-/* seems to be more effective than old method +lzo */
-/* with this encoding lzo isn't efficient anymore */
-/* there is still more potential for better */
-/* encoding but that would need even more cputime */
-/* anyway your mileage may vary */
-/* */
-/* written by Martin BIELY and Roman HOCHLEITNER */
-/*--------------------------------------------------*/
-
-/* +++++++++++++++++++++++++++++++++++++++++++++++++++*/
-/* Block to Stream (encoding) */
-/* */
-
-static int RTjpeg_b2s(__s16 *data, __s8 *strm, __u8 bt8)
-{
- register int ci, co=1;
- register __s16 ZZvalue;
- register unsigned char bitten;
- register unsigned char bitoff;
-
-#ifdef SHOWBLOCK
-
- int ii;
- for (ii=0; ii < 64; ii++) {
- fprintf(stdout, "%d ", data[RTjpeg_ZZ[ii]]);
- }
- fprintf(stdout, "\n\n");
-
-#endif
-
- // first byte allways written
- ((__u8*)strm)[0]=
- (__u8)(data[RTjpeg_ZZ[0]]>254) ? 254:((data[RTjpeg_ZZ[0]]<0)?0:data[RTjpeg_ZZ[0]]);
-
-
- ci=63;
- while (data[RTjpeg_ZZ[ci]]==0 && ci>0) ci--;
-
- bitten = ((unsigned char)ci) << 2;
-
- if (ci==0) {
- ((__u8*)strm)[1]= bitten;
- co = 2;
- return (int)co;
- }
-
- /* bitoff=0 because the high 6bit contain first non zero position */
- bitoff = 0;
- co = 1;
-
- for(; ci>0; ci--) {
-
- ZZvalue = data[RTjpeg_ZZ[ci]];
-
- switch(ZZvalue) {
- case 0:
- break;
- case 1:
- bitten |= (0x01<<bitoff);
- break;
- case -1:
- bitten |= (0x03<<bitoff);
- break;
- default:
- bitten |= (0x02<<bitoff);
- goto HERZWEH;
- break;
- }
-
- if( bitoff == 0 ) {
- ((__u8*)strm)[co]= bitten;
- bitten = 0;
- bitoff = 8;
- co++;
- } /* "fall through" */
- bitoff-=2;
-
- }
-
- /* ci must be 0 */
- if(bitoff != 6) {
-
- ((__u8*)strm)[co]= bitten;
- co++;
-
- }
- goto BAUCHWEH;
-
-HERZWEH:
-/* ci cannot be 0 */
-/* correct bitoff to nibble boundaries */
-
- switch(bitoff){
- case 4:
- case 6:
- bitoff = 0;
- break;
- case 2:
- case 0:
- ((__u8*)strm)[co]= bitten;
- bitoff = 4;
- co++;
- bitten = 0; // clear half nibble values in bitten
- break;
- default:
- break;
- }
-
- for(; ci>0; ci--) {
-
- ZZvalue = data[RTjpeg_ZZ[ci]];
-
- if( (ZZvalue > 7) || (ZZvalue < -7) ) {
- bitten |= (0x08<<bitoff);
- goto HIRNWEH;
- }
-
- bitten |= (ZZvalue&0xf)<<bitoff;
-
- if( bitoff == 0 ) {
- ((__u8*)strm)[co]= bitten;
- bitten = 0;
- bitoff = 8;
- co++;
- } /* "fall thru" */
- bitoff-=4;
- }
-
- /* ci must be 0 */
- if( bitoff == 0 ) {
- ((__u8*)strm)[co]= bitten;
- co++;
- }
- goto BAUCHWEH;
-
-HIRNWEH:
-
- ((__u8*)strm)[co]= bitten;
- co++;
-
-
- /* bitting is over now we bite */
- for(; ci>0; ci--) {
-
- ZZvalue = data[RTjpeg_ZZ[ci]];
-
- if(ZZvalue>0)
- {
- strm[co++]=(__s8)(ZZvalue>127)?127:ZZvalue;
- }
- else
- {
- strm[co++]=(__s8)(ZZvalue<-128)?-128:ZZvalue;
- }
-
- }
-
-
-BAUCHWEH:
- /* we gotoo much now we are ill */
-#ifdef SHOWBLOCK
-{
-int i;
-fprintf(stdout, "\nco = '%d'\n", co);
- for (i=0; i < co+2; i++) {
- fprintf(stdout, "%d ", strm[i]);
- }
-fprintf(stdout, "\n\n");
-}
-#endif
-
- return (int)co;
-}
-
-#else
-
-static int RTjpeg_b2s(__s16 *data, __s8 *strm, __u8 bt8)
-{
- register int ci, co=1, tmp;
- register __s16 ZZvalue;
-
-#ifdef SHOWBLOCK
-
- int ii;
- for (ii=0; ii < 64; ii++) {
- fprintf(stdout, "%d ", data[RTjpeg_ZZ[ii]]);
- }
- fprintf(stdout, "\n\n");
-
-#endif
-
- (__u8)strm[0]=(__u8)(data[RTjpeg_ZZ[0]]>254) ? 254:((data[RTjpeg_ZZ[0]]<0)?0:data[RTjpeg_ZZ[0]]);
-
- for(ci=1; ci<=bt8; ci++)
- {
- ZZvalue = data[RTjpeg_ZZ[ci]];
-
- if(ZZvalue>0)
- {
- strm[co++]=(__s8)(ZZvalue>127)?127:ZZvalue;
- }
- else
- {
- strm[co++]=(__s8)(ZZvalue<-128)?-128:ZZvalue;
- }
- }
-
- for(; ci<64; ci++)
- {
- ZZvalue = data[RTjpeg_ZZ[ci]];
-
- if(ZZvalue>0)
- {
- strm[co++]=(__s8)(ZZvalue>63)?63:ZZvalue;
- }
- else if(ZZvalue<0)
- {
- strm[co++]=(__s8)(ZZvalue<-64)?-64:ZZvalue;
- }
- else /* compress zeros */
- {
- tmp=ci;
- do
- {
- ci++;
- }
- while((ci<64)&&(data[RTjpeg_ZZ[ci]]==0));
-
- strm[co++]=(__s8)(63+(ci-tmp));
- ci--;
- }
- }
- return (int)co;
-}
-
-static int RTjpeg_s2b(__s16 *data, __s8 *strm, __u8 bt8, __u32 *qtbl)
-{
- int ci=1, co=1, tmp;
- register int i;
-
- i=RTjpeg_ZZ[0];
- data[i]=((__u8)strm[0])*qtbl[i];
-
- for(co=1; co<=bt8; co++)
- {
- i=RTjpeg_ZZ[co];
- data[i]=strm[ci++]*qtbl[i];
- }
-
- for(; co<64; co++)
- {
- if(strm[ci]>63)
- {
- tmp=co+strm[ci]-63;
- for(; co<tmp; co++)data[RTjpeg_ZZ[co]]=0;
- co--;
- } else
- {
- i=RTjpeg_ZZ[co];
- data[i]=strm[ci]*qtbl[i];
- }
- ci++;
- }
- return (int)ci;
-}
-#endif
-
-#if HAVE_MMX
-static void RTjpeg_quant_init(void)
-{
- int i;
- __s16 *qtbl;
-
- qtbl=(__s16 *)RTjpeg_lqt;
- for(i=0; i<64; i++)qtbl[i]=(__s16)RTjpeg_lqt[i];
-
- qtbl=(__s16 *)RTjpeg_cqt;
- for(i=0; i<64; i++)qtbl[i]=(__s16)RTjpeg_cqt[i];
-}
-
-static mmx_t RTjpeg_ones={0x0001000100010001LL};
-static mmx_t RTjpeg_half={0x7fff7fff7fff7fffLL};
-
-static void RTjpeg_quant(__s16 *block, __s32 *qtbl)
-{
- int i;
- mmx_t *bl, *ql;
-
- ql=(mmx_t *)qtbl;
- bl=(mmx_t *)block;
-
- movq_m2r(RTjpeg_ones, mm6);
- movq_m2r(RTjpeg_half, mm7);
-
- for(i=16; i; i--)
- {
- movq_m2r(*(ql++), mm0); /* quant vals (4) */
- movq_m2r(*bl, mm2); /* block vals (4) */
- movq_r2r(mm0, mm1);
- movq_r2r(mm2, mm3);
-
- punpcklwd_r2r(mm6, mm0); /* 1 qb 1 qa */
- punpckhwd_r2r(mm6, mm1); /* 1 qd 1 qc */
-
- punpcklwd_r2r(mm7, mm2); /* 32767 bb 32767 ba */
- punpckhwd_r2r(mm7, mm3); /* 32767 bd 32767 bc */
-
- pmaddwd_r2r(mm2, mm0); /* 32767+bb*qb 32767+ba*qa */
- pmaddwd_r2r(mm3, mm1); /* 32767+bd*qd 32767+bc*qc */
-
- psrad_i2r(16, mm0);
- psrad_i2r(16, mm1);
-
- packssdw_r2r(mm1, mm0);
-
- movq_r2m(mm0, *(bl++));
-
- }
-}
-#else
-static void RTjpeg_quant_init(void)
-{
-}
-
-static void RTjpeg_quant(__s16 *block, __s32 *qtbl)
-{
- int i;
-
- for(i=0; i<64; i++)
- block[i]=(__s16)((block[i]*qtbl[i]+32767)>>16);
-}
-#endif
-
-/*
- * Perform the forward DCT on one block of samples.
- */
-#if HAVE_MMX
-static mmx_t RTjpeg_C4 ={0x2D412D412D412D41LL};
-static mmx_t RTjpeg_C6 ={0x187E187E187E187ELL};
-static mmx_t RTjpeg_C2mC6={0x22A322A322A322A3LL};
-static mmx_t RTjpeg_C2pC6={0x539F539F539F539FLL};
-static mmx_t RTjpeg_zero ={0x0000000000000000LL};
-
-#else
-
-#define FIX_0_382683433 ((__s32) 98) /* FIX(0.382683433) */
-#define FIX_0_541196100 ((__s32) 139) /* FIX(0.541196100) */
-#define FIX_0_707106781 ((__s32) 181) /* FIX(0.707106781) */
-#define FIX_1_306562965 ((__s32) 334) /* FIX(1.306562965) */
-
-#define DESCALE10(x) (__s16)( ((x)+128) >> 8)
-#define DESCALE20(x) (__s16)(((x)+32768) >> 16)
-#define D_MULTIPLY(var,const) ((__s32) ((var) * (const)))
-#endif
-
-static void RTjpeg_dct_init(void)
-{
- int i;
-
- for(i=0; i<64; i++)
- {
- RTjpeg_lqt[i]=(((__u64)RTjpeg_lqt[i]<<32)/RTjpeg_aan_tab[i]);
- RTjpeg_cqt[i]=(((__u64)RTjpeg_cqt[i]<<32)/RTjpeg_aan_tab[i]);
- }
-}
-
-static void RTjpeg_dctY(__u8 *idata, __s16 *odata, int rskip)
-{
-#if !HAVE_MMX
- __s32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- __s32 tmp10, tmp11, tmp12, tmp13;
- __s32 z1, z2, z3, z4, z5, z11, z13;
- __u8 *idataptr;
- __s16 *odataptr;
- __s32 *wsptr;
- int ctr;
-
- idataptr = idata;
- wsptr = RTjpeg_ws;
- for (ctr = 7; ctr >= 0; ctr--) {
- tmp0 = idataptr[0] + idataptr[7];
- tmp7 = idataptr[0] - idataptr[7];
- tmp1 = idataptr[1] + idataptr[6];
- tmp6 = idataptr[1] - idataptr[6];
- tmp2 = idataptr[2] + idataptr[5];
- tmp5 = idataptr[2] - idataptr[5];
- tmp3 = idataptr[3] + idataptr[4];
- tmp4 = idataptr[3] - idataptr[4];
-
- tmp10 = (tmp0 + tmp3); /* phase 2 */
- tmp13 = tmp0 - tmp3;
- tmp11 = (tmp1 + tmp2);
- tmp12 = tmp1 - tmp2;
-
- wsptr[0] = (tmp10 + tmp11)<<8; /* phase 3 */
- wsptr[4] = (tmp10 - tmp11)<<8;
-
- z1 = D_MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
- wsptr[2] = (tmp13<<8) + z1; /* phase 5 */
- wsptr[6] = (tmp13<<8) - z1;
-
- tmp10 = tmp4 + tmp5; /* phase 2 */
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
-
- z5 = D_MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
- z2 = D_MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
- z4 = D_MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
- z3 = D_MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
-
- z11 = (tmp7<<8) + z3; /* phase 5 */
- z13 = (tmp7<<8) - z3;
-
- wsptr[5] = z13 + z2; /* phase 6 */
- wsptr[3] = z13 - z2;
- wsptr[1] = z11 + z4;
- wsptr[7] = z11 - z4;
-
- idataptr += rskip<<3; /* advance pointer to next row */
- wsptr += 8;
- }
-
- wsptr = RTjpeg_ws;
- odataptr=odata;
- for (ctr = 7; ctr >= 0; ctr--) {
- tmp0 = wsptr[0] + wsptr[56];
- tmp7 = wsptr[0] - wsptr[56];
- tmp1 = wsptr[8] + wsptr[48];
- tmp6 = wsptr[8] - wsptr[48];
- tmp2 = wsptr[16] + wsptr[40];
- tmp5 = wsptr[16] - wsptr[40];
- tmp3 = wsptr[24] + wsptr[32];
- tmp4 = wsptr[24] - wsptr[32];
-
- tmp10 = tmp0 + tmp3; /* phase 2 */
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- odataptr[0] = DESCALE10(tmp10 + tmp11); /* phase 3 */
- odataptr[32] = DESCALE10(tmp10 - tmp11);
-
- z1 = D_MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
- odataptr[16] = DESCALE20((tmp13<<8) + z1); /* phase 5 */
- odataptr[48] = DESCALE20((tmp13<<8) - z1);
-
- tmp10 = tmp4 + tmp5; /* phase 2 */
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
-
- z5 = D_MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
- z2 = D_MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
- z4 = D_MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
- z3 = D_MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
-
- z11 = (tmp7<<8) + z3; /* phase 5 */
- z13 = (tmp7<<8) - z3;
-
- odataptr[40] = DESCALE20(z13 + z2); /* phase 6 */
- odataptr[24] = DESCALE20(z13 - z2);
- odataptr[8] = DESCALE20(z11 + z4);
- odataptr[56] = DESCALE20(z11 - z4);
-
- odataptr++; /* advance pointer to next column */
- wsptr++;
- }
-#else
- volatile mmx_t tmp6, tmp7;
- register mmx_t *dataptr = (mmx_t *)odata;
- mmx_t *idata2 = (mmx_t *)idata;
-
- // first copy the input 8 bit to the destination 16 bits
-
- movq_m2r(RTjpeg_zero, mm2);
-
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+1));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+2));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+3));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+4));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+5));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+6));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+7));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+8));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+9));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+10));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+11));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+12));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+13));
-
- idata2 += rskip;
-
- movq_m2r(*idata2, mm0);
- movq_r2r(mm0, mm1);
-
- punpcklbw_r2r(mm2, mm0);
- movq_r2m(mm0, *(dataptr+14));
-
- punpckhbw_r2r(mm2, mm1);
- movq_r2m(mm1, *(dataptr+15));
-
-/* Start Transpose to do calculations on rows */
-
- movq_m2r(*(dataptr+9), mm7); // m03:m02|m01:m00 - first line (line 4)and copy into m5
-
- movq_m2r(*(dataptr+13), mm6); // m23:m22|m21:m20 - third line (line 6)and copy into m2
- movq_r2r(mm7, mm5);
-
- punpcklwd_m2r(*(dataptr+11), mm7); // m11:m01|m10:m00 - interleave first and second lines
- movq_r2r(mm6, mm2);
-
- punpcklwd_m2r(*(dataptr+15), mm6); // m31:m21|m30:m20 - interleave third and fourth lines
- movq_r2r(mm7, mm1);
-
- movq_m2r(*(dataptr+11), mm3); // m13:m13|m11:m10 - second line
- punpckldq_r2r(mm6, mm7); // m30:m20|m10:m00 - interleave to produce result 1
-
- movq_m2r(*(dataptr+15), mm0); // m13:m13|m11:m10 - fourth line
- punpckhdq_r2r(mm6, mm1); // m31:m21|m11:m01 - interleave to produce result 2
-
- movq_r2m(mm7,*(dataptr+9)); // write result 1
- punpckhwd_r2r(mm3, mm5); // m13:m03|m12:m02 - interleave first and second lines
-
- movq_r2m(mm1,*(dataptr+11)); // write result 2
- punpckhwd_r2r(mm0, mm2); // m33:m23|m32:m22 - interleave third and fourth lines
-
- movq_r2r(mm5, mm1);
- punpckldq_r2r(mm2, mm5); // m32:m22|m12:m02 - interleave to produce result 3
-
- movq_m2r(*(dataptr+1), mm0); // m03:m02|m01:m00 - first line, 4x4
- punpckhdq_r2r(mm2, mm1); // m33:m23|m13:m03 - interleave to produce result 4
-
- movq_r2m(mm5,*(dataptr+13)); // write result 3
-
- // last 4x4 done
-
- movq_r2m(mm1, *(dataptr+15)); // write result 4, last 4x4
-
- movq_m2r(*(dataptr+5), mm2); // m23:m22|m21:m20 - third line
- movq_r2r(mm0, mm6);
-
- punpcklwd_m2r(*(dataptr+3), mm0); // m11:m01|m10:m00 - interleave first and second lines
- movq_r2r(mm2, mm7);
-
- punpcklwd_m2r(*(dataptr+7), mm2); // m31:m21|m30:m20 - interleave third and fourth lines
- movq_r2r(mm0, mm4);
-
- //
- movq_m2r(*(dataptr+8), mm1); // n03:n02|n01:n00 - first line
- punpckldq_r2r(mm2, mm0); // m30:m20|m10:m00 - interleave to produce first result
-
- movq_m2r(*(dataptr+12), mm3); // n23:n22|n21:n20 - third line
- punpckhdq_r2r(mm2, mm4); // m31:m21|m11:m01 - interleave to produce second result
-
- punpckhwd_m2r(*(dataptr+3), mm6); // m13:m03|m12:m02 - interleave first and second lines
- movq_r2r(mm1, mm2); // copy first line
-
- punpckhwd_m2r(*(dataptr+7), mm7); // m33:m23|m32:m22 - interleave third and fourth lines
- movq_r2r(mm6, mm5); // copy first intermediate result
-
- movq_r2m(mm0, *(dataptr+8)); // write result 1
- punpckhdq_r2r(mm7, mm5); // m33:m23|m13:m03 - produce third result
-
- punpcklwd_m2r(*(dataptr+10), mm1); // n11:n01|n10:n00 - interleave first and second lines
- movq_r2r(mm3, mm0); // copy third line
-
- punpckhwd_m2r(*(dataptr+10), mm2); // n13:n03|n12:n02 - interleave first and second lines
-
- movq_r2m(mm4, *(dataptr+10)); // write result 2 out
- punpckldq_r2r(mm7, mm6); // m32:m22|m12:m02 - produce fourth result
-
- punpcklwd_m2r(*(dataptr+14), mm3); // n31:n21|n30:n20 - interleave third and fourth lines
- movq_r2r(mm1, mm4);
-
- movq_r2m(mm6, *(dataptr+12)); // write result 3 out
- punpckldq_r2r(mm3, mm1); // n30:n20|n10:n00 - produce first result
-
- punpckhwd_m2r(*(dataptr+14), mm0); // n33:n23|n32:n22 - interleave third and fourth lines
- movq_r2r(mm2, mm6);
-
- movq_r2m(mm5, *(dataptr+14)); // write result 4 out
- punpckhdq_r2r(mm3, mm4); // n31:n21|n11:n01- produce second result
-
- movq_r2m(mm1, *(dataptr+1)); // write result 5 out - (first result for other 4 x 4 block)
- punpckldq_r2r(mm0, mm2); // n32:n22|n12:n02- produce third result
-
- movq_r2m(mm4, *(dataptr+3)); // write result 6 out
- punpckhdq_r2r(mm0, mm6); // n33:n23|n13:n03 - produce fourth result
-
- movq_r2m(mm2, *(dataptr+5)); // write result 7 out
-
- movq_m2r(*dataptr, mm0); // m03:m02|m01:m00 - first line, first 4x4
-
- movq_r2m(mm6, *(dataptr+7)); // write result 8 out
-
-
-// Do first 4x4 quadrant, which is used in the beginning of the DCT:
-
- movq_m2r(*(dataptr+4), mm7); // m23:m22|m21:m20 - third line
- movq_r2r(mm0, mm2);
-
- punpcklwd_m2r(*(dataptr+2), mm0); // m11:m01|m10:m00 - interleave first and second lines
- movq_r2r(mm7, mm4);
-
- punpcklwd_m2r(*(dataptr+6), mm7); // m31:m21|m30:m20 - interleave third and fourth lines
- movq_r2r(mm0, mm1);
-
- movq_m2r(*(dataptr+2), mm6); // m13:m12|m11:m10 - second line
- punpckldq_r2r(mm7, mm0); // m30:m20|m10:m00 - interleave to produce result 1
-
- movq_m2r(*(dataptr+6), mm5); // m33:m32|m31:m30 - fourth line
- punpckhdq_r2r(mm7, mm1); // m31:m21|m11:m01 - interleave to produce result 2
-
- movq_r2r(mm0, mm7); // write result 1
- punpckhwd_r2r(mm6, mm2); // m13:m03|m12:m02 - interleave first and second lines
-
- psubw_m2r(*(dataptr+14), mm7); // tmp07=x0-x7 /* Stage 1 */
- movq_r2r(mm1, mm6); // write result 2
-
- paddw_m2r(*(dataptr+14), mm0); // tmp00=x0+x7 /* Stage 1 */
- punpckhwd_r2r(mm5, mm4); // m33:m23|m32:m22 - interleave third and fourth lines
-
- paddw_m2r(*(dataptr+12), mm1); // tmp01=x1+x6 /* Stage 1 */
- movq_r2r(mm2, mm3); // copy first intermediate result
-
- psubw_m2r(*(dataptr+12), mm6); // tmp06=x1-x6 /* Stage 1 */
- punpckldq_r2r(mm4, mm2); // m32:m22|m12:m02 - interleave to produce result 3
-
- movq_r2m(mm7, tmp7);
- movq_r2r(mm2, mm5); // write result 3
-
- movq_r2m(mm6, tmp6);
- punpckhdq_r2r(mm4, mm3); // m33:m23|m13:m03 - interleave to produce result 4
-
- paddw_m2r(*(dataptr+10), mm2); // tmp02=x2+5 /* Stage 1 */
- movq_r2r(mm3, mm4); // write result 4
-
-/************************************************************************************************
- End of Transpose
-************************************************************************************************/
-
-
- paddw_m2r(*(dataptr+8), mm3); // tmp03=x3+x4 /* stage 1*/
- movq_r2r(mm0, mm7);
-
- psubw_m2r(*(dataptr+8), mm4); // tmp04=x3-x4 /* stage 1*/
- movq_r2r(mm1, mm6);
-
- paddw_r2r(mm3, mm0); // tmp10 = tmp00 + tmp03 /* even 2 */
- psubw_r2r(mm3, mm7); // tmp13 = tmp00 - tmp03 /* even 2 */
-
- psubw_r2r(mm2, mm6); // tmp12 = tmp01 - tmp02 /* even 2 */
- paddw_r2r(mm2, mm1); // tmp11 = tmp01 + tmp02 /* even 2 */
-
- psubw_m2r(*(dataptr+10), mm5); // tmp05=x2-x5 /* stage 1*/
- paddw_r2r(mm7, mm6); // tmp12 + tmp13
-
- /* stage 3 */
-
- movq_m2r(tmp6, mm2);
- movq_r2r(mm0, mm3);
-
- psllw_i2r(2, mm6); // m8 * 2^2
- paddw_r2r(mm1, mm0);
-
- pmulhw_m2r(RTjpeg_C4, mm6); // z1
- psubw_r2r(mm1, mm3);
-
- movq_r2m(mm0, *dataptr);
- movq_r2r(mm7, mm0);
-
- /* Odd part */
- movq_r2m(mm3, *(dataptr+8));
- paddw_r2r(mm5, mm4); // tmp10
-
- movq_m2r(tmp7, mm3);
- paddw_r2r(mm6, mm0); // tmp32
-
- paddw_r2r(mm2, mm5); // tmp11
- psubw_r2r(mm6, mm7); // tmp33
-
- movq_r2m(mm0, *(dataptr+4));
- paddw_r2r(mm3, mm2); // tmp12
-
- /* stage 4 */
-
- movq_r2m(mm7, *(dataptr+12));
- movq_r2r(mm4, mm1); // copy of tmp10
-
- psubw_r2r(mm2, mm1); // tmp10 - tmp12
- psllw_i2r(2, mm4); // m8 * 2^2
-
- movq_m2r(RTjpeg_C2mC6, mm0);
- psllw_i2r(2, mm1);
-
- pmulhw_m2r(RTjpeg_C6, mm1); // z5
- psllw_i2r(2, mm2);
-
- pmulhw_r2r(mm0, mm4); // z5
-
- /* stage 5 */
-
- pmulhw_m2r(RTjpeg_C2pC6, mm2);
- psllw_i2r(2, mm5);
-
- pmulhw_m2r(RTjpeg_C4, mm5); // z3
- movq_r2r(mm3, mm0); // copy tmp7
-
- movq_m2r(*(dataptr+1), mm7);
- paddw_r2r(mm1, mm4); // z2
-
- paddw_r2r(mm1, mm2); // z4
-
- paddw_r2r(mm5, mm0); // z11
- psubw_r2r(mm5, mm3); // z13
-
- /* stage 6 */
-
- movq_r2r(mm3, mm5); // copy z13
- psubw_r2r(mm4, mm3); // y3=z13 - z2
-
- paddw_r2r(mm4, mm5); // y5=z13 + z2
- movq_r2r(mm0, mm6); // copy z11
-
- movq_r2m(mm3, *(dataptr+6)); //save y3
- psubw_r2r(mm2, mm0); // y7=z11 - z4
-
- movq_r2m(mm5, *(dataptr+10)); //save y5
- paddw_r2r(mm2, mm6); // y1=z11 + z4
-
- movq_r2m(mm0, *(dataptr+14)); //save y7
-
- /************************************************
- * End of 1st 4 rows
- ************************************************/
-
- movq_m2r(*(dataptr+3), mm1); // load x1 /* stage 1 */
- movq_r2r(mm7, mm0); // copy x0
-
- movq_r2m(mm6, *(dataptr+2)); //save y1
-
- movq_m2r(*(dataptr+5), mm2); // load x2 /* stage 1 */
- movq_r2r(mm1, mm6); // copy x1
-
- paddw_m2r(*(dataptr+15), mm0); // tmp00 = x0 + x7
-
- movq_m2r(*(dataptr+7), mm3); // load x3 /* stage 1 */
- movq_r2r(mm2, mm5); // copy x2
-
- psubw_m2r(*(dataptr+15), mm7); // tmp07 = x0 - x7
- movq_r2r(mm3, mm4); // copy x3
-
- paddw_m2r(*(dataptr+13), mm1); // tmp01 = x1 + x6
-
- movq_r2m(mm7, tmp7); // save tmp07
- movq_r2r(mm0, mm7); // copy tmp00
-
- psubw_m2r(*(dataptr+13), mm6); // tmp06 = x1 - x6
-
- /* stage 2, Even Part */
-
- paddw_m2r(*(dataptr+9), mm3); // tmp03 = x3 + x4
-
- movq_r2m(mm6, tmp6); // save tmp07
- movq_r2r(mm1, mm6); // copy tmp01
-
- paddw_m2r(*(dataptr+11), mm2); // tmp02 = x2 + x5
- paddw_r2r(mm3, mm0); // tmp10 = tmp00 + tmp03
-
- psubw_r2r(mm3, mm7); // tmp13 = tmp00 - tmp03
-
- psubw_m2r(*(dataptr+9), mm4); // tmp04 = x3 - x4
- psubw_r2r(mm2, mm6); // tmp12 = tmp01 - tmp02
-
- paddw_r2r(mm2, mm1); // tmp11 = tmp01 + tmp02
-
- psubw_m2r(*(dataptr+11), mm5); // tmp05 = x2 - x5
- paddw_r2r(mm7, mm6); // tmp12 + tmp13
-
- /* stage 3, Even and stage 4 & 5 even */
-
- movq_m2r(tmp6, mm2); // load tmp6
- movq_r2r(mm0, mm3); // copy tmp10
-
- psllw_i2r(2, mm6); // shift z1
- paddw_r2r(mm1, mm0); // y0=tmp10 + tmp11
-
- pmulhw_m2r(RTjpeg_C4, mm6); // z1
- psubw_r2r(mm1, mm3); // y4=tmp10 - tmp11
-
- movq_r2m(mm0, *(dataptr+1)); //save y0
- movq_r2r(mm7, mm0); // copy tmp13
-
- /* odd part */
-
- movq_r2m(mm3, *(dataptr+9)); //save y4
- paddw_r2r(mm5, mm4); // tmp10 = tmp4 + tmp5
-
- movq_m2r(tmp7, mm3); // load tmp7
- paddw_r2r(mm6, mm0); // tmp32 = tmp13 + z1
-
- paddw_r2r(mm2, mm5); // tmp11 = tmp5 + tmp6
- psubw_r2r(mm6, mm7); // tmp33 = tmp13 - z1
-
- movq_r2m(mm0, *(dataptr+5)); //save y2
- paddw_r2r(mm3, mm2); // tmp12 = tmp6 + tmp7
-
- /* stage 4 */
-
- movq_r2m(mm7, *(dataptr+13)); //save y6
- movq_r2r(mm4, mm1); // copy tmp10
-
- psubw_r2r(mm2, mm1); // tmp10 - tmp12
- psllw_i2r(2, mm4); // shift tmp10
-
- movq_m2r(RTjpeg_C2mC6, mm0); // load C2mC6
- psllw_i2r(2, mm1); // shift (tmp10-tmp12)
-
- pmulhw_m2r(RTjpeg_C6, mm1); // z5
- psllw_i2r(2, mm5); // prepare for multiply
-
- pmulhw_r2r(mm0, mm4); // multiply by converted real
-
- /* stage 5 */
-
- pmulhw_m2r(RTjpeg_C4, mm5); // z3
- psllw_i2r(2, mm2); // prepare for multiply
-
- pmulhw_m2r(RTjpeg_C2pC6, mm2); // multiply
- movq_r2r(mm3, mm0); // copy tmp7
-
- movq_m2r(*(dataptr+9), mm7); // m03:m02|m01:m00 - first line (line 4)and copy into mm7
- paddw_r2r(mm1, mm4); // z2
-
- paddw_r2r(mm5, mm0); // z11
- psubw_r2r(mm5, mm3); // z13
-
- /* stage 6 */
-
- movq_r2r(mm3, mm5); // copy z13
- paddw_r2r(mm1, mm2); // z4
-
- movq_r2r(mm0, mm6); // copy z11
- psubw_r2r(mm4, mm5); // y3
-
- paddw_r2r(mm2, mm6); // y1
- paddw_r2r(mm4, mm3); // y5
-
- movq_r2m(mm5, *(dataptr+7)); //save y3
-
- movq_r2m(mm6, *(dataptr+3)); //save y1
- psubw_r2r(mm2, mm0); // y7
-
-/************************************************************************************************
- Start of Transpose
-************************************************************************************************/
-
- movq_m2r(*(dataptr+13), mm6); // m23:m22|m21:m20 - third line (line 6)and copy into m2
- movq_r2r(mm7, mm5); // copy first line
-
- punpcklwd_r2r(mm3, mm7); // m11:m01|m10:m00 - interleave first and second lines
- movq_r2r(mm6, mm2); // copy third line
-
- punpcklwd_r2r(mm0, mm6); // m31:m21|m30:m20 - interleave third and fourth lines
- movq_r2r(mm7, mm1); // copy first intermediate result
-
- punpckldq_r2r(mm6, mm7); // m30:m20|m10:m00 - interleave to produce result 1
-
- punpckhdq_r2r(mm6, mm1); // m31:m21|m11:m01 - interleave to produce result 2
-
- movq_r2m(mm7, *(dataptr+9)); // write result 1
- punpckhwd_r2r(mm3, mm5); // m13:m03|m12:m02 - interleave first and second lines
-
- movq_r2m(mm1, *(dataptr+11)); // write result 2
- punpckhwd_r2r(mm0, mm2); // m33:m23|m32:m22 - interleave third and fourth lines
-
- movq_r2r(mm5, mm1); // copy first intermediate result
- punpckldq_r2r(mm2, mm5); // m32:m22|m12:m02 - interleave to produce result 3
-
- movq_m2r(*(dataptr+1), mm0); // m03:m02|m01:m00 - first line, 4x4
- punpckhdq_r2r(mm2, mm1); // m33:m23|m13:m03 - interleave to produce result 4
-
- movq_r2m(mm5, *(dataptr+13)); // write result 3
-
- /****** last 4x4 done */
-
- movq_r2m(mm1, *(dataptr+15)); // write result 4, last 4x4
-
- movq_m2r(*(dataptr+5), mm2); // m23:m22|m21:m20 - third line
- movq_r2r(mm0, mm6); // copy first line
-
- punpcklwd_m2r(*(dataptr+3), mm0); // m11:m01|m10:m00 - interleave first and second lines
- movq_r2r(mm2, mm7); // copy third line
-
- punpcklwd_m2r(*(dataptr+7), mm2); // m31:m21|m30:m20 - interleave third and fourth lines
- movq_r2r(mm0, mm4); // copy first intermediate result
-
-
-
- movq_m2r(*(dataptr+8), mm1); // n03:n02|n01:n00 - first line
- punpckldq_r2r(mm2, mm0); // m30:m20|m10:m00 - interleave to produce first result
-
- movq_m2r(*(dataptr+12), mm3); // n23:n22|n21:n20 - third line
- punpckhdq_r2r(mm2, mm4); // m31:m21|m11:m01 - interleave to produce second result
-
- punpckhwd_m2r(*(dataptr+3), mm6); // m13:m03|m12:m02 - interleave first and second lines
- movq_r2r(mm1, mm2); // copy first line
-
- punpckhwd_m2r(*(dataptr+7), mm7); // m33:m23|m32:m22 - interleave third and fourth lines
- movq_r2r(mm6, mm5); // copy first intermediate result
-
- movq_r2m(mm0, *(dataptr+8)); // write result 1
- punpckhdq_r2r(mm7, mm5); // m33:m23|m13:m03 - produce third result
-
- punpcklwd_m2r(*(dataptr+10), mm1); // n11:n01|n10:n00 - interleave first and second lines
- movq_r2r(mm3, mm0); // copy third line
-
- punpckhwd_m2r(*(dataptr+10), mm2); // n13:n03|n12:n02 - interleave first and second lines
-
- movq_r2m(mm4, *(dataptr+10)); // write result 2 out
- punpckldq_r2r(mm7, mm6); // m32:m22|m12:m02 - produce fourth result
-
- punpcklwd_m2r(*(dataptr+14), mm3); // n33:n23|n32:n22 - interleave third and fourth lines
- movq_r2r(mm1, mm4); // copy second intermediate result
-
- movq_r2m(mm6, *(dataptr+12)); // write result 3 out
- punpckldq_r2r(mm3, mm1); //
-
- punpckhwd_m2r(*(dataptr+14), mm0); // n33:n23|n32:n22 - interleave third and fourth lines
- movq_r2r(mm2, mm6); // copy second intermediate result
-
- movq_r2m(mm5, *(dataptr+14)); // write result 4 out
- punpckhdq_r2r(mm3, mm4); // n31:n21|n11:n01- produce second result
-
- movq_r2m(mm1, *(dataptr+1)); // write result 5 out - (first result for other 4 x 4 block)
- punpckldq_r2r(mm0, mm2); // n32:n22|n12:n02- produce third result
-
- movq_r2m(mm4, *(dataptr+3)); // write result 6 out
- punpckhdq_r2r(mm0, mm6); // n33:n23|n13:n03 - produce fourth result
-
- movq_r2m(mm2, *(dataptr+5)); // write result 7 out
-
- movq_m2r(*dataptr, mm0); // m03:m02|m01:m00 - first line, first 4x4
-
- movq_r2m(mm6, *(dataptr+7)); // write result 8 out
-
-// Do first 4x4 quadrant, which is used in the beginning of the DCT:
-
- movq_m2r(*(dataptr+4), mm7); // m23:m22|m21:m20 - third line
- movq_r2r(mm0, mm2); // copy first line
-
- punpcklwd_m2r(*(dataptr+2), mm0); // m11:m01|m10:m00 - interleave first and second lines
- movq_r2r(mm7, mm4); // copy third line
-
- punpcklwd_m2r(*(dataptr+6), mm7); // m31:m21|m30:m20 - interleave third and fourth lines
- movq_r2r(mm0, mm1); // copy first intermediate result
-
- movq_m2r(*(dataptr+2), mm6); // m13:m12|m11:m10 - second line
- punpckldq_r2r(mm7, mm0); // m30:m20|m10:m00 - interleave to produce result 1
-
- movq_m2r(*(dataptr+6), mm5); // m33:m32|m31:m30 - fourth line
- punpckhdq_r2r(mm7, mm1); // m31:m21|m11:m01 - interleave to produce result 2
-
- movq_r2r(mm0, mm7); // write result 1
- punpckhwd_r2r(mm6, mm2); // m13:m03|m12:m02 - interleave first and second lines
-
- psubw_m2r(*(dataptr+14), mm7); // tmp07=x0-x7 /* Stage 1 */
- movq_r2r(mm1, mm6); // write result 2
-
- paddw_m2r(*(dataptr+14), mm0); // tmp00=x0+x7 /* Stage 1 */
- punpckhwd_r2r(mm5, mm4); // m33:m23|m32:m22 - interleave third and fourth lines
-
- paddw_m2r(*(dataptr+12), mm1); // tmp01=x1+x6 /* Stage 1 */
- movq_r2r(mm2, mm3); // copy first intermediate result
-
- psubw_m2r(*(dataptr+12), mm6); // tmp06=x1-x6 /* Stage 1 */
- punpckldq_r2r(mm4, mm2); // m32:m22|m12:m02 - interleave to produce result 3
-
- movq_r2m(mm7, tmp7); // save tmp07
- movq_r2r(mm2, mm5); // write result 3
-
- movq_r2m(mm6, tmp6); // save tmp06
-
- punpckhdq_r2r(mm4, mm3); // m33:m23|m13:m03 - interleave to produce result 4
-
- paddw_m2r(*(dataptr+10), mm2); // tmp02=x2+x5 /* stage 1 */
- movq_r2r(mm3, mm4); // write result 4
-
-/************************************************************************************************
- End of Transpose 2
-************************************************************************************************/
-
- paddw_m2r(*(dataptr+8), mm3); // tmp03=x3+x4 /* stage 1*/
- movq_r2r(mm0, mm7);
-
- psubw_m2r(*(dataptr+8), mm4); // tmp04=x3-x4 /* stage 1*/
- movq_r2r(mm1, mm6);
-
- paddw_r2r(mm3, mm0); // tmp10 = tmp00 + tmp03 /* even 2 */
- psubw_r2r(mm3, mm7); // tmp13 = tmp00 - tmp03 /* even 2 */
-
- psubw_r2r(mm2, mm6); // tmp12 = tmp01 - tmp02 /* even 2 */
- paddw_r2r(mm2, mm1); // tmp11 = tmp01 + tmp02 /* even 2 */
-
- psubw_m2r(*(dataptr+10), mm5); // tmp05=x2-x5 /* stage 1*/
- paddw_r2r(mm7, mm6); // tmp12 + tmp13
-
- /* stage 3 */
-
- movq_m2r(tmp6, mm2);
- movq_r2r(mm0, mm3);
-
- psllw_i2r(2, mm6); // m8 * 2^2
- paddw_r2r(mm1, mm0);
-
- pmulhw_m2r(RTjpeg_C4, mm6); // z1
- psubw_r2r(mm1, mm3);
-
- movq_r2m(mm0, *dataptr);
- movq_r2r(mm7, mm0);
-
- /* Odd part */
- movq_r2m(mm3, *(dataptr+8));
- paddw_r2r(mm5, mm4); // tmp10
-
- movq_m2r(tmp7, mm3);
- paddw_r2r(mm6, mm0); // tmp32
-
- paddw_r2r(mm2, mm5); // tmp11
- psubw_r2r(mm6, mm7); // tmp33
-
- movq_r2m(mm0, *(dataptr+4));
- paddw_r2r(mm3, mm2); // tmp12
-
- /* stage 4 */
- movq_r2m(mm7, *(dataptr+12));
- movq_r2r(mm4, mm1); // copy of tmp10
-
- psubw_r2r(mm2, mm1); // tmp10 - tmp12
- psllw_i2r(2, mm4); // m8 * 2^2
-
- movq_m2r(RTjpeg_C2mC6, mm0);
- psllw_i2r(2, mm1);
-
- pmulhw_m2r(RTjpeg_C6, mm1); // z5
- psllw_i2r(2, mm2);
-
- pmulhw_r2r(mm0, mm4); // z5
-
- /* stage 5 */
-
- pmulhw_m2r(RTjpeg_C2pC6, mm2);
- psllw_i2r(2, mm5);
-
- pmulhw_m2r(RTjpeg_C4, mm5); // z3
- movq_r2r(mm3, mm0); // copy tmp7
-
- movq_m2r(*(dataptr+1), mm7);
- paddw_r2r(mm1, mm4); // z2
-
- paddw_r2r(mm1, mm2); // z4
-
- paddw_r2r(mm5, mm0); // z11
- psubw_r2r(mm5, mm3); // z13
-
- /* stage 6 */
-
- movq_r2r(mm3, mm5); // copy z13
- psubw_r2r(mm4, mm3); // y3=z13 - z2
-
- paddw_r2r(mm4, mm5); // y5=z13 + z2
- movq_r2r(mm0, mm6); // copy z11
-
- movq_r2m(mm3, *(dataptr+6)); //save y3
- psubw_r2r(mm2, mm0); // y7=z11 - z4
-
- movq_r2m(mm5, *(dataptr+10)); //save y5
- paddw_r2r(mm2, mm6); // y1=z11 + z4
-
- movq_r2m(mm0, *(dataptr+14)); //save y7
-
- /************************************************
- * End of 1st 4 rows
- ************************************************/
-
- movq_m2r(*(dataptr+3), mm1); // load x1 /* stage 1 */
- movq_r2r(mm7, mm0); // copy x0
-
- movq_r2m(mm6, *(dataptr+2)); //save y1
-
- movq_m2r(*(dataptr+5), mm2); // load x2 /* stage 1 */
- movq_r2r(mm1, mm6); // copy x1
-
- paddw_m2r(*(dataptr+15), mm0); // tmp00 = x0 + x7
-
- movq_m2r(*(dataptr+7), mm3); // load x3 /* stage 1 */
- movq_r2r(mm2, mm5); // copy x2
-
- psubw_m2r(*(dataptr+15), mm7); // tmp07 = x0 - x7
- movq_r2r(mm3, mm4); // copy x3
-
- paddw_m2r(*(dataptr+13), mm1); // tmp01 = x1 + x6
-
- movq_r2m(mm7, tmp7); // save tmp07
- movq_r2r(mm0, mm7); // copy tmp00
-
- psubw_m2r(*(dataptr+13), mm6); // tmp06 = x1 - x6
-
- /* stage 2, Even Part */
-
- paddw_m2r(*(dataptr+9), mm3); // tmp03 = x3 + x4
-
- movq_r2m(mm6, tmp6); // save tmp07
- movq_r2r(mm1, mm6); // copy tmp01
-
- paddw_m2r(*(dataptr+11), mm2); // tmp02 = x2 + x5
- paddw_r2r(mm3, mm0); // tmp10 = tmp00 + tmp03
-
- psubw_r2r(mm3, mm7); // tmp13 = tmp00 - tmp03
-
- psubw_m2r(*(dataptr+9), mm4); // tmp04 = x3 - x4
- psubw_r2r(mm2, mm6); // tmp12 = tmp01 - tmp02
-
- paddw_r2r(mm2, mm1); // tmp11 = tmp01 + tmp02
-
- psubw_m2r(*(dataptr+11), mm5); // tmp05 = x2 - x5
- paddw_r2r(mm7, mm6); // tmp12 + tmp13
-
- /* stage 3, Even and stage 4 & 5 even */
-
- movq_m2r(tmp6, mm2); // load tmp6
- movq_r2r(mm0, mm3); // copy tmp10
-
- psllw_i2r(2, mm6); // shift z1
- paddw_r2r(mm1, mm0); // y0=tmp10 + tmp11
-
- pmulhw_m2r(RTjpeg_C4, mm6); // z1
- psubw_r2r(mm1, mm3); // y4=tmp10 - tmp11
-
- movq_r2m(mm0, *(dataptr+1)); //save y0
- movq_r2r(mm7, mm0); // copy tmp13
-
- /* odd part */
-
- movq_r2m(mm3, *(dataptr+9)); //save y4
- paddw_r2r(mm5, mm4); // tmp10 = tmp4 + tmp5
-
- movq_m2r(tmp7, mm3); // load tmp7
- paddw_r2r(mm6, mm0); // tmp32 = tmp13 + z1
-
- paddw_r2r(mm2, mm5); // tmp11 = tmp5 + tmp6
- psubw_r2r(mm6, mm7); // tmp33 = tmp13 - z1
-
- movq_r2m(mm0, *(dataptr+5)); //save y2
- paddw_r2r(mm3, mm2); // tmp12 = tmp6 + tmp7
-
- /* stage 4 */
-
- movq_r2m(mm7, *(dataptr+13)); //save y6
- movq_r2r(mm4, mm1); // copy tmp10
-
- psubw_r2r(mm2, mm1); // tmp10 - tmp12
- psllw_i2r(2, mm4); // shift tmp10
-
- movq_m2r(RTjpeg_C2mC6, mm0); // load C2mC6
- psllw_i2r(2, mm1); // shift (tmp10-tmp12)
-
- pmulhw_m2r(RTjpeg_C6, mm1); // z5
- psllw_i2r(2, mm5); // prepare for multiply
-
- pmulhw_r2r(mm0, mm4); // multiply by converted real
-
- /* stage 5 */
-
- pmulhw_m2r(RTjpeg_C4, mm5); // z3
- psllw_i2r(2, mm2); // prepare for multiply
-
- pmulhw_m2r(RTjpeg_C2pC6, mm2); // multiply
- movq_r2r(mm3, mm0); // copy tmp7
-
- movq_m2r(*(dataptr+9), mm7); // m03:m02|m01:m00 - first line (line 4)and copy into mm7
- paddw_r2r(mm1, mm4); // z2
-
- paddw_r2r(mm5, mm0); // z11
- psubw_r2r(mm5, mm3); // z13
-
- /* stage 6 */
-
- movq_r2r(mm3, mm5); // copy z13
- paddw_r2r(mm1, mm2); // z4
-
- movq_r2r(mm0, mm6); // copy z11
- psubw_r2r(mm4, mm5); // y3
-
- paddw_r2r(mm2, mm6); // y1
- paddw_r2r(mm4, mm3); // y5
-
- movq_r2m(mm5, *(dataptr+7)); //save y3
- psubw_r2r(mm2, mm0); // yŤ=z11 - z4
-
- movq_r2m(mm3, *(dataptr+11)); //save y5
-
- movq_r2m(mm6, *(dataptr+3)); //save y1
-
- movq_r2m(mm0, *(dataptr+15)); //save y7
-
-
-#endif
-}
-
-/*
-
-Main Routines
-
-This file contains most of the initialisation and control functions
-
-(C) Justin Schoeman 1998
-
-*/
-
-/*
-
-Private function
-
-Initialise all the cache-aliged data blocks
-
-*/
-
-static void RTjpeg_init_data(void)
-{
- unsigned long dptr;
-
- dptr=(unsigned long)&(RTjpeg_alldata[0]);
- dptr+=32;
- dptr=dptr>>5;
- dptr=dptr<<5; /* cache align data */
-
- RTjpeg_block=(__s16 *)dptr;
- dptr+=sizeof(__s16)*64;
- RTjpeg_lqt=(__s32 *)dptr;
- dptr+=sizeof(__s32)*64;
- RTjpeg_cqt=(__s32 *)dptr;
- dptr+=sizeof(__s32)*64;
- RTjpeg_liqt=(__u32 *)dptr;
- dptr+=sizeof(__u32)*64;
- RTjpeg_ciqt=(__u32 *)dptr;
-}
-
-/*
-
-External Function
-
-Re-set quality factor
-
-Input: buf -> pointer to 128 ints for quant values store to pass back to
- init_decompress.
- Q -> quality factor (192=best, 32=worst)
-*/
-
-static void RTjpeg_init_Q(__u8 Q)
-{
- int i;
- __u64 qual;
-
- qual=(__u64)Q<<(32-7); /* 32 bit FP, 255=2, 0=0 */
-
- for(i=0; i<64; i++)
- {
- RTjpeg_lqt[i]=(__s32)((qual/((__u64)RTjpeg_lum_quant_tbl[i]<<16))>>3);
- if(RTjpeg_lqt[i]==0)RTjpeg_lqt[i]=1;
- RTjpeg_cqt[i]=(__s32)((qual/((__u64)RTjpeg_chrom_quant_tbl[i]<<16))>>3);
- if(RTjpeg_cqt[i]==0)RTjpeg_cqt[i]=1;
- RTjpeg_liqt[i]=(1<<16)/(RTjpeg_lqt[i]<<3);
- RTjpeg_ciqt[i]=(1<<16)/(RTjpeg_cqt[i]<<3);
- RTjpeg_lqt[i]=((1<<16)/RTjpeg_liqt[i])>>3;
- RTjpeg_cqt[i]=((1<<16)/RTjpeg_ciqt[i])>>3;
- }
-
- RTjpeg_lb8=0;
- while(RTjpeg_liqt[RTjpeg_ZZ[++RTjpeg_lb8]]<=8);
- RTjpeg_lb8--;
- RTjpeg_cb8=0;
- while(RTjpeg_ciqt[RTjpeg_ZZ[++RTjpeg_cb8]]<=8);
- RTjpeg_cb8--;
-
- RTjpeg_dct_init();
- RTjpeg_quant_init();
-}
-
-/*
-
-External Function
-
-Initialise compression.
-
-Input: buf -> pointer to 128 ints for quant values store to pass back to
- init_decompress.
- width -> width of image
- height -> height of image
- Q -> quality factor (192=best, 32=worst)
-
-*/
-
-void RTjpeg_init_compress(__u32 *buf, int width, int height, __u8 Q)
-{
- int i;
- __u64 qual;
-
- RTjpeg_init_data();
-
- RTjpeg_width=width;
- RTjpeg_height=height;
- RTjpeg_Ywidth = RTjpeg_width>>3;
- RTjpeg_Ysize=width * height;
- RTjpeg_Cwidth = RTjpeg_width>>4;
- RTjpeg_Csize= (width>>1) * height;
-
- qual=(__u64)Q<<(32-7); /* 32 bit FP, 255=2, 0=0 */
-
- for(i=0; i<64; i++)
- {
- RTjpeg_lqt[i]=(__s32)((qual/((__u64)RTjpeg_lum_quant_tbl[i]<<16))>>3);
- if(RTjpeg_lqt[i]==0)RTjpeg_lqt[i]=1;
- RTjpeg_cqt[i]=(__s32)((qual/((__u64)RTjpeg_chrom_quant_tbl[i]<<16))>>3);
- if(RTjpeg_cqt[i]==0)RTjpeg_cqt[i]=1;
- RTjpeg_liqt[i]=(1<<16)/(RTjpeg_lqt[i]<<3);
- RTjpeg_ciqt[i]=(1<<16)/(RTjpeg_cqt[i]<<3);
- RTjpeg_lqt[i]=((1<<16)/RTjpeg_liqt[i])>>3;
- RTjpeg_cqt[i]=((1<<16)/RTjpeg_ciqt[i])>>3;
- }
-
- RTjpeg_lb8=0;
- while(RTjpeg_liqt[RTjpeg_ZZ[++RTjpeg_lb8]]<=8);
- RTjpeg_lb8--;
- RTjpeg_cb8=0;
- while(RTjpeg_ciqt[RTjpeg_ZZ[++RTjpeg_cb8]]<=8);
- RTjpeg_cb8--;
-
- RTjpeg_dct_init();
- RTjpeg_quant_init();
-
- for(i=0; i<64; i++)
- buf[i]=le2me_32(RTjpeg_liqt[i]);
- for(i=0; i<64; i++)
- buf[64+i]=le2me_32(RTjpeg_ciqt[i]);
-}
-
-int RTjpeg_compressYUV420(__s8 *sp, unsigned char *bp)
-{
- __s8 * sb;
- register __s8 * bp1 = bp + (RTjpeg_width<<3);
- register __s8 * bp2 = bp + RTjpeg_Ysize;
- register __s8 * bp3 = bp2 + (RTjpeg_Csize>>1);
- register int i, j, k;
-
-#if HAVE_MMX
- emms();
-#endif
- sb=sp;
-/* Y */
- for(i=RTjpeg_height>>1; i; i-=8)
- {
- for(j=0, k=0; j<RTjpeg_width; j+=16, k+=8)
- {
- RTjpeg_dctY(bp+j, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
-
- RTjpeg_dctY(bp+j+8, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
-
- RTjpeg_dctY(bp1+j, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
-
- RTjpeg_dctY(bp1+j+8, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
-
- RTjpeg_dctY(bp2+k, RTjpeg_block, RTjpeg_Cwidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_cqt);
- sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_cb8);
-
- RTjpeg_dctY(bp3+k, RTjpeg_block, RTjpeg_Cwidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_cqt);
- sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_cb8);
-
- }
- bp+=RTjpeg_width<<4;
- bp1+=RTjpeg_width<<4;
- bp2+=RTjpeg_width<<2;
- bp3+=RTjpeg_width<<2;
-
- }
-#if HAVE_MMX
- emms();
-#endif
- return (sp-sb);
-}
-
-/*
-External Function
-
-Initialise additional data structures for motion compensation
-
-*/
-
-void RTjpeg_init_mcompress(void)
-{
- unsigned long tmp;
-
- if(!RTjpeg_old)
- {
- RTjpeg_old=malloc((4*RTjpeg_width*RTjpeg_height)+32);
- tmp=(unsigned long)RTjpeg_old;
- tmp+=32;
- tmp=tmp>>5;
- RTjpeg_old=(__s16 *)(tmp<<5);
- }
- if (!RTjpeg_old)
- {
- fprintf(stderr, "RTjpeg: Could not allocate memory\n");
- exit(-1);
- }
- memset(RTjpeg_old, 0, ((4*RTjpeg_width*RTjpeg_height)));
-}
-
-#if HAVE_MMX
-
-static int RTjpeg_bcomp(__s16 *old, mmx_t *mask)
-{
- int i;
- mmx_t *mold=(mmx_t *)old;
- mmx_t *mblock=(mmx_t *)RTjpeg_block;
- volatile mmx_t result;
- static mmx_t neg={0xffffffffffffffffULL};
-
- movq_m2r(*mask, mm7);
- movq_m2r(neg, mm6);
- pxor_r2r(mm5, mm5);
-
- for(i=0; i<8; i++)
- {
- movq_m2r(*(mblock++), mm0);
- movq_m2r(*(mblock++), mm2);
- movq_m2r(*(mold++), mm1);
- movq_m2r(*(mold++), mm3);
- psubsw_r2r(mm1, mm0);
- psubsw_r2r(mm3, mm2);
- movq_r2r(mm0, mm1);
- movq_r2r(mm2, mm3);
- pcmpgtw_r2r(mm7, mm0);
- pcmpgtw_r2r(mm7, mm2);
- pxor_r2r(mm6, mm1);
- pxor_r2r(mm6, mm3);
- pcmpgtw_r2r(mm7, mm1);
- pcmpgtw_r2r(mm7, mm3);
- por_r2r(mm0, mm5);
- por_r2r(mm2, mm5);
- por_r2r(mm1, mm5);
- por_r2r(mm3, mm5);
- }
- movq_r2m(mm5, result);
-
- if(result.q)
- {
- return 0;
- }
- return 1;
-}
-
-#else
-static int RTjpeg_bcomp(__s16 *old, __u16 *mask)
-{
- int i;
-
- for(i=0; i<64; i++)
- if(abs(old[i]-RTjpeg_block[i])>*mask)
- {
- for(i=0; i<16; i++)((__u64 *)old)[i]=((__u64 *)RTjpeg_block)[i];
- return 0;
- }
- return 1;
-}
-#endif
-
-int RTjpeg_mcompressYUV420(__s8 *sp, unsigned char *bp, __u16 lmask, __u16 cmask)
-{
- __s8 * sb;
- register __s8 * bp1 = bp + (RTjpeg_width<<3);
- register __s8 * bp2 = bp + RTjpeg_Ysize;
- register __s8 * bp3 = bp2 + (RTjpeg_Csize>>1);
- register int i, j, k;
-
-#if HAVE_MMX
- emms();
- RTjpeg_lmask.uq=((__u64)lmask<<48)|((__u64)lmask<<32)|((__u64)lmask<<16)|lmask;
- RTjpeg_cmask.uq=((__u64)cmask<<48)|((__u64)cmask<<32)|((__u64)cmask<<16)|cmask;
-#else
- RTjpeg_lmask=lmask;
- RTjpeg_cmask=cmask;
-#endif
-
- sb=sp;
- block=RTjpeg_old;
-/* Y */
- for(i=RTjpeg_height>>1; i; i-=8)
- {
- for(j=0, k=0; j<RTjpeg_width; j+=16, k+=8)
- {
- RTjpeg_dctY(bp+j, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- if(RTjpeg_bcomp(block, &RTjpeg_lmask))
- {
- *((__u8 *)sp++)=255;
- }
- else sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
- block+=64;
-
- RTjpeg_dctY(bp+j+8, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- if(RTjpeg_bcomp(block, &RTjpeg_lmask))
- {
- *((__u8 *)sp++)=255;
- }
- else sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
- block+=64;
-
- RTjpeg_dctY(bp1+j, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- if(RTjpeg_bcomp(block, &RTjpeg_lmask))
- {
- *((__u8 *)sp++)=255;
- }
- else sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
- block+=64;
-
- RTjpeg_dctY(bp1+j+8, RTjpeg_block, RTjpeg_Ywidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_lqt);
- if(RTjpeg_bcomp(block, &RTjpeg_lmask))
- {
- *((__u8 *)sp++)=255;
- }
- else sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_lb8);
- block+=64;
-
- RTjpeg_dctY(bp2+k, RTjpeg_block, RTjpeg_Cwidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_cqt);
- if(RTjpeg_bcomp(block, &RTjpeg_cmask))
- {
- *((__u8 *)sp++)=255;
- }
- else sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_cb8);
- block+=64;
-
- RTjpeg_dctY(bp3+k, RTjpeg_block, RTjpeg_Cwidth);
- RTjpeg_quant(RTjpeg_block, RTjpeg_cqt);
- if(RTjpeg_bcomp(block, &RTjpeg_cmask))
- {
- *((__u8 *)sp++)=255;
- }
- else sp+=RTjpeg_b2s(RTjpeg_block, sp, RTjpeg_cb8);
- block+=64;
- }
- bp+=RTjpeg_width<<4;
- bp1+=RTjpeg_width<<4;
- bp2+=RTjpeg_width<<2;
- bp3+=RTjpeg_width<<2;
-
- }
-#if HAVE_MMX
- emms();
-#endif
- return (sp-sb);
-}
diff --git a/libmpcodecs/native/rtjpegn.h b/libmpcodecs/native/rtjpegn.h
deleted file mode 100644
index 590b172a38..0000000000
--- a/libmpcodecs/native/rtjpegn.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- RTjpeg (C) Justin Schoeman 1998 (justin@suntiger.ee.up.ac.za)
-
- With modifications by:
- (c) 1998, 1999 by Joerg Walter <trouble@moes.pmnet.uni-oldenburg.de>
- and
- (c) 1999 by Wim Taymans <wim.taymans@tvd.be>
-
- This program 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.
-
- This program 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#ifndef MPLAYER_RTJPEGN_H
-#define MPLAYER_RTJPEGN_H
-
-#include <stdint.h>
-
-#define __u8 uint8_t
-#define __u16 uint16_t
-#define __u32 uint32_t
-#define __u64 uint64_t
-#define __s8 int8_t
-#define __s16 int16_t
-#define __s32 int32_t
-#define __s64 int64_t
-
-void RTjpeg_init_compress(__u32 *buf, int width, int height, __u8 Q);
-int RTjpeg_compressYUV420(__s8 *sp, unsigned char *bp);
-
-void RTjpeg_init_mcompress(void);
-int RTjpeg_mcompressYUV420(__s8 *sp, unsigned char *bp, __u16 lmask, __u16 cmask);
-
-#endif /* MPLAYER_RTJPEGN_H */
diff --git a/libmpcodecs/ve.c b/libmpcodecs/ve.c
deleted file mode 100644
index d140559530..0000000000
--- a/libmpcodecs/ve.c
+++ /dev/null
@@ -1,75 +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 "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-extern vf_info_t ve_info_lavc;
-extern vf_info_t ve_info_vfw;
-extern vf_info_t ve_info_raw;
-extern vf_info_t ve_info_libdv;
-extern vf_info_t ve_info_xvid;
-extern vf_info_t ve_info_qtvideo;
-extern vf_info_t ve_info_nuv;
-extern vf_info_t ve_info_x264;
-
-/* Please do not add any new encoders here. If you want to implement a new
- * encoder, add it to libavcodec, except for wrappers around external
- * libraries and encoders requiring binary support. */
-
-static vf_info_t* encoder_list[]={
-#ifdef CONFIG_LIBAVCODEC
- &ve_info_lavc,
-#endif
-#ifdef CONFIG_WIN32DLL
- &ve_info_vfw,
-#ifdef CONFIG_QTX_CODECS_WIN32
- &ve_info_qtvideo,
-#endif
-#endif
-#ifdef CONFIG_LIBDV095
- &ve_info_libdv,
-#endif
- &ve_info_raw,
-#ifdef CONFIG_XVID4
- &ve_info_xvid,
-#endif
-#ifdef CONFIG_LIBLZO
- &ve_info_nuv,
-#endif
-#ifdef CONFIG_X264
- &ve_info_x264,
-#endif
- /* Please do not add any new encoders here. If you want to implement a new
- * encoder, add it to libavcodec, except for wrappers around external
- * libraries and encoders requiring binary support. */
- NULL
-};
-
-vf_instance_t* vf_open_encoder(struct MPOpts *opts, vf_instance_t* next, const char *name, char *args){
- char* vf_args[] = { "_oldargs_", args, NULL };
- return vf_open_plugin(opts, encoder_list,next,name,vf_args);
-}
diff --git a/libmpcodecs/ve_lavc.c b/libmpcodecs/ve_lavc.c
deleted file mode 100644
index 258dbf2cc5..0000000000
--- a/libmpcodecs/ve_lavc.c
+++ /dev/null
@@ -1,1050 +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 <math.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-
-#if !defined(INFINITY) && defined(HUGE_VAL)
-#define INFINITY HUGE_VAL
-#endif
-
-#include "config.h"
-
-#include "mp_msg.h"
-#include "av_opts.h"
-#include "osdep/strsep.h"
-
-#include "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "fmt-conversion.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "vd_ffmpeg.h"
-
-extern char* passtmpfile;
-
-//===========================================================================//
-
-#include "libavcodec/avcodec.h"
-
-
-/* video options */
-static char *lavc_param_vcodec = "mpeg4";
-static int lavc_param_vbitrate = -1;
-static int lavc_param_vrate_tolerance = 1000*8;
-static int lavc_param_mb_decision = 0; /* default is realtime encoding */
-static int lavc_param_v4mv = 0;
-static int lavc_param_vme = 4;
-static float lavc_param_vqscale = -1;
-static int lavc_param_vqmin = 2;
-static int lavc_param_vqmax = 31;
-static int lavc_param_mb_qmin = 2;
-static int lavc_param_mb_qmax = 31;
-static float lavc_param_lmin = 2;
-static float lavc_param_lmax = 31;
-static float lavc_param_mb_lmin = 2;
-static float lavc_param_mb_lmax = 31;
-static int lavc_param_vqdiff = 3;
-static float lavc_param_vqcompress = 0.5;
-static float lavc_param_vqblur = 0.5;
-static float lavc_param_vb_qfactor = 1.25;
-static float lavc_param_vb_qoffset = 1.25;
-static float lavc_param_vi_qfactor = 0.8;
-static float lavc_param_vi_qoffset = 0.0;
-static int lavc_param_vmax_b_frames = 0;
-static int lavc_param_keyint = -1;
-static int lavc_param_vpass = 0;
-static int lavc_param_vrc_strategy = 0;
-static int lavc_param_vb_strategy = 0;
-static int lavc_param_luma_elim_threshold = 0;
-static int lavc_param_chroma_elim_threshold = 0;
-static int lavc_param_packet_size= 0;
-static int lavc_param_strict= -1;
-static int lavc_param_data_partitioning= 0;
-static int lavc_param_gray=0;
-static float lavc_param_rc_qsquish=1.0;
-static float lavc_param_rc_qmod_amp=0;
-static int lavc_param_rc_qmod_freq=0;
-static char *lavc_param_rc_override_string=NULL;
-static char *lavc_param_rc_eq="tex^qComp";
-static int lavc_param_rc_buffer_size=0;
-static float lavc_param_rc_buffer_aggressivity=1.0;
-static int lavc_param_rc_max_rate=0;
-static int lavc_param_rc_min_rate=0;
-static float lavc_param_rc_initial_cplx=0;
-static float lavc_param_rc_initial_buffer_occupancy=0.9;
-static int lavc_param_mpeg_quant=0;
-static int lavc_param_fdct=0;
-static int lavc_param_idct=0;
-static char* lavc_param_aspect = NULL;
-static int lavc_param_autoaspect = 0;
-static float lavc_param_lumi_masking= 0.0;
-static float lavc_param_dark_masking= 0.0;
-static float lavc_param_temporal_cplx_masking= 0.0;
-static float lavc_param_spatial_cplx_masking= 0.0;
-static float lavc_param_p_masking= 0.0;
-static float lavc_param_border_masking= 0.0;
-static int lavc_param_normalize_aqp= 0;
-static int lavc_param_interlaced_dct= 0;
-static int lavc_param_prediction_method= FF_PRED_LEFT;
-static int lavc_param_format= IMGFMT_YV12;
-static int lavc_param_debug= 0;
-static int lavc_param_psnr= 0;
-static int lavc_param_me_pre_cmp= 0;
-static int lavc_param_me_cmp= 0;
-static int lavc_param_me_sub_cmp= 0;
-static int lavc_param_mb_cmp= 0;
-#ifdef FF_CMP_VSAD
-static int lavc_param_ildct_cmp= FF_CMP_VSAD;
-#endif
-static int lavc_param_pre_dia_size= 0;
-static int lavc_param_dia_size= 0;
-static int lavc_param_qpel= 0;
-static int lavc_param_trell= 0;
-static int lavc_param_lowdelay= 0;
-static int lavc_param_bit_exact = 0;
-static int lavc_param_aic= 0;
-static int lavc_param_aiv= 0;
-static int lavc_param_umv= 0;
-static int lavc_param_gmc= 0;
-static int lavc_param_obmc= 0;
-static int lavc_param_loop= 0;
-static int lavc_param_last_pred= 0;
-static int lavc_param_pre_me= 1;
-static int lavc_param_me_subpel_quality= 8;
-static int lavc_param_me_range= 0;
-static int lavc_param_ibias= FF_DEFAULT_QUANT_BIAS;
-static int lavc_param_pbias= FF_DEFAULT_QUANT_BIAS;
-static int lavc_param_coder= 0;
-static int lavc_param_context= 0;
-static char *lavc_param_intra_matrix = NULL;
-static char *lavc_param_inter_matrix = NULL;
-static int lavc_param_cbp= 0;
-static int lavc_param_mv0= 0;
-static int lavc_param_noise_reduction= 0;
-static int lavc_param_qns= 0;
-static int lavc_param_qp_rd= 0;
-static int lavc_param_inter_threshold= 0;
-static int lavc_param_sc_threshold= 0;
-static int lavc_param_ss= 0;
-static int lavc_param_top= -1;
-static int lavc_param_alt= 0;
-static int lavc_param_ilme= 0;
-static int lavc_param_nssew= 8;
-static int lavc_param_closed_gop = 0;
-static int lavc_param_dc_precision = 8;
-static int lavc_param_threads= 1;
-static int lavc_param_turbo = 0;
-static int lavc_param_skip_threshold=0;
-static int lavc_param_skip_factor=0;
-static int lavc_param_skip_exp=0;
-static int lavc_param_skip_cmp=0;
-static int lavc_param_brd_scale = 0;
-static int lavc_param_bidir_refine = 0;
-static int lavc_param_sc_factor = 1;
-static int lavc_param_video_global_header= 0;
-static int lavc_param_mv0_threshold = 256;
-static int lavc_param_refs = 1;
-static int lavc_param_b_sensitivity = 40;
-static int lavc_param_level = FF_LEVEL_UNKNOWN;
-
-char *lavc_param_acodec = "mp2";
-int lavc_param_atag = 0;
-int lavc_param_abitrate = 224;
-int lavc_param_audio_global_header= 0;
-static char *lavc_param_avopt = NULL;
-
-#include "m_option.h"
-
-const m_option_t lavcopts_conf[]={
- {"acodec", &lavc_param_acodec, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"abitrate", &lavc_param_abitrate, CONF_TYPE_INT, CONF_RANGE, 1, 1000000, NULL},
- {"atag", &lavc_param_atag, CONF_TYPE_INT, CONF_RANGE, 0, 0xffff, NULL},
- {"vcodec", &lavc_param_vcodec, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"vbitrate", &lavc_param_vbitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
- {"vratetol", &lavc_param_vrate_tolerance, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
- {"vhq", &lavc_param_mb_decision, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"mbd", &lavc_param_mb_decision, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
- {"v4mv", &lavc_param_v4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"vme", &lavc_param_vme, CONF_TYPE_INT, CONF_RANGE, 0, 8, NULL},
- {"vqscale", &lavc_param_vqscale, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 255.0, NULL},
- {"vqmin", &lavc_param_vqmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"vqmax", &lavc_param_vqmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"mbqmin", &lavc_param_mb_qmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"mbqmax", &lavc_param_mb_qmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"lmin", &lavc_param_lmin, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
- {"lmax", &lavc_param_lmax, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
- {"mblmin", &lavc_param_mb_lmin, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
- {"mblmax", &lavc_param_mb_lmax, CONF_TYPE_FLOAT, CONF_RANGE, 0.01, 255.0, NULL},
- {"vqdiff", &lavc_param_vqdiff, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"vqcomp", &lavc_param_vqcompress, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL},
- {"vqblur", &lavc_param_vqblur, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL},
- {"vb_qfactor", &lavc_param_vb_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL},
- {"vmax_b_frames", &lavc_param_vmax_b_frames, CONF_TYPE_INT, CONF_RANGE, 0, FF_MAX_B_FRAMES, NULL},
- {"vpass", &lavc_param_vpass, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
- {"vrc_strategy", &lavc_param_vrc_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
- {"vb_strategy", &lavc_param_vb_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
- {"vb_qoffset", &lavc_param_vb_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL},
- {"vlelim", &lavc_param_luma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL},
- {"vcelim", &lavc_param_chroma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL},
- {"vpsize", &lavc_param_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
- {"vstrict", &lavc_param_strict, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL},
- {"vdpart", &lavc_param_data_partitioning, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL},
- {"keyint", &lavc_param_keyint, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL},
- {"mpeg_quant", &lavc_param_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"vi_qfactor", &lavc_param_vi_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL},
- {"vi_qoffset", &lavc_param_vi_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL},
- {"vqsquish", &lavc_param_rc_qsquish, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL},
- {"vqmod_amp", &lavc_param_rc_qmod_amp, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL},
- {"vqmod_freq", &lavc_param_rc_qmod_freq, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"vrc_eq", &lavc_param_rc_eq, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"vrc_override", &lavc_param_rc_override_string, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"vrc_maxrate", &lavc_param_rc_max_rate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL},
- {"vrc_minrate", &lavc_param_rc_min_rate, CONF_TYPE_INT, CONF_RANGE, 0, 24000000, NULL},
- {"vrc_buf_size", &lavc_param_rc_buffer_size, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
- {"vrc_buf_aggressivity", &lavc_param_rc_buffer_aggressivity, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL},
- {"vrc_init_cplx", &lavc_param_rc_initial_cplx, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 9999999.0, NULL},
- {"vrc_init_occupancy", &lavc_param_rc_initial_buffer_occupancy, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL},
- {"vfdct", &lavc_param_fdct, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
- {"aspect", &lavc_param_aspect, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"autoaspect", &lavc_param_autoaspect, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"lumi_mask", &lavc_param_lumi_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
- {"tcplx_mask", &lavc_param_temporal_cplx_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
- {"scplx_mask", &lavc_param_spatial_cplx_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
- {"p_mask", &lavc_param_p_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
- {"naq", &lavc_param_normalize_aqp, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"dark_mask", &lavc_param_dark_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL},
- {"ildct", &lavc_param_interlaced_dct, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"idct", &lavc_param_idct, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
- {"pred", &lavc_param_prediction_method, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
- {"format", &lavc_param_format, CONF_TYPE_IMGFMT, 0, 0, 0, NULL},
- {"debug", &lavc_param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
- {"psnr", &lavc_param_psnr, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PSNR, NULL},
- {"precmp", &lavc_param_me_pre_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
- {"cmp", &lavc_param_me_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
- {"subcmp", &lavc_param_me_sub_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
- {"mbcmp", &lavc_param_mb_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
- {"skipcmp", &lavc_param_skip_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
-#ifdef FF_CMP_VSAD
- {"ildctcmp", &lavc_param_ildct_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
-#endif
- {"bit_exact", &lavc_param_bit_exact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL},
- {"predia", &lavc_param_pre_dia_size, CONF_TYPE_INT, CONF_RANGE, -2000, 2000, NULL},
- {"dia", &lavc_param_dia_size, CONF_TYPE_INT, CONF_RANGE, -2000, 2000, NULL},
- {"qpel", &lavc_param_qpel, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QPEL, NULL},
- {"trell", &lavc_param_trell, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"lowdelay", &lavc_param_lowdelay, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_LOW_DELAY, NULL},
- {"last_pred", &lavc_param_last_pred, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
- {"preme", &lavc_param_pre_me, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL},
- {"subq", &lavc_param_me_subpel_quality, CONF_TYPE_INT, CONF_RANGE, 0, 8, NULL},
- {"me_range", &lavc_param_me_range, CONF_TYPE_INT, CONF_RANGE, 0, 16000, NULL},
-#ifdef CODEC_FLAG_AC_PRED
- {"aic", &lavc_param_aic, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_AC_PRED, NULL},
- {"umv", &lavc_param_umv, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_UMV, NULL},
-#endif
-#ifdef CODEC_FLAG_H263P_AIV
- {"aiv", &lavc_param_aiv, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_AIV, NULL},
-#endif
-#ifdef CODEC_FLAG_OBMC
- {"obmc", &lavc_param_obmc, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_OBMC, NULL},
-#endif
-#ifdef CODEC_FLAG_LOOP_FILTER
- {"loop", &lavc_param_loop, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_LOOP_FILTER, NULL},
-#endif
- {"ibias", &lavc_param_ibias, CONF_TYPE_INT, CONF_RANGE, -512, 512, NULL},
- {"pbias", &lavc_param_pbias, CONF_TYPE_INT, CONF_RANGE, -512, 512, NULL},
- {"coder", &lavc_param_coder, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
- {"context", &lavc_param_context, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
- {"intra_matrix", &lavc_param_intra_matrix, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"inter_matrix", &lavc_param_inter_matrix, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"cbp", &lavc_param_cbp, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_CBP_RD, NULL},
- {"mv0", &lavc_param_mv0, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_MV0, NULL},
- {"nr", &lavc_param_noise_reduction, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
-#ifdef CODEC_FLAG_QP_RD
- {"qprd", &lavc_param_qp_rd, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QP_RD, NULL},
-#endif
-#ifdef CODEC_FLAG_H263P_SLICE_STRUCT
- {"ss", &lavc_param_ss, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_SLICE_STRUCT, NULL},
-#endif
-#ifdef CODEC_FLAG_ALT_SCAN
- {"alt", &lavc_param_alt, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_ALT_SCAN, NULL},
-#endif
-#ifdef CODEC_FLAG_INTERLACED_ME
- {"ilme", &lavc_param_ilme, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_INTERLACED_ME, NULL},
-#endif
-#ifdef CODEC_FLAG_CLOSED_GOP
- {"cgop", &lavc_param_closed_gop, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_CLOSED_GOP, NULL},
-#endif
-#ifdef CODEC_FLAG_GMC
- {"gmc", &lavc_param_gmc, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_GMC, NULL},
-#endif
- {"dc", &lavc_param_dc_precision, CONF_TYPE_INT, CONF_RANGE, 8, 11, NULL},
- {"border_mask", &lavc_param_border_masking, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL},
- {"inter_threshold", &lavc_param_inter_threshold, CONF_TYPE_INT, CONF_RANGE, -1000000, 1000000, NULL},
- {"sc_threshold", &lavc_param_sc_threshold, CONF_TYPE_INT, CONF_RANGE, -1000000000, 1000000000, NULL},
- {"top", &lavc_param_top, CONF_TYPE_INT, CONF_RANGE, -1, 1, NULL},
- {"qns", &lavc_param_qns, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
- {"nssew", &lavc_param_nssew, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
- {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL},
- {"turbo", &lavc_param_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"skip_threshold", &lavc_param_skip_threshold, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
- {"skip_factor", &lavc_param_skip_factor, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
- {"skip_exp", &lavc_param_skip_exp, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL},
- {"brd_scale", &lavc_param_brd_scale, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL},
- {"bidir_refine", &lavc_param_bidir_refine, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL},
- {"sc_factor", &lavc_param_sc_factor, CONF_TYPE_INT, CONF_RANGE, 1, INT_MAX, NULL},
- {"vglobal", &lavc_param_video_global_header, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
- {"aglobal", &lavc_param_audio_global_header, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
- {"mv0_threshold", &lavc_param_mv0_threshold, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
- {"refs", &lavc_param_refs, CONF_TYPE_INT, CONF_RANGE, 1, 16, NULL},
- {"b_sensitivity", &lavc_param_b_sensitivity, CONF_TYPE_INT, CONF_RANGE, 1, INT_MAX, NULL},
- {"level", &lavc_param_level, CONF_TYPE_INT, CONF_RANGE, INT_MIN, INT_MAX, NULL},
- {"o", &lavc_param_avopt, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-struct vf_priv_s {
- muxer_stream_t* mux;
- AVCodecContext *context;
- AVFrame *pic;
- AVCodec *codec;
- FILE *stats_file;
-};
-
-#define stats_file (vf->priv->stats_file)
-#define mux_v (vf->priv->mux)
-#define lavc_venc_context (vf->priv->context)
-
-static int encode_frame(struct vf_instance *vf, AVFrame *pic, double pts);
-
-static int config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt){
- int size, i;
- char *p;
-
- mux_v->bih->biWidth=width;
- mux_v->bih->biHeight=height;
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
-
- mp_msg(MSGT_MENCODER, MSGL_INFO,"videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n",
- mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression,
- (char *)&mux_v->bih->biCompression);
-
- lavc_venc_context->width = width;
- lavc_venc_context->height = height;
- if (lavc_param_vbitrate > 16000) /* != -1 */
- lavc_venc_context->bit_rate = lavc_param_vbitrate;
- else if (lavc_param_vbitrate >= 0) /* != -1 */
- lavc_venc_context->bit_rate = lavc_param_vbitrate*1000;
- else
- lavc_venc_context->bit_rate = 800000; /* default */
-
- mux_v->avg_rate= lavc_venc_context->bit_rate;
-
- lavc_venc_context->bit_rate_tolerance= lavc_param_vrate_tolerance*1000;
- lavc_venc_context->time_base= (AVRational){mux_v->h.dwScale, mux_v->h.dwRate};
- lavc_venc_context->qmin= lavc_param_vqmin;
- lavc_venc_context->qmax= lavc_param_vqmax;
- lavc_venc_context->mb_qmin= lavc_param_mb_qmin;
- lavc_venc_context->mb_qmax= lavc_param_mb_qmax;
- lavc_venc_context->lmin= (int)(FF_QP2LAMBDA * lavc_param_lmin + 0.5);
- lavc_venc_context->lmax= (int)(FF_QP2LAMBDA * lavc_param_lmax + 0.5);
- lavc_venc_context->mb_lmin= (int)(FF_QP2LAMBDA * lavc_param_mb_lmin + 0.5);
- lavc_venc_context->mb_lmax= (int)(FF_QP2LAMBDA * lavc_param_mb_lmax + 0.5);
- lavc_venc_context->max_qdiff= lavc_param_vqdiff;
- lavc_venc_context->qcompress= lavc_param_vqcompress;
- lavc_venc_context->qblur= lavc_param_vqblur;
- lavc_venc_context->max_b_frames= lavc_param_vmax_b_frames;
- lavc_venc_context->b_quant_factor= lavc_param_vb_qfactor;
- lavc_venc_context->rc_strategy= lavc_param_vrc_strategy;
- lavc_venc_context->b_frame_strategy= lavc_param_vb_strategy;
- lavc_venc_context->b_quant_offset= (int)(FF_QP2LAMBDA * lavc_param_vb_qoffset + 0.5);
- lavc_venc_context->luma_elim_threshold= lavc_param_luma_elim_threshold;
- lavc_venc_context->chroma_elim_threshold= lavc_param_chroma_elim_threshold;
- lavc_venc_context->rtp_payload_size= lavc_param_packet_size;
- lavc_venc_context->strict_std_compliance= lavc_param_strict;
- lavc_venc_context->i_quant_factor= lavc_param_vi_qfactor;
- lavc_venc_context->i_quant_offset= (int)(FF_QP2LAMBDA * lavc_param_vi_qoffset + 0.5);
- lavc_venc_context->rc_qsquish= lavc_param_rc_qsquish;
- lavc_venc_context->rc_qmod_amp= lavc_param_rc_qmod_amp;
- lavc_venc_context->rc_qmod_freq= lavc_param_rc_qmod_freq;
- lavc_venc_context->rc_eq= lavc_param_rc_eq;
-
- mux_v->max_rate=
- lavc_venc_context->rc_max_rate= lavc_param_rc_max_rate*1000;
- lavc_venc_context->rc_min_rate= lavc_param_rc_min_rate*1000;
-
- mux_v->vbv_size=
- lavc_venc_context->rc_buffer_size= lavc_param_rc_buffer_size*1000;
-
- lavc_venc_context->rc_initial_buffer_occupancy=
- lavc_venc_context->rc_buffer_size *
- lavc_param_rc_initial_buffer_occupancy;
- lavc_venc_context->rc_buffer_aggressivity= lavc_param_rc_buffer_aggressivity;
- lavc_venc_context->rc_initial_cplx= lavc_param_rc_initial_cplx;
- lavc_venc_context->debug= lavc_param_debug;
- lavc_venc_context->last_predictor_count= lavc_param_last_pred;
- lavc_venc_context->pre_me= lavc_param_pre_me;
- lavc_venc_context->me_pre_cmp= lavc_param_me_pre_cmp;
- lavc_venc_context->pre_dia_size= lavc_param_pre_dia_size;
- lavc_venc_context->me_subpel_quality= lavc_param_me_subpel_quality;
- lavc_venc_context->me_range= lavc_param_me_range;
- lavc_venc_context->intra_quant_bias= lavc_param_ibias;
- lavc_venc_context->inter_quant_bias= lavc_param_pbias;
- lavc_venc_context->coder_type= lavc_param_coder;
- lavc_venc_context->context_model= lavc_param_context;
- lavc_venc_context->scenechange_threshold= lavc_param_sc_threshold;
- lavc_venc_context->noise_reduction= lavc_param_noise_reduction;
- lavc_venc_context->quantizer_noise_shaping= lavc_param_qns;
- lavc_venc_context->inter_threshold= lavc_param_inter_threshold;
- lavc_venc_context->nsse_weight= lavc_param_nssew;
- lavc_venc_context->frame_skip_threshold= lavc_param_skip_threshold;
- lavc_venc_context->frame_skip_factor= lavc_param_skip_factor;
- lavc_venc_context->frame_skip_exp= lavc_param_skip_exp;
- lavc_venc_context->frame_skip_cmp= lavc_param_skip_cmp;
-
- if (lavc_param_intra_matrix)
- {
- char *tmp;
-
- lavc_venc_context->intra_matrix =
- av_malloc(sizeof(*lavc_venc_context->intra_matrix)*64);
-
- i = 0;
- while ((tmp = strsep(&lavc_param_intra_matrix, ",")) && (i < 64))
- {
- if (!tmp || (tmp && !strlen(tmp)))
- break;
- lavc_venc_context->intra_matrix[i++] = atoi(tmp);
- }
-
- if (i != 64)
- av_freep(&lavc_venc_context->intra_matrix);
- else
- mp_msg(MSGT_MENCODER, MSGL_V, "Using user specified intra matrix\n");
- }
- if (lavc_param_inter_matrix)
- {
- char *tmp;
-
- lavc_venc_context->inter_matrix =
- av_malloc(sizeof(*lavc_venc_context->inter_matrix)*64);
-
- i = 0;
- while ((tmp = strsep(&lavc_param_inter_matrix, ",")) && (i < 64))
- {
- if (!tmp || (tmp && !strlen(tmp)))
- break;
- lavc_venc_context->inter_matrix[i++] = atoi(tmp);
- }
-
- if (i != 64)
- av_freep(&lavc_venc_context->inter_matrix);
- else
- mp_msg(MSGT_MENCODER, MSGL_V, "Using user specified inter matrix\n");
- }
-
- p= lavc_param_rc_override_string;
- for(i=0; p; i++){
- int start, end, q;
- int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
- if(e!=3){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"error parsing vrc_q\n");
- return 0;
- }
- lavc_venc_context->rc_override=
- realloc(lavc_venc_context->rc_override, sizeof(RcOverride)*(i+1));
- lavc_venc_context->rc_override[i].start_frame= start;
- lavc_venc_context->rc_override[i].end_frame = end;
- if(q>0){
- lavc_venc_context->rc_override[i].qscale= q;
- lavc_venc_context->rc_override[i].quality_factor= 1.0;
- }
- else{
- lavc_venc_context->rc_override[i].qscale= 0;
- lavc_venc_context->rc_override[i].quality_factor= -q/100.0;
- }
- p= strchr(p, '/');
- if(p) p++;
- }
- lavc_venc_context->rc_override_count=i;
-
- lavc_venc_context->mpeg_quant=lavc_param_mpeg_quant;
-
- lavc_venc_context->dct_algo= lavc_param_fdct;
- lavc_venc_context->idct_algo= lavc_param_idct;
-
- lavc_venc_context->lumi_masking= lavc_param_lumi_masking;
- lavc_venc_context->temporal_cplx_masking= lavc_param_temporal_cplx_masking;
- lavc_venc_context->spatial_cplx_masking= lavc_param_spatial_cplx_masking;
- lavc_venc_context->p_masking= lavc_param_p_masking;
- lavc_venc_context->dark_masking= lavc_param_dark_masking;
- lavc_venc_context->border_masking = lavc_param_border_masking;
-
- if (lavc_param_aspect != NULL)
- {
- int par_width, par_height, e;
- float ratio=0;
-
- e= sscanf (lavc_param_aspect, "%d/%d", &par_width, &par_height);
- if(e==2){
- if(par_height)
- ratio= (float)par_width / (float)par_height;
- }else{
- e= sscanf (lavc_param_aspect, "%f", &ratio);
- }
-
- if (e && ratio > 0.1 && ratio < 10.0) {
- lavc_venc_context->sample_aspect_ratio= av_d2q(ratio * height / width, 255);
- mp_dbg(MSGT_MENCODER, MSGL_DBG2, "sample_aspect_ratio: %d/%d\n",
- lavc_venc_context->sample_aspect_ratio.num,
- lavc_venc_context->sample_aspect_ratio.den);
- mux_v->aspect = ratio;
- mp_dbg(MSGT_MENCODER, MSGL_DBG2, "aspect_ratio: %f\n", ratio);
- } else {
- mp_dbg(MSGT_MENCODER, MSGL_ERR, "aspect ratio: cannot parse \"%s\"\n", lavc_param_aspect);
- return 0;
- }
- }
- else if (lavc_param_autoaspect) {
- lavc_venc_context->sample_aspect_ratio = av_d2q((float)d_width/d_height*height / width, 255);
- mux_v->aspect = (float)d_width/d_height;
- }
-
- /* keyframe interval */
- if (lavc_param_keyint >= 0) /* != -1 */
- lavc_venc_context->gop_size = lavc_param_keyint;
- else
- lavc_venc_context->gop_size = 250; /* default */
-
- lavc_venc_context->flags = 0;
- if (lavc_param_mb_decision)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "[VE_LAVC] High quality encoding selected (non-realtime)!\n");
- lavc_venc_context->mb_decision= lavc_param_mb_decision;
- }
-
- lavc_venc_context->me_cmp= lavc_param_me_cmp;
- lavc_venc_context->me_sub_cmp= lavc_param_me_sub_cmp;
- lavc_venc_context->mb_cmp= lavc_param_mb_cmp;
-#ifdef FF_CMP_VSAD
- lavc_venc_context->ildct_cmp= lavc_param_ildct_cmp;
-#endif
- lavc_venc_context->dia_size= lavc_param_dia_size;
- lavc_venc_context->flags|= lavc_param_qpel;
- lavc_venc_context->trellis = lavc_param_trell;
- lavc_venc_context->flags|= lavc_param_lowdelay;
- lavc_venc_context->flags|= lavc_param_bit_exact;
- lavc_venc_context->flags|= lavc_param_aic;
- lavc_venc_context->flags|= lavc_param_aiv;
- lavc_venc_context->flags|= lavc_param_umv;
- lavc_venc_context->flags|= lavc_param_obmc;
- lavc_venc_context->flags|= lavc_param_loop;
- lavc_venc_context->flags|= lavc_param_v4mv ? CODEC_FLAG_4MV : 0;
- lavc_venc_context->flags|= lavc_param_data_partitioning;
- lavc_venc_context->flags|= lavc_param_cbp;
- lavc_venc_context->flags|= lavc_param_mv0;
- lavc_venc_context->flags|= lavc_param_qp_rd;
- lavc_venc_context->flags|= lavc_param_ss;
- lavc_venc_context->flags|= lavc_param_alt;
- lavc_venc_context->flags|= lavc_param_ilme;
- lavc_venc_context->flags|= lavc_param_gmc;
-#ifdef CODEC_FLAG_CLOSED_GOP
- lavc_venc_context->flags|= lavc_param_closed_gop;
-#endif
- if(lavc_param_gray) lavc_venc_context->flags|= CODEC_FLAG_GRAY;
-
- if(lavc_param_normalize_aqp) lavc_venc_context->flags|= CODEC_FLAG_NORMALIZE_AQP;
- if(lavc_param_interlaced_dct) lavc_venc_context->flags|= CODEC_FLAG_INTERLACED_DCT;
- lavc_venc_context->flags|= lavc_param_psnr;
- lavc_venc_context->intra_dc_precision = lavc_param_dc_precision - 8;
- lavc_venc_context->prediction_method= lavc_param_prediction_method;
- lavc_venc_context->brd_scale = lavc_param_brd_scale;
- lavc_venc_context->bidir_refine = lavc_param_bidir_refine;
- lavc_venc_context->scenechange_factor = lavc_param_sc_factor;
- if((lavc_param_video_global_header&1)
- /*|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))*/){
- lavc_venc_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
- }
- if(lavc_param_video_global_header&2){
- lavc_venc_context->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
- }
- lavc_venc_context->mv0_threshold = lavc_param_mv0_threshold;
- lavc_venc_context->refs = lavc_param_refs;
- lavc_venc_context->b_sensitivity = lavc_param_b_sensitivity;
- lavc_venc_context->level = lavc_param_level;
-
- if(lavc_param_avopt){
- if(parse_avopts(lavc_venc_context, lavc_param_avopt) < 0){
- mp_msg(MSGT_MENCODER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavc_param_avopt);
- return 0;
- }
- }
-
- mux_v->imgfmt = lavc_param_format;
- lavc_venc_context->pix_fmt = imgfmt2pixfmt(lavc_param_format);
- if (lavc_venc_context->pix_fmt == PIX_FMT_NONE)
- return 0;
-
- if(!stats_file) {
- /* lavc internal 2pass bitrate control */
- switch(lavc_param_vpass){
- case 2:
- case 3:
- lavc_venc_context->flags|= CODEC_FLAG_PASS2;
- stats_file= fopen(passtmpfile, "rb");
- if(stats_file==NULL){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
- return 0;
- }
- fseek(stats_file, 0, SEEK_END);
- size= ftell(stats_file);
- fseek(stats_file, 0, SEEK_SET);
-
- lavc_venc_context->stats_in= av_malloc(size + 1);
- lavc_venc_context->stats_in[size]=0;
-
- if(fread(lavc_venc_context->stats_in, size, 1, stats_file)<1){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: reading from filename=%s\n", passtmpfile);
- return 0;
- }
- if(lavc_param_vpass == 2)
- break;
- else
- fclose(stats_file);
- /* fall through */
- case 1:
- lavc_venc_context->flags|= CODEC_FLAG_PASS1;
- stats_file= fopen(passtmpfile, "wb");
- if(stats_file==NULL){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
- return 0;
- }
- if(lavc_param_turbo && (lavc_param_vpass == 1)) {
- /* uses SAD comparison functions instead of other hungrier */
- lavc_venc_context->me_pre_cmp = 0;
- lavc_venc_context->me_cmp = 0;
- lavc_venc_context->me_sub_cmp = 0;
- lavc_venc_context->mb_cmp = 2;
-
- /* Disables diamond motion estimation */
- lavc_venc_context->pre_dia_size = 0;
- lavc_venc_context->dia_size = 1;
-
- lavc_venc_context->quantizer_noise_shaping = 0; // qns=0
- lavc_venc_context->noise_reduction = 0; // nr=0
- lavc_venc_context->mb_decision = 0; // mbd=0 ("realtime" encoding)
-
- lavc_venc_context->flags &= ~CODEC_FLAG_QPEL;
- lavc_venc_context->flags &= ~CODEC_FLAG_4MV;
- lavc_venc_context->trellis = 0;
- lavc_venc_context->flags &= ~CODEC_FLAG_CBP_RD;
- lavc_venc_context->flags &= ~CODEC_FLAG_QP_RD;
- lavc_venc_context->flags &= ~CODEC_FLAG_MV0;
- }
- break;
- }
- }
-
- lavc_venc_context->me_method = ME_ZERO+lavc_param_vme;
-
- /* fixed qscale :p */
- if (lavc_param_vqscale >= 0.0)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "[VE_LAVC] Using constant qscale = %f (VBR).\n", lavc_param_vqscale);
- lavc_venc_context->flags |= CODEC_FLAG_QSCALE;
- lavc_venc_context->global_quality=
- vf->priv->pic->quality = (int)(FF_QP2LAMBDA * lavc_param_vqscale + 0.5);
- }
-
- if(lavc_param_threads > 1)
- avcodec_thread_init(lavc_venc_context, lavc_param_threads);
-
- if (avcodec_open(lavc_venc_context, vf->priv->codec) != 0) {
- mp_tmsg(MSGT_MENCODER,MSGL_ERR,"Could not open codec.\n");
- return 0;
- }
-
- if (lavc_venc_context->codec->encode == NULL) {
- mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n");
- return 0;
- }
-
- /* free second pass buffer, its not needed anymore */
- av_freep(&lavc_venc_context->stats_in);
- if(lavc_venc_context->bits_per_coded_sample)
- mux_v->bih->biBitCount= lavc_venc_context->bits_per_coded_sample;
- if(lavc_venc_context->extradata_size){
- mux_v->bih= realloc(mux_v->bih, sizeof(BITMAPINFOHEADER) + lavc_venc_context->extradata_size);
- memcpy(mux_v->bih + 1, lavc_venc_context->extradata, lavc_venc_context->extradata_size);
- mux_v->bih->biSize= sizeof(BITMAPINFOHEADER) + lavc_venc_context->extradata_size;
- }
-
- mux_v->decoder_delay = lavc_venc_context->max_b_frames ? 1 : 0;
-
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-
- switch(request){
- case VFCTRL_FLUSH_FRAMES:
- if(vf->priv->codec->capabilities & CODEC_CAP_DELAY)
- while(encode_frame(vf, NULL, MP_NOPTS_VALUE) > 0);
- return CONTROL_TRUE;
- default:
- return CONTROL_UNKNOWN;
- }
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt){
- switch(fmt){
- case IMGFMT_YV12:
- case IMGFMT_IYUV:
- case IMGFMT_I420:
- if(lavc_param_format == IMGFMT_YV12)
- return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
- break;
- case IMGFMT_411P:
- if(lavc_param_format == IMGFMT_411P)
- return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
- break;
- case IMGFMT_422P:
- if(lavc_param_format == IMGFMT_422P)
- return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
- break;
- case IMGFMT_444P:
- if(lavc_param_format == IMGFMT_444P)
- return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
- break;
- case IMGFMT_YVU9:
- if(lavc_param_format == IMGFMT_YVU9)
- return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
- break;
- case IMGFMT_BGR32:
- if(lavc_param_format == IMGFMT_BGR32)
- return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE;
- break;
- }
- return 0;
-}
-
-static double psnr(double d){
- if(d==0) return INFINITY;
- return -10.0*log(d)/log(10);
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
- AVFrame *pic= vf->priv->pic;
-
- pic->data[0]=mpi->planes[0];
- pic->data[1]=mpi->planes[1];
- pic->data[2]=mpi->planes[2];
- pic->linesize[0]=mpi->stride[0];
- pic->linesize[1]=mpi->stride[1];
- pic->linesize[2]=mpi->stride[2];
-
- if(lavc_param_interlaced_dct){
- if((mpi->fields & MP_IMGFIELD_ORDERED) && (mpi->fields & MP_IMGFIELD_INTERLACED))
- pic->top_field_first= !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
- else
- pic->top_field_first= 1;
-
- if(lavc_param_top!=-1)
- pic->top_field_first= lavc_param_top;
- }
-
- return encode_frame(vf, pic, pts) >= 0;
-}
-
-static int encode_frame(struct vf_instance *vf, AVFrame *pic, double pts){
- const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'};
- int out_size;
- double dts;
-
- if(pts == MP_NOPTS_VALUE)
- pts= lavc_venc_context->frame_number * av_q2d(lavc_venc_context->time_base);
-
- if(pic){
-#if 0
- pic->opaque= malloc(sizeof(pts));
- memcpy(pic->opaque, &pts, sizeof(pts));
-#else
- if(pts != MP_NOPTS_VALUE)
- pic->pts= floor(pts / av_q2d(lavc_venc_context->time_base) + 0.5);
- else
- pic->pts= MP_NOPTS_VALUE;
-#endif
- }
- out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size,
- pic);
-
- if(pts != MP_NOPTS_VALUE)
- dts= pts - lavc_venc_context->delay * av_q2d(lavc_venc_context->time_base);
- else
- dts= MP_NOPTS_VALUE;
-#if 0
- pts= lavc_venc_context->coded_frame->opaque ?
- *(double*)lavc_venc_context->coded_frame->opaque
- : MP_NOPTS_VALUE;
-#else
- if(lavc_venc_context->coded_frame->pts != MP_NOPTS_VALUE)
- pts= lavc_venc_context->coded_frame->pts * av_q2d(lavc_venc_context->time_base);
- else
- pts= MP_NOPTS_VALUE;
- assert(MP_NOPTS_VALUE == AV_NOPTS_VALUE);
-#endif
-//fprintf(stderr, "ve_lavc %f/%f\n", dts, pts);
- if(out_size == 0 && lavc_param_skip_threshold==0 && lavc_param_skip_factor==0){
- ++mux_v->encoder_delay;
- return 0;
- }
-
- muxer_write_chunk(mux_v,out_size,lavc_venc_context->coded_frame->key_frame?0x10:0,
- dts, pts);
- free(lavc_venc_context->coded_frame->opaque);
- lavc_venc_context->coded_frame->opaque= NULL;
-
- /* store psnr / pict size / type / qscale */
- if(lavc_param_psnr){
- static FILE *fvstats=NULL;
- char filename[20];
- double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0;
- double quality=0.0;
- int8_t *q;
-
- if(!fvstats) {
- time_t today2;
- struct tm *today;
- today2 = time(NULL);
- today = localtime(&today2);
- sprintf(filename, "psnr_%02d%02d%02d.log", today->tm_hour,
- today->tm_min, today->tm_sec);
- fvstats = fopen(filename,"w");
- if(!fvstats) {
- perror("fopen");
- lavc_param_psnr=0; // disable block
- mp_msg(MSGT_MENCODER,MSGL_ERR,"Can't open %s for writing. Check its permissions.\n",filename);
- return -1;
- /*exit(1);*/
- }
- }
-
- // average MB quantizer
- q = lavc_venc_context->coded_frame->qscale_table;
- if(q) {
- int x, y;
- int w = (lavc_venc_context->width+15) >> 4;
- int h = (lavc_venc_context->height+15) >> 4;
- for( y = 0; y < h; y++ ) {
- for( x = 0; x < w; x++ )
- quality += (double)*(q+x);
- q += lavc_venc_context->coded_frame->qstride;
- }
- quality /= w * h;
- } else
- quality = lavc_venc_context->coded_frame->quality / (float)FF_QP2LAMBDA;
-
- fprintf(fvstats, "%6d, %2.2f, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n",
- lavc_venc_context->coded_frame->coded_picture_number,
- quality,
- out_size,
- psnr(lavc_venc_context->coded_frame->error[0]/f),
- psnr(lavc_venc_context->coded_frame->error[1]*4/f),
- psnr(lavc_venc_context->coded_frame->error[2]*4/f),
- psnr((lavc_venc_context->coded_frame->error[0]+lavc_venc_context->coded_frame->error[1]+lavc_venc_context->coded_frame->error[2])/(f*1.5)),
- pict_type_char[lavc_venc_context->coded_frame->pict_type]
- );
- }
- /* store stats if there are any */
- if(lavc_venc_context->stats_out && stats_file)
- fprintf(stats_file, "%s", lavc_venc_context->stats_out);
- return out_size;
-}
-
-static void uninit(struct vf_instance *vf){
-
- if(lavc_param_psnr){
- double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0;
- f*= lavc_venc_context->coded_frame->coded_picture_number;
-
- mp_msg(MSGT_MENCODER, MSGL_INFO, "PSNR: Y:%2.2f, Cb:%2.2f, Cr:%2.2f, All:%2.2f\n",
- psnr(lavc_venc_context->error[0]/f),
- psnr(lavc_venc_context->error[1]*4/f),
- psnr(lavc_venc_context->error[2]*4/f),
- psnr((lavc_venc_context->error[0]+lavc_venc_context->error[1]+lavc_venc_context->error[2])/(f*1.5))
- );
- }
-
- av_freep(&lavc_venc_context->intra_matrix);
- av_freep(&lavc_venc_context->inter_matrix);
-
- if (lavc_venc_context->codec)
- avcodec_close(lavc_venc_context);
-
- if(stats_file) fclose(stats_file);
-
- /* free rc_override */
- av_freep(&lavc_venc_context->rc_override);
-
- av_freep(&vf->priv->context);
-}
-
-//===========================================================================//
-
-static int vf_open(vf_instance_t *vf, char* args){
- vf->uninit=uninit;
- vf->config=config;
- vf->default_caps=VFCAP_CONSTANT;
- vf->control=control;
- vf->query_format=query_format;
- vf->put_image=put_image;
- vf->priv=calloc(1, sizeof(struct vf_priv_s));
- vf->priv->mux=(muxer_stream_t*)args;
-
- /* XXX: hack: some of the MJPEG decoder DLL's needs exported huffman
- table, so we define a zero-table, also lavc mjpeg encoder is putting
- huffman tables into the stream, so no problem */
- if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "mjpeg"))
- {
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+28);
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+28;
- }
- else if (lavc_param_vcodec && (!strcasecmp(lavc_param_vcodec, "huffyuv")
- || !strcasecmp(lavc_param_vcodec, "ffvhuff")))
- {
- /* XXX: hack: huffyuv needs to store huffman tables (allthough we dunno the size yet ...) */
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+1000);
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+1000;
- }
- else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "asv1"))
- {
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+8);
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+8;
- }
- else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "asv2"))
- {
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+8);
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+8;
- }
- else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "wmv2"))
- {
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+4);
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+4;
- }
- else
- {
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER));
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
- }
- mux_v->bih->biWidth=0;
- mux_v->bih->biHeight=0;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24;
- if (!lavc_param_vcodec)
- {
- printf("No libavcodec codec specified! It's required!\n");
- return 0;
- }
-
- if (!strcasecmp(lavc_param_vcodec, "mpeg1") || !strcasecmp(lavc_param_vcodec, "mpeg1video"))
- mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '1');
- else if (!strcasecmp(lavc_param_vcodec, "mpeg2") || !strcasecmp(lavc_param_vcodec, "mpeg2video"))
- mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '2');
- else if (!strcasecmp(lavc_param_vcodec, "h263") || !strcasecmp(lavc_param_vcodec, "h263p"))
- mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '3');
- else if (!strcasecmp(lavc_param_vcodec, "rv10"))
- mux_v->bih->biCompression = mmioFOURCC('R', 'V', '1', '0');
- else if (!strcasecmp(lavc_param_vcodec, "mjpeg"))
- mux_v->bih->biCompression = mmioFOURCC('M', 'J', 'P', 'G');
- else if (!strcasecmp(lavc_param_vcodec, "ljpeg"))
- mux_v->bih->biCompression = mmioFOURCC('L', 'J', 'P', 'G');
- else if (!strcasecmp(lavc_param_vcodec, "mpeg4"))
- mux_v->bih->biCompression = mmioFOURCC('F', 'M', 'P', '4');
- else if (!strcasecmp(lavc_param_vcodec, "msmpeg4"))
- mux_v->bih->biCompression = mmioFOURCC('d', 'i', 'v', '3');
- else if (!strcasecmp(lavc_param_vcodec, "msmpeg4v2"))
- mux_v->bih->biCompression = mmioFOURCC('M', 'P', '4', '2');
- else if (!strcasecmp(lavc_param_vcodec, "wmv1"))
- mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '1');
- else if (!strcasecmp(lavc_param_vcodec, "wmv2"))
- mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '2');
- else if (!strcasecmp(lavc_param_vcodec, "huffyuv"))
- mux_v->bih->biCompression = mmioFOURCC('H', 'F', 'Y', 'U');
- else if (!strcasecmp(lavc_param_vcodec, "ffvhuff"))
- mux_v->bih->biCompression = mmioFOURCC('F', 'F', 'V', 'H');
- else if (!strcasecmp(lavc_param_vcodec, "asv1"))
- mux_v->bih->biCompression = mmioFOURCC('A', 'S', 'V', '1');
- else if (!strcasecmp(lavc_param_vcodec, "asv2"))
- mux_v->bih->biCompression = mmioFOURCC('A', 'S', 'V', '2');
- else if (!strcasecmp(lavc_param_vcodec, "ffv1"))
- mux_v->bih->biCompression = mmioFOURCC('F', 'F', 'V', '1');
- else if (!strcasecmp(lavc_param_vcodec, "snow"))
- mux_v->bih->biCompression = mmioFOURCC('S', 'N', 'O', 'W');
- else if (!strcasecmp(lavc_param_vcodec, "flv"))
- mux_v->bih->biCompression = mmioFOURCC('F', 'L', 'V', '1');
- else if (!strcasecmp(lavc_param_vcodec, "dvvideo"))
- mux_v->bih->biCompression = mmioFOURCC('d', 'v', 's', 'd');
- else if (!strcasecmp(lavc_param_vcodec, "libx264"))
- mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '4');
- else if (!strcasecmp(lavc_param_vcodec, "libschroedinger"))
- mux_v->bih->biCompression = mmioFOURCC('d', 'r', 'a', 'c');
- else if (!strcasecmp(lavc_param_vcodec, "libdirac"))
- mux_v->bih->biCompression = mmioFOURCC('d', 'r', 'a', 'c');
- else
- mux_v->bih->biCompression = mmioFOURCC(lavc_param_vcodec[0],
- lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */
-
- init_avcodec();
-
- vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec);
- if (!vf->priv->codec) {
- mp_tmsg(MSGT_MENCODER,MSGL_ERR,"Cannot find codec '%s' in libavcodec...\n", lavc_param_vcodec);
- return 0;
- }
-
- vf->priv->pic = avcodec_alloc_frame();
- vf->priv->context = avcodec_alloc_context();
- vf->priv->context->codec_type = CODEC_TYPE_VIDEO;
- vf->priv->context->codec_id = vf->priv->codec->id;
-
- return 1;
-}
-
-vf_info_t ve_info_lavc = {
- "libavcodec encoder",
- "lavc",
- "A'rpi, Alex, Michael",
- "for internal use by mencoder",
- vf_open
-};
-
-//===========================================================================//
diff --git a/libmpcodecs/ve_libdv.c b/libmpcodecs/ve_libdv.c
deleted file mode 100644
index 99808e34e8..0000000000
--- a/libmpcodecs/ve_libdv.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * requires libdv-0.9.5 !!!
- * (v0.9.0 is too old and has no encoding functionality exported!)
- *
- * 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 "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#include <libdv/dv.h>
-
-#ifndef DV_WIDTH
-#define DV_WIDTH 720
-#define DV_PAL_HEIGHT 576
-#define DV_NTSC_HEIGHT 480
-#endif
-
-struct vf_priv_s {
- muxer_stream_t* mux;
- dv_encoder_t* enc;
-
-};
-#define mux_v (vf->priv->mux)
-
-//===========================================================================//
-
-static int config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt){
-
- if(width!=DV_WIDTH || (height!=DV_PAL_HEIGHT && height!=DV_NTSC_HEIGHT)){
- mp_msg(MSGT_VFILTER,MSGL_ERR,"DV: only 720x480 (NTSC) and 720x576 (PAL) resolutions allowed! Try with -vf scale=720:480\n");
- }
-
- vf->priv->enc->isPAL=(height==DV_PAL_HEIGHT);
- vf->priv->enc->is16x9=(d_width/(float)d_height > 1.7); // 16:9=1.777777
- vf->priv->enc->vlc_encode_passes=3;
- vf->priv->enc->static_qno=0;
- vf->priv->enc->force_dct=0;
-
- mux_v->bih->biWidth=width;
- mux_v->bih->biHeight=height;
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
- mux_v->aspect = (float)d_width/d_height;
-
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-
- return CONTROL_UNKNOWN;
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt){
- if(fmt==IMGFMT_YUY2) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- if(fmt==IMGFMT_RGB24) return VFCAP_CSP_SUPPORTED;
- return 0;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
-
- dv_encode_full_frame(vf->priv->enc, mpi->planes,
- (mpi->flags&MP_IMGFLAG_YUV) ? e_dv_color_yuv : e_dv_color_rgb,
- mux_v->buffer);
-
- muxer_write_chunk(mux_v, 480 * (vf->priv->enc->isPAL ? 300 : 250) , 0x10, pts, pts);
- return 1;
-}
-
-//===========================================================================//
-
-static int vf_open(vf_instance_t *vf, char* args){
- vf->config=config;
- vf->default_caps=VFCAP_CONSTANT;
- vf->control=control;
- vf->query_format=query_format;
- vf->put_image=put_image;
- vf->priv=malloc(sizeof(struct vf_priv_s));
- memset(vf->priv,0,sizeof(struct vf_priv_s));
- vf->priv->mux=(muxer_stream_t*)args;
-
- vf->priv->enc=dv_encoder_new(0,1,1); // FIXME, parse some options!
- if(!vf->priv->enc) return 0;
-
- mux_v->bih=calloc(1, sizeof(*mux_v->bih));
- mux_v->bih->biSize=sizeof(*mux_v->bih);
- mux_v->bih->biWidth=0;
- mux_v->bih->biHeight=0;
- mux_v->bih->biCompression=mmioFOURCC('d','v','s','d');
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24;
-
- return 1;
-}
-
-vf_info_t ve_info_libdv = {
- "DV encoder using libdv",
- "libdv",
- "A'rpi",
- "for internal use by mencoder",
- vf_open
-};
-
-//===========================================================================//
diff --git a/libmpcodecs/ve_nuv.c b/libmpcodecs/ve_nuv.c
deleted file mode 100644
index 807fff5517..0000000000
--- a/libmpcodecs/ve_nuv.c
+++ /dev/null
@@ -1,255 +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 "m_option.h"
-
-#include "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#include "ffmpeg_files/intreadwrite.h"
-#include <lzo/lzo1x.h>
-#include "native/rtjpegn.h"
-
-#define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long))
-#define LZO_OUT_LEN(in) ((in) + (in) / 64 + 16 + 3)
-
-//===========================================================================//
-
-struct vf_priv_s {
- int raw; // Do not use RTjpeg
- int lzo; // Use lzo
- unsigned int l,c,q; // Mjpeg param
- muxer_stream_t* mux;
- uint8_t* buffer;
-
- int buf_size;
- int tbl_wrote;
- lzo_byte *zbuffer;
- long __LZO_MMODEL *zmem;
-};
-#define mux_v (vf->priv->mux)
-
-struct vf_priv_s nuv_priv_dflt = {
- 0, // raw
- 1, // lzo
- 1,1, // l,c
- 255, // q
- NULL,
- NULL,
- 0,0,
- NULL,NULL
-};
-
-const m_option_t nuvopts_conf[] = {
- {"raw", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"rtjpeg", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"lzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nolzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"q", &nuv_priv_dflt.q, CONF_TYPE_INT, M_OPT_RANGE,3,255, NULL},
- {"l", &nuv_priv_dflt.l, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL},
- {"c", &nuv_priv_dflt.c, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-//===========================================================================//
-
-
-#define COMPDATASIZE (128*4)
-#define FRAMEHEADERSIZE 12
-
-static int config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt){
-
- // We need a buffer wich can holda header and a whole YV12 picture
- // or a RTJpeg table
- vf->priv->buf_size = width*height*3/2+FRAMEHEADERSIZE;
- if(vf->priv->buf_size < COMPDATASIZE + FRAMEHEADERSIZE)
- vf->priv->buf_size = COMPDATASIZE + FRAMEHEADERSIZE;
-
- mux_v->bih->biWidth=width;
- mux_v->bih->biHeight=height;
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
- mux_v->aspect = (float)d_width/d_height;
- vf->priv->buffer = realloc(vf->priv->buffer,vf->priv->buf_size);
- if (vf->priv->lzo)
- vf->priv->zbuffer = realloc(vf->priv->zbuffer, FRAMEHEADERSIZE + LZO_OUT_LEN(vf->priv->buf_size));
- vf->priv->tbl_wrote = 0;
-
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-
- return CONTROL_UNKNOWN;
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt){
- if(fmt==IMGFMT_I420) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- return 0;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
- uint8_t *header = vf->priv->buffer;
- uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE;
- uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE;
- int len = 0, r;
- size_t zlen = 0;
-
- memset(header, 0, FRAMEHEADERSIZE); // Reset the header
- if(vf->priv->lzo)
- memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE);
-
- // This has to be don here otherwise tv with sound doesn't work
- if(!vf->priv->tbl_wrote) {
- RTjpeg_init_compress((uint32_t *)data,mpi->width,mpi->height,vf->priv->q);
- RTjpeg_init_mcompress();
-
- header[0] = 'D'; // frametype: compressor data
- header[1] = 'R'; // comptype: compressor data for RTjpeg
- AV_WL32(header + 8, COMPDATASIZE); // packetlength
-
- mux_v->buffer=vf->priv->buffer;
- muxer_write_chunk(mux_v,FRAMEHEADERSIZE + COMPDATASIZE, 0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- vf->priv->tbl_wrote = 1;
- memset(header, 0, FRAMEHEADERSIZE); // Reset the header
- }
-
- // Raw picture
- if(vf->priv->raw) {
- len = mpi->width*mpi->height*3/2;
- // Try lzo ???
- if(vf->priv->lzo) {
- r = lzo1x_1_compress(mpi->planes[0],len,
- zdata,&zlen,vf->priv->zmem);
- if(r != LZO_E_OK) {
- mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n");
- zlen = 0;
- }
- }
-
- if(zlen <= 0 || zlen > len) {
- memcpy(data,mpi->planes[0],len);
- header[1] = '0'; // comptype: uncompressed
- } else { // Use lzo only if it's littler
- header = vf->priv->zbuffer;
- header[1] = '3'; //comptype: lzo
- len = zlen;
- }
-
- } else { // RTjpeg compression
- len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l,
- vf->priv->c);
- if(len <= 0) {
- mp_msg(MSGT_VFILTER,MSGL_ERR,"RTjpeg_mcompressYUV420 error (%d)\n",len);
- return 0;
- }
-
- if(vf->priv->lzo) {
- r = lzo1x_1_compress(data,len,zdata,&zlen,vf->priv->zmem);
- if(r != LZO_E_OK) {
- mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n");
- zlen = 0;
- }
- }
-
- if(zlen <= 0 || zlen > len)
- header[1] = '1'; // comptype: RTjpeg
- else {
- header = vf->priv->zbuffer;
- header[1] = '2'; // comptype: RTjpeg + LZO
- len = zlen;
- }
-
- }
-
- header[0] = 'V'; // frametype: video frame
- AV_WL32(header + 8, len); // packetlength
- mux_v->buffer = header;
- muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10, pts, pts);
- return 1;
-}
-
-static void uninit(struct vf_instance *vf) {
-
- if(vf->priv->buffer)
- free(vf->priv->buffer);
- if(vf->priv->zbuffer)
- free(vf->priv->zbuffer);
- if(vf->priv->zmem)
- free(vf->priv->zmem);
-
-}
-
-//===========================================================================//
-
-static int vf_open(vf_instance_t *vf, char* args){
- vf->config=config;
- vf->default_caps=VFCAP_CONSTANT;
- vf->control=control;
- vf->query_format=query_format;
- vf->put_image=put_image;
- vf->uninit = uninit;
- vf->priv=malloc(sizeof(struct vf_priv_s));
- memcpy(vf->priv, &nuv_priv_dflt,sizeof(struct vf_priv_s));
- vf->priv->mux=(muxer_stream_t*)args;
-
- mux_v->bih=calloc(1, sizeof(*mux_v->bih));
- mux_v->bih->biSize=sizeof(*mux_v->bih);
- mux_v->bih->biWidth=0;
- mux_v->bih->biHeight=0;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=12;
- mux_v->bih->biCompression = mmioFOURCC('N','U','V','1');
-
- if(vf->priv->lzo) {
- if(lzo_init() != LZO_E_OK) {
- mp_msg(MSGT_VFILTER,MSGL_WARN,"LZO init failed: no lzo compression\n");
- vf->priv->lzo = 0;
- } else
- vf->priv->zmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS));
- }
-
- return 1;
-}
-
-vf_info_t ve_info_nuv = {
- "nuv encoder",
- "nuv",
- "Albeu",
- "for internal use by mencoder",
- vf_open
-};
-
-//===========================================================================//
diff --git a/libmpcodecs/ve_qtvideo.c b/libmpcodecs/ve_qtvideo.c
deleted file mode 100644
index 59b8731c93..0000000000
--- a/libmpcodecs/ve_qtvideo.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * QT video encoder using Win32 libs
- *
- * Copyright (C) 2002 Sascha Sommer
- *
- * 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.
- */
-
-#define MAX_IDSIZE 0x6F
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "config.h"
-#include "mp_msg.h"
-#include "mpbswap.h"
-
-#ifdef WIN32_LOADER
-#include "loader/ldt_keeper.h"
-#endif
-
-#include "loader/qtx/qtxsdk/components.h"
-#include "loader/wine/winbase.h"
-#include "loader/wine/windef.h"
-
-#include "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-
-static HINSTANCE qtime_qts; //handle to preloaded quicktime.qts
-static HMODULE handler;
-
-static OSErr (*FindCodec)(CodecType cType,
- CodecComponent specCodec,
- CompressorComponent * compressor,
- DecompressorComponent * decompressor);
-static OSErr (*InitializeQTML)(long flags);
-static PixMapHandle (*GetGWorldPixMap)(GWorldPtr offscreenGWorld);
-static OSErr (*QTNewGWorldFromPtr)(GWorldPtr *gw,
- OSType pixelFormat,
- const Rect *boundsRect,
- CTabHandle cTable,
- /*GDHandle*/void* aGDevice, /*unused anyway*/
- GWorldFlags flags,
- void *baseAddr,
- long rowBytes);
-static Handle (*NewHandleClear)(Size byteCount);
-static OSErr (*CompressSequenceBegin) (
- ImageSequence *seqID,
- PixMapHandle src,
- PixMapHandle prev,
- const Rect *srcRect,
- const Rect *prevRect,
- short colorDepth,
- CodecType cType,
- CompressorComponent codec,
- CodecQ spatialQuality,
- CodecQ temporalQuality,
- long keyFrameRate,
- CTabHandle ctable,
- CodecFlags flags,
- ImageDescriptionHandle desc );
-
-static OSErr (*CompressSequenceFrame) (
- ImageSequence seqID,
- PixMapHandle src,
- const Rect *srcRect,
- CodecFlags flags,
- Ptr data,
- long *dataSize,
- UInt8 *similarity,
- ICMCompletionProcRecordPtr asyncCompletionProc );
-
-static OSErr (*GetMaxCompressionSize)(PixMapHandle src,
- const Rect *srcRect,
- short colorDepth,
- CodecQ quality,
- CodecType cType,
- CompressorComponent codec,
- long *size );
-static OSErr (*CDSequenceEnd)( ImageSequence seqID );
-static Component (*FindNextComponent)(Component prev,ComponentDescription* desc);
-static long (*CountComponents)(ComponentDescription* desc);
-static OSErr (*GetComponentInfo)(Component prev,ComponentDescription* desc,Handle h1,Handle h2,Handle h3);
-
-
-
-//static int format=mmioFOURCC('S','V','Q','1');
-static int format=mmioFOURCC('S','V','Q','3');
-
-
-
-//static void *frame_in; //input frame
-static void *frame_prev; //previous frame
-static void *frame_comp; //compressed frame
-static GWorldPtr frame_GWorld_in = NULL;//a GWorld is some kind of description for a drawing environment
-static GWorldPtr frame_GWorld_prev = NULL;
-static Rect FrameRect;
-
-static CompressorComponent compressor;
-static ImageDescriptionHandle desc;
-static ImageSequence seq;
-
-
-
-
-
-struct vf_priv_s {
- muxer_stream_t* mux;
- //dv_encoder_t* enc;
-
-};
-#define mux_v (vf->priv->mux)
-
-//===========================================================================//
-
-static int config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt){
-// OSErr cres;
- ComponentDescription cdesc;
- mux_v->bih->biWidth=width;
- mux_v->bih->biHeight=height;
- mux_v->bih->biSizeImage=width*height*2;
- mux_v->aspect = (float)d_width/d_height;
-
-
-
- memset(&cdesc,0,sizeof(cdesc));
- cdesc.componentType= (((unsigned char)'i')<<24)|
- (((unsigned char)'m')<<16)|
- (((unsigned char)'c')<<8)|
- (((unsigned char)'o'));
-
- cdesc.componentSubType=bswap_32(format);
- cdesc.componentManufacturer=0;
- cdesc.componentFlags=0;
- cdesc.componentFlagsMask=0;
-
-
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"Count = %ld\n",CountComponents(&cdesc));
- compressor=FindNextComponent(NULL,&cdesc);
- if(!compressor){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"Cannot find requested component\n");
- return 0;
- }
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"Found it! ID = %p\n",compressor);
-
-// cres= FindCodec (fourcc,anyCodec,&compressor,&decompressor );
-// printf("FindCodec returned:%i compressor: 0x%X decompressor: 0x%X\n",cres&0xFFFF,compressor,decompressor);
-
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-
- return CONTROL_UNKNOWN;
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt){
- if(fmt==IMGFMT_YUY2) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- return 0;
-}
-
-static int codec_initialized = 0;
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
-
- OSErr cres;
- long framesizemax;
- UInt8 similarity=0;
- long compressedsize;
- OSType in_format=kYUVSPixelFormat;
- int width = mpi->width;
- int height = mpi->height;
- int stride = width*2;
-if(!codec_initialized){
- FrameRect.top=0;
- FrameRect.left=0;
- FrameRect.right=width;
- FrameRect.bottom=height;
- cres = QTNewGWorldFromPtr(
- &frame_GWorld_in,
- in_format,
- &FrameRect,
- 0,
- 0,
- 0,
- mpi->planes[0],
- stride);
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF);
- //dunno what todo about this
- frame_prev = malloc(stride * height);
- cres = QTNewGWorldFromPtr(
- &frame_GWorld_prev,
- in_format,
- &FrameRect,
- 0,
- 0,
- 0,
- frame_prev,
- stride);
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"height:%i width:%i stride:%i\n",height,width,stride);
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF);
- cres= GetMaxCompressionSize (
- GetGWorldPixMap(frame_GWorld_in),
- &FrameRect,
- 24,
- codecNormalQuality,
- bswap_32(format),
- compressor,
- &framesizemax );
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"GetMaxCompressionSize returned:%i : MaxSize:%li\n",cres&0xFFFF,framesizemax);
- frame_comp=malloc(framesizemax);
-
- desc = (ImageDescriptionHandle)NewHandleClear(MAX_IDSIZE); //memory where the desc will be stored
- (*desc)->idSize=MAX_IDSIZE;
-
- cres= CompressSequenceBegin (
- &seq,
- GetGWorldPixMap( frame_GWorld_in),
- GetGWorldPixMap( frame_GWorld_prev),
- &FrameRect,
- &FrameRect,
- 24, // color depth
- bswap_32(format), // fourcc
- compressor, // codec component
- codecNormalQuality, //codecNormalQuality,
- codecMaxQuality, //codecNormalQuality,
- 10*30, // keyframe rate
- 0,
- 0,
- desc);
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceBegin returned:%i\n",cres&0xFFFF);
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"Sequence ID:%i\n",seq);
-
- dump_ImageDescription(*desc);
- codec_initialized++;
-}
- cres = CompressSequenceFrame (
- seq,
- GetGWorldPixMap(frame_GWorld_in),
- &FrameRect,
- 0,
- (char*)mux_v->buffer,
- &compressedsize,
- &similarity,
- 0);
-
- if(cres&0xFFFF)mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceFrame returned:%i\n",cres&0xFFFF);
-#if 0
- printf("Size %i->%i \n",stride*height,compressedsize);
- printf("Ratio: %i:1\n",(stride*height)/compressedsize);
-#endif
- muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
-
- if(((*desc)->idSize)>MAX_IDSIZE){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize));
- } else {
- // according to QT docs, imagedescription may be changed while encoding
- // a frame (even its size may (and does!) change!)
- memcpy(mux_v->bih+1,*desc,(*desc)->idSize);
- }
-
- return 1;
-}
-
-//===========================================================================//
-
-static int vf_open(vf_instance_t *vf, char* args){
- OSErr cres = 1;
- vf->config=config;
- vf->default_caps=VFCAP_CONSTANT;
- vf->control=control;
- vf->query_format=query_format;
- vf->put_image=put_image;
- vf->priv=malloc(sizeof(struct vf_priv_s));
- memset(vf->priv,0,sizeof(struct vf_priv_s));
- vf->priv->mux=(muxer_stream_t*)args;
-
- mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+MAX_IDSIZE);
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+MAX_IDSIZE;
- mux_v->bih->biWidth=0;
- mux_v->bih->biHeight=0;
- mux_v->bih->biCompression=format;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24;
-
-
-#ifdef WIN32_LOADER
- Setup_LDT_Keeper();
-#endif
- //preload quicktime.qts to avoid the problems caused by the hardcoded path inside the dll
- qtime_qts = LoadLibraryA("QuickTime.qts");
- if(!qtime_qts){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"unable to load QuickTime.qts\n" );
- return 0;
- }
-
- handler = LoadLibraryA("qtmlClient.dll");
- if(!handler){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"unable to load qtmlClient.dll\n");
- return 0;
- }
- InitializeQTML = (OSErr (*)(long))GetProcAddress(handler, "InitializeQTML");
- GetGWorldPixMap = (PixMapHandle (*)(GWorldPtr))GetProcAddress(handler, "GetGWorldPixMap");
- QTNewGWorldFromPtr = (OSErr(*)(GWorldPtr *,OSType,const Rect *,CTabHandle,void*,GWorldFlags,void *,long))GetProcAddress(handler, "QTNewGWorldFromPtr");
- NewHandleClear = (OSErr(*)(Size))GetProcAddress(handler, "NewHandleClear");
- FindCodec = (OSErr (*)(CodecType,CodecComponent,CompressorComponent *,DecompressorComponent *))GetProcAddress(handler,"FindCodec");
- CompressSequenceBegin = (OSErr(*)(ImageSequence *,PixMapHandle,PixMapHandle,const Rect *,const Rect *,short,CodecType,CompressorComponent,CodecQ,CodecQ,long,CTabHandle,CodecFlags,ImageDescriptionHandle))GetProcAddress(handler,"CompressSequenceBegin");
- CompressSequenceFrame = (OSErr(*)(ImageSequence,PixMapHandle,const Rect *,CodecFlags,Ptr,long *,UInt8 *,ICMCompletionProcRecordPtr))GetProcAddress(handler,"CompressSequenceFrame");
- GetMaxCompressionSize = (OSErr(*)(PixMapHandle,const Rect *,short,CodecQ,CodecType,CompressorComponent,long *))GetProcAddress(handler,"GetMaxCompressionSize");
- CDSequenceEnd = (OSErr (*)(ImageSequence))GetProcAddress(handler,"CDSequenceEnd");
- FindNextComponent = (Component (*)(Component,ComponentDescription*))GetProcAddress(handler, "FindNextComponent");
- CountComponents = (long (*)(ComponentDescription*))GetProcAddress(handler, "CountComponents");
- GetComponentInfo = (OSErr (*)(Component,ComponentDescription*,Handle,Handle,Handle))GetProcAddress(handler, "GetComponentInfo");
- if(!InitializeQTML ||!CompressSequenceBegin){
- mp_msg(MSGT_MENCODER,MSGL_ERR,"invalid qt DLL!\n");
- return 0;
- }
- //printf("%i,%i,%i\n",mmioFOURCC('S','V','Q','1'),'SVQ1',bswap_32(mmioFOURCC('S','V','Q','1')));
- cres=InitializeQTML(6+16);
- mp_msg(MSGT_MENCODER,MSGL_DBG2,"InitializeQTML returned %i\n",cres);
- return 1;
-}
-
-vf_info_t ve_info_qtvideo = {
- "Quicktime video encoder using win32 DLLs",
- "qtvideo",
- "Sascha Sommer",
- "for internal use by mencoder",
- vf_open
-};
-
-//===========================================================================//
diff --git a/libmpcodecs/ve_raw.c b/libmpcodecs/ve_raw.c
deleted file mode 100644
index f2b8e9528c..0000000000
--- a/libmpcodecs/ve_raw.c
+++ /dev/null
@@ -1,177 +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 "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-
-//===========================================================================//
-
-struct vf_priv_s {
- muxer_stream_t* mux;
-};
-#define mux_v (vf->priv->mux)
-
-static int set_format(struct vf_instance *vf, unsigned int fmt) {
- if (!force_fourcc)
- mux_v->bih->biCompression = fmt;
-
- mux_v->bih->biPlanes = 1;
- if (IMGFMT_IS_RGB(fmt)) {
- if (IMGFMT_RGB_DEPTH(fmt) < 8 && !(fmt&128))
- mux_v->bih->biBitCount = IMGFMT_RGB_DEPTH(fmt);
- else
- mux_v->bih->biBitCount = (IMGFMT_RGB_DEPTH(fmt)+7)&(~7);
- return 1;
- }
- if (IMGFMT_IS_BGR(fmt)) {
- if (IMGFMT_BGR_DEPTH(fmt) < 8 && !(fmt&128))
- mux_v->bih->biBitCount = IMGFMT_BGR_DEPTH(fmt);
- else
- mux_v->bih->biBitCount = (IMGFMT_BGR_DEPTH(fmt)+7)&(~7);
- return 1;
- }
- switch (fmt) {
- case IMGFMT_I420:
- case IMGFMT_IYUV:
- case IMGFMT_YV12:
- case IMGFMT_411P:
- mux_v->bih->biPlanes = 3;
- mux_v->bih->biBitCount = 12;
- break;
- case IMGFMT_444P:
- mux_v->bih->biPlanes = 3;
- mux_v->bih->biBitCount = 24;
- break;
- case IMGFMT_422P:
- mux_v->bih->biPlanes = 3;
- mux_v->bih->biBitCount = 16;
- break;
- case IMGFMT_IF09:
- mux_v->bih->biPlanes = 4;
- case IMGFMT_YVU9:
- mux_v->bih->biBitCount = 9;
- break;
- case IMGFMT_UYVY:
- case IMGFMT_YUY2:
- mux_v->bih->biBitCount = 16;
- break;
- case IMGFMT_Y8:
- mux_v->bih->biBitCount = 8;
- break;
- default:
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "[VE_RAW] Raw output with FourCC [%x] not supported!\n", fmt);
- mux_v->bih->biCompression = 0;
- return 0;
- }
- return 1;
-}
-
-
-static int config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt)
-{
- int ret;
- mux_v->bih->biWidth = width;
- mux_v->bih->biHeight = height;
- mux_v->aspect = (float)d_width/d_height;
- ret = set_format(vf, outfmt);
- if (!ret) return 0;
-
- mux_v->bih->biSizeImage = mux_v->bih->biWidth*mux_v->bih->biHeight*mux_v->bih->biBitCount/8;
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void *data) {
- return CONTROL_UNKNOWN;
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt) {
- if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt))
- return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- switch (fmt) {
- case IMGFMT_I420:
- case IMGFMT_IYUV:
- case IMGFMT_YV12:
- case IMGFMT_411P:
- case IMGFMT_444P:
- case IMGFMT_422P:
- case IMGFMT_UYVY:
- case IMGFMT_YUY2:
- case IMGFMT_YVU9:
- case IMGFMT_IF09:
- case IMGFMT_Y8:
- return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- }
-
- return 0;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) {
- mux_v->buffer = mpi->planes[0];
- muxer_write_chunk(mux_v, mpi->width*mpi->height*mux_v->bih->biBitCount/8, 0x10, pts, pts);
- return 1;
-}
-
-//===========================================================================//
-
-static int vf_open(vf_instance_t *vf, char* args){
- vf->config = config;
- vf->default_caps = VFCAP_CONSTANT;
- vf->control = control;
- vf->query_format = query_format;
- vf->put_image = put_image;
- vf->default_caps = 0;
- vf->priv = malloc(sizeof(struct vf_priv_s));
- memset(vf->priv, 0, sizeof(struct vf_priv_s));
- vf->priv->mux = (muxer_stream_t*)args;
-
- mux_v->bih = calloc(1, sizeof(BITMAPINFOHEADER));
- mux_v->bih->biSize = sizeof(BITMAPINFOHEADER);
- mux_v->bih->biWidth = 0;
- mux_v->bih->biHeight = 0;
-
- return 1;
-}
-
-vf_info_t ve_info_raw = {
- "raw encoder",
- "raw",
- "jwe21@cam.ac.uk",
- "Based on rawrgb",
- vf_open
-};
-
-//===========================================================================//
diff --git a/libmpcodecs/ve_vfw.c b/libmpcodecs/ve_vfw.c
deleted file mode 100644
index 2825502293..0000000000
--- a/libmpcodecs/ve_vfw.c
+++ /dev/null
@@ -1,377 +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 <unistd.h>
-#include <inttypes.h>
-#include <sys/stat.h>
-
-#include "config.h"
-
-#include "mp_msg.h"
-
-#include "codec-cfg.h"
-//#include "stream/stream.h"
-//#include "libmpdemux/demuxer.h"
-//#include "libmpdemux/stheader.h"
-
-#include "loader/loader.h"
-//#include "loader/wine/mmreg.h"
-#include "loader/wine/vfw.h"
-#include "libmpdemux/aviheader.h"
-#include "loader/wine/winerror.h"
-#include "loader/wine/objbase.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-//===========================================================================//
-
-static char *vfw_param_codec = NULL;
-static char *vfw_param_compdata = NULL;
-static HRESULT CoInitRes = -1;
-
-#include "m_option.h"
-
-const m_option_t vfwopts_conf[]={
- {"codec", &vfw_param_codec, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"compdata", &vfw_param_compdata, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-struct vf_priv_s {
- muxer_stream_t* mux;
- BITMAPINFOHEADER* bih;
-};
-
-static HIC encoder_hic;
-static void* encoder_buf=NULL;
-static int encoder_buf_size=0;
-static int encoder_frameno=0;
-
-//int init_vfw_encoder(char *dll_name, BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih)
-static BITMAPINFOHEADER* vfw_open_encoder(char *dll_name, char *compdatafile, BITMAPINFOHEADER *input_bih,unsigned int out_fourcc)
-{
- HRESULT ret;
- BITMAPINFOHEADER* output_bih=NULL;
- int temp_len;
- FILE *fd=NULL;
- char *drvdata=NULL;
- struct stat st;
-
-//sh_video = malloc(sizeof(sh_video_t));
-
- mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Encoder init =======\n");
- CoInitRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
-// memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER));
-// output_bih->biSize = sizeof(BITMAPINFOHEADER);
-
-// encoder_hic = ICOpen( 0x63646976, out_fourcc, ICMODE_COMPRESS);
- encoder_hic = ICOpen( (long) dll_name, out_fourcc, ICMODE_COMPRESS);
- if(!encoder_hic){
- mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n");
- return NULL;
- }
- mp_msg(MSGT_WIN32,MSGL_INFO,"HIC: %x\n", encoder_hic);
-
-{
- ICINFO icinfo;
-
- ret = ICGetInfo(encoder_hic, &icinfo, sizeof(ICINFO));
- mp_msg(MSGT_WIN32,MSGL_INFO,"%ld - %ld - %d\n", ret, icinfo.dwSize, sizeof(ICINFO));
- mp_tmsg(MSGT_WIN32,MSGL_INFO,"Compressor type: %.4lx\n", icinfo.fccType);
- mp_tmsg(MSGT_WIN32,MSGL_INFO,"Compressor subtype: %.4lx\n", icinfo.fccHandler);
- mp_tmsg(MSGT_WIN32,MSGL_INFO,"Compressor flags: %lu, version %lu, ICM version: %lu\n",
- icinfo.dwFlags, icinfo.dwVersion, icinfo.dwVersionICM);
-//printf("Compressor name: %s\n", icinfo.szName);
-//printf("Compressor description: %s\n", icinfo.szDescription);
-
-mp_tmsg(MSGT_WIN32,MSGL_INFO,"Flags:");
-if (icinfo.dwFlags & VIDCF_QUALITY)
- mp_tmsg(MSGT_WIN32,MSGL_INFO," quality");
-if (icinfo.dwFlags & VIDCF_FASTTEMPORALD)
- mp_msg(MSGT_WIN32,MSGL_INFO," fast-decompr");
-if (icinfo.dwFlags & VIDCF_QUALITYTIME)
- mp_msg(MSGT_WIN32,MSGL_INFO," temp-quality");
-mp_msg(MSGT_WIN32,MSGL_INFO,"\n");
-}
-
- if(compdatafile){
- if (!strncmp(compdatafile, "dialog", 6)){
- if (ICSendMessage(encoder_hic, ICM_CONFIGURE, -1, 0) != ICERR_OK){
- mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor doesn't have a configure dialog!\n");
- return NULL;
- }
- if (ICSendMessage(encoder_hic, ICM_CONFIGURE, 0, 0) != ICERR_OK){
- mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor configure dialog failed!\n");
- return NULL;
- }
- }
- else {
- if (stat(compdatafile, &st) < 0){
- mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor data file not found!\n");
- return NULL;
- }
- fd = fopen(compdatafile, "rb");
- if (!fd){
- mp_msg(MSGT_WIN32,MSGL_ERR,"Cannot open Compressor data file!\n");
- return NULL;
- }
- drvdata = malloc(st.st_size);
- if (fread(drvdata, st.st_size, 1, fd) != 1) {
- mp_msg(MSGT_WIN32,MSGL_ERR,"Cannot read Compressor data file!\n");
- fclose(fd);
- free(drvdata);
- return NULL;
- }
- fclose(fd);
- mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor data %d bytes\n", st.st_size);
- if (!(temp_len = (unsigned int) ICSendMessage(encoder_hic, ICM_SETSTATE, (LPARAM) drvdata, (int) st.st_size))){
- mp_msg(MSGT_WIN32,MSGL_ERR,"ICSetState failed!\n");
- free(drvdata);
- return NULL;
- }
- free(drvdata);
- mp_msg(MSGT_WIN32,MSGL_INFO,"ICSetState ret: %d\n", temp_len);
- }
- }
-
- temp_len = ICCompressGetFormatSize(encoder_hic, input_bih);
- mp_msg(MSGT_WIN32,MSGL_INFO,"ICCompressGetFormatSize ret: %d\n", temp_len);
-
- if (temp_len < sizeof(BITMAPINFOHEADER)) temp_len=sizeof(BITMAPINFOHEADER);
-
- output_bih = malloc(temp_len+4);
- memset(output_bih,0,temp_len);
- output_bih->biSize = temp_len; //sizeof(BITMAPINFOHEADER);
-
- return output_bih;
-}
-
-static int vfw_start_encoder(BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih){
- HRESULT ret;
- int temp_len=output_bih->biSize;
- int i;
-
- ret = ICCompressGetFormat(encoder_hic, input_bih, output_bih);
- if(ret < 0){
- unsigned char* temp=(unsigned char*)output_bih;
- mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressGetFormat failed: Error %d (0x%X)\n", (int)ret, (int)ret);
- for (i=0; i < temp_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", temp[i]);
- return 0;
- }
- mp_msg(MSGT_WIN32,MSGL_V,"ICCompressGetFormat OK\n");
-
- if (temp_len > sizeof(BITMAPINFOHEADER))
- {
- unsigned char* temp=(unsigned char*)output_bih;
- mp_msg(MSGT_WIN32, MSGL_V, "Extra info in o_bih (%d bytes)!\n",
- temp_len-sizeof(BITMAPINFOHEADER));
- for(i=sizeof(output_bih);i<temp_len;i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02X ",temp[i]);
- }
-
-// if( mp_msg_test(MSGT_WIN32,MSGL_V) ) {
- printf("Starting compression:\n");
- printf(" Input format:\n");
- printf(" biSize %ld\n", input_bih->biSize);
- printf(" biWidth %ld\n", input_bih->biWidth);
- printf(" biHeight %ld\n", input_bih->biHeight);
- printf(" biPlanes %d\n", input_bih->biPlanes);
- printf(" biBitCount %d\n", input_bih->biBitCount);
- printf(" biCompression 0x%lx ('%.4s')\n", input_bih->biCompression, (char *)&input_bih->biCompression);
- printf(" biSizeImage %ld\n", input_bih->biSizeImage);
- printf(" Output format:\n");
- printf(" biSize %ld\n", output_bih->biSize);
- printf(" biWidth %ld\n", output_bih->biWidth);
- printf(" biHeight %ld\n", output_bih->biHeight);
- printf(" biPlanes %d\n", output_bih->biPlanes);
- printf(" biBitCount %d\n", output_bih->biBitCount);
- printf(" biCompression 0x%lx ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression);
- printf(" biSizeImage %ld\n", output_bih->biSizeImage);
-// }
-
- output_bih->biWidth=input_bih->biWidth;
- output_bih->biHeight=input_bih->biHeight;
-
- ret = ICCompressQuery(encoder_hic, input_bih, output_bih);
- if(ret){
- mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressQuery failed: Error %d\n", (int)ret);
- return 0;
- } else
- mp_msg(MSGT_WIN32,MSGL_V,"ICCompressQuery OK\n");
-
- ret = ICCompressBegin(encoder_hic, input_bih, output_bih);
- if(ret){
- mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressBegin failed: Error %d\n", (int)ret);
-// return 0;
- } else
- mp_msg(MSGT_WIN32,MSGL_V,"ICCompressBegin OK\n");
- mp_msg(MSGT_WIN32,MSGL_INFO," Output format after query/begin:\n");
- mp_msg(MSGT_WIN32,MSGL_INFO," biSize %ld\n", output_bih->biSize);
- mp_msg(MSGT_WIN32,MSGL_INFO," biWidth %ld\n", output_bih->biWidth);
- mp_msg(MSGT_WIN32,MSGL_INFO," biHeight %ld\n", output_bih->biHeight);
- mp_msg(MSGT_WIN32,MSGL_INFO," biPlanes %d\n", output_bih->biPlanes);
- mp_msg(MSGT_WIN32,MSGL_INFO," biBitCount %d\n", output_bih->biBitCount);
- mp_msg(MSGT_WIN32,MSGL_INFO," biCompression 0x%lx ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression);
- mp_msg(MSGT_WIN32,MSGL_INFO," biSizeImage %ld\n", output_bih->biSizeImage);
-
- encoder_buf_size=input_bih->biSizeImage;
- encoder_buf=malloc(encoder_buf_size);
- encoder_frameno=0;
-
- mp_msg(MSGT_WIN32,MSGL_V,"VIDEO CODEC Init OK!!! ;-)\n");
- return 1;
-}
-
-static int vfw_encode_frame(BITMAPINFOHEADER* biOutput,void* OutBuf,
- BITMAPINFOHEADER* biInput,void* Image,
- long* keyframe, int quality){
- HRESULT ret;
-
-//long VFWAPIV ICCompress(
-// HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpOutputBuf,
-// LPBITMAPINFOHEADER lpbiInput,void* lpImage,long* lpckid,
-// long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality,
-// LPBITMAPINFOHEADER lpbiInputPrev,void* lpImagePrev
-//);
-
-// printf("vfw_encode_frame(%p,%p, %p,%p, %p,%d)\n",biOutput,OutBuf,biInput,Image,keyframe,quality);
-
- ret=ICCompress(encoder_hic, 0,
- biOutput, OutBuf,
- biInput, Image,
- NULL, keyframe, encoder_frameno, 0, quality,
- biInput, encoder_buf);
-
-// printf("ok. size=%ld\n",biOutput->biSizeImage);
-
- memcpy(encoder_buf,Image,encoder_buf_size);
- ++encoder_frameno;
-
- return (int)ret;
-}
-#define mux_v (vf->priv->mux)
-#define vfw_bih (vf->priv->bih)
-
-static int config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt){
-
- vfw_bih->biWidth=width;
- vfw_bih->biHeight=height;
- vfw_bih->biSizeImage=width*height*((vfw_bih->biBitCount+7)/8);
- mux_v->aspect = (float)d_width/d_height;
-
- if(!vfw_start_encoder(vfw_bih, mux_v->bih)) return 0;
-
-// mux_v->bih->biWidth=width;
-// mux_v->bih->biHeight=height;
-// mux_v->bih->biSizeImage=width*height*((mux_v->bih->biBitCount+7)/8);
-
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void* data){
-
- return CONTROL_UNKNOWN;
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt){
- if(fmt==IMGFMT_BGR24) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_FLIPPED;
- return 0;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
- long flags=0;
- int ret;
-// flip_upside_down(vo_image_ptr,vo_image_ptr,3*vo_w,vo_h); // dirty hack
- ret=vfw_encode_frame(mux_v->bih, mux_v->buffer, vfw_bih, mpi->planes[0], &flags, 10000);
-// if (ret != ICERR_OK)
-// return 0;
- muxer_write_chunk(mux_v,mux_v->bih->biSizeImage,flags, pts, pts);
- return 1;
-}
-
-static void uninit(struct vf_instance *vf)
-{
- HRESULT ret;
-
- if(encoder_hic){
- if(encoder_buf){
- ret=ICCompressEnd(encoder_hic);
- if(ret) mp_msg(MSGT_WIN32, MSGL_WARN, "ICCompressEnd failed: %ld\n", ret);
- free(encoder_buf);
- encoder_buf=NULL;
- }
- ret=ICClose(encoder_hic);
- if(ret) mp_msg(MSGT_WIN32, MSGL_WARN, "ICClose failed: %ld\n", ret);
- encoder_hic=0;
- if ((CoInitRes == S_OK) || (CoInitRes == S_FALSE)) CoUninitialize();
- }
-}
-
-//===========================================================================//
-
-static int vf_open(vf_instance_t *vf, char* args){
- vf->config=config;
- vf->default_caps=VFCAP_CONSTANT;
- vf->control=control;
- vf->query_format=query_format;
- vf->put_image=put_image;
- vf->uninit=uninit;
- vf->priv=malloc(sizeof(struct vf_priv_s));
- memset(vf->priv,0,sizeof(struct vf_priv_s));
- vf->priv->mux=(muxer_stream_t*)args;
-
- vfw_bih=calloc(1, sizeof(BITMAPINFOHEADER));
- vfw_bih->biSize=sizeof(BITMAPINFOHEADER);
- vfw_bih->biWidth=0; // FIXME ?
- vfw_bih->biHeight=0;
- vfw_bih->biPlanes=1;
- vfw_bih->biBitCount=24;
- vfw_bih->biCompression=0;
-// vfw_bih->biSizeImage=vo_w*vo_h*((vfw_bih->biBitCount+7)/8);
-
- if (!vfw_param_codec)
- {
- mp_tmsg(MSGT_WIN32,MSGL_WARN, "[VE_RAW] Required VfW codec not specified!!\n");
- return 0;
- }
-// mux_v->bih=vfw_open_encoder("divxc32.dll",vfw_bih,mmioFOURCC('D', 'I', 'V', '3'));
-// mux_v->bih=vfw_open_encoder("AvidAVICodec.dll",vfw_bih, 0);
- mux_v->bih = vfw_open_encoder(vfw_param_codec, vfw_param_compdata, vfw_bih, 0);
- if(!mux_v->bih) return 0;
-
- return 1;
-}
-
-vf_info_t ve_info_vfw = {
- "Win32/VfW encoders",
- "vfw",
- "A'rpi",
- "for internal use by mencoder",
- vf_open
-};
-
-//===========================================================================//
diff --git a/libmpcodecs/ve_x264.c b/libmpcodecs/ve_x264.c
deleted file mode 100644
index 47a636b3cc..0000000000
--- a/libmpcodecs/ve_x264.c
+++ /dev/null
@@ -1,308 +0,0 @@
-/*****************************************************************************
- *
- * - H.264 encoder for mencoder using x264 -
- *
- * Copyright (C) 2004 LINUX4MEDIA GmbH
- * Copyright (C) 2004 Ark Linux
- *
- * Written by Bernhard Rosenkraenzer <bero@arklinux.org>
- *
- * 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 <errno.h>
-
-#include "config.h"
-#include "mp_msg.h"
-
-#include "m_option.h"
-#include "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-#include "ve_x264.h"
-
-#include <x264.h>
-
-typedef struct h264_module_t {
- muxer_stream_t *mux;
- x264_t * x264;
- x264_picture_t pic;
-} h264_module_t;
-
-extern char* passtmpfile;
-static int turbo = 0;
-static x264_param_t param;
-static int parse_error = 0;
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts);
-static int encode_frame(struct vf_instance *vf, x264_picture_t *pic_in);
-
-void x264enc_set_param(const m_option_t* opt, char* arg)
-{
- static int initted = 0;
- if(!initted) {
- x264_param_default(&param);
- x264_param_parse(&param, "psnr", "no");
- x264_param_parse(&param, "ssim", "no");
- initted = 1;
- }
-
- if(!arg) {
- parse_error = 1;
- return;
- }
-
- while(*arg) {
- char *name = arg;
- char *value;
- int ret;
-
- arg += strcspn(arg, ":");
- if(*arg) {
- *arg = 0;
- arg++;
- }
-
- value = strchr( name, '=' );
- if(value) {
- *value = 0;
- value++;
- }
-
- if(!strcmp(name, "turbo")) {
- turbo = value ? atoi(value) : 1;
- continue;
- }
-
- ret = x264_param_parse(&param, name, value);
- if(ret == X264_PARAM_BAD_NAME)
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option x264encopts: Unknown suboption %s\n", name);
- if(ret == X264_PARAM_BAD_VALUE)
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option x264encopts: Bad argument %s=%s\n", name, value ? value : "(null)");
-
- /* mark this option as done, so it's not reparsed if there's another -x264encopts */
- *name = 0;
-
- parse_error |= ret;
- }
-
- if(param.rc.b_stat_write && !param.rc.b_stat_read) {
- /* Adjust or disable some flags to gain speed in the first pass */
- if(turbo == 1)
- {
- param.i_frame_reference = ( param.i_frame_reference + 1 ) >> 1;
- param.analyse.i_subpel_refine = FFMAX( FFMIN( 3, param.analyse.i_subpel_refine - 1 ), 1 );
- param.analyse.inter &= ( ~X264_ANALYSE_PSUB8x8 );
- param.analyse.inter &= ( ~X264_ANALYSE_BSUB16x16 );
- param.analyse.i_trellis = 0;
- }
- else if(turbo >= 2)
- {
- param.i_frame_reference = 1;
- param.analyse.i_subpel_refine = 1;
- param.analyse.i_me_method = X264_ME_DIA;
- param.analyse.inter = 0;
- param.analyse.b_transform_8x8 = 0;
- param.analyse.b_weighted_bipred = 0;
- param.analyse.i_trellis = 0;
- }
- }
-}
-
-static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) {
- h264_module_t *mod=(h264_module_t*)vf->priv;
-
- if(parse_error)
- return 0;
-
- mod->mux->bih->biWidth = width;
- mod->mux->bih->biHeight = height;
- mod->mux->bih->biSizeImage = width * height * 3;
- mod->mux->aspect = (float)d_width/d_height;
-
- // make sure param is initialized
- x264enc_set_param(NULL, "");
- param.i_width = width;
- param.i_height = height;
- param.i_fps_num = mod->mux->h.dwRate;
- param.i_fps_den = mod->mux->h.dwScale;
- param.b_vfr_input = 0;
- param.vui.i_sar_width = d_width*height;
- param.vui.i_sar_height = d_height*width;
-
- x264_param_parse(&param, "stats", passtmpfile);
-
- switch(outfmt) {
- case IMGFMT_I420:
- param.i_csp = X264_CSP_I420;
- break;
- case IMGFMT_YV12:
- param.i_csp = X264_CSP_YV12;
- break;
- default:
- mp_msg(MSGT_MENCODER, MSGL_ERR, "Wrong colorspace.\n");
- return 0;
- }
-
- mod->x264 = x264_encoder_open(&param);
- if(!mod->x264) {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "x264_encoder_open failed.\n");
- return 0;
- }
-
- if(!param.b_repeat_headers){
- x264_nal_t *nal;
- int extradata_size, nnal;
-
- extradata_size = x264_encoder_headers(mod->x264, &nal, &nnal);
-
- mod->mux->bih= realloc(mod->mux->bih, sizeof(*mod->mux->bih) + extradata_size);
- memcpy(mod->mux->bih + 1, nal->p_payload, extradata_size);
- mod->mux->bih->biSize= sizeof(*mod->mux->bih) + extradata_size;
- }
-
- if (param.i_bframe > 1 && param.i_bframe_pyramid)
- mod->mux->decoder_delay = 2;
- else
- mod->mux->decoder_delay = param.i_bframe ? 1 : 0;
-
- return 1;
-}
-
-static int control(struct vf_instance *vf, int request, void *data)
-{
- h264_module_t *mod=(h264_module_t*)vf->priv;
- switch(request){
- case VFCTRL_FLUSH_FRAMES:
- while (x264_encoder_delayed_frames(mod->x264) > 0)
- encode_frame(vf, NULL);
- return CONTROL_TRUE;
- default:
- return CONTROL_UNKNOWN;
- }
-}
-
-static int query_format(struct vf_instance *vf, unsigned int fmt)
-{
- switch(fmt) {
- case IMGFMT_I420:
- return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- case IMGFMT_YV12:
- case IMGFMT_422P:
- case IMGFMT_444P:
- case IMGFMT_YVYU:
- case IMGFMT_RGB:
- case IMGFMT_BGR:
- case IMGFMT_BGR32:
- /* These colorspaces are supported, but they'll just have
- * to be converted to I420 internally */
- return 0; /* VFCAP_CSP_SUPPORTED */
- }
- return 0;
-}
-
-static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
- h264_module_t *mod=(h264_module_t*)vf->priv;
- int i;
-
- memset(&mod->pic, 0, sizeof(x264_picture_t));
- mod->pic.img.i_csp=param.i_csp;
- mod->pic.img.i_plane=3;
- for(i=0; i<4; i++) {
- mod->pic.img.plane[i] = mpi->planes[i];
- mod->pic.img.i_stride[i] = mpi->stride[i];
- }
-
- mod->pic.i_type = X264_TYPE_AUTO;
-
- return encode_frame(vf, &mod->pic) >= 0;
-}
-
-static int encode_frame(struct vf_instance *vf, x264_picture_t *pic_in)
-{
- h264_module_t *mod=(h264_module_t*)vf->priv;
- x264_picture_t pic_out;
- x264_nal_t *nal;
- int i_nal;
- int i_size;
-
- i_size = x264_encoder_encode(mod->x264, &nal, &i_nal, pic_in, &pic_out);
-
- if(i_size<0) {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "x264_encoder_encode failed\n");
- return -1;
- }
- if(i_size>0) {
- int keyframe = pic_out.b_keyframe;
- memcpy(mod->mux->buffer, nal->p_payload, i_size);
- muxer_write_chunk(mod->mux, i_size, keyframe?AVIIF_KEYFRAME:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- }
- else
- ++mod->mux->encoder_delay;
-
- return i_size;
-}
-
-static void uninit(struct vf_instance *vf)
-{
- h264_module_t *mod=(h264_module_t*)vf->priv;
- if (mod->x264)
- x264_encoder_close(mod->x264);
-}
-
-static int vf_open(vf_instance_t *vf, char *args) {
- h264_module_t *mod;
-
- vf->config = config;
- vf->default_caps = VFCAP_CONSTANT;
- vf->control = control;
- vf->query_format = query_format;
- vf->put_image = put_image;
- vf->uninit = uninit;
- vf->priv = malloc(sizeof(h264_module_t));
-
- mod=(h264_module_t*)vf->priv;
- mod->mux = (muxer_stream_t*)args;
- mod->mux->bih = calloc(1, sizeof(*mod->mux->bih));
- mod->mux->bih->biSize = sizeof(*mod->mux->bih);
- mod->mux->bih->biPlanes = 1;
- mod->mux->bih->biBitCount = 24;
- mod->mux->bih->biCompression = mmioFOURCC('h', '2', '6', '4');
-
- return 1;
-}
-
-vf_info_t ve_info_x264 = {
- "H.264 encoder",
- "x264",
- "Bernhard Rosenkraenzer <bero@arklinux.org>",
- "(C) 2004 LINUX4MEDIA GmbH; (C) 2004 Ark Linux",
- vf_open
-};
diff --git a/libmpcodecs/ve_x264.h b/libmpcodecs/ve_x264.h
deleted file mode 100644
index 93da150514..0000000000
--- a/libmpcodecs/ve_x264.h
+++ /dev/null
@@ -1,26 +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_X264_H
-#define MPLAYER_X264_H
-
-#include "m_option.h"
-
-void x264enc_set_param(const m_option_t* opt, char* arg);
-
-#endif /* MPLAYER_X264_H */
diff --git a/libmpcodecs/ve_xvid4.c b/libmpcodecs/ve_xvid4.c
deleted file mode 100644
index 778817c25f..0000000000
--- a/libmpcodecs/ve_xvid4.c
+++ /dev/null
@@ -1,1527 +0,0 @@
-/*
- * - XviD 1.x decoder module for mplayer/mencoder -
- *
- * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
- * 2003-2004 Edouard Gomez <ed.gomez@free.fr>
- *
- * 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.
- */
-
-/*****************************************************************************
- * Includes
- ****************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <math.h>
-#include <limits.h>
-#include <time.h>
-
-#include "config.h"
-#include "mp_msg.h"
-
-#include "codec-cfg.h"
-#include "stream/stream.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/muxer.h"
-
-#include "img_format.h"
-#include "mp_image.h"
-#include "vf.h"
-
-#include <xvid.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <limits.h>
-#include <assert.h>
-
-#include "m_option.h"
-#include "libavutil/avutil.h"
-
-#define FINE (!0)
-#define BAD (!FINE)
-
-#define MAX_ZONES 64
-
-// Profile flag definitions
-#define PROFILE_ADAPTQUANT 0x00000001
-#define PROFILE_BVOP 0x00000002
-#define PROFILE_MPEGQUANT 0x00000004
-#define PROFILE_INTERLACE 0x00000008
-#define PROFILE_QPEL 0x00000010
-#define PROFILE_GMC 0x00000020
-#define PROFILE_4MV 0x00000040
-#define PROFILE_DXN 0x00000080
-
-// Reduce code duplication in profiles[] array
-#define PROFILE_S (PROFILE_4MV)
-#define PROFILE_AS (PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_MPEGQUANT|PROFILE_INTERLACE|PROFILE_QPEL|PROFILE_GMC)
-
-typedef const struct
-{
- const char *name; ///< profile name
- int id; ///< mpeg-4 profile id; iso/iec 14496-2:2001 table G-1
- int width; ///< profile width restriction
- int height; ///< profile height restriction
- int fps; ///< profile frame rate restriction
- int max_objects; ///< ??????
- int total_vmv_buffer_sz; ///< macroblock memory; when BVOPS=false, vmv = 2*vcv; when BVOPS=true, vmv = 3*vcv
- int max_vmv_buffer_sz; ///< max macroblocks per vop
- int vcv_decoder_rate; ///< macroblocks decoded per second
- int max_acpred_mbs; ///< percentage
- int max_vbv_size; ///< max vbv size (bits) 16368 bits
- int max_video_packet_length; ///< bits
- int max_bitrate; ///< bits per second
- int vbv_peakrate; ///< max bits over anyone second period; 0=don't care
- int dxn_max_bframes; ///< dxn: max consecutive bframes
- unsigned int flags; ///< flags for allowed options/dxn note the definitions for PROFILE_S and PROFILE_AS
-} profile_t;
-
-// Code taken from XviD VfW source for profile support
-
-/* default vbv_occupancy is (64/170)*vbv_buffer_size */
-
-static const profile_t profiles[] =
-{
- /* name p@l w h fps obj Tvmv vmv vcv ac% vbv pkt bps vbv_peak dbf flags */
- /* unrestricted profile (default) */
- { "unrestricted", 0x00, 0, 0, 0, 0, 0, 0, 0, 100, 0*16368, -1, 0, 0, -1, 0xffffffff & ~PROFILE_DXN },
-
- { "sp0", 0x08, 176, 144, 15, 1, 198, 99, 1485, 100, 10*16368, 2048, 64000, 0, -1, PROFILE_S },
- /* simple@l0: max f_code=1, intra_dc_vlc_threshold=0 */
- /* if ac preidition is used, adaptive quantization must not be used */
- /* <=qcif must be used */
- { "sp1", 0x01, 176, 144, 15, 4, 198, 99, 1485, 100, 10*16368, 2048, 64000, 0, -1, PROFILE_S|PROFILE_ADAPTQUANT },
- { "sp2", 0x02, 352, 288, 15, 4, 792, 396, 5940, 100, 40*16368, 4096, 128000, 0, -1, PROFILE_S|PROFILE_ADAPTQUANT },
- { "sp3", 0x03, 352, 288, 15, 4, 792, 396, 11880, 100, 40*16368, 8192, 384000, 0, -1, PROFILE_S|PROFILE_ADAPTQUANT },
-
- { "asp0", 0xf0, 176, 144, 30, 1, 297, 99, 2970, 100, 10*16368, 2048, 128000, 0, -1, PROFILE_AS },
- { "asp1", 0xf1, 176, 144, 30, 4, 297, 99, 2970, 100, 10*16368, 2048, 128000, 0, -1, PROFILE_AS },
- { "asp2", 0xf2, 352, 288, 15, 4, 1188, 396, 5940, 100, 40*16368, 4096, 384000, 0, -1, PROFILE_AS },
- { "asp3", 0xf3, 352, 288, 30, 4, 1188, 396, 11880, 100, 40*16368, 4096, 768000, 0, -1, PROFILE_AS },
- /* ISMA Profile 1, (ASP) @ L3b (CIF, 1.5 Mb/s) CIF(352x288), 30fps, 1.5Mbps max ??? */
- { "asp4", 0xf4, 352, 576, 30, 4, 2376, 792, 23760, 50, 80*16368, 8192, 3000000, 0, -1, PROFILE_AS },
- { "asp5", 0xf5, 720, 576, 30, 4, 4860, 1620, 48600, 25, 112*16368, 16384, 8000000, 0, -1, PROFILE_AS },
-
- // information provided by DivXNetworks, USA.
- // "DivX Certified Profile Compatibility v1.1", February 2005
- { "dxnhandheld", 0x00, 176, 144, 15, 1, 198, 99, 1485, 100, 32*8192, -1, 537600, 800000, 0, PROFILE_ADAPTQUANT|PROFILE_DXN },
- { "dxnportntsc", 0x00, 352, 240, 30, 1, 990, 330, 36000, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_DXN },
- { "dxnportpal", 0x00, 352, 288, 25, 1, 1188, 396, 36000, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_DXN },
- { "dxnhtntsc", 0x00, 720, 480, 30, 1, 4050, 1350, 40500, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE|PROFILE_DXN },
- { "dxnhtpal", 0x00, 720, 576, 25, 1, 4860, 1620, 40500, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE|PROFILE_DXN },
- { "dxnhdtv", 0x00, 1280, 720, 30, 1,10800, 3600, 108000, 100, 768*8192, -1, 9708400, 16000000, 2, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE|PROFILE_DXN },
-
- { NULL, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000000 },
-};
-
-/**
- * \brief return the pointer to a chosen profile
- * \param str the profile name
- * \return pointer of the appropriate profiles array entry or NULL for a mistyped profile name
- */
-static const profile_t *profileFromName(const char *str)
-{
- profile_t *cur = profiles;
- while (cur->name && strcasecmp(cur->name, str)) cur++;
- if(!cur->name) return NULL;
- return cur;
-}
-
-/*****************************************************************************
- * Configuration options
- ****************************************************************************/
-
-extern char* passtmpfile;
-
-static int xvidenc_bitrate = 0;
-static int xvidenc_pass = 0;
-static float xvidenc_quantizer = 0;
-
-static int xvidenc_packed = 0;
-static int xvidenc_closed_gop = 1;
-static int xvidenc_interlaced = 0;
-static int xvidenc_quarterpel = 0;
-static int xvidenc_gmc = 0;
-static int xvidenc_trellis = 1;
-static int xvidenc_cartoon = 0;
-static int xvidenc_hqacpred = 1;
-static int xvidenc_chromame = 1;
-static int xvidenc_chroma_opt = 0;
-static int xvidenc_vhq = 1;
-static int xvidenc_bvhq = 1;
-static int xvidenc_motion = 6;
-static int xvidenc_turbo = 0;
-static int xvidenc_stats = 0;
-static int xvidenc_max_key_interval = 0; /* Let xvidcore set a 10s interval by default */
-static int xvidenc_frame_drop_ratio = 0;
-static int xvidenc_greyscale = 0;
-static int xvidenc_luminance_masking = 0;
-static int xvidenc_debug = 0;
-static int xvidenc_psnr = 0;
-
-static int xvidenc_max_bframes = 2;
-static int xvidenc_num_threads = 0;
-static int xvidenc_bquant_ratio = 150;
-static int xvidenc_bquant_offset = 100;
-static int xvidenc_bframe_threshold = 0;
-
-static int xvidenc_min_quant[3] = {2, 2, 2};
-static int xvidenc_max_quant[3] = {31, 31, 31};
-static char *xvidenc_intra_matrix_file = NULL;
-static char *xvidenc_inter_matrix_file = NULL;
-static char *xvidenc_quant_method = NULL;
-
-static int xvidenc_cbr_reaction_delay_factor = 0;
-static int xvidenc_cbr_averaging_period = 0;
-static int xvidenc_cbr_buffer = 0;
-
-static int xvidenc_vbr_keyframe_boost = 0;
-static int xvidenc_vbr_overflow_control_strength = 5;
-static int xvidenc_vbr_curve_compression_high = 0;
-static int xvidenc_vbr_curve_compression_low = 0;
-static int xvidenc_vbr_max_overflow_improvement = 5;
-static int xvidenc_vbr_max_overflow_degradation = 5;
-static int xvidenc_vbr_kfreduction = 0;
-static int xvidenc_vbr_kfthreshold = 0;
-static int xvidenc_vbr_container_frame_overhead = 24; /* mencoder uses AVI container */
-
-// commandline profile option string - default to unrestricted
-static char *xvidenc_profile = "unrestricted";
-
-static char *xvidenc_par = NULL;
-static int xvidenc_par_width = 0;
-static int xvidenc_par_height = 0;
-static float xvidenc_dar_aspect = 0.0f;
-static int xvidenc_autoaspect = 0;
-
-static char *xvidenc_zones = NULL; // zones string
-
-const m_option_t xvidencopts_conf[] =
-{
- /* Standard things mencoder should be able to treat directly */
- {"bitrate", &xvidenc_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 1, 2, NULL},
- {"fixed_quant", &xvidenc_quantizer, CONF_TYPE_FLOAT, CONF_RANGE, 1, 31, NULL},
-
- /* Features */
- {"quant_type", &xvidenc_quant_method, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"me_quality", &xvidenc_motion, CONF_TYPE_INT, CONF_RANGE, 0, 6, NULL},
- {"chroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nochroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"chroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nochroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"vhq", &xvidenc_vhq, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL},
- {"bvhq", &xvidenc_bvhq, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
- {"max_bframes", &xvidenc_max_bframes, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
- {"threads", &xvidenc_num_threads, CONF_TYPE_INT, 0, 0, 0, NULL},
- {"bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL},
- {"bquant_offset", &xvidenc_bquant_offset, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL},
- {"bf_threshold", &xvidenc_bframe_threshold, CONF_TYPE_INT, CONF_RANGE, -255, 255, NULL},
- {"qpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"noqpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nogmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"trellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"notrellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"packed", &xvidenc_packed, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nopacked", &xvidenc_packed, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"closed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"noclosed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"interlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nointerlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"cartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nocartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nohq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"frame_drop_ratio", &xvidenc_frame_drop_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
- {"greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL}, /* kept for backward compatibility */
- {"grayscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nogreyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"lumi_mask", &xvidenc_luminance_masking, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"nolumi_mask", &xvidenc_luminance_masking, CONF_TYPE_FLAG, 0, 1, 0, NULL},
- {"turbo", &xvidenc_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"debug", &xvidenc_debug, CONF_TYPE_INT , 0 ,0,-1,NULL},
- {"stats", &xvidenc_stats, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"psnr", &xvidenc_psnr , CONF_TYPE_FLAG, 0, 0, 1, NULL},
-
-
- /* section [quantizer] */
- {"min_iquant", &xvidenc_min_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"max_iquant", &xvidenc_max_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"min_pquant", &xvidenc_min_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"max_pquant", &xvidenc_max_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"min_bquant", &xvidenc_min_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"max_bquant", &xvidenc_max_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
- {"quant_intra_matrix", &xvidenc_intra_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL},
- {"quant_inter_matrix", &xvidenc_inter_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL},
-
- /* section [cbr] */
- {"rc_reaction_delay_factor", &xvidenc_cbr_reaction_delay_factor, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"rc_averaging_period", &xvidenc_cbr_averaging_period, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
- {"rc_buffer", &xvidenc_cbr_buffer, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
-
- /* section [vbr] */
- {"keyframe_boost", &xvidenc_vbr_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"curve_compression_high", &xvidenc_vbr_curve_compression_high, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"curve_compression_low", &xvidenc_vbr_curve_compression_low, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"overflow_control_strength", &xvidenc_vbr_overflow_control_strength, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"max_overflow_improvement", &xvidenc_vbr_max_overflow_improvement, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"max_overflow_degradation", &xvidenc_vbr_max_overflow_degradation, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"kfreduction", &xvidenc_vbr_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
- {"kfthreshold", &xvidenc_vbr_kfthreshold, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
- {"container_frame_overhead", &xvidenc_vbr_container_frame_overhead, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
-
- /* Section Aspect Ratio */
- {"par", &xvidenc_par, CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"par_width", &xvidenc_par_width, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
- {"par_height", &xvidenc_par_height, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
- {"aspect", &xvidenc_dar_aspect, CONF_TYPE_FLOAT, CONF_RANGE, 0.1, 9.99, NULL},
- {"autoaspect", &xvidenc_autoaspect, CONF_TYPE_FLAG, 0, 0, 1, NULL},
- {"noautoaspect", &xvidenc_autoaspect, CONF_TYPE_FLAG, 0, 1, 0, NULL},
-
- /* Section Zones */
- {"zones", &xvidenc_zones, CONF_TYPE_STRING, 0, 0, 0, NULL},
-
- /* section profiles */
- {"profile", &xvidenc_profile, CONF_TYPE_STRING, 0, 0, 0, NULL},
-
- /* End of the config array */
- {NULL, 0, 0, 0, 0, 0, NULL}
-};
-
-/*****************************************************************************
- * Module private data
- ****************************************************************************/
-
-typedef struct xvid_mplayer_module_t
-{
- /* Instance related global vars */
- void *instance;
- xvid_gbl_init_t init;
- xvid_enc_create_t create;
- xvid_enc_frame_t frame;
- xvid_plugin_single_t onepass;
- xvid_plugin_2pass1_t pass1;
- xvid_plugin_2pass2_t pass2;
-
- /* This data must survive local block scope, so here it is */
- xvid_enc_plugin_t plugins[7];
- xvid_enc_zone_t zones[MAX_ZONES];
-
- /* MPEG4 stream buffer */
- muxer_stream_t *mux;
-
- /* Stats accumulators */
- int frames;
- long long sse_y;
- long long sse_u;
- long long sse_v;
-
- /* Min & Max PSNR */
- int min_sse_y;
- int min_sse_u;
- int min_sse_v;
- int min_framenum;
- int max_sse_y;
- int max_sse_u;
- int max_sse_v;
- int max_framenum;
-
- int pixels;
-
- /* DAR/PAR and all that thingies */
- int d_width;
- int d_height;
- FILE *fvstats;
-} xvid_mplayer_module_t;
-
-static int dispatch_settings(xvid_mplayer_module_t *mod);
-static int set_create_struct(xvid_mplayer_module_t *mod);
-static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi);
-static void update_stats(xvid_mplayer_module_t *mod, xvid_enc_stats_t *stats);
-static void print_stats(xvid_mplayer_module_t *mod);
-static void flush_internal_buffers(xvid_mplayer_module_t *mod);
-static const char *par_string(int parcode);
-static const char *errorstring(int err);
-
-/*****************************************************************************
- * Video Filter API function definitions
- ****************************************************************************/
-
-/*============================================================================
- * config
- *==========================================================================*/
-
-static int
-config(struct vf_instance *vf,
- int width, int height, int d_width, int d_height,
- unsigned int flags, unsigned int outfmt)
-{
- int err;
- xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
-
- /* Complete the muxer initialization */
- mod->mux->bih->biWidth = width;
- mod->mux->bih->biHeight = height;
- mod->mux->bih->biSizeImage =
- mod->mux->bih->biWidth * mod->mux->bih->biHeight * 3 / 2;
- mod->mux->aspect = (float)d_width/d_height;
-
- /* Message the FourCC type */
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "videocodec: XviD (%dx%d fourcc=%x [%.4s])\n",
- width, height, mod->mux->bih->biCompression,
- (char *)&mod->mux->bih->biCompression);
-
- /* Total number of pixels per frame required for PSNR */
- mod->pixels = mod->mux->bih->biWidth*mod->mux->bih->biHeight;
-
- /*--------------------------------------------------------------------
- * Dispatch all module settings to XviD structures
- *------------------------------------------------------------------*/
-
- mod->d_width = d_width;
- mod->d_height = d_height;
-
- if(dispatch_settings(mod) == BAD)
- return BAD;
-
- /*--------------------------------------------------------------------
- * Set remaining information in the xvid_enc_create_t structure
- *------------------------------------------------------------------*/
-
- if(set_create_struct(mod) == BAD)
- return BAD;
-
- /*--------------------------------------------------------------------
- * Encoder instance creation
- *------------------------------------------------------------------*/
-
- err = xvid_encore(NULL, XVID_ENC_CREATE, &mod->create, NULL);
-
- if(err<0) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: xvidcore returned a '%s' error\n", errorstring(err));
- return BAD;
- }
-
- /* Store the encoder instance into the private data */
- mod->instance = mod->create.handle;
-
- mod->mux->decoder_delay = mod->create.max_bframes ? 1 : 0;
-
- return FINE;
-}
-
-/*============================================================================
- * uninit
- *==========================================================================*/
-
-static void
-uninit(struct vf_instance *vf)
-{
-
- xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
-
- /* Destroy xvid instance */
- xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL);
-
- /* Display stats (if any) */
- print_stats(mod);
-
- /* Close PSNR file if ever opened */
- if (mod->fvstats) {
- fclose(mod->fvstats);
- mod->fvstats = NULL;
- }
-
- /* Free allocated memory */
- if(mod->frame.quant_intra_matrix)
- free(mod->frame.quant_intra_matrix);
-
- if(mod->frame.quant_inter_matrix)
- free(mod->frame.quant_inter_matrix);
-
- if(mod->mux->bih)
- free(mod->mux->bih);
-
- free(vf->priv);
- vf->priv=NULL;
-
- return;
-}
-
-/*============================================================================
- * control
- *==========================================================================*/
-
-static int
-control(struct vf_instance *vf, int request, void* data)
-{
-xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
-
- switch(request){
- case VFCTRL_FLUSH_FRAMES:
- if(mod)/*paranoid*/
- flush_internal_buffers(mod);
- break;
- }
- return CONTROL_UNKNOWN;
-}
-
-/*============================================================================
- * query_format
- *==========================================================================*/
-
-static int
-query_format(struct vf_instance *vf, unsigned int fmt)
-{
- switch(fmt){
- case IMGFMT_YV12:
- case IMGFMT_IYUV:
- case IMGFMT_I420:
- return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
- case IMGFMT_YUY2:
- case IMGFMT_UYVY:
- return VFCAP_CSP_SUPPORTED;
- }
- return BAD;
-}
-
-/*============================================================================
- * put_image
- *==========================================================================*/
-
-static int
-put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
-{
- int size;
- xvid_enc_stats_t stats;
- xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
-
- /* Prepare the stats */
- memset(&stats,0,sizeof( xvid_enc_stats_t));
- stats.version = XVID_VERSION;
-
- /* -------------------------------------------------------------------
- * Set remaining information in the xvid_enc_frame_t structure
- * NB: all the other struct members were initialized by
- * dispatch_settings
- * -----------------------------------------------------------------*/
-
- if(set_frame_struct(mod, mpi) == BAD)
- return BAD;
-
- /* -------------------------------------------------------------------
- * Encode the frame
- * ---------------------------------------------------------------- */
-
- size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats);
-
- /* Analyse the returned value */
- if(size<0) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: xvidcore returned a '%s' error\n", errorstring(size));
- return BAD;
- }
-
- /* If size is == 0, we're done with that frame */
- if(size == 0) {
- ++mod->mux->encoder_delay;
- return FINE;
- }
-
- /* xvidcore returns stats about encoded frame in an asynchronous way
- * accumulate these stats */
- update_stats(mod, &stats);
-
- /* xvidcore outputed bitstream -- mux it */
- muxer_write_chunk(mod->mux,
- size,
- (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
-
- return FINE;
-}
-
-/*============================================================================
- * vf_open
- *==========================================================================*/
-
-static int
-vf_open(vf_instance_t *vf, char* args)
-{
- xvid_mplayer_module_t *mod;
- xvid_gbl_init_t xvid_gbl_init;
- xvid_gbl_info_t xvid_gbl_info;
-
- /* Setting libmpcodec module API pointers */
- vf->config = config;
- vf->default_caps = VFCAP_CONSTANT;
- vf->control = control;
- vf->uninit = uninit;
- vf->query_format = query_format;
- vf->put_image = put_image;
-
- /* Allocate the private part of the codec module */
- vf->priv = malloc(sizeof(xvid_mplayer_module_t));
- mod = (xvid_mplayer_module_t*)vf->priv;
-
- if(mod == NULL) {
- mp_msg(MSGT_MENCODER,MSGL_ERR,
- "xvid: memory allocation failure (private data)\n");
- return BAD;
- }
-
- /* Initialize the module to zeros */
- memset(mod, 0, sizeof(xvid_mplayer_module_t));
- mod->min_sse_y = mod->min_sse_u = mod->min_sse_v = INT_MAX;
- mod->max_sse_y = mod->max_sse_u = mod->max_sse_v = INT_MIN;
-
- /* Bind the Muxer */
- mod->mux = (muxer_stream_t*)args;
-
- /* Initialize muxer BITMAP header */
- mod->mux->bih = calloc(1, sizeof(*mod->mux->bih));
-
- if(mod->mux->bih == NULL) {
- mp_msg(MSGT_MENCODER,MSGL_ERR,
- "xvid: memory allocation failure (BITMAP header)\n");
- return BAD;
- }
-
- mod->mux->bih->biSize = sizeof(*mod->mux->bih);
- mod->mux->bih->biWidth = 0;
- mod->mux->bih->biHeight = 0;
- mod->mux->bih->biPlanes = 1;
- mod->mux->bih->biBitCount = 12;
- mod->mux->bih->biCompression = mmioFOURCC('X','V','I','D');
-
- /* Retrieve information about the host XviD library */
- memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t));
- xvid_gbl_info.version = XVID_VERSION;
-
- if (xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) {
- mp_msg(MSGT_MENCODER,MSGL_WARN, "xvid: could not get information about the library\n");
- } else {
- mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n",
- XVID_VERSION_MAJOR(xvid_gbl_info.actual_version),
- XVID_VERSION_MINOR(xvid_gbl_info.actual_version),
- XVID_VERSION_PATCH(xvid_gbl_info.actual_version),
- xvid_gbl_info.build);
- }
-
- /* Initialize the xvid_gbl_init structure */
- memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t));
- xvid_gbl_init.version = XVID_VERSION;
- xvid_gbl_init.debug = xvidenc_debug;
-
- /* Initialize the xvidcore library */
- if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) {
- mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n");
- return BAD;
- }
-
- return FINE;
-}
-
-/*****************************************************************************
- * Helper functions
- ****************************************************************************/
-
-static void *read_matrix(unsigned char *filename);
-
-static int dispatch_settings(xvid_mplayer_module_t *mod)
-{
- xvid_enc_create_t *create = &mod->create;
- xvid_enc_frame_t *frame = &mod->frame;
- xvid_plugin_single_t *onepass = &mod->onepass;
- xvid_plugin_2pass2_t *pass2 = &mod->pass2;
- AVRational ar;
-
- const int motion_presets[7] =
- {
- 0,
- 0,
- 0,
- 0,
- XVID_ME_HALFPELREFINE16,
- XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND16,
- XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |
- XVID_ME_HALFPELREFINE8 | XVID_ME_USESQUARES16
- };
-
- //profile is unrestricted as default
- const profile_t *selected_profile = profileFromName("unrestricted");
- if(xvidenc_profile)
- selected_profile = profileFromName(xvidenc_profile);
- if(!selected_profile)
- {
- mp_msg(MSGT_MENCODER,MSGL_ERR,
- "xvid:[ERROR] \"%s\" is an invalid profile name\n", xvidenc_profile);
- return BAD;
- }
-
- /* -------------------------------------------------------------------
- * Dispatch all settings having an impact on the "create" structure
- * This includes plugins as they are passed to encore through the
- * create structure
- * -----------------------------------------------------------------*/
-
- /* -------------------------------------------------------------------
- * The create structure
- * ---------------------------------------------------------------- */
-
- create->global = 0;
-
- if(xvidenc_psnr)
- xvidenc_stats = 1;
-
- if(xvidenc_stats)
- create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE;
-
- create->num_zones = 0;
- create->zones = NULL;
- create->num_plugins = 0;
- create->plugins = NULL;
- create->num_threads = xvidenc_num_threads;
-
- if( (selected_profile->flags & PROFILE_BVOP) &&
- /* dxn: prevent bframes usage if interlacing is selected */
- !((selected_profile->flags & PROFILE_DXN) && xvidenc_interlaced) )
- {
- create->max_bframes = xvidenc_max_bframes;
- create->bquant_ratio = xvidenc_bquant_ratio;
- create->bquant_offset = xvidenc_bquant_offset;
- if(xvidenc_packed)
- create->global |= XVID_GLOBAL_PACKED;
- if(xvidenc_closed_gop)
- create->global |= XVID_GLOBAL_CLOSED_GOP;
-
- /* dxn: restrict max bframes, require closed gop
- and require packed b-frames */
- if(selected_profile->flags & PROFILE_DXN)
- {
- if(create->max_bframes > selected_profile->dxn_max_bframes)
- create->max_bframes = selected_profile->dxn_max_bframes;
- create->global |= XVID_GLOBAL_CLOSED_GOP;
- create->global |= XVID_GLOBAL_PACKED;
- }
- }
- else
- create->max_bframes = 0;
-
-#if XVID_API >= XVID_MAKE_API(4,1)
- /* dxn: always write divx5 userdata */
- if(selected_profile->flags & PROFILE_DXN)
- create->global |= XVID_GLOBAL_DIVX5_USERDATA;
-#endif
-
- create->max_key_interval = xvidenc_max_key_interval;
- create->frame_drop_ratio = xvidenc_frame_drop_ratio;
- create->min_quant[0] = xvidenc_min_quant[0];
- create->min_quant[1] = xvidenc_min_quant[1];
- create->min_quant[2] = xvidenc_min_quant[2];
- create->max_quant[0] = xvidenc_max_quant[0];
- create->max_quant[1] = xvidenc_max_quant[1];
- create->max_quant[2] = xvidenc_max_quant[2];
-
-
- /* -------------------------------------------------------------------
- * The single pass plugin
- * ---------------------------------------------------------------- */
-
- if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate;
- else onepass->bitrate = xvidenc_bitrate*1000;
- onepass->reaction_delay_factor = xvidenc_cbr_reaction_delay_factor;
- onepass->averaging_period = xvidenc_cbr_averaging_period;
- onepass->buffer = xvidenc_cbr_buffer;
-
- /* -------------------------------------------------------------------
- * The pass2 plugin
- * ---------------------------------------------------------------- */
-
- pass2->keyframe_boost = xvidenc_vbr_keyframe_boost;
- pass2->overflow_control_strength = xvidenc_vbr_overflow_control_strength;
- pass2->curve_compression_high = xvidenc_vbr_curve_compression_high;
- pass2->curve_compression_low = xvidenc_vbr_curve_compression_low;
- pass2->max_overflow_improvement = xvidenc_vbr_max_overflow_improvement;
- pass2->max_overflow_degradation = xvidenc_vbr_max_overflow_degradation;
- pass2->kfreduction = xvidenc_vbr_kfreduction;
- pass2->kfthreshold = xvidenc_vbr_kfthreshold;
- pass2->container_frame_overhead = xvidenc_vbr_container_frame_overhead;
-
- /* VBV */
-
-#if XVID_API >= XVID_MAKE_API(4,1)
- pass2->vbv_size = selected_profile->max_vbv_size;
- pass2->vbv_initial = (selected_profile->max_vbv_size*3)>>2; /* 75% */
- pass2->vbv_maxrate = selected_profile->max_bitrate;
- pass2->vbv_peakrate = selected_profile->vbv_peakrate*3;
-#endif
-// XXX: xvidcore currently provides a "peak bits over 3 seconds" constraint.
-// according to the latest dxn literature, a 1 second constraint is now used
-
- create->profile = selected_profile->id;
-
- /* -------------------------------------------------------------------
- * The frame structure
- * ---------------------------------------------------------------- */
- frame->vol_flags = 0;
- frame->vop_flags = 0;
- frame->motion = 0;
-
- frame->vop_flags |= XVID_VOP_HALFPEL;
- frame->motion |= motion_presets[xvidenc_motion];
-
- if(xvidenc_stats)
- frame->vol_flags |= XVID_VOL_EXTRASTATS;
-
- if(xvidenc_greyscale)
- frame->vop_flags |= XVID_VOP_GREYSCALE;
-
- if(xvidenc_cartoon) {
- frame->vop_flags |= XVID_VOP_CARTOON;
- frame->motion |= XVID_ME_DETECT_STATIC_MOTION;
- }
-
- // MPEG quantisation is only supported in ASP and unrestricted profiles
- if((selected_profile->flags & PROFILE_MPEGQUANT) &&
- (xvidenc_quant_method != NULL) &&
- !strcasecmp(xvidenc_quant_method, "mpeg"))
- {
- frame->vol_flags |= XVID_VOL_MPEGQUANT;
- if(xvidenc_intra_matrix_file != NULL) {
- frame->quant_intra_matrix = (unsigned char*)read_matrix(xvidenc_intra_matrix_file);
- if(frame->quant_intra_matrix != NULL) {
- mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: Loaded Intra matrix (switching to mpeg quantization type)\n");
- if(xvidenc_quant_method) free(xvidenc_quant_method);
- xvidenc_quant_method = strdup("mpeg");
- }
- }
- if(xvidenc_inter_matrix_file != NULL) {
- frame->quant_inter_matrix = read_matrix(xvidenc_inter_matrix_file);
- if(frame->quant_inter_matrix) {
- mp_msg(MSGT_MENCODER, MSGL_INFO, "\nxvid: Loaded Inter matrix (switching to mpeg quantization type)\n");
- if(xvidenc_quant_method) free(xvidenc_quant_method);
- xvidenc_quant_method = strdup("mpeg");
- }
- }
- }
- if(xvidenc_quarterpel && (selected_profile->flags & PROFILE_QPEL)) {
- frame->vol_flags |= XVID_VOL_QUARTERPEL;
- frame->motion |= XVID_ME_QUARTERPELREFINE16;
- frame->motion |= XVID_ME_QUARTERPELREFINE8;
- }
- if(xvidenc_gmc && (selected_profile->flags & PROFILE_GMC)) {
- frame->vol_flags |= XVID_VOL_GMC;
- frame->motion |= XVID_ME_GME_REFINE;
- }
- if(xvidenc_interlaced && (selected_profile->flags & PROFILE_INTERLACE)) {
- frame->vol_flags |= XVID_VOL_INTERLACING;
- }
- if(xvidenc_trellis) {
- frame->vop_flags |= XVID_VOP_TRELLISQUANT;
- }
- if(xvidenc_hqacpred) {
- frame->vop_flags |= XVID_VOP_HQACPRED;
- }
- if(xvidenc_chroma_opt) {
- frame->vop_flags |= XVID_VOP_CHROMAOPT;
- }
- if((xvidenc_motion > 4) && (selected_profile->flags & PROFILE_4MV)) {
- frame->vop_flags |= XVID_VOP_INTER4V;
- }
- if(xvidenc_chromame) {
- frame->motion |= XVID_ME_CHROMA_PVOP;
- frame->motion |= XVID_ME_CHROMA_BVOP;
- }
- if(xvidenc_vhq >= 1) {
- frame->vop_flags |= XVID_VOP_MODEDECISION_RD;
- }
- if(xvidenc_vhq >= 2) {
- frame->motion |= XVID_ME_HALFPELREFINE16_RD;
- frame->motion |= XVID_ME_QUARTERPELREFINE16_RD;
- }
- if(xvidenc_vhq >= 3) {
- frame->motion |= XVID_ME_HALFPELREFINE8_RD;
- frame->motion |= XVID_ME_QUARTERPELREFINE8_RD;
- frame->motion |= XVID_ME_CHECKPREDICTION_RD;
- }
- if(xvidenc_vhq >= 4) {
- frame->motion |= XVID_ME_EXTSEARCH_RD;
- }
- if(xvidenc_bvhq >= 1) {
-#if XVID_API >= XVID_MAKE_API(4,1)
- frame->vop_flags |= XVID_VOP_RD_BVOP;
-#endif
- }
- if(xvidenc_turbo) {
- frame->motion |= XVID_ME_FASTREFINE16;
- frame->motion |= XVID_ME_FASTREFINE8;
- frame->motion |= XVID_ME_SKIP_DELTASEARCH;
- frame->motion |= XVID_ME_FAST_MODEINTERPOLATE;
- frame->motion |= XVID_ME_BFRAME_EARLYSTOP;
- }
-
- /* motion level == 0 means no motion search which is equivalent to
- * intra coding only */
- if(xvidenc_motion == 0) {
- frame->type = XVID_TYPE_IVOP;
- } else {
- frame->type = XVID_TYPE_AUTO;
- }
-
- frame->bframe_threshold = xvidenc_bframe_threshold;
-
- /* PAR related initialization */
- frame->par = XVID_PAR_11_VGA; /* Default */
-
- if( !(selected_profile->flags & PROFILE_DXN) )
- {
- if(xvidenc_dar_aspect > 0)
- ar = av_d2q(xvidenc_dar_aspect * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255);
- else if(xvidenc_autoaspect)
- ar = av_d2q((float)mod->d_width / mod->d_height * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255);
- else ar.num = ar.den = 0;
-
- if(ar.den != 0) {
- if(ar.num == 12 && ar.den == 11)
- frame->par = XVID_PAR_43_PAL;
- else if(ar.num == 10 && ar.den == 11)
- frame->par = XVID_PAR_43_NTSC;
- else if(ar.num == 16 && ar.den == 11)
- frame->par = XVID_PAR_169_PAL;
- else if(ar.num == 40 && ar.den == 33)
- frame->par = XVID_PAR_169_NTSC;
- else
- {
- frame->par = XVID_PAR_EXT;
- frame->par_width = ar.num;
- frame->par_height= ar.den;
- }
-
- } else if(xvidenc_par != NULL) {
- if(strcasecmp(xvidenc_par, "pal43") == 0)
- frame->par = XVID_PAR_43_PAL;
- else if(strcasecmp(xvidenc_par, "pal169") == 0)
- frame->par = XVID_PAR_169_PAL;
- else if(strcasecmp(xvidenc_par, "ntsc43") == 0)
- frame->par = XVID_PAR_43_NTSC;
- else if(strcasecmp(xvidenc_par, "ntsc169") == 0)
- frame->par = XVID_PAR_169_NTSC;
- else if(strcasecmp(xvidenc_par, "ext") == 0)
- frame->par = XVID_PAR_EXT;
-
- if(frame->par == XVID_PAR_EXT) {
- if(xvidenc_par_width)
- frame->par_width = xvidenc_par_width;
- else
- frame->par_width = 1;
-
- if(xvidenc_par_height)
- frame->par_height = xvidenc_par_height;
- else
- frame->par_height = 1;
- }
- }
-
- /* Display par information */
- mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: par=%d/%d (%s), displayed=%dx%d, sampled=%dx%d\n",
- ar.num, ar.den, par_string(frame->par),
- mod->d_width, mod->d_height, mod->mux->bih->biWidth, mod->mux->bih->biHeight);
- }
- else
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: par=0/0 (vga11) forced by choosing a DXN profile\n");
- return FINE;
-}
-
-static int set_create_struct(xvid_mplayer_module_t *mod)
-{
- int pass;
- int doZones = 0;
- xvid_enc_create_t *create = &mod->create;
-
- // profile is unrestricted as default
- profile_t *selected_profile = profileFromName("unrestricted");
- if(xvidenc_profile)
- selected_profile = profileFromName(xvidenc_profile);
- if(!selected_profile)
- return BAD;
-
- /* Most of the structure is initialized by dispatch settings, only a
- * few things are missing */
- create->version = XVID_VERSION;
-
- /* Width and Height */
- create->width = mod->mux->bih->biWidth;
- create->height = mod->mux->bih->biHeight;
-
- /* Check resolution of video to be coded is within profile width/height
- restrictions */
- if( ((selected_profile->width != 0) &&
- (mod->mux->bih->biWidth > selected_profile->width)) ||
- ((selected_profile->height != 0) &&
- (mod->mux->bih->biHeight > selected_profile->height)) )
- {
- mp_msg(MSGT_MENCODER,MSGL_ERR,
- "xvid:[ERROR] resolution must be <= %dx%d for the chosen profile\n",
- selected_profile->width, selected_profile->height);
- return BAD;
- }
-
- /* FPS */
- create->fincr = mod->mux->h.dwScale;
- create->fbase = mod->mux->h.dwRate;
-
- // Check frame rate is within profile restrictions
- if( ((float)mod->mux->h.dwRate/(float)mod->mux->h.dwScale > (float)selected_profile->fps) &&
- (selected_profile->fps != 0))
- {
- mp_msg(MSGT_MENCODER,MSGL_ERR,
- "xvid:[ERROR] frame rate must be <= %d for the chosen profile\n",
- selected_profile->fps);
- return BAD;
- }
-
- /* Encodings zones */
- memset(mod->zones, 0, sizeof(mod->zones));
- create->zones = mod->zones;
- create->num_zones = 0;
-
- /* Plugins */
- memset(mod->plugins, 0, sizeof(mod->plugins));
- create->plugins = mod->plugins;
- create->num_plugins = 0;
-
- /* -------------------------------------------------------------------
- * Initialize and bind the right rate controller plugin
- * ---------------------------------------------------------------- */
-
- /* First we try to sort out configuration conflicts */
- if(xvidenc_quantizer != 0 && (xvidenc_bitrate || xvidenc_pass)) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: you can't mix Fixed Quantizer Rate Control"
- " with other Rate Control mechanisms\n");
- return BAD;
- }
-
- if(xvidenc_bitrate != 0 && xvidenc_pass == 1) {
- mp_msg(MSGT_MENCODER, MSGL_WARN,
- "xvid: bitrate setting is ignored during first pass\n");
- }
-
- /* Sort out which sort of pass we are supposed to do
- * pass == 1<<0 CBR
- * pass == 1<<1 Two pass first pass
- * pass == 1<<2 Two pass second pass
- * pass == 1<<3 Constant quantizer
- */
-#define MODE_CBR (1<<0)
-#define MODE_2PASS1 (1<<1)
-#define MODE_2PASS2 (1<<2)
-#define MODE_QUANT (1<<3)
-
- pass = 0;
-
- if(xvidenc_bitrate != 0 && xvidenc_pass == 0)
- pass |= MODE_CBR;
-
- if(xvidenc_pass == 1)
- pass |= MODE_2PASS1;
-
- if(xvidenc_bitrate != 0 && xvidenc_pass == 2)
- pass |= MODE_2PASS2;
-
- if(xvidenc_quantizer != 0 && xvidenc_pass == 0)
- pass |= MODE_QUANT;
-
- /* We must be in at least one RC mode */
- if(pass == 0) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: you must specify one or a valid combination of "
- "'bitrate', 'pass', 'fixed_quant' settings\n");
- return BAD;
- }
-
- /* Sanity checking */
- if(pass != MODE_CBR && pass != MODE_QUANT &&
- pass != MODE_2PASS1 && pass != MODE_2PASS2) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: this code should not be reached - fill a bug "
- "report\n");
- return BAD;
- }
-
- /* This is a single pass encoding: either a CBR pass or a constant
- * quantizer pass */
- if(pass == MODE_CBR || pass == MODE_QUANT) {
- xvid_plugin_single_t *onepass = &mod->onepass;
-
- /* There is not much left to initialize after dispatch settings */
- onepass->version = XVID_VERSION;
- if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate;
- else onepass->bitrate = xvidenc_bitrate*1000;
-
- /* Quantizer mode uses the same plugin, we have only to define
- * a constant quantizer zone beginning at frame 0 */
- if(pass == MODE_QUANT) {
- AVRational squant;
- squant = av_d2q(xvidenc_quantizer,128);
-
- create->zones[create->num_zones].mode = XVID_ZONE_QUANT;
- create->zones[create->num_zones].frame = 0;
- create->zones[create->num_zones].increment = squant.num;
- create->zones[create->num_zones].base = squant.den;
- create->num_zones++;
-
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: Fixed Quant Rate Control -- quantizer=%d/%d=%2.2f\n",
- squant.num,
- squant.den,
- (float)(squant.num)/(float)(squant.den));
-
- } else {
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: CBR Rate Control -- bitrate=%dkbit/s\n",
- xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate);
- doZones = 1;
- }
-
- create->plugins[create->num_plugins].func = xvid_plugin_single;
- create->plugins[create->num_plugins].param = onepass;
- create->num_plugins++;
- }
-
- /* This is the first pass of a Two pass process */
- if(pass == MODE_2PASS1) {
- xvid_plugin_2pass1_t *pass1 = &mod->pass1;
-
- /* There is not much to initialize for this plugin */
- pass1->version = XVID_VERSION;
- pass1->filename = passtmpfile;
-
- create->plugins[create->num_plugins].func = xvid_plugin_2pass1;
- create->plugins[create->num_plugins].param = pass1;
- create->num_plugins++;
-
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: 2Pass Rate Control -- 1st pass\n");
- }
-
- /* This is the second pass of a Two pass process */
- if(pass == MODE_2PASS2) {
- xvid_plugin_2pass2_t *pass2 = &mod->pass2;
-
- /* There is not much left to initialize after dispatch settings */
- pass2->version = XVID_VERSION;
- pass2->filename = passtmpfile;
-
- /* Positive bitrate values are bitrates as usual but if the
- * value is negative it is considered as being a total size
- * to reach (in kilobytes) */
- if(xvidenc_bitrate > 0) {
- if(xvidenc_bitrate > 16000) pass2->bitrate = xvidenc_bitrate;
- else pass2->bitrate = xvidenc_bitrate*1000;
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: 2Pass Rate Control -- 2nd pass -- bitrate=%dkbit/s\n",
- xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate);
- } else {
- pass2->bitrate = xvidenc_bitrate;
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: 2Pass Rate Control -- 2nd pass -- total size=%dkB\n",
- -xvidenc_bitrate);
- }
-
- create->plugins[create->num_plugins].func = xvid_plugin_2pass2;
- create->plugins[create->num_plugins].param = pass2;
- create->num_plugins++;
- doZones = 1;
- }
-
- if(xvidenc_luminance_masking && (selected_profile->flags & PROFILE_ADAPTQUANT)) {
- create->plugins[create->num_plugins].func = xvid_plugin_lumimasking;
- create->plugins[create->num_plugins].param = NULL;
- create->num_plugins++;
- }
-
- // parse zones
- if (xvidenc_zones != NULL && doZones > 0) // do not apply zones in CQ, and first pass mode (xvid vfw doesn't allow them in those modes either)
- {
- char *p;
- int i;
- p = xvidenc_zones;
- create->num_zones = 0; // set the number of zones back to zero, this overwrites the zone defined for CQ - desired because each zone has to be specified on the commandline even in cq mode
- for(i = 0; p; i++)
- {
- int start;
- int q;
- double value;
- char mode;
- int e = sscanf(p, "%d,%c,%lf", &start, &mode, &value); // start,mode(q = constant quant, w = weight),value
- if(e != 3)
- {
- mp_msg(MSGT_MENCODER,MSGL_ERR, "error parsing zones\n");
- return BAD;
- }
- q = (int)(value * 100);
- if (mode == 'q')
- {
- if (q < 200 || q > 3100) // make sure that quantizer is in allowable range
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "zone quantizer must be between 2 and 31\n");
- return BAD;
- }
- else
- {
- create->zones[create->num_zones].mode = XVID_ZONE_QUANT;
- }
- }
- if (mode == 'w')
- {
- if (q < 1 || q > 200)
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "zone weight must be between 1 and 200\n");
- return BAD;
- }
- else
- {
- create->zones[create->num_zones].mode = XVID_ZONE_WEIGHT;
- }
- }
- create->zones[create->num_zones].frame = start;
- create->zones[create->num_zones].increment = q;
- create->zones[create->num_zones].base = 100; // increment is 100 times the actual value
- create->num_zones++;
- if (create->num_zones > MAX_ZONES) // show warning if we have too many zones
- {
- mp_msg(MSGT_MENCODER, MSGL_ERR, "too many zones, zones will be ignored\n");
- }
- p = strchr(p, '/');
- if(p) p++;
- }
- }
- return FINE;
-}
-
-static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi)
-{
- xvid_enc_frame_t *frame = &mod->frame;
-
- /* Most of the initialization is done during dispatch_settings */
- frame->version = XVID_VERSION;
-
- /* Bind output buffer */
- frame->bitstream = mod->mux->buffer;
- frame->length = -1;
-
- /* Frame format */
- switch(mpi->imgfmt) {
- case IMGFMT_YV12:
- case IMGFMT_IYUV:
- case IMGFMT_I420:
- frame->input.csp = XVID_CSP_USER;
- break;
- case IMGFMT_YUY2:
- frame->input.csp = XVID_CSP_YUY2;
- break;
- case IMGFMT_UYVY:
- frame->input.csp = XVID_CSP_UYVY;
- break;
- default:
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: unsupported picture format (%s)!\n",
- vo_format_name(mpi->imgfmt));
- return BAD;
- }
-
- /* Bind source frame */
- frame->input.plane[0] = mpi->planes[0];
- frame->input.plane[1] = mpi->planes[1];
- frame->input.plane[2] = mpi->planes[2];
- frame->input.stride[0] = mpi->stride[0];
- frame->input.stride[1] = mpi->stride[1];
- frame->input.stride[2] = mpi->stride[2];
-
- /* Force the right quantizer -- It is internally managed by RC
- * plugins */
- frame->quant = 0;
-
- return FINE;
-}
-
-static void
-flush_internal_buffers(xvid_mplayer_module_t *mod)
-{
- int size;
- xvid_enc_frame_t *frame = &mod->frame;
-
- if (mod->instance == NULL)
- return; /* encoder not initialized */
-
- /* Init a fake frame to force flushing */
- frame->version = XVID_VERSION;
- frame->bitstream = mod->mux->buffer;
- frame->length = -1;
- frame->input.csp = XVID_CSP_NULL;
- frame->input.plane[0] = NULL;
- frame->input.plane[1] = NULL;
- frame->input.plane[2] = NULL;
- frame->input.stride[0] = 0;
- frame->input.stride[1] = 0;
- frame->input.stride[2] = 0;
- frame->quant = 0;
-
- /* Flush encoder buffers caused by bframes usage */
- do {
- xvid_enc_stats_t stats;
- memset(&stats, 0, sizeof(xvid_enc_stats_t));
- stats.version = XVID_VERSION;
-
- /* Encode internal buffer */
- size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats);
-
- if (size>0) {
- /* Update stats */
- update_stats(mod, &stats);
-
- /* xvidcore outputed bitstream -- mux it */
- muxer_write_chunk(mod->mux, size,
- (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- }
- } while (size>0);
-}
-
-#define SSE2PSNR(sse, nbpixels) \
- ((!(sse)) ? 99.99f : 48.131f - 10*(double)log10((double)(sse)/(double)((nbpixels))))
-static void
-update_stats(xvid_mplayer_module_t *mod, xvid_enc_stats_t *stats)
-{
- if(xvidenc_stats && stats->type > 0) {
- mod->sse_y += stats->sse_y;
- mod->sse_u += stats->sse_u;
- mod->sse_v += stats->sse_v;
-
- if(mod->min_sse_y > stats->sse_y) {
- mod->min_sse_y = stats->sse_y;
- mod->min_sse_u = stats->sse_u;
- mod->min_sse_v = stats->sse_v;
- mod->min_framenum = mod->frames;
- }
-
- if(mod->max_sse_y < stats->sse_y) {
- mod->max_sse_y = stats->sse_y;
- mod->max_sse_u = stats->sse_u;
- mod->max_sse_v = stats->sse_v;
- mod->max_framenum = mod->frames;
- }
-
- if (xvidenc_psnr) {
- if (!mod->fvstats) {
- char filename[20];
- time_t today2;
- struct tm *today;
- today2 = time (NULL);
- today = localtime (&today2);
- sprintf (filename, "psnr_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec);
- mod->fvstats = fopen (filename,"w");
- if (!mod->fvstats) {
- perror ("fopen");
- /* Disable PSNR file output so we don't get here again */
- xvidenc_psnr = 0;
- }
- }
- fprintf (mod->fvstats, "%6d, %2d, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n",
- mod->frames,
- stats->quant,
- stats->length,
- SSE2PSNR (stats->sse_y, mod->pixels),
- SSE2PSNR (stats->sse_u, mod->pixels / 4),
- SSE2PSNR (stats->sse_v, mod->pixels / 4),
- SSE2PSNR (stats->sse_y + stats->sse_u + stats->sse_v,(double)mod->pixels * 1.5),
- stats->type==1?'I':stats->type==2?'P':stats->type==3?'B':stats->type?'S':'?'
- );
- }
- mod->frames++;
- }
-}
-
-static void
-print_stats(xvid_mplayer_module_t *mod)
-{
- if (mod->frames) {
- mod->sse_y /= mod->frames;
- mod->sse_u /= mod->frames;
- mod->sse_v /= mod->frames;
-
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "The value 99.99dB is a special value and represents "
- "the upper range limit\n");
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: Min PSNR Y:%.2f, Cb:%.2f, Cr:%.2f, All:%.2f in frame %d\n",
- SSE2PSNR(mod->max_sse_y, mod->pixels),
- SSE2PSNR(mod->max_sse_u, mod->pixels/4),
- SSE2PSNR(mod->max_sse_v, mod->pixels/4),
- SSE2PSNR(mod->max_sse_y + mod->max_sse_u + mod->max_sse_v, mod->pixels*1.5),
- mod->max_framenum);
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: Average PSNR Y:%.2f, Cb:%.2f, Cr:%.2f, All:%.2f for %d frames\n",
- SSE2PSNR(mod->sse_y, mod->pixels),
- SSE2PSNR(mod->sse_u, mod->pixels/4),
- SSE2PSNR(mod->sse_v, mod->pixels/4),
- SSE2PSNR(mod->sse_y + mod->sse_u + mod->sse_v, mod->pixels*1.5),
- mod->frames);
- mp_msg(MSGT_MENCODER, MSGL_INFO,
- "xvid: Max PSNR Y:%.2f, Cb:%.2f, Cr:%.2f, All:%.2f in frame %d\n",
- SSE2PSNR(mod->min_sse_y, mod->pixels),
- SSE2PSNR(mod->min_sse_u, mod->pixels/4),
- SSE2PSNR(mod->min_sse_v, mod->pixels/4),
- SSE2PSNR(mod->min_sse_y + mod->min_sse_u + mod->min_sse_v, mod->pixels*1.5),
- mod->min_framenum);
- }
-}
-#undef SSE2PSNR
-
-static void *read_matrix(unsigned char *filename)
-{
- int i;
- unsigned char *matrix;
- FILE *input;
-
- /* Allocate matrix space */
- if((matrix = malloc(64*sizeof(unsigned char))) == NULL)
- return NULL;
-
- /* Open the matrix file */
- if((input = fopen(filename, "rb")) == NULL) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: Error opening the matrix file %s\n",
- filename);
- free(matrix);
- return NULL;
- }
-
- /* Read the matrix */
- for(i=0; i<64; i++) {
-
- int value;
-
- /* If fscanf fails then get out of the loop */
- if(fscanf(input, "%d", &value) != 1) {
- mp_msg(MSGT_MENCODER, MSGL_ERR,
- "xvid: Error reading the matrix file %s\n",
- filename);
- free(matrix);
- fclose(input);
- return NULL;
- }
-
- /* Clamp the value to safe range */
- value = (value< 1)?1 :value;
- value = (value>255)?255:value;
- matrix[i] = value;
- }
-
- /* Fills the rest with 1 */
- while(i<64) matrix[i++] = 1;
-
- /* We're done */
- fclose(input);
-
- return matrix;
-
-}
-
-
-static const char *
-par_string(int parcode)
-{
- const char *par_string;
- switch (parcode) {
- case XVID_PAR_11_VGA:
- par_string = "vga11";
- break;
- case XVID_PAR_43_PAL:
- par_string = "pal43";
- break;
- case XVID_PAR_43_NTSC:
- par_string = "ntsc43";
- break;
- case XVID_PAR_169_PAL:
- par_string = "pal169";
- break;
- case XVID_PAR_169_NTSC:
- par_string = "ntsc69";
- break;
- case XVID_PAR_EXT:
- par_string = "ext";
- break;
- default:
- par_string = "unknown";
- break;
- }
- return par_string;
-}
-
-static const char *errorstring(int err)
-{
- const char *error;
- switch(err) {
- case XVID_ERR_FAIL:
- error = "General fault";
- break;
- case XVID_ERR_MEMORY:
- error = "Memory allocation error";
- break;
- case XVID_ERR_FORMAT:
- error = "File format error";
- break;
- case XVID_ERR_VERSION:
- error = "Structure version not supported";
- break;
- case XVID_ERR_END:
- error = "End of stream reached";
- break;
- default:
- error = "Unknown";
- }
-
- return error;
-}
-
-/*****************************************************************************
- * Module structure definition
- ****************************************************************************/
-
-vf_info_t ve_info_xvid = {
- "XviD 1.0 encoder",
- "xvid",
- "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
- "No comment",
- vf_open
-};
-
-
-/* Please do not change that tag comment.
- * arch-tag: 42ccc257-0548-4a3e-9617-2876c4e8ac88 mplayer xvid encoder module */
diff --git a/libmpdemux/muxer.c b/libmpdemux/muxer.c
deleted file mode 100644
index 32ac1bef8c..0000000000
--- a/libmpdemux/muxer.c
+++ /dev/null
@@ -1,167 +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 <inttypes.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "aviheader.h"
-#include "ms_hdr.h"
-
-#include "stream/stream.h"
-#include "muxer.h"
-#include "demuxer.h"
-#include "mp_msg.h"
-#include "stheader.h"
-
-muxer_t *muxer_new_muxer(int type,stream_t *stream){
- muxer_t* muxer=calloc(1,sizeof(muxer_t));
- if(!muxer)
- return NULL;
- muxer->stream = stream;
- switch (type) {
- case MUXER_TYPE_MPEG:
- if(! muxer_init_muxer_mpeg(muxer))
- goto fail;
- break;
- case MUXER_TYPE_RAWVIDEO:
- if(! muxer_init_muxer_rawvideo(muxer))
- goto fail;
- break;
- case MUXER_TYPE_RAWAUDIO:
- if(! muxer_init_muxer_rawaudio(muxer))
- goto fail;
- break;
-#ifdef CONFIG_LIBAVFORMAT
- case MUXER_TYPE_LAVF:
- if(! muxer_init_muxer_lavf(muxer))
- goto fail;
- break;
-#endif
- case MUXER_TYPE_AVI:
- default:
- if(! muxer_init_muxer_avi(muxer))
- goto fail;
- }
- return muxer;
-
-fail:
- free(muxer);
- return NULL;
-}
-
-/* buffer frames until we either:
- * (a) have at least one frame from each stream
- * (b) run out of memory */
-void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts) {
- if(dts == MP_NOPTS_VALUE) dts= s->timer;
- if(pts == MP_NOPTS_VALUE) pts= s->timer; // this is wrong
-
- if (s->muxer->muxbuf_skip_buffer) {
- s->muxer->cont_write_chunk(s, len, flags, dts, pts);
- }
- else {
- int num = s->muxer->muxbuf_num++;
- muxbuf_t *buf, *tmp;
-
- tmp = realloc_struct(s->muxer->muxbuf, (num+1), sizeof(muxbuf_t));
- if(!tmp) {
- mp_tmsg(MSGT_MUXER, MSGL_FATAL, "Muxer frame buffer cannot reallocate memory!\n");
- return;
- }
- s->muxer->muxbuf = tmp;
- buf = s->muxer->muxbuf + num;
-
- /* buffer this frame */
- buf->stream = s;
- buf->dts= dts;
- buf->pts= pts;
- buf->len = len;
- buf->flags = flags;
- buf->buffer = malloc(len);
- if (!buf->buffer) {
- mp_tmsg(MSGT_MUXER, MSGL_FATAL, "Muxer frame buffer cannot allocate memory!\n");
- return;
- }
- memcpy(buf->buffer, s->buffer, buf->len);
- s->muxbuf_seen = 1;
-
- /* see if we need to keep buffering */
- s->muxer->muxbuf_skip_buffer = 1;
- for (num = 0; s->muxer->streams[num]; ++num)
- if (!s->muxer->streams[num]->muxbuf_seen)
- s->muxer->muxbuf_skip_buffer = 0;
-
- /* see if we can flush buffer now */
- if (s->muxer->muxbuf_skip_buffer) {
- mp_tmsg(MSGT_MUXER, MSGL_V, "Muxer frame buffer sending %d frame(s) to the muxer.\n", s->muxer->muxbuf_num);
-
- /* fix parameters for all streams */
- for (num = 0; s->muxer->streams[num]; ++num) {
- muxer_stream_t *str = s->muxer->streams[num];
- if(str->muxer->fix_stream_parameters)
- muxer_stream_fix_parameters(str->muxer, str);
- }
-
- /* write header */
- if (s->muxer->cont_write_header)
- muxer_write_header(s->muxer);
-
- /* send all buffered frames to muxer */
- for (num = 0; num < s->muxer->muxbuf_num; ++num) {
- muxbuf_t tmp_buf;
- buf = s->muxer->muxbuf + num;
- s = buf->stream;
-
- /* 1. save timer and buffer (might have changed by now) */
- tmp_buf.dts = s->timer;
- tmp_buf.buffer = s->buffer;
-
- /* 2. move stored timer and buffer into stream and mux it */
- s->timer = buf->dts;
- s->buffer = buf->buffer;
- s->muxer->cont_write_chunk(s, buf->len, buf->flags, buf->dts, buf->pts);
-
- /* 3. restore saved timer and buffer */
- s->timer = tmp_buf.dts;
- s->buffer = tmp_buf.buffer;
- }
-
- free(s->muxer->muxbuf);
- s->muxer->muxbuf_num = 0;
- }
- }
-
- /* this code moved directly from muxer_avi.c */
- // alter counters:
- if(s->h.dwSampleSize){
- // CBR
- s->h.dwLength+=len/s->h.dwSampleSize;
- if(len%s->h.dwSampleSize) mp_tmsg(MSGT_MUXER, MSGL_WARN, "Warning, len isn't divisible by samplesize!\n");
- } else {
- // VBR
- s->h.dwLength++;
- }
- s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate;
- s->size+=len;
-
- return;
-}
diff --git a/libmpdemux/muxer.h b/libmpdemux/muxer.h
deleted file mode 100644
index 48b132b85f..0000000000
--- a/libmpdemux/muxer.h
+++ /dev/null
@@ -1,143 +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_MUXER_H
-#define MPLAYER_MUXER_H
-
-#include <stdint.h>
-#include <sys/types.h>
-#include "aviheader.h"
-#include "ms_hdr.h"
-#include "stream/stream.h"
-
-#define MUXER_MAX_STREAMS 16
-
-#define MUXER_TYPE_VIDEO 0
-#define MUXER_TYPE_AUDIO 1
-
-#define MUXER_TYPE_AVI 0
-#define MUXER_TYPE_MPEG 1
-#define MUXER_TYPE_RAWVIDEO 2
-#define MUXER_TYPE_LAVF 3
-#define MUXER_TYPE_RAWAUDIO 4
-
-
-typedef struct {
- // muxer data:
- int type; // audio or video
- int id; // stream no
- uint32_t ckid; // chunk id (00dc 01wb etc)
- double timer;
- off_t size;
- float aspect; // aspect ratio of this stream (set by ve_*.c)
- // buffering:
- unsigned char *buffer;
- unsigned int buffer_size;
- unsigned int buffer_len;
- // mpeg block buffer:
- unsigned char *b_buffer;
- unsigned int b_buffer_size; //size of b_buffer
- unsigned int b_buffer_ptr; //index to next data to write
- unsigned int b_buffer_len; //len of next data to write
- // muxer frame buffer:
- unsigned int muxbuf_seen;
- // source stream:
- void* source; // sh_audio or sh_video
- int codec; // codec used for encoding. 0 means copy
- // avi stream header:
- AVIStreamHeader h; // Rate/Scale and SampleSize must be filled by caller!
- // stream specific:
- WAVEFORMATEX *wf;
- BITMAPINFOHEADER *bih; // in format
- int encoder_delay; // in number of frames
- int decoder_delay; // in number of frames
- int imgfmt;
- // mpeg specific:
- size_t ipb[3]; // sizes of I/P/B frames
- // muxer of that stream
- struct muxer_t *muxer;
- void *priv; // private stream specific data stored by the muxer
-
- int vbv_size;
- int max_rate;
- int avg_rate;
-} muxer_stream_t;
-
-typedef struct {
- uint32_t id;
- char *text;
-} muxer_info_t;
-
-typedef struct muxer_t{
- // encoding:
- MainAVIHeader avih;
- off_t movi_start;
- off_t movi_end;
- off_t file_end; // for MPEG it's system timestamp in 1/90000 s
- float audio_delay_fix;
- // index:
- AVIINDEXENTRY *idx;
- int idx_pos;
- int idx_size;
- // streams:
- int num_videos; // for MPEG recalculations
- int num_audios;
- unsigned int sysrate; // max rate in bytes/s
- //int num_streams;
- muxer_stream_t* def_v; // default video stream (for general headers)
- muxer_stream_t* streams[MUXER_MAX_STREAMS];
- // muxer frame buffer:
- struct muxbuf_t * muxbuf;
- int muxbuf_num;
- int muxbuf_skip_buffer;
- // functions:
- stream_t *stream;
- void (*fix_stream_parameters)(muxer_stream_t *);
- void (*cont_write_chunk)(muxer_stream_t *,size_t,unsigned int, double dts, double pts);
- void (*cont_write_header)(struct muxer_t *);
- void (*cont_write_index)(struct muxer_t *);
- muxer_stream_t* (*cont_new_stream)(struct muxer_t *,int);
- void *priv;
-} muxer_t;
-
-/* muxer frame buffer */
-typedef struct muxbuf_t {
- muxer_stream_t *stream; /* pointer back to corresponding stream */
- double dts; /* decode timestamp / time at which this packet should be feeded into the decoder */
- double pts; /* presentation timestamp / time at which the data in this packet will be presented to the user */
- unsigned char *buffer;
- size_t len;
- unsigned int flags;
-} muxbuf_t;
-
-extern char *force_fourcc;
-
-muxer_t *muxer_new_muxer(int type,stream_t *stream);
-#define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a)
-#define muxer_stream_fix_parameters(muxer, a) muxer->fix_stream_parameters(a)
-void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts);
-#define muxer_write_header(muxer) muxer->cont_write_header(muxer)
-#define muxer_write_index(muxer) muxer->cont_write_index(muxer)
-
-int muxer_init_muxer_avi(muxer_t *);
-int muxer_init_muxer_mpeg(muxer_t *);
-int muxer_init_muxer_rawvideo(muxer_t *);
-int muxer_init_muxer_lavf(muxer_t *);
-int muxer_init_muxer_rawaudio(muxer_t *);
-
-#endif /* MPLAYER_MUXER_H */
diff --git a/libmpdemux/muxer_avi.c b/libmpdemux/muxer_avi.c
deleted file mode 100644
index 8017ef611e..0000000000
--- a/libmpdemux/muxer_avi.c
+++ /dev/null
@@ -1,694 +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 <inttypes.h>
-#include <unistd.h>
-#include <limits.h>
-
-#include "config.h"
-#include "mpcommon.h"
-#include "stream/stream.h"
-#include "demuxer.h"
-#include "stheader.h"
-
-#include "muxer.h"
-#include "aviheader.h"
-#include "ms_hdr.h"
-#include "mp_msg.h"
-
-extern char *info_name;
-extern char *info_artist;
-extern char *info_genre;
-extern char *info_subject;
-extern char *info_copyright;
-extern char *info_sourceform;
-extern char *info_comment;
-
-/* #define ODML_CHUNKLEN 0x02000000 */ /* for testing purposes */
-#define ODML_CHUNKLEN 0x40000000
-#define ODML_NOTKEYFRAME 0x80000000U
-#define MOVIALIGN 0x00001000
-
-float avi_aspect_override = -1.0;
-int write_odml = 1;
-
-struct avi_odmlidx_entry {
- uint64_t ofs;
- uint32_t len;
- uint32_t flags;
-};
-
-struct avi_odmlsuperidx_entry {
- uint64_t ofs;
- uint32_t len;
- uint32_t duration;
-};
-
-struct avi_stream_info {
- int idxsize;
- int idxpos;
- int superidxpos;
- int superidxsize;
- int riffofspos;
- int riffofssize;
- off_t *riffofs;
- struct avi_odmlidx_entry *idx;
- struct avi_odmlsuperidx_entry *superidx;
-};
-
-static unsigned int avi_aspect(muxer_stream_t *vstream)
-{
- int x,y;
- float aspect = vstream->aspect;
-
- if (avi_aspect_override > 0.0) {
- aspect = avi_aspect_override;
- }
-
- if (aspect <= 0.0) return 0;
-
- if (aspect > 15.99/9.0 && aspect < 16.01/9.0) {
- return MAKE_AVI_ASPECT(16, 9);
- }
- if (aspect > 3.99/3.0 && aspect < 4.01/3.0) {
- return MAKE_AVI_ASPECT(4, 3);
- }
-
- if (aspect >= 1.0) {
- x = 16384;
- y = (float)x / aspect;
- } else {
- y = 16384;
- x = (float)y * aspect;
- }
-
- return MAKE_AVI_ASPECT(x, y);
-}
-
-static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
- struct avi_stream_info *si;
- muxer_stream_t* s;
- if (!muxer) return NULL;
- if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
- mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n");
- return NULL;
- }
- s=malloc(sizeof(muxer_stream_t));
- memset(s,0,sizeof(muxer_stream_t));
- if(!s) return NULL; // no mem!?
- muxer->streams[muxer->avih.dwStreams]=s;
- s->type=type;
- s->id=muxer->avih.dwStreams;
- s->timer=0.0;
- s->size=0;
- s->muxer=muxer;
- s->priv=si=malloc(sizeof(struct avi_stream_info));
- memset(si,0,sizeof(struct avi_stream_info));
- si->idxsize=256;
- si->idx=calloc(si->idxsize, sizeof(struct avi_odmlidx_entry));
- si->riffofssize=16;
- si->riffofs=calloc((si->riffofssize+1), sizeof(off_t));
- memset(si->riffofs, 0, sizeof(off_t)*si->riffofssize);
-
- switch(type){
- case MUXER_TYPE_VIDEO:
- s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
- s->h.fccType=streamtypeVIDEO;
- if(!muxer->def_v) muxer->def_v=s;
- break;
- case MUXER_TYPE_AUDIO:
- s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'w','b');
- s->h.fccType=streamtypeAUDIO;
- break;
- default:
- mp_msg(MSGT_MUXER, MSGL_WARN, "Warning! unknown stream type: %d\n",type);
- return NULL;
- }
- muxer->avih.dwStreams++;
- return s;
-}
-
-static void write_avi_chunk(stream_t *stream,unsigned int id,int len,void* data){
- int le_len = le2me_32(len);
- int le_id = le2me_32(id);
- stream_write_buffer(stream, &le_id, 4);
- stream_write_buffer(stream, &le_len, 4);
-
-if(len>0){
- if(data){
- // DATA
- stream_write_buffer(stream, data, len);
- if(len&1){ // padding
- unsigned char zerobyte=0;
- stream_write_buffer(stream, &zerobyte, 1);
- }
- } else {
- // JUNK
- char *avi_junk_data="[= MPlayer junk data! =]";
- if(len&1) ++len; // padding
- while(len>0){
- int l=strlen(avi_junk_data);
- if(l>len) l=len;
- stream_write_buffer(stream, avi_junk_data, l);
- len-=l;
- }
- }
-}
-}
-
-static void write_avi_list(stream_t *s,unsigned int id,int len);
-static void avifile_write_standard_index(muxer_t *muxer);
-
-static void avifile_odml_new_riff(muxer_t *muxer)
-{
- struct avi_stream_info *vsi = muxer->def_v->priv;
- uint32_t riff[3];
-
- mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Starting new RIFF chunk at %dMB.\n", (int)(muxer->file_end/1024/1024));
-
- vsi->riffofspos++;
- if (vsi->riffofspos>=vsi->riffofssize) {
- vsi->riffofssize+=16;
- vsi->riffofs=realloc_struct(vsi->riffofs,(vsi->riffofssize+1),sizeof(off_t));
- }
- vsi->riffofs[vsi->riffofspos] = stream_tell(muxer->stream);
-
- /* RIFF/AVIX chunk */
- riff[0]=le2me_32(mmioFOURCC('R','I','F','F'));
- riff[1]=0;
- riff[2]=le2me_32(mmioFOURCC('A','V','I','X'));
- stream_write_buffer(muxer->stream, riff, 12);
-
- write_avi_list(muxer->stream,listtypeAVIMOVIE,0);
-
- muxer->file_end = stream_tell(muxer->stream);
-}
-
-static void avifile_write_header(muxer_t *muxer);
-
-static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
- off_t rifflen;
- muxer_t *muxer=s->muxer;
- struct avi_stream_info *si = s->priv;
- struct avi_stream_info *vsi = muxer->def_v->priv;
- int paddedlen = len + (len&1);
-
- if (s->type == MUXER_TYPE_VIDEO && !s->h.dwSuggestedBufferSize) {
- off_t pos=stream_tell(muxer->stream);
- stream_seek(muxer->stream, 0);
- avifile_write_header(muxer);
- stream_seek(muxer->stream, pos);
- }
- if(index_mode){
- rifflen = muxer->file_end - vsi->riffofs[vsi->riffofspos] - 8;
- if (vsi->riffofspos == 0) {
- rifflen += 8+muxer->idx_pos*sizeof(AVIINDEXENTRY);
- }
- if (rifflen + paddedlen > ODML_CHUNKLEN && write_odml == 1) {
- if (vsi->riffofspos == 0) {
- avifile_write_standard_index(muxer);
- }
- avifile_odml_new_riff(muxer);
- }
-
- if (vsi->riffofspos == 0) {
- // add to the traditional index:
- if(muxer->idx_pos>=muxer->idx_size){
- muxer->idx_size+=256; // 4kB
- muxer->idx=realloc_struct(muxer->idx,muxer->idx_size,16);
- }
- muxer->idx[muxer->idx_pos].ckid=s->ckid;
- muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
- muxer->idx[muxer->idx_pos].dwChunkOffset=muxer->file_end-(muxer->movi_start-4);
- muxer->idx[muxer->idx_pos].dwChunkLength=len;
- ++muxer->idx_pos;
- }
-
- // add to odml index
- if(si->idxpos>=si->idxsize){
- si->idxsize+=256;
- si->idx=realloc_struct(si->idx,si->idxsize,sizeof(*si->idx));
- }
- si->idx[si->idxpos].flags=(flags&AVIIF_KEYFRAME)?0:ODML_NOTKEYFRAME;
- si->idx[si->idxpos].ofs=muxer->file_end;
- si->idx[si->idxpos].len=len;
- ++si->idxpos;
- }
- // write out the chunk:
- write_avi_chunk(muxer->stream,s->ckid,len,s->buffer); /* unsigned char */
-
- if (len > s->h.dwSuggestedBufferSize){
- s->h.dwSuggestedBufferSize = len;
- }
- if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
-
- muxer->file_end += 8 + paddedlen;
-}
-
-static void write_avi_list(stream_t *stream,unsigned int id,int len){
- unsigned int list_id=FOURCC_LIST;
- int le_len;
- int le_id;
- len+=4; // list fix
- list_id = le2me_32(list_id);
- le_len = le2me_32(len);
- le_id = le2me_32(id);
- stream_write_buffer(stream, &list_id, 4);
- stream_write_buffer(stream, &le_len, 4);
- stream_write_buffer(stream, &le_id, 4);
-}
-
-#define WFSIZE(wf) (sizeof(*wf)+(wf)->cbSize)
-
-static void avifile_write_header(muxer_t *muxer){
- uint32_t riff[3];
- unsigned int dmlh[1];
- unsigned int i;
- unsigned int hdrsize;
- muxer_info_t info[16];
- VideoPropHeader vprp;
- uint32_t aspect = avi_aspect(muxer->def_v);
- struct avi_stream_info *vsi = muxer->def_v->priv;
- int isodml = vsi->riffofspos > 0;
-
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing header...\n");
- if (aspect == 0) {
- mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.\n");
- } else {
- mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: vprp aspect is %d:%d.\n", aspect >> 16, aspect & 0xffff);
- }
-
- /* deal with stream delays */
- for (i = 0; muxer->streams[i] && i < MUXER_MAX_STREAMS; ++i) {
- muxer_stream_t *s = muxer->streams[i];
- if (s->type == MUXER_TYPE_AUDIO && muxer->audio_delay_fix > 0.0) {
- s->h.dwStart = muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale + 0.5;
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Setting audio delay to %5.3fs.\n", (float)s->h.dwStart * s->h.dwScale/s->h.dwRate);
- }
- if (s->type == MUXER_TYPE_VIDEO && muxer->audio_delay_fix < 0.0) {
- s->h.dwStart = -muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale + 0.5;
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Setting video delay to %5.3fs.\n", (float)s->h.dwStart * s->h.dwScale/s->h.dwRate);
- }
- }
-
- if (isodml) {
- unsigned int rifflen, movilen;
- int i;
-
- vsi->riffofs[vsi->riffofspos+1] = muxer->file_end;
-
- /* fixup RIFF lengths */
- for (i=0; i<=vsi->riffofspos; i++) {
- rifflen = vsi->riffofs[i+1] - vsi->riffofs[i] - 8;
- movilen = le2me_32(rifflen - 12);
- rifflen = le2me_32(rifflen);
- stream_seek(muxer->stream, vsi->riffofs[i]+4);
- stream_write_buffer(muxer->stream,&rifflen,4);
-
- /* fixup movi length */
- if (i > 0) {
- stream_seek(muxer->stream, vsi->riffofs[i]+16);
- stream_write_buffer(muxer->stream,&movilen,4);
- }
- }
-
- stream_seek(muxer->stream, 12);
- } else {
- // RIFF header:
- riff[0]=mmioFOURCC('R','I','F','F');
- riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize
- riff[2]=formtypeAVI; // 'AVI '
- riff[0]=le2me_32(riff[0]);
- riff[1]=le2me_32(riff[1]);
- riff[2]=le2me_32(riff[2]);
- stream_write_buffer(muxer->stream,&riff,12);
- }
-
- // update AVI header:
- if(muxer->def_v){
- int i;
- muxer->avih.dwMicroSecPerFrame=1000000.0*muxer->def_v->h.dwScale/muxer->def_v->h.dwRate;
-// muxer->avih.dwMaxBytesPerSec=1000000; // dummy!!!!! FIXME
-// muxer->avih.dwPaddingGranularity=2; // ???
- muxer->avih.dwFlags|=AVIF_ISINTERLEAVED|AVIF_TRUSTCKTYPE;
- muxer->avih.dwTotalFrames=0;
- for (i=0; i<muxer->idx_pos; i++) {
- if (muxer->idx[i].ckid == muxer->def_v->ckid)
- muxer->avih.dwTotalFrames++;
- }
-// muxer->avih.dwSuggestedBufferSize=muxer->def_v->h.dwSuggestedBufferSize;
- muxer->avih.dwWidth=muxer->def_v->bih->biWidth;
- muxer->avih.dwHeight=muxer->def_v->bih->biHeight;
- }
-
- // AVI header:
- hdrsize=sizeof(muxer->avih)+8;
- if (isodml) hdrsize+=sizeof(dmlh)+20; // dmlh
- // calc total header size:
- for(i=0;i<muxer->avih.dwStreams;i++){
- muxer_stream_t *s = muxer->streams[i];
- struct avi_stream_info *si = s->priv;
-
- hdrsize+=12; // LIST
- hdrsize+=sizeof(muxer->streams[i]->h)+8; // strh
- switch(muxer->streams[i]->type){
- case MUXER_TYPE_VIDEO:
- hdrsize+=muxer->streams[i]->bih->biSize+8; // strf
- if (aspect != 0) {
- hdrsize+=8+4*(9+8*1); // vprp
- }
- break;
- case MUXER_TYPE_AUDIO:
- hdrsize+=WFSIZE(muxer->streams[i]->wf)+8; // strf
- break;
- }
- if (isodml && si && si->superidx && si->superidxsize) {
- hdrsize += 32 + 16*si->superidxsize; //indx
- }
- }
- write_avi_list(muxer->stream,listtypeAVIHEADER,hdrsize);
-
- le2me_MainAVIHeader(&muxer->avih);
- write_avi_chunk(muxer->stream,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */
- le2me_MainAVIHeader(&muxer->avih);
-
- // stream headers:
- for(i=0;i<muxer->avih.dwStreams;i++){
- muxer_stream_t *s = muxer->streams[i];
- struct avi_stream_info *si = s->priv;
- unsigned int idxhdr[8];
- int j,n;
-
- hdrsize=sizeof(s->h)+8; // strh
- if (si && si->superidx && si->superidxsize) {
- hdrsize += 32 + 16*si->superidxsize; //indx
- }
- switch(s->type){
- case MUXER_TYPE_VIDEO:
- hdrsize+=s->bih->biSize+8; // strf
- s->h.fccHandler = s->bih->biCompression;
- s->h.rcFrame.right = s->bih->biWidth;
- s->h.rcFrame.bottom = s->bih->biHeight;
- if (aspect != 0) {
- // fill out vprp info
- memset(&vprp, 0, sizeof(vprp));
- vprp.dwVerticalRefreshRate = (s->h.dwRate+s->h.dwScale-1)/s->h.dwScale;
- vprp.dwHTotalInT = muxer->avih.dwWidth;
- vprp.dwVTotalInLines = muxer->avih.dwHeight;
- vprp.dwFrameAspectRatio = aspect;
- vprp.dwFrameWidthInPixels = muxer->avih.dwWidth;
- vprp.dwFrameHeightInLines = muxer->avih.dwHeight;
- vprp.nbFieldPerFrame = 1;
- vprp.FieldInfo[0].CompressedBMHeight = muxer->avih.dwHeight;
- vprp.FieldInfo[0].CompressedBMWidth = muxer->avih.dwWidth;
- vprp.FieldInfo[0].ValidBMHeight = muxer->avih.dwHeight;
- vprp.FieldInfo[0].ValidBMWidth = muxer->avih.dwWidth;
- hdrsize+=8+4*(9+8*1); // vprp
- }
- break;
- case MUXER_TYPE_AUDIO:
- hdrsize+=WFSIZE(s->wf)+8; // strf
- s->h.fccHandler = s->wf->wFormatTag;
- break;
- }
-
- write_avi_list(muxer->stream,listtypeSTREAMHEADER,hdrsize);
- le2me_AVIStreamHeader(&s->h);
- write_avi_chunk(muxer->stream,ckidSTREAMHEADER,sizeof(s->h),&s->h); /* AVISTreamHeader */ // strh
- le2me_AVIStreamHeader(&s->h);
-
- switch(s->type){
- case MUXER_TYPE_VIDEO:
-{
- int biSize=s->bih->biSize;
- le2me_BITMAPINFOHEADER(s->bih);
- write_avi_chunk(muxer->stream,ckidSTREAMFORMAT,biSize,s->bih); /* BITMAPINFOHEADER */
- le2me_BITMAPINFOHEADER(s->bih);
-
- if (aspect != 0) {
- int fields = vprp.nbFieldPerFrame;
- le2me_VideoPropHeader(&vprp);
- le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[0]);
- le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[1]);
- write_avi_chunk(muxer->stream,mmioFOURCC('v','p','r','p'),
- sizeof(VideoPropHeader) -
- sizeof(VIDEO_FIELD_DESC)*(2-fields),
- &vprp); /* Video Properties Header */
- }
-}
- break;
- case MUXER_TYPE_AUDIO:
-{
- int wfsize = WFSIZE(s->wf);
- le2me_WAVEFORMATEX(s->wf);
- write_avi_chunk(muxer->stream,ckidSTREAMFORMAT,wfsize,s->wf); /* WAVEFORMATEX */
- le2me_WAVEFORMATEX(s->wf);
-}
- break;
- }
- if (isodml && si && si->superidx && si->superidxsize) {
- n = si->superidxsize;
-
- idxhdr[0] = le2me_32(mmioFOURCC('i', 'n', 'd', 'x'));
- idxhdr[1] = le2me_32(24 + 16*n);
- idxhdr[2] = le2me_32(0x00000004);
- idxhdr[3] = le2me_32(si->superidxpos);
- idxhdr[4] = le2me_32(s->ckid);
- idxhdr[5] = 0;
- idxhdr[6] = 0;
- idxhdr[7] = 0;
-
- stream_write_buffer(muxer->stream,idxhdr,sizeof(idxhdr));
- for (j=0; j<n; j++) {
- struct avi_odmlsuperidx_entry *entry = &si->superidx[j];
- unsigned int data[4];
- data[0] = le2me_32(entry->ofs);
- data[1] = le2me_32(entry->ofs >> 32);
- data[2] = le2me_32(entry->len);
- data[3] = le2me_32(entry->duration);
- stream_write_buffer(muxer->stream,data,sizeof(data));
- }
- }
- }
-
- // ODML
- if (isodml) {
- memset(dmlh, 0, sizeof(dmlh));
- dmlh[0] = le2me_32(muxer->avih.dwTotalFrames);
- write_avi_list(muxer->stream,mmioFOURCC('o','d','m','l'),sizeof(dmlh)+8);
- write_avi_chunk(muxer->stream,mmioFOURCC('d','m','l','h'),sizeof(dmlh),dmlh);
- }
-
-// ============= INFO ===============
-// always include software info
-info[0].id=mmioFOURCC('I','S','F','T'); // Software:
-info[0].text=mencoder_version;
-// include any optional strings
-i=1;
-if(info_name!=NULL){
- info[i].id=mmioFOURCC('I','N','A','M'); // Name:
- info[i++].text=info_name;
-}
-if(info_artist!=NULL){
- info[i].id=mmioFOURCC('I','A','R','T'); // Artist:
- info[i++].text=info_artist;
-}
-if(info_genre!=NULL){
- info[i].id=mmioFOURCC('I','G','N','R'); // Genre:
- info[i++].text=info_genre;
-}
-if(info_subject!=NULL){
- info[i].id=mmioFOURCC('I','S','B','J'); // Subject:
- info[i++].text=info_subject;
-}
-if(info_copyright!=NULL){
- info[i].id=mmioFOURCC('I','C','O','P'); // Copyright:
- info[i++].text=info_copyright;
-}
-if(info_sourceform!=NULL){
- info[i].id=mmioFOURCC('I','S','R','F'); // Source Form:
- info[i++].text=info_sourceform;
-}
-if(info_comment!=NULL){
- info[i].id=mmioFOURCC('I','C','M','T'); // Comment:
- info[i++].text=info_comment;
-}
-info[i].id=0;
-
- hdrsize=0;
- // calc info size:
- for(i=0;info[i].id!=0;i++) if(info[i].text){
- size_t sz=strlen(info[i].text)+1;
- hdrsize+=sz+8+sz%2;
- }
- // write infos:
- if (hdrsize!=0){
- write_avi_list(muxer->stream,mmioFOURCC('I','N','F','O'),hdrsize);
- for(i=0;info[i].id!=0;i++) if(info[i].text){
- write_avi_chunk(muxer->stream,info[i].id,strlen(info[i].text)+1,info[i].text);
- }
- }
-
- // JUNK:
- write_avi_chunk(muxer->stream,ckidAVIPADDING,MOVIALIGN-(stream_tell(muxer->stream)%MOVIALIGN)-8,NULL); /* junk */
- if (!isodml) {
- // 'movi' header:
- write_avi_list(muxer->stream,listtypeAVIMOVIE,muxer->movi_end-stream_tell(muxer->stream)-12);
- } else {
- if (stream_tell(muxer->stream) != MOVIALIGN) {
- mp_msg(MSGT_MUXER, MSGL_ERR, "Opendml superindex is too big for reserved space!\n");
- mp_msg(MSGT_MUXER, MSGL_ERR, "Expected filepos %d, real filepos %ld, missing space %ld\n", MOVIALIGN, stream_tell(muxer->stream), stream_tell(muxer->stream)-MOVIALIGN);
- mp_msg(MSGT_MUXER, MSGL_ERR, "Try increasing MOVIALIGN in libmpdemux/muxer_avi.c\n");
- }
- write_avi_list(muxer->stream,listtypeAVIMOVIE,muxer->movi_end-stream_tell(muxer->stream)-12);
- }
- muxer->movi_start=stream_tell(muxer->stream);
- if (muxer->file_end == 0) muxer->file_end = stream_tell(muxer->stream);
-}
-
-static void avifile_odml_write_index(muxer_t *muxer){
- muxer_stream_t* s;
- struct avi_stream_info *si;
- int i;
-
- for (i=0; i<muxer->avih.dwStreams; i++) {
- int j,k,n,idxpos,len,last,entries_per_subidx;
- unsigned int idxhdr[8];
- s = muxer->streams[i];
- si = s->priv;
-
- /*
- * According to Avery Lee MSMP wants the subidx chunks to have the same size.
- *
- * So this code figures out how many entries we can put into
- * an ix?? chunk, so that each ix?? chunk has the same size and the offsets
- * don't overflow (Using ODML_CHUNKLEN for that is a bit more restrictive
- * than it has to be though).
- */
-
- len = 0;
- n = 0;
- entries_per_subidx = INT_MAX;
- do {
- off_t start = si->idx[0].ofs;
- last = entries_per_subidx;
- for (j=0; j<si->idxpos; j++) {
- len = si->idx[j].ofs - start;
- if(len >= ODML_CHUNKLEN || n >= entries_per_subidx) {
- if (entries_per_subidx > n) {
- entries_per_subidx = n;
- }
- start = si->idx[j].ofs;
- len = 0;
- n = 0;
- }
- n++;
- }
- } while (last != entries_per_subidx);
-
- si->superidxpos = (si->idxpos+entries_per_subidx-1) / entries_per_subidx;
-
- mp_msg(MSGT_MUXER, MSGL_V, "ODML: Stream %d: Using %d entries per subidx, %d entries in superidx\n",
- i, entries_per_subidx, si->superidxpos);
-
- si->superidxsize = si->superidxpos;
- si->superidx = calloc(si->superidxsize, sizeof(*si->superidx));
- memset(si->superidx, 0, sizeof(*si->superidx) * si->superidxsize);
-
- idxpos = 0;
- for (j=0; j<si->superidxpos; j++) {
- off_t start = si->idx[idxpos].ofs;
- int duration;
-
- duration = 0;
- for (k=0; k<entries_per_subidx && idxpos+k<si->idxpos; k++) {
- duration += s->h.dwSampleSize ? si->idx[idxpos+k].len/s->h.dwSampleSize : 1;
- }
-
- idxhdr[0] = le2me_32((s->ckid << 16) | mmioFOURCC('i', 'x', 0, 0));
- idxhdr[1] = le2me_32(24 + 8*k);
- idxhdr[2] = le2me_32(0x01000002);
- idxhdr[3] = le2me_32(k);
- idxhdr[4] = le2me_32(s->ckid);
- idxhdr[5] = le2me_32(start + 8);
- idxhdr[6] = le2me_32((start + 8)>> 32);
- idxhdr[7] = 0; /* unused */
-
- si->superidx[j].len = 32 + 8*k;
- si->superidx[j].ofs = stream_tell(muxer->stream);
- si->superidx[j].duration = duration;
-
- stream_write_buffer(muxer->stream, idxhdr,sizeof(idxhdr));
- for (k=0; k<entries_per_subidx && idxpos<si->idxpos; k++) {
- unsigned int entry[2];
- entry[0] = le2me_32(si->idx[idxpos].ofs - start);
- entry[1] = le2me_32(si->idx[idxpos].len | si->idx[idxpos].flags);
- idxpos++;
- stream_write_buffer(muxer->stream, entry, sizeof(entry));
- }
- }
- }
- muxer->file_end=stream_tell(muxer->stream);
-}
-
-static void avifile_write_standard_index(muxer_t *muxer){
-
- muxer->movi_end=stream_tell(muxer->stream);
- if(muxer->idx && muxer->idx_pos>0){
- int i;
- // fixup index entries:
-// for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
- // write index chunk:
- for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
- write_avi_chunk(muxer->stream,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
- for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
- muxer->avih.dwFlags|=AVIF_HASINDEX;
- }
- muxer->file_end=stream_tell(muxer->stream);
-}
-
-static void avifile_write_index(muxer_t *muxer){
- struct avi_stream_info *vsi = muxer->def_v->priv;
-
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing index...\n");
- if (vsi->riffofspos > 0){
- avifile_odml_write_index(muxer);
- } else {
- avifile_write_standard_index(muxer);
- }
-}
-
-static void avifile_fix_parameters(muxer_stream_t *s){
- /* adjust audio_delay_fix according to individual stream delay */
- if (s->type == MUXER_TYPE_AUDIO)
- s->muxer->audio_delay_fix -= (float)s->decoder_delay * s->h.dwScale/s->h.dwRate;
- if (s->type == MUXER_TYPE_VIDEO)
- s->muxer->audio_delay_fix += (float)s->decoder_delay * s->h.dwScale/s->h.dwRate;
-}
-
-int muxer_init_muxer_avi(muxer_t *muxer){
- muxer->cont_new_stream = &avifile_new_stream;
- muxer->cont_write_chunk = &avifile_write_chunk;
- muxer->cont_write_header = &avifile_write_header;
- muxer->cont_write_index = &avifile_write_index;
- muxer->fix_stream_parameters = &avifile_fix_parameters;
- return 1;
-}
diff --git a/libmpdemux/muxer_lavf.c b/libmpdemux/muxer_lavf.c
deleted file mode 100644
index a4113c7d9a..0000000000
--- a/libmpdemux/muxer_lavf.c
+++ /dev/null
@@ -1,408 +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 <sys/types.h>
-#include <inttypes.h>
-#include <limits.h>
-#include "config.h"
-#include "mp_msg.h"
-
-#include "aviheader.h"
-#include "ms_hdr.h"
-#include "av_opts.h"
-
-#include "stream/stream.h"
-#include "muxer.h"
-#include "demuxer.h"
-#include "stheader.h"
-#include "m_option.h"
-#include "libavformat/avformat.h"
-#include "libavutil/avstring.h"
-
-#include "mp_taglists.h"
-
-enum PixelFormat imgfmt2pixfmt(int fmt);
-
-extern char *info_name;
-extern char *info_artist;
-extern char *info_genre;
-extern char *info_subject;
-extern char *info_copyright;
-extern char *info_sourceform;
-extern char *info_comment;
-
-#define BIO_BUFFER_SIZE 32768
-
-typedef struct {
- //AVInputFormat *avif;
- AVFormatContext *oc;
- ByteIOContext *pb;
- int audio_streams;
- int video_streams;
- int64_t last_pts;
- uint8_t buffer[BIO_BUFFER_SIZE];
-} muxer_priv_t;
-
-typedef struct {
- int64_t last_pts;
- AVStream *avstream;
-} muxer_stream_priv_t;
-
-static char *conf_format = NULL;
-static int mux_rate= 0;
-static int mux_packet_size= 0;
-static float mux_preload= 0.5;
-static float mux_max_delay= 0.7;
-static char *mux_avopt = NULL;
-
-const m_option_t lavfopts_conf[] = {
- {"format", &(conf_format), CONF_TYPE_STRING, 0, 0, 0, NULL},
- {"muxrate", &mux_rate, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
- {"packetsize", &mux_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
- {"preload", &mux_preload, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL},
- {"delay", &mux_max_delay, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL},
- {"o", &mux_avopt, CONF_TYPE_STRING, 0, 0, 0, NULL},
-
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-static int mp_write(void *opaque, uint8_t *buf, int size)
-{
- muxer_t *muxer = opaque;
- return stream_write_buffer(muxer->stream, buf, size);
-}
-
-static int64_t mp_seek(void *opaque, int64_t pos, int whence)
-{
- muxer_t *muxer = opaque;
- if(whence == SEEK_CUR)
- {
- off_t cur = stream_tell(muxer->stream);
- if(cur == -1)
- return -1;
- pos += cur;
- }
- else if(whence == SEEK_END)
- {
- off_t size=0;
- if(stream_control(muxer->stream, STREAM_CTRL_GET_SIZE, &size) == STREAM_UNSUPPORTED || size < pos)
- return -1;
- pos = size - pos;
- }
- mp_msg(MSGT_MUXER, MSGL_DBG2, "SEEK %"PRIu64"\n", (int64_t)pos);
- if(!stream_seek(muxer->stream, pos))
- return -1;
- return 0;
-}
-
-
-static muxer_stream_t* lavf_new_stream(muxer_t *muxer, int type)
-{
- muxer_priv_t *priv = muxer->priv;
- muxer_stream_t *stream;
- muxer_stream_priv_t *spriv;
- AVCodecContext *ctx;
-
- if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO))
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOWN TYPE %d\n", type);
- return NULL;
- }
-
- stream = calloc(1, sizeof(muxer_stream_t));
- if(!stream)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate muxer_stream, EXIT.\n");
- return NULL;
- }
- muxer->streams[muxer->avih.dwStreams] = stream;
- stream->b_buffer = malloc(2048);
- if(!stream->b_buffer)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate b_buffer, EXIT.\n");
- free(stream);
- return NULL;
- }
- stream->b_buffer_size = 2048;
- stream->b_buffer_ptr = 0;
- stream->b_buffer_len = 0;
-
- spriv = calloc(1, sizeof(muxer_stream_priv_t));
- if(!spriv)
- {
- free(stream);
- return NULL;
- }
- stream->priv = spriv;
-
- spriv->avstream = av_new_stream(priv->oc, 1);
- if(!spriv->avstream)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate avstream, EXIT.\n");
- return NULL;
- }
- spriv->avstream->stream_copy = 1;
-
- ctx = spriv->avstream->codec;
- ctx->codec_id = muxer->avih.dwStreams;
- switch(type)
- {
- case MUXER_TYPE_VIDEO:
- ctx->codec_type = CODEC_TYPE_VIDEO;
- break;
- case MUXER_TYPE_AUDIO:
- ctx->codec_type = CODEC_TYPE_AUDIO;
- break;
- }
-
- muxer->avih.dwStreams++;
- stream->muxer = muxer;
- stream->type = type;
- mp_msg(MSGT_MUXER, MSGL_V, "ALLOCATED STREAM N. %d, type=%d\n", muxer->avih.dwStreams, type);
- return stream;
-}
-
-
-static void fix_parameters(muxer_stream_t *stream)
-{
- muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
- AVCodecContext *ctx;
-
- ctx = spriv->avstream->codec;
-
- ctx->bit_rate= stream->avg_rate;
- if(stream->wf && stream->wf->nAvgBytesPerSec && !ctx->bit_rate)
- ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8;
- ctx->rc_buffer_size= stream->vbv_size;
- ctx->rc_max_rate= stream->max_rate;
-
- if(stream->type == MUXER_TYPE_AUDIO)
- {
- ctx->codec_id = mp_av_codec_get_id(mp_wav_taglists, stream->wf->wFormatTag);
-#if 0 //breaks aac in mov at least
- ctx->codec_tag = codec_get_wav_tag(ctx->codec_id);
-#endif
- mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag);
- ctx->sample_rate = stream->wf->nSamplesPerSec;
-// mp_msg(MSGT_MUXER, MSGL_INFO, "stream->h.dwSampleSize: %d\n", stream->h.dwSampleSize);
- ctx->channels = stream->wf->nChannels;
- if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0)
- ctx->frame_size= (stream->h.dwScale * (int64_t)ctx->sample_rate) / stream->h.dwRate;
- mp_msg(MSGT_MUXER, MSGL_V, "MUXER_LAVF(audio stream) frame_size: %d, scale: %u, sps: %u, rate: %u, ctx->block_align = stream->wf->nBlockAlign; %d=%d stream->wf->nAvgBytesPerSec:%d\n",
- ctx->frame_size, stream->h.dwScale, ctx->sample_rate, stream->h.dwRate,
- ctx->block_align, stream->wf->nBlockAlign, stream->wf->nAvgBytesPerSec);
- ctx->block_align = stream->h.dwSampleSize;
- if(stream->wf+1 && stream->wf->cbSize)
- {
- ctx->extradata = av_malloc(stream->wf->cbSize);
- if(ctx->extradata != NULL)
- {
- ctx->extradata_size = stream->wf->cbSize;
- memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size);
- }
- else
- mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! Could not allocate %d bytes for extradata.\n",
- stream->wf->cbSize);
- }
- }
- else if(stream->type == MUXER_TYPE_VIDEO)
- {
- ctx->codec_id = mp_av_codec_get_id(mp_bmp_taglists, stream->bih->biCompression);
- if(ctx->codec_id <= 0 || force_fourcc)
- ctx->codec_tag= stream->bih->biCompression;
- mp_msg(MSGT_MUXER, MSGL_INFO, "VIDEO CODEC ID: %d\n", ctx->codec_id);
- if (stream->imgfmt)
- ctx->pix_fmt = imgfmt2pixfmt(stream->imgfmt);
- ctx->width = stream->bih->biWidth;
- ctx->height = stream->bih->biHeight;
- ctx->bit_rate = 800000;
- ctx->time_base.den = stream->h.dwRate;
- ctx->time_base.num = stream->h.dwScale;
- if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER)))
- {
- ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER);
- ctx->extradata = av_malloc(ctx->extradata_size);
- if(ctx->extradata != NULL)
- memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
- else
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! Could not allocate %d bytes for extradata.\n",
- ctx->extradata_size);
- ctx->extradata_size = 0;
- }
- }
- }
-}
-
-static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags, double dts, double pts)
-{
- muxer_t *muxer = (muxer_t*) stream->muxer;
- muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
- muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
- AVPacket pkt;
-
- if(len)
- {
- av_init_packet(&pkt);
- pkt.size = len;
- pkt.stream_index= spriv->avstream->index;
- pkt.data = stream->buffer;
-
- if(flags & AVIIF_KEYFRAME)
- pkt.flags |= PKT_FLAG_KEY;
- else
- pkt.flags = 0;
-
- pkt.dts = (dts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
- pkt.pts = (pts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
-//fprintf(stderr, "%Ld %Ld id:%d tb:%f %f\n", pkt.dts, pkt.pts, pkt.stream_index, av_q2d(priv->oc->streams[pkt.stream_index]->time_base), stream->timer);
-
- if(av_interleaved_write_frame(priv->oc, &pkt) != 0) //av_write_frame(priv->oc, &pkt)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "Error while writing frame.\n");
- }
- }
-
- return;
-}
-
-
-static void write_header(muxer_t *muxer)
-{
- muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
-
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing header...\n");
- av_write_header(priv->oc);
- muxer->cont_write_header = NULL;
-}
-
-
-static void write_trailer(muxer_t *muxer)
-{
- int i;
- muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
-
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing index...\n");
- av_write_trailer(priv->oc);
- for(i = 0; i < priv->oc->nb_streams; i++)
- {
- av_freep(&(priv->oc->streams[i]));
- }
-
- av_freep(&priv->oc->pb);
-
- av_free(priv->oc);
-}
-
-static void list_formats(void) {
- AVOutputFormat *fmt;
- mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf output formats:\n");
- for (fmt = first_oformat; fmt; fmt = fmt->next)
- mp_msg(MSGT_DEMUX, MSGL_INFO, "%15s : %s\n", fmt->name, fmt->long_name);
-}
-
-extern char *out_filename;
-int muxer_init_muxer_lavf(muxer_t *muxer)
-{
- muxer_priv_t *priv;
- AVOutputFormat *fmt = NULL;
-
- av_register_all();
-
- if (conf_format && strcmp(conf_format, "help") == 0) {
- list_formats();
- return 0;
- }
-
- mp_msg(MSGT_MUXER, MSGL_WARN, "** MUXER_LAVF *****************************************************************\n");
- mp_msg(MSGT_MUXER, MSGL_WARN,
-"REMEMBER: MEncoder's libavformat muxing is presently broken and can generate\n"
-"INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer\n"
-"will play these INCORRECT files as if nothing were wrong!\n"
-"*******************************************************************************\n");
-
- priv = calloc(1, sizeof(muxer_priv_t));
- if(priv == NULL)
- return 0;
-
- priv->oc = av_alloc_format_context();
- if(!priv->oc)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not get format context.\n");
- goto fail;
- }
-
- if(conf_format)
- fmt = guess_format(conf_format, NULL, NULL);
- if(! fmt)
- fmt = guess_format(NULL, out_filename, NULL);
- if(! fmt)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Cannot get specified format.\n");
- goto fail;
- }
- priv->oc->oformat = fmt;
-
-
- if(av_set_parameters(priv->oc, NULL) < 0)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "invalid output format parameters\n");
- goto fail;
- }
- priv->oc->packet_size= mux_packet_size;
- priv->oc->mux_rate= mux_rate;
- priv->oc->preload= (int)(mux_preload*AV_TIME_BASE);
- priv->oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
- if (info_name)
- av_strlcpy(priv->oc->title , info_name, sizeof(priv->oc->title ));
- if (info_artist)
- av_strlcpy(priv->oc->author , info_artist, sizeof(priv->oc->author ));
- if (info_genre)
- av_strlcpy(priv->oc->genre , info_genre, sizeof(priv->oc->genre ));
- if (info_copyright)
- av_strlcpy(priv->oc->copyright, info_copyright, sizeof(priv->oc->copyright));
- if (info_comment)
- av_strlcpy(priv->oc->comment , info_comment, sizeof(priv->oc->comment ));
-
- if(mux_avopt){
- if(parse_avopts(priv->oc, mux_avopt) < 0){
- mp_msg(MSGT_MUXER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal.\n", mux_avopt);
- goto fail;
- }
- }
-
- priv->oc->pb = av_alloc_put_byte(priv->buffer, BIO_BUFFER_SIZE, 1, muxer, NULL, mp_write, mp_seek);
- if ((muxer->stream->flags & MP_STREAM_SEEK) != MP_STREAM_SEEK)
- priv->oc->pb->is_streamed = 1;
-
- muxer->priv = (void *) priv;
- muxer->cont_new_stream = &lavf_new_stream;
- muxer->cont_write_chunk = &write_chunk;
- muxer->cont_write_header = &write_header;
- muxer->cont_write_index = &write_trailer;
- muxer->fix_stream_parameters = &fix_parameters;
- mp_msg(MSGT_MUXER, MSGL_INFO, "OK, exit.\n");
- return 1;
-
-fail:
- free(priv);
- return 0;
-}
diff --git a/libmpdemux/muxer_mpeg.c b/libmpdemux/muxer_mpeg.c
deleted file mode 100644
index daa1f98a0a..0000000000
--- a/libmpdemux/muxer_mpeg.c
+++ /dev/null
@@ -1,2735 +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 <inttypes.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include "config.h"
-#include "mp_msg.h"
-
-#include "aviheader.h"
-#include "ms_hdr.h"
-
-#include "stream/stream.h"
-#include "muxer.h"
-#include "demuxer.h"
-#include "demux_ts.h"
-#include "stheader.h"
-#include "m_option.h"
-#include "aac_hdr.h"
-#include "mpeg_hdr.h"
-#include "mp3_hdr.h"
-
-#ifdef CONFIG_LIBA52
-#include <a52dec/a52.h>
-#endif
-
-#define PACK_HEADER_START_CODE 0x01ba
-#define SYSTEM_HEADER_START_CODE 0x01bb
-#define PSM_START_CODE 0x01bc
-
-#define PES_PRIVATE1 0x01bd
-#define PES_PRIVATE2 0x01bf
-
-#define MUX_MPEG1 1
-#define MUX_MPEG2 2
-
-#define VIDEO_MPEG1 0x10000001
-#define VIDEO_MPEG2 0x10000002
-#define AUDIO_MP2 0x50
-#define AUDIO_MP3 0x55
-#define AUDIO_A52 0x2000
-#define AUDIO_LPCM 0x10001 /* only a placeholder at the moment */
-#define AUDIO_AAC1 0x706D
-//#define AUDIO_AAC2 (short) mmioFOURCC('m','p','4','a')
-#define AUDIO_AAC2 0x504D
-
-#define ASPECT_1_1 1
-#define ASPECT_4_3 2
-#define ASPECT_16_9 3
-#define ASPECT_2_21_1 4
-
-#define FRAMERATE_23976 1
-#define FRAMERATE_24 2
-#define FRAMERATE_25 3
-#define FRAMERATE_2997 4
-#define FRAMERATE_30 5
-#define FRAMERATE_50 6
-#define FRAMERATE_5994 7
-#define FRAMERATE_60 8
-
-static char ftypes[] = {'?', 'I', 'P', 'B'};
-#define FTYPE(x) (ftypes[(x)])
-
-static const char *framerates[] = {
- "unchanged", "23.976", "24", "25", "29.97", "30", "50", "59.94", "60"
-};
-
-static const char *aspect_ratios[] = {
- "unchanged", "1/1", "4/3", "16/9", "2.21/1"
-};
-
-static char *conf_mux = "mpeg2";
-static uint16_t conf_packet_size = 0; //dvd
-static uint32_t conf_muxrate = 0; //kb/s
-static float conf_vaspect = 0;
-static float conf_vframerate = 0;
-static uint32_t conf_vwidth = 0, conf_vheight = 0, conf_panscan_width = 0, conf_panscan_height = 0;
-static uint32_t conf_vbitrate = 0;
-static int conf_init_vpts = 200, conf_init_apts = 200;
-static int conf_ts_allframes = 0;
-static int conf_init_adelay = 0, conf_init_vdelay = 0;
-static int conf_abuf_size = 0;
-static int conf_vbuf_size = 0;
-static int conf_drop = 0;
-static int conf_telecine = 0;
-static int conf_interleaving2 = 0;
-static float conf_telecine_src = 0;
-static float conf_telecine_dest = 0;
-
-enum FRAME_TYPE {
- I_FRAME = 1,
- P_FRAME = 2,
- B_FRAME = 3
-};
-
-typedef struct {
- uint8_t *buffer;
- size_t size;
- size_t alloc_size;
- uint8_t type;
- uint64_t pts, dts, idur;
- uint32_t pos; //start offset for the frame
-} mpeg_frame_t;
-
-typedef struct {
- uint8_t cnt; // how many entries we use
- struct {
- uint8_t id, type;
- uint32_t bufsize;
- uint32_t format;
- } streams[50]; //16 video + 16 audio mpa + 16 audio private + bd/bf for dvd
-} sys_info_t;
-
-typedef struct {
- uint8_t cnt; // how many entries we use
- struct {
- uint8_t id;
- uint8_t type;
- uint32_t format;
- } streams[50]; //16 video + 16 audio mpa + 16 audio private + bd/bf for dvd
-} psm_info_t;
-
-typedef struct {
- int size;
- uint64_t dts;
-} buffer_track_t;
-
-typedef struct {
- uint64_t dts, pts;
- uint64_t frame_dts, frame_pts;
- int len, stflen;
-} pack_stats_t;
-
-typedef struct {
- int mux;
- sys_info_t sys_info;
- psm_info_t psm_info;
- uint16_t packet_size;
- int is_dvd, is_xvcd, is_xsvcd, is_genmpeg1, is_genmpeg2, rawpes, ts_allframes, has_video, has_audio;
- int update_system_header, use_psm;
- off_t headers_size, data_size;
- uint64_t scr;
- uint64_t delta_scr;
- uint64_t last_psm_scr;
- uint32_t muxrate;
- uint8_t *buff;
- uint32_t headers_cnt;
- double init_adelay;
- int drop;
-
- //video patching parameters
- uint8_t vaspect, vframerate;
- uint16_t vwidth, vheight, panscan_width, panscan_height;
- uint32_t vbitrate;
- int patch_seq, patch_sde;
- int psm_streams_cnt;
-
-//2 million frames are enough
-#define MAX_PATTERN_LENGTH 2000000
- uint8_t bff_mask[MAX_PATTERN_LENGTH];
-} muxer_priv_t;
-
-
-typedef struct {
- int has_pts, has_dts, pes_is_aligned, type, min_pes_hlen;
- int delay_rff;
- uint64_t pts, last_pts, last_dts, dts, size, frame_duration, delta_pts, nom_delta_pts, last_saved_pts;
- uint32_t buffer_size;
- double delta_clock, timer;
- int drop_delayed_frames;
- mpeg_frame_t *framebuf;
- uint16_t framebuf_cnt;
- uint16_t framebuf_used;
- int32_t last_tr;
- int max_tr;
- uint8_t id, is_mpeg12, telecine;
- uint64_t vframes;
- int64_t display_frame;
- mp_mpeg_header_t picture;
- int max_buffer_size;
- buffer_track_t *buffer_track;
- int track_pos, track_len, track_bufsize; //pos and len control the array, bufsize is the size of the buffer
- unsigned char *pack;
- int pack_offset, pes_offset, pes_set, payload_offset;
- int frames;
- int last_frame_rest; //the rest of the previous frame
- int is_ready;
- int mpa_layer;
-} muxer_headers_t;
-
-#define PULLDOWN32 1
-#define TELECINE_FILM2PAL 2
-#define TELECINE_DGPULLDOWN 3
-
-const m_option_t mpegopts_conf[] = {
- {"format", &(conf_mux), CONF_TYPE_STRING, M_OPT_GLOBAL, 0 ,0, NULL},
- {"size", &(conf_packet_size), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 0, 65535, NULL},
- {"muxrate", &(conf_muxrate), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 0, 12000000, NULL}, //12 Mb/s
- {"vaspect", &(conf_vaspect), CONF_TYPE_FLOAT, M_OPT_GLOBAL, 0, 0, NULL},
- {"vframerate", &(conf_vframerate), CONF_TYPE_FLOAT, M_OPT_GLOBAL, 0, 0, NULL},
- {"vwidth", &(conf_vwidth), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 1, 4095, NULL},
- {"vheight", &(conf_vheight), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 1, 4095, NULL},
- {"vpswidth", &(conf_panscan_width), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 1, 16383, NULL},
- {"vpsheight", &(conf_panscan_height), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 1, 16383, NULL},
- {"vbitrate", &(conf_vbitrate), CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 1, 104857599, NULL},
- {"vdelay", &conf_init_vdelay, CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 0, 32760, NULL},
- {"adelay", &conf_init_adelay, CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 0, 32760, NULL},
- {"vbuf_size", &conf_vbuf_size, CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 40, 1194, NULL},
- {"abuf_size", &conf_abuf_size, CONF_TYPE_INT, M_OPT_GLOBAL|M_OPT_RANGE, 4, 64, NULL},
- {"drop", &conf_drop, CONF_TYPE_FLAG, M_OPT_GLOBAL, 0, 1, NULL},
- {"tsaf", &conf_ts_allframes, CONF_TYPE_FLAG, M_OPT_GLOBAL, 0, 1, NULL},
- {"telecine", &conf_telecine, CONF_TYPE_FLAG, M_OPT_GLOBAL, 0, PULLDOWN32, NULL},
- {"interleaving2", &conf_interleaving2, CONF_TYPE_FLAG, M_OPT_GLOBAL, 0, 1, NULL},
- {"film2pal", &conf_telecine, CONF_TYPE_FLAG, M_OPT_GLOBAL, 0, TELECINE_FILM2PAL, NULL},
- {"tele_src", &(conf_telecine_src), CONF_TYPE_FLOAT, M_OPT_GLOBAL, 0, 0, NULL},
- {"tele_dest", &(conf_telecine_dest), CONF_TYPE_FLOAT, M_OPT_GLOBAL, 0, 0, NULL},
- {NULL, NULL, 0, 0, 0, 0, NULL}
-};
-
-static void fix_audio_sys_header(muxer_priv_t *priv, uint8_t id, uint8_t newid, uint32_t size)
-{
- uint8_t i;
-
- for(i = 0; i < priv->sys_info.cnt; i++)
- {
- if(priv->sys_info.streams[i].id == id)
- {
- priv->sys_info.streams[i].id = newid;
- priv->sys_info.streams[i].type = 1;
- priv->sys_info.streams[i].bufsize = size;
- }
- }
-}
-
-static inline int is_mpeg1(uint32_t x)
-{
- return
- (x == 0x10000001) ||
- (x == mmioFOURCC('m','p','g','1')) ||
- (x == mmioFOURCC('M','P','G','1'));
-}
-
-static inline int is_mpeg2(uint32_t x)
-{
- return
- (x == 0x10000002) ||
- (x == mmioFOURCC('m','p','g','2')) ||
- (x == mmioFOURCC('M','P','G','2')) ||
- (x == mmioFOURCC('m','p','e','g')) ||
- (x == mmioFOURCC('M','P','E','G'));
-}
-
-static inline int is_mpeg4(uint32_t x)
-{
- return
- (x == 0x10000004) ||
- (x == mmioFOURCC('d','i','v','x')) ||
- (x == mmioFOURCC('D','I','V','X')) ||
- (x == mmioFOURCC('x','v','i','d')) ||
- (x == mmioFOURCC('X','V','I','D')) ||
- (x == mmioFOURCC('X','v','i','D')) ||
- (x == mmioFOURCC('x','v','i','x')) ||
- (x == mmioFOURCC('X','V','I','X')) ||
- (x == mmioFOURCC('m','p','4','v')) ||
- (x == mmioFOURCC('M','P','4','V')) ||
- (x == mmioFOURCC('F', 'M','P','4')) ||
- (x == mmioFOURCC('f', 'm','p','4')) ||
- (x == mmioFOURCC('D', 'X','5','0')) ||
- (x == mmioFOURCC('d', 'x','5','0'));
-}
-
-//from unrarlib.c
-static uint32_t CalcCRC32(uint8_t *buff, uint32_t size)
-{
- uint32_t i, j, CRCTab[256], crc;
-
- for(i = 0;i < 256; i++)
- {
- for(crc = i, j = 0; j < 8; j++)
- crc= (crc & 1) ? (crc >> 1)^0xEDB88320L : (crc >> 1);
- CRCTab[i] = crc;
- }
-
-
- crc = 0xffffffff;
- for(i = 0; i < size; i++)
- crc = (crc << 8) ^ CRCTab[((crc >> 24) ^ buff[i]) & 0xff];
-
- return crc;
-}
-
-
-static void add_to_psm(muxer_priv_t *priv, uint8_t id, uint32_t format)
-{
- uint8_t i;
-
- i = priv->psm_info.cnt;
- priv->psm_info.streams[i].id = id;
- priv->psm_info.streams[i].format = format;
-
- if(is_mpeg1(format))
- priv->psm_info.streams[i].type = 0x01;
- else if(is_mpeg2(format))
- priv->psm_info.streams[i].type = 0x02;
- else if(is_mpeg4(format))
- priv->psm_info.streams[i].type = 0x10;
- else if(format == AUDIO_MP2 || format == AUDIO_MP3)
- priv->psm_info.streams[i].type = 0x03;
- else if(format == AUDIO_AAC1 || format == AUDIO_AAC2)
- priv->psm_info.streams[i].type = 0x0f;
- else
- priv->psm_info.streams[i].type = 0x81;
-
- if(format == AUDIO_A52)
- memcpy((char*) &(priv->psm_info.streams[i].format), "AC-3", 4);
-
- priv->psm_info.cnt++;
-}
-
-
-static mpeg_frame_t *init_frames(uint16_t num, size_t size)
-{
- mpeg_frame_t *tmp;
- uint16_t i;
-
- tmp = calloc(num, sizeof(mpeg_frame_t));
- if(tmp == NULL)
- return NULL;
-
- for(i=0; i < num; i++)
- {
- tmp[i].buffer = calloc(1, size);
- if(tmp[i].buffer == NULL)
- return NULL;
- tmp[i].size = 0;
- tmp[i].pos = 0;
- tmp[i].alloc_size = size;
- tmp[i].pts = 0;
- }
-
- return tmp;
-}
-
-static int add_frame(muxer_headers_t *spriv, uint64_t idur, uint8_t *ptr, int len, uint8_t pt, uint64_t dts, uint64_t pts);
-
-static muxer_stream_t* mpegfile_new_stream(muxer_t *muxer,int type){
- muxer_priv_t *priv = (muxer_priv_t*) muxer->priv;
- muxer_stream_t *s;
- muxer_headers_t *spriv;
-
- if (!muxer) return NULL;
- if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
- mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n");
- return NULL;
- }
- switch (type) {
- case MUXER_TYPE_VIDEO:
- if (muxer->num_videos >= 16) {
- mp_msg(MSGT_MUXER, MSGL_ERR, "MPEG files can't contain more than 16 video streams!\n");
- return NULL;
- }
- break;
- case MUXER_TYPE_AUDIO:
- if (muxer->num_audios >= 16) {
- mp_msg(MSGT_MUXER, MSGL_ERR, "MPEG files can't contain more than 16 audio streams!\n");
- return NULL;
- }
- break;
- default:
- mp_msg(MSGT_MUXER, MSGL_ERR, "Unknown stream type!\n");
- return NULL;
- }
- s = calloc(1, sizeof(muxer_stream_t));
- if(!s) return NULL; // no mem!?
- if (!(s->b_buffer = malloc(priv->packet_size)))
- goto init_fail;
- s->b_buffer_size = priv->packet_size;
- s->b_buffer_ptr = 0;
- s->b_buffer_len = 0;
- s->priv = calloc(1, sizeof(muxer_headers_t));
- if(s->priv == NULL)
- goto init_fail;
- spriv = (muxer_headers_t *) s->priv;
- spriv->pack = malloc(priv->packet_size);
- if(! spriv->pack)
- goto init_fail;
- spriv->buffer_track = calloc(1, 4096*sizeof(buffer_track_t));
- if(!spriv->buffer_track)
- goto init_fail;
- spriv->track_pos = 0;
- spriv->track_len = 4096;
- muxer->streams[muxer->avih.dwStreams]=s;
- s->type=type;
- s->id=muxer->avih.dwStreams;
- s->muxer=muxer;
-
- if (type == MUXER_TYPE_VIDEO) {
- spriv->type = 1;
- spriv->last_pts = conf_init_vpts * 90 * 300;
- if(conf_init_vdelay) {
- spriv->last_dts += conf_init_vdelay * 90 * 300;
- spriv->last_pts += conf_init_vdelay * 90 * 300;
- }
- spriv->id = 0xe0 + muxer->num_videos;
- s->ckid = be2me_32 (0x100 + spriv->id);
- if(priv->is_genmpeg1 || priv->is_genmpeg2) {
- int v = (conf_vbuf_size ? conf_vbuf_size*1024 :
- (s->h.dwSuggestedBufferSize ? s->h.dwSuggestedBufferSize : 46*1024));
- int n = priv->sys_info.cnt;
-
- priv->sys_info.streams[n].id = spriv->id;
- priv->sys_info.streams[n].type = 1;
- priv->sys_info.streams[n].bufsize = v;
- priv->sys_info.cnt++;
- }
- muxer->num_videos++;
- priv->has_video++;
- s->h.fccType=streamtypeVIDEO;
- if(!muxer->def_v) muxer->def_v=s;
- spriv->framebuf_cnt = 30;
- spriv->framebuf_used = 0;
- spriv->framebuf = init_frames(spriv->framebuf_cnt, (size_t) 5000);
- if(spriv->framebuf == NULL) {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't allocate initial frames structure, abort!\n");
- goto init_fail;
- }
- memset(&(spriv->picture), 0, sizeof(spriv->picture));
- if(priv->is_xvcd)
- spriv->min_pes_hlen = 18;
- else if(priv->is_xsvcd)
- spriv->min_pes_hlen = 22;
- spriv->telecine = conf_telecine;
- mp_msg (MSGT_MUXER, MSGL_DBG2, "Added video stream %d, ckid=%X\n", muxer->num_videos, s->ckid);
- } else { // MUXER_TYPE_AUDIO
- spriv->type = 0;
- spriv->drop_delayed_frames = conf_drop;
- spriv->last_pts = conf_init_apts * 90 * 300;
- if(conf_init_adelay && ! spriv->drop_delayed_frames)
- spriv->last_pts += conf_init_adelay * 90 * 300;
- spriv->pts = spriv->last_pts;
- spriv->id = 0xc0 + muxer->num_audios;
- s->ckid = be2me_32 (0x100 + spriv->id);
- if(priv->is_genmpeg1 || priv->is_genmpeg2) {
- int a1 = (conf_abuf_size ? conf_abuf_size*1024 :
- (s->h.dwSuggestedBufferSize ? s->h.dwSuggestedBufferSize : 4*1024));
- int n = priv->sys_info.cnt;
-
- priv->sys_info.streams[n].id = spriv->id;
- priv->sys_info.streams[n].type = 0;
- priv->sys_info.streams[n].bufsize = a1;
- priv->sys_info.cnt++;
- }
- if(priv->is_xvcd)
- spriv->min_pes_hlen = 13;
- else if(priv->is_xsvcd)
- spriv->min_pes_hlen = 17;
-
- muxer->num_audios++;
- priv->has_audio++;
- s->h.fccType=streamtypeAUDIO;
-
- spriv->framebuf_cnt = 30;
- spriv->framebuf_used = 0;
- spriv->framebuf = init_frames(spriv->framebuf_cnt, (size_t) 2048);
- if(spriv->framebuf == NULL) {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't allocate initial frames structure, abort!\n");
- goto init_fail;
- }
-
- mp_msg (MSGT_MUXER, MSGL_DBG2, "Added audio stream %d, ckid=%X\n", s->id - muxer->num_videos + 1, s->ckid);
- }
- muxer->avih.dwStreams++;
- return s;
-
-init_fail:
- if(s)
- {
- if(s->priv)
- {
- spriv = s->priv;
- if(spriv->pack)
- free(spriv->pack);
- if(spriv->buffer_track)
- free(spriv->buffer_track);
- free(s->priv);
- }
- if(s->b_buffer)
- free(s->b_buffer);
- free(s);
- }
- return NULL;
-}
-
-static void write_mpeg_ts(unsigned char *b, uint64_t ts, uint8_t mod) {
- ts /= 300;
- b[0] = mod | ((ts >> 29) & 0xf) | 1;
- b[1] = (ts >> 22) & 0xff;
- b[2] = ((ts >> 14) & 0xff) | 1;
- b[3] = (ts >> 7) & 0xff;
- b[4] = ((ts << 1) & 0xff) | 1;
-}
-
-
-static void write_mpeg_rate(int type, unsigned char *b, unsigned int rate)
-{
- rate = ((rate*8)+399) / 400;
-
- if(type == MUX_MPEG1)
- {
- b[0] = ((rate >> 15) & 0x7f) | 0x80;
- b[1] = (rate >> 7) & 0xff;
- b[2] = ((rate << 1) & 0xff) | 1;
- }
- else
- {
- b[0] = (rate >> 14);
- b[1] = (rate >> 6) & 0xff;
- b[2] = ((rate & 0x3f) << 2) | 0x03;
- }
-}
-
-
-static void write_mpeg_std(unsigned char *b, unsigned int size, unsigned int type, uint8_t mod)
-{
- //type = 0:mpeg audio/128, 1:video and pes private streams (including ac3/dts/lpcm)/1024
- if(type == 0) //audio
- size = (size + 127) / 128;
- else //video or other
- size = ((size + 1023) / 1024);
-
- if(! size)
- size++;
-
- b[0] = ((size >> 8) & 0x3f) | (type==1 ? 0x60 : 0x40) | mod;
- b[1] = size & 0xff;
-}
-
-static void write_mpeg2_scr(unsigned char *b, uint64_t ts)
-{
- uint16_t t1, t2, t3, scr_ext;
- scr_ext = ts % 300ULL;
- ts /= 300ULL;
- ts &= 0x1FFFFFFFFULL; //33 bits
- t1 = (ts >> 30) & 0x7;
- t2 = (ts >> 15) & 0x7fff;
- t3 = ts & 0x7fff;
-
- b[0] = (t1 << 3 ) | 0x44 | ((t2 >> 13) & 0x3);
- b[1] = (t2 >> 5);
- b[2] = (t2 & 0x1f) << 3 | 0x4 | ((t3 >> 13) & 0x3);
- b[3] = (t3 >> 5);
- b[4] = (t3 & 0x1f) << 3 | ((scr_ext >> 7) & 0x03) | 0x4;
- b[5] = ((scr_ext << 1) & 0xFF) | 1;
-}
-
-
-static int write_mpeg_pack_header(muxer_t *muxer, char *buff)
-{
- int len;
- muxer_priv_t *priv;
-
- priv = (muxer_priv_t *) muxer->priv;
- *(uint32_t *)buff = be2me_32(PACK_HEADER_START_CODE);
- if(priv->mux==MUX_MPEG1)
- {
- write_mpeg_ts(&buff[4], priv->scr, 0x20); // 0010 and SCR
- write_mpeg_rate(priv->mux, &buff[9], muxer->sysrate);
- len = 12;
- }
- else
- {
- write_mpeg2_scr(&buff[4], priv->scr); // 0010 and SCR
- write_mpeg_rate(priv->mux, &buff[10], muxer->sysrate);
- buff[13] = 0xf8; //5 bits reserved + 3 set to 0 to indicate 0 stuffing bytes
- len = 14;
- }
-
- return len;
-}
-
-
-static int write_mpeg_system_header(muxer_t *muxer, char *buff)
-{
- int len;
- uint8_t i;
- muxer_priv_t *priv;
- priv = (muxer_priv_t *) muxer->priv;
-
- len = 0;
- *(uint32_t *)(&buff[len]) = be2me_32(SYSTEM_HEADER_START_CODE);
- len += 4;
- *(uint16_t *)(&buff[len]) = 0; //fake length, we'll fix it later
- len += 2;
- write_mpeg_rate(MUX_MPEG1, &buff[len], muxer->sysrate);
- len += 3;
-
- buff[len++] = 0x4 | (priv->is_xvcd ? 1 : 0); //1 audio stream bound, no fixed, CSPS only for xvcd
- //stolen from libavformat
- if(priv->is_xvcd || priv->is_dvd)
- buff[len++] = 0xe1; //system_audio_lock, system_video_lock, marker, 1 video stream bound
- else
- buff[len++] = 0x21; //marker, 1 video stream bound
-
- buff[len++] = ((priv->mux == MUX_MPEG1) ? 0xff : 0x7f); //in mpeg2 there's the packet rate restriction
-
- for(i = 0; i < priv->sys_info.cnt; i++)
- {
- buff[len++] = priv->sys_info.streams[i].id;
- write_mpeg_std(&buff[len], priv->sys_info.streams[i].bufsize, priv->sys_info.streams[i].type,
- (priv->sys_info.streams[i].type == 1 ? 0xe0: 0xc0));
- len += 2;
- }
-
- *(uint16_t *)(&buff[4]) = be2me_16(len - 6); // length field fixed
-
- return len;
-}
-
-static int write_mpeg_psm(muxer_t *muxer, char *buff)
-{
- int len;
- uint8_t i;
- uint16_t dlen;
- muxer_priv_t *priv;
- priv = (muxer_priv_t *) muxer->priv;
-
- len = 0;
- *(uint32_t *)(&buff[len]) = be2me_32(PSM_START_CODE);
- len += 4;
- *(uint16_t *)(&buff[len]) = 0; //fake length, we'll fix it later
- len += 2;
- buff[len++] = 0xe0; //1 current, 2 bits reserved, 5 version 0
- buff[len++] = 0xff; //7 reserved, 1 marker
- buff[len] = buff[len+1] = 0; //length of the program descriptors (unused)
- len += 2;
- *(uint16_t *)(&buff[len]) = 0; //length of the es descriptors
- len += 2;
-
- dlen = 0;
- for(i = 0; i < priv->psm_info.cnt; i++)
- {
- if(
- (priv->psm_info.streams[i].id == 0xbd) ||
- (priv->psm_info.streams[i].id >= 0xe0 && priv->psm_info.streams[i].id <= 0xef) ||
- (priv->psm_info.streams[i].id >= 0xc0 && priv->psm_info.streams[i].id <= 0xcf)
- )
- {
- buff[len++] = priv->psm_info.streams[i].type;
- buff[len++] = priv->psm_info.streams[i].id;
- buff[len++] = 0; //len of descriptor upper ...
- buff[len++] = 0; //... lower
-
- dlen += 4;
- }
- }
- *(uint16_t *)(&buff[10]) = be2me_16(dlen); //length of the es descriptors
-
- *(uint16_t *)(&buff[4]) = be2me_16(len - 6 + 4); // length field fixed, including size of CRC32
-
- *(uint32_t *)(&buff[len]) = be2me_32(CalcCRC32(buff, len));
-
- len += 4; //for crc
-
- return len;
-}
-
-static int psm_is_late(muxer_priv_t *priv)
-{
- return !priv->data_size || (priv->scr >= priv->last_psm_scr + 27000000ULL);
-}
-
-static int write_mpeg_pes_header(muxer_headers_t *h, uint8_t *pes_id, uint8_t *buff, uint16_t plen, int stuffing_len, int mux_type)
-{
- int len;
-
- len = 0;
- memcpy(&buff[len], pes_id, 4);
- len += 4;
-
- buff[len] = buff[len+1] = 0; //fake len
- len += 2;
-
- if(mux_type == MUX_MPEG1)
- {
- if(stuffing_len > 0)
- {
- memset(&buff[len], 0xff, stuffing_len);
- len += stuffing_len;
- }
-
- if(h->buffer_size > 0)
- {
- write_mpeg_std(&buff[len], h->buffer_size, h->type, 0x40); // 01 is pes1 format
- len += 2;
- }
- }
- else //MPEG2
- {
- buff[len] = (h->pes_is_aligned ? 0x84 : 0x80); //0x10...
- len++;
- buff[len] = ((h->buffer_size > 0) ? 1 : 0) | (h->pts ? (h->dts ? 0xC0 : 0x80) : 0); //pes extension + pts/dts flags
- len++;
- buff[len] = (h->pts ? (h->dts ? 10 : 5) : 0) + ((h->buffer_size > 0) ? 3 : 0) + stuffing_len;//pts + std + stuffing
- len++;
- }
-
-
- if(h->pts)
- {
- write_mpeg_ts(&buff[len], h->pts, (h->dts ? 0x30 : 0x20)); // 001x and both PTS/DTS
- len += 5;
-
- if(h->dts)
- {
- write_mpeg_ts(&buff[len], h->dts, 0x10); // 0001 before DTS
- len += 5;
- }
- }
- else
- {
- if(mux_type == MUX_MPEG1)
- {
- buff[len] = 0x0f;
- len += 1;
- }
- }
-
-
- if(mux_type == MUX_MPEG2)
- {
- if(h->buffer_size > 0)
- {
- buff[len] = 0x1e; //std flag
- len++;
-
- write_mpeg_std(&buff[len], h->buffer_size, h->type, 0x40);
- len += 2;
- }
-
- if(stuffing_len > 0)
- {
- memset(&buff[len], 0xff, stuffing_len);
- len += stuffing_len;
- }
- }
-
- *((uint16_t*) &buff[4]) = be2me_16(len + plen - 6); //fix pes packet size
- return len;
-}
-
-
-static void write_pes_padding(uint8_t *buff, uint16_t len)
-{
- //6 header bytes + len-6 0xff chars
- buff[0] = buff[1] = 0;
- buff[2] = 1;
- buff[3] = 0xbe;
- *((uint16_t*) &buff[4]) = be2me_16(len - 6);
- memset(&buff[6], 0xff, len - 6);
-}
-
-
-static int write_nav_pack(uint8_t *buff)
-{
- // concatenation of pes_private2 + 03d4 x 0 and pes_private2 + 03fa x 0
- int len;
-
- mp_msg(MSGT_MUXER, MSGL_DBG3, "NAV\n");
- len = 0;
- *(uint32_t *)(&buff[len]) = be2me_32(PES_PRIVATE2);
- len += 4;
- buff[len++] = 0x3;
- buff[len++] = 0xd4;
- memset(&buff[len], 0, 0x03d4);
- len += 0x03d4;
-
- *(uint32_t *)(&buff[len]) = be2me_32(PES_PRIVATE2);
- len += 4;
- buff[len++] = 0x3;
- buff[len++] = 0xfa;
- memset(&buff[len], 0, 0x03fa);
- len += 0x03fa;
-
- return len;
-}
-
-static unsigned int calc_psm_len(muxer_priv_t *priv)
-{
- return 16 + 4*(priv->psm_info.cnt);
-}
-
-static uint32_t calc_pes_hlen(int format, muxer_headers_t *h, muxer_priv_t *priv)
-{
- uint32_t len;
-
- if(format == MUX_MPEG1)
- len = 6;
- else
- len = 9;
-
- if(h->pts)
- {
- len += 5;
- if(h->dts)
- len += 5;
- }
- else if(format == MUX_MPEG1)
- len += 1;
-
- if(h->buffer_size > 0)
- {
- if(format == MUX_MPEG2)
- len += 3;
- else
- len += 2;
- }
-
- //len = max(h->min_pes_hlen, len);
-
- return len;
-}
-
-
-static int write_mpeg_pack(muxer_t *muxer, muxer_stream_t *s, stream_t *stream, int isoend)
-{
- size_t tot, offset;
- muxer_priv_t *priv;
- unsigned char *buff;
- int stuffing_len;
-
- priv = (muxer_priv_t *) muxer->priv;
- buff = priv->buff;
-
- if(isoend)
- {
- offset = priv->packet_size - 4;
- write_pes_padding(buff, offset);
- buff[offset + 0] = buff[offset + 1] = 0;
- buff[offset + 2] = 1;
- buff[offset + 3] = 0xb9;
-
- stream_write_buffer(stream, buff, priv->packet_size);
- return 1;
- }
- else //FAKE DVD NAV PACK
- {
- offset = write_mpeg_pack_header(muxer, buff);
- offset += write_mpeg_system_header(muxer, &buff[offset]);
-
- //priv->update_system_header = 0;
-
- if(priv->is_dvd)
- offset += write_nav_pack(&buff[offset]);
-
- stuffing_len = priv->packet_size - offset;
- if(stuffing_len > 0)
- {
- //insert a PES padding packet
- write_pes_padding(&buff[offset], stuffing_len);
- offset += stuffing_len;
- }
-
- stream_write_buffer(stream, buff, offset);
- priv->headers_size += offset;
- tot = offset;
- muxer->movi_end += tot;
-
- return tot;
- }
-}
-
-static void update_demux_bufsize(muxer_headers_t *spriv, uint64_t dts, int framelen, int type)
-{
- int dim = (spriv->track_len+16)*sizeof(buffer_track_t);
-
- if(spriv->track_pos+1 >= spriv->track_len)
- {
- buffer_track_t *tmp = realloc(spriv->buffer_track, dim);
- if(!tmp)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nERROR, couldn't realloc %d bytes for tracking buffer\r\n", dim);
- return;
- }
- spriv->buffer_track = tmp;
- memset(&(spriv->buffer_track[spriv->track_pos+1]), 0, 16*sizeof(buffer_track_t));
- spriv->track_len += 16;
- }
-
- spriv->buffer_track[spriv->track_pos].size = framelen;
- spriv->buffer_track[spriv->track_pos].dts = dts; //must be dts
-
- spriv->track_pos++;
-}
-
-static void fix_a52_headers(muxer_stream_t *s)
-{
- muxer_headers_t *spriv = s->priv;
- int x = spriv->payload_offset;
-
- spriv->pack[x+0] = 0x80;
- spriv->pack[x+1] = spriv->frames;
- if(spriv->frames)
- {
- spriv->pack[x+2] = ((spriv->last_frame_rest+1) >> 8) & 0xff; //256 * 0 ...
- spriv->pack[x+3] = (spriv->last_frame_rest+1) & 0xff; // + 1 byte(s) to skip
- }
- else
- spriv->pack[x+2] = spriv->pack[x+3] = 0;
-}
-
-static inline void remove_frames(muxer_headers_t *spriv, int n)
-{
- mpeg_frame_t tmp;
- int i;
-
- for(i = n; i < spriv->framebuf_used; i++)
- {
- tmp = spriv->framebuf[i - n];
- spriv->framebuf[i - n] = spriv->framebuf[i];
- spriv->framebuf[i] = tmp;
- }
- spriv->framebuf_used -= n;
-}
-
-static int calc_packet_len(muxer_stream_t *s, int psize, int finalize)
-{
- muxer_headers_t *spriv = s->priv;
- int n, len, frpos, m;
-
- n = len = 0;
- frpos = spriv->framebuf[0].pos;
- while(len < psize && n < spriv->framebuf_used)
- {
- if(!frpos && len>0 && s->type == MUXER_TYPE_VIDEO && spriv->framebuf[n].type==I_FRAME)
- return len;
- m = FFMIN(spriv->framebuf[n].size - frpos, psize - len);
- len += m;
- frpos += m;
- if(frpos == spriv->framebuf[n].size)
- {
- frpos = 0;
- n++;
- }
- }
-
- if(len < psize && !finalize)
- return 0;
- return len;
-}
-
-static int find_packet_timestamps(muxer_priv_t *priv, muxer_stream_t *s, unsigned int start, uint64_t *dts, uint64_t *pts)
-{
- muxer_headers_t *spriv = s->priv;
- int i, m, pes_hlen, ret, threshold;
- uint64_t spts, sdts, dpts;
-
- if(!spriv->framebuf_used)
- return 0;
-
- spts = spriv->pts;
- sdts = spriv->dts;
- spriv->dts = spriv->pts = 0;
- ret = 0;
- if(spriv->framebuf[0].pos == 0) // start of frame
- i = 0;
- else
- {
- pes_hlen = calc_pes_hlen(priv->mux, spriv, priv);
-
- if(pes_hlen < spriv->min_pes_hlen)
- pes_hlen = spriv->min_pes_hlen;
-
- m = spriv->framebuf[0].size - spriv->framebuf[0].pos;
-
- if(start + pes_hlen + m >= priv->packet_size) //spriv->pack_offset
- i = -1; //this pack won't have a pts: no space available
- else
- {
- if(spriv->framebuf_used < 2)
- goto fail;
-
- if(spriv->framebuf[1].pts == spriv->framebuf[1].dts)
- threshold = 5;
- else
- threshold = 10;
-
- //headers+frame 0 < space available including timestamps
- if(start + pes_hlen + m < priv->packet_size - threshold)
- i = 1;
- else
- i = -1;
- }
- }
-
- if(i > -1)
- {
- dpts = FFMAX(spriv->last_saved_pts, spriv->framebuf[i].pts) -
- FFMIN(spriv->last_saved_pts, spriv->framebuf[i].pts) +
- spriv->framebuf[0].idur;
-
- if(s->type != MUXER_TYPE_VIDEO)
- ret = 1;
- else if((spriv->framebuf[i].type == I_FRAME || priv->ts_allframes || dpts >= 36000*300)) //0.4 seconds
- ret = 1;
-
- if(ret)
- {
- *pts = spriv->framebuf[i].pts;
- *dts = spriv->framebuf[i].dts;
- if(*dts == *pts)
- *dts = 0;
- }
- }
-
-fail:
- spriv->pts = spts;
- spriv->dts = sdts;
- return ret;
-}
-
-static int get_packet_stats(muxer_priv_t *priv, muxer_stream_t *s, pack_stats_t *p, int finalize)
-{
- muxer_headers_t *spriv = s->priv;
- int len, len2, pack_hlen, pes_hlen, hlen, target, stflen, stuffing_len;
- uint64_t pts, dts;
-
- spriv->pts = spriv->dts = 0;
- p->dts = p->pts = p->frame_pts = p->frame_dts = 0;
- p->len = 0;
-
- if(priv->rawpes)
- pack_hlen = 0;
- else if(priv->mux == MUX_MPEG1)
- pack_hlen = 12;
- else
- pack_hlen = 14;
- if(priv->use_psm && psm_is_late(priv))
- pack_hlen += calc_psm_len(priv);
-
- if(find_packet_timestamps(priv, s, pack_hlen, &dts, &pts))
- {
- p->pts = p->frame_pts = pts;
- p->dts = p->frame_dts = dts;
-
- spriv->pts = pts;
- spriv->dts = dts;
- }
- pes_hlen = calc_pes_hlen(priv->mux, spriv, priv);
-
- p->stflen = stflen = (spriv->min_pes_hlen > pes_hlen ? spriv->min_pes_hlen - pes_hlen : 0);
-
- target = len = priv->packet_size - pack_hlen - pes_hlen - stflen; //max space available
- if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52)
- hlen = 4;
- else
- hlen = 0;
-
- len -= hlen;
- target -= hlen;
-
- len2 = calc_packet_len(s, target, finalize);
- if(!len2 || (len2 < target && s->type == MUXER_TYPE_AUDIO && !finalize))
- {
- //p->len = 0;
- //p->dts = p->pts = 0;
- spriv->pts = spriv->dts = 0;
- //fprintf(stderr, "\r\nLEN2: %d, target: %d, type: %d\r\n", len2, target, s->type);
- return 0;
- }
-
- len = len2;
- stuffing_len = 0;
- if(len < target)
- {
- if(s->type == MUXER_TYPE_VIDEO)
- {
- if(spriv->pts)
- target += 5;
- if(spriv->dts)
- target += 5;
- spriv->pts = spriv->dts = 0;
- p->pts = p->dts = 0;
- }
-
- stuffing_len = target - len;
- if(stuffing_len > 0 && stuffing_len < 7)
- {
- if(stflen + stuffing_len > 16)
- {
- int x = 7 - stuffing_len;
- stflen -= x;
- stuffing_len += x;
- }
- else
- {
- stflen += stuffing_len;
- stuffing_len = 0;
- }
- }
- }
-
- len += hlen;
-
- p->len = len;
- p->stflen = stflen;
-
- return p->len;
-}
-
-static int fill_packet(muxer_t *muxer, muxer_stream_t *s, int finalize)
-{
- //try to fill a packet as much as possible
- //spriv->pack_offset is the start position initialized to 0
- //data is taken from spriv->framebuf
- //if audio and a52 insert the headers
- muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
- muxer_headers_t *spriv = (muxer_headers_t *) s->priv;
- int len, m, n, dvd_pack = 0;
- int write_psm = 0;
- mpeg_frame_t *frm;
- pack_stats_t p;
-
- spriv->dts = spriv->pts = 0;
-
- if(! spriv->framebuf_used)
- {
- spriv->pack_offset = 0;
- return 0;
- }
-
- if(!spriv->pack_offset)
- {
- if(priv->rawpes)
- spriv->pack_offset = 0;
- else
- spriv->pack_offset = write_mpeg_pack_header(muxer, spriv->pack);
- if(priv->update_system_header && (priv->is_genmpeg1 || priv->is_genmpeg2))
- {
- spriv->pack_offset += write_mpeg_system_header(muxer, &spriv->pack[spriv->pack_offset]);
- priv->update_system_header = 0;
- }
-
- if(priv->use_psm && psm_is_late(priv))
- {
- spriv->pack_offset += write_mpeg_psm(muxer, &spriv->pack[spriv->pack_offset]);
- write_psm = 1;
- }
-
- spriv->pes_set = 0;
- spriv->pes_offset = spriv->pack_offset;
- spriv->payload_offset = 0;
- spriv->frames = 0;
- spriv->last_frame_rest = 0;
- }
-
- if(!spriv->pes_set)
- {
- int bufsize = 0;
- //search the pts. yes if either it's video && (I-frame or priv->ts_allframes) && framebuf[i].pos == 0
- //or it's audio && framebuf[i].pos == 0
- //NB pts and dts can only be relative to the first frame beginning in this pack
- if((priv->is_xsvcd || priv->is_xvcd || priv->rawpes) && spriv->size == 0)
- {
- if(s->type == MUXER_TYPE_VIDEO)
- bufsize = (conf_vbuf_size ? conf_vbuf_size : (priv->is_xvcd ? 46 : 232));
- else
- bufsize = (conf_abuf_size ? conf_abuf_size : 4);
- spriv->buffer_size = bufsize*1024;
- }
-
- if(priv->is_dvd && s->type == MUXER_TYPE_VIDEO
- && spriv->framebuf[0].type==I_FRAME && spriv->framebuf[0].pos==0)
- dvd_pack = 1;
-
- if(! get_packet_stats(priv, s, &p, finalize))
- {
- spriv->pack_offset = 0;
- return 0;
- }
- spriv->dts = p.dts;
- spriv->pts = p.pts;
- if(spriv->pts)
- spriv->last_saved_pts = p.pts;
-
- spriv->pack_offset += write_mpeg_pes_header(spriv, (uint8_t *) &s->ckid, &(spriv->pack[spriv->pack_offset]),
- p.len, p.stflen, priv->mux);
-
- if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52)
- {
- spriv->payload_offset = spriv->pack_offset;
- spriv->pack_offset += 4; //for the 4 bytes of header
- if(!spriv->framebuf[0].pos)
- spriv->last_frame_rest = 0;
- else
- spriv->last_frame_rest = spriv->framebuf[0].size - spriv->framebuf[0].pos;
- }
-
- spriv->pes_set = 1;
- }
-
-
- if(spriv->dts || spriv->pts)
- {
- if((spriv->dts && priv->scr >= spriv->dts) || priv->scr >= spriv->pts)
- mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nERROR: scr %.3f, dts %.3f, pts %.3f\r\n", (double) priv->scr/27000000.0, (double) spriv->dts/27000000.0, (double) spriv->pts/27000000.0);
- else if(priv->scr + 63000*300 < spriv->dts)
- mp_msg(MSGT_MUXER, MSGL_INFO, "\r\nWARNING>: scr %.3f, dts %.3f, pts %.3f, diff %.3f, piff %.3f\r\n", (double) priv->scr/27000000.0, (double) spriv->dts/27000000.0, (double) spriv->pts/27000000.0, (double)(spriv->dts - priv->scr)/27000000.0, (double)(spriv->pts - priv->scr)/27000000.0);
- }
-
- n = 0;
- len = 0;
-
- frm = spriv->framebuf;
- while(spriv->pack_offset < priv->packet_size && n < spriv->framebuf_used)
- {
- if(!frm->pos)
- {
- //since iframes must always be aligned at block boundaries exit when we find the
- //beginning of one in the middle of the flush
- if(len > 0 && s->type == MUXER_TYPE_VIDEO && frm->type == I_FRAME)
- {
- break;
- }
- spriv->frames++;
- update_demux_bufsize(spriv, frm->dts, frm->size, s->type);
- }
-
- m = FFMIN(frm->size - frm->pos, priv->packet_size - spriv->pack_offset);
- memcpy(&(spriv->pack[spriv->pack_offset]), &(frm->buffer[frm->pos]), m);
-
- len += m;
- spriv->pack_offset += m;
- frm->pos += m;
-
- if(frm->pos == frm->size) //end of frame
- {
- frm->pos = frm->size = 0;
- frm->pts = frm->dts = 0;
- n++;
- frm++;
- }
- }
-
- if((priv->is_xsvcd || priv->is_xvcd || priv->rawpes) && spriv->size == 0)
- spriv->buffer_size = 0;
-
- spriv->size += len;
-
- if(dvd_pack && (spriv->pack_offset == priv->packet_size))
- write_mpeg_pack(muxer, NULL, muxer->stream, 0); //insert fake Nav Packet
-
- if(n > 0)
- remove_frames(spriv, n);
-
- spriv->track_bufsize += len;
- if(spriv->track_bufsize > spriv->max_buffer_size)
- mp_msg(MSGT_MUXER, MSGL_ERR, "\r\nBUFFER OVERFLOW: %d > %d, pts: %"PRIu64"\r\n", spriv->track_bufsize, spriv->max_buffer_size, spriv->pts);
-
- if(s->type == MUXER_TYPE_AUDIO && s->wf->wFormatTag == AUDIO_A52)
- fix_a52_headers(s);
-
- if(spriv->pack_offset < priv->packet_size && !priv->rawpes) //here finalize is set
- {
- int diff = priv->packet_size - spriv->pack_offset;
- write_pes_padding(&(spriv->pack[spriv->pack_offset]), diff);
- spriv->pack_offset += diff;
- }
-
- stream_write_buffer(muxer->stream, spriv->pack, spriv->pack_offset);
-
- priv->headers_size += spriv->pack_offset - len;
- priv->data_size += len;
- muxer->movi_end += spriv->pack_offset;
-
- spriv->pack_offset = 0;
- spriv->pes_set = 0;
- spriv->frames = 0;
- if(write_psm)
- priv->last_psm_scr = priv->scr;
-
- return len;
-}
-
-static inline int find_best_stream(muxer_t *muxer)
-{
- int i, ndts;
- uint64_t dts = -1;
- muxer_priv_t *priv = muxer->priv;
- muxer_headers_t *spriv;
- pack_stats_t p;
- unsigned int perc, sperc;
-
- ndts = -1;
- perc = -1;
-
- //THIS RULE MUST ALWAYS apply: dts <= SCR + 0.7 seconds
- for(i = 0; i < muxer->avih.dwStreams; i++)
- {
- spriv = muxer->streams[i]->priv;
-
- p.len = 0;
- get_packet_stats(priv, muxer->streams[i], &p, 0);
-
- if(spriv->track_bufsize + p.len > spriv->max_buffer_size)
- continue;
- if(p.frame_pts && p.frame_dts > priv->scr + 63000*300)
- continue;
-
- if(spriv->framebuf[0].dts <= dts)
- {
- dts = spriv->framebuf[0].dts;
- ndts = i;
- }
-
- if(conf_interleaving2)
- {
- sperc = (spriv->track_bufsize * 1024) / spriv->max_buffer_size;
- if(sperc < perc)
- {
- ndts = i;
- perc = sperc;
- }
- }
- }
-
- return ndts;
-}
-
-static void patch_seq(muxer_priv_t *priv, unsigned char *buf)
-{
- if(priv->vwidth > 0)
- {
- buf[4] = (priv->vwidth >> 4) & 0xff;
- buf[5] &= 0x0f;
- buf[5] |= (priv->vwidth & 0x0f) << 4;
- }
-
- if(priv->vheight > 0)
- {
- buf[5] &= 0xf0;
- buf[5] |= (priv->vheight >> 8) & 0x0f;
- buf[6] = priv->vheight & 0xff;
- }
-
- if(priv->vaspect > 0)
- buf[7] = (buf[7] & 0x0f) | (priv->vaspect << 4);
-
- if(priv->vframerate > 0)
- buf[7] = (buf[7] & 0xf0) | priv->vframerate;
-
- if(priv->vbitrate > 0)
- {
- buf[8] = (priv->vbitrate >> 10);
- buf[9] = (priv->vbitrate >> 2);
- buf[10] = (buf[10] & 0x3f) | (unsigned char) ((priv->vbitrate & 0x4) << 2);
- }
-}
-
-static void patch_panscan(muxer_priv_t *priv, unsigned char *buf)
-{ //patches sequence display extension (display_horizontal_size and display_vertical_size)
- //1:
- int offset = 1;
-
- if(buf[0] & 0x01)
- offset += 3;
-
- if(priv->panscan_width > 0)
- {
- buf[offset] = (priv->panscan_width >> 6);
- buf[offset+1] = ((priv->panscan_width & 0x3F) << 2) | (buf[offset + 1] & 0x03);
- }
-
- offset++;
-
- if(priv->panscan_height > 0)
- {
- buf[offset] = (priv->panscan_height >> 13) << 7;
- buf[offset+1] = (priv->panscan_height >> 5) & 0xFF;
- buf[offset+2] = ((priv->panscan_height & 0x1F) << 3) | (buf[offset+2] & 0x07);
- }
-}
-
-
-static void update_scr(muxer_t *muxer)
-{
- muxer_priv_t *priv = muxer->priv;
- muxer_stream_t *stream;
- muxer_headers_t *spriv;
- int i, j;
- uint64_t mindts = (uint64_t) -1;
-
- priv->scr += priv->delta_scr;
-
- for(i = 0; i < muxer->avih.dwStreams; i++)
- {
- stream = muxer->streams[i];
- spriv = stream->priv;
- if(spriv->framebuf_used && spriv->framebuf[0].dts < mindts)
- mindts = spriv->framebuf[0].dts;
- }
-
- mp_msg(MSGT_MUXER, MSGL_DBG2, "UPDATE SCR TO %"PRIu64" (%.3f)\n", priv->scr, (double) (priv->scr/27000000.0));
-
- for(i = 0; i < muxer->avih.dwStreams; i++)
- {
- stream = muxer->streams[i];
- spriv = stream->priv;
-
- j = 0;
- while(j < spriv->track_pos && priv->scr >= spriv->buffer_track[j].dts)
- {
- spriv->track_bufsize -= spriv->buffer_track[j].size;
- j++;
- }
- if(spriv->track_bufsize < 0)
- {
- double d;
- muxer->sysrate = (muxer->sysrate * 11) / 10; //raise by 10%
- d = (double) priv->packet_size / (double)muxer->sysrate;
- priv->delta_scr = (uint64_t) (d * 27000000.0f);
- mp_msg(MSGT_MUXER, MSGL_INFO, "\r\nBUFFER UNDEFLOW at stream %d, raising muxrate to %d kb/s, delta_scr: %"PRIu64"\r\n", i, muxer->sysrate/125, priv->delta_scr);
- spriv->track_bufsize = 0;
- }
-
- if(j > 0)
- {
- memmove(spriv->buffer_track, &(spriv->buffer_track[j]), (spriv->track_len - j) * sizeof(buffer_track_t));
- spriv->track_pos -= j;
- for(j = spriv->track_pos; j < spriv->track_len; j++)
- spriv->buffer_track[j].size = 0;
- }
-
- if(spriv->framebuf_used && spriv->framebuf[0].dts < mindts)
- mindts = spriv->framebuf[0].dts;
- }
-}
-
-
-static int calc_frames_to_flush(muxer_headers_t *vpriv)
-{
- int n, found = 0;
-
- if(vpriv->framebuf_used > 0)
- {
- n = 0;
- //let's count how many frames we'll store in the next pack sequence
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\n");
- while(n < vpriv->framebuf_used)
- {
- mp_msg(MSGT_MUXER, MSGL_DBG2, "CALC_FRAMES, n=%d, type=%c, pts=%.3f\n", n, FTYPE(vpriv->framebuf[n].type), (double)vpriv->framebuf[n].pts/27000000.0f);
- if(n+1 < vpriv->framebuf_used)
- mp_msg(MSGT_MUXER, MSGL_DBG2, "n+1=%d, type=%c, pts=%.3f\n", n+1, FTYPE(vpriv->framebuf[n+1].type), (double)vpriv->framebuf[n+1].pts/27000000.0f);
-
- if(vpriv->framebuf[n].type == I_FRAME)
- {
- if(n > 0)
- {
- found = 1;
- break;
- }
- }
-
- n++;
- }
- }
-
- if(found && (n < vpriv->framebuf_used+1))
- return n;
- else
- return 0;
-}
-
-static int flush_buffers(muxer_t *muxer, int finalize)
-{
- int i, n, found;
- int skip_cnt;
- uint64_t init_delay = 0;
- muxer_stream_t *s, *vs, *as;
- muxer_headers_t *vpriv = NULL, *apriv = NULL;
- muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
- double duration;
- uint64_t iduration, iaduration;
-
- /*
- analyzes all streams and decides what to flush
- trying to respect an interleaving distribution
- equal to the v_bitrate/a_bitrate proportion
- */
- n = 0;
- vs = as = NULL;
- found = 0;
- for(i = 0; i < muxer->avih.dwStreams; i++)
- {
- s = muxer->streams[i];
- if(s->type == MUXER_TYPE_VIDEO)
- {
- vs = muxer->streams[i];
- vpriv = (muxer_headers_t*) vs->priv;
- if(!vpriv->is_ready)
- return 0;
- n = found = calc_frames_to_flush(vpriv);
- }
- else if(s->type == MUXER_TYPE_AUDIO)
- as = s;
- }
-
- if((! found) && finalize)
- {
- if(vpriv != NULL)
- found = n = vpriv->framebuf_used;
- }
-
- if(found)
- {
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\nVIDEO, FLUSH %d frames (of %d), 0 to %d\n", n, vpriv->framebuf_used, n-1);
-
- vpriv = (muxer_headers_t*) vs->priv;
-
- duration = 0;
- iduration = 0;
- for(i = 0; i < n; i++)
- iduration += vpriv->framebuf[i].idur;
- duration = (double) (iduration / 27000000.0);
-
- if(as != NULL)
- {
- apriv = (muxer_headers_t*) as->priv;
- iaduration = 0;
- for(i = 0; i < apriv->framebuf_used; i++)
- {
- iaduration += apriv->framebuf[i].idur;
- }
- if(iaduration < iduration)
- {
- mp_msg(MSGT_MUXER, MSGL_DBG2, "Not enough audio data exit\n");
- return 0;
- }
- }
-
- if(as != NULL && (apriv->size == 0))
- {
- init_delay = vpriv->framebuf[0].pts - vpriv->framebuf[0].dts;
-
- for(i = 0; i < apriv->framebuf_cnt; i++)
- {
- apriv->framebuf[i].pts += init_delay;
- apriv->framebuf[i].dts += init_delay;
- }
- apriv->last_pts += init_delay;
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\r\nINITIAL VIDEO DELAY: %.3f, currAPTS: %.3f\r\n", (double) init_delay/27000000.0f, (double) apriv->last_pts/27000000.0f);
- }
-
- if((priv->is_xvcd || priv->is_xsvcd) && (vpriv->size == 0))
- vpriv->buffer_size = (conf_vbuf_size ? conf_vbuf_size : (priv->is_xvcd ? 46 : 230))*1024;
-
- i = 0;
- skip_cnt = 0;
-
- while(1)
- {
- update_scr(muxer);
- i = find_best_stream(muxer);
- if(i < 0)
- continue;
- if(!fill_packet(muxer, muxer->streams[i], finalize))
- skip_cnt++;
-
- if(skip_cnt == muxer->avih.dwStreams)
- {
- found = 0;
- break;
- }
- }
- }
-
- muxer->file_end = priv->scr;
- return found;
-}
-
-
-static inline uint64_t parse_fps(float fps)
-{
- // 90000 * 300 * 1001 / d , there's no rounding error with any of the admitted framerates
- int d = (int)(fps*1001+0.5);
-
- return 27027000000ULL / d;
-}
-
-
-static int soft_telecine(muxer_priv_t *priv, muxer_headers_t *vpriv, uint8_t *fps_ptr, uint8_t *se_ptr, uint8_t *pce_ptr, int n)
-{
- if(! pce_ptr)
- return 0;
- if(fps_ptr != NULL)
- {
- *fps_ptr = (*fps_ptr & 0xf0) | priv->vframerate;
- vpriv->nom_delta_pts = parse_fps(conf_vframerate);
- }
-
- //in pce_ptr starting from bit 0 bit 24 is tff, bit 30 is rff,
- if(pce_ptr[3] & 0x2)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR! RFF bit is already set, disabling telecining\n");
- vpriv->telecine = 0;
- return 0;
- }
-
- vpriv->picture.progressive_sequence = 0;
- vpriv->picture.progressive_frame = 1;
- if(se_ptr)
- se_ptr[1] &= 0xf7;
-
- //disable tff and rff and overwrite them with the value in bff_mask
- pce_ptr[3] = (pce_ptr[3] & 0x7d) | priv->bff_mask[vpriv->display_frame % MAX_PATTERN_LENGTH];
- pce_ptr[4] |= 0x80; //sets progressive frame
-
- vpriv->display_frame += n;
- if(! vpriv->vframes)
- mp_msg(MSGT_MUXER, MSGL_INFO, "\nENABLED SOFT TELECINING, FPS=%.3f\n",conf_vframerate);
-
- return 1;
-}
-
-static size_t parse_mpeg12_video(muxer_stream_t *s, muxer_priv_t *priv, muxer_headers_t *spriv, float fps, size_t len)
-{
- uint8_t *fps_ptr = NULL; //pointer to the fps byte in the sequence header
- uint8_t *se_ptr = NULL; //pointer to sequence extension
- uint8_t *pce_ptr = NULL; //pointer to picture coding extension
- int frames_diff, d1, gop_reset = 0; //how any frames we advanced respect to the last one
- int ret;
- int i, err;
- uint32_t temp_ref;
- int pt;
-
- mp_msg(MSGT_MUXER, MSGL_DBG2,"parse_mpeg12_video, len=%u\n", (uint32_t) len);
- if(s->buffer[0] != 0 || s->buffer[1] != 0 || s->buffer[2] != 1 || len<6)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR,"Unknown video format, possibly non-MPEG1/2 stream, len=%d!\n", len);
- return 0;
- }
-
- temp_ref = 0;
- pt = 0;
- err = 0;
- i = 0;
- while(i + 4 < len)
- { // Video (0) Sequence header (b3) or GOP (b8)
- if((s->buffer[i] == 0) && (s->buffer[i+1] == 0) && (s->buffer[i+2] == 1))
- {
- switch(s->buffer[i+3])
- {
- case 0xb3: //sequence
- {
- if(i + 11 > len)
- {
- err=1;
- break;
- }
- fps_ptr = &(s->buffer[i+7]);
- mp_header_process_sequence_header(&(spriv->picture), &(s->buffer[i+4]));
- spriv->delta_pts = spriv->nom_delta_pts = parse_fps(spriv->picture.fps);
-
- spriv->delta_clock = (double) 1/fps;
- //the 2 lines below are needed to handle non-standard frame rates (such as 18)
- if(! spriv->delta_pts)
- spriv->delta_pts = spriv->nom_delta_pts = (uint64_t) ((double)27000000.0 * spriv->delta_clock );
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\nFPS: %.3f, FRAMETIME: %.3f\n", fps, (double)1/fps);
- if(priv->patch_seq)
- patch_seq(priv, &(s->buffer[i]));
- }
- break;
-
- case 0xb5:
- if(i + 9 > len)
- {
- err = 1;
- break;
- }
- mp_header_process_extension(&(spriv->picture), &(s->buffer[i+4]));
- if(((s->buffer[i+4] & 0xf0) == 0x10))
- se_ptr = &(s->buffer[i+4]);
- if(((s->buffer[i+4] & 0xf0) == 0x20))
- {
- if(priv->patch_sde)
- patch_panscan(priv, &(s->buffer[i+4]));
- }
- if((s->buffer[i+4] & 0xf0) == 0x80)
- {
- pce_ptr = &(s->buffer[i+4]);
- }
- break;
-
- case 0xb8:
- gop_reset = 1;
- break;
-
- case 0x00:
- if(i + 5 > len)
- {
- err = 1;
- break;
- }
- pt = (s->buffer[i+5] & 0x1c) >> 3;
- temp_ref = (s->buffer[i+4]<<2)+(s->buffer[i+5]>>6);
- break;
- }
- if(err) break; //something went wrong
- if(s->buffer[i+3] >= 0x01 && s->buffer[i+3] <= 0xAF) break; //slice, we have already analized what we need
- }
- i++;
- }
- if(err)
- mp_msg(MSGT_MUXER, MSGL_ERR,"Warning: picture too short or broken!\n");
-
- //following 2 lines are workaround: lavf doesn't sync to sequence headers before passing demux_packets
- if(!spriv->nom_delta_pts)
- spriv->delta_pts = spriv->nom_delta_pts = parse_fps(fps);
- if(!spriv->vframes)
- spriv->last_tr = spriv->max_tr = temp_ref;
- d1 = temp_ref - spriv->last_tr;
- if(gop_reset)
- frames_diff = spriv->max_tr + 1 + temp_ref - spriv->last_tr;
- else
- {
- if(d1 < -6) //there's a wraparound
- frames_diff = spriv->max_tr + 1 + temp_ref - spriv->last_tr;
- else if(d1 > 6) //there's a wraparound
- frames_diff = spriv->max_tr + 1 + spriv->last_tr - temp_ref;
- else if(!d1) //pre-emptive fix against broken sequences
- frames_diff = 1;
- else
- frames_diff = d1;
- }
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\nLAST: %d, TR: %d, GOP: %d, DIFF: %d, MAX: %d, d1: %d\n",
- spriv->last_tr, temp_ref, gop_reset, frames_diff, spriv->max_tr, d1);
-
- if(temp_ref > spriv->max_tr || gop_reset)
- spriv->max_tr = temp_ref;
-
- spriv->last_tr = temp_ref;
- if(spriv->picture.mpeg1 == 0)
- {
- if(spriv->telecine && pce_ptr)
- {
- soft_telecine(priv, spriv, fps_ptr, se_ptr, pce_ptr, frames_diff);
- spriv->picture.display_time = 100;
- mp_header_process_extension(&(spriv->picture), pce_ptr);
- if(spriv->picture.display_time >= 50 && spriv->picture.display_time <= 300)
- spriv->delta_pts = (spriv->nom_delta_pts * spriv->picture.display_time) / 100;
- }
- }
-
- if(! spriv->vframes)
- frames_diff = 1;
-
- spriv->last_dts += spriv->delta_pts;
- spriv->last_pts += spriv->nom_delta_pts*(frames_diff-1) + spriv->delta_pts;
-
- ret = add_frame(spriv, spriv->delta_pts, s->buffer, len, pt, spriv->last_dts, spriv->last_pts);
- if(ret < 0)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "\r\nPARSE_MPEG12: add_frames(%d) failed, exit\r\n", len);
- return 0;
- }
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\r\nVIDEO FRAME, PT: %C, tr: %d, diff: %d, dts: %.3f, pts: %.3f, pdt: %u, gop_reset: %d\r\n",
- ftypes[pt], temp_ref, frames_diff, ((double) spriv->last_dts/27000000.0f),
- ((double) spriv->last_pts/27000000.0f), spriv->picture.display_time, gop_reset);
-
- if(pt == B_FRAME)
- {
- int j, n, adj = 0;
- int64_t diff = spriv->last_dts - spriv->last_pts;
-
- if(diff != 0)
- {
- n = spriv->framebuf_used - 1;
-
- for(j = n; j >= 0; j--)
- {
- if(spriv->framebuf[j].pts >= spriv->last_pts)
- {
- spriv->framebuf[j].pts += diff;
- adj++;
- }
- }
- mp_msg(MSGT_MUXER, MSGL_V, "\r\nResynced B-frame by %d units, DIFF: %"PRId64" (%.3f),[pd]ts=%.3f\r\n",
- n, diff, (double) diff/27000000.0f, (double) spriv->last_pts/27000000.0f);
- spriv->last_pts = spriv->last_dts;
- }
- }
- spriv->vframes++;
-
- mp_msg(MSGT_MUXER, MSGL_DBG2,"parse_mpeg12_video, return %u\n", (uint32_t) len);
- return len;
-}
-
-
-static uint64_t fix_mp4_frame_duration(muxer_headers_t *vpriv)
-{
- uint64_t mn, md, mx, diff;
- uint32_t i;
-
- mn = mx = vpriv->framebuf[0].pts;
- for(i = 0; i < 3; i++)
- {
- mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "PTS: %"PRIu64"\n", vpriv->framebuf[i].pts);
- if(vpriv->framebuf[i].pts < mn)
- mn = vpriv->framebuf[i].pts;
- if(vpriv->framebuf[i].pts > mx)
- mx = vpriv->framebuf[i].pts;
- }
- md = mn;
- for(i=0; i<3; i++)
- {
- if((vpriv->framebuf[i].pts > mn) && (vpriv->framebuf[i].pts < mx))
- md = vpriv->framebuf[i].pts;
- }
-
- if(mx - md > md - mn)
- diff = md - mn;
- else
- diff = mx - md;
-
- mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "MIN: %"PRIu64", mid: %"PRIu64", max: %"PRIu64", diff: %"PRIu64"\n", mn, md, mx, diff);
- if(diff > 0)
- {
- for(i=0; i<3; i++)
- {
- vpriv->framebuf[i].pts += diff;
- vpriv->framebuf[i].dts += i * diff;
- mp_msg(MSGT_MUXER, MSGL_DBG2, "FIXED_PTS: %.3f, FIXED_DTS: %.3f\n",
- (double) (vpriv->framebuf[i].pts/27000000.0), (double) (vpriv->framebuf[i].dts/27000000.0));
- }
- return diff;
- }
- else
- return 0;
-}
-
-
-static size_t parse_mpeg4_video(muxer_stream_t *s, muxer_priv_t *priv, muxer_headers_t *vpriv, float fps, size_t len)
-{
- size_t ptr = 0;
- int64_t delta_pts=0;
- uint8_t pt;
- int ret;
-
- mp_msg(MSGT_MUXER, MSGL_DBG2,"parse_mpeg4_video, len=%u\n", (uint32_t) len);
- if(len<6)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR,"Frame too short: %d, exit!\n", len);
- return 0;
- }
-
- pt = 0;
- while(ptr < len - 5)
- {
- if(s->buffer[ptr] != 0 || s->buffer[ptr+1] != 0 || s->buffer[ptr+2] != 1)
- {
- ptr++;
- continue;
- }
-
- if(s->buffer[ptr+3] >= 0x20 && s->buffer[ptr+3] <= 0x2f) //VOL
- {
- mp4_header_process_vol(&(vpriv->picture), &(s->buffer[ptr+4]));
- }
- else if(s->buffer[ptr+3] == 0xb3) //gov
- {
- //fprintf(stderr, "\nGOV\n");
- }
- else if(s->buffer[ptr+3] == 0xb6) //vop
- {
- int32_t delta;
- mp4_header_process_vop(&(vpriv->picture), &(s->buffer[ptr+4]));
-
- delta = vpriv->picture.timeinc_unit - vpriv->last_tr;
- if((delta > 0) && (delta > (vpriv->picture.timeinc_resolution/2)))
- delta -= vpriv->picture.timeinc_resolution;
- else if((delta < 0) && (delta < (-(vpriv->picture.timeinc_resolution/2))))
- delta += vpriv->picture.timeinc_resolution;
-
- delta_pts = (27000000 * (int64_t) delta) / vpriv->picture.timeinc_resolution;
- //warning, it seems that packed bops can lead to delta == 0
-
- pt = vpriv->picture.picture_type + 1;
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\nTYPE: %c, RESOLUTION: %d, TEMP: %d, delta: %d, delta_pts: %"PRId64" = %.3f, delta2: %.3f\n",
- FTYPE(pt), vpriv->picture.timeinc_resolution, vpriv->picture.timeinc_unit, delta, delta_pts, (double) (delta_pts/27000000.0),
- (double) delta / (double) vpriv->picture.timeinc_resolution);
-
- vpriv->last_tr = vpriv->picture.timeinc_unit;
-
- break;
- }
-
- ptr++;
- }
-
- if(vpriv->vframes)
- {
- vpriv->last_dts += vpriv->frame_duration;
- vpriv->last_pts += delta_pts;
- }
-
- ret = add_frame(vpriv, delta_pts, s->buffer, len, pt, vpriv->last_dts, vpriv->last_pts);
- if(ret < 0)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "\r\nPARSE_MPEG4: add_frames(%d) failed, exit\r\n", len);
- return 0;
- }
-
- if(!vpriv->frame_duration && vpriv->framebuf_used == 3)
- {
- vpriv->frame_duration = fix_mp4_frame_duration(vpriv);
- if(vpriv->frame_duration)
- {
- vpriv->last_pts += vpriv->frame_duration;
- vpriv->last_dts = vpriv->framebuf[vpriv->framebuf_used-1].dts;
- vpriv->delta_clock = ((double) vpriv->frame_duration)/27000000.0;
- mp_msg(MSGT_MUXER, MSGL_INFO, "FRAME DURATION: %"PRIu64" %.3f\n",
- vpriv->frame_duration, (double) (vpriv->frame_duration/27000000.0));
- vpriv->is_ready = 1;
- }
- }
-
- mp_msg(MSGT_MUXER, MSGL_DBG2, "LAST_PTS: %.3f, LAST_DTS: %.3f\n",
- (double) (vpriv->last_pts/27000000.0), (double) (vpriv->last_dts/27000000.0));
-
- vpriv->vframes++;
-
- return len;
-}
-
-
-static int fill_last_frame(muxer_headers_t *spriv, uint8_t *ptr, int len)
-{
- int idx;
-
- if(!len)
- return 0;
-
- if(spriv->framebuf_used == 0)
- idx = spriv->framebuf_used;
- else
- idx = spriv->framebuf_used - 1;
-
- if(spriv->framebuf[idx].alloc_size < spriv->framebuf[idx].size + len)
- {
- if(spriv->framebuf[idx].size > SIZE_MAX - (size_t)len)
- return 0;
- spriv->framebuf[idx].buffer = realloc(spriv->framebuf[idx].buffer, spriv->framebuf[idx].size + len);
- if(! spriv->framebuf[idx].buffer)
- return 0;
- spriv->framebuf[idx].alloc_size = spriv->framebuf[idx].size + len;
- }
-
- memcpy(&(spriv->framebuf[idx].buffer[spriv->framebuf[idx].size]), ptr, len);
- spriv->framebuf[idx].size += len;
-
- return len;
-}
-
-static int add_frame(muxer_headers_t *spriv, uint64_t idur, uint8_t *ptr, int len, uint8_t pt, uint64_t dts, uint64_t pts)
-{
- int idx;
-
- idx = spriv->framebuf_used;
- if(idx >= spriv->framebuf_cnt)
- {
- spriv->framebuf = realloc_struct(spriv->framebuf, (spriv->framebuf_cnt+1), sizeof(mpeg_frame_t));
- if(spriv->framebuf == NULL)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't realloc frame buffer(idx), abort\n");
- return -1;
- }
-
- spriv->framebuf[spriv->framebuf_cnt].size = 0;
- spriv->framebuf[spriv->framebuf_cnt].alloc_size = 0;
- spriv->framebuf[spriv->framebuf_cnt].pos = 0;
-
- spriv->framebuf[spriv->framebuf_cnt].buffer = malloc(len);
- if(spriv->framebuf[spriv->framebuf_cnt].buffer == NULL)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't realloc frame buffer(frame), abort\n");
- return -1;
- }
- spriv->framebuf[spriv->framebuf_cnt].alloc_size = len;
- spriv->framebuf_cnt++;
- }
-
- if(spriv->framebuf[idx].alloc_size < spriv->framebuf[idx].size + len)
- {
- if(spriv->framebuf[idx].size > SIZE_MAX - (size_t)len)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Size overflow, couldn't realloc frame buffer(frame), abort\n");
- return -1;
- }
- spriv->framebuf[idx].buffer = realloc(spriv->framebuf[idx].buffer, spriv->framebuf[idx].size + len);
- if(spriv->framebuf[idx].buffer == NULL)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't realloc frame buffer(frame), abort\n");
- return -1;
- }
- spriv->framebuf[idx].alloc_size = spriv->framebuf[idx].size + len;
- }
-
- memcpy(&(spriv->framebuf[idx].buffer[spriv->framebuf[idx].size]), ptr, len);
- spriv->framebuf[idx].size += len;
- spriv->framebuf[idx].pos = 0;
- spriv->framebuf[idx].type = pt;
-
- spriv->framebuf[idx].idur = idur;
- spriv->framebuf[idx].dts = dts;
- spriv->framebuf[idx].pts = pts;
- spriv->framebuf_used++;
- mp_msg(MSGT_MUXER, MSGL_DBG2, "\r\nAdded frame, size: %u, idur: %"PRIu64", dts: %"PRIu64", pts: %"PRIu64", used: %u\r\n", len, idur, dts, pts, spriv->framebuf_used);
-
- return idx;
-}
-
-static int analyze_mpa(muxer_stream_t *s)
-{
- int i = 0, len, max, chans, srate, spf, layer;
- int score[4] = {0, 0, 0, 0};
-
- while(i < s->b_buffer_len + 3)
- {
- if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xE0) == 0xE0))
- {
- len = mp_get_mp3_header(&(s->b_buffer[i]), &chans, &srate, &spf, &layer, NULL);
- if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
- {
- score[layer]++;
- i += len;
- }
- }
- i++;
- }
-
- max = 0;
- layer = 2;
- for(i = 1; i <= 3; i++)
- {
- if(score[i] >= max)
- {
- max = score[i];
- layer = i;
- }
- }
-
- return layer; //actual layer with the highest score
-}
-
-static int parse_audio(muxer_stream_t *s, int finalize, unsigned int *nf, double *timer, double delay, int drop)
-{
- int i, j, len, chans, srate, spf, layer, dummy, tot, num, frm_idx;
- int finished;
- unsigned int frames;
- uint64_t idur;
- double dur;
- muxer_headers_t *spriv = (muxer_headers_t *) s->priv;
-
- i = tot = frames = 0;
- finished = 0;
- while(1)
- {
- len = 0;
- switch(s->wf->wFormatTag)
- {
- case AUDIO_MP2:
- case AUDIO_MP3:
- {
- if(i + 3 >= s->b_buffer_len)
- {
- finished = 1;
- break;
- }
-
- if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xE0) == 0xE0))
- {
- len = mp_get_mp3_header(&(s->b_buffer[i]), &chans, &srate, &spf, &layer, NULL);
- if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len)
- && layer == spriv->mpa_layer)
- {
- dur = (double) spf / (double) srate;
- idur = (27000000ULL * spf) / srate;
- }
- else
- len = 0;
- }
- }
- break;
-
- case AUDIO_A52:
- {
- if(i + 6 >= s->b_buffer_len)
- {
- finished = 1;
- break;
- }
-
- if(s->b_buffer[i] == 0x0B && s->b_buffer[i+1] == 0x77)
- {
- srate = 0;
- #ifdef CONFIG_LIBA52
- len = a52_syncinfo(&(s->b_buffer[i]), &dummy, &srate, &dummy);
- #else
- len = mp_a52_framesize(&(s->b_buffer[i]), &srate);
- #endif
- if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
- {
- dur = (double) 1536 / (double) srate;
- idur = (27000000ULL * 1536) / srate;
- }
- else
- len = 0;
- }
- }
- break;
-
- case AUDIO_AAC1:
- case AUDIO_AAC2:
- {
- if(i + 7 >= s->b_buffer_len)
- {
- finished = 1;
- break;
- }
-
- if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xF6) == 0xF0))
- {
- len = aac_parse_frame(&(s->b_buffer[i]), &srate, &num);
- if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
- {
- dur = (double) 1024 / (double) srate;
- idur = (27000000ULL * 1024 * num) / srate;
- }
- else
- len = 0;
- }
- }
- }
-
- if(finished)
- break;
-
- if(!len)
- {
- i++;
- continue;
- }
-
- spriv->timer += dur;
- if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
- {
- i += len;
- tot = i;
- continue;
- }
-
- frames++;
- fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
- frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
- if(frm_idx < 0)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't add audio frame buffer(frame), abort\n");
- goto audio_exit;
- }
- for(j = frm_idx; j < spriv->framebuf_cnt; j++)
- spriv->framebuf[j].pts = spriv->last_pts;
- spriv->last_pts += idur;
-
- i += len;
- tot = i;
- }
-
-audio_exit:
- if(tot)
- {
- memmove(s->b_buffer, &(s->b_buffer[tot]), s->b_buffer_len - tot);
- s->b_buffer_len -= tot;
- s->b_buffer_ptr += tot;
- if(s->b_buffer_len > 0)
- memmove(s->b_buffer, &(s->b_buffer[s->b_buffer_ptr]), s->b_buffer_len);
- s->b_buffer_ptr = 0;
- }
-
- if(finalize)
- {
- frm_idx = add_frame(spriv, 0, s->b_buffer, s->b_buffer_len, 0, spriv->last_pts, spriv->last_pts);
- if(frm_idx >= 0)
- {
- for(j = frm_idx; j < spriv->framebuf_cnt; j++)
- spriv->framebuf[j].pts = spriv->last_pts;
- }
- }
-
- *nf = frames;
- *timer = spriv->timer;
-
- return tot;
-}
-
-static void fix_parameters(muxer_stream_t *stream)
-{
- muxer_headers_t *spriv = stream->priv;
- muxer_t *muxer = stream->muxer;
- muxer_priv_t *priv = muxer->priv;
- uint32_t stream_format;
- int needs_psm = 0;
-
- if(stream->type == MUXER_TYPE_AUDIO)
- {
- stream_format = stream->wf->wFormatTag;
- spriv->is_ready = 1;
- if(conf_abuf_size)
- spriv->max_buffer_size = conf_abuf_size*1024;
- else
- spriv->max_buffer_size = 4*1024;
- if(stream->wf->wFormatTag == AUDIO_A52)
- {
- stream->ckid = be2me_32 (0x1bd);
- if(priv->is_genmpeg1 || priv->is_genmpeg2)
- fix_audio_sys_header(priv, spriv->id, 0xbd, FFMAX(conf_abuf_size, 58)*1024); //only one audio at the moment
- spriv->id = 0xbd;
- if(!conf_abuf_size)
- spriv->max_buffer_size = 16*1024;
- }
- else if(stream->wf->wFormatTag == AUDIO_AAC1 || stream->wf->wFormatTag == AUDIO_AAC2)
- needs_psm = 1;
- else if(stream->wf->wFormatTag == AUDIO_MP2 || stream->wf->wFormatTag == AUDIO_MP3)
- spriv->is_ready = 0;
- }
- else //video
- {
- stream_format = stream->bih->biCompression;
- if(conf_vbuf_size)
- spriv->max_buffer_size = conf_vbuf_size*1024;
- else
- {
- if(priv->is_dvd)
- spriv->max_buffer_size = 232*1024;
- else if(priv->is_xsvcd)
- spriv->max_buffer_size = 230*1024;
- else if(priv->is_xvcd)
- spriv->max_buffer_size = 46*1024;
- else
- spriv->max_buffer_size = 232*1024; //no profile => unconstrained :) FIXME!!!
- }
-
- if(is_mpeg4(stream->bih->biCompression))
- spriv->is_ready = 0;
- else
- spriv->is_ready = 1;
-
- if(!is_mpeg1(stream_format) && !is_mpeg2(stream_format))
- needs_psm = 1;
- }
-
- if(priv->is_genmpeg2 && needs_psm)
- {
- priv->use_psm = 1;
- add_to_psm(priv, spriv->id, stream_format);
- priv->psm_streams_cnt++;
- }
-}
-
-
-static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts_arg, double pts_arg)
-{
- size_t sz = 0;
- uint64_t tmp;
- muxer_t *muxer = s->muxer;
- muxer_priv_t *priv = (muxer_priv_t *)muxer->priv;
- muxer_headers_t *spriv = (muxer_headers_t*) s->priv;
- float fps;
- uint32_t stream_format, nf;
-
- if(s->buffer == NULL || len == -1)
- return;
-
- if (s->type == MUXER_TYPE_VIDEO)
- { // try to recognize frame type...
- fps = (float) s->h.dwRate/ (float) s->h.dwScale;
- spriv->type = 1;
- stream_format = s->bih->biCompression;
- if(! spriv->vframes)
- {
- spriv->last_dts = spriv->last_pts - (uint64_t)(27000000.0f/fps);
- mp_msg(MSGT_MUXER, MSGL_INFO,"INITV: %.3f, %.3f, fps: %.3f\r\n", (double) spriv->last_pts/27000000.0f, (double) spriv->last_dts/27000000.0f, fps);
- }
-
- if(is_mpeg1(stream_format) || is_mpeg2(stream_format))
- {
- spriv->is_mpeg12 = 1;
- spriv->is_ready = 1;
- if(len)
- sz = parse_mpeg12_video(s, priv, spriv, fps, len);
- else
- {
- tmp = (uint64_t) (27000000.0f / fps);
- spriv->last_pts += tmp;
- spriv->last_dts += tmp;
- }
- }
- else if(is_mpeg4(stream_format))
- {
- spriv->is_mpeg12 = 0;
- spriv->telecine = 0;
- if(len)
- sz = parse_mpeg4_video(s, priv, spriv, fps, len);
- else
- {
- tmp = (uint64_t) (27000000.0f / fps);
- spriv->last_pts += tmp;
- spriv->last_dts += tmp;
- }
- }
-
- mp_msg(MSGT_MUXER, MSGL_DBG2,"mpegfile_write_chunk, Video codec=%x, len=%u, mpeg12 returned %u\n", stream_format, (uint32_t) len, (uint32_t) sz);
- }
- else
- { // MUXER_TYPE_AUDIO
- double fake_timer;
- spriv->type = 0;
- stream_format = s->wf->wFormatTag;
-
- if(s->b_buffer_size - s->b_buffer_len < len)
- {
- void *tmp;
-
- if(s->b_buffer_len > SIZE_MAX - len)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "\nFATAL! couldn't realloc, integer overflow\n");
- return;
- }
- tmp = realloc(s->b_buffer, len + s->b_buffer_len);
- if(!tmp)
- {
- mp_msg(MSGT_MUXER, MSGL_FATAL, "\nFATAL! couldn't realloc %d bytes\n", len + s->b_buffer_len);
- return;
- }
- s->b_buffer = tmp;
-
- s->b_buffer_size = len + s->b_buffer_len;
- mp_msg(MSGT_MUXER, MSGL_DBG2, "REALLOC(%d) bytes to AUDIO backbuffer\n", s->b_buffer_size);
- }
- memcpy(&(s->b_buffer[s->b_buffer_ptr + s->b_buffer_len]), s->buffer, len);
- s->b_buffer_len += len;
-
- if(!spriv->is_ready)
- {
- if(s->b_buffer_len >= 32*1024)
- {
- spriv->mpa_layer = analyze_mpa(s);
- spriv->is_ready = 1;
- }
- }
- else
- {
- parse_audio(s, 0, &nf, &fake_timer, priv->init_adelay, priv->drop);
- spriv->vframes += nf;
- if(! spriv->vframes)
- mp_msg(MSGT_MUXER, MSGL_INFO, "AINIT: %.3f\r\n", (double) spriv->last_pts/27000000.0f);
- }
- }
-
- flush_buffers(muxer, 0);
-}
-
-
-static void mpegfile_write_index(muxer_t *muxer)
-{
- int i, nf;
- double fake_timer;
- muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
-
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing index...\n");
-
- for(i = 0; i < muxer->avih.dwStreams; i++)
- {
- if(muxer->streams[i]->type == MUXER_TYPE_AUDIO)
- parse_audio(muxer->streams[i], 1, &nf, &fake_timer, priv->init_adelay, priv->drop);
- }
- while(flush_buffers(muxer, 0) > 0);
- flush_buffers(muxer, 1);
- if(priv->is_genmpeg1 || priv->is_genmpeg2)
- {
- priv->scr = 0;
- write_mpeg_pack(muxer, NULL, muxer->stream, 1); //insert fake Nav Packet
- }
-
- mp_msg(MSGT_MUXER, MSGL_INFO, "\nOverhead: %.3f%% (%"PRIu64" / %"PRIu64")\n", 100.0 * (double)priv->headers_size / (double)priv->data_size, priv->headers_size, priv->data_size);
-}
-
-static void mpegfile_write_header(muxer_t *muxer)
-{
- muxer_priv_t *priv = (muxer_priv_t*) muxer->priv;
-
- mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing header...\n");
-
- priv->headers_cnt++;
-
- //write the first system header only for generic mpeg1/2 muxes, and only when we have collected all necessary infos
- if(priv->is_genmpeg1 || priv->is_genmpeg2 || ((priv->is_xvcd || priv->is_xsvcd) && (priv->headers_cnt == 1)))
- {
- write_mpeg_pack(muxer, NULL, muxer->stream, 0);
- priv->update_system_header = 0;
- }
-
- return;
-}
-
-static void setup_sys_params(muxer_priv_t *priv)
-{
- if(priv->is_dvd)
- {
- int v = (conf_vbuf_size ? conf_vbuf_size : 232);
- int a1 = (conf_abuf_size ? conf_abuf_size : 4);
- int a2 = (conf_abuf_size>58 ? conf_abuf_size : 58);
-
- priv->sys_info.cnt = 4;
-
- priv->sys_info.streams[0].id = 0xb9;
- priv->sys_info.streams[0].type = 1;
- priv->sys_info.streams[0].bufsize = v*1024;
-
- priv->sys_info.streams[1].id = 0xb8;
- priv->sys_info.streams[1].type = 0;
- priv->sys_info.streams[1].bufsize = a1*1024;
-
- priv->sys_info.streams[2].id = 0xbd;
- priv->sys_info.streams[2].type = 1;
- priv->sys_info.streams[2].bufsize = a2*1024;
-
- priv->sys_info.streams[3].id = 0xbf;
- priv->sys_info.streams[3].type = 1;
- priv->sys_info.streams[3].bufsize = 2*1024;
- }
- else if(priv->is_xvcd || priv->is_xsvcd)
- {
- int v = (conf_vbuf_size ? conf_vbuf_size : (priv->is_xvcd ? 46: 230));
- int a1 = (conf_abuf_size ? conf_abuf_size : 4);
-
- priv->sys_info.cnt = 2;
-
- priv->sys_info.streams[0].id = 0xe0;
- priv->sys_info.streams[0].type = 1;
- priv->sys_info.streams[0].bufsize = v*1024;
-
- priv->sys_info.streams[1].id = 0xc0;
- priv->sys_info.streams[1].type = 0;
- priv->sys_info.streams[1].bufsize = a1*1024;
- }
- else
- priv->sys_info.cnt = 0;
-}
-
-/* excerpt from DGPulldown Copyright (C) 2005-2006, Donald Graft */
-static void generate_flags(uint8_t *bff_mask, int source, int target)
-{
- unsigned int i, trfp;
- uint64_t dfl,tfl;
- unsigned char ormask[4] = {0x0, 0x2, 0x80, 0x82};
-
- dfl = (target - source) << 1;
- tfl = source >> 1;
-
- trfp = 0;
- for(i = 0; i < MAX_PATTERN_LENGTH; i++)
- {
- tfl += dfl;
- if(tfl >= source)
- {
- tfl -= source;
- bff_mask[i] = ormask[trfp + 1];
- trfp ^= 2;
- }
- else
- bff_mask[i] = ormask[trfp];
- }
-}
-
-int muxer_init_muxer_mpeg(muxer_t *muxer)
-{
- muxer_priv_t *priv;
- priv = calloc(1, sizeof(muxer_priv_t));
- if(priv == NULL)
- return 0;
- priv->update_system_header = 1;
-
- //calloc() already zero-ed all flags, so we assign only the ones we need
-
- if(conf_mux != NULL)
- {
- if(! strcasecmp(conf_mux, "mpeg1"))
- {
- priv->mux = MUX_MPEG1;
- priv->packet_size = 2048;
- priv->is_genmpeg1 = 1;
- priv->muxrate = 1800 * 125; //Constrained parameters
- }
- else if(! strcasecmp(conf_mux, "dvd"))
- {
- priv->mux = MUX_MPEG2;
- priv->is_dvd = 1;
- priv->packet_size = 2048;
- priv->muxrate = 10080 * 125;
- }
- else if(! strcasecmp(conf_mux, "xsvcd"))
- {
- priv->mux = MUX_MPEG2;
- priv->is_xsvcd = 1;
- priv->packet_size = 2324;
- priv->muxrate = 150*2324;
- priv->ts_allframes = 1;
- }
- else if(! strcasecmp(conf_mux, "xvcd"))
- {
- priv->mux = MUX_MPEG1;
- priv->is_xvcd = 1;
- priv->packet_size = 2324;
- priv->muxrate = 75*2352;
- priv->ts_allframes = 1;
- }
- else if(! strcasecmp(conf_mux, "pes1"))
- {
- priv->mux = MUX_MPEG1;
- priv->rawpes = 1;
- priv->packet_size = 2048;
- priv->muxrate = 10080 * 125;
- priv->ts_allframes = 1;
- }
- else if(! strcasecmp(conf_mux, "pes2"))
- {
- priv->mux = MUX_MPEG2;
- priv->rawpes = 1;
- priv->packet_size = 2048;
- priv->muxrate = 10080 * 125;
- priv->ts_allframes = 1;
- }
- else
- {
- if(strcasecmp(conf_mux, "mpeg2"))
- mp_msg(MSGT_MUXER, MSGL_ERR, "Unknown format %s, default to mpeg2\n", conf_mux);
- priv->mux = MUX_MPEG2;
- priv->is_genmpeg2 = 1;
- priv->packet_size = 2048;
- priv->muxrate = 1800 * 125; //Constrained parameters
- }
- }
-
- if(conf_ts_allframes)
- priv->ts_allframes = 1;
- if(conf_muxrate > 0)
- priv->muxrate = conf_muxrate * 125; // * 1000 / 8
- if(conf_packet_size)
- priv->packet_size = conf_packet_size;
- priv->delta_scr = (uint64_t) (90000.0f*300.0f*(double)priv->packet_size/(double)priv->muxrate);
- mp_msg(MSGT_MUXER, MSGL_INFO, "PACKET SIZE: %u bytes, deltascr: %"PRIu64"\n", priv->packet_size, priv->delta_scr);
- setup_sys_params(priv);
-
- if(conf_vaspect > 0)
- {
- int asp = (int) (conf_vaspect * 1000.0f);
- if(asp >= 1332 && asp <= 1334)
- priv->vaspect = ASPECT_4_3;
- else if(asp >= 1776 && asp <= 1778)
- priv->vaspect = ASPECT_16_9;
- else if(asp >= 2209 && asp <= 2211)
- priv->vaspect = ASPECT_2_21_1;
- else if(asp == 1000)
- priv->vaspect = ASPECT_1_1;
- else
- mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: unrecognized aspect %.3f\n", conf_vaspect);
- }
-
- priv->vframerate = 0; // no change
- if(conf_telecine && conf_vframerate > 0)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: options 'telecine' and 'vframerate' are mutually exclusive, vframerate disabled\n");
- conf_vframerate = 0;
- }
-
- if(conf_telecine == TELECINE_FILM2PAL)
- {
- if(conf_telecine_src==0.0f) conf_telecine_src = 24000.0/1001.0;
- conf_telecine_dest = 25;
- conf_telecine = TELECINE_DGPULLDOWN;
- }
- else if(conf_telecine == PULLDOWN32)
- {
- if(conf_telecine_src==0.0f) conf_telecine_src = 24000.0/1001.0;
- conf_telecine_dest = 30000.0/1001.0;
- conf_telecine = TELECINE_DGPULLDOWN;
- }
-
- if(conf_telecine_src>0 && conf_telecine_dest>0 && conf_telecine_src < conf_telecine_dest)
- {
- int sfps, tfps;
-
- sfps = (int) (conf_telecine_src * 1001 + 0.5);
- tfps = (int) (conf_telecine_dest * 1001 + 0.5);
- if(sfps % 2 || tfps % 2)
- {
- sfps *= 2;
- tfps *= 2;
- }
-
- if(((tfps - sfps)>>1) > sfps)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR! Framerate increment must be <= 1.5, telecining disabled\n");
- conf_telecine = 0;
- }
- else
- {
- generate_flags(priv->bff_mask, sfps, tfps);
- conf_telecine = TELECINE_DGPULLDOWN;
- conf_vframerate = conf_telecine_dest;
- }
- }
-
- if(conf_vframerate)
- {
- int fps;
-
- fps = (int) (conf_vframerate * 1001 + 0.5);
- switch(fps)
- {
- case 24000:
- priv->vframerate = FRAMERATE_23976;
- break;
- case 24024:
- priv->vframerate = FRAMERATE_24;
- break;
- case 25025:
- priv->vframerate = FRAMERATE_25;
- break;
- case 30000:
- priv->vframerate = FRAMERATE_2997;
- break;
- case 30030:
- priv->vframerate = FRAMERATE_30;
- break;
- case 50050:
- priv->vframerate = FRAMERATE_50;
- break;
- case 60000:
- priv->vframerate = FRAMERATE_5994;
- break;
- case 60060:
- priv->vframerate = FRAMERATE_60;
- break;
- default:
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "WRONG FPS: %d/1000, ignoring\n", fps);
- if(conf_telecine)
- mp_msg(MSGT_MUXER, MSGL_ERR, "DISABLED TELECINING\n");
- conf_telecine = 0;
- }
- }
- }
-
- priv->vwidth = (uint16_t) conf_vwidth;
- priv->vheight = (uint16_t) conf_vheight;
- priv->panscan_width = (uint16_t) conf_panscan_width;
- priv->panscan_height = (uint16_t) conf_panscan_height;
- priv->vbitrate = ((conf_vbitrate) * 10) >> 2; //*1000 / 400
-
- if(priv->vaspect || priv->vframerate || priv->vwidth || priv->vheight || priv->vbitrate || priv->panscan_width || priv->panscan_height)
- {
- priv->patch_seq = priv->vaspect || priv->vframerate || priv->vwidth || priv->vheight || priv->vbitrate;
- priv->patch_sde = priv->panscan_width || priv->panscan_height;
- mp_msg(MSGT_MUXER, MSGL_INFO, "MPEG MUXER, patching");
- if(priv->vwidth || priv->vheight)
- mp_msg(MSGT_MUXER, MSGL_INFO, " resolution to %dx%d", priv->vwidth, priv->vheight);
- if(priv->panscan_width || priv->panscan_height)
- mp_msg(MSGT_MUXER, MSGL_INFO, " panscan to to %dx%d", priv->panscan_width, priv->panscan_height);
- if(priv->vframerate)
- mp_msg(MSGT_MUXER, MSGL_INFO, " framerate to %s fps", framerates[priv->vframerate]);
- if(priv->vaspect)
- mp_msg(MSGT_MUXER, MSGL_INFO, " aspect ratio to %s", aspect_ratios[priv->vaspect]);
- if(priv->vbitrate)
- mp_msg(MSGT_MUXER, MSGL_INFO, " bitrate to %u", conf_vbitrate);
- mp_msg(MSGT_MUXER, MSGL_INFO, "\n");
- }
-
- priv->has_video = priv->has_audio = 0;
-
- muxer->sysrate = priv->muxrate; // initial muxrate = constrained stream parameter
- priv->scr = muxer->file_end = 0;
-
- if(conf_init_vdelay && conf_drop)
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "\nmuxer_mpg, :drop and :vdelay used together are not supported, exiting\n");
- return 0;
- }
- if(conf_init_adelay)
- priv->init_adelay = - (double) conf_init_adelay / (double) 1000.0;
-
- priv->drop = conf_drop;
-
- priv->buff = malloc(priv->packet_size);
- if((priv->buff == NULL))
- {
- mp_msg(MSGT_MUXER, MSGL_ERR, "\nCouldn't allocate %d bytes, exit\n", priv->packet_size);
- return 0;
- }
-
- muxer->priv = (void *) priv;
- muxer->cont_new_stream = &mpegfile_new_stream;
- muxer->cont_write_chunk = &mpegfile_write_chunk;
- muxer->cont_write_header = &mpegfile_write_header;
- muxer->cont_write_index = &mpegfile_write_index;
- muxer->fix_stream_parameters = &fix_parameters;
- return 1;
-}
diff --git a/libmpdemux/muxer_rawaudio.c b/libmpdemux/muxer_rawaudio.c
deleted file mode 100644
index 68e433f4ad..0000000000
--- a/libmpdemux/muxer_rawaudio.c
+++ /dev/null
@@ -1,89 +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 <sys/types.h>
-
-#include "mp_msg.h"
-
-#include "aviheader.h"
-#include "ms_hdr.h"
-
-#include "stream/stream.h"
-#include "muxer.h"
-
-static muxer_stream_t* rawaudiofile_new_stream(muxer_t *muxer,int type){
- muxer_stream_t* s;
- if (!muxer) return NULL;
- if(type==MUXER_TYPE_AUDIO && muxer->avih.dwStreams>=1){
- mp_msg(MSGT_MUXER, MSGL_ERR, "%s %s", mp_gtext("Too many streams!"),
- mp_gtext("Rawaudio muxer supports only one audio stream!\n"));
- return NULL;
- }
- s=malloc(sizeof(muxer_stream_t));
- memset(s,0,sizeof(muxer_stream_t));
- if(!s) return NULL; // no mem!?
- muxer->streams[muxer->avih.dwStreams]=s;
- s->type=type;
- s->id=muxer->avih.dwStreams;
- s->timer=0.0;
- s->size=0;
- s->muxer=muxer;
- switch(type){
- case MUXER_TYPE_AUDIO:
- s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
- s->h.fccType=streamtypeAUDIO;
- muxer->avih.dwStreams++;
- break;
- case MUXER_TYPE_VIDEO:
- mp_tmsg(MSGT_MUXER,MSGL_WARN,"Ignoring video stream!\n");
- s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
- s->h.fccType=streamtypeAUDIO;
- break;
- default:
- mp_tmsg(MSGT_MUXER,MSGL_ERR,"Warning, unknown stream type: %d\n",type);
- return NULL;
- }
- return s;
-}
-
-static void rawaudiofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
- muxer_t *muxer=s->muxer;
-
- // write out the chunk:
- if (s->type==MUXER_TYPE_AUDIO)
- stream_write_buffer(muxer->stream, s->buffer, len);
-}
-
-static void rawaudiofile_write_header(muxer_t *muxer){
- return;
-}
-
-static void rawaudiofile_write_index(muxer_t *muxer){
- return;
-}
-
-int muxer_init_muxer_rawaudio(muxer_t *muxer){
- muxer->cont_new_stream = &rawaudiofile_new_stream;
- muxer->cont_write_chunk = &rawaudiofile_write_chunk;
- muxer->cont_write_header = &rawaudiofile_write_header;
- muxer->cont_write_index = &rawaudiofile_write_index;
- return 1;
-}
diff --git a/libmpdemux/muxer_rawvideo.c b/libmpdemux/muxer_rawvideo.c
deleted file mode 100644
index c4ed4ba22a..0000000000
--- a/libmpdemux/muxer_rawvideo.c
+++ /dev/null
@@ -1,92 +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 <inttypes.h>
-#include <unistd.h>
-
-#include "config.h"
-//#include "stream/stream.h"
-//#include "demuxer.h"
-//#include "stheader.h"
-#include "aviheader.h"
-#include "ms_hdr.h"
-
-#include "stream/stream.h"
-#include "muxer.h"
-
-static muxer_stream_t* rawvideofile_new_stream(muxer_t *muxer,int type){
- muxer_stream_t* s;
- if (!muxer) return NULL;
- s=malloc(sizeof(muxer_stream_t));
- memset(s,0,sizeof(muxer_stream_t));
- if(!s) return NULL; // no mem!?
- muxer->streams[muxer->avih.dwStreams]=s;
- s->type=type;
- s->id=muxer->avih.dwStreams;
- s->timer=0.0;
- s->size=0;
- s->muxer=muxer;
- switch(type){
- case MUXER_TYPE_VIDEO:
- s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
- s->h.fccType=streamtypeVIDEO;
- if(!muxer->def_v) muxer->def_v=s;
- break;
- }
- muxer->avih.dwStreams++;
- return s;
-}
-
-static void write_rawvideo_chunk(stream_t *stream,int len,void* data){
- if(len>0){
- if(data){
- // DATA
- stream_write_buffer(stream,data,len);
- }
- }
-}
-
-static void rawvideofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
- muxer_t *muxer=s->muxer;
-
- // write out the chunk:
- if (s->type == MUXER_TYPE_VIDEO)
- write_rawvideo_chunk(muxer->stream,len,s->buffer); /* unsigned char */
-
- // if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
-
-}
-
-static void rawvideofile_write_header(muxer_t *muxer){
- return;
-}
-
-static void rawvideofile_write_index(muxer_t *muxer){
- return;
-}
-
-int muxer_init_muxer_rawvideo(muxer_t *muxer){
- muxer->cont_new_stream = &rawvideofile_new_stream;
- muxer->cont_write_chunk = &rawvideofile_write_chunk;
- muxer->cont_write_header = &rawvideofile_write_header;
- muxer->cont_write_index = &rawvideofile_write_index;
- return 1;
-}
diff --git a/mencoder.c b/mencoder.c
deleted file mode 100644
index 34053e3fce..0000000000
--- a/mencoder.c
+++ /dev/null
@@ -1,1779 +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.
- */
-
-#define VCODEC_COPY 0
-#define VCODEC_FRAMENO 1
-// real codecs:
-#define VCODEC_LIBAVCODEC 4
-#define VCODEC_VFW 7
-#define VCODEC_LIBDV 8
-#define VCODEC_XVID 9
-#define VCODEC_QTVIDEO 10
-#define VCODEC_NUV 11
-#define VCODEC_RAW 12
-#define VCODEC_X264 13
-
-#define ACODEC_COPY 0
-#define ACODEC_PCM 1
-#define ACODEC_VBRMP3 2
-#define ACODEC_NULL 3
-#define ACODEC_LAVC 4
-#define ACODEC_TOOLAME 5
-#define ACODEC_FAAC 6
-#define ACODEC_TWOLAME 7
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include "config.h"
-
-#ifdef __MINGW32__
-#define SIGHUP 1
-#define SIGQUIT 3
-#define SIGPIPE 13
-#endif
-#if defined(__MINGW32__) || defined(__CYGWIN__)
-#include <windows.h>
-#endif
-
-#include <sys/time.h>
-
-#include "mp_msg.h"
-#include "av_log.h"
-
-#include "codec-cfg.h"
-#include "m_option.h"
-#include "m_config.h"
-#include "parser-mecmd.h"
-#include "parser-cfg.h"
-#include "mp_fifo.h"
-#include "path.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/aviprint.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-#include "libmpdemux/mp3_hdr.h"
-#include "libmpdemux/muxer.h"
-
-#include "input/input.h"
-#include "libvo/video_out.h"
-
-#include "libaf/af_format.h"
-
-#include "libmpcodecs/mp_image.h"
-#include "libmpcodecs/dec_audio.h"
-#include "libmpcodecs/dec_video.h"
-#include "libmpcodecs/vf.h"
-#include "libmpcodecs/vd.h"
-
-// for MPEGLAYER3WAVEFORMAT:
-#include "libmpdemux/ms_hdr.h"
-
-#include <inttypes.h>
-
-#include "libvo/fastmemcpy.h"
-
-#include "osdep/timer.h"
-
-#ifdef CONFIG_DVDREAD
-#include "stream/stream_dvd.h"
-#endif
-
-#include "stream/stream_dvdnav.h"
-#include "libavcodec/avcodec.h"
-
-#include "libmpcodecs/ae.h"
-#include "options.h"
-#include "defaultopts.h"
-
-MPOpts opts;
-struct osd_state *osd;
-
-const int under_mencoder = 1;
-int vo_doublebuffering=0;
-int vo_directrendering=0;
-int forced_subs_only=0;
-
-//--------------------------
-
-// cache2:
-int stream_cache_size=-1;
-#ifdef CONFIG_STREAM_CACHE
-float stream_cache_min_percent=20.0;
-float stream_cache_seek_min_percent=50.0;
-#endif
-
-int vobsub_id=-1;
-static char* spudec_ifo=NULL;
-
-static char** audio_codec_list=NULL; // override audio codec
-static char** video_codec_list=NULL; // override video codec
-static char** audio_fm_list=NULL; // override audio codec family
-static char** video_fm_list=NULL; // override video codec family
-extern char *demuxer_name; // override demuxer
-extern char *audio_demuxer_name; // override audio demuxer
-extern char *sub_demuxer_name; // override sub demuxer
-
-static int out_audio_codec=-1;
-static int out_video_codec=-1;
-
-int out_file_format=MUXER_TYPE_AVI; // default to AVI
-int quiet=0;
-double video_time_usage=0;
-double vout_time_usage=0;
-double max_video_time_usage=0;
-double max_vout_time_usage=0;
-double cur_video_time_usage=0;
-double cur_vout_time_usage=0;
-int benchmark=0;
-
-#include "osdep/priority.h"
-
-// A-V sync:
-int delay_corrected=1;
-static float default_max_pts_correction=-1;//0.01f;
-static float max_pts_correction=0;//default_max_pts_correction;
-static float c_total=0;
-
-static float audio_preload=0.5;
-static float audio_delay_fix=0.0;
-static float audio_delay=0.0;
-static int ignore_start=0;
-static int audio_density=2;
-
-double force_fps=0;
-static double force_ofps=0; // set to 24 for inverse telecine
-static int skip_limit=-1;
-
-static int force_srate=0;
-static int audio_output_format=0;
-
-char *vobsub_out=NULL;
-unsigned int vobsub_out_index=0;
-char *vobsub_out_id=NULL;
-
-char* out_filename=NULL;
-
-char *force_fourcc=NULL;
-int force_audiofmttag=-1;
-
-char* passtmpfile="divx2pass.log";
-
-static int play_n_frames=-1;
-static int play_n_frames_mf=-1;
-
-#include "libvo/font_load.h"
-#include "libvo/sub.h"
-
-// sub:
-char *font_name=NULL;
-char *sub_font_name=NULL;
-extern int font_fontconfig;
-float font_factor=0.75;
-char **sub_name=NULL;
-float sub_delay=0;
-float sub_fps=0;
-int sub_auto = 0;
-int subcc_enabled=0;
-int suboverlap_enabled = 1;
-
-int auto_expand=1;
-int encode_duplicates=1;
-
-// infos are empty by default
-char *info_name=NULL;
-char *info_artist=NULL;
-char *info_genre=NULL;
-char *info_subject=NULL;
-char *info_copyright=NULL;
-char *info_sourceform=NULL;
-char *info_comment=NULL;
-
-// Needed by libmpcodecs vf_vo.c
-int vo_config(struct vo *vo, uint32_t width, uint32_t height,
- uint32_t d_width, uint32_t d_height, uint32_t flags,
- char *title, uint32_t format) { abort(); }
-int vo_control(struct vo *vo, uint32_t request, void *data) { abort(); }
-void vo_seek_reset(struct vo *vo) { abort(); }
-int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts) { abort(); }
-int vo_draw_frame(struct vo *vo, uint8_t *src[]) { abort(); }
-int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y) { abort(); }
-void vo_draw_osd(struct vo *vo, struct osd_state *osd) { abort(); }
-void vo_flip_page(struct vo *vo, uint32_t pts_us, int duration) { abort(); }
-void vo_check_events(struct vo *vo) { abort(); }
-
-// Needed by getch2
-struct mp_fifo;
-void mplayer_put_key(struct mp_fifo *fifo, int code)
-{
-}
-
-#include "ass_mp.h"
-char *current_module;
-#include "mpcommon.h"
-
-// Needed by mpcommon.c
-void set_osd_subtitle(struct MPContext *mpctx, subtitle *subs) {
- vo_sub = subs;
- vo_osd_changed(OSDTYPE_SUBTITLE);
-}
-
-//-------------------------- config stuff:
-
-m_config_t* mconfig;
-
-static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
-
-static int cfg_include(m_option_t *conf, char *filename){
- return m_config_parse_config_file(mconfig, filename);
-}
-
-static double seek_to_sec;
-static off_t seek_to_byte=0;
-
-static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 };
-
-static char * frameno_filename=NULL;
-
-typedef struct {
- unsigned char* start;
- int in_size;
- float frame_time;
- int already_read;
-} s_frame_data;
-
-#include "edl.h"
-static edl_record_ptr edl_records = NULL; ///< EDL entries memory area
-static edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
-static short edl_muted; ///< Stores whether EDL is currently in muted mode.
-static short edl_seeking; ///< When non-zero, stream is seekable.
-static short edl_seek_type; ///< When non-zero, frames are discarded instead of seeking.
-
-#include "cfg-mencoder.h"
-
-#include "spudec.h"
-#include "vobsub.h"
-
-#include "libao2/audio_out.h"
-/* FIXME */
-static void mencoder_exit(int level, const char *how)
-{
- if (how)
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nExiting... (%s)\n", how);
- else
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nExiting...\n");
-
- exit(level);
-}
-
-static void parse_cfgfiles( m_config_t* conf )
-{
- char *conffile;
- if (!disable_system_conf &&
- m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mencoder.conf") < 0)
- mencoder_exit(1,_("config file error"));
-
- if (!disable_user_conf) {
- if ((conffile = get_path("mencoder.conf")) == NULL) {
- mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"get_path(\"config\") problem\n");
- } else {
- if (m_config_parse_config_file(conf, conffile) < 0)
- mencoder_exit(1,_("config file error"));
- free(conffile);
- }
- }
-}
-
-
-//---------------------------------------------------------------------------
-
-static int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){
- int size=0;
- int at_eof=0;
- while(size<total && !at_eof){
- int len=total-size;
- if (decode_audio(sh_audio, len) < 0) at_eof=1;
- if(len>sh_audio->a_out_buffer_len) len=sh_audio->a_out_buffer_len;
- fast_memcpy(buffer+size,sh_audio->a_out_buffer,len);
- sh_audio->a_out_buffer_len-=len; size+=len;
- if(sh_audio->a_out_buffer_len>0)
- fast_memcpy(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[len],sh_audio->a_out_buffer_len);
- }
- return size;
-}
-
-//---------------------------------------------------------------------------
-
-static volatile int at_eof=0;
-static volatile int interrupted=0;
-
-static void exit_sighandler(int x){
- at_eof=1;
- interrupted=2; /* 1 means error */
-}
-
-static muxer_t* muxer=NULL;
-
-static void add_subtitles(char *filename, float fps, int silent)
-{
- sub_data *subd;
-#ifdef CONFIG_ASS
- ASS_Track *asst = 0;
-#endif
-
- if (!filename) return;
-
- subd = sub_read_file(filename, fps);
-#ifdef CONFIG_ASS
- if (opts.ass_enabled)
-#ifdef CONFIG_ICONV
- asst = ass_read_file(ass_library, filename, sub_cp);
-#else
- asst = ass_read_file(ass_library, filename, 0);
-#endif
- if (opts.ass_enabled && subd && !asst)
- asst = ass_read_subdata(ass_library, subd, fps);
-
- if (!asst && !subd && !silent)
-#else
- if (!subd && !silent)
-#endif
- mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Cannot load subtitles: %s\n",
- filename_recode(filename));
-
-#ifdef CONFIG_ASS
- if (!asst && !subd) return;
- ass_track = asst;
-#else
- if (!subd) return;
-#endif
- mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n",
- filename_recode(filename));
- subdata = subd;
-}
-
-/* This function returns the absolute time for which MEncoder will switch files
- * or move in the file so audio can be cut correctly. -1 if there is no limit. */
-static float stop_time(demuxer_t* demuxer, muxer_stream_t* mux_v)
-{
- float timeleft = -1;
- if (play_n_frames >= 0) timeleft = mux_v->timer + play_n_frames * (double)(mux_v->h.dwScale) / mux_v->h.dwRate;
- if (end_at.type == END_AT_TIME && (timeleft > end_at.pos || timeleft == -1)) timeleft = end_at.pos;
- if (next_edl_record && demuxer && demuxer->video) { // everything is OK to be checked
- float tmp = mux_v->timer + next_edl_record->start_sec - demuxer->video->pts;
- if (timeleft == -1 || timeleft > tmp) {
- // There's less time in EDL than what we already know
- if (next_edl_record->action == EDL_SKIP && edl_seeking) {
- timeleft = tmp;
- } else if (next_edl_record->action == EDL_MUTE) {
- //timeleft = next_edl_record->start_sec - demuxer->video->pts;
- // For the moment (and probably forever) EDL mute doesn't work in MEncoder
- }
- }
- }
- return timeleft;
-}
-
-/// Returns a_pts
-static float calc_a_pts(demux_stream_t *d_audio)
-{
- sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
- float a_pts = 0.;
- if (sh_audio)
- a_pts = d_audio->pts + (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
- return a_pts;
-}
-
-/** \brief Seeks audio forward to pts by dumping audio packets
- * \return The current audio pts. */
-static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* mux_a)
-{
- sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
- int samplesize, avg;
- float a_pts = calc_a_pts(d_audio);
-
- if (!sh_audio) return a_pts;
-
- if (sh_audio->audio.dwScale) samplesize = sh_audio->audio.dwSampleSize;
- else samplesize = (sh_audio->wf ? sh_audio->wf->nBlockAlign : 1);
- avg = (sh_audio->wf ? sh_audio->wf->nAvgBytesPerSec : sh_audio->i_bps);
-
- // after a demux_seek, a_pts will be zero until you read some audio.
- // carefully checking if a_pts is truely correct by reading tiniest amount of data possible.
- if (pts > a_pts && a_pts == 0.0 && samplesize) {
- if (demux_read_data(sh_audio->ds,mux_a->buffer,samplesize) <= 0) return a_pts; // EOF
- a_pts = calc_a_pts(d_audio);
- }
-
- while (pts > a_pts) {
- int len;
- if (samplesize) {
- len = avg * (pts - a_pts > 0.5 ? 0.5 : pts - a_pts);
- len/= samplesize; if(len<1) len=1;
- len*= samplesize;
- len = demux_read_data(sh_audio->ds,mux_a->buffer,len);
- } else {
- unsigned char * crap;
- len = ds_get_packet(sh_audio->ds, &crap);
- }
- if (len <= 0) break; // EOF of audio.
- a_pts = calc_a_pts(d_audio);
- }
- return a_pts;
-}
-
-/** \brief Seeks slowly by dumping frames.
- * \return 1 for success, 2 for EOF. */
-static int slowseek(float end_pts, demux_stream_t *d_video,
- demux_stream_t *d_audio, muxer_stream_t *mux_a,
- s_frame_data *frame_data, int framecopy, int print_info)
-{
- sh_video_t * sh_video = d_video->sh;
- vf_instance_t * vfilter = sh_video ? sh_video->vfilter : NULL;
- int done = 0;
-
- while (!interrupted) {
- float a_pts = 0.;
-
- if (!frame_data->already_read) { // when called after fixdelay, a frame is already read
- frame_data->in_size = video_read_frame(sh_video, &frame_data->frame_time, &frame_data->start, force_fps);
- if(frame_data->in_size<0) return 2;
- sh_video->timer += frame_data->frame_time;
- }
- frame_data->already_read = 0;
-
- a_pts = forward_audio(sh_video->pts - frame_data->frame_time + audio_delay, d_audio, mux_a);
-
- if (done) {
- // wait for keyframe in case of -ovc copy
- if (!framecopy || (sh_video->ds->flags & 1)) {
- frame_data->already_read = 1;
- return 1;
- }
- }
- if (sh_video->pts >= end_pts) done = 1;
-
- if (vfilter) {
- sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ,
- osd);
- int softskip = (vfilter->control(vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) == CONTROL_TRUE);
- void *decoded_frame = decode_video(sh_video, frame_data->start, frame_data->in_size, !softskip, MP_NOPTS_VALUE);
- if (decoded_frame)
- if (filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE)) {
- struct vf_instance *vf = sh_video->vfilter;
- vf->control(vf, VFCTRL_DRAW_EOSD, NULL);
- vf->control(vf, VFCTRL_DRAW_OSD, osd);
- }
- }
-
- if (print_info) mp_tmsg(MSGT_MENCODER, MSGL_STATUS,
- "EDL SKIP: Start: %.2f End: %.2f Current: V: %.2f A: %.2f \r",
- next_edl_record->start_sec, next_edl_record->stop_sec,
- sh_video->pts, a_pts);
- }
- if (interrupted) return 2;
- return 1;
-}
-
-/// Deletes audio or video as told by -delay to sync
-static void fixdelay(demux_stream_t *d_video, demux_stream_t *d_audio,
- muxer_stream_t *mux_a, s_frame_data *frame_data,
- int framecopy)
-{
- // TODO: Find a way to encode silence instead of deleting video
- sh_video_t * sh_video = d_video->sh;
- float a_pts;
-
- // demux_seek has a weirdness that sh_video->pts is meaningless,
- // until a single frame is read... Same for audio actually too.
- // Reading one frame, and keeping it.
- frame_data->in_size = video_read_frame(sh_video, &frame_data->frame_time, &frame_data->start, force_fps);
- if(frame_data->in_size<0) return;
- sh_video->timer += frame_data->frame_time;
- frame_data->already_read = 1;
-
- a_pts = forward_audio(sh_video->pts - frame_data->frame_time + audio_delay, d_audio, mux_a);
-
- if (audio_delay > 0) return;
- else if (sh_video->pts - frame_data->frame_time + audio_delay >= a_pts) return;
-
- slowseek(a_pts - audio_delay, d_video, d_audio, mux_a, frame_data, framecopy, 0);
-}
-
-/** \brief Seeks for EDL
- * \return 1 for success, 0 for failure, 2 for EOF. */
-static int edl_seek(edl_record_ptr next_edl_record, demuxer_t *demuxer,
- demux_stream_t *d_audio, muxer_stream_t *mux_a,
- s_frame_data *frame_data, int framecopy)
-{
- sh_video_t * sh_video = demuxer->video ? demuxer->video->sh : NULL;
-
- if (!sh_video) return 0;
- if (sh_video->pts >= next_edl_record->stop_sec) return 1; // nothing to do...
-
- if (!edl_seek_type) {
- if(demux_seek(demuxer, next_edl_record->stop_sec - sh_video->pts, audio_delay, 0)){
- sh_video->pts = demuxer->video->pts;
- //if (vo_vobsub) vobsub_seek(vo_vobsub,sh_video->pts);
- resync_video_stream(sh_video);
- //if(vo_spudec) spudec_reset(vo_spudec);
- if (audio_delay != 0.0) fixdelay(demuxer->video, d_audio, mux_a, frame_data, framecopy);
- return 1;
- }
- // non-seekable stream.
- return 0;
- }
-
- // slow seek, read every frame.
-
- return slowseek(next_edl_record->stop_sec, demuxer->video, d_audio, mux_a, frame_data, framecopy, 1);
-}
-
-
-int main(int argc,char* argv[]){
-
-stream_t* stream=NULL;
-stream_t* ostream=NULL;
-demuxer_t* demuxer=NULL;
-stream_t* stream2=NULL;
-demuxer_t* demuxer2=NULL;
-demux_stream_t *d_audio=NULL;
-demux_stream_t *d_video=NULL;
-demux_stream_t *d_dvdsub=NULL;
-sh_audio_t *sh_audio=NULL;
-sh_video_t *sh_video=NULL;
-int file_format=DEMUXER_TYPE_UNKNOWN;
-int i=DEMUXER_TYPE_UNKNOWN;
-void *vobsub_writer=NULL;
-s_frame_data frame_data = { .start = NULL, .in_size = 0, .frame_time = 0., .already_read = 0 };
-
-uint32_t ptimer_start;
-uint32_t audiorate=0;
-uint32_t videorate=0;
-uint32_t audiosamples=1;
-uint32_t videosamples=1;
-uint32_t skippedframes=0;
-uint32_t duplicatedframes=0;
-uint32_t badframes=0;
-
-muxer_stream_t* mux_a=NULL;
-muxer_stream_t* mux_v=NULL;
-off_t muxer_f_size=0;
-
-double v_pts_corr=0;
-double v_timer_corr=0;
-
-m_entry_t* filelist = NULL;
-char* filename=NULL;
-
-int decoded_frameno=0;
-int next_frameno=-1;
-int curfile=0;
-int new_srate=0;
-
-unsigned int timer_start=0;
-ao_data_t ao_data = {0,0,0,0,OUTBURST,-1,0};
-
-audio_encoding_params_t aparams;
-audio_encoder_t *aencoder = NULL;
-
- mp_msg_init();
- set_av_log_callback();
-
- // Create the config context and register the options
- set_default_mencoder_options(&opts);
- mconfig = m_config_new(&opts, cfg_include);
- m_config_register_options(mconfig,mencoder_opts);
- m_config_register_options(mconfig, common_opts);
-
- // Preparse the command line
- m_config_preparse_command_line(mconfig,argc,argv);
-
- print_version("MEncoder");
-
-#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
- set_path_env();
-#endif
-
- InitTimer();
-
-// check codec.conf
-if(!codecs_file || !parse_codec_cfg(codecs_file)){
- if(!parse_codec_cfg(get_path("codecs.conf"))){
- if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
- if(!parse_codec_cfg(NULL)){
- mencoder_exit(1,NULL);
- }
- mp_tmsg(MSGT_MENCODER,MSGL_V,"Using built-in default codecs.conf.\n");
- }
- }
-}
-
- parse_cfgfiles(mconfig);
- filelist = m_config_parse_me_command_line(mconfig, argc, argv);
- if(!filelist) mencoder_exit(1, _("error parsing command line"));
-
-{
- char *extension;
-
- if (!out_filename) mencoder_exit(1,_("No output file specified, please see the -o option."));
- extension=strrchr(out_filename,'.');
- if (extension != NULL && strlen(extension) > 3 && strlen(extension) < 6)
- {
- extension++;
-
- switch (out_file_format)
- {
- case MUXER_TYPE_AVI:
- if (strcasecmp(extension,"avi"))
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "\nWARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.\n");
- break;
-
- case MUXER_TYPE_MPEG:
- if (strcasecmp(extension,"mpg") &&
- strcasecmp(extension,"mpeg") &&
- strcasecmp(extension,"vob"))
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "\nWARNING: OUTPUT FILE FORMAT IS _MPEG_. See -of help.\n");
- break;
- }
- }
-}
- /* Display what configure line was used */
- mp_msg(MSGT_MENCODER, MSGL_V, "Configuration: " CONFIGURATION "\n");
-
-#define FormatNotRecognized _("============ Sorry, this file format is not recognized/supported =============\n"\
-"=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n")
-
-
-if (frameno_filename) {
- stream2=open_stream(frameno_filename, NULL, NULL);
- if(stream2){
- demuxer2=demux_open(&opts, stream2,DEMUXER_TYPE_AVI,-1,-1,-2,NULL);
- if(demuxer2) mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Using pass3 control file: %s\n", frameno_filename);
- else mp_tmsg(MSGT_DEMUXER,MSGL_ERR, FormatNotRecognized);
- }
-}
-
-#ifdef CONFIG_PRIORITY
- set_priority();
-#endif
-
- if (codec_path)
- set_codec_path(codec_path);
-
-// check font
-#ifdef CONFIG_FREETYPE
- init_freetype();
-#endif
-#ifdef CONFIG_FONTCONFIG
- if(font_fontconfig <= 0)
- {
-#endif
-#ifdef CONFIG_BITMAP_FONT
- if(font_name){
- vo_font=read_font_desc(font_name,font_factor,verbose>1);
- if(!vo_font) mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"Cannot load bitmap font: %s\n",font_name);
- } else {
- // try default:
- vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
- if(!vo_font)
- vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
- }
-#endif
-#ifdef CONFIG_FONTCONFIG
- }
-#endif
-
- osd = osd_create();
-
- /* HACK, for some weird reason, push() has to be called twice,
- otherwise options are not saved correctly */
- m_config_push(mconfig);
-play_next_file:
- m_config_push(mconfig);
- m_entry_set_options(mconfig,&filelist[curfile]);
- filename = filelist[curfile].name;
-
-#ifdef CONFIG_ASS
- ass_library = ass_init();
-#endif
-
- if(!filename){
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "\nFilename missing.\n\n");
- mencoder_exit(1,NULL);
- }
- stream=open_stream(filename,0,&file_format);
-
- if(!stream){
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Cannot open file/device.\n");
- mencoder_exit(1,NULL);
- }
-
- mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "success: format: %d data: 0x%X - 0x%x\n", file_format, (int)(stream->start_pos), (int)(stream->end_pos));
-
-#ifdef CONFIG_DVDREAD
-if(stream->type==STREAMTYPE_DVD){
- if(opts.audio_lang && opts.audio_id==-1) opts.audio_id=dvd_aid_from_lang(stream,opts.audio_lang);
- if(opts.sub_lang && opts.sub_id==-1) opts.sub_id=dvd_sid_from_lang(stream,opts.sub_lang);
-}
-#endif
-
-#ifdef CONFIG_DVDNAV
-if(stream->type==STREAMTYPE_DVDNAV){
- if(opts.audio_lang && opts.audio_id==-1) opts.audio_id=mp_dvdnav_aid_from_lang(stream,opts.audio_lang);
- if(opts.sub_lang && opts.sub_id==-1) opts.sub_id=mp_dvdnav_sid_from_lang(stream,opts.sub_lang);
-}
-#endif
-
- stream->start_pos+=seek_to_byte;
-
- if(stream_cache_size>0) stream_enable_cache(stream,stream_cache_size*1024,0,0);
-
- if(demuxer2) opts.audio_id=-2; /* do NOT read audio packets... */
-
- demuxer=demux_open(&opts, stream,file_format,opts.audio_id,opts.video_id,opts.sub_id,filename);
- if(!demuxer){
- mp_tmsg(MSGT_DEMUXER, MSGL_FATAL, FormatNotRecognized);
- mp_tmsg(MSGT_DEMUXER, MSGL_FATAL, "Cannot open demuxer.\n");
- mencoder_exit(1,NULL);
- }
-
- if (ts_prog) {
- demux_program_t prog = { .progid = ts_prog };
- if (demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) != DEMUXER_CTRL_NOTIMPL) {
- opts.audio_id = prog.aid; // switching is handled by select_audio below
- opts.video_id = prog.vid;
- demuxer_switch_video(demuxer, opts.video_id);
- }
- }
- select_audio(demuxer, opts.audio_id, opts.audio_lang);
-
- if (opts.sub_id < -1 && opts.sub_lang)
- opts.sub_id = demuxer_sub_track_by_lang(demuxer, opts.sub_lang);
-
- if (opts.sub_id < -1)
- opts.sub_id = demuxer_default_sub_track(demuxer);
-
- for (i = 0; i < MAX_S_STREAMS; i++) {
- sh_sub_t *sh = demuxer->s_streams[i];
- if (sh && sh->sid == opts.sub_id) {
- demuxer->sub->id = i;
- demuxer->sub->sh = sh;
- break;
- }
- }
-
- if(opts.chapterrange[0]>1) {
- double pts;
- if (demuxer_seek_chapter(demuxer, opts.chapterrange[0]-1, &pts, NULL) >= 0 && pts > -1.0)
- seek_to_sec = pts;
- }
-
-d_audio=demuxer2 ? demuxer2->audio : demuxer->audio;
-d_video=demuxer->video;
-d_dvdsub=demuxer->sub;
-sh_audio=d_audio->sh;
-sh_video=d_video->sh;
-
- if(!sh_video)
- {
- mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,"Video stream is mandatory!\n");
- mencoder_exit(1,NULL);
- }
-
- if(!video_read_properties(sh_video)){
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Video: Cannot read properties.\n");
- mencoder_exit(1,NULL);
- }
-
- mp_tmsg(MSGT_MENCODER,MSGL_INFO, "[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n",
- demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
- sh_video->fps,sh_video->frametime
- );
-
- if(force_fps){
- sh_video->fps=force_fps;
- sh_video->frametime=1.0f/sh_video->fps;
- mp_tmsg(MSGT_MENCODER,MSGL_INFO,"Input fps will be interpreted as %5.3f instead.\n", sh_video->fps);
- }
-
- if(sh_audio && out_audio_codec<0){
- if(opts.audio_id==-2)
- mp_tmsg(MSGT_MENCODER,MSGL_ERR,"This demuxer doesn't support -nosound yet.\n");
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nNo audio encoder (-oac) selected. Select one (see -oac help) or use -nosound.\n");
- mencoder_exit(1,NULL);
- }
- if(sh_video && out_video_codec<0){
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nNo video encoder (-ovc) selected. Select one (see -ovc help).\n");
- mencoder_exit(1,NULL);
- }
-
-if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf || opts.playback_speed != 1.0)){
- // Go through the codec.conf and find the best codec...
- mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
- if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
- sh_audio=d_audio->sh=NULL; // failed to init :(
- }
- mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
-}
-
- if (sh_audio) {
- new_srate = sh_audio->samplerate;
- if (opts.playback_speed != 1.0) {
- new_srate *= opts.playback_speed;
- // limits are taken from libaf/af_resample.c
- if (new_srate < 8000) new_srate = 8000;
- if (new_srate > 192000) new_srate = 192000;
- opts.playback_speed = (float)new_srate / (float)sh_audio->samplerate;
- }
- }
-
-// set up video encoder:
-
-if (!curfile) { // curfile is non zero when a second file is opened
-if (vobsub_out) {
- unsigned int palette[16], width, height;
- unsigned char tmp[3] = { 0, 0, 0 };
- if (spudec_ifo && vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, opts.sub_id, tmp) >= 0)
- vobsub_writer = vobsub_out_open(vobsub_out, palette, sh_video->disp_w, sh_video->disp_h,
- vobsub_out_id?vobsub_out_id:(char *)tmp, vobsub_out_index);
-#ifdef CONFIG_DVDREAD
- if (vobsub_writer == NULL) {
- char tmp[3];
- if (vobsub_out_id == NULL && stream->type == STREAMTYPE_DVD) {
- int i;
- dvd_priv_t *dvd = (dvd_priv_t*)stream->priv;
- for (i = 0; i < dvd->nr_of_subtitles; ++i)
- if (dvd->subtitles[i].id == opts.sub_id) {
- tmp[0] = (dvd->subtitles[i].language >> 8) & 0xff;
- tmp[1] = dvd->subtitles[i].language & 0xff;
- tmp[2] = 0;
- vobsub_out_id = tmp;
- break;
- }
- }
- vobsub_writer=vobsub_out_open(vobsub_out, stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL,
- sh_video->disp_w, sh_video->disp_h, vobsub_out_id, vobsub_out_index);
- }
-#endif
-}
-else {
-if (spudec_ifo) {
- unsigned int palette[16], width, height;
- if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
- vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h, NULL, 0);
-}
-#ifdef CONFIG_DVDREAD
-if (vo_spudec==NULL) {
-vo_spudec=spudec_new_scaled(stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL,
- sh_video->disp_w, sh_video->disp_h, NULL, 0);
-}
-#endif
-if (vo_spudec)
- spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
-}
-
-ostream = open_output_stream(out_filename, 0);
-if(!ostream) {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Cannot open output file '%s'.\n", out_filename);
- mencoder_exit(1,NULL);
-}
-
-muxer=muxer_new_muxer(out_file_format,ostream);
-if(!muxer) {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Cannot initialize muxer.");
- mencoder_exit(1,NULL);
-}
-#if 0
-//disabled: it horrybly distorts filtered sound
-if(out_file_format == MUXER_TYPE_MPEG) audio_preload = 0;
-#endif
-
-muxer->audio_delay_fix = audio_delay_fix;
-
-// ============= VIDEO ===============
-
-mux_v=muxer_new_stream(muxer,MUXER_TYPE_VIDEO);
-
-mux_v->buffer_size=0x200000; // 2MB
-mux_v->buffer=malloc(mux_v->buffer_size);
-
-mux_v->source=sh_video;
-
-mux_v->h.dwSampleSize=0; // VBR
-#ifdef CONFIG_LIBAVCODEC
-{
- double fps = force_ofps?force_ofps:sh_video->fps*opts.playback_speed;
- AVRational q= av_d2q(fps, fps*1001+2);
- mux_v->h.dwScale= q.den;
- mux_v->h.dwRate = q.num;
-}
-#else
-mux_v->h.dwScale=10000;
-mux_v->h.dwRate=mux_v->h.dwScale*(force_ofps?force_ofps:sh_video->fps*opts.playback_speed);
-#endif
-
-mux_v->codec=out_video_codec;
-
-mux_v->bih=NULL;
-}
-sh_video->codec=NULL;
-sh_video->vfilter=NULL; // fixme!
-
-switch(mux_v->codec){
-case VCODEC_COPY:
- if (!curfile) {
- if (sh_video->bih) {
- mux_v->bih=malloc(sh_video->bih->biSize);
- memcpy(mux_v->bih, sh_video->bih, sh_video->bih->biSize);
- }
- else
- {
- mux_v->bih=calloc(1,sizeof(BITMAPINFOHEADER));
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
- mux_v->bih->biWidth=sh_video->disp_w;
- mux_v->bih->biHeight=sh_video->disp_h;
- mux_v->bih->biCompression=sh_video->format;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24; // FIXME!!!
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
- }
- }
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n",
- mux_v->bih->biWidth, mux_v->bih->biHeight,
- mux_v->bih->biBitCount, mux_v->bih->biCompression);
-
- if (curfile) {
- if (sh_video->bih) {
- if ((mux_v->bih->biSize != sh_video->bih->biSize) ||
- memcmp(mux_v->bih, sh_video->bih, sh_video->bih->biSize))
- {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n",
- sh_video->bih->biWidth, sh_video->bih->biHeight,
- sh_video->bih->biBitCount, sh_video->bih->biCompression);
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nAll video files must have identical fps, resolution, and codec for -ovc copy.\n");
- mencoder_exit(1,NULL);
- }
- }
- else {
- if ((mux_v->bih->biWidth != sh_video->disp_w) ||
- (mux_v->bih->biHeight != sh_video->disp_h) ||
- (mux_v->bih->biCompression != sh_video->format)) {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n",
- sh_video->disp_w, sh_video->disp_w, 24, sh_video->format);
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nAll video files must have identical fps, resolution, and codec for -ovc copy.\n");
- mencoder_exit(1,NULL);
- }
- }
- }
- break;
-case VCODEC_FRAMENO:
- if (!curfile) {
- mux_v->bih=calloc(1,sizeof(BITMAPINFOHEADER));
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
- mux_v->bih->biWidth=sh_video->disp_w;
- mux_v->bih->biHeight=sh_video->disp_h;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24;
- mux_v->bih->biCompression=mmioFOURCC('F','r','N','o');
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
- }
- break;
-default: {
- static vf_instance_t * ve = NULL;
- if (!ve) {
- switch(mux_v->codec){
- case VCODEC_LIBAVCODEC:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"lavc",(char *)mux_v); break;
- case VCODEC_RAW:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"raw",(char *)mux_v); break;
- case VCODEC_VFW:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"vfw",(char *)mux_v); break;
- case VCODEC_LIBDV:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"libdv",(char *)mux_v); break;
- case VCODEC_XVID:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"xvid",(char *)mux_v); break;
- case VCODEC_QTVIDEO:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"qtvideo",(char *)mux_v); break;
- case VCODEC_NUV:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"nuv",(char *)mux_v); break;
- case VCODEC_X264:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"x264",(char *)mux_v); break;
- }
- if(!mux_v->bih || !sh_video->vfilter){
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"Failed to open the encoder.\n");
- mencoder_exit(1,NULL);
- }
- ve = sh_video->vfilter;
- } else sh_video->vfilter = ve;
- // append 'expand' filter, it fixes stride problems and renders osd:
-#ifdef CONFIG_ASS
- if (auto_expand && !opts.ass_enabled) { /* we do not want both */
-#else
- if (auto_expand) {
-#endif
- char* vf_args[] = { "osd", "1", NULL };
- sh_video->vfilter=vf_open_filter(&opts, sh_video->vfilter,"expand",vf_args);
- }
-
-#ifdef CONFIG_ASS
- if(opts.ass_enabled) {
- int i;
- int insert = 1;
- if (opts.vf_settings)
- for (i = 0; opts.vf_settings[i].name; ++i)
- if (strcmp(opts.vf_settings[i].name, "ass") == 0) {
- insert = 0;
- break;
- }
- if (insert) {
- extern vf_info_t vf_info_ass;
- vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
- char* vf_arg[] = {"auto", "1", NULL};
- vf_instance_t* vf_ass = vf_open_plugin(&opts,libass_vfs,sh_video->vfilter,"ass",vf_arg);
- if (vf_ass)
- sh_video->vfilter=(void*)vf_ass;
- else
- mp_msg(MSGT_CPLAYER,MSGL_ERR, "ASS: cannot add video filter\n");
- }
-
- if (ass_library) {
- for (i = 0; i < demuxer->num_attachments; ++i) {
- demux_attachment_t* att = demuxer->attachments + i;
- if (use_embedded_fonts && attachment_is_font(att))
- ass_add_font(ass_library, att->name, att->data, att->data_size);
- }
- }
- }
-#endif
-
- sh_video->vfilter=append_filters(sh_video->vfilter, opts.vf_settings);
-
-#ifdef CONFIG_ASS
- if (opts.ass_enabled)
- ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_INIT_EOSD, ass_library);
-#endif
-
-// after reading video params we should load subtitles because
-// we know fps so now we can adjust subtitles time to ~6 seconds AST
-// check .sub
- if(sub_name && sub_name[0]){
- for (i = 0; sub_name[i] != NULL; ++i)
- add_subtitles (sub_name[i], sh_video->fps, 0);
- } else
- if(sub_auto && filename) { // auto load sub file ...
- char **tmp = NULL;
- int i = 0;
- char *psub = get_path( "sub/" );
- tmp = sub_filenames((psub ? psub : ""), filename);
- free(psub);
- while (tmp[i])
- {
- add_subtitles (tmp[i], sh_video->fps, 0);
- free(tmp[i++]);
- }
- free(tmp);
- }
-
- mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
- init_best_video_codec(sh_video,video_codec_list,video_fm_list);
- mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
- if(!sh_video->initialized) mencoder_exit(1,NULL);
- }
-}
-
-if (!curfile) {
-/* force output fourcc to .. */
-if ((force_fourcc != NULL) && (strlen(force_fourcc) >= 4))
-{
- mux_v->bih->biCompression = mmioFOURCC(force_fourcc[0], force_fourcc[1],
- force_fourcc[2], force_fourcc[3]);
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Forcing output FourCC to %x [%.4s].\n",
- mux_v->bih->biCompression, (char *)&mux_v->bih->biCompression);
-}
-
-if (! ignore_start)
- muxer->audio_delay_fix -= sh_video->stream_delay;
-
-//if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
-
-// ============= AUDIO ===============
-if(sh_audio){
-
-if (force_audiofmttag != -1) {
- sh_audio->format = force_audiofmttag;
- if (sh_audio->wf) {
- sh_audio->wf->wFormatTag = sh_audio->format;
- }
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Forcing output audio format tag to 0x%x.\n",
- force_audiofmttag);
-}
-
-mux_a=muxer_new_stream(muxer,MUXER_TYPE_AUDIO);
-
-mux_a->buffer_size=0x100000; //16384;
-mux_a->buffer=malloc(mux_a->buffer_size);
-if (!mux_a->buffer)
- mencoder_exit(1,_("Memory allocation failed.\n"));
-
-mux_a->source=sh_audio;
-
-mux_a->codec=out_audio_codec;
-
-ao_data.samplerate = force_srate;
-ao_data.channels = 0;
-ao_data.format = audio_output_format;
-if(!init_audio_filters(sh_audio,
- // input:
- new_srate,
- // output:
- &ao_data.samplerate, &ao_data.channels, &ao_data.format)) {
- mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"Error at audio filter chain pre-init!\n");
- mencoder_exit(1, NULL);
- }
-
-aparams.channels = ao_data.channels;
-aparams.sample_rate = ao_data.samplerate;
-aparams.audio_preload = 1000 * audio_preload;
-if(mux_a->codec != ACODEC_COPY) {
- aencoder = new_audio_encoder(mux_a, &aparams);
- if(!aencoder)
- mencoder_exit(1, NULL);
- if(!init_audio_filters(sh_audio,
- new_srate,
- &aparams.sample_rate, &aparams.channels, &aencoder->input_format)) {
- mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,"Couldn't find matching filter/ao format!\n");
- mencoder_exit(1,NULL);
- }
-}
-
-#define NoSpeedWithFrameCopy _("WARNING: -speed is not guaranteed to work correctly with -oac copy!\n"\
-"Your encode might be broken!\n")
-
-switch(mux_a->codec){
-case ACODEC_COPY:
- if (opts.playback_speed != 1.0) mp_tmsg(MSGT_CPLAYER, MSGL_WARN, NoSpeedWithFrameCopy);
- if (sh_audio->format >= 0x10000) {
- mp_tmsg(MSGT_MENCODER,MSGL_ERR,"Audio format 0x%x is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it.\n", sh_audio->format);
- mencoder_exit(1,NULL);
- }
- if (sh_audio->wf){
- mux_a->wf=malloc(sizeof(WAVEFORMATEX) + sh_audio->wf->cbSize);
- memcpy(mux_a->wf, sh_audio->wf, sizeof(WAVEFORMATEX) + sh_audio->wf->cbSize);
- if(!sh_audio->i_bps) sh_audio->i_bps=mux_a->wf->nAvgBytesPerSec;
- } else {
- mux_a->wf = malloc(sizeof(WAVEFORMATEX));
- mux_a->wf->nBlockAlign = 1; //mux_a->h.dwSampleSize;
- mux_a->wf->wFormatTag = sh_audio->format;
- mux_a->wf->nChannels = sh_audio->channels;
- mux_a->wf->nSamplesPerSec = sh_audio->samplerate;
- mux_a->wf->nAvgBytesPerSec=sh_audio->i_bps; //mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
- mux_a->wf->wBitsPerSample = 16; // FIXME
- mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
- }
- if(sh_audio->audio.dwScale){
- mux_a->h.dwSampleSize=sh_audio->audio.dwSampleSize;
- mux_a->h.dwScale=sh_audio->audio.dwScale;
- mux_a->h.dwRate=sh_audio->audio.dwRate;
- } else {
- mux_a->h.dwSampleSize=mux_a->wf->nBlockAlign;
- mux_a->h.dwScale=mux_a->h.dwSampleSize;
- mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec;
- }
- mux_a->h.dwRate *= opts.playback_speed;
- mux_a->wf->nSamplesPerSec *= opts.playback_speed;
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d B/s=%d sample-%d)\n",
- mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec,
- mux_a->wf->wBitsPerSample, mux_a->wf->nAvgBytesPerSec, mux_a->h.dwSampleSize);
- break;
-}
-
-if ( mp_msg_test(MSGT_MENCODER,MSGL_DBG2) ) print_wave_header(mux_a->wf, MSGL_DBG2);
-
-if (! ignore_start)
- muxer->audio_delay_fix += sh_audio->stream_delay;
-
-} // if(sh_audio)
-
-decoded_frameno=0;
-
-signal(SIGINT,exit_sighandler); // Interrupt from keyboard
-signal(SIGQUIT,exit_sighandler); // Quit from keyboard
-signal(SIGTERM,exit_sighandler); // kill
-signal(SIGHUP,exit_sighandler); // broken terminal line
-signal(SIGPIPE,exit_sighandler); // broken pipe
-
-timer_start=GetTimerMS();
-} // if (!curfile) // if this was the first file.
-else {
- if (!mux_a != !sh_audio) {
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nCannot mix video-only files with audio and video files. Try -nosound.\n");
- mencoder_exit(1,NULL);
- }
- if (sh_audio && mux_a->codec == ACODEC_COPY) {
- if (opts.playback_speed != 1.0) mp_tmsg(MSGT_CPLAYER, MSGL_WARN, NoSpeedWithFrameCopy);
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d B/s=%d sample-%d)\n",
- mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec,
- mux_a->wf->wBitsPerSample, mux_a->wf->nAvgBytesPerSec, mux_a->h.dwSampleSize);
- if (sh_audio->wf) {
- if ((mux_a->wf->wFormatTag != sh_audio->wf->wFormatTag) ||
- (mux_a->wf->nChannels != sh_audio->wf->nChannels) ||
- (mux_a->wf->nSamplesPerSec != sh_audio->wf->nSamplesPerSec * opts.playback_speed))
- {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d B/s=%d sample-%d)\n",
- sh_audio->wf->wFormatTag, sh_audio->wf->nChannels, (int)(sh_audio->wf->nSamplesPerSec * opts.playback_speed),
- sh_audio->wf->wBitsPerSample, sh_audio->wf->nAvgBytesPerSec, 0);
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nAll files must have identical audio codec and format for -oac copy.\n");
- mencoder_exit(1,NULL);
- }
- } else {
- if ((mux_a->wf->wFormatTag != sh_audio->format) ||
- (mux_a->wf->nChannels != sh_audio->channels) ||
- (mux_a->wf->nSamplesPerSec != sh_audio->samplerate * opts.playback_speed))
- {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d B/s=%d sample-%d)\n",
- sh_audio->wf->wFormatTag, sh_audio->wf->nChannels, (int)(sh_audio->wf->nSamplesPerSec * opts.playback_speed),
- sh_audio->wf->wBitsPerSample, sh_audio->wf->nAvgBytesPerSec, 0);
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nAll files must have identical audio codec and format for -oac copy.\n");
- mencoder_exit(1,NULL);
- }
- }
- } else if (sh_audio) {
- int out_srate = mux_a->wf->nSamplesPerSec;
- int out_channels = mux_a->wf->nChannels;
- int out_format = aencoder->input_format;
- if (!init_audio_filters(sh_audio, new_srate,
- &out_srate, &out_channels,
- &out_format)) {
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Couldn't find matching filter/ao format!\n");
- mencoder_exit(1, NULL);
- }
- mux_a->wf->nSamplesPerSec = out_srate;
- mux_a->wf->nChannels = out_channels;
- }
-}
-
-if (seek_to_sec) {
- demux_seek(demuxer, seek_to_sec, audio_delay, 1);
-// there is 2 way to handle the -ss option in 3-pass mode:
-// > 1. do the first pass for the whole file, and use -ss for 2nd/3rd pases only
-// > 2. do all the 3 passes with the same -ss value
-// this line enables behaviour 1. (and kills 2. at the same time):
-// if(demuxer2) demux_seek(demuxer2, d, audio_delay, 1);
-}
-
-if (out_file_format == MUXER_TYPE_MPEG)
- {
- if (audio_preload > 0.4) {
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "Limiting audio preload to 0.4s.\n");
- audio_preload = 0.4;
- }
- if (audio_density < 4) {
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "Increasing audio density to 4.\n");
- audio_density = 4;
- }
- }
-
-if(file_format == DEMUXER_TYPE_TV)
- {
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "Forcing audio preload to 0, max pts correction to 0.\n");
- audio_preload = 0.0;
- default_max_pts_correction = 0;
- }
-
-play_n_frames=play_n_frames_mf;
-if (curfile && end_at.type == END_AT_TIME) end_at.pos += mux_v->timer;
-
-if (edl_records) free_edl(edl_records);
-next_edl_record = edl_records = NULL;
-edl_muted = 0;
-edl_seeking = 1;
-if (edl_filename) {
- next_edl_record = edl_records = edl_parse_file();
-}
-
-if (sh_audio && audio_delay != 0.) fixdelay(d_video, d_audio, mux_a, &frame_data, mux_v->codec==VCODEC_COPY);
-
-while(!at_eof){
-
- int blit_frame=0;
- float a_pts=0;
- float v_pts=0;
- int skip_flag=0; // 1=skip -1=duplicate
-
- if((end_at.type == END_AT_SIZE && end_at.pos <= stream_tell(muxer->stream)) ||
- (end_at.type == END_AT_TIME && end_at.pos < mux_v->timer))
- break;
-
- if(play_n_frames>=0){
- --play_n_frames;
- if(play_n_frames<0) break;
- }
- if(opts.chapterrange[1]>0) {
- int cur_chapter = demuxer_get_current_chapter(demuxer);
- if(cur_chapter!=-1 && cur_chapter+1>opts.chapterrange[1])
- break;
- }
-
-goto_redo_edl:
- if (next_edl_record && sh_video && sh_video->pts >= next_edl_record->start_sec) {
- if (next_edl_record->action == EDL_SKIP && edl_seeking) {
- float last_pos = d_video->pts;
- int result;
- mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_SKIP: start [%f], stop [%f], length [%f]\n",
- next_edl_record->start_sec, next_edl_record->stop_sec, next_edl_record->length_sec);
-
- result = edl_seek(next_edl_record, demuxer, d_audio, mux_a, &frame_data, mux_v->codec==VCODEC_COPY);
-
- if (result == 2) { at_eof=1; break; } // EOF
- else if (result == 0) edl_seeking = 0; // no seeking
- else { // sucess
- edl_muted = 0;
- if (last_pos >= sh_video->pts) {
- // backwards seek detected!! Forget about this EDL skip altogether.
- next_edl_record = next_edl_record->next;
- }
- else for (next_edl_record = edl_records; next_edl_record; next_edl_record = next_edl_record->next) {
- /* note the use of stop_sec,
- meaning if by some magical way we landed in the MIDDLE of a censored area,
- in the next loop it will jump out of it.
- */
- if (next_edl_record->stop_sec > sh_video->pts) break; // we got to the right place.
- if (next_edl_record->action == EDL_MUTE) edl_muted = !edl_muted; // toggle mute each time.
- }
-
- /* for a pedantic EDL, that doesn't show even a single
- frame from the "censored" area, uncomment next line. */
- goto goto_redo_edl;
- }
- } else if (next_edl_record->action == EDL_MUTE) {
- edl_muted = !edl_muted; // This variable does nothing for now.
- mp_msg(MSGT_CPLAYER, MSGL_DBG4, "EDL_MUTE: [%f]\n", next_edl_record->start_sec );
- next_edl_record=next_edl_record->next;
- }
- }
-
-
-if(sh_audio){
- // get audio:
- while(mux_a->timer-audio_preload<mux_v->timer){
- float tottime;
- int len=0;
-
- ptimer_start = GetTimerMS();
- // CBR - copy 0.5 sec of audio
- // or until the end of video:
- tottime = stop_time(demuxer, mux_v);
- if (tottime != -1) {
- tottime -= mux_a->timer;
- if (tottime > 1./audio_density) tottime = 1./audio_density;
- }
- else tottime = 1./audio_density;
-
- // let's not output more audio than necessary
- if (tottime <= 0) break;
-
- if(aencoder)
- {
- if(mux_a->h.dwSampleSize) /* CBR */
- {
- if(aencoder->set_decoded_len)
- {
- len = mux_a->h.dwSampleSize*(int)(mux_a->h.dwRate*tottime);
- aencoder->set_decoded_len(aencoder, len);
- }
- else
- len = aencoder->decode_buffer_size;
-
- len = dec_audio(sh_audio, aencoder->decode_buffer, len);
- mux_a->buffer_len += aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len,
- aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len);
- if(mux_a->buffer_len < mux_a->wf->nBlockAlign)
- len = 0;
- else
- len = mux_a->wf->nBlockAlign*(mux_a->buffer_len/mux_a->wf->nBlockAlign);
- }
- else /* VBR */
- {
- int sz = 0;
- while(1)
- {
- len = 0;
- if(! sz)
- sz = aencoder->get_frame_size(aencoder);
- if(sz > 0 && mux_a->buffer_len >= sz)
- {
- len = sz;
- break;
- }
- len = dec_audio(sh_audio,aencoder->decode_buffer, aencoder->decode_buffer_size);
- if(len <= 0)
- {
- len = 0;
- break;
- }
- len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len);
- mux_a->buffer_len += len;
- }
- }
- if (mux_v->timer == 0) mux_a->h.dwInitialFrames++;
- }
- else {
- if(mux_a->h.dwSampleSize){
- switch(mux_a->codec){
- case ACODEC_COPY: // copy
- len=mux_a->wf->nAvgBytesPerSec*tottime;
- len/=mux_a->h.dwSampleSize;if(len<1) len=1;
- len*=mux_a->h.dwSampleSize;
- len=demux_read_data(sh_audio->ds,mux_a->buffer,len);
- break;
- }
- } else {
- // VBR - encode/copy an audio frame
- switch(mux_a->codec){
- case ACODEC_COPY: // copy
- len=ds_get_packet(sh_audio->ds,(unsigned char**) &mux_a->buffer);
- break;
- }
- }
- }
- if(len<=0) break; // EOF?
- muxer_write_chunk(mux_a,len,AVIIF_KEYFRAME, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- if(!mux_a->h.dwSampleSize && mux_a->timer>0)
- mux_a->wf->nAvgBytesPerSec=0.5f+(double)mux_a->size/mux_a->timer; // avg bps (VBR)
- if(mux_a->buffer_len>=len){
- mux_a->buffer_len-=len;
- fast_memcpy(mux_a->buffer,mux_a->buffer+len,mux_a->buffer_len);
- }
-
-
- audiosamples++;
- audiorate+= (GetTimerMS() - ptimer_start);
-
- }
-}
-
- // get video frame!
-
- if (!frame_data.already_read) {
- frame_data.in_size=video_read_frame(sh_video,&frame_data.frame_time,&frame_data.start,force_fps);
- sh_video->timer+=frame_data.frame_time;
- }
- frame_data.frame_time /= opts.playback_speed;
- if(frame_data.in_size<0){ at_eof=1; break; }
- ++decoded_frameno;
-
- v_timer_corr-=frame_data.frame_time-(float)mux_v->h.dwScale/mux_v->h.dwRate;
-
-if(demuxer2){ // 3-pass encoding, read control file (frameno.avi)
- // find our frame:
- while(next_frameno<decoded_frameno){
- int* start;
- int len=ds_get_packet(demuxer2->video,(unsigned char**) &start);
- if(len<0){ at_eof=1;break;}
- if(len==0) --skip_flag; else // duplicate
- if(len==4) next_frameno=start[0];
- }
- if(at_eof) break;
- skip_flag=next_frameno-decoded_frameno;
- // find next frame:
- while(next_frameno<=decoded_frameno){
- int* start;
- int len=ds_get_packet(demuxer2->video,(unsigned char**) &start);
- if(len<0){ at_eof=1;break;}
- if(len==0) --skip_flag; else // duplicate
- if(len==4) next_frameno=start[0];
- }
-} else {
-
-// check frame duplicate/drop:
-
-float mux_frametime = (float)mux_v->h.dwScale/mux_v->h.dwRate;
-
-if (v_timer_corr >= mux_frametime && (skip_limit<0 || skip_flag < skip_limit)) {
- v_timer_corr-=mux_frametime;
- ++skip_flag; // skip
-}
-while (v_timer_corr <= -mux_frametime && (skip_limit<0 || -skip_flag < skip_limit)) {
- v_timer_corr+=mux_frametime;
- --skip_flag; // dup
-}
-
-// either v_pts_corr is big, more than 2 times framerate, then we follow its advice,
-// or, it cancels out v_timer_corr, in which case be happy and do nothing.
-
-while ((v_pts_corr <= -mux_frametime && skip_flag > 0) || (v_pts_corr <= -2*mux_frametime)) {
- v_pts_corr+=mux_frametime;
- --skip_flag; // dup
-}
-if ((v_pts_corr >= mux_frametime && skip_flag < 0) || (v_pts_corr >= 2*mux_frametime)) {
- if (skip_flag<=0) { // we can't skip more than 1 frame now
- v_pts_corr-=mux_frametime;
- ++skip_flag; // skip
- }
-}
-
-} // demuxer2
-
-ptimer_start = GetTimerMS();
-
-switch(mux_v->codec){
-case VCODEC_COPY:
- mux_v->buffer=frame_data.start;
- if(skip_flag<=0) muxer_write_chunk(mux_v,frame_data.in_size,(sh_video->ds->flags&1)?AVIIF_KEYFRAME:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- break;
-case VCODEC_FRAMENO:
- mux_v->buffer=(unsigned char *)&decoded_frameno; // tricky
- if(skip_flag<=0) muxer_write_chunk(mux_v,sizeof(int),AVIIF_KEYFRAME, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- break;
-default:
- // decode_video will callback down to ve_*.c encoders, through the video filters
- sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ, osd);
- {void *decoded_frame = decode_video(sh_video,frame_data.start,frame_data.in_size,
- skip_flag>0 && (!sh_video->vfilter || sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) != CONTROL_TRUE), MP_NOPTS_VALUE);
- blit_frame = decoded_frame && filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE);
- if (blit_frame) {
- struct vf_instance *vf = sh_video->vfilter;
- vf->control(vf, VFCTRL_DRAW_EOSD, NULL);
- vf->control(vf, VFCTRL_DRAW_OSD, osd);
- }
- }
-
- if (sh_video->vf_initialized < 0) mencoder_exit(1, NULL);
-
- if(!blit_frame){
- if (play_n_frames >= 0)
- play_n_frames++;
- badframes++;
- if(skip_flag<=0){
- // unwanted skipping of a frame, what to do?
- v_timer_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate;
-#if 0
- // Old code apparently made under the assumption that !blit_frame means
- // decoding failed due to corruption or something.. but duplication and
- // skipping of frames should be entirely disabled when skip_limit==0,
- // and must be in order for many filters to work with -noskip.
- // Eventually this entire block should probably be removed.
- if(skip_limit==0){
- // skipping not allowed -> write empty frame:
- if (!encode_duplicates || !sh_video->vfilter || sh_video->vfilter->control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE)
- muxer_write_chunk(mux_v,0,0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- } else {
- // skipping allowed -> skip it and distriubute timer error:
- v_timer_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate;
- }
-#endif
- }
- }
-}
-
-videosamples++;
-videorate+=(GetTimerMS() - ptimer_start);
-
-if(skip_flag<0){
- // duplicate frame
- if(!quiet) mp_tmsg(MSGT_MENCODER, MSGL_WARN, "\n%d duplicate frame(s)!\n",-skip_flag);
- while(skip_flag<0){
- duplicatedframes++;
- if (!encode_duplicates || !sh_video->vfilter || sh_video->vfilter->control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE)
- muxer_write_chunk(mux_v,0,0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
- ++skip_flag;
- }
-} else
-if(skip_flag>0){
- // skip frame
- if(!quiet) mp_tmsg(MSGT_MENCODER, MSGL_WARN, "\nSkipping frame!\n");
- skippedframes++;
- --skip_flag;
-}
-
-if(sh_audio && !demuxer2){
- float AV_delay,x;
- // A-V sync!
-#if 0
- if(pts_from_bps){
- unsigned int samples=(sh_audio->audio.dwSampleSize)?
- ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
- (d_audio->block_no); // <- used for VBR audio
- a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
- delay_corrected=1;
- } else
-#endif
- {
- // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
- a_pts=d_audio->pts;
- if(!delay_corrected) if(a_pts) delay_corrected=1;
- a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
- }
- v_pts=sh_video ? sh_video->pts : d_video->pts;
- // av = compensated (with out buffering delay) A-V diff
- AV_delay=(a_pts-v_pts);
- AV_delay-=audio_delay;
- AV_delay /= opts.playback_speed;
- AV_delay-=mux_a->timer-(mux_v->timer-(v_timer_corr+v_pts_corr));
- // adjust for encoder delays
- AV_delay -= (float) mux_a->encoder_delay * mux_a->h.dwScale/mux_a->h.dwRate;
- AV_delay += (float) mux_v->encoder_delay * mux_v->h.dwScale/mux_v->h.dwRate;
- // compensate input video timer by av:
- x=AV_delay*0.1f;
- if(x<-max_pts_correction) x=-max_pts_correction; else
- if(x> max_pts_correction) x= max_pts_correction;
- if(default_max_pts_correction>=0)
- max_pts_correction=default_max_pts_correction*opts.playback_speed;
- else
- max_pts_correction=sh_video->frametime*0.10 *opts.playback_speed; // +-10% of time
- // sh_video->timer-=x;
- c_total+=x;
- v_pts_corr+=x;
-}
-
- { float t=(GetTimerMS()-timer_start)*0.001f;
- float len=(demuxer->movi_end-demuxer->movi_start);
- off_t pos = demuxer->filepos >= 0 ? demuxer->filepos : stream_tell(demuxer->stream);
- float p=len>1000 ? (float)(pos-demuxer->movi_start) / len :
- (demuxer_get_percent_pos(demuxer) / 100.0);
-#if 0
- if(!len && sh_audio && sh_audio->audio.dwLength>100){
- p=(sh_audio->audio.dwSampleSize? ds_tell(sh_audio->ds)/sh_audio->audio.dwSampleSize : sh_audio->ds->block_no)
- / (float)(sh_audio->audio.dwLength);
- }
-#endif
- if(!quiet) {
- if( mp_msg_test(MSGT_STATUSLINE,MSGL_V) ) {
- mp_msg(MSGT_STATUSLINE,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d] A/Vms %d/%d D/B/S %d/%d/%d \r",
- mux_v->timer, decoded_frameno, (int)(p*100),
- (t>1) ? (int)(decoded_frameno/t+0.5) : 0,
- (p>0.001) ? (int)((t/p-t)/60) : 0,
- (p>0.001) ? (int)(stream_tell(muxer->stream)/p/1024/1024) : 0,
- v_pts_corr,
- (mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0,
- (mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0,
- audiorate/audiosamples, videorate/videosamples,
- duplicatedframes, badframes, skippedframes
- );
- } else
- mp_msg(MSGT_STATUSLINE,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %5.2ffps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d]\r",
- mux_v->timer, decoded_frameno, (int)(p*100),
- (t>1) ? (float)(decoded_frameno/t) : 0,
- (p>0.001) ? (int)((t/p-t)/60) : 0,
- (p>0.001) ? (int)(stream_tell(muxer->stream)/p/1024/1024) : 0,
- v_pts_corr,
- (mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0,
- (mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0
- );
- }
- }
- fflush(stdout);
-
-#ifdef CONFIG_DVDREAD
-// DVD sub:
- if(vobsub_writer){
- unsigned char* packet=NULL;
- int len;
- while((len=ds_get_packet_sub(d_dvdsub,&packet))>0){
- mp_msg(MSGT_MENCODER,MSGL_V,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f \n",len,sh_video->pts,d_dvdsub->pts);
- vobsub_out_output(vobsub_writer,packet,len,mux_v->timer + d_dvdsub->pts - sh_video->pts);
- }
- }
- else
-#endif
- update_subtitles(NULL, &opts, sh_video, sh_video->pts, 0, d_dvdsub, 0);
-
- frame_data = (s_frame_data){ .start = NULL, .in_size = 0, .frame_time = 0., .already_read = 0 };
-
-#if 0
- if(ferror(muxer_f)) {
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"%s: Error writing file.\n", out_filename);
- mencoder_exit(1, NULL);
- }
-#endif
-
-} // while(!at_eof)
-
-if (!interrupted && filelist[++curfile].name != 0) {
- if (sh_video && sh_video->vfilter) { // Before uniniting sh_video and the filter chain, break apart the VE.
- vf_instance_t * ve; // this will be the filter right before the ve.
- for (ve = sh_video->vfilter; ve->next && ve->next->next; ve = ve->next);
-
- if (ve->next) ve->next = NULL; // I'm telling the last filter, before the VE, there is nothing after it
- else sh_video->vfilter = NULL; // There is no chain except the VE.
- }
-
- if(sh_audio){ uninit_audio(sh_audio);sh_audio=NULL; }
- if(sh_video){ uninit_video(sh_video);sh_video=NULL; }
- if(demuxer) free_demuxer(demuxer);
- if(stream) free_stream(stream); // kill cache thread
-
- at_eof = 0;
-
- m_config_pop(mconfig);
- goto play_next_file;
-}
-
-/* Emit the remaining frames in the video system */
-/*TODO emit frmaes delayed by decoder lag*/
-if(sh_video && sh_video->vfilter){
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nFlushing video frames.\n");
- if (!sh_video->vfilter->fmt.have_configured)
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "Filters have not been configured! Empty file?\n");
- else
- sh_video->vfilter->control(sh_video->vfilter,
- VFCTRL_FLUSH_FRAMES, 0);
-}
-
-if(aencoder)
- if(aencoder->fixup)
- aencoder->fixup(aencoder);
-
-if (muxer->cont_write_index) muxer_write_index(muxer);
-muxer_f_size=stream_tell(muxer->stream);
-stream_seek(muxer->stream,0);
-if (muxer->cont_write_header) muxer_write_header(muxer); // update header
-#if 0
-if(ferror(muxer_f) || fclose(muxer_f) != 0) {
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"%s: Error writing file.\n", out_filename);
- mencoder_exit(1, NULL);
-}
-#endif
-if(vobsub_writer)
- vobsub_out_close(vobsub_writer);
-
-if(out_video_codec==VCODEC_FRAMENO && mux_v->timer>100){
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Recommended video bitrate for %s CD: %d\n","650MB",(int)((650*1024*1024-muxer_f_size)/mux_v->timer/125));
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Recommended video bitrate for %s CD: %d\n","700MB",(int)((700*1024*1024-muxer_f_size)/mux_v->timer/125));
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Recommended video bitrate for %s CD: %d\n","800MB",(int)((800*1024*1024-muxer_f_size)/mux_v->timer/125));
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Recommended video bitrate for %s CD: %d\n","2 x 650MB",(int)((2*650*1024*1024-muxer_f_size)/mux_v->timer/125));
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Recommended video bitrate for %s CD: %d\n","2 x 700MB",(int)((2*700*1024*1024-muxer_f_size)/mux_v->timer/125));
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Recommended video bitrate for %s CD: %d\n","2 x 800MB",(int)((2*800*1024*1024-muxer_f_size)/mux_v->timer/125));
-}
-
-mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nVideo stream: %8.3f kbit/s (%d B/s) size: %"PRIu64" bytes %5.3f secs %d frames\n",
- (float)(mux_v->size/mux_v->timer*8.0f/1000.0f), (int)(mux_v->size/mux_v->timer), (uint64_t)mux_v->size, (float)mux_v->timer, decoded_frameno);
-if(sh_audio)
-mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nAudio stream: %8.3f kbit/s (%d B/s) size: %"PRIu64" bytes %5.3f secs\n",
- (float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), (uint64_t)mux_a->size, (float)mux_a->timer);
-
-if(sh_audio){ uninit_audio(sh_audio);sh_audio=NULL; }
-if(sh_video){ uninit_video(sh_video);sh_video=NULL; }
-if(demuxer) free_demuxer(demuxer);
-if(stream) free_stream(stream); // kill cache thread
-
-return interrupted;
-}
diff --git a/parser-mecmd.c b/parser-mecmd.c
deleted file mode 100644
index c1820d99da..0000000000
--- a/parser-mecmd.c
+++ /dev/null
@@ -1,169 +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.
- */
-
-/// \file
-/// \ingroup ConfigParsers MEntry
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#ifdef MP_DEBUG
-#include <assert.h>
-#endif
-
-#include "mp_msg.h"
-#include "m_option.h"
-#include "m_config.h"
-#include "parser-mecmd.h"
-
-void
-m_entry_list_free(m_entry_t* lst) {
- int i,j;
-
- for(i = 0 ; lst[i].name != NULL ; i++){
- free(lst[i].name);
- for(j = 0 ; lst[i].opts[2*j] != NULL ; j++) {
- free(lst[i].opts[2*j]);
- free(lst[i].opts[2*j+1]);
- }
- free(lst[i].opts);
- }
- free(lst);
-}
-
-int
-m_entry_set_options(m_config_t *config, m_entry_t* entry) {
- int i,r;
-
- for(i = 0 ; entry->opts[2*i] != NULL ; i++){
- r = m_config_set_option(config,entry->opts[2*i],entry->opts[2*i+1]);
- if(r < 0)
- return 0;
- }
- return 1;
-}
-
-
-
-
-m_entry_t*
-m_config_parse_me_command_line(m_config_t *config, int argc, char **argv)
-{
- int i,nf = 0,no = 0;
- int tmp;
- char *opt;
- int no_more_opts = 0;
- int opt_exit = 0;
- m_entry_t *lst = NULL, *entry = NULL;
-
-#ifdef MP_DEBUG
- assert(config != NULL);
- assert(argv != NULL);
- assert(argc >= 1);
-#endif
-
- config->mode = M_COMMAND_LINE;
-
- lst = calloc(1,sizeof(m_entry_t));
-
- for (i = 1; i < argc; i++) {
- //next:
- opt = argv[i];
- /* check for -- (no more options id.) except --help! */
- if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
- {
- no_more_opts = 1;
- if (i+1 >= argc)
- {
- mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, "'--' indicates no more options, but no filename was given on the command line.\n");
- goto err_out;
- }
- continue;
- }
-
- if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
- {
- const m_option_t* mp_opt = NULL;
- /* remove trailing '-' */
- opt++;
- mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
- mp_opt = m_config_get_option(config,opt);
- if(!mp_opt) {
- tmp = M_OPT_UNKNOWN;
- mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, "-%s is not an MEncoder option\n", opt);
- goto err_out;
- }
- if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){
- tmp = m_config_set_option(config, opt, argv[i + 1]);
- if (tmp <= M_OPT_EXIT) {
- opt_exit = 1;
- tmp = M_OPT_EXIT - tmp;
- }
- else
- if(tmp < 0){
-// mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
- mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL, "Error parsing option on the command line: -%s\n", opt);
- goto err_out;
- }
- } else {
- tmp = m_config_check_option(config, opt, argv[i + 1]);
- if (tmp <= M_OPT_EXIT) {
- opt_exit = 1;
- tmp = M_OPT_EXIT - tmp;
- }
- if(tmp >= 0) {
- entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*));
- entry->opts[2*no] = strdup(opt);
- entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL;
- entry->opts[2*no+2] = entry->opts[2*no+3] = NULL;
- no++;
- } else {
-// mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
- goto err_out;
- }
- }
- i += tmp;
- } else {/* filename */
- mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]);
- lst = realloc(lst,(nf+2)*sizeof(m_entry_t));
- lst[nf].name = strdup(argv[i]);
- lst[nf].opts = calloc(2,sizeof(char*));
- entry = &lst[nf];
- no = 0;
- memset(&lst[nf+1],0,sizeof(m_entry_t));
- nf++;
- }
- }
-
- if (opt_exit)
- exit(0);
- if(nf == 0) {
- m_entry_list_free(lst);
- mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n");
- return NULL;
- }
- return lst;
-
- err_out:
- m_entry_list_free(lst);
- return NULL;
-}
diff --git a/parser-mecmd.h b/parser-mecmd.h
deleted file mode 100644
index 86d885ba98..0000000000
--- a/parser-mecmd.h
+++ /dev/null
@@ -1,55 +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_PARSER_MECMD_H
-#define MPLAYER_PARSER_MECMD_H
-
-#include "m_config.h"
-
-/// \file
-/// \ingroup ConfigParsers MEntry
-/// \brief A simple parser with per-entry settings.
-
-/// \defgroup MEntry MEncoder's playlist
-///@{
-
-/// Playlist entry
-typedef struct m_entry_st {
- /// Filename, url or whatever.
- char* name;
- /// NULL terminated list of name,val pairs.
- char** opts;
-} m_entry_t;
-
-/// Free a list returned by \ref m_config_parse_me_command_line.
-void
-m_entry_list_free(m_entry_t* lst);
-
-/// Helper to set all config options from an entry.
-int
-m_entry_set_options(m_config_t *config, m_entry_t* entry);
-
-/// Setup the \ref Config from command line arguments and build a playlist.
-/** \ingroup ConfigParsers
- */
-m_entry_t*
-m_config_parse_me_command_line(m_config_t *config, int argc, char **argv);
-
-///@}
-
-#endif /* MPLAYER_PARSER_MECMD_H */
diff --git a/xvid_vbr.c b/xvid_vbr.c
deleted file mode 100644
index 08053248fc..0000000000
--- a/xvid_vbr.c
+++ /dev/null
@@ -1,1648 +0,0 @@
-/******************************************************************************
- *
- * XviD VBR Library
- *
- * Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
- *
- * The curve treatment algorithm is based on work done by Foxer <email?> and
- * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library.
- *
- * This program 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.
- *
- * This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *****************************************************************************/
-
-/* Standard Headers */
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <math.h>
-
-/* Local headers */
-#include "xvid_vbr.h"
-
-/******************************************************************************
- * Build time constants
- *****************************************************************************/
-
-/*
- * Portability note
- * Perhaps the msvc headers define Pi with another constant name
- */
-#define DEG2RAD (M_PI / 180.0)
-
-/* Defaults settings will be computed with the help of these constants */
-#define DEFAULT_DESIRED_SIZE 700
-#define DEFAULT_AUDIO_BITRATE 128
-#define DEFAULT_MOVIE_LENGTH 2
-#define DEFAULT_TWOPASS_BOOST 1000
-#define DEFAULT_FPS 25.0f
-#define DEFAULT_CREDITS_SIZE 0
-
-#define DEFAULT_XVID_DBG_FILE "xvid.dbg"
-#define DEFAULT_XVID_STATS_FILE "xvid.stats"
-
-
-/******************************************************************************
- * Local prototypes
- *****************************************************************************/
-
-/* Sub vbrInit cases functions */
-static vbr_init_function vbr_init_dummy;
-static vbr_init_function vbr_init_2pass1;
-static vbr_init_function vbr_init_2pass2;
-static vbr_init_function vbr_init_fixedquant;
-
-/* Sub vbrGetQuant cases functions */
-static vbr_get_quant_function vbr_getquant_1pass;
-static vbr_get_quant_function vbr_getquant_2pass1;
-static vbr_get_quant_function vbr_getquant_2pass2;
-static vbr_get_quant_function vbr_getquant_fixedquant;
-
-/* Sub vbrGetIntra cases functions */
-static vbr_get_intra_function vbr_getintra_1pass;
-static vbr_get_intra_function vbr_getintra_2pass1;
-static vbr_get_intra_function vbr_getintra_2pass2;
-static vbr_get_intra_function vbr_getintra_fixedquant;
-
-/* Sub vbrUpdate prototypes */
-static vbr_update_function vbr_update_dummy;
-static vbr_update_function vbr_update_2pass1;
-static vbr_update_function vbr_update_2pass2;
-
-/* Sub vbrFinish cases functions */
-static vbr_finish_function vbr_finish_dummy;
-static vbr_finish_function vbr_finish_2pass1;
-static vbr_finish_function vbr_finish_2pass2;
-
-/* Is the encoder in the credits */
-#define FRAME_TYPE_NORMAL_MOVIE 0x00
-#define FRAME_TYPE_STARTING_CREDITS 0x01
-#define FRAME_TYPE_ENDING_CREDITS 0x02
-
-/******************************************************************************
- * Inline utility functions
- *****************************************************************************/
-
-static inline int util_frametype(vbr_control_t *state)
-{
-
- if(state->credits_start) {
-
- if(state->cur_frame >= state->credits_start_begin &&
- state->cur_frame < state->credits_start_end)
- return(FRAME_TYPE_STARTING_CREDITS);
-
- }
-
- if(state->credits_end) {
-
- if(state->cur_frame >= state->credits_end_begin &&
- state->cur_frame < state->credits_end_end)
- return(FRAME_TYPE_ENDING_CREDITS);
-
- }
-
- return(FRAME_TYPE_NORMAL_MOVIE);
-
-
-}
-
-static inline int util_creditsframes(vbr_control_t *state)
-{
-
- int frames = 0;
-
- if(state->credits_start)
- frames += state->credits_start_end - state->credits_start_begin;
- if(state->credits_end)
- frames += state->credits_end_end - state->credits_end_begin;
-
- return(frames);
-
-}
-
-/******************************************************************************
- * Functions
- *****************************************************************************/
-
-/*****************************************************************************
- * Function description :
- *
- * This function initialiazes the vbr_control_t with safe defaults for all
- * modes.
- *
- * Return Values :
- * = 0
- ****************************************************************************/
-
-int vbrSetDefaults(vbr_control_t *state)
-{
-
- /* Set all the structure to zero */
- memset(state, 0, sizeof(state));
-
- /* Default mode is CBR */
- state->mode = VBR_MODE_1PASS;
-
- /* Default statistic filename */
- state->filename = DEFAULT_XVID_STATS_FILE;
-
- /*
- * Default is a 2hour movie on 700Mo CD-ROM + 128kbit sound track
- * This represents a target bitrate of 687kbit/s
- */
- state->desired_size = DEFAULT_DESIRED_SIZE*1024*1024 -
- DEFAULT_MOVIE_LENGTH*3600*DEFAULT_AUDIO_BITRATE*1000/8;
- state->desired_bitrate = state->desired_size*8/(DEFAULT_MOVIE_LENGTH*3600);
-
- /* Credits */
- state->credits_mode = VBR_CREDITS_MODE_RATE;
- state->credits_start = 0;
- state->credits_start_begin = 0;
- state->credits_start_end = 0;
- state->credits_end = 0;
- state->credits_end_begin = 0;
- state->credits_end_end = 0;
- state->credits_quant_ratio = 20;
- state->credits_fixed_quant = 20;
- state->credits_quant_i = 20;
- state->credits_quant_p = 20;
- state->credits_start_size = DEFAULT_CREDITS_SIZE*1024*1024;
- state->credits_end_size = DEFAULT_CREDITS_SIZE*1024*1024;
-
- /* Keyframe boost */
- state->keyframe_boost = 0;
- state->kftreshold = 10;
- state->kfreduction = 30;
- state->min_key_interval = 1;
- state->max_key_interval = (int)DEFAULT_FPS*10;
-
- /* Normal curve treatment */
- state->curve_compression_high = 25;
- state->curve_compression_low = 10;
-
- /* Alt curve */
- state->use_alt_curve = 1;
- state->alt_curve_type = VBR_ALT_CURVE_LINEAR;
- state->alt_curve_low_dist = 90;
- state->alt_curve_high_dist = 500;
- state->alt_curve_min_rel_qual = 50;
- state->alt_curve_use_auto = 1;
- state->alt_curve_auto_str = 30;
- state->alt_curve_use_auto_bonus_bias = 1;
- state->alt_curve_bonus_bias = 50;
- state->bitrate_payback_method = VBR_PAYBACK_BIAS;
- state->bitrate_payback_delay = 250;
- state->twopass_max_bitrate = DEFAULT_TWOPASS_BOOST*state->desired_bitrate;
- state->twopass_max_overflow_improvement = 60;
- state->twopass_max_overflow_degradation = 60;
- state->max_iquant = 31;
- state->min_iquant = 2;
- state->max_pquant = 31;
- state->min_pquant = 2;
- state->fixed_quant = 3;
-
- state->max_framesize = (1.0/(float)DEFAULT_FPS) * state->twopass_max_bitrate / 8;
-
- state->fps = (float)DEFAULT_FPS;
-
- return(0);
-
-}
-
-/*****************************************************************************
- * Function description :
- *
- * This function initialiaze the vbr_control_t state passed in parameter.
- *
- * The initialization depends on state->mode, there are 4 modes allowed.
- * Each mode description is done in the README file shipped with the lib.
- *
- * Return values :
- *
- * = 0 on success
- * = -1 on error
- *****************************************************************************/
-
-int vbrInit(vbr_control_t *state)
-{
-
- if(state == NULL) return(-1);
-
- /* Function pointers safe initialization */
- state->init = NULL;
- state->getquant = NULL;
- state->getintra = NULL;
- state->update = NULL;
- state->finish = NULL;
-
- if(state->debug) {
-
- state->debug_file = fopen(DEFAULT_XVID_DBG_FILE, "w+");
-
- if(state->debug_file == NULL)
- return(-1);
-
- fprintf(state->debug_file, "# XviD Debug output\n");
- fprintf(state->debug_file, "# quant | intra | header bytes"
- "| total bytes | kblocks | mblocks | ublocks"
- "| vbr overflow | vbr kf overflow"
- "| vbr kf partial overflow\n\n");
- }
-
- /* Function pointers sub case initialization */
- switch(state->mode) {
- case VBR_MODE_1PASS:
- state->init = vbr_init_dummy;
- state->getquant = vbr_getquant_1pass;
- state->getintra = vbr_getintra_1pass;
- state->update = vbr_update_dummy;
- state->finish = vbr_finish_dummy;
- break;
- case VBR_MODE_2PASS_1:
- state->init = vbr_init_2pass1;
- state->getquant = vbr_getquant_2pass1;
- state->getintra = vbr_getintra_2pass1;
- state->update = vbr_update_2pass1;
- state->finish = vbr_finish_2pass1;
- break;
- case VBR_MODE_FIXED_QUANT:
- state->init = vbr_init_fixedquant;
- state->getquant = vbr_getquant_fixedquant;
- state->getintra = vbr_getintra_fixedquant;
- state->update = vbr_update_dummy;
- state->finish = vbr_finish_dummy;
- break;
- case VBR_MODE_2PASS_2:
- state->init = vbr_init_2pass2;
- state->getintra = vbr_getintra_2pass2;
- state->getquant = vbr_getquant_2pass2;
- state->update = vbr_update_2pass2;
- state->finish = vbr_finish_2pass2;
- break;
- default:
- return(-1);
- }
-
- return(state->init(state));
-
-}
-
-/******************************************************************************
- * Function description :
- *
- * This function returns an adapted quantizer according to the current vbr
- * controler state
- *
- * Return values :
- * the quantizer value (0 <= value <= 31)
- * (0 is a special case, means : let XviD decide)
- *
- *****************************************************************************/
-
-int vbrGetQuant(vbr_control_t *state)
-{
-
- /* Returns Zero, so XviD decides alone */
- if(state == NULL || state->getquant == NULL) return(0);
-
- return(state->getquant(state));
-
-}
-
-/******************************************************************************
- * Function description :
- *
- * This function returns the type of the frame to be encoded next (I or P/B)
- *
- * Return values :
- * = -1 let the XviD encoder decide wether or not the next frame is I
- * = 0 no I frame
- * = 1 force keyframe
- *
- *****************************************************************************/
-
-int vbrGetIntra(vbr_control_t *state)
-{
-
- /* Returns -1, means let XviD decide */
- if(state == NULL || state->getintra == NULL) return(-1);
-
- return(state->getintra(state));
-
-}
-
-/******************************************************************************
- * Function description :
- *
- * This function updates the vbr control state according to collected statistics
- * from XviD core
- *
- * Return values :
- *
- * = 0 on success
- * = -1 on error
- *****************************************************************************/
-
-int vbrUpdate(vbr_control_t *state,
- int quant,
- int intra,
- int header_bytes,
- int total_bytes,
- int kblocks,
- int mblocks,
- int ublocks)
-{
-
- if(state == NULL || state->update == NULL) return(-1);
-
- if(state->debug && state->debug_file != NULL) {
- int idx;
-
- fprintf(state->debug_file, "%d %d %d %d %d %d %d %d %d %d\n",
- quant, intra, header_bytes, total_bytes, kblocks,
- mblocks, ublocks, state->overflow, state->KFoverflow,
- state->KFoverflow_partial);
-
- idx = quant;
-
- if(quant < 1)
- idx = 1;
- if(quant > 31)
- idx = 31;
-
- idx--;
-
- state->debug_quant_count[idx]++;
-
- }
-
- return(state->update(state, quant, intra, header_bytes, total_bytes,
- kblocks, mblocks, ublocks));
-
-}
-
-/******************************************************************************
- * Function description :
- *
- * This function stops the vbr controller
- *
- * Return values :
- *
- * = 0 on success
- * = -1 on error
- *****************************************************************************/
-
-int vbrFinish(vbr_control_t *state)
-{
-
- if(state == NULL || state->finish == NULL) return(-1);
-
- if(state->debug && state->debug_file != NULL) {
-
- int i;
-
- fprintf(state->debug_file, "\n\n");
-
- for(i=0; i<79; i++)
- fprintf(state->debug_file, "#");
-
- fprintf(state->debug_file, "\n# Quantizer distribution :\n\n");
-
- for(i=0;i<32; i++) {
-
- fprintf(state->debug_file, "# quant %d : %d\n",
- i+1,
- state->debug_quant_count[i]);
-
- }
-
- fclose(state->debug_file);
-
- }
-
- return(state->finish(state));
-
-}
-
-/******************************************************************************
- * Dummy functions - Used when a mode does not need such a function
- *****************************************************************************/
-
-static int vbr_init_dummy(void *sstate)
-{
-
- vbr_control_t *state = sstate;
-
- state->cur_frame = 0;
-
- return(0);
-
-}
-
-static int vbr_update_dummy(void *state,
- int quant,
- int intra,
- int header_bytes,
- int total_bytes,
- int kblocks,
- int mblocks,
- int ublocks)
-{
-
- ((vbr_control_t*)state)->cur_frame++;
-
- return(0);
-
-}
-
-static int vbr_finish_dummy(void *state)
-{
-
- return(0);
-
-}
-
-/******************************************************************************
- * 1 pass mode - XviD will do its job alone.
- *****************************************************************************/
-
-static int vbr_getquant_1pass(void *state)
-{
-
- return(0);
-
-}
-
-static int vbr_getintra_1pass(void *state)
-{
-
- return(-1);
-
-}
-
-/******************************************************************************
- * 2 pass mode - first pass functions
- *****************************************************************************/
-
-static int vbr_init_2pass1(void *sstate)
-{
-
- FILE *f;
- vbr_control_t *state = sstate;
-
- /* Check the filename */
- if(state->filename == NULL || state->filename[0] == '\0')
- return(-1);
-
- /* Initialize safe defaults for 2pass 1 */
- state->pass1_file = NULL;
- state->nb_frames = 0;
- state->nb_keyframes = 0;
- state->cur_frame = 0;
-
- /* Open the 1st pass file */
- if((f = fopen(state->filename, "w+")) == NULL)
- return(-1);
-
- /*
- * The File Header
- *
- * The extra white spaces will be used during the vbrFinish to write
- * the resulting number of frames and keyframes (10 spaces == maximum
- * string length of an int on 32bit machines, i don't think anyone is
- * encoding more than 4 billion frames :-)
- */
- fprintf(f, "# ASCII XviD vbr stat file version %d\n#\n", VBR_VERSION);
- fprintf(f, "# frames : \n");
- fprintf(f, "# keyframes : \n");
- fprintf(f, "#\n# quant | intra | header bytes | total bytes | kblocks |"
- " mblocks | ublocks\n\n");
-
- /* Save file pointer */
- state->pass1_file = f;
-
- return(0);
-
-}
-
-static int vbr_getquant_2pass1(void *state)
-{
-
- return(2);
-
-}
-
-static int vbr_getintra_2pass1(void *state)
-{
-
- return(-1);
-
-}
-
-static int vbr_update_2pass1(void *sstate,
- int quant,
- int intra,
- int header_bytes,
- int total_bytes,
- int kblocks,
- int mblocks,
- int ublocks)
-
-
-{
-
- vbr_control_t *state = sstate;
-
- if(state->pass1_file == NULL)
- return(-1);
-
- /* Writes the resulting statistics */
- fprintf(state->pass1_file, "%d %d %d %d %d %d %d\n",
- quant,
- intra,
- header_bytes,
- total_bytes,
- kblocks,
- mblocks,
- ublocks);
-
- /* Update vbr control state */
- if(intra) state->nb_keyframes++;
- state->nb_frames++;
- state->cur_frame++;
-
- return(0);
-
-}
-
-static int vbr_finish_2pass1(void *sstate)
-{
-
- int c, i;
- vbr_control_t *state = sstate;
-
- if(state->pass1_file == NULL)
- return(-1);
-
- /* Goto to the file beginning */
- fseek(state->pass1_file, 0, SEEK_SET);
-
- /* Skip the version line and the empty line */
- c = i = 0;
- do {
- c = fgetc(state->pass1_file);
-
- if(c == EOF) return(-1);
- if(c == '\n') i++;
-
- }while(i < 2);
-
- /* Prepare to write to the stream */
- fseek( state->pass1_file, 0L, SEEK_CUR );
-
- /* Overwrite the frame field - safe as we have written extra spaces */
- fprintf(state->pass1_file, "# frames : %.10d\n", state->nb_frames);
-
- /* Overwrite the keyframe field */
- fprintf(state->pass1_file, "# keyframes : %.10d\n",
- state->nb_keyframes);
-
- /* Close the file */
- if(fclose(state->pass1_file) != 0)
- return(-1);
-
- return(0);
-
-}
-
-/******************************************************************************
- * 2 pass mode - 2nd pass functions (Need to be finished)
- *****************************************************************************/
-
-static int vbr_init_2pass2(void *sstate)
-{
-
- FILE *f;
- int c, n, pos_firstframe, credits_frames;
- long long credits1_bytes;
- long long credits2_bytes;
- long long desired;
- long long total_bytes;
- long long itotal_bytes;
- long long start_curved;
- long long end_curved;
- double total1;
- double total2;
-
- vbr_control_t *state = sstate;
-
- /* Check the filename */
- if(state->filename == NULL || state->filename[0] == '\0')
- return(-1);
-
- /* Initialize safe defaults for 2pass 2 */
- state->pass1_file = NULL;
- state->nb_frames = 0;
- state->nb_keyframes = 0;
-
- /* Open the 1st pass file */
- if((f = fopen(state->filename, "r")) == NULL)
- return(-1);
-
- state->pass1_file = f;
-
- /* Get the file version and check against current version */
- fscanf(state->pass1_file, "# ASCII XviD vbr stat file version %d\n", &n);
-
- if(n != VBR_VERSION) {
- fclose(state->pass1_file);
- state->pass1_file = NULL;
- return(-1);
- }
-
- /* Skip the blank commented line */
- c = n = 0;
- do {
-
- c = fgetc(state->pass1_file);
-
- if(c == EOF) {
- fclose(state->pass1_file);
- state->pass1_file = NULL;
- return(-1);
- }
-
- if(c == '\n') n++;
-
- }while(n < 1);
-
-
- /* Get the number of frames */
- fscanf(state->pass1_file, "# frames : %d\n", &state->nb_frames);
-
- /* Compute the desired size */
- state->desired_size = (long long)
- (((long long)state->nb_frames * (long long)state->desired_bitrate) /
- (state->fps * 8.0));
-
- /* Get the number of keyframes */
- fscanf(state->pass1_file, "# keyframes : %d\n", &state->nb_keyframes);
-
- /* Allocate memory space for the keyframe_location array */
- if((state->keyframe_locations
- = malloc((state->nb_keyframes+1)*sizeof(int))) == NULL) {
- fclose(state->pass1_file);
- state->pass1_file = NULL;
- return(-1);
- }
-
- /* Skip the blank commented line and the colum description */
- c = n = 0;
- do {
-
- c = fgetc(state->pass1_file);
-
- if(c == EOF) {
- fclose(state->pass1_file);
- state->pass1_file = NULL;
- return(-1);
- }
-
- if(c == '\n') n++;
-
- }while(n < 2);
-
- /* Save position for future use */
- pos_firstframe = ftell(state->pass1_file);
-
- /* Read and initialize some variables */
- credits1_bytes = credits2_bytes = 0;
- total_bytes = itotal_bytes = 0;
- start_curved = end_curved = 0;
- credits_frames = 0;
-
- for(state->cur_frame = c = 0; state->cur_frame<state->nb_frames; state->cur_frame++) {
-
- int quant, keyframe, frame_hbytes, frame_bytes;
- int kblocks, mblocks, ublocks;
-
- fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n",
- &quant, &keyframe, &frame_hbytes, &frame_bytes,
- &kblocks, &mblocks, &ublocks);
-
- /* Is the frame in the beginning credits */
- if(util_frametype(state) == FRAME_TYPE_STARTING_CREDITS) {
- credits1_bytes += frame_bytes;
- credits_frames++;
- continue;
- }
-
- /* Is the frame in the eding credits */
- if(util_frametype(state) == FRAME_TYPE_ENDING_CREDITS) {
- credits2_bytes += frame_bytes;
- credits_frames++;
- continue;
- }
-
- /* We only care about Keyframes when not in credits */
- if(keyframe) {
- itotal_bytes += frame_bytes + frame_bytes *
- state->keyframe_boost / 100;
- total_bytes += frame_bytes *
- state->keyframe_boost / 100;
- state->keyframe_locations[c++] = state->cur_frame;
- }
-
- total_bytes += frame_bytes;
-
- }
-
- /*
- * Last frame is treated like an I Frame so we can dispatch overflow
- * all other the last film segment
- */
- state->keyframe_locations[c] = state->cur_frame;
-
- desired = state->desired_size;
-
- switch(state->credits_mode) {
- case VBR_CREDITS_MODE_QUANT :
-
- state->movie_curve = (double)
- (total_bytes - credits1_bytes - credits2_bytes) /
- (desired - credits1_bytes - credits2_bytes);
-
- start_curved = credits1_bytes;
- end_curved = credits2_bytes;
-
- break;
- case VBR_CREDITS_MODE_SIZE:
-
- /* start curve = (start / start desired size) */
- state->credits_start_curve = (double)
- (credits1_bytes / state->credits_start_size);
-
- /* end curve = (end / end desired size) */
- state->credits_end_curve = (double)
- (credits2_bytes / state->credits_end_size);
-
- start_curved = (long long)
- (credits1_bytes / state->credits_start_curve);
-
- end_curved = (long long)
- (credits2_bytes / state->credits_end_curve);
-
- /* movie curve=(total-credits)/(desired_size-curved credits) */
- state->movie_curve = (double)
- (total_bytes - credits1_bytes - credits2_bytes) /
- (desired - start_curved - end_curved);
-
- break;
- case VBR_CREDITS_MODE_RATE:
- default:
-
- /* credits curve = (total/desired_size)*(100/credits_rate) */
- state->credits_start_curve = state->credits_end_curve =
- ((double)total_bytes / desired) *
- ((double)100 / state->credits_quant_ratio);
-
- start_curved =
- (long long)(credits1_bytes/state->credits_start_curve);
-
- end_curved =
- (long long)(credits2_bytes/state->credits_end_curve);
-
- state->movie_curve = (double)
- (total_bytes - credits1_bytes - credits2_bytes) /
- (desired - start_curved - end_curved);
-
- break;
- }
-
- /*
- * average frame size = (desired - curved credits - curved keyframes) /
- * (frames - credits frames - keyframes)
- */
- state->average_frame = (double)
- (desired - start_curved - end_curved -
- (itotal_bytes / state->movie_curve)) /
- (state->nb_frames - util_creditsframes(state) -
- state->nb_keyframes);
-
- /* Initialize alt curve parameters */
- if (state->use_alt_curve) {
-
- state->alt_curve_low =
- state->average_frame - state->average_frame *
- (double)(state->alt_curve_low_dist / 100.0);
-
- state->alt_curve_low_diff =
- state->average_frame - state->alt_curve_low;
-
- state->alt_curve_high =
- state->average_frame + state->average_frame *
- (double)(state->alt_curve_high_dist / 100.0);
-
- state->alt_curve_high_diff =
- state->alt_curve_high - state->average_frame;
-
- if (state->alt_curve_use_auto) {
-
- if (state->movie_curve > 1.0) {
-
- state->alt_curve_min_rel_qual =
- (int)(100.0 - (100.0 - 100.0 / state->movie_curve) *
- (double)state->alt_curve_auto_str / 100.0);
-
- if (state->alt_curve_min_rel_qual < 20)
- state->alt_curve_min_rel_qual = 20;
- }
- else {
- state->alt_curve_min_rel_qual = 100;
- }
-
- }
-
- state->alt_curve_mid_qual =
- (1.0 + (double)state->alt_curve_min_rel_qual / 100.0) / 2.0;
-
- state->alt_curve_qual_dev = 1.0 - state->alt_curve_mid_qual;
-
- if (state->alt_curve_low_dist > 100) {
-
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
- /* Sine Curve (high aggressiveness) */
- state->alt_curve_qual_dev *=
- 2.0 /
- (1.0 + sin(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff)));
-
- state->alt_curve_mid_qual =
- 1.0 - state->alt_curve_qual_dev *
- sin(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff));
- break;
-
- default:
- case VBR_ALT_CURVE_LINEAR:
- /* Linear (medium aggressiveness) */
- state->alt_curve_qual_dev *=
- 2.0 /
- (1.0 + state->average_frame / state->alt_curve_low_diff);
-
- state->alt_curve_mid_qual =
- 1.0 - state->alt_curve_qual_dev *
- state->average_frame / state->alt_curve_low_diff;
-
- break;
-
- case VBR_ALT_CURVE_SOFT:
- /* Cosine Curve (low aggressiveness) */
- state->alt_curve_qual_dev *=
- 2.0 /
- (1.0 + (1.0 - cos(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff))));
-
- state->alt_curve_mid_qual =
- 1.0 - state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff)));
-
- break;
- }
- }
- }
-
- /* Go to the first non credits frame stats line into file */
- fseek(state->pass1_file, pos_firstframe, SEEK_SET);
-
- /* Perform prepass to compensate for over/undersizing */
- total1 = total2 = 0.0;
- for(state->cur_frame=0; state->cur_frame<state->nb_frames; state->cur_frame++) {
-
- int quant, keyframe, frame_hbytes, frame_bytes;
- int kblocks, mblocks, ublocks;
-
- fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n",
- &quant, &keyframe, &frame_hbytes, &frame_bytes,
- &kblocks, &mblocks, &ublocks);
-
- if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE)
- continue;
-
- if(!keyframe) {
-
- double dbytes = frame_bytes / state->movie_curve;
- total1 += dbytes;
-
- if (state->use_alt_curve) {
-
- if (dbytes > state->average_frame) {
-
- if (dbytes >= state->alt_curve_high) {
- total2 += dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev);
- }
- else {
-
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
-
- total2 +=
- dbytes *
- (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff)));
- break;
- default:
- case VBR_ALT_CURVE_LINEAR:
-
- total2 +=
- dbytes *
- (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (dbytes - state->average_frame) / state->alt_curve_high_diff);
- break;
- case VBR_ALT_CURVE_SOFT:
- total2 +=
- dbytes *
- (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff))));
- }
- }
- }
- else {
-
- if (dbytes <= state->alt_curve_low) {
- total2 += dbytes;
- }
- else {
-
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
- total2 +=
- dbytes *
- (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff)));
- break;
- default:
- case VBR_ALT_CURVE_LINEAR:
- total2 +=
- dbytes *
- (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (dbytes - state->average_frame) / state->alt_curve_low_diff);
- break;
- case VBR_ALT_CURVE_SOFT:
- total2 +=
- dbytes *
- (state->alt_curve_mid_qual + state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff))));
- }
- }
- }
- }
- else {
- if (dbytes > state->average_frame) {
- total2 +=
- ((double)dbytes +
- (state->average_frame - dbytes) *
- state->curve_compression_high / 100.0);
- }
- else {
- total2 +=
- ((double)dbytes +
- (state->average_frame - dbytes) *
- state->curve_compression_low / 100.0);
- }
- }
- }
- }
-
- state->curve_comp_scale = total1 / total2;
-
- if (state->use_alt_curve) {
-
- double curve_temp, dbytes;
- int newquant, percent;
- int oldquant = 1;
-
- if (state->alt_curve_use_auto_bonus_bias)
- state->alt_curve_bonus_bias = state->alt_curve_min_rel_qual;
-
- state->curve_bias_bonus =
- (total1 - total2) * (double)state->alt_curve_bonus_bias /
- (100.0 * (double)(state->nb_frames - util_creditsframes(state) - state->nb_keyframes));
- state->curve_comp_scale =
- ((total1 - total2) * (1.0 - (double)state->alt_curve_bonus_bias / 100.0) + total2) /
- total2;
-
-
- for (n=1; n <= (int)(state->alt_curve_high*2) + 1; n++) {
- dbytes = n;
- if (dbytes > state->average_frame)
- {
- if (dbytes >= state->alt_curve_high) {
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev);
- }
- else {
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff)));
- break;
- default:
- case VBR_ALT_CURVE_LINEAR:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (dbytes - state->average_frame) / state->alt_curve_high_diff);
- break;
- case VBR_ALT_CURVE_SOFT:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff))));
- }
- }
- }
- else {
- if (dbytes <= state->alt_curve_low) {
- curve_temp = dbytes;
- }
- else {
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff)));
- break;
- default:
- case VBR_ALT_CURVE_LINEAR:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (dbytes - state->average_frame) / state->alt_curve_low_diff);
- break;
- case VBR_ALT_CURVE_SOFT:
- curve_temp = dbytes * (state->alt_curve_mid_qual + state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff))));
- }
- }
- }
-
- if (state->movie_curve > 1.0)
- dbytes *= state->movie_curve;
-
- newquant = (int)(dbytes * 2.0 / (curve_temp * state->curve_comp_scale + state->curve_bias_bonus));
- if (newquant > 1)
- {
- if (newquant != oldquant)
- {
- oldquant = newquant;
- percent = (int)((n - state->average_frame) * 100.0 / state->average_frame);
- }
-
- }
-
- }
-
- }
-
- state->overflow = 0;
- state->KFoverflow = 0;
- state->KFoverflow_partial = 0;
- state->KF_idx = 1;
-
- for (n=0 ; n < 32 ; n++) {
- state->quant_error[n] = 0.0;
- state->quant_count[n] = 0;
- }
-
- state->curve_comp_error = 0.0;
- state->last_quant = 0;
-
- /*
- * Above this frame size limit, normal vbr rules will not apply
- * This means :
- * 1 - Quant can de/increase more than -/+2 between 2 frames
- * 2 - Leads to artifacts because of 1
- */
- state->max_framesize = state->twopass_max_bitrate/state->fps;
-
- /* Get back to the beginning of frame statistics */
- fseek(state->pass1_file, pos_firstframe, SEEK_SET);
-
- /*
- * Small hack : We have to get next frame stats before the
- * getintra/quant calls
- * User clients update the data when they call vbrUpdate
- * we are just bypassing this because we don't have to update
- * the overflow and so on...
- */
- {
-
- /* Fake vars */
- int next_hbytes, next_kblocks, next_mblocks, next_ublocks;
-
- fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n",
- &state->pass1_quant, &state->pass1_intra, &next_hbytes,
- &state->pass1_bytes, &next_kblocks, &next_mblocks,
- &next_ublocks);
-
- }
-
- /* Initialize the frame counter */
- state->cur_frame = 0;
- state->last_keyframe = 0;
-
- return(0);
-
-}
-
-static int vbr_getquant_2pass2(void *sstate)
-{
-
- int quant;
- int intra;
- int bytes1, bytes2;
- int overflow;
- int capped_to_max_framesize = 0;
- int KFdistance, KF_min_size;
- vbr_control_t *state = sstate;
-
- bytes1 = state->pass1_bytes;
- overflow = state->overflow / 8;
- /* To shut up gcc warning */
- bytes2 = bytes1;
-
-
- if (state->pass1_intra)
- {
- overflow = 0;
- }
-
- if (util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) {
-
-
- switch (state->credits_mode) {
- case VBR_CREDITS_MODE_QUANT :
- if (state->credits_quant_i != state->credits_quant_p) {
- quant = state->pass1_intra ?
- state->credits_quant_i:
- state->credits_quant_p;
- }
- else {
- quant = state->credits_quant_p;
- }
-
- state->bytes1 = bytes1;
- state->bytes2 = bytes1;
- state->desired_bytes2 = bytes1;
- return(quant);
- default:
- case VBR_CREDITS_MODE_RATE :
- case VBR_CREDITS_MODE_SIZE :
- if(util_frametype(state) == FRAME_TYPE_STARTING_CREDITS)
- bytes2 = (int)(bytes1 / state->credits_start_curve);
- else
- bytes2 = (int)(bytes1 / state->credits_end_curve);
- break;
- }
- }
- else {
- /* Foxer: apply curve compression outside credits */
- double dbytes, curve_temp;
-
- bytes2 = bytes1;
-
- if (state->pass1_intra)
- dbytes = ((int)(bytes2 + bytes2 * state->keyframe_boost / 100)) /
- state->movie_curve;
- else
- dbytes = bytes2 / state->movie_curve;
-
- /* spread the compression error accross payback_delay frames */
- if (state->bitrate_payback_method == VBR_PAYBACK_BIAS) {
- bytes2 = (int)(state->curve_comp_error / state->bitrate_payback_delay);
- }
- else {
- bytes2 = (int)(state->curve_comp_error * dbytes /
- state->average_frame / state->bitrate_payback_delay);
-
- if (labs(bytes2) > fabs(state->curve_comp_error))
- bytes2 = (int)state->curve_comp_error;
- }
-
- state->curve_comp_error -= bytes2;
-
- if (state->use_alt_curve) {
-
- if (!state->pass1_intra) {
-
- if (dbytes > state->average_frame) {
- if (dbytes >= state->alt_curve_high)
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev);
- else {
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff)));
- break;
- default:
- case VBR_ALT_CURVE_LINEAR:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (dbytes - state->average_frame) / state->alt_curve_high_diff);
- break;
- case VBR_ALT_CURVE_SOFT:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff))));
- }
- }
- }
- else {
- if (dbytes <= state->alt_curve_low)
- curve_temp = dbytes;
- else {
- switch(state->alt_curve_type) {
- case VBR_ALT_CURVE_AGGRESIVE:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff)));
- break;
- default:
- case VBR_ALT_CURVE_LINEAR:
- curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
- (dbytes - state->average_frame) / state->alt_curve_low_diff);
- break;
- case VBR_ALT_CURVE_SOFT:
- curve_temp = dbytes * (state->alt_curve_mid_qual + state->alt_curve_qual_dev *
- (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff))));
- }
- }
- }
-
- curve_temp = curve_temp * state->curve_comp_scale + state->curve_bias_bonus;
-
- bytes2 += ((int)curve_temp);
- state->curve_comp_error += curve_temp - ((int)curve_temp);
-
- }
- else {
- state->curve_comp_error += dbytes - ((int)dbytes);
- bytes2 += ((int)dbytes);
- }
- }
- else if ((state->curve_compression_high + state->curve_compression_low) &&
- !state->pass1_intra) {
-
- if (dbytes > state->average_frame) {
- curve_temp = state->curve_comp_scale *
- ((double)dbytes + (state->average_frame - dbytes) *
- state->curve_compression_high / 100.0);
- }
- else {
- curve_temp = state->curve_comp_scale *
- ((double)dbytes + (state->average_frame - dbytes) *
- state->curve_compression_low / 100.0);
- }
-
- bytes2 += ((int)curve_temp);
- state->curve_comp_error += curve_temp - ((int)curve_temp);
- }
- else {
- state->curve_comp_error += dbytes - ((int)dbytes);
- bytes2 += ((int)dbytes);
- }
-
- /* cap bytes2 to first pass size, lowers number of quant=1 frames */
- if (bytes2 > bytes1) {
- state->curve_comp_error += bytes2 - bytes1;
- bytes2 = bytes1;
- }
- else if (bytes2 < 1) {
- state->curve_comp_error += --bytes2;
- bytes2 = 1;
- }
- }
-
- state->desired_bytes2 = bytes2;
-
- /* Ugly dependence between getquant and getintra */
- intra = state->getintra(state);
-
- if(intra) {
-
- KFdistance = state->keyframe_locations[state->KF_idx] -
- state->keyframe_locations[state->KF_idx - 1];
-
- if (KFdistance < state->kftreshold) {
- KFdistance = KFdistance - state->min_key_interval;
-
- if (KFdistance >= 0) {
-
- KF_min_size = bytes2 * (100 - state->kfreduction) / 100;
- if (KF_min_size < 1)
- KF_min_size = 1;
-
- bytes2 = KF_min_size + (bytes2 - KF_min_size) * KFdistance /
- (state->kftreshold - state->min_key_interval);
-
- if (bytes2 < 1)
- bytes2 = 1;
- }
- }
- }
-
- /*
- * Foxer: scale overflow in relation to average size, so smaller frames don't get
- * too much/little bitrate
- */
- overflow = (int)((double)overflow * bytes2 / state->average_frame);
-
- /* Foxer: reign in overflow with huge frames */
- if (labs(overflow) > labs(state->overflow)) {
- overflow = state->overflow;
- }
-
- /* Foxer: make sure overflow doesn't run away */
- if(overflow > bytes2 * state->twopass_max_overflow_improvement / 100) {
- bytes2 += (overflow <= bytes2) ? bytes2 * state->twopass_max_overflow_improvement / 100 :
- overflow * state->twopass_max_overflow_improvement / 100;
- }
- else if(overflow < bytes2 * state->twopass_max_overflow_degradation / -100) {
- bytes2 += bytes2 * state->twopass_max_overflow_degradation / -100;
- }
- else {
- bytes2 += overflow;
- }
-
- if(bytes2 > state->max_framesize) {
- capped_to_max_framesize = 1;
- bytes2 = state->max_framesize;
- }
-
- if(bytes2 < 1) {
- bytes2 = 1;
- }
-
- state->bytes1 = bytes1;
- state->bytes2 = bytes2;
-
- /* very 'simple' quant<->filesize relationship */
- quant = state->pass1_quant * bytes1 / bytes2;
-
- if(quant < 1)
- quant = 1;
- else if(quant > 31)
- quant = 31;
- else if(!state->pass1_intra) {
-
- /* Foxer: aid desired quantizer precision by accumulating decision error */
- state->quant_error[quant] += ((double)(state->pass1_quant * bytes1) / bytes2) - quant;
-
- if (state->quant_error[quant] >= 1.0) {
- state->quant_error[quant] -= 1.0;
- quant++;
- }
- }
-
- /* we're done with credits */
- if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) {
- return(quant);
- }
-
- if(intra) {
-
- if (quant < state->min_iquant)
- quant = state->min_iquant;
- if (quant > state->max_iquant)
- quant = state->max_iquant;
- }
- else {
-
- if(quant > state->max_pquant)
- quant = state->max_pquant;
- if(quant < state->min_pquant)
- quant = state->min_pquant;
-
- /* subsequent frame quants can only be +- 2 */
- if(state->last_quant && capped_to_max_framesize == 0) {
- if (quant > state->last_quant + 2)
- quant = state->last_quant + 2;
- if (quant < state->last_quant - 2)
- quant = state->last_quant - 2;
- }
- }
-
- return(quant);
-
-}
-
-static int vbr_getintra_2pass2(void *sstate)
-{
-
- int intra;
- vbr_control_t *state = sstate;
-
-
- /* Get next intra state (fetched by update) */
- intra = state->pass1_intra;
-
- /* During credits, XviD will decide itself */
- if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) {
-
-
- switch(state->credits_mode) {
- default:
- case VBR_CREDITS_MODE_RATE :
- case VBR_CREDITS_MODE_SIZE :
- intra = -1;
- break;
- case VBR_CREDITS_MODE_QUANT :
- /* Except in this case */
- if (state->credits_quant_i == state->credits_quant_p)
- intra = -1;
- break;
- }
-
- }
-
- /* Force I Frame when max_key_interval is reached */
- if((state->cur_frame - state->last_keyframe) > state->max_key_interval)
- intra = 1;
-
- /*
- * Force P or B Frames for frames whose distance is less than the
- * requested minimum
- */
- if((state->cur_frame - state->last_keyframe) < state->min_key_interval)
- intra = 0;
-
-
- /* Return the given intra mode except for first frame */
- return((state->cur_frame==0)?1:intra);
-
-}
-
-static int vbr_update_2pass2(void *sstate,
- int quant,
- int intra,
- int header_bytes,
- int total_bytes,
- int kblocks,
- int mblocks,
- int ublocks)
-
-
-{
-
-
- int next_hbytes, next_kblocks, next_mblocks, next_ublocks;
- int tempdiv;
-
- vbr_control_t *state = sstate;
-
- /*
- * We do not depend on getintra/quant because we have the real results
- * from the xvid core
- */
-
- if (util_frametype(state) == FRAME_TYPE_NORMAL_MOVIE) {
-
- state->quant_count[quant]++;
-
- if (state->pass1_intra) {
-
- state->overflow += state->KFoverflow;
- state->KFoverflow = state->desired_bytes2 - total_bytes;
-
- tempdiv = (state->keyframe_locations[state->KF_idx] -
- state->keyframe_locations[state->KF_idx - 1]);
-
- /* redistribute correctly (by koepi) */
- if (tempdiv > 1) {
- /* non-consecutive keyframes */
- state->KFoverflow_partial = state->KFoverflow /
- (tempdiv - 1);
- }
- else {
- state->overflow += state->KFoverflow;
- state->KFoverflow = 0;
- state->KFoverflow_partial = 0;
- }
- state->KF_idx++;
-
- }
- else {
- state->overflow += state->desired_bytes2 - total_bytes +
- state->KFoverflow_partial;
- state->KFoverflow -= state->KFoverflow_partial;
- }
- }
- else {
-
- state->overflow += state->desired_bytes2 - total_bytes;
- state->overflow += state->KFoverflow;
- state->KFoverflow = 0;
- state->KFoverflow_partial = 0;
- }
-
- /* Save old quant */
- state->last_quant = quant;
-
- /* Update next frame data */
- fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n",
- &state->pass1_quant, &state->pass1_intra, &next_hbytes,
- &state->pass1_bytes, &next_kblocks, &next_mblocks,
- &next_ublocks);
-
- /* Save the last Keyframe pos */
- if(intra)
- state->last_keyframe = state->cur_frame;
-
- /* Ok next frame */
- state->cur_frame++;
-
- return(0);
-
-}
-
-static int vbr_finish_2pass2(void *sstate)
-{
-
- vbr_control_t *state = sstate;
-
- if(state->pass1_file == NULL)
- return(-1);
-
- /* Close the file */
- if(fclose(state->pass1_file) != 0)
- return(-1);
-
- /* Free the memory */
- if(state->keyframe_locations)
- free(state->keyframe_locations);
-
- return(0);
-
-}
-
-
-/******************************************************************************
- * Fixed quant mode - Most of the functions will be dummy functions
- *****************************************************************************/
-
-static int vbr_init_fixedquant(void *sstate)
-{
-
- vbr_control_t *state = sstate;
-
- if(state->fixed_quant < 1)
- state->fixed_quant = 1;
-
- if(state->fixed_quant > 31)
- state->fixed_quant = 31;
-
- state->cur_frame = 0;
-
- return(0);
-
-}
-
-static int vbr_getquant_fixedquant(void *sstate)
-{
-
- vbr_control_t *state = sstate;
-
- /* Credits' frame ? */
- if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) {
-
- int quant;
-
- switch(state->credits_mode) {
- case VBR_CREDITS_MODE_RATE:
- quant = state->fixed_quant * state->credits_quant_ratio;
- break;
- case VBR_CREDITS_MODE_QUANT:
- quant = state->credits_fixed_quant;
- break;
- default:
- quant = state->fixed_quant;
-
- }
-
- return(quant);
-
- }
-
- /* No credit frame - return fixed quant */
- return(state->fixed_quant);
-
-}
-
-static int vbr_getintra_fixedquant(void *state)
-{
-
- return(-1);
-
-}
diff --git a/xvid_vbr.h b/xvid_vbr.h
deleted file mode 100644
index 2c91ebb6ee..0000000000
--- a/xvid_vbr.h
+++ /dev/null
@@ -1,231 +0,0 @@
-/******************************************************************************
- *
- * XviD VBR Library
- *
- * Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
- *
- * The curve treatment algorithm is based on work done by Foxer <email?> and
- * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library.
- *
- * This program 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.
- *
- * This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *****************************************************************************/
-
-#ifndef MPLAYER_XVID_VBR_H
-#define MPLAYER_XVID_VBR_H
-
-#define VBR_VERSION 0
-
-/******************************************************************************
- * Function types used in the vbr controler
- *****************************************************************************/
-
-typedef int (vbr_init_function)(void *state);
-typedef vbr_init_function *vbr_init_function_ptr;
-
-typedef int (vbr_get_quant_function)(void *state);
-typedef vbr_get_quant_function *vbr_get_quant_function_ptr;
-
-typedef int (vbr_get_intra_function)(void *state);
-typedef vbr_get_intra_function *vbr_get_intra_function_ptr;
-
-typedef int (vbr_update_function)(void *state,
- int quant,
- int intra,
- int header_bytes,
- int total_bytes,
- int kblocks,
- int mblocks,
- int ublocks);
-typedef vbr_update_function *vbr_update_function_ptr;
-
-typedef int (vbr_finish_function)(void *state);
-typedef vbr_finish_function *vbr_finish_function_ptr;
-
-/******************************************************************************
- * The VBR CONTROLER structure - the spin of the library
- *****************************************************************************/
-
-typedef struct vbr_control_t
-{
-
- /* All modes - specifies what VBR algorithm has to be used */
- int mode;
-
- /* All modes - specifies what fps the movie uses */
- float fps;
-
- /* All modes */
- int debug;
-
- /*
- * For VBR_MODE_2PASS_1/2 - specifies from/to what file the vbr
- * controller has to write/read stats
- */
- char *filename;
-
- /* For VBR_MODE_2PASS_2 - Target size */
- int desired_bitrate;
-
- /* For VBR_MODE_2PASS_2 - Credits parameters */
- int credits_mode;
- int credits_start;
- int credits_start_begin;
- int credits_start_end;
- int credits_end;
- int credits_end_begin;
- int credits_end_end;
- int credits_quant_ratio;
- int credits_fixed_quant;
- int credits_quant_i;
- int credits_quant_p;
- int credits_start_size;
- int credits_end_size;
-
- /* For VBR_MODE_2PASS_2 - keyframe parameters */
- int keyframe_boost;
- int kftreshold;
- int kfreduction;
- int min_key_interval;
- int max_key_interval;
-
- /* For VBR_MODE_2PASS_2 - Normal curve */
- int curve_compression_high;
- int curve_compression_low;
-
- /* For VBR_MODE_2PASS_2 - Alternate curve parameters */
- int use_alt_curve;
- int alt_curve_type;
- int alt_curve_low_dist;
- int alt_curve_high_dist;
- int alt_curve_min_rel_qual;
- int alt_curve_use_auto;
- int alt_curve_auto_str;
- int alt_curve_use_auto_bonus_bias;
- int alt_curve_bonus_bias;
- int bitrate_payback_method;
- int bitrate_payback_delay;
- int max_iquant;
- int min_iquant;
- int max_pquant;
- int min_pquant;
- int twopass_max_bitrate;
- int twopass_max_overflow_improvement;
- int twopass_max_overflow_degradation;
-
- /*
- * For VBR_MODE_FIXED_QUANT - the quantizer that has to be used for all
- * frames
- */
- int fixed_quant;
-
- /* ----------- Internal data - Do not modify ----------- */
- void *debug_file;
- void *pass1_file;
-
- long long desired_size;
-
- int cur_frame;
- int nb_frames;
- int nb_keyframes;
-
- int *keyframe_locations;
- int last_keyframe;
-
- double credits_start_curve;
- double credits_end_curve;
- double movie_curve;
- double average_frame;
- double alt_curve_low;
- double alt_curve_low_diff;
- double alt_curve_high;
- double alt_curve_high_diff;
- double alt_curve_mid_qual;
- double alt_curve_qual_dev;
- double curve_bias_bonus;
- double curve_comp_scale;
- double curve_comp_error;
-
- int pass1_quant;
- int pass1_intra;
- int pass1_bytes;
-
- int bytes1;
- int bytes2;
- int desired_bytes2;
- int max_framesize;
- int last_quant;
- int quant_count[32];
- double quant_error[32];
-
- int overflow;
- int KFoverflow;
- int KFoverflow_partial;
- int KF_idx;
-
- int debug_quant_count[32];
-
- /* ----------- Internal data - do not modify ----------- */
- vbr_init_function_ptr init;
- vbr_get_quant_function_ptr getquant;
- vbr_get_intra_function_ptr getintra;
- vbr_update_function_ptr update;
- vbr_finish_function_ptr finish;
-
-}vbr_control_t;
-
-/******************************************************************************
- * Constants
- *****************************************************************************/
-
-/* Constants for the mode member */
-#define VBR_MODE_1PASS 0x01
-#define VBR_MODE_2PASS_1 0x02
-#define VBR_MODE_2PASS_2 0x04
-#define VBR_MODE_FIXED_QUANT 0x08
-
-/* Constants for the credits mode */
-#define VBR_CREDITS_MODE_RATE 0x01
-#define VBR_CREDITS_MODE_QUANT 0x02
-#define VBR_CREDITS_MODE_SIZE 0x04
-
-/* Alternate curve treatment types */
-#define VBR_ALT_CURVE_SOFT 0x01
-#define VBR_ALT_CURVE_LINEAR 0x02
-#define VBR_ALT_CURVE_AGGRESIVE 0x04
-
-/* Payback modes */
-#define VBR_PAYBACK_BIAS 0x01
-#define VBR_PAYBACK_PROPORTIONAL 0x02
-
-/******************************************************************************
- * VBR API
- *****************************************************************************/
-
-extern int vbrSetDefaults(vbr_control_t *state);
-extern int vbrInit(vbr_control_t *state);
-extern int vbrGetQuant(vbr_control_t *state);
-extern int vbrGetIntra(vbr_control_t *state);
-extern int vbrUpdate(vbr_control_t *state,
- int quant,
- int intra,
- int header_bytes,
- int total_bytes,
- int kblocks,
- int mblocks,
- int ublocks);
-extern int vbrFinish(vbr_control_t *state);
-
-#endif /* MPLAYER_XVID_VBR_H */