aboutsummaryrefslogtreecommitdiff
path: root/src/encoder_plugin.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-04-05 00:03:38 +0200
committerMax Kellermann <max@duempel.org>2012-04-05 00:21:53 +0200
commit5acee73fc85e44179120a5818247fc0760038cff (patch)
tree143a8f28c8537041f08ecd64a9d3bfba35a412f4 /src/encoder_plugin.h
parent466c337bcb71fb6bca0384300586e7213685d53d (diff)
encoder/vorbis: generate end-of-stream packet when playback ends
Add the encoder_plugin method end(). This is important for the recorder plugin.
Diffstat (limited to 'src/encoder_plugin.h')
-rw-r--r--src/encoder_plugin.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/encoder_plugin.h b/src/encoder_plugin.h
index af3f76a4..70eee51a 100644
--- a/src/encoder_plugin.h
+++ b/src/encoder_plugin.h
@@ -35,7 +35,7 @@ struct encoder {
const struct encoder_plugin *plugin;
#ifndef NDEBUG
- bool open, pre_tag, tag;
+ bool open, pre_tag, tag, end;
#endif
};
@@ -53,6 +53,8 @@ struct encoder_plugin {
void (*close)(struct encoder *encoder);
+ bool (*end)(struct encoder *encoder, GError **error);
+
bool (*flush)(struct encoder *encoder, GError **error);
bool (*pre_tag)(struct encoder *encoder, GError **error);
@@ -132,7 +134,7 @@ encoder_open(struct encoder *encoder, struct audio_format *audio_format,
bool success = encoder->plugin->open(encoder, audio_format, error);
#ifndef NDEBUG
encoder->open = success;
- encoder->pre_tag = encoder->tag = false;
+ encoder->pre_tag = encoder->tag = encoder->end = false;
#endif
return success;
}
@@ -157,6 +159,35 @@ encoder_close(struct encoder *encoder)
}
/**
+ * Ends the stream: flushes the encoder object, generate an
+ * end-of-stream marker (if applicable), make everything which might
+ * currently be buffered available by encoder_read().
+ *
+ * After this function has been called, the encoder may not be usable
+ * for more data, and only encoder_read() and encoder_close() can be
+ * called.
+ *
+ * @param encoder the encoder
+ * @param error location to store the error occuring, or NULL to ignore errors.
+ * @return true on success
+ */
+static inline bool
+encoder_end(struct encoder *encoder, GError **error)
+{
+ assert(encoder->open);
+ assert(!encoder->end);
+
+#ifndef NDEBUG
+ encoder->end = true;
+#endif
+
+ /* this method is optional */
+ return encoder->plugin->end != NULL
+ ? encoder->plugin->end(encoder, error)
+ : true;
+}
+
+/**
* Flushes an encoder object, make everything which might currently be
* buffered available by encoder_read().
*
@@ -170,6 +201,7 @@ encoder_flush(struct encoder *encoder, GError **error)
assert(encoder->open);
assert(!encoder->pre_tag);
assert(!encoder->tag);
+ assert(!encoder->end);
/* this method is optional */
return encoder->plugin->flush != NULL
@@ -193,6 +225,7 @@ encoder_pre_tag(struct encoder *encoder, GError **error)
assert(encoder->open);
assert(!encoder->pre_tag);
assert(!encoder->tag);
+ assert(!encoder->end);
/* this method is optional */
bool success = encoder->plugin->pre_tag != NULL
@@ -222,6 +255,7 @@ encoder_tag(struct encoder *encoder, const struct tag *tag, GError **error)
assert(encoder->open);
assert(!encoder->pre_tag);
assert(encoder->tag);
+ assert(!encoder->end);
#ifndef NDEBUG
encoder->tag = false;
@@ -249,6 +283,7 @@ encoder_write(struct encoder *encoder, const void *data, size_t length,
assert(encoder->open);
assert(!encoder->pre_tag);
assert(!encoder->tag);
+ assert(!encoder->end);
return encoder->plugin->write(encoder, data, length, error);
}