Ejemplo n.º 1
0
OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,
								  const OPJ_BYTE * p_buffer,
								  OPJ_SIZE_T p_size, 
								  opj_event_mgr_t * p_event_mgr)
{
	OPJ_SIZE_T l_remaining_bytes = 0;
	OPJ_SIZE_T l_write_nb_bytes = 0;

	if (p_stream->m_status & opj_stream_e_error) {
		return (OPJ_SIZE_T)-1;
	}

	while(1) {
		l_remaining_bytes = p_stream->m_buffer_size - p_stream->m_bytes_in_buffer;
		
		/* we have more memory than required */
		if (l_remaining_bytes >= p_size) {
			memcpy(p_stream->m_current_data, p_buffer, p_size);
			
			p_stream->m_current_data += p_size;
			p_stream->m_bytes_in_buffer += p_size;
			l_write_nb_bytes += p_size;
			p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
			
			return l_write_nb_bytes;
		}

		/* we copy data and then do an actual read on the stream */
		if (l_remaining_bytes) {
			l_write_nb_bytes += l_remaining_bytes;
			
			memcpy(p_stream->m_current_data,p_buffer,l_remaining_bytes);
			
			p_stream->m_current_data = p_stream->m_stored_data;
			
			p_buffer += l_remaining_bytes;
			p_size -= l_remaining_bytes;
			p_stream->m_bytes_in_buffer += l_remaining_bytes;
			p_stream->m_byte_offset += (OPJ_OFF_T)l_remaining_bytes;
		}

		if (! opj_stream_flush(p_stream, p_event_mgr)) {
			return (OPJ_SIZE_T)-1;
		}
	}

}
Ejemplo n.º 2
0
/**
 * Skips a number of bytes from the stream.
 * @param		p_stream	the stream to skip data from.
 * @param		p_size		the number of bytes to skip.
 * @param		p_event_mgr	the user event manager to be notified of special events.
 * @return		the number of bytes skipped, or -1 if an error occured.
 */
OPJ_SIZE_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
{
	OPJ_BOOL l_is_written = 0;
	OPJ_SIZE_T l_current_skip_nb_bytes = 0;
	OPJ_SIZE_T l_skip_nb_bytes = 0;

	if
		(p_stream->m_status & opj_stream_e_error)
	{
		return (OPJ_SIZE_T) -1;
	}
	
	// we should flush data
	l_is_written = opj_stream_flush (p_stream, p_event_mgr);
	if
		(! l_is_written)
	{
		p_stream->m_status |= opj_stream_e_error;
		p_stream->m_bytes_in_buffer = 0;
		p_stream->m_current_data = p_stream->m_current_data;
		return (OPJ_SIZE_T) -1;
	}
	// then skip

	while
		(p_size > 0)
	{
		// we should do an actual skip on the media
		l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
		if
			(l_current_skip_nb_bytes == (OPJ_SIZE_T)-1)
		{
			opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n");
			p_stream->m_status |= opj_stream_e_error;
			p_stream->m_byte_offset += l_skip_nb_bytes;
			// end if stream
			return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_SIZE_T)-1;
		}
		p_size -= l_current_skip_nb_bytes;
		l_skip_nb_bytes += l_current_skip_nb_bytes;
	}
	p_stream->m_byte_offset += l_skip_nb_bytes;
	return l_skip_nb_bytes;
}
Ejemplo n.º 3
0
OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{
	if (! opj_stream_flush(p_stream,p_event_mgr)) {
		p_stream->m_status |= opj_stream_e_error;
		return OPJ_FALSE;
	}

	p_stream->m_current_data = p_stream->m_stored_data;
	p_stream->m_bytes_in_buffer = 0;

	if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) {
		p_stream->m_status |= opj_stream_e_error;
		return OPJ_FALSE;
	}
	else {
		p_stream->m_byte_offset = p_size;
	}

	return OPJ_TRUE;
}