25 #include "libavutil/mem.h"
26 #include "libavutil/bprint.h"
43 printf(
"send message to ZMQ recipient, to use with the zmq filters\n");
44 printf(
"usage: zmqsend [OPTIONS]\n");
47 "-b ADDRESS set bind address\n"
48 "-h print this help\n"
49 "-i INFILE set INFILE as input file, stdin if omitted\n");
52 int main(
int argc,
char **argv)
55 char c, *src_buf, *recv_buf;
56 int recv_buf_size,
ret;
58 const char *bind_address =
"tcp://localhost:5555";
59 const char *infilename = NULL;
63 while ((c =
getopt(argc, argv,
"b:hi:")) != -1) {
79 if (!infilename || !strcmp(infilename,
"-")) {
83 infile = fopen(infilename,
"r");
87 "Impossible to open input file '%s': %s\n", infilename, strerror(errno));
94 "Could not create ZMQ context: %s\n", zmq_strerror(errno));
98 socket = zmq_socket(ctx, ZMQ_REQ);
101 "Could not create ZMQ socket: %s\n", zmq_strerror(errno));
106 if (zmq_connect(socket, bind_address) == -1) {
108 bind_address, zmq_strerror(errno));
115 while ((c = fgetc(infile)) != EOF)
127 if (zmq_send(socket, src_buf, strlen(src_buf), 0) == -1) {
133 if (zmq_msg_init(&msg) == -1) {
135 "Could not initialize receiving message: %s\n", zmq_strerror(errno));
140 if (zmq_msg_recv(&msg, socket, 0) == -1) {
142 "Could not receive message: %s\n", zmq_strerror(errno));
148 recv_buf_size = zmq_msg_size(&msg) + 1;
152 "Could not allocate receiving message buffer\n");
157 memcpy(recv_buf, zmq_msg_data(&msg), recv_buf_size);
158 recv_buf[recv_buf_size-1] = 0;
159 printf(
"%s\n", recv_buf);
165 zmq_ctx_destroy(ctx);
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static av_cold int end(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define AV_BPRINT_SIZE_UNLIMITED
Convenience macros for special values for av_bprint_init() size_max parameter.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
Buffer to print data progressively.
static int av_bprint_is_complete(AVBPrint *buf)
Test if the print buffer is complete (not truncated).
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int getopt(int argc, char *argv[], char *opts)
int main(int argc, char **argv)