[vlc-commits] [Git][videolan/vlc][master] 3 commits: player: add methods to explicitly set AB loop by time/position
Steve Lhomme (@robUx4)
gitlab at videolan.org
Mon Jan 27 09:25:53 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
df808ad3 by Mark Lee at 2025-01-27T08:47:51+00:00
player: add methods to explicitly set AB loop by time/position
- - - - -
07d15098 by Mark Lee at 2025-01-27T08:47:51+00:00
libvlc: add new API to set AB loop explicitly
Adds:
- libvlc_media_player_set_abloop_time
- libvlc_media_player_set_abloop_position
- libvlc_media_player_reset_abloop
These new methods allow to set a specific start and end time or
position to setup an AB loop, and a way to remove the loop.
There must be an active input before setting the AB loop.
- - - - -
ccd05000 by Mark Lee at 2025-01-27T08:47:51+00:00
libvlc: remove libvlc_media_player_set_abloop
This is superseded by new API methods to set an AB loop with
specific start and end times/positions.
- - - - -
6 changed files:
- include/vlc/libvlc_media_player.h
- include/vlc_player.h
- lib/libvlc.sym
- lib/media_player.c
- src/libvlccore.sym
- src/player/player.c
Changes:
=====================================
include/vlc/libvlc_media_player.h
=====================================
@@ -1319,21 +1319,46 @@ LIBVLC_API int libvlc_media_player_set_position( libvlc_media_player_t *p_mi,
double f_pos, bool b_fast );
/**
- * Enable A to B loop for the current media
+ * Enable A to B loop for the current media by setting the start time and end
+ * time
*
- * This function need to be called 2 times with libvlc_abloop_a and
- * libvlc_abloop_b to setup an A to B loop. It uses and stores the
- * current time/position when called. The B time must be higher than the
- * A time.
+ * The B time must be higher than the A time.
*
* \param p_mi the Media Player
- * \param abloop select which A/B cursor to set
+ * \param a_time start time for the loop (in ms)
+ * \param b_time end time for the loop (in ms)
* \return 0 on success, -1 on error
* \version LibVLC 4.0.0 and later.
*/
LIBVLC_API int
-libvlc_media_player_set_abloop( libvlc_media_player_t *p_mi,
- libvlc_abloop_t abloop );
+libvlc_media_player_set_abloop_time( libvlc_media_player_t *p_mi,
+ libvlc_time_t a_time, libvlc_time_t b_time );
+
+/**
+ * Enable A to B loop for the current media by setting the start position and
+ * end position
+ *
+ * The B position must be higher than the A position.
+ *
+ * \param p_mi the Media Player
+ * \param a_pos start position for the loop
+ * \param b_pos end position for the loop
+ * \return 0 on success, -1 on error
+ * \version LibVLC 4.0.0 and later.
+ */
+LIBVLC_API int
+libvlc_media_player_set_abloop_position( libvlc_media_player_t *p_mi,
+ double a_pos, double b_pos );
+
+/**
+ * Reset/remove the A to B loop for the current media
+ *
+ * \param p_mi the Media Player
+ * \return 0 on success, -1 on error
+ * \version LibVLC 4.0.0 and later.
+ */
+LIBVLC_API int
+libvlc_media_player_reset_abloop( libvlc_media_player_t *p_mi );
/**
* Get the A to B loop status
=====================================
include/vlc_player.h
=====================================
@@ -767,6 +767,41 @@ vlc_player_DisplayPosition(vlc_player_t *player);
VLC_API int
vlc_player_SetAtoBLoop(vlc_player_t *player, enum vlc_player_abloop abloop);
+/**
+ * Enable A to B loop of the current media by setting start and end time
+ *
+ * The B time must be higher than the A time.
+ *
+ * @param player locked player instance
+ * @param a_time start time for the loop
+ * @param b_time end time for the loop
+ * @return VLC_SUCCESS or a VLC error code
+ */
+VLC_API int
+vlc_player_SetAtoBLoopTime(vlc_player_t *player, vlc_tick_t a_time, vlc_tick_t b_time);
+
+/**
+ * Enable A to B loop of the current media by setting start and end position
+ *
+ * The B position must be higher than the A position.
+ *
+ * @param player locked player instance
+ * @param a_pos start position for the loop
+ * @param b_pos end position for the loop
+ * @return VLC_SUCCESS or a VLC error code
+ */
+VLC_API int
+vlc_player_SetAtoBLoopPosition(vlc_player_t *player, double a_pos, double b_pos);
+
+/**
+ * Reset/remove the A to B loop of the current media
+ *
+ * @param player locked player instance
+ * @return VLC_SUCCESS or a VLC error code
+ */
+VLC_API int
+vlc_player_ResetAtoBLoop(vlc_player_t *player);
+
/**
* Get the A to B loop status
*
=====================================
lib/libvlc.sym
=====================================
@@ -187,7 +187,9 @@ libvlc_media_player_select_track
libvlc_media_player_unselect_track_type
libvlc_media_player_select_tracks
libvlc_media_player_select_tracks_by_ids
-libvlc_media_player_set_abloop
+libvlc_media_player_set_abloop_time
+libvlc_media_player_set_abloop_position
+libvlc_media_player_reset_abloop
libvlc_media_player_get_abloop
libvlc_player_program_delete
libvlc_player_programlist_count
=====================================
lib/media_player.c
=====================================
@@ -1403,16 +1403,49 @@ double libvlc_media_player_get_position( libvlc_media_player_t *p_mi )
}
int
-libvlc_media_player_set_abloop( libvlc_media_player_t *p_mi,
- libvlc_abloop_t abloop )
+libvlc_media_player_set_abloop_time( libvlc_media_player_t *p_mi,
+ libvlc_time_t a_time, libvlc_time_t b_time )
{
+ vlc_tick_t a_tick = vlc_tick_from_libvlc_time(a_time);
+ if (a_tick >= 0)
+ a_tick += VLC_TICK_0;
+
+ vlc_tick_t b_tick = vlc_tick_from_libvlc_time(b_time);
+ if (b_tick >= 0)
+ b_tick += VLC_TICK_0;
+
vlc_player_t *player = p_mi->player;
vlc_player_Lock(player);
- int ret = vlc_player_SetAtoBLoop(player, (int) abloop);
+ int ret = vlc_player_SetAtoBLoopTime(player, a_tick, b_tick);
vlc_player_Unlock(player);
- return ret;
+ return ret == VLC_SUCCESS ? 0 : -1;
+}
+
+int
+libvlc_media_player_set_abloop_position( libvlc_media_player_t *p_mi,
+ double a_pos, double b_pos )
+{
+ vlc_player_t *player = p_mi->player;
+ vlc_player_Lock(player);
+
+ int ret = vlc_player_SetAtoBLoopPosition(player, a_pos, b_pos);
+
+ vlc_player_Unlock(player);
+ return ret == VLC_SUCCESS ? 0 : -1;
+}
+
+int
+libvlc_media_player_reset_abloop( libvlc_media_player_t *p_mi )
+{
+ vlc_player_t *player = p_mi->player;
+ vlc_player_Lock(player);
+
+ int ret = vlc_player_ResetAtoBLoop(player);
+
+ vlc_player_Unlock(player);
+ return ret == VLC_SUCCESS ? 0 : -1;
}
libvlc_abloop_t
=====================================
src/libvlccore.sym
=====================================
@@ -922,6 +922,9 @@ vlc_player_SelectTitleIdx
vlc_player_SelectTracksByStringIds
vlc_player_SetAssociatedSubsFPS
vlc_player_SetAtoBLoop
+vlc_player_SetAtoBLoopTime
+vlc_player_SetAtoBLoopPosition
+vlc_player_ResetAtoBLoop
vlc_player_GetAtoBLoop
vlc_player_SetCategoryDelay
vlc_player_SetCurrentMedia
=====================================
src/player/player.c
=====================================
@@ -1513,6 +1513,83 @@ vlc_player_SetAtoBLoop(vlc_player_t *player, enum vlc_player_abloop abloop)
return ret;
}
+int
+vlc_player_SetAtoBLoopTime(vlc_player_t *player, vlc_tick_t a_time, vlc_tick_t b_time)
+{
+ if (a_time < 0 || b_time < 0)
+ return VLC_EINVAL;
+
+ if (a_time == VLC_TICK_INVALID || b_time == VLC_TICK_INVALID)
+ return VLC_EINVAL;
+
+ if (b_time <= a_time)
+ return VLC_EINVAL;
+
+ struct vlc_player_input *input = vlc_player_get_input_locked(player);
+
+ if (!input || !vlc_player_CanSeek(player))
+ return VLC_EGENERIC;
+
+ input->abloop_state[0].time = a_time;
+ input->abloop_state[0].pos = 0;
+ input->abloop_state[0].set = true;
+ input->abloop_state[1].time = b_time;
+ input->abloop_state[1].pos = 0;
+ input->abloop_state[1].set = true;
+
+ vlc_player_SetTime(player, a_time);
+
+ vlc_player_SendEvent(player, on_atobloop_changed, VLC_PLAYER_ABLOOP_A, a_time, 0);
+ vlc_player_SendEvent(player, on_atobloop_changed, VLC_PLAYER_ABLOOP_B, b_time, 0);
+ return VLC_SUCCESS;
+}
+
+int
+vlc_player_SetAtoBLoopPosition(vlc_player_t *player, double a_pos, double b_pos)
+{
+ if (a_pos < 0 || a_pos > 1.0 || b_pos < 0 || b_pos > 1.0)
+ return VLC_EINVAL;
+
+ if (b_pos <= a_pos)
+ return VLC_EINVAL;
+
+ struct vlc_player_input *input = vlc_player_get_input_locked(player);
+
+ if (!input || !vlc_player_CanSeek(player))
+ return VLC_EGENERIC;
+
+ input->abloop_state[0].time = VLC_TICK_INVALID;
+ input->abloop_state[0].pos = a_pos;
+ input->abloop_state[0].set = true;
+ input->abloop_state[1].time = VLC_TICK_INVALID;
+ input->abloop_state[1].pos = b_pos;
+ input->abloop_state[1].set = true;
+
+ vlc_player_SetPosition(player, a_pos);
+
+ vlc_player_SendEvent(player, on_atobloop_changed, VLC_PLAYER_ABLOOP_A, VLC_TICK_INVALID, a_pos);
+ vlc_player_SendEvent(player, on_atobloop_changed, VLC_PLAYER_ABLOOP_B, VLC_TICK_INVALID, b_pos);
+ return VLC_SUCCESS;
+}
+
+int
+vlc_player_ResetAtoBLoop(vlc_player_t *player) {
+ struct vlc_player_input *input = vlc_player_get_input_locked(player);
+
+ if (!input || !vlc_player_CanSeek(player))
+ return VLC_EGENERIC;
+
+ input->abloop_state[0].time = VLC_TICK_INVALID;
+ input->abloop_state[0].pos = 0;
+ input->abloop_state[0].set = false;
+ input->abloop_state[1].time = VLC_TICK_INVALID;
+ input->abloop_state[1].pos = 0;
+ input->abloop_state[1].set = false;
+
+ vlc_player_SendEvent(player, on_atobloop_changed, VLC_PLAYER_ABLOOP_NONE, VLC_TICK_INVALID, 0);
+ return VLC_SUCCESS;
+}
+
enum vlc_player_abloop
vlc_player_GetAtoBLoop(vlc_player_t *player, vlc_tick_t *a_time, double *a_pos,
vlc_tick_t *b_time, double *b_pos)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ec9c87d20f110e2583b81c8d49054eb72cf2058e...ccd050001147e010f9e348f13588425e0ed97b19
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ec9c87d20f110e2583b81c8d49054eb72cf2058e...ccd050001147e010f9e348f13588425e0ed97b19
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list