blob: 79f9b8c0637cad2ecfac11809c4048d34f2d18a1 [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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/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 {
// 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| is the bitrate of the entire
// stream. |num_temporal_layers| is the number of temporal layers in each
// spatial layer.
// First, |bitrate| 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.
MEDIA_GPU_EXPORT VideoBitrateAllocation
AllocateDefaultBitrateForTesting(const size_t num_spatial_layers,
const size_t num_temporal_layers,
const uint32_t bitrate);
} // namespace media
#endif // MEDIA_GPU_GPU_VIDEO_ENCODE_ACCELERATOR_HELPERS_H_