Ring Daemon 16.0.0
Loading...
Searching...
No Matches
media_player.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 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
26namespace jami {
28{
29public:
30 MediaPlayer(const std::string& resource);
32
33 void pause(bool pause);
34 bool isInputValid();
35 const std::string& getId() const;
36 void muteAudio(bool mute);
40 bool isPaused() const;
41 void setAutoRestart(bool state) { autoRestart_ = state; }
42
43private:
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 inline bool hasAudio() const { return audioStream_ >= 0; }
60
61 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
void pause(bool pause)
void muteAudio(bool mute)
bool isPaused() const
bool seekToTime(int64_t time)
const std::string & getId() const
int64_t getPlayerPosition() const
int64_t getPlayerDuration() const
void setAutoRestart(bool state)
void emitSignal(Args... args)
Definition ring_signal.h:64