Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::make_shared to allocate shared ptrs, instead of std::shared_ptr constructors #556

Merged
merged 7 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/DummyReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace openshot
* // Create blank frame (with specific frame #, samples, and channels)
* // Sample count should be 44100 / 30 fps = 1470 samples per frame
* int sample_count = 1470;
* std::shared_ptr<openshot::Frame> f(new openshot::Frame(frame_number, sample_count, 2));
* auto f = std::make_shared<openshot::Frame>(frame_number, sample_count, 2);
*
* // Create test samples with incrementing value
* float *audio_buffer = new float[sample_count];
Expand Down
26 changes: 9 additions & 17 deletions include/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,8 @@
#include <iomanip>
#include <sstream>
#include <queue>
#include <QtWidgets/QApplication>
#include <QtGui/QImage>
#include <QtGui/QColor>
#include <QtGui/QBitmap>
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtGui/QPainter>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QWidget>
#include <QtWidgets/QLabel>
#include <QApplication>
#include <QImage>
#include <memory>
#include <unistd.h>
#include "ZmqLogger.h"
Expand Down Expand Up @@ -73,17 +65,17 @@ namespace openshot
* There are many ways to create an instance of an openshot::Frame:
* @code
*
* // Most basic: a blank frame (300x200 blank image, 48kHz audio silence)
* // Most basic: a blank frame (all default values)
* Frame();
*
* // Image only settings (48kHz audio silence)
* // Image only settings
* Frame(1, // Frame number
* 720, // Width of image
* 480, // Height of image
* "#000000" // HTML color code of background color
* );
*
* // Audio only (300x200 blank image)
* // Audio only
* Frame(number, // Frame number
* 44100, // Sample rate of audio stream
* 2 // Number of audio channels
Expand All @@ -99,7 +91,7 @@ namespace openshot
* );
*
* // Some methods require a shared pointer to an openshot::Frame object.
* std::shared_ptr<Frame> f(new Frame(1, 720, 480, "#000000", 44100, 2));
* auto f = std::make_shared<openshot::Frame>(1, 720, 480, "#000000", 44100, 2);
*
* @endcode
*/
Expand Down Expand Up @@ -131,13 +123,13 @@ namespace openshot
bool has_image_data; ///< This frame has been loaded with pixel data


/// Constructor - blank frame (300x200 blank image, 48kHz audio silence)
/// Constructor - blank frame
Frame();

/// Constructor - image only (48kHz audio silence)
/// Constructor - image only
Frame(int64_t number, int width, int height, std::string color);

/// Constructor - audio only (300x200 blank image)
/// Constructor - audio only
Frame(int64_t number, int samples, int channels);

/// Constructor - image & audio
Expand Down
6 changes: 4 additions & 2 deletions include/Qt/VideoRenderWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
#ifndef OPENSHOT_VIDEO_RENDERER_WIDGET_H
#define OPENSHOT_VIDEO_RENDERER_WIDGET_H

#include <QtWidgets/QWidget>
#include <QtGui/QImage>
#include "../Fraction.h"
#include "VideoRenderer.h"

#include <QWidget>
#include <QImage>
#include <QPaintEvent>
#include <QRect>

class VideoRenderWidget : public QWidget
{
Expand Down
1 change: 0 additions & 1 deletion include/effects/Pixelate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <cmath>
#include <stdio.h>
#include <memory>
#include "../Color.h"
#include "../Json.h"
#include "../KeyFrame.h"

Expand Down
6 changes: 3 additions & 3 deletions src/CacheDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ std::shared_ptr<Frame> CacheDisk::GetFrame(int64_t frame_number)
if (path.exists(frame_path)) {

// Load image file
std::shared_ptr<QImage> image = std::shared_ptr<QImage>(new QImage());
auto image = std::make_shared<QImage>();
image->load(frame_path);

// Set pixel formatimage->
image = std::shared_ptr<QImage>(new QImage(image->convertToFormat(QImage::Format_RGBA8888)));
image = std::make_shared<QImage>(image->convertToFormat(QImage::Format_RGBA8888));

// Create frame object
std::shared_ptr<Frame> frame(new Frame());
auto frame = std::make_shared<Frame>();
frame->number = frame_number;
frame->AddImage(image);

Expand Down
4 changes: 3 additions & 1 deletion src/ChunkWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ void ChunkWriter::WriteFrame(std::shared_ptr<Frame> frame)
writer_thumb->WriteFrame(last_frame);
} else {
// Write the 1st frame (of the 1st chunk)... since no previous chunk is available
std::shared_ptr<Frame> blank_frame(new Frame(1, info.width, info.height, "#000000", info.sample_rate, info.channels));
auto blank_frame = std::make_shared<Frame>(
1, info.width, info.height, "#000000",
info.sample_rate, info.channels);
blank_frame->AddColor(info.width, info.height, "#000000");
writer_final->WriteFrame(blank_frame);
writer_preview->WriteFrame(blank_frame);
Expand Down
7 changes: 5 additions & 2 deletions src/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,18 @@ std::shared_ptr<Frame> Clip::GetFrame(int64_t requested_frame)
original_frame = GetOrCreateFrame(new_frame_number);

// Create a new frame
std::shared_ptr<Frame> frame(new Frame(new_frame_number, 1, 1, "#000000", original_frame->GetAudioSamplesCount(), original_frame->GetAudioChannelsCount()));
auto frame = std::make_shared<Frame>(
new_frame_number, 1, 1, "#000000",
original_frame->GetAudioSamplesCount(),
original_frame->GetAudioChannelsCount());
{
frame->SampleRate(original_frame->SampleRate());
frame->ChannelsLayout(original_frame->ChannelsLayout());
}

// Copy the image from the odd field
if (enabled_video)
frame->AddImage(std::shared_ptr<QImage>(new QImage(*original_frame->GetImage())));
frame->AddImage(std::make_shared<QImage>(*original_frame->GetImage()));

// Loop through each channel, add audio
if (enabled_audio && reader->info.has_audio)
Expand Down
8 changes: 3 additions & 5 deletions src/DecklinkInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ HRESULT DeckLinkInputDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame*
{
// Handle Video Frame
if(videoFrame)
{
{

if (videoFrame->GetFlags() & bmdFrameHasNoInputSource)
{
Expand Down Expand Up @@ -245,7 +245,8 @@ omp_set_nested(true);
m_rgbFrame->GetBytes(&frameBytes);

// *********** CREATE OPENSHOT FRAME **********
std::shared_ptr<openshot::Frame> f(new openshot::Frame(copy_frameCount, width, height, "#000000", 2048, 2));
auto f = std::make_shared<openshot::Frame>(
copy_frameCount, width, height, "#000000", 2048, 2);

// Add Image data to openshot frame
// TODO: Fix Decklink support with QImage Upgrade
Expand Down Expand Up @@ -289,6 +290,3 @@ HRESULT DeckLinkInputDelegate::VideoInputFormatChanged(BMDVideoInputFormatChange
{
return S_OK;
}



2 changes: 1 addition & 1 deletion src/DecklinkWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void DecklinkWriter::Open()
// throw DecklinkError("Failed to enable audio output. Is another application using the card?");

// Begin video preroll by scheduling a second of frames in hardware
//std::shared_ptr<Frame> f(new Frame(1, displayMode->GetWidth(), displayMode->GetHeight(), "Blue"));
//auto f = std::make_shared<Frame>(1, displayMode->GetWidth(), displayMode->GetHeight(), "Blue");
//f->AddColor(displayMode->GetWidth(), displayMode->GetHeight(), "Blue");

// Preroll 1 second of video
Expand Down
6 changes: 3 additions & 3 deletions src/FFmpegReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ bool FFmpegReader::CheckMissingFrame(int64_t requested_frame) {
// Add this frame to the processed map (since it's already done)
std::shared_ptr<QImage> parent_image = parent_frame->GetImage();
if (parent_image) {
missing_frame->AddImage(std::shared_ptr<QImage>(new QImage(*parent_image)));
missing_frame->AddImage(std::make_shared<QImage>(*parent_image));
processed_video_frames[missing_frame->number] = missing_frame->number;
}
}
Expand Down Expand Up @@ -2224,7 +2224,7 @@ void FFmpegReader::CheckWorkingFrames(bool end_of_stream, int64_t requested_fram

if (info.has_video && !is_video_ready && last_video_frame) {
// Copy image from last frame
f->AddImage(std::shared_ptr<QImage>(new QImage(*last_video_frame->GetImage())));
f->AddImage(std::make_shared<QImage>(*last_video_frame->GetImage()));
is_video_ready = true;
}

Expand All @@ -2246,7 +2246,7 @@ void FFmpegReader::CheckWorkingFrames(bool end_of_stream, int64_t requested_fram
// Add missing image (if needed - sometimes end_of_stream causes frames with only audio)
if (info.has_video && !is_video_ready && last_video_frame)
// Copy image from last frame
f->AddImage(std::shared_ptr<QImage>(new QImage(*last_video_frame->GetImage())));
f->AddImage(std::make_shared<QImage>(*last_video_frame->GetImage()));

// Reset counter since last 'final' frame
num_checks_since_final = 0;
Expand Down