[cvs] / xvidcore / src / encoder.c Repository:
ViewVC logotype

Diff of /xvidcore/src/encoder.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.135.2.6, Thu Apr 7 19:07:36 2011 UTC revision 1.137, Wed Dec 29 22:39:35 2010 UTC
# Line 449  Line 449 
449    
450          /* multithreaded stuff */          /* multithreaded stuff */
451          if (create->num_threads > 0) {          if (create->num_threads > 0) {
 #ifndef HAVE_PTHREAD  
                 int t = MAX(1, create->num_threads);  
 #else  
452                  int t = MIN(create->num_threads, (int) (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */                  int t = MIN(create->num_threads, (int) (pEnc->mbParam.mb_height>>1)); /* at least two rows per thread */
 #endif  
453                  int threads_per_slice = MAX(1, (t / pEnc->num_slices));                  int threads_per_slice = MAX(1, (t / pEnc->num_slices));
454                  int rows_per_thread = (pEnc->mbParam.mb_height + threads_per_slice - 1) / threads_per_slice;                  int rows_per_thread = (pEnc->mbParam.mb_height + threads_per_slice - 1) / threads_per_slice;
455    
# Line 1613  Line 1609 
1609                  memcpy((void *)((ptr_t)bs->start + pos),                  memcpy((void *)((ptr_t)bs->start + pos),
1610                             (void *)((ptr_t)pEnc->smpData[k].bs->start), len);                             (void *)((ptr_t)pEnc->smpData[k].bs->start), len);
1611    
1612                  current->length += len;                  current->length = pos += len;
                 pos += len;  
1613    
1614                  /* collect stats */                  /* collect stats */
1615                  current->sStat.iTextBits += pEnc->smpData[k].sStat->iTextBits;                  current->sStat.iTextBits += pEnc->smpData[k].sStat->iTextBits;
# Line 1651  Line 1646 
1646          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
1647          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
1648          int mb_height = pEnc->mbParam.mb_height;          int mb_height = pEnc->mbParam.mb_height;
 #ifdef HAVE_PTHREAD  
1649          void * status = NULL;          void * status = NULL;
 #endif  
1650          uint16_t k;          uint16_t k;
1651    
1652          pEnc->mbParam.m_rounding_type = 1;          pEnc->mbParam.m_rounding_type = 1;
# Line 1694  Line 1687 
1687          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
1688          pEnc->smpData[0].sStat = &pEnc->current->sStat;          pEnc->smpData[0].sStat = &pEnc->current->sStat;
1689    
 #ifdef HAVE_PTHREAD  
1690          /* create threads */          /* create threads */
1691          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
1692                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
1693                                 (void*)SliceCodeI, (void*)&pEnc->smpData[k]);                                 (void*)SliceCodeI, (void*)&pEnc->smpData[k]);
1694          }          }
 #endif  
1695    
1696          SliceCodeI(&pEnc->smpData[0]);          SliceCodeI(&pEnc->smpData[0]);
1697    
 #ifdef HAVE_PTHREAD  
1698          /* wait until all threads are finished */          /* wait until all threads are finished */
1699          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
1700                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
1701          }          }
 #endif  
1702    
1703          pEnc->current->length = BitstreamLength(bs) - (bits/8);          pEnc->current->length = BitstreamLength(bs) - (bits/8);
1704    
# Line 1918  Line 1907 
1907    
1908          int k = 0, bound = 0, num_slices = pEnc->num_slices;          int k = 0, bound = 0, num_slices = pEnc->num_slices;
1909          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
 #ifdef HAVE_PTHREAD  
1910          void * status = NULL;          void * status = NULL;
         int threads_per_slice = (pEnc->num_threads*1024 / num_threads);  
 #endif  
1911          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
1912            int threads_per_slice = (pEnc->num_threads*1024 / num_threads);
1913    
1914          IMAGE *pRef = &reference->image;          IMAGE *pRef = &reference->image;
1915    
1916          if (!reference->is_edged) {          if (!reference->is_edged) {
1917                  start_timer();                  start_timer();
1918                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,                  image_setedges(pRef, pParam->edged_width, pParam->edged_height,
1919                                             pParam->width, pParam->height, XVID_BS_VERSION);                                             pParam->width, pParam->height, 0);
1920                  stop_edges_timer();                  stop_edges_timer();
1921                  reference->is_edged = 1;                  reference->is_edged = 1;
1922          }          }
# Line 2017  Line 2004 
2004                  }                  }
2005          }          }
2006    
 #ifdef HAVE_PTHREAD  
2007          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2008    
2009                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
# Line 2072  Line 2058 
2058                                  current->fcode = pEnc->smpData[k].minfcode;                                  current->fcode = pEnc->smpData[k].minfcode;
2059                  }                  }
2060    
2061          } else          } else {
 #endif  
         {  
2062    
2063                  /* regular ME */                  /* regular ME */
2064    
# Line 2118  Line 2102 
2102          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
2103          pEnc->smpData[0].sStat = &current->sStat;          pEnc->smpData[0].sStat = &current->sStat;
2104    
 #ifdef HAVE_PTHREAD  
2105          /* create threads */          /* create threads */
2106          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2107                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
2108                          (void*)SliceCodeP, (void*)&pEnc->smpData[k]);                          (void*)SliceCodeP, (void*)&pEnc->smpData[k]);
2109          }          }
 #endif  
2110    
2111          SliceCodeP(&pEnc->smpData[0]);          SliceCodeP(&pEnc->smpData[0]);
2112    
 #ifdef HAVE_PTHREAD  
2113          /* wait until all threads are finished */          /* wait until all threads are finished */
2114          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2115                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
2116          }          }
 #endif  
2117    
2118          current->length = BitstreamLength(bs) - (bits/8);          current->length = BitstreamLength(bs) - (bits/8);
2119    
# Line 2149  Line 2129 
2129    
2130          if (current->sStat.kblks + current->sStat.mblks <          if (current->sStat.kblks + current->sStat.mblks <
2131                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&                  (pParam->frame_drop_ratio * mb_width * mb_height) / 100 &&
2132                  ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) &&                  ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) )
                 (current->coding_type == P_VOP) )  
2133          {          {
2134                  current->sStat.kblks = current->sStat.mblks = current->sStat.iTextBits = 0;                  current->sStat.kblks = current->sStat.mblks = current->sStat.iTextBits = 0;
2135                  current->sStat.ublks = mb_width * mb_height;                  current->sStat.ublks = mb_width * mb_height;
# Line 2296  Line 2275 
2275          int bits = BitstreamPos(bs);          int bits = BitstreamPos(bs);
2276          int k = 0, bound = 0, num_slices = pEnc->num_slices;          int k = 0, bound = 0, num_slices = pEnc->num_slices;
2277          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));          int num_threads = MAX(1, MIN(pEnc->num_threads, num_slices));
 #ifdef HAVE_PTHREAD  
2278          void * status = NULL;          void * status = NULL;
         int threads_per_slice = (pEnc->num_threads*1024 / num_threads);  
 #endif  
2279          int slices_per_thread = (num_slices*1024 / num_threads);          int slices_per_thread = (num_slices*1024 / num_threads);
2280            int threads_per_slice = (pEnc->num_threads*1024 / num_threads);
2281    
2282          IMAGE *f_ref = &pEnc->reference->image;          IMAGE *f_ref = &pEnc->reference->image;
2283          IMAGE *b_ref = &pEnc->current->image;          IMAGE *b_ref = &pEnc->current->image;
# Line 2324  Line 2301 
2301          if (!pEnc->reference->is_edged) {          if (!pEnc->reference->is_edged) {
2302                  image_setedges(f_ref, pEnc->mbParam.edged_width,                  image_setedges(f_ref, pEnc->mbParam.edged_width,
2303                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,
2304                                             pEnc->mbParam.height, XVID_BS_VERSION);                                             pEnc->mbParam.height, 0);
2305                  pEnc->reference->is_edged = 1;                  pEnc->reference->is_edged = 1;
2306          }          }
2307    
# Line 2341  Line 2318 
2318          if (!pEnc->current->is_edged) {          if (!pEnc->current->is_edged) {
2319                  image_setedges(b_ref, pEnc->mbParam.edged_width,                  image_setedges(b_ref, pEnc->mbParam.edged_width,
2320                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,                                             pEnc->mbParam.edged_height, pEnc->mbParam.width,
2321                                             pEnc->mbParam.height, XVID_BS_VERSION);                                             pEnc->mbParam.height, 0);
2322                  pEnc->current->is_edged = 1;                  pEnc->current->is_edged = 1;
2323          }          }
2324    
# Line 2367  Line 2344 
2344    
2345          start_timer();          start_timer();
2346    
 #ifdef HAVE_PTHREAD  
2347          if (pEnc->num_threads > 0) {          if (pEnc->num_threads > 0) {
2348    
2349                  /* multithreaded motion estimation - dispatch threads */                  /* multithreaded motion estimation - dispatch threads */
# Line 2423  Line 2399 
2399                          if (pEnc->smpData[k].minbcode > frame->bcode)                          if (pEnc->smpData[k].minbcode > frame->bcode)
2400                                  frame->bcode = pEnc->smpData[k].minbcode;                                  frame->bcode = pEnc->smpData[k].minbcode;
2401                  }                  }
2402          } else          } else {
 #endif  
         {  
2403    
2404                  MotionEstimationBVOP(&pEnc->mbParam, frame,                  MotionEstimationBVOP(&pEnc->mbParam, frame,
2405                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */                                                           ((int32_t)(pEnc->current->stamp - frame->stamp)),                              /* time_bp */
# Line 2475  Line 2449 
2449                  }                  }
2450          }          }
2451    
 #ifdef HAVE_PTHREAD  
2452          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2453                  pthread_create(&pEnc->smpData[k].handle, NULL,                  pthread_create(&pEnc->smpData[k].handle, NULL,
2454                          (void*)SliceCodeB, (void*)&pEnc->smpData[k]);                          (void*)SliceCodeB, (void*)&pEnc->smpData[k]);
2455          }          }
 #endif  
2456    
2457          pEnc->smpData[0].bs = bs;          pEnc->smpData[0].bs = bs;
2458          pEnc->smpData[0].sStat = &frame->sStat;          pEnc->smpData[0].sStat = &frame->sStat;
2459          SliceCodeB(&pEnc->smpData[0]);          SliceCodeB(&pEnc->smpData[0]);
2460    
 #ifdef HAVE_PTHREAD  
2461          for (k = 1; k < num_threads; k++) {          for (k = 1; k < num_threads; k++) {
2462                  pthread_join(pEnc->smpData[k].handle, &status);                  pthread_join(pEnc->smpData[k].handle, &status);
2463          }          }
 #endif  
2464    
2465          frame->length = BitstreamLength(bs) - (bits/8);          frame->length = BitstreamLength(bs) - (bits/8);
2466    

Legend:
Removed from v.1.135.2.6  
changed lines
  Added in v.1.137

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4