LCOV - code coverage report
Current view: top level - foo/src/media/video - video_base.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 2 2 100.0 %
Date: 2026-02-28 10:41:24 Functions: 2 2 100.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             : #include "observer.h"
      20             : 
      21             : #pragma GCC diagnostic push
      22             : #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
      23             : #pragma GCC diagnostic ignored "-Wshadow"
      24             : #include <yaml-cpp/yaml.h>
      25             : #pragma GCC diagnostic pop
      26             : 
      27             : #include <cstdlib>
      28             : #include <memory>
      29             : #include <mutex>
      30             : 
      31             : extern "C" {
      32             : #include <libavutil/pixfmt.h>
      33             : 
      34             : struct AVPacket;
      35             : struct AVDictionary;
      36             : 
      37             : #ifndef AVFORMAT_AVIO_H
      38             : struct AVIOContext;
      39             : #endif
      40             : }
      41             : 
      42             : namespace libjami {
      43             : class MediaFrame;
      44             : class VideoFrame;
      45             : } // namespace libjami
      46             : 
      47             : namespace jami {
      48             : using MediaFrame = libjami::MediaFrame;
      49             : using VideoFrame = libjami::VideoFrame;
      50             : } // namespace jami
      51             : 
      52             : namespace jami {
      53             : namespace video {
      54             : 
      55             : struct VideoFrameActiveWriter : Observable<std::shared_ptr<MediaFrame>>
      56             : {};
      57             : struct VideoFramePassiveReader : Observer<std::shared_ptr<MediaFrame>>
      58             : {};
      59             : 
      60             : /*=== VideoGenerator =========================================================*/
      61             : 
      62             : class VideoGenerator : public VideoFrameActiveWriter
      63             : {
      64             : public:
      65         231 :     VideoGenerator() {}
      66             : 
      67             :     virtual int getWidth() const = 0;
      68             :     virtual int getHeight() const = 0;
      69             :     virtual AVPixelFormat getPixelFormat() const = 0;
      70             : 
      71             :     std::shared_ptr<VideoFrame> obtainLastFrame();
      72             : 
      73             : public:
      74             :     // getNewFrame and publishFrame must be called by the same thread only
      75             :     VideoFrame& getNewFrame();
      76             :     void publishFrame();
      77             :     void publishFrame(std::shared_ptr<VideoFrame>);
      78             :     void flushFrames();
      79             : 
      80             : private:
      81             :     std::shared_ptr<VideoFrame> writableFrame_ = nullptr;
      82             :     std::shared_ptr<VideoFrame> lastFrame_ = nullptr;
      83             :     std::mutex mutex_ {}; // lock writableFrame_/lastFrame_ access
      84             : };
      85             : 
      86             : struct VideoSettings
      87             : {
      88          90 :     VideoSettings() {}
      89             :     VideoSettings(const std::map<std::string, std::string>& settings);
      90             : 
      91             :     std::map<std::string, std::string> to_map() const;
      92             : 
      93             :     std::string unique_id {};
      94             :     std::string input {};
      95             :     std::string name {};
      96             :     std::string channel {};
      97             :     std::string video_size {};
      98             :     std::string framerate {};
      99             : };
     100             : 
     101             : } // namespace video
     102             : } // namespace jami
     103             : 
     104             : namespace YAML {
     105             : template<>
     106             : struct convert<jami::video::VideoSettings>
     107             : {
     108             :     static Node encode(const jami::video::VideoSettings& rhs);
     109             :     static bool decode(const Node& node, jami::video::VideoSettings& rhs);
     110             : };
     111             : 
     112             : Emitter& operator<<(Emitter& out, const jami::video::VideoSettings& v);
     113             : 
     114             : } // namespace YAML

Generated by: LCOV version 1.14