#include "ffcpp.h" #include "Frame.h" #include namespace ffcpp { Frame::Frame() { _frame = av_frame_alloc(); } Frame::Frame(int size, int channels, AVSampleFormat sampleFormat, int sampleRate): Frame() { _frame->nb_samples = size; _frame->channels = channels; _frame->channel_layout = (uint64_t)av_get_default_channel_layout(channels); _frame->format = sampleFormat; _frame->sample_rate = sampleRate; int res = av_frame_get_buffer(_frame, 0); throwIfError(res, "cannot initialize buffer in audio frame"); } Frame::Frame(Frame &&frame) { *this = std::move(frame); } Frame::~Frame() { if(_frame) { av_frame_free(&_frame); } } Frame& Frame::operator=(Frame&& frame) { _frame = frame._frame; frame._frame = nullptr; return *this; } Frame::operator AVFrame*() { return _frame; } Frame::operator const AVFrame*() const { return _frame; } void Frame::guessPts() { _frame->pts = av_frame_get_best_effort_timestamp(_frame); } void Frame::setPictureType(AVPictureType type) { _frame->pict_type = type; } int Frame::samplesCount() const { return _frame->nb_samples; } void Frame::setPts(int pts) { _frame->pts = pts; } }