summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-04-29 07:16:09 +0200
committerwm4 <wm4@mplayer2.org>2012-04-29 10:01:28 +0200
commit97ac824124fc5cdfbd9ac74156b79c098bce09c6 (patch)
tree2c924403e2fb619ec57ee0933cd12d32ef1bb62a
parent87f4cafe9c0881743d1117c2e8cd7e3376e33302 (diff)
parentf64a4e9931428de0f308f6ed0a0144edb8ce9619 (diff)
downloadmpv-97ac824124fc5cdfbd9ac74156b79c098bce09c6.tar.bz2
mpv-97ac824124fc5cdfbd9ac74156b79c098bce09c6.tar.xz
Merge remote-tracking branch 'origin/master'
Conflicts: bstr.c bstr.h libvo/cocoa_common.m libvo/gl_common.c libvo/video_out.c mplayer.c screenshot.c sub/subassconvert.c Merge of cocoa_common.m done by pigoz. Picking my version of screenshot.c. The fix in commit aadf1002f8a will be redone in a follow-up commit, as the original commit causes too many conflicts with the work done locally in this branch, and other work in progress.
-rw-r--r--Makefile7
-rw-r--r--av_log.c1
-rw-r--r--bstr.h1
-rwxr-xr-xconfigure187
-rw-r--r--input/input.c24
-rw-r--r--libmpcodecs/ad_ffmpeg.c181
-rw-r--r--libvo/cocoa_common.h6
-rw-r--r--libvo/cocoa_common.m47
-rw-r--r--libvo/gl_common.c5
-rw-r--r--libvo/gl_common.h1
-rw-r--r--libvo/video_out.c4
-rw-r--r--libvo/vo_corevideo.h87
-rw-r--r--libvo/vo_corevideo.m1317
-rw-r--r--libvo/vo_sharedbuffer.h37
-rw-r--r--libvo/vo_sharedbuffer.m277
-rw-r--r--mplayer.c34
-rw-r--r--osdep/cocoa_events.h30
-rw-r--r--osdep/cocoa_events.m137
-rw-r--r--path.c8
-rw-r--r--stream/stream_ffmpeg.c2
-rw-r--r--sub/subassconvert.c67
21 files changed, 1204 insertions, 1256 deletions
diff --git a/Makefile b/Makefile
index 34d910687f..53cbb966ae 100644
--- a/Makefile
+++ b/Makefile
@@ -100,6 +100,9 @@ SRCS_COMMON-$(LIVE555) += libmpdemux/demux_rtp.cpp \
libmpdemux/demux_rtp_codec.cpp \
stream/stream_live555.c
SRCS_COMMON-$(MACOSX_FINDER) += osdep/macosx_finder_args.m
+SRCS_COMMON-$(COCOA) += libvo/osx_common.c \
+ libvo/cocoa_common.m \
+ osdep/cocoa_events.m
SRCS_COMMON-$(MNG) += libmpdemux/demux_mng.c
SRCS_COMMON-$(MPG123) += libmpcodecs/ad_mpg123.c
@@ -439,7 +442,8 @@ SRCS_MPLAYER-$(ARTS) += libao2/ao_arts.c
SRCS_MPLAYER-$(BL) += libvo/vo_bl.c
SRCS_MPLAYER-$(CACA) += libvo/vo_caca.c
SRCS_MPLAYER-$(COREAUDIO) += libao2/ao_coreaudio.c
-SRCS_MPLAYER-$(COREVIDEO) += libvo/vo_corevideo.m libvo/osx_common.c
+SRCS_MPLAYER-$(COREVIDEO) += libvo/vo_corevideo.m
+SRCS_MPLAYER-$(SHAREDBUFFER) += libvo/vo_sharedbuffer.m
SRCS_MPLAYER-$(DGA) += libvo/vo_dga.c
SRCS_MPLAYER-$(DIRECT3D) += libvo/vo_direct3d.c libvo/w32_common.c
SRCS_MPLAYER-$(DIRECTFB) += libvo/vo_directfb2.c libvo/vo_dfbmga.c
@@ -451,7 +455,6 @@ SRCS_MPLAYER-$(GGI) += libvo/vo_ggi.c
SRCS_MPLAYER-$(GIF) += libvo/vo_gif89a.c
SRCS_MPLAYER-$(GL) += libvo/gl_common.c libvo/vo_gl.c libvo/vo_gl3.c \
pnm_loader.c
-SRCS_MPLAYER-$(GL_COCOA) += libvo/cocoa_common.m
SRCS_MPLAYER-$(GL_SDL) += libvo/sdl_common.c
SRCS_MPLAYER-$(GL_WIN32) += libvo/w32_common.c
SRCS_MPLAYER-$(GL_X11) += libvo/x11_common.c
diff --git a/av_log.c b/av_log.c
index 63f8fd7dc3..4e27e98d0f 100644
--- a/av_log.c
+++ b/av_log.c
@@ -112,6 +112,7 @@ void init_libav(void)
av_log_set_callback(mp_msg_av_log_callback);
avcodec_register_all();
av_register_all();
+ avformat_network_init();
}
#define V(x) (x)>>16, (x)>>8 & 255, (x) & 255
diff --git a/bstr.h b/bstr.h
index e8a34b4f2c..688ed41771 100644
--- a/bstr.h
+++ b/bstr.h
@@ -96,7 +96,6 @@ bool bstr_case_endswith(struct bstr s, struct bstr suffix);
struct bstr bstr_strip_ext(struct bstr str);
struct bstr bstr_get_ext(struct bstr s);
-
static inline struct bstr bstr_cut(struct bstr str, int n)
{
if (n < 0) {
diff --git a/configure b/configure
index 93f4766e39..0021665824 100755
--- a/configure
+++ b/configure
@@ -435,6 +435,7 @@ Video output:
--disable-yuv4mpeg disable yuv4mpeg video output [enable]
--disable-corevideo disable CoreVideo video output [autodetect]
--disable-cocoa disable Cocoa OpenGL backend [autodetect]
+ --disable-sharedbuffer disable OSX shared buffer video output [autodetect]
Audio output:
--disable-alsa disable ALSA audio output [autodetect]
@@ -692,6 +693,7 @@ _qtx=auto
_coreaudio=auto
_corevideo=auto
_cocoa=auto
+_sharedbuffer=auto
quicktime=auto
_macosx_finder=no
_macosx_bundle=auto
@@ -1121,6 +1123,8 @@ for ac_option do
--disable-corevideo) _corevideo=no ;;
--enable-cocoa) _cocoa=yes ;;
--disable-cocoa) _cocoa=no ;;
+ --enable-sharedbuffer) _sharedbuffer=yes ;;
+ --disable-sharedbuffer) _sharedbuffer=no ;;
--enable-macosx-finder) _macosx_finder=yes ;;
--disable-macosx-finder) _macosx_finder=no ;;
--enable-macosx-bundle) _macosx_bundle=yes ;;
@@ -2311,23 +2315,22 @@ fi # if darwin && test "$cc_vendor" = "gnu" ; then
# Checking for CFLAGS
_install_strip="-s"
if test "$_profile" != "" || test "$_debug" != "" ; then
- CFLAGS="-O2 $_march $_mcpu $_pipe $_debug $_profile"
- WARNFLAGS="-W -Wall"
_install_strip=
-elif test -z "$CFLAGS" ; then
+fi
+if test -z "$CFLAGS" ; then
if test "$cc_vendor" = "intel" ; then
- CFLAGS="-O2 $_march $_mcpu $_pipe -fomit-frame-pointer"
+ CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe -fomit-frame-pointer"
WARNFLAGS="-wd167 -wd556 -wd144"
elif test "$cc_vendor" = "sun" ; then
- CFLAGS="-O2 $_march $_mcpu $_pipe -xc99 -xregs=frameptr"
+ CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe -xc99 -xregs=frameptr"
elif test "$cc_vendor" = "clang"; then
- CFLAGS="-O2 $_march $_pipe"
+ CFLAGS="-O2 $_debug $_profile $_march $_pipe"
WARNFLAGS="-Wall -Wno-switch-enum -Wno-logical-op-parentheses -Wpointer-arith -Wundef -Wno-pointer-sign -Wmissing-prototypes"
ERRORFLAGS="-Werror=implicit-function-declaration"
elif test "$cc_vendor" != "gnu" ; then
- CFLAGS="-O2 $_march $_mcpu $_pipe"
+ CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe"
else
- CFLAGS="-O2 $_march $_mcpu $_pipe -ffast-math -fomit-frame-pointer"
+ CFLAGS="-O2 $_debug $_profile $_march $_mcpu $_pipe -ffast-math -fomit-frame-pointer"
WARNFLAGS="-Wall -Wno-switch -Wno-parentheses -Wpointer-arith -Wredundant-decls"
ERRORFLAGS="-Werror-implicit-function-declaration"
extra_ldflags="$extra_ldflags -ffast-math"
@@ -3794,6 +3797,87 @@ fi
echores "$_directfb"
+if darwin; then
+
+echocheck "QuickTime"
+if test "$quicktime" = auto ; then
+ quicktime=no
+ statement_check QuickTime/QuickTime.h 'ImageDescription *desc; EnterMovies(); ExitMovies()' -framework QuickTime && quicktime=yes
+fi
+if test "$quicktime" = yes ; then
+ extra_ldflags="$extra_ldflags -framework QuickTime"
+ def_quicktime='#define CONFIG_QUICKTIME 1'
+else
+ def_quicktime='#undef CONFIG_QUICKTIME'
+fi
+echores $quicktime
+
+echocheck "Cocoa"
+if test "$_cocoa" = auto ; then
+ cat > $TMPC <<EOF
+#include <CoreServices/CoreServices.h>
+#include <OpenGL/OpenGL.h>
+int main(void) {
+ NSApplicationLoad();
+}
+EOF
+ _cocoa=no
+ cc_check -framework Cocoa -framework OpenGL && _cocoa=yes
+fi
+if test "$_cocoa" = yes ; then
+ libs_mplayer="$libs_mplayer -framework Cocoa -framework OpenGL"
+ def_cocoa='#define CONFIG_COCOA 1'
+else
+ def_cocoa='#undef CONFIG_COCOA'
+fi
+echores "$_cocoa"
+
+echocheck "CoreVideo"
+if test "$_cocoa" = yes && test "$_corevideo" = auto ; then
+ cat > $TMPC <<EOF
+#include <QuartzCore/CoreVideo.h>
+int main(void) { return 0; }
+EOF
+ _corevideo=no
+ cc_check -framework Cocoa -framework QuartzCore -framework OpenGL && _corevideo=yes
+fi
+if test "$_corevideo" = yes ; then
+ vomodules="corevideo $vomodules"
+ libs_mplayer="$libs_mplayer -framework QuartzCore"
+ def_corevideo='#define CONFIG_COREVIDEO 1'
+else
+ novomodules="corevideo $novomodules"
+ def_corevideo='#undef CONFIG_COREVIDEO'
+fi
+echores "$_corevideo"
+
+echocheck "SharedBuffer"
+if test "$_sharedbuffer" = auto ; then
+ cat > $TMPC <<EOF
+int main(void) {
+ NSApplicationLoad();
+}
+EOF
+ _sharedbuffer=no
+ cc_check -framework Cocoa && _sharedbuffer=yes
+fi
+if test "$_sharedbuffer" = yes ; then
+ vomodules="sharedbuffer $vomodules"
+ libs_mplayer="$libs_mplayer -framework Cocoa"
+ def_sharedbuffer='#define CONFIG_SHAREDBUFFER 1'
+else
+ novomodules="sharedbuffer $novomodules"
+ def_sharedbuffer='#undef CONFIG_SHAREDBUFFER'
+fi
+echores "$_sharedbuffer"
+
+depends_on_application_services(){
+ test "$_corevideo" = yes
+}
+
+fi #if darwin
+
+
echocheck "X11 headers presence"
_x11_headers="no"
res_comment="check if the dev(el) packages are installed"
@@ -3829,7 +3913,20 @@ if test "$_x11" = auto && test "$_x11_headers" = yes ; then
_ld_tmp="$I -lXext -lX11 $_ld_pthread"
fi
statement_check X11/Xutil.h 'XCreateWindow(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)' $_ld_tmp &&
- libs_mplayer="$libs_mplayer $_ld_tmp" && _x11=yes && break
+ _x11=yes
+ # Check that there aren't conflicting headers between ApplicationServices
+ # and X11. On versions of Mac OSX prior to 10.7 the deprecated QuickDraw API
+ # is included by -framework ApplicationServices and clashes with the X11
+ # definition of the "Cursor" type.
+ if darwin && depends_on_application_services && test "$_x11" = yes ; then
+ _x11=no
+ header_check_broken ApplicationServices/ApplicationServices.h \
+ X11/Xutil.h $_ld_tmp && _x11=yes
+ fi
+ if test "$_x11" = yes ; then
+ libs_mplayer="$libs_mplayer $_ld_tmp"
+ break
+ fi
done
fi
if test "$_x11" = yes ; then
@@ -4174,66 +4271,6 @@ else
fi
-if darwin; then
-
-echocheck "QuickTime"
-if test "$quicktime" = auto ; then
- quicktime=no
- statement_check QuickTime/QuickTime.h 'ImageDescription *desc; EnterMovies(); ExitMovies()' -framework QuickTime && quicktime=yes
-fi
-if test "$quicktime" = yes ; then
- extra_ldflags="$extra_ldflags -framework QuickTime"
- def_quicktime='#define CONFIG_QUICKTIME 1'
-else
- def_quicktime='#undef CONFIG_QUICKTIME'
-fi
-echores $quicktime
-
-echocheck "CoreVideo"
-if test "$_corevideo" = auto ; then
- cat > $TMPC <<EOF
-#include <Carbon/Carbon.h>
-#include <CoreServices/CoreServices.h>
-#include <OpenGL/OpenGL.h>
-#include <QuartzCore/CoreVideo.h>
-int main(void) { return 0; }
-EOF
- _corevideo=no
- cc_check -framework Carbon -framework Cocoa -framework QuartzCore -framework OpenGL && _corevideo=yes
-fi
-if test "$_corevideo" = yes ; then
- vomodules="corevideo $vomodules"
- libs_mplayer="$libs_mplayer -framework Carbon -framework Cocoa -framework QuartzCore -framework OpenGL"
- def_corevideo='#define CONFIG_COREVIDEO 1'
-else
- novomodules="corevideo $novomodules"
- def_corevideo='#undef CONFIG_COREVIDEO'
-fi
-echores "$_corevideo"
-
-echocheck "Cocoa"
-if test "$_gl" = no ; then
- # if _gl is not enabled there is no point to add potentially unused linker flags
- _cocoa=no
-fi
-if test "$_cocoa" = auto ; then
- cat > $TMPC <<EOF
-#include <CoreServices/CoreServices.h>
-#include <OpenGL/OpenGL.h>
-#include <QuartzCore/CoreVideo.h>
-int main(void) { return 0; }
-EOF
- _cocoa=no
- cc_check -framework Cocoa -framework QuartzCore -framework OpenGL && _cocoa=yes
-fi
-if test "$_cocoa" = yes ; then
- libs_mplayer="$libs_mplayer -framework Cocoa -framework QuartzCore -framework OpenGL"
-fi
-echores "$_cocoa"
-
-fi #if darwin
-
-
echocheck "PNG support"
if test "$_png" = auto ; then
_png=no
@@ -4525,7 +4562,7 @@ int main(int argc, char *argv[]) {
EOF
_gl=no
for _ld_tmp in "" -lGL "-lGL -lXdamage" "-lGL $_ld_pthread" ; do
- if test "$_cocoa" != yes && cc_check $_ld_tmp $_ld_lm ; then
+ if cc_check $_ld_tmp $_ld_lm ; then
_gl=yes
_gl_x11=yes
libs_mplayer="$libs_mplayer $_ld_tmp $_ld_dl"
@@ -6349,8 +6386,10 @@ BL = $_bl
CACA = $_caca
CDDA = $_cdda
CDDB = $_cddb
+COCOA = $_cocoa
COREAUDIO = $_coreaudio
COREVIDEO = $_corevideo
+SHAREDBUFFER = $_sharedbuffer
DGA = $_dga
DIRECT3D = $_direct3d
DIRECTFB = $_directfb
@@ -6752,6 +6791,8 @@ $def_aa
$def_bl
$def_caca
$def_corevideo
+$def_cocoa
+$def_sharedbuffer
$def_dga
$def_dga1
$def_dga2
@@ -6829,12 +6870,8 @@ $def_yasm
#define HAVE_INLINE_ASM 1
-/* Use these registers in FFmpeg x86 inline asm. No proper detection yet. */
-#ifndef MP_DEBUG
+/* Use these registers in x86 inline asm. No proper detection yet. */
#define HAVE_EBP_AVAILABLE 1
-#else
-#define HAVE_EBP_AVAILABLE 0
-#endif
#endif /* MPLAYER_CONFIG_H */
EOF
diff --git a/input/input.c b/input/input.c
index 57b2d21f9d..ffa69043f8 100644
--- a/input/input.c
+++ b/input/input.c
@@ -59,6 +59,10 @@
#include "ar.h"
+#ifdef CONFIG_COCOA
+#include "osdep/cocoa_events.h"
+#endif
+
#define MP_MAX_KEY_DOWN 32
struct cmd_bind {
@@ -1454,7 +1458,7 @@ static void read_events(struct input_ctx *ictx, int time)
* every source until it's known to be empty. Instead we use this wrapper
* to run select() again.
*/
-static void read_all_events(struct input_ctx *ictx, int time)
+static void read_all_fd_events(struct input_ctx *ictx, int time)
{
while (1) {
read_events(ictx, time);
@@ -1464,6 +1468,15 @@ static void read_all_events(struct input_ctx *ictx, int time)
}
}
+static void read_all_events(struct input_ctx *ictx, int time)
+{
+#ifdef CONFIG_COCOA
+ cocoa_events_read_all_events(ictx, time);
+#else
+ read_all_fd_events(ictx, time);
+#endif
+}
+
int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd)
{
ictx->got_new_events = true;
@@ -1761,6 +1774,10 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf)
.wakeup_pipe = {-1, -1},
};
+#ifdef CONFIG_COCOA
+ cocoa_events_init(ictx, read_all_fd_events);
+#endif
+
#ifndef __MINGW32__
long ret = pipe(ictx->wakeup_pipe);
for (int i = 0; i < 2 && ret >= 0; i++) {
@@ -1866,11 +1883,16 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf)
mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't open %s: %s\n",
input_conf->in_file, strerror(errno));
}
+
return ictx;
}
void mp_input_uninit(struct input_ctx *ictx)
{
+#ifdef CONFIG_COCOA
+ cocoa_events_uninit();
+#endif
+
if (!ictx)
return;
diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c
index 4a5062ba00..0bfc5e5f0a 100644
--- a/libmpcodecs/ad_ffmpeg.c
+++ b/libmpcodecs/ad_ffmpeg.c
@@ -49,12 +49,15 @@ LIBAD_EXTERN(ffmpeg)
struct priv {
AVCodecContext *avctx;
- int previous_data_left;
+ AVFrame *avframe;
+ char *output;
+ int output_left;
+ int unitsize;
+ int previous_data_left; // input demuxer packet data
};
static int preinit(sh_audio_t *sh)
{
- sh->audio_out_minsize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
return 1;
}
@@ -74,6 +77,7 @@ static int setup_format(sh_audio_t *sh_audio,
case AV_SAMPLE_FMT_FLT: sample_format = AF_FORMAT_FLOAT_NE; break;
default:
mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Unsupported sample format\n");
+ sample_format = AF_FORMAT_UNKNOWN;
}
bool broken_srate = false;
@@ -122,6 +126,7 @@ static int init(sh_audio_t *sh_audio)
sh_audio->context = ctx;
lavc_context = avcodec_alloc_context3(lavc_codec);
ctx->avctx = lavc_context;
+ ctx->avframe = avcodec_alloc_frame();
// Always try to set - option only exists for AC3 at the moment
av_opt_set_double(lavc_context, "drc_scale", opts->drc_level,
@@ -223,6 +228,7 @@ static void uninit(sh_audio_t *sh)
av_freep(&lavc_context->extradata);
av_freep(&lavc_context);
}
+ av_free(ctx->avframe);
talloc_free(ctx);
sh->context = NULL;
}
@@ -235,86 +241,123 @@ static int control(sh_audio_t *sh, int cmd, void *arg, ...)
avcodec_flush_buffers(ctx->avctx);
ds_clear_parser(sh->ds);
ctx->previous_data_left = 0;
+ ctx->output_left = 0;
return CONTROL_TRUE;
}
return CONTROL_UNKNOWN;
}
+static int decode_new_packet(struct sh_audio *sh)
+{
+ struct priv *priv = sh->context;
+ AVCodecContext *avctx = priv->avctx;
+ double pts = MP_NOPTS_VALUE;
+ int insize;
+ bool packet_already_used = priv->previous_data_left;
+ struct demux_packet *mpkt = ds_get_packet2(sh->ds,
+ priv->previous_data_left);
+ unsigned char *start;
+ if (!mpkt) {
+ assert(!priv->previous_data_left);
+ start = NULL;
+ insize = 0;
+ ds_parse(sh->ds, &start, &insize, pts, 0);
+ if (insize <= 0)
+ return -1; // error or EOF
+ } else {
+ assert(mpkt->len >= priv->previous_data_left);
+ if (!priv->previous_data_left) {
+ priv->previous_data_left = mpkt->len;
+ pts = mpkt->pts;
+ }
+ insize = priv->previous_data_left;
+ start = mpkt->buffer + mpkt->len - priv->previous_data_left;
+ int consumed = ds_parse(sh->ds, &start, &insize, pts, 0);
+ priv->previous_data_left -= consumed;
+ }
+
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.data = start;
+ pkt.size = insize;
+ if (mpkt && mpkt->avpacket) {
+ pkt.side_data = mpkt->avpacket->side_data;
+ pkt.side_data_elems = mpkt->avpacket->side_data_elems;
+ }
+ if (pts != MP_NOPTS_VALUE && !packet_already_used) {
+ sh->pts = pts;
+ sh->pts_bytes = 0;
+ }
+ int got_frame = 0;
+ int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt);
+ // LATM may need many packets to find mux info
+ if (ret == AVERROR(EAGAIN))
+ return 0;
+ if (ret < 0) {
+ mp_msg(MSGT_DECAUDIO, MSGL_V, "lavc_audio: error\n");
+ return -1;
+ }
+ if (!sh->parser)
+ priv->previous_data_left += insize - ret;
+ if (!got_frame)
+ return 0;
+ /* An error is reported later from output format checking, but make
+ * sure we don't crash by overreading first plane. */
+ if (av_sample_fmt_is_planar(avctx->sample_fmt) && avctx->channels > 1)
+ return 0;
+ uint64_t unitsize = (uint64_t)av_get_bytes_per_sample(avctx->sample_fmt) *
+ avctx->channels;
+ if (unitsize > 100000)
+ abort();
+ priv->unitsize = unitsize;
+ uint64_t output_left = unitsize * priv->avframe->nb_samples;
+ if (output_left > 500000000)
+ abort();
+ priv->output_left = output_left;
+ priv->output = priv->avframe->data[0];
+ mp_dbg(MSGT_DECAUDIO, MSGL_DBG2, "Decoded %d -> %d \n", insize,
+ priv->output_left);
+ return 0;
+}
+
+
static int decode_audio(sh_audio_t *sh_audio, unsigned char *buf, int minlen,
int maxlen)
{
- struct priv *ctx = sh_audio->context;
- AVCodecContext *avctx = ctx->avctx;
+ struct priv *priv = sh_audio->context;
+ AVCodecContext *avctx = priv->avctx;
- unsigned char *start = NULL;
- int y, len = -1;
+ int len = -1;
while (len < minlen) {
- AVPacket pkt;
- int len2 = maxlen;
- double pts = MP_NOPTS_VALUE;
- int x;
- bool packet_already_used = ctx->previous_data_left;
- struct demux_packet *mpkt = ds_get_packet2(sh_audio->ds,
- ctx->previous_data_left);
- if (!mpkt) {
- assert(!ctx->previous_data_left);
- start = NULL;
- x = 0;
- ds_parse(sh_audio->ds, &start, &x, pts, 0);
- if (x <= 0)
- break; // error
- } else {
- assert(mpkt->len >= ctx->previous_data_left);
- if (!ctx->previous_data_left) {
- ctx->previous_data_left = mpkt->len;
- pts = mpkt->pts;
- }
- x = ctx->previous_data_left;
- start = mpkt->buffer + mpkt->len - ctx->previous_data_left;
- int consumed = ds_parse(sh_audio->ds, &start, &x, pts, 0);
- ctx->previous_data_left -= consumed;
- }
- av_init_packet(&pkt);
- pkt.data = start;
- pkt.size = x;
- if (mpkt && mpkt->avpacket) {
- pkt.side_data = mpkt->avpacket->side_data;
- pkt.side_data_elems = mpkt->avpacket->side_data_elems;
- }
- if (pts != MP_NOPTS_VALUE && !packet_already_used) {
- sh_audio->pts = pts;
- sh_audio->pts_bytes = 0;
- }
- y = avcodec_decode_audio3(avctx, (int16_t *)buf, &len2, &pkt);
- // LATM may need many packets to find mux info
- if (y == AVERROR(EAGAIN))
+ if (!priv->output_left) {
+ if (decode_new_packet(sh_audio) < 0)
+ break;
continue;
- if (y < 0) {
- mp_msg(MSGT_DECAUDIO, MSGL_V, "lavc_audio: error\n");
- break;
- }
- if (!sh_audio->parser)
- ctx->previous_data_left += x - y;
- if (len2 > 0) {
- if (avctx->channels >= 5) {
- int samplesize = av_get_bytes_per_sample(avctx->sample_fmt);
- reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_LAVC_DEFAULT,
- AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
- avctx->channels,
- len2 / samplesize, samplesize);
- }
- if (len < 0)
- len = len2;
- else
- len += len2;
- buf += len2;
- maxlen -= len2;
- sh_audio->pts_bytes += len2;
}
- mp_dbg(MSGT_DECAUDIO, MSGL_DBG2, "Decoded %d -> %d \n", y, len2);
-
if (setup_format(sh_audio, avctx))
- break;
+ return len;
+ int size = (minlen - len + priv->unitsize - 1);
+ size -= size % priv->unitsize;
+ size = FFMIN(size, priv->output_left);
+ if (size > maxlen)
+ abort();
+ memcpy(buf, priv->output, size);
+ priv->output += size;
+ priv->output_left -= size;
+ if (avctx->channels >= 5) {
+ int samplesize = av_get_bytes_per_sample(avctx->sample_fmt);
+ reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_LAVC_DEFAULT,
+ AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
+ avctx->channels,
+ size / samplesize, samplesize);
+ }
+ if (len < 0)
+ len = size;
+ else
+ len += size;
+ buf += size;
+ maxlen -= size;
+ sh_audio->pts_bytes += size;
}
return len;
}
diff --git a/libvo/cocoa_common.h b/libvo/cocoa_common.h
index d47ac51500..1a2ec7bd75 100644
--- a/libvo/cocoa_common.h
+++ b/libvo/cocoa_common.h
@@ -22,6 +22,9 @@
#include "video_out.h"
+bool vo_cocoa_gui_running(void);
+void *vo_cocoa_glgetaddr(const char *s);
+
int vo_cocoa_init(struct vo *vo);
void vo_cocoa_uninit(struct vo *vo);
@@ -40,4 +43,7 @@ void vo_cocoa_ontop(struct vo *vo);
// returns an int to conform to the gl extensions from other platforms
int vo_cocoa_swap_interval(int enabled);
+void *vo_cocoa_cgl_context(void);
+void *vo_cocoa_cgl_pixel_format(void);
+
#endif /* MPLAYER_COCOA_COMMON_H */
diff --git a/libvo/cocoa_common.m b/libvo/cocoa_common.m
index e8ef278b1e..66f4cd3937 100644
--- a/libvo/cocoa_common.m
+++ b/libvo/cocoa_common.m
@@ -21,6 +21,8 @@
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreServices/CoreServices.h> // for CGDisplayHideCursor and Gestalt
+#include <dlfcn.h>
+
#include "cocoa_common.h"
#include "options.h"
@@ -66,6 +68,7 @@ struct vo_cocoa_state {
NSAutoreleasePool *pool;
GLMPlayerWindow *window;
NSOpenGLContext *glContext;
+ NSOpenGLPixelFormat *pixelFormat;
NSSize current_video_size;
NSSize previous_video_size;
@@ -125,6 +128,24 @@ struct vo_cocoa_state *vo_cocoa_init_state(void)
return s;
}
+bool vo_cocoa_gui_running(void)
+{
+ return !!s;
+}
+
+void *vo_cocoa_glgetaddr(const char *s)
+{
+ void *ret = NULL;
+ void *handle = dlopen(
+ "/System/Library/Frameworks/OpenGL.framework/OpenGL",
+ RTLD_LAZY | RTLD_LOCAL);
+ if (!handle)
+ return NULL;
+ ret = dlsym(handle, s);
+ dlclose(handle);
+ return ret;
+}
+
int vo_cocoa_init(struct vo *vo)
{
s = vo_cocoa_init_state();
@@ -140,6 +161,8 @@ int vo_cocoa_init(struct vo *vo)
void vo_cocoa_uninit(struct vo *vo)
{
CGDisplayShowCursor(kCGDirectMainDisplay);
+ [NSApp setPresentationOptions:NSApplicationPresentationDefault];
+
[s->window release];
s->window = nil;
[s->glContext release];
@@ -148,6 +171,7 @@ void vo_cocoa_uninit(struct vo *vo)
s->pool = nil;
talloc_free(s);
+ s = nil;
}
void update_screen_info(void)
@@ -232,8 +256,8 @@ int vo_cocoa_create_window(struct vo *vo, uint32_t d_width,
attr[i++] = (NSOpenGLPixelFormatAttribute)16; // 16 bit depth buffer
attr[i] = (NSOpenGLPixelFormatAttribute)0;
- NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
- s->glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
+ s->pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attr] autorelease];
+ s->glContext = [[NSOpenGLContext alloc] initWithFormat:s->pixelFormat shareContext:nil];
create_menu();
@@ -365,6 +389,16 @@ int vo_cocoa_swap_interval(int enabled)
return 0;
}
+void *vo_cocoa_cgl_context(void)
+{
+ return [s->glContext CGLContextObj];
+}
+
+void *vo_cocoa_cgl_pixel_format(void)
+{
+ return [s->pixelFormat CGLPixelFormatObj];
+}
+
void create_menu()
{
NSMenu *menu;
@@ -565,18 +599,19 @@ bool is_lion_or_better(void)
- (void) applicationWillBecomeActive:(NSNotification *)aNotification
{
if (vo_fs) {
+ [s->window makeKeyAndOrderFront:s->window];
[s->window setLevel:s->fullscreen_window_level];
- [NSApp setPresentationOptions:NSApplicationPresentationHideDock|NSApplicationPresentationHideMenuBar];
- [s->window makeKeyAndOrderFront:nil];
- [NSApp activateIgnoringOtherApps: YES];
+ [NSApp setPresentationOptions:NSApplicationPresentationHideDock|
+ NSApplicationPresentationHideMenuBar];
}
}
- (void) applicationWillResignActive:(NSNotification *)aNotification
{
if (vo_fs) {
- [s->window setLevel:s->windowed_window_level];
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
+ [s->window setLevel:s->windowed_window_level];
+ [s->window orderBack:s->window];
}
}
diff --git a/libvo/gl_common.c b/libvo/gl_common.c
index 9a8de977b2..cd618b443c 100644
--- a/libvo/gl_common.c
+++ b/libvo/gl_common.c
@@ -330,6 +330,7 @@ static const extfunc_desc_t extfuncs[] = {
DEF_FUNC_DESC(Color4ub),
DEF_FUNC_DESC(Color4f),
DEF_FUNC_DESC(TexCoord2f),
+ DEF_FUNC_DESC(TexCoord2fv),
DEF_FUNC_DESC(Vertex2f),
DEF_FUNC_DESC(VertexPointer),
DEF_FUNC_DESC(ColorPointer),
@@ -1725,14 +1726,14 @@ static int create_window_cocoa_gl3(struct MPGLContext *ctx, int gl_flags,
uint32_t d_height, uint32_t flags)
{
int rv = vo_cocoa_create_window(ctx->vo, d_width, d_height, flags, 1);
- getFunctions(ctx->gl, (void *)getdladdr, NULL, true);
+ getFunctions(ctx->gl, (void *)vo_cocoa_glgetaddr, NULL, true);
return rv;
}
static int setGlWindow_cocoa(MPGLContext *ctx)
{
vo_cocoa_change_attributes(ctx->vo);
- getFunctions(ctx->gl, (void *)getdladdr, NULL, false);
+ getFunctions(ctx->gl, (void *)vo_cocoa_glgetaddr, NULL, false);
if (!ctx->gl->SwapInterval)
ctx->gl->SwapInterval = vo_cocoa_swap_interval;
return SET_WINDOW_OK;
diff --git a/libvo/gl_common.h b/libvo/gl_common.h
index 8091886b1f..f0e5912dd9 100644
--- a/libvo/gl_common.h
+++ b/libvo/gl_common.h
@@ -260,6 +260,7 @@ struct GL {
void (GLAPIENTRY *TexParameterf)(GLenum, GLenum, GLfloat);
void (GLAPIENTRY *TexParameterfv)(GLenum, GLenum, const GLfloat *);
void (GLAPIENTRY *TexCoord2f)(GLfloat, GLfloat);
+ void (GLAPIENTRY *TexCoord2fv)(const GLfloat *);
void (GLAPIENTRY *Vertex2f)(GLfloat, GLfloat);
void (GLAPIENTRY *GetIntegerv)(GLenum, GLint *);
void (GLAPIENTRY *GetBooleanv)(GLenum, GLboolean *);
diff --git a/libvo/video_out.c b/libvo/video_out.c
index 9b06794c61..aea62ce0ab 100644
--- a/libvo/video_out.c
+++ b/libvo/video_out.c
@@ -118,6 +118,7 @@ extern struct vo_driver video_out_tdfx_vid;
extern struct vo_driver video_out_xvr100;
extern struct vo_driver video_out_tga;
extern struct vo_driver video_out_corevideo;
+extern struct vo_driver video_out_sharedbuffer;
extern struct vo_driver video_out_pnm;
extern struct vo_driver video_out_md5sum;
@@ -221,6 +222,9 @@ const struct vo_driver *video_out_drivers[] =
#endif
&video_out_null,
// should not be auto-selected
+#ifdef CONFIG_SHAREDBUFFER
+ &video_out_sharedbuffer,
+#endif
#ifdef CONFIG_DIRECTFB
// vo directfb can call exit() if initialization fails
&video_out_directfb,
diff --git a/libvo/vo_corevideo.h b/libvo/vo_corevideo.h
index 926399053f..cfb86621bc 100644
--- a/libvo/vo_corevideo.h
+++ b/libvo/vo_corevideo.h
@@ -23,93 +23,6 @@
#ifndef MPLAYER_VO_COREVIDEO_H
#define MPLAYER_VO_COREVIDEO_H
-#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
-#import <Carbon/Carbon.h>
-
-// MPlayer OS X VO Protocol
-@protocol MPlayerOSXVOProto
-- (int) startWithWidth: (bycopy int)width
- withHeight: (bycopy int)height
- withBytes: (bycopy int)bytes
- withAspect: (bycopy int)aspect;
-- (void) stop;
-- (void) render;
-- (void) toggleFullscreen;
-- (void) ontop;
-@end
-
-@interface MPlayerOpenGLView : NSOpenGLView
-{
- //Cocoa
- NSWindow *window;
-
- //CoreVideo
- CVPixelBufferRef frameBuffers[2];
- CVOpenGLTextureCacheRef textureCache;
- CVOpenGLTextureRef texture;
- NSRect textureFrame;
-
- GLfloat lowerLeft[2];
- GLfloat lowerRight[2];
- GLfloat upperRight[2];
- GLfloat upperLeft[2];
-
- BOOL mouseHide;
-
- //menu command id
- NSMenuItem *kHalfScreenCmd;
- NSMenuItem *kNormalScreenCmd;
- NSMenuItem *kDoubleScreenCmd;
- NSMenuItem *kFullScreenCmd;
- NSMenuItem *kKeepAspectCmd;
- NSMenuItem *kAspectOrgCmd;
- NSMenuItem *kAspectFullCmd;
- NSMenuItem *kAspectWideCmd;
- NSMenuItem *kPanScanCmd;
-
- //timestamps for disabling screensaver and mouse hiding
- int lastMouseHide;
- int lastScreensaverUpdate;
-@public
- float winSizeMult;
-}
-
-- (BOOL) acceptsFirstResponder;
-- (BOOL) becomeFirstResponder;
-- (BOOL) resignFirstResponder;
-
-//window & rendering
-- (void) preinit;
-- (void) config;
-- (void) prepareOpenGL;
-- (void) render;
-- (void) reshape;
-- (void) setCurrentTexture;
-- (void) drawRect: (NSRect *) bounds;
-
-//vo control
-- (void) fullscreen: (BOOL) animate;
-- (void) ontop;
-- (void) panscan;
-- (void) rootwin;
-
-//menu
-- (void) initMenu;
-- (void) menuAction:(id)sender;
-
-//event
-- (void) keyDown: (NSEvent *) theEvent;
-- (void) mouseMoved: (NSEvent *) theEvent;
-- (void) mouseDown: (NSEvent *) theEvent;
-- (void) mouseUp: (NSEvent *) theEvent;
-- (void) rightMouseDown: (NSEvent *) theEvent;
-- (void) rightMouseUp: (NSEvent *) theEvent;
-- (void) otherMouseDown: (NSEvent *) theEvent;
-- (void) otherMouseUp: (NSEvent *) theEvent;
-- (void) scrollWheel: (NSEvent *) theEvent;
-- (void) mouseEvent: (NSEvent *) theEvent;
-- (void) check_events;
-@end
#endif /* MPLAYER_VO_COREVIDEO_H */
diff --git a/libvo/vo_corevideo.m b/libvo/vo_corevideo.m
index e937460636..57e93a9326 100644
--- a/libvo/vo_corevideo.m
+++ b/libvo/vo_corevideo.m
@@ -20,1057 +20,448 @@
*/
#import "vo_corevideo.h"
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <CoreServices/CoreServices.h>
-//special workaround for Apple bug #6267445
-//(OSServices Power API disabled in OSServices.h for 64bit systems)
-#ifndef __POWER__
-#include <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h>
-#endif
-
-//MPLAYER
-#include "config.h"
-#include "fastmemcpy.h"
-#include "video_out.h"
-#include "video_out_internal.h"
-#include "aspect.h"
-#include "mp_msg.h"
-#include "m_option.h"
-#include "mp_fifo.h"
-#include "sub/sub.h"
-#include "subopt-helper.h"
-
-#include "input/input.h"
-#include "input/keycodes.h"
-#include "osx_common.h"
-
-//Cocoa
-NSDistantObject *mplayerosxProxy;
-id <MPlayerOSXVOProto> mplayerosxProto;
-MPlayerOpenGLView *mpGLView;
-NSAutoreleasePool *autoreleasepool;
-OSType pixelFormat;
-
-//shared memory
-BOOL shared_buffer = false;
-#define DEFAULT_BUFFER_NAME "mplayerosx"
-static char *buffer_name;
-
-//Screen
-int screen_id = -1;
-NSRect screen_frame;
-NSScreen *screen_handle;
-NSArray *screen_array;
-
-//image
-unsigned char *image_data;
-// For double buffering
-static uint8_t image_page = 0;
-static unsigned char *image_datas[2];
-
-static uint32_t image_width;
-static uint32_t image_height;
-static uint32_t image_depth;
-static uint32_t image_bytes;
-static uint32_t image_format;
-
-//vo
-static int isFullscreen;
-static int isOntop;
-static int isRootwin;
-
-static float winAlpha = 1;
-static int int_pause = 0;
-
-static BOOL isLeopardOrLater;
-
-#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask)
-#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask)
-
-static vo_info_t info =
-{
- "Mac OS X Core Video",
- "corevideo",
- "Nicolas Plourde <nicolas.plourde@gmail.com>",
- ""
+
+// mplayer includes
+#import "fastmemcpy.h"
+#import "talloc.h"
+#import "video_out.h"
+#import "aspect.h"
+#import "sub/font_load.h"
+#import "sub/sub.h"
+#import "subopt-helper.h"
+
+#import "csputils.h"
+#import "libmpcodecs/vfcap.h"
+#import "libmpcodecs/mp_image.h"
+#import "osd.h"
+
+#import "gl_common.h"
+#import "cocoa_common.h"
+
+struct quad {
+ GLfloat lowerLeft[2];
+ GLfloat lowerRight[2];
+ GLfloat upperRight[2];
+ GLfloat upperLeft[2];
};
-LIBVO_EXTERN(corevideo)
+#define CV_VERTICES_PER_QUAD 6
+#define CV_MAX_OSD_PARTS 20
-static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
-{
- switch (image_format)
- {
- case IMGFMT_RGB24:
- vo_draw_alpha_rgb24(w,h,src,srca,stride,image_data+3*(y0*image_width+x0),3*image_width);
- break;
- case IMGFMT_ARGB:
- case IMGFMT_BGRA:
- vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width);
- break;
- case IMGFMT_YUY2:
- vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2);
- break;
- }
-}
+struct osd_p {
+ GLuint tex[CV_MAX_OSD_PARTS];
+ NSRect tex_rect[CV_MAX_OSD_PARTS];
+ int tex_cnt;
+};
-static void update_screen_info(void)
-{
- if (screen_id == -1 && xinerama_screen > -1)
- screen_id = xinerama_screen;
-
- screen_array = [NSScreen screens];
- if(screen_id >= (int)[screen_array count])
- {
- mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] Device ID %d does not exist, falling back to main device\n", screen_id);
- screen_id = -1;
- }
- if (screen_id < 0 && [mpGLView window])
- screen_handle = [[mpGLView window] screen];
- else
- screen_handle = [screen_array objectAtIndex:(screen_id < 0 ? 0 : screen_id)];
-
- screen_frame = [screen_handle frame];
- vo_screenwidth = screen_frame.size.width;
- vo_screenheight = screen_frame.size.height;
- xinerama_x = xinerama_y = 0;
- aspect_save_screenres(vo_screenwidth, vo_screenheight);
-}
+struct priv {
+ MPGLContext *mpglctx;
+ OSType pixelFormat;
+ unsigned int image_width;
+ unsigned int image_height;
+ struct mp_csp_details colorspace;
-static void free_file_specific(void)
-{
- if(shared_buffer)
- {
- [mplayerosxProto stop];
- mplayerosxProto = nil;
- [mplayerosxProxy release];
- mplayerosxProxy = nil;
-
- if (munmap(image_data, image_width*image_height*image_bytes) == -1)
- mp_msg(MSGT_VO, MSGL_FATAL, "[vo_corevideo] uninit: munmap failed. Error: %s\n", strerror(errno));
-
- if (shm_unlink(buffer_name) == -1)
- mp_msg(MSGT_VO, MSGL_FATAL, "[vo_corevideo] uninit: shm_unlink failed. Error: %s\n", strerror(errno));
- } else {
- free(image_datas[0]);
- if (vo_doublebuffering)
- free(image_datas[1]);
- image_datas[0] = NULL;
- image_datas[1] = NULL;
- image_data = NULL;
- }
-}
+ CVPixelBufferRef pixelBuffer;
+ CVOpenGLTextureCacheRef textureCache;
+ CVOpenGLTextureRef texture;
+ struct quad *quad;
-static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
-{
- free_file_specific();
-
- //misc mplayer setup
- image_width = width;
- image_height = height;
- switch (image_format)
- {
- case IMGFMT_RGB24:
- image_depth = 24;
- break;
- case IMGFMT_ARGB:
- case IMGFMT_BGRA:
- image_depth = 32;
- break;
- case IMGFMT_YUY2:
- image_depth = 16;
- break;
- }
- image_bytes = (image_depth + 7) / 8;
-
- if(!shared_buffer)
- {
- config_movie_aspect((float)d_width/d_height);
-
- vo_dwidth = d_width *= mpGLView->winSizeMult;
- vo_dheight = d_height *= mpGLView->winSizeMult;
-
- image_data = malloc(image_width*image_height*image_bytes);
- image_datas[0] = image_data;
- if (vo_doublebuffering)
- image_datas[1] = malloc(image_width*image_height*image_bytes);
- image_page = 0;
-
- vo_fs = flags & VOFLAG_FULLSCREEN;
-
- //config OpenGL View
- [mpGLView config];
- [mpGLView reshape];
- }
- else
- {
- int shm_fd;
- mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer "
- "named \"%s\"\n",buffer_name);
-
- // create shared memory
- shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
- if (shm_fd == -1)
- {
- mp_msg(MSGT_VO, MSGL_FATAL,
- "[vo_corevideo] failed to open shared memory. Error: %s\n", strerror(errno));
- return 1;
- }
-
-
- if (ftruncate(shm_fd, image_width*image_height*image_bytes) == -1)
- {
- mp_msg(MSGT_VO, MSGL_FATAL,
- "[vo_corevideo] failed to size shared memory, possibly already in use. Error: %s\n", strerror(errno));
- close(shm_fd);
- shm_unlink(buffer_name);
- return 1;
- }
-
- image_data = mmap(NULL, image_width*image_height*image_bytes,
- PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
- close(shm_fd);
-
- if (image_data == MAP_FAILED)
- {
- mp_msg(MSGT_VO, MSGL_FATAL,
- "[vo_corevideo] failed to map shared memory. Error: %s\n", strerror(errno));
- shm_unlink(buffer_name);
- return 1;
- }
-
- //connect to mplayerosx
- mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil];
- if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) {
- [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)];
- mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy;
- [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:d_width*100/d_height];
- }
- else {
- [mplayerosxProxy release];
- mplayerosxProxy = nil;
- mplayerosxProto = nil;
- }
- }
- return 0;
-}
+ struct osd_p *osd;
+};
-static void check_events(void)
-{
- if (mpGLView)
- [mpGLView check_events];
-}
+static struct priv *p;
-static void draw_osd(void)
+static void resize(struct vo *vo, int width, int height)
{
- vo_draw_text(image_width, image_height, draw_alpha);
-}
+ GL *gl = p->mpglctx->gl;
+ p->image_width = width;
+ p->image_height = height;
-static void flip_page(void)
-{
- if(shared_buffer) {
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- [mplayerosxProto render];
- [pool release];
- } else {
- [mpGLView setCurrentTexture];
- [mpGLView render];
- if (vo_doublebuffering) {
- image_page = 1 - image_page;
- image_data = image_datas[image_page];
- }
- }
-}
+ mp_msg(MSGT_VO, MSGL_V, "[vo_corevideo] New OpenGL Viewport (0, 0, %d, "
+ "%d)\n", p->image_width, p->image_height);
-static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
-{
- return 0;
-}
+ gl->Viewport(0, 0, p->image_width, p->image_height);
+ gl->MatrixMode(GL_PROJECTION);
+ gl->LoadIdentity();
+ if (aspect_scaling()) {
+ int new_w, new_h;
+ GLdouble scale_x, scale_y;
-static int draw_frame(uint8_t *src[])
-{
- return 0;
-}
+ aspect(vo, &new_w, &new_h, A_WINZOOM);
+ panscan_calc_windowed(vo);
+ new_w += vo->panscan_x;
+ new_h += vo->panscan_y;
+ scale_x = (GLdouble)new_w / (GLdouble)p->image_width;
+ scale_y = (GLdouble)new_h / (GLdouble)p->image_height;
+ gl->Scaled(scale_x, scale_y, 1);
+ }
-static uint32_t draw_image(mp_image_t *mpi)
-{
- memcpy_pic(image_data, mpi->planes[0], image_width*image_bytes, image_height, image_width*image_bytes, mpi->stride[0]);
+ gl->Ortho(0, p->image_width, p->image_height, 0, -1.0, 1.0);
+ gl->MatrixMode(GL_MODELVIEW);
+ gl->LoadIdentity();
- return 0;
-}
+ force_load_font = 1;
+ vo_osd_changed(OSDTYPE_OSD);
-static int query_format(uint32_t format)
-{
- const int supportflags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN;
- image_format = format;
-
- switch(format)
- {
- case IMGFMT_YUY2:
- pixelFormat = kYUVSPixelFormat;
- return supportflags;
-
- case IMGFMT_RGB24:
- pixelFormat = k24RGBPixelFormat;
- return supportflags;
-
- case IMGFMT_ARGB:
- pixelFormat = k32ARGBPixelFormat;
- return supportflags;
-
- case IMGFMT_BGRA:
- pixelFormat = k32BGRAPixelFormat;
- return supportflags;
- }
- return 0;
+ gl->Clear(GL_COLOR_BUFFER_BIT);
+ vo->want_redraw = true;
}
-static void uninit(void)
+static int init_gl(struct vo *vo, uint32_t d_width, uint32_t d_height)
{
- SetSystemUIMode( kUIModeNormal, 0);
- CGDisplayShowCursor(kCGDirectMainDisplay);
+ GL *gl = p->mpglctx->gl;
- free_file_specific();
+ const char *vendor = gl->GetString(GL_VENDOR);
+ const char *version = gl->GetString(GL_VERSION);
+ const char *renderer = gl->GetString(GL_RENDERER);
- if(mpGLView)
- {
- NSAutoreleasePool *finalPool;
- mpGLView = nil;
- [autoreleasepool release];
- finalPool = [[NSAutoreleasePool alloc] init];
- [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
- [finalPool release];
- }
+ mp_msg(MSGT_VO, MSGL_V, "[vo_corevideo] Running on OpenGL '%s' by '%s',"
+ " version '%s'\n", renderer, vendor, version);
- free(buffer_name);
- buffer_name = NULL;
-}
+ gl->Disable(GL_BLEND);
+ gl->Disable(GL_DEPTH_TEST);
+ gl->DepthMask(GL_FALSE);
+ gl->Disable(GL_CULL_FACE);
+ gl->Enable(GL_TEXTURE_2D);
+ gl->DrawBuffer(GL_BACK);
+ gl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-static const opt_t subopts[] = {
-{"device_id", OPT_ARG_INT, &screen_id, NULL},
-{"shared_buffer", OPT_ARG_BOOL, &shared_buffer, NULL},
-{"buffer_name", OPT_ARG_MSTRZ,&buffer_name, NULL},
-{NULL}
-};
+ resize(vo, d_width, d_height);
-static int preinit(const char *arg)
-{
+ gl->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ gl->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ if (gl->SwapInterval)
+ gl->SwapInterval(1);
+ return 1;
+}
- // set defaults
- screen_id = -1;
- shared_buffer = false;
- buffer_name = NULL;
-
- if (subopt_parse(arg, subopts) != 0) {
- mp_msg(MSGT_VO, MSGL_FATAL,
- "\n-vo corevideo command line help:\n"
- "Example: mplayer -vo corevideo:device_id=1:shared_buffer:buffer_name=mybuff\n"
- "\nOptions:\n"
- " device_id=<0-...>\n"
- " Set screen device ID for fullscreen.\n"
- " shared_buffer\n"
- " Write output to a shared memory buffer instead of displaying it.\n"
- " buffer_name=<name>\n"
- " Name of the shared buffer created with shm_open() as well as\n"
- " the name of the NSConnection MPlayer will try to open.\n"
- " Setting buffer_name implicitly enables shared_buffer.\n"
- "\n" );
- return -1;
- }
-
- autoreleasepool = [[NSAutoreleasePool alloc] init];
-
- if (!buffer_name)
- buffer_name = strdup(DEFAULT_BUFFER_NAME);
- else
- shared_buffer = true;
-
- if(!shared_buffer)
- {
- NSApplicationLoad();
- NSApp = [NSApplication sharedApplication];
- isLeopardOrLater = floor(NSAppKitVersionNumber) > 824;
-
- osx_foreground_hack();
-
- if(!mpGLView)
- {
- mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]];
- [mpGLView autorelease];
- }
- // Install an event handler so the Quit menu entry works
- // The proper way using NSApp setDelegate: and
- // applicationShouldTerminate: does not work,
- // probably NSApplication never installs its handler.
- [[NSAppleEventManager sharedAppleEventManager]
- setEventHandler:mpGLView
- andSelector:@selector(handleQuitEvent:withReplyEvent:)
- forEventClass:kCoreEventClass
- andEventID:kAEQuitApplication];
-
- [mpGLView display];
- [mpGLView preinit];
- }
+static void release_cv_entities(void) {
+ CVPixelBufferRelease(p->pixelBuffer);
+ p->pixelBuffer = NULL;
+ CVOpenGLTextureRelease(p->texture);
+ p->texture = NULL;
+ CVOpenGLTextureCacheRelease(p->textureCache);
+ p->textureCache = NULL;
- return 0;
}
-static int control(uint32_t request, void *data)
+static int config(struct vo *vo, uint32_t width, uint32_t height,
+ uint32_t d_width, uint32_t d_height, uint32_t flags,
+ uint32_t format)
{
- switch (request)
- {
- case VOCTRL_DRAW_IMAGE: return draw_image(data);
- case VOCTRL_PAUSE: return int_pause = 1;
- case VOCTRL_RESUME: return int_pause = 0;
- case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t*)data);
- case VOCTRL_ONTOP: vo_ontop = !vo_ontop; if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE;
- case VOCTRL_ROOTWIN: vo_rootwin = !vo_rootwin; [mpGLView rootwin]; return VO_TRUE;
- case VOCTRL_FULLSCREEN: vo_fs = !vo_fs; if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE;
- case VOCTRL_GET_PANSCAN: return VO_TRUE;
- case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE;
- case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE;
- }
- return VO_NOTIMPL;
-}
+ release_cv_entities();
+ p->image_width = width;
+ p->image_height = height;
-//////////////////////////////////////////////////////////////////////////
-// NSOpenGLView Subclass
-//////////////////////////////////////////////////////////////////////////
-@implementation MPlayerOpenGLView
-- (void) preinit
-{
- NSOpenGLContext *glContext;
- GLint swapInterval = 1;
- CVReturn error;
-
- //init menu
- [self initMenu];
-
- //create window
- window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
- styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
- backing:NSBackingStoreBuffered defer:NO];
-
- [window autorelease];
- [window setDelegate:mpGLView];
- [window setContentView:mpGLView];
- [window setInitialFirstResponder:mpGLView];
- [window setAcceptsMouseMovedEvents:YES];
- [window setTitle:@"MPlayer - The Movie Player"];
-
- isFullscreen = 0;
- winSizeMult = 1;
-
- //create OpenGL Context
- glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
-
- [self setOpenGLContext:glContext];
- [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
- [glContext setView:self];
- [glContext makeCurrentContext];
- [glContext release];
-
- error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
- if(error != kCVReturnSuccess)
- mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
-}
+ if (p->mpglctx->create_window(p->mpglctx, d_width, d_height, flags) < 0)
+ return -1;
+ if (p->mpglctx->setGlWindow(p->mpglctx) == SET_WINDOW_FAILED)
+ return -1;
-- (void) releaseVideoSpecific
-{
- CVPixelBufferRelease(frameBuffers[0]);
- frameBuffers[0] = NULL;
- CVPixelBufferRelease(frameBuffers[1]);
- frameBuffers[1] = NULL;
- CVOpenGLTextureRelease(texture);
- texture = NULL;
-}
+ init_gl(vo, vo->dwidth, vo->dheight);
-- (void) dealloc
-{
- [self releaseVideoSpecific];
- CVOpenGLTextureCacheRelease(textureCache);
- textureCache = NULL;
- [self setOpenGLContext:nil];
- [super dealloc];
+ return 0;
}
-- (void) config
+static void check_events(struct vo *vo)
{
- NSRect visibleFrame;
- CVReturn error = kCVReturnSuccess;
-
- //config window
- [window setContentSize:NSMakeSize(vo_dwidth, vo_dheight)];
-
- // Use visibleFrame to position the window taking the menu bar and dock into account.
- // Also flip vo_dy since the screen origin is in the bottom left on OSX.
- update_screen_info();
- visibleFrame = [screen_handle visibleFrame];
- [window setFrameTopLeftPoint:NSMakePoint(
- visibleFrame.origin.x + vo_dx,
- visibleFrame.origin.y + visibleFrame.size.height - vo_dy)];
-
- [self releaseVideoSpecific];
- error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]);
- if(error != kCVReturnSuccess)
- mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error);
- if (vo_doublebuffering) {
- error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]);
- if(error != kCVReturnSuccess)
- mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error);
- }
-
- error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
- if(error != kCVReturnSuccess)
- mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);
-
- //show window
- [window makeKeyAndOrderFront:mpGLView];
-
- if(vo_rootwin)
- [mpGLView rootwin];
-
- if(vo_fs)
- [mpGLView fullscreen: NO];
-
- if(vo_ontop)
- [mpGLView ontop];
+ int e = p->mpglctx->check_events(vo);
+ if (e & VO_EVENT_RESIZE)
+ resize(vo, vo->dwidth, vo->dheight);
}
-/*
- Init Menu
-*/
-- (void)initMenu
+static void create_osd_texture(void *ctx, int x0, int y0, int w, int h,
+ unsigned char *src, unsigned char *srca,
+ int stride)
{
- NSMenu *menu, *aspectMenu;
- NSMenuItem *menuItem;
-
- menu = [[NSMenu new] autorelease];
- menuItem = [[NSMenuItem new] autorelease];
- [menu addItem: menuItem];
- [NSApp setMainMenu: menu];
-
-//Create Movie Menu
- menu = [[NSMenu alloc] initWithTitle:@"Movie"];
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem];
- kHalfScreenCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem];
- kNormalScreenCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem];
- kDoubleScreenCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem];
- kFullScreenCmd = menuItem;
- menuItem = [NSMenuItem separatorItem]; [menu addItem:menuItem];
-
- aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"];
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
- if(vo_keepaspect) [menuItem setState:NSOnState];
- kKeepAspectCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
- if(vo_panscan) [menuItem setState:NSOnState];
- kPanScanCmd = menuItem;
- menuItem = [NSMenuItem separatorItem]; [aspectMenu addItem:menuItem];
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
- kAspectOrgCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
- kAspectFullCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem];
- kAspectWideCmd = menuItem;
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:aspectMenu];
- [menu addItem:menuItem];
- [aspectMenu release];
-
- //Add to menubar
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:menu];
- [[NSApp mainMenu] addItem:menuItem];
-
-//Create Window Menu
- menu = [[NSMenu alloc] initWithTitle:@"Window"];
-
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem];
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem];
-
- //Add to menubar
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:menu];
- [[NSApp mainMenu] addItem:menuItem];
- [NSApp setWindowsMenu:menu];
-
- [menu release];
- [menuItem release];
-}
+ struct osd_p *osd = p->osd;
+ GL *gl = p->mpglctx->gl;
-- (void)set_winSizeMult:(float)mult
-{
- NSRect frame;
- int d_width, d_height;
- aspect(&d_width, &d_height, A_NOZOOM);
+ if (w <= 0 || h <= 0 || stride < w) {
+ mp_msg(MSGT_VO, MSGL_V, "Invalid dimensions OSD for part!\n");
+ return;
+ }
- if (isFullscreen) {
- vo_fs = !vo_fs;
- [self fullscreen:NO];
+ if (osd->tex_cnt >= CV_MAX_OSD_PARTS) {
+ mp_msg(MSGT_VO, MSGL_ERR, "Too many OSD parts, contact the"
+ " developers!\n");
+ return;
}
- winSizeMult = mult;
- frame.size.width = d_width * mult;
- frame.size.height = d_height * mult;
- [window setContentSize: frame.size];
- [self reshape];
-}
+ gl->GenTextures(1, &osd->tex[osd->tex_cnt]);
+ gl->BindTexture(GL_TEXTURE_2D, osd->tex[osd->tex_cnt]);
+ glCreateClearTex(gl, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_BYTE, GL_LINEAR, w, h, 0);
+ {
+ int i;
+ unsigned char *tmp = malloc(stride * h * 2);
+ // convert alpha from weird MPlayer scale.
+ for (i = 0; i < h * stride; i++) {
+ tmp[i*2+0] = src[i];
+ tmp[i*2+1] = -srca[i];
+ }
+ glUploadTex(gl, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
+ tmp, stride * 2, 0, 0, w, h, 0);
+ free(tmp);
+ }
-/*
- Menu Action
- */
-- (void)menuAction:(id)sender
-{
- if(sender == kHalfScreenCmd)
- [self set_winSizeMult: 0.5];
- if(sender == kNormalScreenCmd)
- [self set_winSizeMult: 1];
- if(sender == kDoubleScreenCmd)
- [self set_winSizeMult: 2];
- if(sender == kFullScreenCmd)
- {
- vo_fs = !vo_fs;
- [self fullscreen:NO];
- }
-
- if(sender == kKeepAspectCmd)
- {
- vo_keepaspect = !vo_keepaspect;
- if(vo_keepaspect)
- [kKeepAspectCmd setState:NSOnState];
- else
- [kKeepAspectCmd setState:NSOffState];
-
- [self reshape];
- }
-
- if(sender == kPanScanCmd)
- {
- vo_panscan = !vo_panscan;
- if(vo_panscan)
- [kPanScanCmd setState:NSOnState];
- else
- [kPanScanCmd setState:NSOffState];
-
- [self panscan];
- }
-
- if(sender == kAspectOrgCmd)
- change_movie_aspect(-1);
-
- if(sender == kAspectFullCmd)
- change_movie_aspect(4.0f/3.0f);
-
- if(sender == kAspectWideCmd)
- change_movie_aspect(16.0f/9.0f);
-}
+ osd->tex_rect[osd->tex_cnt] = NSMakeRect(x0, y0, w, h);
-/*
- Setup OpenGL
-*/
-- (void)prepareOpenGL
-{
- glEnable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- glDepthMask(GL_FALSE);
- glDisable(GL_CULL_FACE);
- [self reshape];
+ gl->BindTexture(GL_TEXTURE_2D, 0);
+ osd->tex_cnt++;
}
-/*
- reshape OpenGL viewport
-*/
-- (void)reshape
+static void clearOSD(struct vo *vo)
{
- int d_width, d_height;
-
- NSRect frame = [self frame];
- vo_dwidth = frame.size.width;
- vo_dheight = frame.size.height;
-
- glViewport(0, 0, frame.size.width, frame.size.height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- //set texture frame
- if(vo_keepaspect)
- {
- aspect(&d_width, &d_height, A_WINZOOM);
-
- textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height);
- }
- else
- {
- textureFrame = frame;
- }
-}
+ struct osd_p *osd = p->osd;
+ GL *gl = p->mpglctx->gl;
-/*
- Render frame
-*/
-- (void) render
-{
- glClear(GL_COLOR_BUFFER_BIT);
-
- glEnable(CVOpenGLTextureGetTarget(texture));
- glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture));
-
- glColor3f(1,1,1);
- glBegin(GL_QUADS);
- glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1));
- glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(textureFrame.origin.x-(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1));
- glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1));
- glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1));
- glEnd();
- glDisable(CVOpenGLTextureGetTarget(texture));
-
- //render resize box
- if(!isFullscreen)
- {
- NSRect frame = [self frame];
-
- glBegin(GL_LINES);
- glColor4f(0.2, 0.2, 0.2, 0.5);
- glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1);
- glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1);
- glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1);
-
- glColor4f(0.4, 0.4, 0.4, 0.5);
- glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1);
- glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1);
- glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1);
-
- glColor4f(0.6, 0.6, 0.6, 0.5);
- glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1);
- glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1);
- glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1);
- glEnd();
- }
-
- glFlush();
+ if (!osd->tex_cnt)
+ return;
+ gl->DeleteTextures(osd->tex_cnt, osd->tex);
+ osd->tex_cnt = 0;
}
-/*
- Create OpenGL texture from current frame & set texco
-*/
-- (void) setCurrentTexture
+static void draw_osd(struct vo *vo, struct osd_state *osd_s)
{
- CVReturn error = kCVReturnSuccess;
+ struct osd_p *osd = p->osd;
+ GL *gl = p->mpglctx->gl;
- CVOpenGLTextureRelease(texture);
- error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
- if(error != kCVReturnSuccess)
- mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);
+ if (vo_osd_changed(0)) {
+ clearOSD(vo);
+ osd_draw_text_ext(osd_s, vo->dwidth, vo->dheight, 0, 0, 0, 0,
+ p->image_width, p->image_height, create_osd_texture,
+ vo);
+ }
- CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft);
-}
+ if (osd->tex_cnt > 0) {
+ gl->Enable(GL_BLEND);
+ gl->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-/*
- redraw win rect
-*/
-- (void) drawRect: (NSRect *) bounds
-{
- [self render];
-}
+ for (int n = 0; n < osd->tex_cnt; n++) {
+ NSRect tr = osd->tex_rect[n];
+ gl->BindTexture(GL_TEXTURE_2D, osd->tex[n]);
+ glDrawTex(gl, tr.origin.x, tr.origin.y,
+ tr.size.width, tr.size.height,
+ 0, 0, 1.0, 1.0, 1, 1, 0, 0, 0);
+ }
-/*
- Toggle Fullscreen
-*/
-- (void) fullscreen: (BOOL) animate
-{
- static NSRect old_frame;
- static NSRect old_view_frame;
-
- panscan_calc();
-
- //go fullscreen
- if(vo_fs)
- {
- if(!isRootwin)
- {
- SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
- CGDisplayHideCursor(kCGDirectMainDisplay);
- mouseHide = YES;
- }
-
- old_frame = [window frame]; //save main window size & position
- update_screen_info();
-
- [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx
- old_view_frame = [self bounds];
-
- //fix origin for multi screen setup
- screen_frame.origin.x = 0;
- screen_frame.origin.y = 0;
- [self setFrame:screen_frame];
- [self setNeedsDisplay:YES];
- [window setHasShadow:NO];
- isFullscreen = 1;
- }
- else
- {
- SetSystemUIMode( kUIModeNormal, 0);
-
- isFullscreen = 0;
- CGDisplayShowCursor(kCGDirectMainDisplay);
- mouseHide = NO;
-
- //revert window to previous setting
- [self setFrame:old_view_frame];
- [self setNeedsDisplay:YES];
- [window setHasShadow:YES];
- [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx
- }
+ gl->Disable(GL_BLEND);
+ gl->BindTexture(GL_TEXTURE_2D, 0);
+ }
}
-/*
- Toggle ontop
-*/
-- (void) ontop
+static void prepare_texture(void)
{
- if(vo_ontop)
- {
- [window setLevel:NSScreenSaverWindowLevel];
- isOntop = YES;
- }
- else
- {
- [window setLevel:NSNormalWindowLevel];
- isOntop = NO;
- }
-}
+ CVReturn error;
+ struct quad *q = p->quad;
-/*
- Toggle panscan
-*/
-- (void) panscan
-{
- panscan_calc();
-}
+ CVOpenGLTextureRelease(p->texture);
+ error = CVOpenGLTextureCacheCreateTextureFromImage(NULL,
+ p->textureCache, p->pixelBuffer, 0, &p->texture);
+ if(error != kCVReturnSuccess)
+ mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL"
+ " texture(%d)\n", error);
-/*
- Toggle rootwin
- */
-- (void) rootwin
-{
- if(vo_rootwin)
- {
- [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
- [window orderBack:self];
- isRootwin = YES;
- }
- else
- {
- [window setLevel:NSNormalWindowLevel];
- isRootwin = NO;
- }
+ CVOpenGLTextureGetCleanTexCoords(p->texture, q->lowerLeft, q->lowerRight,
+ q->upperRight, q->upperLeft);
}
-/*
- Check event for new event
-*/
-- (void) check_events
+static void do_render(struct vo *vo)
{
- NSEvent *event;
- int curTime = TickCount()/60;
-
- //automatically hide mouse cursor (and future on-screen control?)
- if(isFullscreen && !mouseHide && !isRootwin)
- {
- if(curTime - lastMouseHide >= 5 || lastMouseHide == 0)
- {
- CGDisplayHideCursor(kCGDirectMainDisplay);
- mouseHide = TRUE;
- lastMouseHide = curTime;
- }
- }
-
- //update activity every 30 seconds to prevent
- //screensaver from starting up.
- if(curTime - lastScreensaverUpdate >= 30 || lastScreensaverUpdate == 0)
- {
- UpdateSystemActivity(UsrActivity);
- lastScreensaverUpdate = curTime;
- }
-
- event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSEventTrackingRunLoopMode dequeue:YES];
- if (event == nil)
- return;
- [NSApp sendEvent:event];
- // Without SDL's bootstrap code (include SDL.h in mplayer.c),
- // on Leopard, we have trouble to get the play window automatically focused
- // when the app is actived. The Following code fix this problem.
-#ifndef CONFIG_SDL
- if (isLeopardOrLater && [event type] == NSAppKitDefined
- && [event subtype] == NSApplicationActivatedEventType) {
- [window makeMainWindow];
- [window makeKeyAndOrderFront:mpGLView];
- }
-#endif
-}
+ struct quad *q = p->quad;
+ GL *gl = p->mpglctx->gl;
+ prepare_texture();
-/*
- From NSView, respond to key equivalents.
-*/
-- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
-{
- switch([theEvent keyCode])
- {
- case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES;
- case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES;
- }
- return NO;
-}
+ float x0 = 0;
+ float y0 = 0;
+ float w = p->image_width;
+ float h = p->image_height;
-/*
- Process key event
-*/
-- (void) keyDown: (NSEvent *) theEvent
-{
- unsigned char charcode;
- if (([theEvent modifierFlags] & NSRightAlternateKeyMask) == NSRightAlternateKeyMask)
- charcode = *[[theEvent characters] UTF8String];
- else
- charcode = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
-
- int key = convert_key([theEvent keyCode], charcode);
-
- if (key > -1) {
- if([theEvent modifierFlags] & NSShiftKeyMask)
- key |= KEY_MODIFIER_SHIFT;
- if([theEvent modifierFlags] & NSControlKeyMask)
- key |= KEY_MODIFIER_CTRL;
- if(([theEvent modifierFlags] & NSLeftAlternateKeyMask) == NSLeftAlternateKeyMask)
- key |= KEY_MODIFIER_ALT;
- if([theEvent modifierFlags] & NSCommandKeyMask)
- key |= KEY_MODIFIER_META;
- mplayer_put_key(key);
- }
-}
+ // vertically flips the image
+ y0 += h;
+ h = -h;
-/*
- Process mouse button event
-*/
-- (void) mouseMoved: (NSEvent *) theEvent
-{
- if(isFullscreen && !isRootwin)
- {
- CGDisplayShowCursor(kCGDirectMainDisplay);
- mouseHide = NO;
- }
- if (enable_mouse_movements && !isRootwin) {
- NSPoint p =[self convertPoint:[theEvent locationInWindow] fromView:nil];
- if ([self mouse:p inRect:textureFrame]) {
- vo_mouse_movement(global_vo, vo_fs ? p.x : p.x - textureFrame.origin.x,
- vo_fs ? [self frame].size.height - p.y : NSMaxY(textureFrame) - p.y);
- }
- }
-}
+ float xm = x0 + w;
+ float ym = y0 + h;
-- (void) mouseDown: (NSEvent *) theEvent
-{
- [self mouseEvent: theEvent];
-}
+ gl->Enable(CVOpenGLTextureGetTarget(p->texture));
+ gl->BindTexture(
+ CVOpenGLTextureGetTarget(p->texture),
+ CVOpenGLTextureGetName(p->texture));
-- (void) mouseUp: (NSEvent *) theEvent
-{
- [self mouseEvent: theEvent];
-}
+ gl->Begin(GL_QUADS);
+ gl->TexCoord2fv(q->lowerLeft); gl->Vertex2f(x0, y0);
+ gl->TexCoord2fv(q->upperLeft); gl->Vertex2f(x0, ym);
+ gl->TexCoord2fv(q->upperRight); gl->Vertex2f(xm, ym);
+ gl->TexCoord2fv(q->lowerRight); gl->Vertex2f(xm, y0);
+ gl->End();
-- (void) rightMouseDown: (NSEvent *) theEvent
-{
- [self mouseEvent: theEvent];
+ gl->Disable(CVOpenGLTextureGetTarget(p->texture));
}
-- (void) rightMouseUp: (NSEvent *) theEvent
+static void flip_page(struct vo *vo)
{
- [self mouseEvent: theEvent];
+ p->mpglctx->swapGlBuffers(p->mpglctx);
+ p->mpglctx->gl->Clear(GL_COLOR_BUFFER_BIT);
}
-- (void) otherMouseDown: (NSEvent *) theEvent
+static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
{
- [self mouseEvent: theEvent];
-}
+ CVReturn error;
-- (void) otherMouseUp: (NSEvent *) theEvent
-{
- [self mouseEvent: theEvent];
-}
+ if (!p->textureCache || !p->pixelBuffer) {
+ error = CVOpenGLTextureCacheCreate(NULL, 0, vo_cocoa_cgl_context(),
+ vo_cocoa_cgl_pixel_format(), 0, &p->textureCache);
+ if(error != kCVReturnSuccess)
+ mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL"
+ " texture Cache(%d)\n", error);
-- (void) scrollWheel: (NSEvent *) theEvent
-{
- if([theEvent deltaY] > 0)
- mplayer_put_key(MOUSE_BTN3);
- else
- mplayer_put_key(MOUSE_BTN4);
-}
+ error = CVPixelBufferCreateWithBytes(NULL, mpi->width, mpi->height,
+ p->pixelFormat, mpi->planes[0], mpi->width * mpi->bpp / 8,
+ NULL, NULL, NULL, &p->pixelBuffer);
+ if(error != kCVReturnSuccess)
+ mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel"
+ "Buffer(%d)\n", error);
+ }
-- (void) mouseEvent: (NSEvent *) theEvent
-{
- if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 )
- {
- int buttonNumber = [theEvent buttonNumber];
- // Fix to mplayer defined button order: left, middle, right
- if (buttonNumber == 1)
- buttonNumber = 2;
- else if (buttonNumber == 2)
- buttonNumber = 1;
- switch([theEvent type])
- {
- case NSLeftMouseDown:
- case NSRightMouseDown:
- case NSOtherMouseDown:
- mplayer_put_key((MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN);
- break;
- case NSLeftMouseUp:
- case NSRightMouseUp:
- case NSOtherMouseUp:
- mplayer_put_key(MOUSE_BTN0 + buttonNumber);
- break;
- }
- }
+ do_render(vo);
+ return VO_TRUE;
}
-/*
- NSResponder
-*/
-- (BOOL) acceptsFirstResponder
+static int query_format(uint32_t format)
{
- return YES;
+ const int flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW |
+ VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN |
+ VOCAP_NOSLICES;
+ switch (format) {
+ case IMGFMT_YUY2:
+ p->pixelFormat = kYUVSPixelFormat;
+ return flags;
+
+ case IMGFMT_RGB24:
+ p->pixelFormat = k24RGBPixelFormat;
+ return flags;
+
+ case IMGFMT_ARGB:
+ p->pixelFormat = k32ARGBPixelFormat;
+ return flags;
+
+ case IMGFMT_BGRA:
+ p->pixelFormat = k32BGRAPixelFormat;
+ return flags;
+ }
+ return 0;
}
-- (BOOL) becomeFirstResponder
+static void uninit(struct vo *vo)
{
- return YES;
+ uninit_mpglcontext(p->mpglctx);
+ release_cv_entities();
+ talloc_free(p);
}
-- (BOOL) resignFirstResponder
-{
- return YES;
-}
-- (BOOL)windowShouldClose:(id)sender
+static int preinit(struct vo *vo, const char *arg)
{
- mplayer_put_key(KEY_CLOSE_WIN);
- // We have to wait for MPlayer to handle this,
- // otherwise we are in trouble if the
- // KEY_CLOSE_WIN handler is disabled
- return NO;
+ const opt_t subopts[] = {
+ {NULL}
+ };
+
+ if (subopt_parse(arg, subopts) != 0) {
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "\n-vo corevideo command line help:\n"
+ "Example: mplayer -vo corevideo\n"
+ "\n" );
+ return -1;
+ }
+
+ p = talloc_ptrtype(NULL, p);
+ *p = (struct priv) {
+ .mpglctx = init_mpglcontext(GLTYPE_COCOA, vo),
+ .colorspace = MP_CSP_DETAILS_DEFAULTS,
+ .quad = talloc_ptrtype(p, p->quad),
+ .osd = talloc_ptrtype(p, p->osd),
+ };
+
+ *p->osd = (struct osd_p) {
+ .tex_cnt = 0,
+ };
+
+ return 0;
}
-- (void)handleQuitEvent:(NSAppleEventDescriptor*)e withReplyEvent:(NSAppleEventDescriptor*)r
+static CFStringRef get_cv_csp_matrix(void)
{
- mplayer_put_key(KEY_CLOSE_WIN);
-}
-@end
+ switch (p->colorspace.format) {
+ case MP_CSP_BT_601:
+ return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
+ case MP_CSP_BT_709:
+ return kCVImageBufferYCbCrMatrix_ITU_R_709_2;
+ case MP_CSP_SMPTE_240M:
+ return kCVImageBufferYCbCrMatrix_SMPTE_240M_1995;
+ }
+ return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
+}
+
+static void set_yuv_colorspace(struct vo *vo)
+{
+ CVBufferSetAttachment(p->pixelBuffer,
+ kCVImageBufferYCbCrMatrixKey, get_cv_csp_matrix(),
+ kCVAttachmentMode_ShouldPropagate);
+ vo->want_redraw = true;
+}
+
+static int control(struct vo *vo, uint32_t request, void *data)
+{
+ switch (request) {
+ case VOCTRL_DRAW_IMAGE:
+ return draw_image(vo, data);
+ case VOCTRL_QUERY_FORMAT:
+ return query_format(*(uint32_t*)data);
+ case VOCTRL_ONTOP:
+ p->mpglctx->ontop(vo);
+ return VO_TRUE;
+ case VOCTRL_FULLSCREEN:
+ p->mpglctx->fullscreen(vo);
+ resize(vo, vo->dwidth, vo->dheight);
+ return VO_TRUE;
+ case VOCTRL_GET_PANSCAN:
+ return VO_TRUE;
+ case VOCTRL_SET_PANSCAN:
+ resize(vo, vo->dwidth, vo->dheight);
+ return VO_TRUE;
+ case VOCTRL_UPDATE_SCREENINFO:
+ p->mpglctx->update_xinerama_info(vo);
+ return VO_TRUE;
+ case VOCTRL_REDRAW_FRAME:
+ do_render(vo);
+ return VO_TRUE;
+ case VOCTRL_SET_YUV_COLORSPACE:
+ p->colorspace.format = ((struct mp_csp_details *)data)->format;
+ set_yuv_colorspace(vo);
+ return VO_TRUE;
+ case VOCTRL_GET_YUV_COLORSPACE:
+ *(struct mp_csp_details *)data = p->colorspace;
+ return VO_TRUE;
+ }
+ return VO_NOTIMPL;
+}
+
+const struct vo_driver video_out_corevideo = {
+ .is_new = true,
+ .info = &(const vo_info_t) {
+ "Mac OS X Core Video",
+ "corevideo",
+ "Nicolas Plourde <nicolas.plourde@gmail.com> and others",
+ ""
+ },
+ .preinit = preinit,
+ .config = config,
+ .control = control,
+ .draw_osd = draw_osd,
+ .flip_page = flip_page,
+ .check_events = check_events,
+ .uninit = uninit,
+};
diff --git a/libvo/vo_sharedbuffer.h b/libvo/vo_sharedbuffer.h
new file mode 100644
index 0000000000..c25463aa0a
--- /dev/null
+++ b/libvo/vo_sharedbuffer.h
@@ -0,0 +1,37 @@
+/*
+ * OSX Shared Buffer Video Output (extracted from mplayer's corevideo)
+ *
+ * This file is part of mplayer2.
+ *
+ * mplayer2 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.
+ *
+ * mplayer2 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 mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MPLAYER_VO_OSX_SHAREDBUFFER_H
+#define MPLAYER_VO_OSX_SHAREDBUFFER_H
+
+#import <Cocoa/Cocoa.h>
+
+// Protocol to communicate with the GUI
+@protocol MPlayerOSXVOProto
+- (int) startWithWidth: (bycopy int)width
+ withHeight: (bycopy int)height
+ withBytes: (bycopy int)bytes
+ withAspect: (bycopy int)aspect;
+- (void) stop;
+- (void) render;
+- (void) toggleFullscreen;
+- (void) ontop;
+@end
+
+#endif /* MPLAYER_VO_OSX_SHAREDBUFFER_H */
diff --git a/libvo/vo_sharedbuffer.m b/libvo/vo_sharedbuffer.m
new file mode 100644
index 0000000000..0b811f1848
--- /dev/null
+++ b/libvo/vo_sharedbuffer.m
@@ -0,0 +1,277 @@
+/*
+ * OSX Shared Buffer Video Output (extracted from mplayer's corevideo)
+ *
+ * This file is part of mplayer2.
+ *
+ * mplayer2 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.
+ *
+ * mplayer2 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 mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This video output was extracted from mplayer's corevideo. It's purpose it
+ * to copy mp_image data to a shared buffer using mmap and to do simple
+ * coordination with the GUIs using Distributed Objects.
+ */
+
+#include <sys/mman.h>
+
+#include "vo_sharedbuffer.h"
+#include "video_out.h"
+#include "subopt-helper.h"
+#include "talloc.h"
+
+#include "libmpcodecs/vfcap.h"
+#include "libmpcodecs/mp_image.h"
+#include "fastmemcpy.h"
+
+#include "sub/sub.h"
+#include "osd.h"
+
+// declarations
+struct priv {
+ char *buffer_name;
+ unsigned char *image_data;
+ unsigned int image_bytespp;
+ unsigned int image_width;
+ unsigned int image_height;
+
+ void (*vo_draw_alpha_fnc)(int w, int h, unsigned char* src,
+ unsigned char *srca, int srcstride, unsigned char* dstbase,
+ int dststride);
+
+ NSDistantObject *mposx_proxy;
+ id <MPlayerOSXVOProto> mposx_proto;
+};
+
+struct priv *p;
+
+// implementation
+static void draw_alpha(void *ctx, int x0, int y0, int w, int h,
+ unsigned char *src, unsigned char *srca,
+ int stride)
+{
+ p->vo_draw_alpha_fnc(w, h, src, srca, stride,
+ p->image_data + (x0 + y0 * p->image_width) * p->image_bytespp,
+ p->image_width * p->image_bytespp);
+}
+
+static unsigned int image_bytes()
+{
+ return p->image_width * p->image_height * p->image_bytespp;
+}
+
+static int preinit(struct vo *vo, const char *arg)
+{
+ p = talloc_zero(NULL, struct priv);
+
+ const opt_t subopts[] = {
+ {"buffer_name", OPT_ARG_MSTRZ, &p->buffer_name, NULL},
+ {NULL}
+ };
+
+ if (subopt_parse(arg, subopts) != 0) {
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "\n-vo sharedbuffer command line help:\n"
+ "Example: mplayer -vo shared_buffer:buffer_name=mybuff\n"
+ "\nOptions:\n"
+ " buffer_name=<name>\n"
+ " Name of the shared buffer created with shm_open() as well as\n"
+ " the name of the NSConnection mplayer2 will try to open.\n"
+ "Example: mplayer -vo sharedbuffer\n"
+ "\n" );
+ return -1;
+ }
+
+ if (!p->buffer_name) p->buffer_name = "mplayerosx";
+
+ return 0;
+}
+
+static void flip_page(struct vo *vo)
+{
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ [p->mposx_proto render];
+ [pool release];
+}
+
+static void check_events(struct vo *vo) { }
+
+static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
+{
+ memcpy_pic(p->image_data, mpi->planes[0],
+ (p->image_width) * (p->image_bytespp), p->image_height,
+ (p->image_width) * (p->image_bytespp), mpi->stride[0]);
+ return 0;
+}
+
+static void draw_osd(struct vo *vo, struct osd_state *osd) {
+ osd_draw_text(osd, p->image_width, p->image_height, draw_alpha, vo);
+}
+
+static void free_buffers(void)
+{
+ [p->mposx_proto stop];
+ p->mposx_proto = nil;
+ [p->mposx_proxy release];
+ p->mposx_proxy = nil;
+
+ if (p->image_data) {
+ if (munmap(p->image_data, image_bytes()) == -1)
+ mp_msg(MSGT_VO, MSGL_FATAL, "[vo_sharedbuffer] uninit: munmap "
+ "failed. Error: %s\n", strerror(errno));
+
+ if (shm_unlink(p->buffer_name) == -1)
+ mp_msg(MSGT_VO, MSGL_FATAL, "[vo_sharedbuffer] uninit: shm_unlink "
+ "failed. Error: %s\n", strerror(errno));
+ }
+}
+
+static int config(struct vo *vo, uint32_t width, uint32_t height,
+ uint32_t d_width, uint32_t d_height, uint32_t flags,
+ uint32_t format)
+{
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ free_buffers();
+
+ p->image_width = width;
+ p->image_height = height;
+
+ mp_msg(MSGT_VO, MSGL_INFO, "[vo_sharedbuffer] writing output to a shared "
+ "buffer named \"%s\"\n", p->buffer_name);
+
+ // create shared memory
+ int shm_fd = shm_open(p->buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ if (shm_fd == -1) {
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "[vo_sharedbuffer] failed to open shared memory. Error: %s\n",
+ strerror(errno));
+ goto err_out;
+ }
+
+ if (ftruncate(shm_fd, image_bytes()) == -1) {
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "[vo_sharedbuffer] failed to size shared memory, possibly "
+ "already in use. Error: %s\n", strerror(errno));
+ close(shm_fd);
+ shm_unlink(p->buffer_name);
+ goto err_out;
+ }
+
+ p->image_data = mmap(NULL, image_bytes(),
+ PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
+ close(shm_fd);
+
+ if (p->image_data == MAP_FAILED) {
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "[vo_sharedbuffer] failed to map shared memory. "
+ "Error: %s\n", strerror(errno));
+ shm_unlink(p->buffer_name);
+ goto err_out;
+ }
+
+ //connect to mplayerosx
+ p->mposx_proxy = [NSConnection
+ rootProxyForConnectionWithRegisteredName:
+ [NSString stringWithUTF8String:p->buffer_name] host:nil];
+
+ if ([p->mposx_proxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) {
+ [p->mposx_proxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)];
+ p->mposx_proto = (id <MPlayerOSXVOProto>)p->mposx_proxy;
+ [p->mposx_proto startWithWidth:p->image_width
+ withHeight:p->image_height
+ withBytes:p->image_bytespp
+ withAspect:d_width*100/d_height];
+ } else {
+ mp_msg(MSGT_VO, MSGL_ERR,
+ "[vo_sharedbuffer] distributed object doesn't conform "
+ "to the correct protocol.\n");
+ [p->mposx_proxy release];
+ p->mposx_proxy = nil;
+ p->mposx_proto = nil;
+ }
+
+ [pool release];
+ return 0;
+err_out:
+ [pool release];
+ return 1;
+}
+
+static int query_format(uint32_t format)
+{
+ unsigned int image_depth = 0;
+ switch (format) {
+ case IMGFMT_YUY2:
+ p->vo_draw_alpha_fnc = vo_draw_alpha_yuy2;
+ image_depth = 16;
+ goto supported;
+ case IMGFMT_RGB24:
+ p->vo_draw_alpha_fnc = vo_draw_alpha_rgb24;
+ image_depth = 24;
+ goto supported;
+ case IMGFMT_ARGB:
+ p->vo_draw_alpha_fnc = vo_draw_alpha_rgb32;
+ image_depth = 32;
+ goto supported;
+ case IMGFMT_BGRA:
+ p->vo_draw_alpha_fnc = vo_draw_alpha_rgb32;
+ image_depth = 32;
+ goto supported;
+ }
+ return 0;
+
+supported:
+ p->image_bytespp = (image_depth + 7) / 8;
+ return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW |
+ VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN |
+ VOCAP_NOSLICES;
+}
+
+static void uninit(struct vo *vo)
+{
+ free_buffers();
+}
+
+static int control(struct vo *vo, uint32_t request, void *data)
+{
+ switch (request) {
+ case VOCTRL_DRAW_IMAGE:
+ return draw_image(vo, data);
+ case VOCTRL_FULLSCREEN:
+ [p->mposx_proto toggleFullscreen];
+ return VO_TRUE;
+ case VOCTRL_QUERY_FORMAT:
+ return query_format(*(uint32_t*)data);
+ case VOCTRL_ONTOP:
+ [p->mposx_proto ontop];
+ return VO_TRUE;
+ }
+ return VO_NOTIMPL;
+}
+
+const struct vo_driver video_out_sharedbuffer = {
+ .is_new = true,
+ .info = &(const vo_info_t) {
+ "Mac OS X Shared Buffer (headless video output for GUIs)",
+ "sharedbuffer",
+ "Stefano Pigozzi <stefano.pigozzi@gmail.com> and others.",
+ ""
+ },
+ .preinit = preinit,
+ .config = config,
+ .control = control,
+ .flip_page = flip_page,
+ .check_events = check_events,
+ .uninit = uninit,
+ .draw_osd = draw_osd
+};
diff --git a/mplayer.c b/mplayer.c
index ce617eccff..36d6c825ff 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -31,6 +31,16 @@
#if defined(__MINGW32__) || defined(__CYGWIN__)
#include <windows.h>
+// No proper file descriptor event handling; keep waking up to poll input
+#define WAKEUP_PERIOD 0.02
+#else
+/* Even if we can immediately wake up in response to most input events,
+ * there are some timers which are not registered to the event loop
+ * and need to be checked periodically (like automatic mouse cursor hiding).
+ * OSD content updates behave similarly. Also some uncommon input devices
+ * may not have proper FD event support.
+ */
+#define WAKEUP_PERIOD 0.5
#endif
#include <string.h>
#include <unistd.h>
@@ -1766,8 +1776,10 @@ void reinit_audio_chain(struct MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
struct ao *ao;
- if (!mpctx->sh_audio)
+ if (!mpctx->sh_audio) {
+ uninit_player(mpctx, INITIALIZED_AO);
return;
+ }
if (!(mpctx->initialized_flags & INITIALIZED_ACODEC)) {
current_module = "init_audio_codec";
mp_msg(MSGT_CPLAYER, MSGL_INFO, "==========================================================================\n");
@@ -2621,11 +2633,10 @@ int reinit_video_chain(struct MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
sh_video_t * const sh_video = mpctx->sh_video;
- if (!sh_video){
+ if (!sh_video) {
uninit_player(mpctx, INITIALIZED_VO);
return 0;
}
-
double ar = -1.0;
//================== Init VIDEO (codec & libvo) ==========================
if (!opts->fixed_vo || !(mpctx->initialized_flags & INITIALIZED_VO)) {
@@ -2717,6 +2728,8 @@ int reinit_video_chain(struct MPContext *mpctx)
sh_video->last_pts = MP_NOPTS_VALUE;
sh_video->num_buffered_pts = 0;
sh_video->next_frame_time = 0;
+ mpctx->restart_playback = true;
+ mpctx->delay = 0;
if (opts->auto_quality > 0) {
// Auto quality option enabled
@@ -3424,7 +3437,7 @@ static void run_playloop(struct MPContext *mpctx)
bool audio_left = false, video_left = false;
double endpts = end_at.type == END_AT_TIME ? end_at.pos : MP_NOPTS_VALUE;
bool end_is_chapter = false;
- double sleeptime = 0.5;
+ double sleeptime = WAKEUP_PERIOD;
bool was_restart = mpctx->restart_playback;
if (mpctx->timeline) {
@@ -4256,17 +4269,13 @@ play_next_file:
mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n[[[init getch2]]]\n");
}
- // ================= GUI idle loop (STOP state) =========================
+ // ================= idle loop (STOP state) =========================
while (opts->player_idle_mode && !mpctx->filename) {
+ uninit_player(mpctx, INITIALIZED_AO | INITIALIZED_VO);
play_tree_t *entry = NULL;
mp_cmd_t *cmd;
- if (mpctx->video_out && mpctx->video_out->config_ok)
- vo_control(mpctx->video_out, VOCTRL_PAUSE, NULL);
- while (!(cmd = mp_input_get_cmd(mpctx->input, 0, 0))) {
- if (mpctx->video_out)
- vo_check_events(mpctx->video_out);
- usec_sleep(20000);
- }
+ while (!(cmd = mp_input_get_cmd(mpctx->input, WAKEUP_PERIOD * 1000,
+ false)));
switch (cmd->id) {
case MP_CMD_LOADFILE:
// prepare a tree entry with the new filename
@@ -4853,7 +4862,6 @@ goto_enable_cache:
mixer_setvolume(&mpctx->mixer, start_volume, start_volume);
if (!ignore_start)
audio_delay -= mpctx->sh_audio->stream_delay;
- mpctx->delay = -audio_delay;
}
if (!mpctx->sh_audio) {
diff --git a/osdep/cocoa_events.h b/osdep/cocoa_events.h
new file mode 100644
index 0000000000..3f0e775e03
--- /dev/null
+++ b/osdep/cocoa_events.h
@@ -0,0 +1,30 @@
+/*
+ * Cocoa Event Handling
+ *
+ * This file is part of mplayer2.
+ *
+ * mplayer2 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.
+ *
+ * mplayer2 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 mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MPLAYER_COCOA_EVENTS_H
+#define MPLAYER_COCOA_EVENTS_H
+
+#include "input/input.h"
+
+void cocoa_events_init(struct input_ctx *ictx,
+ void (*read_all_fd_events)(struct input_ctx *ictx, int time));
+void cocoa_events_uninit(void);
+void cocoa_events_read_all_events(struct input_ctx *ictx, int time);
+
+#endif /* MPLAYER_COCOA_EVENTS_H */
diff --git a/osdep/cocoa_events.m b/osdep/cocoa_events.m
new file mode 100644
index 0000000000..ba09c13cad
--- /dev/null
+++ b/osdep/cocoa_events.m
@@ -0,0 +1,137 @@
+/*
+ * Cocoa Event Handling
+ *
+ * This file is part of mplayer2.
+ *
+ * mplayer2 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.
+ *
+ * mplayer2 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 mplayer2. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Implementation details:
+ * This file deals with custom event polling on MacOSX. When mplayer2 is paused
+ * it will asynchronously poll for events using select. This works correctly on
+ * Linux with X11 since the events are notified through the file descriptors
+ * where mplayer2 is listening on. On the other hand, the OSX window server
+ * notifies the processes for events using mach ports.
+ *
+ * The code below uses functionality from Cocoa that abstracts the async polling
+ * of events from the window server. When a Cocoa event comes in, the polling is
+ * interrupted and the event is dealt with in the next vo_check_events.
+ *
+ * To keep the select fd polling code working, that functionality is executed
+ * from another thread. Whoever finishes polling before the given time, be it
+ * Cocoa or the original select code, notifies the other for an immediate wake.
+ */
+
+#include "cocoa_events.h"
+#include "libvo/cocoa_common.h"
+#include "talloc.h"
+
+#import <Cocoa/Cocoa.h>
+#include <dispatch/dispatch.h>
+
+// Bogus event subtype to wake the Cocoa code from polling state
+#define MP_EVENT_SUBTYPE_WAKE_EVENTLOOP 100
+
+// This is the threshold in milliseconds below which the Cocoa polling is not
+// executed. There is some overhead caused by the synchronization between
+// threads. Even if in practice it isn't noticeable, we try to avoid the useless
+// waste of resources.
+#define MP_ASYNC_THRESHOLD 50
+
+struct priv {
+ dispatch_queue_t select_queue;
+ bool is_runloop_polling;
+ void (*read_all_fd_events)(struct input_ctx *ictx, int time);
+};
+
+static struct priv *p;
+
+static void cocoa_wait_events(int mssleeptime)
+{
+ NSTimeInterval sleeptime = mssleeptime / 1000.0;
+ NSEvent *event;
+ p->is_runloop_polling = YES;
+ event = [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:[NSDate dateWithTimeIntervalSinceNow:sleeptime]
+ inMode:NSEventTrackingRunLoopMode dequeue:NO];
+
+ // dequeue the next event if it is a fake to wake the cocoa polling
+ if (event && [event type] == NSApplicationDefined &&
+ [event subtype] == MP_EVENT_SUBTYPE_WAKE_EVENTLOOP) {
+ [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
+ inMode:NSEventTrackingRunLoopMode dequeue:YES];
+ }
+ p->is_runloop_polling = NO;
+}
+
+static void cocoa_wake_runloop()
+{
+ if (p->is_runloop_polling) {
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ NSEvent *event;
+
+ /* Post an event so we'll wake the run loop that is async polling */
+ event = [NSEvent otherEventWithType: NSApplicationDefined
+ location: NSZeroPoint
+ modifierFlags: 0
+ timestamp: 0
+ windowNumber: 0
+ context: nil
+ subtype: MP_EVENT_SUBTYPE_WAKE_EVENTLOOP
+ data1: 0
+ data2: 0];
+
+ [NSApp postEvent:event atStart:NO];
+ [pool release];
+ }
+}
+
+void cocoa_events_init(struct input_ctx *ictx,
+ void (*read_all_fd_events)(struct input_ctx *ictx, int time))
+{
+ NSApplicationLoad();
+ p = talloc_ptrtype(NULL, p);
+ *p = (struct priv){
+ .is_runloop_polling = NO,
+ .read_all_fd_events = read_all_fd_events,
+ .select_queue = dispatch_queue_create("org.mplayer2.select_queue",
+ NULL),
+ };
+}
+
+void cocoa_events_uninit(void)
+{
+ talloc_free(p);
+}
+
+void cocoa_events_read_all_events(struct input_ctx *ictx, int time)
+{
+ // don't bother delegating the select to the async queue if the blocking
+ // time is really low or if we are not running a GUI
+ if (time > MP_ASYNC_THRESHOLD && vo_cocoa_gui_running()) {
+ dispatch_async(p->select_queue, ^{
+ p->read_all_fd_events(ictx, time);
+ cocoa_wake_runloop();
+ });
+
+ cocoa_wait_events(time);
+ mp_input_wakeup(ictx);
+
+ // wait for the async queue to get empty.
+ dispatch_sync(p->select_queue, ^{});
+ } else {
+ p->read_all_fd_events(ictx, time);
+ }
+}
diff --git a/path.c b/path.c
index 785c48eec9..e51c4c9c34 100644
--- a/path.c
+++ b/path.c
@@ -56,6 +56,9 @@ char *get_path(const char *filename){
#else
static char *config_dir = "/.mplayer";
#endif
+#if defined(__MINGW32__) || defined(__CYGWIN__)
+ char exedir[260];
+#endif
int len;
#ifdef CONFIG_MACOSX_BUNDLE
struct stat dummy;
@@ -73,9 +76,8 @@ char *get_path(const char *filename){
/* Hack to get fonts etc. loaded outside of Cygwin environment. */
{
int i,imax=0;
- char exedir[260];
- GetModuleFileNameA(NULL, exedir, 260);
- for (i=0; i< strlen(exedir); i++)
+ len = (int)GetModuleFileNameA(NULL, exedir, 260);
+ for (i=0; i < len; i++)
if (exedir[i] =='\\')
{exedir[i]='/'; imax=i;}
exedir[imax]='\0';
diff --git a/stream/stream_ffmpeg.c b/stream/stream_ffmpeg.c
index a76b9e5f3b..af71675713 100644
--- a/stream/stream_ffmpeg.c
+++ b/stream/stream_ffmpeg.c
@@ -56,7 +56,7 @@ static int seek(stream_t *s, off_t newpos)
static int control(stream_t *s, int cmd, void *arg)
{
- AVIOContext *avio = avio;
+ AVIOContext *avio = s->priv;
int64_t size, ts;
double pts;
switch(cmd) {
diff --git a/sub/subassconvert.c b/sub/subassconvert.c
index bbd789f91f..e1db9bb033 100644
--- a/sub/subassconvert.c
+++ b/sub/subassconvert.c
@@ -106,25 +106,30 @@ static const struct {
#define SUBRIP_MAX_STACKED_FONT_TAGS 16
-/* read the attribute value starting at *s, and skip *s past the value
- * return the value in out_value, with possible '"' stripped
- * return whether the attribute is well formed */
-static bool read_value(char **s, struct bstr *out_value)
+/* Read the HTML-style attribute starting at *s, and skip *s past the value.
+ * Set attr and val to the parsed attribute name and value.
+ * Return 0 on success, or -1 if no valid attribute was found.
+ */
+static int read_attr(char **s, struct bstr *attr, struct bstr *val)
{
- char term = '\0';
- if (**s == '"') {
- term = '"';
- (*s)++;
- }
- out_value->start = *s;
- out_value->len = 0;
- unsigned char *start = *s;
- unsigned char *end = term ? strchr(start, term) : strpbrk(start, " >");
+ char *eq = strchr(*s, '=');
+ if (!eq)
+ return -1;
+ attr->start = *s;
+ attr->len = eq - *s;
+ for (int i = 0; i < attr->len; i++)
+ if (!isalnum(attr->start[i]))
+ return -1;
+ val->start = eq + 1;
+ bool quoted = val->start[0] == '"';
+ if (quoted)
+ val->start++;
+ unsigned char *end = strpbrk(val->start, quoted ? "\"" : " >");
if (!end)
- return false;
- out_value->len = end - out_value->start;
- *s = end + (term ? 1 : 0);
- return true;
+ return -1;
+ val->len = end - val->start;
+ *s = end + quoted;
+ return 0;
}
void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
@@ -195,22 +200,21 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
line += 6;
while (*line && *line != '>') {
- if (strncmp(line, "size=", 5) == 0) {
- line += 5;
- struct bstr val;
- if (!read_value(&line, &val))
- break;
+ if (*line == ' ') {
+ line++;
+ continue;
+ }
+ struct bstr attr, val;
+ if (read_attr(&line, &attr, &val) < 0)
+ break;
+ if (!bstrcmp0(attr, "size")) {
tag->size = bstrtoll(val, &val, 10);
if (val.len)
break;
append_text(&new_line, "{\\fs%d}", tag->size);
tag->has_size = true;
has_valid_attr = true;
- } else if (strncmp(line, "color=", 6) == 0) {
- line += 6;
- struct bstr val;
- if (!read_value(&line, &val))
- break;
+ } else if (!bstrcmp0(attr, "color")) {
if (bstr_eatstart(&val, bstr("#"))) {
// #RRGGBB format
tag->color = bstrtoll(val, &val, 16) & 0x00ffffff;
@@ -240,18 +244,15 @@ void subassconvert_subrip(const char *orig, char *dest, int dest_buffer_size)
append_text(&new_line, "{\\c&H%06X&}", tag->color);
tag->has_color = true;
has_valid_attr = true;
- } else if (strncmp(line, "face=", 5) == 0) {
+ } else if (!bstrcmp0(attr, "face")) {
/* Font face attribute */
- line += 5;
- struct bstr val;
- if (!read_value(&line, &val))
- break;
tag->face = val;
append_text(&new_line, "{\\fn%.*s}", BSTR_P(tag->face));
tag->has_face = true;
has_valid_attr = true;
} else
- line++;
+ mp_tmsg(MSGT_SUBREADER, MSGL_WARN,"SubRip: unrecognized "
+ "attribute \"%.*s\" in font tag\n", BSTR_P(attr));
}
if (!has_valid_attr || *line != '>') { /* Not valid font tag */