gpu_video_encode_accelerator_helpers.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2018 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 MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_
  5. #define MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_
  6. #include <vector>
  7. #include "media/base/bitrate.h"
  8. #include "media/base/video_bitrate_allocation.h"
  9. #include "media/gpu/media_gpu_export.h"
  10. #include "media/video/video_encode_accelerator.h"
  11. #include "ui/gfx/geometry/size.h"
  12. namespace media {
  13. class Bitrate;
  14. // Helper functions for VideoEncodeAccelerator implementations in GPU process.
  15. // Calculate the bitstream buffer size for VideoEncodeAccelerator.
  16. // |size|: the resolution of video stream
  17. // |bitrate|: the bit rate in bps
  18. // |framerate|: the frame rate in fps
  19. MEDIA_GPU_EXPORT size_t GetEncodeBitstreamBufferSize(const gfx::Size& size,
  20. uint32_t bitrate,
  21. uint32_t framerate);
  22. // Get the maximum bitstream buffer size for VideoEncodeAccelerator.
  23. // |size|: the resolution of video stream
  24. MEDIA_GPU_EXPORT size_t GetEncodeBitstreamBufferSize(const gfx::Size& size);
  25. // Get the frame rate fraction assigned to each temporal layer.
  26. // |num_temporal_layers|: total number of temporal layers
  27. MEDIA_GPU_EXPORT std::vector<uint8_t> GetFpsAllocation(
  28. size_t num_temporal_layers);
  29. // Create default VideoBitrateAllocation from |config|. A bitrate of each
  30. // spatial layer (|config.spatial_layers[i].bitrate_bps| is distributed to
  31. // temporal layers in the spatial layer based on the same bitrate division ratio
  32. // as a software encoder. If |config.spatial_layers| is empty,
  33. // VideoBitrateAllocation(0, 0) is set to |config.bitrate.target_bps()| as it is
  34. // a configuration with no layers.
  35. MEDIA_GPU_EXPORT VideoBitrateAllocation
  36. AllocateBitrateForDefaultEncoding(const VideoEncodeAccelerator::Config& config);
  37. // Create VideoBitrateAllocation with |num_spatial_layers|,
  38. // |num_temporal_layers| and |bitrate|. |bitrate.target_bps()| is the bitrate of
  39. // the entire stream. |num_temporal_layers| is the number of temporal layers in
  40. // each spatial layer.
  41. // First, |bitrate.target_bps()| is distributed to spatial layers based on
  42. // libwebrtc bitrate division. Then the bitrate of each spatial layer is
  43. // distributed to temporal layers in the spatial layer based on the same bitrate
  44. // division ratio as a software encoder. If a variable bitrate is requested,
  45. // that is, |bitrate.mode()| is Bitrate::Mode::Variable, the peak will be set
  46. // equal to the |bitrate.peak_bps()|.
  47. MEDIA_GPU_EXPORT VideoBitrateAllocation
  48. AllocateDefaultBitrateForTesting(const size_t num_spatial_layers,
  49. const size_t num_temporal_layers,
  50. const Bitrate& bitrate);
  51. } // namespace media
  52. #endif // MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_