#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/video/vpx_video_encoder.h"
#include <algorithm>
#include <memory>
#include <optional>
#include "base/containers/heap_array.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "media/base/media_switches.h"
#include "media/base/svc_scalability_mode.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_codecs.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "media/video/video_encoder_info.h"
#include "third_party/libvpx/source/libvpx/vpx/vp8cx.h"
#include "third_party/libyuv/include/libyuv/convert.h"
namespace media {
namespace {
constexpr vpx_enc_frame_flags_t VP8_UPDATE_NOTHING = …;
vpx_enc_frame_flags_t vp8_2layers_temporal_flags[] = …;
vpx_enc_frame_flags_t vp8_3layers_temporal_flags[] = …;
EncoderStatus SetUpVpxConfig(const VideoEncoder::Options& opts,
VideoCodecProfile profile,
vpx_codec_enc_cfg_t* config) { … }
vpx_svc_extra_cfg_t MakeSvcExtraConfig(const vpx_codec_enc_cfg_t& config) { … }
void FreeCodecCtx(vpx_codec_ctx_t* codec_ctx) { … }
std::string LogVpxErrorMessage(vpx_codec_ctx_t* context,
const char* message,
vpx_codec_err_t status) { … }
std::optional<VideoPixelFormat> GetConversionFormat(VideoCodecProfile profile,
VideoPixelFormat format,
bool needs_resize) { … }
void SetupStandardYuvPlanes(const VideoFrame& frame, vpx_image_t* vpx_image) { … }
void I444ToI410(const VideoFrame& frame, vpx_image_t* vpx_image) { … }
}
VpxVideoEncoder::VpxVideoEncoder() : … { … }
void VpxVideoEncoder::Initialize(VideoCodecProfile profile,
const Options& options,
EncoderInfoCB info_cb,
OutputCB output_cb,
EncoderStatusCB done_cb) { … }
void VpxVideoEncoder::Encode(scoped_refptr<VideoFrame> frame,
const EncodeOptions& encode_options,
EncoderStatusCB done_cb) { … }
void VpxVideoEncoder::ChangeOptions(const Options& options,
OutputCB output_cb,
EncoderStatusCB done_cb) { … }
base::TimeDelta VpxVideoEncoder::GetFrameDuration(const VideoFrame& frame) { … }
VpxVideoEncoder::~VpxVideoEncoder() { … }
void VpxVideoEncoder::Flush(EncoderStatusCB done_cb) { … }
VideoEncoderOutput VpxVideoEncoder::GetEncoderOutput(
int temporal_id,
base::TimeDelta timestamp,
gfx::ColorSpace color_space) const { … }
void VpxVideoEncoder::RecreateVpxImageIfNeeded(vpx_img_fmt fmt,
bool needs_memory) { … }
void VpxVideoEncoder::UpdateEncoderColorSpace() { … }
}