-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathIFrame.cpp
More file actions
95 lines (81 loc) · 1.85 KB
/
Copy pathIFrame.cpp
File metadata and controls
95 lines (81 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "IFrame.hpp"
#include <stdexcept>
namespace avtranscoder
{
IFrame::IFrame()
: _frame(NULL)
, _dataAllocated(false)
{
allocateAVFrame();
}
IFrame::~IFrame()
{
freeAVFrame();
}
void IFrame::copyData(const IFrame& frameToRef)
{
const int ret = av_frame_copy(_frame, &frameToRef.getAVFrame());
if(ret < 0)
{
throw std::ios_base::failure("Unable to copy data of other frame: " + getDescriptionFromErrorCode(ret));
}
}
void IFrame::copyProperties(const IFrame& otherFrame)
{
av_frame_copy_props(_frame, &otherFrame.getAVFrame());
}
void IFrame::allocateAVFrame()
{
#if LIBAVCODEC_VERSION_MAJOR > 54
_frame = av_frame_alloc();
#else
_frame = avcodec_alloc_frame();
#endif
if(_frame == NULL)
{
LOG_ERROR("Unable to allocate an empty Frame.")
throw std::bad_alloc();
}
}
void IFrame::freeAVFrame()
{
if(_frame != NULL)
{
#if LIBAVCODEC_VERSION_MAJOR > 54
av_frame_free(&_frame);
#else
#if LIBAVCODEC_VERSION_MAJOR > 53
avcodec_free_frame(&_frame);
#else
av_free(_frame);
#endif
#endif
_frame = NULL;
}
}
void IFrame::assignValue(const unsigned char value)
{
// Free the existing data
freeData();
// Create the buffer
const int bufferSize = getDataSize();
unsigned char* dataBuffer = static_cast<unsigned char*>(av_malloc(bufferSize * sizeof(unsigned char)));
memset(dataBuffer, value, bufferSize);
// Fill the frame
assignBuffer(dataBuffer);
// Prepare to free the data
_dataAllocated = true;
}
bool IFrame::isAudioFrame() const
{
if(_frame->sample_rate && _frame->channels && _frame->channel_layout && _frame->format != -1)
return true;
return false;
}
bool IFrame::isVideoFrame() const
{
if(_frame->width && _frame->height && _frame->format != -1)
return true;
return false;
}
}