Similar code works very well for me:

class CContext
{
        public:
        int OnDataRequested(uint8_t* p, int n)
        {
        }
        int64_t OnSeekRequested(int64_t offset, int whence)
        {
        }
};

static int file_open(URLContext *h, const char *filename, int flags)
{
        CContext* pContext = <static variable where CContext is temporarily 
stored>;
        h->priv_data = (void*) pContext;
        return 0;
}

static int file_read(URLContext *h, unsigned char *buf, int size)
{
        CContext* p = (CContext*) h->priv_data;
        return p->OnDataRequested(buf, size);
}

static int file_write(URLContext *h, unsigned char *buf, int size)
{
        return 0;
}

static int64_t file_seek(URLContext *h, int64_t pos, int whence)
{
        CContext* p = (CContext*) h->priv_data;
        return p->OnSeekRequested(pos, whence);
}

static int file_close(URLContext *h)
{
        return 0;
}

static int file_get_handle(URLContext *h)
{
        return (intptr_t) h->priv_data;
}

On Wed, Jun 9, 2010 at 4:00 PM, Mark Kenna
<[email protected]> wrote:
> Hi All
>
> I have a problem whilst implementing a custom URLProtocol for use with
> av_open_input_file(...). I am trying to use the protocol so that a custom
> url_read method will receive data from a callback which the user can supply
> from the calling application. To illustrate, I have the following methods
> for the url_open and url_read (which are both static member functions of an
> unmanaged C++ class)
>
> int BufferProtocol::BufferOpen(URLContext *h, const char *pseudofilename,
> int flags)
> {
>    //setup the buffer
>    BUFFER *buffer = new BUFFER();
>    buffer->buflen = BUFFERLENGTH;
>    buffer->offset = 0;
>    buffer->buf = new unsigned char[BUFFERLENGTH];
>    memset(buffer->buf, 0, BUFFERLENGTH);
>
>
>    //assign the URLContext's private data to be the buffer
>    h->priv_data = buffer;
>
>    return 1;
> }
>
> int BufferProtocol::BufferRead(URLContext *h, unsigned char *buf, int size)
> {
>    BUFFER *buffer = (BUFFER*)h->priv_data;
>
>    int amountRead = 1024;
>    unsigned char* data = HELP_HERE_PLEASE
> ...
> ...
>
> }
>
> So in the above Read method I want to invoke a callback which will prompt
> for a certain number of bytes and return the received data (which can be put
> into *buf). I understand how this would work with a typical callback but I
> have one more problem - because I am using Class members for the URLProtocol
> they have to be static, also the application that is going to use this will
> probably call av_open_input_file(...) more than once (for multiple input
> buffer sources) and because the methods are all static I will not be able to
> tell which buffer the callback refers to. This is kind of confusing to
> describe and I hope that my point is clear enough to understand.
>
> Thanks,
> Mark.
>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to