• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override;
53   std::unique_ptr<VideoEncoder> CreateVideoEncoder(
54       const SdpVideoFormat& format) override;
55 
56  private:
57   std::unique_ptr<VideoEncoderFactory> factory_;
58   const bool supports_augmenting_data_;
59 };
60 
61 class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
62  public:
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.
66   MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory,
67                           bool supports_augmenting_data = false);
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_;
75   const bool supports_augmenting_data_;
76 };
77 
78 }  // namespace webrtc
79 
80 #endif  // MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
81