From 5da635c2da9a427bb8b2c60bca0ba852e1642d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 26 Oct 2024 11:42:48 +0300 Subject: [PATCH] play: Improve play message API inconsistencies * Consistently name parse functions according to their message type and deprecate the misnamed ones, * Add missing parse functions, * Check for the correct message type when parsing * Use correct field name for warning message details Part-of: --- girs/GstPlay-1.0.gir | 184 +++++++++++++++--- .../gst-libs/gst/play/gstplay.c | 147 ++++++++++---- .../gst-libs/gst/play/gstplay.h | 16 +- 3 files changed, 287 insertions(+), 60 deletions(-) diff --git a/girs/GstPlay-1.0.gir b/girs/GstPlay-1.0.gir index 2b7bc5451d..796b6640ce 100644 --- a/girs/GstPlay-1.0.gir +++ b/girs/GstPlay-1.0.gir @@ -1812,8 +1812,8 @@ See also #gst_play_get_message_bus() - - Parse the given buffering-percent @msg and extract the corresponding value + + Parse the given buffering @msg and extract the corresponding value @@ -1829,8 +1829,44 @@ See also #gst_play_get_message_bus() - - Parse the given duration @msg and extract the corresponding #GstClockTime + + Parse the given buffering @msg and extract the corresponding value + Use gst_play_message_parse_buffering(). + + + + + + + A #GstMessage + + + + the resulting buffering percent + + + + + + Parse the given duration-changed @msg and extract the corresponding #GstClockTime + + + + + + + A #GstMessage + + + + the resulting duration + + + + + + Parse the given duration-changed @msg and extract the corresponding #GstClockTime + Use gst_play_message_parse_duration_changed(). @@ -1868,7 +1904,7 @@ See also #gst_play_get_message_bus() - Parse the given @msg and extract the corresponding media information + Parse the given media-info-updated @msg and extract the corresponding media information @@ -1885,7 +1921,7 @@ See also #gst_play_get_message_bus() - Parse the given @msg and extract the corresponding audio muted state + Parse the given mute-changed @msg and extract the corresponding audio muted state @@ -1902,7 +1938,24 @@ See also #gst_play_get_message_bus() - Parse the given position @msg and extract the corresponding #GstClockTime + Parse the given position-updated @msg and extract the corresponding #GstClockTime + + + + + + + A #GstMessage + + + + the resulting position + + + + + + Parse the given seek-done @msg and extract the corresponding #GstClockTime @@ -1919,7 +1972,7 @@ See also #gst_play_get_message_bus() - Parse the given state @msg and extract the corresponding #GstPlayState + Parse the given state-changed @msg and extract the corresponding #GstPlayState @@ -1952,8 +2005,25 @@ See also #gst_play_get_message_bus() + + Parse the given uri-loaded @msg and extract the corresponding value + + + + + + + A #GstMessage + + + + the resulting URI + + + + - Parse the given @msg and extract the corresponding video dimensions + Parse the given video-dimensions-changed @msg and extract the corresponding video dimensions @@ -1974,7 +2044,7 @@ See also #gst_play_get_message_bus() - Parse the given @msg and extract the corresponding audio volume + Parse the given volume-changed @msg and extract the corresponding audio volume @@ -1991,7 +2061,7 @@ See also #gst_play_get_message_bus() - Parse the given error @msg and extract the corresponding #GError warning + Parse the given warning @msg and extract the corresponding #GError @@ -2755,8 +2825,8 @@ freed using gst_play_visualization_free(). - - Parse the given buffering-percent @msg and extract the corresponding value + + Parse the given buffering @msg and extract the corresponding value @@ -2772,8 +2842,44 @@ freed using gst_play_visualization_free(). - - Parse the given duration @msg and extract the corresponding #GstClockTime + + Parse the given buffering @msg and extract the corresponding value + Use gst_play_message_parse_buffering(). + + + + + + + A #GstMessage + + + + the resulting buffering percent + + + + + + Parse the given duration-changed @msg and extract the corresponding #GstClockTime + + + + + + + A #GstMessage + + + + the resulting duration + + + + + + Parse the given duration-changed @msg and extract the corresponding #GstClockTime + Use gst_play_message_parse_duration_changed(). @@ -2811,7 +2917,7 @@ freed using gst_play_visualization_free(). - Parse the given @msg and extract the corresponding media information + Parse the given media-info-updated @msg and extract the corresponding media information @@ -2828,7 +2934,7 @@ freed using gst_play_visualization_free(). - Parse the given @msg and extract the corresponding audio muted state + Parse the given mute-changed @msg and extract the corresponding audio muted state @@ -2845,7 +2951,24 @@ freed using gst_play_visualization_free(). - Parse the given position @msg and extract the corresponding #GstClockTime + Parse the given position-updated @msg and extract the corresponding #GstClockTime + + + + + + + A #GstMessage + + + + the resulting position + + + + + + Parse the given seek-done @msg and extract the corresponding #GstClockTime @@ -2862,7 +2985,7 @@ freed using gst_play_visualization_free(). - Parse the given state @msg and extract the corresponding #GstPlayState + Parse the given state-changed @msg and extract the corresponding #GstPlayState @@ -2895,8 +3018,25 @@ freed using gst_play_visualization_free(). + + Parse the given uri-loaded @msg and extract the corresponding value + + + + + + + A #GstMessage + + + + the resulting URI + + + + - Parse the given @msg and extract the corresponding video dimensions + Parse the given video-dimensions-changed @msg and extract the corresponding video dimensions @@ -2917,7 +3057,7 @@ freed using gst_play_visualization_free(). - Parse the given @msg and extract the corresponding audio volume + Parse the given volume-changed @msg and extract the corresponding audio volume @@ -2934,7 +3074,7 @@ freed using gst_play_visualization_free(). - Parse the given error @msg and extract the corresponding #GError warning + Parse the given warning @msg and extract the corresponding #GError diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c index 3f46c13788..09227788f9 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c @@ -4696,9 +4696,12 @@ gst_play_is_play_message (GstMessage * msg) return g_str_equal (gst_structure_get_name (data), GST_PLAY_MESSAGE_DATA); } -#define PARSE_MESSAGE_FIELD(msg, field, value_type, value) G_STMT_START { \ +#define PARSE_MESSAGE_FIELD(msg, expected_msg_type, field, value_type, value) G_STMT_START { \ const GstStructure *data = NULL; \ + GstPlayMessage msg_type; \ g_return_if_fail (gst_play_is_play_message (msg)); \ + gst_play_message_parse_type (msg, &msg_type); \ + g_return_if_fail (msg_type == expected_msg_type); \ data = gst_message_get_structure (msg); \ gst_structure_get (data, field, value_type, value, NULL); \ } G_STMT_END @@ -4715,8 +4718,44 @@ gst_play_is_play_message (GstMessage * msg) void gst_play_message_parse_type (GstMessage * msg, GstPlayMessage * type) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_TYPE, - GST_TYPE_PLAY_MESSAGE, type); + const GstStructure *data = NULL; + g_return_if_fail (gst_play_is_play_message (msg)); + data = gst_message_get_structure (msg); + gst_structure_get (data, GST_PLAY_MESSAGE_DATA_TYPE, GST_TYPE_PLAY_MESSAGE, + type, NULL); +} + +/** + * gst_play_message_parse_uri_loaded: + * @msg: A #GstMessage + * @uri: (out) (optional) (transfer full): the resulting URI + * + * Parse the given uri-loaded @msg and extract the corresponding value + * + * Since: 1.26 + */ +void +gst_play_message_parse_uri_loaded (GstMessage * msg, gchar ** uri) +{ + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_URI_LOADED, + GST_PLAY_MESSAGE_DATA_URI, G_TYPE_STRING, uri); +} + +/** + * gst_play_message_parse_duration_changed: + * @msg: A #GstMessage + * @duration: (out) (optional): the resulting duration + * + * Parse the given duration-changed @msg and extract the corresponding #GstClockTime + * + * Since: 1.26 + */ +void +gst_play_message_parse_duration_changed (GstMessage * msg, + GstClockTime * duration) +{ + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DURATION_CHANGED, + GST_PLAY_MESSAGE_DATA_DURATION, GST_TYPE_CLOCK_TIME, duration); } /** @@ -4724,16 +4763,17 @@ gst_play_message_parse_type (GstMessage * msg, GstPlayMessage * type) * @msg: A #GstMessage * @duration: (out) (optional): the resulting duration * - * Parse the given duration @msg and extract the corresponding #GstClockTime + * Parse the given duration-changed @msg and extract the corresponding #GstClockTime * * Since: 1.20 + * + * Deprecated: 1.26: Use gst_play_message_parse_duration_changed(). */ void gst_play_message_parse_duration_updated (GstMessage * msg, GstClockTime * duration) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_DURATION, - GST_TYPE_CLOCK_TIME, duration); + gst_play_message_parse_duration_changed (msg, duration); } /** @@ -4741,7 +4781,7 @@ gst_play_message_parse_duration_updated (GstMessage * msg, * @msg: A #GstMessage * @position: (out) (optional): the resulting position * - * Parse the given position @msg and extract the corresponding #GstClockTime + * Parse the given position-updated @msg and extract the corresponding #GstClockTime * * Since: 1.20 */ @@ -4749,8 +4789,8 @@ void gst_play_message_parse_position_updated (GstMessage * msg, GstClockTime * position) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_POSITION, - GST_TYPE_CLOCK_TIME, position); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_POSITION_UPDATED, + GST_PLAY_MESSAGE_DATA_POSITION, GST_TYPE_CLOCK_TIME, position); } /** @@ -4758,15 +4798,31 @@ gst_play_message_parse_position_updated (GstMessage * msg, * @msg: A #GstMessage * @state: (out) (optional): the resulting play state * - * Parse the given state @msg and extract the corresponding #GstPlayState + * Parse the given state-changed @msg and extract the corresponding #GstPlayState * * Since: 1.20 */ void gst_play_message_parse_state_changed (GstMessage * msg, GstPlayState * state) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_PLAY_STATE, - GST_TYPE_PLAY_STATE, state); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_STATE_CHANGED, + GST_PLAY_MESSAGE_DATA_PLAY_STATE, GST_TYPE_PLAY_STATE, state); +} + +/** + * gst_play_message_parse_buffering: + * @msg: A #GstMessage + * @percent: (out) (optional): the resulting buffering percent + * + * Parse the given buffering @msg and extract the corresponding value + * + * Since: 1.26 + */ +void +gst_play_message_parse_buffering (GstMessage * msg, guint * percent) +{ + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_BUFFERING, + GST_PLAY_MESSAGE_DATA_BUFFERING_PERCENT, G_TYPE_UINT, percent); } /** @@ -4774,15 +4830,16 @@ gst_play_message_parse_state_changed (GstMessage * msg, GstPlayState * state) * @msg: A #GstMessage * @percent: (out) (optional): the resulting buffering percent * - * Parse the given buffering-percent @msg and extract the corresponding value + * Parse the given buffering @msg and extract the corresponding value * * Since: 1.20 + * + * Deprecated: 1.26: Use gst_play_message_parse_buffering(). */ void gst_play_message_parse_buffering_percent (GstMessage * msg, guint * percent) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_BUFFERING_PERCENT, - G_TYPE_UINT, percent); + gst_play_message_parse_buffering (msg, percent); } /** @@ -4799,9 +4856,10 @@ void gst_play_message_parse_error (GstMessage * msg, GError ** error, GstStructure ** details) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_ERROR, G_TYPE_ERROR, error); - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_ERROR_DETAILS, - GST_TYPE_STRUCTURE, details); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_ERROR, GST_PLAY_MESSAGE_DATA_ERROR, + G_TYPE_ERROR, error); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_ERROR, + GST_PLAY_MESSAGE_DATA_ERROR_DETAILS, GST_TYPE_STRUCTURE, details); } /** @@ -4810,7 +4868,7 @@ gst_play_message_parse_error (GstMessage * msg, GError ** error, * @error: (out) (optional) (transfer full): the resulting warning * @details: (out) (optional) (nullable) (transfer full): A #GstStructure containing additional details about the warning * - * Parse the given error @msg and extract the corresponding #GError warning + * Parse the given warning @msg and extract the corresponding #GError * * Since: 1.20 */ @@ -4818,9 +4876,10 @@ void gst_play_message_parse_warning (GstMessage * msg, GError ** error, GstStructure ** details) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_WARNING, G_TYPE_ERROR, error); - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_WARNING, GST_TYPE_STRUCTURE, - details); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_WARNING, + GST_PLAY_MESSAGE_DATA_WARNING, G_TYPE_ERROR, error); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_WARNING, + GST_PLAY_MESSAGE_DATA_WARNING_DETAILS, GST_TYPE_STRUCTURE, details); } /** @@ -4829,7 +4888,7 @@ gst_play_message_parse_warning (GstMessage * msg, GError ** error, * @width: (out) (optional): the resulting video width * @height: (out) (optional): the resulting video height * - * Parse the given @msg and extract the corresponding video dimensions + * Parse the given video-dimensions-changed @msg and extract the corresponding video dimensions * * Since: 1.20 */ @@ -4837,10 +4896,10 @@ void gst_play_message_parse_video_dimensions_changed (GstMessage * msg, guint * width, guint * height) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_VIDEO_WIDTH, - G_TYPE_UINT, width); - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_VIDEO_HEIGHT, - G_TYPE_UINT, height); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_VIDEO_DIMENSIONS_CHANGED, + GST_PLAY_MESSAGE_DATA_VIDEO_WIDTH, G_TYPE_UINT, width); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_VIDEO_DIMENSIONS_CHANGED, + GST_PLAY_MESSAGE_DATA_VIDEO_HEIGHT, G_TYPE_UINT, height); } /** @@ -4848,7 +4907,7 @@ gst_play_message_parse_video_dimensions_changed (GstMessage * msg, * @msg: A #GstMessage * @info: (out) (optional) (transfer full): the resulting media info * - * Parse the given @msg and extract the corresponding media information + * Parse the given media-info-updated @msg and extract the corresponding media information * * Since: 1.20 */ @@ -4856,8 +4915,8 @@ void gst_play_message_parse_media_info_updated (GstMessage * msg, GstPlayMediaInfo ** info) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_MEDIA_INFO, - GST_TYPE_PLAY_MEDIA_INFO, info); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_MEDIA_INFO_UPDATED, + GST_PLAY_MESSAGE_DATA_MEDIA_INFO, GST_TYPE_PLAY_MEDIA_INFO, info); } /** @@ -4865,15 +4924,15 @@ gst_play_message_parse_media_info_updated (GstMessage * msg, * @msg: A #GstMessage * @volume: (out) (optional): the resulting audio volume * - * Parse the given @msg and extract the corresponding audio volume + * Parse the given volume-changed @msg and extract the corresponding audio volume * * Since: 1.20 */ void gst_play_message_parse_volume_changed (GstMessage * msg, gdouble * volume) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_VOLUME, G_TYPE_DOUBLE, - volume); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_VOLUME_CHANGED, + GST_PLAY_MESSAGE_DATA_VOLUME, G_TYPE_DOUBLE, volume); } /** @@ -4881,13 +4940,29 @@ gst_play_message_parse_volume_changed (GstMessage * msg, gdouble * volume) * @msg: A #GstMessage * @muted: (out) (optional): the resulting audio muted state * - * Parse the given @msg and extract the corresponding audio muted state + * Parse the given mute-changed @msg and extract the corresponding audio muted state * * Since: 1.20 */ void gst_play_message_parse_muted_changed (GstMessage * msg, gboolean * muted) { - PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_DATA_IS_MUTED, G_TYPE_BOOLEAN, - muted); + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_MUTE_CHANGED, + GST_PLAY_MESSAGE_DATA_IS_MUTED, G_TYPE_BOOLEAN, muted); +} + +/** + * gst_play_message_parse_seek_done: + * @msg: A #GstMessage + * @position: (out) (optional): the resulting position + * + * Parse the given seek-done @msg and extract the corresponding #GstClockTime + * + * Since: 1.26 + */ +void +gst_play_message_parse_seek_done (GstMessage * msg, GstClockTime * position) +{ + PARSE_MESSAGE_FIELD (msg, GST_PLAY_MESSAGE_SEEK_DONE, + GST_PLAY_MESSAGE_DATA_POSITION, GST_TYPE_CLOCK_TIME, position); } diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h index f733fd2991..e6d839f03f 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h @@ -409,23 +409,32 @@ GstSample * gst_play_get_video_snapshot (GstPlay * play, GstPlaySnapshotFormat format, const GstStructure * config); GST_PLAY_API -gboolean gst_play_is_play_message (GstMessage *msg); +gboolean gst_play_is_play_message (GstMessage *msg); GST_PLAY_API void gst_play_message_parse_type (GstMessage *msg, GstPlayMessage *type); GST_PLAY_API +void gst_play_message_parse_uri_loaded (GstMessage *msg, gchar **uri); + +GST_PLAY_DEPRECATED_FOR(gst_play_message_parse_duration_changed) void gst_play_message_parse_duration_updated (GstMessage *msg, GstClockTime *duration); +GST_PLAY_API +void gst_play_message_parse_duration_changed (GstMessage *msg, GstClockTime *duration); + GST_PLAY_API void gst_play_message_parse_position_updated (GstMessage *msg, GstClockTime *position); GST_PLAY_API void gst_play_message_parse_state_changed (GstMessage *msg, GstPlayState *state); -GST_PLAY_API +GST_PLAY_DEPRECATED_FOR(gst_play_message_parse_buffering_percent) void gst_play_message_parse_buffering_percent (GstMessage *msg, guint *percent); +GST_PLAY_API +void gst_play_message_parse_buffering (GstMessage *msg, guint *percent); + GST_PLAY_API void gst_play_message_parse_error (GstMessage *msg, GError **error, GstStructure **details); @@ -444,6 +453,9 @@ void gst_play_message_parse_volume_changed (GstMessage *ms GST_PLAY_API void gst_play_message_parse_muted_changed (GstMessage *msg, gboolean *muted); +GST_PLAY_API +void gst_play_message_parse_seek_done (GstMessage *msg, GstClockTime *position); + G_END_DECLS #endif /* __GST_PLAY_H__ */