Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFMPEG 6 + Cmake deprecation updates #27

Open
wants to merge 4 commits into
base: linux
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SET( GLOBAL_INCLUDE_DIRS
${SDLIMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_PATH}
${GLEW_INCLUDE_DIRS}
${GTK2_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIR}
Expand All @@ -65,7 +65,7 @@ SET( GLOBAL_LIBRARIES
${SDLIMAGE_LIBRARY}
${SDLTTF_LIBRARY}
${OPENGL_LIBRARIES}
${GLEW_LIBRARY}
${GLEW_LIBRARIES}
${ZLIB_LIBRARIES}
${OPENAL_LIBRARY}
${AVCODEC_LIBRARIES}
Expand Down
52 changes: 0 additions & 52 deletions cmake/FindGLEW.cmake

This file was deleted.

32 changes: 14 additions & 18 deletions storm/storm3dv2/treader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libavutil/log.h>
#include <libswscale/swscale.h>
}
Expand All @@ -32,7 +33,6 @@ VideoBackgroundLoader::VideoBackgroundLoader()
{
static bool avinit = false;
if (!avinit) {
av_register_all();
av_log_set_level(AV_LOG_QUIET);
avinit = true;
}
Expand Down Expand Up @@ -74,26 +74,23 @@ bool VideoBackgroundLoader::init(const char *filename, IStorm3D_StreamBuilder *b

mContext->videoindex = mContext->audioindex = -1;
for (unsigned int i = 0; i < mContext->formatctx->nb_streams; ++i) {
if (mContext->formatctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && mContext->videoindex ==
if (mContext->formatctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && mContext->videoindex ==
-1) mContext->videoindex = i;
else if (mContext->formatctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && mContext->audioindex ==
else if (mContext->formatctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && mContext->audioindex ==
-1) mContext->audioindex = i;
}

if (mContext->videoindex == -1) {
LOG_WARNING("No video streams detected.");
return false;
} else { mContext->videocodecctx = mContext->formatctx->streams[mContext->videoindex]->codec; }
} else { mContext->videocodecctx = (AVCodecContext *) mContext->formatctx->streams[mContext->videoindex]->codecpar; }

mContext->videocodec = avcodec_find_decoder(mContext->videocodecctx->codec_id);
mContext->videocodec = (AVCodec *) avcodec_find_decoder(mContext->videocodecctx->codec_id);
if (!mContext->videocodec) {
LOG_WARNING("Unable to find suitable video codec.");
return false;
}

if (mContext->videocodec->capabilities & CODEC_CAP_TRUNCATED)
mContext->videocodecctx->flags |= CODEC_FLAG_TRUNCATED;

if (avcodec_open2(mContext->videocodecctx, mContext->videocodec, 0) < 0) {
LOG_WARNING("Unable to open video codec.");
return false;
Expand All @@ -116,18 +113,18 @@ bool VideoBackgroundLoader::init(const char *filename, IStorm3D_StreamBuilder *b
LOG_WARNING("Unable to allocate draw frame.");
return false;
}
unsigned int bytes = avpicture_get_size(AV_PIX_FMT_RGB24, mContext->videowidth, mContext->videoheight);
unsigned int bytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, mContext->videowidth, mContext->videoheight, 1);
mContext->drawbuffer = new unsigned char[bytes * 4 + 1];
if (!mContext->drawbuffer) {
LOG_WARNING("Unable to allocate draw buffer.");
return false;
}
avpicture_fill( (AVPicture *)mContext->drawframe, mContext->drawbuffer, AV_PIX_FMT_RGB24, mContext->videowidth,
mContext->videoheight );
av_image_fill_arrays(mContext->drawframe->data, mContext->drawframe->linesize, mContext->drawbuffer, AV_PIX_FMT_RGB24, mContext->videowidth,
mContext->videoheight, 1);

if (mContext->audioindex != -1 && builder) {
mContext->audiocodecctx = mContext->formatctx->streams[mContext->audioindex]->codec;
mContext->audiocodec = avcodec_find_decoder(mContext->audiocodecctx->codec_id);
mContext->audiocodecctx = (AVCodecContext *) mContext->formatctx->streams[mContext->audioindex]->codecpar;
mContext->audiocodec = (AVCodec *) avcodec_find_decoder(mContext->audiocodecctx->codec_id);
if (!mContext->audiocodec) {
LOG_WARNING("Unable to find suitable audio codec.");
} else {
Expand All @@ -140,7 +137,7 @@ bool VideoBackgroundLoader::init(const char *filename, IStorm3D_StreamBuilder *b
if (!mContext->audiobuffer) {
LOG_WARNING("Unable to allocate audio buffer.");
} else {
builder->setStereo(mContext->audiocodecctx->channels);
builder->setStereo(mContext->audiocodecctx->ch_layout.nb_channels);
builder->setFrequency(mContext->audiocodecctx->sample_rate);
builder->setBits(16);
mContext->audiostream = builder->getStream();
Expand Down Expand Up @@ -294,7 +291,7 @@ void VideoBackgroundLoader::startLoadingThread()
if (av_read_frame(mContext->formatctx, &packet) >= 0) {
if (packet.stream_index == mContext->videoindex) {
int framedone = 0;
avcodec_decode_video2(mContext->videocodecctx, mContext->readframe, &framedone, &packet);
avcodec_receive_frame(mContext->videocodecctx, mContext->readframe);
if (framedone) {
size_t bsize = (mContext->videowidth * mContext->videoheight * 3 + 4);
boost::shared_array<unsigned char> buffer(new unsigned char[bsize]);
Expand Down Expand Up @@ -334,7 +331,7 @@ void VideoBackgroundLoader::startLoadingThread()
} else if (packet.stream_index == mContext->audioindex && mContext->audiobuffer) {
AVFrame *frame = av_frame_alloc();
int size = 0;
avcodec_decode_audio4(mContext->audiocodecctx, frame, &size, &packet);
avcodec_receive_frame(mContext->audiocodecctx, frame);
if (size) {
unsigned long long duration =
(unsigned long long)( (double(mContext->audiocodecctx->time_base.num)
Expand All @@ -344,10 +341,9 @@ void VideoBackgroundLoader::startLoadingThread()
duration );
mContext->audiotime += duration;
}

av_free(frame);
}
av_free_packet(&packet);
av_packet_unref(&packet);
} else { break; }
}
{
Expand Down