#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/gpu/test/video_encoder/video_encoder_client.h"
#include <algorithm>
#include <numeric>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_preferences.h"
#include "media/base/bitrate.h"
#include "media/base/media_log.h"
#include "media/gpu/gpu_video_encode_accelerator_factory.h"
#include "media/gpu/macros.h"
#include "media/gpu/test/bitstream_helpers.h"
#include "media/gpu/test/raw_video.h"
#include "media/gpu/test/video_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace test {
namespace {
static unsigned int kMinInFlightFrames = …;
template <typename CallbackFunc, typename... CallbackArgs>
void CallbackThunk(
std::optional<base::WeakPtr<VideoEncoderClient>> encoder_client,
scoped_refptr<base::SequencedTaskRunner> task_runner,
CallbackFunc func,
CallbackArgs... args) { … }
}
VideoEncoderClientConfig::VideoEncoderClientConfig(
const RawVideo* video,
VideoCodecProfile output_profile,
const std::vector<VideoEncodeAccelerator::Config::SpatialLayer>&
spatial_layers,
SVCInterLayerPredMode inter_layer_pred_mode,
VideoEncodeAccelerator::Config::ContentType content_type,
const VideoBitrateAllocation& bitrate_allocation,
bool reverse)
: … { … }
VideoEncoderClientConfig::VideoEncoderClientConfig(
const VideoEncoderClientConfig&) = default;
VideoEncoderClientConfig::~VideoEncoderClientConfig() = default;
VideoEncoderStats::VideoEncoderStats() = default;
VideoEncoderStats::~VideoEncoderStats() = default;
VideoEncoderStats::VideoEncoderStats(const VideoEncoderStats&) = default;
VideoEncoderStats::VideoEncoderStats(uint32_t framerate,
size_t num_temporal_layers,
size_t num_spatial_layers)
: … { … }
uint32_t VideoEncoderStats::Bitrate() const { … }
uint32_t VideoEncoderStats::LayerBitrate(size_t spatial_idx,
size_t temporal_idx) const { … }
void VideoEncoderStats::Reset() { … }
VideoEncoderClient::VideoEncoderClient(
const VideoEncoder::EventCallback& event_cb,
std::vector<std::unique_ptr<BitstreamProcessor>> bitstream_processors,
const VideoEncoderClientConfig& config)
: … { … }
VideoEncoderClient::~VideoEncoderClient() { … }
std::unique_ptr<VideoEncoderClient> VideoEncoderClient::Create(
const VideoEncoder::EventCallback& event_cb,
std::vector<std::unique_ptr<BitstreamProcessor>> bitstream_processors,
const VideoEncoderClientConfig& config) { … }
bool VideoEncoderClient::Initialize(const RawVideo* video) { … }
void VideoEncoderClient::Destroy() { … }
void VideoEncoderClient::Encode() { … }
void VideoEncoderClient::Flush() { … }
void VideoEncoderClient::UpdateBitrate(const VideoBitrateAllocation& bitrate,
uint32_t framerate) { … }
void VideoEncoderClient::ForceKeyFrame() { … }
bool VideoEncoderClient::WaitForBitstreamProcessors() { … }
VideoEncoderStats VideoEncoderClient::GetStats() const { … }
void VideoEncoderClient::ResetStats() { … }
void VideoEncoderClient::RequireBitstreamBuffers(
unsigned int input_count,
const gfx::Size& input_coded_size,
size_t output_buffer_size) { … }
scoped_refptr<BitstreamProcessor::BitstreamRef>
VideoEncoderClient::CreateBitstreamRef(
int32_t bitstream_buffer_id,
const BitstreamBufferMetadata& metadata) { … }
void VideoEncoderClient::BitstreamBufferReady(
int32_t bitstream_buffer_id,
const BitstreamBufferMetadata& metadata) { … }
void VideoEncoderClient::FlushDoneTaskIfNeeded() { … }
void VideoEncoderClient::BitstreamBufferProcessed(int32_t bitstream_buffer_id) { … }
void VideoEncoderClient::NotifyErrorStatus(const EncoderStatus& status) { … }
void VideoEncoderClient::NotifyEncoderInfoChange(const VideoEncoderInfo& info) { … }
void VideoEncoderClient::CreateEncoderTask(const RawVideo* video,
bool* success,
base::WaitableEvent* done) { … }
void VideoEncoderClient::DestroyEncoderTask(base::WaitableEvent* done) { … }
void VideoEncoderClient::EncodeTask() { … }
void VideoEncoderClient::EncodeNextFrameTask() { … }
void VideoEncoderClient::FlushTask() { … }
void VideoEncoderClient::UpdateBitrateTask(
const VideoBitrateAllocation& bitrate,
uint32_t framerate) { … }
void VideoEncoderClient::ForceKeyFrameTask() { … }
void VideoEncoderClient::EncodeDoneTask(base::TimeDelta timestamp) { … }
void VideoEncoderClient::FlushDoneTask(bool success) { … }
void VideoEncoderClient::FireEvent(VideoEncoder::EncoderEvent event) { … }
int32_t VideoEncoderClient::GetNextBitstreamBufferId() { … }
}
}