#ifndef MEDIA_FFMPEG_FFMPEG_COMMON_H_
#define MEDIA_FFMPEG_FFMPEG_COMMON_H_
#include <stdint.h>
#include <string>
#include <cerrno>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "media/base/audio_codecs.h"
#include "media/base/channel_layout.h"
#include "media/base/encryption_scheme.h"
#include "media/base/media_export.h"
#include "media/base/sample_format.h"
#include "media/base/video_codecs.h"
#include "media/base/video_frame.h"
#include "media/ffmpeg/ffmpeg_deleters.h"
#include "third_party/ffmpeg/ffmpeg_features.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavutil/avutil.h>
#include <libavutil/channel_layout.h>
#if BUILDFLAG(ENABLE_PLATFORM_DOLBY_VISION)
#include <libavutil/dovi_meta.h>
#endif
#include <libavutil/imgutils.h>
#include <libavutil/log.h>
#include <libavutil/mastering_display_metadata.h>
#include <libavutil/mathematics.h>
#include <libavutil/opt.h>
}
namespace media {
constexpr int64_t kNoFFmpegTimestamp = …;
#if defined(ARCH_CPU_ARM_FAMILY)
constexpr inline int kFFmpegBufferAddressAlignment = 16;
#else
constexpr inline int kFFmpegBufferAddressAlignment = …;
#endif
class AudioDecoderConfig;
class VideoDecoderConfig;
inline void ScopedPtrAVFree::operator()(void* x) const { … }
inline void ScopedPtrAVFreePacket::operator()(void* x) const { … }
inline void ScopedPtrAVFreeContext::operator()(void* x) const { … }
inline void ScopedPtrAVFreeFrame::operator()(void* x) const { … }
inline base::span<const uint8_t> AVPacketData(const AVPacket& packet) { … }
MEDIA_EXPORT base::TimeDelta ConvertFromTimeBase(const AVRational& time_base,
int64_t timestamp);
MEDIA_EXPORT int64_t ConvertToTimeBase(const AVRational& time_base,
const base::TimeDelta& timestamp);
MEDIA_EXPORT AudioCodec CodecIDToAudioCodec(AVCodecID codec_id);
MEDIA_EXPORT std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext>
AVStreamToAVCodecContext(const AVStream* stream);
MEDIA_EXPORT bool AVStreamToAudioDecoderConfig(const AVStream* stream,
AudioDecoderConfig* config);
void AudioDecoderConfigToAVCodecContext(
const AudioDecoderConfig& config,
AVCodecContext* codec_context);
MEDIA_EXPORT bool AVStreamToVideoDecoderConfig(const AVStream* stream,
VideoDecoderConfig* config);
void VideoDecoderConfigToAVCodecContext(
const VideoDecoderConfig& config,
AVCodecContext* codec_context);
MEDIA_EXPORT bool AVCodecContextToAudioDecoderConfig(
const AVCodecContext* codec_context,
EncryptionScheme encryption_scheme,
AudioDecoderConfig* config);
MEDIA_EXPORT ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout,
int channels);
MEDIA_EXPORT AVCodecID AudioCodecToCodecID(AudioCodec audio_codec,
SampleFormat sample_format);
MEDIA_EXPORT AVCodecID VideoCodecToCodecID(VideoCodec video_codec);
MEDIA_EXPORT SampleFormat
AVSampleFormatToSampleFormat(AVSampleFormat sample_format, AVCodecID codec_id);
MEDIA_EXPORT VideoPixelFormat
AVPixelFormatToVideoPixelFormat(AVPixelFormat pixel_format);
std::string AVErrorToString(int errnum);
MEDIA_EXPORT int32_t HashCodecName(const char* codec_name);
}
#endif