On 09/06/2010 18:22, Eugene Mymrin wrote:
For every av_open_input_file you will have file_open called once.
When you first receive URLContext (along with pseudo filename) in
file_open you need to "connect" it with some data stream.
For this purpose you have URLContext->priv_data.
Create CContext object for every new stream and keep it in
URLContext->priv_data.
Later, when file_read, file_write or file_seek is called, let CContext
stored in URLContext->priv_data do the job.


On Wed, Jun 9, 2010 at 7:35 PM, Mark Kenna
<[email protected]>  wrote:
On 09/06/2010 15:20, Eugene Mymrin wrote:
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

Hi

This is still a problem for me because of this:
CContext* pContext =<static variable where CContext is temporarily
stored>;
If that static variable is changed in order to start another buffer, it will
change the pContext in h->priv_data (or am I wrong). How does this work if
you want to open two lots of your custom protocol in the same application?

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

Hi

I have successfully implented a buffer protocol, the question I now have is related to MP4/H264 buffering. My customer "buffer" decoder now works very well for avi, mpg but not for MP4 or H264. Am I correct in assuming that I must handle the seek function because of the possibility of P or B frames?

Thanks,
Mark
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to