mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
media: fix incorrect usage of SRB2_ASSERT on functions with side effects
This commit is contained in:
parent
bf8d90af8c
commit
cea8a10007
5 changed files with 49 additions and 13 deletions
|
|
@ -20,6 +20,19 @@
|
|||
|
||||
using namespace srb2::media;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void runtime_assert(VorbisError error, const char *what)
|
||||
{
|
||||
if (error != 0)
|
||||
{
|
||||
throw std::runtime_error(fmt::format("{}: {}", what, error));
|
||||
}
|
||||
}
|
||||
|
||||
}; // namespace
|
||||
|
||||
VorbisEncoder::VorbisEncoder(Config cfg)
|
||||
{
|
||||
const long max_bitrate = options_.get<int>("max_bitrate");
|
||||
|
|
@ -58,8 +71,8 @@ VorbisEncoder::VorbisEncoder(Config cfg)
|
|||
}
|
||||
}
|
||||
|
||||
SRB2_ASSERT(vorbis_analysis_init(&vd_, &vi_) == 0);
|
||||
SRB2_ASSERT(vorbis_block_init(&vd_, &vb_) == 0);
|
||||
runtime_assert(vorbis_analysis_init(&vd_, &vi_), "vorbis_analysis_init");
|
||||
runtime_assert(vorbis_block_init(&vd_, &vb_), "vorbis_block_init");
|
||||
}
|
||||
|
||||
VorbisEncoder::~VorbisEncoder()
|
||||
|
|
@ -104,12 +117,12 @@ void VorbisEncoder::analyse(sample_buffer_t in)
|
|||
}
|
||||
|
||||
// automatically handles end of stream if n = 0
|
||||
SRB2_ASSERT(vorbis_analysis_wrote(&vd_, n) == 0);
|
||||
runtime_assert(vorbis_analysis_wrote(&vd_, n), "vorbis_analysis_wrote");
|
||||
|
||||
while (vorbis_analysis_blockout(&vd_, &vb_) > 0)
|
||||
{
|
||||
SRB2_ASSERT(vorbis_analysis(&vb_, nullptr) == 0);
|
||||
SRB2_ASSERT(vorbis_bitrate_addblock(&vb_) == 0);
|
||||
runtime_assert(vorbis_analysis(&vb_, nullptr), "vorbis_analysis");
|
||||
runtime_assert(vorbis_bitrate_addblock(&vb_), "vorbis_bitrate_addblock");
|
||||
|
||||
ogg_packet op;
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,10 @@ VP8Encoder::CtxWrapper::~CtxWrapper()
|
|||
|
||||
VP8Encoder::ImgWrapper::ImgWrapper(int width, int height)
|
||||
{
|
||||
SRB2_ASSERT(vpx_img_alloc(&img_, VPX_IMG_FMT_I420, width, height, YUV420pFrame::kAlignment) != nullptr);
|
||||
if (vpx_img_alloc(&img_, VPX_IMG_FMT_I420, width, height, YUV420pFrame::kAlignment) == nullptr)
|
||||
{
|
||||
throw std::runtime_error("vpx_img_alloc");
|
||||
}
|
||||
}
|
||||
|
||||
VP8Encoder::ImgWrapper::~ImgWrapper()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "../cxxutil.hpp"
|
||||
#include "webm_vorbis.hpp"
|
||||
|
|
@ -20,7 +23,10 @@ using time_unit_t = MediaEncoder::time_unit_t;
|
|||
|
||||
WebmContainer::WebmContainer(const Config cfg) : writer_(cfg.file_name), dtor_cb_(cfg.destructor_callback)
|
||||
{
|
||||
SRB2_ASSERT(segment_.Init(&writer_) == true);
|
||||
if (!segment_.Init(&writer_))
|
||||
{
|
||||
throw std::runtime_error("mkvmuxer::Segment::Init");
|
||||
}
|
||||
}
|
||||
|
||||
WebmContainer::~WebmContainer()
|
||||
|
|
@ -101,15 +107,22 @@ void WebmContainer::write_frame(
|
|||
bool is_key_frame
|
||||
)
|
||||
{
|
||||
SRB2_ASSERT(
|
||||
segment_.AddFrame(
|
||||
if (!segment_.AddFrame(
|
||||
reinterpret_cast<const uint8_t*>(buffer.data()),
|
||||
buffer.size_bytes(),
|
||||
trackid,
|
||||
timestamp,
|
||||
is_key_frame
|
||||
) == true
|
||||
);
|
||||
))
|
||||
{
|
||||
throw std::runtime_error(fmt::format(
|
||||
"mkvmuxer::Segment::AddFrame, size={}, track={}, ts={}, key={}",
|
||||
buffer.size_bytes(),
|
||||
trackid,
|
||||
timestamp,
|
||||
is_key_frame
|
||||
));
|
||||
}
|
||||
|
||||
queue_[trackid].data_size += buffer.size_bytes();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,11 @@
|
|||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "../cxxutil.hpp"
|
||||
#include "vorbis.hpp"
|
||||
#include "webm_encoder.hpp"
|
||||
|
|
@ -32,7 +35,10 @@ public:
|
|||
|
||||
const auto p = make_vorbis_private_data();
|
||||
|
||||
SRB2_ASSERT(track()->SetCodecPrivate(reinterpret_cast<const uint8_t*>(p.data()), p.size()) == true);
|
||||
if (!track()->SetCodecPrivate(reinterpret_cast<const uint8_t*>(p.data()), p.size()))
|
||||
{
|
||||
throw std::runtime_error(fmt::format("mkvmuxer::AudioTrack::SetCodecPrivate, size={}", p.size()));
|
||||
}
|
||||
}
|
||||
|
||||
virtual BitRate estimated_bit_rate() const override final
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ bool YUV420pFrame::BufferRGBA::resize(int width, int height)
|
|||
void* p = vec_.data();
|
||||
std::size_t n = vec_.size();
|
||||
|
||||
SRB2_ASSERT(std::align(kAlignment, 1, p, n) != nullptr);
|
||||
p = std::align(kAlignment, 1, p, n);
|
||||
SRB2_ASSERT(p != nullptr);
|
||||
|
||||
plane = tcb::span<uint8_t>(reinterpret_cast<uint8_t*>(p), new_size);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue