multiplex_codec_factory.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
  11. #define MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/video_codecs/sdp_video_format.h"
  15. #include "api/video_codecs/video_decoder.h"
  16. #include "api/video_codecs/video_decoder_factory.h"
  17. #include "api/video_codecs/video_encoder.h"
  18. #include "api/video_codecs/video_encoder_factory.h"
  19. #include "rtc_base/system/rtc_export.h"
  20. namespace webrtc {
  21. // 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.
  39. class RTC_EXPORT MultiplexEncoderFactory : public VideoEncoderFactory {
  40. public:
  41. // |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.
  44. MultiplexEncoderFactory(std::unique_ptr<VideoEncoderFactory> factory,
  45. bool supports_augmenting_data = false);
  46. std::vector<SdpVideoFormat> GetSupportedFormats() const override;
  47. std::unique_ptr<VideoEncoder> CreateVideoEncoder(
  48. const SdpVideoFormat& format) override;
  49. private:
  50. std::unique_ptr<VideoEncoderFactory> factory_;
  51. const bool supports_augmenting_data_;
  52. };
  53. class RTC_EXPORT MultiplexDecoderFactory : public VideoDecoderFactory {
  54. public:
  55. // |supports_augmenting_data| defines if the decoder would support augmenting
  56. // data. If set, the decoder is expected to output video frame buffers of type
  57. // AugmentedVideoFrameBuffer.
  58. MultiplexDecoderFactory(std::unique_ptr<VideoDecoderFactory> factory,
  59. bool supports_augmenting_data = false);
  60. std::vector<SdpVideoFormat> GetSupportedFormats() const override;
  61. std::unique_ptr<VideoDecoder> CreateVideoDecoder(
  62. const SdpVideoFormat& format) override;
  63. private:
  64. std::unique_ptr<VideoDecoderFactory> factory_;
  65. const bool supports_augmenting_data_;
  66. };
  67. } // namespace webrtc
  68. #endif // MEDIA_ENGINE_MULTIPLEX_CODEC_FACTORY_H_