summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
Diffstat (limited to 'decoders')
-rw-r--r--decoders/mpg123_decoder.cpp8
-rw-r--r--decoders/mpg123_decoder.h11
2 files changed, 10 insertions, 9 deletions
diff --git a/decoders/mpg123_decoder.cpp b/decoders/mpg123_decoder.cpp
index 0618320..8b3d9b4 100644
--- a/decoders/mpg123_decoder.cpp
+++ b/decoders/mpg123_decoder.cpp
@@ -5,7 +5,7 @@
#include <iostream>
#include <stdexcept>
-DecoderMpg123::DecoderMpg123() {
+DecoderMpg123::DecoderMpg123(const std::string& filename) : ifile(filename.c_str()) {
int error;
handle = mpg123_new("generic", &error);
if(error) {
@@ -49,10 +49,10 @@ size_t DecoderMpg123::decode(const uint8_t *input, size_t input_size, uint8_t *o
return output_written;
}
-size_t DecoderMpg123::decode(ReadFunc read, uint8_t *output, size_t output_size) {
+std::size_t DecoderMpg123::read(char* buf, std::size_t buf_size) {
char src_data[0x2000];
- std::streamsize src_read = read(src_data, 0x2000);
+ std::streamsize src_read = ifile.get(src_data, 0x2000).gcount();
if(src_read < 0)
src_read = 0;
- return decode((const uint8_t*)src_data, src_read, (uint8_t*)output, output_size);
+ return decode((const uint8_t*)src_data, src_read, (uint8_t*)buf, buf_size);
}
diff --git a/decoders/mpg123_decoder.h b/decoders/mpg123_decoder.h
index 5a637af..f71dbe7 100644
--- a/decoders/mpg123_decoder.h
+++ b/decoders/mpg123_decoder.h
@@ -3,20 +3,21 @@
#include "decoder.h"
+#include <fstream>
#include <mpg123.h>
-class DecoderMpg123 : public DecoderBase {
+class DecoderMpg123 : public Decoder {
private:
mpg123_handle *handle;
+ std::ifstream ifile;
size_t decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size);
- protected:
- virtual size_t decode(ReadFunc read, uint8_t *output, size_t output_size);
-
public:
- DecoderMpg123();
+ DecoderMpg123(const std::string& filename);
~DecoderMpg123();
+
+ virtual std::size_t read(char* buf, std::size_t buf_size);
};
#endif