Open lain3d opened 4 years ago
This doesn't look like proper use of the file IO factory. Each given filename needs to return a unique file/istream handle for the named file, rather than one membuf for all files. Your custom istream handle type also needs to implement seeking, or else the decoders will have problems.
I think OP's final goal is to have an istream
created from the factory from each ID, which is analogous to file handling. @lain3d: Here is a quite informative article on properly deriving std::streambuf
.
@McSinyx I'm now using the std::streambuf for that example + this seekoff:
membuf::pos_type membuf::seekoff(off_type off,
std::ios_base::seekdir dir,
std::ios_base::openmode which = std::ios_base::in) {
if (dir == std::ios_base::cur)
gbump(off);
else if (dir == std::ios_base::end)
setg(eback(), egptr() + off, egptr());
else if (dir == std::ios_base::beg)
setg(eback(), eback() + off, egptr());
return gptr() - eback();
}
Unfortunately when I'm creating the object it looks like the underlying std::basic_streambuf is not updated..? So I'm still having the same problem as before.
After I implemented membuf::seekpos it's getting further but for some reason not decoding the frame properly..
But if I instead use the file the audio plays fine.
FWIW, this is what I use to create a std::istream
that reads from a memory buffer instead of a file on disk:
https://github.com/kcat/openal-soft/blob/openal-soft-1.20.1/alc/hrtf.cpp#L111...L178
Your factory's openFile
method would just need to create an idstream
using the appropriate start and end data pointers.
Hell yeah, got it working thanks to that.. I needed to have
this->setg(const_cast<char_type*>(begin_), const_cast<char_type*>(begin_),
const_cast<char_type*>(end_));
in my constructor (I took it out earlier because the example from the above link did not have setg).. Thanks. :)
Just as a test I've done this:
When I run my test I get:
Failed to rewind file for the next decoder factory
This is just a test, I was planning to pass in a map of id,buf in the constructor to the factory if I got this to work.