video_mixer.h 2.43 KB
Newer Older
1
/*
Sébastien Blin's avatar
Sébastien Blin committed
2
 *  Copyright (C) 2013-2019 Savoir-faire Linux Inc.
3 4
 *
 *  Author: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com>
Denys Vidal's avatar
Denys Vidal committed
5
 *  Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 *  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
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */

Guillaume Roguez's avatar
Guillaume Roguez committed
22
#pragma once
23 24

#include "noncopyable.h"
25
#include "video_base.h"
26
#include "video_scaler.h"
27
#include "threadloop.h"
28
#include "rw_mutex.h"
29

30
#include <list>
31
#include <chrono>
32
#include <memory>
33

Adrien Béraud's avatar
Adrien Béraud committed
34
namespace jami { namespace video {
35

36 37
class SinkClient;

38
class VideoMixer:
39
        public VideoGenerator,
40
        public VideoFramePassiveReader
41 42
{
public:
Guillaume Roguez's avatar
Guillaume Roguez committed
43 44
    VideoMixer(const std::string& id);
    ~VideoMixer();
45

46
    void setDimensions(int width, int height);
47

Guillaume Roguez's avatar
Guillaume Roguez committed
48 49
    int getWidth() const override;
    int getHeight() const override;
50
    AVPixelFormat getPixelFormat() const override;
51

52
    // as VideoFramePassiveReader
53 54 55
    void update(Observable<std::shared_ptr<MediaFrame>>* ob, const std::shared_ptr<MediaFrame>& v) override;
    void attached(Observable<std::shared_ptr<MediaFrame>>* ob) override;
    void detached(Observable<std::shared_ptr<MediaFrame>>* ob) override;
56

57
private:
58
    NON_COPYABLE(VideoMixer);
59

Guillaume Roguez's avatar
Guillaume Roguez committed
60
    struct VideoMixerSource;
61

Denys Vidal's avatar
Denys Vidal committed
62 63
    void render_frame(VideoFrame& output, const VideoFrame& input,
        const std::unique_ptr<VideoMixerSource>& source, int index);
64

65 66
    void start_sink();
    void stop_sink();
67

68 69
    void process();

70
    const std::string id_;
71 72
    int width_ = 0;
    int height_ = 0;
73
    std::list<std::unique_ptr<VideoMixerSource>> sources_;
Guillaume Roguez's avatar
Guillaume Roguez committed
74
    rw_mutex rwMutex_;
75

76
    std::shared_ptr<SinkClient> sink_;
77

Guillaume Roguez's avatar
Guillaume Roguez committed
78 79 80 81 82
    std::chrono::time_point<std::chrono::system_clock> lastProcess_;
    std::shared_ptr<VideoFrameActiveWriter> videoLocal_;
    VideoScaler scaler_;

    ThreadLoop loop_; // as to be last member
83
};
84

Adrien Béraud's avatar
Adrien Béraud committed
85
}} // namespace jami::video