Hello,
I try to write a program that decodes (using mpg123) and plays mp3 data from a network stream. My function for receiving and decoding is the following.
bool player::OnGetData(sf::SoundStream::Chunk& ck)
{
size_t got_now = 0;
for (unsigned rcb = 0; rcb < in_size; ++rcb)
{
char* temp = in + rcb;
*temp = data_stream->recieve_byte();
}
out = new unsigned char [out_size*2];
int ret = mpg123_decode (mpg, (unsigned char* ) in, in_size,out, out_size*2, &got_now);
if (ret == MPG123_NEED_MORE)
throw std::runtime_error ("Decoding error");
ck.Samples = reinterpret_cast<sf::Int16*> (out);
ck.NbSamples = got_now;
return true;
}
It plays some strange noises and the I get an segmentation fault with the following backtrace
#0 0x7ff8317fa11b memcpy() (/lib/libc.so.6:??)
#1 0x7ff82dab6c6e ??() (/usr/lib/libopenal.so.1:??)
#2 0x7ff82dab6e26 alBufferData() (/usr/lib/libopenal.so.1:??)
#3 0x7ff8322a0967 sf::SoundStream::FillAndPushBuffer() (/usr/lib/libsfml-audio.so.1.4:??)
#4 0x7ff8322a0b9d sf::SoundStream::Run() (/usr/lib/libsfml-audio.so.1.4:??)
#5 0x7ff8324b5f59 sf::Thread::ThreadFunc() (/usr/lib/libsfml-system.so.1.4:??)
#6 0x7ff83135d3ba start_thread() (/lib/libpthread.so.0:??)
#7 0x7ff83185bfcd clone() (/lib/libc.so.6:??)
#8 ( 0x0000000000000000 in ??() (??:??)
I think that I'm doing something wrong when feeding the audio stream. But since I haven't got any idea what it is, I am asking you for help. My buffer are all unsigned char* arrays and I guess that they are not too small but maybe too big.
If you need more code to help me just write it.
Thanks in advance