OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file contains an implementation of a VP8 raw stream parser, | 5 // This file contains an implementation of a VP8 raw stream parser, |
6 // as defined in RFC 6386. | 6 // as defined in RFC 6386. |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/filters/vp8_parser.h" | 9 #include "media/filters/vp8_parser.h" |
10 | 10 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 sizeof(curr_entropy_hdr_.mv_probs)); | 786 sizeof(curr_entropy_hdr_.mv_probs)); |
787 } | 787 } |
788 | 788 |
789 return true; | 789 return true; |
790 } | 790 } |
791 | 791 |
792 bool Vp8Parser::ParsePartitions(Vp8FrameHeader* fhdr) { | 792 bool Vp8Parser::ParsePartitions(Vp8FrameHeader* fhdr) { |
793 CHECK_GE(fhdr->num_of_dct_partitions, 1u); | 793 CHECK_GE(fhdr->num_of_dct_partitions, 1u); |
794 CHECK_LE(fhdr->num_of_dct_partitions, kMaxDCTPartitions); | 794 CHECK_LE(fhdr->num_of_dct_partitions, kMaxDCTPartitions); |
795 | 795 |
796 // Jump to the beginning of the first dct partition. | 796 // DCT partitions start after the first partition and partition size values |
797 size_t first_dct_pos = fhdr->first_part_offset + fhdr->first_part_size; | 797 // that follow it. There are num_of_dct_partitions - 1 sizes stored in the |
798 // stream after the first partition, each 3 bytes long. The size of last | |
799 // DCT partition is not stored in the stream, but is instead calculated by | |
800 // taking the remainder of the frame size after the penultimate DCT partition. | |
801 size_t first_dct_pos = fhdr->first_part_offset + fhdr->first_part_size + | |
802 (fhdr->num_of_dct_partitions - 1) * 3; | |
803 | |
804 // Make sure we have enough data for the first partition and partition sizes. | |
798 if (fhdr->frame_size < first_dct_pos) | 805 if (fhdr->frame_size < first_dct_pos) |
799 return false; | 806 return false; |
800 const uint8_t* ptr = fhdr->data + first_dct_pos; | 807 |
808 // Total size of all DCT partitions. | |
801 size_t bytes_left = fhdr->frame_size - first_dct_pos; | 809 size_t bytes_left = fhdr->frame_size - first_dct_pos; |
802 | 810 |
811 // Position ourselves at the beginning of partition size values. | |
812 const uint8_t* ptr = | |
813 fhdr->data + fhdr->first_part_offset + fhdr->first_part_size; | |
Ville-Mikko Rautio
2015/02/13 23:03:02
To minimize the chance of confusion it might be wo
Pawel Osciak
2015/02/13 23:07:21
So you mean change num_of_dct_partitions to num_of
Ville-Mikko Rautio
2015/02/13 23:17:38
Either that or change (first_part_offset, first_pa
Pawel Osciak
2015/02/13 23:20:39
I see, makes sense. Given that this will have to b
| |
814 | |
815 // Read sizes from the stream (if present). | |
803 for (size_t i = 0; i < fhdr->num_of_dct_partitions - 1; ++i) { | 816 for (size_t i = 0; i < fhdr->num_of_dct_partitions - 1; ++i) { |
804 // Need 3 bytes at the beginning of the partition to read its size from. | 817 fhdr->dct_partition_sizes[i] = (ptr[2] << 16) | (ptr[1] << 8) | ptr[0]; |
Ville-Mikko Rautio
2015/02/13 23:03:02
IIUC ptr[i] (i>=0) might refer out of allocated bo
Pawel Osciak
2015/02/13 23:07:21
I check this at l.801 above. I check that frame_si
Ville-Mikko Rautio
2015/02/13 23:17:38
You're correct. Also on line 821 you'll exit if th
| |
805 if (bytes_left < 3) | 818 |
819 // Make sure we have enough data in the stream for ith partition and | |
820 // subtract its size from total. | |
821 if (bytes_left < fhdr->dct_partition_sizes[i]) | |
806 return false; | 822 return false; |
807 | 823 |
808 fhdr->dct_partition_sizes[i] = (ptr[2] << 16) | (ptr[1] << 8) | ptr[0]; | 824 bytes_left -= fhdr->dct_partition_sizes[i]; |
809 | 825 |
810 ptr += fhdr->dct_partition_sizes[i] + 3; | 826 // Move to the position of the next partition size value. |
811 bytes_left -= fhdr->dct_partition_sizes[i] + 3; | 827 ptr += 3; |
812 } | 828 } |
813 | 829 |
830 // The remainder of the data belongs to the last DCT partition. | |
814 fhdr->dct_partition_sizes[fhdr->num_of_dct_partitions - 1] = bytes_left; | 831 fhdr->dct_partition_sizes[fhdr->num_of_dct_partitions - 1] = bytes_left; |
815 | 832 |
816 DVLOG(4) << "Control part size: " << fhdr->first_part_size; | 833 DVLOG(4) << "Control part size: " << fhdr->first_part_size; |
817 for (size_t i = 0; i < fhdr->num_of_dct_partitions; ++i) | 834 for (size_t i = 0; i < fhdr->num_of_dct_partitions; ++i) |
818 DVLOG(4) << "DCT part " << i << " size: " << fhdr->dct_partition_sizes[i]; | 835 DVLOG(4) << "DCT part " << i << " size: " << fhdr->dct_partition_sizes[i]; |
819 | 836 |
820 return true; | 837 return true; |
821 } | 838 } |
822 | 839 |
823 } // namespace media | 840 } // namespace media |
OLD | NEW |