Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
comparison libavcodec/h264.c @ 6:55fb61482128
VSs working
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 06 Mar 2013 14:35:39 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d6b85067e280 |
|---|---|
| 1 #include "config.h" | |
| 2 #include "h264.h" | |
| 3 #include "h264_misc.h" | |
| 4 #include <math.h> | |
| 5 | |
| 6 H264Context *get_h264dec_context(const char *file_name, int ifile, int ofile, int width, int height, h264_options *opts){ | |
| 7 int i; | |
| 8 const int mb_height = (height + 15) / 16; | |
| 9 const int mb_width = (width + 15) / 16; | |
| 10 const int mb_stride = ((mb_width+1)/16 + 1) *16; //align mb_stride to 16 | |
| 11 | |
| 12 ff_init_cabac_states(); | |
| 13 | |
| 14 H264Context *h= av_mallocz(sizeof(H264Context)); | |
| 15 | |
| 16 start_timer(h, TOTAL); | |
| 17 h->file_name = file_name; | |
| 18 h->profile = opts->profile; | |
| 19 for (i=0; i<PROFILE_STAGES; i++) | |
| 20 h->total_time[i]=0; | |
| 21 | |
| 22 h->ifile=ifile; | |
| 23 h->ofile =ofile; | |
| 24 | |
| 25 h->verbose =opts->verbose; | |
| 26 h->no_mbd =opts->no_mbd; | |
| 27 h->static_3d =opts->static_3d; | |
| 28 h->pipe_bufs = opts->pipe_bufs; | |
| 29 h->slice_bufs = opts->slice_bufs; | |
| 30 | |
| 31 h->ed_ppe_threads =0; | |
| 32 if (opts->ppe_ed){ | |
| 33 h->ed_ppe_threads = (opts->threads >opts->ppe_ed)? opts->ppe_ed :opts->threads; | |
| 34 } | |
| 35 | |
| 36 h->threads = opts->threads - h->ed_ppe_threads; | |
| 37 h->smt = opts->smt; | |
| 38 if (h->smt){ | |
| 39 h->threads *= 2; | |
| 40 } | |
| 41 | |
| 42 h->num_frames = opts->numframes; | |
| 43 | |
| 44 h->frame_width = width; | |
| 45 h->frame_height = height; | |
| 46 | |
| 47 while ((width/2) %STRIDE_ALIGN) | |
| 48 width+=STRIDE_ALIGN; | |
| 49 h->width = width; | |
| 50 h->height = mb_height*16; | |
| 51 | |
| 52 h->mb_height = mb_height; | |
| 53 h->mb_width = mb_width; | |
| 54 h->mb_stride = mb_stride; | |
| 55 h->b4_stride = mb_width*4 + 1; | |
| 56 h->b_stride = mb_width*4; | |
| 57 | |
| 58 h->smb_width = opts->smb_size[0]; | |
| 59 h->smb_height = opts->smb_size[1] < h->smb_width ? opts->smb_size[1] : h->smb_width; | |
| 60 h->smbc = getSuperMBContext(h, h->smb_width, h->smb_height); | |
| 61 | |
| 62 h->wave_order = opts->wave_order; | |
| 63 | |
| 64 h->pipe_bufs = opts->pipe_bufs; | |
| 65 | |
| 66 h->max_dpb_cnt = DPB_SIZE + opts->pipe_bufs; | |
| 67 h->free_dpb_cnt = h->max_dpb_cnt; | |
| 68 h->dpb = av_mallocz (h->max_dpb_cnt* sizeof (DecodedPicture)); | |
| 69 | |
| 70 | |
| 71 h->free_sb_cnt = h->threads*opts->slice_bufs + (h->no_mbd != 0) ; //one extra to overlap some latency of signaling/freeing slicebuffers in entropy only mode | |
| 72 h->sb_size = h->free_sb_cnt; | |
| 73 h->sb = av_mallocz(h->sb_size* sizeof(SliceBufferEntry)); | |
| 74 | |
| 75 h->rl_q.size = FFMAX(1, FFMIN( (h->height-3 - 512)/16, h->mb_width/2)) +1; | |
| 76 h->rl_q.free = h->rl_q.size -1; | |
| 77 h->rl_q.ready=0; | |
| 78 h->rl_q.fi = h->rl_q.fo= 0; | |
| 79 h->rl_q.queue = av_malloc(h->rl_q.size* sizeof(RingLineEntry*)); | |
| 80 for (i=0; i<h->rl_q.size; i++){ | |
| 81 if( posix_memalign((void**)&h->rl_q.queue[i],64,sizeof(RingLineEntry))) | |
| 82 h->rl_q.queue[i]=NULL; | |
| 83 h->rl_q.queue[i]->top = av_malloc(h->mb_width*sizeof(TopBorder)); | |
| 84 } | |
| 85 | |
| 86 h->rl_q.queue[0]->prev_line = h->rl_q.queue[h->rl_q.size-1]; | |
| 87 for (i=1; i<h->rl_q.size; i++){ | |
| 88 h->rl_q.queue[i]->prev_line = h->rl_q.queue[i-1]; | |
| 89 } | |
| 90 | |
| 91 if( HAVE_MMX | HAVE_ALTIVEC| HAVE_NEON ){ | |
| 92 for(i=0; i<16; i++){ | |
| 93 #define T(x) (x>>2) | ((x<<2) & 0xF) | |
| 94 h->zigzag_scan[i] = T(zigzag_scan[i]); | |
| 95 #undef T | |
| 96 } | |
| 97 for(i=0; i<64; i++){ | |
| 98 #define T(x) (x>>3) | ((x&7)<<3) | |
| 99 h->zigzag_scan8x8[i] = T(ff_zigzag_direct[i]); | |
| 100 #undef T | |
| 101 } | |
| 102 }else{ | |
| 103 memcpy(h->zigzag_scan, zigzag_scan, 16*sizeof(uint8_t)); | |
| 104 memcpy(h->zigzag_scan8x8, ff_zigzag_direct, 64*sizeof(uint8_t)); | |
| 105 } | |
| 106 | |
| 107 pthread_mutex_init(&h->smb_lock, NULL); | |
| 108 pthread_mutex_init(&h->sdl_lock, NULL); | |
| 109 pthread_cond_init(&h->sdl_cond, NULL); | |
| 110 | |
| 111 ///pthread initialization | |
| 112 pthread_mutex_init(&h->ilock, NULL); | |
| 113 pthread_cond_init(&h->icond, NULL); | |
| 114 pthread_mutex_init(&h->slock, NULL); | |
| 115 pthread_cond_init(&h->scond, NULL); | |
| 116 pthread_mutex_init(&h->tlock, NULL); | |
| 117 pthread_cond_init(&h->tcond, NULL); | |
| 118 pthread_mutex_init(&h->tdlock, NULL); | |
| 119 pthread_cond_init(&h->tdcond, NULL); | |
| 120 h->start =!opts->numamap; //default dont wait for start signal | |
| 121 h->statmbd = opts->statmbd; | |
| 122 h->rl_side_touch= opts->numamap; | |
| 123 h->touch_start=0; | |
| 124 h->setaff =opts->statsched; | |
| 125 h->init_threads=0; | |
| 126 | |
| 127 pthread_mutex_init(&h->task_lock, NULL); | |
| 128 pthread_cond_init(&h->task_cond, NULL); | |
| 129 for (i=0; i<STAGES; i++){ | |
| 130 pthread_mutex_init (&h->lock[i], NULL); | |
| 131 pthread_cond_init (&h->cond[i], NULL); | |
| 132 | |
| 133 pthread_mutex_init (&h->sb_q[i].lock, NULL); | |
| 134 pthread_cond_init (&h->sb_q[i].cond, NULL); | |
| 135 h->sb_q[i].size = h->free_sb_cnt; //change to num threads later | |
| 136 h->sb_q[i].queue = av_malloc(h->free_sb_cnt* sizeof(SliceBufferEntry*)); | |
| 137 h->sb_q[i].cnt = h->sb_q[i].fi = h->sb_q[i].fo =0; | |
| 138 } | |
| 139 | |
| 140 #if HAVE_LIBSDL2 | |
| 141 h->sdlq.size=2; | |
| 142 h->sdlq.ready=2; | |
| 143 h->sdlq.queue = av_malloc(2* sizeof(SDL_Texture*)); | |
| 144 pthread_mutex_init (&h->sdlq.sdl_lock, NULL); | |
| 145 pthread_cond_init (&h->sdlq.sdl_cond, NULL); | |
| 146 #endif | |
| 147 | |
| 148 h->display=opts->display; | |
| 149 h->fullscreen=opts->fullscreen; | |
| 150 | |
| 151 return h; | |
| 152 } | |
| 153 | |
| 154 | |
| 155 void free_h264dec_context(H264Context *h) { | |
| 156 int i; | |
| 157 | |
| 158 for(i=0; i<h->max_dpb_cnt; i++) | |
| 159 free_dp(&h->dpb[i]); | |
| 160 av_free (h->dpb); | |
| 161 | |
| 162 for(i=0; i<h->sb_size; i++){ | |
| 163 if (h->sb[i].initialized){ | |
| 164 free_sb_entry(&h->sb[i]); | |
| 165 } | |
| 166 } | |
| 167 av_freep(&h->sb); | |
| 168 | |
| 169 for (i=0; i<h->rl_q.size; i++){ | |
| 170 av_freep(&h->rl_q.queue[i]->top); | |
| 171 av_freep(&h->rl_q.queue[i]); | |
| 172 } | |
| 173 av_freep(&h->rl_q.queue); | |
| 174 | |
| 175 ///pthread cleanup | |
| 176 pthread_mutex_destroy (&h->task_lock); | |
| 177 pthread_cond_destroy (&h->task_cond); | |
| 178 for (i=0; i<STAGES; i++){ | |
| 179 pthread_mutex_destroy (&h->lock[i]); | |
| 180 pthread_cond_destroy (&h->cond[i]); | |
| 181 | |
| 182 pthread_mutex_destroy (&h->sb_q[i].lock); | |
| 183 pthread_cond_destroy (&h->sb_q[i].cond); | |
| 184 av_freep( &h->sb_q[i].queue); | |
| 185 } | |
| 186 pthread_mutex_destroy (&h->slock); | |
| 187 pthread_cond_destroy (&h->scond); | |
| 188 pthread_mutex_destroy (&h->ilock); | |
| 189 pthread_cond_destroy (&h->icond); | |
| 190 | |
| 191 pthread_mutex_destroy(&h->smb_lock); | |
| 192 pthread_mutex_destroy (&h->sdl_lock); | |
| 193 pthread_cond_destroy (&h->sdl_cond); | |
| 194 #if HAVE_LIBSDL2 | |
| 195 av_free(h->sdlq.queue); | |
| 196 pthread_mutex_destroy (&h->sdlq.sdl_lock); | |
| 197 pthread_cond_destroy (&h->sdlq.sdl_cond); | |
| 198 #endif | |
| 199 | |
| 200 stop_timer(h, TOTAL); | |
| 201 if (h->threads==0){ | |
| 202 for (i=0; i<PROFILE_STAGES; i++) | |
| 203 h->total_time[i] /= h->num_frames; | |
| 204 double others = h->total_time[TOTAL]; | |
| 205 for (i=1; i<PROFILE_STAGES; i++) | |
| 206 others-=h->total_time[i]; | |
| 207 if (h->profile == 1){ | |
| 208 printf("\n[FRAME %.3fms] [FRONT %.3fms] [ENTROPY %.3fms] [MBREC %.3fms] [OTHERS %.3fms]\n", h->total_time[TOTAL], h->total_time[FRONT], h->total_time[ED], h->total_time[REC], others); | |
| 209 }else if (h->profile ==2){ | |
| 210 printf("\n[FRAME %.3fms] [FRONT %.3fms] [ENTROPY %.3fms] [PRED %.3fms] [OTHERS %.3fms]\n", h->total_time[TOTAL], h->total_time[FRONT], h->total_time[ED],h->total_time[REC], others); | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 av_free(h); | |
| 215 } |
