AW: [vorbis] ov_pcm_total() returns always 0 after ov_open_callbacks()...

Mike just.me at aon.at
Mon Mar 3 13:53:16 PST 2003



Greetings again,

i've rewritten the callback funktions to use indexes instead of casted
pointers (which makes to code a little easier to read, but the result is the
same.) Maybe i've misunderstood something...
Please let me know if you have any ideas and thanks in advance,
Mike

<p>// This is the structure for the parameter 'pDataSource'
typedef struct
{
    UINT8* pRawData; // Contains a copy of the raw data
    SINT32 NextByte; // The next byte that will be delivered
    SINT32 DataSize; // The size in bytes of pRawData[]
}MEMFILE;

<p><p>// This is how i call ov_open_callbacks()
// m_MemFile is already initialized.
Callbacks.read_func  = ReadCallback;
Callbacks.seek_func  = SeekCallback;
Callbacks.close_func = CloseCallback;
Callbacks.tell_func  = TellCallback;
// NOTICE: i pass the structure, not an address to 'Callbacks'
//         Docs says pointer to struct, header says structure!
RetVal = ov_open_callbacks(&m_MemFile, &m_VF, NULL, 0, Callbacks);

<p>// ReadCallback
size_t ReadCallback(void* pDstData, size_t Len, size_t LenCount, void*
pDataSource)
{
    UINT32   BytesDelivered;
    UINT32   BytesToCopy;
    UINT8*   pDst;
    MEMFILE* pSrc;

    BytesToCopy = Len * LenCount;
    pDst        = (UINT8 *)pDstData;
    pSrc        = (MEMFILE *)pDataSource;

    for (BytesDelivered = 0; BytesDelivered < BytesToCopy; BytesDelivered++)
    {
        if ( pSrc->NextByte >= pSrc->DataSize)
            break;

        *pDst = pSrc->pRawData[pSrc->NextByte];
        pDst++;
        pSrc->NextByte++;
    }
    return (BytesDelivered / Len);
}

<p><p>// SeekCallback()
int SeekCallback(void* pDataSource, ogg_int64_t Offset, int whence)
{
    MEMFILE* pSrc;

    pSrc = (MEMFILE *)pDataSource;
    if (whence == SEEK_CUR)
    {
        // I assume my oggfiles are less than 2 GB!
        pSrc->NextByte += (SINT32)Offset;

        // Be sure we stay inside the buffer!
        /* FIXME: Debug!
        if (pSrc->NextByte < 0)
            pSrc->NextByte = 0;
        else if(pSrc->NextByte > pSrc->DataSize)
            pSrc->NextByte = pSrc->DataSize;
        */

        return 0;
    }

    else if (whence == SEEK_END)
    {
        pSrc->NextByte = pSrc->DataSize;
        return 0;
    }

    else if (whence == SEEK_SET)
    {
        pSrc->NextByte = 0;
        return 0;
    }

    return -1;
}

<p><p>// CloseCallback
int CloseCallback(void* pDataSource)
{
    return 0;
}

<p><p>// TellCallback
long TellCallback(void *pDataSource)
{
    MEMFILE* pSrc;

    pSrc = (MEMFILE *)pDataSource;
    return (pSrc->NextByte);
}

<p><p><p><p><p><p><p><p><p><p><p><p>-----Ursprüngliche Nachricht-----
Von: owner-vorbis at xiph.org [mailto:owner-vorbis at xiph.org]Im Auftrag von
Michael Smith
Gesendet: 03 March 2003 01:08
An: vorbis at xiph.org
Betreff: Re: [vorbis] ov_pcm_total() returns always 0 after
ov_open_callbacks()...

<p>Mike <just.me at aon.at> said:

> Hi Folks,
>
> i implemented the required callback funktions to open an ogg file from
> memory.
> Now ov_pcm_total() returns always 0, strange thing about is that
> ov_pcm_total does not call any of the callback funktions.
> I also like to mention that ov_info (which uses the read and seek callback
> funktions) delivers correct values. Thats why i doubt that there's an
error
> in (the rather simple) callback funktions...

Do your callbacks support seeking? If not, that's why - obviously, without
seeking, it can't figure out how long the stream is.

If you DO support seeking, perhaps you've got some other bug in your
callback(s)? Can you show us the tell and seek callbacks you've implemented?

Mike

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis mailing list