blob: 7a851c8c1ecfc4203ca83fae91ac86eac77fe67a [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"
19
20namespace webrtc {
Emircan Uysalered425d12018-09-06 15:35:55 -070021// Multiplex codec is a completely modular/optional codec that allows users to
22// send more than a frame's opaque content(RGB/YUV) over video channels.
23// - Allows sending Alpha channel over the wire iff input is
24// I420ABufferInterface. Users can expect to receive I420ABufferInterface as the
25// decoded video frame buffer. I420A data is split into YUV/AXX portions,
26// encoded/decoded seperately and bitstreams are concatanated.
27// - Allows sending augmenting data over the wire attached to the frame. This
28// attached data portion is not encoded in any way and sent as it is. Users can
29// input AugmentedVideoFrameBuffer and can expect the same interface as the
30// decoded video frame buffer.
31// - Showcases an example of how to add a custom codec in webrtc video channel.
32// How to use it end-to-end:
33// - Wrap your existing VideoEncoderFactory implemention with
34// MultiplexEncoderFactory and VideoDecoderFactory implemention with
35// MultiplexDecoderFactory below. For actual coding, multiplex creates encoder
36// and decoder instance(s) using these factories.
37// - Use Multiplex*coderFactory classes in CreatePeerConnectionFactory() calls.
38// - Select "multiplex" codec in SDP negotiation.
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -080039class MultiplexEncoderFactory : public VideoEncoderFactory {
Emircan Uysaler0a375472017-12-11 12:21:02 +053040 public:
Emircan Uysalered425d12018-09-06 15:35:55 -070041 // |supports_augmenting_data| defines if the encoder would support augmenting
42 // data. If set, the encoder expects to receive video frame buffers of type
43 // AugmentedVideoFrameBuffer.
Tarek Hefny77c8e652018-08-15 10:19:32 -070044 MultiplexEncoderFactory(std::unique_ptr<VideoEncoderFactory> factory,
45 bool supports_augmenting_data = false);
Emircan Uysaler0a375472017-12-11 12:21:02 +053046
47 std::vector<SdpVideoFormat> GetSupportedFormats() const override;
48 CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override;
49 std::unique_ptr<VideoEncoder> CreateVideoEncoder(
50 const SdpVideoFormat& format) override;
51
52 private:
53 std::unique_ptr<VideoEncoderFactory> factory_;
Tarek Hefny77c8e652018-08-15 10:19:32 -070054 const bool supports_augmenting_data_;
Emircan Uysaler0a375472017-12-11 12:21:02 +053055};
56
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -080057class MultiplexDecoderFactory : public VideoDecoderFactory {
Emircan Uysaler0a375472017-12-11 12:21:02 +053058 public:
Emircan Uysalered425d12018-09-06 15:35:55 -070059 // |supports_augmenting_data| defines if the decoder would support augmenting
60 // data. If set, the decoder is expected to output video frame buffers of type
61 // AugmentedVideoFrameBuffer.
Tarek Hefny77c8e652018-08-15 10:19:32 -070062 MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory,
63 bool supports_augmenting_data = false);
Emircan Uysaler0a375472017-12-11 12:21:02 +053064
65 std::vector<SdpVideoFormat> GetSupportedFormats() const override;
66 std::unique_ptr<VideoDecoder> CreateVideoDecoder(
67 const SdpVideoFormat& format) override;
68
69 private:
70 std::unique_ptr<VideoDecoderFactory> factory_;
Tarek Hefny77c8e652018-08-15 10:19:32 -070071 const bool supports_augmenting_data_;
Emircan Uysaler0a375472017-12-11 12:21:02 +053072};
73
74} // namespace webrtc
75
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -080076#endif // MEDIA_ENGINE_MULTIPLEXCODECFACTORY_H_