| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 size_t num_short_refs = ref_pic_list_p0_.size(); | 355 size_t num_short_refs = ref_pic_list_p0_.size(); |
| 356 | 356 |
| 357 // and sort them to get [1]. | 357 // and sort them to get [1]. |
| 358 std::sort(ref_pic_list_p0_.begin(), ref_pic_list_p0_.end(), | 358 std::sort(ref_pic_list_p0_.begin(), ref_pic_list_p0_.end(), |
| 359 PicNumDescCompare()); | 359 PicNumDescCompare()); |
| 360 | 360 |
| 361 // Now get long term pics and sort them by long_term_pic_num to get [2]. | 361 // Now get long term pics and sort them by long_term_pic_num to get [2]. |
| 362 dpb_.GetLongTermRefPicsAppending(&ref_pic_list_p0_); | 362 dpb_.GetLongTermRefPicsAppending(&ref_pic_list_p0_); |
| 363 std::sort(ref_pic_list_p0_.begin() + num_short_refs, ref_pic_list_p0_.end(), | 363 std::sort(ref_pic_list_p0_.begin() + num_short_refs, ref_pic_list_p0_.end(), |
| 364 LongTermPicNumAscCompare()); | 364 LongTermPicNumAscCompare()); |
| 365 | |
| 366 // Cut off if we have more than requested in slice header. | |
| 367 ref_pic_list_p0_.resize(slice_hdr->num_ref_idx_l0_active_minus1 + 1); | |
| 368 } | 365 } |
| 369 | 366 |
| 370 struct POCAscCompare { | 367 struct POCAscCompare { |
| 371 bool operator()(const scoped_refptr<H264Picture>& a, | 368 bool operator()(const scoped_refptr<H264Picture>& a, |
| 372 const scoped_refptr<H264Picture>& b) const { | 369 const scoped_refptr<H264Picture>& b) const { |
| 373 return a->pic_order_cnt < b->pic_order_cnt; | 370 return a->pic_order_cnt < b->pic_order_cnt; |
| 374 } | 371 } |
| 375 }; | 372 }; |
| 376 | 373 |
| 377 struct POCDescCompare { | 374 struct POCDescCompare { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 // Now add [3] and sort by ascending long_term_pic_num | 426 // Now add [3] and sort by ascending long_term_pic_num |
| 430 dpb_.GetShortTermRefPicsAppending(&ref_pic_list_b1_); | 427 dpb_.GetShortTermRefPicsAppending(&ref_pic_list_b1_); |
| 431 std::sort(ref_pic_list_b1_.begin() + num_short_refs, ref_pic_list_b1_.end(), | 428 std::sort(ref_pic_list_b1_.begin() + num_short_refs, ref_pic_list_b1_.end(), |
| 432 LongTermPicNumAscCompare()); | 429 LongTermPicNumAscCompare()); |
| 433 | 430 |
| 434 // If lists identical, swap first two entries in RefPicList1 (spec 8.2.4.2.3) | 431 // If lists identical, swap first two entries in RefPicList1 (spec 8.2.4.2.3) |
| 435 if (ref_pic_list_b1_.size() > 1 && | 432 if (ref_pic_list_b1_.size() > 1 && |
| 436 std::equal(ref_pic_list_b0_.begin(), ref_pic_list_b0_.end(), | 433 std::equal(ref_pic_list_b0_.begin(), ref_pic_list_b0_.end(), |
| 437 ref_pic_list_b1_.begin())) | 434 ref_pic_list_b1_.begin())) |
| 438 std::swap(ref_pic_list_b1_[0], ref_pic_list_b1_[1]); | 435 std::swap(ref_pic_list_b1_[0], ref_pic_list_b1_[1]); |
| 439 | |
| 440 // Per 8.2.4.2 it's possible for num_ref_idx_lX_active_minus1 to indicate | |
| 441 // there should be more ref pics on list than we constructed. | |
| 442 // Those superfluous ones should be treated as non-reference. | |
| 443 ref_pic_list_b0_.resize(slice_hdr->num_ref_idx_l0_active_minus1 + 1); | |
| 444 ref_pic_list_b1_.resize(slice_hdr->num_ref_idx_l1_active_minus1 + 1); | |
| 445 } | 436 } |
| 446 | 437 |
| 447 // See 8.2.4 | 438 // See 8.2.4 |
| 448 int H264Decoder::PicNumF(const scoped_refptr<H264Picture>& pic) { | 439 int H264Decoder::PicNumF(const scoped_refptr<H264Picture>& pic) { |
| 449 if (!pic) | 440 if (!pic) |
| 450 return -1; | 441 return -1; |
| 451 | 442 |
| 452 if (!pic->long_term) | 443 if (!pic->long_term) |
| 453 return pic->pic_num; | 444 return pic->pic_num; |
| 454 else | 445 else |
| (...skipping 27 matching lines...) Expand all Loading... |
| 482 | 473 |
| 483 for (int i = to + 1; i > from; --i) | 474 for (int i = to + 1; i > from; --i) |
| 484 (*v)[i] = (*v)[i - 1]; | 475 (*v)[i] = (*v)[i - 1]; |
| 485 | 476 |
| 486 (*v)[from] = pic; | 477 (*v)[from] = pic; |
| 487 } | 478 } |
| 488 | 479 |
| 489 bool H264Decoder::ModifyReferencePicList(media::H264SliceHeader* slice_hdr, | 480 bool H264Decoder::ModifyReferencePicList(media::H264SliceHeader* slice_hdr, |
| 490 int list, | 481 int list, |
| 491 H264Picture::Vector* ref_pic_listx) { | 482 H264Picture::Vector* ref_pic_listx) { |
| 483 bool ref_pic_list_modification_flag_lX; |
| 492 int num_ref_idx_lX_active_minus1; | 484 int num_ref_idx_lX_active_minus1; |
| 493 media::H264ModificationOfPicNum* list_mod; | 485 media::H264ModificationOfPicNum* list_mod; |
| 494 | 486 |
| 495 // This can process either ref_pic_list0 or ref_pic_list1, depending on | 487 // This can process either ref_pic_list0 or ref_pic_list1, depending on |
| 496 // the list argument. Set up pointers to proper list to be processed here. | 488 // the list argument. Set up pointers to proper list to be processed here. |
| 497 if (list == 0) { | 489 if (list == 0) { |
| 498 if (!slice_hdr->ref_pic_list_modification_flag_l0) | 490 ref_pic_list_modification_flag_lX = |
| 499 return true; | 491 slice_hdr->ref_pic_list_modification_flag_l0; |
| 500 | 492 num_ref_idx_lX_active_minus1 = |
| 493 slice_hdr->num_ref_idx_l0_active_minus1; |
| 501 list_mod = slice_hdr->ref_list_l0_modifications; | 494 list_mod = slice_hdr->ref_list_l0_modifications; |
| 502 } else { | 495 } else { |
| 503 if (!slice_hdr->ref_pic_list_modification_flag_l1) | 496 ref_pic_list_modification_flag_lX = |
| 504 return true; | 497 slice_hdr->ref_pic_list_modification_flag_l1; |
| 505 | 498 num_ref_idx_lX_active_minus1 = |
| 499 slice_hdr->num_ref_idx_l1_active_minus1; |
| 506 list_mod = slice_hdr->ref_list_l1_modifications; | 500 list_mod = slice_hdr->ref_list_l1_modifications; |
| 507 } | 501 } |
| 508 | 502 |
| 509 num_ref_idx_lX_active_minus1 = ref_pic_listx->size() - 1; | 503 // Resize the list to the size requested in the slice header. |
| 504 // Note that per 8.2.4.2 it's possible for num_ref_idx_lX_active_minus1 to |
| 505 // indicate there should be more ref pics on list than we constructed. |
| 506 // Those superfluous ones should be treated as non-reference and will be |
| 507 // initialized to nullptr, which must be handled by clients. |
| 510 DCHECK_GE(num_ref_idx_lX_active_minus1, 0); | 508 DCHECK_GE(num_ref_idx_lX_active_minus1, 0); |
| 509 ref_pic_listx->resize(num_ref_idx_lX_active_minus1 + 1); |
| 510 |
| 511 if (!ref_pic_list_modification_flag_lX) |
| 512 return true; |
| 511 | 513 |
| 512 // Spec 8.2.4.3: | 514 // Spec 8.2.4.3: |
| 513 // Reorder pictures on the list in a way specified in the stream. | 515 // Reorder pictures on the list in a way specified in the stream. |
| 514 int pic_num_lx_pred = curr_pic_->pic_num; | 516 int pic_num_lx_pred = curr_pic_->pic_num; |
| 515 int ref_idx_lx = 0; | 517 int ref_idx_lx = 0; |
| 516 int pic_num_lx_no_wrap; | 518 int pic_num_lx_no_wrap; |
| 517 int pic_num_lx; | 519 int pic_num_lx; |
| 518 bool done = false; | 520 bool done = false; |
| 519 scoped_refptr<H264Picture> pic; | 521 scoped_refptr<H264Picture> pic; |
| 520 for (int i = 0; i < media::H264SliceHeader::kRefListModSize && !done; ++i) { | 522 for (int i = 0; i < media::H264SliceHeader::kRefListModSize && !done; ++i) { |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 | 1285 |
| 1284 gfx::Size H264Decoder::GetPicSize() const { | 1286 gfx::Size H264Decoder::GetPicSize() const { |
| 1285 return pic_size_; | 1287 return pic_size_; |
| 1286 } | 1288 } |
| 1287 | 1289 |
| 1288 size_t H264Decoder::GetRequiredNumOfPictures() const { | 1290 size_t H264Decoder::GetRequiredNumOfPictures() const { |
| 1289 return dpb_.max_num_pics() + kPicsInPipeline; | 1291 return dpb_.max_num_pics() + kPicsInPipeline; |
| 1290 } | 1292 } |
| 1291 | 1293 |
| 1292 } // namespace content | 1294 } // namespace content |
| OLD | NEW |