LCOV - code coverage report
Current view: top level - src/media/video - video_receive_thread.h (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 100.0 % 3 3
Test Date: 2026-06-13 09:18:46 Functions: 100.0 % 3 3

            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              : 
      18              : #ifndef _VIDEO_RECEIVE_THREAD_H_
      19              : #define _VIDEO_RECEIVE_THREAD_H_
      20              : 
      21              : #include "video_base.h"
      22              : #include "media/media_codec.h"
      23              : #include "media/media_io_handle.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              : 
      37              : namespace jami {
      38              : class SocketPair;
      39              : class MediaDecoder;
      40              : } // namespace jami
      41              : 
      42              : namespace jami {
      43              : namespace video {
      44              : 
      45              : class SinkClient;
      46              : 
      47              : class VideoReceiveThread : public VideoGenerator
      48              : {
      49              : public:
      50              :     VideoReceiveThread(const std::string& id, bool useSink, const std::string& sdp, uint16_t mtu);
      51              :     ~VideoReceiveThread();
      52              : 
      53              :     void startLoop();
      54              :     void stopLoop();
      55              :     void decodeFrame();
      56              :     void addIOContext(SocketPair& socketPair);
      57          136 :     void setRequestKeyFrameCallback(std::function<void(void)> cb) { keyFrameRequestCallback_ = std::move(cb); };
      58              :     void startSink();
      59              :     void stopSink();
      60          177 :     std::shared_ptr<SinkClient>& getSink() { return sink_; }
      61              : 
      62              :     // as VideoGenerator
      63              :     int getWidth() const;
      64              :     int getHeight() const;
      65              :     AVPixelFormat getPixelFormat() const;
      66              :     MediaStream getInfo() const;
      67              : 
      68              :     /**
      69              :      * Set angle of rotation to apply to the video by the decoder
      70              :      *
      71              :      * @param angle Angle of rotation in degrees (counterclockwise)
      72              :      */
      73              :     void setRotation(int angle);
      74              : 
      75          136 :     void setSuccessfulSetupCb(const std::function<void(MediaType, bool)>& cb) { onSuccessfulSetup_ = cb; }
      76              : 
      77              :     void setRecorderCallback(const std::function<void(const MediaStream& ms)>& cb);
      78              : 
      79              : private:
      80              :     NON_COPYABLE(VideoReceiveThread);
      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_
        

Generated by: LCOV version 2.0-1