chromium/media/gpu/test/video_encoder/video_encoder_client.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 {

// Minimum number of bitstream buffers we need to make sure we don't risk a
// deadlock. See crrev/c/2340653.
// FFmpeg decoder buffers until its thread pool is full. The number of desired
// threads is 12 in 4k.
// https://source.chromium.org/chromium/chromium/src/+/main:media/filters/ffmpeg_video_decoder.cc;l=94;drc=002c0bc1ac64f33a327a42a54afb87500943a3b3
// Therefore, we need to have the number of bitstream buffers. See b/277368164.
static unsigned int kMinInFlightFrames =;

// TODO(crbug.com/1045825): Support encoding parameter changes.

// Callbacks can be called from any thread, but WeakPtrs are not thread-safe.
// This helper thunk wraps a WeakPtr into an 'Optional' value, so the WeakPtr is
// only dereferenced after rescheduling the task on the specified task runner.
template <typename CallbackFunc, typename... CallbackArgs>
void CallbackThunk(
    std::optional<base::WeakPtr<VideoEncoderClient>> encoder_client,
    scoped_refptr<base::SequencedTaskRunner> task_runner,
    CallbackFunc func,
    CallbackArgs... args) {}

}  // namespace

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() {}

// static
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() {}

}  // namespace test
}  // namespace media