blob: b8a15e21f6a91e08a745f18da873c9d1623097ee [file] [log] [blame]
Emircan Uysaler0a375472017-12-11 12:21:02 +05301/*
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 Anton10542f22019-01-11 09:11:00 -080011#ifndef MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
12#define MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
Emircan Uysaler0a375472017-12-11 12:21:02 +053013
14#include <memory>
15#include <vector>
16
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "api/video_codecs/sdp_video_format.h"
18#include "api/video_codecs/video_decoder.h"
Emircan Uysaler0a375472017-12-11 12:21:02 +053019#include "api/video_codecs/video_decoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "api/video_codecs/video_encoder.h"
Emircan Uysaler0a375472017-12-11 12:21:02 +053021#include "api/video_codecs/video_encoder_factory.h"
Mirko Bonadei276827c2018-10-16 14:13:50 +020022#include "rtc_base/system/rtc_export.h"
Emircan Uysaler0a375472017-12-11 12:21:02 +053023
24namespace webrtc {
Emircan Uysalered425d12018-09-06 15:35:55 -070025// 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 Bonadei276827c2018-10-16 14:13:50 +020043class RTC_EXPORT MultiplexEncoderFactory : public VideoEncoderFactory {
Emircan Uysaler0a375472017-12-11 12:21:02 +053044 public:
Emircan Uysalered425d12018-09-06 15:35:55 -070045 // |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 Hefny77c8e652018-08-15 10:19:32 -070048 MultiplexEncoderFactory(std::unique_ptr<VideoEncoderFactory> factory,
49 bool supports_augmenting_data = false);
Emircan Uysaler0a375472017-12-11 12:21:02 +053050
51 std::vector<SdpVideoFormat> GetSupportedFormats() const override;
Mirta Dvornicic1ec2a162018-12-10 09:47:34 +000052 CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override;
Emircan Uysaler0a375472017-12-11 12:21:02 +053053 std::unique_ptr<VideoEncoder> CreateVideoEncoder(
54 const SdpVideoFormat& format) override;
55
56 private:
57 std::unique_ptr<VideoEncoderFactory> factory_;
Tarek Hefny77c8e652018-08-15 10:19:32 -070058 const bool supports_augmenting_data_;
Emircan Uysaler0a375472017-12-11 12:21:02 +053059};
60
Mirko Bonadei276827c2018-10-16 14:13:50 +020061class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
Emircan Uysaler0a375472017-12-11 12:21:02 +053062 public:
Emircan Uysalered425d12018-09-06 15:35:55 -070063 // |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 Hefny77c8e652018-08-15 10:19:32 -070066 MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory,
67 bool supports_augmenting_data = false);
Emircan Uysaler0a375472017-12-11 12:21:02 +053068
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 Hefny77c8e652018-08-15 10:19:32 -070075 const bool supports_augmenting_data_;
Emircan Uysaler0a375472017-12-11 12:21:02 +053076};
77
78} // namespace webrtc
79
Steve Anton10542f22019-01-11 09:11:00 -080080#endif // MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_