Thanks! I now have a working function that takes a C++ ostream and returns a
smart pointer to a AVIOContext: (Feel free to use for whatever you want)
//support old version of the AVIO API
#define USE_OLD_AVIO_API 1
#if USE_OLD_AVIO_API
typedef ByteIOContext AVIOContext;
# define avio_alloc_context av_alloc_put_byte
#endif
class avio_context_from_ostream_utilities
{
private:
static void destroy(AVIOContext* ctx) {
delete[] ctx->buffer;
av_free(ctx);
}
static int write_packet(void* opaque, unsigned char * buf, int
buf_size) {
static_cast<ostream*>(opaque)->write(
reinterpret_cast<char*>(buf),
buf_size
);
}
friend
shared_ptr<AVIOContext>
avio_context_from_ostream(ostream& stream);
};
shared_ptr<AVIOContext> avio_context_from_ostream(ostream& stream)
{
const streamsize buf_size = 1048576;
unsigned char *buf = new unsigned char [buf_size];
shared_ptr<AVIOContext> avio_context(
avio_alloc_context(
buf,
buf_size,
0,
&stream,
0,
&avio_context_from_ostream_utilities::write_packet,
0
),
&avio_context_from_ostream_utilities::destroy
);
if(!avio_context)
{
delete[] buf;
throw bad_alloc();
}
avio_context->is_streamed = 1;
return avio_context;
}
Now, I have one more question. If I wanted a random access AVIOContext, what
should I do? Provide a seek function and set is_streamed to 0? What is the
"whence" parameter of the seek function for?
Many Thanks,
Jonathan Baldwin
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user