LCOV - code coverage report
Current view: top level - foo/src/media/video - sinkclient.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 1 7 14.3 %
Date: 2026-02-28 10:41:24 Functions: 1 4 25.0 %

          Line data    Source code
       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             : #pragma once
      18             : 
      19             : #ifdef HAVE_CONFIG_H
      20             : #include "config.h"
      21             : #endif
      22             : 
      23             : #include "video_base.h"
      24             : #include <videomanager_interface.h>
      25             : 
      26             : #include <string>
      27             : #include <memory>
      28             : 
      29             : // #define DEBUG_FPS
      30             : 
      31             : namespace jami {
      32             : class MediaFilter;
      33             : }
      34             : 
      35             : namespace jami {
      36             : namespace video {
      37             : 
      38             : #ifdef ENABLE_SHM
      39             : class ShmHolder;
      40             : #endif // ENABLE_SHM
      41             : 
      42             : class VideoScaler;
      43             : 
      44             : class SinkClient : public VideoFramePassiveReader, public VideoFrameActiveWriter
      45             : {
      46             : public:
      47             :     SinkClient(const std::string& id = "", bool mixer = false);
      48             : 
      49         388 :     const std::string& getId() const noexcept { return id_; }
      50             : 
      51             :     std::string openedName() const noexcept;
      52             : 
      53           0 :     int getWidth() const noexcept { return width_; }
      54             : 
      55           0 :     int getHeight() const noexcept { return height_; }
      56             : 
      57             :     AVPixelFormat getPreferredFormat() const noexcept { return (AVPixelFormat) target_.preferredFormat; }
      58             : 
      59             :     // as VideoFramePassiveReader
      60             :     void update(Observable<std::shared_ptr<jami::MediaFrame>>*, const std::shared_ptr<jami::MediaFrame>&) override;
      61             : 
      62             :     bool start() noexcept;
      63             :     bool stop() noexcept;
      64             : 
      65             :     void setFrameSize(int width, int height);
      66             :     void setCrop(int x, int y, int w, int h);
      67             : 
      68           0 :     void registerTarget(libjami::SinkTarget target) noexcept
      69             :     {
      70           0 :         std::lock_guard lock(mtx_);
      71           0 :         target_ = std::move(target);
      72           0 :     }
      73             : 
      74             : #ifdef ENABLE_SHM
      75             :     void enableShm(bool value) { doShmTransfer_.store(value); }
      76             : #endif
      77             : 
      78             : private:
      79             :     const std::string id_;
      80             :     // True if the instance is used by a mixer.
      81             :     const bool mixer_ {false};
      82             :     int width_ {0};
      83             :     int height_ {0};
      84             : 
      85             :     struct Rect
      86             :     {
      87             :         int x {0}, y {0}, w {0}, h {0};
      88             :     };
      89             :     Rect crop_ {};
      90             : 
      91             :     bool started_ {false}; // used to arbitrate client's stop signal.
      92             :     int rotation_ {0};
      93             :     libjami::SinkTarget target_;
      94             :     std::unique_ptr<VideoScaler> scaler_;
      95             :     std::unique_ptr<MediaFilter> filter_;
      96             :     std::mutex mtx_;
      97             : 
      98             :     libjami::FrameBuffer configureFrameDirect(const std::shared_ptr<jami::MediaFrame>&);
      99             :     void sendFrameTransformed(AVFrame* frame);
     100             : 
     101             :     /**
     102             :      * Apply required transformations before sending frames to clients/observers:
     103             :      * - Transfer the frame from gpu to main memory, if needed.
     104             :      * - Rotate the frame as needed.
     105             :      * - Apply cropping as needed
     106             :      */
     107             :     std::shared_ptr<VideoFrame> applyTransform(VideoFrame& frame);
     108             : 
     109             : #ifdef DEBUG_FPS
     110             :     unsigned frameCount_;
     111             :     std::chrono::steady_clock::time_point lastFrameDebug_;
     112             : #endif
     113             : 
     114             : #ifdef ENABLE_SHM
     115             :     // using shared_ptr and not unique_ptr as ShmHolder is forwared only
     116             :     std::shared_ptr<ShmHolder> shm_;
     117             :     std::atomic_bool doShmTransfer_ {false};
     118             : #endif // ENABLE_SHM
     119             : };
     120             : 
     121             : } // namespace video
     122             : } // namespace jami

Generated by: LCOV version 1.14