Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
diff libavcodec/h264_seq.c @ 2:897f711a7157
rearrange to work with autoconf
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 25 Sep 2012 15:55:33 +0200 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libavcodec/h264_seq.c Tue Sep 25 15:55:33 2012 +0200 1.3 @@ -0,0 +1,220 @@ 1.4 +/* 1.5 +* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder 1.6 +* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> 1.7 +* 1.8 +* This file is part of FFmpeg. 1.9 +* 1.10 +* FFmpeg is free software; you can redistribute it and/or 1.11 +* modify it under the terms of the GNU Lesser General Public 1.12 +* License as published by the Free Software Foundation; either 1.13 +* version 2.1 of the License, or (at your option) any later version. 1.14 +* 1.15 +* FFmpeg is distributed in the hope that it will be useful, 1.16 +* but WITHOUT ANY WARRANTY; without even the implied warranty of 1.17 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.18 +* Lesser General Public License for more details. 1.19 +* 1.20 +* You should have received a copy of the GNU Lesser General Public 1.21 +* License along with FFmpeg; if not, write to the Free Software 1.22 +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1.23 +*/ 1.24 +#include "h264_types.h" 1.25 +#include "h264_parser.h" 1.26 +#include "h264_nal.h" 1.27 +#include "h264_entropy.h" 1.28 +#include "h264_rec.h" 1.29 +#include "h264_pred_mode.h" 1.30 +#include "h264_misc.h" 1.31 +// #undef NDEBUG 1.32 +#include <assert.h> 1.33 + 1.34 +static int decode_slice_entropy_seq(H264Context *h, EntropyContext *ec, H264Slice *s, GetBitContext *gb, H264Mb *mbs){ 1.35 + int i,j; 1.36 +// GetBitContext *gb = s->gb; 1.37 + CABACContext *c = &ec->c; 1.38 + 1.39 + if( !s->pps.cabac ){ 1.40 + av_log(AV_LOG_ERROR, "Only cabac encoded streams are supported\n"); 1.41 + return -1; 1.42 + } 1.43 + 1.44 + init_dequant_tables(s, ec); 1.45 + ec->curr_qscale = s->qscale; 1.46 + ec->last_qscale_diff = 0; 1.47 + ec->chroma_qp[0] = get_chroma_qp((H264Slice *) s, 0, s->qscale); 1.48 + ec->chroma_qp[1] = get_chroma_qp((H264Slice *) s, 1, s->qscale); 1.49 + 1.50 + /* realign */ 1.51 + align_get_bits( gb ); 1.52 + /* init cabac */ 1.53 + ff_init_cabac_decoder( c, gb->buffer + get_bits_count(gb)/8, (get_bits_left(gb) + 7)/8); 1.54 + 1.55 + ff_h264_init_cabac_states(ec, s, c); 1.56 + 1.57 + for(j=0; j<ec->mb_height; j++){ 1.58 + init_entropy_buf(ec, s, j); 1.59 + for(i=0; i<ec->mb_width; i++){ 1.60 + int eos,ret; 1.61 + H264Mb *m = &mbs[i + j*ec->mb_width]; 1.62 + //memset(m, 0, sizeof(H264Mb)); 1.63 + m->mb_x=i; 1.64 + m->mb_y=j; 1.65 + ec->m = m; 1.66 + 1.67 + ret = ff_h264_decode_mb_cabac(ec, s, c); 1.68 + eos = get_cabac_terminate( c); 1.69 + (void) eos; 1.70 + if( ret < 0 || c->bytestream > c->bytestream_end + 2) { 1.71 + 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); 1.72 + return -1; 1.73 + } 1.74 + } 1.75 + } 1.76 + 1.77 +// av_freep(&s->gb.raw); 1.78 +// if (s->gb.rbsp) 1.79 +// av_freep(&s->gb.rbsp); 1.80 + 1.81 + return 0; 1.82 +} 1.83 + 1.84 + 1.85 + 1.86 +/** 1.87 +* Sequential version 1.88 +*/ 1.89 +static void decode_slice_mb_seq(H264Context *h, MBRecContext *d, H264Slice *s2, H264Mb *mbs){ 1.90 + 1.91 + for (int i=0; i<2; i++){ 1.92 + for(int j=0; j< s2->ref_count[i]; j++){ 1.93 + if (s2->ref_list_cpn[i][j] ==-1) 1.94 + continue; 1.95 + int k; 1.96 + for (k=0; k<h->max_dpb_cnt; k++){ 1.97 + if(h->dpb[k].reference >= 2 && h->dpb[k].cpn == s2->ref_list_cpn[i][j]){ 1.98 + s2->dp_ref_list[i][j] = &h->dpb[k]; 1.99 + break; 1.100 + } 1.101 + } 1.102 + } 1.103 + } 1.104 + 1.105 + get_dpb_entry(h, s2); 1.106 + 1.107 + if (!h->no_mbd){ 1.108 + for(int j=0; j<d->mb_height; j++){ 1.109 + init_mbrec_context(d, d->mrs, s2, j); 1.110 + if (h->profile) printf("\n[MBREC LINE %d ", j); 1.111 + for(int i=0; i<d->mb_width; i++){ 1.112 + 1.113 + if ((i & 0x7) == 0) start_timer(h, REC); 1.114 + H264Mb *m = &mbs[i + j*d->mb_width]; 1.115 + if (h->profile==2) 1.116 + pred_motion_mb_rec (d, d->mrs, s2, m); 1.117 + else{ 1.118 + h264_decode_mb_internal(d, d->mrs, s2, m); 1.119 + } 1.120 + stop_timer(h, REC); 1.121 + } 1.122 + draw_edges(d, s2, j); 1.123 + 1.124 + } 1.125 + } 1.126 + 1.127 + for (int i=0; i<s2->release_cnt; i++){ 1.128 + for(int j=0; j<h->max_dpb_cnt; j++){ 1.129 + if(h->dpb[j].cpn== s2->release_ref_cpn[i]){ 1.130 + release_dpb_entry(h, &h->dpb[j], 2); 1.131 + break; 1.132 + } 1.133 + } 1.134 + } 1.135 + s2->release_cnt=0; 1.136 +} 1.137 + 1.138 +/* 1.139 +* The following code is the main loop of the file converter 1.140 +*/ 1.141 +int h264_decode_seq( H264Context *h) { 1.142 + ParserContext *pc; 1.143 + NalContext *nc; 1.144 + EntropyContext *ec; 1.145 + MBRecContext *rc; 1.146 + OutputContext *oc; 1.147 + 1.148 + H264Slice slice, *s=&slice; 1.149 + H264Mb *mbs; 1.150 + DecodedPicture *out; 1.151 + int frames=0; 1.152 + 1.153 +#if HAVE_LIBSDL2 1.154 + pthread_t sdl_thr; 1.155 + if (h->display){ 1.156 + pthread_create(&sdl_thr, NULL, sdl_thread, h); 1.157 + } 1.158 +#endif 1.159 + 1.160 + pc = get_parse_context(h->ifile); 1.161 + nc = get_nal_context(h->width, h->height); 1.162 + 1.163 + memset(s, 0, sizeof(H264Slice)); 1.164 + mbs = av_malloc( h->mb_height * h->mb_width * sizeof(H264Mb)); 1.165 + 1.166 + ec = get_entropy_context( h ); 1.167 + rc = get_mbrec_context(h); 1.168 + rc->top_next = rc->top = av_malloc( h->mb_width * sizeof(TopBorder)); 1.169 + 1.170 + oc = get_output_context( h ); 1.171 + 1.172 + av_start_timer(); 1.173 + GetBitContext gb = {0,}; 1.174 + while(!pc->final_frame && frames++ < h->num_frames && !h->quit){ 1.175 + if (h->profile) start_timer(h, FRONT); 1.176 + av_read_frame_internal(pc, &gb); 1.177 + decode_nal_units(nc, s, &gb); 1.178 + if (h->profile) stop_timer(h, FRONT); 1.179 +// memset(s->mbs, 0, sizeof(H264Mb)*ec->mb_width*ec->mb_height); 1.180 + if (h->profile) start_timer(h, ED); 1.181 + decode_slice_entropy_seq(h, ec, s, &gb, mbs); 1.182 + if (h->profile) stop_timer(h, ED); 1.183 + 1.184 + if (h->profile) start_timer(h, REC); 1.185 + decode_slice_mb_seq(h, rc, s, mbs); 1.186 + if (h->profile) stop_timer(h, REC); 1.187 + 1.188 + out =output_frame(h, oc, s->curr_pic, h->ofile, h->frame_width, h->frame_height); 1.189 + if (out){ 1.190 + release_dpb_entry(h, out, 1); 1.191 + } 1.192 + 1.193 + print_report(oc->frame_number, oc->video_size, 0, h->verbose); 1.194 + if (h->profile == 3){ 1.195 + printf("[ENTROPY %.3fms] [MBREC %.3fms]\n", h->last_time[ED] , h->last_time[REC]); 1.196 + } 1.197 + } 1.198 + while ((out=output_frame(h, oc, NULL, h->ofile, h->frame_width, h->frame_height))) ; 1.199 + 1.200 + print_report(oc->frame_number, oc->video_size, 1, h->verbose); 1.201 + h->num_frames = oc->frame_number; 1.202 + /* finished ! */ 1.203 + av_freep(&mbs); 1.204 + av_freep(&gb.raw); 1.205 + if (gb.rbsp) 1.206 + av_freep(&gb.rbsp); 1.207 + av_freep(&rc->top); 1.208 + 1.209 + free_parse_context(pc); 1.210 + free_nal_context (nc); 1.211 + free_entropy_context(ec); 1.212 + free_mbrec_context(rc); 1.213 + free_output_context(oc); 1.214 + 1.215 +#if HAVE_LIBSDL2 1.216 + if (h->display){ 1.217 + signal_sdl_exit(h); 1.218 + pthread_join(sdl_thr, NULL); 1.219 + } 1.220 +#endif 1.221 + 1.222 + return 0; 1.223 +}
