openh264_imp.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2015 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 OPENH264_IMP_H_
  12. #define OPENH264_IMP_H_
  13. // Everything declared in this header is only required when WebRTC is
  14. // build with H264 support, please do not move anything out of the
  15. // #ifdef unless needed and tested.
  16. #if defined(WEBRTC_WIN) && !defined(__clang__)
  17. #error "See: bugs.webrtc.org/9213#c13."
  18. #endif
  19. #include <memory>
  20. #include <vector>
  21. #include "api/video/i420_buffer.h"
  22. #include "api/video_codecs/video_encoder.h"
  23. #include "common_video/h264/h264_bitstream_parser.h"
  24. #include "modules/video_coding/codecs/h264/include/h264.h"
  25. #include "modules/video_coding/utility/quality_scaler.h"
  26. #include "third_party/openh264/src/codec/api/svc/codec_app_def.h"
  27. class ISVCEncoder;
  28. namespace webrtc {
  29. class H264EncoderImpl : public H264Encoder {
  30. public:
  31. struct LayerConfig {
  32. int simulcast_idx = 0;
  33. int width = -1;
  34. int height = -1;
  35. bool sending = true;
  36. bool key_frame_request = false;
  37. float max_frame_rate = 0;
  38. uint32_t target_bps = 0;
  39. uint32_t max_bps = 0;
  40. bool frame_dropping_on = false;
  41. int key_frame_interval = 0;
  42. int num_temporal_layers = 1;
  43. void SetStreamState(bool send_stream);
  44. };
  45. public:
  46. explicit H264EncoderImpl(const cricket::VideoCodec& codec);
  47. ~H264EncoderImpl() override;
  48. // |settings.max_payload_size| is ignored.
  49. // The following members of |codec_settings| are used. The rest are ignored.
  50. // - codecType (must be kVideoCodecH264)
  51. // - targetBitrate
  52. // - maxFramerate
  53. // - width
  54. // - height
  55. int32_t InitEncode(const VideoCodec* codec_settings,
  56. const VideoEncoder::Settings& settings) override;
  57. int32_t Release() override;
  58. int32_t RegisterEncodeCompleteCallback(
  59. EncodedImageCallback* callback) override;
  60. void SetRates(const RateControlParameters& parameters) override;
  61. // The result of encoding - an EncodedImage and CodecSpecificInfo - are
  62. // passed to the encode complete callback.
  63. int32_t Encode(const VideoFrame& frame,
  64. const std::vector<VideoFrameType>* frame_types) override;
  65. EncoderInfo GetEncoderInfo() const override;
  66. // Exposed for testing.
  67. H264PacketizationMode PacketizationModeForTesting() const {
  68. return packetization_mode_;
  69. }
  70. private:
  71. SEncParamExt CreateEncoderParams(size_t i) const;
  72. webrtc::H264BitstreamParser h264_bitstream_parser_;
  73. // Reports statistics with histograms.
  74. void ReportInit();
  75. void ReportError();
  76. std::vector<ISVCEncoder*> encoders_;
  77. std::vector<SSourcePicture> pictures_;
  78. std::vector<rtc::scoped_refptr<I420Buffer>> downscaled_buffers_;
  79. std::vector<LayerConfig> configurations_;
  80. std::vector<EncodedImage> encoded_images_;
  81. VideoCodec codec_;
  82. H264PacketizationMode packetization_mode_;
  83. size_t max_payload_size_;
  84. int32_t number_of_cores_;
  85. EncodedImageCallback* encoded_image_callback_;
  86. bool has_reported_init_;
  87. bool has_reported_error_;
  88. std::vector<uint8_t> tl0sync_limit_;
  89. };
  90. } // namespace webrtc
  91. #endif // OPENH264_IMP_H_