video_base.h 3.11 KB
Newer Older
1
/*
2
 *  Copyright (C) 2013-2019 Savoir-faire Linux Inc.
3
 *
4
 *  Author: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com>
5
 *  Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  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 28 29
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wshadow"
30
#include <yaml-cpp/yaml.h>
31
#pragma GCC diagnostic pop
32

33 34
#include <cstdlib>
#include <cstdint>
35
#include <memory>
36 37
#include <set>
#include <mutex>
38
#include <ciso646> // fix windows compiler bug
39

40 41 42
extern "C" {
#include <libavutil/pixfmt.h>

Adrien Béraud's avatar
Adrien Béraud committed
43 44
struct AVPacket;
struct AVDictionary;
45

46
#ifndef AVFORMAT_AVIO_H
Adrien Béraud's avatar
Adrien Béraud committed
47
struct AVIOContext;
48
#endif
49
}
50

51
namespace DRing {
52
class MediaFrame;
53 54 55
class VideoFrame;
}

Adrien Béraud's avatar
Adrien Béraud committed
56
namespace jami {
57
using MediaFrame = DRing::MediaFrame;
58 59 60
using VideoFrame = DRing::VideoFrame;
}

Adrien Béraud's avatar
Adrien Béraud committed
61
namespace jami { namespace video {
62

63 64
struct VideoFrameActiveWriter: Observable<std::shared_ptr<MediaFrame>> {};
struct VideoFramePassiveReader: Observer<std::shared_ptr<MediaFrame>> {};
65

66
/*=== VideoGenerator =========================================================*/
67

68 69
class VideoGenerator : public VideoFrameActiveWriter
{
70
public:
71
    VideoGenerator() { }
72 73 74

    virtual int getWidth() const = 0;
    virtual int getHeight() const = 0;
75
    virtual AVPixelFormat getPixelFormat() const = 0;
76

77
    std::shared_ptr<VideoFrame> obtainLastFrame();
78

79
public:
80
    // getNewFrame and publishFrame must be called by the same thread only
81
    VideoFrame& getNewFrame();
82
    void publishFrame();
83
    void publishFrame(std::shared_ptr<VideoFrame>);
84
    void flushFrames();
85 86

private:
87 88
    std::shared_ptr<VideoFrame> writableFrame_ = nullptr;
    std::shared_ptr<VideoFrame> lastFrame_ = nullptr;
89
    std::mutex mutex_ {}; // lock writableFrame_/lastFrame_ access
90 91
};

92 93 94 95 96 97 98 99 100
struct VideoSettings
{
    VideoSettings() {}
    VideoSettings(const std::map<std::string, std::string>& settings);

    std::map<std::string, std::string> to_map() const;

    std::string name {};
    std::string channel {};
101 102
    std::string video_size {};
    std::string framerate {};
103 104
};

Adrien Béraud's avatar
Adrien Béraud committed
105
}} // namespace jami::video
106 107 108

namespace YAML {
template<>
Adrien Béraud's avatar
Adrien Béraud committed
109 110 111
struct convert<jami::video::VideoSettings> {
    static Node encode(const jami::video::VideoSettings& rhs);
    static bool decode(const Node& node, jami::video::VideoSettings& rhs);
112 113
};

Adrien Béraud's avatar
Adrien Béraud committed
114
Emitter& operator << (Emitter& out, const jami::video::VideoSettings& v);
115 116

} // namespace YAML