Guest User

Untitled

a guest
Apr 18th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.93 KB | None | 0 0
  1. From 7340c73604eec66a58cc2bc9bbb6a3a346af09da Mon Sep 17 00:00:00 2001
  2. From: unknown <Konstantin@RED.(none)>
  3. Date: Wed, 30 Nov 2011 22:55:45 +0200
  4. Subject: [PATCH] mpegvideo.c : Code cleanup
  5.  
  6. ---
  7. libavcodec/mpegvideo.c | 2622 +++++++++++++++++++++++++++---------------------
  8. 1 files changed, 1486 insertions(+), 1136 deletions(-)
  9.  
  10. diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
  11. index dcef706..2c2adc7 100644
  12. --- a/libavcodec/mpegvideo.c
  13. +++ b/libavcodec/mpegvideo.c
  14. @@ -1,25 +1,25 @@
  15. /*
  16. * The simplest mpeg encoder (well, it was the simplest!)
  17. * Copyright (c) 2000,2001 Fabrice Bellard
  18. - * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  19. + * Copyright (c) 2002-2004 Michael Niedermayer < michaelni@gmx.at>
  20. *
  21. - * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
  22. + * 4MV & hq & B-frame encoding stuff by Michael Niedermayer < michaelni@gmx.at>
  23. *
  24. * This file is part of Libav.
  25. *
  26. * Libav is free software; you can redistribute it and/or
  27. - * modify it under the terms of the GNU Lesser General Public
  28. + * modif y it under the terms of the GNU Lesser General Public
  29. * License as published by the Free Software Foundation; either
  30. * version 2.1 of the License, or (at your option) any later version.
  31. *
  32. * Libav is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  35. - * Lesser General Public License for more details.
  36. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  37. + * Lesser General Public License for more details.
  38. *
  39. * You should have received a copy of the GNU Lesser General Public
  40. - * License along with Libav; if not, write to the Free Software
  41. - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  42. + * License along with Libav; if not, write to the Free Software
  43. + * Foundation, Inc., 51 Franklin Street, Fif th Floor, Boston, MA 02110-1301 USA
  44. */
  45.  
  46. /**
  47. @@ -39,10 +39,10 @@
  48. #include "faandct.h"
  49. #include "xvmc_internal.h"
  50. #include "thread.h"
  51. -#include <limits.h>
  52. +#include < limits.h>
  53.  
  54. //#undef NDEBUG
  55. -//#include <assert.h>
  56. +//#include < assert.h>
  57.  
  58. static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
  59. DCTELEM *block, int n, int qscale);
  60. @@ -60,50 +60,72 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
  61. DCTELEM *block, int n, int qscale);
  62.  
  63.  
  64. -/* enable all paranoid tests for rounding, overflows, etc... */
  65. +/* enable all paranoid tests for rounding, overflows, etc... */
  66. //#define PARANOID
  67.  
  68. //#define DEBUG
  69.  
  70.  
  71. -static const uint8_t ff_default_chroma_qscale_table[32]={
  72. -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  73. - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
  74. +static const uint8_t ff_default_chroma_qscale_table[32] = {
  75. +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  76. +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  77. + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
  78. + 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
  79. };
  80.  
  81. -const uint8_t ff_mpeg1_dc_scale_table[128]={
  82. -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  83. - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  84. - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  85. - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  86. - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  87. +const uint8_t ff_mpeg1_dc_scale_table[128] = {
  88. +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  89. +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  90. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  91. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  92. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  93. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  94. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  95. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  96. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  97. + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  98. };
  99.  
  100. -static const uint8_t mpeg2_dc_scale_table1[128]={
  101. -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  102. - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  103. - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  104. - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  105. - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  106. +static const uint8_t mpeg2_dc_scale_table1[128] = {
  107. +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  108. +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  109. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  110. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  111. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  112. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  113. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  114. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  115. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  116. + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  117. };
  118.  
  119. -static const uint8_t mpeg2_dc_scale_table2[128]={
  120. -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  121. - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  122. - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  123. - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  124. - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  125. +static const uint8_t mpeg2_dc_scale_table2[128] = {
  126. +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  127. +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  128. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  129. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  130. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  131. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  132. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  133. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  134. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  135. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  136. };
  137.  
  138. -static const uint8_t mpeg2_dc_scale_table3[128]={
  139. -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  140. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  141. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  142. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  143. - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  144. +static const uint8_t mpeg2_dc_scale_table3[128] = {
  145. +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  146. +// 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  147. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  148. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  149. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  150. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  151. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  152. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  153. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  154. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  155. };
  156.  
  157. -const uint8_t * const ff_mpeg2_dc_scale_table[4]={
  158. +const uint8_t * const ff_mpeg2_dc_scale_table[4] = {
  159. ff_mpeg1_dc_scale_table,
  160. mpeg2_dc_scale_table1,
  161. mpeg2_dc_scale_table2,
  162. @@ -123,37 +145,39 @@ const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = {
  163. PIX_FMT_NONE
  164. };
  165.  
  166. -const uint8_t *avpriv_mpv_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){
  167. +const uint8_t *avpriv_mpv_find_start_code(const uint8_t * restrict p,
  168. + const uint8_t *end,
  169. + uint32_t * restrict state){
  170. int i;
  171.  
  172. - assert(p<=end);
  173. - if(p>=end)
  174. + assert(p <= end);
  175. + if (p> = end)
  176. return end;
  177.  
  178. - for(i=0; i<3; i++){
  179. - uint32_t tmp= *state << 8;
  180. - *state= tmp + *(p++);
  181. - if(tmp == 0x100 || p==end)
  182. + for (i = 0; i < 3; i++ ){
  183. + uint32_t tmp = *state << 8;
  184. + *state = tmp + *(p++ );
  185. + if (tmp == 0x100 || p == end)
  186. return p;
  187. }
  188.  
  189. - while(p<end){
  190. - if (p[-1] > 1 ) p+= 3;
  191. - else if(p[-2] ) p+= 2;
  192. - else if(p[-3]|(p[-1]-1)) p++;
  193. + while(p < end){
  194. + if (p[-1] > 1 ) p += 3;
  195. + else if (p[-2] ) p += 2;
  196. + else if (p[-3]|(p[-1]-1)) p++ ;
  197. else{
  198. - p++;
  199. + p + + ;
  200. break;
  201. }
  202. }
  203.  
  204. - p= FFMIN(p, end)-4;
  205. - *state= AV_RB32(p);
  206. + p = FFMIN(p, end)-4;
  207. + *state = AV_RB32(p);
  208.  
  209. - return p+4;
  210. + return p + 4;
  211. }
  212.  
  213. -/* init common dct for both encoder and decoder */
  214. +/* init common dct for both encoder and decoder */
  215. av_cold int ff_dct_common_init(MpegEncContext *s)
  216. {
  217. dsputil_init(&s->dsp, s->avctx);
  218. @@ -163,11 +187,11 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
  219. s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
  220. s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
  221. s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
  222. - if(s->flags & CODEC_FLAG_BITEXACT)
  223. + if (s->flags & CODEC_FLAG_BITEXACT)
  224. s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
  225. s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
  226.  
  227. -#if HAVE_MMX
  228. +#if HAVE_MMX
  229. MPV_common_init_mmx(s);
  230. #elif ARCH_ALPHA
  231. MPV_common_init_axp(s);
  232. @@ -184,9 +208,9 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
  233. #endif
  234.  
  235. /* load & permutate scantables
  236. - note: only wmv uses different ones
  237. + note: only wmv uses dif ferent ones
  238. */
  239. - if(s->alternate_scan){
  240. + if (s->alternate_scan){
  241. ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
  242. ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
  243. }else{
  244. @@ -201,7 +225,7 @@ av_cold int ff_dct_common_init(MpegEncContext *s)
  245.  
  246. void ff_copy_picture(Picture *dst, Picture *src){
  247. *dst = *src;
  248. - dst->f.type= FF_BUFFER_TYPE_COPY;
  249. + dst->f.type = FF_BUFFER_TYPE_COPY;
  250. }
  251.  
  252. /**
  253. @@ -209,9 +233,9 @@ void ff_copy_picture(Picture *dst, Picture *src){
  254. */
  255. static void free_frame_buffer(MpegEncContext *s, Picture *pic)
  256. {
  257. - /* Windows Media Image codecs allocate internal buffers with different
  258. - dimensions; ignore user defined callbacks for these */
  259. - if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
  260. + /* Windows Media Image codecs allocate internal buffers with dif ferent
  261. + dimensions; ignore user defined callbacks for these */
  262. + if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
  263. ff_thread_release_buffer(s->avctx, (AVFrame*)pic);
  264. else
  265. avcodec_default_release_buffer(s->avctx, (AVFrame*)pic);
  266. @@ -225,37 +249,40 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
  267. {
  268. int r;
  269.  
  270. - if (s->avctx->hwaccel) {
  271. + if (s->avctx->hwaccel) {
  272. assert(!pic->f.hwaccel_picture_private);
  273. - if (s->avctx->hwaccel->priv_data_size) {
  274. + if (s->avctx->hwaccel->priv_data_size) {
  275. pic->f.hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size);
  276. - if (!pic->f.hwaccel_picture_private) {
  277. + if (!pic->f.hwaccel_picture_private) {
  278. av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
  279. return -1;
  280. }
  281. }
  282. }
  283.  
  284. - if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
  285. + if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE)
  286. r = ff_thread_get_buffer(s->avctx, (AVFrame*)pic);
  287. else
  288. r = avcodec_default_get_buffer(s->avctx, (AVFrame*)pic);
  289.  
  290. - if (r < 0 || !pic->f.age || !pic->f.type || !pic->f.data[0]) {
  291. + if (r < 0 || !pic->f.age || !pic->f.type || !pic->f.data[0]) {
  292. av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n",
  293. r, pic->f.age, pic->f.type, pic->f.data[0]);
  294. av_freep(&pic->f.hwaccel_picture_private);
  295. return -1;
  296. }
  297.  
  298. - if (s->linesize && (s->linesize != pic->f.linesize[0] || s->uvlinesize != pic->f.linesize[1])) {
  299. - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
  300. + if (s->linesize && (s->linesize != pic->f.linesize[0] ||
  301. + s->uvlinesize != pic->f.linesize[1])) {
  302. + av_log(s->avctx, AV_LOG_ERROR,
  303. + "get_buffer() failed (stride changed)\n");
  304. free_frame_buffer(s, pic);
  305. return -1;
  306. }
  307.  
  308. - if (pic->f.linesize[1] != pic->f.linesize[2]) {
  309. - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
  310. + if (pic->f.linesize[1] != pic->f.linesize[2]) {
  311. + av_log(s->avctx, AV_LOG_ERROR,
  312. + "get_buffer() failed (uv stride mismatch)\n");
  313. free_frame_buffer(s, pic);
  314. return -1;
  315. }
  316. @@ -265,75 +292,97 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
  317.  
  318. /**
  319. * allocates a Picture
  320. - * The pixels are allocated/set by calling get_buffer() if shared=0
  321. + * The pixels are allocated/set by calling get_buffer() if shared = 0
  322. */
  323. int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){
  324. - const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11
  325. - const int mb_array_size= s->mb_stride*s->mb_height;
  326. - const int b8_array_size= s->b8_stride*s->mb_height*2;
  327. - const int b4_array_size= s->b4_stride*s->mb_height*4;
  328. + const int big_mb_num = s->mb_stride*(s->mb_height + 1) + 1;
  329. +
  330. + //the + 1 is needed so memset(,,stride*height) does not sig11
  331. +
  332. + const int mb_array_size = s->mb_stride*s->mb_height;
  333. + const int b8_array_size = s->b8_stride*s->mb_height*2;
  334. + const int b4_array_size = s->b4_stride*s->mb_height*4;
  335. int i;
  336. - int r= -1;
  337. + int r = -1;
  338.  
  339. - if(shared){
  340. + if (shared){
  341. assert(pic->f.data[0]);
  342. assert(pic->f.type == 0 || pic->f.type == FF_BUFFER_TYPE_SHARED);
  343. pic->f.type = FF_BUFFER_TYPE_SHARED;
  344. }else{
  345. assert(!pic->f.data[0]);
  346.  
  347. - if (alloc_frame_buffer(s, pic) < 0)
  348. + if (alloc_frame_buffer(s, pic) < 0)
  349. return -1;
  350.  
  351. - s->linesize = pic->f.linesize[0];
  352. + s->linesize = pic->f.linesize[0];
  353. s->uvlinesize = pic->f.linesize[1];
  354. }
  355.  
  356. - if (pic->f.qscale_table == NULL) {
  357. - if (s->encoding) {
  358. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var , mb_array_size * sizeof(int16_t) , fail)
  359. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t) , fail)
  360. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean , mb_array_size * sizeof(int8_t ) , fail)
  361. - }
  362. -
  363. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.mbskip_table, mb_array_size * sizeof(uint8_t) + 2, fail) //the +2 is for the slice end check
  364. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table_base , (big_mb_num + s->mb_stride) * sizeof(uint8_t) , fail)
  365. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail)
  366. - pic->f.mb_type = pic->mb_type_base + 2*s->mb_stride + 1;
  367. - pic->f.qscale_table = pic->qscale_table_base + 2*s->mb_stride + 1;
  368. - if(s->out_format == FMT_H264){
  369. - for(i=0; i<2; i++){
  370. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t), fail)
  371. - pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
  372. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
  373. + if (pic->f.qscale_table == NULL) {
  374. + if (s->encoding) {
  375. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var ,
  376. + mb_array_size * sizeof(int16_t) , fail)
  377. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var,
  378. + mb_array_size * sizeof(int16_t) , fail)
  379. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean ,
  380. + mb_array_size * sizeof(int8_t ) , fail)
  381. + }
  382. +
  383. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.mbskip_table,
  384. + mb_array_size * sizeof(uint8_t) + 2, fail)
  385. + //the + 2 is for the slice end check
  386. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table_base ,
  387. + (big_mb_num + s->mb_stride) * sizeof(uint8_t),
  388. + fail)
  389. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base ,
  390. + (big_mb_num + s->mb_stride) * sizeof(uint32_t),
  391. + fail)
  392. + pic->f.mb_type = pic->mb_type_base + 2*s->mb_stride + 1;
  393. + pic->f.qscale_table = pic->qscale_table_base + 2*s->mb_stride + 1;
  394. + if (s->out_format == FMT_H264){
  395. + for (i = 0; i < 2; i++ ){
  396. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 *
  397. + (b4_array_size + 4) * sizeof(int16_t), fail)
  398. + pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
  399. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size *
  400. + sizeof(uint8_t), fail)
  401. }
  402. pic->f.motion_subsample_log2 = 2;
  403. - }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
  404. - for(i=0; i<2; i++){
  405. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail)
  406. - pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
  407. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail)
  408. + }else if (s->out_format == FMT_H263 || s->encoding ||
  409. + (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
  410. + for (i = 0; i < 2; i++ ){
  411. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 *
  412. + (b8_array_size + 4) * sizeof(int16_t), fail)
  413. + pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
  414. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i],
  415. + 4*mb_array_size * sizeof(uint8_t), fail)
  416. }
  417. pic->f.motion_subsample_log2 = 3;
  418. }
  419. - if(s->avctx->debug&FF_DEBUG_DCT_COEFF) {
  420. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, 64 * mb_array_size * sizeof(DCTELEM) * 6, fail)
  421. + if (s->avctx->debug&FF_DEBUG_DCT_COEFF) {
  422. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, 64 * mb_array_size *
  423. + sizeof(DCTELEM) * 6, fail)
  424. }
  425. pic->f.qstride = s->mb_stride;
  426. - FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan , 1 * sizeof(AVPanScan), fail)
  427. + FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan , 1 *
  428. + sizeof(AVPanScan), fail)
  429. }
  430.  
  431. - /* It might be nicer if the application would keep track of these
  432. + /* It might be nicer if the application would keep track of these
  433. * but it would require an API change. */
  434. - memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
  435. - s->prev_pict_types[0]= s->dropable ? AV_PICTURE_TYPE_B : s->pict_type;
  436. - if (pic->f.age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->f.age] == AV_PICTURE_TYPE_B)
  437. - pic->f.age = INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway.
  438. + memmove(s->prev_pict_types + 1, s->prev_pict_types,
  439. + PREV_PICT_TYPES_BUFFER_SIZE-1);
  440. + s->prev_pict_types[0] = s->dropable ? AV_PICTURE_TYPE_B : s->pict_type;
  441. + if (pic->f.age < PREV_PICT_TYPES_BUFFER_SIZE &&
  442. + s->prev_pict_types[pic->f.age] == AV_PICTURE_TYPE_B)
  443. + pic->f.age = INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2
  444. + // and it is a bit tricky to skip them anyway.
  445. pic->owner2 = s;
  446.  
  447. return 0;
  448. -fail: //for the FF_ALLOCZ_OR_GOTO macro
  449. - if(r>=0)
  450. +fail: //for the FF_ALLOCZ_OR_GOTO macro
  451. + if (r> = 0)
  452. free_frame_buffer(s, pic);
  453. return -1;
  454. }
  455. @@ -344,7 +393,7 @@ fail: //for the FF_ALLOCZ_OR_GOTO macro
  456. static void free_picture(MpegEncContext *s, Picture *pic){
  457. int i;
  458.  
  459. - if (pic->f.data[0] && pic->f.type != FF_BUFFER_TYPE_SHARED) {
  460. + if (pic->f.data[0] && pic->f.type != FF_BUFFER_TYPE_SHARED) {
  461. free_frame_buffer(s, pic);
  462. }
  463.  
  464. @@ -357,14 +406,14 @@ static void free_picture(MpegEncContext *s, Picture *pic){
  465. av_freep(&pic->f.dct_coeff);
  466. av_freep(&pic->f.pan_scan);
  467. pic->f.mb_type = NULL;
  468. - for(i=0; i<2; i++){
  469. + for (i = 0; i < 2; i++ ){
  470. av_freep(&pic->motion_val_base[i]);
  471. av_freep(&pic->f.ref_index[i]);
  472. }
  473.  
  474. - if (pic->f.type == FF_BUFFER_TYPE_SHARED) {
  475. - for(i=0; i<4; i++){
  476. - pic->f.base[i] =
  477. + if (pic->f.type == FF_BUFFER_TYPE_SHARED) {
  478. + for (i = 0; i < 4; i++ ){
  479. + pic->f.base[i] =
  480. pic->f.data[i] = NULL;
  481. }
  482. pic->f.type = 0;
  483. @@ -372,40 +421,49 @@ static void free_picture(MpegEncContext *s, Picture *pic){
  484. }
  485.  
  486. static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){
  487. - int y_size = s->b8_stride * (2 * s->mb_height + 1);
  488. - int c_size = s->mb_stride * (s->mb_height + 1);
  489. - int yc_size = y_size + 2 * c_size;
  490. + int y_size = s->b8_stride * (2 * s->mb_height + 1);
  491. + int c_size = s->mb_stride * (s->mb_height + 1);
  492. + int yc_size = y_size + 2 * c_size;
  493. int i;
  494.  
  495. - // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
  496. - FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance
  497. -
  498. - //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer()
  499. - FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail)
  500. - s->me.temp= s->me.scratchpad;
  501. - s->rd_scratchpad= s->me.scratchpad;
  502. - s->b_scratchpad= s->me.scratchpad;
  503. - s->obmc_scratchpad= s->me.scratchpad + 16;
  504. - if (s->encoding) {
  505. - FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map , ME_MAP_SIZE*sizeof(uint32_t), fail)
  506. - FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail)
  507. - if(s->avctx->noise_reduction){
  508. - FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail)
  509. + // edge emu needs blocksize + filter length - 1
  510. + //( = 17x17 for halfpel / 21x21 for h264)
  511. + FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer,
  512. + (s->width + 64)*2*21*2, fail);
  513. + //(width + edge + align)*interlaced*MBsize*tolerance
  514. +
  515. + // FIXME should be linesize instead of s->width*2
  516. + // but that is not known befor e get_buffer()
  517. + FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad,
  518. +
Add Comment
Please, Sign In to add comment