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-04-16 08:04:53 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com>
       5             :  *  Author: Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
       6             :  *
       7             :  *  This program is free software; you can redistribute it and/or modify
       8             :  *  it under the terms of the GNU General Public License as published by
       9             :  *  the Free Software Foundation; either version 3 of the License, or
      10             :  *  (at your option) any later version.
      11             :  *
      12             :  *  This program is distributed in the hope that it will be useful,
      13             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  *  GNU General Public License for more details.
      16             :  *
      17             :  *  You should have received a copy of the GNU General Public License
      18             :  *  along with this program; if not, write to the Free Software
      19             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      20             :  */
      21             : 
      22             : #pragma once
      23             : 
      24             : #include "noncopyable.h"
      25             : #include "observer.h"
      26             : 
      27             : #pragma GCC diagnostic push
      28             : #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
      29             : #pragma GCC diagnostic ignored "-Wshadow"
      30             : #include <yaml-cpp/yaml.h>
      31             : #pragma GCC diagnostic pop
      32             : 
      33             : #include <cstdlib>
      34             : #include <cstdint>
      35             : #include <memory>
      36             : #include <set>
      37             : #include <mutex>
      38             : #include <ciso646> // fix windows compiler bug
      39             : 
      40             : extern "C" {
      41             : #include <libavutil/pixfmt.h>
      42             : 
      43             : struct AVPacket;
      44             : struct AVDictionary;
      45             : 
      46             : #ifndef AVFORMAT_AVIO_H
      47             : struct AVIOContext;
      48             : #endif
      49             : }
      50             : 
      51             : namespace libjami {
      52             : class MediaFrame;
      53             : class VideoFrame;
      54             : } // namespace libjami
      55             : 
      56             : namespace jami {
      57             : using MediaFrame = libjami::MediaFrame;
      58             : using VideoFrame = libjami::VideoFrame;
      59             : } // namespace jami
      60             : 
      61             : namespace jami {
      62             : namespace video {
      63             : 
      64             : struct VideoFrameActiveWriter : Observable<std::shared_ptr<MediaFrame>>
      65             : {};
      66             : struct VideoFramePassiveReader : Observer<std::shared_ptr<MediaFrame>>
      67             : {};
      68             : 
      69             : /*=== VideoGenerator =========================================================*/
      70             : 
      71             : class VideoGenerator : public VideoFrameActiveWriter
      72             : {
      73             : public:
      74         241 :     VideoGenerator() {}
      75             : 
      76             :     virtual int getWidth() const = 0;
      77             :     virtual int getHeight() const = 0;
      78             :     virtual AVPixelFormat getPixelFormat() const = 0;
      79             : 
      80             :     std::shared_ptr<VideoFrame> obtainLastFrame();
      81             : 
      82             : public:
      83             :     // getNewFrame and publishFrame must be called by the same thread only
      84             :     VideoFrame& getNewFrame();
      85             :     void publishFrame();
      86             :     void publishFrame(std::shared_ptr<VideoFrame>);
      87             :     void flushFrames();
      88             : 
      89             : private:
      90             :     std::shared_ptr<VideoFrame> writableFrame_ = nullptr;
      91             :     std::shared_ptr<VideoFrame> lastFrame_ = nullptr;
      92             :     std::mutex mutex_ {}; // lock writableFrame_/lastFrame_ access
      93             : };
      94             : 
      95             : struct VideoSettings
      96             : {
      97         106 :     VideoSettings() {}
      98             :     VideoSettings(const std::map<std::string, std::string>& settings);
      99             : 
     100             :     std::map<std::string, std::string> to_map() const;
     101             : 
     102             :     std::string unique_id {};
     103             :     std::string input {};
     104             :     std::string name {};
     105             :     std::string channel {};
     106             :     std::string video_size {};
     107             :     std::string framerate {};
     108             : };
     109             : 
     110             : } // namespace video
     111             : } // namespace jami
     112             : 
     113             : namespace YAML {
     114             : template<>
     115             : struct convert<jami::video::VideoSettings>
     116             : {
     117             :     static Node encode(const jami::video::VideoSettings& rhs);
     118             :     static bool decode(const Node& node, jami::video::VideoSettings& rhs);
     119             : };
     120             : 
     121             : Emitter& operator<<(Emitter& out, const jami::video::VideoSettings& v);
     122             : 
     123             : } // namespace YAML

Generated by: LCOV version 1.14