Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc. 3 : * 4 : * Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com> 5 : * Author: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com> 6 : * 7 : * This program is free software; you can redistribute it and/or modify 8 : * it under the terms of the GNU General Public License as published by 9 : * the Free Software Foundation; either version 3 of the License, or 10 : * (at your option) any later version. 11 : * 12 : * This program is distributed in the hope that it will be useful, 13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : * GNU General Public License for more details. 16 : * 17 : * You should have received a copy of the GNU General Public License 18 : * along with this program; if not, write to the Free Software 19 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 : */ 21 : 22 : #pragma once 23 : 24 : #include "noncopyable.h" 25 : #include "media_encoder.h" 26 : #include "media_io_handle.h" 27 : 28 : #include <map> 29 : #include <string> 30 : #include <memory> 31 : #include <atomic> 32 : 33 : // Forward declarations 34 : namespace jami { 35 : class SocketPair; 36 : struct DeviceParams; 37 : } // namespace jami 38 : 39 : namespace jami { 40 : namespace video { 41 : 42 : class VideoSender : public VideoFramePassiveReader 43 : { 44 : public: 45 : VideoSender(const std::string& dest, 46 : const MediaStream& opts, 47 : const MediaDescription& args, 48 : SocketPair& socketPair, 49 : const uint16_t seqVal, 50 : uint16_t mtu, 51 : bool allowHwAccel = true); 52 : 53 300 : ~VideoSender() {}; 54 : 55 : void forceKeyFrame(); 56 : 57 : // as VideoFramePassiveReader 58 : void update(Observable<std::shared_ptr<MediaFrame>>* obs, 59 : const std::shared_ptr<MediaFrame>& frame_p) override; 60 : 61 : uint16_t getLastSeqValue(); 62 : 63 : void setChangeOrientationCallback(std::function<void(int)> cb); 64 : int setBitrate(uint64_t br); 65 : 66 : private: 67 : static constexpr int KEYFRAMES_AT_START {1}; // Number of keyframes to enforce at stream startup 68 : static constexpr unsigned KEY_FRAME_PERIOD {0}; // seconds before forcing a keyframe 69 : 70 : NON_COPYABLE(VideoSender); 71 : 72 : void encodeAndSendVideo(const std::shared_ptr<VideoFrame>&); 73 : 74 : // encoder MUST be deleted before muxContext 75 : std::unique_ptr<MediaIOHandle> muxContext_ = nullptr; 76 : std::unique_ptr<MediaEncoder> videoEncoder_ = nullptr; 77 : 78 : std::atomic<int> forceKeyFrame_ {KEYFRAMES_AT_START}; 79 : int keyFrameFreq_ {0}; // Set keyframe rate, 0 to disable auto-keyframe. Computed in constructor 80 : int64_t frameNumber_ = 0; 81 : 82 : int rotation_ = -1; 83 : std::function<void(int)> changeOrientationCallback_; 84 : }; 85 : } // namespace video 86 : } // namespace jami