Skip to content

Commit 759620a

Browse files
committed
It looks ffmpeg is a must for OSG? Now, compatible with ffmpeg-6.0.1
1 parent 2e4ae2e commit 759620a

10 files changed

+37
-28
lines changed

src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ osg::ref_ptr<osg::Geometry> ReaderWritterOpenCASCADE::OCCTKReader::_createGeomet
211211
{
212212
// populate vertex list
213213
// Ref: http://www.opencascade.org/org/forum/thread_16694/?forum=3
214-
gp_Pnt pt = (triangulation->Nodes())(j).Transformed(transformation * location.Transformation());
214+
gp_Pnt pt = (triangulation->Node(j)).Transformed(transformation * location.Transformation());
215215
vertexList->push_back(osg::Vec3(pt.X(), pt.Y(), pt.Z()));
216216

217217
// populate color list

src/osgPlugins/ffmpeg/FFmpegDecoder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool FFmpegDecoder::open(const std::string & filename, FFmpegParameters* paramet
6262
{
6363
// Open video file
6464
AVFormatContext * p_format_context = 0;
65-
AVInputFormat *iformat = 0;
65+
const AVInputFormat *iformat = 0;
6666

6767
if (filename.compare(0, 5, "/dev/")==0)
6868
{
@@ -304,9 +304,9 @@ bool FFmpegDecoder::readNextPacketNormal()
304304
else
305305
{
306306
// Make the packet data available beyond av_read_frame() logical scope.
307-
if ((error = av_dup_packet(&packet)) < 0) {
308-
OSG_FATAL << "av_dup_packet() returned " << AvStrError(error) << std::endl;
309-
throw std::runtime_error("av_dup_packet() failed");
307+
if ((error = av_packet_make_refcounted(&packet)) < 0) {
308+
OSG_FATAL << "av_packet_make_refcounted() returned " << AvStrError(error) << std::endl;
309+
throw std::runtime_error("av_packet_make_refcounted() failed");
310310
}
311311

312312
m_pending_packet = FFmpegPacket(packet);

src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ static int decode_audio(AVCodecContext *avctx, int16_t *samples,
4040
avpkt.size = buf_size;
4141

4242
AVFrame *frame = av_frame_alloc();
43-
int ret, got_frame = 0;
43+
int ret;
4444

4545
if (!frame)
4646
return AVERROR(ENOMEM);
4747

48-
ret = avcodec_decode_audio4(avctx, frame, &got_frame, &avpkt);
48+
ret = avcodec_receive_frame(avctx, frame);
4949

5050
#ifdef USE_AVRESAMPLE // libav's AVFrame structure does not contain a 'channels' field
51-
if (ret >= 0 && got_frame) {
51+
if (ret >= 0) {
5252
#else
53-
if (ret >= 0 && got_frame && av_frame_get_channels(frame)>0) {
53+
if (ret >= 0 && frame->channels>0) {
5454
#endif
5555
int ch, plane_size;
5656
int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
@@ -151,7 +151,9 @@ void FFmpegDecoderAudio::open(AVStream * const stream, FFmpegParameters* paramet
151151
return;
152152

153153
m_stream = stream;
154-
m_context = stream->codec;
154+
m_codecpar = stream->codecpar;
155+
const AVCodec* p_codec = avcodec_find_decoder(m_codecpar->codec_id);
156+
m_context = avcodec_alloc_context3(p_codec);
155157

156158
m_in_sample_rate = m_context->sample_rate;
157159
m_in_nb_channels = m_context->channels;
@@ -214,7 +216,7 @@ printf("### CONVERTING from sample format %s TO %s\n\t\tFROM %d TO %d channels\n
214216
throw std::runtime_error("invalid audio codec");;
215217

216218
// Find the decoder for the audio stream
217-
AVCodec * const p_codec = avcodec_find_decoder(m_context->codec_id);
219+
p_codec = avcodec_find_decoder(m_context->codec_id);
218220

219221
if (p_codec == 0)
220222
throw std::runtime_error("avcodec_find_decoder() failed");

src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class FFmpegDecoderAudio : public OpenThreads::Thread
5959
PacketQueue & m_packets;
6060
FFmpegClocks & m_clocks;
6161
AVStream * m_stream;
62+
AVCodecParameters * m_codecpar;
6263
AVCodecContext * m_context;
6364
FFmpegPacket m_packet;
6465
const uint8_t * m_packet_data;

src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
6262
void FFmpegDecoderVideo::open(AVStream * const stream)
6363
{
6464
m_stream = stream;
65-
m_context = stream->codec;
65+
m_codecpar = stream->codecpar;
66+
const AVCodec* p_codec = avcodec_find_decoder(m_codecpar->codec_id);
67+
m_context = avcodec_alloc_context3(p_codec);
6668

6769
// Trust the video size given at this point
6870
// (avcodec_open seems to sometimes return a 0x0 size)
@@ -99,11 +101,12 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
99101

100102
// Allocate converted RGB frame
101103
m_frame_rgba.reset(av_frame_alloc());
102-
m_buffer_rgba[0].resize(avpicture_get_size(AV_PIX_FMT_RGB24, width(), height()));
104+
m_buffer_rgba[0].resize(av_image_get_buffer_size(AV_PIX_FMT_RGB24, width(), height(), 1));
103105
m_buffer_rgba[1].resize(m_buffer_rgba[0].size());
104106

105107
// Assign appropriate parts of the buffer to image planes in m_frame_rgba
106-
avpicture_fill((AVPicture *) (m_frame_rgba).get(), &(m_buffer_rgba[0])[0], AV_PIX_FMT_RGB24, width(), height());
108+
AVFrame *avf = m_frame_rgba.get();
109+
av_image_fill_arrays(avf->data, avf->linesize, &(m_buffer_rgba[0])[0], AV_PIX_FMT_RGB24, width(), height(), 1);
107110

108111
// Override get_buffer()/release_buffer() from codec context in order to retrieve the PTS of each frame.
109112
m_context->opaque = this;
@@ -169,7 +172,7 @@ void FFmpegDecoderVideo::decodeLoop()
169172
int frame_finished = 0;
170173

171174
// We want to use the entire packet since some codecs will require extra information for decoding
172-
const int bytes_decoded = avcodec_decode_video2(m_context, m_frame.get(), &frame_finished, &(packet.packet));
175+
const int bytes_decoded = avcodec_receive_frame(m_context, m_frame.get());
173176

174177
if (bytes_decoded < 0)
175178
throw std::runtime_error("avcodec_decode_video failed()");
@@ -283,7 +286,7 @@ void FFmpegDecoderVideo::findAspectRatio()
283286
m_pixel_aspect_ratio = ratio;
284287
}
285288

286-
int FFmpegDecoderVideo::convert(AVPicture *dst, int dst_pix_fmt, AVPicture *src,
289+
int FFmpegDecoderVideo::convert(AVFrame *dst, int dst_pix_fmt, AVFrame *src,
287290
int src_pix_fmt, int src_width, int src_height)
288291
{
289292
osg::Timer_t startTick = osg::Timer::instance()->tick();
@@ -334,11 +337,11 @@ void FFmpegDecoderVideo::publishFrame(const double delay, bool audio_disabled)
334337
return;
335338
#endif
336339

337-
AVPicture * const src = (AVPicture *) m_frame.get();
338-
AVPicture * const dst = (AVPicture *) m_frame_rgba.get();
340+
AVFrame * const src = (AVFrame *) m_frame.get();
341+
AVFrame * const dst = (AVFrame *) m_frame_rgba.get();
339342

340-
// Assign appropriate parts of the buffer to image planes in m_frame_rgba
341-
avpicture_fill((AVPicture *) (m_frame_rgba).get(), &(m_buffer_rgba[m_writeBuffer])[0], AV_PIX_FMT_RGB24, width(), height());
343+
// Assign appropriate parts of the buffer to image planes in m_frame_rgba
344+
av_image_fill_arrays(dst->data, dst->linesize, &(m_buffer_rgba[m_writeBuffer])[0], AV_PIX_FMT_RGB24, width(), height(), 1);
342345

343346
// Convert YUVA420p (i.e. YUV420p plus alpha channel) using our own routine
344347

@@ -370,7 +373,7 @@ void FFmpegDecoderVideo::publishFrame(const double delay, bool audio_disabled)
370373

371374

372375

373-
void FFmpegDecoderVideo::yuva420pToRgba(AVPicture * const dst, AVPicture * const src, int width, int height)
376+
void FFmpegDecoderVideo::yuva420pToRgba(AVFrame * const dst, AVFrame * const src, int width, int height)
374377
{
375378
convert(dst, AV_PIX_FMT_RGB24, src, m_context->pix_fmt, width, height);
376379

src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class FFmpegDecoderVideo : public OpenThreads::Thread
8888
void findAspectRatio();
8989
void publishFrame(double delay, bool audio_disabled);
9090
double synchronizeVideo(double pts);
91-
void yuva420pToRgba(AVPicture *dst, AVPicture *src, int width, int height);
91+
void yuva420pToRgba(AVFrame *dst, AVFrame *src, int width, int height);
9292

93-
int convert(AVPicture *dst, int dst_pix_fmt, AVPicture *src,
93+
int convert(AVFrame *dst, int dst_pix_fmt, AVFrame *src,
9494
int src_pix_fmt, int src_width, int src_height);
9595

9696

@@ -100,8 +100,9 @@ class FFmpegDecoderVideo : public OpenThreads::Thread
100100
PacketQueue & m_packets;
101101
FFmpegClocks & m_clocks;
102102
AVStream * m_stream;
103+
AVCodecParameters * m_codecpar;
103104
AVCodecContext * m_context;
104-
AVCodec * m_codec;
105+
const AVCodec * m_codec;
105106
const uint8_t * m_packet_data;
106107
int m_bytes_remaining;
107108
int64_t m_packet_pts;

src/osgPlugins/ffmpeg/FFmpegHeaders.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern "C"
4444
#endif
4545

4646
#include <libavutil/mathematics.h>
47+
#include <libavutil/imgutils.h>
4748

4849
#ifdef USE_SWSCALE
4950
#include <libswscale/swscale.h>

src/osgPlugins/ffmpeg/FFmpegPacket.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace osgFFmpeg
4242
void clear()
4343
{
4444
if (packet.data != 0)
45-
av_free_packet(&packet);
45+
av_packet_unref(&packet);
4646

4747
release();
4848
}

src/osgPlugins/ffmpeg/FFmpegParameters.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FFmpegParameters : public osg::Referenced
2020

2121
bool isFormatAvailable() const { return m_format!=NULL; }
2222

23-
AVInputFormat* getFormat() { return m_format; }
23+
const AVInputFormat* getFormat() { return m_format; }
2424
AVDictionary** getOptions() { return &m_options; }
2525
void setContext(AVIOContext* context) { m_context = context; }
2626
AVIOContext* getContext() { return m_context; }
@@ -29,7 +29,7 @@ class FFmpegParameters : public osg::Referenced
2929

3030
protected:
3131

32-
AVInputFormat* m_format;
32+
const AVInputFormat* m_format;
3333
AVIOContext* m_context;
3434
AVDictionary* m_options;
3535
};

src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
(LIBAVCODEC_VERSION_MAJOR==52 && LIBAVCODEC_VERSION_MINOR==20 && LIBAVCODEC_VERSION_MICRO >= 1)
2626
#define USE_AV_LOCK_MANAGER
2727
#endif
28+
#undef USE_AV_LOCK_MANAGER
2829

2930
extern "C" {
3031

@@ -118,7 +119,7 @@ class ReaderWriterFFmpeg : public osgDB::ReaderWriter
118119
av_lockmgr_register(&lockMgr);
119120
#endif
120121
// Register all FFmpeg formats/codecs
121-
av_register_all();
122+
// av_register_all(); // Omit after ffmpeg 4.0
122123

123124
avformat_network_init();
124125
}

0 commit comments

Comments
 (0)