Merge "Fix incorrect macroblock counts in twopass rate control"
[profile/ivi/libvpx.git] / vp8 / encoder / ethreading.c
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include "onyx_int.h"
12 #include "vp8/common/threading.h"
13 #include "vp8/common/common.h"
14 #include "vp8/common/extend.h"
15
16 #if CONFIG_MULTITHREAD
17
18 extern int vp8cx_encode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
19                                          TOKENEXTRA **t, int recon_yoffset,
20                                          int recon_uvoffset);
21 extern int vp8cx_encode_intra_macro_block(VP8_COMP *cpi, MACROBLOCK *x,
22                                           TOKENEXTRA **t);
23 extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x);
24 extern void vp8_build_block_offsets(MACROBLOCK *x);
25 extern void vp8_setup_block_ptrs(MACROBLOCK *x);
26
27 #if CONFIG_MULTITHREAD
28
29 extern void loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
30
31 static THREAD_FUNCTION loopfilter_thread(void *p_data)
32 {
33     VP8_COMP *cpi = (VP8_COMP *)(((LPFTHREAD_DATA *)p_data)->ptr1);
34     VP8_COMMON *cm = &cpi->common;
35
36     while (1)
37     {
38         if (cpi->b_multi_threaded == 0)
39             break;
40
41         if (sem_wait(&cpi->h_event_start_lpf) == 0)
42         {
43             if (cpi->b_multi_threaded == FALSE) // we're shutting down
44                 break;
45
46             loopfilter_frame(cpi, cm);
47
48             sem_post(&cpi->h_event_end_lpf);
49         }
50     }
51
52     return 0;
53 }
54 #endif
55
56 static
57 THREAD_FUNCTION thread_encoding_proc(void *p_data)
58 {
59     int ithread = ((ENCODETHREAD_DATA *)p_data)->ithread;
60     VP8_COMP *cpi = (VP8_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr1);
61     MB_ROW_COMP *mbri = (MB_ROW_COMP *)(((ENCODETHREAD_DATA *)p_data)->ptr2);
62     ENTROPY_CONTEXT_PLANES mb_row_left_context;
63
64     const int nsync = cpi->mt_sync_range;
65     //printf("Started thread %d\n", ithread);
66
67     while (1)
68     {
69         if (cpi->b_multi_threaded == 0)
70             break;
71
72         //if(WaitForSingleObject(cpi->h_event_mbrencoding[ithread], INFINITE) == WAIT_OBJECT_0)
73         if (sem_wait(&cpi->h_event_start_encoding[ithread]) == 0)
74         {
75             VP8_COMMON *cm = &cpi->common;
76             int mb_row;
77             MACROBLOCK *x = &mbri->mb;
78             MACROBLOCKD *xd = &x->e_mbd;
79             TOKENEXTRA *tp ;
80
81             int *segment_counts = mbri->segment_counts;
82             int *totalrate = &mbri->totalrate;
83
84             if (cpi->b_multi_threaded == FALSE) // we're shutting down
85                 break;
86
87             for (mb_row = ithread + 1; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1))
88             {
89
90                 int i;
91                 int recon_yoffset, recon_uvoffset;
92                 int mb_col;
93                 int ref_fb_idx = cm->lst_fb_idx;
94                 int dst_fb_idx = cm->new_fb_idx;
95                 int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride;
96                 int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
97                 volatile int *last_row_current_mb_col;
98                 INT64 activity_sum = 0;
99
100                 tp = cpi->tok + (mb_row * (cm->mb_cols * 16 * 24));
101
102                 last_row_current_mb_col = &cpi->mt_current_mb_col[mb_row - 1];
103
104                 // reset above block coeffs
105                 xd->above_context = cm->above_context;
106                 xd->left_context = &mb_row_left_context;
107
108                 vp8_zero(mb_row_left_context);
109
110                 xd->up_available = (mb_row != 0);
111                 recon_yoffset = (mb_row * recon_y_stride * 16);
112                 recon_uvoffset = (mb_row * recon_uv_stride * 8);
113
114                 cpi->tplist[mb_row].start = tp;
115
116                 //printf("Thread mb_row = %d\n", mb_row);
117
118                 // for each macroblock col in image
119                 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
120                 {
121                     int seg_map_index = (mb_row * cm->mb_cols);
122
123                     if ((mb_col & (nsync - 1)) == 0)
124                     {
125                         while (mb_col > (*last_row_current_mb_col - nsync) && *last_row_current_mb_col != cm->mb_cols - 1)
126                         {
127                             x86_pause_hint();
128                             thread_sleep(0);
129                         }
130                     }
131
132                     // Distance of Mb to the various image edges.
133                     // These specified to 8th pel as they are always compared to values that are in 1/8th pel units
134                     xd->mb_to_left_edge = -((mb_col * 16) << 3);
135                     xd->mb_to_right_edge = ((cm->mb_cols - 1 - mb_col) * 16) << 3;
136                     xd->mb_to_top_edge = -((mb_row * 16) << 3);
137                     xd->mb_to_bottom_edge = ((cm->mb_rows - 1 - mb_row) * 16) << 3;
138
139                     // Set up limit values for motion vectors used to prevent them extending outside the UMV borders
140                     x->mv_col_min = -((mb_col * 16) + (VP8BORDERINPIXELS - 16));
141                     x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + (VP8BORDERINPIXELS - 16);
142                     x->mv_row_min = -((mb_row * 16) + (VP8BORDERINPIXELS - 16));
143                     x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + (VP8BORDERINPIXELS - 16);
144
145                     xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
146                     xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
147                     xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
148                     xd->left_available = (mb_col != 0);
149
150                     x->rddiv = cpi->RDDIV;
151                     x->rdmult = cpi->RDMULT;
152
153                     if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
154                         activity_sum += vp8_activity_masking(cpi, x);
155
156                     // Is segmentation enabled
157                     // MB level adjutment to quantizer
158                     if (xd->segmentation_enabled)
159                     {
160                         // Code to set segment id in xd->mbmi.segment_id for current MB (with range checking)
161                         if (cpi->segmentation_map[seg_map_index + mb_col] <= 3)
162                             xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[seg_map_index + mb_col];
163                         else
164                             xd->mode_info_context->mbmi.segment_id = 0;
165
166                         vp8cx_mb_init_quantizer(cpi, x);
167                     }
168                     else
169                         xd->mode_info_context->mbmi.segment_id = 0; // Set to Segment 0 by default
170
171                     x->active_ptr = cpi->active_map + seg_map_index + mb_col;
172
173                     if (cm->frame_type == KEY_FRAME)
174                     {
175                         *totalrate += vp8cx_encode_intra_macro_block(cpi, x, &tp);
176 #ifdef MODE_STATS
177                         y_modes[xd->mbmi.mode] ++;
178 #endif
179                     }
180                     else
181                     {
182                         *totalrate += vp8cx_encode_inter_macroblock(cpi, x, &tp, recon_yoffset, recon_uvoffset);
183
184 #ifdef MODE_STATS
185                         inter_y_modes[xd->mbmi.mode] ++;
186
187                         if (xd->mbmi.mode == SPLITMV)
188                         {
189                             int b;
190
191                             for (b = 0; b < xd->mbmi.partition_count; b++)
192                             {
193                                 inter_b_modes[x->partition->bmi[b].mode] ++;
194                             }
195                         }
196
197 #endif
198
199                         // Count of last ref frame 0,0 useage
200                         if ((xd->mode_info_context->mbmi.mode == ZEROMV) && (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME))
201                             cpi->inter_zz_count++;
202
203                         // Special case code for cyclic refresh
204                         // If cyclic update enabled then copy xd->mbmi.segment_id; (which may have been updated based on mode
205                         // during vp8cx_encode_inter_macroblock()) back into the global sgmentation map
206                         if (cpi->cyclic_refresh_mode_enabled && xd->segmentation_enabled)
207                         {
208                             const MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
209                             cpi->segmentation_map[seg_map_index + mb_col] = mbmi->segment_id;
210
211                             // If the block has been refreshed mark it as clean (the magnitude of the -ve influences how long it will be before we consider another refresh):
212                             // Else if it was coded (last frame 0,0) and has not already been refreshed then mark it as a candidate for cleanup next time (marked 0)
213                             // else mark it as dirty (1).
214                             if (mbmi->segment_id)
215                                 cpi->cyclic_refresh_map[seg_map_index + mb_col] = -1;
216                             else if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME))
217                             {
218                                 if (cpi->cyclic_refresh_map[seg_map_index + mb_col] == 1)
219                                     cpi->cyclic_refresh_map[seg_map_index + mb_col] = 0;
220                             }
221                             else
222                                 cpi->cyclic_refresh_map[seg_map_index + mb_col] = 1;
223
224                         }
225                     }
226                     cpi->tplist[mb_row].stop = tp;
227
228                     x->gf_active_ptr++; // Increment pointer into gf useage flags structure for next mb
229
230                     for (i = 0; i < 16; i++)
231                         vpx_memcpy(&xd->mode_info_context->bmi[i], &xd->block[i].bmi, sizeof(xd->block[i].bmi));
232
233                     // adjust to the next column of macroblocks
234                     x->src.y_buffer += 16;
235                     x->src.u_buffer += 8;
236                     x->src.v_buffer += 8;
237
238                     recon_yoffset += 16;
239                     recon_uvoffset += 8;
240
241                     // Keep track of segment useage
242                     segment_counts[xd->mode_info_context->mbmi.segment_id]++;
243
244                     // skip to next mb
245                     xd->mode_info_context++;
246                     x->partition_info++;
247                     xd->above_context++;
248
249                     cpi->mt_current_mb_col[mb_row] = mb_col;
250                 }
251
252                 //extend the recon for intra prediction
253                 vp8_extend_mb_row(
254                     &cm->yv12_fb[dst_fb_idx],
255                     xd->dst.y_buffer + 16,
256                     xd->dst.u_buffer + 8,
257                     xd->dst.v_buffer + 8);
258
259                 // this is to account for the border
260                 xd->mode_info_context++;
261                 x->partition_info++;
262                 x->activity_sum += activity_sum;
263
264                 x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols;
265                 x->src.u_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
266                 x->src.v_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
267
268                 xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
269                 x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
270
271                 if (mb_row == cm->mb_rows - 1)
272                 {
273                     //SetEvent(cpi->h_event_main);
274                     sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
275                 }
276             }
277         }
278     }
279
280     //printf("exit thread %d\n", ithread);
281     return 0;
282 }
283
284 static void setup_mbby_copy(MACROBLOCK *mbdst, MACROBLOCK *mbsrc)
285 {
286
287     MACROBLOCK *x = mbsrc;
288     MACROBLOCK *z = mbdst;
289     int i;
290
291     z->ss               = x->ss;
292     z->ss_count          = x->ss_count;
293     z->searches_per_step  = x->searches_per_step;
294     z->errorperbit      = x->errorperbit;
295
296     z->sadperbit16      = x->sadperbit16;
297     z->sadperbit4       = x->sadperbit4;
298     z->errthresh        = x->errthresh;
299
300     /*
301     z->mv_col_min    = x->mv_col_min;
302     z->mv_col_max    = x->mv_col_max;
303     z->mv_row_min    = x->mv_row_min;
304     z->mv_row_max    = x->mv_row_max;
305     z->vector_range = x->vector_range ;
306     */
307
308     z->vp8_short_fdct4x4     = x->vp8_short_fdct4x4;
309     z->vp8_short_fdct8x4     = x->vp8_short_fdct8x4;
310     z->short_walsh4x4    = x->short_walsh4x4;
311     z->quantize_b        = x->quantize_b;
312     z->optimize          = x->optimize;
313
314     /*
315     z->mvc              = x->mvc;
316     z->src.y_buffer      = x->src.y_buffer;
317     z->src.u_buffer      = x->src.u_buffer;
318     z->src.v_buffer      = x->src.v_buffer;
319     */
320
321
322     vpx_memcpy(z->mvcosts,          x->mvcosts,         sizeof(x->mvcosts));
323     z->mvcost[0] = &z->mvcosts[0][mv_max+1];
324     z->mvcost[1] = &z->mvcosts[1][mv_max+1];
325     z->mvsadcost[0] = &z->mvsadcosts[0][mv_max+1];
326     z->mvsadcost[1] = &z->mvsadcosts[1][mv_max+1];
327
328
329     vpx_memcpy(z->token_costs,       x->token_costs,      sizeof(x->token_costs));
330     vpx_memcpy(z->inter_bmode_costs,  x->inter_bmode_costs, sizeof(x->inter_bmode_costs));
331     //memcpy(z->mvcosts,            x->mvcosts,         sizeof(x->mvcosts));
332     //memcpy(z->mvcost,         x->mvcost,          sizeof(x->mvcost));
333     vpx_memcpy(z->mbmode_cost,       x->mbmode_cost,      sizeof(x->mbmode_cost));
334     vpx_memcpy(z->intra_uv_mode_cost,  x->intra_uv_mode_cost, sizeof(x->intra_uv_mode_cost));
335     vpx_memcpy(z->bmode_costs,       x->bmode_costs,      sizeof(x->bmode_costs));
336
337     for (i = 0; i < 25; i++)
338     {
339         z->block[i].quant           = x->block[i].quant;
340         z->block[i].quant_fast      = x->block[i].quant_fast;
341         z->block[i].quant_shift     = x->block[i].quant_shift;
342         z->block[i].zbin            = x->block[i].zbin;
343         z->block[i].zrun_zbin_boost   = x->block[i].zrun_zbin_boost;
344         z->block[i].round           = x->block[i].round;
345         /*
346         z->block[i].src             = x->block[i].src;
347         */
348         z->block[i].src_stride       = x->block[i].src_stride;
349         z->block[i].force_empty      = x->block[i].force_empty;
350
351     }
352
353     {
354         MACROBLOCKD *xd = &x->e_mbd;
355         MACROBLOCKD *zd = &z->e_mbd;
356
357         /*
358         zd->mode_info_context = xd->mode_info_context;
359         zd->mode_info        = xd->mode_info;
360
361         zd->mode_info_stride  = xd->mode_info_stride;
362         zd->frame_type       = xd->frame_type;
363         zd->up_available     = xd->up_available   ;
364         zd->left_available   = xd->left_available;
365         zd->left_context     = xd->left_context;
366         zd->last_frame_dc     = xd->last_frame_dc;
367         zd->last_frame_dccons = xd->last_frame_dccons;
368         zd->gold_frame_dc     = xd->gold_frame_dc;
369         zd->gold_frame_dccons = xd->gold_frame_dccons;
370         zd->mb_to_left_edge    = xd->mb_to_left_edge;
371         zd->mb_to_right_edge   = xd->mb_to_right_edge;
372         zd->mb_to_top_edge     = xd->mb_to_top_edge   ;
373         zd->mb_to_bottom_edge  = xd->mb_to_bottom_edge;
374         zd->gf_active_ptr     = xd->gf_active_ptr;
375         zd->frames_since_golden       = xd->frames_since_golden;
376         zd->frames_till_alt_ref_frame   = xd->frames_till_alt_ref_frame;
377         */
378         zd->subpixel_predict         = xd->subpixel_predict;
379         zd->subpixel_predict8x4      = xd->subpixel_predict8x4;
380         zd->subpixel_predict8x8      = xd->subpixel_predict8x8;
381         zd->subpixel_predict16x16    = xd->subpixel_predict16x16;
382         zd->segmentation_enabled     = xd->segmentation_enabled;
383         zd->mb_segement_abs_delta      = xd->mb_segement_abs_delta;
384         vpx_memcpy(zd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
385
386         for (i = 0; i < 25; i++)
387         {
388             zd->block[i].dequant = xd->block[i].dequant;
389         }
390     }
391 }
392
393 void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
394                                MACROBLOCK *x,
395                                MB_ROW_COMP *mbr_ei,
396                                int mb_row,
397                                int count
398                               )
399 {
400
401     VP8_COMMON *const cm = & cpi->common;
402     MACROBLOCKD *const xd = & x->e_mbd;
403     int i;
404     (void) mb_row;
405
406     for (i = 0; i < count; i++)
407     {
408         MACROBLOCK *mb = & mbr_ei[i].mb;
409         MACROBLOCKD *mbd = &mb->e_mbd;
410
411         mbd->subpixel_predict        = xd->subpixel_predict;
412         mbd->subpixel_predict8x4     = xd->subpixel_predict8x4;
413         mbd->subpixel_predict8x8     = xd->subpixel_predict8x8;
414         mbd->subpixel_predict16x16   = xd->subpixel_predict16x16;
415 #if CONFIG_RUNTIME_CPU_DETECT
416         mbd->rtcd                   = xd->rtcd;
417 #endif
418         mb->gf_active_ptr            = x->gf_active_ptr;
419
420         mb->vector_range             = 32;
421
422         vpx_memset(mbr_ei[i].segment_counts, 0, sizeof(mbr_ei[i].segment_counts));
423         mbr_ei[i].totalrate = 0;
424
425         mb->partition_info = x->pi + x->e_mbd.mode_info_stride * (i + 1);
426
427         mbd->mode_info_context = cm->mi   + x->e_mbd.mode_info_stride * (i + 1);
428         mbd->mode_info_stride  = cm->mode_info_stride;
429
430         mbd->frame_type = cm->frame_type;
431
432         mbd->frames_since_golden = cm->frames_since_golden;
433         mbd->frames_till_alt_ref_frame = cm->frames_till_alt_ref_frame;
434
435         mb->src = * cpi->Source;
436         mbd->pre = cm->yv12_fb[cm->lst_fb_idx];
437         mbd->dst = cm->yv12_fb[cm->new_fb_idx];
438
439         mb->src.y_buffer += 16 * x->src.y_stride * (i + 1);
440         mb->src.u_buffer +=  8 * x->src.uv_stride * (i + 1);
441         mb->src.v_buffer +=  8 * x->src.uv_stride * (i + 1);
442
443         vp8_build_block_offsets(mb);
444
445         vp8_setup_block_dptrs(mbd);
446
447         vp8_setup_block_ptrs(mb);
448
449         mb->activity_sum = 0;
450
451         mbd->left_context = &cm->left_context;
452         mb->mvc = cm->fc.mvc;
453
454         setup_mbby_copy(&mbr_ei[i].mb, x);
455
456     }
457 }
458
459 void vp8cx_create_encoder_threads(VP8_COMP *cpi)
460 {
461     cpi->b_multi_threaded = 0;
462
463     cpi->processor_core_count = 32; //vp8_get_proc_core_count();
464
465     if (cpi->processor_core_count > 1 && cpi->oxcf.multi_threaded > 1)
466     {
467         int ithread;
468
469         if (cpi->oxcf.multi_threaded > cpi->processor_core_count)
470             cpi->encoding_thread_count = cpi->processor_core_count - 1;
471         else
472             cpi->encoding_thread_count = cpi->oxcf.multi_threaded - 1;
473
474         CHECK_MEM_ERROR(cpi->h_encoding_thread, vpx_malloc(sizeof(pthread_t) * cpi->encoding_thread_count));
475         CHECK_MEM_ERROR(cpi->h_event_start_encoding, vpx_malloc(sizeof(sem_t) * cpi->encoding_thread_count));
476         CHECK_MEM_ERROR(cpi->mb_row_ei, vpx_memalign(32, sizeof(MB_ROW_COMP) * cpi->encoding_thread_count));
477         vpx_memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * cpi->encoding_thread_count);
478         CHECK_MEM_ERROR(cpi->en_thread_data, vpx_malloc(sizeof(ENCODETHREAD_DATA) * cpi->encoding_thread_count));
479         CHECK_MEM_ERROR(cpi->mt_current_mb_col, vpx_malloc(sizeof(*cpi->mt_current_mb_col) * cpi->common.mb_rows));
480
481         //cpi->h_event_main = CreateEvent(NULL, FALSE, FALSE, NULL);
482         sem_init(&cpi->h_event_end_encoding, 0, 0);
483
484         cpi->b_multi_threaded = 1;
485
486         //printf("[VP8:] multi_threaded encoding is enabled with %d threads\n\n", (cpi->encoding_thread_count +1));
487
488         for (ithread = 0; ithread < cpi->encoding_thread_count; ithread++)
489         {
490             ENCODETHREAD_DATA * ethd = &cpi->en_thread_data[ithread];
491
492             //cpi->h_event_mbrencoding[ithread] = CreateEvent(NULL, FALSE, FALSE, NULL);
493             sem_init(&cpi->h_event_start_encoding[ithread], 0, 0);
494             ethd->ithread = ithread;
495             ethd->ptr1 = (void *)cpi;
496             ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread];
497
498             //printf(" call begin thread %d \n", ithread);
499
500             //cpi->h_encoding_thread[ithread] =   (HANDLE)_beginthreadex(
501             //  NULL,           // security
502             //  0,              // stksize
503             //  thread_encoding_proc,
504             //  (&cpi->en_thread_data[ithread]),          // Thread data
505             //  0,
506             //  NULL);
507
508             pthread_create(&cpi->h_encoding_thread[ithread], 0, thread_encoding_proc, ethd);
509         }
510
511         {
512             LPFTHREAD_DATA * lpfthd = &cpi->lpf_thread_data;
513
514             sem_init(&cpi->h_event_start_lpf, 0, 0);
515             sem_init(&cpi->h_event_end_lpf, 0, 0);
516
517             lpfthd->ptr1 = (void *)cpi;
518             pthread_create(&cpi->h_filter_thread, 0, loopfilter_thread, lpfthd);
519         }
520     }
521
522 }
523
524 void vp8cx_remove_encoder_threads(VP8_COMP *cpi)
525 {
526     if (cpi->b_multi_threaded)
527     {
528         //shutdown other threads
529         cpi->b_multi_threaded = 0;
530         {
531             int i;
532
533             for (i = 0; i < cpi->encoding_thread_count; i++)
534             {
535                 //SetEvent(cpi->h_event_mbrencoding[i]);
536                 sem_post(&cpi->h_event_start_encoding[i]);
537                 pthread_join(cpi->h_encoding_thread[i], 0);
538
539                 sem_destroy(&cpi->h_event_start_encoding[i]);
540             }
541
542             sem_post(&cpi->h_event_start_lpf);
543             pthread_join(cpi->h_filter_thread, 0);
544         }
545
546         sem_destroy(&cpi->h_event_end_encoding);
547         sem_destroy(&cpi->h_event_end_lpf);
548         sem_destroy(&cpi->h_event_start_lpf);
549
550         //free thread related resources
551         vpx_free(cpi->h_event_start_encoding);
552         vpx_free(cpi->h_encoding_thread);
553         vpx_free(cpi->mb_row_ei);
554         vpx_free(cpi->en_thread_data);
555         vpx_free(cpi->mt_current_mb_col);
556     }
557 }
558 #endif