/* audio_recorder.c generated by valac 0.56.19, the Vala compiler
 * generated from audio_recorder.vala, do not modify */

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <signal.h>
#include <glib/gstdio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_AUDIO_RECORDER (dc_audio_recorder_get_type ())
#define DC_AUDIO_RECORDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_AUDIO_RECORDER, DcAudioRecorder))
#define DC_AUDIO_RECORDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_AUDIO_RECORDER, DcAudioRecorderClass))
#define DC_IS_AUDIO_RECORDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_AUDIO_RECORDER))
#define DC_IS_AUDIO_RECORDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_AUDIO_RECORDER))
#define DC_AUDIO_RECORDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_AUDIO_RECORDER, DcAudioRecorderClass))

typedef struct _DcAudioRecorder DcAudioRecorder;
typedef struct _DcAudioRecorderClass DcAudioRecorderClass;
typedef struct _DcAudioRecorderPrivate DcAudioRecorderPrivate;
enum  {
	DC_AUDIO_RECORDER_0_PROPERTY,
	DC_AUDIO_RECORDER_OUTPUT_PATH_PROPERTY,
	DC_AUDIO_RECORDER_NUM_PROPERTIES
};
static GParamSpec* dc_audio_recorder_properties[DC_AUDIO_RECORDER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block31Data Block31Data;
typedef struct _Block32Data Block32Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
enum  {
	DC_AUDIO_RECORDER_COMPLETED_SIGNAL,
	DC_AUDIO_RECORDER_FAILED_SIGNAL,
	DC_AUDIO_RECORDER_NUM_SIGNALS
};
static guint dc_audio_recorder_signals[DC_AUDIO_RECORDER_NUM_SIGNALS] = {0};

struct _DcAudioRecorder {
	GObject parent_instance;
	DcAudioRecorderPrivate * priv;
};

struct _DcAudioRecorderClass {
	GObjectClass parent_class;
};

struct _DcAudioRecorderPrivate {
	gchar* _output_path;
	gboolean prefer_external;
	gboolean tried_gstreamer;
	gboolean tried_ffmpeg;
	gboolean using_ffmpeg;
	GSubprocess* process;
	gboolean stop_requested;
	gboolean timed_out;
	guint stop_timeout;
};

struct _Block31Data {
	int _ref_count_;
	DcAudioRecorder* self;
	GSubprocess* active;
};

struct _Block32Data {
	int _ref_count_;
	DcAudioRecorder* self;
	GSubprocess* child;
};

static gint DcAudioRecorder_private_offset;
static gpointer dc_audio_recorder_parent_class = NULL;

VALA_EXTERN GType dc_audio_recorder_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcAudioRecorder, g_object_unref)
VALA_EXTERN DcAudioRecorder* dc_audio_recorder_new (gboolean prefer_external);
VALA_EXTERN DcAudioRecorder* dc_audio_recorder_construct (GType object_type,
                                              gboolean prefer_external);
VALA_EXTERN void dc_audio_recorder_start (DcAudioRecorder* self,
                              GError** error);
VALA_EXTERN const gchar* dc_audio_recorder_get_output_path (DcAudioRecorder* self);
static void dc_audio_recorder_set_output_path (DcAudioRecorder* self,
                                        const gchar* value);
static gboolean dc_audio_recorder_spawn_next (DcAudioRecorder* self);
static void dc_audio_recorder_discard_output (DcAudioRecorder* self);
VALA_EXTERN void dc_audio_recorder_stop (DcAudioRecorder* self);
static Block31Data* block31_data_ref (Block31Data* _data31_);
static void block31_data_unref (void * _userdata_);
static gboolean __lambda19_ (Block31Data* _data31_);
static gboolean ___lambda19__gsource_func (gpointer self);
VALA_EXTERN gchar* dc_audio_recorder_take_output (DcAudioRecorder* self);
VALA_EXTERN void dc_audio_recorder_cancel (DcAudioRecorder* self);
static void dc_audio_recorder_clear_stop_timeout (DcAudioRecorder* self);
static gchar** dc_audio_recorder_ffmpeg_command (const gchar* output,
                                          gint* result_length1);
static gchar** dc_audio_recorder_gstreamer_command (const gchar* output,
                                             gint* result_length1);
static Block32Data* block32_data_ref (Block32Data* _data32_);
static void block32_data_unref (void * _userdata_);
VALA_EXTERN GSubprocess* dc_subprocess_util_spawnv (GSubprocessLauncher* launcher,
                                        gchar** argv,
                                        gint argv_length1,
                                        GError** error);
static void _____lambda18_ (Block32Data* _data32_,
                     GObject* obj,
                     GAsyncResult* res);
static void dc_audio_recorder_on_process_exit (DcAudioRecorder* self,
                                        GSubprocess* child);
static void ______lambda18__gasync_ready_callback (GObject* source_object,
                                            GAsyncResult* res,
                                            gpointer self);
static gint64 dc_audio_recorder_output_size (DcAudioRecorder* self);
VALA_EXTERN gboolean dc_platform_is_macos (void);
static void dc_audio_recorder_finalize (GObject * obj);
static GType dc_audio_recorder_get_type_once (void);
static void _vala_dc_audio_recorder_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_dc_audio_recorder_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_audio_recorder_get_instance_private (DcAudioRecorder* self)
{
	return G_STRUCT_MEMBER_P (self, DcAudioRecorder_private_offset);
}

DcAudioRecorder*
dc_audio_recorder_construct (GType object_type,
                             gboolean prefer_external)
{
	DcAudioRecorder * self = NULL;
	self = (DcAudioRecorder*) g_object_new (object_type, NULL);
	self->priv->prefer_external = prefer_external;
	return self;
}

DcAudioRecorder*
dc_audio_recorder_new (gboolean prefer_external)
{
	return dc_audio_recorder_construct (DC_TYPE_AUDIO_RECORDER, prefer_external);
}

void
dc_audio_recorder_start (DcAudioRecorder* self,
                         GError** error)
{
	gboolean _tmp0_ = FALSE;
	GSubprocess* _tmp1_;
	GFileIOStream* stream = NULL;
	GFile* _tmp6_ = NULL;
	GFileIOStream* _tmp7_ = NULL;
	GFile* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	GFileIOStream* _tmp11_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->process;
	if (_tmp1_ != NULL) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		_tmp2_ = self->priv->_output_path;
		_tmp3_ = strlen (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ > 0;
	}
	if (_tmp0_) {
		GError* _tmp5_;
		_tmp5_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_BUSY, "An audio recording is already active");
		_inner_error0_ = _tmp5_;
		g_propagate_error (error, _inner_error0_);
		return;
	}
	_tmp8_ = g_file_new_tmp ("parla-voice-XXXXXX.m4a", &_tmp7_, &_inner_error0_);
	_g_object_unref0 (stream);
	stream = _tmp7_;
	_tmp6_ = _tmp8_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (stream);
		return;
	}
	_tmp9_ = g_file_get_path (_tmp6_);
	_tmp10_ = _tmp9_;
	dc_audio_recorder_set_output_path (self, _tmp10_);
	_g_free0 (_tmp10_);
	_tmp11_ = stream;
	g_io_stream_close ((GIOStream*) _tmp11_, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp6_);
		_g_object_unref0 (stream);
		return;
	}
	if (!dc_audio_recorder_spawn_next (self)) {
		GError* _tmp12_;
		dc_audio_recorder_discard_output (self);
		_tmp12_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Install GStreamer or FFmpeg to record voice messages");
		_inner_error0_ = _tmp12_;
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (_tmp6_);
		_g_object_unref0 (stream);
		return;
	}
	_g_object_unref0 (_tmp6_);
	_g_object_unref0 (stream);
}

static Block31Data*
block31_data_ref (Block31Data* _data31_)
{
	g_atomic_int_inc (&_data31_->_ref_count_);
	return _data31_;
}

static void
block31_data_unref (void * _userdata_)
{
	Block31Data* _data31_;
	_data31_ = (Block31Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data31_->_ref_count_)) {
		DcAudioRecorder* self;
		self = _data31_->self;
		_g_object_unref0 (_data31_->active);
		_g_object_unref0 (self);
		g_slice_free (Block31Data, _data31_);
	}
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static gboolean
__lambda19_ (Block31Data* _data31_)
{
	DcAudioRecorder* self;
	GSubprocess* _tmp0_;
	GSubprocess* _tmp1_;
	gboolean result;
	self = _data31_->self;
	self->priv->stop_timeout = (guint) 0;
	_tmp0_ = self->priv->process;
	_tmp1_ = _data31_->active;
	if (_tmp0_ == _tmp1_) {
		GSubprocess* _tmp2_;
		self->priv->timed_out = TRUE;
		_tmp2_ = _data31_->active;
		g_subprocess_force_exit (_tmp2_);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda19__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda19_ (self);
	return result;
}

void
dc_audio_recorder_stop (DcAudioRecorder* self)
{
	Block31Data* _data31_;
	GSubprocess* _tmp0_;
	GSubprocess* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GSubprocess* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_data31_ = g_slice_new0 (Block31Data);
	_data31_->_ref_count_ = 1;
	_data31_->self = g_object_ref (self);
	_tmp0_ = self->priv->process;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data31_->active = _tmp1_;
	_tmp3_ = _data31_->active;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = self->priv->stop_requested;
	}
	if (_tmp2_) {
		block31_data_unref (_data31_);
		_data31_ = NULL;
		return;
	}
	self->priv->stop_requested = TRUE;
	if (self->priv->using_ffmpeg) {
		{
			GOutputStream* input = NULL;
			GSubprocess* _tmp4_;
			GOutputStream* _tmp5_;
			GOutputStream* _tmp6_;
			GOutputStream* _tmp7_;
			_tmp4_ = _data31_->active;
			_tmp5_ = g_subprocess_get_stdin_pipe (_tmp4_);
			_tmp6_ = _g_object_ref0 (_tmp5_);
			input = _tmp6_;
			_tmp7_ = input;
			if (_tmp7_ != NULL) {
				gsize written = 0UL;
				GOutputStream* _tmp8_;
				guint8* _tmp9_;
				gint _tmp9__length1;
				gint _tmp10_ = 0;
				guint8* _tmp11_;
				gint _tmp11__length1;
				gsize _tmp12_ = 0UL;
				GOutputStream* _tmp13_;
				_tmp8_ = input;
				_tmp9_ = string_get_data ("q\n", &_tmp10_);
				_tmp9__length1 = _tmp10_;
				_tmp11_ = _tmp9_;
				_tmp11__length1 = _tmp9__length1;
				g_output_stream_write_all (_tmp8_, _tmp11_, (gsize) _tmp11__length1, &_tmp12_, NULL, &_inner_error0_);
				written = _tmp12_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (input);
					goto __catch0_g_error;
				}
				_tmp13_ = input;
				g_output_stream_close (_tmp13_, NULL, &_inner_error0_);
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (input);
					goto __catch0_g_error;
				}
			}
			_g_object_unref0 (input);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GSubprocess* _tmp14_;
			g_clear_error (&_inner_error0_);
			_tmp14_ = _data31_->active;
			g_subprocess_force_exit (_tmp14_);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			block31_data_unref (_data31_);
			_data31_ = NULL;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	} else {
		GSubprocess* _tmp15_;
		_tmp15_ = _data31_->active;
		g_subprocess_send_signal (_tmp15_, (gint) SIGINT);
	}
	self->priv->stop_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 8, ___lambda19__gsource_func, block31_data_ref (_data31_), block31_data_unref);
	block31_data_unref (_data31_);
	_data31_ = NULL;
}

gchar*
dc_audio_recorder_take_output (DcAudioRecorder* self)
{
	gchar* path = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_output_path;
	_tmp1_ = g_strdup (_tmp0_);
	path = _tmp1_;
	dc_audio_recorder_set_output_path (self, "");
	result = path;
	return result;
}

void
dc_audio_recorder_cancel (DcAudioRecorder* self)
{
	GSubprocess* active = NULL;
	GSubprocess* _tmp0_;
	GSubprocess* _tmp1_;
	GSubprocess* _tmp2_;
	g_return_if_fail (self != NULL);
	dc_audio_recorder_clear_stop_timeout (self);
	_tmp0_ = self->priv->process;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	active = _tmp1_;
	_g_object_unref0 (self->priv->process);
	self->priv->process = NULL;
	_tmp2_ = active;
	if (_tmp2_ != NULL) {
		GSubprocess* _tmp3_;
		_tmp3_ = active;
		g_subprocess_force_exit (_tmp3_);
	}
	dc_audio_recorder_discard_output (self);
	_g_object_unref0 (active);
}

static Block32Data*
block32_data_ref (Block32Data* _data32_)
{
	g_atomic_int_inc (&_data32_->_ref_count_);
	return _data32_;
}

static void
block32_data_unref (void * _userdata_)
{
	Block32Data* _data32_;
	_data32_ = (Block32Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data32_->_ref_count_)) {
		DcAudioRecorder* self;
		self = _data32_->self;
		_g_object_unref0 (_data32_->child);
		_g_object_unref0 (self);
		g_slice_free (Block32Data, _data32_);
	}
}

static void
_____lambda18_ (Block32Data* _data32_,
                GObject* obj,
                GAsyncResult* res)
{
	DcAudioRecorder* self;
	GSubprocess* _tmp1_;
	GError* _inner_error0_ = NULL;
	self = _data32_->self;
	g_return_if_fail (res != NULL);
	{
		GSubprocess* _tmp0_;
		_tmp0_ = _data32_->child;
		g_subprocess_wait_finish (_tmp0_, res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	_tmp1_ = _data32_->child;
	dc_audio_recorder_on_process_exit (self, _tmp1_);
}

static void
______lambda18__gasync_ready_callback (GObject* source_object,
                                       GAsyncResult* res,
                                       gpointer self)
{
	_____lambda18_ (self, source_object, res);
	block32_data_unref (self);
}

static gboolean
dc_audio_recorder_spawn_next (DcAudioRecorder* self)
{
	gboolean* order = NULL;
	gboolean* _tmp0_;
	gint order_length1;
	gint _order_size_;
	gboolean* _tmp1_;
	gint _tmp1__length1;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = g_new0 (gboolean, 2);
	_tmp0_[0] = self->priv->prefer_external;
	_tmp0_[1] = !self->priv->prefer_external;
	order = _tmp0_;
	order_length1 = 2;
	_order_size_ = order_length1;
	_tmp1_ = order;
	_tmp1__length1 = order_length1;
	{
		gboolean* ffmpeg_collection = NULL;
		gint ffmpeg_collection_length1 = 0;
		gint _ffmpeg_collection_size_ = 0;
		gint ffmpeg_it = 0;
		ffmpeg_collection = _tmp1_;
		ffmpeg_collection_length1 = _tmp1__length1;
		for (ffmpeg_it = 0; ffmpeg_it < ffmpeg_collection_length1; ffmpeg_it = ffmpeg_it + 1) {
			gboolean ffmpeg = FALSE;
			ffmpeg = ffmpeg_collection[ffmpeg_it];
			{
				gboolean _tmp2_ = FALSE;
				gchar** _tmp3_ = NULL;
				gint _tmp3__length1 = 0;
				gint __tmp3__size_ = 0;
				gchar** argv = NULL;
				gchar** _tmp10_;
				gint _tmp10__length1;
				gint argv_length1;
				gint _argv_size_;
				gchar** _tmp11_;
				gint _tmp11__length1;
				const gchar* _tmp12_;
				if (ffmpeg) {
					_tmp2_ = self->priv->tried_ffmpeg;
				} else {
					_tmp2_ = self->priv->tried_gstreamer;
				}
				if (_tmp2_) {
					continue;
				}
				if (ffmpeg) {
					self->priv->tried_ffmpeg = TRUE;
				} else {
					self->priv->tried_gstreamer = TRUE;
				}
				if (ffmpeg) {
					const gchar* _tmp4_;
					gint _tmp5_ = 0;
					gchar** _tmp6_;
					_tmp4_ = self->priv->_output_path;
					_tmp6_ = dc_audio_recorder_ffmpeg_command (_tmp4_, &_tmp5_);
					_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
					_tmp3_ = _tmp6_;
					_tmp3__length1 = _tmp5_;
					__tmp3__size_ = _tmp3__length1;
				} else {
					const gchar* _tmp7_;
					gint _tmp8_ = 0;
					gchar** _tmp9_;
					_tmp7_ = self->priv->_output_path;
					_tmp9_ = dc_audio_recorder_gstreamer_command (_tmp7_, &_tmp8_);
					_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
					_tmp3_ = _tmp9_;
					_tmp3__length1 = _tmp8_;
					__tmp3__size_ = _tmp3__length1;
				}
				_tmp10_ = _tmp3_;
				_tmp10__length1 = _tmp3__length1;
				_tmp3_ = NULL;
				_tmp3__length1 = 0;
				argv = _tmp10_;
				argv_length1 = _tmp10__length1;
				_argv_size_ = argv_length1;
				_tmp11_ = argv;
				_tmp11__length1 = argv_length1;
				if (_tmp11_ == NULL) {
					argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
					_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
					continue;
				}
				_tmp12_ = self->priv->_output_path;
				g_unlink (_tmp12_);
				{
					Block32Data* _data32_;
					GSubprocessLauncher* launcher = NULL;
					GSubprocessLauncher* _tmp13_;
					GSubprocessLauncher* _tmp14_;
					gchar** _tmp15_;
					gint _tmp15__length1;
					GSubprocess* _tmp16_;
					GSubprocess* _tmp17_;
					GSubprocess* _tmp18_;
					GSubprocess* _tmp19_;
					_data32_ = g_slice_new0 (Block32Data);
					_data32_->_ref_count_ = 1;
					_data32_->self = g_object_ref (self);
					_tmp13_ = g_subprocess_launcher_new ((G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_SILENCE) | G_SUBPROCESS_FLAGS_STDERR_SILENCE);
					launcher = _tmp13_;
					_tmp14_ = launcher;
					_tmp15_ = argv;
					_tmp15__length1 = argv_length1;
					_tmp16_ = dc_subprocess_util_spawnv (_tmp14_, _tmp15_, (gint) _tmp15__length1, &_inner_error0_);
					_data32_->child = _tmp16_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_object_unref0 (launcher);
						block32_data_unref (_data32_);
						_data32_ = NULL;
						goto __catch0_g_error;
					}
					_tmp17_ = _data32_->child;
					_tmp18_ = _g_object_ref0 (_tmp17_);
					_g_object_unref0 (self->priv->process);
					self->priv->process = _tmp18_;
					self->priv->using_ffmpeg = ffmpeg;
					_tmp19_ = _data32_->child;
					g_subprocess_wait_async (_tmp19_, NULL, ______lambda18__gasync_ready_callback, block32_data_ref (_data32_));
					result = TRUE;
					_g_object_unref0 (launcher);
					block32_data_unref (_data32_);
					_data32_ = NULL;
					argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
					_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
					order = (g_free (order), NULL);
					return result;
				}
				goto __finally0;
				__catch0_g_error:
				{
					GError* e = NULL;
					gchar** _tmp20_;
					gint _tmp20__length1;
					const gchar* _tmp21_;
					GError* _tmp22_;
					const gchar* _tmp23_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp20_ = argv;
					_tmp20__length1 = argv_length1;
					_tmp21_ = _tmp20_[0];
					_tmp22_ = e;
					_tmp23_ = _tmp22_->message;
					g_warning ("audio_recorder.vala:116: audio recording: failed to spawn %s: %s", _tmp21_, _tmp23_);
					_g_error_free0 (e);
				}
				__finally0:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gboolean _tmp24_ = FALSE;
					argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
					_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
					order = (g_free (order), NULL);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp24_;
				}
				argv = (_vala_array_free (argv, argv_length1, (GDestroyNotify) g_free), NULL);
				_tmp3_ = (_vala_array_free (_tmp3_, _tmp3__length1, (GDestroyNotify) g_free), NULL);
			}
		}
	}
	result = FALSE;
	order = (g_free (order), NULL);
	return result;
}

static void
dc_audio_recorder_on_process_exit (DcAudioRecorder* self,
                                   GSubprocess* child)
{
	GSubprocess* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (child != NULL);
	_tmp0_ = self->priv->process;
	if (_tmp0_ != child) {
		return;
	}
	_g_object_unref0 (self->priv->process);
	self->priv->process = NULL;
	dc_audio_recorder_clear_stop_timeout (self);
	if (self->priv->stop_requested) {
		gboolean _tmp1_ = FALSE;
		if (!self->priv->timed_out) {
			_tmp1_ = dc_audio_recorder_output_size (self) > ((gint64) 512);
		} else {
			_tmp1_ = FALSE;
		}
		if (_tmp1_) {
			g_signal_emit (self, dc_audio_recorder_signals[DC_AUDIO_RECORDER_COMPLETED_SIGNAL], 0);
		} else {
			const gchar* _tmp2_ = NULL;
			dc_audio_recorder_discard_output (self);
			if (self->priv->timed_out) {
				_tmp2_ = "Audio recording did not stop cleanly";
			} else {
				_tmp2_ = "The recording was too short or could not be encoded";
			}
			g_signal_emit (self, dc_audio_recorder_signals[DC_AUDIO_RECORDER_FAILED_SIGNAL], 0, _tmp2_);
		}
		return;
	}
	if (dc_audio_recorder_spawn_next (self)) {
		return;
	}
	dc_audio_recorder_discard_output (self);
	g_signal_emit (self, dc_audio_recorder_signals[DC_AUDIO_RECORDER_FAILED_SIGNAL], 0, "Could not access the microphone; check microphone " "permission and the configured media tools");
}

static void
dc_audio_recorder_clear_stop_timeout (DcAudioRecorder* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->stop_timeout == ((guint) 0)) {
		return;
	}
	g_source_remove (self->priv->stop_timeout);
	self->priv->stop_timeout = (guint) 0;
}

static gint64
dc_audio_recorder_output_size (DcAudioRecorder* self)
{
	gint64 _tmp6_ = -1LL;
	GError* _inner_error0_ = NULL;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	{
		GFileInfo* _tmp0_ = NULL;
		const gchar* _tmp1_;
		GFile* _tmp2_;
		GFile* _tmp3_;
		GFileInfo* _tmp4_;
		GFileInfo* _tmp5_;
		_tmp1_ = self->priv->_output_path;
		_tmp2_ = g_file_new_for_path (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = g_file_query_info (_tmp3_, "standard::size", G_FILE_QUERY_INFO_NONE, NULL, &_inner_error0_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_tmp0_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		result = g_file_info_get_size (_tmp0_);
		_g_object_unref0 (_tmp0_);
		return result;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		result = (gint64) 0;
		return result;
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return _tmp6_;
}

static void
dc_audio_recorder_discard_output (DcAudioRecorder* self)
{
	const gchar* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_output_path;
	_tmp1_ = strlen (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		return;
	}
	_tmp3_ = dc_audio_recorder_take_output (self);
	_tmp4_ = _tmp3_;
	g_unlink (_tmp4_);
	_g_free0 (_tmp4_);
}

static gchar**
dc_audio_recorder_gstreamer_command (const gchar* output,
                                     gint* result_length1)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar** _tmp23_;
	gchar** _tmp24_;
	gint _tmp24__length1;
	gchar** result;
	g_return_val_if_fail (output != NULL, NULL);
	_tmp0_ = g_find_program_in_path ("gst-launch-1.0");
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ == NULL;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp3_ = NULL;
		_tmp3__length1 = 0;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		return result;
	}
	_tmp4_ = g_strdup ("gst-launch-1.0");
	_tmp5_ = g_strdup ("-q");
	_tmp6_ = g_strdup ("-e");
	_tmp7_ = g_strdup ("autoaudiosrc");
	_tmp8_ = g_strdup ("!");
	_tmp9_ = g_strdup ("audioconvert");
	_tmp10_ = g_strdup ("!");
	_tmp11_ = g_strdup ("audioresample");
	_tmp12_ = g_strdup ("!");
	_tmp13_ = g_strdup ("audio/x-raw,rate=48000,channels=1");
	_tmp14_ = g_strdup ("!");
	_tmp15_ = g_strdup ("avenc_aac");
	_tmp16_ = g_strdup ("bitrate=64000");
	_tmp17_ = g_strdup ("!");
	_tmp18_ = g_strdup ("mp4mux");
	_tmp19_ = g_strdup ("faststart=true");
	_tmp20_ = g_strdup ("!");
	_tmp21_ = g_strdup ("filesink");
	_tmp22_ = g_strconcat ("location=", output, NULL);
	_tmp23_ = g_new0 (gchar*, 19 + 1);
	_tmp23_[0] = _tmp4_;
	_tmp23_[1] = _tmp5_;
	_tmp23_[2] = _tmp6_;
	_tmp23_[3] = _tmp7_;
	_tmp23_[4] = _tmp8_;
	_tmp23_[5] = _tmp9_;
	_tmp23_[6] = _tmp10_;
	_tmp23_[7] = _tmp11_;
	_tmp23_[8] = _tmp12_;
	_tmp23_[9] = _tmp13_;
	_tmp23_[10] = _tmp14_;
	_tmp23_[11] = _tmp15_;
	_tmp23_[12] = _tmp16_;
	_tmp23_[13] = _tmp17_;
	_tmp23_[14] = _tmp18_;
	_tmp23_[15] = _tmp19_;
	_tmp23_[16] = _tmp20_;
	_tmp23_[17] = _tmp21_;
	_tmp23_[18] = _tmp22_;
	_tmp24_ = _tmp23_;
	_tmp24__length1 = 19;
	if (result_length1) {
		*result_length1 = _tmp24__length1;
	}
	result = _tmp24_;
	return result;
}

static gchar**
dc_audio_recorder_ffmpeg_command (const gchar* output,
                                  gint* result_length1)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gchar* format = NULL;
	gchar* source = NULL;
	gboolean macos = FALSE;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	const gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	gchar** _tmp32_;
	gchar** _tmp33_;
	gint _tmp33__length1;
	gchar** result;
	g_return_val_if_fail (output != NULL, NULL);
	_tmp0_ = g_find_program_in_path ("ffmpeg");
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ == NULL;
	_g_free0 (_tmp1_);
	if (_tmp2_) {
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp3_ = NULL;
		_tmp3__length1 = 0;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		return result;
	}
	macos = dc_platform_is_macos ();
	if (macos) {
		_tmp4_ = "avfoundation";
	} else {
		_tmp4_ = "pulse";
	}
	_tmp5_ = g_strdup (_tmp4_);
	_g_free0 (format);
	format = _tmp5_;
	if (macos) {
		_tmp6_ = ":0";
	} else {
		_tmp6_ = "default";
	}
	_tmp7_ = g_strdup (_tmp6_);
	_g_free0 (source);
	source = _tmp7_;
	_tmp8_ = g_strdup ("ffmpeg");
	_tmp9_ = g_strdup ("-hide_banner");
	_tmp10_ = g_strdup ("-loglevel");
	_tmp11_ = g_strdup ("error");
	_tmp12_ = g_strdup ("-nostats");
	_tmp13_ = g_strdup ("-y");
	_tmp14_ = g_strdup ("-f");
	_tmp15_ = format;
	_tmp16_ = g_strdup (_tmp15_);
	_tmp17_ = g_strdup ("-i");
	_tmp18_ = source;
	_tmp19_ = g_strdup (_tmp18_);
	_tmp20_ = g_strdup ("-vn");
	_tmp21_ = g_strdup ("-ac");
	_tmp22_ = g_strdup ("1");
	_tmp23_ = g_strdup ("-ar");
	_tmp24_ = g_strdup ("48000");
	_tmp25_ = g_strdup ("-c:a");
	_tmp26_ = g_strdup ("aac");
	_tmp27_ = g_strdup ("-b:a");
	_tmp28_ = g_strdup ("64k");
	_tmp29_ = g_strdup ("-movflags");
	_tmp30_ = g_strdup ("+faststart");
	_tmp31_ = g_strdup (output);
	_tmp32_ = g_new0 (gchar*, 22 + 1);
	_tmp32_[0] = _tmp8_;
	_tmp32_[1] = _tmp9_;
	_tmp32_[2] = _tmp10_;
	_tmp32_[3] = _tmp11_;
	_tmp32_[4] = _tmp12_;
	_tmp32_[5] = _tmp13_;
	_tmp32_[6] = _tmp14_;
	_tmp32_[7] = _tmp16_;
	_tmp32_[8] = _tmp17_;
	_tmp32_[9] = _tmp19_;
	_tmp32_[10] = _tmp20_;
	_tmp32_[11] = _tmp21_;
	_tmp32_[12] = _tmp22_;
	_tmp32_[13] = _tmp23_;
	_tmp32_[14] = _tmp24_;
	_tmp32_[15] = _tmp25_;
	_tmp32_[16] = _tmp26_;
	_tmp32_[17] = _tmp27_;
	_tmp32_[18] = _tmp28_;
	_tmp32_[19] = _tmp29_;
	_tmp32_[20] = _tmp30_;
	_tmp32_[21] = _tmp31_;
	_tmp33_ = _tmp32_;
	_tmp33__length1 = 22;
	if (result_length1) {
		*result_length1 = _tmp33__length1;
	}
	result = _tmp33_;
	_g_free0 (source);
	_g_free0 (format);
	return result;
}

const gchar*
dc_audio_recorder_get_output_path (DcAudioRecorder* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_output_path;
	result = _tmp0_;
	return result;
}

static void
dc_audio_recorder_set_output_path (DcAudioRecorder* self,
                                   const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_audio_recorder_get_output_path (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_output_path);
		self->priv->_output_path = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dc_audio_recorder_properties[DC_AUDIO_RECORDER_OUTPUT_PATH_PROPERTY]);
	}
}

static void
dc_audio_recorder_class_init (DcAudioRecorderClass * klass,
                              gpointer klass_data)
{
	dc_audio_recorder_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcAudioRecorder_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_audio_recorder_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_audio_recorder_set_property;
	G_OBJECT_CLASS (klass)->finalize = dc_audio_recorder_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_AUDIO_RECORDER_OUTPUT_PATH_PROPERTY, dc_audio_recorder_properties[DC_AUDIO_RECORDER_OUTPUT_PATH_PROPERTY] = g_param_spec_string ("output-path", "output-path", "output-path", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dc_audio_recorder_signals[DC_AUDIO_RECORDER_COMPLETED_SIGNAL] = g_signal_new ("completed", DC_TYPE_AUDIO_RECORDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	dc_audio_recorder_signals[DC_AUDIO_RECORDER_FAILED_SIGNAL] = g_signal_new ("failed", DC_TYPE_AUDIO_RECORDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
dc_audio_recorder_instance_init (DcAudioRecorder * self,
                                 gpointer klass)
{
	gchar* _tmp0_;
	self->priv = dc_audio_recorder_get_instance_private (self);
	_tmp0_ = g_strdup ("");
	self->priv->_output_path = _tmp0_;
}

static void
dc_audio_recorder_finalize (GObject * obj)
{
	DcAudioRecorder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_AUDIO_RECORDER, DcAudioRecorder);
	_g_free0 (self->priv->_output_path);
	_g_object_unref0 (self->priv->process);
	G_OBJECT_CLASS (dc_audio_recorder_parent_class)->finalize (obj);
}

static GType
dc_audio_recorder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcAudioRecorderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_audio_recorder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcAudioRecorder), 0, (GInstanceInitFunc) dc_audio_recorder_instance_init, NULL };
	GType dc_audio_recorder_type_id;
	dc_audio_recorder_type_id = g_type_register_static (G_TYPE_OBJECT, "DcAudioRecorder", &g_define_type_info, 0);
	DcAudioRecorder_private_offset = g_type_add_instance_private (dc_audio_recorder_type_id, sizeof (DcAudioRecorderPrivate));
	return dc_audio_recorder_type_id;
}

GType
dc_audio_recorder_get_type (void)
{
	static volatile gsize dc_audio_recorder_type_id__once = 0;
	if (g_once_init_enter (&dc_audio_recorder_type_id__once)) {
		GType dc_audio_recorder_type_id;
		dc_audio_recorder_type_id = dc_audio_recorder_get_type_once ();
		g_once_init_leave (&dc_audio_recorder_type_id__once, dc_audio_recorder_type_id);
	}
	return dc_audio_recorder_type_id__once;
}

static void
_vala_dc_audio_recorder_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	DcAudioRecorder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_AUDIO_RECORDER, DcAudioRecorder);
	switch (property_id) {
		case DC_AUDIO_RECORDER_OUTPUT_PATH_PROPERTY:
		g_value_set_string (value, dc_audio_recorder_get_output_path (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_audio_recorder_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	DcAudioRecorder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_AUDIO_RECORDER, DcAudioRecorder);
	switch (property_id) {
		case DC_AUDIO_RECORDER_OUTPUT_PATH_PROPERTY:
		dc_audio_recorder_set_output_path (self, g_value_get_string (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

