summaryrefslogtreecommitdiff
path: root/encoders
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-01-06 03:24:28 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-01-06 03:24:28 +0100
commite755f01e631e832e3ef529049888d62af38d2b38 (patch)
tree1f2b8c8b888157cdd4c598541ebb8f26e9cc078f /encoders
parent70f111b184928feab0c94f762954b5ec83a441c6 (diff)
Change decoder/encoder API to provide decode/encode functions with a read callback function.
Diffstat (limited to 'encoders')
-rw-r--r--encoders/lame_encoder.cpp14
-rw-r--r--encoders/lame_encoder.h10
2 files changed, 21 insertions, 3 deletions
diff --git a/encoders/lame_encoder.cpp b/encoders/lame_encoder.cpp
index 125ee5e..7bf2ebc 100644
--- a/encoders/lame_encoder.cpp
+++ b/encoders/lame_encoder.cpp
@@ -22,3 +22,17 @@ size_t EncoderLame::encode(const uint8_t *input, size_t input_size, uint8_t *out
size_t EncoderLame::flush(uint8_t *output, size_t output_size) {
return lame_encode_flush(gfp, output, output_size);
}
+
+size_t EncoderLame::encode(ReadFunc read, uint8_t *output, size_t output_size) {
+ char src_data[0x2000];
+ std::streamsize src_read = read(src_data, 0x2000);
+ if(src_read < 0)
+ src_read = 0;
+ std::streamsize size = encode((const uint8_t*)src_data, src_read, (uint8_t*)output, output_size);
+ // no more data, flush encoder
+ if(src_read == 0 && size == 0) {
+ size = flush((uint8_t*)output, output_size);
+ }
+ return size;
+
+} \ No newline at end of file
diff --git a/encoders/lame_encoder.h b/encoders/lame_encoder.h
index 1843361..98ebc9f 100644
--- a/encoders/lame_encoder.h
+++ b/encoders/lame_encoder.h
@@ -8,12 +8,16 @@
class EncoderLame : public EncoderBase {
private:
lame_global_flags *gfp;
-
+
+ size_t encode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size);
+ size_t flush(uint8_t *output, size_t output_size);
+
+ protected:
+ virtual size_t encode(ReadFunc read, uint8_t *output, size_t output_size);
+
public:
EncoderLame();
~EncoderLame();
- size_t encode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size);
- size_t flush(uint8_t *output, size_t output_size);
};
#endif