decoder/ffmpeg: add AVFrame wrapper class

This commit is contained in:
Max Kellermann 2019-03-12 23:51:46 +01:00
parent 9acc6617d2
commit 38a0844cdf
2 changed files with 56 additions and 9 deletions

View File

@ -27,6 +27,7 @@
#include "lib/ffmpeg/LogError.hxx"
#include "lib/ffmpeg/Init.hxx"
#include "lib/ffmpeg/Buffer.hxx"
#include "lib/ffmpeg/Frame.hxx"
#include "../DecoderAPI.hxx"
#include "FfmpegMetaData.hxx"
#include "FfmpegIo.hxx"
@ -574,15 +575,7 @@ FfmpegDecode(DecoderClient &client, InputStream &input,
FfmpegParseMetaData(client, format_context, audio_stream);
AVFrame *frame = av_frame_alloc();
if (!frame) {
LogError(ffmpeg_domain, "Could not allocate frame");
return;
}
AtScopeExit(&frame) {
av_frame_free(&frame);
};
Ffmpeg::Frame frame;
FfmpegBuffer interleaved_buffer;

54
src/lib/ffmpeg/Frame.hxx Normal file
View File

@ -0,0 +1,54 @@
/*
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_FFMPEG_FRAME_HXX
#define MPD_FFMPEG_FRAME_HXX
extern "C" {
#include <libavutil/frame.h>
}
#include <new>
namespace Ffmpeg {
class Frame {
AVFrame *frame;
public:
Frame():frame(av_frame_alloc()) {
if (frame == nullptr)
throw std::bad_alloc();
}
~Frame() noexcept {
av_frame_free(&frame);
}
Frame(const Frame &) = delete;
Frame &operator=(const Frame &) = delete;
AVFrame &operator*() noexcept {
return *frame;
}
};
} // namespace Ffmpeg
#endif