videomanager.cpp 17.5 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2019 Savoir-faire Linux Inc.
3
 *
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 *  Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
 *
 *  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.
 */

23
#include "videomanager_interface.h"
24
#include "videomanager.h"
25 26
#include "localrecorder.h"
#include "localrecordermanager.h"
27
#include "libav_utils.h"
28
#include "video/video_input.h"
29
#include "video/video_device_monitor.h"
30 31 32
#include "account.h"
#include "logger.h"
#include "manager.h"
33
#include "system_codec_container.h"
34
#include "video/sinkclient.h"
35
#include "client/ring_signal.h"
36
#include "audio/ringbufferpool.h"
37
#include "dring/media_const.h"
38
#include "libav_utils.h"
39
#include "call_const.h"
40 41 42 43 44

#include <functional>
#include <memory>
#include <string>
#include <vector>
45 46 47 48
#include <new> // std::bad_alloc
#include <cstdlib>
#include <cstring> // std::memset
#include <ciso646> // fix windows compiler bug
49

50
namespace DRing {
51

52
MediaFrame::MediaFrame()
53 54 55 56 57 58 59
    : frame_ {av_frame_alloc(), [](AVFrame* frame){ av_frame_free(&frame); }},
      packet_(nullptr, [](AVPacket* p) {
        if (p) {
            av_packet_unref(p);
            delete p;
        }
    })
60 61 62 63 64
{
    if (not frame_)
        throw std::bad_alloc();
}

65
void
66
MediaFrame::copyFrom(const MediaFrame& o)
67 68 69 70 71
{
    reset();
    av_frame_ref(frame_.get(), o.frame_.get());
}

72 73 74 75
void
MediaFrame::reset() noexcept
{
    av_frame_unref(frame_.get());
76 77 78 79 80 81 82
    packet_.reset();
}

void
MediaFrame::setPacket(std::unique_ptr<AVPacket, void(*)(AVPacket*)>&& pkt)
{
    packet_ = std::move(pkt);
83 84
}

Adrien Béraud's avatar
Adrien Béraud committed
85
AudioFrame::AudioFrame(const jami::AudioFormat& format, size_t nb_samples)
86 87 88 89 90 91 92 93
 : MediaFrame()
{
    setFormat(format);
    if (nb_samples)
        reserve(nb_samples);
}

void
Adrien Béraud's avatar
Adrien Béraud committed
94
AudioFrame::setFormat(const jami::AudioFormat& format)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
{
    auto d = pointer();
    d->channels = format.nb_channels;
    d->channel_layout = av_get_default_channel_layout(format.nb_channels);
    d->sample_rate = format.sample_rate;
    d->format = format.sampleFormat;
}

void
AudioFrame::reserve(size_t nb_samples)
{
    if (nb_samples != 0) {
        auto d = pointer();
        d->nb_samples = nb_samples;
        int err;
        if ((err = av_frame_get_buffer(d, 0)) < 0) {
            throw std::bad_alloc();
        }
    }
}

void
117
AudioFrame::mix(const AudioFrame& frame)
118
{
119 120 121 122 123 124 125
    auto& f = *pointer();
    auto& fIn = *frame.pointer();
    if (f.channels != fIn.channels || f.format != fIn.format || f.sample_rate != fIn.sample_rate) {
        throw std::invalid_argument("Can't mix frames with different formats");
    }
    if (f.nb_samples == 0) {
        reserve(fIn.nb_samples);
Adrien Béraud's avatar
Adrien Béraud committed
126
        jami::libav_utils::fillWithSilence(&f);
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
    } else if (f.nb_samples != fIn.nb_samples) {
        throw std::invalid_argument("Can't mix frames with different length");
    }
    AVSampleFormat fmt = (AVSampleFormat)f.format;
    bool isPlanar = av_sample_fmt_is_planar(fmt);
    unsigned samplesPerChannel = isPlanar ? f.nb_samples : f.nb_samples * f.channels;
    unsigned channels = isPlanar ? f.channels : 1;
    if (fmt == AV_SAMPLE_FMT_S16 || fmt == AV_SAMPLE_FMT_S16P) {
        for (unsigned i=0; i < channels; i++) {
            auto c = (int16_t*)f.extended_data[i];
            auto cIn = (int16_t*)fIn.extended_data[i];
            for (unsigned s=0; s < samplesPerChannel; s++) {
                int32_t n = (int32_t)c[s] + (int32_t)cIn[s];
                n = std::min<int32_t>(n, std::numeric_limits<int16_t>::max());
                n = std::max<int32_t>(n, std::numeric_limits<int16_t>::min());
                c[s] = n;
            }
        }
    } else if (fmt == AV_SAMPLE_FMT_FLT || fmt == AV_SAMPLE_FMT_FLTP) {
        for (unsigned i=0; i < channels; i++) {
            auto c = (float*)f.extended_data[i];
            auto cIn = (float*)fIn.extended_data[i];
            for (unsigned s=0; s < samplesPerChannel; s++) {
                c[s] += cIn[s];
            }
        }
    } else {
        throw std::invalid_argument(std::string("Unsupported format for mixing: ") + av_get_sample_fmt_name(fmt));
    }
156 157
}

Philippe Gorley's avatar
Philippe Gorley committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
float
AudioFrame::calcRMS() const
{
    double rms = 0.0;
    auto fmt = static_cast<AVSampleFormat>(frame_->format);
    bool planar = av_sample_fmt_is_planar(fmt);
    int perChannel = planar ? frame_->nb_samples : frame_->nb_samples * frame_->channels;
    int channels = planar ? frame_->channels : 1;
    if (fmt == AV_SAMPLE_FMT_S16 || fmt == AV_SAMPLE_FMT_S16P) {
        for (int c = 0; c < channels; ++c) {
            auto buf = reinterpret_cast<int16_t*>(frame_->extended_data[c]);
            for (int i = 0; i < perChannel; ++i) {
                auto sample = buf[i] * 0.000030517578125f;
                rms += sample * sample;
            }
        }
    } else if (fmt == AV_SAMPLE_FMT_FLT || fmt == AV_SAMPLE_FMT_FLTP) {
        for (int c = 0; c < channels; ++c) {
            auto buf = reinterpret_cast<float*>(frame_->extended_data[c]);
            for (int i = 0; i < perChannel; ++i) {
                rms += buf[i] * buf[i];
            }
        }
    } else {
        // Should not happen
Adrien Béraud's avatar
Adrien Béraud committed
183
        JAMI_ERR() << "Unsupported format for getting volume level: " << av_get_sample_fmt_name(fmt);
Philippe Gorley's avatar
Philippe Gorley committed
184 185 186 187 188 189
        return 0.0;
    }
    // divide by the number of multi-byte samples
    return sqrt(rms / (frame_->nb_samples * frame_->channels));
}

190 191 192 193 194 195 196 197 198 199 200 201 202 203
VideoFrame::~VideoFrame()
{
    if (releaseBufferCb_)
        releaseBufferCb_(ptr_);
}

void
VideoFrame::reset() noexcept
{
    MediaFrame::reset();
    allocated_ = false;
    releaseBufferCb_ = {};
}

204
void
205
VideoFrame::copyFrom(const VideoFrame& o)
206 207 208 209 210 211
{
    MediaFrame::copyFrom(o);
    ptr_ = o.ptr_;
    allocated_ = o.allocated_;
}

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
size_t
VideoFrame::size() const noexcept
{
    return av_image_get_buffer_size((AVPixelFormat)frame_->format, frame_->width, frame_->height, 1);
}

int
VideoFrame::format() const noexcept
{
    return frame_->format;
}

int
VideoFrame::width() const noexcept
{
    return frame_->width;
}

int
VideoFrame::height() const noexcept
{
    return frame_->height;
}

void
VideoFrame::setGeometry(int format, int width, int height) noexcept
{
    frame_->format = format;
    frame_->width = width;
    frame_->height = height;
}

void
VideoFrame::reserve(int format, int width, int height)
{
    auto libav_frame = frame_.get();

    if (allocated_) {
        // nothing to do if same properties
        if (width == libav_frame->width
            and height == libav_frame->height
            and format == libav_frame->format)
        av_frame_unref(libav_frame);
    }

    setGeometry(format, width, height);
    if (av_frame_get_buffer(libav_frame, 32))
        throw std::bad_alloc();
    allocated_ = true;
    releaseBufferCb_ = {};
}

void
VideoFrame::setFromMemory(uint8_t* ptr, int format, int width, int height) noexcept
{
    reset();
    setGeometry(format, width, height);
    if (not ptr)
        return;
    av_image_fill_arrays(frame_->data, frame_->linesize, (uint8_t*)ptr,
                         (AVPixelFormat)frame_->format, width, height, 1);
}

void
VideoFrame::setFromMemory(uint8_t* ptr, int format, int width, int height,
277
                          const std::function<void(uint8_t*)>& cb) noexcept
278 279 280 281 282 283 284 285 286
{
    setFromMemory(ptr, format, width, height);
    if (cb) {
        releaseBufferCb_ = cb;
        ptr_ = ptr;
    }
}

void
287
VideoFrame::setReleaseCb(const std::function<void(uint8_t*)>& cb) noexcept
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
{
    if (cb) {
        releaseBufferCb_ = cb;
    }
}

void
VideoFrame::noise()
{
    auto f = frame_.get();
    if (f->data[0] == nullptr)
        return;
    for (std::size_t i=0 ; i < size(); ++i) {
        f->data[0][i] = std::rand() & 255;
    }
}

VideoFrame* getNewFrame()
{
Adrien Béraud's avatar
Adrien Béraud committed
307
    if (auto input = jami::Manager::instance().getVideoManager().videoInput.lock())
308 309 310 311 312 313
        return &input->getNewFrame();
    return nullptr;
}

void publishFrame()
{
Adrien Béraud's avatar
Adrien Béraud committed
314
    if (auto input = jami::Manager::instance().getVideoManager().videoInput.lock())
315 316 317
        return input->publishFrame();
}

318 319
void
registerVideoHandlers(const std::map<std::string,
320
    std::shared_ptr<CallbackWrapperBase>>&handlers)
321
{
322
    registerSignalHandlers(handlers);
323 324 325
}

std::vector<std::string>
326
getDeviceList()
327
{
Adrien Béraud's avatar
Adrien Béraud committed
328
    return jami::Manager::instance().getVideoManager().videoDeviceMonitor.getDeviceList();
329 330
}

331 332
VideoCapabilities
getCapabilities(const std::string& name)
333
{
Adrien Béraud's avatar
Adrien Béraud committed
334
    return jami::Manager::instance().getVideoManager().videoDeviceMonitor.getCapabilities(name);
335 336
}

337
std::string
338
getDefaultDevice()
339
{
Adrien Béraud's avatar
Adrien Béraud committed
340
    return jami::Manager::instance().getVideoManager().videoDeviceMonitor.getDefaultDevice();
341 342 343
}

void
344
setDefaultDevice(const std::string& name)
345
{
Adrien Béraud's avatar
Adrien Béraud committed
346 347 348
    JAMI_DBG("Setting default device to %s", name.c_str());
    jami::Manager::instance().getVideoManager().videoDeviceMonitor.setDefaultDevice(name);
    jami::Manager::instance().saveConfig();
349 350
}

Adrien Béraud's avatar
Adrien Béraud committed
351 352 353
void
setDeviceOrientation(const std::string& name, int angle)
{
Adrien Béraud's avatar
Adrien Béraud committed
354
    jami::Manager::instance().getVideoManager().setDeviceOrientation(name, angle);
Adrien Béraud's avatar
Adrien Béraud committed
355 356
}

357 358 359
std::map<std::string, std::string>
getDeviceParams(const std::string& name)
{
Adrien Béraud's avatar
Adrien Béraud committed
360
    auto params = jami::Manager::instance().getVideoManager().videoDeviceMonitor.getDeviceParams(name);
361 362 363 364 365 366 367 368 369 370 371 372
    std::stringstream width, height, rate;
    width << params.width;
    height << params.height;
    rate << params.framerate;
    return {
        {"format", params.format},
        {"width", width.str()},
        {"height", height.str()},
        {"rate", rate.str()}
    };
}

373
std::map<std::string, std::string>
374 375
getSettings(const std::string& name)
{
Adrien Béraud's avatar
Adrien Béraud committed
376
    return jami::Manager::instance().getVideoManager().videoDeviceMonitor.getSettings(name).to_map();
377 378
}

379
void
380 381
applySettings(const std::string& name,
              const std::map<std::string, std::string>& settings)
382
{
Adrien Béraud's avatar
Adrien Béraud committed
383
    jami::Manager::instance().getVideoManager().videoDeviceMonitor.applySettings(name, settings);
384
    jami::Manager::instance().saveConfig();
385 386
}

387
void
388
startCamera()
389
{
Adrien Béraud's avatar
Adrien Béraud committed
390 391
    jami::Manager::instance().getVideoManager().videoPreview = jami::getVideoCamera();
    jami::Manager::instance().getVideoManager().started = switchToCamera();
392 393 394
}

void
395
stopCamera()
396
{
397
    if (switchInput(""))
Adrien Béraud's avatar
Adrien Béraud committed
398 399
        jami::Manager::instance().getVideoManager().started = false;
    jami::Manager::instance().getVideoManager().videoPreview.reset();
400 401
}

Philippe Gorley's avatar
Philippe Gorley committed
402 403 404
void
startAudioDevice()
{
405
    // Don't start audio layer if already done
Adrien Béraud's avatar
Adrien Béraud committed
406
    auto audioLayer = jami::Manager::instance().getAudioDriver();
407
    if (!audioLayer)
Adrien Béraud's avatar
Adrien Béraud committed
408
        jami::Manager::instance().initAudioDriver();
409
    if (!audioLayer->isStarted())
Adrien Béraud's avatar
Adrien Béraud committed
410 411
        jami::Manager::instance().startAudioDriverStream();
    jami::Manager::instance().getVideoManager().audioPreview = jami::getAudioInput(jami::RingBufferPool::DEFAULT_ID);
Philippe Gorley's avatar
Philippe Gorley committed
412 413 414 415 416
}

void
stopAudioDevice()
{
Adrien Béraud's avatar
Adrien Béraud committed
417 418
    jami::Manager::instance().getVideoManager().audioPreview.reset();
    jami::Manager::instance().checkAudio(); // stops audio layer if no calls
Philippe Gorley's avatar
Philippe Gorley committed
419 420
}

421 422 423
std::string
startLocalRecorder(const bool& audioOnly, const std::string& filepath)
{
Adrien Béraud's avatar
Adrien Béraud committed
424 425
    if (!audioOnly && !jami::Manager::instance().getVideoManager().started) {
        JAMI_ERR("Couldn't start local video recorder (camera is not started)");
426 427 428
        return "";
    }

Adrien Béraud's avatar
Adrien Béraud committed
429
    auto rec = std::make_unique<jami::LocalRecorder>(audioOnly);
430 431 432 433 434 435
    rec->setPath(filepath);

    // retrieve final path (containing file extension)
    auto path = rec->getPath();

    try {
Adrien Béraud's avatar
Adrien Béraud committed
436
        jami::LocalRecorderManager::instance().insertRecorder(path, std::move(rec));
437
    } catch (const std::invalid_argument&) {
438 439 440
        return "";
    }

Adrien Béraud's avatar
Adrien Béraud committed
441
    auto ret = jami::LocalRecorderManager::instance().getRecorderByPath(path)->startRecording();
442
    if (!ret) {
Adrien Béraud's avatar
Adrien Béraud committed
443
        jami::LocalRecorderManager::instance().removeRecorderByPath(filepath);
444 445 446 447 448 449 450 451 452
        return "";
    }

    return path;
}

void
stopLocalRecorder(const std::string& filepath)
{
Adrien Béraud's avatar
Adrien Béraud committed
453
    jami::LocalRecorder *rec = jami::LocalRecorderManager::instance().getRecorderByPath(filepath);
454
    if (!rec) {
Adrien Béraud's avatar
Adrien Béraud committed
455
        JAMI_WARN("Can't stop non existing local recorder.");
456 457 458 459
        return;
    }

    rec->stopRecording();
Adrien Béraud's avatar
Adrien Béraud committed
460
    jami::LocalRecorderManager::instance().removeRecorderByPath(filepath);
461 462
}

463
bool
464
switchInput(const std::string& resource)
465
{
Adrien Béraud's avatar
Adrien Béraud committed
466
    if (auto call = jami::Manager::instance().getCurrentCall()) {
467 468 469 470 471
        if (call->hasVideo()) {
            // TODO remove this part when clients are updated to use Calljami::Manager::switchInput
            call->switchInput(resource);
            return true;
        }
472
    }
473 474 475 476 477 478 479 480 481
    bool ret = true;
    if (auto input = jami::Manager::instance().getVideoManager().videoInput.lock())
        ret = input->switchInput(resource).valid();
    else
        JAMI_WARN("Video input not initialized");

    if (auto input = jami::getAudioInput(jami::RingBufferPool::DEFAULT_ID))
        ret &= input->switchInput(resource).valid();
    return ret;
482 483
}

484
bool
485
switchToCamera()
486
{
Adrien Béraud's avatar
Adrien Béraud committed
487
    return switchInput(jami::Manager::instance().getVideoManager().videoDeviceMonitor.getMRLForDefaultDevice());
488 489 490
}

bool
491
hasCameraStarted()
492
{
Adrien Béraud's avatar
Adrien Béraud committed
493
    return jami::Manager::instance().getVideoManager().started;
494 495
}

496
void
497
registerSinkTarget(const std::string& sinkId, const SinkTarget& target)
498
{
Adrien Béraud's avatar
Adrien Béraud committed
499
   if (auto sink = jami::Manager::instance().getSinkClient(sinkId))
500 501
       sink->registerTarget(target);
   else
Adrien Béraud's avatar
Adrien Béraud committed
502
       JAMI_WARN("No sink found for id '%s'", sinkId.c_str());
503 504 505 506 507
}

void
registerAVSinkTarget(const std::string& sinkId, const AVSinkTarget& target)
{
Adrien Béraud's avatar
Adrien Béraud committed
508
   if (auto sink = jami::Manager::instance().getSinkClient(sinkId))
509 510
       sink->registerAVTarget(target);
   else
Adrien Béraud's avatar
Adrien Béraud committed
511
       JAMI_WARN("No sink found for id '%s'", sinkId.c_str());
512
}
513

514 515 516
std::map<std::string, std::string>
getRenderer(const std::string& callId)
{
Adrien Béraud's avatar
Adrien Béraud committed
517
   if (auto sink = jami::Manager::instance().getSinkClient(callId))
518 519 520
       return {
           {DRing::Media::Details::CALL_ID,  callId},
           {DRing::Media::Details::SHM_PATH, sink->openedName()},
521 522
           {DRing::Media::Details::WIDTH,    std::to_string(sink->getWidth())},
           {DRing::Media::Details::HEIGHT,   std::to_string(sink->getHeight())},
523 524 525 526 527 528 529 530 531 532
       };
   else
       return {
           {DRing::Media::Details::CALL_ID,  callId},
           {DRing::Media::Details::SHM_PATH, ""},
           {DRing::Media::Details::WIDTH,    "0"},
           {DRing::Media::Details::HEIGHT,   "0"},
       };
}

533 534 535 536
bool
getDecodingAccelerated()
{
#ifdef RING_ACCEL
Adrien Béraud's avatar
Adrien Béraud committed
537
    return jami::Manager::instance().videoPreferences.getDecodingAccelerated();
538 539 540 541 542 543 544 545 546
#else
    return false;
#endif
}

void
setDecodingAccelerated(bool state)
{
#ifdef RING_ACCEL
Adrien Béraud's avatar
Adrien Béraud committed
547 548
    JAMI_DBG("%s hardware acceleration", (state ? "Enabling" : "Disabling"));
    jami::Manager::instance().videoPreferences.setDecodingAccelerated(state);
549
    jami::Manager::instance().saveConfig();
550 551 552
#endif
}

553 554 555 556
bool
getEncodingAccelerated()
{
#ifdef RING_ACCEL
Adrien Béraud's avatar
Adrien Béraud committed
557
    return jami::Manager::instance().videoPreferences.getEncodingAccelerated();
558 559 560 561 562 563 564 565 566
#else
    return false;
#endif
}

void
setEncodingAccelerated(bool state)
{
#ifdef RING_ACCEL
Adrien Béraud's avatar
Adrien Béraud committed
567 568
    JAMI_DBG("%s hardware acceleration", (state ? "Enabling" : "Disabling"));
    jami::Manager::instance().videoPreferences.setEncodingAccelerated(state);
569
    jami::Manager::instance().saveConfig();
570 571 572
#endif
}

573
#if defined(__ANDROID__) || defined(RING_UWP) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)
574
void
575
addVideoDevice(const std::string &node, std::vector<std::map<std::string, std::string>> const * devInfo)
576
{
Adrien Béraud's avatar
Adrien Béraud committed
577
    jami::Manager::instance().getVideoManager().videoDeviceMonitor.addDevice(node, devInfo);
578 579 580 581 582
}

void
removeVideoDevice(const std::string &node)
{
Adrien Béraud's avatar
Adrien Béraud committed
583
    jami::Manager::instance().getVideoManager().videoDeviceMonitor.removeDevice(node);
584
}
585 586 587 588

void*
obtainFrame(int length)
{
Adrien Béraud's avatar
Adrien Béraud committed
589
    if (auto input = jami::Manager::instance().getVideoManager().videoInput.lock())
590 591 592 593 594 595 596 597
        return (*input).obtainFrame(length);

    return nullptr;
}

void
releaseFrame(void* frame)
{
Adrien Béraud's avatar
Adrien Béraud committed
598
    if (auto input = jami::Manager::instance().getVideoManager().videoInput.lock())
599 600
        (*input).releaseFrame(frame);
}
601 602
#endif

603 604
} // namespace DRing

Adrien Béraud's avatar
Adrien Béraud committed
605
namespace jami {
606

607 608
std::shared_ptr<video::VideoFrameActiveWriter>
getVideoCamera()
609
{
610 611
    auto& vmgr = Manager::instance().getVideoManager();
    if (auto input = vmgr.videoInput.lock())
612 613
        return input;

614
    vmgr.started = false;
615
    auto input = std::make_shared<video::VideoInput>();
616
    vmgr.videoInput = input;
617
    return input;
618 619
}

620 621
video::VideoDeviceMonitor&
getVideoDeviceMonitor()
622
{
623
    return Manager::instance().getVideoManager().videoDeviceMonitor;
624
}
625

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
std::shared_ptr<AudioInput>
getAudioInput(const std::string& id)
{
    auto& vmgr = Manager::instance().getVideoManager();
    std::lock_guard<std::mutex> lk(vmgr.audioMutex);

    // erase expired audio inputs
    for (auto it = vmgr.audioInputs.cbegin(); it != vmgr.audioInputs.cend();) {
        if (it->second.expired())
            it = vmgr.audioInputs.erase(it);
        else
            ++it;
    }

    auto it = vmgr.audioInputs.find(id);
    if (it != vmgr.audioInputs.end()) {
        if (auto input = it->second.lock()) {
            return input;
        }
    }

    auto input = std::make_shared<AudioInput>(id);
    vmgr.audioInputs[id] = input;
    return input;
}

Adrien Béraud's avatar
Adrien Béraud committed
652 653 654 655 656 657
void
VideoManager::setDeviceOrientation(const std::string& name, int angle)
{
    videoDeviceMonitor.setDeviceOrientation(name, angle);
}

Adrien Béraud's avatar
Adrien Béraud committed
658
} // namespace jami