OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <dlfcn.h> | 5 #include <dlfcn.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 ref_pic_marking_array_sizes_do_not_match); | 1125 ref_pic_marking_array_sizes_do_not_match); |
1126 memcpy(curr_pic_->ref_pic_marking, slice_hdr->ref_pic_marking, | 1126 memcpy(curr_pic_->ref_pic_marking, slice_hdr->ref_pic_marking, |
1127 sizeof(curr_pic_->ref_pic_marking)); | 1127 sizeof(curr_pic_->ref_pic_marking)); |
1128 } | 1128 } |
1129 | 1129 |
1130 return true; | 1130 return true; |
1131 } | 1131 } |
1132 | 1132 |
1133 bool VaapiH264Decoder::CalculatePicOrderCounts(H264SliceHeader* slice_hdr) { | 1133 bool VaapiH264Decoder::CalculatePicOrderCounts(H264SliceHeader* slice_hdr) { |
1134 DCHECK_NE(curr_sps_id_, -1); | 1134 DCHECK_NE(curr_sps_id_, -1); |
1135 const H264SPS* sps = parser_.GetSPS(curr_sps_id_); | |
1135 | 1136 |
1136 int pic_order_cnt_lsb = slice_hdr->pic_order_cnt_lsb; | 1137 int pic_order_cnt_lsb = slice_hdr->pic_order_cnt_lsb; |
1137 curr_pic_->pic_order_cnt_lsb = pic_order_cnt_lsb; | 1138 curr_pic_->pic_order_cnt_lsb = pic_order_cnt_lsb; |
1138 if (parser_.GetSPS(curr_sps_id_)->pic_order_cnt_type != 0) { | |
1139 DVLOG(1) << "Unsupported pic_order_cnt_type"; | |
1140 return false; | |
1141 } | |
1142 | 1139 |
1143 // See spec 8.2.1.1. | 1140 switch (sps->pic_order_cnt_type) { |
1144 int prev_pic_order_cnt_msb, prev_pic_order_cnt_lsb; | 1141 case 0: |
1145 if (slice_hdr->idr_pic_flag) { | 1142 // See spec 8.2.1.1. |
1146 prev_pic_order_cnt_msb = prev_pic_order_cnt_lsb = 0; | 1143 int prev_pic_order_cnt_msb, prev_pic_order_cnt_lsb; |
1147 } else { | 1144 if (slice_hdr->idr_pic_flag) { |
1148 if (prev_ref_has_memmgmnt5_) { | 1145 prev_pic_order_cnt_msb = prev_pic_order_cnt_lsb = 0; |
1149 if (prev_ref_field_ != H264Picture::FIELD_BOTTOM) { | |
1150 prev_pic_order_cnt_msb = 0; | |
1151 prev_pic_order_cnt_lsb = prev_ref_top_field_order_cnt_; | |
1152 } else { | 1146 } else { |
1153 prev_pic_order_cnt_msb = 0; | 1147 if (prev_ref_has_memmgmnt5_) { |
1154 prev_pic_order_cnt_lsb = 0; | 1148 if (prev_ref_field_ != H264Picture::FIELD_BOTTOM) { |
1149 prev_pic_order_cnt_msb = 0; | |
1150 prev_pic_order_cnt_lsb = prev_ref_top_field_order_cnt_; | |
1151 } else { | |
1152 prev_pic_order_cnt_msb = 0; | |
1153 prev_pic_order_cnt_lsb = 0; | |
1154 } | |
1155 } else { | |
1156 prev_pic_order_cnt_msb = prev_ref_pic_order_cnt_msb_; | |
1157 prev_pic_order_cnt_lsb = prev_ref_pic_order_cnt_lsb_; | |
1158 } | |
1155 } | 1159 } |
1156 } else { | 1160 |
1157 prev_pic_order_cnt_msb = prev_ref_pic_order_cnt_msb_; | 1161 DCHECK_NE(max_pic_order_cnt_lsb_, 0); |
1158 prev_pic_order_cnt_lsb = prev_ref_pic_order_cnt_lsb_; | 1162 if ((pic_order_cnt_lsb < prev_pic_order_cnt_lsb) && |
1163 (prev_pic_order_cnt_lsb - pic_order_cnt_lsb >= | |
1164 max_pic_order_cnt_lsb_ / 2)) { | |
1165 curr_pic_->pic_order_cnt_msb = prev_pic_order_cnt_msb + | |
1166 max_pic_order_cnt_lsb_; | |
1167 } else if ((pic_order_cnt_lsb > prev_pic_order_cnt_lsb) && | |
1168 (pic_order_cnt_lsb - prev_pic_order_cnt_lsb > | |
1169 max_pic_order_cnt_lsb_ / 2)) { | |
1170 curr_pic_->pic_order_cnt_msb = prev_pic_order_cnt_msb - | |
1171 max_pic_order_cnt_lsb_; | |
1172 } else { | |
1173 curr_pic_->pic_order_cnt_msb = prev_pic_order_cnt_msb; | |
1174 } | |
1175 | |
1176 if (curr_pic_->field != H264Picture::FIELD_BOTTOM) { | |
1177 curr_pic_->top_field_order_cnt = curr_pic_->pic_order_cnt_msb + | |
1178 pic_order_cnt_lsb; | |
1179 } | |
1180 | |
1181 if (curr_pic_->field != H264Picture::FIELD_TOP) { | |
1182 // TODO posciak: perhaps replace with pic->field? | |
1183 if (!slice_hdr->field_pic_flag) { | |
1184 curr_pic_->bottom_field_order_cnt = curr_pic_->top_field_order_cnt + | |
1185 slice_hdr->delta_pic_order_cnt_bottom; | |
1186 } else { | |
1187 curr_pic_->bottom_field_order_cnt = curr_pic_->pic_order_cnt_msb + | |
1188 pic_order_cnt_lsb; | |
1189 } | |
1190 } | |
1191 break; | |
1192 | |
1193 case 1: { | |
1194 // See spec 8.2.1.2. | |
1195 if (prev_has_memmgmnt5_) | |
1196 prev_frame_num_offset_ = 0; | |
1197 | |
1198 if (slice_hdr->idr_pic_flag) | |
1199 curr_pic_->frame_num_offset = 0; | |
1200 else if (prev_frame_num_ > slice_hdr->frame_num) | |
1201 curr_pic_->frame_num_offset = prev_frame_num_offset_ + max_frame_num_; | |
1202 else | |
1203 curr_pic_->frame_num_offset = prev_frame_num_offset_; | |
1204 | |
1205 int abs_frame_num = 0; | |
1206 if (sps->num_ref_frames_in_pic_order_cnt_cycle != 0) | |
1207 abs_frame_num = curr_pic_->frame_num_offset + slice_hdr->frame_num; | |
1208 else | |
1209 abs_frame_num = 0; | |
1210 | |
1211 if (slice_hdr->nal_ref_idc == 0 && abs_frame_num > 0) | |
1212 --abs_frame_num; | |
1213 | |
1214 int expected_pic_order_cnt = 0; | |
1215 if (abs_frame_num > 0) { | |
1216 if (sps->num_ref_frames_in_pic_order_cnt_cycle == 0) { | |
1217 DVLOG(1) << "Invalid num_ref_frames_in_pic_order_cnt_cycle " | |
1218 << "in stream"; | |
1219 return false; | |
1220 } | |
1221 | |
1222 int pic_order_cnt_cycle_cnt = (abs_frame_num - 1) / | |
1223 sps->num_ref_frames_in_pic_order_cnt_cycle; | |
1224 int frame_num_in_pic_order_cnt_cycle = (abs_frame_num - 1) % | |
1225 sps->num_ref_frames_in_pic_order_cnt_cycle; | |
1226 | |
1227 expected_pic_order_cnt = pic_order_cnt_cycle_cnt * | |
1228 sps->expected_delta_per_pic_order_cnt_cycle; | |
1229 // frame_num_in_pic_order_cnt_cycle is verified < 255 in parser | |
1230 for (int i = 0; i <= frame_num_in_pic_order_cnt_cycle; ++i) | |
1231 expected_pic_order_cnt += sps->offset_for_ref_frame[i]; | |
1232 } | |
1233 | |
1234 if (!slice_hdr->nal_ref_idc) | |
1235 expected_pic_order_cnt += sps->offset_for_non_ref_pic; | |
1236 | |
1237 if (!slice_hdr->field_pic_flag) { | |
1238 curr_pic_->top_field_order_cnt = expected_pic_order_cnt + | |
1239 slice_hdr->delta_pic_order_cnt[0]; | |
1240 curr_pic_->bottom_field_order_cnt = curr_pic_->top_field_order_cnt + | |
1241 sps->offset_for_top_to_bottom_field + | |
1242 slice_hdr->delta_pic_order_cnt[1]; | |
1243 } else if (!slice_hdr->bottom_field_flag) { | |
1244 curr_pic_->top_field_order_cnt = expected_pic_order_cnt + | |
1245 slice_hdr->delta_pic_order_cnt[0]; | |
1246 } else { | |
1247 curr_pic_->bottom_field_order_cnt = expected_pic_order_cnt + | |
1248 sps->offset_for_top_to_bottom_field + | |
1249 slice_hdr->delta_pic_order_cnt[0]; | |
1250 } | |
1251 break; | |
1159 } | 1252 } |
1160 } | |
1161 | 1253 |
1162 DCHECK_NE(max_pic_order_cnt_lsb_, 0); | 1254 case 2: |
1163 if ((pic_order_cnt_lsb < prev_pic_order_cnt_lsb) && | 1255 // See spec 8.2.1.3. |
1164 (prev_pic_order_cnt_lsb - pic_order_cnt_lsb >= | 1256 if (prev_has_memmgmnt5_) |
1165 max_pic_order_cnt_lsb_ / 2)) { | 1257 prev_frame_num_offset_ = 0; |
1166 curr_pic_->pic_order_cnt_msb = prev_pic_order_cnt_msb + | |
1167 max_pic_order_cnt_lsb_; | |
1168 } else if ((pic_order_cnt_lsb > prev_pic_order_cnt_lsb) && | |
1169 (pic_order_cnt_lsb - prev_pic_order_cnt_lsb > | |
1170 max_pic_order_cnt_lsb_ / 2)) { | |
1171 curr_pic_->pic_order_cnt_msb = prev_pic_order_cnt_msb - | |
1172 max_pic_order_cnt_lsb_; | |
1173 } else { | |
1174 curr_pic_->pic_order_cnt_msb = prev_pic_order_cnt_msb; | |
1175 } | |
1176 | 1258 |
1177 if (curr_pic_->field != H264Picture::FIELD_BOTTOM) { | 1259 if (slice_hdr->idr_pic_flag) |
1178 curr_pic_->top_field_order_cnt = curr_pic_->pic_order_cnt_msb + | 1260 curr_pic_->frame_num_offset = 0; |
1179 pic_order_cnt_lsb; | 1261 else if (prev_frame_num_ > slice_hdr->frame_num) |
1180 } | 1262 curr_pic_->frame_num_offset = prev_frame_num_offset_ + max_frame_num_; |
1263 else | |
1264 curr_pic_->frame_num_offset = prev_frame_num_offset_; | |
1181 | 1265 |
1182 if (curr_pic_->field != H264Picture::FIELD_TOP) { | 1266 int temp_pic_order_cnt; |
1183 // TODO posciak: perhaps replace with pic->field? | 1267 if (slice_hdr->idr_pic_flag) { |
1184 if (!slice_hdr->field_pic_flag) { | 1268 temp_pic_order_cnt = 0; |
1185 curr_pic_->bottom_field_order_cnt = curr_pic_->top_field_order_cnt + | 1269 } else if (!slice_hdr->nal_ref_idc) { |
1186 slice_hdr->delta_pic_order_cnt_bottom; | 1270 temp_pic_order_cnt = |
1187 } else { | 1271 2 * (curr_pic_->frame_num_offset + slice_hdr->frame_num) - 1; |
1188 curr_pic_->bottom_field_order_cnt = curr_pic_->pic_order_cnt_msb + | 1272 } else { |
1189 pic_order_cnt_lsb; | 1273 temp_pic_order_cnt = 2 * (curr_pic_->frame_num_offset + |
1190 } | 1274 slice_hdr->frame_num); |
1275 } | |
1276 | |
1277 if (!slice_hdr->field_pic_flag) { | |
1278 curr_pic_->top_field_order_cnt = temp_pic_order_cnt; | |
1279 curr_pic_->bottom_field_order_cnt = temp_pic_order_cnt; | |
1280 } else if (slice_hdr->bottom_field_flag) { | |
1281 curr_pic_->bottom_field_order_cnt = temp_pic_order_cnt; | |
1282 } else { | |
1283 curr_pic_->top_field_order_cnt = temp_pic_order_cnt; | |
1284 } | |
1285 break; | |
1286 | |
1287 default: | |
1288 DVLOG(1) << "Invalid pic_order_cnt_type"; | |
Ami GONE FROM CHROMIUM
2012/08/22 21:53:12
s/type";/type: " << sps->pic_order_cnt_type;/
| |
1289 return false; | |
1191 } | 1290 } |
1192 | 1291 |
1193 switch (curr_pic_->field) { | 1292 switch (curr_pic_->field) { |
1194 case H264Picture::FIELD_NONE: | 1293 case H264Picture::FIELD_NONE: |
1195 curr_pic_->pic_order_cnt = std::min(curr_pic_->top_field_order_cnt, | 1294 curr_pic_->pic_order_cnt = std::min(curr_pic_->top_field_order_cnt, |
1196 curr_pic_->bottom_field_order_cnt); | 1295 curr_pic_->bottom_field_order_cnt); |
1197 break; | 1296 break; |
1198 case H264Picture::FIELD_TOP: | 1297 case H264Picture::FIELD_TOP: |
1199 curr_pic_->pic_order_cnt = curr_pic_->top_field_order_cnt; | 1298 curr_pic_->pic_order_cnt = curr_pic_->top_field_order_cnt; |
1200 break; | 1299 break; |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1780 // Start by storing previous reference picture data for later use, | 1879 // Start by storing previous reference picture data for later use, |
1781 // if picture being finished is a reference picture. | 1880 // if picture being finished is a reference picture. |
1782 if (curr_pic_->ref) { | 1881 if (curr_pic_->ref) { |
1783 ReferencePictureMarking(); | 1882 ReferencePictureMarking(); |
1784 prev_ref_has_memmgmnt5_ = curr_pic_->mem_mgmt_5; | 1883 prev_ref_has_memmgmnt5_ = curr_pic_->mem_mgmt_5; |
1785 prev_ref_top_field_order_cnt_ = curr_pic_->top_field_order_cnt; | 1884 prev_ref_top_field_order_cnt_ = curr_pic_->top_field_order_cnt; |
1786 prev_ref_pic_order_cnt_msb_ = curr_pic_->pic_order_cnt_msb; | 1885 prev_ref_pic_order_cnt_msb_ = curr_pic_->pic_order_cnt_msb; |
1787 prev_ref_pic_order_cnt_lsb_ = curr_pic_->pic_order_cnt_lsb; | 1886 prev_ref_pic_order_cnt_lsb_ = curr_pic_->pic_order_cnt_lsb; |
1788 prev_ref_field_ = curr_pic_->field; | 1887 prev_ref_field_ = curr_pic_->field; |
1789 } | 1888 } |
1889 prev_has_memmgmnt5_ = curr_pic_->mem_mgmt_5; | |
1890 prev_frame_num_offset_ = curr_pic_->frame_num_offset; | |
1790 | 1891 |
1791 // Remove unused (for reference or later output) pictures from DPB. | 1892 // Remove unused (for reference or later output) pictures from DPB. |
1792 dpb_.RemoveUnused(); | 1893 dpb_.RemoveUnused(); |
1793 | 1894 |
1794 DVLOG(4) << "Finishing picture, DPB entries: " << dpb_.size() | 1895 DVLOG(4) << "Finishing picture, DPB entries: " << dpb_.size() |
1795 << " Num available dec surfaces: " | 1896 << " Num available dec surfaces: " |
1796 << num_available_decode_surfaces_; | 1897 << num_available_decode_surfaces_; |
1797 | 1898 |
1798 // Whatever happens below, curr_pic_ will stop managing the pointer to the | 1899 // Whatever happens below, curr_pic_ will stop managing the pointer to the |
1799 // picture after this function returns. The ownership will either be | 1900 // picture after this function returns. The ownership will either be |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1865 // Fields/interlaced video not supported. | 1966 // Fields/interlaced video not supported. |
1866 DVLOG(1) << "frame_mbs_only_flag != 1 not supported"; | 1967 DVLOG(1) << "frame_mbs_only_flag != 1 not supported"; |
1867 return false; | 1968 return false; |
1868 } | 1969 } |
1869 | 1970 |
1870 if (sps->gaps_in_frame_num_value_allowed_flag) { | 1971 if (sps->gaps_in_frame_num_value_allowed_flag) { |
1871 DVLOG(1) << "Gaps in frame numbers not supported"; | 1972 DVLOG(1) << "Gaps in frame numbers not supported"; |
1872 return false; | 1973 return false; |
1873 } | 1974 } |
1874 | 1975 |
1875 if (sps->pic_order_cnt_type != 0) { | |
1876 DVLOG(1) << "Unsupported pic_order_cnt_type"; | |
1877 return false; | |
1878 } | |
1879 | |
1880 curr_sps_id_ = sps->seq_parameter_set_id; | 1976 curr_sps_id_ = sps->seq_parameter_set_id; |
1881 | 1977 |
1882 // Calculate picture height/width (spec 7.4.2.1.1, 7.4.3). | 1978 // Calculate picture height/width (spec 7.4.2.1.1, 7.4.3). |
1883 int width = 16 * (sps->pic_width_in_mbs_minus1 + 1); | 1979 int width = 16 * (sps->pic_width_in_mbs_minus1 + 1); |
1884 int height = 16 * (2 - sps->frame_mbs_only_flag) * | 1980 int height = 16 * (2 - sps->frame_mbs_only_flag) * |
1885 (sps->pic_height_in_map_units_minus1 + 1); | 1981 (sps->pic_height_in_map_units_minus1 + 1); |
1886 | 1982 |
1887 if ((pic_width_ != -1 || pic_height_ != -1) && | 1983 if ((pic_width_ != -1 || pic_height_ != -1) && |
1888 (width != pic_width_ || height != pic_height_)) { | 1984 (width != pic_width_ || height != pic_height_)) { |
1889 DVLOG(1) << "Picture size changed mid-stream"; | 1985 DVLOG(1) << "Picture size changed mid-stream"; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2178 VAAPI_SyncSurface && | 2274 VAAPI_SyncSurface && |
2179 VAAPI_BeginPicture && | 2275 VAAPI_BeginPicture && |
2180 VAAPI_RenderPicture && | 2276 VAAPI_RenderPicture && |
2181 VAAPI_EndPicture && | 2277 VAAPI_EndPicture && |
2182 VAAPI_CreateBuffer && | 2278 VAAPI_CreateBuffer && |
2183 VAAPI_DestroyBuffer && | 2279 VAAPI_DestroyBuffer && |
2184 VAAPI_ErrorStr; | 2280 VAAPI_ErrorStr; |
2185 } | 2281 } |
2186 | 2282 |
2187 } // namespace content | 2283 } // namespace content |
OLD | NEW |