LCOV - code coverage report
Current view: top level - src/media/video - video_base.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 2 2 100.0 %
Date: 2024-11-15 09:04:49 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.14