]> git.sesse.net Git - vlc/blobdiff - src/input/stream.c
Ahem: (v)asprintf requires stdio.h; strndup requires string.h
[vlc] / src / input / stream.c
index 26276f59ab4aa993401aefc507532d0f240b89d0..09115af62c2274c7c8917d3e9b46cf6f6caa3c03 100644 (file)
  *
  * 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"
 
@@ -807,7 +808,7 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
 
         if( !b_aseek )
         {
-            msg_Err( s, "backward seek impossible (access non seekable)" );
+            msg_Err( s, "backward seeking impossible (access not seekable)" );
             return VLC_EGENERIC;
         }
 
@@ -1327,7 +1328,7 @@ static void AStreamPrebufferStream( stream_t *s )
         ( (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( ;; )
     {
@@ -1347,7 +1348,7 @@ static void AStreamPrebufferStream( stream_t *s )
             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),
@@ -1465,7 +1466,9 @@ char * stream_ReadLine( stream_t *s )
             /* Open the converter if we need it */
             if( psz_encoding != NULL )
             {
+                input_thread_t *p_input;
                 msg_Dbg( s, "%s BOM detected", psz_encoding );
+                p_input = (input_thread_t *)vlc_object_find( s, VLC_OBJECT_INPUT, FIND_PARENT );
                 if( s->i_char_width > 1 )
                 {
                     s->conv = vlc_iconv_open( "UTF-8", psz_encoding );
@@ -1474,6 +1477,12 @@ char * stream_ReadLine( stream_t *s )
                         msg_Err( s, "iconv_open failed" );
                     }
                 }
+                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 );
             }
         }
@@ -1520,7 +1529,7 @@ char * stream_ReadLine( stream_t *s )
         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;
             
@@ -1564,11 +1573,29 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
 {
     stream_sys_t *p_sys = s->p_sys;
     access_t *p_access = p_sys->p_access;
+    input_thread_t *p_input = NULL;
     int i_read_orig = i_read;
+    int i_total = 0;
+
+    if( s->p_parent && s->p_parent->p_parent &&
+        s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
+        p_input = (input_thread_t *)s->p_parent->p_parent;
 
     if( !p_sys->i_list )
     {
         i_read = p_access->pf_read( p_access, p_read, i_read );
+        if( p_input )
+        {
+            vlc_object_yield( p_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 );
+            vlc_object_release( p_input );
+        }
         return i_read;
     }
 
@@ -1596,6 +1623,18 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
         return AReadStream( s, p_read, i_read_orig );
     }
 
+    /* Update read bytes in input */
+    if( p_input )
+    {
+        vlc_object_yield( p_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 );
+        vlc_object_release( p_input );
+    }
     return i_read;
 }
 
@@ -1603,13 +1642,31 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
 {
     stream_sys_t *p_sys = s->p_sys;
     access_t *p_access = p_sys->p_access;
+    input_thread_t *p_input = NULL;
     block_t *p_block;
     vlc_bool_t b_eof;
+    int i_total = 0;
+
+    if( s->p_parent && s->p_parent->p_parent &&
+        s->p_parent->p_parent->i_object_type == VLC_OBJECT_INPUT )
+        p_input = (input_thread_t *)s->p_parent->p_parent;
 
     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_input &&  p_block && p_access->p_libvlc->b_stats )
+        {
+            vlc_object_yield( p_input );
+            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 );
+            vlc_object_release( p_input );
+        }
         return p_block;
     }
 
@@ -1637,7 +1694,22 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
         /* We have to read some data */
         return AReadBlock( s, pb_eof );
     }
-
+    if( p_block )
+    {
+        if( p_input )
+        {
+            vlc_object_yield( p_input );
+            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 );
+            vlc_object_release( p_input );
+        }
+    }
     return p_block;
 }