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-03-29 09:30:40 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.14