various small code cleanups and improvements

Largely refactoring work to make the code somewhat nicer to work with.
This commit is contained in:
itsmattkc
2019-12-26 19:00:08 +11:00
parent 83077c939e
commit 61c60e00d6
87 changed files with 596 additions and 567 deletions
+17 -17
View File
@@ -66,36 +66,36 @@ AVSampleFormat FFmpegCommon::GetFFmpegSampleFormat(const SampleFormat &smp_fmt)
return AV_SAMPLE_FMT_NONE;
}
AVPixelFormat FFmpegCommon::GetFFmpegPixelFormat(const olive::PixelFormat &pix_fmt)
AVPixelFormat FFmpegCommon::GetFFmpegPixelFormat(const PixelFormat::Format &pix_fmt)
{
switch (pix_fmt) {
case olive::PIX_FMT_RGBA8:
case PixelFormat::PIX_FMT_RGBA8:
return AV_PIX_FMT_RGBA;
case olive::PIX_FMT_RGBA16U:
case PixelFormat::PIX_FMT_RGBA16U:
return AV_PIX_FMT_RGBA64;
case olive::PIX_FMT_RGBA16F:
case olive::PIX_FMT_RGBA32F:
case olive::PIX_FMT_INVALID:
case olive::PIX_FMT_COUNT:
case PixelFormat::PIX_FMT_RGBA16F:
case PixelFormat::PIX_FMT_RGBA32F:
case PixelFormat::PIX_FMT_INVALID:
case PixelFormat::PIX_FMT_COUNT:
break;
}
return AV_PIX_FMT_NONE;
}
olive::PixelFormat FFmpegCommon::GetCompatiblePixelFormat(const olive::PixelFormat &pix_fmt)
PixelFormat::Format FFmpegCommon::GetCompatiblePixelFormat(const PixelFormat::Format &pix_fmt)
{
switch (pix_fmt) {
case olive::PIX_FMT_RGBA8:
return olive::PIX_FMT_RGBA8;
case olive::PIX_FMT_RGBA16U:
case olive::PIX_FMT_RGBA16F:
case olive::PIX_FMT_RGBA32F:
return olive::PIX_FMT_RGBA16U;
case olive::PIX_FMT_INVALID:
case olive::PIX_FMT_COUNT:
case PixelFormat::PIX_FMT_RGBA8:
return PixelFormat::PIX_FMT_RGBA8;
case PixelFormat::PIX_FMT_RGBA16U:
case PixelFormat::PIX_FMT_RGBA16F:
case PixelFormat::PIX_FMT_RGBA32F:
return PixelFormat::PIX_FMT_RGBA16U;
case PixelFormat::PIX_FMT_INVALID:
case PixelFormat::PIX_FMT_COUNT:
break;
}
return olive::PIX_FMT_INVALID;
return PixelFormat::PIX_FMT_INVALID;
}
+2 -2
View File
@@ -18,12 +18,12 @@ public:
/**
* @brief Returns a native pixel format that can be used to convert from a native frame to an AVFrame with minimal data loss
*/
static olive::PixelFormat GetCompatiblePixelFormat(const olive::PixelFormat& pix_fmt);
static PixelFormat::Format GetCompatiblePixelFormat(const PixelFormat::Format& pix_fmt);
/**
* @brief Returns an FFmpeg pixel format for a given native pixel format
*/
static AVPixelFormat GetFFmpegPixelFormat(const olive::PixelFormat& pix_fmt);
static AVPixelFormat GetFFmpegPixelFormat(const PixelFormat::Format& pix_fmt);
/**
* @brief Returns a native sample format type for a given AVSampleFormat
+4 -4
View File
@@ -141,10 +141,10 @@ bool FFmpegDecoder::Open()
// Note that FFmpeg doesn't support float formats
switch (ideal_pix_fmt) {
case AV_PIX_FMT_RGBA:
output_fmt_ = olive::PIX_FMT_RGBA8;
output_fmt_ = PixelFormat::PIX_FMT_RGBA8;
break;
case AV_PIX_FMT_RGBA64:
output_fmt_ = olive::PIX_FMT_RGBA16U;
output_fmt_ = PixelFormat::PIX_FMT_RGBA16U;
break;
default:
// We should never get here, but if we do there's nothing we can do with this format
@@ -224,13 +224,13 @@ FramePtr FFmpegDecoder::RetrieveVideo(const rational &timecode)
FramePtr frame_container = Frame::Create();
frame_container->set_width(frame->width);
frame_container->set_height(frame->height);
frame_container->set_format(static_cast<olive::PixelFormat>(output_fmt_));
frame_container->set_format(static_cast<PixelFormat::Format>(output_fmt_));
frame_container->set_timestamp(Timecode::timestamp_to_time(target_ts, avstream_->time_base));
frame_container->allocate();
// Convert pixel format/linesize if necessary
uint8_t* dst_data = reinterpret_cast<uint8_t*>(frame_container->data());
int dst_linesize = frame_container->width() * PixelService::BytesPerPixel(static_cast<olive::PixelFormat>(output_fmt_));
int dst_linesize = frame_container->width() * PixelService::BytesPerPixel(static_cast<PixelFormat::Format>(output_fmt_));
// Perform pixel conversion
sws_scale(scale_ctx_,
+1 -1
View File
@@ -115,7 +115,7 @@ bool FFmpegEncoder::OpenInternal()
}
// This is the format we will expect frames received in Write() to be in
olive::PixelFormat native_pixel_fmt = params().video_params().format();
PixelFormat::Format native_pixel_fmt = params().video_params().format();
// This is the format we will need to convert the frame to for swscale to understand it
video_conversion_fmt_ = FFmpegCommon::GetCompatiblePixelFormat(native_pixel_fmt);
+1 -1
View File
@@ -56,7 +56,7 @@ private:
AVStream* video_stream_;
AVCodecContext* video_codec_ctx_;
SwsContext* video_scale_ctx_;
olive::PixelFormat video_conversion_fmt_;
PixelFormat::Format video_conversion_fmt_;
AVStream* audio_stream_;
AVCodecContext* audio_codec_ctx_;