1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MEDIA_ENGINE_WEBRTC_MEDIA_ENGINE_H_
12 #define MEDIA_ENGINE_WEBRTC_MEDIA_ENGINE_H_
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "api/audio/audio_mixer.h"
19 #include "api/audio_codecs/audio_decoder_factory.h"
20 #include "api/audio_codecs/audio_encoder_factory.h"
21 #include "api/rtp_parameters.h"
22 #include "api/task_queue/task_queue_factory.h"
23 #include "api/transport/bitrate_settings.h"
24 #include "api/video_codecs/video_decoder_factory.h"
25 #include "api/video_codecs/video_encoder_factory.h"
26 #include "media/base/codec.h"
27 #include "media/base/media_engine.h"
28 #include "modules/audio_device/include/audio_device.h"
29 #include "modules/audio_processing/include/audio_processing.h"
30 #include "rtc_base/system/rtc_export.h"
31 
32 namespace cricket {
33 
34 struct MediaEngineDependencies {
35   MediaEngineDependencies() = default;
36   MediaEngineDependencies(const MediaEngineDependencies&) = delete;
37   MediaEngineDependencies(MediaEngineDependencies&&) = default;
38   MediaEngineDependencies& operator=(const MediaEngineDependencies&) = delete;
39   MediaEngineDependencies& operator=(MediaEngineDependencies&&) = default;
40   ~MediaEngineDependencies() = default;
41 
42   webrtc::TaskQueueFactory* task_queue_factory = nullptr;
43   rtc::scoped_refptr<webrtc::AudioDeviceModule> adm;
44   rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory;
45   rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory;
46   rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer;
47   rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing;
48 
49   std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory;
50   std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory;
51 };
52 
53 // CreateMediaEngine may be called on any thread, though the engine is
54 // only expected to be used on one thread, internally called the "worker
55 // thread". This is the thread Init must be called on.
56 RTC_EXPORT std::unique_ptr<MediaEngineInterface> CreateMediaEngine(
57     MediaEngineDependencies dependencies);
58 
59 // Verify that extension IDs are within 1-byte extension range and are not
60 // overlapping.
61 bool ValidateRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions);
62 
63 // Discard any extensions not validated by the 'supported' predicate. Duplicate
64 // extensions are removed if 'filter_redundant_extensions' is set, and also any
65 // mutually exclusive extensions (see implementation for details) are removed.
66 std::vector<webrtc::RtpExtension> FilterRtpExtensions(
67     const std::vector<webrtc::RtpExtension>& extensions,
68     bool (*supported)(absl::string_view),
69     bool filter_redundant_extensions);
70 
71 webrtc::BitrateConstraints GetBitrateConfigForCodec(const Codec& codec);
72 
73 }  // namespace cricket
74 
75 #endif  // MEDIA_ENGINE_WEBRTC_MEDIA_ENGINE_H_
76