1
mirror of https://github.com/mpv-player/mpv synced 2024-10-26 07:22:17 +02:00

vo_sharedbuffer: remove this VO

Since slave mode is not planned to be kept, this VO is useless and I'm
removing it.

This VO was useful for OSX GUIs. Since in cocoa you can't embed views in
windows from other processes, this VO was writing to a sharedbuffer with
mmap. The OSX GUIs would then read from the buffer and render the image
with an external renderer.

If in the future we will want to support GUIs we will need to reasearch the
IOSurface framework. This allows to share kernel managed image data
across processes and integrates well with OpenGL.
This commit is contained in:
Stefano Pigozzi 2012-08-15 10:13:18 +02:00
parent 4e2fe3724b
commit 6879d1162c
6 changed files with 0 additions and 348 deletions

View File

@ -712,14 +712,3 @@ image
JPEG DPI (default: 72)
outdir=<dirname>
Specify the directory to save the image files to (default: ``./``).
sharedbuffer (Mac OS X 10.6 and later)
Mac OS X headless video output designed to interact with GUIs. It copies
image data to a shared buffer so that the data can be read from a GUI and
rendered.
It uses the same protocol as MPlayer's ``-vo corevideo:shared_buffer``
buffer_name=<buffer_name>
Name of the shared buffer created with shm_open() as well as the name
of the NSConnection mplayer2 will try to open (default: mplayerosx).

View File

@ -381,7 +381,6 @@ SRCS_MPLAYER-$(APPLE_REMOTE) += input/ar.c
SRCS_MPLAYER-$(CACA) += libvo/vo_caca.c
SRCS_MPLAYER-$(COREAUDIO) += libao2/ao_coreaudio.c
SRCS_MPLAYER-$(COREVIDEO) += libvo/vo_corevideo.m
SRCS_MPLAYER-$(SHAREDBUFFER) += libvo/vo_sharedbuffer.m
SRCS_MPLAYER-$(DIRECT3D) += libvo/vo_direct3d.c libvo/w32_common.c
SRCS_MPLAYER-$(DIRECTFB) += libvo/vo_directfb2.c
SRCS_MPLAYER-$(DIRECTX) += libao2/ao_dsound.c libvo/vo_directx.c

26
configure vendored
View File

@ -372,7 +372,6 @@ Video output:
--enable-directfb enable DirectFB video output [autodetect]
--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]
@ -527,7 +526,6 @@ _qtx=auto
_coreaudio=auto
_corevideo=auto
_cocoa=auto
_sharedbuffer=auto
quicktime=auto
_macosx_finder=no
_macosx_bundle=auto
@ -834,8 +832,6 @@ 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 ;;
@ -2127,26 +2123,6 @@ else
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
}
@ -3872,7 +3848,6 @@ CDDB = $_cddb
COCOA = $_cocoa
COREAUDIO = $_coreaudio
COREVIDEO = $_corevideo
SHAREDBUFFER = $_sharedbuffer
DIRECT3D = $_direct3d
DIRECTFB = $_directfb
DIRECTX = $_directx
@ -4187,7 +4162,6 @@ $def_lcms2
$def_caca
$def_corevideo
$def_cocoa
$def_sharedbuffer
$def_direct3d
$def_directfb
$def_directx

View File

@ -87,7 +87,6 @@ extern struct vo_driver video_out_direct3d_shaders;
extern struct vo_driver video_out_directx;
extern struct vo_driver video_out_directfb;
extern struct vo_driver video_out_corevideo;
extern struct vo_driver video_out_sharedbuffer;
const struct vo_driver *video_out_drivers[] =
{
@ -124,9 +123,6 @@ 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,

View File

@ -1,37 +0,0 @@
/*
* 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 */

View File

@ -1,269 +0,0 @@
/*
* 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. Its purpose is
* 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 "m_option.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;
};
// implementation
static void draw_alpha(void *ctx, int x0, int y0, int w, int h,
unsigned char *src, unsigned char *srca,
int stride)
{
struct priv *p = ((struct vo *) ctx)->priv;
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(struct priv *p)
{
return p->image_width * p->image_height * p->image_bytespp;
}
static int preinit(struct vo *vo, const char *arg)
{
return 0;
}
static void flip_page(struct vo *vo)
{
struct priv *p = vo->priv;
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)
{
struct priv *p = vo->priv;
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) {
struct priv *p = vo->priv;
osd_draw_text(osd, p->image_width, p->image_height, draw_alpha, vo);
}
static void free_buffers(struct priv *p)
{
[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(p)) == -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)
{
struct priv *p = vo->priv;
NSAutoreleasePool *pool = [NSAutoreleasePool new];
free_buffers(p);
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(p)) == -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(p),
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(struct vo *vo, uint32_t format)
{
struct priv *p = vo->priv;
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)
{
struct priv *p = vo->priv;
free_buffers(p);
}
static int control(struct vo *vo, uint32_t request, void *data)
{
struct priv *p = vo->priv;
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(vo, *(uint32_t*)data);
case VOCTRL_ONTOP:
[p->mposx_proto ontop];
return VO_TRUE;
}
return VO_NOTIMPL;
}
#undef OPT_BASE_STRUCT
#define OPT_BASE_STRUCT struct priv
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,
.priv_size = sizeof(struct priv),
.options = (const struct m_option[]) {
OPT_STRING("buffer_name", buffer_name, 0, OPTDEF_STR("mplayerosx")),
{NULL},
},
};