xref: /aosp_15_r20/external/webrtc/media/engine/multiplex_codec_factory.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
11 #ifndef MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
12 #define MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "api/video_codecs/sdp_video_format.h"
18 #include "api/video_codecs/video_decoder.h"
19 #include "api/video_codecs/video_decoder_factory.h"
20 #include "api/video_codecs/video_encoder.h"
21 #include "api/video_codecs/video_encoder_factory.h"
22 #include "rtc_base/system/rtc_export.h"
23 
24 namespace webrtc {
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.
43 class RTC_EXPORT MultiplexEncoderFactory : public VideoEncoderFactory {
44  public:
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.
48   MultiplexEncoderFactory(std::unique_ptr<VideoEncoderFactory> factory,
49                           bool supports_augmenting_data = false);
50 
51   std::vector<SdpVideoFormat> GetSupportedFormats() const override;
52   std::unique_ptr<VideoEncoder> CreateVideoEncoder(
53       const SdpVideoFormat& format) override;
54 
55  private:
56   std::unique_ptr<VideoEncoderFactory> factory_;
57   const bool supports_augmenting_data_;
58 };
59 
60 class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
61  public:
62   // `supports_augmenting_data` defines if the decoder would support augmenting
63   // data. If set, the decoder is expected to output video frame buffers of type
64   // AugmentedVideoFrameBuffer.
65   MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory,
66                           bool supports_augmenting_data = false);
67 
68   std::vector<SdpVideoFormat> GetSupportedFormats() const override;
69   std::unique_ptr<VideoDecoder> CreateVideoDecoder(
70       const SdpVideoFormat& format) override;
71 
72  private:
73   std::unique_ptr<VideoDecoderFactory> factory_;
74   const bool supports_augmenting_data_;
75 };
76 
77 }  // namespace webrtc
78 
79 #endif  // MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
80