Skip to content

Commit 0933c6e

Browse files
randomsjihoonl
authored andcommitted
Fix Build for ubuntu 14.04 (#48)
* fix issue #47 * fix double free
1 parent 9a8d433 commit 0933c6e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/libav_streamer.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LibavStreamer::~LibavStreamer()
6868
avcodec_close(codec_context_);
6969
if (frame_)
7070
{
71-
#if (LIBAVCODEC_VERSION_MAJOR < 54)
71+
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
7272
av_free(frame_);
7373
frame_ = NULL;
7474
#else
@@ -163,7 +163,11 @@ void LibavStreamer::initialize(const cv::Mat &img)
163163
}
164164

165165
// Allocate frame buffers
166+
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
167+
frame_ = avcodec_alloc_frame();
168+
#else
166169
frame_ = av_frame_alloc();
170+
#endif
167171
av_image_alloc(frame_->data, frame_->linesize, output_width_, output_height_,
168172
codec_context_->pix_fmt, 1);
169173

@@ -219,14 +223,22 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
219223
first_image_timestamp_ = time;
220224
}
221225
std::vector<uint8_t> encoded_frame;
222-
#if (LIBAVUTIL_VERSION_MAJOR < 52)
226+
#if (LIBAVUTIL_VERSION_MAJOR < 53)
223227
PixelFormat input_coding_format = PIX_FMT_BGR24;
224228
#else
225229
AVPixelFormat input_coding_format = AV_PIX_FMT_BGR24;
226230
#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
227236
AVFrame *raw_frame = av_frame_alloc();
228237
av_image_fill_arrays(raw_frame->data, raw_frame->linesize,
229238
img.data, input_coding_format, output_width_, output_height_, 0);
239+
#endif
240+
241+
230242

231243
// Convert from opencv to libav
232244
if (!sws_context_)
@@ -245,7 +257,11 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
245257
(const uint8_t * const *)raw_frame->data, raw_frame->linesize, 0,
246258
output_height_, frame_->data, frame_->linesize);
247259

260+
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
261+
delete raw_frame;
262+
#else
248263
av_frame_free(&raw_frame);
264+
#endif
249265

250266
// Encode the frame
251267
AVPacket pkt;
@@ -312,11 +328,15 @@ void LibavStreamer::sendImage(const cv::Mat &img, const ros::Time &time)
312328
{
313329
encoded_frame.clear();
314330
}
315-
#if (LIBAVCODEC_VERSION_MAJOR < 54)
331+
#if LIBAVCODEC_VERSION_INT < 54
316332
av_free(pkt.data);
317333
#endif
318334

335+
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
336+
av_free_packet(&pkt);
337+
#else
319338
av_packet_unref(&pkt);
339+
#endif
320340

321341
connection_->write_and_clear(encoded_frame);
322342
}

0 commit comments

Comments
 (0)