LCOV - code coverage report
Current view: top level - src/media - media_player.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 3 3 100.0 %
Date: 2024-12-21 08:56:24 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : #pragma once
      18             : 
      19             : #include "audio/audio_input.h"
      20             : #ifdef ENABLE_VIDEO
      21             : #include "video/video_input.h"
      22             : #endif
      23             : #include "media_decoder.h"
      24             : #include <atomic>
      25             : 
      26             : namespace jami {
      27             : class MediaPlayer
      28             : {
      29             : public:
      30             :     MediaPlayer(const std::string& resource);
      31             :     ~MediaPlayer();
      32             : 
      33             :     void pause(bool pause);
      34             :     bool isInputValid();
      35             :     const std::string& getId() const;
      36             :     void muteAudio(bool mute);
      37             :     bool seekToTime(int64_t time);
      38             :     int64_t getPlayerPosition() const;
      39             :     int64_t getPlayerDuration() const;
      40             :     bool isPaused() const;
      41           5 :     void setAutoRestart(bool state) { autoRestart_ = state; }
      42             : 
      43             : private:
      44             :     std::string path_;
      45             :     bool autoRestart_ {false};
      46             : 
      47             :     // media inputs
      48             : #ifdef ENABLE_VIDEO
      49             :     std::shared_ptr<jami::video::VideoInput> videoInput_;
      50             : #endif
      51             :     std::shared_ptr<jami::AudioInput> audioInput_;
      52             :     std::shared_ptr<MediaDemuxer> demuxer_;
      53             :     ThreadLoop loop_;
      54             : 
      55             :     int64_t startTime_;
      56             :     int64_t lastPausedTime_;
      57             :     int64_t pauseInterval_;
      58             : 
      59   204605260 :     inline bool hasAudio() const { return audioStream_ >= 0; }
      60             : 
      61   204605261 :     inline bool hasVideo() const { return videoStream_ >= 0; }
      62             : 
      63             :     int audioStream_ = -1;
      64             :     int videoStream_ = -1;
      65             :     int64_t fileDuration_ = 0;
      66             : 
      67             :     void playFileFromBeginning();
      68             :     std::atomic_bool paused_ {true};
      69             :     bool readBufferOverflow_ = false;
      70             :     bool audioStreamEnded_ {false};
      71             :     bool videoStreamEnded_ {false};
      72             : 
      73             :     bool configureMediaInputs();
      74             :     void process();
      75             : 
      76             :     void emitInfo();
      77             :     void flushMediaBuffers();
      78             : 
      79             :     bool streamsFinished();
      80             : };
      81             : } // namespace jami

Generated by: LCOV version 1.14