Merge branch 'add-stream-object' of github.com:libvips/libvips into add-stream-object
This commit is contained in:
commit
c91cfc4050
|
@ -3,7 +3,7 @@
|
|||
#set -x
|
||||
set -e
|
||||
|
||||
# Glib is build without -fno-omit-frame-pointer. We need
|
||||
# Glib is built without -fno-omit-frame-pointer. We need
|
||||
# to disable the fast unwinder to get full stacktraces.
|
||||
export ASAN_OPTIONS="fast_unwind_on_malloc=0:allocator_may_return_null=1"
|
||||
export UBSAN_OPTIONS="print_stacktrace=1"
|
||||
|
|
|
@ -191,8 +191,11 @@ typedef struct _VipsStreamiClass {
|
|||
*
|
||||
* Unseekable streams should always return -1. VipsStreami will then
|
||||
* seek by _read()ing bytes into memory as required.
|
||||
*
|
||||
* We have to use int64 rather than off_t, since we must work on
|
||||
* Windows, where off_t can be 32-bits.
|
||||
*/
|
||||
gint64 (*seek)( VipsStreami *, gint64 offset, int );
|
||||
gint64 (*seek)( VipsStreami *, gint64, int );
|
||||
|
||||
} VipsStreamiClass;
|
||||
|
||||
|
@ -217,6 +220,44 @@ size_t vips_streami_sniff_at_most( VipsStreami *streami,
|
|||
unsigned char *vips_streami_sniff( VipsStreami *streami, size_t length );
|
||||
gint64 vips_streami_size( VipsStreami *streami );
|
||||
|
||||
#define VIPS_TYPE_STREAMIU (vips_streamiu_get_type())
|
||||
#define VIPS_STREAMIU( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
VIPS_TYPE_STREAMIU, VipsStreamiu ))
|
||||
#define VIPS_STREAMIU_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_CAST( (klass), \
|
||||
VIPS_TYPE_STREAMIU, VipsStreamiuClass))
|
||||
#define VIPS_IS_STREAMIU( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMIU ))
|
||||
#define VIPS_IS_STREAMIU_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMIU ))
|
||||
#define VIPS_STREAMIU_GET_CLASS( obj ) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
||||
VIPS_TYPE_STREAMIU, VipsStreamiuClass ))
|
||||
|
||||
/* Subclass of streamiu with signals for handlers. This is supposed to be
|
||||
* useful for language bindings.
|
||||
*/
|
||||
typedef struct _VipsStreamiu {
|
||||
VipsStreami parent_object;
|
||||
|
||||
} VipsStreamiu;
|
||||
|
||||
typedef struct _VipsStreamiuClass {
|
||||
VipsStreamiClass parent_class;
|
||||
|
||||
/* The action signals clients can use to implement read and seek.
|
||||
* We must use gint64 everywhere since there's no G_TYPE_SIZE.
|
||||
*/
|
||||
|
||||
gint64 (*read)( VipsStreamiu *, void *, gint64 );
|
||||
gint64 (*seek)( VipsStreamiu *, gint64, int );
|
||||
|
||||
} VipsStreamiuClass;
|
||||
|
||||
GType vips_streamiu_get_type( void );
|
||||
VipsStreamiu *vips_streamiu_new( void );
|
||||
|
||||
#define VIPS_TYPE_STREAMO (vips_streamo_get_type())
|
||||
#define VIPS_STREAMO( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
|
@ -232,7 +273,9 @@ gint64 vips_streami_size( VipsStreami *streami );
|
|||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
||||
VIPS_TYPE_STREAMO, VipsStreamoClass ))
|
||||
|
||||
#define VIPS_STREAMO_BUFFER_SIZE (4096)
|
||||
/* PNG writes in 8kb chunks, so we need to be a little larger than that.
|
||||
*/
|
||||
#define VIPS_STREAMO_BUFFER_SIZE (8500)
|
||||
|
||||
/* Output to something like a socket, pipe or memory area.
|
||||
*/
|
||||
|
@ -241,13 +284,17 @@ typedef struct _VipsStreamo {
|
|||
|
||||
/*< private >*/
|
||||
|
||||
/* This stream should write to memory.
|
||||
*/
|
||||
gboolean memory;
|
||||
|
||||
/* The stream has been finished and can no longer be written.
|
||||
*/
|
||||
gboolean finished;
|
||||
|
||||
/* Write memory output here.
|
||||
*/
|
||||
GByteArray *memory;
|
||||
GByteArray *memory_buffer;
|
||||
|
||||
/* And return memory via this blob.
|
||||
*/
|
||||
|
@ -296,6 +343,45 @@ int vips_streamo_writef( VipsStreamo *streamo, const char *fmt, ... )
|
|||
__attribute__((format(printf, 2, 3)));
|
||||
int vips_streamo_write_amp( VipsStreamo *streamo, const char *str );
|
||||
|
||||
#define VIPS_TYPE_STREAMOU (vips_streamou_get_type())
|
||||
#define VIPS_STREAMOU( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
|
||||
VIPS_TYPE_STREAMOU, VipsStreamou ))
|
||||
#define VIPS_STREAMOU_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_CAST( (klass), \
|
||||
VIPS_TYPE_STREAMOU, VipsStreamouClass))
|
||||
#define VIPS_IS_STREAMOU( obj ) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_STREAMOU ))
|
||||
#define VIPS_IS_STREAMOU_CLASS( klass ) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_STREAMOU ))
|
||||
#define VIPS_STREAMOU_GET_CLASS( obj ) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
|
||||
VIPS_TYPE_STREAMOU, VipsStreamouClass ))
|
||||
|
||||
#define VIPS_STREAMOU_BUFFER_SIZE (4096)
|
||||
|
||||
/* Output to something like a socket, pipe or memory area.
|
||||
*/
|
||||
typedef struct _VipsStreamou {
|
||||
VipsStreamo parent_object;
|
||||
|
||||
} VipsStreamou;
|
||||
|
||||
typedef struct _VipsStreamouClass {
|
||||
VipsStreamoClass parent_class;
|
||||
|
||||
/* The action signals clients can use to implement write and finish.
|
||||
* We must use gint64 everywhere since there's no G_TYPE_SIZE.
|
||||
*/
|
||||
|
||||
gint64 (*write)( VipsStreamou *, const void *, gint64 );
|
||||
void (*finish)( VipsStreamou * );
|
||||
|
||||
} VipsStreamouClass;
|
||||
|
||||
GType vips_streamou_get_type( void );
|
||||
VipsStreamou *vips_streamou_new( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
|
|
@ -3,7 +3,9 @@ noinst_LTLIBRARIES = libiofuncs.la
|
|||
libiofuncs_la_SOURCES = \
|
||||
stream.c \
|
||||
streami.c \
|
||||
streamiu.c \
|
||||
streamo.c \
|
||||
streamou.c \
|
||||
bufis.c \
|
||||
dbuf.c \
|
||||
reorder.c \
|
||||
|
@ -40,9 +42,9 @@ libiofuncs_la_SOURCES = \
|
|||
system.c \
|
||||
buffer.c
|
||||
|
||||
vipsmarshal.h:
|
||||
vipsmarshal.h: vipsmarshal.list
|
||||
glib-genmarshal --prefix=vips --header vipsmarshal.list > vipsmarshal.h
|
||||
vipsmarshal.c:
|
||||
vipsmarshal.c: vipsmarshal.list
|
||||
echo "#include \"vipsmarshal.h\"" > vipsmarshal.c
|
||||
glib-genmarshal --prefix=vips --body vipsmarshal.list >> vipsmarshal.c
|
||||
|
||||
|
|
|
@ -331,7 +331,9 @@ vips_init( const char *argv0 )
|
|||
extern GType sink_memory_thread_state_get_type( void );
|
||||
extern GType render_thread_state_get_type( void );
|
||||
extern GType vips_streami_get_type( void );
|
||||
extern GType vips_streamiu_get_type( void );
|
||||
extern GType vips_streamo_get_type( void );
|
||||
extern GType vips_streamou_get_type( void );
|
||||
|
||||
static gboolean started = FALSE;
|
||||
static gboolean done = FALSE;
|
||||
|
@ -447,7 +449,9 @@ vips_init( const char *argv0 )
|
|||
(void) sink_memory_thread_state_get_type();
|
||||
(void) render_thread_state_get_type();
|
||||
(void) vips_streami_get_type();
|
||||
(void) vips_streamiu_get_type();
|
||||
(void) vips_streamo_get_type();
|
||||
(void) vips_streamou_get_type();
|
||||
vips__meta_init_types();
|
||||
vips__interpolate_init();
|
||||
im__format_init();
|
||||
|
|
|
@ -33,10 +33,7 @@
|
|||
|
||||
/* TODO
|
||||
*
|
||||
* - gaussblur is missing the vector path again argh
|
||||
* - can we map and then close the fd? how about on Windows?
|
||||
* - make a subclass that lets you set vfuncs as params, inc. close(),
|
||||
* is_pipe etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -280,7 +277,6 @@ vips_streami_read_real( VipsStreami *streami, void *data, size_t length )
|
|||
} while( bytes_read < 0 && errno == EINTR );
|
||||
|
||||
return( bytes_read );
|
||||
|
||||
}
|
||||
|
||||
static gint64
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
/* A Streami subclass with signals you can easily hook up to other input
|
||||
* sources.
|
||||
*
|
||||
* J.Cupitt, 21/11/19
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS 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 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
#define VIPS_DEBUG
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /*HAVE_UNISTD_H*/
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
#include <vips/debug.h>
|
||||
|
||||
#include "vipsmarshal.h"
|
||||
|
||||
G_DEFINE_TYPE( VipsStreamiu, vips_streamiu, VIPS_TYPE_STREAMI );
|
||||
|
||||
/* Our signals.
|
||||
*/
|
||||
enum {
|
||||
SIG_SEEK,
|
||||
SIG_READ,
|
||||
SIG_LAST
|
||||
};
|
||||
|
||||
static guint vips_streamiu_signals[SIG_LAST] = { 0 };
|
||||
|
||||
static ssize_t
|
||||
vips_streamiu_read_real( VipsStreami *streami,
|
||||
void *buffer, size_t length )
|
||||
{
|
||||
gint64 bytes_read;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiu_read_real:\n" );
|
||||
|
||||
/* Return value if no attached handler.
|
||||
*/
|
||||
bytes_read = 0;
|
||||
|
||||
g_signal_emit( streami, vips_streamiu_signals[SIG_READ], 0,
|
||||
buffer, length, &bytes_read );
|
||||
|
||||
VIPS_DEBUG_MSG( " %zd\n", bytes_read );
|
||||
|
||||
return( bytes_read );
|
||||
}
|
||||
|
||||
static gint64
|
||||
vips_streamiu_seek_real( VipsStreami *streami,
|
||||
gint64 offset, int whence )
|
||||
{
|
||||
gint64 new_position;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiu_seek_real:\n" );
|
||||
|
||||
/* If there's no user action attached, we fail.
|
||||
*/
|
||||
new_position = -1;
|
||||
|
||||
g_signal_emit( streami, vips_streamiu_signals[SIG_SEEK], 0,
|
||||
offset, whence, &new_position );
|
||||
|
||||
VIPS_DEBUG_MSG( " %zd\n", new_position );
|
||||
|
||||
return( new_position );
|
||||
}
|
||||
|
||||
static gint64
|
||||
vips_streamiu_read_signal_real( VipsStreamiu *streamiu,
|
||||
void *data, gint64 length )
|
||||
{
|
||||
VIPS_DEBUG_MSG( "vips_streamiu_read_signal_real:\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static gint64
|
||||
vips_streamiu_seek_signal_real( VipsStreamiu *streamiu,
|
||||
gint64 offset, int whence )
|
||||
{
|
||||
VIPS_DEBUG_MSG( "vips_streamiu_seek_signal_real:\n" );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiu_class_init( VipsStreamiuClass *class )
|
||||
{
|
||||
VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class );
|
||||
VipsStreamiClass *streami_class = VIPS_STREAMI_CLASS( class );
|
||||
|
||||
object_class->nickname = "streamiu";
|
||||
object_class->description = _( "input stream" );
|
||||
|
||||
streami_class->read = vips_streamiu_read_real;
|
||||
streami_class->seek = vips_streamiu_seek_real;
|
||||
|
||||
class->read = vips_streamiu_read_signal_real;
|
||||
class->seek = vips_streamiu_seek_signal_real;
|
||||
|
||||
/**
|
||||
* VipsStreamiu::read:
|
||||
* @streamiu: the stream being operated on
|
||||
* @buffer: %gpointer, buffer to fill
|
||||
* @size: %gint64, size of buffer
|
||||
*
|
||||
* This signal is emitted to read bytes from the source into @buffer.
|
||||
*
|
||||
* Returns: the number of bytes read.
|
||||
*/
|
||||
vips_streamiu_signals[SIG_READ] = g_signal_new( "read",
|
||||
G_TYPE_FROM_CLASS( class ),
|
||||
G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET( VipsStreamiuClass, read ),
|
||||
NULL, NULL,
|
||||
vips_INT64__INT64_INT,
|
||||
G_TYPE_INT64, 2,
|
||||
G_TYPE_INT64, G_TYPE_INT );
|
||||
|
||||
/**
|
||||
* VipsStreamiu::seek:
|
||||
* @streamiu: the stream being operated on
|
||||
* @offset: %gint64, seek offset
|
||||
* @whence: %gint, seek origin
|
||||
*
|
||||
* This signal is emitted to seek the stream. The handler should
|
||||
* change the stream position appropriately.
|
||||
*
|
||||
* The handler on an unseekable stream should always return -1.
|
||||
*
|
||||
* Returns: the new seek position.
|
||||
*/
|
||||
vips_streamiu_signals[SIG_SEEK] = g_signal_new( "seek",
|
||||
G_TYPE_FROM_CLASS( class ),
|
||||
G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET( VipsStreamiuClass, seek ),
|
||||
NULL, NULL,
|
||||
vips_INT64__POINTER_INT64,
|
||||
G_TYPE_INT64, 2,
|
||||
G_TYPE_POINTER, G_TYPE_INT64 );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamiu_init( VipsStreamiu *streamiu )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_streamiu_new:
|
||||
*
|
||||
* Create a #VipsStreamiu. Attach signals to implement read and seek.
|
||||
*
|
||||
* Returns: a new #VipsStreamiu
|
||||
*/
|
||||
VipsStreamiu *
|
||||
vips_streamiu_new( void )
|
||||
{
|
||||
VipsStreamiu *streamiu;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamiu_new:\n" );
|
||||
|
||||
streamiu = VIPS_STREAMIU( g_object_new( VIPS_TYPE_STREAMIU, NULL ) );
|
||||
|
||||
if( vips_object_build( VIPS_OBJECT( streamiu ) ) ) {
|
||||
VIPS_UNREF( streamiu );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( streamiu );
|
||||
}
|
|
@ -31,12 +31,6 @@
|
|||
|
||||
*/
|
||||
|
||||
/* TODO
|
||||
*
|
||||
* - test we can really change all behaviour in the subclass ... add callbacks
|
||||
* as well to make it simpler for language bindings
|
||||
*/
|
||||
|
||||
/*
|
||||
#define VIPS_DEBUG
|
||||
*/
|
||||
|
@ -93,7 +87,7 @@ vips_streamo_finalize( GObject *gobject )
|
|||
|
||||
VIPS_DEBUG_MSG( "vips_streamo_finalize:\n" );
|
||||
|
||||
VIPS_FREEF( g_byte_array_unref, streamo->memory );
|
||||
VIPS_FREEF( g_byte_array_unref, streamo->memory_buffer );
|
||||
if( streamo->blob ) {
|
||||
vips_area_unref( VIPS_AREA( streamo->blob ) );
|
||||
streamo->blob = NULL;
|
||||
|
@ -120,7 +114,7 @@ vips_streamo_build( VipsObject *object )
|
|||
return( -1 );
|
||||
}
|
||||
|
||||
if( vips_object_argument_isset( object, "filename" ) ) {
|
||||
if( stream->filename ) {
|
||||
const char *filename = stream->filename;
|
||||
|
||||
int fd;
|
||||
|
@ -141,8 +135,8 @@ vips_streamo_build( VipsObject *object )
|
|||
stream->descriptor = dup( stream->descriptor );
|
||||
stream->close_descriptor = stream->descriptor;
|
||||
}
|
||||
else {
|
||||
streamo->memory = g_byte_array_new();
|
||||
else if( streamo->memory ) {
|
||||
streamo->memory_buffer = g_byte_array_new();
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
|
@ -182,10 +176,17 @@ vips_streamo_class_init( VipsStreamoClass *class )
|
|||
class->write = vips_streamo_write_real;
|
||||
class->finish = vips_streamo_finish_real;
|
||||
|
||||
VIPS_ARG_BOOL( class, "memory", 3,
|
||||
_( "Memory" ),
|
||||
_( "File descriptor should output to memory" ),
|
||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||
G_STRUCT_OFFSET( VipsStreamo, memory ),
|
||||
FALSE );
|
||||
|
||||
/* SET_ALWAYS means that blob is set by C and the obj system is not
|
||||
* involved in creation or destruction. It can be read at any time.
|
||||
*/
|
||||
VIPS_ARG_BOXED( class, "blob", 3,
|
||||
VIPS_ARG_BOXED( class, "blob", 4,
|
||||
_( "Blob" ),
|
||||
_( "Blob to save to" ),
|
||||
VIPS_ARGUMENT_SET_ALWAYS,
|
||||
|
@ -277,7 +278,9 @@ vips_streamo_new_to_memory( void )
|
|||
|
||||
VIPS_DEBUG_MSG( "vips_streamo_new_to_memory:\n" );
|
||||
|
||||
streamo = VIPS_STREAMO( g_object_new( VIPS_TYPE_STREAMO, NULL ) );
|
||||
streamo = VIPS_STREAMO( g_object_new( VIPS_TYPE_STREAMO,
|
||||
"memory", TRUE,
|
||||
NULL ) );
|
||||
|
||||
if( vips_object_build( VIPS_OBJECT( streamo ) ) ) {
|
||||
VIPS_UNREF( streamo );
|
||||
|
@ -293,11 +296,13 @@ vips_streamo_write_unbuffered( VipsStreamo *streamo,
|
|||
{
|
||||
VipsStreamoClass *class = VIPS_STREAMO_GET_CLASS( streamo );
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamo_write_unbuffered:\n" );
|
||||
|
||||
if( streamo->finished )
|
||||
return( 0 );
|
||||
|
||||
if( streamo->memory )
|
||||
g_byte_array_append( streamo->memory, data, length );
|
||||
if( streamo->memory_buffer )
|
||||
g_byte_array_append( streamo->memory_buffer, data, length );
|
||||
else
|
||||
while( length > 0 ) {
|
||||
ssize_t n;
|
||||
|
@ -328,6 +333,8 @@ vips_streamo_flush( VipsStreamo *streamo )
|
|||
g_assert( streamo->write_point >= 0 );
|
||||
g_assert( streamo->write_point <= VIPS_STREAMO_BUFFER_SIZE );
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamo_flush:\n" );
|
||||
|
||||
if( streamo->write_point > 0 ) {
|
||||
if( vips_streamo_write_unbuffered( streamo,
|
||||
streamo->output_buffer, streamo->write_point ) )
|
||||
|
@ -397,13 +404,13 @@ vips_streamo_finish( VipsStreamo *streamo )
|
|||
|
||||
/* Move the stream buffer into the blob so it can be read out.
|
||||
*/
|
||||
if( streamo->memory ) {
|
||||
if( streamo->memory_buffer ) {
|
||||
unsigned char *data;
|
||||
size_t length;
|
||||
|
||||
length = streamo->memory->len;
|
||||
data = g_byte_array_free( streamo->memory, FALSE );
|
||||
streamo->memory = NULL;
|
||||
length = streamo->memory_buffer->len;
|
||||
data = g_byte_array_free( streamo->memory_buffer, FALSE );
|
||||
streamo->memory_buffer = NULL;
|
||||
vips_blob_set( streamo->blob,
|
||||
(VipsCallbackFn) g_free, data, length );
|
||||
}
|
||||
|
@ -436,22 +443,22 @@ vips_streamo_steal( VipsStreamo *streamo, size_t *length )
|
|||
|
||||
(void) vips_streamo_flush( streamo );
|
||||
|
||||
if( !streamo->memory ||
|
||||
if( !streamo->memory_buffer ||
|
||||
streamo->finished ) {
|
||||
if( length )
|
||||
*length = streamo->memory->len;
|
||||
*length = streamo->memory_buffer->len;
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
if( length )
|
||||
*length = streamo->memory->len;
|
||||
data = g_byte_array_free( streamo->memory, FALSE );
|
||||
streamo->memory = NULL;
|
||||
*length = streamo->memory_buffer->len;
|
||||
data = g_byte_array_free( streamo->memory_buffer, FALSE );
|
||||
streamo->memory_buffer = NULL;
|
||||
|
||||
/* We must have a valid byte array or finish will fail.
|
||||
*/
|
||||
streamo->memory = g_byte_array_new();
|
||||
streamo->memory_buffer = g_byte_array_new();
|
||||
|
||||
vips_streamo_finish( streamo );
|
||||
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
/* A Streamo subclass with signals you can easily hook up to other output
|
||||
* sources.
|
||||
*
|
||||
* J.Cupitt, 21/11/19
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS 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 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
#define VIPS_DEBUG
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /*HAVE_UNISTD_H*/
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
#include <vips/debug.h>
|
||||
|
||||
#include "vipsmarshal.h"
|
||||
|
||||
G_DEFINE_TYPE( VipsStreamou, vips_streamou, VIPS_TYPE_STREAMO );
|
||||
|
||||
/* Our signals.
|
||||
*/
|
||||
enum {
|
||||
SIG_WRITE,
|
||||
SIG_FINISH,
|
||||
SIG_LAST
|
||||
};
|
||||
|
||||
static guint vips_streamou_signals[SIG_LAST] = { 0 };
|
||||
|
||||
static ssize_t
|
||||
vips_streamou_write_real( VipsStreamo *streamo,
|
||||
const void *data, size_t length )
|
||||
{
|
||||
gint64 bytes_written;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamou_write_real:\n" );
|
||||
|
||||
/* Return value if no attached handler.
|
||||
*/
|
||||
bytes_written = 0;
|
||||
|
||||
g_signal_emit( streamo, vips_streamou_signals[SIG_WRITE], 0,
|
||||
data, length, &bytes_written );
|
||||
|
||||
VIPS_DEBUG_MSG( " %zd\n", bytes_written );
|
||||
|
||||
return( bytes_written );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamou_finish_real( VipsStreamo *streamo )
|
||||
{
|
||||
VIPS_DEBUG_MSG( "vips_streamou_seek_real:\n" );
|
||||
|
||||
g_signal_emit( streamo, vips_streamou_signals[SIG_FINISH], 0 );
|
||||
}
|
||||
|
||||
static gint64
|
||||
vips_streamou_write_signal_real( VipsStreamou *streamou,
|
||||
const void *data, gint64 length )
|
||||
{
|
||||
VIPS_DEBUG_MSG( "vips_streamou_write_signal_real:\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamou_finish_signal_real( VipsStreamou *streamou )
|
||||
{
|
||||
VIPS_DEBUG_MSG( "vips_streamou_finish_signal_real:\n" );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamou_class_init( VipsStreamouClass *class )
|
||||
{
|
||||
VipsObjectClass *object_class = VIPS_OBJECT_CLASS( class );
|
||||
VipsStreamoClass *streamo_class = VIPS_STREAMO_CLASS( class );
|
||||
|
||||
object_class->nickname = "streamou";
|
||||
object_class->description = _( "input stream" );
|
||||
|
||||
streamo_class->write = vips_streamou_write_real;
|
||||
streamo_class->finish = vips_streamou_finish_real;
|
||||
|
||||
class->write = vips_streamou_write_signal_real;
|
||||
class->finish = vips_streamou_finish_signal_real;
|
||||
|
||||
/**
|
||||
* VipsStreamou::write:
|
||||
* @streamou: the stream being operated on
|
||||
* @data: %pointer, bytes to write
|
||||
* @length: %gint64, number of bytes
|
||||
*
|
||||
* This signal is emitted to write bytes to the stream.
|
||||
*
|
||||
* Returns: the number of bytes written.
|
||||
*/
|
||||
vips_streamou_signals[SIG_WRITE] = g_signal_new( "write",
|
||||
G_TYPE_FROM_CLASS( class ),
|
||||
G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET( VipsStreamouClass, write ),
|
||||
NULL, NULL,
|
||||
vips_INT64__POINTER_INT64,
|
||||
G_TYPE_INT64, 2,
|
||||
G_TYPE_POINTER, G_TYPE_INT64 );
|
||||
|
||||
/**
|
||||
* VipsStreamou::finish:
|
||||
* @streamou: the stream being operated on
|
||||
*
|
||||
* This signal is emitted at the end of write. The stream should do
|
||||
* any finishing necessary.
|
||||
*/
|
||||
vips_streamou_signals[SIG_FINISH] = g_signal_new( "finish",
|
||||
G_TYPE_FROM_CLASS( class ),
|
||||
G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET( VipsStreamouClass, finish ),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0 );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_streamou_init( VipsStreamou *streamou )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_streamou_new:
|
||||
*
|
||||
* Create a #VipsStreamou. Attach signals to implement write and finish.
|
||||
*
|
||||
* Returns: a new #VipsStreamou
|
||||
*/
|
||||
VipsStreamou *
|
||||
vips_streamou_new( void )
|
||||
{
|
||||
VipsStreamou *streamou;
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_streamou_new:\n" );
|
||||
|
||||
streamou = VIPS_STREAMOU( g_object_new( VIPS_TYPE_STREAMOU, NULL ) );
|
||||
|
||||
if( vips_object_build( VIPS_OBJECT( streamou ) ) ) {
|
||||
VIPS_UNREF( streamou );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( streamou );
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#include "vipsmarshal.h"
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
|
||||
#include <glib-object.h>
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
|
||||
|
@ -49,21 +48,20 @@
|
|||
#define g_marshal_value_peek_variant(v) (v)->data[0].v_pointer
|
||||
#endif /* !G_ENABLE_DEBUG */
|
||||
|
||||
|
||||
/* INT:VOID (vipsmarshal.list:25) */
|
||||
/* INT: VOID (vipsmarshal.list:25) */
|
||||
void
|
||||
vips_INT__VOID (GClosure *closure,
|
||||
GValue *return_value G_GNUC_UNUSED,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint G_GNUC_UNUSED,
|
||||
gpointer marshal_data)
|
||||
{
|
||||
typedef gint (*GMarshalFunc_INT__VOID) (gpointer data1,
|
||||
gpointer data2);
|
||||
register GMarshalFunc_INT__VOID callback;
|
||||
register GCClosure *cc = (GCClosure*) closure;
|
||||
register gpointer data1, data2;
|
||||
typedef gint (*GMarshalFunc_INT__VOID) (gpointer data1,
|
||||
gpointer data2);
|
||||
GCClosure *cc = (GCClosure *) closure;
|
||||
gpointer data1, data2;
|
||||
GMarshalFunc_INT__VOID callback;
|
||||
gint v_return;
|
||||
|
||||
g_return_if_fail (return_value != NULL);
|
||||
|
@ -87,3 +85,85 @@ vips_INT__VOID (GClosure *closure,
|
|||
g_value_set_int (return_value, v_return);
|
||||
}
|
||||
|
||||
/* INT64: INT64, INT (vipsmarshal.list:26) */
|
||||
void
|
||||
vips_INT64__INT64_INT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint G_GNUC_UNUSED,
|
||||
gpointer marshal_data)
|
||||
{
|
||||
typedef gint64 (*GMarshalFunc_INT64__INT64_INT) (gpointer data1,
|
||||
gint64 arg1,
|
||||
gint arg2,
|
||||
gpointer data2);
|
||||
GCClosure *cc = (GCClosure *) closure;
|
||||
gpointer data1, data2;
|
||||
GMarshalFunc_INT64__INT64_INT callback;
|
||||
gint64 v_return;
|
||||
|
||||
g_return_if_fail (return_value != NULL);
|
||||
g_return_if_fail (n_param_values == 3);
|
||||
|
||||
if (G_CCLOSURE_SWAP_DATA (closure))
|
||||
{
|
||||
data1 = closure->data;
|
||||
data2 = g_value_peek_pointer (param_values + 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
data1 = g_value_peek_pointer (param_values + 0);
|
||||
data2 = closure->data;
|
||||
}
|
||||
callback = (GMarshalFunc_INT64__INT64_INT) (marshal_data ? marshal_data : cc->callback);
|
||||
|
||||
v_return = callback (data1,
|
||||
g_marshal_value_peek_int64 (param_values + 1),
|
||||
g_marshal_value_peek_int (param_values + 2),
|
||||
data2);
|
||||
|
||||
g_value_set_int64 (return_value, v_return);
|
||||
}
|
||||
|
||||
/* INT64: POINTER, INT64 (vipsmarshal.list:27) */
|
||||
void
|
||||
vips_INT64__POINTER_INT64 (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint G_GNUC_UNUSED,
|
||||
gpointer marshal_data)
|
||||
{
|
||||
typedef gint64 (*GMarshalFunc_INT64__POINTER_INT64) (gpointer data1,
|
||||
gpointer arg1,
|
||||
gint64 arg2,
|
||||
gpointer data2);
|
||||
GCClosure *cc = (GCClosure *) closure;
|
||||
gpointer data1, data2;
|
||||
GMarshalFunc_INT64__POINTER_INT64 callback;
|
||||
gint64 v_return;
|
||||
|
||||
g_return_if_fail (return_value != NULL);
|
||||
g_return_if_fail (n_param_values == 3);
|
||||
|
||||
if (G_CCLOSURE_SWAP_DATA (closure))
|
||||
{
|
||||
data1 = closure->data;
|
||||
data2 = g_value_peek_pointer (param_values + 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
data1 = g_value_peek_pointer (param_values + 0);
|
||||
data2 = closure->data;
|
||||
}
|
||||
callback = (GMarshalFunc_INT64__POINTER_INT64) (marshal_data ? marshal_data : cc->callback);
|
||||
|
||||
v_return = callback (data1,
|
||||
g_marshal_value_peek_pointer (param_values + 1),
|
||||
g_marshal_value_peek_int64 (param_values + 2),
|
||||
data2);
|
||||
|
||||
g_value_set_int64 (return_value, v_return);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,39 @@
|
|||
/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
|
||||
#ifndef __VIPS_MARSHAL_H__
|
||||
#define __VIPS_MARSHAL_H__
|
||||
|
||||
#ifndef __vips_MARSHAL_H__
|
||||
#define __vips_MARSHAL_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* INT:VOID (vipsmarshal.list:25) */
|
||||
extern void vips_INT__VOID (GClosure *closure,
|
||||
/* INT: VOID (vipsmarshal.list:25) */
|
||||
extern
|
||||
void vips_INT__VOID (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* INT64: INT64, INT (vipsmarshal.list:26) */
|
||||
extern
|
||||
void vips_INT64__INT64_INT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* INT64: POINTER, INT64 (vipsmarshal.list:27) */
|
||||
extern
|
||||
void vips_INT64__POINTER_INT64 (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __vips_MARSHAL_H__ */
|
||||
|
||||
#endif /* __VIPS_MARSHAL_H__ */
|
||||
|
|
|
@ -23,5 +23,5 @@
|
|||
# BOOL deprecated alias for BOOLEAN
|
||||
|
||||
INT: VOID
|
||||
|
||||
|
||||
INT64: INT64, INT
|
||||
INT64: POINTER, INT64
|
||||
|
|
Loading…
Reference in New Issue