Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 11 | #ifndef MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_ |
| 12 | #define MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_ |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "api/video_codecs/video_decoder_factory.h" |
| 18 | #include "api/video_codecs/video_encoder_factory.h" |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame^] | 19 | #include "rtc_base/system/rtc_export.h" |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
Emircan Uysaler | ed425d1 | 2018-09-06 15:35:55 -0700 | [diff] [blame] | 22 | // Multiplex codec is a completely modular/optional codec that allows users to |
| 23 | // send more than a frame's opaque content(RGB/YUV) over video channels. |
| 24 | // - Allows sending Alpha channel over the wire iff input is |
| 25 | // I420ABufferInterface. Users can expect to receive I420ABufferInterface as the |
| 26 | // decoded video frame buffer. I420A data is split into YUV/AXX portions, |
| 27 | // encoded/decoded seperately and bitstreams are concatanated. |
| 28 | // - Allows sending augmenting data over the wire attached to the frame. This |
| 29 | // attached data portion is not encoded in any way and sent as it is. Users can |
| 30 | // input AugmentedVideoFrameBuffer and can expect the same interface as the |
| 31 | // decoded video frame buffer. |
| 32 | // - Showcases an example of how to add a custom codec in webrtc video channel. |
| 33 | // How to use it end-to-end: |
| 34 | // - Wrap your existing VideoEncoderFactory implemention with |
| 35 | // MultiplexEncoderFactory and VideoDecoderFactory implemention with |
| 36 | // MultiplexDecoderFactory below. For actual coding, multiplex creates encoder |
| 37 | // and decoder instance(s) using these factories. |
| 38 | // - Use Multiplex*coderFactory classes in CreatePeerConnectionFactory() calls. |
| 39 | // - Select "multiplex" codec in SDP negotiation. |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame^] | 40 | class RTC_EXPORT MultiplexEncoderFactory : public VideoEncoderFactory { |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 41 | public: |
Emircan Uysaler | ed425d1 | 2018-09-06 15:35:55 -0700 | [diff] [blame] | 42 | // |supports_augmenting_data| defines if the encoder would support augmenting |
| 43 | // data. If set, the encoder expects to receive video frame buffers of type |
| 44 | // AugmentedVideoFrameBuffer. |
Tarek Hefny | 77c8e65 | 2018-08-15 10:19:32 -0700 | [diff] [blame] | 45 | MultiplexEncoderFactory(std::unique_ptr<VideoEncoderFactory> factory, |
| 46 | bool supports_augmenting_data = false); |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 47 | |
| 48 | std::vector<SdpVideoFormat> GetSupportedFormats() const override; |
| 49 | CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override; |
| 50 | std::unique_ptr<VideoEncoder> CreateVideoEncoder( |
| 51 | const SdpVideoFormat& format) override; |
| 52 | |
| 53 | private: |
| 54 | std::unique_ptr<VideoEncoderFactory> factory_; |
Tarek Hefny | 77c8e65 | 2018-08-15 10:19:32 -0700 | [diff] [blame] | 55 | const bool supports_augmenting_data_; |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 56 | }; |
| 57 | |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame^] | 58 | class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory { |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 59 | public: |
Emircan Uysaler | ed425d1 | 2018-09-06 15:35:55 -0700 | [diff] [blame] | 60 | // |supports_augmenting_data| defines if the decoder would support augmenting |
| 61 | // data. If set, the decoder is expected to output video frame buffers of type |
| 62 | // AugmentedVideoFrameBuffer. |
Tarek Hefny | 77c8e65 | 2018-08-15 10:19:32 -0700 | [diff] [blame] | 63 | MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory, |
| 64 | bool supports_augmenting_data = false); |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 65 | |
| 66 | std::vector<SdpVideoFormat> GetSupportedFormats() const override; |
| 67 | std::unique_ptr<VideoDecoder> CreateVideoDecoder( |
| 68 | const SdpVideoFormat& format) override; |
| 69 | |
| 70 | private: |
| 71 | std::unique_ptr<VideoDecoderFactory> factory_; |
Tarek Hefny | 77c8e65 | 2018-08-15 10:19:32 -0700 | [diff] [blame] | 72 | const bool supports_augmenting_data_; |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace webrtc |
| 76 | |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 77 | #endif // MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_ |