summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-01-10 17:52:44 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2011-01-10 17:52:44 +0100
commitfbbb74bac8db34e1d472213d0c625413545bc48e (patch)
tree1bcc57bced8f5d6887f81d6419e5c519d36422cc /decoders
parent089f3579a16a414d91d2512e2868faa329dbe7b0 (diff)
Fixed mpg123 decoder.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/mpg123_decoder.cpp27
-rw-r--r--decoders/mpg123_decoder.h6
2 files changed, 9 insertions, 24 deletions
diff --git a/decoders/mpg123_decoder.cpp b/decoders/mpg123_decoder.cpp
index 8b3d9b4..ec6f490 100644
--- a/decoders/mpg123_decoder.cpp
+++ b/decoders/mpg123_decoder.cpp
@@ -5,14 +5,14 @@
#include <iostream>
#include <stdexcept>
-DecoderMpg123::DecoderMpg123(const std::string& filename) : ifile(filename.c_str()) {
+DecoderMpg123::DecoderMpg123(const std::string& filename) {
int error;
handle = mpg123_new("generic", &error);
if(error) {
throw std::runtime_error(mpg123_plain_strerror(error));
}
- error = mpg123_open_feed(handle);
+ error = mpg123_open(handle, filename.c_str());
if(error) {
throw std::runtime_error(mpg123_plain_strerror(error));
}
@@ -26,33 +26,24 @@ DecoderMpg123::~DecoderMpg123() {
mpg123_delete(handle);
}
-size_t DecoderMpg123::decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) {
- if(mpg123_feed(handle, input, input_size) != MPG123_OK) {
- throw std::runtime_error(mpg123_strerror(handle));
- }
-
+std::size_t DecoderMpg123::read(char* buf, std::size_t buf_size) {
+ char src_data[0x2000];
+ int error = MPG123_NEED_MORE;
size_t output_written;
- int error = mpg123_read(handle, output, output_size, &output_written);
+
+ error = mpg123_read(handle, (unsigned char*)buf, buf_size, &output_written);
if(error == MPG123_NEW_FORMAT) {
long rate;
int channels, enc;
mpg123_getformat(handle, &rate, &channels, &enc);
std::cout << boost::format("mpg123: New format: %li Hz, %i channels, encoding value %i") % rate % channels % enc << std::endl;
- error = mpg123_read(handle, output, output_size, &output_written);
+ error = mpg123_read(handle, (unsigned char*)buf, buf_size, &output_written);
}
- if(error != MPG123_OK && error != MPG123_DONE && error != MPG123_NEED_MORE) {
+ if(error != MPG123_OK && error != MPG123_DONE) {
throw std::runtime_error(mpg123_plain_strerror(error));
}
return output_written;
}
-
-std::size_t DecoderMpg123::read(char* buf, std::size_t buf_size) {
- char 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*)buf, buf_size);
-}
diff --git a/decoders/mpg123_decoder.h b/decoders/mpg123_decoder.h
index bc35ed9..edd2108 100644
--- a/decoders/mpg123_decoder.h
+++ b/decoders/mpg123_decoder.h
@@ -3,17 +3,11 @@
#include "decoder.h"
-#include <fstream>
#include <mpg123.h>
-// needed for uint8_t
-#include <boost/cstdint.hpp>
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);
public:
DecoderMpg123(const std::string& filename);