* ninput.h
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: ninput.h,v 1.4 2003/08/14 11:25:56 sigmunau Exp $
+ * $Id: ninput.h,v 1.5 2003/08/18 19:17:54 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
VLC_EXPORT( int, stream_Control, ( stream_t *, int i_query, ... ) );
VLC_EXPORT( int, stream_Read, ( stream_t *, void *p_read, int i_read ) );
VLC_EXPORT( int, stream_Peek, ( stream_t *, uint8_t **pp_peek, int i_peek ) );
+VLC_EXPORT( data_packet_t *,stream_DataPacket, ( stream_t *, int i_size, vlc_bool_t b_force ) );
VLC_EXPORT( pes_packet_t *, stream_PesPacket, ( stream_t *, int i_size ) );
/**
* @}
* stream.c
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: stream.c,v 1.2 2003/08/14 11:25:56 sigmunau Exp $
+ * $Id: stream.c,v 1.3 2003/08/18 19:17:54 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
if( s->p_input->stream.b_seekable &&
( s->p_input->stream.i_method == INPUT_METHOD_FILE ||
i64 - s->p_input->stream.p_selected_area->i_tell < 0 ||
- i64 - s->p_input->stream.p_selected_area->i_tell > 1024 ) )
+ i64 - s->p_input->stream.p_selected_area->i_tell > 4096 ) )
{
input_AccessReinit( s->p_input );
s->p_input->pf_seek( s->p_input, i64 );
{
int i_read;
- i_read = input_SplitBuffer( s->p_input, &p_data, __MIN( 4096, i_skip ) );
+ i_read = input_SplitBuffer( s->p_input, &p_data,
+ __MIN( (int)s->p_input->i_bufsize, i_skip ) );
if( i_read < 0 )
{
return VLC_EGENERIC;
{
int i_count;
- i_count = input_SplitBuffer( s->p_input, &p_packet, __MIN( i_data, 4096 ) );
+ i_count = input_SplitBuffer( s->p_input, &p_packet,
+ __MIN( i_data, (int)s->p_input->i_bufsize ) );
if( i_count <= 0 )
{
return i_read;
{
int i_read;
- i_read = input_SplitBuffer( s->p_input, &p_packet, __MIN( i_data, 4096 ) );
+ i_read = input_SplitBuffer( s->p_input, &p_packet,
+ __MIN( i_data, (int)s->p_input->i_bufsize ) );
if( i_read <= 0 )
{
/* should occur only with EOF and max allocation reached
return p_pes;
}
+/**
+ * Read i_size into a data_packet_t. If b_force is not set, fewer bytes can
+ * be returned. You should always set b_force, unless you know what you are
+ * doing.
+ */
+data_packet_t *stream_DataPacket( stream_t *s, int i_size, vlc_bool_t b_force )
+{
+ data_packet_t *p_pk;
+ int i_read;
+
+ if( i_size <= 0 )
+ {
+ p_pk = input_NewPacket( s->p_input->p_method_data, 0 );
+ if( p_pk )
+ {
+ p_pk->p_payload_end = p_pk->p_payload_start;
+ }
+ return p_pk;
+ }
+
+ i_read = input_SplitBuffer( s->p_input, &p_pk, i_size );
+ if( i_read <= 0 )
+ {
+ return NULL;
+ }
+ /* Should be really rare, near 0 */
+ if( i_read < i_size && b_force )
+ {
+ data_packet_t *p_old = p_pk;
+ int i_missing = i_size - i_read;
+
+ p_pk = input_NewPacket( s->p_input->p_method_data, i_size );
+ if( p_pk == NULL )
+ {
+ input_DeletePacket( s->p_input->p_method_data, p_old );
+ return NULL;
+ }
+ p_pk->p_payload_end = p_pk->p_payload_start + i_size;
+ memcpy( p_pk->p_payload_start, p_old->p_payload_start, i_read );
+ input_DeletePacket( s->p_input->p_method_data, p_old );
+
+ if( stream_Read( s, &p_pk->p_payload_start[i_read], i_missing ) < i_missing )
+ {
+ input_DeletePacket( s->p_input->p_method_data, p_pk );
+ return NULL;
+ }
+ }
+
+ return p_pk;
+}