xine-lib-1.2.13-ffmpeg6-compatibility_2.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. # HG changeset patch
  2. # User Torsten Jager <t.jager@gmx.de>
  3. # Date 1715025355 -7200
  4. # Mon May 06 21:55:55 2024 +0200
  5. # Node ID 1e7b184008860c8be2289c3cefd9dee57f06193a
  6. # Parent d1954d852980ddc887a67a9f1a26626909561ff5
  7. ffmpeg compatibility update 1.
  8. diff -r d1954d852980 -r 1e7b18400886 src/combined/ffmpeg/ff_audio_decoder.c
  9. --- a/src/combined/ffmpeg/ff_audio_decoder.c Mon Apr 08 13:25:10 2024 +0200
  10. +++ b/src/combined/ffmpeg/ff_audio_decoder.c Mon May 06 21:55:55 2024 +0200
  11. @@ -1,5 +1,5 @@
  12. /*
  13. - * Copyright (C) 2001-2023 the xine project
  14. + * Copyright (C) 2001-2024 the xine project
  15. *
  16. * This file is part of xine, a free video player.
  17. *
  18. @@ -67,6 +67,7 @@
  19. xine_t *xine;
  20. float gain;
  21. + int bitexact;
  22. } ff_audio_class_t;
  23. typedef struct ff_audio_decoder_s {
  24. @@ -188,14 +189,25 @@
  25. xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
  26. "ffmpeg_audio_dec: found AAC ADTS syncword after %d bytes\n", i);
  27. if (this->buftype == BUF_AUDIO_AAC_LATM) {
  28. + uint8_t *ed = NULL;
  29. + int es = 0;
  30. xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
  31. "ffmpeg_audio_dec: stream says LATM but is ADTS -> switching decoders\n");
  32. - if (this->decoder_ok) {
  33. - pthread_mutex_lock (&ffmpeg_lock);
  34. - avcodec_close (this->context);
  35. - pthread_mutex_unlock (&ffmpeg_lock);
  36. - this->decoder_ok = 0;
  37. + pthread_mutex_lock (&ffmpeg_lock);
  38. + if (this->context) {
  39. + ed = this->context->extradata;
  40. + es = this->context->extradata_size;
  41. + this->context->extradata = NULL;
  42. + this->context->extradata_size = 0;
  43. + XFF_FREE_CONTEXT (this->context);
  44. }
  45. + this->decoder_ok = 0;
  46. + this->context = XFF_ALLOC_CONTEXT ();
  47. + if (this->context) {
  48. + this->context->extradata = ed;
  49. + this->context->extradata_size = es;
  50. + }
  51. + pthread_mutex_unlock (&ffmpeg_lock);
  52. this->codec = NULL;
  53. ff_audio_open_codec (this, BUF_AUDIO_AAC);
  54. }
  55. @@ -349,6 +361,11 @@
  56. return -1;
  57. }
  58. + if (this->class->bitexact)
  59. + this->context->flags |= CODEC_FLAG_BITEXACT;
  60. + else
  61. + this->context->flags &= ~CODEC_FLAG_BITEXACT;
  62. +
  63. pthread_mutex_lock (&ffmpeg_lock);
  64. if (XFF_AVCODEC_OPEN (this->context, this->codec) < 0) {
  65. pthread_mutex_unlock (&ffmpeg_lock);
  66. @@ -1377,9 +1394,21 @@
  67. }
  68. #endif
  69. pthread_mutex_lock (&ffmpeg_lock);
  70. - avcodec_close (this->context);
  71. - if (XFF_AVCODEC_OPEN (this->context, this->codec) < 0)
  72. + {
  73. + uint8_t *ed = this->context->extradata;
  74. + int es = this->context->extradata_size;
  75. + this->context->extradata = NULL;
  76. + this->context->extradata_size = 0;
  77. + XFF_FREE_CONTEXT (this->context);
  78. this->decoder_ok = 0;
  79. + this->context = XFF_ALLOC_CONTEXT ();
  80. + if (this->context) {
  81. + this->context->extradata = ed;
  82. + this->context->extradata_size = es;
  83. + }
  84. + }
  85. + if (XFF_AVCODEC_OPEN (this->context, this->codec) >= 0)
  86. + this->decoder_ok = 1;
  87. pthread_mutex_unlock (&ffmpeg_lock);
  88. }
  89. @@ -1418,20 +1447,20 @@
  90. XFF_FREE_FRAME (this->av_frame);
  91. }
  92. #endif
  93. - pthread_mutex_lock (&ffmpeg_lock);
  94. - avcodec_close (this->context);
  95. - pthread_mutex_unlock (&ffmpeg_lock);
  96. }
  97. + pthread_mutex_lock (&ffmpeg_lock);
  98. + if (this->context) {
  99. + _x_freep (&this->context->extradata);
  100. + this->context->extradata_size = 0;
  101. + XFF_FREE_CONTEXT (this->context);
  102. + }
  103. + pthread_mutex_unlock (&ffmpeg_lock);
  104. ff_audio_output_close(this);
  105. xine_free_aligned (this->buf);
  106. xine_free_aligned (this->decode_buffer);
  107. - _x_freep (&this->context->extradata);
  108. - this->context->extradata_size = 0;
  109. - XFF_FREE_CONTEXT (this->context);
  110. -
  111. XFF_PACKET_UNREF (this->avpkt);
  112. xine_pts_queue_delete (&this->pts_queue);
  113. @@ -1513,6 +1542,12 @@
  114. free (this);
  115. }
  116. +static void ff_bitexact_cb (void *user_data, xine_cfg_entry_t *entry) {
  117. + ff_audio_class_t *class = (ff_audio_class_t *)user_data;
  118. +
  119. + class->bitexact = entry->num_value;
  120. +}
  121. +
  122. void *init_audio_plugin (xine_t *xine, const void *data) {
  123. ff_audio_class_t *this ;
  124. @@ -1540,5 +1575,12 @@
  125. 10, ff_gain_cb, this)
  126. / (float)20);
  127. + this->bitexact = xine->config->register_bool (xine->config,
  128. + "audio.processing.ffmpeg_bitexact", 0,
  129. + _("Let FFmpeg use precise but slower math"),
  130. + _("Get slightly better sound, at the expense of speed.\n"
  131. + "Takes effect with next stream."),
  132. + 10, ff_bitexact_cb, this);
  133. +
  134. return this;
  135. }
  136. diff -r d1954d852980 -r 1e7b18400886 src/combined/ffmpeg/ff_video_decoder.c
  137. --- a/src/combined/ffmpeg/ff_video_decoder.c Mon Apr 08 13:25:10 2024 +0200
  138. +++ b/src/combined/ffmpeg/ff_video_decoder.c Mon May 06 21:55:55 2024 +0200
  139. @@ -1,5 +1,5 @@
  140. /*
  141. - * Copyright (C) 2001-2022 the xine project
  142. + * Copyright (C) 2001-2024 the xine project
  143. *
  144. * This file is part of xine, a free video player.
  145. *
  146. @@ -128,6 +128,7 @@
  147. int64_t pts;
  148. int64_t last_pts;
  149. + int64_t tagged_pts;
  150. int video_step;
  151. int reported_video_step;
  152. uint8_t pts_tag_pass;
  153. @@ -551,7 +552,9 @@
  154. # ifdef XFF_FRAME_AGE
  155. av_frame->age = 1;
  156. # endif
  157. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  158. av_frame->reordered_opaque = context->reordered_opaque;
  159. +#endif
  160. ffsf = ffsf_new (this);
  161. if (!ffsf)
  162. @@ -862,7 +865,9 @@
  163. # endif
  164. /* take over pts for this frame to have it reordered */
  165. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  166. av_frame->reordered_opaque = context->reordered_opaque;
  167. +#endif
  168. return 0;
  169. }
  170. @@ -1142,9 +1147,13 @@
  171. if (this->codec->id == CODEC_ID_VC1 &&
  172. (!this->bih.biWidth || !this->bih.biHeight)) {
  173. /* VC1 codec must be re-opened with correct width and height. */
  174. - avcodec_close(this->context);
  175. -
  176. - if (XFF_AVCODEC_OPEN (this->context, this->codec) < 0) {
  177. + if (this->context) {
  178. + _x_freep (&this->context->extradata);
  179. + this->context->extradata_size = 0;
  180. + XFF_FREE_CONTEXT (this->context);
  181. + }
  182. + this->context = XFF_ALLOC_CONTEXT ();
  183. + if (!(this->context && XFF_AVCODEC_OPEN (this->context, this->codec) >= 0)) {
  184. pthread_mutex_unlock(&ffmpeg_lock);
  185. xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
  186. _("ffmpeg_video_dec: couldn't open decoder (pass 2)\n"));
  187. @@ -1211,6 +1220,11 @@
  188. /* dont want initial AV_NOPTS_VALUE here */
  189. this->context->reordered_opaque = 0;
  190. #endif
  191. +
  192. +#ifdef XFF_AVCODEC_FRAME_PTS
  193. + this->context->time_base.num = 1;
  194. + this->context->time_base.den = 90000 << 8;
  195. +#endif
  196. }
  197. #ifdef ENABLE_VAAPI
  198. @@ -1959,7 +1973,26 @@
  199. return (pts * 256) | this->pts_tag_pass;
  200. }
  201. -static int64_t ff_untag_pts (ff_video_decoder_t *this, int64_t pts) {
  202. +static int64_t ff_untag_pts (ff_video_decoder_t *this, AVFrame *av_frame) {
  203. + int64_t pts;
  204. +#if defined(XFF_AVCODEC_FRAME_PTS)
  205. + pts = (av_frame->pts != AV_NOPTS_VALUE) ? av_frame->pts : 0;
  206. +# if defined(XFF_AVCODEC_REORDERED_OPAQUE)
  207. + /* paranoia !!! */
  208. + if (pts != av_frame->reordered_opaque) {
  209. + xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
  210. + LOG_MODULE ": WARNING: frame pts %" PRId64 " != reordered_opaque %" PRId64 ".\n",
  211. + pts, av_frame->reordered_opaque);
  212. + pts = av_frame->reordered_opaque;
  213. + }
  214. + av_frame->reordered_opaque = 0;
  215. +# endif
  216. +#elif defined(XFF_AVCODEC_REORDERED_OPAQUE)
  217. + pts = av_frame->reordered_opaque;
  218. + av_frame->reordered_opaque = 0;
  219. +#else
  220. + pts = this->tagged_pts;
  221. +#endif
  222. if ((uint8_t)(pts & 0xff) == this->pts_tag_pass) {
  223. /* restore sign. */
  224. return pts >> 8;
  225. @@ -1984,7 +2017,9 @@
  226. this->avpkt->data = buf;
  227. this->avpkt->size = buf_size;
  228. this->avpkt->flags = AV_PKT_FLAG_KEY;
  229. -
  230. +# ifdef XFF_AVCODEC_FRAME_PTS
  231. + this->avpkt->pts = this->tagged_pts;
  232. +# endif
  233. # if XFF_PALETTE == 2 || XFF_PALETTE == 3
  234. if (buf && this->palette_changed) {
  235. uint8_t *sd = av_packet_new_side_data (this->avpkt, AV_PKT_DATA_PALETTE, 256 * 4);
  236. @@ -2094,9 +2129,14 @@
  237. #endif
  238. /* apply valid pts to first frame _starting_ thereafter only */
  239. - if (this->pts && !this->context->reordered_opaque) {
  240. - this->context->reordered_opaque =
  241. - this->av_frame->reordered_opaque = ff_tag_pts (this, this->pts);
  242. + if (this->pts && !this->tagged_pts) {
  243. + this->tagged_pts = ff_tag_pts (this, this->pts);
  244. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  245. + this->context->reordered_opaque = this->av_frame->reordered_opaque = this->tagged_pts;
  246. +#endif
  247. +#ifdef XFF_AVCODEC_FRAME_PTS
  248. + this->av_frame->pts = this->tagged_pts;
  249. +#endif
  250. this->pts = 0;
  251. }
  252. @@ -2207,9 +2247,11 @@
  253. img->top_field_first = this->av_frame->top_field_first;
  254. /* get back reordered pts */
  255. - img->pts = ff_untag_pts (this, this->av_frame->reordered_opaque);
  256. - this->av_frame->reordered_opaque = 0;
  257. + img->pts = ff_untag_pts (this, this->av_frame);
  258. + this->tagged_pts = 0;
  259. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  260. this->context->reordered_opaque = 0;
  261. +#endif
  262. if (this->av_frame->repeat_pict)
  263. img->duration = this->video_step * 3 / 2;
  264. @@ -2330,9 +2372,14 @@
  265. }
  266. if (this->size == 0) {
  267. + this->tagged_pts = ff_tag_pts (this, this->pts);
  268. /* take over pts when we are about to buffer a frame */
  269. - this->av_frame->reordered_opaque = ff_tag_pts(this, this->pts);
  270. - this->context->reordered_opaque = ff_tag_pts(this, this->pts);
  271. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  272. + this->av_frame->reordered_opaque = this->context->reordered_opaque = this->tagged_pts;
  273. +#endif
  274. +#ifdef XFF_AVCODEC_FRAME_PTS
  275. + this->av_frame->pts = this->tagged_pts;
  276. +#endif
  277. this->pts = 0;
  278. }
  279. @@ -2405,7 +2452,10 @@
  280. need_unref = 1;
  281. #endif
  282. /* reset consumed pts value */
  283. - this->context->reordered_opaque = ff_tag_pts(this, 0);
  284. + this->tagged_pts = ff_tag_pts (this, 0);
  285. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  286. + this->context->reordered_opaque = this->tagged_pts;
  287. +#endif
  288. if (err) {
  289. @@ -2439,10 +2489,14 @@
  290. ff_check_bufsize(this, this->size);
  291. memmove (this->buf, &chunk_buf[offset], this->size);
  292. chunk_buf = this->buf;
  293. -
  294. /* take over pts for next access unit */
  295. - this->av_frame->reordered_opaque = ff_tag_pts(this, this->pts);
  296. - this->context->reordered_opaque = ff_tag_pts(this, this->pts);
  297. + this->tagged_pts = ff_tag_pts (this, this->pts);
  298. +#ifdef XFF_AVCODEC_REORDERED_OPAQUE
  299. + this->av_frame->reordered_opaque = this->context->reordered_opaque = this->tagged_pts;
  300. +#endif
  301. +#ifdef XFF_AVCODEC_FRAME_PTS
  302. + this->av_frame->pts = this->tagged_pts;
  303. +#endif
  304. this->pts = 0;
  305. }
  306. }
  307. @@ -2559,8 +2613,7 @@
  308. ff_convert_frame(this, img, this->av_frame);
  309. }
  310. - img->pts = ff_untag_pts(this, this->av_frame->reordered_opaque);
  311. - this->av_frame->reordered_opaque = 0;
  312. + img->pts = ff_untag_pts(this, this->av_frame);
  313. /* workaround for weird 120fps streams */
  314. if( video_step_to_use == 750 ) {
  315. @@ -2600,8 +2653,7 @@
  316. this->output_format,
  317. VO_BOTH_FIELDS|this->frame_flags);
  318. /* set PTS to allow early syncing */
  319. - img->pts = ff_untag_pts(this, this->av_frame->reordered_opaque);
  320. - this->av_frame->reordered_opaque = 0;
  321. + img->pts = ff_untag_pts(this, this->av_frame);
  322. img->duration = video_step_to_use;
  323. @@ -2783,7 +2835,7 @@
  324. ff_convert_frame (this, img, this->av_frame2);
  325. }
  326. - img->pts = ff_untag_pts (this, this->av_frame2->reordered_opaque);
  327. + img->pts = ff_untag_pts (this, this->av_frame2);
  328. if (video_step_to_use == 750)
  329. video_step_to_use = 0;
  330. @@ -2903,7 +2955,9 @@
  331. if (this->decoder_ok) {
  332. pthread_mutex_lock(&ffmpeg_lock);
  333. - avcodec_close (this->context);
  334. + _x_freep (&this->context->extradata);
  335. + this->context->extradata_size = 0;
  336. + XFF_FREE_CONTEXT (this->context);
  337. pthread_mutex_unlock(&ffmpeg_lock);
  338. #ifdef ENABLE_DIRECT_RENDERING
  339. @@ -2912,16 +2966,15 @@
  340. this->stream->video_out->close(this->stream->video_out, this->stream);
  341. this->decoder_ok = 0;
  342. + } else if (this->context) {
  343. + _x_freep (&this->context->extradata);
  344. + this->context->extradata_size = 0;
  345. + XFF_FREE_CONTEXT (this->context);
  346. }
  347. if (this->slice_offset_table)
  348. free (this->slice_offset_table);
  349. - if (this->context) {
  350. - _x_freep (&this->context->extradata);
  351. - this->context->extradata_size = 0;
  352. - XFF_FREE_CONTEXT (this->context);
  353. - }
  354. #if XFF_VIDEO > 1
  355. XFF_PACKET_UNREF (this->avpkt);
  356. diff -r d1954d852980 -r 1e7b18400886 src/combined/ffmpeg/ffmpeg_compat.h
  357. --- a/src/combined/ffmpeg/ffmpeg_compat.h Mon Apr 08 13:25:10 2024 +0200
  358. +++ b/src/combined/ffmpeg/ffmpeg_compat.h Mon May 06 21:55:55 2024 +0200
  359. @@ -1,5 +1,5 @@
  360. /*
  361. - * Copyright (C) 2000-2022 the xine project
  362. + * Copyright (C) 2000-2024 the xine project
  363. *
  364. * This file is part of xine, a unix video player.
  365. *
  366. @@ -54,9 +54,16 @@
  367. #endif
  368. /* reordered_opaque appeared in libavcodec 51.68.0 */
  369. -#define XFF_AVCODEC_REORDERED_OPAQUE
  370. -#if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(51,68,0)
  371. -# undef XFF_AVCODEC_REORDERED_OPAQUE
  372. +#if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(51,68,0) && LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(60,0,0)
  373. +# define XFF_AVCODEC_REORDERED_OPAQUE
  374. +#else
  375. +# undef XFF_AVCODEC_REORDERED_OPAQUE
  376. +#endif
  377. +
  378. +#if LIBAVCODEC_VERSION_INT >= XFF_INT_VERSION(58,33,100)
  379. +# define XFF_AVCODEC_FRAME_PTS
  380. +#else
  381. +# undef XFF_AVCODEC_FRAME_PTS
  382. #endif
  383. /* colorspace and color_range were added before 52.29.0 */
  384. @@ -210,9 +217,11 @@
  385. #endif
  386. #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(55,63,100)
  387. -# define XFF_FREE_CONTEXT(pp) do {av_free(pp); pp = NULL;} while (0)
  388. +# define XFF_FREE_CONTEXT(pp) do {if (pp) avcodec_close (pp); av_free (pp); pp = NULL;} while (0)
  389. +#elif LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(58,33,100)
  390. +# define XFF_FREE_CONTEXT(pp) do {if (pp) avcodec_close (pp); avcodec_free_context (&(pp));} while (0)
  391. #else
  392. -# define XFF_FREE_CONTEXT(pp) avcodec_free_context(&(pp))
  393. +# define XFF_FREE_CONTEXT(pp) avcodec_free_context (&(pp))
  394. #endif
  395. #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(54,59,100)
  396. @@ -303,4 +312,3 @@
  397. #endif /* defined(LIBAVCODEC_VERSION_INT) */
  398. #endif /* XINE_AVCODEC_COMPAT_H */
  399. -
  400. diff -r d1954d852980 -r 1e7b18400886 src/dxr3/ffmpeg_encoder.c
  401. --- a/src/dxr3/ffmpeg_encoder.c Mon Apr 08 13:25:10 2024 +0200
  402. +++ b/src/dxr3/ffmpeg_encoder.c Mon May 06 21:55:55 2024 +0200
  403. @@ -1,5 +1,5 @@
  404. /*
  405. - * Copyright (C) 2000-2022 the xine project
  406. + * Copyright (C) 2000-2024 the xine project
  407. *
  408. * This file is part of xine, a unix video player.
  409. *
  410. @@ -127,10 +127,8 @@
  411. unsigned char use_quantizer;
  412. if (this->context) {
  413. - avcodec_close(this->context);
  414. - free(this->context);
  415. + XFF_FREE_CONTEXT (this->context);
  416. free(this->picture);
  417. - this->context = NULL;
  418. this->picture = NULL;
  419. }
  420. @@ -344,10 +342,8 @@
  421. #if XFF_ENCVIDEO > 1
  422. XFF_PACKET_UNREF (this->pkt);
  423. #endif
  424. - avcodec_close(this->context);
  425. XFF_FREE_CONTEXT (this->context);
  426. free(this->picture);
  427. - this->context = NULL;
  428. this->picture = NULL;
  429. }
  430. return 1;