frame_transformer_interface.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2020 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 API_FRAME_TRANSFORMER_INTERFACE_H_
  11. #define API_FRAME_TRANSFORMER_INTERFACE_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "api/scoped_refptr.h"
  15. #include "api/video/encoded_frame.h"
  16. #include "api/video/video_frame_metadata.h"
  17. #include "rtc_base/ref_count.h"
  18. namespace webrtc {
  19. // Owns the frame payload data.
  20. class TransformableFrameInterface {
  21. public:
  22. virtual ~TransformableFrameInterface() = default;
  23. // Returns the frame payload data. The data is valid until the next non-const
  24. // method call.
  25. virtual rtc::ArrayView<const uint8_t> GetData() const = 0;
  26. // Copies |data| into the owned frame payload data.
  27. virtual void SetData(rtc::ArrayView<const uint8_t> data) = 0;
  28. virtual uint32_t GetTimestamp() const = 0;
  29. virtual uint32_t GetSsrc() const = 0;
  30. };
  31. class TransformableVideoFrameInterface : public TransformableFrameInterface {
  32. public:
  33. virtual ~TransformableVideoFrameInterface() = default;
  34. virtual bool IsKeyFrame() const = 0;
  35. // Returns data needed in the frame transformation logic; for example,
  36. // when the transformation applied to the frame is encryption/decryption, the
  37. // additional data holds the serialized generic frame descriptor extension
  38. // calculated in webrtc::RtpDescriptorAuthentication.
  39. // TODO(bugs.webrtc.org/11380) remove from interface once
  40. // webrtc::RtpDescriptorAuthentication is exposed in api/.
  41. virtual std::vector<uint8_t> GetAdditionalData() const = 0;
  42. virtual const VideoFrameMetadata& GetMetadata() const = 0;
  43. };
  44. // Extends the TransformableFrameInterface to expose audio-specific information.
  45. class TransformableAudioFrameInterface : public TransformableFrameInterface {
  46. public:
  47. virtual ~TransformableAudioFrameInterface() = default;
  48. // Exposes the frame header, enabling the interface clients to use the
  49. // information in the header as needed, for example to compile the list of
  50. // csrcs.
  51. virtual const RTPHeader& GetHeader() const = 0;
  52. };
  53. // Objects implement this interface to be notified with the transformed frame.
  54. class TransformedFrameCallback : public rtc::RefCountInterface {
  55. public:
  56. virtual void OnTransformedFrame(
  57. std::unique_ptr<TransformableFrameInterface> frame) = 0;
  58. protected:
  59. ~TransformedFrameCallback() override = default;
  60. };
  61. // Transforms encoded frames. The transformed frame is sent in a callback using
  62. // the TransformedFrameCallback interface (see above).
  63. class FrameTransformerInterface : public rtc::RefCountInterface {
  64. public:
  65. // Transforms |frame| using the implementing class' processing logic.
  66. virtual void Transform(
  67. std::unique_ptr<TransformableFrameInterface> transformable_frame) = 0;
  68. virtual void RegisterTransformedFrameCallback(
  69. rtc::scoped_refptr<TransformedFrameCallback>) {}
  70. virtual void RegisterTransformedFrameSinkCallback(
  71. rtc::scoped_refptr<TransformedFrameCallback>,
  72. uint32_t ssrc) {}
  73. virtual void UnregisterTransformedFrameCallback() {}
  74. virtual void UnregisterTransformedFrameSinkCallback(uint32_t ssrc) {}
  75. protected:
  76. ~FrameTransformerInterface() override = default;
  77. };
  78. } // namespace webrtc
  79. #endif // API_FRAME_TRANSFORMER_INTERFACE_H_