int32_t S3_HLS_Get_Item_From_Queue()

in S3_HLS_Queue.c [161:204]


int32_t S3_HLS_Get_Item_From_Queue(S3_HLS_QUEUE_CTX* ctx, S3_HLS_BUFFER_PART_CTX* buffer_ctx) {
    QUEUE_DEBUG("Get Item From Queue!\n");
    if(NULL == ctx || NULL == buffer_ctx) {
        QUEUE_DEBUG("Invalid Queue Context!\n");
        return S3_HLS_INVALID_PARAMETER;
    }
    
    QUEUE_DEBUG("[Get]Locking queue!\n");
    int32_t ret = pthread_mutex_lock(&ctx->s3_hls_queue_lock);
    if(0 != ret) {
        QUEUE_DEBUG("[Get]Failed to lock queue lock! %d\n", ret);
        return ret;
    }
    
    
    if(0 == ctx->queue_length) {
        QUEUE_DEBUG("[Get]Queue is Empty!\n");
        ret = pthread_mutex_unlock(&ctx->s3_hls_queue_lock);
        if(0 != ret) {
            QUEUE_DEBUG("[Get]Unlock queue failed! %d\n", ret);
        }
        buffer_ctx->first_part_start = NULL;
        buffer_ctx->first_part_length = 0;
        buffer_ctx->second_part_start = NULL;
        buffer_ctx->second_part_length = 0;
        buffer_ctx->timestamp = 0;
        return ret; // queue is full
    }

    buffer_ctx->first_part_start = ctx->queue[ctx->queue_pos].first_part_start;
    buffer_ctx->first_part_length = ctx->queue[ctx->queue_pos].first_part_length;
    buffer_ctx->second_part_start = ctx->queue[ctx->queue_pos].second_part_start;
    buffer_ctx->second_part_length = ctx->queue[ctx->queue_pos].second_part_length;
    buffer_ctx->timestamp = ctx->queue[ctx->queue_pos].timestamp;

    QUEUE_DEBUG("[Get]Unlocking queue!\n");
    ret = pthread_mutex_unlock(&ctx->s3_hls_queue_lock);
    if(0 != ret) {
        QUEUE_DEBUG("[Get]Failed to unlock queue lock! %d\n", ret);
        return ret;
    }

    return S3_HLS_OK;
}