Ring Daemon
Loading...
Searching...
No Matches
video_receive_thread.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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
18#ifndef _VIDEO_RECEIVE_THREAD_H_
19#define _VIDEO_RECEIVE_THREAD_H_
20
21#include "video_base.h"
22#include "media/media_codec.h"
24#include "media/media_codec.h"
25#include "media/media_device.h"
26#include "media/media_stream.h"
27#include "threadloop.h"
28#include "noncopyable.h"
29#include "media/libav_utils.h"
30
31#include <functional>
32#include <string>
33#include <climits>
34#include <sstream>
35#include <memory>
36
37namespace jami {
38class SocketPair;
39class MediaDecoder;
40} // namespace jami
41
42namespace jami {
43namespace video {
44
45class SinkClient;
46
48{
49public:
50 VideoReceiveThread(const std::string& id, bool useSink, const std::string& sdp, uint16_t mtu);
52
53 void startLoop();
54 void stopLoop();
55 void decodeFrame();
57 void setRequestKeyFrameCallback(std::function<void(void)> cb) { keyFrameRequestCallback_ = std::move(cb); };
58 void startSink();
59 void stopSink();
60 std::shared_ptr<SinkClient>& getSink() { return sink_; }
61
62 // as VideoGenerator
63 int getWidth() const;
64 int getHeight() const;
66 MediaStream getInfo() const;
67
73 void setRotation(int angle);
74
75 void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) { onSuccessfulSetup_ = cb; }
76
77 void setRecorderCallback(const std::function<void(const MediaStream& ms)>& cb);
78
79private:
81
82 DeviceParams args_;
83
84 /*-------------------------------------------------------------*/
85 /* These variables should be used in thread (i.e. run()) only! */
86 /*-------------------------------------------------------------*/
87 std::unique_ptr<MediaDecoder> videoDecoder_;
88 int dstWidth_ {0};
89 int dstHeight_ {0};
90 const std::string id_;
91 bool useSink_;
92 std::istringstream stream_;
93 MediaIOHandle sdpContext_;
94 std::unique_ptr<MediaIOHandle> demuxContext_;
95 std::shared_ptr<SinkClient> sink_;
96 bool isVideoConfigured_ {false};
97 uint16_t mtu_;
98 int rotation_ {0};
99
100 std::mutex rotationMtx_;
101 libav_utils::AVBufferPtr displayMatrix_;
102
103 static int interruptCb(void* ctx);
104 static int readFunction(void* opaque, uint8_t* buf, int buf_size);
105 bool configureVideoOutput();
106
107 ThreadLoop loop_;
108
109 // used by ThreadLoop
110 bool setup();
111 void process();
112 void cleanup();
113
114 std::function<void(void)> keyFrameRequestCallback_;
115 std::function<void(MediaType, bool)> onSuccessfulSetup_;
116 std::function<void(const MediaStream& ms)> recorderCallback_;
117};
118
119} // namespace video
120} // namespace jami
121
122#endif // _VIDEO_RECEIVE_THREAD_H_
void setSuccessfulSetupCb(const std::function< void(MediaType, bool)> &cb)
std::shared_ptr< SinkClient > & getSink()
void setRotation(int angle)
Set angle of rotation to apply to the video by the decoder.
void setRecorderCallback(const std::function< void(const MediaStream &ms)> &cb)
void addIOContext(SocketPair &socketPair)
void setRequestKeyFrameCallback(std::function< void(void)> cb)
std::unique_ptr< AVBufferRef, AVBufferRef_deleter > AVBufferPtr
Definition libav_utils.h:66
void emitSignal(Args... args)
Definition jami_signal.h:64
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30
DeviceParams Parameters used by MediaDecoder and MediaEncoder to open a LibAV device/stream.