47 #include <jack/jack.h>
48 #include <jack/ringbuffer.h>
50 #include <libresample.h>
61 #define RESAMPLE_QUALITY 1
64 #define RINGBUFFER_FRAME_CAPACITY 100
67 #define COMMON_OPTIONS \
68 " s(<name>) - Connect to the specified jack server name.\n" \
69 " i(<name>) - Connect the output port that gets created to the specified\n" \
70 " jack input port.\n" \
71 " o(<name>) - Connect the input port that gets created to the specified\n" \
72 " jack output port.\n" \
73 " n - Do not automatically start the JACK server if it is not already\n" \
75 " c(<name>) - By default, Asterisk will use the channel name for the jack client\n" \
76 " name. Use this option to specify a custom client name.\n"
117 static const char jack_app[] =
"JACK";
126 jack_client_t *client;
127 jack_port_t *input_port;
128 jack_port_t *output_port;
129 jack_ringbuffer_t *input_rb;
130 jack_ringbuffer_t *output_rb;
132 unsigned int audiohook_rate;
133 unsigned int frame_datalen;
134 void *output_resampler;
135 double output_resample_factor;
136 void *input_resampler;
137 double input_resample_factor;
139 unsigned int has_audiohook:1;
140 unsigned int no_start_server:1;
145 static const struct {
148 } jack_status_table[] = {
149 { JackFailure,
"Failure" },
150 { JackInvalidOption,
"Invalid Option" },
151 { JackNameNotUnique,
"Name Not Unique" },
152 { JackServerStarted,
"Server Started" },
153 { JackServerFailed,
"Server Failed" },
154 { JackServerError,
"Server Error" },
155 { JackNoSuchClient,
"No Such Client" },
156 { JackLoadFailure,
"Load Failure" },
157 { JackInitFailure,
"Init Failure" },
158 { JackShmFailure,
"Shared Memory Access Failure" },
159 { JackVersionError,
"Version Mismatch" },
162 static const char *jack_status_to_str(jack_status_t status)
166 for (i = 0; i < ARRAY_LEN(jack_status_table); i++) {
167 if (jack_status_table[i].status == status)
168 return jack_status_table[i].str;
171 return "Unknown Error";
174 static void log_jack_status(
const char *prefix, jack_status_t status)
176 struct ast_str *str = ast_str_alloca(512);
179 for (i = 0; i < (
sizeof(status) * 8); i++) {
180 if (!(status & (1 << i)))
184 ast_str_set(&str, 0,
"%s", jack_status_to_str((1 << i)));
195 double from_srate, to_srate, jack_srate;
197 double *resample_factor;
199 if (input && jack_data->input_resampler)
202 if (!input && jack_data->output_resampler)
205 jack_srate = jack_get_sample_rate(jack_data->client);
207 to_srate = input ? jack_data->audiohook_rate : jack_srate;
208 from_srate = input ? jack_srate : jack_data->audiohook_rate;
210 resample_factor = input ? &jack_data->input_resample_factor :
211 &jack_data->output_resample_factor;
213 if (from_srate == to_srate) {
216 *resample_factor = 1.0;
220 *resample_factor = to_srate / from_srate;
222 resampler = input ? &jack_data->input_resampler :
223 &jack_data->output_resampler;
225 if (!(*resampler = resample_open(RESAMPLE_QUALITY,
226 *resample_factor, *resample_factor))) {
227 ast_log(LOG_ERROR,
"Failed to open %s resampler\n",
228 input ?
"input" :
"output");
242 struct jack_data *jack_data)
244 short s_buf[nframes];
248 size_t write_len =
sizeof(s_buf);
250 if (jack_data->input_resampler) {
251 int total_in_buf_used = 0;
252 int total_out_buf_used = 0;
253 float f_buf[nframes + 1];
255 memset(f_buf, 0,
sizeof(f_buf));
257 while (total_in_buf_used < nframes) {
261 out_buf_used = resample_process(jack_data->input_resampler,
262 jack_data->input_resample_factor,
263 &in_buf[total_in_buf_used], nframes - total_in_buf_used,
265 &f_buf[total_out_buf_used], ARRAY_LEN(f_buf) - total_out_buf_used);
267 if (out_buf_used < 0)
270 total_out_buf_used += out_buf_used;
271 total_in_buf_used += in_buf_used;
273 if (total_out_buf_used == ARRAY_LEN(f_buf)) {
274 ast_log(LOG_ERROR,
"Output buffer filled ... need to increase its size, "
275 "nframes '%d', total_out_buf_used '%d'\n", nframes, total_out_buf_used);
280 for (i = 0; i < total_out_buf_used; i++)
281 s_buf[i] = f_buf[i] * (SHRT_MAX / 1.0);
283 write_len = total_out_buf_used *
sizeof(int16_t);
287 for (i = 0; i < nframes; i++)
288 s_buf[i] = in_buf[i] * (SHRT_MAX / 1.0);
291 res = jack_ringbuffer_write(jack_data->input_rb, (
const char *) s_buf, write_len);
292 if (res != write_len) {
293 ast_log(LOG_WARNING,
"Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
294 (
int)
sizeof(s_buf), (
int) res);
305 struct jack_data *jack_data)
309 len = nframes *
sizeof(float);
311 res = jack_ringbuffer_read(jack_data->output_rb, buf, len);
314 ast_debug(2,
"Wanted %d bytes to send to the output port, "
315 "but only got %d\n", (
int) len, (
int) res);
319 static int jack_process(jack_nframes_t nframes,
void *arg)
321 struct jack_data *jack_data = arg;
322 void *input_port_buf, *output_port_buf;
324 if (!jack_data->input_resample_factor)
325 alloc_resampler(jack_data, 1);
327 input_port_buf = jack_port_get_buffer(jack_data->input_port, nframes);
330 output_port_buf = jack_port_get_buffer(jack_data->output_port, nframes);
336 static void jack_shutdown(
void *arg)
338 struct jack_data *jack_data = arg;
343 static struct jack_data *destroy_jack_data(
struct jack_data *jack_data)
345 if (jack_data->input_port) {
346 jack_port_unregister(jack_data->client, jack_data->input_port);
347 jack_data->input_port = NULL;
350 if (jack_data->output_port) {
351 jack_port_unregister(jack_data->client, jack_data->output_port);
352 jack_data->output_port = NULL;
355 if (jack_data->client) {
356 jack_client_close(jack_data->client);
357 jack_data->client = NULL;
360 if (jack_data->input_rb) {
361 jack_ringbuffer_free(jack_data->input_rb);
362 jack_data->input_rb = NULL;
365 if (jack_data->output_rb) {
366 jack_ringbuffer_free(jack_data->output_rb);
367 jack_data->output_rb = NULL;
370 if (jack_data->output_resampler) {
371 resample_close(jack_data->output_resampler);
372 jack_data->output_resampler = NULL;
375 if (jack_data->input_resampler) {
376 resample_close(jack_data->input_resampler);
377 jack_data->input_resampler = NULL;
380 if (jack_data->has_audiohook)
390 static int init_jack_data(
struct ast_channel *chan,
struct jack_data *jack_data)
392 const char *client_name;
393 jack_status_t status = 0;
394 jack_options_t jack_options = JackNullOption;
396 unsigned int channel_rate;
398 unsigned int ringbuffer_size;
408 jack_data->frame_datalen = jack_data->audiohook_rate / 50;
410 ringbuffer_size = jack_data->frame_datalen * RINGBUFFER_FRAME_CAPACITY;
412 ast_debug(1,
"Audiohook parameters: slin-format:%s, rate:%d, frame-len:%d, ringbuffer_size: %d\n",
413 ast_format_get_name(jack_data->audiohook_format), jack_data->audiohook_rate, jack_data->frame_datalen, ringbuffer_size);
415 if (!ast_strlen_zero(jack_data->client_name)) {
416 client_name = jack_data->client_name;
418 ast_channel_lock(chan);
420 ast_channel_unlock(chan);
423 if (!(jack_data->output_rb = jack_ringbuffer_create(ringbuffer_size)))
426 if (!(jack_data->input_rb = jack_ringbuffer_create(ringbuffer_size)))
429 if (jack_data->no_start_server)
430 jack_options |= JackNoStartServer;
432 if (!ast_strlen_zero(jack_data->server_name)) {
433 jack_options |= JackServerName;
434 jack_data->client = jack_client_open(client_name, jack_options, &status,
435 jack_data->server_name);
437 jack_data->client = jack_client_open(client_name, jack_options, &status);
441 log_jack_status(
"Client Open Status", status);
443 if (!jack_data->client)
446 jack_data->input_port = jack_port_register(jack_data->client,
"input",
447 JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput | JackPortIsTerminal, 0);
448 if (!jack_data->input_port) {
449 ast_log(LOG_ERROR,
"Failed to create input port for jack port\n");
453 jack_data->output_port = jack_port_register(jack_data->client,
"output",
454 JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput | JackPortIsTerminal, 0);
455 if (!jack_data->output_port) {
456 ast_log(LOG_ERROR,
"Failed to create output port for jack port\n");
460 if (jack_set_process_callback(jack_data->client, jack_process, jack_data)) {
461 ast_log(LOG_ERROR,
"Failed to register process callback with jack client\n");
465 jack_on_shutdown(jack_data->client, jack_shutdown, jack_data);
467 if (jack_activate(jack_data->client)) {
468 ast_log(LOG_ERROR,
"Unable to activate jack client\n");
472 while (!ast_strlen_zero(jack_data->connect_input_port)) {
476 ports = jack_get_ports(jack_data->client, jack_data->connect_input_port,
477 NULL, JackPortIsInput);
480 ast_log(LOG_ERROR,
"No input port matching '%s' was found\n",
481 jack_data->connect_input_port);
485 for (i = 0; ports[i]; i++) {
486 ast_debug(1,
"Found port '%s' that matched specified input port '%s'\n",
487 ports[i], jack_data->connect_input_port);
490 if (jack_connect(jack_data->client, jack_port_name(jack_data->output_port), ports[0])) {
491 ast_log(LOG_ERROR,
"Failed to connect '%s' to '%s'\n", ports[0],
492 jack_port_name(jack_data->output_port));
494 ast_debug(1,
"Connected '%s' to '%s'\n", ports[0],
495 jack_port_name(jack_data->output_port));
503 while (!ast_strlen_zero(jack_data->connect_output_port)) {
507 ports = jack_get_ports(jack_data->client, jack_data->connect_output_port,
508 NULL, JackPortIsOutput);
511 ast_log(LOG_ERROR,
"No output port matching '%s' was found\n",
512 jack_data->connect_output_port);
516 for (i = 0; ports[i]; i++) {
517 ast_debug(1,
"Found port '%s' that matched specified output port '%s'\n",
518 ports[i], jack_data->connect_output_port);
521 if (jack_connect(jack_data->client, ports[0], jack_port_name(jack_data->input_port))) {
522 ast_log(LOG_ERROR,
"Failed to connect '%s' to '%s'\n", ports[0],
523 jack_port_name(jack_data->input_port));
525 ast_debug(1,
"Connected '%s' to '%s'\n", ports[0],
526 jack_port_name(jack_data->input_port));
537 static int queue_voice_frame(
struct jack_data *jack_data,
struct ast_frame *f)
540 size_t f_buf_used = 0;
542 int16_t *s_buf = f->
data.ptr;
545 memset(f_buf, 0,
sizeof(f_buf));
547 if (!jack_data->output_resample_factor)
548 alloc_resampler(jack_data, 0);
550 if (jack_data->output_resampler) {
552 int total_in_buf_used = 0;
553 int total_out_buf_used = 0;
555 memset(in_buf, 0,
sizeof(in_buf));
557 for (i = 0; i < f->
samples; i++)
558 in_buf[i] = s_buf[i] * (1.0 / SHRT_MAX);
560 while (total_in_buf_used < ARRAY_LEN(in_buf)) {
564 out_buf_used = resample_process(jack_data->output_resampler,
565 jack_data->output_resample_factor,
566 &in_buf[total_in_buf_used], ARRAY_LEN(in_buf) - total_in_buf_used,
568 &f_buf[total_out_buf_used], ARRAY_LEN(f_buf) - total_out_buf_used);
570 if (out_buf_used < 0)
573 total_out_buf_used += out_buf_used;
574 total_in_buf_used += in_buf_used;
576 if (total_out_buf_used == ARRAY_LEN(f_buf)) {
577 ast_log(LOG_ERROR,
"Output buffer filled ... need to increase its size\n");
582 f_buf_used = total_out_buf_used;
583 if (f_buf_used > ARRAY_LEN(f_buf))
584 f_buf_used = ARRAY_LEN(f_buf);
588 for (i = 0; i < f->
samples; i++)
589 f_buf[i] = s_buf[i] * (1.0 / SHRT_MAX);
594 res = jack_ringbuffer_write(jack_data->output_rb, (
const char *) f_buf, f_buf_used *
sizeof(
float));
595 if (res != (f_buf_used *
sizeof(
float))) {
596 ast_log(LOG_WARNING,
"Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
597 (
int) (f_buf_used *
sizeof(
float)), (
int) res);
622 short buf[jack_data->frame_datalen];
625 .subclass.format = jack_data->audiohook_format,
628 .datalen =
sizeof(buf),
633 size_t res, read_len;
636 read_len = out_frame ? out_frame->
datalen :
sizeof(buf);
637 read_buf = out_frame ? out_frame->
data.ptr : buf;
639 res = jack_ringbuffer_read_space(jack_data->input_rb);
641 if (res < read_len) {
644 ast_debug(1,
"Sending an empty frame for the JACK_HOOK\n");
645 memset(out_frame->
data.ptr, 0, out_frame->
datalen);
650 res = jack_ringbuffer_read(jack_data->input_rb, (
char *) read_buf, read_len);
652 if (res < read_len) {
653 ast_log(LOG_ERROR,
"Error reading from ringbuffer, even though it said there was enough data\n");
668 OPT_SERVER_NAME = (1 << 0),
669 OPT_INPUT_PORT = (1 << 1),
670 OPT_OUTPUT_PORT = (1 << 2),
671 OPT_NOSTART_SERVER = (1 << 3),
672 OPT_CLIENT_NAME = (1 << 4),
693 static struct jack_data *jack_data_alloc(
void)
695 struct jack_data *jack_data;
707 static int handle_options(
struct jack_data *jack_data,
const char *__options_str)
710 char *option_args[OPT_ARG_ARRAY_SIZE];
717 if (ast_test_flag(&options, OPT_SERVER_NAME)) {
718 if (!ast_strlen_zero(option_args[OPT_ARG_SERVER_NAME]))
721 ast_log(LOG_ERROR,
"A server name must be provided with the s() option\n");
726 if (ast_test_flag(&options, OPT_CLIENT_NAME)) {
727 if (!ast_strlen_zero(option_args[OPT_ARG_CLIENT_NAME]))
730 ast_log(LOG_ERROR,
"A client name must be provided with the c() option\n");
735 if (ast_test_flag(&options, OPT_INPUT_PORT)) {
736 if (!ast_strlen_zero(option_args[OPT_ARG_INPUT_PORT]))
739 ast_log(LOG_ERROR,
"A name must be provided with the i() option\n");
744 if (ast_test_flag(&options, OPT_OUTPUT_PORT)) {
745 if (!ast_strlen_zero(option_args[OPT_ARG_OUTPUT_PORT]))
748 ast_log(LOG_ERROR,
"A name must be provided with the o() option\n");
753 jack_data->no_start_server = ast_test_flag(&options, OPT_NOSTART_SERVER) ? 1 : 0;
758 static int jack_exec(
struct ast_channel *chan,
const char *data)
760 struct jack_data *jack_data;
762 if (!(jack_data = jack_data_alloc()))
766 destroy_jack_data(jack_data);
770 if (init_jack_data(chan, jack_data)) {
771 destroy_jack_data(jack_data);
776 destroy_jack_data(jack_data);
781 destroy_jack_data(jack_data);
785 while (!jack_data->stop) {
804 queue_voice_frame(jack_data, f);
814 jack_data = destroy_jack_data(jack_data);
819 static void jack_hook_ds_destroy(
void *data)
821 struct jack_data *jack_data = data;
823 destroy_jack_data(jack_data);
828 .destroy = jack_hook_ds_destroy,
835 struct jack_data *jack_data;
846 ast_channel_lock(chan);
849 ast_log(LOG_ERROR,
"JACK_HOOK datastore not found for '%s'\n", ast_channel_name(chan));
850 ast_channel_unlock(chan);
854 jack_data = datastore->
data;
857 ast_log(LOG_WARNING,
"Expected frame in %s for the audiohook, but got format %s\n",
860 ast_channel_unlock(chan);
864 queue_voice_frame(jack_data, frame);
868 ast_channel_unlock(chan);
873 static int enable_jack_hook(
struct ast_channel *chan,
char *data)
876 struct jack_data *jack_data = NULL;
884 ast_channel_lock(chan);
887 ast_log(LOG_ERROR,
"JACK_HOOK already enabled for '%s'\n", ast_channel_name(chan));
891 if (ast_strlen_zero(args.mode) || strcasecmp(args.mode,
"manipulate")) {
892 ast_log(LOG_ERROR,
"'%s' is not a supported mode. Only manipulate is supported.\n",
893 S_OR(args.mode,
"<none>"));
897 if (!(jack_data = jack_data_alloc()))
900 if (!ast_strlen_zero(args.options) &&
handle_options(jack_data, args.options))
903 if (init_jack_data(chan, jack_data))
906 if (!(datastore = ast_datastore_alloc(&jack_hook_ds_info, NULL)))
909 jack_data->has_audiohook = 1;
913 datastore->
data = jack_data;
921 ast_channel_unlock(chan);
926 ast_channel_unlock(chan);
929 destroy_jack_data(jack_data);
933 datastore->
data = NULL;
940 static int disable_jack_hook(
struct ast_channel *chan)
943 struct jack_data *jack_data;
945 ast_channel_lock(chan);
948 ast_channel_unlock(chan);
949 ast_log(LOG_WARNING,
"No JACK_HOOK found to disable\n");
955 jack_data = datastore->
data;
963 ast_channel_unlock(chan);
968 static int jack_hook_write(
struct ast_channel *chan,
const char *cmd,
char *data,
974 ast_log(LOG_WARNING,
"No channel was provided to %s function.\n", cmd);
978 if (!strcasecmp(value,
"on"))
979 res = enable_jack_hook(chan, data);
980 else if (!strcasecmp(value,
"off"))
981 res = disable_jack_hook(chan);
983 ast_log(LOG_ERROR,
"'%s' is not a valid value for JACK_HOOK()\n", value);
992 .synopsis =
"Enable a jack hook on a channel",
993 .syntax =
"JACK_HOOK(<mode>,[options])",
995 " The JACK_HOOK allows turning on or off jack connectivity to this channel.\n"
996 "When the JACK_HOOK is turned on, jack ports will get created that allow\n"
997 "access to the audio stream for this channel. The mode specifies which mode\n"
998 "this hook should run in. A mode must be specified when turning the JACK_HOOK.\n"
999 "on. However, all arguments are optional when turning it off.\n"
1001 " Valid modes are:\n"
1004 " spy - Create a read-only audio hook. Only an output jack port will\n"
1006 " whisper - Create a write-only audio hook. Only an input jack port will\n"
1009 " manipulate - Create a read/write audio hook. Both an input and an output\n"
1010 " jack port will get created. Audio from the channel will be\n"
1011 " sent out the output port and will be replaced by the audio\n"
1012 " coming in on the input port as it gets passed on.\n"
1014 " Valid options are:\n"
1018 " To turn on the JACK_HOOK,\n"
1019 " Set(JACK_HOOK(manipulate,i(pure_data_0:input0)o(pure_data_0:output0))=on)\n"
1020 " To turn off the JACK_HOOK,\n"
1021 " Set(JACK_HOOK()=off)\n"
1023 .write = jack_hook_write,
1026 static int unload_module(
void)
1036 static int load_module(
void)
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
String manipulation functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static void handle_input(void *buf, jack_nframes_t nframes, struct jack_data *jack_data)
Handle jack input port.
static int handle_options(struct jack_data *jack_data, const char *__options_str)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Structure for a data store type.
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
int ast_unregister_application(const char *app)
Unregister an application.
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
struct ast_frame_subclass subclass
static void handle_output(void *buf, jack_nframes_t nframes, struct jack_data *jack_data)
Handle jack output port.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
ast_audiohook_manipulate_callback manipulate_callback
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
Initialize an audiohook structure.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define COMMON_OPTIONS
Common options between the Jack() app and JACK_HOOK() function.
General Asterisk PBX channel definitions.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Data structure associated with a custom dialplan function.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_debug(level,...)
Log a DEBUG message.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
static void handle_jack_audio(struct ast_channel *chan, struct jack_data *jack_data, struct ast_frame *out_frame)
handle jack audio
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Core PBX routines and definitions.
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Support for dynamic strings.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
union ast_frame::@224 data
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Module has failed to load, may be in an inconsistent state.
Structure used to handle boolean flags.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Data structure associated with a single frame of data.
enum ast_audiohook_status status
enum ast_frame_type frametype
struct ast_audiohook audiohook
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
#define ast_custom_function_register(acf)
Register a custom function.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define AST_APP_ARG(name)
Define an application argument.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.