2020-10-09 21:56:16 +02:00
|
|
|
/*
|
|
|
|
* unix_iface.c - This is the Win32 side of the Unix interface.
|
|
|
|
*
|
|
|
|
* Copyright 2020 Esme Povirk
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
|
|
|
|
#include "wincodecs_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
|
|
|
|
|
|
|
|
static const struct unix_funcs *unix_funcs;
|
|
|
|
|
2020-10-09 21:56:17 +02:00
|
|
|
static const struct win32_funcs win32_funcs = {
|
2020-10-27 18:54:42 +01:00
|
|
|
stream_getsize,
|
2020-10-09 21:56:17 +02:00
|
|
|
stream_read,
|
2020-11-15 21:12:25 +01:00
|
|
|
stream_seek,
|
|
|
|
stream_write
|
2020-10-09 21:56:17 +02:00
|
|
|
};
|
|
|
|
|
2020-10-09 21:56:16 +02:00
|
|
|
static BOOL WINAPI load_unixlib( INIT_ONCE *once, void *param, void **context )
|
|
|
|
{
|
2020-10-09 21:56:17 +02:00
|
|
|
__wine_init_unix_lib( windowscodecs_module, DLL_PROCESS_ATTACH, &win32_funcs, &unix_funcs );
|
2020-10-09 21:56:16 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_unixlib(void)
|
|
|
|
{
|
|
|
|
InitOnceExecuteOnce( &init_once, load_unixlib, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
struct decoder_wrapper
|
|
|
|
{
|
|
|
|
struct decoder win32_decoder;
|
|
|
|
struct decoder *unix_decoder;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct decoder_wrapper *impl_from_decoder(struct decoder* iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct decoder_wrapper, win32_decoder);
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:17 +02:00
|
|
|
HRESULT CDECL decoder_wrapper_initialize(struct decoder* iface, IStream* stream, struct decoder_stat *st)
|
|
|
|
{
|
|
|
|
struct decoder_wrapper* This = impl_from_decoder(iface);
|
|
|
|
return unix_funcs->decoder_initialize(This->unix_decoder, stream, st);
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:18 +02:00
|
|
|
HRESULT CDECL decoder_wrapper_get_frame_info(struct decoder* iface, UINT frame, struct decoder_frame *info)
|
|
|
|
{
|
|
|
|
struct decoder_wrapper* This = impl_from_decoder(iface);
|
|
|
|
return unix_funcs->decoder_get_frame_info(This->unix_decoder, frame, info);
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:19 +02:00
|
|
|
HRESULT CDECL decoder_wrapper_copy_pixels(struct decoder* iface, UINT frame,
|
|
|
|
const WICRect *prc, UINT stride, UINT buffersize, BYTE *buffer)
|
|
|
|
{
|
|
|
|
struct decoder_wrapper* This = impl_from_decoder(iface);
|
|
|
|
return unix_funcs->decoder_copy_pixels(This->unix_decoder, frame, prc, stride, buffersize, buffer);
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:20 +02:00
|
|
|
HRESULT CDECL decoder_wrapper_get_metadata_blocks(struct decoder* iface,
|
|
|
|
UINT frame, UINT *count, struct decoder_block **blocks)
|
|
|
|
{
|
|
|
|
struct decoder_wrapper* This = impl_from_decoder(iface);
|
|
|
|
return unix_funcs->decoder_get_metadata_blocks(This->unix_decoder, frame, count, blocks);
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:21 +02:00
|
|
|
HRESULT CDECL decoder_wrapper_get_color_context(struct decoder* iface,
|
|
|
|
UINT frame, UINT num, BYTE **data, DWORD *datasize)
|
|
|
|
{
|
|
|
|
struct decoder_wrapper* This = impl_from_decoder(iface);
|
|
|
|
return unix_funcs->decoder_get_color_context(This->unix_decoder, frame, num, data, datasize);
|
|
|
|
}
|
|
|
|
|
2020-10-09 21:56:16 +02:00
|
|
|
void CDECL decoder_wrapper_destroy(struct decoder* iface)
|
|
|
|
{
|
|
|
|
struct decoder_wrapper* This = impl_from_decoder(iface);
|
|
|
|
unix_funcs->decoder_destroy(This->unix_decoder);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct decoder_funcs decoder_wrapper_vtable = {
|
2020-10-09 21:56:17 +02:00
|
|
|
decoder_wrapper_initialize,
|
2020-10-09 21:56:18 +02:00
|
|
|
decoder_wrapper_get_frame_info,
|
2020-10-09 21:56:19 +02:00
|
|
|
decoder_wrapper_copy_pixels,
|
2020-10-09 21:56:20 +02:00
|
|
|
decoder_wrapper_get_metadata_blocks,
|
2020-10-09 21:56:21 +02:00
|
|
|
decoder_wrapper_get_color_context,
|
2020-10-09 21:56:16 +02:00
|
|
|
decoder_wrapper_destroy
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT get_unix_decoder(const CLSID *decoder_clsid, struct decoder_info *info, struct decoder **result)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
struct decoder_wrapper *wrapper;
|
|
|
|
struct decoder *unix_decoder;
|
|
|
|
|
|
|
|
init_unixlib();
|
|
|
|
|
|
|
|
hr = unix_funcs->decoder_create(decoder_clsid, info, &unix_decoder);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
wrapper = HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper));
|
|
|
|
|
|
|
|
if (!wrapper)
|
|
|
|
{
|
|
|
|
unix_funcs->decoder_destroy(unix_decoder);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper->win32_decoder.vtable = &decoder_wrapper_vtable;
|
|
|
|
wrapper->unix_decoder = unix_decoder;
|
|
|
|
*result = &wrapper->win32_decoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2020-11-15 21:12:24 +01:00
|
|
|
|
|
|
|
struct encoder_wrapper
|
|
|
|
{
|
|
|
|
struct encoder win32_encoder;
|
|
|
|
struct encoder *unix_encoder;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct encoder_wrapper *impl_from_encoder(struct encoder* iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct encoder_wrapper, win32_encoder);
|
|
|
|
}
|
|
|
|
|
2020-11-15 21:12:25 +01:00
|
|
|
HRESULT CDECL encoder_wrapper_initialize(struct encoder* iface, IStream* stream)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
return unix_funcs->encoder_initialize(This->unix_encoder, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL encoder_wrapper_get_supported_format(struct encoder* iface, GUID *pixel_format, DWORD *bpp, BOOL *indexed)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
return unix_funcs->encoder_get_supported_format(This->unix_encoder, pixel_format, bpp, indexed);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL encoder_wrapper_create_frame(struct encoder* iface, const struct encoder_frame *frame)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
return unix_funcs->encoder_create_frame(This->unix_encoder, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL encoder_wrapper_write_lines(struct encoder* iface, BYTE *data, DWORD line_count, DWORD stride)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
return unix_funcs->encoder_write_lines(This->unix_encoder, data, line_count, stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL encoder_wrapper_commit_frame(struct encoder* iface)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
return unix_funcs->encoder_commit_frame(This->unix_encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL encoder_wrapper_commit_file(struct encoder* iface)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
return unix_funcs->encoder_commit_file(This->unix_encoder);
|
|
|
|
}
|
|
|
|
|
2020-11-15 21:12:24 +01:00
|
|
|
void CDECL encoder_wrapper_destroy(struct encoder* iface)
|
|
|
|
{
|
|
|
|
struct encoder_wrapper* This = impl_from_encoder(iface);
|
|
|
|
unix_funcs->encoder_destroy(This->unix_encoder);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct encoder_funcs encoder_wrapper_vtable = {
|
2020-11-15 21:12:25 +01:00
|
|
|
encoder_wrapper_initialize,
|
|
|
|
encoder_wrapper_get_supported_format,
|
|
|
|
encoder_wrapper_create_frame,
|
|
|
|
encoder_wrapper_write_lines,
|
|
|
|
encoder_wrapper_commit_frame,
|
|
|
|
encoder_wrapper_commit_file,
|
2020-11-15 21:12:24 +01:00
|
|
|
encoder_wrapper_destroy
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT get_unix_encoder(const CLSID *encoder_clsid, struct encoder_info *info, struct encoder **result)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
struct encoder_wrapper *wrapper;
|
|
|
|
struct encoder *unix_encoder;
|
|
|
|
|
|
|
|
init_unixlib();
|
|
|
|
|
|
|
|
hr = unix_funcs->encoder_create(encoder_clsid, info, &unix_encoder);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
wrapper = HeapAlloc(GetProcessHeap(), 0, sizeof(*wrapper));
|
|
|
|
|
|
|
|
if (!wrapper)
|
|
|
|
{
|
|
|
|
unix_funcs->encoder_destroy(unix_encoder);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper->win32_encoder.vtable = &encoder_wrapper_vtable;
|
|
|
|
wrapper->unix_encoder = unix_encoder;
|
|
|
|
*result = &wrapper->win32_encoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|