File: gpu_video_encode_accelerator_helpers.h

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 3,792 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_
#define MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_

#include <vector>

#include "media/base/bitrate.h"
#include "media/base/video_bitrate_allocation.h"
#include "media/gpu/media_gpu_export.h"
#include "media/video/video_encode_accelerator.h"
#include "ui/gfx/geometry/size.h"

namespace media {

class Bitrate;

// Helper functions for VideoEncodeAccelerator implementations in GPU process.

// Calculate the bitstream buffer size for VideoEncodeAccelerator.
// |size|: the resolution of video stream
// |bitrate|: the bit rate in bps
// |framerate|: the frame rate in fps
MEDIA_GPU_EXPORT size_t GetEncodeBitstreamBufferSize(const gfx::Size& size,
                                                     uint32_t bitrate,
                                                     uint32_t framerate);

// Get the maximum bitstream buffer size for VideoEncodeAccelerator.
// |size|: the resolution of video stream
MEDIA_GPU_EXPORT size_t GetEncodeBitstreamBufferSize(const gfx::Size& size);

// Get the frame rate fraction assigned to each temporal layer.
// |num_temporal_layers|: total number of temporal layers
MEDIA_GPU_EXPORT std::vector<uint8_t> GetFpsAllocation(
    size_t num_temporal_layers);

// Create default VideoBitrateAllocation from |config|. A bitrate of each
// spatial layer (|config.spatial_layers[i].bitrate_bps| is distributed to
// temporal layers in the spatial layer based on the same bitrate division ratio
// as a software encoder. If |config.spatial_layers| is empty,
// VideoBitrateAllocation(0, 0) is set to |config.bitrate.target_bps()| as it is
// a configuration with no layers.
MEDIA_GPU_EXPORT VideoBitrateAllocation
AllocateBitrateForDefaultEncoding(const VideoEncodeAccelerator::Config& config);

// Create VideoBitrateAllocation with |num_spatial_layers|,
// |num_temporal_layers| and |bitrate|. |bitrate.target_bps()| is the bitrate of
// the entire stream. |num_temporal_layers| is the number of temporal layers in
// each spatial layer.
// First, |bitrate.target_bps()| is distributed to spatial layers based on
// libwebrtc bitrate division. Then the bitrate of each spatial layer is
// distributed to temporal layers in the spatial layer based on the same bitrate
// division ratio as a software encoder. If a variable bitrate is requested,
// that is, |bitrate.mode()| is Bitrate::Mode::Variable, the peak will be set
// equal to the |bitrate.peak_bps()|.
MEDIA_GPU_EXPORT VideoBitrateAllocation
AllocateDefaultBitrateForTesting(const size_t num_spatial_layers,
                                 const size_t num_temporal_layers,
                                 const Bitrate& bitrate);

// Create VideoBitrateAllocation with the bitrate for each spatial layer and
// |num_temporal_layers|.
VideoBitrateAllocation MEDIA_GPU_EXPORT
AllocateBitrateForDefaultEncodingWithBitrates(
    const std::vector<uint32_t>& spatial_layer_bitrates,
    const size_t num_temporal_layers,
    const bool uses_vbr);

VideoBitrateAllocation MEDIA_GPU_EXPORT
BitrateToBitrateAllocation(const Bitrate& bitrate);

class MEDIA_GPU_EXPORT VEAEncodingLatencyMetricsHelper {
 public:
  explicit VEAEncodingLatencyMetricsHelper(const std::string& uma_prefix,
                                           VideoCodec codec);
  VEAEncodingLatencyMetricsHelper() = delete;
  ~VEAEncodingLatencyMetricsHelper();

  void EncodeOneFrame(bool is_key_frame, base::TimeDelta start_time);

 private:
  const std::string uma_name_;
  uint32_t frame_count_ = 0;
  int64_t total_encode_time_ms_ = 0;
};

}  // namespace media

#endif  // MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_