LCOV - code coverage report
Current view: top level - foo/src/jami - videomanager_interface.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 13 14 92.9 %
Date: 2026-02-28 10:41:24 Functions: 10 12 83.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 DENABLE_VIDEOMANAGERI_H
      19             : #define DENABLE_VIDEOMANAGERI_H
      20             : 
      21             : #include "jami.h"
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif // HAVE_CONFIG_H
      25             : 
      26             : extern "C" {
      27             : struct AVFrame;
      28             : struct AVPacket;
      29             : void av_frame_free(AVFrame** frame);
      30             : void av_packet_free(AVPacket** frame);
      31             : }
      32             : 
      33             : #include "def.h"
      34             : 
      35             : #include <memory>
      36             : #include <vector>
      37             : #include <map>
      38             : #include <string>
      39             : #include <functional>
      40             : #include <cstdint>
      41             : #include <cstdlib>
      42             : 
      43             : #ifdef __APPLE__
      44             : #import "TargetConditionals.h"
      45             : #endif
      46             : 
      47             : namespace jami {
      48             : struct AudioFormat;
      49             : }
      50             : 
      51             : namespace libjami {
      52             : 
      53             : [[deprecated("Replaced by registerSignalHandlers")]] LIBJAMI_PUBLIC void registerVideoHandlers(
      54             :     const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
      55             : 
      56             : struct LIBJAMI_PUBLIC AVFrame_deleter
      57             : {
      58       34689 :     inline void operator()(AVFrame* frame) const { av_frame_free(&frame); }
      59             : };
      60             : 
      61             : typedef std::unique_ptr<AVFrame, AVFrame_deleter> FrameBuffer;
      62             : 
      63             : struct LIBJAMI_PUBLIC AVPacket_deleter
      64             : {
      65        5672 :     inline void operator()(AVPacket* pkt) const { av_packet_free(&pkt); }
      66             : };
      67             : 
      68             : typedef std::unique_ptr<AVPacket, AVPacket_deleter> PacketBuffer;
      69             : 
      70             : class LIBJAMI_PUBLIC MediaFrame
      71             : {
      72             : public:
      73             :     // Construct an empty MediaFrame
      74             :     MediaFrame();
      75             :     MediaFrame(const MediaFrame&) = delete;
      76             :     MediaFrame& operator=(const MediaFrame& o) = delete;
      77             :     MediaFrame(MediaFrame&& o) = delete;
      78             :     MediaFrame& operator=(MediaFrame&& o) = delete;
      79             : 
      80       33790 :     virtual ~MediaFrame() = default;
      81             : 
      82             :     // Return a pointer on underlaying buffer
      83       26227 :     const AVFrame* pointer() const noexcept { return frame_.get(); }
      84       62972 :     AVFrame* pointer() noexcept { return frame_.get(); }
      85       20630 :     AVPacket* packet() const noexcept { return packet_.get(); }
      86             : 
      87             :     // Fill this MediaFrame with data from o
      88             :     void copyFrom(const MediaFrame& o);
      89             :     void setPacket(PacketBuffer&& pkt);
      90             : 
      91             :     // Reset internal buffers (return to an empty MediaFrame)
      92             :     virtual void reset() noexcept;
      93             : 
      94           0 :     FrameBuffer getFrame() { return std::move(frame_); }
      95             : 
      96             : protected:
      97             :     FrameBuffer frame_;
      98             :     PacketBuffer packet_;
      99             : };
     100             : 
     101             : class LIBJAMI_PUBLIC AudioFrame : public MediaFrame
     102             : {
     103             : public:
     104         152 :     AudioFrame()
     105         152 :         : MediaFrame()
     106         152 :     {}
     107             :     AudioFrame(const jami::AudioFormat& format, size_t nb_samples = 0);
     108       10216 :     ~AudioFrame() {};
     109             :     void mix(const AudioFrame& o);
     110             :     float calcRMS() const;
     111             :     jami::AudioFormat getFormat() const;
     112             :     size_t getFrameSize() const;
     113             :     bool has_voice {false};
     114             : 
     115             : private:
     116             :     void setFormat(const jami::AudioFormat& format);
     117             :     void reserve(size_t nb_samples = 0);
     118             : };
     119             : 
     120             : class LIBJAMI_PUBLIC VideoFrame : public MediaFrame
     121             : {
     122             : public:
     123             :     // Construct an empty VideoFrame
     124       23680 :     VideoFrame()
     125       23680 :         : MediaFrame()
     126       23676 :     {}
     127             :     ~VideoFrame();
     128             : 
     129             :     // Reset internal buffers (return to an empty VideoFrame)
     130             :     void reset() noexcept override;
     131             : 
     132             :     // Fill this VideoFrame with data from o
     133             :     void copyFrom(const VideoFrame& o);
     134             : 
     135             :     // Return frame size in bytes
     136             :     std::size_t size() const noexcept;
     137             : 
     138             :     // Return pixel format
     139             :     int format() const noexcept;
     140             : 
     141             :     // Return frame width in pixels
     142             :     int width() const noexcept;
     143             : 
     144             :     // Return frame height in pixels
     145             :     int height() const noexcept;
     146             : 
     147             :     // Allocate internal pixel buffers following given specifications
     148             :     void reserve(int format, int width, int height);
     149             : 
     150             :     // Return orientation (in degrees) stored in the frame metadata, or 0 by default.
     151             :     int getOrientation() const;
     152             : 
     153             :     // Set internal pixel buffers on given memory buffer
     154             :     // This buffer must follow given specifications.
     155             :     void setFromMemory(uint8_t* data, int format, int width, int height) noexcept;
     156             :     void setFromMemory(
     157             :         uint8_t* data, int format, int width, int height, const std::function<void(uint8_t*)>& cb) noexcept;
     158             :     void setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept;
     159             : 
     160             :     void noise();
     161             : 
     162             : private:
     163             :     std::function<void(uint8_t*)> releaseBufferCb_ {};
     164             :     uint8_t* ptr_ {nullptr};
     165             :     bool allocated_ {false};
     166             :     void setGeometry(int format, int width, int height) noexcept;
     167             : };
     168             : 
     169             : struct LIBJAMI_PUBLIC SinkTarget
     170             : {
     171             :     std::function<FrameBuffer()> pull;
     172             :     std::function<void(FrameBuffer)> push;
     173             :     int /* AVPixelFormat */ preferredFormat {-1 /* AV_PIX_FMT_NONE */};
     174             : };
     175             : 
     176             : using VideoCapabilities = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
     177             : 
     178             : LIBJAMI_PUBLIC std::vector<std::string> getDeviceList();
     179             : LIBJAMI_PUBLIC VideoCapabilities getCapabilities(const std::string& deviceId);
     180             : LIBJAMI_PUBLIC std::map<std::string, std::string> getSettings(const std::string& deviceId);
     181             : LIBJAMI_PUBLIC void applySettings(const std::string& deviceId, const std::map<std::string, std::string>& settings);
     182             : LIBJAMI_PUBLIC void setDefaultDevice(const std::string& deviceId);
     183             : LIBJAMI_PUBLIC void setDeviceOrientation(const std::string& deviceId, int angle);
     184             : LIBJAMI_PUBLIC std::map<std::string, std::string> getDeviceParams(const std::string& deviceId);
     185             : LIBJAMI_PUBLIC std::string getDefaultDevice();
     186             : LIBJAMI_PUBLIC void startAudioDevice();
     187             : LIBJAMI_PUBLIC void stopAudioDevice();
     188             : 
     189             : LIBJAMI_PUBLIC std::string openVideoInput(const std::string& path);
     190             : LIBJAMI_PUBLIC bool closeVideoInput(const std::string& id);
     191             : 
     192             : LIBJAMI_PUBLIC std::string createMediaPlayer(const std::string& path);
     193             : LIBJAMI_PUBLIC bool closeMediaPlayer(const std::string& id);
     194             : LIBJAMI_PUBLIC bool pausePlayer(const std::string& id, const bool& pause);
     195             : LIBJAMI_PUBLIC bool mutePlayerAudio(const std::string& id, const bool& mute);
     196             : LIBJAMI_PUBLIC bool playerSeekToTime(const std::string& id, const int& time);
     197             : LIBJAMI_PUBLIC int64_t getPlayerPosition(const std::string& id);
     198             : LIBJAMI_PUBLIC int64_t getPlayerDuration(const std::string& id);
     199             : LIBJAMI_PUBLIC void setAutoRestart(const std::string& id, const bool& restart);
     200             : 
     201             : LIBJAMI_PUBLIC bool registerSinkTarget(const std::string& sinkId, SinkTarget target);
     202             : #ifdef ENABLE_SHM
     203             : LIBJAMI_PUBLIC void startShmSink(const std::string& sinkId, bool value);
     204             : #endif
     205             : LIBJAMI_PUBLIC std::map<std::string, std::string> getRenderer(const std::string& callId);
     206             : 
     207             : LIBJAMI_PUBLIC std::string startLocalMediaRecorder(const std::string& videoInputId, const std::string& filepath);
     208             : LIBJAMI_PUBLIC void stopLocalRecorder(const std::string& filepath);
     209             : 
     210             : #if defined(__ANDROID__) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
     211             : LIBJAMI_PUBLIC void addVideoDevice(const std::string& node,
     212             :                                    const std::vector<std::map<std::string, std::string>>& devInfo = {});
     213             : LIBJAMI_PUBLIC void removeVideoDevice(const std::string& node);
     214             : LIBJAMI_PUBLIC VideoFrame* getNewFrame(std::string_view id);
     215             : LIBJAMI_PUBLIC void publishFrame(std::string_view id);
     216             : #endif
     217             : 
     218             : LIBJAMI_PUBLIC bool getDecodingAccelerated();
     219             : LIBJAMI_PUBLIC void setDecodingAccelerated(bool state);
     220             : LIBJAMI_PUBLIC bool getEncodingAccelerated();
     221             : LIBJAMI_PUBLIC void setEncodingAccelerated(bool state);
     222             : 
     223             : // player signal type definitions
     224             : struct LIBJAMI_PUBLIC MediaPlayerSignal
     225             : {
     226             :     struct LIBJAMI_PUBLIC FileOpened
     227             :     {
     228             :         constexpr static const char* name = "FileOpened";
     229             :         using cb_type = void(const std::string& /*playerId*/, std::map<std::string, std::string> /*playerInfo*/);
     230             :     };
     231             : };
     232             : 
     233             : // Video signal type definitions
     234             : struct LIBJAMI_PUBLIC VideoSignal
     235             : {
     236             :     struct LIBJAMI_PUBLIC DeviceEvent
     237             :     {
     238             :         constexpr static const char* name = "DeviceEvent";
     239             :         using cb_type = void(void);
     240             :     };
     241             :     struct LIBJAMI_PUBLIC DecodingStarted
     242             :     {
     243             :         constexpr static const char* name = "DecodingStarted";
     244             :         using cb_type = void(
     245             :             const std::string& /*id*/, const std::string& /*shm_path*/, int /*w*/, int /*h*/, bool /*is_mixer*/ id);
     246             :     };
     247             :     struct LIBJAMI_PUBLIC DecodingStopped
     248             :     {
     249             :         constexpr static const char* name = "DecodingStopped";
     250             :         using cb_type = void(const std::string& /*id*/, const std::string& /*shm_path*/, bool /*is_mixer*/);
     251             :     };
     252             : #ifdef __ANDROID__
     253             :     struct LIBJAMI_PUBLIC SetParameters
     254             :     {
     255             :         constexpr static const char* name = "SetParameters";
     256             :         using cb_type = void(
     257             :             const std::string& device, const int format, const int width, const int height, const int rate);
     258             :     };
     259             :     struct LIBJAMI_PUBLIC GetCameraInfo
     260             :     {
     261             :         constexpr static const char* name = "GetCameraInfo";
     262             :         using cb_type = void(const std::string& device,
     263             :                              std::vector<int>* formats,
     264             :                              std::vector<unsigned>* sizes,
     265             :                              std::vector<unsigned>* rates);
     266             :     };
     267             :     struct LIBJAMI_PUBLIC RequestKeyFrame
     268             :     {
     269             :         constexpr static const char* name = "RequestKeyFrame";
     270             :         using cb_type = void(const std::string& /*device*/);
     271             :     };
     272             :     struct LIBJAMI_PUBLIC SetBitrate
     273             :     {
     274             :         constexpr static const char* name = "SetBitrate";
     275             :         using cb_type = void(const std::string& /*device*/, const int bitrate);
     276             :     };
     277             : #endif
     278             :     struct LIBJAMI_PUBLIC StartCapture
     279             :     {
     280             :         constexpr static const char* name = "StartCapture";
     281             :         using cb_type = void(const std::string& /*device*/);
     282             :     };
     283             :     struct LIBJAMI_PUBLIC StopCapture
     284             :     {
     285             :         constexpr static const char* name = "StopCapture";
     286             :         using cb_type = void(const std::string& /*device*/);
     287             :     };
     288             :     struct LIBJAMI_PUBLIC DeviceAdded
     289             :     {
     290             :         constexpr static const char* name = "DeviceAdded";
     291             :         using cb_type = void(const std::string& /*device*/);
     292             :     };
     293             :     struct LIBJAMI_PUBLIC ParametersChanged
     294             :     {
     295             :         constexpr static const char* name = "ParametersChanged";
     296             :         using cb_type = void(const std::string& /*device*/);
     297             :     };
     298             : };
     299             : 
     300             : } // namespace libjami
     301             : 
     302             : #endif // DENABLE_VIDEOMANAGERI_H

Generated by: LCOV version 1.14