sri_build_encoder_factory.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // /*
  2. // * Copyright (c) 2018 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. #include "api/video_codecs/builtin_video_encoder_factory.h"
  11. #include <memory>
  12. #include <vector>
  13. #include "absl/strings/match.h"
  14. #include "api/video_codecs/sdp_video_format.h"
  15. #include "api/video_codecs/video_encoder.h"
  16. #include "media/base/codec.h"
  17. #include "media/base/media_constants.h"
  18. #include "media/engine/encoder_simulcast_proxy.h"
  19. #include "media/engine/internal_encoder_factory.h"
  20. #include "rtc_base/checks.h"
  21. #include "sri_build_encoder_factory.h"
  22. #include "absl/memory/memory.h"
  23. #include "media/engine/internal_decoder_factory.h"
  24. #include "rtc_base/logging.h"
  25. #include "modules/video_coding/codecs/h264/include/h264.h"
  26. #include "modules/video_coding/codecs/vp8/include/vp8.h"
  27. #include "modules/video_coding/codecs/vp9/include/vp9.h"
  28. #include "api/video_codecs/video_encoder_factory.h"
  29. #include "rtc_base/checks.h"
  30. namespace webrtc {
  31. class ExternalEncoderFactory : public webrtc::VideoEncoderFactory {
  32. public:
  33. std::vector<webrtc::SdpVideoFormat> GetSupportedFormats()
  34. const override {
  35. std::vector<webrtc::SdpVideoFormat> video_formats;
  36. for (const webrtc::SdpVideoFormat& h264_format : webrtc::SupportedH264Codecs())
  37. video_formats.push_back(h264_format);
  38. return video_formats;
  39. }
  40. ExternalEncoderFactory::CodecInfo QueryVideoEncoder(
  41. const webrtc::SdpVideoFormat& format) const override {
  42. CodecInfo codec_info = { false };
  43. // codec_info.is_hardware_accelerated = true;
  44. codec_info.has_internal_source = false;
  45. return codec_info;
  46. }
  47. std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder(
  48. const webrtc::SdpVideoFormat& format) override {
  49. if (absl::EqualsIgnoreCase(format.name, cricket::kH264CodecName)) {
  50. if (webrtc::H264Encoder::IsSupported()) {
  51. // printf("进入h264 encode \n");
  52. // return absl::make_unique<webrtc::H264EncoderImpl>(cricket::VideoCodec(format));
  53. //jetson nvenc加速
  54. return absl::make_unique<webrtc::JetsonVideoEncoder>(cricket::VideoCodec(format));
  55. }
  56. }
  57. return nullptr;
  58. }
  59. };
  60. std::unique_ptr<webrtc::VideoEncoderFactory> CreateExternalVideoEncoderFactory() {
  61. return std::make_unique<ExternalEncoderFactory>();
  62. }
  63. }