97 lines
1.9 KiB
C++
97 lines
1.9 KiB
C++
/**
|
|
This file is a part of 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef LIBAV_PACKET_HPP
|
|
#define LIBAV_PACKET_HPP
|
|
|
|
#include "libav/libav.hpp"
|
|
|
|
extern "C"{
|
|
# include <libavcodec/avcodec.h>
|
|
}
|
|
|
|
#include <utility> //exchange
|
|
|
|
namespace libav{
|
|
|
|
class packet
|
|
{
|
|
private:
|
|
AVPacket* m_pkt;
|
|
public:
|
|
packet(void):
|
|
m_pkt(av_packet_alloc())
|
|
{
|
|
if(m_pkt){
|
|
m_pkt->data = nullptr;
|
|
m_pkt->size = 0;
|
|
}
|
|
}
|
|
packet(const packet&) = delete;
|
|
packet(packet&& p)noexcept:
|
|
m_pkt(std::exchange(p.m_pkt, nullptr)){}
|
|
constexpr packet(AVPacket* pkt):
|
|
m_pkt(pkt){}
|
|
|
|
~packet(void){
|
|
reset();
|
|
}
|
|
|
|
packet& operator=(const packet&) = delete;
|
|
packet& operator=(packet&& p)noexcept{
|
|
std::swap(m_pkt, p.m_pkt);
|
|
return *this;
|
|
}
|
|
void reset(AVPacket* packet = nullptr){
|
|
if(m_pkt)
|
|
av_packet_free(&m_pkt);
|
|
m_pkt = packet;
|
|
}
|
|
AVPacket* release(void){
|
|
return std::exchange(m_pkt, nullptr);
|
|
}
|
|
|
|
AVPacket* operator->(void){
|
|
return m_pkt;
|
|
}
|
|
const AVPacket* operator->(void)const{
|
|
return m_pkt;
|
|
}
|
|
|
|
AVPacket* get(void){
|
|
return m_pkt;
|
|
}
|
|
const AVPacket* get(void)const{
|
|
return m_pkt;
|
|
}
|
|
operator AVPacket*(void){
|
|
return m_pkt;
|
|
}
|
|
operator const AVPacket*(void)const{
|
|
return m_pkt;
|
|
}
|
|
operator bool(void)const{
|
|
return m_pkt;
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|