@@ -68,7 +68,7 @@ LibavStreamer::~LibavStreamer()
68
68
avcodec_close (codec_context_);
69
69
if (frame_)
70
70
{
71
- #if (LIBAVCODEC_VERSION_MAJOR < 54 )
71
+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1 )
72
72
av_free (frame_);
73
73
frame_ = NULL ;
74
74
#else
@@ -163,7 +163,11 @@ void LibavStreamer::initialize(const cv::Mat &img)
163
163
}
164
164
165
165
// Allocate frame buffers
166
+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
167
+ frame_ = avcodec_alloc_frame ();
168
+ #else
166
169
frame_ = av_frame_alloc ();
170
+ #endif
167
171
av_image_alloc (frame_->data , frame_->linesize , output_width_, output_height_,
168
172
codec_context_->pix_fmt , 1 );
169
173
@@ -219,14 +223,22 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
219
223
first_image_timestamp_ = time;
220
224
}
221
225
std::vector<uint8_t > encoded_frame;
222
- #if (LIBAVUTIL_VERSION_MAJOR < 52 )
226
+ #if (LIBAVUTIL_VERSION_MAJOR < 53 )
223
227
PixelFormat input_coding_format = PIX_FMT_BGR24;
224
228
#else
225
229
AVPixelFormat input_coding_format = AV_PIX_FMT_BGR24;
226
230
#endif
231
+
232
+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
233
+ AVPicture *raw_frame = new AVPicture;
234
+ avpicture_fill (raw_frame, img.data , input_coding_format, output_width_, output_height_);
235
+ #else
227
236
AVFrame *raw_frame = av_frame_alloc ();
228
237
av_image_fill_arrays (raw_frame->data , raw_frame->linesize ,
229
238
img.data , input_coding_format, output_width_, output_height_, 0 );
239
+ #endif
240
+
241
+
230
242
231
243
// Convert from opencv to libav
232
244
if (!sws_context_)
@@ -245,7 +257,11 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
245
257
(const uint8_t * const *)raw_frame->data , raw_frame->linesize , 0 ,
246
258
output_height_, frame_->data , frame_->linesize );
247
259
260
+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
261
+ delete raw_frame;
262
+ #else
248
263
av_frame_free (&raw_frame);
264
+ #endif
249
265
250
266
// Encode the frame
251
267
AVPacket pkt;
@@ -312,11 +328,15 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
312
328
{
313
329
encoded_frame.clear ();
314
330
}
315
- #if (LIBAVCODEC_VERSION_MAJOR < 54)
331
+ #if LIBAVCODEC_VERSION_INT < 54
316
332
av_free (pkt.data );
317
333
#endif
318
334
335
+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
336
+ av_free_packet (&pkt);
337
+ #else
319
338
av_packet_unref (&pkt);
339
+ #endif
320
340
321
341
connection_->write_and_clear (encoded_frame);
322
342
}
0 commit comments