Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
comparison libavcodec/h264_seq.c @ 4:96e628866d41
naming some tasks to help debugging
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 19 Dec 2012 15:40:26 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:508c5916412f |
|---|---|
| 1 /* | |
| 2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder | |
| 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 #include "h264_types.h" | |
| 22 #include "h264_parser.h" | |
| 23 #include "h264_nal.h" | |
| 24 #include "h264_entropy.h" | |
| 25 #include "h264_rec.h" | |
| 26 #include "h264_pred_mode.h" | |
| 27 #include "h264_misc.h" | |
| 28 // #undef NDEBUG | |
| 29 #include <assert.h> | |
| 30 | |
| 31 static int decode_slice_entropy_seq(H264Context *h, EntropyContext *ec, H264Slice *s, GetBitContext *gb, H264Mb *mbs){ | |
| 32 int i,j; | |
| 33 // GetBitContext *gb = s->gb; | |
| 34 CABACContext *c = &ec->c; | |
| 35 | |
| 36 if( !s->pps.cabac ){ | |
| 37 av_log(AV_LOG_ERROR, "Only cabac encoded streams are supported\n"); | |
| 38 return -1; | |
| 39 } | |
| 40 | |
| 41 init_dequant_tables(s, ec); | |
| 42 ec->curr_qscale = s->qscale; | |
| 43 ec->last_qscale_diff = 0; | |
| 44 ec->chroma_qp[0] = get_chroma_qp((H264Slice *) s, 0, s->qscale); | |
| 45 ec->chroma_qp[1] = get_chroma_qp((H264Slice *) s, 1, s->qscale); | |
| 46 | |
| 47 /* realign */ | |
| 48 align_get_bits( gb ); | |
| 49 /* init cabac */ | |
| 50 ff_init_cabac_decoder( c, gb->buffer + get_bits_count(gb)/8, (get_bits_left(gb) + 7)/8); | |
| 51 | |
| 52 ff_h264_init_cabac_states(ec, s, c); | |
| 53 | |
| 54 for(j=0; j<ec->mb_height; j++){ | |
| 55 init_entropy_buf(ec, s, j); | |
| 56 for(i=0; i<ec->mb_width; i++){ | |
| 57 int eos,ret; | |
| 58 H264Mb *m = &mbs[i + j*ec->mb_width]; | |
| 59 //memset(m, 0, sizeof(H264Mb)); | |
| 60 m->mb_x=i; | |
| 61 m->mb_y=j; | |
| 62 ec->m = m; | |
| 63 | |
| 64 ret = ff_h264_decode_mb_cabac(ec, s, c); | |
| 65 eos = get_cabac_terminate( c); | |
| 66 (void) eos; | |
| 67 if( ret < 0 || c->bytestream > c->bytestream_end + 2) { | |
| 68 av_log(AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", m->mb_x, m->mb_y, c->bytestream_end - c->bytestream); | |
| 69 return -1; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 // av_freep(&s->gb.raw); | |
| 75 // if (s->gb.rbsp) | |
| 76 // av_freep(&s->gb.rbsp); | |
| 77 | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 | |
| 82 | |
| 83 /** | |
| 84 * Sequential version | |
| 85 */ | |
| 86 static void decode_slice_mb_seq(H264Context *h, MBRecContext *d, H264Slice *s2, H264Mb *mbs){ | |
| 87 | |
| 88 for (int i=0; i<2; i++){ | |
| 89 for(int j=0; j< s2->ref_count[i]; j++){ | |
| 90 if (s2->ref_list_cpn[i][j] ==-1) | |
| 91 continue; | |
| 92 int k; | |
| 93 for (k=0; k<h->max_dpb_cnt; k++){ | |
| 94 if(h->dpb[k].reference >= 2 && h->dpb[k].cpn == s2->ref_list_cpn[i][j]){ | |
| 95 s2->dp_ref_list[i][j] = &h->dpb[k]; | |
| 96 break; | |
| 97 } | |
| 98 } | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 get_dpb_entry(h, s2); | |
| 103 | |
| 104 if (!h->no_mbd){ | |
| 105 for(int j=0; j<d->mb_height; j++){ | |
| 106 init_mbrec_context(d, d->mrs, s2, j); | |
| 107 if (h->profile) printf("\n[MBREC LINE %d ", j); | |
| 108 for(int i=0; i<d->mb_width; i++){ | |
| 109 | |
| 110 if ((i & 0x7) == 0) start_timer(h, REC); | |
| 111 H264Mb *m = &mbs[i + j*d->mb_width]; | |
| 112 if (h->profile==2) | |
| 113 pred_motion_mb_rec (d, d->mrs, s2, m); | |
| 114 else{ | |
| 115 h264_decode_mb_internal(d, d->mrs, s2, m); | |
| 116 } | |
| 117 stop_timer(h, REC); | |
| 118 } | |
| 119 draw_edges(d, s2, j); | |
| 120 | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 for (int i=0; i<s2->release_cnt; i++){ | |
| 125 for(int j=0; j<h->max_dpb_cnt; j++){ | |
| 126 if(h->dpb[j].cpn== s2->release_ref_cpn[i]){ | |
| 127 release_dpb_entry(h, &h->dpb[j], 2); | |
| 128 break; | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 s2->release_cnt=0; | |
| 133 } | |
| 134 | |
| 135 /* | |
| 136 * The following code is the main loop of the file converter | |
| 137 */ | |
| 138 int h264_decode_seq( H264Context *h) { | |
| 139 ParserContext *pc; | |
| 140 NalContext *nc; | |
| 141 EntropyContext *ec; | |
| 142 MBRecContext *rc; | |
| 143 OutputContext *oc; | |
| 144 | |
| 145 H264Slice slice, *s=&slice; | |
| 146 H264Mb *mbs; | |
| 147 DecodedPicture *out; | |
| 148 int frames=0; | |
| 149 | |
| 150 #if HAVE_LIBSDL2 | |
| 151 pthread_t sdl_thr; | |
| 152 if (h->display){ | |
| 153 pthread_create(&sdl_thr, NULL, sdl_thread, h); | |
| 154 } | |
| 155 #endif | |
| 156 | |
| 157 pc = get_parse_context(h->ifile); | |
| 158 nc = get_nal_context(h->width, h->height); | |
| 159 | |
| 160 memset(s, 0, sizeof(H264Slice)); | |
| 161 mbs = av_malloc( h->mb_height * h->mb_width * sizeof(H264Mb)); | |
| 162 | |
| 163 ec = get_entropy_context( h ); | |
| 164 rc = get_mbrec_context(h); | |
| 165 rc->top_next = rc->top = av_malloc( h->mb_width * sizeof(TopBorder)); | |
| 166 | |
| 167 oc = get_output_context( h ); | |
| 168 | |
| 169 av_start_timer(); | |
| 170 GetBitContext gb = {0,}; | |
| 171 while(!pc->final_frame && frames++ < h->num_frames && !h->quit){ | |
| 172 if (h->profile) start_timer(h, FRONT); | |
| 173 av_read_frame_internal(pc, &gb); | |
| 174 decode_nal_units(nc, s, &gb); | |
| 175 if (h->profile) stop_timer(h, FRONT); | |
| 176 // memset(s->mbs, 0, sizeof(H264Mb)*ec->mb_width*ec->mb_height); | |
| 177 if (h->profile) start_timer(h, ED); | |
| 178 decode_slice_entropy_seq(h, ec, s, &gb, mbs); | |
| 179 if (h->profile) stop_timer(h, ED); | |
| 180 | |
| 181 if (h->profile) start_timer(h, REC); | |
| 182 decode_slice_mb_seq(h, rc, s, mbs); | |
| 183 if (h->profile) stop_timer(h, REC); | |
| 184 | |
| 185 out =output_frame(h, oc, s->curr_pic, h->ofile, h->frame_width, h->frame_height); | |
| 186 if (out){ | |
| 187 release_dpb_entry(h, out, 1); | |
| 188 } | |
| 189 | |
| 190 print_report(oc->frame_number, oc->video_size, 0, h->verbose); | |
| 191 if (h->profile == 3){ | |
| 192 printf("[ENTROPY %.3fms] [MBREC %.3fms]\n", h->last_time[ED] , h->last_time[REC]); | |
| 193 } | |
| 194 } | |
| 195 while ((out=output_frame(h, oc, NULL, h->ofile, h->frame_width, h->frame_height))) ; | |
| 196 | |
| 197 print_report(oc->frame_number, oc->video_size, 1, h->verbose); | |
| 198 h->num_frames = oc->frame_number; | |
| 199 /* finished ! */ | |
| 200 av_freep(&mbs); | |
| 201 av_freep(&gb.raw); | |
| 202 if (gb.rbsp) | |
| 203 av_freep(&gb.rbsp); | |
| 204 av_freep(&rc->top); | |
| 205 | |
| 206 free_parse_context(pc); | |
| 207 free_nal_context (nc); | |
| 208 free_entropy_context(ec); | |
| 209 free_mbrec_context(rc); | |
| 210 free_output_context(oc); | |
| 211 | |
| 212 #if HAVE_LIBSDL2 | |
| 213 if (h->display){ | |
| 214 signal_sdl_exit(h); | |
| 215 pthread_join(sdl_thr, NULL); | |
| 216 } | |
| 217 #endif | |
| 218 | |
| 219 return 0; | |
| 220 } |
