LCOV - code coverage report
Current view: top level - media/server/gstplayer/interface - IGstWebAudioPlayer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 4 4
Test Date: 2025-02-18 13:13:53 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 2023 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_SERVER_I_GST_WEB_AUDIO_PLAYER_H_
      21              : #define FIREBOLT_RIALTO_SERVER_I_GST_WEB_AUDIO_PLAYER_H_
      22              : 
      23              : #include "IGstWebAudioPlayerClient.h"
      24              : #include "IHeartbeatHandler.h"
      25              : #include <memory>
      26              : #include <stdint.h>
      27              : #include <string>
      28              : 
      29              : namespace firebolt::rialto::server
      30              : {
      31              : class IGstWebAudioPlayer;
      32              : 
      33              : /**
      34              :  * @brief IGstWebAudioPlayer factory class, returns a concrete implementation of IGstWebAudioPlayer
      35              :  */
      36              : class IGstWebAudioPlayerFactory
      37              : {
      38              : public:
      39           64 :     IGstWebAudioPlayerFactory() = default;
      40           64 :     virtual ~IGstWebAudioPlayerFactory() = default;
      41              : 
      42              :     /**
      43              :      * @brief Gets the IGstWebAudioPlayerFactory instance.
      44              :      *
      45              :      * @retval the factory instance or null on error.
      46              :      */
      47              :     static std::shared_ptr<IGstWebAudioPlayerFactory> getFactory();
      48              : 
      49              :     /**
      50              :      * @brief Creates a IGstWebAudioPlayer object.
      51              :      *
      52              :      * @param[in] client    : The gstreamer web audio player client.
      53              :      * @param[in] priority  : Priority value for this pipeline.
      54              :      *
      55              :      * @retval the new player instance or null on error.
      56              :      */
      57              :     virtual std::unique_ptr<IGstWebAudioPlayer> createGstWebAudioPlayer(IGstWebAudioPlayerClient *client,
      58              :                                                                         const uint32_t priority) = 0;
      59              : };
      60              : 
      61              : class IGstWebAudioPlayer
      62              : {
      63              : public:
      64           72 :     IGstWebAudioPlayer() = default;
      65           72 :     virtual ~IGstWebAudioPlayer() = default;
      66              : 
      67              :     IGstWebAudioPlayer(const IGstWebAudioPlayer &) = delete;
      68              :     IGstWebAudioPlayer &operator=(const IGstWebAudioPlayer &) = delete;
      69              :     IGstWebAudioPlayer(IGstWebAudioPlayer &&) = delete;
      70              :     IGstWebAudioPlayer &operator=(IGstWebAudioPlayer &&) = delete;
      71              : 
      72              :     /**
      73              :      * @brief Sets the capabilities on the audio source.
      74              :      *
      75              :      * @param[in] audioMimeType: The audio encoding format, currently only "audio/x-raw" (PCM).
      76              :      * @param[in] config:        Additional type dependent configuration data or nullptr,
      77              :      */
      78              :     virtual void setCaps(const std::string &audioMimeType, std::weak_ptr<const WebAudioConfig> config) = 0;
      79              : 
      80              :     /**
      81              :      * @brief Starts playback of the web audio.
      82              :      *
      83              :      * This method is considered to be asynchronous and MUST NOT block
      84              :      * but should request playback and then return.
      85              :      *
      86              :      * Once the backend is successfully playing it should notify the
      87              :      * web audio player client of state WebAudioPlayerState::PLAYING.
      88              :      */
      89              :     virtual void play() = 0;
      90              : 
      91              :     /**
      92              :      * @brief Pauses playback of the web audio.
      93              :      *
      94              :      * This method is considered to be asynchronous and MUST NOT block
      95              :      * but should request the playback pause and then return.
      96              :      *
      97              :      * Once the backend is successfully paused it should notify the
      98              :      * web audio player client of state WebAudioPlayerState::PAUSED.
      99              :      */
     100              :     virtual void pause() = 0;
     101              : 
     102              :     /**
     103              :      * @brief Set level and transition of audio attenuation.
     104              :      *        Sets the current volume for the pipeline (0.0 silent -> 1.0 full volume).
     105              :      *
     106              :      * @param[in] volume : Target volume level (0.0 - 1.0)
     107              :      */
     108              :     virtual void setVolume(double volume) = 0;
     109              : 
     110              :     /**
     111              :      * @brief Get current audio level. Fetches the current volume level for the pipeline.
     112              :      *
     113              :      * @param[out] volume : Current volume level (range 0.0 - 1.0)
     114              :      *
     115              :      * @retval True on success.
     116              :      */
     117              :     virtual bool getVolume(double &volume) = 0;
     118              : 
     119              :     /**
     120              :      * @brief Write the buffer to gstreamer buffer.
     121              :      *
     122              :      * @param[in] mainPtr       : Pointer to the start of the data.
     123              :      * @param[in] mainLength    : Amount of bytes to write from the mainPtr.
     124              :      * @param[in] wrapPtr       : Pointer to the start of the wrapped data.
     125              :      * @param[in] wrapLength    : Amount of bytes to write from the wrapPtr.
     126              :      *
     127              :      * @retval The number of bytes written to gstreamer.
     128              :      */
     129              :     virtual uint32_t writeBuffer(uint8_t *mainPtr, uint32_t mainLength, uint8_t *wrapPtr, uint32_t wrapLength) = 0;
     130              : 
     131              :     /**
     132              :      * @brief Notify EOS at the end of the gstreamer buffers.
     133              :      */
     134              :     virtual void setEos() = 0;
     135              : 
     136              :     /**
     137              :      * @brief Gets the amount of bytes queued for playback on the app source.
     138              :      *
     139              :      * @retval The number of bytes queued.
     140              :      */
     141              :     virtual uint64_t getQueuedBytes() = 0;
     142              : 
     143              :     /**
     144              :      * @brief Checks if worker thread is not deadlocked
     145              :      *
     146              :      * @param[out] heartbeatHandler : The heartbeat handler instance
     147              :      *
     148              :      */
     149              :     virtual void ping(std::unique_ptr<IHeartbeatHandler> &&heartbeatHandler) = 0;
     150              : };
     151              : 
     152              : }; // namespace firebolt::rialto::server
     153              : 
     154              : #endif // FIREBOLT_RIALTO_SERVER_I_GST_WEB_AUDIO_PLAYER_H_
        

Generated by: LCOV version 2.0-1