From 426c4587ccc78ee9a3d36c7120596fbb037b3ff8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 10 Jul 2019 02:13:28 -0700 Subject: Some clean up to use uniform initialization --- examples/alffplay.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'examples/alffplay.cpp') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 4deda33a..21ebce77 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -1399,7 +1399,7 @@ int VideoState::handler() avcodec_send_packet(mCodecCtx.get(), nullptr); } /* Decode video frame */ - int ret = avcodec_receive_frame(mCodecCtx.get(), decoded_frame.get()); + int ret{avcodec_receive_frame(mCodecCtx.get(), decoded_frame.get())}; if(ret == AVERROR_EOF) break; if(ret < 0) { @@ -1438,8 +1438,8 @@ int MovieState::decode_interrupt_cb(void *ctx) bool MovieState::prepare() { - AVIOContext *avioctx = nullptr; - AVIOInterruptCB intcb = { decode_interrupt_cb, this }; + AVIOContext *avioctx{nullptr}; + AVIOInterruptCB intcb{decode_interrupt_cb, this}; if(avio_open2(&avioctx, mFilename.c_str(), AVIO_FLAG_READ, &intcb, nullptr)) { std::cerr<< "Failed to open "<pb = mIOContext.get(); fmtctx->interrupt_callback = intcb; if(avformat_open_input(&fmtctx, mFilename.c_str(), nullptr, nullptr) != 0) @@ -1467,9 +1467,9 @@ bool MovieState::prepare() return false; } - mVideo.schedRefresh(milliseconds(40)); + mVideo.schedRefresh(milliseconds{40}); - mParseThread = std::thread(std::mem_fn(&MovieState::parse_handler), this); + mParseThread = std::thread{std::mem_fn(&MovieState::parse_handler), this}; return true; } @@ -1508,17 +1508,17 @@ int MovieState::streamComponentOpen(int stream_index) /* Get a pointer to the codec context for the stream, and open the * associated codec. */ - AVCodecCtxPtr avctx(avcodec_alloc_context3(nullptr)); + AVCodecCtxPtr avctx{avcodec_alloc_context3(nullptr)}; if(!avctx) return -1; if(avcodec_parameters_to_context(avctx.get(), mFormatCtx->streams[stream_index]->codecpar)) return -1; - AVCodec *codec = avcodec_find_decoder(avctx->codec_id); + AVCodec *codec{avcodec_find_decoder(avctx->codec_id)}; if(!codec || avcodec_open2(avctx.get(), codec, nullptr) < 0) { std::cerr<< "Unsupported codec: "<codec_id) - << " (0x"<codec_id<codec_id<nb_streams;i++) + for(unsigned int i{0u};i < mFormatCtx->nb_streams;i++) { auto codecpar = mFormatCtx->streams[i]->codecpar; if(codecpar->codec_type == AVMEDIA_TYPE_VIDEO && !DisableVideo && video_index < 0) @@ -1611,7 +1611,7 @@ int MovieState::parse_handler() mAudioThread.join(); mVideo.mEOS = true; - std::unique_lock lock(mVideo.mPictQMutex); + std::unique_lock lock{mVideo.mPictQMutex}; while(!mVideo.mFinalUpdate) mVideo.mPictQCond.wait(lock); lock.unlock(); @@ -1642,7 +1642,7 @@ inline std::ostream &operator<<(std::ostream &os, const PrettyTime &rhs) } // Only handle up to hour formatting - if(t >= hours(1)) + if(t >= hours{1}) os << duration_cast(t).count() << 'h' << std::setfill('0') << std::setw(2) << (duration_cast(t).count() % 60) << 'm'; else @@ -1678,25 +1678,25 @@ int main(int argc, char *argv[]) } /* Make a window to put our video */ - SDL_Window *screen = SDL_CreateWindow(AppName.c_str(), 0, 0, 640, 480, SDL_WINDOW_RESIZABLE); + SDL_Window *screen{SDL_CreateWindow(AppName.c_str(), 0, 0, 640, 480, SDL_WINDOW_RESIZABLE)}; if(!screen) { std::cerr<< "SDL: could not set video mode - exiting" <(new MovieState(argv[fileidx++])); + movState = std::unique_ptr{new MovieState{argv[fileidx++]}}; if(!movState->prepare()) movState = nullptr; } if(!movState) @@ -1812,12 +1812,12 @@ int main(int argc, char *argv[]) /* Default to going to the next movie at the end of one. */ enum class EomAction { Next, Quit - } eom_action = EomAction::Next; - seconds last_time(-1); - SDL_Event event; + } eom_action{EomAction::Next}; + seconds last_time{-1}; + SDL_Event event{}; while(1) { - int have_evt = SDL_WaitEventTimeout(&event, 10); + int have_evt{SDL_WaitEventTimeout(&event, 10)}; auto cur_time = std::chrono::duration_cast(movState->getMasterClock()); if(cur_time != last_time) @@ -1882,7 +1882,7 @@ int main(int argc, char *argv[]) movState = nullptr; while(fileidx < argc && !movState) { - movState = std::unique_ptr(new MovieState(argv[fileidx++])); + movState = std::unique_ptr{new MovieState{argv[fileidx++]}}; if(!movState->prepare()) movState = nullptr; } if(movState) -- cgit v1.2.3