xine-lib-1.2.13-ffmpeg7-compatibility.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. # HG changeset patch
  2. # User Torsten Jager <t.jager@gmx.de>
  3. # Date 1715160885 -7200
  4. # Wed May 08 11:34:45 2024 +0200
  5. # Node ID 73b833e7fe356cd2d9490dda4ebc9bfe16fce958
  6. # Parent 1e7b184008860c8be2289c3cefd9dee57f06193a
  7. ffmpeg compatibility update 2.
  8. diff -r 1e7b18400886 -r 73b833e7fe35 src/combined/ffmpeg/ff_audio_decoder.c
  9. --- a/src/combined/ffmpeg/ff_audio_decoder.c Mon May 06 21:55:55 2024 +0200
  10. +++ b/src/combined/ffmpeg/ff_audio_decoder.c Wed May 08 11:34:45 2024 +0200
  11. @@ -1393,6 +1393,9 @@
  12. XFF_FREE_FRAME (this->av_frame);
  13. }
  14. #endif
  15. +#if 1
  16. + avcodec_flush_buffers (this->context);
  17. +#else
  18. pthread_mutex_lock (&ffmpeg_lock);
  19. {
  20. uint8_t *ed = this->context->extradata;
  21. @@ -1410,6 +1413,7 @@
  22. if (XFF_AVCODEC_OPEN (this->context, this->codec) >= 0)
  23. this->decoder_ok = 1;
  24. pthread_mutex_unlock (&ffmpeg_lock);
  25. +#endif
  26. }
  27. ff_audio_reset_parser(this);
  28. diff -r 1e7b18400886 -r 73b833e7fe35 src/combined/ffmpeg/ff_video_decoder.c
  29. --- a/src/combined/ffmpeg/ff_video_decoder.c Mon May 06 21:55:55 2024 +0200
  30. +++ b/src/combined/ffmpeg/ff_video_decoder.c Wed May 08 11:34:45 2024 +0200
  31. @@ -89,6 +89,11 @@
  32. # define ENABLE_EMMS
  33. #endif
  34. +/*
  35. +#undef XFF_AVCODEC_SLICE_TABLE
  36. +#define XFF_AVCODEC_SLICE_TABLE 1
  37. +*/
  38. +
  39. #define VIDEOBUFSIZE (128*1024)
  40. #define SLICE_BUFFER_SIZE (1194*1024)
  41. @@ -148,11 +153,11 @@
  42. int bufsize;
  43. int size;
  44. int skipframes;
  45. -
  46. +#if XFF_AVCODEC_SLICE_TABLE == 1
  47. int *slice_offset_table;
  48. int slice_offset_size;
  49. int slice_offset_pos;
  50. -
  51. +#endif
  52. AVFrame *av_frame;
  53. AVFrame *av_frame2;
  54. AVCodecContext *context;
  55. @@ -238,6 +243,13 @@
  56. #if XFF_VIDEO > 1
  57. XFF_PACKET_DECL (avpkt);
  58. #endif
  59. +
  60. +#if XFF_AVCODEC_SLICE_TABLE == 2
  61. + uint8_t *temp_buf;
  62. + uint32_t temp_size;
  63. + int slice_num;
  64. + uint8_t slice_table[1 + 256 * 8];
  65. +#endif
  66. };
  67. /* import color matrix names */
  68. @@ -1783,10 +1795,9 @@
  69. this->size += buf->size;
  70. if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
  71. - int codec_type;
  72. + uint32_t codec_type = buf->type & 0xFFFF0000;
  73. lprintf ("header complete\n");
  74. - codec_type = buf->type & 0xFFFF0000;
  75. if (buf->decoder_flags & BUF_FLAG_STDHEADER) {
  76. @@ -1912,33 +1923,44 @@
  77. #endif
  78. }
  79. else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) {
  80. - /* o dear. Multiple decoding threads use individual contexts.
  81. - av_decode_video2 () does only copy the _pointer_ to the offsets,
  82. - not the offsets themselves. So we must not overwrite anything
  83. - that another thread has not yet read. */
  84. - int i, l, total;
  85. -
  86. - lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n");
  87. - l = buf->decoder_info[2] + 1;
  88. -
  89. - total = l * this->class->thread_count;
  90. - if (total < SLICE_OFFSET_SIZE)
  91. - total = SLICE_OFFSET_SIZE;
  92. - if (total > this->slice_offset_size) {
  93. - this->slice_offset_table = realloc (this->slice_offset_table, total * sizeof (int));
  94. - this->slice_offset_size = total;
  95. - }
  96. -
  97. - if (this->slice_offset_pos + l > this->slice_offset_size)
  98. - this->slice_offset_pos = 0;
  99. - this->context->slice_offset = this->slice_offset_table + this->slice_offset_pos;
  100. - this->context->slice_count = l;
  101. -
  102. - lprintf ("slice_count=%d\n", l);
  103. - for (i = 0; i < l; i++) {
  104. - this->slice_offset_table[this->slice_offset_pos++] =
  105. - ((uint32_t *)buf->decoder_info_ptr[2])[(2 * i) + 1];
  106. - lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]);
  107. + {
  108. +#if XFF_AVCODEC_SLICE_TABLE == 1
  109. + /* o dear. Multiple decoding threads use individual contexts.
  110. + * av_decode_video2 () does only copy the _pointer_ to the offsets,
  111. + * not the offsets themselves. So we must not overwrite anything
  112. + * that another thread has not yet read. */
  113. + int i, l, total;
  114. +
  115. + lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n");
  116. + l = buf->decoder_info[2] + 1;
  117. +
  118. + total = l * this->class->thread_count;
  119. + if (total < SLICE_OFFSET_SIZE)
  120. + total = SLICE_OFFSET_SIZE;
  121. + if (total > this->slice_offset_size) {
  122. + this->slice_offset_table = realloc (this->slice_offset_table, total * sizeof (int));
  123. + this->slice_offset_size = total;
  124. + }
  125. +
  126. + if (this->slice_offset_pos + l > this->slice_offset_size)
  127. + this->slice_offset_pos = 0;
  128. + this->context->slice_offset = this->slice_offset_table + this->slice_offset_pos;
  129. + this->context->slice_count = l;
  130. +
  131. + lprintf ("slice_count=%d\n", l);
  132. + for (i = 0; i < l; i++) {
  133. + this->slice_offset_table[this->slice_offset_pos++] =
  134. + ((uint32_t *)buf->decoder_info_ptr[2])[(2 * i) + 1];
  135. + lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]);
  136. + }
  137. +#elif XFF_AVCODEC_SLICE_TABLE == 2
  138. + /* (count-1):1, 1:4, (offs[0]):4, 1:4, (offs[1]:4, ... just in front of the frame bitstream.
  139. + * reverse engineered from ffmpeg/libavcodec/rv34.c. they seem to expect no
  140. + * external use of rv decoders, and did not document this. */
  141. + this->slice_table[0] = buf->decoder_info[2];
  142. + this->slice_num = this->slice_table[0] + 1;
  143. + memcpy (this->slice_table + 1, buf->decoder_info_ptr[2], 8 * this->slice_num);
  144. +#endif
  145. }
  146. }
  147. }
  148. @@ -2004,6 +2026,7 @@
  149. static int decode_video_wrapper (ff_video_decoder_t *this,
  150. AVFrame *av_frame, int *err, void *buf, size_t buf_size) {
  151. + uint32_t tsize = 0;
  152. int len;
  153. #if ENABLE_VAAPI
  154. @@ -2013,9 +2036,32 @@
  155. }
  156. #endif /* ENABLE_VAAPI */
  157. +#if XFF_AVCODEC_SLICE_TABLE == 2
  158. + if ((this->slice_num > 0) && buf) {
  159. + uint32_t nsize;
  160. + tsize = 1 + this->slice_num * 8;
  161. + nsize = tsize + buf_size + AV_INPUT_BUFFER_PADDING_SIZE;
  162. + if (this->temp_size < nsize) {
  163. + nsize = nsize * 3 / 2;
  164. + free (this->temp_buf);
  165. + this->temp_buf = malloc (nsize);
  166. + if (!this->temp_buf)
  167. + nsize = 0;
  168. + this->temp_size = nsize;
  169. + nsize = tsize + buf_size + AV_INPUT_BUFFER_PADDING_SIZE;
  170. + }
  171. + if (this->temp_size >= nsize) {
  172. + memcpy (this->temp_buf, this->slice_table, tsize);
  173. + memcpy (this->temp_buf + tsize, buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
  174. + buf = this->temp_buf;
  175. + }
  176. + this->slice_num = 0;
  177. + }
  178. +#endif
  179. +
  180. #if XFF_VIDEO > 1
  181. this->avpkt->data = buf;
  182. - this->avpkt->size = buf_size;
  183. + this->avpkt->size = buf_size + tsize;
  184. this->avpkt->flags = AV_PKT_FLAG_KEY;
  185. # ifdef XFF_AVCODEC_FRAME_PTS
  186. this->avpkt->pts = this->tagged_pts;
  187. @@ -2486,7 +2532,6 @@
  188. this->size -= len;
  189. if (this->size > 0) {
  190. - ff_check_bufsize(this, this->size);
  191. memmove (this->buf, &chunk_buf[offset], this->size);
  192. chunk_buf = this->buf;
  193. /* take over pts for next access unit */
  194. @@ -2615,8 +2660,8 @@
  195. img->pts = ff_untag_pts(this, this->av_frame);
  196. - /* workaround for weird 120fps streams */
  197. - if( video_step_to_use == 750 ) {
  198. + /* workaround for weird 120fps streams, as well as some rv20 with frame duration 3pts. */
  199. + if (video_step_to_use <= 750) {
  200. /* fallback to the VIDEO_PTS_MODE */
  201. video_step_to_use = 0;
  202. }
  203. @@ -2837,7 +2882,7 @@
  204. img->pts = ff_untag_pts (this, this->av_frame2);
  205. - if (video_step_to_use == 750)
  206. + if (video_step_to_use <= 750)
  207. video_step_to_use = 0;
  208. img->duration = this->av_frame2->repeat_pict ? video_step_to_use * 3 / 2 : video_step_to_use;
  209. img->progressive_frame = !this->av_frame2->interlaced_frame;
  210. @@ -2941,6 +2986,9 @@
  211. mpeg_parser_reset(this->mpeg_parser);
  212. /* this->pts_tag_pass = 0; */
  213. +#if XFF_AVCODEC_SLICE_TABLE == 2
  214. + this->slice_num = 0;
  215. +#endif
  216. }
  217. static void ff_dispose (video_decoder_t *this_gen) {
  218. @@ -2953,12 +3001,15 @@
  219. rgb2yuy2_free (this->rgb2yuy2);
  220. if (this->decoder_ok) {
  221. + uint8_t *ed;
  222. pthread_mutex_lock(&ffmpeg_lock);
  223. - _x_freep (&this->context->extradata);
  224. + ed = this->context->extradata;
  225. + this->context->extradata = NULL;
  226. this->context->extradata_size = 0;
  227. XFF_FREE_CONTEXT (this->context);
  228. pthread_mutex_unlock(&ffmpeg_lock);
  229. + _x_freep (&ed);
  230. #ifdef ENABLE_DIRECT_RENDERING
  231. ff_free_dr1_frames (this, 1);
  232. @@ -2972,9 +3023,11 @@
  233. XFF_FREE_CONTEXT (this->context);
  234. }
  235. - if (this->slice_offset_table)
  236. - free (this->slice_offset_table);
  237. -
  238. +#if XFF_AVCODEC_SLICE_TABLE == 1
  239. + free (this->slice_offset_table);
  240. +#elif XFF_AVCODEC_SLICE_TABLE == 2
  241. + free (this->temp_buf);
  242. +#endif
  243. #if XFF_VIDEO > 1
  244. XFF_PACKET_UNREF (this->avpkt);
  245. @@ -3062,21 +3115,25 @@
  246. this->decoder_ok = 0;
  247. this->aspect_ratio = 0;
  248. this->pts_tag_pass = 0;
  249. -#ifdef HAVE_POSTPROC
  250. +# ifdef HAVE_POSTPROC
  251. this->pp_quality = 0;
  252. this->our_context = NULL;
  253. this->our_mode = NULL;
  254. -#endif
  255. +# endif
  256. this->mpeg_parser = NULL;
  257. this->set_stream_info = 0;
  258. this->rgb2yuy2 = NULL;
  259. -#ifdef ENABLE_VAAPI
  260. +# ifdef ENABLE_VAAPI
  261. this->accel = NULL;
  262. this->accel_img = NULL;
  263. -#endif
  264. -#if XFF_VIDEO == 3
  265. +# endif
  266. +# if XFF_VIDEO == 3
  267. this->flush_packet_sent = 0;
  268. -#endif
  269. +# endif
  270. +# if XFF_AVCODEC_SLICE_TABLE == 2
  271. + this->temp_size = 0;
  272. + this->temp_buf = NULL;
  273. +# endif
  274. #endif
  275. this->video_decoder.decode_data = ff_decode_data;
  276. diff -r 1e7b18400886 -r 73b833e7fe35 src/combined/ffmpeg/ffmpeg_compat.h
  277. --- a/src/combined/ffmpeg/ffmpeg_compat.h Mon May 06 21:55:55 2024 +0200
  278. +++ b/src/combined/ffmpeg/ffmpeg_compat.h Wed May 08 11:34:45 2024 +0200
  279. @@ -139,6 +139,14 @@
  280. # define XFF_PALETTE 3
  281. #endif
  282. +#if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(59,42,100)
  283. +/* AVCodecContext.slice_{offset,count} */
  284. +# define XFF_AVCODEC_SLICE_TABLE 1
  285. +#else
  286. +/* inline offset table before the frame. */
  287. +# define XFF_AVCODEC_SLICE_TABLE 2
  288. +#endif
  289. +
  290. #if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(59,0,100) /** << revise this */
  291. # define XFF_VAAPI 1 /** << libavcodec/vaapi.h */
  292. #else