LCOV - code coverage report
Current view: top level - src/libvalent/media - valent-media-player.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 97.9 % 193 189
Test Date: 2024-04-23 06:02:46 Functions: 100.0 % 25 25
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 62.1 % 58 36

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #define G_LOG_DOMAIN "valent-media-player"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : #include <libvalent-core.h>
      10                 :             : 
      11                 :             : #include "valent-media-enums.h"
      12                 :             : #include "valent-media-player.h"
      13                 :             : 
      14                 :             : 
      15                 :             : /**
      16                 :             :  * ValentMediaPlayer:
      17                 :             :  *
      18                 :             :  * A base class for media players.
      19                 :             :  *
      20                 :             :  * A `ValentMediaPlayer` is a base class for plugins to providing an interface to
      21                 :             :  * media players via [class@Valent.MediaAdapter].
      22                 :             :  *
      23                 :             :  * Since: 1.0
      24                 :             :  */
      25                 :             : 
      26   [ +  +  +  - ]:         718 : G_DEFINE_TYPE (ValentMediaPlayer, valent_media_player, VALENT_TYPE_OBJECT)
      27                 :             : 
      28                 :             : /**
      29                 :             :  * ValentMediaPlayerClass:
      30                 :             :  * @next: the virtual function pointer for valent_media_player_next()
      31                 :             :  * @pause: the virtual function pointer for valent_media_player_pause()
      32                 :             :  * @play: the virtual function pointer for valent_media_player_play()
      33                 :             :  * @previous: the virtual function pointer for valent_media_player_previous()
      34                 :             :  * @seek: the virtual function pointer for valent_media_player_seek()
      35                 :             :  * @stop: the virtual function pointer for valent_media_player_stop()
      36                 :             :  * @get_flags: Getter for the `ValentMediaPlayer`:flags property.
      37                 :             :  * @get_metadata: Getter for the `ValentMediaPlayer`:metadata property.
      38                 :             :  * @get_name: Getter for the `ValentMediaPlayer`:name property.
      39                 :             :  * @get_position: Getter for the `ValentMediaPlayer`:position property.
      40                 :             :  * @set_position: Setter for the `ValentMediaPlayer`:position property.
      41                 :             :  * @get_repeat: Getter for the `ValentMediaPlayer`:repeat property.
      42                 :             :  * @set_repeat: Setter for the `ValentMediaPlayer`:repeat property.
      43                 :             :  * @get_state: Getter for the `ValentMediaPlayer`:state property.
      44                 :             :  * @get_volume: Getter for the `ValentMediaPlayer`:volume property.
      45                 :             :  * @set_volume: Setter for the `ValentMediaPlayer`:volume property.
      46                 :             :  *
      47                 :             :  * Virtual table for `ValentMediaPlayer`
      48                 :             :  */
      49                 :             : 
      50                 :             : enum {
      51                 :             :   PROP_0,
      52                 :             :   PROP_FLAGS,
      53                 :             :   PROP_METADATA,
      54                 :             :   PROP_NAME,
      55                 :             :   PROP_POSITION,
      56                 :             :   PROP_REPEAT,
      57                 :             :   PROP_SHUFFLE,
      58                 :             :   PROP_STATE,
      59                 :             :   PROP_VOLUME,
      60                 :             :   N_PROPERTIES
      61                 :             : };
      62                 :             : 
      63                 :             : static GParamSpec *properties[N_PROPERTIES] = { NULL, };
      64                 :             : 
      65                 :             : 
      66                 :             : /* LCOV_EXCL_START */
      67                 :             : static ValentMediaActions
      68                 :             : valent_media_player_real_get_flags (ValentMediaPlayer *player)
      69                 :             : {
      70                 :             :   return VALENT_MEDIA_ACTION_NONE;
      71                 :             : }
      72                 :             : 
      73                 :             : static GVariant *
      74                 :             : valent_media_player_real_get_metadata (ValentMediaPlayer *player)
      75                 :             : {
      76                 :             :   return NULL;
      77                 :             : }
      78                 :             : 
      79                 :             : static const char *
      80                 :             : valent_media_player_real_get_name (ValentMediaPlayer *player)
      81                 :             : {
      82                 :             :   return "Media Player";
      83                 :             : }
      84                 :             : 
      85                 :             : static double
      86                 :             : valent_media_player_real_get_position (ValentMediaPlayer *player)
      87                 :             : {
      88                 :             :   return 0.0;
      89                 :             : }
      90                 :             : 
      91                 :             : static void
      92                 :             : valent_media_player_real_set_position (ValentMediaPlayer *player,
      93                 :             :                                        double             position)
      94                 :             : {
      95                 :             : }
      96                 :             : 
      97                 :             : static ValentMediaRepeat
      98                 :             : valent_media_player_real_get_repeat (ValentMediaPlayer *player)
      99                 :             : {
     100                 :             :   return VALENT_MEDIA_REPEAT_NONE;
     101                 :             : }
     102                 :             : 
     103                 :             : static void
     104                 :             : valent_media_player_real_set_repeat (ValentMediaPlayer *player,
     105                 :             :                                      ValentMediaRepeat  repeat)
     106                 :             : {
     107                 :             : }
     108                 :             : 
     109                 :             : static gboolean
     110                 :             : valent_media_player_real_get_shuffle (ValentMediaPlayer *player)
     111                 :             : {
     112                 :             :   return FALSE;
     113                 :             : }
     114                 :             : 
     115                 :             : static void
     116                 :             : valent_media_player_real_set_shuffle (ValentMediaPlayer *player,
     117                 :             :                                       gboolean           shuffle)
     118                 :             : {
     119                 :             : }
     120                 :             : 
     121                 :             : static ValentMediaState
     122                 :             : valent_media_player_real_get_state (ValentMediaPlayer *player)
     123                 :             : {
     124                 :             :   return VALENT_MEDIA_STATE_STOPPED;
     125                 :             : }
     126                 :             : 
     127                 :             : static double
     128                 :             : valent_media_player_real_get_volume (ValentMediaPlayer *player)
     129                 :             : {
     130                 :             :   return 1.0;
     131                 :             : }
     132                 :             : 
     133                 :             : static void
     134                 :             : valent_media_player_real_set_volume (ValentMediaPlayer *player,
     135                 :             :                                      double             volume)
     136                 :             : {
     137                 :             : }
     138                 :             : 
     139                 :             : static void
     140                 :             : valent_media_player_real_next (ValentMediaPlayer *player)
     141                 :             : {
     142                 :             : }
     143                 :             : 
     144                 :             : static void
     145                 :             : valent_media_player_real_pause (ValentMediaPlayer *player)
     146                 :             : {
     147                 :             : }
     148                 :             : 
     149                 :             : static void
     150                 :             : valent_media_player_real_play (ValentMediaPlayer *player)
     151                 :             : {
     152                 :             : }
     153                 :             : 
     154                 :             : static void
     155                 :             : valent_media_player_real_previous (ValentMediaPlayer *player)
     156                 :             : {
     157                 :             :   g_debug ("%s(): operation not supported", G_STRFUNC);
     158                 :             : }
     159                 :             : 
     160                 :             : static void
     161                 :             : valent_media_player_real_seek (ValentMediaPlayer *player,
     162                 :             :                                double             offset)
     163                 :             : {
     164                 :             :   g_debug ("%s(): operation not supported", G_STRFUNC);
     165                 :             : }
     166                 :             : 
     167                 :             : static void
     168                 :             : valent_media_player_real_stop (ValentMediaPlayer *player)
     169                 :             : {
     170                 :             :   g_debug ("%s(): operation not supported", G_STRFUNC);
     171                 :             : }
     172                 :             : /* LCOV_EXCL_STOP */
     173                 :             : 
     174                 :             : 
     175                 :             : /*
     176                 :             :  * GObject
     177                 :             :  */
     178                 :             : static void
     179                 :          26 : valent_media_player_get_property (GObject    *object,
     180                 :             :                                   guint       prop_id,
     181                 :             :                                   GValue     *value,
     182                 :             :                                   GParamSpec *pspec)
     183                 :             : {
     184                 :          26 :   ValentMediaPlayer *self = VALENT_MEDIA_PLAYER (object);
     185                 :             : 
     186   [ +  +  +  +  :          26 :   switch (prop_id)
             +  +  +  +  
                      - ]
     187                 :             :     {
     188                 :           3 :     case PROP_FLAGS:
     189                 :           3 :       g_value_set_flags (value, valent_media_player_get_flags (self));
     190                 :           3 :       break;
     191                 :             : 
     192                 :           3 :     case PROP_METADATA:
     193                 :           3 :       g_value_take_variant (value, valent_media_player_get_metadata (self));
     194                 :           3 :       break;
     195                 :             : 
     196                 :           5 :     case PROP_NAME:
     197                 :           5 :       g_value_set_string (value, valent_media_player_get_name (self));
     198                 :           5 :       break;
     199                 :             : 
     200                 :           3 :     case PROP_POSITION:
     201                 :           3 :       g_value_set_double (value, valent_media_player_get_position (self));
     202                 :           3 :       break;
     203                 :             : 
     204                 :           3 :     case PROP_REPEAT:
     205                 :           3 :       g_value_set_enum (value, valent_media_player_get_repeat (self));
     206                 :           3 :       break;
     207                 :             : 
     208                 :           3 :     case PROP_SHUFFLE:
     209                 :           3 :       g_value_set_boolean (value, valent_media_player_get_shuffle (self));
     210                 :           3 :       break;
     211                 :             : 
     212                 :           3 :     case PROP_STATE:
     213                 :           3 :       g_value_set_enum (value, valent_media_player_get_state (self));
     214                 :           3 :       break;
     215                 :             : 
     216                 :           3 :     case PROP_VOLUME:
     217                 :           3 :       g_value_set_double (value, valent_media_player_get_volume (self));
     218                 :           3 :       break;
     219                 :             : 
     220                 :           0 :     default:
     221                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     222                 :             :     }
     223                 :          26 : }
     224                 :             : 
     225                 :             : static void
     226                 :          11 : valent_media_player_set_property (GObject      *object,
     227                 :             :                                   guint         prop_id,
     228                 :             :                                   const GValue *value,
     229                 :             :                                   GParamSpec   *pspec)
     230                 :             : {
     231                 :          11 :   ValentMediaPlayer *self = VALENT_MEDIA_PLAYER (object);
     232                 :             : 
     233   [ +  +  +  +  :          11 :   switch (prop_id)
                      - ]
     234                 :             :     {
     235                 :           2 :     case PROP_POSITION:
     236                 :           2 :       valent_media_player_set_position (self, g_value_get_double (value));
     237                 :           2 :       break;
     238                 :             : 
     239                 :           3 :     case PROP_REPEAT:
     240                 :           3 :       valent_media_player_set_repeat (self, g_value_get_enum (value));
     241                 :           3 :       break;
     242                 :             : 
     243                 :           3 :     case PROP_SHUFFLE:
     244                 :           3 :       valent_media_player_set_shuffle (self, g_value_get_boolean (value));
     245                 :           3 :       break;
     246                 :             : 
     247                 :           3 :     case PROP_VOLUME:
     248                 :           3 :       valent_media_player_set_volume (self, g_value_get_double (value));
     249                 :           3 :       break;
     250                 :             : 
     251                 :           0 :     default:
     252                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     253                 :             :     }
     254                 :          11 : }
     255                 :             : 
     256                 :             : static void
     257                 :           5 : valent_media_player_class_init (ValentMediaPlayerClass *klass)
     258                 :             : {
     259                 :           5 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     260                 :           5 :   ValentMediaPlayerClass *player_class = VALENT_MEDIA_PLAYER_CLASS (klass);
     261                 :             : 
     262                 :           5 :   object_class->get_property = valent_media_player_get_property;
     263                 :           5 :   object_class->set_property = valent_media_player_set_property;
     264                 :             : 
     265                 :           5 :   player_class->get_flags = valent_media_player_real_get_flags;
     266                 :           5 :   player_class->get_metadata = valent_media_player_real_get_metadata;
     267                 :           5 :   player_class->get_name = valent_media_player_real_get_name;
     268                 :           5 :   player_class->get_position = valent_media_player_real_get_position;
     269                 :           5 :   player_class->set_position = valent_media_player_real_set_position;
     270                 :           5 :   player_class->get_repeat = valent_media_player_real_get_repeat;
     271                 :           5 :   player_class->set_repeat = valent_media_player_real_set_repeat;
     272                 :           5 :   player_class->get_shuffle = valent_media_player_real_get_shuffle;
     273                 :           5 :   player_class->set_shuffle = valent_media_player_real_set_shuffle;
     274                 :           5 :   player_class->get_state = valent_media_player_real_get_state;
     275                 :           5 :   player_class->get_volume = valent_media_player_real_get_volume;
     276                 :           5 :   player_class->set_volume = valent_media_player_real_set_volume;
     277                 :           5 :   player_class->next = valent_media_player_real_next;
     278                 :           5 :   player_class->pause = valent_media_player_real_pause;
     279                 :           5 :   player_class->play = valent_media_player_real_play;
     280                 :           5 :   player_class->previous = valent_media_player_real_previous;
     281                 :           5 :   player_class->seek = valent_media_player_real_seek;
     282                 :           5 :   player_class->stop = valent_media_player_real_stop;
     283                 :             : 
     284                 :             :   /**
     285                 :             :    * ValentMediaPlayer:flags:
     286                 :             :    *
     287                 :             :    * The available actions.
     288                 :             :    *
     289                 :             :    * Implementations should emit [signal@GObject.Object::notify] when they
     290                 :             :    * change the internal representation of this property.
     291                 :             :    *
     292                 :             :    * Since: 1.0
     293                 :             :    */
     294                 :          10 :   properties [PROP_FLAGS] =
     295                 :           5 :     g_param_spec_flags ("flags", NULL, NULL,
     296                 :             :                         VALENT_TYPE_MEDIA_ACTIONS,
     297                 :             :                         VALENT_MEDIA_ACTION_NONE,
     298                 :             :                         (G_PARAM_READABLE |
     299                 :             :                          G_PARAM_EXPLICIT_NOTIFY |
     300                 :             :                          G_PARAM_STATIC_STRINGS));
     301                 :             : 
     302                 :             :   /**
     303                 :             :    * ValentMediaPlayer:metadata: (getter get_metadata)
     304                 :             :    *
     305                 :             :    * The metadata of the active media item.
     306                 :             :    *
     307                 :             :    * The content of the variant should be in the same format as MPRISv2.
     308                 :             :    *
     309                 :             :    * Implementations should emit [signal@GObject.Object::notify] when they
     310                 :             :    * change the internal representation of this property.
     311                 :             :    *
     312                 :             :    * Since: 1.0
     313                 :             :    */
     314                 :          10 :   properties [PROP_METADATA] =
     315                 :           5 :     g_param_spec_variant ("metadata", NULL, NULL,
     316                 :             :                           G_VARIANT_TYPE ("a{sv}"),
     317                 :             :                           NULL,
     318                 :             :                           (G_PARAM_READABLE |
     319                 :             :                            G_PARAM_EXPLICIT_NOTIFY |
     320                 :             :                            G_PARAM_STATIC_STRINGS));
     321                 :             : 
     322                 :             :   /**
     323                 :             :    * ValentMediaPlayer:name: (getter get_name)
     324                 :             :    *
     325                 :             :    * The display name of the media player.
     326                 :             :    *
     327                 :             :    * Typically, this property should remain constant through the lifetime of the
     328                 :             :    * media player. Implementations should emit [signal@GObject.Object::notify]
     329                 :             :    * the internal representation of this property changes, regardless.
     330                 :             :    *
     331                 :             :    * Since: 1.0
     332                 :             :    */
     333                 :          10 :   properties [PROP_NAME] =
     334                 :           5 :     g_param_spec_string ("name", NULL, NULL,
     335                 :             :                          NULL,
     336                 :             :                          (G_PARAM_READABLE |
     337                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     338                 :             :                           G_PARAM_STATIC_STRINGS));
     339                 :             : 
     340                 :             :   /**
     341                 :             :    * ValentMediaPlayer:position: (getter get_position) (setter set_position)
     342                 :             :    *
     343                 :             :    * The current track position in seconds.
     344                 :             :    *
     345                 :             :    * Acceptable values are between `0` and the `mpris:length` metadata entry
     346                 :             :    * (see [property@Valent.MediaPlayer:metadata]). If the player does not have
     347                 :             :    * %VALENT_MEDIA_ACTION_SEEK in [property@Valent.MediaPlayer:flags], setting
     348                 :             :    * this property should have no effect.
     349                 :             :    *
     350                 :             :    * Since: 1.0
     351                 :             :    */
     352                 :          10 :   properties [PROP_POSITION] =
     353                 :           5 :     g_param_spec_double ("position", NULL, NULL,
     354                 :             :                          0.0, G_MAXDOUBLE,
     355                 :             :                          0.0,
     356                 :             :                          (G_PARAM_READWRITE |
     357                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     358                 :             :                           G_PARAM_STATIC_STRINGS));
     359                 :             : 
     360                 :             :   /**
     361                 :             :    * ValentMediaPlayer:repeat: (getter get_repeat) (setter set_repeat)
     362                 :             :    *
     363                 :             :    * The repeat mode.
     364                 :             :    *
     365                 :             :    * If the player does not have the appropriate bitmask in
     366                 :             :    * [property@Valent.MediaPlayer:flags], setting this property should have no
     367                 :             :    * effect.
     368                 :             :    *
     369                 :             :    * Implementations should emit [signal@GObject.Object::notify] when they
     370                 :             :    * change the internal representation of this property.
     371                 :             :    *
     372                 :             :    * Since: 1.0
     373                 :             :    */
     374                 :          10 :   properties [PROP_REPEAT] =
     375                 :           5 :     g_param_spec_enum ("repeat", NULL, NULL,
     376                 :             :                        VALENT_TYPE_MEDIA_REPEAT,
     377                 :             :                        VALENT_MEDIA_REPEAT_NONE,
     378                 :             :                        (G_PARAM_READWRITE |
     379                 :             :                         G_PARAM_EXPLICIT_NOTIFY |
     380                 :             :                         G_PARAM_STATIC_STRINGS));
     381                 :             : 
     382                 :             :   /**
     383                 :             :    * ValentMediaPlayer:state: (getter get_state)
     384                 :             :    *
     385                 :             :    * The playback state.
     386                 :             :    *
     387                 :             :    * Implementations should emit [signal@GObject.Object::notify] when they
     388                 :             :    * change the internal representation of this property.
     389                 :             :    *
     390                 :             :    * Since: 1.0
     391                 :             :    */
     392                 :          10 :   properties [PROP_STATE] =
     393                 :           5 :     g_param_spec_enum ("state", NULL, NULL,
     394                 :             :                        VALENT_TYPE_MEDIA_STATE,
     395                 :             :                        VALENT_MEDIA_STATE_STOPPED,
     396                 :             :                        (G_PARAM_READABLE |
     397                 :             :                         G_PARAM_EXPLICIT_NOTIFY |
     398                 :             :                         G_PARAM_STATIC_STRINGS));
     399                 :             : 
     400                 :             :   /**
     401                 :             :    * ValentMediaPlayer:shuffle: (getter get_shuffle) (setter set_shuffle)
     402                 :             :    *
     403                 :             :    * Whether playback order is shuffled.
     404                 :             :    *
     405                 :             :    * A value of %FALSE indicates that playback is progressing linearly through a
     406                 :             :    * playlist, while %TRUE means playback is progressing through a playlist in
     407                 :             :    * some other order.
     408                 :             :    *
     409                 :             :    * Implementations should emit [signal@GObject.Object::notify] when they
     410                 :             :    * change the internal representation of this property.
     411                 :             :    *
     412                 :             :    * Since: 1.0
     413                 :             :    */
     414                 :          10 :   properties [PROP_SHUFFLE] =
     415                 :           5 :     g_param_spec_boolean ("shuffle", NULL, NULL,
     416                 :             :                           FALSE,
     417                 :             :                           (G_PARAM_READWRITE |
     418                 :             :                            G_PARAM_EXPLICIT_NOTIFY |
     419                 :             :                            G_PARAM_STATIC_STRINGS));
     420                 :             : 
     421                 :             :   /**
     422                 :             :    * ValentMediaPlayer:volume: (getter get_volume) (setter set_volume)
     423                 :             :    *
     424                 :             :    * The volume level.
     425                 :             :    *
     426                 :             :    * Attempts to change this property may be ignored by some implementations.
     427                 :             :    *
     428                 :             :    * Implementations should emit [signal@GObject.Object::notify] when they
     429                 :             :    * change the internal representation of this property.
     430                 :             :    *
     431                 :             :    * Since: 1.0
     432                 :             :    */
     433                 :          10 :   properties [PROP_VOLUME] =
     434                 :           5 :     g_param_spec_double ("volume", NULL, NULL,
     435                 :             :                          0.0, G_MAXDOUBLE,
     436                 :             :                          0.0,
     437                 :             :                          (G_PARAM_READWRITE |
     438                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     439                 :             :                           G_PARAM_STATIC_STRINGS));
     440                 :             : 
     441                 :           5 :   g_object_class_install_properties (object_class, N_PROPERTIES, properties);
     442                 :           5 : }
     443                 :             : 
     444                 :             : static void
     445                 :          14 : valent_media_player_init (ValentMediaPlayer *self)
     446                 :             : {
     447                 :          14 : }
     448                 :             : 
     449                 :             : /**
     450                 :             :  * valent_media_player_get_flags: (virtual get_flags) (get-property flags)
     451                 :             :  * @player: a `ValentMediaPlayer`
     452                 :             :  *
     453                 :             :  * Get flags describing the available actions of @player.
     454                 :             :  *
     455                 :             :  * Returns: a bitmask of `ValentMediaActions`
     456                 :             :  *
     457                 :             :  * Since: 1.0
     458                 :             :  */
     459                 :             : ValentMediaActions
     460                 :          65 : valent_media_player_get_flags (ValentMediaPlayer *player)
     461                 :             : {
     462                 :          65 :   ValentMediaActions ret;
     463                 :             : 
     464                 :          65 :   VALENT_ENTRY;
     465                 :             : 
     466         [ +  - ]:          65 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), VALENT_MEDIA_ACTION_NONE);
     467                 :             : 
     468                 :          65 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_flags (player);
     469                 :             : 
     470                 :          65 :   VALENT_RETURN (ret);
     471                 :             : }
     472                 :             : 
     473                 :             : /**
     474                 :             :  * valent_media_player_get_metadata: (virtual get_metadata) (get-property metadata)
     475                 :             :  * @player: a `ValentMediaPlayer`
     476                 :             :  *
     477                 :             :  * Get the metadata of the active media items.
     478                 :             :  *
     479                 :             :  * Implementations should typically have an entry for the `mpris:length` field.
     480                 :             :  * Other fields generally supported by KDE Connect clients include
     481                 :             :  * `mpris:artUrl`, `xesam:artist`, `xesam:album` and `xesam:title`.
     482                 :             :  *
     483                 :             :  * Returns: (transfer full): a `GVariant` of type `a{sv}`
     484                 :             :  *
     485                 :             :  * Since: 1.0
     486                 :             :  */
     487                 :             : GVariant *
     488                 :          54 : valent_media_player_get_metadata (ValentMediaPlayer *player)
     489                 :             : {
     490                 :          54 :   GVariant *ret;
     491                 :             : 
     492                 :          54 :   VALENT_ENTRY;
     493                 :             : 
     494         [ +  - ]:          54 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), NULL);
     495                 :             : 
     496                 :          54 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_metadata (player);
     497                 :             : 
     498         [ +  + ]:          54 :   if G_UNLIKELY (ret == NULL)
     499                 :          11 :     ret = g_variant_parse (G_VARIANT_TYPE_VARDICT, "{}", NULL, NULL, NULL);
     500                 :             : 
     501                 :          54 :   VALENT_RETURN (ret);
     502                 :             : }
     503                 :             : 
     504                 :             : /**
     505                 :             :  * valent_media_player_get_name: (virtual get_name) (get-property name)
     506                 :             :  * @player: a `ValentMediaPlayer`
     507                 :             :  *
     508                 :             :  * Get the display name of the @player.
     509                 :             :  *
     510                 :             :  * Returns: (transfer none): player name
     511                 :             :  *
     512                 :             :  * Since: 1.0
     513                 :             :  */
     514                 :             : const char *
     515                 :          40 : valent_media_player_get_name (ValentMediaPlayer *player)
     516                 :             : {
     517                 :          40 :   const char *ret;
     518                 :             : 
     519                 :          40 :   VALENT_ENTRY;
     520                 :             : 
     521         [ +  - ]:          40 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), NULL);
     522                 :             : 
     523                 :          40 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_name (player);
     524                 :             : 
     525                 :          40 :   VALENT_RETURN (ret);
     526                 :             : }
     527                 :             : 
     528                 :             : /**
     529                 :             :  * valent_media_player_get_position: (virtual get_position) (get-property position)
     530                 :             :  * @player: a `ValentMediaPlayer`
     531                 :             :  *
     532                 :             :  * Get the current position in seconds.
     533                 :             :  *
     534                 :             :  * Returns: position in seconds
     535                 :             :  *
     536                 :             :  * Since: 1.0
     537                 :             :  */
     538                 :             : double
     539                 :          50 : valent_media_player_get_position (ValentMediaPlayer *player)
     540                 :             : {
     541                 :          50 :   double ret;
     542                 :             : 
     543                 :          50 :   VALENT_ENTRY;
     544                 :             : 
     545         [ +  - ]:          50 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), 0.0);
     546                 :             : 
     547                 :          50 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_position (player);
     548                 :             : 
     549                 :          50 :   VALENT_RETURN (ret);
     550                 :             : }
     551                 :             : 
     552                 :             : /**
     553                 :             :  * valent_media_player_set_position: (virtual set_position) (set-property position)
     554                 :             :  * @player: a `ValentMediaPlayer`
     555                 :             :  * @position: position in seconds
     556                 :             :  *
     557                 :             :  * Set the current position in seconds.
     558                 :             :  *
     559                 :             :  * Since: 1.0
     560                 :             :  */
     561                 :             : void
     562                 :           6 : valent_media_player_set_position (ValentMediaPlayer *player,
     563                 :             :                                   double             position)
     564                 :             : {
     565                 :           6 :   VALENT_ENTRY;
     566                 :             : 
     567         [ +  - ]:           6 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     568         [ -  + ]:           6 :   g_return_if_fail (position >= 0.0);
     569                 :             : 
     570                 :           6 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->set_position (player, position);
     571                 :             : 
     572                 :           6 :   VALENT_EXIT;
     573                 :             : }
     574                 :             : 
     575                 :             : /**
     576                 :             :  * valent_media_player_get_repeat: (virtual get_repeat) (get-property repeat)
     577                 :             :  * @player: a `ValentMediaPlayer`
     578                 :             :  *
     579                 :             :  * Get the repeat mode for @player.
     580                 :             :  *
     581                 :             :  * Returns: `ValentMediaRepeat`
     582                 :             :  *
     583                 :             :  * Since: 1.0
     584                 :             :  */
     585                 :             : ValentMediaRepeat
     586                 :          27 : valent_media_player_get_repeat (ValentMediaPlayer *player)
     587                 :             : {
     588                 :          27 :   ValentMediaRepeat ret;
     589                 :             : 
     590                 :          27 :   VALENT_ENTRY;
     591                 :             : 
     592         [ +  - ]:          27 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), VALENT_MEDIA_REPEAT_NONE);
     593                 :             : 
     594                 :          27 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_repeat (player);
     595                 :             : 
     596                 :          27 :   VALENT_RETURN (ret);
     597                 :             : }
     598                 :             : 
     599                 :             : /**
     600                 :             :  * valent_media_player_set_repeat: (virtual set_repeat) (set-property repeat)
     601                 :             :  * @player: a `ValentMediaPlayer`
     602                 :             :  * @repeat: a `ValentMediaRepeat`
     603                 :             :  *
     604                 :             :  * Set the repeat mode of @player to @repeat.
     605                 :             :  *
     606                 :             :  * Since: 1.0
     607                 :             :  */
     608                 :             : void
     609                 :          11 : valent_media_player_set_repeat (ValentMediaPlayer *player,
     610                 :             :                                ValentMediaRepeat   repeat)
     611                 :             : {
     612                 :          11 :   VALENT_ENTRY;
     613                 :             : 
     614         [ +  - ]:          11 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     615                 :             : 
     616                 :          11 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->set_repeat (player, repeat);
     617                 :             : 
     618                 :          11 :   VALENT_EXIT;
     619                 :             : }
     620                 :             : 
     621                 :             : /**
     622                 :             :  * valent_media_player_get_shuffle: (virtual get_shuffle) (get-property shuffle)
     623                 :             :  * @player: a `ValentMediaPlayer`
     624                 :             :  *
     625                 :             :  * Get whether playback order is shuffled.
     626                 :             :  *
     627                 :             :  * Returns: the shuffle state
     628                 :             :  *
     629                 :             :  * Since: 1.0
     630                 :             :  */
     631                 :             : gboolean
     632                 :          28 : valent_media_player_get_shuffle (ValentMediaPlayer *player)
     633                 :             : {
     634                 :          28 :   gboolean ret;
     635                 :             : 
     636                 :          28 :   VALENT_ENTRY;
     637                 :             : 
     638         [ +  - ]:          28 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), FALSE);
     639                 :             : 
     640                 :          28 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_shuffle (player);
     641                 :             : 
     642                 :          28 :   VALENT_RETURN (ret);
     643                 :             : }
     644                 :             : 
     645                 :             : /**
     646                 :             :  * valent_media_player_set_shuffle: (virtual set_shuffle) (set-property shuffle)
     647                 :             :  * @player: a `ValentMediaPlayer`
     648                 :             :  * @shuffle: shuffle state
     649                 :             :  *
     650                 :             :  * Set whether playback order is shuffled.
     651                 :             :  *
     652                 :             :  * Since: 1.0
     653                 :             :  */
     654                 :             : void
     655                 :          10 : valent_media_player_set_shuffle (ValentMediaPlayer *player,
     656                 :             :                                   gboolean           shuffle)
     657                 :             : {
     658                 :          10 :   VALENT_ENTRY;
     659                 :             : 
     660         [ +  - ]:          10 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     661                 :             : 
     662                 :          10 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->set_shuffle (player, shuffle);
     663                 :             : 
     664                 :          10 :   VALENT_EXIT;
     665                 :             : }
     666                 :             : 
     667                 :             : /**
     668                 :             :  * valent_media_player_get_state: (virtual get_state) (get-property state)
     669                 :             :  * @player: a `ValentMediaPlayer`
     670                 :             :  *
     671                 :             :  * Get the playback state for @player.
     672                 :             :  *
     673                 :             :  * Returns: `ValentMediaState`
     674                 :             :  *
     675                 :             :  * Since: 1.0
     676                 :             :  */
     677                 :             : ValentMediaState
     678                 :          87 : valent_media_player_get_state (ValentMediaPlayer *player)
     679                 :             : {
     680                 :          87 :   ValentMediaState ret;
     681                 :             : 
     682                 :          87 :   VALENT_ENTRY;
     683                 :             : 
     684         [ +  - ]:          87 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), VALENT_MEDIA_STATE_STOPPED);
     685                 :             : 
     686                 :          87 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_state (player);
     687                 :             : 
     688                 :          87 :   VALENT_RETURN (ret);
     689                 :             : }
     690                 :             : 
     691                 :             : /**
     692                 :             :  * valent_media_player_get_volume: (virtual get_volume) (get-property volume)
     693                 :             :  * @player: a `ValentMediaPlayer`
     694                 :             :  *
     695                 :             :  * Get the volume level.
     696                 :             :  *
     697                 :             :  * Returns: the volume of @player
     698                 :             :  *
     699                 :             :  * Since: 1.0
     700                 :             :  */
     701                 :             : double
     702                 :          26 : valent_media_player_get_volume (ValentMediaPlayer *player)
     703                 :             : {
     704                 :          26 :   double ret;
     705                 :             : 
     706                 :          26 :   VALENT_ENTRY;
     707                 :             : 
     708         [ +  - ]:          26 :   g_return_val_if_fail (VALENT_IS_MEDIA_PLAYER (player), 0.0);
     709                 :             : 
     710                 :          26 :   ret = VALENT_MEDIA_PLAYER_GET_CLASS (player)->get_volume (player);
     711                 :             : 
     712                 :          26 :   VALENT_RETURN (ret);
     713                 :             : }
     714                 :             : 
     715                 :             : /**
     716                 :             :  * valent_media_player_set_volume: (virtual set_volume) (set-property volume)
     717                 :             :  * @player: a `ValentMediaPlayer`
     718                 :             :  * @volume: volume level
     719                 :             :  *
     720                 :             :  * Set the volume level of @player.
     721                 :             :  *
     722                 :             :  * Since: 1.0
     723                 :             :  */
     724                 :             : void
     725                 :           8 : valent_media_player_set_volume (ValentMediaPlayer *player,
     726                 :             :                                 double             volume)
     727                 :             : {
     728                 :           8 :   VALENT_ENTRY;
     729                 :             : 
     730         [ +  - ]:           8 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     731                 :             : 
     732                 :           8 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->set_volume (player, volume);
     733                 :             : 
     734                 :           8 :   VALENT_EXIT;
     735                 :             : }
     736                 :             : 
     737                 :             : /**
     738                 :             :  * valent_media_player_next: (virtual next)
     739                 :             :  * @player: a `ValentMediaPlayer`
     740                 :             :  *
     741                 :             :  * Skip to the next media item.
     742                 :             :  *
     743                 :             :  * If there is no next track (and endless playback and track repeat are both
     744                 :             :  * off), stop playback. If playback is paused or stopped, it remains that way.
     745                 :             :  *
     746                 :             :  * If [property@Valent.MediaPlayer:flags] does not include
     747                 :             :  * %VALENT_MEDIA_ACTION_NEXT, calling this method should have no effect.
     748                 :             :  *
     749                 :             :  * Since: 1.0
     750                 :             :  */
     751                 :             : void
     752                 :           9 : valent_media_player_next (ValentMediaPlayer *player)
     753                 :             : {
     754                 :           9 :   VALENT_ENTRY;
     755                 :             : 
     756         [ +  - ]:           9 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     757                 :             : 
     758                 :           9 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->next (player);
     759                 :             : 
     760                 :           9 :   VALENT_EXIT;
     761                 :             : }
     762                 :             : 
     763                 :             : /**
     764                 :             :  * valent_media_player_pause: (virtual pause)
     765                 :             :  * @player: a `ValentMediaPlayer`
     766                 :             :  *
     767                 :             :  * Pauses playback.
     768                 :             :  *
     769                 :             :  * If playback is already paused, this has no effect. Calling
     770                 :             :  * [method@Valent.MediaPlayer.pause] after this should cause playback to start
     771                 :             :  * again from the same position.
     772                 :             :  *
     773                 :             :  * If [property@Valent.MediaPlayer:flags] does not include
     774                 :             :  * %VALENT_MEDIA_ACTION_PAUSE, calling this method should have no effect.
     775                 :             :  *
     776                 :             :  * Since: 1.0
     777                 :             :  */
     778                 :             : void
     779                 :          10 : valent_media_player_pause (ValentMediaPlayer *player)
     780                 :             : {
     781                 :          10 :   VALENT_ENTRY;
     782                 :             : 
     783         [ +  - ]:          10 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     784                 :             : 
     785                 :          10 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->pause (player);
     786                 :             : 
     787                 :          10 :   VALENT_EXIT;
     788                 :             : }
     789                 :             : 
     790                 :             : /**
     791                 :             :  * valent_media_player_play: (virtual play)
     792                 :             :  * @player: a `ValentMediaPlayer`
     793                 :             :  *
     794                 :             :  * Start playback.
     795                 :             :  *
     796                 :             :  * If already playing, this has no effect. If paused, playback resumes from the
     797                 :             :  * current position. If there is no track to play, this has no effect.
     798                 :             :  *
     799                 :             :  * If [property@Valent.MediaPlayer:flags] does not include
     800                 :             :  * %VALENT_MEDIA_ACTION_PLAY, calling this method should have no effect.
     801                 :             :  *
     802                 :             :  * Since: 1.0
     803                 :             :  */
     804                 :             : void
     805                 :          11 : valent_media_player_play (ValentMediaPlayer *player)
     806                 :             : {
     807                 :          11 :   VALENT_ENTRY;
     808                 :             : 
     809         [ +  - ]:          11 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     810                 :             : 
     811                 :          11 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->play (player);
     812                 :             : 
     813                 :          11 :   VALENT_EXIT;
     814                 :             : }
     815                 :             : 
     816                 :             : /**
     817                 :             :  * valent_media_player_previous: (virtual previous)
     818                 :             :  * @player: a `ValentMediaPlayer`
     819                 :             :  *
     820                 :             :  * Skip to the previous media item.
     821                 :             :  *
     822                 :             :  * If there is no previous track (and endless playback and track repeat are both
     823                 :             :  * off), stop playback. If playback is paused or stopped, it remains that way.
     824                 :             :  *
     825                 :             :  * If [property@Valent.MediaPlayer:flags] does not include
     826                 :             :  * %VALENT_MEDIA_ACTION_PREVIOUS, calling this method should have no effect.
     827                 :             :  *
     828                 :             :  * Since: 1.0
     829                 :             :  */
     830                 :             : void
     831                 :           9 : valent_media_player_previous (ValentMediaPlayer *player)
     832                 :             : {
     833                 :           9 :   VALENT_ENTRY;
     834                 :             : 
     835         [ +  - ]:           9 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     836                 :             : 
     837                 :           9 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->previous (player);
     838                 :             : 
     839                 :           9 :   VALENT_EXIT;
     840                 :             : }
     841                 :             : 
     842                 :             : /**
     843                 :             :  * valent_media_player_seek: (virtual seek)
     844                 :             :  * @player: a `ValentMediaPlayer`
     845                 :             :  * @offset: number of seconds to seek forward
     846                 :             :  *
     847                 :             :  * Seek in the current media item by @offset seconds.
     848                 :             :  *
     849                 :             :  * A negative value seeks back. If this would mean seeking back further than the
     850                 :             :  * start of the track, the position is set to `0`. If the value passed in would
     851                 :             :  * mean seeking beyond the end of the track, acts like a call to
     852                 :             :  * valent_media_player_seek().
     853                 :             :  *
     854                 :             :  * If [property@Valent.MediaPlayer:flags] does not include
     855                 :             :  * %VALENT_MEDIA_ACTION_SEEK, calling this method should have no effect.
     856                 :             :  *
     857                 :             :  * Since: 1.0
     858                 :             :  */
     859                 :             : void
     860                 :          10 : valent_media_player_seek (ValentMediaPlayer *player,
     861                 :             :                           double             offset)
     862                 :             : {
     863                 :          10 :   VALENT_ENTRY;
     864                 :             : 
     865         [ +  - ]:          10 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     866                 :             : 
     867                 :          10 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->seek (player, offset);
     868                 :             : 
     869                 :          10 :   VALENT_EXIT;
     870                 :             : }
     871                 :             : 
     872                 :             : /**
     873                 :             :  * valent_media_player_stop: (virtual stop)
     874                 :             :  * @player: a `ValentMediaPlayer`
     875                 :             :  *
     876                 :             :  * Stop playback.
     877                 :             :  *
     878                 :             :  * If playback is already stopped, this has no effect. Calling
     879                 :             :  * valent_media_player_play() after this should cause playback to start again
     880                 :             :  * from the beginning of the track.
     881                 :             :  *
     882                 :             :  * If [property@Valent.MediaPlayer:flags] does not include
     883                 :             :  * %VALENT_MEDIA_ACTION_STOP, calling this method should have no effect.
     884                 :             :  *
     885                 :             :  * Since: 1.0
     886                 :             :  */
     887                 :             : void
     888                 :           9 : valent_media_player_stop (ValentMediaPlayer *player)
     889                 :             : {
     890                 :           9 :   VALENT_ENTRY;
     891                 :             : 
     892         [ +  - ]:           9 :   g_return_if_fail (VALENT_IS_MEDIA_PLAYER (player));
     893                 :             : 
     894                 :           9 :   VALENT_MEDIA_PLAYER_GET_CLASS (player)->stop (player);
     895                 :             : 
     896                 :           9 :   VALENT_EXIT;
     897                 :             : }
     898                 :             : 
        

Generated by: LCOV version 2.0-1