*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <stdlib.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
+#include <assert.h>
#include "input_internal.h"
+#undef STREAM_DEBUG
+
/* TODO:
* - tune the 2 methods
* - compute cost for seek
b = b->p_next;
}
- if( p_access->info.b_prebuffered )
+ if( p_access->info.b_prebuffered )
{
/* Access has already prebufferred - update stats and exit */
p_sys->stat.i_bytes = p_sys->block.i_size;
if( !b_aseek )
{
- msg_Err( s, "backward seek impossible (access non seekable)" );
+ msg_Err( s, "backward seeking impossible (access not seekable)" );
return VLC_EGENERIC;
}
}
else
{
- /* Read enought data */
+ /* Read enough data */
while( p_sys->block.i_start + p_sys->block.i_size < i_pos )
{
if( AStreamRefillBlock( s ) )
return AStreamSeekStream( s, p_sys->i_pos + i_read ) ? 0 : i_read;
}
-#if 0
+#ifdef STREAM_DEBUG
msg_Dbg( s, "AStreamReadStream: %d pos="I64Fd" tk=%d start="I64Fd
" offset=%d end="I64Fd,
i_read, p_sys->i_pos, p_sys->stream.i_tk,
if( tk->i_start >= tk->i_end ) return 0; /* EOF */
-#if 0
+#ifdef STREAM_DEBUG
msg_Dbg( s, "AStreamPeekStream: %d pos="I64Fd" tk=%d "
"start="I64Fd" offset=%d end="I64Fd,
i_read, p_sys->i_pos, p_sys->stream.i_tk,
int i_new;
int i;
-#if 0
+#ifdef STREAM_DEBUG
msg_Dbg( s, "AStreamSeekStream: to "I64Fd" pos="I64Fd
- "tk=%d start="I64Fd" offset=%d end="I64Fd,
+ " tk=%d start="I64Fd" offset=%d end="I64Fd,
i_pos, p_sys->i_pos, p_sys->stream.i_tk,
p_sys->stream.tk[p_sys->stream.i_tk].i_start,
p_sys->stream.i_offset,
if( i_pos >= p_sys->stream.tk[p_sys->stream.i_tk].i_start &&
i_pos < p_sys->stream.tk[p_sys->stream.i_tk].i_end )
{
- //msg_Dbg( s, "AStreamSeekStream: current track" );
+ stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
+#ifdef STREAM_DEBUG
+ msg_Dbg( s, "AStreamSeekStream: current track" );
+#endif
p_sys->i_pos = i_pos;
- p_sys->stream.i_offset = i_pos - p_sys->stream.tk[p_sys->stream.i_tk].i_start;
+ p_sys->stream.i_offset = i_pos - tk->i_start;
+
+ /* If there is not enough data left in the track, refill */
+ /* \todo How to get a correct value for
+ * - refilling threshold
+ * - how much to refill
+ */
+ if( (tk->i_end - tk->i_start ) - p_sys->stream.i_offset <
+ p_sys->stream.i_read_size )
+ {
+ if( p_sys->stream.i_used < STREAM_READ_ATONCE / 2 )
+ {
+ p_sys->stream.i_used = STREAM_READ_ATONCE / 2 ;
+ AStreamRefillStream( s );
+ }
+ }
return VLC_SUCCESS;
}
if( i_pos >= tk->i_start && i_pos <= tk->i_end )
{
-#if 0
+#ifdef STREAM_DEBUG
msg_Dbg( s, "AStreamSeekStream: reusing %d start="I64Fd
" end="I64Fd, i, tk->i_start, tk->i_end );
#endif
+
/* Seek at the end of the buffer */
if( ASeek( s, tk->i_end ) ) return VLC_EGENERIC;
if( i_toread <= 0 ) return VLC_EGENERIC; /* EOF */
- /* msg_Dbg( s, "AStreamRefillStream: toread=%d", i_toread ); */
+#ifdef STREAM_DEBUG
+ msg_Dbg( s, "AStreamRefillStream: used=%d toread=%d",
+ p_sys->stream.i_used, i_toread );
+#endif
i_start = mdate();
while( i_toread > 0 )
( (p_access->info.i_title > 1 || p_access->info.i_seekpoint > 1) ?
STREAM_CACHE_PREBUFFER_SIZE : STREAM_CACHE_TRACK_SIZE / 3 );
- msg_Dbg( s, "pre buffering" );
+ msg_Dbg( s, "pre-buffering..." );
i_start = mdate();
for( ;; )
{
i_byterate = ( I64C(1000000) * p_sys->stat.i_bytes ) /
(p_sys->stat.i_read_time+1);
- msg_Dbg( s, "prebuffering done "I64Fd" bytes in "I64Fd"s - "
+ msg_Dbg( s, "pre-buffering done "I64Fd" bytes in "I64Fd"s - "
I64Fd" kbytes/s",
p_sys->stat.i_bytes,
p_sys->stat.i_read_time / I64C(1000000),
/* Open the converter if we need it */
if( psz_encoding != NULL )
{
+ input_thread_t *p_input;
msg_Dbg( s, "%s BOM detected", psz_encoding );
if( s->i_char_width > 1 )
{
{
msg_Err( s, "iconv_open failed" );
}
+ var_Create( s->p_parent->p_parent, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+ var_SetString( s->p_parent->p_parent, "subsdec-encoding", "UTF-8" );
+ }
+ p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT );
+ if( p_input != NULL)
+ {
+ var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+ var_SetString( p_input, "subsdec-encoding", "UTF-8" );
+ vlc_object_release( p_input );
}
if( psz_encoding ) free( psz_encoding );
}
if( s->i_char_width > 1 )
{
size_t i_in = 0, i_out = 0;
- char * p_in = NULL;
+ const char * p_in = NULL;
char * p_out = NULL;
char * psz_new_line = NULL;
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
int i_read_orig = i_read;
+ int i_total;
+
+ input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ;
+ assert( p_input );
if( !p_sys->i_list )
{
i_read = p_access->pf_read( p_access, p_read, i_read );
+ vlc_mutex_lock( &p_input->counters.counters_lock );
+ stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read,
+ &i_total );
+ stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
+ (float)i_total, NULL );
+ stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
+ vlc_mutex_unlock( &p_input->counters.counters_lock );
return i_read;
}
return AReadStream( s, p_read, i_read_orig );
}
+ /* Update read bytes in input */
+ vlc_mutex_lock( &p_input->counters.counters_lock );
+ stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, &i_total );
+ stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
+ (float)i_total, NULL );
+ stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
+ vlc_mutex_unlock( &p_input->counters.counters_lock );
return i_read;
}
access_t *p_access = p_sys->p_access;
block_t *p_block;
vlc_bool_t b_eof;
+ int i_total;
+
+ input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ;
+ assert( p_input );
if( !p_sys->i_list )
{
p_block = p_access->pf_block( p_access );
if( pb_eof ) *pb_eof = p_access->info.b_eof;
+ if( p_block && p_access->p_libvlc->b_stats )
+ {
+ vlc_mutex_lock( &p_input->counters.counters_lock );
+ stats_UpdateInteger( s, p_input->counters.p_read_bytes,
+ p_block->i_buffer, &i_total );
+ stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
+ (float)i_total, NULL );
+ stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
+ vlc_mutex_unlock( &p_input->counters.counters_lock );
+ }
return p_block;
}
/* We have to read some data */
return AReadBlock( s, pb_eof );
}
-
+ if( p_block )
+ {
+ vlc_mutex_lock( &p_input->counters.counters_lock );
+ stats_UpdateInteger( s, p_input->counters.p_read_bytes,
+ p_block->i_buffer, &i_total );
+ stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
+ (float)i_total, NULL );
+ stats_UpdateInteger( s, p_input->counters.p_read_packets,
+ 1 , NULL);
+ vlc_mutex_unlock( &p_input->counters.counters_lock );
+ }
return p_block;
}