Exemple #1
0
static mpg_ssize_t feed_read( mpg123_handle_t *fr, byte *out, mpg_ssize_t count )
{
	mpg_ssize_t	gotcount = bc_give( &fr->rdat.buffer, out, count );

	if( gotcount >= 0 && gotcount != count )
		return MPG123_ERR;

	return gotcount;
}
Exemple #2
0
static ssize_t buffered_fullread(mpg123_handle *fr, unsigned char *out, ssize_t count)
{
    struct bufferchain *bc = &fr->rdat.buffer;
    ssize_t gotcount;
    if(bc->size - bc->pos < count)
    {   /* Add more stuff to buffer. If hitting end of file, adjust count. */
        unsigned char readbuf[BUFFBLOCK];
        ssize_t need = count - (bc->size-bc->pos);
        while(need>0)
        {
            int ret;
            ssize_t got = fr->rdat.fullread(fr, readbuf, BUFFBLOCK);
            if(got < 0)
            {
                if(NOQUIET) error("buffer reading");
                return READER_ERROR;
            }

            if(VERBOSE3) debug1("buffered_fullread: buffering %li bytes from stream (if > 0)", (long)got);
            if(got > 0 && (ret=bc_add(bc, readbuf, got)) != 0)
            {
                if(NOQUIET) error1("unable to add to chain, return: %i", ret);
                return READER_ERROR;
            }

            need -= got; /* May underflow here... */
            if(got < BUFFBLOCK) /* That naturally catches got == 0, too. */
            {
                if(VERBOSE3) fprintf(stderr, "Note: Input data end.\n");
                break; /* End. */
            }
        }
        if(bc->size - bc->pos < count)
            count = bc->size - bc->pos; /* We want only what we got. */
    }
    gotcount = bc_give(bc, out, count);

    if(VERBOSE3) debug2("wanted %li, got %li", (long)count, (long)gotcount);

    if(gotcount != count) {
        if(NOQUIET) error("gotcount != count");
        return READER_ERROR;
    }
    else return gotcount;
}
Exemple #3
0
// the specific stuff for buffered stream reader.
static mpg_ssize_t buffered_fullread( mpg123_handle_t *fr, byte *out, mpg_ssize_t count )
{
	bufferchain_t	*bc = &fr->rdat.buffer;
	mpg_ssize_t		gotcount;

	if( bc->size - bc->pos < count )
	{
		// add more stuff to buffer. If hitting end of file, adjust count.
		byte	readbuf[4096];

		mpg_ssize_t need = count - (bc->size - bc->pos);

		while( need > 0 )
		{
			mpg_ssize_t	got = fr->rdat.fullread( fr, readbuf, sizeof( readbuf ));
			int	ret;

			if( got < 0 )
				return MPG123_ERR;

			if( got > 0 && ( ret = bc_add( bc, readbuf, got )) != 0 )
				return MPG123_ERR;

			need -= got; // may underflow here...

			if( got < sizeof( readbuf )) // that naturally catches got == 0, too.
				break; // end.
		}

		if( bc->size - bc->pos < count )
			count = bc->size - bc->pos; // we want only what we got.
	}

	gotcount = bc_give( bc, out, count );

	if( gotcount != count )
		return MPG123_ERR;
	return gotcount;
}
Exemple #4
0
static ssize_t feed_read(mpg123_handle *fr, unsigned char *out, ssize_t count)
{
	ssize_t gotcount = bc_give(&fr->rdat.buffer, out, count);
	if(gotcount >= 0 && gotcount != count) return READER_ERROR;
	else return gotcount;
}