Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 104.87 KB | None | 0 0
  1. From 90a249aa40deec9234f9ea7554deb8a418183094 Mon Sep 17 00:00:00 2001
  2. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  3. Date: Thu, 21 Jan 2010 10:00:07 -0800
  4. Subject: [PATCH 01/15] Merge nnz_backup with scratch buffer
  5. Slightly less memory usage.
  6.  
  7. ---
  8. common/common.h | 1 -
  9. common/frame.c | 5 +++--
  10. common/macroblock.c | 2 --
  11. encoder/encoder.c | 4 +++-
  12. 4 files changed, 6 insertions(+), 6 deletions(-)
  13.  
  14. diff --git a/common/common.h b/common/common.h
  15. index 02d1748..df39f26 100644
  16. --- a/common/common.h
  17. +++ b/common/common.h
  18. @@ -532,7 +532,6 @@ struct x264_t
  19. int8_t *skipbp; /* block pattern for SKIP or DIRECT (sub)mbs. B-frames + cabac only */
  20. int8_t *mb_transform_size; /* transform_size_8x8_flag of each mb */
  21. uint8_t *intra_border_backup[2][3]; /* bottom pixels of the previous mb row, used for intra prediction after the framebuffer has been deblocked */
  22. - uint8_t (*nnz_backup)[16]; /* when using cavlc + 8x8dct, the deblocker uses a modified nnz */
  23.  
  24. /* buffer for weighted versions of the reference frames */
  25. uint8_t *p_weight_buf[16];
  26. diff --git a/common/frame.c b/common/frame.c
  27. index 08ef87f..3ef303a 100644
  28. --- a/common/frame.c
  29. +++ b/common/frame.c
  30. @@ -661,9 +661,10 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
  31. int stride2y = stridey << b_interlaced;
  32. int strideuv = h->fdec->i_stride[1];
  33. int stride2uv = strideuv << b_interlaced;
  34. + uint8_t (*nnz_backup)[16] = h->scratch_buffer;
  35.  
  36. if( !h->pps->b_cabac && h->pps->b_transform_8x8_mode )
  37. - munge_cavlc_nnz( h, mb_y, h->mb.nnz_backup, munge_cavlc_nnz_row );
  38. + munge_cavlc_nnz( h, mb_y, nnz_backup, munge_cavlc_nnz_row );
  39.  
  40. for( mb_x = 0; mb_x < h->sps->i_mb_width; mb_x += (~b_interlaced | mb_y)&1, mb_y ^= b_interlaced )
  41. {
  42. @@ -823,7 +824,7 @@ void x264_frame_deblock_row( x264_t *h, int mb_y )
  43. }
  44.  
  45. if( !h->pps->b_cabac && h->pps->b_transform_8x8_mode )
  46. - munge_cavlc_nnz( h, mb_y, h->mb.nnz_backup, restore_cavlc_nnz_row );
  47. + munge_cavlc_nnz( h, mb_y, nnz_backup, restore_cavlc_nnz_row );
  48. }
  49.  
  50. void x264_frame_deblock( x264_t *h )
  51. diff --git a/common/macroblock.c b/common/macroblock.c
  52. index 921d2b9..10f09ac 100644
  53. --- a/common/macroblock.c
  54. +++ b/common/macroblock.c
  55. @@ -701,7 +701,6 @@ int x264_macroblock_cache_init( x264_t *h )
  56.  
  57. /* all coeffs */
  58. CHECKED_MALLOC( h->mb.non_zero_count, i_mb_count * 24 * sizeof(uint8_t) );
  59. - CHECKED_MALLOC( h->mb.nnz_backup, h->sps->i_mb_width * 4 * 16 * sizeof(uint8_t) );
  60.  
  61. if( h->param.b_cabac )
  62. {
  63. @@ -797,7 +796,6 @@ void x264_macroblock_cache_end( x264_t *h )
  64. }
  65. x264_free( h->mb.intra4x4_pred_mode );
  66. x264_free( h->mb.non_zero_count );
  67. - x264_free( h->mb.nnz_backup );
  68. x264_free( h->mb.mb_transform_size );
  69. x264_free( h->mb.skipbp );
  70. x264_free( h->mb.cbp );
  71. diff --git a/encoder/encoder.c b/encoder/encoder.c
  72. index f97df1b..db2c861 100644
  73. --- a/encoder/encoder.c
  74. +++ b/encoder/encoder.c
  75. @@ -1018,7 +1018,9 @@ x264_t *x264_encoder_open( x264_param_t *param )
  76. int buf_tesa = (h->param.analyse.i_me_method >= X264_ME_ESA) *
  77. ((me_range*2+18) * sizeof(int16_t) + (me_range+4) * (me_range+1) * 4 * sizeof(mvsad_t));
  78. int buf_mbtree = h->param.rc.b_mb_tree * ((h->sps->i_mb_width+3)&~3) * sizeof(int);
  79. - CHECKED_MALLOC( h->thread[i]->scratch_buffer, X264_MAX4( buf_hpel, buf_ssim, buf_tesa, buf_mbtree ) );
  80. + int buf_nnz = !h->param.b_cabac * h->pps->b_transform_8x8_mode * (h->sps->i_mb_width * 4 * 16 * sizeof(uint8_t));
  81. + int scratch_size = X264_MAX4( buf_hpel, buf_ssim, buf_tesa, X264_MAX( buf_mbtree, buf_nnz ) );
  82. + CHECKED_MALLOC( h->thread[i]->scratch_buffer, scratch_size );
  83. }
  84.  
  85. if( x264_ratecontrol_new( h ) < 0 )
  86. --
  87. 1.6.1.2
  88.  
  89.  
  90. From 1a1b356a2996629d2c5ad2b568df8df9bff32954 Mon Sep 17 00:00:00 2001
  91. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  92. Date: Thu, 21 Jan 2010 23:07:11 -0800
  93. Subject: [PATCH 02/15] Fix bitstream alignment with multiple slices
  94. Broke multi-slice encoding on CPUs without unaligned access.
  95. New system simply forces a bitstream realignment at the start of each writing function and flushes when it reaches the end.
  96.  
  97. ---
  98. common/bs.h | 14 +++++++++++++-
  99. encoder/encoder.c | 2 +-
  100. encoder/set.c | 8 ++++++++
  101. 3 files changed, 22 insertions(+), 2 deletions(-)
  102.  
  103. diff --git a/common/bs.h b/common/bs.h
  104. index d13eb03..0773de6 100644
  105. --- a/common/bs.h
  106. +++ b/common/bs.h
  107. @@ -77,7 +77,7 @@ static inline void bs_init( bs_t *s, void *p_data, int i_data )
  108. s->p = s->p_start = (uint8_t*)p_data - offset;
  109. s->p_end = (uint8_t*)p_data + i_data;
  110. s->i_left = (WORD_SIZE - offset)*8;
  111. - s->cur_bits = endian_fix32(*(uint32_t *)(s->p));
  112. + s->cur_bits = endian_fix32( M32(s->p) );
  113. s->cur_bits >>= (4-offset)*8;
  114. }
  115. static inline int bs_pos( bs_t *s )
  116. @@ -92,6 +92,18 @@ static inline void bs_flush( bs_t *s )
  117. s->p += WORD_SIZE - s->i_left / 8;
  118. s->i_left = WORD_SIZE*8;
  119. }
  120. +/* The inverse of bs_flush: prepare the bitstream to be written to again. */
  121. +static inline void bs_realign( bs_t *s )
  122. +{
  123. + int offset = ((intptr_t)s->p & 3);
  124. + if( offset )
  125. + {
  126. + s->p = (uint8_t*)s->p - offset;
  127. + s->i_left = (WORD_SIZE - offset)*8;
  128. + s->cur_bits = endian_fix32( M32(s->p) );
  129. + s->cur_bits >>= (4-offset)*8;
  130. + }
  131. +}
  132.  
  133. static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
  134. {
  135. diff --git a/encoder/encoder.c b/encoder/encoder.c
  136. index db2c861..c7065a2 100644
  137. --- a/encoder/encoder.c
  138. +++ b/encoder/encoder.c
  139. @@ -1206,7 +1206,6 @@ int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
  140. x264_pps_write( &h->out.bs, h->pps );
  141. if( x264_nal_end( h ) )
  142. return -1;
  143. - bs_flush( &h->out.bs );
  144.  
  145. frame_size = x264_encoder_encapsulate_nals( h );
  146.  
  147. @@ -1657,6 +1656,7 @@ static int x264_slice_write( x264_t *h )
  148. /* Assume no more than 3 bytes of NALU escaping. */
  149. int slice_max_size = h->param.i_slice_max_size > 0 ? (h->param.i_slice_max_size-3-NALU_OVERHEAD)*8 : INT_MAX;
  150. int starting_bits = bs_pos(&h->out.bs);
  151. + bs_realign( &h->out.bs );
  152.  
  153. /* Slice */
  154. x264_nal_start( h, h->i_nal_type, h->i_nal_ref_idc );
  155. diff --git a/encoder/set.c b/encoder/set.c
  156. index 641eae9..f79919b 100644
  157. --- a/encoder/set.c
  158. +++ b/encoder/set.c
  159. @@ -210,6 +210,7 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
  160.  
  161. void x264_sps_write( bs_t *s, x264_sps_t *sps )
  162. {
  163. + bs_realign( s );
  164. bs_write( s, 8, sps->i_profile_idc );
  165. bs_write( s, 1, sps->b_constraint_set0 );
  166. bs_write( s, 1, sps->b_constraint_set1 );
  167. @@ -359,6 +360,7 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )
  168. }
  169.  
  170. bs_rbsp_trailing( s );
  171. + bs_flush( s );
  172. }
  173.  
  174. void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps )
  175. @@ -423,6 +425,7 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
  176.  
  177. void x264_pps_write( bs_t *s, x264_pps_t *pps )
  178. {
  179. + bs_realign( s );
  180. bs_write_ue( s, pps->i_id );
  181. bs_write_ue( s, pps->i_sps_id );
  182.  
  183. @@ -465,12 +468,14 @@ void x264_pps_write( bs_t *s, x264_pps_t *pps )
  184. }
  185.  
  186. bs_rbsp_trailing( s );
  187. + bs_flush( s );
  188. }
  189.  
  190. void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt )
  191. {
  192. int payload_size;
  193.  
  194. + bs_realign( s );
  195. bs_write( s, 8, 0x06 ); // payload_type = Recovery Point
  196. payload_size = bs_size_ue( recovery_frame_cnt ) + 4;
  197.  
  198. @@ -482,6 +487,7 @@ void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt )
  199.  
  200. bs_align_10( s );
  201. bs_rbsp_trailing( s );
  202. + bs_flush( s );
  203. }
  204.  
  205. int x264_sei_version_write( x264_t *h, bs_t *s )
  206. @@ -505,6 +511,7 @@ int x264_sei_version_write( x264_t *h, bs_t *s )
  207. X264_BUILD, X264_VERSION, opts );
  208. length = strlen(version)+1+16;
  209.  
  210. + bs_realign( s );
  211. bs_write( s, 8, 0x5 ); // payload_type = user_data_unregistered
  212. // payload_size
  213. for( i = 0; i <= length-255; i += 255 )
  214. @@ -517,6 +524,7 @@ int x264_sei_version_write( x264_t *h, bs_t *s )
  215. bs_write( s, 8, version[i] );
  216.  
  217. bs_rbsp_trailing( s );
  218. + bs_flush( s );
  219.  
  220. x264_free( opts );
  221. x264_free( version );
  222. --
  223. 1.6.1.2
  224.  
  225.  
  226. From 00f933f05df722e4b133d2c57f1f45dba285430c Mon Sep 17 00:00:00 2001
  227. From: David Conrad <lessen42@gmail.com>
  228. Date: Sat, 23 Jan 2010 18:05:25 -0800
  229. Subject: [PATCH 03/15] Fix lavf input with pipes and image sequences
  230. x264 should now be able to encode from an image sequence using an image2-style formatted string (e.g. file%02d.jpg).
  231.  
  232. ---
  233. x264.c | 10 ++++------
  234. 1 files changed, 4 insertions(+), 6 deletions(-)
  235.  
  236. diff --git a/x264.c b/x264.c
  237. index 3a07bb3..db33536 100644
  238. --- a/x264.c
  239. +++ b/x264.c
  240. @@ -719,13 +719,11 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename
  241. if( b_regular )
  242. {
  243. FILE *f = fopen( filename, "r" );
  244. - if( !f )
  245. + if( f )
  246. {
  247. - fprintf( stderr, "x264 [error]: could not open input file `%s'\n", filename );
  248. - return -1;
  249. + b_regular = x264_is_regular_file( f );
  250. + fclose( f );
  251. }
  252. - b_regular = x264_is_regular_file( f );
  253. - fclose( f );
  254. }
  255. const char *module = b_auto ? ext : demuxer;
  256.  
  257. @@ -756,7 +754,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename
  258. #endif
  259. #ifdef LAVF_INPUT
  260. if( (b_auto || !strcasecmp( demuxer, "lavf" )) &&
  261. - (!b_regular || !lavf_input.open_file( filename, p_handle, info, opt )) )
  262. + !lavf_input.open_file( filename, p_handle, info, opt ) )
  263. {
  264. module = "lavf";
  265. b_auto = 0;
  266. --
  267. 1.6.1.2
  268.  
  269.  
  270. From 0f985245093047980c1b6148562222265b230dff Mon Sep 17 00:00:00 2001
  271. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  272. Date: Mon, 25 Jan 2010 11:23:55 -0800
  273. Subject: [PATCH 04/15] Hardcode the bs_t in cavlc.c; passing it around is a waste
  274.  
  275. Saves ~1.5kb of code size, very slight speed boost.
  276. ---
  277. encoder/cavlc.c | 143 ++++++++++++++++++++++++++------------------------
  278. encoder/encoder.c | 2 +-
  279. encoder/macroblock.h | 2 +-
  280. encoder/rdo.c | 6 +--
  281. 4 files changed, 79 insertions(+), 74 deletions(-)
  282.  
  283. diff --git a/encoder/cavlc.c b/encoder/cavlc.c
  284. index 59f362a..c65c9bd 100644
  285. --- a/encoder/cavlc.c
  286. +++ b/encoder/cavlc.c
  287. @@ -61,8 +61,9 @@ static const uint8_t sub_mb_type_b_to_golomb[13]=
  288. /****************************************************************************
  289. * block_residual_write_cavlc:
  290. ****************************************************************************/
  291. -static inline int block_residual_write_cavlc_escape( x264_t *h, bs_t *s, int i_suffix_length, int level )
  292. +static inline int block_residual_write_cavlc_escape( x264_t *h, int i_suffix_length, int level )
  293. {
  294. + bs_t *s = &h->out.bs;
  295. static const uint16_t next_suffix[7] = { 0, 3, 6, 12, 24, 48, 0xffff };
  296. int i_level_prefix = 15;
  297. int mask = level >> 15;
  298. @@ -112,8 +113,9 @@ static inline int block_residual_write_cavlc_escape( x264_t *h, bs_t *s, int i_s
  299. return i_suffix_length;
  300. }
  301.  
  302. -static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, int16_t *l, int nC )
  303. +static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l, int nC )
  304. {
  305. + bs_t *s = &h->out.bs;
  306. static const uint8_t ctz_index[8] = {3,0,1,0,2,0,1,0};
  307. static const int count_cat[5] = {16, 15, 16, 4, 15};
  308. x264_run_level_t runlevel;
  309. @@ -157,7 +159,7 @@ static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, in
  310. i_suffix_length = x264_level_token[i_suffix_length][val_original].i_next;
  311. }
  312. else
  313. - i_suffix_length = block_residual_write_cavlc_escape( h, s, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  314. + i_suffix_length = block_residual_write_cavlc_escape( h, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  315. for( i = i_trailing+1; i < i_total; i++ )
  316. {
  317. val = runlevel.level[i] + LEVEL_TABLE_SIZE/2;
  318. @@ -167,7 +169,7 @@ static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, in
  319. i_suffix_length = x264_level_token[i_suffix_length][val].i_next;
  320. }
  321. else
  322. - i_suffix_length = block_residual_write_cavlc_escape( h, s, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  323. + i_suffix_length = block_residual_write_cavlc_escape( h, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  324. }
  325. }
  326.  
  327. @@ -191,18 +193,19 @@ static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, in
  328.  
  329. static const uint8_t ct_index[17] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3};
  330.  
  331. -#define block_residual_write_cavlc(h,s,cat,idx,l)\
  332. +#define block_residual_write_cavlc(h,cat,idx,l)\
  333. {\
  334. int nC = cat == DCT_CHROMA_DC ? 4 : ct_index[x264_mb_predict_non_zero_code( h, cat == DCT_LUMA_DC ? 0 : idx )];\
  335. uint8_t *nnz = &h->mb.cache.non_zero_count[x264_scan8[idx]];\
  336. if( !*nnz )\
  337. - bs_write_vlc( s, x264_coeff0_token[nC] );\
  338. + bs_write_vlc( &h->out.bs, x264_coeff0_token[nC] );\
  339. else\
  340. - *nnz = block_residual_write_cavlc(h,s,cat,l,nC);\
  341. + *nnz = block_residual_write_cavlc(h,cat,l,nC);\
  342. }
  343.  
  344. -static void cavlc_qp_delta( x264_t *h, bs_t *s )
  345. +static void cavlc_qp_delta( x264_t *h )
  346. {
  347. + bs_t *s = &h->out.bs;
  348. int i_dqp = h->mb.i_qp - h->mb.i_last_qp;
  349.  
  350. /* Avoid writing a delta quant if we have an empty i16x16 block, e.g. in a completely flat background area */
  351. @@ -225,39 +228,40 @@ static void cavlc_qp_delta( x264_t *h, bs_t *s )
  352. bs_write_se( s, i_dqp );
  353. }
  354.  
  355. -static void cavlc_mb_mvd( x264_t *h, bs_t *s, int i_list, int idx, int width )
  356. +static void cavlc_mb_mvd( x264_t *h, int i_list, int idx, int width )
  357. {
  358. + bs_t *s = &h->out.bs;
  359. ALIGNED_4( int16_t mvp[2] );
  360. x264_mb_predict_mv( h, i_list, idx, width, mvp );
  361. bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[idx]][0] - mvp[0] );
  362. bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[idx]][1] - mvp[1] );
  363. }
  364.  
  365. -static inline void cavlc_mb8x8_mvd( x264_t *h, bs_t *s, int i )
  366. +static inline void cavlc_mb8x8_mvd( x264_t *h, int i )
  367. {
  368. switch( h->mb.i_sub_partition[i] )
  369. {
  370. case D_L0_8x8:
  371. - cavlc_mb_mvd( h, s, 0, 4*i, 2 );
  372. + cavlc_mb_mvd( h, 0, 4*i, 2 );
  373. break;
  374. case D_L0_8x4:
  375. - cavlc_mb_mvd( h, s, 0, 4*i+0, 2 );
  376. - cavlc_mb_mvd( h, s, 0, 4*i+2, 2 );
  377. + cavlc_mb_mvd( h, 0, 4*i+0, 2 );
  378. + cavlc_mb_mvd( h, 0, 4*i+2, 2 );
  379. break;
  380. case D_L0_4x8:
  381. - cavlc_mb_mvd( h, s, 0, 4*i+0, 1 );
  382. - cavlc_mb_mvd( h, s, 0, 4*i+1, 1 );
  383. + cavlc_mb_mvd( h, 0, 4*i+0, 1 );
  384. + cavlc_mb_mvd( h, 0, 4*i+1, 1 );
  385. break;
  386. case D_L0_4x4:
  387. - cavlc_mb_mvd( h, s, 0, 4*i+0, 1 );
  388. - cavlc_mb_mvd( h, s, 0, 4*i+1, 1 );
  389. - cavlc_mb_mvd( h, s, 0, 4*i+2, 1 );
  390. - cavlc_mb_mvd( h, s, 0, 4*i+3, 1 );
  391. + cavlc_mb_mvd( h, 0, 4*i+0, 1 );
  392. + cavlc_mb_mvd( h, 0, 4*i+1, 1 );
  393. + cavlc_mb_mvd( h, 0, 4*i+2, 1 );
  394. + cavlc_mb_mvd( h, 0, 4*i+3, 1 );
  395. break;
  396. }
  397. }
  398.  
  399. -static inline void x264_macroblock_luma_write_cavlc( x264_t *h, bs_t *s, int i8start, int i8end )
  400. +static inline void x264_macroblock_luma_write_cavlc( x264_t *h, int i8start, int i8end )
  401. {
  402. int i8, i4;
  403. if( h->mb.b_transform_8x8 )
  404. @@ -271,20 +275,23 @@ static inline void x264_macroblock_luma_write_cavlc( x264_t *h, bs_t *s, int i8s
  405. for( i8 = i8start; i8 <= i8end; i8++ )
  406. if( h->mb.i_cbp_luma & (1 << i8) )
  407. for( i4 = 0; i4 < 4; i4++ )
  408. - block_residual_write_cavlc( h, s, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4] );
  409. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4] );
  410. }
  411.  
  412. /*****************************************************************************
  413. * x264_macroblock_write:
  414. *****************************************************************************/
  415. -void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  416. +void x264_macroblock_write_cavlc( x264_t *h )
  417. {
  418. + bs_t *s = &h->out.bs;
  419. const int i_mb_type = h->mb.i_type;
  420. static const uint8_t i_offsets[3] = {5,23,0};
  421. int i_mb_i_offset = i_offsets[h->sh.i_type];
  422. int i;
  423.  
  424. -#if !RDO_SKIP_BS
  425. +#if RDO_SKIP_BS
  426. + s->i_bits_encoded = 0;
  427. +#else
  428. const int i_mb_pos_start = bs_pos( s );
  429. int i_mb_pos_tex;
  430. #endif
  431. @@ -365,7 +372,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  432.  
  433. if( h->mb.pic.i_fref[0] > 1 )
  434. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
  435. - cavlc_mb_mvd( h, s, 0, 0, 4 );
  436. + cavlc_mb_mvd( h, 0, 0, 4 );
  437. }
  438. else if( h->mb.i_partition == D_16x8 )
  439. {
  440. @@ -375,8 +382,8 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  441. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
  442. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[8]] );
  443. }
  444. - cavlc_mb_mvd( h, s, 0, 0, 4 );
  445. - cavlc_mb_mvd( h, s, 0, 8, 4 );
  446. + cavlc_mb_mvd( h, 0, 0, 4 );
  447. + cavlc_mb_mvd( h, 0, 8, 4 );
  448. }
  449. else if( h->mb.i_partition == D_8x16 )
  450. {
  451. @@ -386,8 +393,8 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  452. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
  453. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4]] );
  454. }
  455. - cavlc_mb_mvd( h, s, 0, 0, 2 );
  456. - cavlc_mb_mvd( h, s, 0, 4, 2 );
  457. + cavlc_mb_mvd( h, 0, 0, 2 );
  458. + cavlc_mb_mvd( h, 0, 4, 2 );
  459. }
  460. }
  461. else if( i_mb_type == P_8x8 )
  462. @@ -422,7 +429,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  463. }
  464.  
  465. for( i = 0; i < 4; i++ )
  466. - cavlc_mb8x8_mvd( h, s, i );
  467. + cavlc_mb8x8_mvd( h, i );
  468. }
  469. else if( i_mb_type == B_8x8 )
  470. {
  471. @@ -445,10 +452,10 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  472. /* mvd */
  473. for( i = 0; i < 4; i++ )
  474. if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
  475. - cavlc_mb_mvd( h, s, 0, 4*i, 2 );
  476. + cavlc_mb_mvd( h, 0, 4*i, 2 );
  477. for( i = 0; i < 4; i++ )
  478. if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
  479. - cavlc_mb_mvd( h, s, 1, 4*i, 2 );
  480. + cavlc_mb_mvd( h, 1, 4*i, 2 );
  481. }
  482. else if( i_mb_type != B_DIRECT )
  483. {
  484. @@ -463,8 +470,8 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  485. {
  486. if( i_ref0_max && b_list[0][0] ) bs_write_te( s, i_ref0_max, h->mb.cache.ref[0][x264_scan8[0]] );
  487. if( i_ref1_max && b_list[1][0] ) bs_write_te( s, i_ref1_max, h->mb.cache.ref[1][x264_scan8[0]] );
  488. - if( b_list[0][0] ) cavlc_mb_mvd( h, s, 0, 0, 4 );
  489. - if( b_list[1][0] ) cavlc_mb_mvd( h, s, 1, 0, 4 );
  490. + if( b_list[0][0] ) cavlc_mb_mvd( h, 0, 0, 4 );
  491. + if( b_list[1][0] ) cavlc_mb_mvd( h, 1, 0, 4 );
  492. }
  493. else
  494. {
  495. @@ -474,17 +481,17 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  496. if( i_ref1_max && b_list[1][1] ) bs_write_te( s, i_ref1_max, h->mb.cache.ref[1][x264_scan8[12]] );
  497. if( h->mb.i_partition == D_16x8 )
  498. {
  499. - if( b_list[0][0] ) cavlc_mb_mvd( h, s, 0, 0, 4 );
  500. - if( b_list[0][1] ) cavlc_mb_mvd( h, s, 0, 8, 4 );
  501. - if( b_list[1][0] ) cavlc_mb_mvd( h, s, 1, 0, 4 );
  502. - if( b_list[1][1] ) cavlc_mb_mvd( h, s, 1, 8, 4 );
  503. + if( b_list[0][0] ) cavlc_mb_mvd( h, 0, 0, 4 );
  504. + if( b_list[0][1] ) cavlc_mb_mvd( h, 0, 8, 4 );
  505. + if( b_list[1][0] ) cavlc_mb_mvd( h, 1, 0, 4 );
  506. + if( b_list[1][1] ) cavlc_mb_mvd( h, 1, 8, 4 );
  507. }
  508. else //if( h->mb.i_partition == D_8x16 )
  509. {
  510. - if( b_list[0][0] ) cavlc_mb_mvd( h, s, 0, 0, 2 );
  511. - if( b_list[0][1] ) cavlc_mb_mvd( h, s, 0, 4, 2 );
  512. - if( b_list[1][0] ) cavlc_mb_mvd( h, s, 1, 0, 2 );
  513. - if( b_list[1][1] ) cavlc_mb_mvd( h, s, 1, 4, 2 );
  514. + if( b_list[0][0] ) cavlc_mb_mvd( h, 0, 0, 2 );
  515. + if( b_list[0][1] ) cavlc_mb_mvd( h, 0, 4, 2 );
  516. + if( b_list[1][0] ) cavlc_mb_mvd( h, 1, 0, 2 );
  517. + if( b_list[1][1] ) cavlc_mb_mvd( h, 1, 4, 2 );
  518. }
  519. }
  520. }
  521. @@ -509,29 +516,29 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  522. /* write residual */
  523. if( i_mb_type == I_16x16 )
  524. {
  525. - cavlc_qp_delta( h, s );
  526. + cavlc_qp_delta( h );
  527.  
  528. /* DC Luma */
  529. - block_residual_write_cavlc( h, s, DCT_LUMA_DC, 24 , h->dct.luma16x16_dc );
  530. + block_residual_write_cavlc( h, DCT_LUMA_DC, 24 , h->dct.luma16x16_dc );
  531.  
  532. /* AC Luma */
  533. if( h->mb.i_cbp_luma )
  534. for( i = 0; i < 16; i++ )
  535. - block_residual_write_cavlc( h, s, DCT_LUMA_AC, i, h->dct.luma4x4[i]+1 );
  536. + block_residual_write_cavlc( h, DCT_LUMA_AC, i, h->dct.luma4x4[i]+1 );
  537. }
  538. else if( h->mb.i_cbp_luma | h->mb.i_cbp_chroma )
  539. {
  540. - cavlc_qp_delta( h, s );
  541. - x264_macroblock_luma_write_cavlc( h, s, 0, 3 );
  542. + cavlc_qp_delta( h );
  543. + x264_macroblock_luma_write_cavlc( h, 0, 3 );
  544. }
  545. if( h->mb.i_cbp_chroma )
  546. {
  547. /* Chroma DC residual present */
  548. - block_residual_write_cavlc( h, s, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  549. - block_residual_write_cavlc( h, s, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  550. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  551. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  552. if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */
  553. for( i = 16; i < 24; i++ )
  554. - block_residual_write_cavlc( h, s, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  555. + block_residual_write_cavlc( h, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  556. }
  557.  
  558. #if !RDO_SKIP_BS
  559. @@ -549,36 +556,36 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  560. *****************************************************************************/
  561. static int x264_partition_size_cavlc( x264_t *h, int i8, int i_pixel )
  562. {
  563. + bs_t *s = &h->out.bs;
  564. const int i_mb_type = h->mb.i_type;
  565. int b_8x16 = h->mb.i_partition == D_8x16;
  566. int j;
  567. - h->out.bs.i_bits_encoded = 0;
  568.  
  569. if( i_mb_type == P_8x8 )
  570. {
  571. - cavlc_mb8x8_mvd( h, &h->out.bs, i8 );
  572. - bs_write_ue( &h->out.bs, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i8] ] );
  573. + cavlc_mb8x8_mvd( h, i8 );
  574. + bs_write_ue( s, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i8] ] );
  575. }
  576. else if( i_mb_type == P_L0 )
  577. - cavlc_mb_mvd( h, &h->out.bs, 0, 4*i8, 4>>b_8x16 );
  578. + cavlc_mb_mvd( h, 0, 4*i8, 4>>b_8x16 );
  579. else if( i_mb_type > B_DIRECT && i_mb_type < B_8x8 )
  580. {
  581. - if( x264_mb_type_list_table[ i_mb_type ][0][!!i8] ) cavlc_mb_mvd( h, &h->out.bs, 0, 4*i8, 4>>b_8x16 );
  582. - if( x264_mb_type_list_table[ i_mb_type ][1][!!i8] ) cavlc_mb_mvd( h, &h->out.bs, 1, 4*i8, 4>>b_8x16 );
  583. + if( x264_mb_type_list_table[ i_mb_type ][0][!!i8] ) cavlc_mb_mvd( h, 0, 4*i8, 4>>b_8x16 );
  584. + if( x264_mb_type_list_table[ i_mb_type ][1][!!i8] ) cavlc_mb_mvd( h, 1, 4*i8, 4>>b_8x16 );
  585. }
  586. else //if( i_mb_type == B_8x8 )
  587. {
  588. if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i8] ] )
  589. - cavlc_mb_mvd( h, &h->out.bs, 0, 4*i8, 2 );
  590. + cavlc_mb_mvd( h, 0, 4*i8, 2 );
  591. if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i8] ] )
  592. - cavlc_mb_mvd( h, &h->out.bs, 1, 4*i8, 2 );
  593. + cavlc_mb_mvd( h, 1, 4*i8, 2 );
  594. }
  595.  
  596. for( j = (i_pixel < PIXEL_8x8); j >= 0; j-- )
  597. {
  598. - x264_macroblock_luma_write_cavlc( h, &h->out.bs, i8, i8 );
  599. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_AC, 16+i8, h->dct.luma4x4[16+i8]+1 );
  600. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_AC, 20+i8, h->dct.luma4x4[20+i8]+1 );
  601. + x264_macroblock_luma_write_cavlc( h, i8, i8 );
  602. + block_residual_write_cavlc( h, DCT_CHROMA_AC, 16+i8, h->dct.luma4x4[16+i8]+1 );
  603. + block_residual_write_cavlc( h, DCT_CHROMA_AC, 20+i8, h->dct.luma4x4[20+i8]+1 );
  604. i8 += x264_pixel_size[i_pixel].h >> 3;
  605. }
  606.  
  607. @@ -589,12 +596,12 @@ static int x264_subpartition_size_cavlc( x264_t *h, int i4, int i_pixel )
  608. {
  609. int b_8x4 = i_pixel == PIXEL_8x4;
  610. h->out.bs.i_bits_encoded = 0;
  611. - cavlc_mb_mvd( h, &h->out.bs, 0, i4, 1+b_8x4 );
  612. - block_residual_write_cavlc( h, &h->out.bs, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  613. + cavlc_mb_mvd( h, 0, i4, 1+b_8x4 );
  614. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  615. if( i_pixel != PIXEL_4x4 )
  616. {
  617. i4 += 2-b_8x4;
  618. - block_residual_write_cavlc( h, &h->out.bs, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  619. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  620. }
  621.  
  622. return h->out.bs.i_bits_encoded;
  623. @@ -612,14 +619,14 @@ static int x264_partition_i8x8_size_cavlc( x264_t *h, int i8, int i_mode )
  624. {
  625. h->out.bs.i_bits_encoded = cavlc_intra4x4_pred_size( h, 4*i8, i_mode );
  626. bs_write_ue( &h->out.bs, intra4x4_cbp_to_golomb[( h->mb.i_cbp_chroma << 4 )|h->mb.i_cbp_luma] );
  627. - x264_macroblock_luma_write_cavlc( h, &h->out.bs, i8, i8 );
  628. + x264_macroblock_luma_write_cavlc( h, i8, i8 );
  629. return h->out.bs.i_bits_encoded;
  630. }
  631.  
  632. static int x264_partition_i4x4_size_cavlc( x264_t *h, int i4, int i_mode )
  633. {
  634. h->out.bs.i_bits_encoded = cavlc_intra4x4_pred_size( h, i4, i_mode );
  635. - block_residual_write_cavlc( h, &h->out.bs, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  636. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  637. return h->out.bs.i_bits_encoded;
  638. }
  639.  
  640. @@ -628,14 +635,14 @@ static int x264_i8x8_chroma_size_cavlc( x264_t *h )
  641. h->out.bs.i_bits_encoded = bs_size_ue( x264_mb_pred_mode8x8c_fix[ h->mb.i_chroma_pred_mode ] );
  642. if( h->mb.i_cbp_chroma )
  643. {
  644. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  645. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  646. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  647. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  648.  
  649. if( h->mb.i_cbp_chroma == 2 )
  650. {
  651. int i;
  652. for( i = 16; i < 24; i++ )
  653. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  654. + block_residual_write_cavlc( h, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  655. }
  656. }
  657. return h->out.bs.i_bits_encoded;
  658. diff --git a/encoder/encoder.c b/encoder/encoder.c
  659. index c7065a2..15b373d 100644
  660. --- a/encoder/encoder.c
  661. +++ b/encoder/encoder.c
  662. @@ -1741,7 +1741,7 @@ static int x264_slice_write( x264_t *h )
  663. bs_write_ue( &h->out.bs, i_skip ); /* skip run */
  664. i_skip = 0;
  665. }
  666. - x264_macroblock_write_cavlc( h, &h->out.bs );
  667. + x264_macroblock_write_cavlc( h );
  668. }
  669. }
  670.  
  671. diff --git a/encoder/macroblock.h b/encoder/macroblock.h
  672. index 24a43b1..25beb18 100644
  673. --- a/encoder/macroblock.h
  674. +++ b/encoder/macroblock.h
  675. @@ -45,7 +45,7 @@ void x264_predict_lossless_16x16( x264_t *h, int i_mode );
  676.  
  677. void x264_macroblock_encode ( x264_t *h );
  678. void x264_macroblock_write_cabac ( x264_t *h, x264_cabac_t *cb );
  679. -void x264_macroblock_write_cavlc ( x264_t *h, bs_t *s );
  680. +void x264_macroblock_write_cavlc ( x264_t *h );
  681.  
  682. void x264_macroblock_encode_p8x8( x264_t *h, int i8 );
  683. void x264_macroblock_encode_p4x4( x264_t *h, int i4 );
  684. diff --git a/encoder/rdo.c b/encoder/rdo.c
  685. index 9dee56d..3ed4a47 100644
  686. --- a/encoder/rdo.c
  687. +++ b/encoder/rdo.c
  688. @@ -159,10 +159,8 @@ static int x264_rd_cost_mb( x264_t *h, int i_lambda2 )
  689. }
  690. else
  691. {
  692. - bs_t bs_tmp = h->out.bs;
  693. - bs_tmp.i_bits_encoded = 0;
  694. - x264_macroblock_size_cavlc( h, &bs_tmp );
  695. - i_bits = ( bs_tmp.i_bits_encoded * i_lambda2 + 128 ) >> 8;
  696. + x264_macroblock_size_cavlc( h );
  697. + i_bits = ( h->out.bs.i_bits_encoded * i_lambda2 + 128 ) >> 8;
  698. }
  699.  
  700. h->mb.b_transform_8x8 = b_transform_bak;
  701. --
  702. 1.6.1.2
  703.  
  704.  
  705. From e46a9752509b139a54ca57650057d3c64b2b4c0b Mon Sep 17 00:00:00 2001
  706. From: Anton Mitrofanov <BugMaster@narod.ru>
  707. Date: Tue, 26 Jan 2010 11:41:18 -0800
  708. Subject: [PATCH 05/15] Various threading-related cosmetics
  709. Simplify a lot of code and remove some unnecessary variables.
  710.  
  711. ---
  712. common/common.h | 13 ++-----
  713. encoder/analyse.c | 12 +++---
  714. encoder/encoder.c | 83 +++++++++++++++++++++++++++----------------------
  715. encoder/ratecontrol.c | 22 ++++++------
  716. 4 files changed, 67 insertions(+), 63 deletions(-)
  717.  
  718. diff --git a/common/common.h b/common/common.h
  719. index df39f26..2205047 100644
  720. --- a/common/common.h
  721. +++ b/common/common.h
  722. @@ -362,16 +362,11 @@ struct x264_t
  723.  
  724. /* frame number/poc */
  725. int i_frame;
  726. + int i_frame_num;
  727.  
  728. - int i_frame_offset; /* decoding only */
  729. - int i_frame_num; /* decoding only */
  730. - int i_poc_msb; /* decoding only */
  731. - int i_poc_lsb; /* decoding only */
  732. - int i_poc; /* decoding only */
  733. -
  734. - int i_thread_num; /* threads only */
  735. - int i_nal_type; /* threads only */
  736. - int i_nal_ref_idc; /* threads only */
  737. + int i_thread_frames;
  738. + int i_nal_type;
  739. + int i_nal_ref_idc;
  740.  
  741. /* We use only one SPS and one PPS */
  742. x264_sps_t sps_array[1];
  743. diff --git a/encoder/analyse.c b/encoder/analyse.c
  744. index 37d7fd9..666596b 100644
  745. --- a/encoder/analyse.c
  746. +++ b/encoder/analyse.c
  747. @@ -413,7 +413,7 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
  748. int mb_height = h->sps->i_mb_height >> h->sh.b_mbaff;
  749. int thread_mvy_range = i_fmv_range;
  750.  
  751. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  752. + if( h->i_thread_frames > 1 )
  753. {
  754. int pix_y = (h->mb.i_mb_y | h->mb.b_interlaced) * 16;
  755. int thresh = pix_y + h->param.analyse.i_mv_range_thread;
  756. @@ -1167,7 +1167,7 @@ static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
  757. {
  758. h->mb.i_type = P_SKIP;
  759. x264_analyse_update_cache( h, a );
  760. - assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->param.i_threads == 1 || h->param.b_sliced_threads );
  761. + assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
  762. return;
  763. }
  764.  
  765. @@ -1183,7 +1183,7 @@ static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
  766. }
  767.  
  768. x264_macroblock_cache_ref( h, 0, 0, 4, 4, 0, a->l0.me16x16.i_ref );
  769. - assert( a->l0.me16x16.mv[1] <= h->mb.mv_max_spel[1] || h->param.i_threads == 1 || h->param.b_sliced_threads );
  770. + assert( a->l0.me16x16.mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
  771.  
  772. h->mb.i_type = P_L0;
  773. if( a->i_mbrd )
  774. @@ -2403,7 +2403,7 @@ intra_analysis:
  775. /* Fast P_SKIP detection */
  776. if( h->param.analyse.b_fast_pskip )
  777. {
  778. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads && h->mb.cache.pskip_mv[1] > h->mb.mv_max_spel[1] )
  779. + if( h->i_thread_frames > 1 && h->mb.cache.pskip_mv[1] > h->mb.mv_max_spel[1] )
  780. // FIXME don't need to check this if the reference frame is done
  781. {}
  782. else if( h->param.analyse.i_subpel_refine >= 3 )
  783. @@ -2422,7 +2422,7 @@ intra_analysis:
  784. {
  785. h->mb.i_type = P_SKIP;
  786. h->mb.i_partition = D_16x16;
  787. - assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->param.i_threads == 1 || h->param.b_sliced_threads );
  788. + assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
  789. }
  790. else
  791. {
  792. @@ -3143,7 +3143,7 @@ static void x264_analyse_update_cache( x264_t *h, x264_mb_analysis_t *a )
  793. }
  794.  
  795. #ifndef NDEBUG
  796. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads && !IS_INTRA(h->mb.i_type) )
  797. + if( h->i_thread_frames > 1 && !IS_INTRA(h->mb.i_type) )
  798. {
  799. int l;
  800. for( l=0; l <= (h->sh.i_type == SLICE_TYPE_B); l++ )
  801. diff --git a/encoder/encoder.c b/encoder/encoder.c
  802. index 15b373d..e54037c 100644
  803. --- a/encoder/encoder.c
  804. +++ b/encoder/encoder.c
  805. @@ -421,6 +421,7 @@ static int x264_validate_parameters( x264_t *h )
  806. }
  807. else
  808. h->param.b_sliced_threads = 0;
  809. + h->i_thread_frames = h->param.b_sliced_threads ? 1 : h->param.i_threads;
  810.  
  811. if( h->param.b_interlaced )
  812. {
  813. @@ -589,8 +590,8 @@ static int x264_validate_parameters( x264_t *h )
  814. h->param.rc.i_lookahead = 0;
  815. #ifdef HAVE_PTHREAD
  816. if( h->param.i_sync_lookahead )
  817. - h->param.i_sync_lookahead = x264_clip3( h->param.i_sync_lookahead, h->param.i_threads + h->param.i_bframe, X264_LOOKAHEAD_MAX );
  818. - if( h->param.rc.b_stat_read || h->param.i_threads == 1 || h->param.b_sliced_threads )
  819. + h->param.i_sync_lookahead = x264_clip3( h->param.i_sync_lookahead, h->i_thread_frames + h->param.i_bframe, X264_LOOKAHEAD_MAX );
  820. + if( h->param.rc.b_stat_read || h->i_thread_frames == 1 )
  821. h->param.i_sync_lookahead = 0;
  822. #else
  823. h->param.i_sync_lookahead = 0;
  824. @@ -708,7 +709,7 @@ static int x264_validate_parameters( x264_t *h )
  825. if( !h->param.analyse.i_weighted_pred && h->param.rc.b_mb_tree && h->param.analyse.b_psy && !h->param.b_interlaced )
  826. h->param.analyse.i_weighted_pred = X264_WEIGHTP_FAKE;
  827.  
  828. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  829. + if( h->i_thread_frames > 1 )
  830. {
  831. int r = h->param.analyse.i_mv_range_thread;
  832. int r2;
  833. @@ -718,7 +719,7 @@ static int x264_validate_parameters( x264_t *h )
  834. // the rest is allocated to whichever thread is far enough ahead to use it.
  835. // reserving more space increases quality for some videos, but costs more time
  836. // in thread synchronization.
  837. - int max_range = (h->param.i_height + X264_THREAD_HEIGHT) / h->param.i_threads - X264_THREAD_HEIGHT;
  838. + int max_range = (h->param.i_height + X264_THREAD_HEIGHT) / h->i_thread_frames - X264_THREAD_HEIGHT;
  839. r = max_range / 2;
  840. }
  841. r = X264_MAX( r, h->param.analyse.i_me_range );
  842. @@ -886,8 +887,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
  843. if( h->param.rc.b_mb_tree || h->param.rc.i_vbv_buffer_size )
  844. h->frames.i_delay = X264_MAX( h->frames.i_delay, h->param.rc.i_lookahead );
  845. i_slicetype_length = h->frames.i_delay;
  846. - if( !h->param.b_sliced_threads )
  847. - h->frames.i_delay += h->param.i_threads - 1;
  848. + h->frames.i_delay += h->i_thread_frames - 1;
  849. h->frames.i_delay = X264_MIN( h->frames.i_delay, X264_LOOKAHEAD_MAX );
  850. h->frames.i_delay += h->param.i_sync_lookahead;
  851. h->frames.i_bframe_delay = h->param.i_bframe ? (h->param.i_bframe_pyramid ? 2 : 1) : 0;
  852. @@ -910,11 +910,11 @@ x264_t *x264_encoder_open( x264_param_t *param )
  853.  
  854. CHECKED_MALLOCZERO( h->frames.unused[0], (h->frames.i_delay + 3) * sizeof(x264_frame_t *) );
  855. /* Allocate room for max refs plus a few extra just in case. */
  856. - CHECKED_MALLOCZERO( h->frames.unused[1], (h->param.i_threads + 20) * sizeof(x264_frame_t *) );
  857. + CHECKED_MALLOCZERO( h->frames.unused[1], (h->i_thread_frames + 20) * sizeof(x264_frame_t *) );
  858. CHECKED_MALLOCZERO( h->frames.current, (h->param.i_sync_lookahead + h->param.i_bframe
  859. - + h->param.i_threads + 3) * sizeof(x264_frame_t *) );
  860. + + h->i_thread_frames + 3) * sizeof(x264_frame_t *) );
  861. if( h->param.analyse.i_weighted_pred > 0 )
  862. - CHECKED_MALLOCZERO( h->frames.blank_unused, h->param.i_threads * 4 * sizeof(x264_frame_t *) );
  863. + CHECKED_MALLOCZERO( h->frames.blank_unused, h->i_thread_frames * 4 * sizeof(x264_frame_t *) );
  864. h->i_ref0 = 0;
  865. h->i_ref1 = 0;
  866.  
  867. @@ -977,7 +977,6 @@ x264_t *x264_encoder_open( x264_param_t *param )
  868. h->nal_buffer_size = h->out.i_bitstream * 3/2 + 4;
  869.  
  870. h->thread[0] = h;
  871. - h->i_thread_num = 0;
  872. for( i = 1; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
  873. CHECKED_MALLOC( h->thread[i], sizeof(x264_t) );
  874.  
  875. @@ -1501,7 +1500,7 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y )
  876. }
  877. }
  878.  
  879. - if( h->param.i_threads > 1 && h->fdec->b_kept_as_ref && !h->param.b_sliced_threads )
  880. + if( h->i_thread_frames > 1 && h->fdec->b_kept_as_ref )
  881. x264_frame_cond_broadcast( h->fdec, mb_y*16 + (b_end ? 10000 : -(X264_THREAD_HEIGHT << h->sh.b_mbaff)) );
  882.  
  883. min_y = X264_MAX( min_y*16-8, 0 );
  884. @@ -1537,7 +1536,7 @@ static inline int x264_reference_update( x264_t *h )
  885. int i, j;
  886. if( !h->fdec->b_kept_as_ref )
  887. {
  888. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  889. + if( h->i_thread_frames > 1 )
  890. {
  891. x264_frame_push_unused( h, h->fdec );
  892. h->fdec = x264_frame_pop_unused( h, 1 );
  893. @@ -1982,11 +1981,15 @@ static int x264_threaded_slices_write( x264_t *h )
  894.  
  895. /* dispatch */
  896. for( i = 0; i < h->param.i_threads; i++ )
  897. + {
  898. if( x264_pthread_create( &h->thread[i]->thread_handle, NULL, (void*)x264_slices_write, (void*)h->thread[i] ) )
  899. return -1;
  900. + h->thread[i]->b_thread_active = 1;
  901. + }
  902. for( i = 0; i < h->param.i_threads; i++ )
  903. {
  904. x264_pthread_join( h->thread[i]->thread_handle, &ret );
  905. + h->thread[i]->b_thread_active = 0;
  906. if( (intptr_t)ret )
  907. return (intptr_t)ret;
  908. }
  909. @@ -2036,12 +2039,12 @@ int x264_encoder_encode( x264_t *h,
  910. x264_t *thread_current, *thread_prev, *thread_oldest;
  911. int i_nal_type, i_nal_ref_idc, i_global_qp, i;
  912.  
  913. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  914. + if( h->i_thread_frames > 1 )
  915. {
  916. thread_prev = h->thread[ h->i_thread_phase ];
  917. - h->i_thread_phase = (h->i_thread_phase + 1) % h->param.i_threads;
  918. + h->i_thread_phase = (h->i_thread_phase + 1) % h->i_thread_frames;
  919. thread_current = h->thread[ h->i_thread_phase ];
  920. - thread_oldest = h->thread[ (h->i_thread_phase + 1) % h->param.i_threads ];
  921. + thread_oldest = h->thread[ (h->i_thread_phase + 1) % h->i_thread_frames ];
  922. x264_thread_sync_context( thread_current, thread_prev );
  923. x264_thread_sync_ratecontrol( thread_current, thread_prev, thread_oldest );
  924. h = thread_current;
  925. @@ -2100,7 +2103,7 @@ int x264_encoder_encode( x264_t *h,
  926. /* 2: Place the frame into the queue for its slice type decision */
  927. x264_lookahead_put_frame( h, fenc );
  928.  
  929. - if( h->frames.i_input <= h->frames.i_delay + (h->param.b_sliced_threads ? 0 : 1 - h->param.i_threads) )
  930. + if( h->frames.i_input <= h->frames.i_delay + 1 - h->i_thread_frames )
  931. {
  932. /* Nothing yet to encode, waiting for filling of buffers */
  933. pic_out->i_type = X264_TYPE_AUTO;
  934. @@ -2327,7 +2330,7 @@ int x264_encoder_encode( x264_t *h,
  935. /* Write frame */
  936. h->i_threadslice_start = 0;
  937. h->i_threadslice_end = h->sps->i_mb_height;
  938. - if( !h->param.b_sliced_threads && h->param.i_threads > 1 )
  939. + if( h->i_thread_frames > 1 )
  940. {
  941. if( x264_pthread_create( &h->thread_handle, NULL, (void*)x264_slices_write, h ) )
  942. return -1;
  943. @@ -2356,9 +2359,9 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
  944. {
  945. void *ret = NULL;
  946. x264_pthread_join( h->thread_handle, &ret );
  947. + h->b_thread_active = 0;
  948. if( (intptr_t)ret )
  949. return (intptr_t)ret;
  950. - h->b_thread_active = 0;
  951. }
  952. if( !h->out.i_nal )
  953. {
  954. @@ -2564,25 +2567,28 @@ void x264_encoder_close ( x264_t *h )
  955.  
  956. x264_lookahead_delete( h );
  957.  
  958. - for( i = 0; i < h->param.i_threads; i++ )
  959. + if( h->param.i_threads > 1 )
  960. {
  961. // don't strictly have to wait for the other threads, but it's simpler than canceling them
  962. - if( h->thread[i]->b_thread_active )
  963. + for( i = 0; i < h->param.i_threads; i++ )
  964. + if( h->thread[i]->b_thread_active )
  965. + x264_pthread_join( h->thread[i]->thread_handle, NULL );
  966. + if( h->i_thread_frames > 1 )
  967. {
  968. - x264_pthread_join( h->thread[i]->thread_handle, NULL );
  969. - assert( h->thread[i]->fenc->i_reference_count == 1 );
  970. - x264_frame_delete( h->thread[i]->fenc );
  971. - }
  972. - }
  973. -
  974. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  975. - {
  976. - x264_t *thread_prev;
  977. + for( i = 0; i < h->i_thread_frames; i++ )
  978. + {
  979. + if( h->thread[i]->b_thread_active )
  980. + {
  981. + assert( h->thread[i]->fenc->i_reference_count == 1 );
  982. + x264_frame_delete( h->thread[i]->fenc );
  983. + }
  984. + }
  985.  
  986. - thread_prev = h->thread[h->i_thread_phase];
  987. - x264_thread_sync_ratecontrol( h, thread_prev, h );
  988. - x264_thread_sync_ratecontrol( thread_prev, thread_prev, h );
  989. - h->i_frame = thread_prev->i_frame + 1 - h->param.i_threads;
  990. + x264_t *thread_prev = h->thread[h->i_thread_phase];
  991. + x264_thread_sync_ratecontrol( h, thread_prev, h );
  992. + x264_thread_sync_ratecontrol( thread_prev, thread_prev, h );
  993. + h->i_frame = thread_prev->i_frame + 1 - h->i_thread_frames;
  994. + }
  995. }
  996. h->i_frame++;
  997.  
  998. @@ -2833,7 +2839,7 @@ void x264_encoder_close ( x264_t *h )
  999. x264_free( h->nal_buffer );
  1000. x264_analyse_free_costs( h );
  1001.  
  1002. - if( h->param.i_threads > 1)
  1003. + if( h->i_thread_frames > 1)
  1004. h = h->thread[h->i_thread_phase];
  1005.  
  1006. /* frames */
  1007. @@ -2878,9 +2884,12 @@ int x264_encoder_delayed_frames( x264_t *h )
  1008. {
  1009. int delayed_frames = 0;
  1010. int i;
  1011. - for( i=0; i<h->param.i_threads; i++ )
  1012. - delayed_frames += h->thread[i]->b_thread_active;
  1013. - h = h->thread[h->i_thread_phase];
  1014. + if( h->i_thread_frames > 1 )
  1015. + {
  1016. + for( i=0; i<h->i_thread_frames; i++ )
  1017. + delayed_frames += h->thread[i]->b_thread_active;
  1018. + h = h->thread[h->i_thread_phase];
  1019. + }
  1020. for( i=0; h->frames.current[i]; i++ )
  1021. delayed_frames++;
  1022. x264_pthread_mutex_lock( &h->lookahead->ofbuf.mutex );
  1023. diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
  1024. index 761ff2c..746b17a 100644
  1025. --- a/encoder/ratecontrol.c
  1026. +++ b/encoder/ratecontrol.c
  1027. @@ -1578,13 +1578,13 @@ static void update_vbv_plan( x264_t *h, int overhead )
  1028. {
  1029. x264_ratecontrol_t *rcc = h->rc;
  1030. rcc->buffer_fill = h->thread[0]->rc->buffer_fill_final - overhead;
  1031. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  1032. + if( h->i_thread_frames > 1 )
  1033. {
  1034. int j = h->rc - h->thread[0]->rc;
  1035. int i;
  1036. - for( i=1; i<h->param.i_threads; i++ )
  1037. + for( i=1; i<h->i_thread_frames; i++ )
  1038. {
  1039. - x264_t *t = h->thread[ (j+i)%h->param.i_threads ];
  1040. + x264_t *t = h->thread[ (j+i)%h->i_thread_frames ];
  1041. double bits = t->rc->frame_size_planned;
  1042. if( !t->b_thread_active )
  1043. continue;
  1044. @@ -1794,7 +1794,7 @@ static float rate_estimate_qscale( x264_t *h )
  1045. }
  1046. else
  1047. {
  1048. - double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate * (h->param.b_sliced_threads?1:h->param.i_threads);
  1049. + double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate * h->i_thread_frames;
  1050.  
  1051. if( rcc->b_2pass )
  1052. {
  1053. @@ -1804,13 +1804,13 @@ static float rate_estimate_qscale( x264_t *h )
  1054.  
  1055. if( rcc->b_vbv )
  1056. {
  1057. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  1058. + if( h->i_thread_frames > 1 )
  1059. {
  1060. int j = h->rc - h->thread[0]->rc;
  1061. int i;
  1062. - for( i=1; i<h->param.i_threads; i++ )
  1063. + for( i=1; i<h->i_thread_frames; i++ )
  1064. {
  1065. - x264_t *t = h->thread[ (j+i)%h->param.i_threads ];
  1066. + x264_t *t = h->thread[ (j+i)%h->i_thread_frames ];
  1067. double bits = t->rc->frame_size_planned;
  1068. if( !t->b_thread_active )
  1069. continue;
  1070. @@ -1821,16 +1821,16 @@ static float rate_estimate_qscale( x264_t *h )
  1071. }
  1072. else
  1073. {
  1074. - if( h->fenc->i_frame < h->param.i_threads )
  1075. + if( h->fenc->i_frame < h->i_thread_frames )
  1076. predicted_bits += (int64_t)h->fenc->i_frame * rcc->bitrate / rcc->fps;
  1077. else
  1078. - predicted_bits += (int64_t)(h->param.i_threads - 1) * rcc->bitrate / rcc->fps;
  1079. + predicted_bits += (int64_t)(h->i_thread_frames - 1) * rcc->bitrate / rcc->fps;
  1080. }
  1081.  
  1082. diff = predicted_bits - (int64_t)rce.expected_bits;
  1083. q = rce.new_qscale;
  1084. q /= x264_clip3f((double)(abr_buffer - diff) / abr_buffer, .5, 2);
  1085. - if( ((h->fenc->i_frame + 1 - h->param.i_threads) >= rcc->fps) &&
  1086. + if( ((h->fenc->i_frame + 1 - h->i_thread_frames) >= rcc->fps) &&
  1087. (rcc->expected_bits_sum > 0))
  1088. {
  1089. /* Adjust quant based on the difference between
  1090. @@ -1897,7 +1897,7 @@ static float rate_estimate_qscale( x264_t *h )
  1091. }
  1092. else
  1093. {
  1094. - int i_frame_done = h->fenc->i_frame + 1 - h->param.i_threads;
  1095. + int i_frame_done = h->fenc->i_frame + 1 - h->i_thread_frames;
  1096.  
  1097. q = get_qscale( h, &rce, rcc->wanted_bits_window / rcc->cplxr_sum, h->fenc->i_frame );
  1098.  
  1099. --
  1100. 1.6.1.2
  1101.  
  1102.  
  1103. From b5a63c276b746451fbf87d47c521133cf8db9f3c Mon Sep 17 00:00:00 2001
  1104. From: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
  1105. Date: Tue, 26 Jan 2010 16:01:54 -0800
  1106. Subject: [PATCH 06/15] Improve DTS generation, move DTS compression into libx264
  1107. This change fixes some cases in which PTS could be less than DTS.
  1108.  
  1109. Additionally, a new parameter, b_dts_compress, enables DTS compression.
  1110. DTS compression eliminates negative DTS (i.e. initial delay) due to B-frames.
  1111. The algorithm changes timebase in order to avoid duplicating DTS.
  1112. Currently, in x264cli, only the FLV muxer uses it. The MP4 muxer doesn't need it, as it uses an EditBox instead.
  1113. ---
  1114. common/common.c | 1 +
  1115. common/common.h | 5 ++++
  1116. common/frame.c | 2 +-
  1117. common/frame.h | 2 +-
  1118. encoder/encoder.c | 39 ++++++++++++++++++++++++++++++++-
  1119. encoder/slicetype.c | 4 +-
  1120. output/flv.c | 58 ++++++++++++++++----------------------------------
  1121. output/mp4.c | 28 ++----------------------
  1122. x264.c | 10 ++++++++-
  1123. x264.h | 5 +++-
  1124. 10 files changed, 82 insertions(+), 72 deletions(-)
  1125.  
  1126. diff --git a/common/common.c b/common/common.c
  1127. index 9eed5c3..b454e37 100644
  1128. --- a/common/common.c
  1129. +++ b/common/common.c
  1130. @@ -157,6 +157,7 @@ void x264_param_default( x264_param_t *param )
  1131. param->b_annexb = 1;
  1132. param->b_aud = 0;
  1133. param->b_vfr_input = 1;
  1134. + param->b_dts_compress = 0;
  1135. }
  1136.  
  1137. static int parse_enum( const char *arg, const char * const *names, int *dst )
  1138. diff --git a/common/common.h b/common/common.h
  1139. index 2205047..db61ad4 100644
  1140. --- a/common/common.h
  1141. +++ b/common/common.h
  1142. @@ -375,6 +375,9 @@ struct x264_t
  1143. x264_pps_t *pps;
  1144. int i_idr_pic_id;
  1145.  
  1146. + /* Timebase multiplier for DTS compression */
  1147. + int i_dts_compress_multiplier;
  1148. +
  1149. /* quantization matrix for decoding, [cqm][qp%6][coef] */
  1150. int (*dequant4_mf[4])[16]; /* [4][6][16] */
  1151. int (*dequant8_mf[2])[64]; /* [2][6][64] */
  1152. @@ -428,6 +431,8 @@ struct x264_t
  1153. int i_delay; /* Number of frames buffered for B reordering */
  1154. int i_bframe_delay;
  1155. int64_t i_bframe_delay_time;
  1156. + int64_t i_init_delta;
  1157. + int64_t i_prev_dts[2];
  1158. int b_have_lowres; /* Whether 1/2 resolution luma planes are being used */
  1159. int b_have_sub8x8_esa;
  1160. } frames;
  1161. diff --git a/common/frame.c b/common/frame.c
  1162. index 3ef303a..40cc78f 100644
  1163. --- a/common/frame.c
  1164. +++ b/common/frame.c
  1165. @@ -223,7 +223,7 @@ int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
  1166.  
  1167. dst->i_type = src->i_type;
  1168. dst->i_qpplus1 = src->i_qpplus1;
  1169. - dst->i_pts = dst->i_dts = src->i_pts;
  1170. + dst->i_pts = dst->i_reordered_pts = src->i_pts;
  1171. dst->param = src->param;
  1172.  
  1173. for( i=0; i<3; i++ )
  1174. diff --git a/common/frame.h b/common/frame.h
  1175. index 786869e..b1852b3 100644
  1176. --- a/common/frame.h
  1177. +++ b/common/frame.h
  1178. @@ -35,7 +35,7 @@ typedef struct x264_frame
  1179. int i_type;
  1180. int i_qpplus1;
  1181. int64_t i_pts;
  1182. - int64_t i_dts;
  1183. + int64_t i_reordered_pts;
  1184. x264_param_t *param;
  1185.  
  1186. int i_frame; /* Presentation frame number */
  1187. diff --git a/encoder/encoder.c b/encoder/encoder.c
  1188. index e54037c..0a16a6b 100644
  1189. --- a/encoder/encoder.c
  1190. +++ b/encoder/encoder.c
  1191. @@ -863,6 +863,18 @@ x264_t *x264_encoder_open( x264_param_t *param )
  1192. h->i_frame = -1;
  1193. h->i_frame_num = 0;
  1194. h->i_idr_pic_id = 0;
  1195. + if( h->param.b_dts_compress )
  1196. + {
  1197. + /* h->i_dts_compress_multiplier == h->frames.i_bframe_delay + 1 */
  1198. + h->i_dts_compress_multiplier = h->param.i_bframe ? (h->param.i_bframe_pyramid ? 3 : 2) : 1;
  1199. + if( h->i_dts_compress_multiplier != 1 )
  1200. + x264_log( h, X264_LOG_DEBUG, "DTS compresion changed timebase: %d/%d -> %d/%d\n",
  1201. + h->param.i_timebase_num, h->param.i_timebase_den,
  1202. + h->param.i_timebase_num, h->param.i_timebase_den * h->i_dts_compress_multiplier );
  1203. + h->param.i_timebase_den *= h->i_dts_compress_multiplier;
  1204. + }
  1205. + else
  1206. + h->i_dts_compress_multiplier = 1;
  1207.  
  1208. h->sps = &h->sps_array[0];
  1209. x264_sps_init( h->sps, h->param.i_sps_id, &h->param );
  1210. @@ -2388,8 +2400,31 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
  1211. pic_out->i_type = X264_TYPE_B;
  1212.  
  1213. pic_out->b_keyframe = h->fenc->b_keyframe;
  1214. - pic_out->i_pts = h->fenc->i_pts;
  1215. - pic_out->i_dts = h->fenc->i_dts - h->frames.i_bframe_delay_time;
  1216. +
  1217. + pic_out->i_pts = h->fenc->i_pts *= h->i_dts_compress_multiplier;
  1218. + if( h->frames.i_bframe_delay )
  1219. + {
  1220. + int64_t *i_prev_dts = thread_current->frames.i_prev_dts;
  1221. + if( h->i_frame <= h->frames.i_bframe_delay )
  1222. + {
  1223. + if( h->i_dts_compress_multiplier == 1 )
  1224. + pic_out->i_dts = h->fenc->i_reordered_pts - h->frames.i_bframe_delay_time;
  1225. + else
  1226. + {
  1227. + /* DTS compression */
  1228. + if( h->i_frame == 1 )
  1229. + thread_current->frames.i_init_delta = h->fenc->i_reordered_pts * h->i_dts_compress_multiplier;
  1230. + pic_out->i_dts = h->i_frame * thread_current->frames.i_init_delta / h->i_dts_compress_multiplier;
  1231. + }
  1232. + }
  1233. + else
  1234. + pic_out->i_dts = i_prev_dts[ (h->i_frame - h->frames.i_bframe_delay) % h->frames.i_bframe_delay ];
  1235. + i_prev_dts[ h->i_frame % h->frames.i_bframe_delay ] = h->fenc->i_reordered_pts * h->i_dts_compress_multiplier;
  1236. + }
  1237. + else
  1238. + pic_out->i_dts = h->fenc->i_reordered_pts;
  1239. + assert( pic_out->i_pts >= pic_out->i_dts );
  1240. +
  1241. pic_out->img.i_plane = h->fdec->i_plane;
  1242. for(i = 0; i < 3; i++)
  1243. {
  1244. diff --git a/encoder/slicetype.c b/encoder/slicetype.c
  1245. index 9d955a1..057f6a6 100644
  1246. --- a/encoder/slicetype.c
  1247. +++ b/encoder/slicetype.c
  1248. @@ -1336,10 +1336,10 @@ void x264_slicetype_decide( x264_t *h )
  1249. {
  1250. int idx = index[h->lookahead->next.list[i]->i_type == X264_TYPE_BREF]++;
  1251. frames[idx] = h->lookahead->next.list[i];
  1252. - frames[idx]->i_dts = h->lookahead->next.list[idx]->i_pts;
  1253. + frames[idx]->i_reordered_pts = h->lookahead->next.list[idx]->i_pts;
  1254. }
  1255. frames[0] = h->lookahead->next.list[bframes];
  1256. - frames[0]->i_dts = h->lookahead->next.list[0]->i_pts;
  1257. + frames[0]->i_reordered_pts = h->lookahead->next.list[0]->i_pts;
  1258. memcpy( h->lookahead->next.list, frames, (bframes+1) * sizeof(x264_frame_t*) );
  1259. }
  1260. for( i = 0; i <= bframes; i++ )
  1261. diff --git a/output/flv.c b/output/flv.c
  1262. index 8a937cf..5ef5b0f 100644
  1263. --- a/output/flv.c
  1264. +++ b/output/flv.c
  1265. @@ -37,8 +37,6 @@ typedef struct
  1266. int64_t i_fps_num;
  1267. int64_t i_fps_den;
  1268. int64_t i_framenum;
  1269. - int i_init_delay;
  1270. - int i_delay_time;
  1271.  
  1272. uint64_t i_framerate_pos;
  1273. uint64_t i_duration_pos;
  1274. @@ -46,8 +44,8 @@ typedef struct
  1275. uint64_t i_bitrate_pos;
  1276.  
  1277. uint8_t b_write_length;
  1278. - int64_t i_init_delta;
  1279. - int64_t i_prev_timestamps[2];
  1280. + int64_t i_prev_dts;
  1281. + int64_t i_prev_pts;
  1282.  
  1283. int i_timebase_num;
  1284. int i_timebase_den;
  1285. @@ -146,10 +144,8 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
  1286. p_flv->i_fps_den = p_param->i_fps_den;
  1287. p_flv->i_timebase_num = p_param->i_timebase_num;
  1288. p_flv->i_timebase_den = p_param->i_timebase_den;
  1289. - p_flv->i_init_delay = p_param->i_bframe ? (p_param->i_bframe_pyramid ? 2 : 1) : 0;
  1290. p_flv->b_vfr_input = p_param->b_vfr_input;
  1291.  
  1292. -
  1293. return 0;
  1294. }
  1295.  
  1296. @@ -216,45 +212,29 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  1297. flv_hnd_t *p_flv = handle;
  1298. flv_buffer *c = p_flv->c;
  1299.  
  1300. - int64_t dts;
  1301. - int64_t cts;
  1302. - int64_t offset;
  1303. -
  1304. - if( !p_flv->i_framenum )
  1305. - p_flv->i_delay_time = p_picture->i_dts;
  1306. + int64_t dts = (int64_t)( (p_picture->i_dts * 1000 * ((double)p_flv->i_timebase_num / p_flv->i_timebase_den)) + 0.5 );
  1307. + int64_t cts = (int64_t)( (p_picture->i_pts * 1000 * ((double)p_flv->i_timebase_num / p_flv->i_timebase_den)) + 0.5 );
  1308. + int64_t offset = cts - dts;
  1309.  
  1310. - if( !p_flv->i_init_delay )
  1311. - dts = cts = (int64_t)((p_picture->i_pts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1312. - else
  1313. + if( p_flv->i_framenum )
  1314. {
  1315. - // Use DTS compression
  1316. - dts = p_picture->i_dts - p_flv->i_delay_time;
  1317. -
  1318. - if( p_flv->i_framenum == 1 )
  1319. - p_flv->i_init_delta = p_picture->i_dts - p_flv->i_delay_time;
  1320. -
  1321. - if( p_flv->i_framenum > p_flv->i_init_delay )
  1322. + int64_t prev_dts = (int64_t)( (p_flv->i_prev_dts * 1000 * ((double)p_flv->i_timebase_num / p_flv->i_timebase_den)) + 0.5 );
  1323. + int64_t prev_cts = (int64_t)( (p_flv->i_prev_pts * 1000 * ((double)p_flv->i_timebase_num / p_flv->i_timebase_den)) + 0.5 );
  1324. + if( prev_dts == dts )
  1325. {
  1326. - dts = p_flv->i_prev_timestamps[ (p_flv->i_framenum - p_flv->i_init_delay) % p_flv->i_init_delay ];
  1327. - dts = (int64_t)((dts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1328. + double fps = ((double)p_flv->i_timebase_den / p_flv->i_timebase_num) / (p_picture->i_dts - p_flv->i_prev_dts);
  1329. + fprintf( stderr, "flv [warning]: duplicate DTS %"PRId64" generated by rounding\n"
  1330. + " current internal decoding framerate: %.6f fps\n", dts, fps );
  1331. }
  1332. - else if( p_flv->i_init_delta )
  1333. + if( prev_cts == cts )
  1334. {
  1335. - // Compressed DTSs might not fit in input timescale
  1336. - double compressed_dts;
  1337. - compressed_dts = (p_flv->i_framenum * ((double)p_flv->i_init_delta / (2 * p_flv->i_init_delay)));
  1338. - dts = (int64_t)((compressed_dts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1339. + double fps = ((double)p_flv->i_timebase_den / p_flv->i_timebase_num) / (p_picture->i_pts - p_flv->i_prev_pts);
  1340. + fprintf( stderr, "flv [warning]: duplicating CTS %"PRId64" is generated by rounding\n"
  1341. + " current internal composition framerate: %.6f fps\n", cts, fps );
  1342. }
  1343. -
  1344. - p_flv->i_prev_timestamps[ p_flv->i_framenum % p_flv->i_init_delay ] = p_picture->i_dts - p_flv->i_delay_time;
  1345. -
  1346. - cts = p_picture->i_pts;
  1347. - cts = (int64_t)((cts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1348. - }
  1349. -
  1350. - offset = cts - dts;
  1351. -
  1352. - assert( cts >= dts );
  1353. + }
  1354. + p_flv->i_prev_dts = p_picture->i_dts;
  1355. + p_flv->i_prev_pts = p_picture->i_pts;
  1356.  
  1357. // A new frame - write packet header
  1358. x264_put_byte( c, FLV_TAG_TYPE_VIDEO );
  1359. diff --git a/output/mp4.c b/output/mp4.c
  1360. index 7889e4f..e3ad9c6 100644
  1361. --- a/output/mp4.c
  1362. +++ b/output/mp4.c
  1363. @@ -34,11 +34,7 @@ typedef struct
  1364. int i_time_res;
  1365. int64_t i_time_inc;
  1366. int i_numframe;
  1367. - int i_init_delay;
  1368. int i_delay_time;
  1369. -
  1370. - int64_t i_prev_timestamps[2];
  1371. - int64_t i_init_delta;
  1372. } mp4_hnd_t;
  1373.  
  1374. static void recompute_bitrate_mp4( GF_ISOFile *p_file, int i_track )
  1375. @@ -195,8 +191,6 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
  1376. p_mp4->i_time_res = p_param->i_timebase_den;
  1377. p_mp4->i_time_inc = p_param->i_timebase_num;
  1378.  
  1379. - p_mp4->i_init_delay = p_param->i_bframe ? (p_param->i_bframe_pyramid ? 2 : 1) : 0;
  1380. -
  1381. p_mp4->i_track = gf_isom_new_track( p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
  1382. p_mp4->i_time_res );
  1383.  
  1384. @@ -282,7 +276,6 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  1385. mp4_hnd_t *p_mp4 = handle;
  1386. int64_t dts;
  1387. int64_t cts;
  1388. - int32_t offset = 0;
  1389.  
  1390. memcpy( p_mp4->p_sample->data + p_mp4->p_sample->dataLength, p_nalu, i_size );
  1391. p_mp4->p_sample->dataLength += i_size;
  1392. @@ -290,27 +283,12 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  1393. if( !p_mp4->i_numframe )
  1394. p_mp4->i_delay_time = p_picture->i_dts * -1;
  1395.  
  1396. - if( !p_mp4->i_init_delay )
  1397. - dts = cts = p_picture->i_pts * p_mp4->i_time_inc;
  1398. - else
  1399. - {
  1400. - if( p_mp4->i_numframe <= p_mp4->i_init_delay )
  1401. - dts = p_picture->i_dts + p_mp4->i_delay_time;
  1402. - else
  1403. - dts = p_mp4->i_prev_timestamps[ (p_mp4->i_numframe - p_mp4->i_init_delay) % p_mp4->i_init_delay ] + p_mp4->i_delay_time;
  1404. -
  1405. - // unordered pts
  1406. - p_mp4->i_prev_timestamps[ p_mp4->i_numframe % p_mp4->i_init_delay ] = p_picture->i_dts + p_mp4->i_delay_time;
  1407. -
  1408. - dts *= p_mp4->i_time_inc;
  1409. - cts = (p_picture->i_pts + p_mp4->i_delay_time) * p_mp4->i_time_inc;
  1410. -
  1411. - offset = cts - dts;
  1412. - }
  1413. + dts = (p_picture->i_dts + p_mp4->i_delay_time) * p_mp4->i_time_inc;
  1414. + cts = (p_picture->i_pts + p_mp4->i_delay_time) * p_mp4->i_time_inc;
  1415.  
  1416. p_mp4->p_sample->IsRAP = p_picture->b_keyframe;
  1417. p_mp4->p_sample->DTS = dts;
  1418. - p_mp4->p_sample->CTS_Offset = offset;
  1419. + p_mp4->p_sample->CTS_Offset = (uint32_t)(cts - dts);
  1420. gf_isom_add_sample( p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_mp4->p_sample );
  1421.  
  1422. p_mp4->p_sample->dataLength = 0;
  1423. diff --git a/x264.c b/x264.c
  1424. index db33536..8669cb3 100644
  1425. --- a/x264.c
  1426. +++ b/x264.c
  1427. @@ -683,6 +683,7 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param
  1428. output = mp4_output;
  1429. param->b_annexb = 0;
  1430. param->b_aud = 0;
  1431. + param->b_dts_compress = 0;
  1432. param->b_repeat_headers = 0;
  1433. #else
  1434. fprintf( stderr, "x264 [error]: not compiled with MP4 output support\n" );
  1435. @@ -694,6 +695,7 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param
  1436. output = mkv_output;
  1437. param->b_annexb = 0;
  1438. param->b_aud = 0;
  1439. + param->b_dts_compress = 0;
  1440. param->b_repeat_headers = 0;
  1441. }
  1442. else if( !strcasecmp( ext, "flv" ) )
  1443. @@ -701,6 +703,7 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param
  1444. output = flv_output;
  1445. param->b_annexb = 0;
  1446. param->b_aud = 0;
  1447. + param->b_dts_compress = 1;
  1448. param->b_repeat_headers = 0;
  1449. }
  1450. else
  1451. @@ -1455,6 +1458,8 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  1452. int64_t second_largest_pts = -1;
  1453. int64_t ticks_per_frame;
  1454. double duration;
  1455. + int prev_timebase_den = param->i_timebase_den;
  1456. + int dts_compress_multiplier;
  1457.  
  1458. opt->b_progress &= param->i_log_level < X264_LOG_DEBUG;
  1459. i_frame_total = input.get_frame_total( opt->hin );
  1460. @@ -1474,6 +1479,8 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  1461.  
  1462. x264_encoder_parameters( h, param );
  1463.  
  1464. + dts_compress_multiplier = param->i_timebase_den / prev_timebase_den;
  1465. +
  1466. if( output.set_param( opt->hout, param ) )
  1467. {
  1468. fprintf( stderr, "x264 [error]: can't set outfile param\n" );
  1469. @@ -1528,7 +1535,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  1470. {
  1471. if( h->param.i_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING )
  1472. fprintf( stderr, "x264 [warning]: non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n",
  1473. - i_frame, pic.i_pts, largest_pts );
  1474. + i_frame, pic.i_pts * dts_compress_multiplier, largest_pts * dts_compress_multiplier );
  1475. else if( pts_warning_cnt == MAX_PTS_WARNING )
  1476. fprintf( stderr, "x264 [warning]: too many nonmonotonic pts warnings, suppressing further ones\n" );
  1477. pts_warning_cnt++;
  1478. @@ -1583,6 +1590,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  1479. duration = (double)param->i_fps_den / param->i_fps_num;
  1480. else
  1481. duration = (double)(2 * largest_pts - second_largest_pts) * param->i_timebase_num / param->i_timebase_den;
  1482. + duration *= dts_compress_multiplier;
  1483.  
  1484. i_end = x264_mdate();
  1485. input.picture_clean( &pic );
  1486. diff --git a/x264.h b/x264.h
  1487. index 1223df7..2550864 100644
  1488. --- a/x264.h
  1489. +++ b/x264.h
  1490. @@ -35,7 +35,7 @@
  1491.  
  1492. #include <stdarg.h>
  1493.  
  1494. -#define X264_BUILD 83
  1495. +#define X264_BUILD 84
  1496.  
  1497. /* x264_t:
  1498. * opaque handler for encoder */
  1499. @@ -316,6 +316,9 @@ typedef struct x264_param_t
  1500. int b_vfr_input; /* VFR input */
  1501. int i_timebase_num; /* Timebase numerator */
  1502. int i_timebase_den; /* Timebase denominator */
  1503. + int b_dts_compress; /* DTS compression: this algorithm eliminates negative DTS
  1504. + * by compressing them to be less than the second PTS.
  1505. + * Warning: this will change the timebase! */
  1506.  
  1507. /* Slicing parameters */
  1508. int i_slice_max_size; /* Max size per slice in bytes; includes estimated NAL overhead. */
  1509. --
  1510. 1.6.1.2
  1511.  
  1512.  
  1513. From f2e64879d5600500f539221d96df0017be6063ea Mon Sep 17 00:00:00 2001
  1514. From: Diogo Franco <diogomfranco@gmail.com>
  1515. Date: Wed, 27 Jan 2010 09:26:35 -0800
  1516. Subject: [PATCH 07/15] Fix cross-compiling with lavf, add support for ffms2.pc
  1517. Also update configure script to work with newest ffms.
  1518.  
  1519. ---
  1520. configure | 52 ++++++++++++++++++++++++++++++----------------------
  1521. 1 files changed, 30 insertions(+), 22 deletions(-)
  1522.  
  1523. diff --git a/configure b/configure
  1524. index 9f04a18..133a569 100755
  1525. --- a/configure
  1526. +++ b/configure
  1527. @@ -416,25 +416,23 @@ fi
  1528.  
  1529. if [ "$lavf_input" = "auto" ] ; then
  1530. lavf_input="no"
  1531. - if [ `${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL` ] ; then
  1532. - LAVF_LDFLAGS="$LAVF_LDFLAGS $(pkg-config --libs libavformat libavcodec libswscale)"
  1533. - LAVF_CFLAGS="$LAVF_CFLAGS $(pkg-config --cflags libavformat libavcodec libswscale)"
  1534. + if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
  1535. + LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libswscale)"
  1536. + LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libswscale)"
  1537. fi
  1538. - if [ -z "$LAVF_LDFLAGS" -a -z "$LAVF_CFLAGS" ]; then
  1539. - LAVF_LDFLAGS="-lavformat -lswscale"
  1540. + if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
  1541. + LAVF_LIBS="-lavformat -lswscale"
  1542. for lib in -lpostproc -lavcodec -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
  1543. - cc_check "" $lib && LAVF_LDFLAGS="$LAVF_LDFLAGS $lib"
  1544. + cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
  1545. done
  1546. fi
  1547. - LAVF_LDFLAGS="-L. $LAVF_LDFLAGS"
  1548. - if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LDFLAGS" && \
  1549. - cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LDFLAGS" ; then
  1550. + LAVF_LIBS="-L. $LAVF_LIBS"
  1551. + if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" && \
  1552. + cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
  1553. # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351
  1554. - if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LDFLAGS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
  1555. + if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
  1556. lavf_input="yes"
  1557. echo "#define LAVF_INPUT" >> config.h
  1558. - LDFLAGSCLI="$LDFLAGSCLI $LAVF_LDFLAGS"
  1559. - [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
  1560. else
  1561. echo "Warning: libavformat is too old, update to ffmpeg r18351+"
  1562. fi
  1563. @@ -443,19 +441,29 @@ fi
  1564.  
  1565. if [ "$ffms_input" = "auto" ] ; then
  1566. ffms_input="no"
  1567. - if [ "$lavf_input" = "yes" ] ; then
  1568. - if cc_check ffms.h -lFFMS2 "FFMS_DestroyVideoSource(0);" ; then
  1569. - ffms_input="yes"
  1570. - echo "#define FFMS_INPUT" >> config.h
  1571. - LDFLAGSCLI="$LDFLAGSCLI -lFFMS2"
  1572. - elif cc_check ffms.h "-lFFMS2 $LAVF_LDFLAGS -lstdc++" "FFMS_DestroyVideoSource(0);" ; then
  1573. - ffms_input="yes"
  1574. - echo "#define FFMS_INPUT" >> config.h
  1575. - LDFLAGSCLI="-lFFMS2 $LDFLAGSCLI -lstdc++"
  1576. - fi
  1577. + if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
  1578. + FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
  1579. + FFMS2_CFLAGS="$FFMS2_LIBS $(${cross_prefix}pkg-config --cflags ffms2)"
  1580. + fi
  1581. + [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
  1582. +
  1583. + if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
  1584. + ffms_input="yes"
  1585. + elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
  1586. + ffms_input="yes"
  1587. + FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
  1588. fi
  1589. fi
  1590.  
  1591. +if [ "$ffms_input" = "yes" ]; then
  1592. + LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
  1593. + [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
  1594. + echo "#define FFMS_INPUT" >> config.h
  1595. +elif [ "$lavf_input" = "yes" ]; then
  1596. + LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
  1597. + [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
  1598. +fi
  1599. +
  1600. MP4_LDFLAGS="-lgpac_static"
  1601. if [ $SYS = MINGW ]; then
  1602. MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
  1603. --
  1604. 1.6.1.2
  1605.  
  1606.  
  1607. From 7230dd08902de8842d4f3c50be2ea4374977e377 Mon Sep 17 00:00:00 2001
  1608. From: Diogo Franco <diogomfranco@gmail.com>
  1609. Date: Wed, 27 Jan 2010 10:12:42 -0800
  1610. Subject: [PATCH 08/15] Add config.log support
  1611. Now, if configure fails, you'll be able to see why.
  1612.  
  1613. ---
  1614. .gitignore | 1 +
  1615. configure | 106 +++++++++++++++++++++++++++++++++++++++++++++++++----------
  1616. 2 files changed, 89 insertions(+), 18 deletions(-)
  1617.  
  1618. diff --git a/.gitignore b/.gitignore
  1619. index 308b793..9d8cb70 100644
  1620. --- a/.gitignore
  1621. +++ b/.gitignore
  1622. @@ -12,6 +12,7 @@
  1623. .depend
  1624. config.h
  1625. config.mak
  1626. +config.log
  1627. x264
  1628. checkasm
  1629.  
  1630. diff --git a/configure b/configure
  1631. index 133a569..7cb14ba 100755
  1632. --- a/configure
  1633. +++ b/configure
  1634. @@ -27,24 +27,77 @@ echo ""
  1635. exit 1
  1636. fi
  1637.  
  1638. +log_check() {
  1639. + echo -n "checking $1... " >> config.log
  1640. +}
  1641. +
  1642. +log_ok() {
  1643. + echo "yes" >> config.log
  1644. +}
  1645. +
  1646. +log_fail() {
  1647. + echo "no" >> config.log
  1648. +}
  1649. +
  1650. +log_msg() {
  1651. + echo "$1" >> config.log
  1652. +}
  1653. +
  1654. cc_check() {
  1655. + if [ -z "$3" ]; then
  1656. + if [ -z "$1" ]; then
  1657. + log_check "whether $CC works"
  1658. + else
  1659. + log_check "for $1"
  1660. + fi
  1661. + elif [ -z "$1" ]; then
  1662. + log_check "whether $CC supports $3"
  1663. + else
  1664. + log_check "for $3 on $1";
  1665. + fi
  1666. rm -f conftest.c
  1667. [ -n "$1" ] && echo "#include <$1>" > conftest.c
  1668. echo "int main () { $3 return 0; }" >> conftest.c
  1669. - $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest 2>$DEVNULL
  1670. + if $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest >conftest.log 2>&1; then
  1671. + res=$?
  1672. + log_ok
  1673. + else
  1674. + res=$?
  1675. + log_fail
  1676. + log_msg "Failed commandline was:"
  1677. + log_msg "--------------------------------------------------"
  1678. + log_msg "$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2"
  1679. + cat conftest.log >> config.log
  1680. + log_msg "--------------------------------------------------"
  1681. + fi
  1682. + return $res
  1683. }
  1684.  
  1685. as_check() {
  1686. + log_check "whether $AS supports $1"
  1687. echo "$1" > conftest.asm
  1688. - $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
  1689. + if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
  1690. + res=$?
  1691. + log_ok
  1692. + else
  1693. + res=$?
  1694. + log_fail
  1695. + log_msg "Failed commandline was:"
  1696. + log_msg "--------------------------------------------------"
  1697. + log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
  1698. + cat conftest.log >> config.log
  1699. + log_msg "--------------------------------------------------"
  1700. + fi
  1701. + return $res
  1702. }
  1703.  
  1704. die() {
  1705. + log_msg "DIED: $@"
  1706. echo "$@"
  1707. exit 1
  1708. }
  1709.  
  1710. -rm -f config.h config.mak x264.pc conftest*
  1711. +rm -f config.h config.mak config.log x264.pc conftest*
  1712.  
  1713. prefix='/usr/local'
  1714. exec_prefix='${prefix}'
  1715. @@ -320,6 +373,16 @@ case $host_cpu in
  1716. ;;
  1717. esac
  1718.  
  1719. +log_msg "x264 configure script"
  1720. +if [ -n "$*" ]; then
  1721. + msg="Command line options:"
  1722. + for i in $@; do
  1723. + msg="$msg \"$i\""
  1724. + done
  1725. + log_msg "$msg"
  1726. +fi
  1727. +log_msg ""
  1728. +
  1729. # check requirements
  1730.  
  1731. cc_check || die "No working C compiler found."
  1732. @@ -506,9 +569,9 @@ if [ "$debug" = "yes" ]; then
  1733. elif [ $ARCH = ARM ]; then
  1734. # arm-gcc-4.2 produces incorrect output with -ffast-math
  1735. # and it doesn't save any speed anyway on 4.4, so disable it
  1736. - CFLAGS="-O4 -fno-fast-math $CFLAGS"
  1737. + CFLAGS="-O3 -fno-fast-math $CFLAGS"
  1738. else
  1739. - CFLAGS="-O4 -ffast-math $CFLAGS"
  1740. + CFLAGS="-O3 -ffast-math $CFLAGS"
  1741. fi
  1742.  
  1743. if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
  1744. @@ -585,20 +648,27 @@ Libs: $pclibs
  1745. Cflags: -I$includedir
  1746. EOF
  1747.  
  1748. +cat > conftest.log <<EOF
  1749. +Platform: $ARCH
  1750. +System: $SYS
  1751. +asm: $asm
  1752. +avs input: $avs_input
  1753. +lavf input: $lavf_input
  1754. +ffms input: $ffms_input
  1755. +mp4 output: $mp4_output
  1756. +pthread: $pthread
  1757. +debug: $debug
  1758. +gprof: $gprof
  1759. +PIC: $pic
  1760. +shared: $shared
  1761. +visualize: $vis
  1762. +EOF
  1763. +
  1764. +echo >> config.log
  1765. +cat conftest.log >> config.log
  1766. +cat conftest.log
  1767. +rm conftest.log
  1768.  
  1769. -echo "Platform: $ARCH"
  1770. -echo "System: $SYS"
  1771. -echo "asm: $asm"
  1772. -echo "avs input: $avs_input"
  1773. -echo "lavf input: $lavf_input"
  1774. -echo "ffms input: $ffms_input"
  1775. -echo "mp4 output: $mp4_output"
  1776. -echo "pthread: $pthread"
  1777. -echo "debug: $debug"
  1778. -echo "gprof: $gprof"
  1779. -echo "PIC: $pic"
  1780. -echo "shared: $shared"
  1781. -echo "visualize: $vis"
  1782. echo
  1783. echo "You can run 'make' or 'make fprofiled' now."
  1784.  
  1785. --
  1786. 1.6.1.2
  1787.  
  1788.  
  1789. From 672c417412f70ef65e81d5cfe6116d0e4500147b Mon Sep 17 00:00:00 2001
  1790. From: Diogo Franco <diogomfranco@gmail.com>
  1791. Date: Wed, 27 Jan 2010 13:11:08 -0800
  1792. Subject: [PATCH 09/15] Add configure check for log2 support
  1793. Some incredibly braindamaged operating systems, such as FreeBSD, blatantly ignore the C specification and omit certain functions that are required by ISO C.
  1794. log2f is one of these functions that periodically goes missing in such operating systems.
  1795.  
  1796. ---
  1797. common/osdep.h | 4 ++++
  1798. configure | 4 ++++
  1799. 2 files changed, 8 insertions(+), 0 deletions(-)
  1800.  
  1801. diff --git a/common/osdep.h b/common/osdep.h
  1802. index abae9ac..9988803 100644
  1803. --- a/common/osdep.h
  1804. +++ b/common/osdep.h
  1805. @@ -34,6 +34,10 @@
  1806. #include <inttypes.h>
  1807. #endif
  1808.  
  1809. +#ifndef HAVE_LOG2F
  1810. +#define log2f(x) (logf((x))/0.693147180559945f)
  1811. +#endif
  1812. +
  1813. #ifdef _WIN32
  1814. #include <io.h> // _setmode()
  1815. #include <fcntl.h> // _O_BINARY
  1816. diff --git a/configure b/configure
  1817. index 7cb14ba..271d919 100755
  1818. --- a/configure
  1819. +++ b/configure
  1820. @@ -477,6 +477,10 @@ if test "$pthread" = "yes" ; then
  1821. LDFLAGS="$LDFLAGS $libpthread"
  1822. fi
  1823.  
  1824. +if cc_check "math.h" "-Werror" "log2f(2);" ; then
  1825. + CFLAGS="$CFLAGS -DHAVE_LOG2F"
  1826. +fi
  1827. +
  1828. if [ "$lavf_input" = "auto" ] ; then
  1829. lavf_input="no"
  1830. if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
  1831. --
  1832. 1.6.1.2
  1833.  
  1834.  
  1835. From 8a869c92d8976633c04577455b449ebef3e07cfd Mon Sep 17 00:00:00 2001
  1836. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  1837. Date: Wed, 27 Jan 2010 19:41:27 -0800
  1838. Subject: [PATCH 10/15] Fix implicit CBR message to only print when in ABR mode
  1839. Also make it print outside of debug mode.
  1840.  
  1841. ---
  1842. encoder/ratecontrol.c | 12 ++++++++++--
  1843. 1 files changed, 10 insertions(+), 2 deletions(-)
  1844.  
  1845. diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
  1846. index 746b17a..5304616 100644
  1847. --- a/encoder/ratecontrol.c
  1848. +++ b/encoder/ratecontrol.c
  1849. @@ -436,8 +436,16 @@ int x264_ratecontrol_new( x264_t *h )
  1850. }
  1851. else if( h->param.rc.i_vbv_max_bitrate == 0 )
  1852. {
  1853. - x264_log( h, X264_LOG_DEBUG, "VBV maxrate unspecified, assuming CBR\n" );
  1854. - h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  1855. + if( h->param.rc.i_rc_method == X264_RC_ABR )
  1856. + {
  1857. + x264_log( h, X264_LOG_INFO, "VBV maxrate unspecified, assuming CBR\n" );
  1858. + h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  1859. + }
  1860. + else
  1861. + {
  1862. + x264_log( h, X264_LOG_INFO, "VBV bufsize set but maxrate unspecified, ignored\n" );
  1863. + h->param.rc.i_vbv_buffer_size = 0;
  1864. + }
  1865. }
  1866. }
  1867. if( h->param.rc.i_vbv_max_bitrate < h->param.rc.i_bitrate &&
  1868. --
  1869. 1.6.1.2
  1870.  
  1871.  
  1872. From 297a8c4712c1241fcae6e152ab7351649eaf3f5c Mon Sep 17 00:00:00 2001
  1873. From: Diogo Franco <diogomfranco@gmail.com>
  1874. Date: Wed, 27 Jan 2010 20:29:50 -0800
  1875. Subject: [PATCH 11/15] Implement ffms2 version check
  1876. Depends on ffms2 version 2.13.1 (r272).
  1877. Tries pkg-config's built-in version checking first.
  1878. Uses only the preprocessor to avoid cross-compilation issues.
  1879.  
  1880. ---
  1881. configure | 20 +++++++++++++++++++-
  1882. 1 files changed, 19 insertions(+), 1 deletions(-)
  1883.  
  1884. diff --git a/configure b/configure
  1885. index 271d919..adebdb8 100755
  1886. --- a/configure
  1887. +++ b/configure
  1888. @@ -507,10 +507,17 @@ if [ "$lavf_input" = "auto" ] ; then
  1889. fi
  1890.  
  1891. if [ "$ffms_input" = "auto" ] ; then
  1892. + ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
  1893. +
  1894. ffms_input="no"
  1895. - if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
  1896. + [ $ffms_micro -gt 0 -o $ffms_bump -gt 0 ] && vmicro=".$ffms_micro"
  1897. + [ $ffms_bump -gt 0 ] && vbump=".$ffms_bump"
  1898. + if ${cross_prefix}pkg-config --atleast-version="$ffms_major.$ffms_minor$vmicro$vbump" ffms2 2>$DEVNULL; then
  1899. FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
  1900. FFMS2_CFLAGS="$FFMS2_LIBS $(${cross_prefix}pkg-config --cflags ffms2)"
  1901. + api_check="no"
  1902. + else
  1903. + api_check="yes"
  1904. fi
  1905. [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
  1906.  
  1907. @@ -520,6 +527,17 @@ if [ "$ffms_input" = "auto" ] ; then
  1908. ffms_input="yes"
  1909. FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
  1910. fi
  1911. +
  1912. + if [ $api_check = "yes" -a $ffms_input = "yes" ]; then
  1913. + log_check "whether ffms2 version is at least $ffms_major.$ffms_minor$vmicro$vbump"
  1914. + $CC $CFLAGS $FFMS2_CFLAGS -c -o conftest -x c - >$DEVNULL 2>&1 <<EOF
  1915. +#include <ffms.h>
  1916. +#if FFMS_VERSION < (($ffms_major << 24) | ($ffms_minor << 16) | ($ffms_micro << 8) | $ffms_bump)
  1917. +#error Requires ffms2 version 2.13.1
  1918. +#endif
  1919. +EOF
  1920. + [ $? = 0 ] && log_ok || { ffms_input="no"; log_fail; }
  1921. + fi
  1922. fi
  1923.  
  1924. if [ "$ffms_input" = "yes" ]; then
  1925. --
  1926. 1.6.1.2
  1927.  
  1928.  
  1929. From c410a86ab22f580f7be3148e38eec087e4f386ce Mon Sep 17 00:00:00 2001
  1930. From: Steven Walters <kemuri9@gmail.com>
  1931. Date: Thu, 28 Jan 2010 17:26:40 -0800
  1932. Subject: [PATCH 12/15] Fix stat with large file support
  1933.  
  1934. ---
  1935. common/common.h | 1 -
  1936. common/osdep.h | 1 +
  1937. 2 files changed, 1 insertions(+), 1 deletions(-)
  1938.  
  1939. diff --git a/common/common.h b/common/common.h
  1940. index db61ad4..b92b4e0 100644
  1941. --- a/common/common.h
  1942. +++ b/common/common.h
  1943. @@ -70,7 +70,6 @@ do {\
  1944. /****************************************************************************
  1945. * Includes
  1946. ****************************************************************************/
  1947. -#include <sys/stat.h>
  1948. #include "osdep.h"
  1949. #include <stdarg.h>
  1950. #include <stddef.h>
  1951. diff --git a/common/osdep.h b/common/osdep.h
  1952. index 9988803..3d12072 100644
  1953. --- a/common/osdep.h
  1954. +++ b/common/osdep.h
  1955. @@ -27,6 +27,7 @@
  1956. #define _LARGEFILE_SOURCE 1
  1957. #define _FILE_OFFSET_BITS 64
  1958. #include <stdio.h>
  1959. +#include <sys/stat.h>
  1960.  
  1961. #ifdef HAVE_STDINT_H
  1962. #include <stdint.h>
  1963. --
  1964. 1.6.1.2
  1965.  
  1966.  
  1967. From 50a70f3ae50a56a6a8d1b434748de1a0275436d4 Mon Sep 17 00:00:00 2001
  1968. From: Diogo Franco <diogomfranco@gmail.com>
  1969. Date: Thu, 28 Jan 2010 17:28:03 -0800
  1970. Subject: [PATCH 13/15] Move -D CFLAGS to config.h
  1971.  
  1972. ---
  1973. Makefile | 12 +++++-----
  1974. common/common.h | 1 -
  1975. common/osdep.h | 2 +
  1976. configure | 60 ++++++++++++++++++++++++++++++------------------------
  1977. 4 files changed, 41 insertions(+), 34 deletions(-)
  1978.  
  1979. diff --git a/Makefile b/Makefile
  1980. index f643228..cef8725 100644
  1981. --- a/Makefile
  1982. +++ b/Makefile
  1983. @@ -18,26 +18,26 @@ SRCCLI = x264.c input/yuv.c input/y4m.c output/raw.c \
  1984.  
  1985. SRCSO =
  1986.  
  1987. -MUXERS := $(shell grep -E "(IN|OUT)PUT" config.h)
  1988. +CONFIG := $(shell cat config.h)
  1989.  
  1990. # Optional muxer module sources
  1991. -ifneq ($(findstring AVS_INPUT, $(MUXERS)),)
  1992. +ifneq ($(findstring AVS_INPUT, $(CONFIG)),)
  1993. SRCCLI += input/avs.c
  1994. endif
  1995.  
  1996. -ifneq ($(findstring HAVE_PTHREAD, $(CFLAGS)),)
  1997. +ifneq ($(findstring HAVE_PTHREAD, $(CONFIG)),)
  1998. SRCCLI += input/thread.c
  1999. endif
  2000.  
  2001. -ifneq ($(findstring LAVF_INPUT, $(MUXERS)),)
  2002. +ifneq ($(findstring LAVF_INPUT, $(CONFIG)),)
  2003. SRCCLI += input/lavf.c
  2004. endif
  2005.  
  2006. -ifneq ($(findstring FFMS_INPUT, $(MUXERS)),)
  2007. +ifneq ($(findstring FFMS_INPUT, $(CONFIG)),)
  2008. SRCCLI += input/ffms.c
  2009. endif
  2010.  
  2011. -ifneq ($(findstring MP4_OUTPUT, $(MUXERS)),)
  2012. +ifneq ($(findstring MP4_OUTPUT, $(CONFIG)),)
  2013. SRCCLI += output/mp4.c
  2014. endif
  2015.  
  2016. diff --git a/common/common.h b/common/common.h
  2017. index b92b4e0..628ae33 100644
  2018. --- a/common/common.h
  2019. +++ b/common/common.h
  2020. @@ -102,7 +102,6 @@ typedef union { uint64_t i; uint32_t a[2]; uint16_t b[4]; uint8_t c[8]; } MAY_AL
  2021. #include "dct.h"
  2022. #include "cabac.h"
  2023. #include "quant.h"
  2024. -#include "config.h"
  2025.  
  2026. /****************************************************************************
  2027. * General functions
  2028. diff --git a/common/osdep.h b/common/osdep.h
  2029. index 3d12072..907bcee 100644
  2030. --- a/common/osdep.h
  2031. +++ b/common/osdep.h
  2032. @@ -29,6 +29,8 @@
  2033. #include <stdio.h>
  2034. #include <sys/stat.h>
  2035.  
  2036. +#include "config.h"
  2037. +
  2038. #ifdef HAVE_STDINT_H
  2039. #include <stdint.h>
  2040. #else
  2041. diff --git a/configure b/configure
  2042. index adebdb8..3bb5a40 100755
  2043. --- a/configure
  2044. +++ b/configure
  2045. @@ -91,6 +91,10 @@ as_check() {
  2046. return $res
  2047. }
  2048.  
  2049. +define() {
  2050. + echo "#define $1$([ -n "$2" ] && echo " $2")" >> config.h
  2051. +}
  2052. +
  2053. die() {
  2054. log_msg "DIED: $@"
  2055. echo "$@"
  2056. @@ -208,7 +212,7 @@ for opt do
  2057. ;;
  2058. --enable-visualize)
  2059. LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
  2060. - CFLAGS="$CFLAGS -DVISUALIZE=1"
  2061. + define VISUALIZE
  2062. vis="yes"
  2063. ;;
  2064. --host=*)
  2065. @@ -243,7 +247,7 @@ host_os="${host#*-}"
  2066. case $host_os in
  2067. beos*)
  2068. SYS="BEOS"
  2069. - CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
  2070. + define HAVE_MALLOC_H
  2071. ;;
  2072. darwin*)
  2073. SYS="MACOSX"
  2074. @@ -259,7 +263,7 @@ case $host_os in
  2075. ;;
  2076. kfreebsd*-gnu)
  2077. SYS="FREEBSD"
  2078. - CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
  2079. + define HAVE_MALLOC_H
  2080. LDFLAGS="$LDFLAGS -lm"
  2081. ;;
  2082. netbsd*)
  2083. @@ -273,7 +277,7 @@ case $host_os in
  2084. ;;
  2085. *linux*)
  2086. SYS="LINUX"
  2087. - CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
  2088. + define HAVE_MALLOC_H
  2089. LDFLAGS="$LDFLAGS -lm"
  2090. ;;
  2091. cygwin*)
  2092. @@ -292,7 +296,7 @@ case $host_os in
  2093. ;;
  2094. sunos*|solaris*)
  2095. SYS="SunOS"
  2096. - CFLAGS="$CFLAGS -DHAVE_MALLOC_H"
  2097. + define HAVE_MALLOC_H
  2098. LDFLAGS="$LDFLAGS -lm"
  2099. HAVE_GETOPT_LONG=0
  2100. ;;
  2101. @@ -341,7 +345,8 @@ case $host_cpu in
  2102. then
  2103. CFLAGS="$CFLAGS -faltivec -fastf -mcpu=G4"
  2104. else
  2105. - CFLAGS="$CFLAGS -maltivec -mabi=altivec -DHAVE_ALTIVEC_H"
  2106. + CFLAGS="$CFLAGS -maltivec -mabi=altivec"
  2107. + define HAVE_ALTIVEC_H
  2108. fi
  2109. ;;
  2110. sparc)
  2111. @@ -407,17 +412,17 @@ if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
  2112. echo "If you really want to compile without asm, configure with --disable-asm."
  2113. exit 1
  2114. fi
  2115. - CFLAGS="$CFLAGS -DHAVE_MMX"
  2116. + define HAVE_MMX
  2117. fi
  2118.  
  2119. if [ $asm = yes -a $ARCH = ARM ] ; then
  2120. # set flags so neon is built by default
  2121. echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu|-mfloat-abi)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
  2122.  
  2123. - if cc_check '' '' 'asm("rev ip, ip");' ; then CFLAGS="$CFLAGS -DHAVE_ARMV6"
  2124. - cc_check '' '' 'asm("movt r0, #0");' && CFLAGS="$CFLAGS -DHAVE_ARMV6T2"
  2125. - cc_check '' '' 'asm("vadd.i16 q0, q0, q0");' && CFLAGS="$CFLAGS -DHAVE_NEON"
  2126. - ASFLAGS="$ASFLAGS $CFLAGS -c"
  2127. + if cc_check '' '' 'asm("rev ip, ip");' ; then define HAVE_ARMV6 && ASFLAGS="$ASFLAGS -DHAVE_ARMV6"
  2128. + cc_check '' '' 'asm("movt r0, #0");' && define HAVE_ARMV6T2 && ASFLAGS="$ASFLAGS -DHAVE_ARMV6T2"
  2129. + cc_check '' '' 'asm("vadd.i16 q0, q0, q0");' && define HAVE_NEON && ASFLAGS="$ASFLAGS -DHAVE_NEON"
  2130. + ASFLAGS="$ASFLAGS -c"
  2131. else
  2132. echo "You specified a pre-ARMv6 or Thumb-1 CPU in your CFLAGS."
  2133. echo "If you really want to run on such a CPU, configure with --disable-asm."
  2134. @@ -428,12 +433,13 @@ fi
  2135. [ $asm = no ] && AS=""
  2136. [ "x$AS" = x ] && asm="no"
  2137.  
  2138. -CFLAGS="$CFLAGS -DARCH_$ARCH -DSYS_$SYS"
  2139. +define ARCH_$ARCH
  2140. +define SYS_$SYS
  2141.  
  2142. echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c
  2143. $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed"
  2144. if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then
  2145. - CFLAGS="$CFLAGS -DWORDS_BIGENDIAN"
  2146. + define WORDS_BIGENDIAN
  2147. elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then
  2148. die "endian test failed"
  2149. fi
  2150. @@ -457,11 +463,11 @@ if test "$pthread" = "auto" ; then
  2151. elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
  2152. pthread="yes"
  2153. libpthread="-lpthreadGC2 -lwsock32"
  2154. - CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
  2155. + define PTW32_STATIC_LIB
  2156. elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
  2157. pthread="yes"
  2158. libpthread="-lpthreadGC2 -lws2_32"
  2159. - CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
  2160. + define PTW32_STATIC_LIB
  2161. fi
  2162. ;;
  2163. OPENBSD)
  2164. @@ -473,12 +479,12 @@ if test "$pthread" = "auto" ; then
  2165. esac
  2166. fi
  2167. if test "$pthread" = "yes" ; then
  2168. - CFLAGS="$CFLAGS -DHAVE_PTHREAD"
  2169. + define HAVE_PTHREAD
  2170. LDFLAGS="$LDFLAGS $libpthread"
  2171. fi
  2172.  
  2173. if cc_check "math.h" "-Werror" "log2f(2);" ; then
  2174. - CFLAGS="$CFLAGS -DHAVE_LOG2F"
  2175. + define HAVE_LOG2F
  2176. fi
  2177.  
  2178. if [ "$lavf_input" = "auto" ] ; then
  2179. @@ -499,7 +505,7 @@ if [ "$lavf_input" = "auto" ] ; then
  2180. # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351
  2181. if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
  2182. lavf_input="yes"
  2183. - echo "#define LAVF_INPUT" >> config.h
  2184. + define LAVF_INPUT
  2185. else
  2186. echo "Warning: libavformat is too old, update to ffmpeg r18351+"
  2187. fi
  2188. @@ -543,7 +549,7 @@ fi
  2189. if [ "$ffms_input" = "yes" ]; then
  2190. LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
  2191. [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
  2192. - echo "#define FFMS_INPUT" >> config.h
  2193. + define FFMS_INPUT
  2194. elif [ "$lavf_input" = "yes" ]; then
  2195. LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
  2196. [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
  2197. @@ -558,7 +564,7 @@ if [ "$mp4_output" = "auto" ] ; then
  2198. cc_check gpac/isomedia.h "$MP4_LDFLAGS" && mp4_output="yes"
  2199. fi
  2200. if [ "$mp4_output" = "yes" ] ; then
  2201. - echo "#define MP4_OUTPUT" >> config.h
  2202. + define MP4_OUTPUT
  2203. LDFLAGSCLI="$LDFLAGSCLI $MP4_LDFLAGS"
  2204. fi
  2205.  
  2206. @@ -566,11 +572,11 @@ if [ "$avs_input" = "auto" ] ; then
  2207. avs_input=no
  2208. if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then
  2209. avs_input="yes"
  2210. - echo "#define AVS_INPUT" >> config.h
  2211. - echo "#define HAVE_AVISYNTH_C_H" >> config.h
  2212. + define AVS_INPUT
  2213. + define HAVE_AVISYNTH_C_H
  2214. elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then
  2215. avs_input="yes"
  2216. - echo "#define AVS_INPUT" >> config.h
  2217. + define AVS_INPUT
  2218. fi
  2219. fi
  2220.  
  2221. @@ -597,11 +603,11 @@ else
  2222. fi
  2223.  
  2224. if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
  2225. - echo "#define fseek fseeko" >> config.h
  2226. - echo "#define ftell ftello" >> config.h
  2227. + define fseek fseeko
  2228. + define ftell ftello
  2229. elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then
  2230. - echo "#define fseek fseeko64" >> config.h
  2231. - echo "#define ftell ftello64" >> config.h
  2232. + define fseek fseeko64
  2233. + define ftell ftello64
  2234. fi
  2235.  
  2236. rm -f conftest*
  2237. --
  2238. 1.6.1.2
  2239.  
  2240.  
  2241. From 9b35d680c35372ef4380afeb47d963d33bf5195e Mon Sep 17 00:00:00 2001
  2242. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  2243. Date: Fri, 29 Jan 2010 02:40:41 -0800
  2244. Subject: [PATCH 14/15] Add ability to adjust ratecontrol parameters on the fly
  2245. encoder_reconfig and x264_picture_t->param can now be used to change ratecontrol parameters.
  2246. This is extraordinarily useful in certain streaming situations where the encoder needs to adapt the bitrate to network circumstances.
  2247.  
  2248. What can be changed:
  2249. 1) CRF can be adjusted if in CRF mode.
  2250. 2) VBV maxrate and bufsize can be adjusted if in VBV mode.
  2251. 3) Bitrate can be adjusted if in CBR mode.
  2252. However, x264 cannot switch between modes and cannot change bitrate in ABR mode.
  2253.  
  2254. Commit sponsored by SayMama video calling.
  2255. ---
  2256. encoder/encoder.c | 55 +++++++++++++++++++-
  2257. encoder/ratecontrol.c | 137 +++++++++++++++++++++++-------------------------
  2258. encoder/ratecontrol.h | 2 +
  2259. x264.h | 7 ++-
  2260. 4 files changed, 125 insertions(+), 76 deletions(-)
  2261.  
  2262. diff --git a/encoder/encoder.c b/encoder/encoder.c
  2263. index 0a16a6b..cd763ab 100644
  2264. --- a/encoder/encoder.c
  2265. +++ b/encoder/encoder.c
  2266. @@ -507,6 +507,39 @@ static int x264_validate_parameters( x264_t *h )
  2267. }
  2268. h->param.rc.i_qp_max = x264_clip3( h->param.rc.i_qp_max, 0, 51 );
  2269. h->param.rc.i_qp_min = x264_clip3( h->param.rc.i_qp_min, 0, h->param.rc.i_qp_max );
  2270. + if( h->param.rc.i_vbv_buffer_size )
  2271. + {
  2272. + if( h->param.rc.i_rc_method == X264_RC_CQP )
  2273. + {
  2274. + x264_log(h, X264_LOG_WARNING, "VBV is incompatible with constant QP, ignored.\n");
  2275. + h->param.rc.i_vbv_max_bitrate = 0;
  2276. + h->param.rc.i_vbv_buffer_size = 0;
  2277. + }
  2278. + else if( h->param.rc.i_vbv_max_bitrate == 0 )
  2279. + {
  2280. + if( h->param.rc.i_rc_method == X264_RC_ABR )
  2281. + {
  2282. + x264_log( h, X264_LOG_INFO, "VBV maxrate unspecified, assuming CBR\n" );
  2283. + h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  2284. + }
  2285. + else
  2286. + {
  2287. + x264_log( h, X264_LOG_INFO, "VBV bufsize set but maxrate unspecified, ignored\n" );
  2288. + h->param.rc.i_vbv_buffer_size = 0;
  2289. + }
  2290. + }
  2291. + else if( h->param.rc.i_vbv_max_bitrate < h->param.rc.i_bitrate &&
  2292. + h->param.rc.i_vbv_max_bitrate > 0 )
  2293. + {
  2294. + x264_log(h, X264_LOG_WARNING, "max bitrate less than average bitrate, ignored.\n");
  2295. + h->param.rc.i_vbv_max_bitrate = 0;
  2296. + }
  2297. + }
  2298. + else if( h->param.rc.i_vbv_max_bitrate )
  2299. + {
  2300. + x264_log(h, X264_LOG_WARNING, "VBV maxrate specified, but no bufsize.\n");
  2301. + h->param.rc.i_vbv_max_bitrate = 0;
  2302. + }
  2303.  
  2304. int max_slices = (h->param.i_height+((16<<h->param.b_interlaced)-1))/(16<<h->param.b_interlaced);
  2305. if( h->param.b_sliced_threads )
  2306. @@ -1071,7 +1104,7 @@ fail:
  2307. ****************************************************************************/
  2308. int x264_encoder_reconfig( x264_t *h, x264_param_t *param )
  2309. {
  2310. - h = h->thread[h->i_thread_phase];
  2311. + h = h->thread[h->thread[0]->i_thread_phase];
  2312. x264_set_aspect_ratio( h, param, 0 );
  2313. #define COPY(var) h->param.var = param->var
  2314. COPY( i_frame_reference ); // but never uses more refs than initially specified
  2315. @@ -1110,11 +1143,29 @@ int x264_encoder_reconfig( x264_t *h, x264_param_t *param )
  2316. COPY( i_slice_max_size );
  2317. COPY( i_slice_max_mbs );
  2318. COPY( i_slice_count );
  2319. + /* VBV can't be turned on if it wasn't on to begin with */
  2320. + if( h->param.rc.i_vbv_max_bitrate > 0 && h->param.rc.i_vbv_buffer_size > 0 )
  2321. + {
  2322. + COPY( rc.i_vbv_max_bitrate );
  2323. + COPY( rc.i_vbv_buffer_size );
  2324. + COPY( rc.i_bitrate );
  2325. + }
  2326. + COPY( rc.f_rf_constant );
  2327. #undef COPY
  2328.  
  2329. mbcmp_init( h );
  2330.  
  2331. - return x264_validate_parameters( h );
  2332. + int failure = x264_validate_parameters( h );
  2333. +
  2334. + /* Supported reconfiguration options (1-pass only):
  2335. + * vbv-maxrate
  2336. + * vbv-bufsize
  2337. + * crf
  2338. + * bitrate (CBR only) */
  2339. + if( !failure )
  2340. + x264_ratecontrol_init_reconfigurable( h, 0 );
  2341. +
  2342. + return failure;
  2343. }
  2344.  
  2345. /****************************************************************************
  2346. diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
  2347. index 5304616..19bc258 100644
  2348. --- a/encoder/ratecontrol.c
  2349. +++ b/encoder/ratecontrol.c
  2350. @@ -388,6 +388,53 @@ static char *x264_strcat_filename( char *input, char *suffix )
  2351. return output;
  2352. }
  2353.  
  2354. +void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init )
  2355. +{
  2356. + x264_ratecontrol_t *rc = h->rc;
  2357. + if( !b_init && rc->b_2pass )
  2358. + return;
  2359. +
  2360. + if( h->param.rc.i_vbv_max_bitrate > 0 && h->param.rc.i_vbv_buffer_size > 0 )
  2361. + {
  2362. + if( h->param.rc.i_vbv_buffer_size < (int)(h->param.rc.i_vbv_max_bitrate / rc->fps) )
  2363. + {
  2364. + h->param.rc.i_vbv_buffer_size = h->param.rc.i_vbv_max_bitrate / rc->fps;
  2365. + x264_log( h, X264_LOG_WARNING, "VBV buffer size cannot be smaller than one frame, using %d kbit\n",
  2366. + h->param.rc.i_vbv_buffer_size );
  2367. + }
  2368. +
  2369. + /* We don't support changing the ABR bitrate right now,
  2370. + so if the stream starts as CBR, keep it CBR. */
  2371. + if( rc->b_vbv_min_rate )
  2372. + h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  2373. + rc->buffer_rate = h->param.rc.i_vbv_max_bitrate * 1000. / rc->fps;
  2374. + rc->buffer_size = h->param.rc.i_vbv_buffer_size * 1000.;
  2375. + rc->single_frame_vbv = rc->buffer_rate * 1.1 > rc->buffer_size;
  2376. + rc->cbr_decay = 1.0 - rc->buffer_rate / rc->buffer_size
  2377. + * 0.5 * X264_MAX(0, 1.5 - rc->buffer_rate * rc->fps / rc->bitrate);
  2378. + if( b_init )
  2379. + {
  2380. + if( h->param.rc.f_vbv_buffer_init > 1. )
  2381. + h->param.rc.f_vbv_buffer_init = x264_clip3f( h->param.rc.f_vbv_buffer_init / h->param.rc.i_vbv_buffer_size, 0, 1 );
  2382. + h->param.rc.f_vbv_buffer_init = X264_MAX( h->param.rc.f_vbv_buffer_init, rc->buffer_rate / rc->buffer_size );
  2383. + rc->buffer_fill_final = rc->buffer_size * h->param.rc.f_vbv_buffer_init;
  2384. + rc->b_vbv = 1;
  2385. + rc->b_vbv_min_rate = !rc->b_2pass
  2386. + && h->param.rc.i_rc_method == X264_RC_ABR
  2387. + && h->param.rc.i_vbv_max_bitrate <= h->param.rc.i_bitrate;
  2388. + }
  2389. + }
  2390. + if( h->param.rc.i_rc_method == X264_RC_CRF )
  2391. + {
  2392. + /* Arbitrary rescaling to make CRF somewhat similar to QP.
  2393. + * Try to compensate for MB-tree's effects as well. */
  2394. + double base_cplx = h->mb.i_mb_count * (h->param.i_bframe ? 120 : 80);
  2395. + double mbtree_offset = h->param.rc.b_mb_tree ? (1.0-h->param.rc.f_qcompress)*13.5 : 0;
  2396. + rc->rate_factor_constant = pow( base_cplx, 1 - rc->qcompress )
  2397. + / qp2qscale( h->param.rc.f_rf_constant + mbtree_offset );
  2398. + }
  2399. +}
  2400. +
  2401. int x264_ratecontrol_new( x264_t *h )
  2402. {
  2403. x264_ratecontrol_t *rc;
  2404. @@ -426,60 +473,10 @@ int x264_ratecontrol_new( x264_t *h )
  2405. x264_log(h, X264_LOG_ERROR, "constant rate-factor is incompatible with 2pass.\n");
  2406. return -1;
  2407. }
  2408. - if( h->param.rc.i_vbv_buffer_size )
  2409. - {
  2410. - if( h->param.rc.i_rc_method == X264_RC_CQP )
  2411. - {
  2412. - x264_log(h, X264_LOG_WARNING, "VBV is incompatible with constant QP, ignored.\n");
  2413. - h->param.rc.i_vbv_max_bitrate = 0;
  2414. - h->param.rc.i_vbv_buffer_size = 0;
  2415. - }
  2416. - else if( h->param.rc.i_vbv_max_bitrate == 0 )
  2417. - {
  2418. - if( h->param.rc.i_rc_method == X264_RC_ABR )
  2419. - {
  2420. - x264_log( h, X264_LOG_INFO, "VBV maxrate unspecified, assuming CBR\n" );
  2421. - h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  2422. - }
  2423. - else
  2424. - {
  2425. - x264_log( h, X264_LOG_INFO, "VBV bufsize set but maxrate unspecified, ignored\n" );
  2426. - h->param.rc.i_vbv_buffer_size = 0;
  2427. - }
  2428. - }
  2429. - }
  2430. - if( h->param.rc.i_vbv_max_bitrate < h->param.rc.i_bitrate &&
  2431. - h->param.rc.i_vbv_max_bitrate > 0)
  2432. - x264_log(h, X264_LOG_WARNING, "max bitrate less than average bitrate, ignored.\n");
  2433. - else if( h->param.rc.i_vbv_max_bitrate > 0 &&
  2434. - h->param.rc.i_vbv_buffer_size > 0 )
  2435. - {
  2436. - if( h->param.rc.i_vbv_buffer_size < (int)(h->param.rc.i_vbv_max_bitrate / rc->fps) )
  2437. - {
  2438. - h->param.rc.i_vbv_buffer_size = h->param.rc.i_vbv_max_bitrate / rc->fps;
  2439. - x264_log( h, X264_LOG_WARNING, "VBV buffer size cannot be smaller than one frame, using %d kbit\n",
  2440. - h->param.rc.i_vbv_buffer_size );
  2441. - }
  2442. - if( h->param.rc.f_vbv_buffer_init > 1. )
  2443. - h->param.rc.f_vbv_buffer_init = x264_clip3f( h->param.rc.f_vbv_buffer_init / h->param.rc.i_vbv_buffer_size, 0, 1 );
  2444. - rc->buffer_rate = h->param.rc.i_vbv_max_bitrate * 1000. / rc->fps;
  2445. - rc->buffer_size = h->param.rc.i_vbv_buffer_size * 1000.;
  2446. - rc->single_frame_vbv = rc->buffer_rate * 1.1 > rc->buffer_size;
  2447. - h->param.rc.f_vbv_buffer_init = X264_MAX( h->param.rc.f_vbv_buffer_init, rc->buffer_rate / rc->buffer_size );
  2448. - rc->buffer_fill_final = rc->buffer_size * h->param.rc.f_vbv_buffer_init;
  2449. - rc->cbr_decay = 1.0 - rc->buffer_rate / rc->buffer_size
  2450. - * 0.5 * X264_MAX(0, 1.5 - rc->buffer_rate * rc->fps / rc->bitrate);
  2451. - rc->b_vbv = 1;
  2452. - rc->b_vbv_min_rate = !rc->b_2pass
  2453. - && h->param.rc.i_rc_method == X264_RC_ABR
  2454. - && h->param.rc.i_vbv_max_bitrate <= h->param.rc.i_bitrate;
  2455. - }
  2456. - else if( h->param.rc.i_vbv_max_bitrate )
  2457. - {
  2458. - x264_log(h, X264_LOG_WARNING, "VBV maxrate specified, but no bufsize.\n");
  2459. - h->param.rc.i_vbv_max_bitrate = 0;
  2460. - }
  2461. - if(rc->rate_tolerance < 0.01)
  2462. +
  2463. + x264_ratecontrol_init_reconfigurable( h, 1 );
  2464. +
  2465. + if( rc->rate_tolerance < 0.01 )
  2466. {
  2467. x264_log(h, X264_LOG_WARNING, "bitrate tolerance too small, using .01\n");
  2468. rc->rate_tolerance = 0.01;
  2469. @@ -499,16 +496,6 @@ int x264_ratecontrol_new( x264_t *h )
  2470. rc->last_non_b_pict_type = SLICE_TYPE_I;
  2471. }
  2472.  
  2473. - if( h->param.rc.i_rc_method == X264_RC_CRF )
  2474. - {
  2475. - /* Arbitrary rescaling to make CRF somewhat similar to QP.
  2476. - * Try to compensate for MB-tree's effects as well. */
  2477. - double base_cplx = h->mb.i_mb_count * (h->param.i_bframe ? 120 : 80);
  2478. - double mbtree_offset = h->param.rc.b_mb_tree ? (1.0-h->param.rc.f_qcompress)*13.5 : 0;
  2479. - rc->rate_factor_constant = pow( base_cplx, 1 - rc->qcompress )
  2480. - / qp2qscale( h->param.rc.f_rf_constant + mbtree_offset );
  2481. - }
  2482. -
  2483. rc->ip_offset = 6.0 * log(h->param.rc.f_ip_factor) / log(2.0);
  2484. rc->pb_offset = 6.0 * log(h->param.rc.f_pb_factor) / log(2.0);
  2485. rc->qp_constant[SLICE_TYPE_P] = h->param.rc.i_qp_constant;
  2486. @@ -1577,15 +1564,15 @@ static void update_vbv( x264_t *h, int bits )
  2487. if( rct->buffer_fill_final < 0 )
  2488. x264_log( h, X264_LOG_WARNING, "VBV underflow (frame %d, %.0f bits)\n", h->i_frame, rct->buffer_fill_final );
  2489. rct->buffer_fill_final = X264_MAX( rct->buffer_fill_final, 0 );
  2490. - rct->buffer_fill_final += rct->buffer_rate;
  2491. - rct->buffer_fill_final = X264_MIN( rct->buffer_fill_final, rct->buffer_size );
  2492. + rct->buffer_fill_final += rcc->buffer_rate;
  2493. + rct->buffer_fill_final = X264_MIN( rct->buffer_fill_final, rcc->buffer_size );
  2494. }
  2495.  
  2496. // provisionally update VBV according to the planned size of all frames currently in progress
  2497. static void update_vbv_plan( x264_t *h, int overhead )
  2498. {
  2499. x264_ratecontrol_t *rcc = h->rc;
  2500. - rcc->buffer_fill = h->thread[0]->rc->buffer_fill_final - overhead;
  2501. + rcc->buffer_fill = h->thread[0]->rc->buffer_fill_final;
  2502. if( h->i_thread_frames > 1 )
  2503. {
  2504. int j = h->rc - h->thread[0]->rc;
  2505. @@ -1603,6 +1590,8 @@ static void update_vbv_plan( x264_t *h, int overhead )
  2506. rcc->buffer_fill = X264_MIN( rcc->buffer_fill, rcc->buffer_size );
  2507. }
  2508. }
  2509. + rcc->buffer_fill = X264_MIN( rcc->buffer_fill, rcc->buffer_size );
  2510. + rcc->buffer_fill -= overhead;
  2511. }
  2512.  
  2513. // apply VBV constraints and clip qscale to between lmin and lmax
  2514. @@ -2027,8 +2016,7 @@ void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next )
  2515. #define COPY(var) memcpy(&cur->rc->var, &prev->rc->var, sizeof(cur->rc->var))
  2516. /* these vars are updated in x264_ratecontrol_start()
  2517. * so copy them from the context that most recently started (prev)
  2518. - * to the context that's about to start (cur).
  2519. - */
  2520. + * to the context that's about to start (cur). */
  2521. COPY(accum_p_qp);
  2522. COPY(accum_p_norm);
  2523. COPY(last_satd);
  2524. @@ -2040,6 +2028,14 @@ void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next )
  2525. COPY(bframes);
  2526. COPY(prev_zone);
  2527. COPY(qpbuf_pos);
  2528. + /* these vars can be updated by x264_ratecontrol_init_reconfigurable */
  2529. + COPY(buffer_rate);
  2530. + COPY(buffer_size);
  2531. + COPY(single_frame_vbv);
  2532. + COPY(cbr_decay);
  2533. + COPY(b_vbv_min_rate);
  2534. + COPY(rate_factor_constant);
  2535. + COPY(bitrate);
  2536. #undef COPY
  2537. }
  2538. if( cur != next )
  2539. @@ -2047,8 +2043,7 @@ void x264_thread_sync_ratecontrol( x264_t *cur, x264_t *prev, x264_t *next )
  2540. #define COPY(var) next->rc->var = cur->rc->var
  2541. /* these vars are updated in x264_ratecontrol_end()
  2542. * so copy them from the context that most recently ended (cur)
  2543. - * to the context that's about to end (next)
  2544. - */
  2545. + * to the context that's about to end (next) */
  2546. COPY(cplxr_sum);
  2547. COPY(expected_bits_sum);
  2548. COPY(wanted_bits_window);
  2549. diff --git a/encoder/ratecontrol.h b/encoder/ratecontrol.h
  2550. index 5a8d088..2767866 100644
  2551. --- a/encoder/ratecontrol.h
  2552. +++ b/encoder/ratecontrol.h
  2553. @@ -27,6 +27,8 @@
  2554. int x264_ratecontrol_new ( x264_t * );
  2555. void x264_ratecontrol_delete( x264_t * );
  2556.  
  2557. +void x264_ratecontrol_init_reconfigurable( x264_t *h, int b_init );
  2558. +
  2559. void x264_adaptive_quant_frame( x264_t *h, x264_frame_t *frame );
  2560. void x264_adaptive_quant( x264_t * );
  2561. int x264_macroblock_tree_read( x264_t *h, x264_frame_t *frame );
  2562. diff --git a/x264.h b/x264.h
  2563. index 2550864..e7d19b7 100644
  2564. --- a/x264.h
  2565. +++ b/x264.h
  2566. @@ -35,7 +35,7 @@
  2567.  
  2568. #include <stdarg.h>
  2569.  
  2570. -#define X264_BUILD 84
  2571. +#define X264_BUILD 85
  2572.  
  2573. /* x264_t:
  2574. * opaque handler for encoder */
  2575. @@ -480,11 +480,12 @@ typedef struct
  2576. x264_t *x264_encoder_open( x264_param_t * );
  2577.  
  2578. /* x264_encoder_reconfig:
  2579. - * analysis-related parameters from x264_param_t are copied.
  2580. + * various parameters from x264_param_t are copied.
  2581. * this takes effect immediately, on whichever frame is encoded next;
  2582. * due to delay, this may not be the next frame passed to encoder_encode.
  2583. * if the change should apply to some particular frame, use x264_picture_t->param instead.
  2584. - * returns 0 on success, negative on parameter validation error. */
  2585. + * returns 0 on success, negative on parameter validation error.
  2586. + * not all parameters can be changed; see the actual function for a detailed breakdown. */
  2587. int x264_encoder_reconfig( x264_t *, x264_param_t * );
  2588. /* x264_encoder_parameters:
  2589. * copies the current internal set of parameters to the pointer provided
  2590. --
  2591. 1.6.1.2
  2592.  
  2593.  
  2594. From ccf2010622f660b924b5bb664502513cc3240f60 Mon Sep 17 00:00:00 2001
  2595. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  2596. Date: Fri, 29 Jan 2010 11:01:44 -0800
  2597. Subject: [PATCH 15/15] Fix abstraction violations in x264.c
  2598. No calling application--not even x264cli--should ever look inside x264_t.
  2599.  
  2600. ---
  2601. x264.c | 10 +++++-----
  2602. 1 files changed, 5 insertions(+), 5 deletions(-)
  2603.  
  2604. diff --git a/x264.c b/x264.c
  2605. index 8669cb3..7098b0f 100644
  2606. --- a/x264.c
  2607. +++ b/x264.c
  2608. @@ -1498,14 +1498,14 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  2609.  
  2610. i_start = x264_mdate();
  2611. /* ticks/frame = ticks/second / frames/second */
  2612. - ticks_per_frame = (int64_t)h->param.i_timebase_den * h->param.i_fps_den / h->param.i_timebase_num / h->param.i_fps_num;
  2613. + ticks_per_frame = (int64_t)param->i_timebase_den * param->i_fps_den / param->i_timebase_num / param->i_fps_num;
  2614. if( ticks_per_frame < 1 )
  2615. {
  2616. fprintf( stderr, "x264 [error]: ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame );
  2617. return -1;
  2618. }
  2619.  
  2620. - if( !h->param.b_repeat_headers )
  2621. + if( !param->b_repeat_headers )
  2622. {
  2623. // Write SPS/PPS/SEI
  2624. x264_nal_t *headers;
  2625. @@ -1531,9 +1531,9 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  2626. pic.i_pts = i_frame;
  2627. if( pic.i_pts <= largest_pts )
  2628. {
  2629. - if( h->param.i_log_level >= X264_LOG_WARNING )
  2630. + if( param->i_log_level >= X264_LOG_WARNING )
  2631. {
  2632. - if( h->param.i_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING )
  2633. + if( param->i_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING )
  2634. fprintf( stderr, "x264 [warning]: non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n",
  2635. i_frame, pic.i_pts * dts_compress_multiplier, largest_pts * dts_compress_multiplier );
  2636. else if( pts_warning_cnt == MAX_PTS_WARNING )
  2637. @@ -1582,7 +1582,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  2638. if( opt->b_progress && i_frame_output % i_update_interval == 0 && i_frame_output )
  2639. Print_status( i_start, i_frame_output, i_frame_total, i_file, param, last_pts );
  2640. }
  2641. - if( pts_warning_cnt >= MAX_PTS_WARNING && h->param.i_log_level < X264_LOG_DEBUG )
  2642. + if( pts_warning_cnt >= MAX_PTS_WARNING && param->i_log_level < X264_LOG_DEBUG )
  2643. fprintf( stderr, "x264 [warning]: %d suppressed nonmonotonic pts warnings\n", pts_warning_cnt-MAX_PTS_WARNING );
  2644.  
  2645. /* duration algorithm fails when only 1 frame is output */
  2646. --
  2647. 1.6.1.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement