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