Exemple #1
0
block_t * AbstractStream::readNextBlock(size_t toread)
{
    SegmentChunk *chunk = getChunk();
    if(!chunk)
        return NULL;

    if(format != chunk->getStreamFormat())
    {
        /* Force stream to end for this call */
        msg_Info(p_realdemux, "Changing stream format %u->%u",
                 (unsigned)format, (unsigned)chunk->getStreamFormat());

        restarting_output = true;
        format = chunk->getStreamFormat();
        /* Next stream will use current unused chunk */
        return NULL;
    }

    if(chunk->discontinuity)
    {
        discontinuity = true;
        chunk->discontinuity = false;
        msg_Info(p_realdemux, "Encountered discontinuity");
        return NULL;
    }

    const bool b_segment_head_chunk = (chunk->getBytesRead() == 0);

    block_t *block = chunk->read(toread);
    if(block == NULL)
    {
        currentChunk = NULL;
        delete chunk;
        return NULL;
    }

    if (chunk->getBytesToRead() == 0)
    {
        currentChunk = NULL;
        delete chunk;
    }

    block = checkBlock(block, b_segment_head_chunk);

    return block;
}
Exemple #2
0
size_t Stream::read(HTTPConnectionManager *connManager)
{
    SegmentChunk *chunk = getChunk();
    if(!chunk)
        return 0;

    if(!chunk->getConnection())
    {
       if(!connManager->connectChunk(chunk))
        return 0;
    }

    size_t readsize = 0;
    bool b_segment_head_chunk = false;

    /* New chunk, do query */
    if(chunk->getBytesRead() == 0)
    {
        if(chunk->getConnection()->query(chunk->getPath()) != VLC_SUCCESS)
        {
            chunk->getConnection()->releaseChunk();
            currentChunk = NULL;
            delete chunk;
            return 0;
        }
        b_segment_head_chunk = true;
    }

    /* Because we don't know Chunk size at start, we need to get size
       from content length */
    readsize = chunk->getBytesToRead();
    if (readsize > 32768)
        readsize = 32768;

    block_t *block = block_Alloc(readsize);
    if(!block)
        return 0;

    mtime_t time = mdate();
    ssize_t ret = chunk->getConnection()->read(block->p_buffer, readsize);
    time = mdate() - time;

    if(ret < 0)
    {
        block_Release(block);
        chunk->getConnection()->releaseChunk();
        currentChunk = NULL;
        delete chunk;
        return 0;
    }
    else
    {
        block->i_buffer = (size_t)ret;

        adaptationLogic->updateDownloadRate(block->i_buffer, time);
        chunk->onDownload(&block);

        StreamFormat chunkStreamFormat = chunk->getStreamFormat();
        if(output && chunkStreamFormat != output->getStreamFormat())
        {
            msg_Info(p_demux, "Changing stream format");
            updateFormat(chunkStreamFormat);
        }

        if (chunk->getBytesToRead() == 0)
        {
            chunk->getConnection()->releaseChunk();
            currentChunk = NULL;
            delete chunk;
        }
    }

    readsize = block->i_buffer;

    if(output)
        output->pushBlock(block, b_segment_head_chunk);
    else
        block_Release(block);

    return readsize;
}
Exemple #3
0
block_t * AbstractStream::readNextBlock(size_t)
{
    SegmentChunk *chunk = getChunk();
    if(!chunk)
        return NULL;

    if(format != chunk->getStreamFormat())
    {
        /* Force stream to end for this call */
        msg_Info(p_realdemux, "Changing stream format %u->%u",
                 (unsigned)format, (unsigned)chunk->getStreamFormat());

        restarting_output = true;
        format = chunk->getStreamFormat();
        /* Next stream will use current unused chunk */
        return NULL;
    }

    if(chunk->discontinuity)
    {
        discontinuity = true;
        chunk->discontinuity = false;
        msg_Info(p_realdemux, "Encountered discontinuity");
        return NULL;
    }

    if(!chunk->getConnection())
    {
       if(!connManager->connectChunk(chunk))
        return NULL;
    }

    size_t readsize = 0;
    bool b_segment_head_chunk = false;

    /* New chunk, do query */
    if(chunk->getBytesRead() == 0)
    {
        if(chunk->getConnection()->query(chunk->getPath()) != VLC_SUCCESS)
        {
            chunk->getConnection()->releaseChunk();
            currentChunk = NULL;
            delete chunk;
            return NULL;
        }
        b_segment_head_chunk = true;
    }

    /* Because we don't know Chunk size at start, we need to get size
       from content length */
    readsize = chunk->getBytesToRead();
    if (readsize > 32768)
        readsize = 32768;

    block_t *block = block_Alloc(readsize);
    if(!block)
        return NULL;

    mtime_t time = mdate();
    ssize_t ret = chunk->getConnection()->read(block->p_buffer, readsize);
    time = mdate() - time;

    if(ret < 0)
    {
        block_Release(block);
        chunk->getConnection()->releaseChunk();
        currentChunk = NULL;
        delete chunk;
        return NULL;
    }
    else
    {
        block->i_buffer = (size_t)ret;

        adaptationLogic->updateDownloadRate(block->i_buffer, time);
        chunk->onDownload(&block);

        if (chunk->getBytesToRead() == 0)
        {
            chunk->getConnection()->releaseChunk();
            currentChunk = NULL;
            delete chunk;
        }
    }

    block = checkBlock(block, b_segment_head_chunk);

    return block;
}