Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: media/video/h264_poc.cc

Issue 2011353003: H264POC: Re-compute PicOrderCnt for duplicate frame_nums. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/video/h264_poc.h ('k') | media/video/h264_poc_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "media/filters/h264_parser.h" 11 #include "media/filters/h264_parser.h"
12 #include "media/video/h264_poc.h" 12 #include "media/video/h264_poc.h"
13 13
14 namespace media { 14 namespace media {
15 15
16 H264POC::H264POC() { 16 H264POC::H264POC() {
17 Reset(); 17 Reset();
18 } 18 }
19 19
20 H264POC::~H264POC() { 20 H264POC::~H264POC() {
21 } 21 }
22 22
23 void H264POC::Reset() { 23 void H264POC::Reset() {
24 // It shouldn't be necessary to reset these values, but doing so will improve 24 // It shouldn't be necessary to reset these values, but doing so will improve
25 // reproducibility for buggy streams. 25 // reproducibility for buggy streams.
26 ref_pic_order_cnt_msb_ = 0; 26 ref_pic_order_cnt_msb_ = 0;
27 ref_pic_order_cnt_lsb_ = 0; 27 ref_pic_order_cnt_lsb_ = 0;
28 prev_frame_num_ = 0; 28 prev_frame_num_ = 0;
29 prev_frame_num_offset_ = 0; 29 prev_frame_num_offset_ = 0;
30 prev_poc_ = 0;
31 } 30 }
32 31
33 // Check if a slice includes memory management control operation 5, which 32 // Check if a slice includes memory management control operation 5, which
34 // results in some |pic_order_cnt| state being cleared. 33 // results in some |pic_order_cnt| state being cleared.
35 static bool HasMMCO5(const media::H264SliceHeader& slice_hdr) { 34 static bool HasMMCO5(const media::H264SliceHeader& slice_hdr) {
36 // Require that the frame actually has memory management control operations. 35 // Require that the frame actually has memory management control operations.
37 if (slice_hdr.nal_ref_idc == 0 || 36 if (slice_hdr.nal_ref_idc == 0 ||
38 slice_hdr.idr_pic_flag || 37 slice_hdr.idr_pic_flag ||
39 !slice_hdr.adaptive_ref_pic_marking_mode_flag) { 38 !slice_hdr.adaptive_ref_pic_marking_mode_flag) {
40 return false; 39 return false;
(...skipping 15 matching lines...) Expand all
56 55
57 bool H264POC::ComputePicOrderCnt( 56 bool H264POC::ComputePicOrderCnt(
58 const H264SPS* sps, 57 const H264SPS* sps,
59 const H264SliceHeader& slice_hdr, 58 const H264SliceHeader& slice_hdr,
60 int32_t *pic_order_cnt) { 59 int32_t *pic_order_cnt) {
61 if (slice_hdr.field_pic_flag) { 60 if (slice_hdr.field_pic_flag) {
62 DLOG(ERROR) << "Interlaced frames are not supported"; 61 DLOG(ERROR) << "Interlaced frames are not supported";
63 return false; 62 return false;
64 } 63 }
65 64
66 if (!slice_hdr.idr_pic_flag && slice_hdr.frame_num == prev_frame_num_) {
67 DLOG(WARNING) << "Redundant picture passed to H264POC";
68 *pic_order_cnt = prev_poc_;
69 return true;
70 }
71
72 bool mmco5 = HasMMCO5(slice_hdr); 65 bool mmco5 = HasMMCO5(slice_hdr);
73 int32_t max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4); 66 int32_t max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4);
74 int32_t max_pic_order_cnt_lsb = 67 int32_t max_pic_order_cnt_lsb =
75 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4); 68 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
76 69
70 // Check for invalid (including duplicate) |frame_num| values. All cases are
71 // treated as gaps, which is to say that nothing is done. (Gaps don't affect
72 // POC computation.)
77 if (!slice_hdr.idr_pic_flag && 73 if (!slice_hdr.idr_pic_flag &&
78 slice_hdr.frame_num != (prev_frame_num_ + 1) % max_frame_num) { 74 slice_hdr.frame_num != (prev_frame_num_ + 1) % max_frame_num) {
79 // We don't do any special handling of gaps in |frame_num|, because the
80 // computations below are unaffected by them. In particular, wrapping is
81 // handled the same whether we simulate the missing frames or not.
82 if (!sps->gaps_in_frame_num_value_allowed_flag) 75 if (!sps->gaps_in_frame_num_value_allowed_flag)
83 DLOG(WARNING) << "Invalid gap in frame_num"; 76 DLOG(WARNING) << "Invalid gap in frame_num";
84 } 77 }
85 78
86 // Based on T-REC-H.264 8.2.1, "Decoding process for picture order 79 // Based on T-REC-H.264 8.2.1, "Decoding process for picture order
87 // count", available from http://www.itu.int/rec/T-REC-H.264. 80 // count", available from http://www.itu.int/rec/T-REC-H.264.
88 // 81 //
89 // Reorganized slightly from spec pseudocode to handle MMCO5 when storing 82 // Reorganized slightly from spec pseudocode to handle MMCO5 when storing
90 // state instead of when loading it. 83 // state instead of when loading it.
91 int32_t poc;
92 switch (sps->pic_order_cnt_type) { 84 switch (sps->pic_order_cnt_type) {
93 case 0: { 85 case 0: {
94 int32_t prev_pic_order_cnt_msb = ref_pic_order_cnt_msb_; 86 int32_t prev_pic_order_cnt_msb = ref_pic_order_cnt_msb_;
95 int32_t prev_pic_order_cnt_lsb = ref_pic_order_cnt_lsb_; 87 int32_t prev_pic_order_cnt_lsb = ref_pic_order_cnt_lsb_;
96 88
97 // For an IDR picture, clear the state. 89 // For an IDR picture, clear the state.
98 if (slice_hdr.idr_pic_flag) { 90 if (slice_hdr.idr_pic_flag) {
99 prev_pic_order_cnt_msb = 0; 91 prev_pic_order_cnt_msb = 0;
100 prev_pic_order_cnt_lsb = 0; 92 prev_pic_order_cnt_lsb = 0;
101 } 93 }
(...skipping 11 matching lines...) Expand all
113 max_pic_order_cnt_lsb / 2)) { 105 max_pic_order_cnt_lsb / 2)) {
114 pic_order_cnt_msb = prev_pic_order_cnt_msb - max_pic_order_cnt_lsb; 106 pic_order_cnt_msb = prev_pic_order_cnt_msb - max_pic_order_cnt_lsb;
115 } else { 107 } else {
116 pic_order_cnt_msb = prev_pic_order_cnt_msb; 108 pic_order_cnt_msb = prev_pic_order_cnt_msb;
117 } 109 }
118 110
119 // 8-4, 8-5. Derive |top_field_order_count| and |bottom_field_order_cnt| 111 // 8-4, 8-5. Derive |top_field_order_count| and |bottom_field_order_cnt|
120 // (assuming no interlacing). 112 // (assuming no interlacing).
121 int32_t top_foc = pic_order_cnt_msb + slice_hdr.pic_order_cnt_lsb; 113 int32_t top_foc = pic_order_cnt_msb + slice_hdr.pic_order_cnt_lsb;
122 int32_t bottom_foc = top_foc + slice_hdr.delta_pic_order_cnt_bottom; 114 int32_t bottom_foc = top_foc + slice_hdr.delta_pic_order_cnt_bottom;
123 poc = std::min(top_foc, bottom_foc); 115 *pic_order_cnt = std::min(top_foc, bottom_foc);
124 116
125 // Store state. 117 // Store state.
126 prev_frame_num_ = slice_hdr.frame_num; 118 prev_frame_num_ = slice_hdr.frame_num;
127 if (slice_hdr.nal_ref_idc != 0) { 119 if (slice_hdr.nal_ref_idc != 0) {
128 if (mmco5) { 120 if (mmco5) {
129 ref_pic_order_cnt_msb_ = 0; 121 ref_pic_order_cnt_msb_ = 0;
130 ref_pic_order_cnt_lsb_ = top_foc; 122 ref_pic_order_cnt_lsb_ = top_foc;
131 } else { 123 } else {
132 ref_pic_order_cnt_msb_ = pic_order_cnt_msb; 124 ref_pic_order_cnt_msb_ = pic_order_cnt_msb;
133 ref_pic_order_cnt_lsb_ = slice_hdr.pic_order_cnt_lsb; 125 ref_pic_order_cnt_lsb_ = slice_hdr.pic_order_cnt_lsb;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 expected_pic_order_cnt += sps->offset_for_ref_frame[i]; 174 expected_pic_order_cnt += sps->offset_for_ref_frame[i];
183 } 175 }
184 if (slice_hdr.nal_ref_idc == 0) 176 if (slice_hdr.nal_ref_idc == 0)
185 expected_pic_order_cnt += sps->offset_for_non_ref_pic; 177 expected_pic_order_cnt += sps->offset_for_non_ref_pic;
186 178
187 // 8-10. Derive |top_field_order_cnt| and |bottom_field_order_cnt| 179 // 8-10. Derive |top_field_order_cnt| and |bottom_field_order_cnt|
188 // (assuming no interlacing). 180 // (assuming no interlacing).
189 int32_t top_foc = expected_pic_order_cnt + slice_hdr.delta_pic_order_cnt0; 181 int32_t top_foc = expected_pic_order_cnt + slice_hdr.delta_pic_order_cnt0;
190 int32_t bottom_foc = top_foc + sps->offset_for_top_to_bottom_field + 182 int32_t bottom_foc = top_foc + sps->offset_for_top_to_bottom_field +
191 slice_hdr.delta_pic_order_cnt1; 183 slice_hdr.delta_pic_order_cnt1;
192 poc = std::min(top_foc, bottom_foc); 184 *pic_order_cnt = std::min(top_foc, bottom_foc);
193 185
194 // Store state. 186 // Store state.
195 prev_frame_num_ = slice_hdr.frame_num; 187 prev_frame_num_ = slice_hdr.frame_num;
196 prev_frame_num_offset_ = frame_num_offset; 188 prev_frame_num_offset_ = frame_num_offset;
197 if (mmco5) 189 if (mmco5)
198 prev_frame_num_offset_ = 0; 190 prev_frame_num_offset_ = 0;
199 191
200 break; 192 break;
201 } 193 }
202 194
203 case 2: { 195 case 2: {
204 // 8-11. Derive |frame_num_offset|. 196 // 8-11. Derive |frame_num_offset|.
205 int32_t frame_num_offset; 197 int32_t frame_num_offset;
206 if (slice_hdr.idr_pic_flag) 198 if (slice_hdr.idr_pic_flag)
207 frame_num_offset = 0; 199 frame_num_offset = 0;
208 else if (prev_frame_num_ > slice_hdr.frame_num) 200 else if (prev_frame_num_ > slice_hdr.frame_num)
209 frame_num_offset = prev_frame_num_offset_ + max_frame_num; 201 frame_num_offset = prev_frame_num_offset_ + max_frame_num;
210 else 202 else
211 frame_num_offset = prev_frame_num_offset_; 203 frame_num_offset = prev_frame_num_offset_;
212 204
213 // 8-12, 8-13. Derive |temp_pic_order_count| (it's always the 205 // 8-12, 8-13. Derive |temp_pic_order_count| (it's always the
214 // |pic_order_cnt|, regardless of interlacing). 206 // |pic_order_cnt|, regardless of interlacing).
215 if (slice_hdr.idr_pic_flag) 207 if (slice_hdr.idr_pic_flag)
216 poc = 0; 208 *pic_order_cnt = 0;
217 else if (slice_hdr.nal_ref_idc == 0) 209 else if (slice_hdr.nal_ref_idc == 0)
218 poc = 2 * (frame_num_offset + slice_hdr.frame_num) - 1; 210 *pic_order_cnt = 2 * (frame_num_offset + slice_hdr.frame_num) - 1;
219 else 211 else
220 poc = 2 * (frame_num_offset + slice_hdr.frame_num); 212 *pic_order_cnt = 2 * (frame_num_offset + slice_hdr.frame_num);
221 213
222 // Store state. 214 // Store state.
223 prev_frame_num_ = slice_hdr.frame_num; 215 prev_frame_num_ = slice_hdr.frame_num;
224 prev_frame_num_offset_ = frame_num_offset; 216 prev_frame_num_offset_ = frame_num_offset;
225 if (mmco5) 217 if (mmco5)
226 prev_frame_num_offset_ = 0; 218 prev_frame_num_offset_ = 0;
227 219
228 break; 220 break;
229 } 221 }
230 222
231 default: 223 default:
232 DLOG(ERROR) << "Invalid pic_order_cnt_type: " << sps->pic_order_cnt_type; 224 DLOG(ERROR) << "Invalid pic_order_cnt_type: " << sps->pic_order_cnt_type;
233 return false; 225 return false;
234 } 226 }
235 227
236 *pic_order_cnt = prev_poc_ = poc;
237 return true; 228 return true;
238 } 229 }
239 230
240 } // namespace media 231 } // namespace media
OLDNEW
« no previous file with comments | « media/video/h264_poc.h ('k') | media/video/h264_poc_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698