static int dump_input_stream(struct input_stream *is) { GError *error = NULL; input_stream_lock(is); /* wait until the stream becomes ready */ input_stream_wait_ready(is); if (!input_stream_check(is, &error)) { g_warning("%s", error->message); g_error_free(error); input_stream_unlock(is); return EXIT_FAILURE; } /* read data and tags from the stream */ input_stream_unlock(is); struct text_input_stream *tis = text_input_stream_new(is); dump_text_file(tis); text_input_stream_free(tis); input_stream_lock(is); if (!input_stream_check(is, &error)) { g_warning("%s", error->message); g_error_free(error); input_stream_unlock(is); return EXIT_FAILURE; } input_stream_unlock(is); return 0; }
/** * Opens the input stream with input_stream_open(), and waits until * the stream gets ready. If a decoder STOP command is received * during that, it cancels the operation (but does not close the * stream). * * Unlock the decoder before calling this function. * * @return an input_stream on success or if #DECODE_COMMAND_STOP is * received, NULL on error */ static struct input_stream * decoder_input_stream_open(struct decoder_control *dc, const char *uri) { GError *error = NULL; struct input_stream *is; is = input_stream_open(uri, dc->mutex, dc->cond, &error); if (is == NULL) { if (error != NULL) { g_warning("%s", error->message); g_error_free(error); } return NULL; } /* wait for the input stream to become ready; its metadata will be available then */ decoder_lock(dc); input_stream_update(is); while (!is->ready && dc->command != DECODE_COMMAND_STOP) { decoder_wait(dc); input_stream_update(is); } if (!input_stream_check(is, &error)) { decoder_unlock(dc); g_warning("%s", error->message); g_error_free(error); return NULL; } decoder_unlock(dc); return is; }
static int dump_input_stream(struct input_stream *is) { GError *error = NULL; char buffer[4096]; size_t num_read; ssize_t num_written; input_stream_lock(is); /* wait until the stream becomes ready */ input_stream_wait_ready(is); if (!input_stream_check(is, &error)) { g_warning("%s", error->message); g_error_free(error); input_stream_unlock(is); return EXIT_FAILURE; } /* print meta data */ if (is->mime != NULL) g_printerr("MIME type: %s\n", is->mime); /* read data and tags from the stream */ while (!input_stream_eof(is)) { struct tag *tag = input_stream_tag(is); if (tag != NULL) { g_printerr("Received a tag:\n"); tag_save(stderr, tag); tag_free(tag); } num_read = input_stream_read(is, buffer, sizeof(buffer), &error); if (num_read == 0) { if (error != NULL) { g_warning("%s", error->message); g_error_free(error); } break; } num_written = write(1, buffer, num_read); if (num_written <= 0) break; } if (!input_stream_check(is, &error)) { g_warning("%s", error->message); g_error_free(error); input_stream_unlock(is); return EXIT_FAILURE; } input_stream_unlock(is); return 0; }