Skip to content

Commit 2a61683

Browse files
author
Clement Champetier
committed
frames: define assign method in the IFrame based class
* Less code to maintain. * Rename assign methods to assignBuffer and assignValue (to avoid implicite C++ cast and so calling the wrong method).
1 parent 6847185 commit 2a61683

File tree

7 files changed

+28
-49
lines changed

7 files changed

+28
-49
lines changed

src/AvTranscoder/data/decoded/AudioFrame.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,7 @@ void AudioFrame::freeData()
122122
_dataAllocated = false;
123123
}
124124

125-
void AudioFrame::assign(const unsigned char value)
126-
{
127-
// Create the audio buffer
128-
// The buffer will be freed in destructor of based class
129-
const int audioSize = getSize();
130-
unsigned char* audioBuffer = new unsigned char[audioSize];
131-
memset(audioBuffer, value, audioSize);
132-
133-
// Fill the picture
134-
assign(audioBuffer);
135-
}
136-
137-
void AudioFrame::assign(const unsigned char* ptrValue)
125+
void AudioFrame::assignBuffer(const unsigned char* ptrValue)
138126
{
139127
const int align = 0;
140128
const int ret = av_samples_fill_arrays(_frame->data, _frame->linesize, ptrValue, getNbChannels(),

src/AvTranscoder/data/decoded/AudioFrame.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,7 @@ class AvExport AudioFrame : public IFrame
5858

5959
void setNbSamplesPerChannel(const size_t nbSamples) { _frame->nb_samples = nbSamples; }
6060

61-
/**
62-
* @brief Assign the given value to all the data of the audio frame.
63-
*/
64-
void assign(const unsigned char value);
65-
66-
/**
67-
* @brief Assign the given ptr of data to the data of the audio frame.
68-
* @warning the given ptr should have the size of the audio frame..
69-
* @see getSize
70-
*/
71-
void assign(const unsigned char* ptrValue);
61+
void assignBuffer(const unsigned char* ptrValue);
7262

7363
private:
7464
/**

src/AvTranscoder/data/decoded/IFrame.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ void IFrame::freeAVFrame()
6262
}
6363
}
6464

65+
void IFrame::assignValue(const unsigned char value)
66+
{
67+
// Create the buffer
68+
const int bufferSize = getSize();
69+
unsigned char* dataBuffer = new unsigned char[bufferSize];
70+
memset(dataBuffer, value, bufferSize);
71+
72+
// Fill the frame
73+
assignBuffer(dataBuffer);
74+
}
75+
6576
bool IFrame::isAudioFrame() const
6677
{
6778
if(_frame->sample_rate && _frame->channels && _frame->channel_layout && _frame->format != -1)

src/AvTranscoder/data/decoded/IFrame.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ class AvExport IFrame
4545
*/
4646
virtual size_t getSize() const = 0;
4747

48+
/**
49+
* @brief Assign the given ptr of data to the data of the frame.
50+
* @warning the given ptr should have the size of the frame..
51+
* @see getSize
52+
*/
53+
virtual void assignBuffer(const unsigned char* ptrValue) = 0;
54+
55+
/**
56+
* @brief Assign the given value to all the data of the frame.
57+
*/
58+
void assignValue(const unsigned char value);
59+
4860
/**
4961
* @brief Get all the data of the frame.
5062
*/

src/AvTranscoder/data/decoded/VideoFrame.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,7 @@ void VideoFrame::freeData()
105105
_dataAllocated = false;
106106
}
107107

108-
void VideoFrame::assign(const unsigned char value)
109-
{
110-
// Create the image buffer
111-
// The buffer will be freed in destructor of based class
112-
const int imageSize = getSize();
113-
unsigned char* imageBuffer = new unsigned char[imageSize];
114-
memset(imageBuffer, value, imageSize);
115-
116-
// Fill the picture
117-
assign(imageBuffer);
118-
}
119-
120-
void VideoFrame::assign(const unsigned char* ptrValue)
108+
void VideoFrame::assignBuffer(const unsigned char* ptrValue)
121109
{
122110
const int ret =
123111
avpicture_fill(reinterpret_cast<AVPicture*>(_frame), ptrValue, getPixelFormat(), getWidth(), getHeight());

src/AvTranscoder/data/decoded/VideoFrame.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,7 @@ class AvExport VideoFrame : public IFrame
6060

6161
size_t getSize() const;
6262

63-
/**
64-
* @brief Assign the given value to all the data of the picture.
65-
*/
66-
void assign(const unsigned char value);
67-
68-
/**
69-
* @brief Assign the given ptr of data to the data of the picture.
70-
* @warning the given ptr should have the size of the picture.
71-
* @see getSize
72-
*/
73-
void assign(const unsigned char* ptrValue);
63+
void assignBuffer(const unsigned char* ptrValue);
7464

7565
private:
7666
/**

src/AvTranscoder/decoder/VideoGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool VideoGenerator::decodeNextFrame(IFrame& frameBuffer)
3131
VideoFrameDesc blackDesc(_frameDesc._width, _frameDesc._height, "rgb24");
3232
_blackImage = new VideoFrame(blackDesc);
3333
const unsigned char fillChar = 0;
34-
_blackImage->assign(fillChar);
34+
_blackImage->assignValue(fillChar);
3535

3636
std::stringstream msg;
3737
msg << "Generate a black image with the following features:" << std::endl;

0 commit comments

Comments
 (0)