Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 73.18 KB | None | 0 0
  1. From 97303087110867a0800610f30b1a467e6dd7c77e 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/11] 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..a0af7ea 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->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 24d1da8806f4419347ed0954788f081924ed64dc 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/11] 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 | 11 +++++++++++
  99. encoder/encoder.c | 2 +-
  100. encoder/set.c | 8 ++++++++
  101. 3 files changed, 20 insertions(+), 1 deletions(-)
  102.  
  103. diff --git a/common/bs.h b/common/bs.h
  104. index d13eb03..3bbb436 100644
  105. --- a/common/bs.h
  106. +++ b/common/bs.h
  107. @@ -92,6 +92,17 @@ static inline void bs_flush( bs_t *s )
  108. s->p += WORD_SIZE - s->i_left / 8;
  109. s->i_left = WORD_SIZE*8;
  110. }
  111. +static inline void bs_realign( bs_t *s )
  112. +{
  113. + int offset = ((intptr_t)s->p & 3);
  114. + if( offset )
  115. + {
  116. + s->p = (uint8_t*)s->p - offset;
  117. + s->i_left = (WORD_SIZE - offset)*8;
  118. + s->cur_bits = endian_fix32(*(uint32_t *)(s->p));
  119. + s->cur_bits >>= (4-offset)*8;
  120. + }
  121. +}
  122.  
  123. static inline void bs_write( bs_t *s, int i_count, uint32_t i_bits )
  124. {
  125. diff --git a/encoder/encoder.c b/encoder/encoder.c
  126. index a0af7ea..8afadb0 100644
  127. --- a/encoder/encoder.c
  128. +++ b/encoder/encoder.c
  129. @@ -1206,7 +1206,6 @@ int x264_encoder_headers( x264_t *h, x264_nal_t **pp_nal, int *pi_nal )
  130. x264_pps_write( &h->out.bs, h->pps );
  131. if( x264_nal_end( h ) )
  132. return -1;
  133. - bs_flush( &h->out.bs );
  134.  
  135. frame_size = x264_encoder_encapsulate_nals( h );
  136.  
  137. @@ -1657,6 +1656,7 @@ static int x264_slice_write( x264_t *h )
  138. /* Assume no more than 3 bytes of NALU escaping. */
  139. int slice_max_size = h->param.i_slice_max_size > 0 ? (h->param.i_slice_max_size-3-NALU_OVERHEAD)*8 : INT_MAX;
  140. int starting_bits = bs_pos(&h->out.bs);
  141. + bs_realign( &h->out.bs );
  142.  
  143. /* Slice */
  144. x264_nal_start( h, h->i_nal_type, h->i_nal_ref_idc );
  145. diff --git a/encoder/set.c b/encoder/set.c
  146. index 641eae9..f79919b 100644
  147. --- a/encoder/set.c
  148. +++ b/encoder/set.c
  149. @@ -210,6 +210,7 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
  150.  
  151. void x264_sps_write( bs_t *s, x264_sps_t *sps )
  152. {
  153. + bs_realign( s );
  154. bs_write( s, 8, sps->i_profile_idc );
  155. bs_write( s, 1, sps->b_constraint_set0 );
  156. bs_write( s, 1, sps->b_constraint_set1 );
  157. @@ -359,6 +360,7 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps )
  158. }
  159.  
  160. bs_rbsp_trailing( s );
  161. + bs_flush( s );
  162. }
  163.  
  164. void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps )
  165. @@ -423,6 +425,7 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
  166.  
  167. void x264_pps_write( bs_t *s, x264_pps_t *pps )
  168. {
  169. + bs_realign( s );
  170. bs_write_ue( s, pps->i_id );
  171. bs_write_ue( s, pps->i_sps_id );
  172.  
  173. @@ -465,12 +468,14 @@ void x264_pps_write( bs_t *s, x264_pps_t *pps )
  174. }
  175.  
  176. bs_rbsp_trailing( s );
  177. + bs_flush( s );
  178. }
  179.  
  180. void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt )
  181. {
  182. int payload_size;
  183.  
  184. + bs_realign( s );
  185. bs_write( s, 8, 0x06 ); // payload_type = Recovery Point
  186. payload_size = bs_size_ue( recovery_frame_cnt ) + 4;
  187.  
  188. @@ -482,6 +487,7 @@ void x264_sei_recovery_point_write( x264_t *h, bs_t *s, int recovery_frame_cnt )
  189.  
  190. bs_align_10( s );
  191. bs_rbsp_trailing( s );
  192. + bs_flush( s );
  193. }
  194.  
  195. int x264_sei_version_write( x264_t *h, bs_t *s )
  196. @@ -505,6 +511,7 @@ int x264_sei_version_write( x264_t *h, bs_t *s )
  197. X264_BUILD, X264_VERSION, opts );
  198. length = strlen(version)+1+16;
  199.  
  200. + bs_realign( s );
  201. bs_write( s, 8, 0x5 ); // payload_type = user_data_unregistered
  202. // payload_size
  203. for( i = 0; i <= length-255; i += 255 )
  204. @@ -517,6 +524,7 @@ int x264_sei_version_write( x264_t *h, bs_t *s )
  205. bs_write( s, 8, version[i] );
  206.  
  207. bs_rbsp_trailing( s );
  208. + bs_flush( s );
  209.  
  210. x264_free( opts );
  211. x264_free( version );
  212. --
  213. 1.6.1.2
  214.  
  215.  
  216. From c19bfc3d3111129f572e1b6091f4919d6f6c1d96 Mon Sep 17 00:00:00 2001
  217. From: David Conrad <lessen42@gmail.com>
  218. Date: Sat, 23 Jan 2010 18:05:25 -0800
  219. Subject: [PATCH 03/11] Fix lavf input with pipes and image sequences
  220. x264 should now be able to encode from an image sequence using an image2-style formatted string (e.g. file%02d.jpg).
  221.  
  222. ---
  223. x264.c | 10 ++++------
  224. 1 files changed, 4 insertions(+), 6 deletions(-)
  225.  
  226. diff --git a/x264.c b/x264.c
  227. index 3a07bb3..db33536 100644
  228. --- a/x264.c
  229. +++ b/x264.c
  230. @@ -719,13 +719,11 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename
  231. if( b_regular )
  232. {
  233. FILE *f = fopen( filename, "r" );
  234. - if( !f )
  235. + if( f )
  236. {
  237. - fprintf( stderr, "x264 [error]: could not open input file `%s'\n", filename );
  238. - return -1;
  239. + b_regular = x264_is_regular_file( f );
  240. + fclose( f );
  241. }
  242. - b_regular = x264_is_regular_file( f );
  243. - fclose( f );
  244. }
  245. const char *module = b_auto ? ext : demuxer;
  246.  
  247. @@ -756,7 +754,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename
  248. #endif
  249. #ifdef LAVF_INPUT
  250. if( (b_auto || !strcasecmp( demuxer, "lavf" )) &&
  251. - (!b_regular || !lavf_input.open_file( filename, p_handle, info, opt )) )
  252. + !lavf_input.open_file( filename, p_handle, info, opt ) )
  253. {
  254. module = "lavf";
  255. b_auto = 0;
  256. --
  257. 1.6.1.2
  258.  
  259.  
  260. From 3b0dd65039d8ffe694ac005c25468fe0b7cfd764 Mon Sep 17 00:00:00 2001
  261. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  262. Date: Mon, 25 Jan 2010 11:23:55 -0800
  263. Subject: [PATCH 04/11] Hardcode the bs_t in cavlc.c; passing it around is a waste.
  264.  
  265. Saves ~1.5kb of code size, very slight speed boost.
  266. ---
  267. encoder/cavlc.c | 143 ++++++++++++++++++++++++++------------------------
  268. encoder/encoder.c | 2 +-
  269. encoder/macroblock.h | 2 +-
  270. encoder/rdo.c | 6 +--
  271. 4 files changed, 79 insertions(+), 74 deletions(-)
  272.  
  273. diff --git a/encoder/cavlc.c b/encoder/cavlc.c
  274. index 59f362a..c65c9bd 100644
  275. --- a/encoder/cavlc.c
  276. +++ b/encoder/cavlc.c
  277. @@ -61,8 +61,9 @@ static const uint8_t sub_mb_type_b_to_golomb[13]=
  278. /****************************************************************************
  279. * block_residual_write_cavlc:
  280. ****************************************************************************/
  281. -static inline int block_residual_write_cavlc_escape( x264_t *h, bs_t *s, int i_suffix_length, int level )
  282. +static inline int block_residual_write_cavlc_escape( x264_t *h, int i_suffix_length, int level )
  283. {
  284. + bs_t *s = &h->out.bs;
  285. static const uint16_t next_suffix[7] = { 0, 3, 6, 12, 24, 48, 0xffff };
  286. int i_level_prefix = 15;
  287. int mask = level >> 15;
  288. @@ -112,8 +113,9 @@ static inline int block_residual_write_cavlc_escape( x264_t *h, bs_t *s, int i_s
  289. return i_suffix_length;
  290. }
  291.  
  292. -static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, int16_t *l, int nC )
  293. +static int block_residual_write_cavlc( x264_t *h, int i_ctxBlockCat, int16_t *l, int nC )
  294. {
  295. + bs_t *s = &h->out.bs;
  296. static const uint8_t ctz_index[8] = {3,0,1,0,2,0,1,0};
  297. static const int count_cat[5] = {16, 15, 16, 4, 15};
  298. x264_run_level_t runlevel;
  299. @@ -157,7 +159,7 @@ static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, in
  300. i_suffix_length = x264_level_token[i_suffix_length][val_original].i_next;
  301. }
  302. else
  303. - i_suffix_length = block_residual_write_cavlc_escape( h, s, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  304. + i_suffix_length = block_residual_write_cavlc_escape( h, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  305. for( i = i_trailing+1; i < i_total; i++ )
  306. {
  307. val = runlevel.level[i] + LEVEL_TABLE_SIZE/2;
  308. @@ -167,7 +169,7 @@ static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, in
  309. i_suffix_length = x264_level_token[i_suffix_length][val].i_next;
  310. }
  311. else
  312. - i_suffix_length = block_residual_write_cavlc_escape( h, s, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  313. + i_suffix_length = block_residual_write_cavlc_escape( h, i_suffix_length, val-LEVEL_TABLE_SIZE/2 );
  314. }
  315. }
  316.  
  317. @@ -191,18 +193,19 @@ static int block_residual_write_cavlc( x264_t *h, bs_t *s, int i_ctxBlockCat, in
  318.  
  319. static const uint8_t ct_index[17] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3};
  320.  
  321. -#define block_residual_write_cavlc(h,s,cat,idx,l)\
  322. +#define block_residual_write_cavlc(h,cat,idx,l)\
  323. {\
  324. int nC = cat == DCT_CHROMA_DC ? 4 : ct_index[x264_mb_predict_non_zero_code( h, cat == DCT_LUMA_DC ? 0 : idx )];\
  325. uint8_t *nnz = &h->mb.cache.non_zero_count[x264_scan8[idx]];\
  326. if( !*nnz )\
  327. - bs_write_vlc( s, x264_coeff0_token[nC] );\
  328. + bs_write_vlc( &h->out.bs, x264_coeff0_token[nC] );\
  329. else\
  330. - *nnz = block_residual_write_cavlc(h,s,cat,l,nC);\
  331. + *nnz = block_residual_write_cavlc(h,cat,l,nC);\
  332. }
  333.  
  334. -static void cavlc_qp_delta( x264_t *h, bs_t *s )
  335. +static void cavlc_qp_delta( x264_t *h )
  336. {
  337. + bs_t *s = &h->out.bs;
  338. int i_dqp = h->mb.i_qp - h->mb.i_last_qp;
  339.  
  340. /* Avoid writing a delta quant if we have an empty i16x16 block, e.g. in a completely flat background area */
  341. @@ -225,39 +228,40 @@ static void cavlc_qp_delta( x264_t *h, bs_t *s )
  342. bs_write_se( s, i_dqp );
  343. }
  344.  
  345. -static void cavlc_mb_mvd( x264_t *h, bs_t *s, int i_list, int idx, int width )
  346. +static void cavlc_mb_mvd( x264_t *h, int i_list, int idx, int width )
  347. {
  348. + bs_t *s = &h->out.bs;
  349. ALIGNED_4( int16_t mvp[2] );
  350. x264_mb_predict_mv( h, i_list, idx, width, mvp );
  351. bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[idx]][0] - mvp[0] );
  352. bs_write_se( s, h->mb.cache.mv[i_list][x264_scan8[idx]][1] - mvp[1] );
  353. }
  354.  
  355. -static inline void cavlc_mb8x8_mvd( x264_t *h, bs_t *s, int i )
  356. +static inline void cavlc_mb8x8_mvd( x264_t *h, int i )
  357. {
  358. switch( h->mb.i_sub_partition[i] )
  359. {
  360. case D_L0_8x8:
  361. - cavlc_mb_mvd( h, s, 0, 4*i, 2 );
  362. + cavlc_mb_mvd( h, 0, 4*i, 2 );
  363. break;
  364. case D_L0_8x4:
  365. - cavlc_mb_mvd( h, s, 0, 4*i+0, 2 );
  366. - cavlc_mb_mvd( h, s, 0, 4*i+2, 2 );
  367. + cavlc_mb_mvd( h, 0, 4*i+0, 2 );
  368. + cavlc_mb_mvd( h, 0, 4*i+2, 2 );
  369. break;
  370. case D_L0_4x8:
  371. - cavlc_mb_mvd( h, s, 0, 4*i+0, 1 );
  372. - cavlc_mb_mvd( h, s, 0, 4*i+1, 1 );
  373. + cavlc_mb_mvd( h, 0, 4*i+0, 1 );
  374. + cavlc_mb_mvd( h, 0, 4*i+1, 1 );
  375. break;
  376. case D_L0_4x4:
  377. - cavlc_mb_mvd( h, s, 0, 4*i+0, 1 );
  378. - cavlc_mb_mvd( h, s, 0, 4*i+1, 1 );
  379. - cavlc_mb_mvd( h, s, 0, 4*i+2, 1 );
  380. - cavlc_mb_mvd( h, s, 0, 4*i+3, 1 );
  381. + cavlc_mb_mvd( h, 0, 4*i+0, 1 );
  382. + cavlc_mb_mvd( h, 0, 4*i+1, 1 );
  383. + cavlc_mb_mvd( h, 0, 4*i+2, 1 );
  384. + cavlc_mb_mvd( h, 0, 4*i+3, 1 );
  385. break;
  386. }
  387. }
  388.  
  389. -static inline void x264_macroblock_luma_write_cavlc( x264_t *h, bs_t *s, int i8start, int i8end )
  390. +static inline void x264_macroblock_luma_write_cavlc( x264_t *h, int i8start, int i8end )
  391. {
  392. int i8, i4;
  393. if( h->mb.b_transform_8x8 )
  394. @@ -271,20 +275,23 @@ static inline void x264_macroblock_luma_write_cavlc( x264_t *h, bs_t *s, int i8s
  395. for( i8 = i8start; i8 <= i8end; i8++ )
  396. if( h->mb.i_cbp_luma & (1 << i8) )
  397. for( i4 = 0; i4 < 4; i4++ )
  398. - block_residual_write_cavlc( h, s, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4] );
  399. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4+i8*4, h->dct.luma4x4[i4+i8*4] );
  400. }
  401.  
  402. /*****************************************************************************
  403. * x264_macroblock_write:
  404. *****************************************************************************/
  405. -void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  406. +void x264_macroblock_write_cavlc( x264_t *h )
  407. {
  408. + bs_t *s = &h->out.bs;
  409. const int i_mb_type = h->mb.i_type;
  410. static const uint8_t i_offsets[3] = {5,23,0};
  411. int i_mb_i_offset = i_offsets[h->sh.i_type];
  412. int i;
  413.  
  414. -#if !RDO_SKIP_BS
  415. +#if RDO_SKIP_BS
  416. + s->i_bits_encoded = 0;
  417. +#else
  418. const int i_mb_pos_start = bs_pos( s );
  419. int i_mb_pos_tex;
  420. #endif
  421. @@ -365,7 +372,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  422.  
  423. if( h->mb.pic.i_fref[0] > 1 )
  424. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
  425. - cavlc_mb_mvd( h, s, 0, 0, 4 );
  426. + cavlc_mb_mvd( h, 0, 0, 4 );
  427. }
  428. else if( h->mb.i_partition == D_16x8 )
  429. {
  430. @@ -375,8 +382,8 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  431. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
  432. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[8]] );
  433. }
  434. - cavlc_mb_mvd( h, s, 0, 0, 4 );
  435. - cavlc_mb_mvd( h, s, 0, 8, 4 );
  436. + cavlc_mb_mvd( h, 0, 0, 4 );
  437. + cavlc_mb_mvd( h, 0, 8, 4 );
  438. }
  439. else if( h->mb.i_partition == D_8x16 )
  440. {
  441. @@ -386,8 +393,8 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  442. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
  443. bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4]] );
  444. }
  445. - cavlc_mb_mvd( h, s, 0, 0, 2 );
  446. - cavlc_mb_mvd( h, s, 0, 4, 2 );
  447. + cavlc_mb_mvd( h, 0, 0, 2 );
  448. + cavlc_mb_mvd( h, 0, 4, 2 );
  449. }
  450. }
  451. else if( i_mb_type == P_8x8 )
  452. @@ -422,7 +429,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  453. }
  454.  
  455. for( i = 0; i < 4; i++ )
  456. - cavlc_mb8x8_mvd( h, s, i );
  457. + cavlc_mb8x8_mvd( h, i );
  458. }
  459. else if( i_mb_type == B_8x8 )
  460. {
  461. @@ -445,10 +452,10 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  462. /* mvd */
  463. for( i = 0; i < 4; i++ )
  464. if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
  465. - cavlc_mb_mvd( h, s, 0, 4*i, 2 );
  466. + cavlc_mb_mvd( h, 0, 4*i, 2 );
  467. for( i = 0; i < 4; i++ )
  468. if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
  469. - cavlc_mb_mvd( h, s, 1, 4*i, 2 );
  470. + cavlc_mb_mvd( h, 1, 4*i, 2 );
  471. }
  472. else if( i_mb_type != B_DIRECT )
  473. {
  474. @@ -463,8 +470,8 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  475. {
  476. if( i_ref0_max && b_list[0][0] ) bs_write_te( s, i_ref0_max, h->mb.cache.ref[0][x264_scan8[0]] );
  477. if( i_ref1_max && b_list[1][0] ) bs_write_te( s, i_ref1_max, h->mb.cache.ref[1][x264_scan8[0]] );
  478. - if( b_list[0][0] ) cavlc_mb_mvd( h, s, 0, 0, 4 );
  479. - if( b_list[1][0] ) cavlc_mb_mvd( h, s, 1, 0, 4 );
  480. + if( b_list[0][0] ) cavlc_mb_mvd( h, 0, 0, 4 );
  481. + if( b_list[1][0] ) cavlc_mb_mvd( h, 1, 0, 4 );
  482. }
  483. else
  484. {
  485. @@ -474,17 +481,17 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  486. if( i_ref1_max && b_list[1][1] ) bs_write_te( s, i_ref1_max, h->mb.cache.ref[1][x264_scan8[12]] );
  487. if( h->mb.i_partition == D_16x8 )
  488. {
  489. - if( b_list[0][0] ) cavlc_mb_mvd( h, s, 0, 0, 4 );
  490. - if( b_list[0][1] ) cavlc_mb_mvd( h, s, 0, 8, 4 );
  491. - if( b_list[1][0] ) cavlc_mb_mvd( h, s, 1, 0, 4 );
  492. - if( b_list[1][1] ) cavlc_mb_mvd( h, s, 1, 8, 4 );
  493. + if( b_list[0][0] ) cavlc_mb_mvd( h, 0, 0, 4 );
  494. + if( b_list[0][1] ) cavlc_mb_mvd( h, 0, 8, 4 );
  495. + if( b_list[1][0] ) cavlc_mb_mvd( h, 1, 0, 4 );
  496. + if( b_list[1][1] ) cavlc_mb_mvd( h, 1, 8, 4 );
  497. }
  498. else //if( h->mb.i_partition == D_8x16 )
  499. {
  500. - if( b_list[0][0] ) cavlc_mb_mvd( h, s, 0, 0, 2 );
  501. - if( b_list[0][1] ) cavlc_mb_mvd( h, s, 0, 4, 2 );
  502. - if( b_list[1][0] ) cavlc_mb_mvd( h, s, 1, 0, 2 );
  503. - if( b_list[1][1] ) cavlc_mb_mvd( h, s, 1, 4, 2 );
  504. + if( b_list[0][0] ) cavlc_mb_mvd( h, 0, 0, 2 );
  505. + if( b_list[0][1] ) cavlc_mb_mvd( h, 0, 4, 2 );
  506. + if( b_list[1][0] ) cavlc_mb_mvd( h, 1, 0, 2 );
  507. + if( b_list[1][1] ) cavlc_mb_mvd( h, 1, 4, 2 );
  508. }
  509. }
  510. }
  511. @@ -509,29 +516,29 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  512. /* write residual */
  513. if( i_mb_type == I_16x16 )
  514. {
  515. - cavlc_qp_delta( h, s );
  516. + cavlc_qp_delta( h );
  517.  
  518. /* DC Luma */
  519. - block_residual_write_cavlc( h, s, DCT_LUMA_DC, 24 , h->dct.luma16x16_dc );
  520. + block_residual_write_cavlc( h, DCT_LUMA_DC, 24 , h->dct.luma16x16_dc );
  521.  
  522. /* AC Luma */
  523. if( h->mb.i_cbp_luma )
  524. for( i = 0; i < 16; i++ )
  525. - block_residual_write_cavlc( h, s, DCT_LUMA_AC, i, h->dct.luma4x4[i]+1 );
  526. + block_residual_write_cavlc( h, DCT_LUMA_AC, i, h->dct.luma4x4[i]+1 );
  527. }
  528. else if( h->mb.i_cbp_luma | h->mb.i_cbp_chroma )
  529. {
  530. - cavlc_qp_delta( h, s );
  531. - x264_macroblock_luma_write_cavlc( h, s, 0, 3 );
  532. + cavlc_qp_delta( h );
  533. + x264_macroblock_luma_write_cavlc( h, 0, 3 );
  534. }
  535. if( h->mb.i_cbp_chroma )
  536. {
  537. /* Chroma DC residual present */
  538. - block_residual_write_cavlc( h, s, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  539. - block_residual_write_cavlc( h, s, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  540. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  541. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  542. if( h->mb.i_cbp_chroma&0x02 ) /* Chroma AC residual present */
  543. for( i = 16; i < 24; i++ )
  544. - block_residual_write_cavlc( h, s, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  545. + block_residual_write_cavlc( h, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  546. }
  547.  
  548. #if !RDO_SKIP_BS
  549. @@ -549,36 +556,36 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s )
  550. *****************************************************************************/
  551. static int x264_partition_size_cavlc( x264_t *h, int i8, int i_pixel )
  552. {
  553. + bs_t *s = &h->out.bs;
  554. const int i_mb_type = h->mb.i_type;
  555. int b_8x16 = h->mb.i_partition == D_8x16;
  556. int j;
  557. - h->out.bs.i_bits_encoded = 0;
  558.  
  559. if( i_mb_type == P_8x8 )
  560. {
  561. - cavlc_mb8x8_mvd( h, &h->out.bs, i8 );
  562. - bs_write_ue( &h->out.bs, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i8] ] );
  563. + cavlc_mb8x8_mvd( h, i8 );
  564. + bs_write_ue( s, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i8] ] );
  565. }
  566. else if( i_mb_type == P_L0 )
  567. - cavlc_mb_mvd( h, &h->out.bs, 0, 4*i8, 4>>b_8x16 );
  568. + cavlc_mb_mvd( h, 0, 4*i8, 4>>b_8x16 );
  569. else if( i_mb_type > B_DIRECT && i_mb_type < B_8x8 )
  570. {
  571. - if( x264_mb_type_list_table[ i_mb_type ][0][!!i8] ) cavlc_mb_mvd( h, &h->out.bs, 0, 4*i8, 4>>b_8x16 );
  572. - if( x264_mb_type_list_table[ i_mb_type ][1][!!i8] ) cavlc_mb_mvd( h, &h->out.bs, 1, 4*i8, 4>>b_8x16 );
  573. + if( x264_mb_type_list_table[ i_mb_type ][0][!!i8] ) cavlc_mb_mvd( h, 0, 4*i8, 4>>b_8x16 );
  574. + if( x264_mb_type_list_table[ i_mb_type ][1][!!i8] ) cavlc_mb_mvd( h, 1, 4*i8, 4>>b_8x16 );
  575. }
  576. else //if( i_mb_type == B_8x8 )
  577. {
  578. if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i8] ] )
  579. - cavlc_mb_mvd( h, &h->out.bs, 0, 4*i8, 2 );
  580. + cavlc_mb_mvd( h, 0, 4*i8, 2 );
  581. if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i8] ] )
  582. - cavlc_mb_mvd( h, &h->out.bs, 1, 4*i8, 2 );
  583. + cavlc_mb_mvd( h, 1, 4*i8, 2 );
  584. }
  585.  
  586. for( j = (i_pixel < PIXEL_8x8); j >= 0; j-- )
  587. {
  588. - x264_macroblock_luma_write_cavlc( h, &h->out.bs, i8, i8 );
  589. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_AC, 16+i8, h->dct.luma4x4[16+i8]+1 );
  590. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_AC, 20+i8, h->dct.luma4x4[20+i8]+1 );
  591. + x264_macroblock_luma_write_cavlc( h, i8, i8 );
  592. + block_residual_write_cavlc( h, DCT_CHROMA_AC, 16+i8, h->dct.luma4x4[16+i8]+1 );
  593. + block_residual_write_cavlc( h, DCT_CHROMA_AC, 20+i8, h->dct.luma4x4[20+i8]+1 );
  594. i8 += x264_pixel_size[i_pixel].h >> 3;
  595. }
  596.  
  597. @@ -589,12 +596,12 @@ static int x264_subpartition_size_cavlc( x264_t *h, int i4, int i_pixel )
  598. {
  599. int b_8x4 = i_pixel == PIXEL_8x4;
  600. h->out.bs.i_bits_encoded = 0;
  601. - cavlc_mb_mvd( h, &h->out.bs, 0, i4, 1+b_8x4 );
  602. - block_residual_write_cavlc( h, &h->out.bs, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  603. + cavlc_mb_mvd( h, 0, i4, 1+b_8x4 );
  604. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  605. if( i_pixel != PIXEL_4x4 )
  606. {
  607. i4 += 2-b_8x4;
  608. - block_residual_write_cavlc( h, &h->out.bs, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  609. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  610. }
  611.  
  612. return h->out.bs.i_bits_encoded;
  613. @@ -612,14 +619,14 @@ static int x264_partition_i8x8_size_cavlc( x264_t *h, int i8, int i_mode )
  614. {
  615. h->out.bs.i_bits_encoded = cavlc_intra4x4_pred_size( h, 4*i8, i_mode );
  616. bs_write_ue( &h->out.bs, intra4x4_cbp_to_golomb[( h->mb.i_cbp_chroma << 4 )|h->mb.i_cbp_luma] );
  617. - x264_macroblock_luma_write_cavlc( h, &h->out.bs, i8, i8 );
  618. + x264_macroblock_luma_write_cavlc( h, i8, i8 );
  619. return h->out.bs.i_bits_encoded;
  620. }
  621.  
  622. static int x264_partition_i4x4_size_cavlc( x264_t *h, int i4, int i_mode )
  623. {
  624. h->out.bs.i_bits_encoded = cavlc_intra4x4_pred_size( h, i4, i_mode );
  625. - block_residual_write_cavlc( h, &h->out.bs, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  626. + block_residual_write_cavlc( h, DCT_LUMA_4x4, i4, h->dct.luma4x4[i4] );
  627. return h->out.bs.i_bits_encoded;
  628. }
  629.  
  630. @@ -628,14 +635,14 @@ static int x264_i8x8_chroma_size_cavlc( x264_t *h )
  631. h->out.bs.i_bits_encoded = bs_size_ue( x264_mb_pred_mode8x8c_fix[ h->mb.i_chroma_pred_mode ] );
  632. if( h->mb.i_cbp_chroma )
  633. {
  634. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  635. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  636. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 25, h->dct.chroma_dc[0] );
  637. + block_residual_write_cavlc( h, DCT_CHROMA_DC, 26, h->dct.chroma_dc[1] );
  638.  
  639. if( h->mb.i_cbp_chroma == 2 )
  640. {
  641. int i;
  642. for( i = 16; i < 24; i++ )
  643. - block_residual_write_cavlc( h, &h->out.bs, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  644. + block_residual_write_cavlc( h, DCT_CHROMA_AC, i, h->dct.luma4x4[i]+1 );
  645. }
  646. }
  647. return h->out.bs.i_bits_encoded;
  648. diff --git a/encoder/encoder.c b/encoder/encoder.c
  649. index 8afadb0..5dc281c 100644
  650. --- a/encoder/encoder.c
  651. +++ b/encoder/encoder.c
  652. @@ -1741,7 +1741,7 @@ static int x264_slice_write( x264_t *h )
  653. bs_write_ue( &h->out.bs, i_skip ); /* skip run */
  654. i_skip = 0;
  655. }
  656. - x264_macroblock_write_cavlc( h, &h->out.bs );
  657. + x264_macroblock_write_cavlc( h );
  658. }
  659. }
  660.  
  661. diff --git a/encoder/macroblock.h b/encoder/macroblock.h
  662. index 24a43b1..25beb18 100644
  663. --- a/encoder/macroblock.h
  664. +++ b/encoder/macroblock.h
  665. @@ -45,7 +45,7 @@ void x264_predict_lossless_16x16( x264_t *h, int i_mode );
  666.  
  667. void x264_macroblock_encode ( x264_t *h );
  668. void x264_macroblock_write_cabac ( x264_t *h, x264_cabac_t *cb );
  669. -void x264_macroblock_write_cavlc ( x264_t *h, bs_t *s );
  670. +void x264_macroblock_write_cavlc ( x264_t *h );
  671.  
  672. void x264_macroblock_encode_p8x8( x264_t *h, int i8 );
  673. void x264_macroblock_encode_p4x4( x264_t *h, int i4 );
  674. diff --git a/encoder/rdo.c b/encoder/rdo.c
  675. index 9dee56d..3ed4a47 100644
  676. --- a/encoder/rdo.c
  677. +++ b/encoder/rdo.c
  678. @@ -159,10 +159,8 @@ static int x264_rd_cost_mb( x264_t *h, int i_lambda2 )
  679. }
  680. else
  681. {
  682. - bs_t bs_tmp = h->out.bs;
  683. - bs_tmp.i_bits_encoded = 0;
  684. - x264_macroblock_size_cavlc( h, &bs_tmp );
  685. - i_bits = ( bs_tmp.i_bits_encoded * i_lambda2 + 128 ) >> 8;
  686. + x264_macroblock_size_cavlc( h );
  687. + i_bits = ( h->out.bs.i_bits_encoded * i_lambda2 + 128 ) >> 8;
  688. }
  689.  
  690. h->mb.b_transform_8x8 = b_transform_bak;
  691. --
  692. 1.6.1.2
  693.  
  694.  
  695. From 32be11b2df49dc74f2ab6601e482197e27e2d637 Mon Sep 17 00:00:00 2001
  696. From: Anton Mitrofanov <BugMaster@narod.ru>
  697. Date: Tue, 26 Jan 2010 11:41:18 -0800
  698. Subject: [PATCH 05/11] Various threading-related cosmetics
  699. Simplify a lot of code and remove some unnecessary variables.
  700.  
  701. ---
  702. common/common.h | 13 +++------
  703. encoder/analyse.c | 12 ++++----
  704. encoder/encoder.c | 68 ++++++++++++++++++++++++------------------------
  705. encoder/ratecontrol.c | 22 ++++++++--------
  706. 4 files changed, 55 insertions(+), 60 deletions(-)
  707.  
  708. diff --git a/common/common.h b/common/common.h
  709. index df39f26..2205047 100644
  710. --- a/common/common.h
  711. +++ b/common/common.h
  712. @@ -362,16 +362,11 @@ struct x264_t
  713.  
  714. /* frame number/poc */
  715. int i_frame;
  716. + int i_frame_num;
  717.  
  718. - int i_frame_offset; /* decoding only */
  719. - int i_frame_num; /* decoding only */
  720. - int i_poc_msb; /* decoding only */
  721. - int i_poc_lsb; /* decoding only */
  722. - int i_poc; /* decoding only */
  723. -
  724. - int i_thread_num; /* threads only */
  725. - int i_nal_type; /* threads only */
  726. - int i_nal_ref_idc; /* threads only */
  727. + int i_thread_frames;
  728. + int i_nal_type;
  729. + int i_nal_ref_idc;
  730.  
  731. /* We use only one SPS and one PPS */
  732. x264_sps_t sps_array[1];
  733. diff --git a/encoder/analyse.c b/encoder/analyse.c
  734. index 37d7fd9..666596b 100644
  735. --- a/encoder/analyse.c
  736. +++ b/encoder/analyse.c
  737. @@ -413,7 +413,7 @@ static void x264_mb_analyse_init( x264_t *h, x264_mb_analysis_t *a, int i_qp )
  738. int mb_height = h->sps->i_mb_height >> h->sh.b_mbaff;
  739. int thread_mvy_range = i_fmv_range;
  740.  
  741. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  742. + if( h->i_thread_frames > 1 )
  743. {
  744. int pix_y = (h->mb.i_mb_y | h->mb.b_interlaced) * 16;
  745. int thresh = pix_y + h->param.analyse.i_mv_range_thread;
  746. @@ -1167,7 +1167,7 @@ static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
  747. {
  748. h->mb.i_type = P_SKIP;
  749. x264_analyse_update_cache( h, a );
  750. - assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->param.i_threads == 1 || h->param.b_sliced_threads );
  751. + assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
  752. return;
  753. }
  754.  
  755. @@ -1183,7 +1183,7 @@ static void x264_mb_analyse_inter_p16x16( x264_t *h, x264_mb_analysis_t *a )
  756. }
  757.  
  758. x264_macroblock_cache_ref( h, 0, 0, 4, 4, 0, a->l0.me16x16.i_ref );
  759. - assert( a->l0.me16x16.mv[1] <= h->mb.mv_max_spel[1] || h->param.i_threads == 1 || h->param.b_sliced_threads );
  760. + assert( a->l0.me16x16.mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
  761.  
  762. h->mb.i_type = P_L0;
  763. if( a->i_mbrd )
  764. @@ -2403,7 +2403,7 @@ intra_analysis:
  765. /* Fast P_SKIP detection */
  766. if( h->param.analyse.b_fast_pskip )
  767. {
  768. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads && h->mb.cache.pskip_mv[1] > h->mb.mv_max_spel[1] )
  769. + if( h->i_thread_frames > 1 && h->mb.cache.pskip_mv[1] > h->mb.mv_max_spel[1] )
  770. // FIXME don't need to check this if the reference frame is done
  771. {}
  772. else if( h->param.analyse.i_subpel_refine >= 3 )
  773. @@ -2422,7 +2422,7 @@ intra_analysis:
  774. {
  775. h->mb.i_type = P_SKIP;
  776. h->mb.i_partition = D_16x16;
  777. - assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->param.i_threads == 1 || h->param.b_sliced_threads );
  778. + assert( h->mb.cache.pskip_mv[1] <= h->mb.mv_max_spel[1] || h->i_thread_frames == 1 );
  779. }
  780. else
  781. {
  782. @@ -3143,7 +3143,7 @@ static void x264_analyse_update_cache( x264_t *h, x264_mb_analysis_t *a )
  783. }
  784.  
  785. #ifndef NDEBUG
  786. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads && !IS_INTRA(h->mb.i_type) )
  787. + if( h->i_thread_frames > 1 && !IS_INTRA(h->mb.i_type) )
  788. {
  789. int l;
  790. for( l=0; l <= (h->sh.i_type == SLICE_TYPE_B); l++ )
  791. diff --git a/encoder/encoder.c b/encoder/encoder.c
  792. index 5dc281c..5660286 100644
  793. --- a/encoder/encoder.c
  794. +++ b/encoder/encoder.c
  795. @@ -421,6 +421,7 @@ static int x264_validate_parameters( x264_t *h )
  796. }
  797. else
  798. h->param.b_sliced_threads = 0;
  799. + h->i_thread_frames = h->param.b_sliced_threads ? 1 : h->param.i_threads;
  800.  
  801. if( h->param.b_interlaced )
  802. {
  803. @@ -589,8 +590,8 @@ static int x264_validate_parameters( x264_t *h )
  804. h->param.rc.i_lookahead = 0;
  805. #ifdef HAVE_PTHREAD
  806. if( h->param.i_sync_lookahead )
  807. - h->param.i_sync_lookahead = x264_clip3( h->param.i_sync_lookahead, h->param.i_threads + h->param.i_bframe, X264_LOOKAHEAD_MAX );
  808. - if( h->param.rc.b_stat_read || h->param.i_threads == 1 || h->param.b_sliced_threads )
  809. + h->param.i_sync_lookahead = x264_clip3( h->param.i_sync_lookahead, h->i_thread_frames + h->param.i_bframe, X264_LOOKAHEAD_MAX );
  810. + if( h->param.rc.b_stat_read || h->i_thread_frames == 1 )
  811. h->param.i_sync_lookahead = 0;
  812. #else
  813. h->param.i_sync_lookahead = 0;
  814. @@ -708,7 +709,7 @@ static int x264_validate_parameters( x264_t *h )
  815. if( !h->param.analyse.i_weighted_pred && h->param.rc.b_mb_tree && h->param.analyse.b_psy && !h->param.b_interlaced )
  816. h->param.analyse.i_weighted_pred = X264_WEIGHTP_FAKE;
  817.  
  818. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  819. + if( h->i_thread_frames > 1 )
  820. {
  821. int r = h->param.analyse.i_mv_range_thread;
  822. int r2;
  823. @@ -718,7 +719,7 @@ static int x264_validate_parameters( x264_t *h )
  824. // the rest is allocated to whichever thread is far enough ahead to use it.
  825. // reserving more space increases quality for some videos, but costs more time
  826. // in thread synchronization.
  827. - int max_range = (h->param.i_height + X264_THREAD_HEIGHT) / h->param.i_threads - X264_THREAD_HEIGHT;
  828. + int max_range = (h->param.i_height + X264_THREAD_HEIGHT) / h->i_thread_frames - X264_THREAD_HEIGHT;
  829. r = max_range / 2;
  830. }
  831. r = X264_MAX( r, h->param.analyse.i_me_range );
  832. @@ -886,8 +887,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
  833. if( h->param.rc.b_mb_tree || h->param.rc.i_vbv_buffer_size )
  834. h->frames.i_delay = X264_MAX( h->frames.i_delay, h->param.rc.i_lookahead );
  835. i_slicetype_length = h->frames.i_delay;
  836. - if( !h->param.b_sliced_threads )
  837. - h->frames.i_delay += h->param.i_threads - 1;
  838. + h->frames.i_delay += h->i_thread_frames - 1;
  839. h->frames.i_delay = X264_MIN( h->frames.i_delay, X264_LOOKAHEAD_MAX );
  840. h->frames.i_delay += h->param.i_sync_lookahead;
  841. h->frames.i_bframe_delay = h->param.i_bframe ? (h->param.i_bframe_pyramid ? 2 : 1) : 0;
  842. @@ -910,11 +910,11 @@ x264_t *x264_encoder_open( x264_param_t *param )
  843.  
  844. CHECKED_MALLOCZERO( h->frames.unused[0], (h->frames.i_delay + 3) * sizeof(x264_frame_t *) );
  845. /* Allocate room for max refs plus a few extra just in case. */
  846. - CHECKED_MALLOCZERO( h->frames.unused[1], (h->param.i_threads + 20) * sizeof(x264_frame_t *) );
  847. + CHECKED_MALLOCZERO( h->frames.unused[1], (h->i_thread_frames + 20) * sizeof(x264_frame_t *) );
  848. CHECKED_MALLOCZERO( h->frames.current, (h->param.i_sync_lookahead + h->param.i_bframe
  849. - + h->param.i_threads + 3) * sizeof(x264_frame_t *) );
  850. + + h->i_thread_frames + 3) * sizeof(x264_frame_t *) );
  851. if( h->param.analyse.i_weighted_pred > 0 )
  852. - CHECKED_MALLOCZERO( h->frames.blank_unused, h->param.i_threads * 4 * sizeof(x264_frame_t *) );
  853. + CHECKED_MALLOCZERO( h->frames.blank_unused, h->i_thread_frames * 4 * sizeof(x264_frame_t *) );
  854. h->i_ref0 = 0;
  855. h->i_ref1 = 0;
  856.  
  857. @@ -977,7 +977,6 @@ x264_t *x264_encoder_open( x264_param_t *param )
  858. h->nal_buffer_size = h->out.i_bitstream * 3/2 + 4;
  859.  
  860. h->thread[0] = h;
  861. - h->i_thread_num = 0;
  862. for( i = 1; i < h->param.i_threads + !!h->param.i_sync_lookahead; i++ )
  863. CHECKED_MALLOC( h->thread[i], sizeof(x264_t) );
  864.  
  865. @@ -1501,7 +1500,7 @@ static void x264_fdec_filter_row( x264_t *h, int mb_y )
  866. }
  867. }
  868.  
  869. - if( h->param.i_threads > 1 && h->fdec->b_kept_as_ref && !h->param.b_sliced_threads )
  870. + if( h->i_thread_frames > 1 && h->fdec->b_kept_as_ref )
  871. x264_frame_cond_broadcast( h->fdec, mb_y*16 + (b_end ? 10000 : -(X264_THREAD_HEIGHT << h->sh.b_mbaff)) );
  872.  
  873. min_y = X264_MAX( min_y*16-8, 0 );
  874. @@ -1537,7 +1536,7 @@ static inline int x264_reference_update( x264_t *h )
  875. int i, j;
  876. if( !h->fdec->b_kept_as_ref )
  877. {
  878. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  879. + if( h->i_thread_frames > 1 )
  880. {
  881. x264_frame_push_unused( h, h->fdec );
  882. h->fdec = x264_frame_pop_unused( h, 1 );
  883. @@ -2036,12 +2035,12 @@ int x264_encoder_encode( x264_t *h,
  884. x264_t *thread_current, *thread_prev, *thread_oldest;
  885. int i_nal_type, i_nal_ref_idc, i_global_qp, i;
  886.  
  887. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  888. + if( h->i_thread_frames > 1 )
  889. {
  890. thread_prev = h->thread[ h->i_thread_phase ];
  891. - h->i_thread_phase = (h->i_thread_phase + 1) % h->param.i_threads;
  892. + h->i_thread_phase = (h->i_thread_phase + 1) % h->i_thread_frames;
  893. thread_current = h->thread[ h->i_thread_phase ];
  894. - thread_oldest = h->thread[ (h->i_thread_phase + 1) % h->param.i_threads ];
  895. + thread_oldest = h->thread[ (h->i_thread_phase + 1) % h->i_thread_frames ];
  896. x264_thread_sync_context( thread_current, thread_prev );
  897. x264_thread_sync_ratecontrol( thread_current, thread_prev, thread_oldest );
  898. h = thread_current;
  899. @@ -2100,7 +2099,7 @@ int x264_encoder_encode( x264_t *h,
  900. /* 2: Place the frame into the queue for its slice type decision */
  901. x264_lookahead_put_frame( h, fenc );
  902.  
  903. - if( h->frames.i_input <= h->frames.i_delay + (h->param.b_sliced_threads ? 0 : 1 - h->param.i_threads) )
  904. + if( h->frames.i_input <= h->frames.i_delay + 1 - h->i_thread_frames )
  905. {
  906. /* Nothing yet to encode, waiting for filling of buffers */
  907. pic_out->i_type = X264_TYPE_AUTO;
  908. @@ -2327,7 +2326,7 @@ int x264_encoder_encode( x264_t *h,
  909. /* Write frame */
  910. h->i_threadslice_start = 0;
  911. h->i_threadslice_end = h->sps->i_mb_height;
  912. - if( !h->param.b_sliced_threads && h->param.i_threads > 1 )
  913. + if( h->i_thread_frames > 1 )
  914. {
  915. if( x264_pthread_create( &h->thread_handle, NULL, (void*)x264_slices_write, h ) )
  916. return -1;
  917. @@ -2564,25 +2563,23 @@ void x264_encoder_close ( x264_t *h )
  918.  
  919. x264_lookahead_delete( h );
  920.  
  921. - for( i = 0; i < h->param.i_threads; i++ )
  922. + if( h->i_thread_frames > 1 )
  923. {
  924. - // don't strictly have to wait for the other threads, but it's simpler than canceling them
  925. - if( h->thread[i]->b_thread_active )
  926. + for( i = 0; i < h->i_thread_frames; i++ )
  927. {
  928. - x264_pthread_join( h->thread[i]->thread_handle, NULL );
  929. - assert( h->thread[i]->fenc->i_reference_count == 1 );
  930. - x264_frame_delete( h->thread[i]->fenc );
  931. + // don't strictly have to wait for the other threads, but it's simpler than canceling them
  932. + if( h->thread[i]->b_thread_active )
  933. + {
  934. + x264_pthread_join( h->thread[i]->thread_handle, NULL );
  935. + assert( h->thread[i]->fenc->i_reference_count == 1 );
  936. + x264_frame_delete( h->thread[i]->fenc );
  937. + }
  938. }
  939. - }
  940. -
  941. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  942. - {
  943. - x264_t *thread_prev;
  944.  
  945. - thread_prev = h->thread[h->i_thread_phase];
  946. + x264_t *thread_prev = h->thread[h->i_thread_phase];
  947. x264_thread_sync_ratecontrol( h, thread_prev, h );
  948. x264_thread_sync_ratecontrol( thread_prev, thread_prev, h );
  949. - h->i_frame = thread_prev->i_frame + 1 - h->param.i_threads;
  950. + h->i_frame = thread_prev->i_frame + 1 - h->i_thread_frames;
  951. }
  952. h->i_frame++;
  953.  
  954. @@ -2833,7 +2830,7 @@ void x264_encoder_close ( x264_t *h )
  955. x264_free( h->nal_buffer );
  956. x264_analyse_free_costs( h );
  957.  
  958. - if( h->param.i_threads > 1)
  959. + if( h->i_thread_frames > 1)
  960. h = h->thread[h->i_thread_phase];
  961.  
  962. /* frames */
  963. @@ -2878,9 +2875,12 @@ int x264_encoder_delayed_frames( x264_t *h )
  964. {
  965. int delayed_frames = 0;
  966. int i;
  967. - for( i=0; i<h->param.i_threads; i++ )
  968. - delayed_frames += h->thread[i]->b_thread_active;
  969. - h = h->thread[h->i_thread_phase];
  970. + if( h->i_thread_frames > 1 )
  971. + {
  972. + for( i=0; i<h->i_thread_frames; i++ )
  973. + delayed_frames += h->thread[i]->b_thread_active;
  974. + h = h->thread[h->i_thread_phase];
  975. + }
  976. for( i=0; h->frames.current[i]; i++ )
  977. delayed_frames++;
  978. x264_pthread_mutex_lock( &h->lookahead->ofbuf.mutex );
  979. diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
  980. index 761ff2c..746b17a 100644
  981. --- a/encoder/ratecontrol.c
  982. +++ b/encoder/ratecontrol.c
  983. @@ -1578,13 +1578,13 @@ static void update_vbv_plan( x264_t *h, int overhead )
  984. {
  985. x264_ratecontrol_t *rcc = h->rc;
  986. rcc->buffer_fill = h->thread[0]->rc->buffer_fill_final - overhead;
  987. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  988. + if( h->i_thread_frames > 1 )
  989. {
  990. int j = h->rc - h->thread[0]->rc;
  991. int i;
  992. - for( i=1; i<h->param.i_threads; i++ )
  993. + for( i=1; i<h->i_thread_frames; i++ )
  994. {
  995. - x264_t *t = h->thread[ (j+i)%h->param.i_threads ];
  996. + x264_t *t = h->thread[ (j+i)%h->i_thread_frames ];
  997. double bits = t->rc->frame_size_planned;
  998. if( !t->b_thread_active )
  999. continue;
  1000. @@ -1794,7 +1794,7 @@ static float rate_estimate_qscale( x264_t *h )
  1001. }
  1002. else
  1003. {
  1004. - double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate * (h->param.b_sliced_threads?1:h->param.i_threads);
  1005. + double abr_buffer = 2 * rcc->rate_tolerance * rcc->bitrate * h->i_thread_frames;
  1006.  
  1007. if( rcc->b_2pass )
  1008. {
  1009. @@ -1804,13 +1804,13 @@ static float rate_estimate_qscale( x264_t *h )
  1010.  
  1011. if( rcc->b_vbv )
  1012. {
  1013. - if( h->param.i_threads > 1 && !h->param.b_sliced_threads )
  1014. + if( h->i_thread_frames > 1 )
  1015. {
  1016. int j = h->rc - h->thread[0]->rc;
  1017. int i;
  1018. - for( i=1; i<h->param.i_threads; i++ )
  1019. + for( i=1; i<h->i_thread_frames; i++ )
  1020. {
  1021. - x264_t *t = h->thread[ (j+i)%h->param.i_threads ];
  1022. + x264_t *t = h->thread[ (j+i)%h->i_thread_frames ];
  1023. double bits = t->rc->frame_size_planned;
  1024. if( !t->b_thread_active )
  1025. continue;
  1026. @@ -1821,16 +1821,16 @@ static float rate_estimate_qscale( x264_t *h )
  1027. }
  1028. else
  1029. {
  1030. - if( h->fenc->i_frame < h->param.i_threads )
  1031. + if( h->fenc->i_frame < h->i_thread_frames )
  1032. predicted_bits += (int64_t)h->fenc->i_frame * rcc->bitrate / rcc->fps;
  1033. else
  1034. - predicted_bits += (int64_t)(h->param.i_threads - 1) * rcc->bitrate / rcc->fps;
  1035. + predicted_bits += (int64_t)(h->i_thread_frames - 1) * rcc->bitrate / rcc->fps;
  1036. }
  1037.  
  1038. diff = predicted_bits - (int64_t)rce.expected_bits;
  1039. q = rce.new_qscale;
  1040. q /= x264_clip3f((double)(abr_buffer - diff) / abr_buffer, .5, 2);
  1041. - if( ((h->fenc->i_frame + 1 - h->param.i_threads) >= rcc->fps) &&
  1042. + if( ((h->fenc->i_frame + 1 - h->i_thread_frames) >= rcc->fps) &&
  1043. (rcc->expected_bits_sum > 0))
  1044. {
  1045. /* Adjust quant based on the difference between
  1046. @@ -1897,7 +1897,7 @@ static float rate_estimate_qscale( x264_t *h )
  1047. }
  1048. else
  1049. {
  1050. - int i_frame_done = h->fenc->i_frame + 1 - h->param.i_threads;
  1051. + int i_frame_done = h->fenc->i_frame + 1 - h->i_thread_frames;
  1052.  
  1053. q = get_qscale( h, &rce, rcc->wanted_bits_window / rcc->cplxr_sum, h->fenc->i_frame );
  1054.  
  1055. --
  1056. 1.6.1.2
  1057.  
  1058.  
  1059. From 25f3f396e7b7710fb575be6c5484c102dca860f2 Mon Sep 17 00:00:00 2001
  1060. From: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
  1061. Date: Tue, 26 Jan 2010 16:01:54 -0800
  1062. Subject: [PATCH 06/11] Improve DTS generation, move DTS compression into libx264
  1063. This change fixes some cases in which PTS could be less than DTS.
  1064.  
  1065. Additionally, a new parameter, b_dts_compress, enables DTS compression.
  1066. DTS compression eliminates negative DTS (i.e. initial delay) due to B-frames.
  1067. The algorithm changes timebase in order to avoid duplicating DTS.
  1068. Currently, in x264cli, only the FLV muxer uses it. The MP4 muxer doesn't need it, as it uses an EditBox instead.
  1069. ---
  1070. common/common.c | 1 +
  1071. common/common.h | 5 ++++
  1072. encoder/encoder.c | 40 ++++++++++++++++++++++++++++++++++-
  1073. output/flv.c | 58 +++++++++++++++++-----------------------------------
  1074. output/mp4.c | 28 ++----------------------
  1075. x264.c | 6 ++++-
  1076. x264.h | 5 +++-
  1077. 7 files changed, 75 insertions(+), 68 deletions(-)
  1078.  
  1079. diff --git a/common/common.c b/common/common.c
  1080. index 9eed5c3..b454e37 100644
  1081. --- a/common/common.c
  1082. +++ b/common/common.c
  1083. @@ -157,6 +157,7 @@ void x264_param_default( x264_param_t *param )
  1084. param->b_annexb = 1;
  1085. param->b_aud = 0;
  1086. param->b_vfr_input = 1;
  1087. + param->b_dts_compress = 0;
  1088. }
  1089.  
  1090. static int parse_enum( const char *arg, const char * const *names, int *dst )
  1091. diff --git a/common/common.h b/common/common.h
  1092. index 2205047..12d282a 100644
  1093. --- a/common/common.h
  1094. +++ b/common/common.h
  1095. @@ -375,6 +375,9 @@ struct x264_t
  1096. x264_pps_t *pps;
  1097. int i_idr_pic_id;
  1098.  
  1099. + /* multiplier for DTS compression */
  1100. + int i_dts_compress_multiplier;
  1101. +
  1102. /* quantization matrix for decoding, [cqm][qp%6][coef] */
  1103. int (*dequant4_mf[4])[16]; /* [4][6][16] */
  1104. int (*dequant8_mf[2])[64]; /* [2][6][64] */
  1105. @@ -428,6 +431,8 @@ struct x264_t
  1106. int i_delay; /* Number of frames buffered for B reordering */
  1107. int i_bframe_delay;
  1108. int64_t i_bframe_delay_time;
  1109. + int64_t i_init_delta;
  1110. + int64_t i_prev_dts[2];
  1111. int b_have_lowres; /* Whether 1/2 resolution luma planes are being used */
  1112. int b_have_sub8x8_esa;
  1113. } frames;
  1114. diff --git a/encoder/encoder.c b/encoder/encoder.c
  1115. index 5660286..9ccc628 100644
  1116. --- a/encoder/encoder.c
  1117. +++ b/encoder/encoder.c
  1118. @@ -863,6 +863,18 @@ x264_t *x264_encoder_open( x264_param_t *param )
  1119. h->i_frame = -1;
  1120. h->i_frame_num = 0;
  1121. h->i_idr_pic_id = 0;
  1122. + if( h->param.b_dts_compress )
  1123. + {
  1124. + /* h->i_dts_compress_multiplier == h->frames.i_bframe_delay + 1 */
  1125. + h->i_dts_compress_multiplier = h->param.i_bframe ? (h->param.i_bframe_pyramid ? 3 : 2) : 1;
  1126. + if( h->i_dts_compress_multiplier != 1 )
  1127. + x264_log( h, X264_LOG_DEBUG, "DTS compresion changed timebase: %d/%d -> %d/%d\n",
  1128. + h->param.i_timebase_num, h->param.i_timebase_den,
  1129. + h->param.i_timebase_num, h->param.i_timebase_den * h->i_dts_compress_multiplier );
  1130. + h->param.i_timebase_den *= h->i_dts_compress_multiplier;
  1131. + }
  1132. + else
  1133. + h->i_dts_compress_multiplier = 1;
  1134.  
  1135. h->sps = &h->sps_array[0];
  1136. x264_sps_init( h->sps, h->param.i_sps_id, &h->param );
  1137. @@ -2384,8 +2396,32 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
  1138. pic_out->i_type = X264_TYPE_B;
  1139.  
  1140. pic_out->b_keyframe = h->fenc->b_keyframe;
  1141. - pic_out->i_pts = h->fenc->i_pts;
  1142. - pic_out->i_dts = h->fenc->i_dts - h->frames.i_bframe_delay_time;
  1143. +
  1144. + pic_out->i_pts = h->fenc->i_pts *= h->i_dts_compress_multiplier;
  1145. + if( h->frames.i_bframe_delay )
  1146. + {
  1147. + int64_t *i_prev_dts = thread_current->frames.i_prev_dts;
  1148. + if( h->i_frame <= h->frames.i_bframe_delay )
  1149. + {
  1150. + if( h->i_dts_compress_multiplier == 1 )
  1151. + pic_out->i_dts = h->fenc->i_dts - h->frames.i_bframe_delay_time;
  1152. + else
  1153. + {
  1154. + /* DTS compression */
  1155. + if( h->i_frame == 1 )
  1156. + thread_current->frames.i_init_delta = h->fenc->i_dts * h->i_dts_compress_multiplier;
  1157. + pic_out->i_dts = h->i_frame * thread_current->frames.i_init_delta / h->i_dts_compress_multiplier;
  1158. + }
  1159. + }
  1160. + else
  1161. + pic_out->i_dts = i_prev_dts[ (h->i_frame - h->frames.i_bframe_delay) % h->frames.i_bframe_delay ];
  1162. + i_prev_dts[ h->i_frame % h->frames.i_bframe_delay ] = h->fenc->i_dts * h->i_dts_compress_multiplier;
  1163. + h->fenc->i_dts = pic_out->i_dts;
  1164. + }
  1165. + else
  1166. + pic_out->i_dts = h->fenc->i_dts;
  1167. + assert( pic_out->i_pts >= pic_out->i_dts );
  1168. +
  1169. pic_out->img.i_plane = h->fdec->i_plane;
  1170. for(i = 0; i < 3; i++)
  1171. {
  1172. diff --git a/output/flv.c b/output/flv.c
  1173. index 8a937cf..5ef5b0f 100644
  1174. --- a/output/flv.c
  1175. +++ b/output/flv.c
  1176. @@ -37,8 +37,6 @@ typedef struct
  1177. int64_t i_fps_num;
  1178. int64_t i_fps_den;
  1179. int64_t i_framenum;
  1180. - int i_init_delay;
  1181. - int i_delay_time;
  1182.  
  1183. uint64_t i_framerate_pos;
  1184. uint64_t i_duration_pos;
  1185. @@ -46,8 +44,8 @@ typedef struct
  1186. uint64_t i_bitrate_pos;
  1187.  
  1188. uint8_t b_write_length;
  1189. - int64_t i_init_delta;
  1190. - int64_t i_prev_timestamps[2];
  1191. + int64_t i_prev_dts;
  1192. + int64_t i_prev_pts;
  1193.  
  1194. int i_timebase_num;
  1195. int i_timebase_den;
  1196. @@ -146,10 +144,8 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
  1197. p_flv->i_fps_den = p_param->i_fps_den;
  1198. p_flv->i_timebase_num = p_param->i_timebase_num;
  1199. p_flv->i_timebase_den = p_param->i_timebase_den;
  1200. - p_flv->i_init_delay = p_param->i_bframe ? (p_param->i_bframe_pyramid ? 2 : 1) : 0;
  1201. p_flv->b_vfr_input = p_param->b_vfr_input;
  1202.  
  1203. -
  1204. return 0;
  1205. }
  1206.  
  1207. @@ -216,45 +212,29 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  1208. flv_hnd_t *p_flv = handle;
  1209. flv_buffer *c = p_flv->c;
  1210.  
  1211. - int64_t dts;
  1212. - int64_t cts;
  1213. - int64_t offset;
  1214. -
  1215. - if( !p_flv->i_framenum )
  1216. - p_flv->i_delay_time = p_picture->i_dts;
  1217. + int64_t dts = (int64_t)( (p_picture->i_dts * 1000 * ((double)p_flv->i_timebase_num / p_flv->i_timebase_den)) + 0.5 );
  1218. + int64_t cts = (int64_t)( (p_picture->i_pts * 1000 * ((double)p_flv->i_timebase_num / p_flv->i_timebase_den)) + 0.5 );
  1219. + int64_t offset = cts - dts;
  1220.  
  1221. - if( !p_flv->i_init_delay )
  1222. - dts = cts = (int64_t)((p_picture->i_pts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1223. - else
  1224. + if( p_flv->i_framenum )
  1225. {
  1226. - // Use DTS compression
  1227. - dts = p_picture->i_dts - p_flv->i_delay_time;
  1228. -
  1229. - if( p_flv->i_framenum == 1 )
  1230. - p_flv->i_init_delta = p_picture->i_dts - p_flv->i_delay_time;
  1231. -
  1232. - if( p_flv->i_framenum > p_flv->i_init_delay )
  1233. + 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 );
  1234. + 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 );
  1235. + if( prev_dts == dts )
  1236. {
  1237. - dts = p_flv->i_prev_timestamps[ (p_flv->i_framenum - p_flv->i_init_delay) % p_flv->i_init_delay ];
  1238. - dts = (int64_t)((dts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1239. + double fps = ((double)p_flv->i_timebase_den / p_flv->i_timebase_num) / (p_picture->i_dts - p_flv->i_prev_dts);
  1240. + fprintf( stderr, "flv [warning]: duplicate DTS %"PRId64" generated by rounding\n"
  1241. + " current internal decoding framerate: %.6f fps\n", dts, fps );
  1242. }
  1243. - else if( p_flv->i_init_delta )
  1244. + if( prev_cts == cts )
  1245. {
  1246. - // Compressed DTSs might not fit in input timescale
  1247. - double compressed_dts;
  1248. - compressed_dts = (p_flv->i_framenum * ((double)p_flv->i_init_delta / (2 * p_flv->i_init_delay)));
  1249. - dts = (int64_t)((compressed_dts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1250. + double fps = ((double)p_flv->i_timebase_den / p_flv->i_timebase_num) / (p_picture->i_pts - p_flv->i_prev_pts);
  1251. + fprintf( stderr, "flv [warning]: duplicating CTS %"PRId64" is generated by rounding\n"
  1252. + " current internal composition framerate: %.6f fps\n", cts, fps );
  1253. }
  1254. -
  1255. - p_flv->i_prev_timestamps[ p_flv->i_framenum % p_flv->i_init_delay ] = p_picture->i_dts - p_flv->i_delay_time;
  1256. -
  1257. - cts = p_picture->i_pts;
  1258. - cts = (int64_t)((cts * 1000 * p_flv->i_timebase_num / p_flv->i_timebase_den) + 0.5);
  1259. - }
  1260. -
  1261. - offset = cts - dts;
  1262. -
  1263. - assert( cts >= dts );
  1264. + }
  1265. + p_flv->i_prev_dts = p_picture->i_dts;
  1266. + p_flv->i_prev_pts = p_picture->i_pts;
  1267.  
  1268. // A new frame - write packet header
  1269. x264_put_byte( c, FLV_TAG_TYPE_VIDEO );
  1270. diff --git a/output/mp4.c b/output/mp4.c
  1271. index 7889e4f..e3ad9c6 100644
  1272. --- a/output/mp4.c
  1273. +++ b/output/mp4.c
  1274. @@ -34,11 +34,7 @@ typedef struct
  1275. int i_time_res;
  1276. int64_t i_time_inc;
  1277. int i_numframe;
  1278. - int i_init_delay;
  1279. int i_delay_time;
  1280. -
  1281. - int64_t i_prev_timestamps[2];
  1282. - int64_t i_init_delta;
  1283. } mp4_hnd_t;
  1284.  
  1285. static void recompute_bitrate_mp4( GF_ISOFile *p_file, int i_track )
  1286. @@ -195,8 +191,6 @@ static int set_param( hnd_t handle, x264_param_t *p_param )
  1287. p_mp4->i_time_res = p_param->i_timebase_den;
  1288. p_mp4->i_time_inc = p_param->i_timebase_num;
  1289.  
  1290. - p_mp4->i_init_delay = p_param->i_bframe ? (p_param->i_bframe_pyramid ? 2 : 1) : 0;
  1291. -
  1292. p_mp4->i_track = gf_isom_new_track( p_mp4->p_file, 0, GF_ISOM_MEDIA_VISUAL,
  1293. p_mp4->i_time_res );
  1294.  
  1295. @@ -282,7 +276,6 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  1296. mp4_hnd_t *p_mp4 = handle;
  1297. int64_t dts;
  1298. int64_t cts;
  1299. - int32_t offset = 0;
  1300.  
  1301. memcpy( p_mp4->p_sample->data + p_mp4->p_sample->dataLength, p_nalu, i_size );
  1302. p_mp4->p_sample->dataLength += i_size;
  1303. @@ -290,27 +283,12 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_
  1304. if( !p_mp4->i_numframe )
  1305. p_mp4->i_delay_time = p_picture->i_dts * -1;
  1306.  
  1307. - if( !p_mp4->i_init_delay )
  1308. - dts = cts = p_picture->i_pts * p_mp4->i_time_inc;
  1309. - else
  1310. - {
  1311. - if( p_mp4->i_numframe <= p_mp4->i_init_delay )
  1312. - dts = p_picture->i_dts + p_mp4->i_delay_time;
  1313. - else
  1314. - 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;
  1315. -
  1316. - // unordered pts
  1317. - p_mp4->i_prev_timestamps[ p_mp4->i_numframe % p_mp4->i_init_delay ] = p_picture->i_dts + p_mp4->i_delay_time;
  1318. -
  1319. - dts *= p_mp4->i_time_inc;
  1320. - cts = (p_picture->i_pts + p_mp4->i_delay_time) * p_mp4->i_time_inc;
  1321. -
  1322. - offset = cts - dts;
  1323. - }
  1324. + dts = (p_picture->i_dts + p_mp4->i_delay_time) * p_mp4->i_time_inc;
  1325. + cts = (p_picture->i_pts + p_mp4->i_delay_time) * p_mp4->i_time_inc;
  1326.  
  1327. p_mp4->p_sample->IsRAP = p_picture->b_keyframe;
  1328. p_mp4->p_sample->DTS = dts;
  1329. - p_mp4->p_sample->CTS_Offset = offset;
  1330. + p_mp4->p_sample->CTS_Offset = (uint32_t)(cts - dts);
  1331. gf_isom_add_sample( p_mp4->p_file, p_mp4->i_track, p_mp4->i_descidx, p_mp4->p_sample );
  1332.  
  1333. p_mp4->p_sample->dataLength = 0;
  1334. diff --git a/x264.c b/x264.c
  1335. index db33536..d77fa47 100644
  1336. --- a/x264.c
  1337. +++ b/x264.c
  1338. @@ -683,6 +683,7 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param
  1339. output = mp4_output;
  1340. param->b_annexb = 0;
  1341. param->b_aud = 0;
  1342. + param->b_dts_compress = 0;
  1343. param->b_repeat_headers = 0;
  1344. #else
  1345. fprintf( stderr, "x264 [error]: not compiled with MP4 output support\n" );
  1346. @@ -694,6 +695,7 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param
  1347. output = mkv_output;
  1348. param->b_annexb = 0;
  1349. param->b_aud = 0;
  1350. + param->b_dts_compress = 0;
  1351. param->b_repeat_headers = 0;
  1352. }
  1353. else if( !strcasecmp( ext, "flv" ) )
  1354. @@ -701,6 +703,7 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param
  1355. output = flv_output;
  1356. param->b_annexb = 0;
  1357. param->b_aud = 0;
  1358. + param->b_dts_compress = 1;
  1359. param->b_repeat_headers = 0;
  1360. }
  1361. else
  1362. @@ -1528,7 +1531,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  1363. {
  1364. if( h->param.i_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING )
  1365. fprintf( stderr, "x264 [warning]: non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n",
  1366. - i_frame, pic.i_pts, largest_pts );
  1367. + i_frame, pic.i_pts * h->i_dts_compress_multiplier, largest_pts * h->i_dts_compress_multiplier );
  1368. else if( pts_warning_cnt == MAX_PTS_WARNING )
  1369. fprintf( stderr, "x264 [warning]: too many nonmonotonic pts warnings, suppressing further ones\n" );
  1370. pts_warning_cnt++;
  1371. @@ -1583,6 +1586,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt )
  1372. duration = (double)param->i_fps_den / param->i_fps_num;
  1373. else
  1374. duration = (double)(2 * largest_pts - second_largest_pts) * param->i_timebase_num / param->i_timebase_den;
  1375. + duration *= h->i_dts_compress_multiplier;
  1376.  
  1377. i_end = x264_mdate();
  1378. input.picture_clean( &pic );
  1379. diff --git a/x264.h b/x264.h
  1380. index 1223df7..2550864 100644
  1381. --- a/x264.h
  1382. +++ b/x264.h
  1383. @@ -35,7 +35,7 @@
  1384.  
  1385. #include <stdarg.h>
  1386.  
  1387. -#define X264_BUILD 83
  1388. +#define X264_BUILD 84
  1389.  
  1390. /* x264_t:
  1391. * opaque handler for encoder */
  1392. @@ -316,6 +316,9 @@ typedef struct x264_param_t
  1393. int b_vfr_input; /* VFR input */
  1394. int i_timebase_num; /* Timebase numerator */
  1395. int i_timebase_den; /* Timebase denominator */
  1396. + int b_dts_compress; /* DTS compression: this algorithm eliminates negative DTS
  1397. + * by compressing them to be less than the second PTS.
  1398. + * Warning: this will change the timebase! */
  1399.  
  1400. /* Slicing parameters */
  1401. int i_slice_max_size; /* Max size per slice in bytes; includes estimated NAL overhead. */
  1402. --
  1403. 1.6.1.2
  1404.  
  1405.  
  1406. From 1590d5060503c837af1866057f00d44a666a1b24 Mon Sep 17 00:00:00 2001
  1407. From: Diogo Franco <diogomfranco@gmail.com>
  1408. Date: Wed, 27 Jan 2010 09:26:35 -0800
  1409. Subject: [PATCH 07/11] Fix cross-compiling with lavf, add support for ffms2.pc
  1410. Also update configure script to work with newest ffms.
  1411.  
  1412. ---
  1413. configure | 52 ++++++++++++++++++++++++++++++----------------------
  1414. 1 files changed, 30 insertions(+), 22 deletions(-)
  1415.  
  1416. diff --git a/configure b/configure
  1417. index 9f04a18..133a569 100755
  1418. --- a/configure
  1419. +++ b/configure
  1420. @@ -416,25 +416,23 @@ fi
  1421.  
  1422. if [ "$lavf_input" = "auto" ] ; then
  1423. lavf_input="no"
  1424. - if [ `${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL` ] ; then
  1425. - LAVF_LDFLAGS="$LAVF_LDFLAGS $(pkg-config --libs libavformat libavcodec libswscale)"
  1426. - LAVF_CFLAGS="$LAVF_CFLAGS $(pkg-config --cflags libavformat libavcodec libswscale)"
  1427. + if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
  1428. + LAVF_LIBS="$LAVF_LIBS $(${cross_prefix}pkg-config --libs libavformat libavcodec libswscale)"
  1429. + LAVF_CFLAGS="$LAVF_CFLAGS $(${cross_prefix}pkg-config --cflags libavformat libavcodec libswscale)"
  1430. fi
  1431. - if [ -z "$LAVF_LDFLAGS" -a -z "$LAVF_CFLAGS" ]; then
  1432. - LAVF_LDFLAGS="-lavformat -lswscale"
  1433. + if [ -z "$LAVF_LIBS" -a -z "$LAVF_CFLAGS" ]; then
  1434. + LAVF_LIBS="-lavformat -lswscale"
  1435. for lib in -lpostproc -lavcodec -lavutil -lm -lz -lbz2 $libpthread -lavifil32; do
  1436. - cc_check "" $lib && LAVF_LDFLAGS="$LAVF_LDFLAGS $lib"
  1437. + cc_check "" $lib && LAVF_LIBS="$LAVF_LIBS $lib"
  1438. done
  1439. fi
  1440. - LAVF_LDFLAGS="-L. $LAVF_LDFLAGS"
  1441. - if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LDFLAGS" && \
  1442. - cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LDFLAGS" ; then
  1443. + LAVF_LIBS="-L. $LAVF_LIBS"
  1444. + if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" && \
  1445. + cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LIBS" ; then
  1446. # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351
  1447. - if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LDFLAGS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
  1448. + if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then
  1449. lavf_input="yes"
  1450. echo "#define LAVF_INPUT" >> config.h
  1451. - LDFLAGSCLI="$LDFLAGSCLI $LAVF_LDFLAGS"
  1452. - [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
  1453. else
  1454. echo "Warning: libavformat is too old, update to ffmpeg r18351+"
  1455. fi
  1456. @@ -443,19 +441,29 @@ fi
  1457.  
  1458. if [ "$ffms_input" = "auto" ] ; then
  1459. ffms_input="no"
  1460. - if [ "$lavf_input" = "yes" ] ; then
  1461. - if cc_check ffms.h -lFFMS2 "FFMS_DestroyVideoSource(0);" ; then
  1462. - ffms_input="yes"
  1463. - echo "#define FFMS_INPUT" >> config.h
  1464. - LDFLAGSCLI="$LDFLAGSCLI -lFFMS2"
  1465. - elif cc_check ffms.h "-lFFMS2 $LAVF_LDFLAGS -lstdc++" "FFMS_DestroyVideoSource(0);" ; then
  1466. - ffms_input="yes"
  1467. - echo "#define FFMS_INPUT" >> config.h
  1468. - LDFLAGSCLI="-lFFMS2 $LDFLAGSCLI -lstdc++"
  1469. - fi
  1470. + if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
  1471. + FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
  1472. + FFMS2_CFLAGS="$FFMS2_LIBS $(${cross_prefix}pkg-config --cflags ffms2)"
  1473. + fi
  1474. + [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
  1475. +
  1476. + if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then
  1477. + ffms_input="yes"
  1478. + elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then
  1479. + ffms_input="yes"
  1480. + FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
  1481. fi
  1482. fi
  1483.  
  1484. +if [ "$ffms_input" = "yes" ]; then
  1485. + LDFLAGSCLI="$FFMS2_LIBS $LDFLAGSCLI"
  1486. + [ -n "$FFMS2_CFLAGS" ] && CFLAGS="$CFLAGS $FFMS2_CFLAGS"
  1487. + echo "#define FFMS_INPUT" >> config.h
  1488. +elif [ "$lavf_input" = "yes" ]; then
  1489. + LDFLAGSCLI="$LAVF_LIBS $LDFLAGSCLI"
  1490. + [ -n "$LAVF_CFLAGS" ] && CFLAGS="$CFLAGS $LAVF_CFLAGS"
  1491. +fi
  1492. +
  1493. MP4_LDFLAGS="-lgpac_static"
  1494. if [ $SYS = MINGW ]; then
  1495. MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm"
  1496. --
  1497. 1.6.1.2
  1498.  
  1499.  
  1500. From 9c2216e94c2c001c5852fd2bfc398a0d17fe6d56 Mon Sep 17 00:00:00 2001
  1501. From: Diogo Franco <diogomfranco@gmail.com>
  1502. Date: Wed, 27 Jan 2010 10:12:42 -0800
  1503. Subject: [PATCH 08/11] Add config.log support
  1504. Now, if configure fails, you'll be able to see why.
  1505.  
  1506. ---
  1507. .gitignore | 1 +
  1508. configure | 105 +++++++++++++++++++++++++++++++++++++++++++++++++----------
  1509. 2 files changed, 88 insertions(+), 18 deletions(-)
  1510.  
  1511. diff --git a/.gitignore b/.gitignore
  1512. index 308b793..9d8cb70 100644
  1513. --- a/.gitignore
  1514. +++ b/.gitignore
  1515. @@ -12,6 +12,7 @@
  1516. .depend
  1517. config.h
  1518. config.mak
  1519. +config.log
  1520. x264
  1521. checkasm
  1522.  
  1523. diff --git a/configure b/configure
  1524. index 133a569..a532788 100755
  1525. --- a/configure
  1526. +++ b/configure
  1527. @@ -27,24 +27,77 @@ echo ""
  1528. exit 1
  1529. fi
  1530.  
  1531. +log_check() {
  1532. + echo -n "checking $1... " >> config.log
  1533. +}
  1534. +
  1535. +log_ok() {
  1536. + echo "yes" >> config.log
  1537. +}
  1538. +
  1539. +log_fail() {
  1540. + echo "no" >> config.log
  1541. +}
  1542. +
  1543. +log_msg() {
  1544. + echo "$1" >> config.log
  1545. +}
  1546. +
  1547. cc_check() {
  1548. + if [ -z "$3" ]; then
  1549. + if [ -z "$1" ]; then
  1550. + log_check "whether $CC works"
  1551. + else
  1552. + log_check "for $1"
  1553. + fi
  1554. + elif [ -z "$1" ]; then
  1555. + log_check "whether $CC supports $3"
  1556. + else
  1557. + log_check "for $3 on $1";
  1558. + fi
  1559. rm -f conftest.c
  1560. [ -n "$1" ] && echo "#include <$1>" > conftest.c
  1561. echo "int main () { $3 return 0; }" >> conftest.c
  1562. - $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest 2>$DEVNULL
  1563. + if $CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest >conftest.log 2>&1; then
  1564. + res=$?
  1565. + log_ok
  1566. + else
  1567. + res=$?
  1568. + log_fail
  1569. + log_msg "Failed commandline was:"
  1570. + log_msg "--------------------------------------------------"
  1571. + log_msg "$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2"
  1572. + cat conftest.log >> config.log
  1573. + log_msg "--------------------------------------------------"
  1574. + fi
  1575. + return $res
  1576. }
  1577.  
  1578. as_check() {
  1579. + log_check "whether $AS supports $1"
  1580. echo "$1" > conftest.asm
  1581. - $AS conftest.asm $ASFLAGS $2 -o conftest.o 2>$DEVNULL
  1582. + if $AS conftest.asm $ASFLAGS $2 -o conftest.o >conftest.log 2>&1; then
  1583. + res=$?
  1584. + log_ok
  1585. + else
  1586. + res=$?
  1587. + log_fail
  1588. + log_msg "Failed commandline was:"
  1589. + log_msg "--------------------------------------------------"
  1590. + log_msg "$AS conftest.asm $ASFLAGS $2 -o conftest.o"
  1591. + cat conftest.log >> config.log
  1592. + log_msg "--------------------------------------------------"
  1593. + fi
  1594. + return $res
  1595. }
  1596.  
  1597. die() {
  1598. + log_msg "DIED: $@"
  1599. echo "$@"
  1600. exit 1
  1601. }
  1602.  
  1603. -rm -f config.h config.mak x264.pc conftest*
  1604. +rm -f config.h config.mak config.log x264.pc conftest*
  1605.  
  1606. prefix='/usr/local'
  1607. exec_prefix='${prefix}'
  1608. @@ -320,6 +373,16 @@ case $host_cpu in
  1609. ;;
  1610. esac
  1611.  
  1612. +log_msg "x264 configure script"
  1613. +if [ ! -z "$*" ]; then
  1614. + msg="Command line options:"
  1615. + for i in $@; do
  1616. + msg="$msg \"$i\""
  1617. + done
  1618. + log_msg "$msg"
  1619. +fi
  1620. +log_msg ""
  1621. +
  1622. # check requirements
  1623.  
  1624. cc_check || die "No working C compiler found."
  1625. @@ -506,9 +569,9 @@ if [ "$debug" = "yes" ]; then
  1626. elif [ $ARCH = ARM ]; then
  1627. # arm-gcc-4.2 produces incorrect output with -ffast-math
  1628. # and it doesn't save any speed anyway on 4.4, so disable it
  1629. - CFLAGS="-O4 -fno-fast-math $CFLAGS"
  1630. + CFLAGS="-O3 -fno-fast-math $CFLAGS"
  1631. else
  1632. - CFLAGS="-O4 -ffast-math $CFLAGS"
  1633. + CFLAGS="-O3 -ffast-math $CFLAGS"
  1634. fi
  1635.  
  1636. if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then
  1637. @@ -586,19 +649,25 @@ Cflags: -I$includedir
  1638. EOF
  1639.  
  1640.  
  1641. -echo "Platform: $ARCH"
  1642. -echo "System: $SYS"
  1643. -echo "asm: $asm"
  1644. -echo "avs input: $avs_input"
  1645. -echo "lavf input: $lavf_input"
  1646. -echo "ffms input: $ffms_input"
  1647. -echo "mp4 output: $mp4_output"
  1648. -echo "pthread: $pthread"
  1649. -echo "debug: $debug"
  1650. -echo "gprof: $gprof"
  1651. -echo "PIC: $pic"
  1652. -echo "shared: $shared"
  1653. -echo "visualize: $vis"
  1654. +echo "Platform: $ARCH" > conftest.log
  1655. +echo "System: $SYS" >> conftest.log
  1656. +echo "asm: $asm" >> conftest.log
  1657. +echo "avs input: $avs_input" >> conftest.log
  1658. +echo "lavf input: $lavf_input" >> conftest.log
  1659. +echo "ffms input: $ffms_input" >> conftest.log
  1660. +echo "mp4 output: $mp4_output" >> conftest.log
  1661. +echo "pthread: $pthread" >> conftest.log
  1662. +echo "debug: $debug" >> conftest.log
  1663. +echo "gprof: $gprof" >> conftest.log
  1664. +echo "PIC: $pic" >> conftest.log
  1665. +echo "shared: $shared" >> conftest.log
  1666. +echo "visualize: $vis" >> conftest.log
  1667. +
  1668. +echo >> config.log
  1669. +cat conftest.log >> config.log
  1670. +cat conftest.log
  1671. +rm conftest.log
  1672. +
  1673. echo
  1674. echo "You can run 'make' or 'make fprofiled' now."
  1675.  
  1676. --
  1677. 1.6.1.2
  1678.  
  1679.  
  1680. From a7c86d0ce68d0835df10b1153134053d02affbbf Mon Sep 17 00:00:00 2001
  1681. From: Diogo Franco <diogomfranco@gmail.com>
  1682. Date: Wed, 27 Jan 2010 13:11:08 -0800
  1683. Subject: [PATCH 09/11] Add configure check for log2 support
  1684. Some incredibly braindamaged operating systems, such as FreeBSD, blatantly ignore the C specification and omit certain functions that are required by ISO C.
  1685. log2f is one of these functions that periodically goes missing in such operating systems.
  1686.  
  1687. ---
  1688. common/osdep.h | 4 ++++
  1689. configure | 4 ++++
  1690. 2 files changed, 8 insertions(+), 0 deletions(-)
  1691.  
  1692. diff --git a/common/osdep.h b/common/osdep.h
  1693. index abae9ac..9988803 100644
  1694. --- a/common/osdep.h
  1695. +++ b/common/osdep.h
  1696. @@ -34,6 +34,10 @@
  1697. #include <inttypes.h>
  1698. #endif
  1699.  
  1700. +#ifndef HAVE_LOG2F
  1701. +#define log2f(x) (logf((x))/0.693147180559945f)
  1702. +#endif
  1703. +
  1704. #ifdef _WIN32
  1705. #include <io.h> // _setmode()
  1706. #include <fcntl.h> // _O_BINARY
  1707. diff --git a/configure b/configure
  1708. index a532788..f778233 100755
  1709. --- a/configure
  1710. +++ b/configure
  1711. @@ -477,6 +477,10 @@ if test "$pthread" = "yes" ; then
  1712. LDFLAGS="$LDFLAGS $libpthread"
  1713. fi
  1714.  
  1715. +if cc_check "math.h" "-Werror" "log2f(2);" ; then
  1716. + CFLAGS="$CFLAGS -DHAVE_LOG2F"
  1717. +fi
  1718. +
  1719. if [ "$lavf_input" = "auto" ] ; then
  1720. lavf_input="no"
  1721. if ${cross_prefix}pkg-config --exists libavformat libavcodec libswscale 2>$DEVNULL; then
  1722. --
  1723. 1.6.1.2
  1724.  
  1725.  
  1726. From 664ac05833320b614f50ccff84306645b7f28620 Mon Sep 17 00:00:00 2001
  1727. From: Jason Garrett-Glaser <darkshikari@gmail.com>
  1728. Date: Wed, 27 Jan 2010 19:41:27 -0800
  1729. Subject: [PATCH 10/11] Fix implicit CBR message to only print when in ABR mode.
  1730. Also make it print outside of debug mode.
  1731.  
  1732. ---
  1733. encoder/ratecontrol.c | 12 ++++++++++--
  1734. 1 files changed, 10 insertions(+), 2 deletions(-)
  1735.  
  1736. diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
  1737. index 746b17a..5304616 100644
  1738. --- a/encoder/ratecontrol.c
  1739. +++ b/encoder/ratecontrol.c
  1740. @@ -436,8 +436,16 @@ int x264_ratecontrol_new( x264_t *h )
  1741. }
  1742. else if( h->param.rc.i_vbv_max_bitrate == 0 )
  1743. {
  1744. - x264_log( h, X264_LOG_DEBUG, "VBV maxrate unspecified, assuming CBR\n" );
  1745. - h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  1746. + if( h->param.rc.i_rc_method == X264_RC_ABR )
  1747. + {
  1748. + x264_log( h, X264_LOG_INFO, "VBV maxrate unspecified, assuming CBR\n" );
  1749. + h->param.rc.i_vbv_max_bitrate = h->param.rc.i_bitrate;
  1750. + }
  1751. + else
  1752. + {
  1753. + x264_log( h, X264_LOG_INFO, "VBV bufsize set but maxrate unspecified, ignored\n" );
  1754. + h->param.rc.i_vbv_buffer_size = 0;
  1755. + }
  1756. }
  1757. }
  1758. if( h->param.rc.i_vbv_max_bitrate < h->param.rc.i_bitrate &&
  1759. --
  1760. 1.6.1.2
  1761.  
  1762.  
  1763. From ba35cc56357f039a61db5c9e53cadd8bfbf8673e Mon Sep 17 00:00:00 2001
  1764. From: Diogo Franco <diogomfranco@gmail.com>
  1765. Date: Wed, 27 Jan 2010 20:29:50 -0800
  1766. Subject: [PATCH 11/11] Implement ffms2 version check
  1767. Depends on ffms2 version 2.13.1 (r272).
  1768. Tries pkg-config's built-in version checking first.
  1769. Uses only the preprocessor to avoid cross-compilation issues.
  1770.  
  1771. ---
  1772. configure | 21 ++++++++++++++++++++-
  1773. 1 files changed, 20 insertions(+), 1 deletions(-)
  1774.  
  1775. diff --git a/configure b/configure
  1776. index f778233..b04ec2a 100755
  1777. --- a/configure
  1778. +++ b/configure
  1779. @@ -507,10 +507,17 @@ if [ "$lavf_input" = "auto" ] ; then
  1780. fi
  1781.  
  1782. if [ "$ffms_input" = "auto" ] ; then
  1783. + ffms_major="2"; ffms_minor="13"; ffms_micro="1"; ffms_bump="0"
  1784. +
  1785. ffms_input="no"
  1786. - if ${cross_prefix}pkg-config --exists ffms2 2>$DEVNULL; then
  1787. + [ $ffms_micro -gt 0 -o $ffms_bump -gt 0 ] && vmicro=".$ffms_micro"
  1788. + [ $ffms_bump -gt 0 ] && vbump=".$ffms_bump"
  1789. + if ${cross_prefix}pkg-config --atleast-version="$ffms_major.$ffms_minor$vmicro$vbump" ffms2 2>$DEVNULL; then
  1790. FFMS2_LIBS="$FFMS2_LIBS $(${cross_prefix}pkg-config --libs ffms2)"
  1791. FFMS2_CFLAGS="$FFMS2_LIBS $(${cross_prefix}pkg-config --cflags ffms2)"
  1792. + api_check="no"
  1793. + else
  1794. + api_check="yes"
  1795. fi
  1796. [ -z "$FFMS2_LIBS" ] && FFMS2_LIBS="-lffms2"
  1797.  
  1798. @@ -520,6 +527,18 @@ if [ "$ffms_input" = "auto" ] ; then
  1799. ffms_input="yes"
  1800. FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS"
  1801. fi
  1802. +
  1803. + if [ $api_check = "yes" -a $ffms_input = "yes" ]; then
  1804. + log_check "whether ffms2 version is at least $ffms_major.$ffms_minor$vmicro$vbump"
  1805. + $CC $CFLAGS $FFMS2_CFLAGS -c -o conftest -x c - >$DEVNULL 2>&1 <<EOF
  1806. +#include <ffms.h>
  1807. +#if FFMS_VERSION < (($ffms_major << 24) | ($ffms_minor << 16)| ($ffms_micro << 8) | $ffms_bump)
  1808. +#error Requires ffms2 version 2.13.1
  1809. +#endif
  1810. +int main() { return 0; }
  1811. +EOF
  1812. + [ $? = 0 ] && log_ok || { ffms_input="no"; log_fail; }
  1813. + fi
  1814. fi
  1815.  
  1816. if [ "$ffms_input" = "yes" ]; then
  1817. --
  1818. 1.6.1.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement