Skip to content

Commit

Permalink
VIDEO: Replace ScopedPtr/ScopedArray with std::unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 11, 2020
1 parent a21984c commit 9878e50
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 97 deletions.
5 changes: 3 additions & 2 deletions src/video/actimagine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#ifndef VIDEO_ACTIMAGINE_H
#define VIDEO_ACTIMAGINE_H

#include <memory>

#include "src/common/types.h"
#include "src/common/scopedptr.h"

#include "src/video/decoder.h"

Expand Down Expand Up @@ -90,7 +91,7 @@ class ActimagineDecoder : public VideoDecoder {
uint32 dataOffset;
};

Common::ScopedPtr<Common::SeekableReadStream> _vx;
std::unique_ptr<Common::SeekableReadStream> _vx;

std::vector<KeyFrame> _keyFrames;

Expand Down
12 changes: 6 additions & 6 deletions src/video/aurora/videoplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ VideoPlayer::~VideoPlayer() {
void VideoPlayer::load(const Common::UString &name) {
::Aurora::FileType type;

Common::ScopedPtr<Common::SeekableReadStream>
std::unique_ptr<Common::SeekableReadStream>
video(ResMan.getResource(::Aurora::kResourceVideo, name, &type));
if (!video)
throw Common::Exception("No such video resource \"%s\"", name.c_str());

// Loading the different video formats
switch (type) {
case ::Aurora::kFileTypeBIK:
_video.reset(new Bink(video.release()));
_video = std::make_unique<Bink>(video.release());
break;
case ::Aurora::kFileTypeMOV:
_video.reset(new QuickTimeDecoder(video.release()));
_video = std::make_unique<QuickTimeDecoder>(video.release());
break;
case ::Aurora::kFileTypeXMV:
_video.reset(new XboxMediaVideo(video.release()));
_video = std::make_unique<XboxMediaVideo>(video.release());
break;
case ::Aurora::kFileTypeVX:
_video.reset(new ActimagineDecoder(video.release()));
_video = std::make_unique<ActimagineDecoder>(video.release());
break;
case ::Aurora::kFileTypeWBM:
_video.reset(new Matroska(video.release()));
_video = std::make_unique<Matroska>(video.release());
break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/video/aurora/videoplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifndef VIDEO_AURORA_VIDEOPLAYER_H
#define VIDEO_AURORA_VIDEOPLAYER_H

#include "src/common/scopedptr.h"
#include <memory>

namespace Common {
class UString;
Expand All @@ -46,7 +46,7 @@ class VideoPlayer {
void play();

private:
Common::ScopedPtr<VideoDecoder> _video;
std::unique_ptr<VideoDecoder> _video;

void load(const Common::UString &name);
};
Expand Down
22 changes: 11 additions & 11 deletions src/video/bink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void Bink::BinkVideoTrack::initBundles() {
uint32 blocks = bw * bh;

for (int i = 0; i < kSourceMAX; i++) {
_bundles[i].data.reset(new byte[blocks * 64]);
_bundles[i].data = std::make_unique<byte[]>(blocks * 64);
_bundles[i].dataEnd = _bundles[i].data.get() + blocks * 64;
}

Expand All @@ -611,7 +611,7 @@ void Bink::BinkVideoTrack::initBundles() {

void Bink::BinkVideoTrack::initHuffman() {
for (int i = 0; i < 16; i++)
_huffman[i].reset(new Common::Huffman(binkHuffmanLengths[i][15], 16, binkHuffmanCodes[i], binkHuffmanLengths[i]));
_huffman[i] = std::make_unique<Common::Huffman>(binkHuffmanLengths[i][15], 16, binkHuffmanCodes[i], binkHuffmanLengths[i]);
}

byte Bink::BinkVideoTrack::getHuffmanSymbol(VideoFrame &video, Huffman &huffman) {
Expand Down Expand Up @@ -1368,7 +1368,7 @@ void Bink::BinkAudioTrack::decodeAudio(Common::SeekableReadStream& bink, const s
int outSize = _info.frameLen * _info.channels;

while (bits.pos() < bits.size()) {
Common::ScopedArray<int16> out(new int16[outSize]);
std::unique_ptr<int16[]> out = std::make_unique<int16[]>(outSize);
memset(out.get(), 0, outSize * 2);

audioBlock(bits, out.get());
Expand Down Expand Up @@ -1611,14 +1611,14 @@ Bink::BinkVideoTrack::BinkVideoTrack(uint32 width, uint32 height, uint32 frameCo
width = _width + 32;
height = _height + 32;

_curPlanes[0].reset(new byte[ width * height ]); // Y
_curPlanes[1].reset(new byte[(width >> 1) * (height >> 1)]); // U, 1/4 resolution
_curPlanes[2].reset(new byte[(width >> 1) * (height >> 1)]); // V, 1/4 resolution
_curPlanes[3].reset(new byte[ width * height ]); // A
_oldPlanes[0].reset(new byte[ width * height ]); // Y
_oldPlanes[1].reset(new byte[(width >> 1) * (height >> 1)]); // U, 1/4 resolution
_oldPlanes[2].reset(new byte[(width >> 1) * (height >> 1)]); // V, 1/4 resolution
_oldPlanes[3].reset(new byte[ width * height ]); // A
_curPlanes[0] = std::make_unique<byte[]>( width * height ); // Y
_curPlanes[1] = std::make_unique<byte[]>((width >> 1) * (height >> 1)); // U, 1/4 resolution
_curPlanes[2] = std::make_unique<byte[]>((width >> 1) * (height >> 1)); // V, 1/4 resolution
_curPlanes[3] = std::make_unique<byte[]>( width * height ); // A
_oldPlanes[0] = std::make_unique<byte[]>( width * height ); // Y
_oldPlanes[1] = std::make_unique<byte[]>((width >> 1) * (height >> 1)); // U, 1/4 resolution
_oldPlanes[2] = std::make_unique<byte[]>((width >> 1) * (height >> 1)); // V, 1/4 resolution
_oldPlanes[3] = std::make_unique<byte[]>( width * height ); // A

// Initialize the video with solid green
std::memset(_curPlanes[0].get(), 0, width * height );
Expand Down
12 changes: 6 additions & 6 deletions src/video/bink.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
#define VIDEO_BINK_H

#include <vector>
#include <memory>

#include "src/common/types.h"
#include "src/common/rational.h"
#include "src/common/scopedptr.h"

#include "src/video/decoder.h"

Expand Down Expand Up @@ -162,7 +162,7 @@ class Bink : public VideoDecoder {
~VideoFrame();
};

Common::ScopedPtr<Common::SeekableReadStream> _bink;
std::unique_ptr<Common::SeekableReadStream> _bink;

std::vector<AudioInfo> _audioTracks; ///< All audio tracks.
std::vector<VideoFrame> _frames; ///< All video frames.
Expand Down Expand Up @@ -256,7 +256,7 @@ class Bink : public VideoDecoder {

Huffman huffman; ///< Huffman codebook.

Common::ScopedArray<byte> data; ///< Buffer for decoded symbols.
std::unique_ptr<byte[]> data; ///< Buffer for decoded symbols.

byte *dataEnd; ///< Pointer to the data end end.
byte *curDec; ///< Pointer to the data that wasn't yet decoded.
Expand All @@ -280,15 +280,15 @@ class Bink : public VideoDecoder {

Bundle _bundles[kSourceMAX]; ///< Bundles for decoding all data types.

Common::ScopedPtr<Common::Huffman> _huffman[16]; ///< The 16 Huffman codebooks used in Bink decoding.
std::unique_ptr<Common::Huffman> _huffman[16]; ///< The 16 Huffman codebooks used in Bink decoding.

/** Huffman codebooks to use for decoding high nibbles in color data types. */
Huffman _colHighHuffman[16];
/** Value of the last decoded high nibble in color data types. */
int _colLastVal;

Common::ScopedArray<byte> _curPlanes[4]; ///< The 4 color planes, YUVA, current frame.
Common::ScopedArray<byte> _oldPlanes[4]; ///< The 4 color planes, YUVA, last frame.
std::unique_ptr<byte[]> _curPlanes[4]; ///< The 4 color planes, YUVA, current frame.
std::unique_ptr<byte[]> _oldPlanes[4]; ///< The 4 color planes, YUVA, last frame.

/** Initialize the bundles. */
void initBundles();
Expand Down
5 changes: 3 additions & 2 deletions src/video/codecs/h263.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

#include <cstring>

#include <memory>

#include <xvid.h>

#include "src/common/scopedptr.h"
#include "src/common/util.h"
#include "src/common/readstream.h"
#include "src/common/types.h"
Expand Down Expand Up @@ -98,7 +99,7 @@ void H263Codec::decodeInternal(Common::SeekableReadStream &dataStream, Graphics:
// alternatively do the YUV->BGRA conversion ourselves. We chose the latter.

size_t dataSize = dataStream.size();
Common::ScopedArray<byte> data(new byte[dataSize]);
std::unique_ptr<byte[]> data = std::make_unique<byte[]>(dataSize);
dataStream.read(data.get(), dataSize);

xvid_dec_frame_t xvid_dec_frame;
Expand Down
8 changes: 4 additions & 4 deletions src/video/codecs/vpx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include <algorithm>
#include <memory>

#include <vpx/vpx_decoder.h>
#include <vpx/vp8dx.h>
Expand All @@ -31,7 +32,6 @@
#undef UNUSED

#include "src/common/readstream.h"
#include "src/common/scopedptr.h"
#include "src/graphics/yuv_to_rgb.h"
#include "src/graphics/images/surface.h"
#include "src/video/codecs/codec.h"
Expand Down Expand Up @@ -89,7 +89,7 @@ void VPXDecoder::decodeFrame(Graphics::Surface &surface, Common::SeekableReadStr
return;

// Read all the data from the stream
Common::ScopedArray<byte> data(new byte[dataStream.size()]);
std::unique_ptr<byte[]> data = std::make_unique<byte[]>(dataStream.size());
dataStream.read(data.get(), dataStream.size());

// Perform the actual decode
Expand Down Expand Up @@ -127,15 +127,15 @@ void VPXDecoder::decodeFrame(Graphics::Surface &surface, Common::SeekableReadStr
}

Codec *makeVP8Decoder() {
Common::ScopedPtr<VPXDecoder> decoder(new VPXDecoder());
std::unique_ptr<VPXDecoder> decoder = std::make_unique<VPXDecoder>();
if (!decoder->init(&vpx_codec_vp8_dx_algo))
return 0;

return decoder.release();
}

Codec *makeVP9Decoder() {
Common::ScopedPtr<VPXDecoder> decoder(new VPXDecoder());
std::unique_ptr<VPXDecoder> decoder = std::make_unique<VPXDecoder>();
if (!decoder->init(&vpx_codec_vp9_dx_algo))
return 0;

Expand Down
40 changes: 20 additions & 20 deletions src/video/codecs/xmvwmv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ void XMVWMV2Codec::init() {


// Color planes
_curPlanes[0].reset(new byte[_lumaWidth * _lumaHeight ]);
_curPlanes[1].reset(new byte[_chromaWidth * _chromaHeight]);
_curPlanes[2].reset(new byte[_chromaWidth * _chromaHeight]);
_oldPlanes[0].reset(new byte[_lumaWidth * _lumaHeight ]);
_oldPlanes[1].reset(new byte[_chromaWidth * _chromaHeight]);
_oldPlanes[2].reset(new byte[_chromaWidth * _chromaHeight]);
_curPlanes[0] = std::make_unique<byte[]>(_lumaWidth * _lumaHeight );
_curPlanes[1] = std::make_unique<byte[]>(_chromaWidth * _chromaHeight);
_curPlanes[2] = std::make_unique<byte[]>(_chromaWidth * _chromaHeight);
_oldPlanes[0] = std::make_unique<byte[]>(_lumaWidth * _lumaHeight );
_oldPlanes[1] = std::make_unique<byte[]>(_chromaWidth * _chromaHeight);
_oldPlanes[2] = std::make_unique<byte[]>(_chromaWidth * _chromaHeight);

std::memset(_curPlanes[0].get(), 0, _lumaWidth * _lumaHeight );
std::memset(_curPlanes[1].get(), 0, _chromaWidth * _chromaHeight);
Expand All @@ -266,25 +266,25 @@ void XMVWMV2Codec::init() {


// Coded block pattern
_cbp.reset(new CBP[_mbCountWidth + 1]); // +1 border for the start of the row
_cbp = std::make_unique<CBP[]>(_mbCountWidth + 1); // +1 border for the start of the row

_huffCBP[0].reset(new Common::Huffman(wmv2HuffmanIMB));
_huffCBP[1].reset(new Common::Huffman(wmv2HuffmanPMB[0]));
_huffCBP[2].reset(new Common::Huffman(wmv2HuffmanPMB[1]));
_huffCBP[3].reset(new Common::Huffman(wmv2HuffmanPMB[2]));
_huffCBP[0] = std::make_unique<Common::Huffman>(wmv2HuffmanIMB);
_huffCBP[1] = std::make_unique<Common::Huffman>(wmv2HuffmanPMB[0]);
_huffCBP[2] = std::make_unique<Common::Huffman>(wmv2HuffmanPMB[1]);
_huffCBP[3] = std::make_unique<Common::Huffman>(wmv2HuffmanPMB[2]);


// DC Huffman decoders
_huffDC[0][0].reset(new Common::Huffman(wmv2HuffmanDC[0][0]));
_huffDC[0][1].reset(new Common::Huffman(wmv2HuffmanDC[0][1]));
_huffDC[1][0].reset(new Common::Huffman(wmv2HuffmanDC[1][0]));
_huffDC[1][1].reset(new Common::Huffman(wmv2HuffmanDC[1][1]));
_huffDC[0][0] = std::make_unique<Common::Huffman>(wmv2HuffmanDC[0][0]);
_huffDC[0][1] = std::make_unique<Common::Huffman>(wmv2HuffmanDC[0][1]);
_huffDC[1][0] = std::make_unique<Common::Huffman>(wmv2HuffmanDC[1][0]);
_huffDC[1][1] = std::make_unique<Common::Huffman>(wmv2HuffmanDC[1][1]);


// AC predictors
_predAC[0].reset(new int32[_lumaWidth]);
_predAC[1].reset(new int32[_chromaWidth]);
_predAC[2].reset(new int32[_chromaWidth]);
_predAC[0] = std::make_unique<int32[]>(_lumaWidth);
_predAC[1] = std::make_unique<int32[]>(_chromaWidth);
_predAC[2] = std::make_unique<int32[]>(_chromaWidth);


// AC decoders
Expand All @@ -293,7 +293,7 @@ void XMVWMV2Codec::init() {
const WMV2ACCoefficientTable *params = &wmv2AC[i][j];

_decoderAC[i][j].parameters = params;
_decoderAC[i][j].huffman.reset(new Common::Huffman(params->huffman));
_decoderAC[i][j].huffman = std::make_unique<Common::Huffman>(params->huffman);
}
}

Expand All @@ -302,7 +302,7 @@ void XMVWMV2Codec::init() {
const WMV2MVTable *params = &wmv2MV[i];

_decoderMV[i].parameters = params;
_decoderMV[i].huffman.reset(new Common::Huffman(params->huffman));
_decoderMV[i].huffman = std::make_unique<Common::Huffman>(params->huffman);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/video/codecs/xmvwmv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
#ifndef VIDEO_CODECS_XMVWMV2_H
#define VIDEO_CODECS_XMVWMV2_H

#include <memory>

#include "src/common/types.h"
#include "src/common/scopedptr.h"

#include "src/video/codecs/codec.h"

Expand Down Expand Up @@ -97,13 +98,13 @@ class XMVWMV2Codec : public Codec {

/** Decoders for DCT AC coefficients. */
struct ACDecoder {
Common::ScopedPtr<Common::Huffman> huffman;
std::unique_ptr<Common::Huffman> huffman;
const WMV2ACCoefficientTable *parameters;
};

/** Decoder for motion vectors. */
struct MVDecoder {
Common::ScopedPtr<Common::Huffman> huffman;
std::unique_ptr<Common::Huffman> huffman;
const WMV2MVTable *parameters;
};

Expand Down Expand Up @@ -188,8 +189,8 @@ class XMVWMV2Codec : public Codec {

// Color planes

Common::ScopedArray<byte> _curPlanes[3]; ///< The 3 color planes, YUV, current frame.
Common::ScopedArray<byte> _oldPlanes[3]; ///< The 3 color planes, YUV, last frame.
std::unique_ptr<byte[]> _curPlanes[3]; ///< The 3 color planes, YUV, current frame.
std::unique_ptr<byte[]> _oldPlanes[3]; ///< The 3 color planes, YUV, last frame.

// Decoder flags

Expand All @@ -204,17 +205,17 @@ class XMVWMV2Codec : public Codec {

// CBP

Common::ScopedArray<CBP> _cbp; ///< Coded block pattern, previous row.
Common::ScopedPtr<Common::Huffman> _huffCBP[4]; ///< Huffman codes for coded block pattern.
std::unique_ptr<CBP[]> _cbp; ///< Coded block pattern, previous row.
std::unique_ptr<Common::Huffman> _huffCBP[4]; ///< Huffman codes for coded block pattern.

// DCT DC coefficients

/** Huffman code for DCT DC coefficients, [luma/chroma][low/high motion]. */
Common::ScopedPtr<Common::Huffman> _huffDC[2][2];
std::unique_ptr<Common::Huffman> _huffDC[2][2];

// DCT AC coefficients

Common::ScopedArray<int32> _predAC[3]; ///< AC predictors, previous row.
std::unique_ptr<int32[]> _predAC[3]; ///< AC predictors, previous row.

/** Decoders for DCT AC coefficients [luma/chroma][low motion/high motion/MPEG4]. */
ACDecoder _decoderAC[2][3];
Expand Down
2 changes: 1 addition & 1 deletion src/video/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void VideoDecoder::initVideo() {
_textureWidth = ((float) width ) / ((float) realWidth );
_textureHeight = ((float) height) / ((float) realHeight);

_surface.reset(new Graphics::Surface(realWidth, realHeight));
_surface = std::make_unique<Graphics::Surface>(realWidth, realHeight);

_surface->fill(0, 0, 0, 0);

Expand Down

0 comments on commit 9878e50

Please sign in to comment.