2
Copyright (c) 2012-2014 Maarten Baert <maarten-baert@hotmail.com>
4
This file is part of SimpleScreenRecorder.
6
SimpleScreenRecorder is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
SimpleScreenRecorder is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with SimpleScreenRecorder. If not, see <http://www.gnu.org/licenses/>.
23
#if !SSR_USE_AV_CODEC_ID
24
#define AV_CODEC_ID_NONE CODEC_ID_NONE
27
#if !SSR_USE_AV_PIX_FMT
28
#define AV_PIX_FMT_NONE PIX_FMT_NONE
29
#define AV_PIX_FMT_PAL8 PIX_FMT_PAL8
30
#define AV_PIX_FMT_RGB565 PIX_FMT_RGB565
31
#define AV_PIX_FMT_RGB555 PIX_FMT_RGB555
32
#define AV_PIX_FMT_BGR24 PIX_FMT_BGR24
33
#define AV_PIX_FMT_RGB24 PIX_FMT_RGB24
34
#define AV_PIX_FMT_BGRA PIX_FMT_BGRA
35
#define AV_PIX_FMT_RGBA PIX_FMT_RGBA
36
#define AV_PIX_FMT_ABGR PIX_FMT_ABGR
37
#define AV_PIX_FMT_ARGB PIX_FMT_ARGB
38
#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
39
#define AV_PIX_FMT_YUV422P PIX_FMT_YUV422P
40
#define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P
43
// A trivial class that holds (aligned) frame data. This makes it easy to implement reference counting through std::shared_ptr.
48
inline AVFrameData(size_t size) {
49
m_data = (uint8_t*) av_malloc(size);
51
throw std::bad_alloc();
53
inline ~AVFrameData() {
56
inline uint8_t* GetData() {
61
// A wrapper around AVFrame to manage memory allocation and reference counting.
62
// Note: This reference counting mechanism is unrelated to the mechanism added in later versions of ffmpeg/libav.
63
class AVFrameWrapper {
67
std::shared_ptr<AVFrameData> m_refcounted_data;
70
AVFrameWrapper(const std::shared_ptr<AVFrameData>& refcounted_data);
73
AVFrameWrapper(const AVFrameWrapper&) = delete;
74
AVFrameWrapper& operator=(const AVFrameWrapper&) = delete;
77
inline AVFrame* GetFrame() { return m_frame; }
78
inline uint8_t* GetRawData() { return m_refcounted_data->GetData(); }
79
inline std::shared_ptr<AVFrameData> GetFrameData() { return m_refcounted_data; }
83
// A wrapper around AVPacket to manage memory allocation. There is no copying or reference counting in this case.
84
class AVPacketWrapper {
88
bool m_free_on_destruct;
92
AVPacketWrapper(size_t size);
95
AVPacketWrapper(const AVPacketWrapper&) = delete;
96
AVPacketWrapper& operator=(const AVPacketWrapper&) = delete;
99
inline AVPacket* GetPacket() { return &m_packet; }
100
inline void SetFreeOnDestruct(bool free_on_destruct) { m_free_on_destruct = free_on_destruct; }
104
bool AVFormatIsInstalled(const QString& format_name);
105
bool AVCodecIsInstalled(const QString& codec_name);
106
bool AVCodecSupportsPixelFormat(const AVCodec* codec, PixelFormat pixel_fmt);
107
bool AVCodecSupportsSampleFormat(const AVCodec* codec, AVSampleFormat sample_fmt);
109
#if !SSR_USE_AV_CODEC_IS_ENCODER
110
inline int av_codec_is_encoder(const AVCodec* codec) {
111
return (codec != NULL && (codec->encode != NULL || codec->encode2 != NULL));