webrtc_video_encoder_gpu.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_GPU_H_
  5. #define REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_GPU_H_
  6. #include "base/memory/scoped_refptr.h"
  7. #include "media/base/video_codecs.h"
  8. #include "remoting/codec/webrtc_video_encoder.h"
  9. #include "ui/gfx/geometry/size.h"
  10. namespace base {
  11. class SingleThreadTaskRunner;
  12. }
  13. namespace remoting {
  14. // A WebrtcVideoEncoder implementation utilizing the VideoEncodeAccelerator
  15. // framework to do hardware-accelerated encoding. Due to threading requirements
  16. // when using the VEA on Windows, WebrtcVideoEncoderGpu uses an inner 'core'
  17. // class which is run on a dedicated thread.
  18. class WebrtcVideoEncoderGpu : public WebrtcVideoEncoder {
  19. public:
  20. struct Profile {
  21. gfx::Size resolution;
  22. int frame_rate; // Always > 0
  23. };
  24. static std::unique_ptr<WebrtcVideoEncoder> CreateForH264();
  25. static bool IsSupportedByH264(const Profile& profile);
  26. ~WebrtcVideoEncoderGpu() override;
  27. WebrtcVideoEncoderGpu(const WebrtcVideoEncoderGpu&) = delete;
  28. WebrtcVideoEncoderGpu& operator=(const WebrtcVideoEncoderGpu&) = delete;
  29. // WebrtcVideoEncoder interface.
  30. void Encode(std::unique_ptr<webrtc::DesktopFrame> frame,
  31. const FrameParams& params,
  32. WebrtcVideoEncoder::EncodeCallback done) override;
  33. private:
  34. class Core;
  35. std::unique_ptr<Core> core_;
  36. explicit WebrtcVideoEncoderGpu(media::VideoCodecProfile codec_profile);
  37. // GPU operations are performed on this task runner. This is necessary as the
  38. // MF VEA must be created and destroyed on a specific thread and not a
  39. // sequence.
  40. // TODO(joedow): If we start supporting H.264 on non-Windows platforms and
  41. // they do not have this requirement, we can refactor this such that the
  42. // Windows impl runs on a dedicated thread and other platforms do not.
  43. scoped_refptr<base::SingleThreadTaskRunner> hw_encode_task_runner_;
  44. };
  45. } // namespace remoting
  46. #endif // REMOTING_CODEC_WEBRTC_VIDEO_ENCODER_GPU_H_