Commit 3dcdd8d7 authored by Gildas Bazin's avatar Gildas Bazin

* src/input/control.c: INPUT_ADD/DEL_BOOKMARK also modifies the "bookmarks"...

* src/input/control.c: INPUT_ADD/DEL_BOOKMARK also modifies the "bookmarks" input option so the bookmarks are kept even when the input is stopped.
parent d93ca7c4
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*****************************************************************************/ *****************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/input.h> #include <vlc/input.h>
...@@ -38,6 +39,8 @@ struct input_thread_sys_t ...@@ -38,6 +39,8 @@ struct input_thread_sys_t
int64_t i_stop_time; int64_t i_stop_time;
}; };
static void UpdateBookmarksOption( input_thread_t * );
/**************************************************************************** /****************************************************************************
* input_Control * input_Control
****************************************************************************/ ****************************************************************************/
...@@ -78,6 +81,28 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args ) ...@@ -78,6 +81,28 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
i_ret = VLC_EGENERIC; i_ret = VLC_EGENERIC;
vlc_mutex_lock( &p_input->p_item->lock ); vlc_mutex_lock( &p_input->p_item->lock );
/* Check if option already exists */
for( i = 0; i < p_input->p_item->i_options; i++ )
{
if( !strncmp( p_input->p_item->ppsz_options[i], psz_option,
strlen( psz_option ) ) &&
p_input->p_item->ppsz_options[i][strlen(psz_option)]
== '=' )
{
free( p_input->p_item->ppsz_options[i] );
break;
}
}
if( i == p_input->p_item->i_options )
{
p_input->p_item->i_options++;
p_input->p_item->ppsz_options =
realloc( p_input->p_item->ppsz_options,
p_input->p_item->i_options * sizeof(char **) );
}
asprintf( &p_input->p_item->ppsz_options[i],
"%s=%s", psz_option, psz_value ) ;
vlc_mutex_unlock( &p_input->p_item->lock ); vlc_mutex_unlock( &p_input->p_item->lock );
i_ret = VLC_SUCCESS; i_ret = VLC_SUCCESS;
...@@ -210,6 +235,8 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args ) ...@@ -210,6 +235,8 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
} }
} }
UpdateBookmarksOption( p_input );
i_ret = VLC_SUCCESS; i_ret = VLC_SUCCESS;
break; break;
...@@ -232,6 +259,9 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args ) ...@@ -232,6 +259,9 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE, var_Change( p_input, "bookmark", VLC_VAR_ADDCHOICE,
&val, &text ); &val, &text );
} }
UpdateBookmarksOption( p_input );
i_ret = VLC_SUCCESS; i_ret = VLC_SUCCESS;
} }
else i_ret = VLC_EGENERIC; else i_ret = VLC_EGENERIC;
...@@ -276,6 +306,9 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args ) ...@@ -276,6 +306,9 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
} }
var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 ); var_Change( p_input, "bookmark", VLC_VAR_CLEARCHOICES, 0, 0 );
} }
UpdateBookmarksOption( p_input );
i_ret = VLC_SUCCESS; i_ret = VLC_SUCCESS;
break; break;
...@@ -361,3 +394,40 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args ) ...@@ -361,3 +394,40 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
return i_ret; return i_ret;
} }
static void UpdateBookmarksOption( input_thread_t *p_input )
{
int i, i_len = 0;
char *psz_value = NULL, *psz_next = NULL;
vlc_mutex_unlock( &p_input->stream.stream_lock );
for( i = 0; i < p_input->i_bookmarks; i++ )
{
asprintf( &psz_value, "{name=%s,bytes="I64Fd",time="I64Fd"}",
p_input->pp_bookmarks[i]->psz_name,
p_input->pp_bookmarks[i]->i_byte_offset,
p_input->pp_bookmarks[i]->i_time_offset/1000000 );
i_len += strlen( psz_value );
free( psz_value );
}
for( i = 0; i < p_input->i_bookmarks; i++ )
{
if( !i ) psz_value = psz_next = malloc( i_len + p_input->i_bookmarks );
sprintf( psz_next, "{name=%s,bytes="I64Fd",time="I64Fd"}",
p_input->pp_bookmarks[i]->psz_name,
p_input->pp_bookmarks[i]->i_byte_offset,
p_input->pp_bookmarks[i]->i_time_offset/1000000 );
psz_next += strlen( psz_next );
if( i < p_input->i_bookmarks - 1)
{
*psz_next = ','; psz_next++;
}
}
input_Control( p_input, INPUT_ADD_OPTION, "bookmarks",
psz_value ? psz_value : "" );
vlc_mutex_lock( &p_input->stream.stream_lock );
}
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