[vlc-devel] [PATCH] Add option to change network cache while playing video

Paulo Vitor Magacho da Silva pvmagacho at gmail.com
Tue Oct 27 10:45:23 CET 2015


This patch is interesting when a live camera is being played that supports PTZ. When the PTZ
is enabled we want to reduce network cache to allow fast response from the video. 
This patch will allow this transition to happen while the video is playing without the
need to stop and start again, making the change faster.

---
 include/vlc/libvlc_media_player.h |  8 ++++++++
 include/vlc_input.h               |  2 ++
 lib/video.c                       | 11 +++++++++++
 src/input/control.c               |  5 +++++
 src/input/input.c                 |  9 +++++++++
 src/input/input_internal.h        |  2 ++
 6 files changed, 37 insertions(+)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index b0b4208..825293a 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1005,6 +1005,14 @@ LIBVLC_API
 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on );
 
 /**
+ * Reset buffer and set network cache to new PTS delay value.
+ *
+ * \param pts_delay the new network cache value
+ */
+LIBVLC_API
+void libvlc_media_player_reset_caching( libvlc_media_player_t* p_mi, int pts_delay );
+
+/**
  * Get the pixel dimensions of a video.
  *
  * \param p_mi media player
diff --git a/include/vlc_input.h b/include/vlc_input.h
index 81a93d7..d6a4916 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -472,6 +472,8 @@ enum input_query_e
     INPUT_SET_RECORD_STATE, /* arg1=bool    res=can fail */
     INPUT_GET_RECORD_STATE, /* arg1=bool*   res=can fail */
 
+    INPUT_RESET_CACHING,    /* arg1=int */
+
     /* ES */
     INPUT_RESTART_ES,       /* arg1=int (-AUDIO/VIDEO/SPU_ES for the whole category) */
 
diff --git a/lib/video.c b/lib/video.c
index 588aa1d..a62685e 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -165,6 +165,17 @@ libvlc_video_take_snapshot( libvlc_media_player_t *p_mi, unsigned num,
     return 0;
 }
 
+void libvlc_media_player_reset_caching( libvlc_media_player_t* p_mi,
+                                        int pts_delay )
+{
+    input_thread_t *p_input = libvlc_get_input_thread ( p_mi );
+    if ( p_input == NULL )
+      return;
+
+    input_Control( p_input, INPUT_RESET_CACHING, pts_delay );
+    vlc_object_release( p_input );
+}
+
 int libvlc_video_get_size( libvlc_media_player_t *p_mi, unsigned num,
                            unsigned *restrict px, unsigned *restrict py )
 {
diff --git a/src/input/control.c b/src/input/control.c
index 79a1029..113d136 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -511,6 +511,11 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             *pb_bool = var_GetBool( p_input, "record" );
             return VLC_SUCCESS;
 
+        case INPUT_RESET_CACHING:
+            val.i_int = (int)va_arg( args, int );
+            input_ControlPush( p_input, INPUT_CONTROL_RESET_CACHING, &val );
+            return VLC_SUCCESS;
+
         case INPUT_RESTART_ES:
             val.i_int = (int)va_arg( args, int );
             input_ControlPush( p_input, INPUT_CONTROL_RESTART_ES, &val );
diff --git a/src/input/input.c b/src/input/input.c
index 42aa157..e6a7284 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1806,6 +1806,15 @@ static bool Control( input_thread_t *p_input,
                             ES_OUT_RESTART_ES_BY_ID, (int)val.i_int );
             break;
 
+        case INPUT_CONTROL_RESET_CACHING:
+        {
+            int i_pts_delay = (int)val.i_int;
+            const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
+            es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESET_PCR );
+            es_out_SetJitter( p_input->p->p_es_out_display, i_pts_delay, 0, i_cr_average );
+            break;
+        }
+
         case INPUT_CONTROL_SET_AUDIO_DELAY:
             input_SendEventAudioDelay( p_input, val.i_int );
             UpdatePtsDelay( p_input );
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index cf27ff3..a26a742 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -199,6 +199,8 @@ enum input_control_e
     INPUT_CONTROL_NAV_LEFT,
     INPUT_CONTROL_NAV_RIGHT,
 
+    INPUT_CONTROL_RESET_CACHING,
+
     INPUT_CONTROL_SET_ES,
     INPUT_CONTROL_RESTART_ES,
 
-- 
2.3.8 (Apple Git-58)



More information about the vlc-devel mailing list