make use of std::array `pictq.size()` instead of VIDEO_PICTURE_ARRAY_SIZE; remove redundant smart-pointer .get calls; fix typos

librecast_all_the_things
Bret Curtis 3 years ago
parent 4eea734551
commit bae8713998

@ -97,7 +97,7 @@ VideoState::VideoState()
{ {
mFlushPktData = flush_pkt.data; mFlushPktData = flush_pkt.data;
// This is not needed anymore above FFMpeg version 4.0 // This is not needed any more above FFMpeg version 4.0
#if LIBAVCODEC_VERSION_INT < 3805796 #if LIBAVCODEC_VERSION_INT < 3805796
av_register_all(); av_register_all();
#endif #endif
@ -310,7 +310,7 @@ void VideoState::video_refresh()
VideoPicture* vp = &this->pictq[this->pictq_rindex]; VideoPicture* vp = &this->pictq[this->pictq_rindex];
this->video_display(vp); this->video_display(vp);
this->pictq_rindex = (pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE; this->pictq_rindex = (pictq_rindex+1) % pictq.size();
this->frame_last_pts = vp->pts; this->frame_last_pts = vp->pts;
this->pictq_size--; this->pictq_size--;
this->pictq_cond.notify_one(); this->pictq_cond.notify_one();
@ -327,12 +327,12 @@ void VideoState::video_refresh()
for (; i<this->pictq_size-1; ++i) for (; i<this->pictq_size-1; ++i)
{ {
if (this->pictq[pictq_rindex].pts + threshold <= this->get_master_clock()) if (this->pictq[pictq_rindex].pts + threshold <= this->get_master_clock())
this->pictq_rindex = (this->pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE; // not enough time to show this picture this->pictq_rindex = (this->pictq_rindex+1) % pictq.size(); // not enough time to show this picture
else else
break; break;
} }
assert (this->pictq_rindex < VIDEO_PICTURE_ARRAY_SIZE); assert (this->pictq_rindex < pictq.size());
VideoPicture* vp = &this->pictq[this->pictq_rindex]; VideoPicture* vp = &this->pictq[this->pictq_rindex];
this->video_display(vp); this->video_display(vp);
@ -342,7 +342,7 @@ void VideoState::video_refresh()
this->pictq_size -= i; this->pictq_size -= i;
// update queue for next picture // update queue for next picture
this->pictq_size--; this->pictq_size--;
this->pictq_rindex = (this->pictq_rindex+1) % VIDEO_PICTURE_ARRAY_SIZE; this->pictq_rindex = (this->pictq_rindex+1) % pictq.size();
this->pictq_cond.notify_one(); this->pictq_cond.notify_one();
} }
} }
@ -392,7 +392,7 @@ int VideoState::queue_picture(const AVFrame &pFrame, double pts)
0, this->video_ctx->height, vp->rgbaFrame->data, vp->rgbaFrame->linesize); 0, this->video_ctx->height, vp->rgbaFrame->data, vp->rgbaFrame->linesize);
// now we inform our display thread that we have a pic ready // now we inform our display thread that we have a pic ready
this->pictq_windex = (this->pictq_windex+1) % VIDEO_PICTURE_ARRAY_SIZE; this->pictq_windex = (this->pictq_windex+1) % pictq.size();
this->pictq_size++; this->pictq_size++;
return 0; return 0;
@ -656,7 +656,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx)
this->audio_ctx = avcodec_alloc_context3(codec); this->audio_ctx = avcodec_alloc_context3(codec);
avcodec_parameters_to_context(this->audio_ctx, pFormatCtx->streams[stream_index]->codecpar); avcodec_parameters_to_context(this->audio_ctx, pFormatCtx->streams[stream_index]->codecpar);
// This is not needed anymore above FFMpeg version 4.0 // This is not needed any more above FFMpeg version 4.0
#if LIBAVCODEC_VERSION_INT < 3805796 #if LIBAVCODEC_VERSION_INT < 3805796
av_codec_set_pkt_timebase(this->audio_ctx, pFormatCtx->streams[stream_index]->time_base); av_codec_set_pkt_timebase(this->audio_ctx, pFormatCtx->streams[stream_index]->time_base);
#endif #endif
@ -693,7 +693,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx)
this->video_ctx = avcodec_alloc_context3(codec); this->video_ctx = avcodec_alloc_context3(codec);
avcodec_parameters_to_context(this->video_ctx, pFormatCtx->streams[stream_index]->codecpar); avcodec_parameters_to_context(this->video_ctx, pFormatCtx->streams[stream_index]->codecpar);
// This is not needed anymore above FFMpeg version 4.0 // This is not needed any more above FFMpeg version 4.0
#if LIBAVCODEC_VERSION_INT < 3805796 #if LIBAVCODEC_VERSION_INT < 3805796
av_codec_set_pkt_timebase(this->video_ctx, pFormatCtx->streams[stream_index]->time_base); av_codec_set_pkt_timebase(this->video_ctx, pFormatCtx->streams[stream_index]->time_base);
#endif #endif
@ -724,7 +724,7 @@ void VideoState::init(std::shared_ptr<std::istream> inputstream, const std::stri
this->mQuit = false; this->mQuit = false;
this->stream = std::move(inputstream); this->stream = std::move(inputstream);
if(!this->stream.get()) if(!this->stream)
throw std::runtime_error("Failed to open video resource"); throw std::runtime_error("Failed to open video resource");
AVIOContext *ioCtx = avio_alloc_context(nullptr, 0, 0, this, istream_read, istream_write, istream_seek); AVIOContext *ioCtx = avio_alloc_context(nullptr, 0, 0, this, istream_read, istream_write, istream_seek);
@ -852,7 +852,7 @@ void VideoState::deinit()
mTexture = nullptr; mTexture = nullptr;
} }
// Dellocate RGBA frame queue. // Deallocate RGBA frame queue.
for (auto & i : this->pictq) for (auto & i : this->pictq)
i.rgbaFrame = nullptr; i.rgbaFrame = nullptr;
@ -879,7 +879,7 @@ double VideoState::get_video_clock() const
double VideoState::get_audio_clock() double VideoState::get_audio_clock()
{ {
if (!mAudioDecoder.get()) if (!mAudioDecoder)
return 0.0; return 0.0;
return mAudioDecoder->getAudioClock(); return mAudioDecoder->getAudioClock();
} }

@ -1,8 +1,9 @@
#ifndef VIDEOPLAYER_VIDEOSTATE_H #ifndef VIDEOPLAYER_VIDEOSTATE_H
#define VIDEOPLAYER_VIDEOSTATE_H #define VIDEOPLAYER_VIDEOSTATE_H
#include <stdint.h> #include <cstdint>
#include <atomic> #include <atomic>
#include <array>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <string> #include <string>
@ -40,8 +41,6 @@ extern "C"
#include "videodefs.hpp" #include "videodefs.hpp"
#define VIDEO_PICTURE_QUEUE_SIZE 50 #define VIDEO_PICTURE_QUEUE_SIZE 50
// allocate one extra to make sure we do not overwrite the osg::Image currently set on the texture
#define VIDEO_PICTURE_ARRAY_SIZE (VIDEO_PICTURE_QUEUE_SIZE+1)
extern "C" extern "C"
{ {
@ -184,7 +183,7 @@ struct VideoState {
PacketQueue videoq; PacketQueue videoq;
SwsContext* sws_context; SwsContext* sws_context;
int sws_context_w, sws_context_h; int sws_context_w, sws_context_h;
VideoPicture pictq[VIDEO_PICTURE_ARRAY_SIZE]; std::array<VideoPicture, VIDEO_PICTURE_QUEUE_SIZE+1> pictq; // allocate one extra to make sure we do not overwrite the osg::Image currently set on the texture
int pictq_size, pictq_rindex, pictq_windex; int pictq_size, pictq_rindex, pictq_windex;
std::mutex pictq_mutex; std::mutex pictq_mutex;
std::condition_variable pictq_cond; std::condition_variable pictq_cond;

Loading…
Cancel
Save