blob: ae099a4ef3e78b1efadfb192d76903015dcb5349 [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
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -080011#ifndef MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_
12#define MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_
Emircan Uysaler0a375472017-12-11 12:21:02 +053013
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 Bonadei276827c2018-10-16 14:13:50 +020019#include "rtc_base/system/rtc_export.h"
Emircan Uysaler0a375472017-12-11 12:21:02 +053020
21namespace webrtc {
Emircan Uysalered425d12018-09-06 15:35:55 -070022// 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 Bonadei276827c2018-10-16 14:13:50 +020040class RTC_EXPORT MultiplexEncoderFactory : public VideoEncoderFactory {
Emircan Uysaler0a375472017-12-11 12:21:02 +053041 public:
Emircan Uysalered425d12018-09-06 15:35:55 -070042 // |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 Hefny77c8e652018-08-15 10:19:32 -070045 MultiplexEncoderFactory(std::unique_ptr<VideoEncoderFactory> factory,
46 bool supports_augmenting_data = false);
Emircan Uysaler0a375472017-12-11 12:21:02 +053047
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 Hefny77c8e652018-08-15 10:19:32 -070055 const bool supports_augmenting_data_;
Emircan Uysaler0a375472017-12-11 12:21:02 +053056};
57
Mirko Bonadei276827c2018-10-16 14:13:50 +020058class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
Emircan Uysaler0a375472017-12-11 12:21:02 +053059 public:
Emircan Uysalered425d12018-09-06 15:35:55 -070060 // |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 Hefny77c8e652018-08-15 10:19:32 -070063 MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory,
64 bool supports_augmenting_data = false);
Emircan Uysaler0a375472017-12-11 12:21:02 +053065
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 Hefny77c8e652018-08-15 10:19:32 -070072 const bool supports_augmenting_data_;
Emircan Uysaler0a375472017-12-11 12:21:02 +053073};
74
75} // namespace webrtc
76
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -080077#endif // MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_