Skip to content

Commit ca3c386

Browse files
author
Clement Champetier
committed
VideoFrame: update constructors
* Remove default constructor. * Add a constructor from a profile.
1 parent 50d46ad commit ca3c386

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/AvTranscoder/codec/VideoCodec.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "VideoCodec.hpp"
22

3+
#include <AvTranscoder/util.hpp>
4+
35
#include <cmath>
46
#include <cassert>
57

@@ -24,7 +26,7 @@ VideoCodec::VideoCodec(const ECodecType type, AVCodecContext& avCodecContext)
2426
VideoFrameDesc VideoCodec::getVideoFrameDesc() const
2527
{
2628
assert(_avCodecContext != NULL);
27-
VideoFrameDesc videoFrameDesc(_avCodecContext->width, _avCodecContext->height, _avCodecContext->pix_fmt);
29+
VideoFrameDesc videoFrameDesc(_avCodecContext->width, _avCodecContext->height, getPixelFormatName(_avCodecContext->pix_fmt));
2830
double fps = 1.0 * _avCodecContext->time_base.den / (_avCodecContext->time_base.num * _avCodecContext->ticks_per_frame);
2931
if(!std::isinf(fps))
3032
videoFrameDesc._fps = fps;

src/AvTranscoder/data/decoded/VideoFrame.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@ extern "C" {
1313
namespace avtranscoder
1414
{
1515

16-
VideoFrameDesc::VideoFrameDesc(const size_t width, const size_t height, const AVPixelFormat pixelFormat)
16+
VideoFrameDesc::VideoFrameDesc(const size_t width, const size_t height, const std::string& pixelFormatName)
1717
: _width(width)
1818
, _height(height)
19-
, _pixelFormat(pixelFormat)
19+
, _pixelFormat(getAVPixelFormat(pixelFormatName))
2020
, _fps(1.0)
2121
{
2222
}
2323

24-
VideoFrameDesc::VideoFrameDesc(const size_t width, const size_t height, const std::string& pixelFormatName)
25-
: _width(width)
26-
, _height(height)
27-
, _pixelFormat(getAVPixelFormat(pixelFormatName))
24+
VideoFrameDesc::VideoFrameDesc(const ProfileLoader::Profile& profile)
25+
: _width(0)
26+
, _height(0)
27+
, _pixelFormat(AV_PIX_FMT_NONE)
2828
, _fps(1.0)
2929
{
30+
setParameters(profile);
3031
}
3132

33+
3234
void VideoFrameDesc::setParameters(const ProfileLoader::Profile& profile)
3335
{
3436
// width

src/AvTranscoder/data/decoded/VideoFrame.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace avtranscoder
2121
struct AvExport VideoFrameDesc
2222
{
2323
public:
24-
VideoFrameDesc(const size_t width = 0, const size_t height = 0, const AVPixelFormat pixelFormat = AV_PIX_FMT_NONE);
2524
VideoFrameDesc(const size_t width, const size_t height, const std::string& pixelFormatName);
25+
VideoFrameDesc(const ProfileLoader::Profile& profile);
2626

2727
/**
2828
* @brief Set the attributes from the given profile.
@@ -46,7 +46,6 @@ class AvExport VideoFrame : public IFrame
4646
VideoFrame(const VideoFrame& otherFrame);
4747
VideoFrame& operator=(const VideoFrame& otherFrame);
4848

49-
5049
public:
5150
VideoFrame(const VideoFrameDesc& desc, const bool forceDataAllocation = true);
5251
~VideoFrame();

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ size_t VideoProperties::getBitRate() const
347347

348348
avcodec_open2(_codecContext, _codec, NULL);
349349

350-
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getAVPixelFormat()), false);
350+
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getPixelFormatName()), false);
351351
AVFrame& avFrame = frame.getAVFrame();
352352

353353
int gotFrame = 0;
@@ -569,7 +569,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
569569
// Initialize the AVCodecContext to use the given AVCodec
570570
avcodec_open2(_codecContext, _codec, NULL);
571571

572-
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getAVPixelFormat()), false);
572+
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getPixelFormatName()), false);
573573
AVFrame& avFrame = frame.getAVFrame();
574574

575575
size_t count = 0;

src/AvTranscoder/reader/VideoReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "VideoReader.hpp"
22

3+
#include <AvTranscoder/util.hpp>
34
#include <AvTranscoder/decoder/VideoDecoder.hpp>
45
#include <AvTranscoder/decoder/VideoGenerator.hpp>
56
#include <AvTranscoder/data/decoded/VideoFrame.hpp>
@@ -50,7 +51,7 @@ void VideoReader::init()
5051
// create dst frame
5152
_outputWidth = srcFrame->getWidth();
5253
_outputHeight = srcFrame->getHeight();
53-
_dstFrame = new VideoFrame(VideoFrameDesc(_outputWidth, _outputHeight, getOutputPixelFormat()));
54+
_dstFrame = new VideoFrame(VideoFrameDesc(_outputWidth, _outputHeight, getPixelFormatName(getOutputPixelFormat())));
5455

5556
// generator
5657
_generator = new VideoGenerator(srcFrameDesc);
@@ -75,6 +76,6 @@ void VideoReader::updateOutput(const size_t width, const size_t height, const st
7576
_outputPixelProperties = PixelProperties(pixelFormat);
7677
// update dst frame
7778
delete _dstFrame;
78-
_dstFrame = new VideoFrame(VideoFrameDesc(_outputWidth, _outputHeight, getOutputPixelFormat()));
79+
_dstFrame = new VideoFrame(VideoFrameDesc(_outputWidth, _outputHeight, getPixelFormatName(getOutputPixelFormat())));
7980
}
8081
}

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader:
301301
if(profile.find(constants::avProfileType)->second == constants::avProfileTypeVideo)
302302
{
303303
VideoCodec inputVideoCodec(eCodecTypeEncoder, profile.find(constants::avProfileCodec)->second);
304-
VideoFrameDesc inputFrameDesc;
305-
inputFrameDesc.setParameters(profile);
304+
VideoFrameDesc inputFrameDesc(profile);
306305
inputVideoCodec.setImageParameters(inputFrameDesc);
307306

308307
// generator decoder

0 commit comments

Comments
 (0)