LCOV - code coverage report
Current view: top level - media/public/include - IWebAudioPlayer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2025-03-21 11:02:39 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2022 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #ifndef FIREBOLT_RIALTO_I_WEB_AUDIO_PLAYER_H_
      21              : #define FIREBOLT_RIALTO_I_WEB_AUDIO_PLAYER_H_
      22              : 
      23              : /**
      24              :  * @file IWebAudioPlayer.h
      25              :  *
      26              :  * The definition of the IWebAudioPlayer interface.
      27              :  *
      28              :  * This interface defines the public API of Rialto for mixing PCM audio with
      29              :  * current audio output.
      30              :  */
      31              : 
      32              : #include <memory>
      33              : #include <stdint.h>
      34              : #include <string>
      35              : 
      36              : #include "IWebAudioPlayerClient.h"
      37              : #include "MediaCommon.h"
      38              : 
      39              : namespace firebolt::rialto
      40              : {
      41              : class IWebAudioPlayer;
      42              : 
      43              : /**
      44              :  * @brief IWebAudioPlayer factory class, returns a concrete implementation of IWebAudioPlayer
      45              :  */
      46              : class IWebAudioPlayerFactory
      47              : {
      48              : public:
      49           46 :     IWebAudioPlayerFactory() = default;
      50           46 :     virtual ~IWebAudioPlayerFactory() = default;
      51              : 
      52              :     /**
      53              :      * @brief Create a IWebAudioPlayerFactory instance.
      54              :      *
      55              :      * @retval the factory instance or null on error.
      56              :      */
      57              :     static std::shared_ptr<IWebAudioPlayerFactory> createFactory();
      58              : 
      59              :     /**
      60              :      * @brief IWebAudioPlayer factory method, returns a concrete implementation of
      61              :      * IWebAudioPlayer for playback of audio.
      62              :      *
      63              :      * @param[in] client:        The Web Audio Player client
      64              :      * @param[in] audioMimeType: The audio encoding format, currently only "audio/x-raw" (PCM)
      65              :      * @param[in] priority:      Priority value for this pipeline.
      66              :      * @param[in] config:        Additional type dependent configuration data or nullptr
      67              :      *
      68              :      * Some platforms have limited numbers of audio playbacks that can be mixed. The client application
      69              :      * should therefore assign a priority to each audio player it creates, starting with priority 1 for
      70              :      * the most important, priority 2 for the next etc. If a platform supports 'n' players, then any
      71              :      * player with priority>n will appear to function normally by but the audio data will be silently
      72              :      * discarded.
      73              :      *
      74              :      * @retval the new Web Audio Player instance or null on error.
      75              :      */
      76              :     virtual std::unique_ptr<IWebAudioPlayer> createWebAudioPlayer(std::weak_ptr<IWebAudioPlayerClient> client,
      77              :                                                                   const std::string &audioMimeType,
      78              :                                                                   const uint32_t priority,
      79              :                                                                   std::weak_ptr<const WebAudioConfig> config) const = 0;
      80              : };
      81              : 
      82              : /**
      83              :  * @brief The definition of the IWebAudioPlayer interface.
      84              :  *
      85              :  * This interface defines the public API of Rialto for mixing PCM audio with
      86              :  * current audio output. It should be implemented by both Rialto Client &
      87              :  * Rialto Server.
      88              :  */
      89              : class IWebAudioPlayer
      90              : {
      91              : public:
      92          112 :     IWebAudioPlayer() = default;
      93          112 :     virtual ~IWebAudioPlayer() = default;
      94              : 
      95              :     IWebAudioPlayer(const IWebAudioPlayer &) = delete;
      96              :     IWebAudioPlayer &operator=(const IWebAudioPlayer &) = delete;
      97              :     IWebAudioPlayer(IWebAudioPlayer &&) = delete;
      98              :     IWebAudioPlayer &operator=(IWebAudioPlayer &&) = delete;
      99              : 
     100              :     /**
     101              :      * @brief Play the web audio.
     102              :      *
     103              :      * Sets the player to the PLAYING state (it is IDLE when created).
     104              :      *
     105              :      * @retval true on success.
     106              :      */
     107              :     virtual bool play() = 0;
     108              : 
     109              :     /**
     110              :      * @brief Pause the web audio.
     111              :      *
     112              :      * Sets the player to the PAUSED state (it is IDLE when created).
     113              :      *
     114              :      * @retval true on success.
     115              :      */
     116              :     virtual bool pause() = 0;
     117              : 
     118              :     /**
     119              :      * @brief Notify EOS.
     120              :      *
     121              :      * Notifies the player that no further frames will be provided. When
     122              :      * all buffered frames are played the player will enter the EOS state.
     123              :      *
     124              :      * @retval true on success.
     125              :      */
     126              :     virtual bool setEos() = 0;
     127              : 
     128              :     /**
     129              :      * @brief Get the available frames.
     130              :      *
     131              :      * Gets the available buffer space for sending more frames. Client should not
     132              :      * write more than the number of frames returned by this API.
     133              :      *
     134              :      * webAudioShmInfo is not required by the client application and can be ignored.
     135              :      *
     136              :      * @param[out] availableFrames : Number of frames available to be written.
     137              :      * @param[out] webAudioShmInfo : Location in shm to write the data (Server only).
     138              :      *
     139              :      * @retval true on success.
     140              :      */
     141              :     virtual bool getBufferAvailable(uint32_t &availableFrames, std::shared_ptr<WebAudioShmInfo> &webAudioShmInfo) = 0;
     142              : 
     143              :     /**
     144              :      * @brief Get the delay frames.
     145              :      *
     146              :      * Gets the frame delay of the playback from Rialto. Frame delay is the number
     147              :      * of frames left to play by the server.
     148              :      *
     149              :      * @param[out] delayFrames : Number of frames to be played.
     150              :      *
     151              :      * @retval true on success.
     152              :      */
     153              :     virtual bool getBufferDelay(uint32_t &delayFrames) = 0;
     154              : 
     155              :     /**
     156              :      * @brief Write audio frames
     157              :      *
     158              :      * Sends a buffer of audio data for playback
     159              :      *
     160              :      * @param[in]  numberOfFrames : Number of frames of audio in 'data'.
     161              :      * @param[in]  data           : Pointer to the data, byte length = numberOfFrames*sampleSize
     162              :      *
     163              :      * @retval true on success.
     164              :      */
     165              :     virtual bool writeBuffer(const uint32_t numberOfFrames, void *data) = 0;
     166              : 
     167              :     /**
     168              :      * @brief Get device information.
     169              :      *
     170              :      * Gets information for the web audio playback.
     171              :      * This information is used to determine the preferred buffer size to commit,
     172              :      * the maximum buffer size an application can commit and whether buffers can
     173              :      * be committed before a Play request.
     174              :      *
     175              :      * @param[out] preferredFrames     : preferred number of frames to be commited.
     176              :      * @param[out] maximumFrames       : Maximum number of frames that can be commited.
     177              :      * @param[out] supportDeferredPlay : Whether defered play is supported.
     178              :      *
     179              :      * @retval true on success.
     180              :      */
     181              :     virtual bool getDeviceInfo(uint32_t &preferredFrames, uint32_t &maximumFrames, bool &supportDeferredPlay) = 0;
     182              : 
     183              :     /**
     184              :      *
     185              :      * @brief Set level and transition of audio attenuation
     186              :      *
     187              :      * Sets the current volume for the pipeline (0.0 silent -> 1.0 full volume)
     188              :      *
     189              :      * @param[in] volume    : Target volume level (0.0 - 1.0)
     190              :      *
     191              :      * @retval true on success false otherwise
     192              :      */
     193              :     virtual bool setVolume(double volume) = 0;
     194              : 
     195              :     /**
     196              :      * @brief Get current audio level
     197              :      *
     198              :      * Fetches the current volume level for the pipeline.
     199              :      *
     200              :      * @param[out] volume   : Current volume level (range 0.0 - 1.0)
     201              :      *
     202              :      * @retval true on success false otherwise
     203              :      */
     204              :     virtual bool getVolume(double &volume) = 0;
     205              : 
     206              :     /**
     207              :      * @brief Returns the web audio player client.
     208              :      *
     209              :      * @retval The web audio player client.
     210              :      */
     211              :     virtual std::weak_ptr<IWebAudioPlayerClient> getClient() = 0;
     212              : };
     213              : 
     214              : }; // namespace firebolt::rialto
     215              : 
     216              : #endif // FIREBOLT_RIALTO_I_WEB_AUDIO_PLAYER_H_
        

Generated by: LCOV version 2.0-1