Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
comparison libavcodec/h264_sei.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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7d09856a9b55 |
|---|---|
| 1 /* | |
| 2 * H.26L/H.264/AVC/JVT/14496-10/... sei decoding | |
| 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 | |
| 22 /** | |
| 23 * @file | |
| 24 * H.264 / AVC / MPEG4 part10 sei decoding. | |
| 25 * @author Michael Niedermayer <michaelni@gmx.at> | |
| 26 */ | |
| 27 | |
| 28 #include "avcodec.h" | |
| 29 #include "h264_types.h" | |
| 30 #include "golomb.h" | |
| 31 | |
| 32 //#undef NDEBUG | |
| 33 #include <assert.h> | |
| 34 | |
| 35 static const uint8_t sei_num_clock_ts_table[9]={ | |
| 36 1, 1, 1, 2, 2, 3, 3, 2, 3 | |
| 37 }; | |
| 38 | |
| 39 void ff_h264_reset_sei(NalContext *n) { | |
| 40 n->sei_recovery_frame_cnt = -1; | |
| 41 n->sei_dpb_output_delay = 0; | |
| 42 n->sei_cpb_removal_delay = -1; | |
| 43 n->sei_buffering_period_present = 0; | |
| 44 } | |
| 45 | |
| 46 static int decode_picture_timing(NalContext *n, GetBitContext *gb){ | |
| 47 if(n->sps.nal_hrd_parameters_present_flag || n->sps.vcl_hrd_parameters_present_flag){ | |
| 48 n->sei_cpb_removal_delay = get_bits(gb, n->sps.cpb_removal_delay_length); | |
| 49 n->sei_dpb_output_delay = get_bits(gb, n->sps.dpb_output_delay_length); | |
| 50 } | |
| 51 if(n->sps.pic_struct_present_flag){ | |
| 52 unsigned int i, num_clock_ts; | |
| 53 n->sei_pic_struct = get_bits(gb, 4); | |
| 54 n->sei_ct_type = 0; | |
| 55 | |
| 56 if (n->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) | |
| 57 return -1; | |
| 58 | |
| 59 num_clock_ts = sei_num_clock_ts_table[n->sei_pic_struct]; | |
| 60 | |
| 61 for (i = 0 ; i < num_clock_ts ; i++){ | |
| 62 if(get_bits(gb, 1)){ /* clock_timestamp_flag */ | |
| 63 unsigned int full_timestamp_flag; | |
| 64 n->sei_ct_type |= 1<<get_bits(gb, 2); | |
| 65 skip_bits(gb, 1); /* nuit_field_based_flag */ | |
| 66 skip_bits(gb, 5); /* counting_type */ | |
| 67 full_timestamp_flag = get_bits(gb, 1); | |
| 68 skip_bits(gb, 1); /* discontinuity_flag */ | |
| 69 skip_bits(gb, 1); /* cnt_dropped_flag */ | |
| 70 skip_bits(gb, 8); /* n_frames */ | |
| 71 if(full_timestamp_flag){ | |
| 72 skip_bits(gb, 6); /* seconds_value 0..59 */ | |
| 73 skip_bits(gb, 6); /* minutes_value 0..59 */ | |
| 74 skip_bits(gb, 5); /* hours_value 0..23 */ | |
| 75 }else{ | |
| 76 if(get_bits(gb, 1)){ /* seconds_flag */ | |
| 77 skip_bits(gb, 6); /* seconds_value range 0..59 */ | |
| 78 if(get_bits(gb, 1)){ /* minutes_flag */ | |
| 79 skip_bits(gb, 6); /* minutes_value 0..59 */ | |
| 80 if(get_bits(gb, 1)) /* hours_flag */ | |
| 81 skip_bits(gb, 5); /* hours_value 0..23 */ | |
| 82 } | |
| 83 } | |
| 84 } | |
| 85 if(n->sps.time_offset_length > 0) | |
| 86 skip_bits(gb, n->sps.time_offset_length); /* time_offset */ | |
| 87 } | |
| 88 } | |
| 89 } | |
| 90 return 0; | |
| 91 } | |
| 92 | |
| 93 static int decode_unregistered_user_data(GetBitContext *gb, int size){ | |
| 94 char user_data[16+256]; | |
| 95 int e, build, i; | |
| 96 | |
| 97 if(size<16) | |
| 98 return -1; | |
| 99 | |
| 100 for(i=0; i<(int) sizeof(user_data)-1 && i<size; i++){ | |
| 101 user_data[i]= get_bits(gb, 8); | |
| 102 } | |
| 103 | |
| 104 user_data[i]= 0; | |
| 105 e= sscanf(user_data+16, "x264 - core %d"/*%s - H.264/MPEG-4 AVC codec - Copyleft 2005 - http://www.videolan.org/x264.html*/, &build); | |
| 106 (void) e; | |
| 107 for(; i<size; i++) | |
| 108 skip_bits(gb, 8); | |
| 109 | |
| 110 return 0; | |
| 111 } | |
| 112 | |
| 113 static int decode_recovery_point(NalContext *n, GetBitContext *gb){ | |
| 114 | |
| 115 n->sei_recovery_frame_cnt = get_ue_golomb(gb); | |
| 116 skip_bits(gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ | |
| 117 | |
| 118 return 0; | |
| 119 } | |
| 120 | |
| 121 static int decode_buffering_period(NalContext *n, GetBitContext *gb){ | |
| 122 unsigned int sps_id; | |
| 123 int sched_sel_idx; | |
| 124 SPS *sps; | |
| 125 | |
| 126 sps_id = get_ue_golomb_31(gb); | |
| 127 if(sps_id > 31 || !n->sps_buffers[sps_id]) { | |
| 128 av_log(AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); | |
| 129 return -1; | |
| 130 } | |
| 131 sps = n->sps_buffers[sps_id]; | |
| 132 | |
| 133 // NOTE: This is really so duplicated in the standard... See H.264, D.1.1 | |
| 134 if (sps->nal_hrd_parameters_present_flag) { | |
| 135 for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { | |
| 136 n->initial_cpb_removal_delay[sched_sel_idx] = get_bits(gb, sps->initial_cpb_removal_delay_length); | |
| 137 skip_bits(gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset | |
| 138 } | |
| 139 } | |
| 140 if (sps->vcl_hrd_parameters_present_flag) { | |
| 141 for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { | |
| 142 n->initial_cpb_removal_delay[sched_sel_idx] = get_bits(gb, sps->initial_cpb_removal_delay_length); | |
| 143 skip_bits(gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 n->sei_buffering_period_present = 1; | |
| 148 return 0; | |
| 149 } | |
| 150 | |
| 151 int ff_h264_decode_sei(NalContext *n, GetBitContext *gb){ | |
| 152 while(get_bits_count(gb) + 16 < gb->size_in_bits){ | |
| 153 int size, type; | |
| 154 | |
| 155 type=0; | |
| 156 do{ | |
| 157 type+= show_bits(gb, 8); | |
| 158 }while(get_bits(gb, 8) == 255); | |
| 159 | |
| 160 size=0; | |
| 161 do{ | |
| 162 size+= show_bits(gb, 8); | |
| 163 }while(get_bits(gb, 8) == 255); | |
| 164 | |
| 165 switch(type){ | |
| 166 case SEI_TYPE_PIC_TIMING: // Picture timing SEI | |
| 167 if(decode_picture_timing(n, gb) < 0) | |
| 168 return -1; | |
| 169 break; | |
| 170 case SEI_TYPE_USER_DATA_UNREGISTERED: | |
| 171 if(decode_unregistered_user_data(gb, size) < 0) | |
| 172 return -1; | |
| 173 break; | |
| 174 case SEI_TYPE_RECOVERY_POINT: | |
| 175 if(decode_recovery_point(n, gb) < 0) | |
| 176 return -1; | |
| 177 break; | |
| 178 case SEI_BUFFERING_PERIOD: | |
| 179 if(decode_buffering_period(n, gb) < 0) | |
| 180 return -1; | |
| 181 break; | |
| 182 default: | |
| 183 skip_bits(gb, 8*size); | |
| 184 } | |
| 185 | |
| 186 //FIXME check bits here | |
| 187 align_get_bits(gb); | |
| 188 } | |
| 189 | |
| 190 return 0; | |
| 191 } |
