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: 2025-12-18 10:07:43 Functions: 1 4 25.0 %

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

Generated by: LCOV version 1.14