/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
#ifndef LIBAV_FRAME_HPP
#define LIBAV_FRAME_HPP
extern "C"{
# include
}
#include //exchange
namespace libav{
class frame
{
private:
AVFrame* m_frame;
bool m_freep = false;
public:
frame(void){
m_frame = av_frame_alloc();
m_frame->data[0] = nullptr;
}
frame(int width, int height, int format):
frame()
{
m_frame->width = width;
m_frame->height = height;
m_frame->format = format;
}
frame(const frame&) = delete;
frame(frame&& f)noexcept:
m_frame(std::exchange(f.m_frame, nullptr)),
m_freep(f.m_freep){}
~frame(void){
reset();
}
frame& operator=(const frame&) = delete;
frame& operator=(frame&& f)noexcept{
std::swap(m_frame, f.m_frame);
std::swap(m_freep, f.m_freep);
return *this;
}
void reset(AVFrame* frame = nullptr){
if(m_frame){
if(m_freep){
av_freep(&m_frame->data[0]);
}
av_frame_unref(m_frame);
av_frame_free(&m_frame);
}
m_frame = frame;
}
void set_freep(bool b = true){
m_freep = b;
}
AVFrame* release(void){
return std::exchange(m_frame, nullptr);
}
AVFrame* operator->(void){
return m_frame;
}
const AVFrame* operator->(void)const{
return m_frame;
}
AVFrame* get(void){
return m_frame;
}
const AVFrame* get(void)const{
return m_frame;
}
operator AVFrame*(void){
return m_frame;
}
operator const AVFrame*(void)const{
return m_frame;
}
};
}
#endif