aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/alffplay.cpp61
1 files changed, 28 insertions, 33 deletions
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp
index 1f02ef70..54803035 100644
--- a/examples/alffplay.cpp
+++ b/examples/alffplay.cpp
@@ -474,8 +474,8 @@ nanoseconds AudioState::getClockNoLock()
// Get the current device clock time and latency.
auto device = alcGetContextsDevice(alcGetCurrentContext());
- ALCint64SOFT devtimes[2]{0,0};
- alcGetInteger64vSOFT(device, ALC_DEVICE_CLOCK_LATENCY_SOFT, 2, devtimes);
+ std::array<ALCint64SOFT,2> devtimes{};
+ alcGetInteger64vSOFT(device, ALC_DEVICE_CLOCK_LATENCY_SOFT, 2, devtimes.data());
auto latency = nanoseconds{devtimes[1]};
auto device_time = nanoseconds{devtimes[0]};
@@ -494,15 +494,14 @@ nanoseconds AudioState::getClockNoLock()
* actually the timestamp of the first sample frame played. The audio
* clock, then, is that plus the current source offset.
*/
- ALint64SOFT offset[2];
+ std::array<ALint64SOFT,2> offset{};
if(alGetSourcei64vSOFT)
- alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_LATENCY_SOFT, offset);
+ alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_LATENCY_SOFT, offset.data());
else
{
ALint ioffset;
alGetSourcei(mSource, AL_SAMPLE_OFFSET, &ioffset);
offset[0] = ALint64SOFT{ioffset} << 32;
- offset[1] = 0;
}
/* NOTE: The source state must be checked last, in case an underrun
* occurs and the source stops between getting the state and retrieving
@@ -550,15 +549,14 @@ nanoseconds AudioState::getClockNoLock()
nanoseconds pts{mCurrentPts};
if(mSource)
{
- ALint64SOFT offset[2];
+ std::array<ALint64SOFT,2> offset{};
if(alGetSourcei64vSOFT)
- alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_LATENCY_SOFT, offset);
+ alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_LATENCY_SOFT, offset.data());
else
{
ALint ioffset;
alGetSourcei(mSource, AL_SAMPLE_OFFSET, &ioffset);
offset[0] = ALint64SOFT{ioffset} << 32;
- offset[1] = 0;
}
ALint queued, status;
alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
@@ -610,8 +608,8 @@ bool AudioState::startPlayback()
/* Subtract the total buffer queue time from the current pts to get the
* pts of the start of the queue.
*/
- int64_t srctimes[2]{0,0};
- alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_CLOCK_SOFT, srctimes);
+ std::array<int64_t,2> srctimes{};
+ alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_CLOCK_SOFT, srctimes.data());
auto device_time = nanoseconds{srctimes[1]};
auto src_offset = duration_cast<nanoseconds>(fixed32{srctimes[0]}) /
mCodecCtx->sample_rate;
@@ -1151,9 +1149,9 @@ int AudioState::handler()
mSwresCtx.reset(ps);
if(err != 0)
{
- char errstr[AV_ERROR_MAX_STRING_SIZE]{};
+ std::array<char,AV_ERROR_MAX_STRING_SIZE> errstr{};
std::cerr<< "Failed to allocate SwrContext: "
- <<av_make_error_string(errstr, AV_ERROR_MAX_STRING_SIZE, err) <<std::endl;
+ <<av_make_error_string(errstr.data(), AV_ERROR_MAX_STRING_SIZE, err) <<std::endl;
return 0;
}
@@ -1185,17 +1183,17 @@ int AudioState::handler()
mSwresCtx.reset(ps);
if(err != 0)
{
- char errstr[AV_ERROR_MAX_STRING_SIZE]{};
+ std::array<char,AV_ERROR_MAX_STRING_SIZE> errstr{};
std::cerr<< "Failed to allocate SwrContext: "
- <<av_make_error_string(errstr, AV_ERROR_MAX_STRING_SIZE, err) <<std::endl;
+ <<av_make_error_string(errstr.data(), AV_ERROR_MAX_STRING_SIZE, err) <<std::endl;
return 0;
}
}
if(int err{swr_init(mSwresCtx.get())})
{
- char errstr[AV_ERROR_MAX_STRING_SIZE]{};
+ std::array<char,AV_ERROR_MAX_STRING_SIZE> errstr{};
std::cerr<< "Failed to initialize audio converter: "
- <<av_make_error_string(errstr, AV_ERROR_MAX_STRING_SIZE, err) <<std::endl;
+ <<av_make_error_string(errstr.data(), AV_ERROR_MAX_STRING_SIZE, err) <<std::endl;
return 0;
}
@@ -1206,8 +1204,8 @@ int AudioState::handler()
alSourcei(mSource, AL_DIRECT_CHANNELS_SOFT, DirectOutMode);
if(EnableWideStereo)
{
- const float angles[2]{static_cast<float>(M_PI / 3.0), static_cast<float>(-M_PI / 3.0)};
- alSourcefv(mSource, AL_STEREO_ANGLES, angles);
+ const std::array angles{static_cast<float>(M_PI / 3.0), static_cast<float>(-M_PI / 3.0)};
+ alSourcefv(mSource, AL_STEREO_ANGLES, angles.data());
}
if(has_bfmt_ex)
{
@@ -1260,7 +1258,7 @@ int AudioState::handler()
/* Prefill the codec buffer. */
auto packet_sender = [this]()
{
- while(1)
+ while(true)
{
const int ret{mQueue.sendPacket(mCodecCtx.get())};
if(ret == AVErrorEOF) break;
@@ -1287,7 +1285,7 @@ int AudioState::handler()
mCurrentPts += skip;
}
- while(1)
+ while(true)
{
if(mMovie.mQuit.load(std::memory_order_relaxed))
{
@@ -1451,7 +1449,7 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer, bool re
auto clocktime = mMovie.getMasterClock();
bool updated{false};
- while(1)
+ while(true)
{
size_t next_idx{(read_idx+1)%mPictQ.size()};
if(next_idx == mPictQWrite.load(std::memory_order_acquire))
@@ -1546,18 +1544,15 @@ void VideoState::updateVideo(SDL_Window *screen, SDL_Renderer *renderer, bool re
}
/* point pict at the queue */
- uint8_t *pict_data[3];
+ std::array<uint8_t*,3> pict_data;
pict_data[0] = static_cast<uint8_t*>(pixels);
pict_data[1] = pict_data[0] + w*h;
pict_data[2] = pict_data[1] + w*h/4;
- int pict_linesize[3];
- pict_linesize[0] = pitch;
- pict_linesize[1] = pitch / 2;
- pict_linesize[2] = pitch / 2;
+ std::array pict_linesize{pitch, pitch/2, pitch/2};
- sws_scale(mSwscaleCtx.get(), reinterpret_cast<uint8_t**>(frame->data), frame->linesize,
- 0, h, pict_data, pict_linesize);
+ sws_scale(mSwscaleCtx.get(), reinterpret_cast<uint8_t**>(frame->data),
+ frame->linesize, 0, h, pict_data.data(), pict_linesize.data());
SDL_UnlockTexture(mImage);
}
@@ -1599,7 +1594,7 @@ int VideoState::handler()
/* Prefill the codec buffer. */
auto packet_sender = [this]()
{
- while(1)
+ while(true)
{
const int ret{mQueue.sendPacket(mCodecCtx.get())};
if(ret == AVErrorEOF) break;
@@ -1613,7 +1608,7 @@ int VideoState::handler()
}
auto current_pts = nanoseconds::zero();
- while(1)
+ while(true)
{
size_t write_idx{mPictQWrite.load(std::memory_order_relaxed)};
Picture *vp{&mPictQ[write_idx]};
@@ -2062,7 +2057,7 @@ int main(int argc, char *argv[])
while(fileidx < argc && !movState)
{
- movState = std::unique_ptr<MovieState>{new MovieState{argv[fileidx++]}};
+ movState = std::make_unique<MovieState>(argv[fileidx++]);
if(!movState->prepare()) movState = nullptr;
}
if(!movState)
@@ -2077,7 +2072,7 @@ int main(int argc, char *argv[])
Next, Quit
} eom_action{EomAction::Next};
seconds last_time{seconds::min()};
- while(1)
+ while(true)
{
/* SDL_WaitEventTimeout is broken, just force a 10ms sleep. */
std::this_thread::sleep_for(milliseconds{10});
@@ -2145,7 +2140,7 @@ int main(int argc, char *argv[])
movState = nullptr;
while(fileidx < argc && !movState)
{
- movState = std::unique_ptr<MovieState>{new MovieState{argv[fileidx++]}};
+ movState = std::make_unique<MovieState>(argv[fileidx++]);
if(!movState->prepare()) movState = nullptr;
}
if(movState)