Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.68 KB | None | 0 0
  1. From dc5f7f4f60a1caaff14133bbfedf076813f45a43 Mon Sep 17 00:00:00 2001
  2. From: Anton Mitrofanov <BugMaster@narod.ru>
  3. Date: Thu, 17 Aug 2017 23:46:23 +0300
  4. Subject: [PATCH 1/7] flv: Split FrameType and CodecID values
  5.  
  6. ---
  7. output/flv.c | 4 ++--
  8. output/flv_bytestream.h | 4 ++--
  9. 2 files changed, 4 insertions(+), 4 deletions(-)
  10.  
  11. diff --git a/output/flv.c b/output/flv.c
  12. index 63ecbddc..8c127128 100644
  13. --- a/output/flv.c
  14. +++ b/output/flv.c
  15. @@ -199,7 +199,7 @@ static int write_headers( hnd_t handle, x264_nal_t *p_nal )
  16. flv_put_be24( c, 0 ); // StreamID - Always 0
  17. p_flv->start = c->d_cur; // needed for overwriting length
  18.  
  19. - flv_put_byte( c, 7 | FLV_FRAME_KEY ); // Frametype and CodecID
  20. + flv_put_byte( c, FLV_FRAME_KEY | FLV_CODECID_H264 ); // FrameType and CodecID
  21. flv_put_byte( c, 0 ); // AVC sequence header
  22. flv_put_be24( c, 0 ); // composition time
  23.  
  24. @@ -282,7 +282,7 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  25. flv_put_be24( c, 0 );
  26.  
  27. p_flv->start = c->d_cur;
  28. - flv_put_byte( c, p_picture->b_keyframe ? FLV_FRAME_KEY : FLV_FRAME_INTER );
  29. + flv_put_byte( c, (p_picture->b_keyframe ? FLV_FRAME_KEY : FLV_FRAME_INTER) | FLV_CODECID_H264 );
  30. flv_put_byte( c, 1 ); // AVC NALU
  31. flv_put_be24( c, offset );
  32.  
  33. diff --git a/output/flv_bytestream.h b/output/flv_bytestream.h
  34. index 5da56960..d3f89ca4 100644
  35. --- a/output/flv_bytestream.h
  36. +++ b/output/flv_bytestream.h
  37. @@ -92,8 +92,8 @@ enum
  38.  
  39. enum
  40. {
  41. - FLV_FRAME_KEY = 1 << FLV_VIDEO_FRAMETYPE_OFFSET | 7,
  42. - FLV_FRAME_INTER = 2 << FLV_VIDEO_FRAMETYPE_OFFSET | 7,
  43. + FLV_FRAME_KEY = 1 << FLV_VIDEO_FRAMETYPE_OFFSET,
  44. + FLV_FRAME_INTER = 2 << FLV_VIDEO_FRAMETYPE_OFFSET,
  45. };
  46.  
  47. typedef enum
  48. --
  49. 2.13.0.windows.1
  50.  
  51.  
  52. From 2ac159b201e4500732e13fcae293bc5bc7d23882 Mon Sep 17 00:00:00 2001
  53. From: Anton Mitrofanov <BugMaster@narod.ru>
  54. Date: Thu, 17 Aug 2017 23:51:14 +0300
  55. Subject: [PATCH 2/7] flv: Fix one frame video total duration
  56.  
  57. ---
  58. output/flv.c | 7 ++++++-
  59. 1 file changed, 6 insertions(+), 1 deletion(-)
  60.  
  61. diff --git a/output/flv.c b/output/flv.c
  62. index 8c127128..b7827f99 100644
  63. --- a/output/flv.c
  64. +++ b/output/flv.c
  65. @@ -325,7 +325,12 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest
  66.  
  67. CHECK( flv_flush_data( c ) );
  68.  
  69. - double total_duration = (2 * largest_pts - second_largest_pts) * p_flv->d_timebase;
  70. + double total_duration;
  71. + /* duration algorithm fails with one frame */
  72. + if( p_flv->i_framenum == 1 )
  73. + total_duration = p_flv->i_fps_num ? (double)p_flv->i_fps_den / p_flv->i_fps_num : 0;
  74. + else
  75. + total_duration = (2 * largest_pts - second_largest_pts) * p_flv->d_timebase;
  76.  
  77. if( x264_is_regular_file( c->fp ) && total_duration > 0 )
  78. {
  79. --
  80. 2.13.0.windows.1
  81.  
  82.  
  83. From 131f30940b970b3c3b642a194ca0ebd04e96d1fd Mon Sep 17 00:00:00 2001
  84. From: Anton Mitrofanov <BugMaster@narod.ru>
  85. Date: Fri, 22 Sep 2017 16:20:15 +0300
  86. Subject: [PATCH 3/7] Fix compilation with mp4 output (gpac)
  87.  
  88. ---
  89. input/input.h | 5 -----
  90. output/flv.c | 1 -
  91. output/flv_bytestream.c | 1 -
  92. output/matroska_ebml.c | 1 -
  93. output/mp4_lsmash.c | 1 -
  94. output/raw.c | 1 -
  95. x264.c | 1 -
  96. x264cli.h | 1 +
  97. 8 files changed, 1 insertion(+), 11 deletions(-)
  98.  
  99. diff --git a/input/input.h b/input/input.h
  100. index 816ee32c..3b33be4a 100644
  101. --- a/input/input.h
  102. +++ b/input/input.h
  103. @@ -28,13 +28,8 @@
  104. #ifndef X264_INPUT_H
  105. #define X264_INPUT_H
  106.  
  107. -#include <stdio.h>
  108. -
  109. -#include "config.h"
  110. #include "x264cli.h"
  111.  
  112. -#include "common/osdep.h"
  113. -
  114. #ifdef _WIN32
  115. #include <windows.h>
  116. #endif
  117. diff --git a/output/flv.c b/output/flv.c
  118. index b7827f99..606842fb 100644
  119. --- a/output/flv.c
  120. +++ b/output/flv.c
  121. @@ -27,7 +27,6 @@
  122.  
  123. #include "output.h"
  124. #include "flv_bytestream.h"
  125. -#include "common/osdep.h"
  126.  
  127. #define CHECK(x)\
  128. do {\
  129. diff --git a/output/flv_bytestream.c b/output/flv_bytestream.c
  130. index c18f38c1..b57a63ca 100644
  131. --- a/output/flv_bytestream.c
  132. +++ b/output/flv_bytestream.c
  133. @@ -25,7 +25,6 @@
  134.  
  135. #include "output.h"
  136. #include "flv_bytestream.h"
  137. -#include "common/osdep.h"
  138.  
  139. uint64_t flv_dbl2int( double value )
  140. {
  141. diff --git a/output/matroska_ebml.c b/output/matroska_ebml.c
  142. index 0fb47ca0..ef246cbf 100644
  143. --- a/output/matroska_ebml.c
  144. +++ b/output/matroska_ebml.c
  145. @@ -27,7 +27,6 @@
  146.  
  147. #include "output.h"
  148. #include "matroska_ebml.h"
  149. -#include "common/osdep.h"
  150.  
  151. #define CLSIZE 1048576
  152. #define CHECK(x)\
  153. diff --git a/output/mp4_lsmash.c b/output/mp4_lsmash.c
  154. index b8af7a35..30bded00 100644
  155. --- a/output/mp4_lsmash.c
  156. +++ b/output/mp4_lsmash.c
  157. @@ -29,7 +29,6 @@
  158.  
  159. #include "output.h"
  160. #include <lsmash.h>
  161. -#include "common/osdep.h"
  162.  
  163. #define H264_NALU_LENGTH_SIZE 4
  164.  
  165. diff --git a/output/raw.c b/output/raw.c
  166. index 02bfc201..47e33539 100644
  167. --- a/output/raw.c
  168. +++ b/output/raw.c
  169. @@ -25,7 +25,6 @@
  170. *****************************************************************************/
  171.  
  172. #include "output.h"
  173. -#include "common/osdep.h"
  174.  
  175. static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt )
  176. {
  177. diff --git a/x264.c b/x264.c
  178. index 90e0a0b7..06d15897 100644
  179. --- a/x264.c
  180. +++ b/x264.c
  181. @@ -44,7 +44,6 @@
  182. #include "output/output.h"
  183. #include "filters/filters.h"
  184. #include "common/cpu.h"
  185. -#include "common/osdep.h"
  186. #include "common/mathematics.h"
  187.  
  188. #define MAX_BIT_DEPTH 10
  189. diff --git a/x264cli.h b/x264cli.h
  190. index 6ae500e2..0920d7b4 100644
  191. --- a/x264cli.h
  192. +++ b/x264cli.h
  193. @@ -31,6 +31,7 @@
  194. #include <stdlib.h>
  195. #include <string.h>
  196. #include "x264.h"
  197. +#include "common/osdep.h"
  198.  
  199. /* In microseconds */
  200. #define UPDATE_INTERVAL 250000
  201. --
  202. 2.13.0.windows.1
  203.  
  204.  
  205. From a0c87fcd2b10dc3aac864e97b052ae1ce3e7d9d3 Mon Sep 17 00:00:00 2001
  206. From: Anton Mitrofanov <BugMaster@narod.ru>
  207. Date: Fri, 22 Sep 2017 16:59:13 +0300
  208. Subject: [PATCH 4/7] configure: Improvements
  209.  
  210. Log result of pkg-config checks to config.log.
  211. Fix lavf support detection for pkg-config fallback case.
  212. Fix detection of linking dependencies errors for lavf/lsmash/gpac.
  213. Cosmetics.
  214. ---
  215. configure | 48 +++++++++++++++++++++++++++++++++---------------
  216. 1 file changed, 33 insertions(+), 15 deletions(-)
  217.  
  218. diff --git a/configure b/configure
  219. index de809f12..dc32a3f3 100755
  220. --- a/configure
  221. +++ b/configure
  222. @@ -253,6 +253,24 @@ rc_check() {
  223. return $res
  224. }
  225.  
  226. +pkg_check() {
  227. + log_check "for packages: $1"
  228. + pkg_cmd="$PKGCONFIG --exists $1"
  229. + if $pkg_cmd >conftest.log 2>&1; then
  230. + res=$?
  231. + log_ok
  232. + else
  233. + res=$?
  234. + log_fail
  235. + log_msg "Failed commandline was:"
  236. + log_msg "--------------------------------------------------"
  237. + log_msg "$pkg_cmd"
  238. + cat conftest.log >> config.log
  239. + log_msg "--------------------------------------------------"
  240. + fi
  241. + return $res
  242. +}
  243. +
  244. define() {
  245. echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
  246. }
  247. @@ -978,7 +996,7 @@ fi
  248.  
  249. if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then
  250. [ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static"
  251. - if $PKGCONFIG --exists x264 2>/dev/null; then
  252. + if pkg_check x264 ; then
  253. X264_LIBS="$($PKGCONFIG --libs x264)"
  254. X264_INCLUDE_DIR="${X264_INCLUDE_DIR-$($PKGCONFIG --variable=includedir x264)}"
  255. configure_system_override "$X264_INCLUDE_DIR" || die "Detection of system libx264 configuration failed"
  256. @@ -1040,7 +1058,7 @@ if [ "$thread" = "posix" ]; then
  257. fi
  258. [ "$thread" != "no" ] && define HAVE_THREAD
  259.  
  260. -if cc_check "math.h" "-Werror" "return log2f(2);" ; then
  261. +if cc_check 'math.h' '' 'log2f(2);' ; then
  262. define HAVE_LOG2F
  263. fi
  264.  
  265. @@ -1068,7 +1086,7 @@ fi
  266.  
  267. if [ "$swscale" = "auto" ] ; then
  268. swscale="no"
  269. - if $PKGCONFIG --exists libswscale 2>/dev/null; then
  270. + if pkg_check 'libswscale libavutil' ; then
  271. SWSCALE_LIBS="$SWSCALE_LIBS $($PKGCONFIG --libs libswscale libavutil)"
  272. SWSCALE_CFLAGS="$SWSCALE_CFLAGS $($PKGCONFIG --cflags libswscale libavutil)"
  273. fi
  274. @@ -1085,18 +1103,18 @@ fi
  275.  
  276. if [ "$lavf" = "auto" ] ; then
  277. lavf="no"
  278. - if $PKGCONFIG --exists libavformat libavcodec libswscale 2>/dev/null; then
  279. - LAVF_LIBS="$LAVF_LIBS $($PKGCONFIG --libs libavformat libavcodec libavutil libswscale)"
  280. - LAVF_CFLAGS="$LAVF_CFLAGS $($PKGCONFIG --cflags libavformat libavcodec libavutil libswscale)"
  281. + if pkg_check 'libavformat libavcodec libavutil' ; then
  282. + LAVF_LIBS="$LAVF_LIBS $($PKGCONFIG --libs libavformat libavcodec libavutil)"
  283. + LAVF_CFLAGS="$LAVF_CFLAGS $($PKGCONFIG --cflags libavformat libavcodec libavutil)"
  284. fi
  285. - if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
  286. + if [ -z "$LAVF_LIBS" ] && cc_check '' -lavformat ; then
  287. LAVF_LIBS="-lavformat"
  288. - for lib in -lpostproc -lavcodec -lswscale -lavutil -lm -lz -lbz2 $libpthread -lavifil32 -lws2_32; do
  289. + for lib in -lavcodec -lavresample -lswresample -lavutil -lbz2 -lz $libpthread -lole32 -luser32 -lws2_32 -lsecur32 ; do
  290. cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
  291. done
  292. fi
  293. - LAVF_LIBS="-L. $LAVF_LIBS"
  294. - if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "av_frame_free(0);" ; then
  295. +
  296. + if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "av_register_all();" ; then
  297. if [ "$swscale" = "yes" ]; then
  298. lavf="yes"
  299. else
  300. @@ -1109,7 +1127,7 @@ if [ "$ffms" = "auto" ] ; then
  301. ffms_major="2"; ffms_minor="21"; ffms_micro="0"; ffms_bump="0"
  302. ffms="no"
  303.  
  304. - if $PKGCONFIG --exists ffms2 2>/dev/null; then
  305. + if pkg_check ffms2 ; then
  306. FFMS2_LIBS="$FFMS2_LIBS $($PKGCONFIG --libs ffms2)"
  307. FFMS2_CFLAGS="$FFMS2_CFLAGS $($PKGCONFIG --cflags ffms2)"
  308. fi
  309. @@ -1151,13 +1169,13 @@ fi
  310.  
  311. if [ "$lsmash" = "auto" ] ; then
  312. lsmash="no"
  313. - if $PKGCONFIG --exists liblsmash 2>/dev/null; then
  314. + if pkg_check liblsmash ; then
  315. LSMASH_LIBS="$LSMASH_LIBS $($PKGCONFIG --libs liblsmash)"
  316. LSMASH_CFLAGS="$LSMASH_CFLAGS $($PKGCONFIG --cflags liblsmash)"
  317. fi
  318. [ -z "$LSMASH_LIBS" ] && LSMASH_LIBS="-llsmash"
  319.  
  320. - if cc_check lsmash.h "$LSMASH_CFLAGS $LSMASH_LIBS" ; then
  321. + if cc_check lsmash.h "$LSMASH_CFLAGS $LSMASH_LIBS" "lsmash_destroy_root(0);" ; then
  322. if cpp_check lsmash.h "$LSMASH_CFLAGS" "LSMASH_VERSION_MAJOR > 1 || (LSMASH_VERSION_MAJOR == 1 && LSMASH_VERSION_MINOR >= 5)" ; then
  323. lsmash="yes"
  324. else
  325. @@ -1174,7 +1192,7 @@ if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then
  326. cc_check "" -lws2_32 && GPAC_LIBS="$GPAC_LIBS -lws2_32"
  327. cc_check "" -lwinmm && GPAC_LIBS="$GPAC_LIBS -lwinmm"
  328. fi
  329. - if cc_check gpac/isomedia.h "$GPAC_LIBS" ; then
  330. + if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_close(0);" ; then
  331. if cc_check gpac/isomedia.h "$GPAC_LIBS" "gf_isom_set_pixel_aspect_ratio(0,0,0,0,0);" ; then
  332. gpac="yes"
  333. else
  334. @@ -1190,8 +1208,8 @@ if [ "$lsmash" = "yes" ] ; then
  335. define HAVE_LSMASH
  336. elif [ "$gpac" = "yes" ] ; then
  337. mp4="gpac"
  338. - define HAVE_GPAC
  339. LDFLAGSCLI="$GPAC_LIBS $LDFLAGSCLI"
  340. + define HAVE_GPAC
  341. fi
  342.  
  343. if [ "$avs" = "auto" ] ; then
  344. --
  345. 2.13.0.windows.1
  346.  
  347.  
  348. From 8a3f8a1cffde234fd474addfcbd2edc646733bc6 Mon Sep 17 00:00:00 2001
  349. From: Anton Mitrofanov <BugMaster@narod.ru>
  350. Date: Fri, 22 Sep 2017 17:05:06 +0300
  351. Subject: [PATCH 5/7] Fix thread safety of x264_threading_init() and use of
  352. X264_PTHREAD_MUTEX_INITIALIZER with win32thread
  353.  
  354. ---
  355. common/osdep.c | 22 ++++++++++++++++++----
  356. common/threadpool.c | 3 +++
  357. common/win32thread.c | 10 +++++++++-
  358. 3 files changed, 30 insertions(+), 5 deletions(-)
  359.  
  360. diff --git a/common/osdep.c b/common/osdep.c
  361. index e5615dcf..42b5aaa9 100644
  362. --- a/common/osdep.c
  363. +++ b/common/osdep.c
  364. @@ -72,11 +72,8 @@ static void threading_destroy( void )
  365. #endif
  366. }
  367.  
  368. -int x264_threading_init( void )
  369. +static int threading_init( void )
  370. {
  371. - /* if already init, then do nothing */
  372. - if( InterlockedCompareExchange( &x264_threading_is_init, 1, 0 ) )
  373. - return 0;
  374. #if PTW32_STATIC_LIB
  375. /* if static pthread-win32 is already initialized, then do nothing */
  376. if( ptw32_processInitialized )
  377. @@ -89,7 +86,24 @@ int x264_threading_init( void )
  378. #endif
  379. /* register cleanup to run at process termination */
  380. atexit( threading_destroy );
  381. + return 0;
  382. +}
  383.  
  384. +int x264_threading_init( void )
  385. +{
  386. + LONG state;
  387. + while( (state = InterlockedCompareExchange( &x264_threading_is_init, -1, 0 )) != 0 )
  388. + {
  389. + /* if already init, then do nothing */
  390. + if( state > 0 )
  391. + return 0;
  392. + }
  393. + if( threading_init() < 0 )
  394. + {
  395. + InterlockedExchange( &x264_threading_is_init, 0 );
  396. + return -1;
  397. + }
  398. + InterlockedExchange( &x264_threading_is_init, 1 );
  399. return 0;
  400. }
  401. #endif
  402. diff --git a/common/threadpool.c b/common/threadpool.c
  403. index 61d75ce0..f707cfdd 100644
  404. --- a/common/threadpool.c
  405. +++ b/common/threadpool.c
  406. @@ -78,6 +78,9 @@ int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
  407. if( threads <= 0 )
  408. return -1;
  409.  
  410. + if( x264_threading_init() < 0 )
  411. + return -1;
  412. +
  413. x264_threadpool_t *pool;
  414. CHECKED_MALLOCZERO( pool, sizeof(x264_threadpool_t) );
  415. *p_pool = pool;
  416. diff --git a/common/win32thread.c b/common/win32thread.c
  417. index 8f878d94..76940d3f 100644
  418. --- a/common/win32thread.c
  419. +++ b/common/win32thread.c
  420. @@ -95,7 +95,15 @@ int x264_pthread_mutex_lock( x264_pthread_mutex_t *mutex )
  421. {
  422. static const x264_pthread_mutex_t init = X264_PTHREAD_MUTEX_INITIALIZER;
  423. if( !memcmp( mutex, &init, sizeof(x264_pthread_mutex_t) ) )
  424. - *mutex = static_mutex;
  425. + {
  426. + int ret = 0;
  427. + EnterCriticalSection( &static_mutex );
  428. + if( !memcmp( mutex, &init, sizeof(x264_pthread_mutex_t) ) )
  429. + ret = x264_pthread_mutex_init( mutex, NULL );
  430. + LeaveCriticalSection( &static_mutex );
  431. + if( ret )
  432. + return ret;
  433. + }
  434. EnterCriticalSection( mutex );
  435. return 0;
  436. }
  437. --
  438. 2.13.0.windows.1
  439.  
  440.  
  441. From e907e2ffc2fbc3907c6ac842ccf9fa33334f1af1 Mon Sep 17 00:00:00 2001
  442. From: Anton Mitrofanov <BugMaster@narod.ru>
  443. Date: Fri, 22 Sep 2017 17:18:55 +0300
  444. Subject: [PATCH 6/7] Make ref and i4x4_mode costs global instead of static
  445.  
  446. Fixes some thread safety doubts and makes code cleaner.
  447. Downside: slightly higher memory usage when calling multiple encoders from the same application.
  448. ---
  449. common/common.h | 7 ++++++-
  450. encoder/analyse.c | 16 +++++-----------
  451. encoder/encoder.c | 2 ++
  452. 3 files changed, 13 insertions(+), 12 deletions(-)
  453.  
  454. diff --git a/common/common.h b/common/common.h
  455. index 279babf1..32485b56 100644
  456. --- a/common/common.h
  457. +++ b/common/common.h
  458. @@ -501,9 +501,14 @@ struct x264_t
  459. udctcoef (*quant8_bias0[4])[64]; /* [4][QP_MAX_SPEC+1][64] */
  460. udctcoef (*nr_offset_emergency)[4][64];
  461.  
  462. - /* mv/ref cost arrays. */
  463. + /* mv/ref/mode cost arrays. */
  464. uint16_t *cost_mv[QP_MAX+1];
  465. uint16_t *cost_mv_fpel[QP_MAX+1][4];
  466. + struct
  467. + {
  468. + uint16_t ref[QP_MAX+1][3][33];
  469. + ALIGNED_64( uint16_t i4x4_mode[(QP_MAX+2)*32] );
  470. + } *cost_table;
  471.  
  472. const uint8_t *chroma_qp_table; /* includes both the nonlinear luma->chroma mapping and chroma_qp_offset */
  473.  
  474. diff --git a/encoder/analyse.c b/encoder/analyse.c
  475. index 2e9ad6b8..d077a75c 100644
  476. --- a/encoder/analyse.c
  477. +++ b/encoder/analyse.c
  478. @@ -191,10 +191,6 @@ static const uint8_t i_sub_mb_p_cost_table[4] =
  479.  
  480. static void analyse_update_cache( x264_t *h, x264_mb_analysis_t *a );
  481.  
  482. -static uint16_t x264_cost_ref[QP_MAX+1][3][33];
  483. -static UNUSED x264_pthread_mutex_t cost_ref_mutex = X264_PTHREAD_MUTEX_INITIALIZER;
  484. -static uint16_t x264_cost_i4x4_mode[(QP_MAX+2)*32];
  485. -
  486. static int init_costs( x264_t *h, float *logs, int qp )
  487. {
  488. if( h->cost_mv[qp] )
  489. @@ -210,11 +206,9 @@ static int init_costs( x264_t *h, float *logs, int qp )
  490. h->cost_mv[qp][-i] =
  491. h->cost_mv[qp][i] = X264_MIN( (int)(lambda * logs[i] + .5f), UINT16_MAX );
  492. }
  493. - x264_pthread_mutex_lock( &cost_ref_mutex );
  494. for( int i = 0; i < 3; i++ )
  495. for( int j = 0; j < 33; j++ )
  496. - x264_cost_ref[qp][i][j] = i ? X264_MIN( lambda * bs_size_te( i, j ), UINT16_MAX ) : 0;
  497. - x264_pthread_mutex_unlock( &cost_ref_mutex );
  498. + h->cost_table->ref[qp][i][j] = i ? X264_MIN( lambda * bs_size_te( i, j ), UINT16_MAX ) : 0;
  499. if( h->param.analyse.i_me_method >= X264_ME_ESA && !h->cost_mv_fpel[qp][0] )
  500. {
  501. for( int j = 0; j < 4; j++ )
  502. @@ -225,7 +219,7 @@ static int init_costs( x264_t *h, float *logs, int qp )
  503. h->cost_mv_fpel[qp][j][i] = h->cost_mv[qp][i*4+j];
  504. }
  505. }
  506. - uint16_t *cost_i4x4_mode = (uint16_t*)ALIGN((intptr_t)x264_cost_i4x4_mode,64) + qp*32;
  507. + uint16_t *cost_i4x4_mode = (uint16_t*)h->cost_table->i4x4_mode + qp*32;
  508. for( int i = 0; i < 17; i++ )
  509. cost_i4x4_mode[i] = 3*lambda*(i!=8);
  510. return 0;
  511. @@ -303,8 +297,8 @@ void x264_analyse_weight_frame( x264_t *h, int end )
  512. static void mb_analyse_load_costs( x264_t *h, x264_mb_analysis_t *a )
  513. {
  514. a->p_cost_mv = h->cost_mv[a->i_qp];
  515. - a->p_cost_ref[0] = x264_cost_ref[a->i_qp][x264_clip3(h->sh.i_num_ref_idx_l0_active-1,0,2)];
  516. - a->p_cost_ref[1] = x264_cost_ref[a->i_qp][x264_clip3(h->sh.i_num_ref_idx_l1_active-1,0,2)];
  517. + a->p_cost_ref[0] = h->cost_table->ref[a->i_qp][x264_clip3(h->sh.i_num_ref_idx_l0_active-1,0,2)];
  518. + a->p_cost_ref[1] = h->cost_table->ref[a->i_qp][x264_clip3(h->sh.i_num_ref_idx_l1_active-1,0,2)];
  519. }
  520.  
  521. static void mb_analyse_init_qp( x264_t *h, x264_mb_analysis_t *a, int qp )
  522. @@ -800,7 +794,7 @@ static void mb_analyse_intra( x264_t *h, x264_mb_analysis_t *a, int i_satd_inter
  523. return;
  524. }
  525.  
  526. - uint16_t *cost_i4x4_mode = (uint16_t*)ALIGN((intptr_t)x264_cost_i4x4_mode,64) + a->i_qp*32 + 8;
  527. + uint16_t *cost_i4x4_mode = (uint16_t*)h->cost_table->i4x4_mode + a->i_qp*32 + 8;
  528. /* 8x8 prediction selection */
  529. if( flags & X264_ANALYSE_I8x8 )
  530. {
  531. diff --git a/encoder/encoder.c b/encoder/encoder.c
  532. index f6e593c9..b3abc168 100644
  533. --- a/encoder/encoder.c
  534. +++ b/encoder/encoder.c
  535. @@ -1521,6 +1521,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
  536. h->frames.i_largest_pts = h->frames.i_second_largest_pts = -1;
  537. h->frames.i_poc_last_open_gop = -1;
  538.  
  539. + CHECKED_MALLOCZERO( h->cost_table, sizeof(*h->cost_table) );
  540. CHECKED_MALLOCZERO( h->frames.unused[0], (h->frames.i_delay + 3) * sizeof(x264_frame_t *) );
  541. /* Allocate room for max refs plus a few extra just in case. */
  542. CHECKED_MALLOCZERO( h->frames.unused[1], (h->i_thread_frames + X264_REF_MAX + 4) * sizeof(x264_frame_t *) );
  543. @@ -4358,6 +4359,7 @@ void x264_encoder_close ( x264_t *h )
  544. x264_free( h->nal_buffer );
  545. x264_free( h->reconfig_h );
  546. x264_analyse_free_costs( h );
  547. + x264_free( h->cost_table );
  548.  
  549. if( h->i_thread_frames > 1 )
  550. h = h->thread[h->i_thread_phase];
  551. --
  552. 2.13.0.windows.1
  553.  
  554.  
  555. From 91031f71beb94c97abb0fcc40116347f9f4e66fc Mon Sep 17 00:00:00 2001
  556. From: Anton Mitrofanov <BugMaster@narod.ru>
  557. Date: Fri, 22 Sep 2017 17:28:18 +0300
  558. Subject: [PATCH 7/7] Don't force fast-intra for subme < 3
  559.  
  560. It have caused significant quality hit without any meaningful (if any) speed up.
  561. ---
  562. encoder/analyse.c | 6 ++----
  563. 1 file changed, 2 insertions(+), 4 deletions(-)
  564.  
  565. diff --git a/encoder/analyse.c b/encoder/analyse.c
  566. index d077a75c..871670bb 100644
  567. --- a/encoder/analyse.c
  568. +++ b/encoder/analyse.c
  569. @@ -494,14 +494,12 @@ static void mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int qp )
  570. /* Fast intra decision */
  571. if( a->b_early_terminate && h->mb.i_mb_xy - h->sh.i_first_mb > 4 )
  572. {
  573. - /* Always run in fast-intra mode for subme < 3 */
  574. - if( h->mb.i_subpel_refine > 2 &&
  575. - ( IS_INTRA( h->mb.i_mb_type_left[0] ) ||
  576. + if( IS_INTRA( h->mb.i_mb_type_left[0] ) ||
  577. IS_INTRA( h->mb.i_mb_type_top ) ||
  578. IS_INTRA( h->mb.i_mb_type_topleft ) ||
  579. IS_INTRA( h->mb.i_mb_type_topright ) ||
  580. (h->sh.i_type == SLICE_TYPE_P && IS_INTRA( h->fref[0][0]->mb_type[h->mb.i_mb_xy] )) ||
  581. - (h->mb.i_mb_xy - h->sh.i_first_mb < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_8x8] + h->stat.frame.i_mb_count[I_16x16])) ) )
  582. + (h->mb.i_mb_xy - h->sh.i_first_mb < 3*(h->stat.frame.i_mb_count[I_4x4] + h->stat.frame.i_mb_count[I_8x8] + h->stat.frame.i_mb_count[I_16x16])) )
  583. { /* intra is likely */ }
  584. else
  585. {
  586. --
  587. 2.13.0.windows.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement