1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
|
From: Erik Massop <e.massop@hccnet.nl>
To: 739455@bugs.debian.org
Subject: Re: Bug#739455: FTBFS with libav10
Date: Wed, 19 Feb 2014 02:28:22 +0100
This patch did originally not apply, and needed to be updated. The
updates were done by Reinhard Tartler <siretart@tauware.de> on Mar 26,
2014.
--- a/src/plugins/avcodec/avcodec.c
+++ b/src/plugins/avcodec/avcodec.c
@@ -1,7 +1,7 @@
/** @file avcodec.c
* Decoder plugin for ffmpeg avcodec formats
*
- * Copyright (C) 2006-2011 XMMS2 Team
+ * Copyright (C) 2006-2014 XMMS2 Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,10 +14,10 @@
* Lesser General Public License for more details.
*/
-#include "xmms_configuration.h"
-#include "xmms/xmms_xformplugin.h"
-#include "xmms/xmms_sample.h"
-#include "xmms/xmms_log.h"
+#include <xmms_configuration.h>
+#include <xmms/xmms_xformplugin.h>
+#include <xmms/xmms_sample.h>
+#include <xmms/xmms_log.h>
#include <stdio.h>
#include <stdlib.h>
@@ -37,6 +37,8 @@ typedef struct {
guint buffer_size;
gboolean no_demuxer;
+ AVFrame *read_out_frame;
+
guint channels;
guint samplerate;
xmms_sample_format_t sampleformat;
@@ -54,10 +56,14 @@ typedef struct {
static gboolean xmms_avcodec_plugin_setup (xmms_xform_plugin_t *xform_plugin);
static gboolean xmms_avcodec_init (xmms_xform_t *xform);
static void xmms_avcodec_destroy (xmms_xform_t *xform);
+static gint xmms_avcodec_internal_read_some (xmms_xform_t *xform, xmms_avcodec_data_t *data, xmms_error_t *error);
+static gint xmms_avcodec_internal_decode_some (xmms_avcodec_data_t *data);
+static void xmms_avcodec_internal_append (xmms_avcodec_data_t *data);
static gint xmms_avcodec_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
xmms_error_t *error);
static gint64 xmms_avcodec_seek (xmms_xform_t *xform, gint64 samples,
xmms_xform_seek_mode_t whence, xmms_error_t *err);
+static xmms_sample_format_t xmms_avcodec_translate_sample_format (enum AVSampleFormat av_sample_format);
/*
* Plugin header
@@ -86,13 +92,23 @@ xmms_avcodec_plugin_setup (xmms_xform_pl
xmms_magic_add ("A/52 (AC-3) header", "audio/x-ffmpeg-ac3",
"0 beshort 0x0b77", NULL);
xmms_magic_add ("DTS header", "audio/x-ffmpeg-dca",
- "0 belong 0x7ffe8001", NULL);
+ "0 belong 0x7ffe8001", NULL);
xmms_xform_plugin_indata_add (xform_plugin,
XMMS_STREAM_TYPE_MIMETYPE,
"audio/x-ffmpeg-*",
NULL);
+ XMMS_DBG ("avcodec version at build time is %d.%d.%d",
+ (LIBAVCODEC_VERSION_INT >> 16),
+ (LIBAVCODEC_VERSION_INT >> 8) & 0xff,
+ LIBAVCODEC_VERSION_INT & 0xff);
+ XMMS_DBG ("avcodec version at run time is %d.%d.%d",
+ (avcodec_version() >> 16),
+ (avcodec_version() >> 8) & 0xff,
+ avcodec_version() & 0xff);
+ XMMS_DBG ("avcodec configuration is %s", avcodec_configuration());
+
return TRUE;
}
@@ -108,6 +124,7 @@ xmms_avcodec_destroy (xmms_xform_t *xfor
avcodec_close (data->codecctx);
av_free (data->codecctx);
+ av_frame_free (&data->read_out_frame);
g_string_free (data->outbuf, TRUE);
g_free (data->buffer);
@@ -133,9 +150,10 @@ xmms_avcodec_init (xmms_xform_t *xform)
data->buffer_size = AVCODEC_BUFFER_SIZE;
data->codecctx = NULL;
+ data->read_out_frame = av_frame_alloc ();
+
xmms_xform_private_data_set (xform, data);
- avcodec_init ();
avcodec_register_all ();
mimetype = xmms_xform_indata_get_str (xform,
@@ -162,12 +180,12 @@ xmms_avcodec_init (xmms_xform_t *xform)
data->channels = ret;
}
- /* bitrate required for WMA files */
+ /* Required by WMA xform. */
xmms_xform_auxdata_get_int (xform,
"bitrate",
&data->bitrate);
- /* ALAC and MAC require bits per sample field to be 16 */
+ /* Required by tta and apefile xforms. */
xmms_xform_auxdata_get_int (xform,
"samplebits",
&data->samplebits);
@@ -189,7 +207,8 @@ xmms_avcodec_init (xmms_xform_t *xform)
!strcmp (data->codec_id, "adpcm_swf") ||
!strcmp (data->codec_id, "pcm_s16le") ||
!strcmp (data->codec_id, "ac3") ||
- !strcmp (data->codec_id, "dca")) {
+ !strcmp (data->codec_id, "dca") ||
+ !strcmp (data->codec_id, "nellymoser")) {
/* number 1024 taken from libavformat raw.c RAW_PACKET_SIZE */
data->extradata = g_malloc0 (1024);
data->extradata_size = 1024;
@@ -205,7 +224,7 @@ xmms_avcodec_init (xmms_xform_t *xform)
data->codecctx->sample_rate = data->samplerate;
data->codecctx->channels = data->channels;
data->codecctx->bit_rate = data->bitrate;
- CONTEXT_BPS (data->codecctx) = data->samplebits;
+ data->codecctx->bits_per_coded_sample = data->samplebits;
data->codecctx->block_align = data->block_align;
data->codecctx->extradata = data->extradata;
data->codecctx->extradata_size = data->extradata_size;
@@ -221,7 +240,7 @@ xmms_avcodec_init (xmms_xform_t *xform)
/* some codecs need to have something read before they set
* the samplerate and channels correctly, unfortunately... */
- if ((ret = xmms_avcodec_read (xform, buf, 42, &error)) > 0) {
+ if ((ret = xmms_avcodec_read (xform, buf, sizeof (buf), &error)) > 0) {
g_string_insert_len (data->outbuf, 0, buf, ret);
} else {
XMMS_DBG ("First read failed, codec is not working...");
@@ -232,19 +251,27 @@ xmms_avcodec_init (xmms_xform_t *xform)
data->samplerate = data->codecctx->sample_rate;
data->channels = data->codecctx->channels;
+ data->sampleformat = xmms_avcodec_translate_sample_format (data->codecctx->sample_fmt);
+ if (data->sampleformat == XMMS_SAMPLE_FORMAT_UNKNOWN) {
+ avcodec_close (data->codecctx);
+ goto err;
+ }
xmms_xform_outdata_type_add (xform,
XMMS_STREAM_TYPE_MIMETYPE,
"audio/pcm",
XMMS_STREAM_TYPE_FMT_FORMAT,
- XMMS_SAMPLE_FORMAT_S16,
+ data->sampleformat,
XMMS_STREAM_TYPE_FMT_CHANNELS,
data->channels,
XMMS_STREAM_TYPE_FMT_SAMPLERATE,
data->samplerate,
XMMS_STREAM_TYPE_END);
- XMMS_DBG ("Decoder '%s' initialized successfully!", codec->name);
+ XMMS_DBG ("Decoder %s at rate %d with %d channels of format %s initialized",
+ codec->name, data->codecctx->sample_rate,
+ data->codecctx->channels,
+ av_get_sample_fmt_name (data->codecctx->sample_fmt));
return TRUE;
@@ -252,6 +279,9 @@ err:
if (data->codecctx) {
av_free (data->codecctx);
}
+ if (data->read_out_frame) {
+ avcodec_free_frame (&data->read_out_frame);
+ }
g_string_free (data->outbuf, TRUE);
g_free (data->extradata);
g_free (data);
@@ -264,102 +294,24 @@ xmms_avcodec_read (xmms_xform_t *xform,
xmms_error_t *error)
{
xmms_avcodec_data_t *data;
- char outbuf[AVCODEC_MAX_AUDIO_FRAME_SIZE];
- gint outbufsize, bytes_read = 0;
guint size;
data = xmms_xform_private_data_get (xform);
g_return_val_if_fail (data, -1);
- size = MIN (data->outbuf->len, len);
- while (size == 0) {
- AVPacket packet;
- av_init_packet (&packet);
+ while (0 == (size = MIN (data->outbuf->len, len))) {
+ gint res;
if (data->no_demuxer || data->buffer_length == 0) {
- gint read_total;
-
- bytes_read = xmms_xform_read (xform,
- (gchar *) (data->buffer + data->buffer_length),
- data->buffer_size - data->buffer_length,
- error);
-
- if (bytes_read < 0) {
- XMMS_DBG ("Error while reading data");
- return bytes_read;
- } else if (bytes_read == 0) {
- XMMS_DBG ("EOF");
- return 0;
- }
-
- read_total = bytes_read;
-
- /* If we have a demuxer plugin, make sure we read the whole packet */
- while (read_total == data->buffer_size && !data->no_demuxer) {
- /* multiply the buffer size and try to read again */
- data->buffer = g_realloc (data->buffer, data->buffer_size * 2);
- bytes_read = xmms_xform_read (xform,
- (gchar *) data->buffer +
- data->buffer_size,
- data->buffer_size,
- error);
- data->buffer_size *= 2;
-
- if (bytes_read < 0) {
- XMMS_DBG ("Error while reading data");
- return bytes_read;
- }
-
- read_total += bytes_read;
-
- if (read_total < data->buffer_size) {
- /* finally double the buffer size for performance reasons, the
- * hotspot handling likes to fit two frames in the buffer */
- data->buffer = g_realloc (data->buffer, data->buffer_size * 2);
- data->buffer_size *= 2;
- XMMS_DBG ("Reallocated avcodec internal buffer to be %d bytes",
- data->buffer_size);
-
- break;
- }
- }
-
- /* Update the buffer length */
- data->buffer_length += read_total;
- }
-
- packet.data = data->buffer;
- packet.size = data->buffer_length;
-
- outbufsize = sizeof (outbuf);
- bytes_read = avcodec_decode_audio3 (data->codecctx, (short *) outbuf,
- &outbufsize, &packet);
-
- /* The DTS decoder of ffmpeg is buggy and always returns
- * the input buffer length, get frame length from header */
- if (!strcmp (data->codec_id, "dca") && bytes_read > 0) {
- bytes_read = ((int)data->buffer[5] << 12) |
- ((int)data->buffer[6] << 4) |
- ((int)data->buffer[7] >> 4);
- bytes_read = (bytes_read & 0x3fff) + 1;
- }
+ gint bytes_read;
- if (bytes_read < 0 || bytes_read > data->buffer_length) {
- XMMS_DBG ("Error decoding data!");
- return -1;
- } else if (bytes_read != data->buffer_length) {
- g_memmove (data->buffer,
- data->buffer + bytes_read,
- data->buffer_length - bytes_read);
- }
-
- data->buffer_length -= bytes_read;
-
- if (outbufsize > 0) {
- g_string_append_len (data->outbuf, outbuf, outbufsize);
+ bytes_read = xmms_avcodec_internal_read_some (xform, data, error);
+ if (bytes_read <= 0) { return bytes_read; }
}
- size = MIN (data->outbuf->len, len);
+ res = xmms_avcodec_internal_decode_some (data);
+ if (res < 0) { return res; }
+ if (res > 0) { xmms_avcodec_internal_append (data); }
}
memcpy (buf, data->outbuf->str, size);
@@ -372,8 +324,6 @@ static gint64
xmms_avcodec_seek (xmms_xform_t *xform, gint64 samples, xmms_xform_seek_mode_t whence, xmms_error_t *err)
{
xmms_avcodec_data_t *data;
- char outbuf[AVCODEC_MAX_AUDIO_FRAME_SIZE];
- gint outbufsize, bytes_read = 0;
gint64 ret = -1;
g_return_val_if_fail (xform, -1);
@@ -391,23 +341,11 @@ xmms_avcodec_seek (xmms_xform_t *xform,
/* The buggy ape decoder doesn't flush buffers, so we need to finish decoding
* the frame before seeking to avoid segfaults... this hack sucks */
+ /* FIXME: Is ^^^ still true? */
while (data->buffer_length > 0) {
- AVPacket packet;
- av_init_packet (&packet);
- packet.data = data->buffer;
- packet.size = data->buffer_length;
-
- outbufsize = sizeof (outbuf);
- bytes_read = avcodec_decode_audio3 (data->codecctx, (short *) outbuf,
- &outbufsize, &packet);
-
- if (bytes_read < 0 || bytes_read > data->buffer_length) {
- XMMS_DBG ("Error decoding data!");
+ if (xmms_avcodec_internal_decode_some (data) < 0) {
return -1;
}
-
- data->buffer_length -= bytes_read;
- g_memmove (data->buffer, data->buffer + bytes_read, data->buffer_length);
}
ret = xmms_xform_seek (xform, samples, whence, err);
@@ -421,3 +359,178 @@ xmms_avcodec_seek (xmms_xform_t *xform,
return ret;
}
+
+static xmms_sample_format_t
+xmms_avcodec_translate_sample_format (enum AVSampleFormat av_sample_format)
+{
+ switch (av_sample_format) {
+ case AV_SAMPLE_FMT_U8:
+ case AV_SAMPLE_FMT_U8P:
+ return XMMS_SAMPLE_FORMAT_U8;
+ case AV_SAMPLE_FMT_S16:
+ case AV_SAMPLE_FMT_S16P:
+ return XMMS_SAMPLE_FORMAT_S16;
+ case AV_SAMPLE_FMT_S32:
+ case AV_SAMPLE_FMT_S32P:
+ return XMMS_SAMPLE_FORMAT_S32;
+ case AV_SAMPLE_FMT_FLT:
+ case AV_SAMPLE_FMT_FLTP:
+ return XMMS_SAMPLE_FORMAT_FLOAT;
+ case AV_SAMPLE_FMT_DBL:
+ case AV_SAMPLE_FMT_DBLP:
+ return XMMS_SAMPLE_FORMAT_DOUBLE;
+ default:
+ XMMS_DBG ("AVSampleFormat (%i: %s) not supported.", av_sample_format,
+ av_get_sample_fmt_name (av_sample_format));
+ return XMMS_SAMPLE_FORMAT_UNKNOWN;
+ }
+}
+
+/*
+Read some data from our source of data to data->buffer, updating buffer_length
+and buffer_size as needed.
+
+Returns: on error: negative
+ on EOF: zero
+ otherwise: number of bytes read.
+*/
+static gint
+xmms_avcodec_internal_read_some (xmms_xform_t *xform,
+ xmms_avcodec_data_t *data,
+ xmms_error_t *error)
+{
+ gint bytes_read, read_total;
+
+ bytes_read = xmms_xform_read (xform,
+ (gchar *) (data->buffer + data->buffer_length),
+ data->buffer_size - data->buffer_length,
+ error);
+
+ if (bytes_read < 0) {
+ XMMS_DBG ("Error while reading data");
+ return bytes_read;
+ } else if (bytes_read == 0) {
+ XMMS_DBG ("EOF");
+ return 0;
+ }
+
+ read_total = bytes_read;
+
+ /* If we have a demuxer plugin, make sure we read the whole packet */
+ while (read_total == data->buffer_size && !data->no_demuxer) {
+ /* multiply the buffer size and try to read again */
+ data->buffer = g_realloc (data->buffer, data->buffer_size * 2);
+ bytes_read = xmms_xform_read (xform,
+ (gchar *) data->buffer +
+ data->buffer_size,
+ data->buffer_size,
+ error);
+ data->buffer_size *= 2;
+
+ if (bytes_read < 0) {
+ XMMS_DBG ("Error while reading data");
+ return bytes_read;
+ }
+
+ read_total += bytes_read;
+
+ if (read_total < data->buffer_size) {
+ /* finally double the buffer size for performance reasons, the
+ * hotspot handling likes to fit two frames in the buffer */
+ data->buffer = g_realloc (data->buffer, data->buffer_size * 2);
+ data->buffer_size *= 2;
+ XMMS_DBG ("Reallocated avcodec internal buffer to be %d bytes",
+ data->buffer_size);
+
+ break;
+ }
+ }
+
+ /* Update the buffer length */
+ data->buffer_length += read_total;
+
+ return read_total;
+}
+
+/*
+Decode some data from data->buffer[0..data->buffer_length-1] to
+data->read_out_frame
+
+Returns: on error: negative
+ on no new data produced: zero
+ otherwise: positive
+
+FIXME: data->buffer should be at least data->buffer_length +
+FF_INPUT_BUFFER_PADDING_SIZE long.
+*/
+static gint
+xmms_avcodec_internal_decode_some (xmms_avcodec_data_t *data)
+{
+ int got_frame = 0;
+ gint bytes_read = 0;
+ AVPacket packet;
+
+ av_init_packet (&packet);
+ packet.data = data->buffer;
+ packet.size = data->buffer_length;
+
+ /* clear buffers and reset fields to defaults */
+ av_frame_unref (data->read_out_frame);
+
+ bytes_read = avcodec_decode_audio4 (
+ data->codecctx, data->read_out_frame, &got_frame, &packet);
+
+ /* The DTS decoder of ffmpeg is buggy and always returns
+ * the input buffer length, get frame length from header */
+ /* FIXME: Is ^^^^ still true? */
+ if (!strcmp (data->codec_id, "dca") && bytes_read > 0) {
+ bytes_read = ((int)data->buffer[5] << 12) |
+ ((int)data->buffer[6] << 4) |
+ ((int)data->buffer[7] >> 4);
+ bytes_read = (bytes_read & 0x3fff) + 1;
+ }
+
+ if (bytes_read < 0 || bytes_read > data->buffer_length) {
+ XMMS_DBG ("Error decoding data!");
+ return -1;
+ }
+
+ if (bytes_read < data->buffer_length) {
+ data->buffer_length -= bytes_read;
+ g_memmove (data->buffer,
+ data->buffer + bytes_read,
+ data->buffer_length);
+ } else {
+ data->buffer_length = 0;
+ }
+
+ return got_frame ? 1 : 0;
+}
+
+static void
+xmms_avcodec_internal_append (xmms_avcodec_data_t *data)
+{
+ enum AVSampleFormat fmt = (enum AVSampleFormat) data->read_out_frame->format;
+ int samples = data->read_out_frame->nb_samples;
+ int channels = data->codecctx->channels;
+ int bps = av_get_bytes_per_sample (fmt);
+
+ if (av_sample_fmt_is_planar (fmt)) {
+ /* Convert from planar to packed format */
+ gint i, j;
+
+ for (i = 0; i < samples; i++) {
+ for (j = 0; j < channels; j++) {
+ g_string_append_len (
+ data->outbuf,
+ (gchar *) (data->read_out_frame->extended_data[j] + i*bps),
+ bps
+ );
+ }
+ }
+ } else {
+ g_string_append_len (data->outbuf,
+ (gchar *) data->read_out_frame->extended_data[0],
+ samples * channels * bps);
+ }
+}
--- a/src/plugins/avcodec/avcodec_compat.h
+++ b/src/plugins/avcodec/avcodec_compat.h
@@ -1,7 +1,7 @@
/** @file avcodec_compat.h
* Compatibility header for libavcodec backwards compatibility
*
- * Copyright (C) 2011 XMMS2 Team
+ * Copyright (C) 2011-2014 XMMS2 Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,50 +21,19 @@
# include "avcodec.h"
#endif
-/* Map avcodec_decode_audio2 into the deprecated version
- * avcodec_decode_audio in versions earlier than 51.28 */
-#if LIBAVCODEC_VERSION_INT < 0x331c00
-# define avcodec_decode_audio2 avcodec_decode_audio
+/* Map avcodec_free_frame to av_freep if the former doesn't exist.
+ * (This is in versions earlier than 54.28.0 (libav) or 54.59.100 (ffmpeg)) */
+#if ! HAVE_AVCODEC_FREE_FRAME
+# define avcodec_free_frame av_freep
#endif
-/* Handle API change that happened in libavcodec 52.00 */
-#if LIBAVCODEC_VERSION_INT < 0x340000
-# define CONTEXT_BPS(codecctx) (codecctx)->bits_per_sample
-#else
-# define CONTEXT_BPS(codecctx) (codecctx)->bits_per_coded_sample
-#endif
-
-/* Before 52.23 AVPacket was defined in avformat.h which we
- * do not want to depend on, so we define part of it manually
- * on versions smaller than 52.23 (this makes me cry) */
-#if LIBAVCODEC_VERSION_INT < 0x341700
-typedef struct AVPacket {
- uint8_t *data;
- int size;
-} AVPacket;
-#endif
-
-/* Same thing as above for av_init_packet and version 52.25 */
-#if LIBAVCODEC_VERSION_INT < 0x341900
-# define av_init_packet(pkt) do { \
- (pkt)->data = NULL; \
- (pkt)->size = 0; \
- } while(0)
+/* Map av_frame_alloc, av_frame_unref, av_frame_free into their
+ * deprecated versions in versions earlier than 55.28.1 */
+#if LIBAVCODEC_VERSION_INT < 0x371c01
+# define av_frame_alloc avcodec_alloc_frame
+# define av_frame_unref avcodec_get_frame_defaults
+# define av_frame_free avcodec_free_frame
#endif
-
-/* Map avcodec_decode_audio3 into the deprecated version
- * avcodec_decode_audio2 in versions earlier than 52.26 */
-#if LIBAVCODEC_VERSION_INT < 0x341a00
-# define avcodec_decode_audio3(avctx, samples, frame_size_ptr, avpkt) \
- avcodec_decode_audio2(avctx, samples, frame_size_ptr, \
- (avpkt)->data, (avpkt)->size)
-#endif
-
-/* Handle API change that happened in libavcodec 52.64 */
-#if LIBAVCODEC_VERSION_INT < 0x344000
-# define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
-#endif
-
/* Calling avcodec_init is not necessary after 53.04 (ffmpeg 0.9) */
#if LIBAVCODEC_VERSION_INT >= 0x350400
# define avcodec_init()
--- a/src/plugins/avcodec/wscript
+++ b/src/plugins/avcodec/wscript
@@ -1,10 +1,58 @@
from waftools.plugin import plugin
+## Code fragments for configuration
+avcodec_decode_audio4_fragment = """
+#ifdef HAVE_LIBAVCODEC_AVCODEC_H
+# include "libavcodec/avcodec.h"
+#else
+# include "avcodec.h"
+#endif
+int main(void) {
+ AVCodecContext *ctx;
+ AVFrame *frame;
+ int got_frame;
+ AVPacket *pkt;
+
+ avcodec_decode_audio4 (ctx, frame, &got_frame, pkt);
+
+ return 0;
+}
+"""
+
+avcodec_free_frame_fragment = """
+#ifdef HAVE_LIBAVCODEC_AVCODEC_H
+# include "libavcodec/avcodec.h"
+#else
+# include "avcodec.h"
+#endif
+int main(void) {
+ AVFrame *frame;
+
+ avcodec_free_frame (&frame);
+
+ return 0;
+}
+"""
+
def plugin_configure(conf):
conf.check_cfg(package="libavcodec", uselib_store="avcodec",
args="--cflags --libs")
conf.check_cc(header_name="avcodec.h", uselib="avcodec", type="cshlib", mandatory=False)
conf.check_cc(header_name="libavcodec/avcodec.h", uselib="avcodec", type="cshlib", mandatory=False)
+ # mandatory function avcodec_decode_audio4 available since
+ # * ffmpeg: commit e4de716, lavc 53.40.0, release 0.9
+ # * libav: commit 0eea212, lavc 53.25.0, release 0.8
+ conf.check_cc(fragment=avcodec_decode_audio4_fragment, uselib="avcodec",
+ uselib_store="avcodec_decode_audio4",
+ msg="Checking for function avcodec_decode_audio4", mandatory=True)
+
+ # non-mandatory function avcodec_free_frame since
+ # * ffmpeg: commit 46a3595, lavc 54.59.100, release 1.0
+ # * libav: commit a42aada, lavc 54.28.0, release 9
+ conf.check_cc(fragment=avcodec_free_frame_fragment, uselib="avcodec",
+ uselib_store="avcodec_free_frame",
+ msg="Checking for function avcodec_free_frame", mandatory=False)
+
configure, build = plugin('avcodec', configure=plugin_configure,
libs=["avcodec"])
|