LCOV - code coverage report
Current view: top level - media/client/main/include - WebAudioPlayer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2025-02-18 13:13:53 Functions: 100.0 % 2 2

            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_CLIENT_WEB_AUDIO_PLAYER_H_
      21              : #define FIREBOLT_RIALTO_CLIENT_WEB_AUDIO_PLAYER_H_
      22              : 
      23              : #include "IClientController.h"
      24              : #include "IControlClient.h"
      25              : #include "IWebAudioPlayer.h"
      26              : #include "IWebAudioPlayerIpc.h"
      27              : #include "IWebAudioPlayerIpcClient.h"
      28              : #include <atomic>
      29              : #include <memory>
      30              : #include <mutex>
      31              : #include <stdint.h>
      32              : #include <string>
      33              : 
      34              : namespace firebolt::rialto
      35              : {
      36              : /**
      37              :  * @brief IWebAudioPlayer factory class definition.
      38              :  */
      39              : class WebAudioPlayerFactory : public IWebAudioPlayerFactory
      40              : {
      41              : public:
      42            2 :     WebAudioPlayerFactory() = default;
      43            2 :     ~WebAudioPlayerFactory() override = default;
      44              : 
      45              :     std::unique_ptr<IWebAudioPlayer> createWebAudioPlayer(std::weak_ptr<IWebAudioPlayerClient> client,
      46              :                                                           const std::string &audioMimeType, const uint32_t priority,
      47              :                                                           std::weak_ptr<const WebAudioConfig> config) const override;
      48              : 
      49              :     /**
      50              :      * @brief IWebAudioPlayer factory method with factory parameters for mock injection.
      51              :      *
      52              :      * @param[in] client                    : The Web Audio Player client.
      53              :      * @param[in] audioMimeType             : The audio encoding format, currently only "audio/x-raw" (PCM).
      54              :      * @param[in] priority                  : Priority value for this pipeline.
      55              :      * @param[in] config                    : Additional type dependent configuration data or nullptr.
      56              :      * @param[in] webAudioPlayerIpcFactory  : This was added for the test environment where a mock object needs to be
      57              :      * passed in.
      58              :      * @param[in] clientController          : This was added for the test environment where a mock object needs to be
      59              :      * passed in.
      60              :      *
      61              :      * @retval the new Web Audio Player instance or null on error.
      62              :      */
      63              :     virtual std::unique_ptr<IWebAudioPlayer>
      64              :     createWebAudioPlayer(std::weak_ptr<IWebAudioPlayerClient> client, const std::string &audioMimeType,
      65              :                          const uint32_t priority, std::weak_ptr<const WebAudioConfig> config,
      66              :                          std::weak_ptr<client::IWebAudioPlayerIpcFactory> webAudioPlayerIpcFactory,
      67              :                          std::weak_ptr<client::IClientController> clientController) const;
      68              : };
      69              : 
      70              : }; // namespace firebolt::rialto
      71              : 
      72              : namespace firebolt::rialto::client
      73              : {
      74              : class IWebAudioPlayerAndIControlClient : public IWebAudioPlayer, public IControlClient
      75              : {
      76              : };
      77              : 
      78              : /**
      79              :  * @brief The definition of the WebAudioPlayer.
      80              :  */
      81              : class WebAudioPlayer : public IWebAudioPlayerAndIControlClient, public client::IWebAudioPlayerIpcClient
      82              : {
      83              : public:
      84              :     /**
      85              :      * @brief The constructor.
      86              :      *
      87              :      * @param[in] client        : The Web Audio Player client
      88              :      * @param[in] audioMimeType : The audio encoding format, currently only "audio/x-raw" (PCM)
      89              :      * @param[in] priority      : Priority value for this pipeline.
      90              :      * @param[in] config        : Additional type dependent configuration data or nullptr
      91              :      */
      92              :     WebAudioPlayer(std::weak_ptr<IWebAudioPlayerClient> client, const std::string &audioMimeType,
      93              :                    const uint32_t priority, std::weak_ptr<const WebAudioConfig> config,
      94              :                    const std::shared_ptr<IWebAudioPlayerIpcFactory> &webAudioPlayerIpcFactory,
      95              :                    IClientController &clientController);
      96              : 
      97              :     /**
      98              :      * @brief Virtual destructor.
      99              :      */
     100              :     virtual ~WebAudioPlayer();
     101              : 
     102              :     bool play() override;
     103              : 
     104              :     bool pause() override;
     105              : 
     106              :     bool setEos() override;
     107              : 
     108              :     bool getBufferAvailable(uint32_t &availableFrames, std::shared_ptr<WebAudioShmInfo> &webAudioShmInfo) override;
     109              : 
     110              :     bool getBufferDelay(uint32_t &delayFrames) override;
     111              : 
     112              :     bool writeBuffer(const uint32_t numberOfFrames, void *data) override;
     113              : 
     114              :     bool getDeviceInfo(uint32_t &preferredFrames, uint32_t &maximumFrames, bool &supportDeferredPlay) override;
     115              : 
     116              :     bool setVolume(double volume) override;
     117              : 
     118              :     bool getVolume(double &volume) override;
     119              : 
     120              :     std::weak_ptr<IWebAudioPlayerClient> getClient() override;
     121              : 
     122              :     void notifyState(WebAudioPlayerState state) override;
     123              : 
     124              :     void notifyApplicationState(ApplicationState state) override;
     125              : 
     126              : protected:
     127              :     /**
     128              :      * @brief The web audio player client.
     129              :      */
     130              :     std::weak_ptr<IWebAudioPlayerClient> m_webAudioPlayerClient;
     131              : 
     132              :     /**
     133              :      * @brief The media player ipc object.
     134              :      */
     135              :     std::unique_ptr<IWebAudioPlayerIpc> m_webAudioPlayerIpc;
     136              : 
     137              :     /**
     138              :      * @brief The rialto client controller object.
     139              :      */
     140              :     IClientController &m_clientController;
     141              : 
     142              :     /**
     143              :      * @brief The shared memory region info.
     144              :      */
     145              :     std::shared_ptr<WebAudioShmInfo> m_webAudioShmInfo;
     146              : 
     147              :     /**
     148              :      * @brief Ensure thread safety for clients by preventing concurrent writing to the buffer.
     149              :      */
     150              :     std::mutex m_bufLock;
     151              : 
     152              :     /**
     153              :      * @brief The bytes per frame for this audio playback.
     154              :      */
     155              :     uint32_t m_bytesPerFrame;
     156              : 
     157              :     /**
     158              :      * @brief The current application state.
     159              :      */
     160              :     std::atomic<ApplicationState> m_currentAppState;
     161              : };
     162              : 
     163              : }; // namespace firebolt::rialto::client
     164              : 
     165              : #endif // FIREBOLT_RIALTO_CLIENT_WEB_AUDIO_PLAYER_H_
        

Generated by: LCOV version 2.0-1