typedef enum
{
STREAM_METHOD_BLOCK,
- STREAM_METHOD_STREAM
+ STREAM_METHOD_STREAM,
+ STREAM_METHOD_READDIR
} stream_read_method_t;
struct stream_sys_t
static void AStreamPrebufferStream( stream_t *s );
static int AReadStream( stream_t *s, void *p_read, unsigned int i_read );
+/* ReadDir */
+static int AStreamReadDir( stream_t *s, input_item_node_t *p_node );
+
/* Common */
+static int AStreamGenericError( ) { return VLC_EGENERIC; }
static int AStreamControl( stream_t *s, int i_query, va_list );
static void AStreamDestroy( stream_t *s );
static int ASeek( stream_t *s, uint64_t i_pos );
return NULL;
}
- s->pf_read = NULL; /* Set up later */
- s->pf_peek = NULL;
+ s->pf_read = AStreamGenericError; /* Replaced later */
+ s->pf_peek = AStreamGenericError;
+ s->pf_readdir = AStreamGenericError;
s->pf_control = AStreamControl;
s->pf_destroy = AStreamDestroy;
/* Common field */
p_sys->p_access = p_access;
+ assert( p_access->pf_block || p_access->pf_read || p_access->pf_readdir );
if( p_access->pf_block )
p_sys->method = STREAM_METHOD_BLOCK;
- else
+ else if( p_access->pf_read )
p_sys->method = STREAM_METHOD_STREAM;
+ else
+ p_sys->method = STREAM_METHOD_READDIR;
p_sys->i_pos = p_access->info.i_pos;
access_t *p_tmp = access_New( p_access, p_access->p_input,
p_access->psz_access, "", psz_name );
if( !p_tmp )
+ {
+ free( psz_name );
continue;
+ }
p_entry = malloc( sizeof(*p_entry) );
if( p_entry )
goto error;
}
}
- else
+ else if ( p_sys->method == STREAM_METHOD_STREAM )
{
int i;
- assert( p_sys->method == STREAM_METHOD_STREAM );
-
msg_Dbg( s, "Using stream method for AStream*" );
s->pf_read = AStreamReadStream;
goto error;
}
}
+ else
+ {
+ msg_Dbg( s, "Using readdir method for AStream*" );
+
+ assert( p_sys->method == STREAM_METHOD_READDIR );
+ s->pf_readdir = AStreamReadDir;
+ }
return s;
{
/* Nothing yet */
}
- else
+ else if( p_sys->method == STREAM_METHOD_STREAM )
{
free( p_sys->stream.p_buffer );
}
if( p_sys->method == STREAM_METHOD_BLOCK )
block_ChainRelease( p_sys->block.p_first );
- else
+ else if( p_sys->method == STREAM_METHOD_STREAM )
free( p_sys->stream.p_buffer );
free( p_sys->p_peek );
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
- uint64_t *pi_64, i_64;
-
static_control_match(CAN_SEEK);
static_control_match(CAN_FASTSEEK);
static_control_match(CAN_PAUSE);
static_control_match(CAN_CONTROL_PACE);
+ static_control_match(GET_PTS_DELAY);
static_control_match(GET_TITLE_INFO);
+ static_control_match(GET_TITLE);
+ static_control_match(GET_SEEKPOINT);
static_control_match(GET_META);
static_control_match(GET_CONTENT_TYPE);
static_control_match(GET_SIGNAL);
static_control_match(SET_PAUSE_STATE);
static_control_match(SET_TITLE);
static_control_match(SET_SEEKPOINT);
+ static_control_match(SET_PRIVATE_ID_STATE);
+ static_control_match(SET_PRIVATE_ID_CA);
+ static_control_match(GET_PRIVATE_ID_STATE);
switch( i_query )
{
case STREAM_CAN_FASTSEEK:
case STREAM_CAN_PAUSE:
case STREAM_CAN_CONTROL_PACE:
+ case STREAM_GET_PTS_DELAY:
case STREAM_GET_TITLE_INFO:
+ case STREAM_GET_TITLE:
+ case STREAM_GET_SEEKPOINT:
case STREAM_GET_META:
case STREAM_GET_CONTENT_TYPE:
case STREAM_GET_SIGNAL:
case STREAM_SET_PAUSE_STATE:
+ case STREAM_SET_PRIVATE_ID_STATE:
+ case STREAM_SET_PRIVATE_ID_CA:
+ case STREAM_GET_PRIVATE_ID_STATE:
return access_vaControl( p_access, i_query, args );
case STREAM_GET_SIZE:
- pi_64 = va_arg( args, uint64_t * );
+ {
+ uint64_t *pi_64 = va_arg( args, uint64_t * );
if( s->p_sys->i_list )
{
int i;
}
*pi_64 = access_GetSize( p_access );
break;
+ }
case STREAM_GET_POSITION:
- pi_64 = va_arg( args, uint64_t * );
- *pi_64 = p_sys->i_pos;
+ *va_arg( args, uint64_t * ) = p_sys->i_pos;
break;
case STREAM_SET_POSITION:
- i_64 = va_arg( args, uint64_t );
+ {
+ uint64_t offset = va_arg( args, uint64_t );
switch( p_sys->method )
{
case STREAM_METHOD_BLOCK:
- return AStreamSeekBlock( s, i_64 );
+ return AStreamSeekBlock( s, offset );
case STREAM_METHOD_STREAM:
- return AStreamSeekStream( s, i_64 );
+ return AStreamSeekStream( s, offset );
default:
assert(0);
return VLC_EGENERIC;
}
-
- case STREAM_CONTROL_ACCESS:
- {
- int i_int = (int) va_arg( args, int );
- if( i_int != ACCESS_SET_PRIVATE_ID_STATE &&
- i_int != ACCESS_SET_PRIVATE_ID_CA &&
- i_int != ACCESS_GET_PRIVATE_ID_STATE )
- {
- msg_Err( s, "Hey, what are you thinking ?"
- "DON'T USE STREAM_CONTROL_ACCESS !!!" );
- return VLC_EGENERIC;
- }
- return access_vaControl( p_access, i_int, args );
}
case STREAM_UPDATE_SIZE:
return ret;
}
+ case STREAM_IS_DIRECTORY:
+ {
+ bool *pb_canreaddir = va_arg( args, bool * );
+ *pb_canreaddir = p_sys->method == STREAM_METHOD_READDIR;
+ return VLC_SUCCESS;
+ }
+
case STREAM_SET_RECORD_STATE:
default:
msg_Err( s, "invalid stream_vaControl query=0x%x", i_query );
/* Update stat */
p_sys->stat.i_bytes = p_sys->block.i_size;
p_sys->stat.i_read_time = i_date - i_start;
- i_byterate = ( INT64_C(1000000) * p_sys->stat.i_bytes ) /
+ i_byterate = ( CLOCK_FREQ * p_sys->stat.i_bytes ) /
(p_sys->stat.i_read_time + 1);
msg_Dbg( s, "prebuffering done %"PRId64" bytes in %"PRId64"s - "
"%"PRId64" KiB/s",
p_sys->stat.i_bytes,
- p_sys->stat.i_read_time / INT64_C(1000000),
+ p_sys->stat.i_read_time / CLOCK_FREQ,
i_byterate / 1024 );
break;
}
if( p_data == NULL )
{
/* seek within this stream if possible, else use plain old read and discard */
- stream_sys_t *p_sys = s->p_sys;
- access_t *p_access = p_sys->p_access;
- bool b_aseek;
+ access_t *p_access = p_sys->p_access;
+ bool b_aseek;
+
access_Control( p_access, ACCESS_CAN_SEEK, &b_aseek );
if( b_aseek )
return AStreamSeekBlock( s, p_sys->i_pos + i_read ) ? 0 : i_read;
static int AStreamRefillBlock( stream_t *s )
{
stream_sys_t *p_sys = s->p_sys;
- block_t *b;
/* Release data */
while( p_sys->block.i_size >= STREAM_CACHE_SIZE &&
/* Now read a new block */
const int64_t i_start = mdate();
+ block_t *b;
+
for( ;; )
{
bool b_eof;
/* Update stat */
p_sys->stat.i_bytes = i_buffered;
p_sys->stat.i_read_time = i_date - i_start;
- i_byterate = ( INT64_C(1000000) * p_sys->stat.i_bytes ) /
+ i_byterate = ( CLOCK_FREQ * p_sys->stat.i_bytes ) /
(p_sys->stat.i_read_time+1);
msg_Dbg( s, "pre-buffering done %"PRId64" bytes in %"PRId64"s - "
"%"PRId64" KiB/s",
p_sys->stat.i_bytes,
- p_sys->stat.i_read_time / INT64_C(1000000),
+ p_sys->stat.i_read_time / CLOCK_FREQ,
i_byterate / 1024 );
break;
}
char *p_line = NULL;
int i_line = 0, i_read = 0;
+ /* Let's fail quickly if this is a readdir access */
+ if( s->pf_read == NULL )
+ return NULL;
+
for( ;; )
{
char *psz_eol;
return p_access->pf_seek( p_access, i_pos );
}
+static int AStreamReadDir( stream_t *s, input_item_node_t *p_node )
+{
+ access_t *p_access = s->p_sys->p_access;
+
+ return p_access->pf_readdir( p_access, p_node );
+}
/**
* Try to read "i_read" bytes into a buffer pointed by "p_read". If
return p_block;
}
+/**
+ * Returns a node containing all the input_item of the directory pointer by
+ * this stream. returns VLC_SUCCESS on success.
+ */
+int stream_ReadDir( stream_t *s, input_item_node_t *p_node )
+{
+ return s->pf_readdir( s, p_node );
+}