Commit c95c5508 authored by Laurent Aimar's avatar Laurent Aimar

* all: added stream_DataPacket

parent cd4cd776
......@@ -2,7 +2,7 @@
* 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>
*
......@@ -54,6 +54,7 @@ VLC_EXPORT( int, stream_vaControl, ( stream_t *, int i_query, v
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 ) );
/**
* @}
......
......@@ -2,7 +2,7 @@
* 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>
*
......@@ -133,7 +133,7 @@ int stream_vaControl( stream_t *s, int i_query, va_list args )
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 );
......@@ -151,7 +151,8 @@ int stream_vaControl( stream_t *s, int i_query, va_list args )
{
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;
......@@ -222,7 +223,8 @@ int stream_Read( stream_t *s, void *p_data, int i_data )
{
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;
......@@ -288,7 +290,8 @@ pes_packet_t *stream_PesPacket( stream_t *s, int i_data )
{
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
......@@ -315,7 +318,57 @@ pes_packet_t *stream_PesPacket( stream_t *s, int i_data )
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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment