diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-25 23:33:46 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-25 23:33:46 +0100 |
commit | 3a23129ac5110d72040692b229554babc2aa2a99 (patch) | |
tree | 81a74d9d92ec6f474f038f0089d69ffb6b2ecbc6 | |
parent | 03d091e6150a17a71f1f8e6440ed5ea9aaa1311d (diff) |
Added encoder_flush() to flush encoder buffers.old
-rw-r--r-- | encoder.c | 4 | ||||
-rw-r--r-- | encoder.h | 2 | ||||
-rw-r--r-- | encoders/encoder_lame.c | 9 | ||||
-rw-r--r-- | transcode.c | 3 |
4 files changed, 18 insertions, 0 deletions
@@ -9,6 +9,10 @@ gssize encoder_encode(struct encoder *encoder, GInputStream *input, return encoder->encoder->encode(encoder->data, input, output, error); } +void encoder_flush(struct encoder *encoder, GOutputStream *output, GError **error) { + encoder->encoder->flush(encoder->data, output, error); +} + void encoder_close(struct encoder *encoder) { encoder->encoder->close(encoder->data); } @@ -10,6 +10,7 @@ struct encoder_plugin { gboolean (*init)(gpointer *data); gssize (*encode)(gpointer data, GInputStream *input, GOutputStream *output, GError **error); + void (*flush)(gpointer data, GOutputStream *output, GError **error); void (*close)(gpointer data); }; @@ -22,6 +23,7 @@ struct encoder { gboolean encoder_init(struct encoder *encoder); gssize encoder_encode(struct encoder *encoder, GInputStream *input, GOutputStream *output, GError **error); +void encoder_flush(struct encoder *encoder, GOutputStream *output, GError **error); void encoder_close(struct encoder *encoder); const struct encoder_plugin *encoder_get(const gchar *name); diff --git a/encoders/encoder_lame.c b/encoders/encoder_lame.c index 0836d17..ead8f7c 100644 --- a/encoders/encoder_lame.c +++ b/encoders/encoder_lame.c @@ -34,6 +34,14 @@ static gssize lame_encoder_encode(gpointer data, GInputStream *input, return ret; } +static void lame_encoder_flush(gpointer data, GOutputStream *output, GError **error) { + lame_global_flags *gfp = data; + const int outbuf_size = 7200; + unsigned char outbuf[outbuf_size]; + int size = lame_encode_flush(gfp, outbuf, outbuf_size); + g_output_stream_write(output, outbuf, size, NULL, error); +} + static void lame_encoder_close(gpointer data) { lame_global_flags *gfp = data; lame_close(gfp); @@ -43,5 +51,6 @@ const struct encoder_plugin encoder_lame_encoder = { .name = "lame", .init = lame_encoder_init, .encode = lame_encoder_encode, + .flush = lame_encoder_flush, .close = lame_encoder_close, }; diff --git a/transcode.c b/transcode.c index 20f91b5..636f8d7 100644 --- a/transcode.c +++ b/transcode.c @@ -76,6 +76,9 @@ void transcode(GInputStream *input, const struct decoder_plugin *_decoder, * if the decoder isn't done yet */ encode_done = decode_done; + if(encode_done == TRUE) { + encoder_flush(encoder, output, &error); + } } else { g_warning(error->message); break; |