mirror of
https://code.videolan.org/videolan/vlc
synced 2024-09-24 20:48:52 +02:00
lib: media_player: split function
Splitting the function allows return statement, which removes the need for break, and simplify the code. It also allows to use a designated initializer for the event structure. The code also move the vlc_assert_unreachable in the new function. By moving the vlc_assert_unreachable after the switch(), we can get warnings when not every cases are handled since there is no default case, and we can keep asserting when it fails to reach any return statement before.
This commit is contained in:
parent
4a35193e39
commit
6d40b91c18
@ -79,6 +79,24 @@ on_current_media_changed(vlc_player_t *player, input_item_t *new_media,
|
||||
libvlc_event_send(&mp->event_manager, &event);
|
||||
}
|
||||
|
||||
static libvlc_event_type_t
|
||||
PlayerStateToLibvlcEventType(enum vlc_player_state new_state)
|
||||
{
|
||||
switch (new_state) {
|
||||
case VLC_PLAYER_STATE_STOPPED:
|
||||
return libvlc_MediaPlayerStopped;
|
||||
case VLC_PLAYER_STATE_STOPPING:
|
||||
return libvlc_MediaPlayerStopping;
|
||||
case VLC_PLAYER_STATE_STARTED:
|
||||
return libvlc_MediaPlayerOpening;
|
||||
case VLC_PLAYER_STATE_PLAYING:
|
||||
return libvlc_MediaPlayerPlaying;
|
||||
case VLC_PLAYER_STATE_PAUSED:
|
||||
return libvlc_MediaPlayerPaused;
|
||||
}
|
||||
vlc_assert_unreachable();
|
||||
}
|
||||
|
||||
static void
|
||||
on_state_changed(vlc_player_t *player, enum vlc_player_state new_state,
|
||||
void *data)
|
||||
@ -87,27 +105,9 @@ on_state_changed(vlc_player_t *player, enum vlc_player_state new_state,
|
||||
|
||||
libvlc_media_player_t *mp = data;
|
||||
|
||||
libvlc_event_t event;
|
||||
switch (new_state) {
|
||||
case VLC_PLAYER_STATE_STOPPED:
|
||||
event.type = libvlc_MediaPlayerStopped;
|
||||
break;
|
||||
case VLC_PLAYER_STATE_STOPPING:
|
||||
event.type = libvlc_MediaPlayerStopping;
|
||||
break;
|
||||
case VLC_PLAYER_STATE_STARTED:
|
||||
event.type = libvlc_MediaPlayerOpening;
|
||||
break;
|
||||
case VLC_PLAYER_STATE_PLAYING:
|
||||
event.type = libvlc_MediaPlayerPlaying;
|
||||
break;
|
||||
case VLC_PLAYER_STATE_PAUSED:
|
||||
event.type = libvlc_MediaPlayerPaused;
|
||||
break;
|
||||
default:
|
||||
vlc_assert_unreachable();
|
||||
}
|
||||
|
||||
libvlc_event_t event = {
|
||||
.type = PlayerStateToLibvlcEventType(new_state)
|
||||
};
|
||||
libvlc_event_send(&mp->event_manager, &event);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user