| OLD | NEW |
| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <cstdlib> | 6 #include <cstdlib> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 // Now parse a whole cluster to verify that all the blocks will get parsed. | 796 // Now parse a whole cluster to verify that all the blocks will get parsed. |
| 797 result = parser_->Parse(cluster->data(), cluster->size()); | 797 result = parser_->Parse(cluster->data(), cluster->size()); |
| 798 EXPECT_EQ(cluster->size(), result); | 798 EXPECT_EQ(cluster->size(), result); |
| 799 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 799 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 800 } | 800 } |
| 801 | 801 |
| 802 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { | 802 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { |
| 803 InSequence s; | 803 InSequence s; |
| 804 | 804 |
| 805 // Absent DefaultDuration information, SimpleBlock durations are derived from | 805 // Absent DefaultDuration information, SimpleBlock durations are derived from |
| 806 // inter-buffer track timestamp delta if within the cluster, and are estimated | 806 // inter-buffer track timestamp delta if within the cluster. Duration for the |
| 807 // as the lowest non-zero duration seen so far if the last buffer in the track | 807 // last block in a cluster is estimated independently for each track in the |
| 808 // in the cluster (independently for each track in the cluster). | 808 // cluster. For video tracks we use the maximum seen so far. For audio we use |
| 809 // the the minimum. |
| 810 // TODO(chcunningham): Move audio over to use the maximum. |
| 809 const BlockInfo kBlockInfo1[] = { | 811 const BlockInfo kBlockInfo1[] = { |
| 810 {kAudioTrackNum, 0, 23, true, NULL, 0}, | 812 {kAudioTrackNum, 0, 23, true, NULL, 0}, |
| 811 {kAudioTrackNum, 23, 22, true, NULL, 0}, | 813 {kAudioTrackNum, 23, 22, true, NULL, 0}, |
| 812 {kVideoTrackNum, 33, 33, true, NULL, 0}, | 814 {kVideoTrackNum, 33, 33, true, NULL, 0}, |
| 813 {kAudioTrackNum, 45, 23, true, NULL, 0}, | 815 {kAudioTrackNum, 45, 23, true, NULL, 0}, |
| 814 {kVideoTrackNum, 66, 34, true, NULL, 0}, | 816 {kVideoTrackNum, 66, 34, true, NULL, 0}, |
| 815 // Estimated from minimum audio dur | 817 // Estimated from minimum audio dur |
| 816 {kAudioTrackNum, 68, 22, true, NULL, 0}, | 818 {kAudioTrackNum, 68, 22, true, NULL, 0}, |
| 817 // Estimated from minimum video dur | 819 // Estimated from maximum video dur |
| 818 {kVideoTrackNum, 100, 33, true, NULL, 0}, | 820 {kVideoTrackNum, 100, 34, true, NULL, 0}, |
| 819 }; | 821 }; |
| 820 | 822 |
| 821 int block_count1 = arraysize(kBlockInfo1); | 823 int block_count1 = arraysize(kBlockInfo1); |
| 822 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 824 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); |
| 823 | 825 |
| 824 // Send slightly less than the first full cluster so all but the last video | 826 // Send slightly less than the first full cluster so all but the last video |
| 825 // block is parsed. Verify the last fully parsed audio and video buffer are | 827 // block is parsed. Verify the last fully parsed audio and video buffer are |
| 826 // both missing from the result (parser should hold them aside for duration | 828 // both missing from the result (parser should hold them aside for duration |
| 827 // estimation prior to end of cluster detection in the absence of | 829 // estimation prior to end of cluster detection in the absence of |
| 828 // DefaultDurations.) | 830 // DefaultDurations.) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 839 result = parser_->Parse(cluster1->data(), cluster1->size()); | 841 result = parser_->Parse(cluster1->data(), cluster1->size()); |
| 840 EXPECT_EQ(cluster1->size(), result); | 842 EXPECT_EQ(cluster1->size(), result); |
| 841 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 843 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 842 | 844 |
| 843 // Verify that the estimated frame duration is tracked across clusters for | 845 // Verify that the estimated frame duration is tracked across clusters for |
| 844 // each track. | 846 // each track. |
| 845 const BlockInfo kBlockInfo2[] = { | 847 const BlockInfo kBlockInfo2[] = { |
| 846 // Estimate carries over across clusters | 848 // Estimate carries over across clusters |
| 847 {kAudioTrackNum, 200, 22, true, NULL, 0}, | 849 {kAudioTrackNum, 200, 22, true, NULL, 0}, |
| 848 // Estimate carries over across clusters | 850 // Estimate carries over across clusters |
| 849 {kVideoTrackNum, 201, 33, true, NULL, 0}, | 851 {kVideoTrackNum, 201, 34, true, NULL, 0}, |
| 850 }; | 852 }; |
| 851 | 853 |
| 852 int block_count2 = arraysize(kBlockInfo2); | 854 int block_count2 = arraysize(kBlockInfo2); |
| 853 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 855 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); |
| 854 result = parser_->Parse(cluster2->data(), cluster2->size()); | 856 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 855 EXPECT_EQ(cluster2->size(), result); | 857 EXPECT_EQ(cluster2->size(), result); |
| 856 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 858 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 857 } | 859 } |
| 858 | 860 |
| 859 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { | 861 TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { |
| 860 InSequence s; | 862 InSequence s; |
| 861 | 863 |
| 862 // Absent DefaultDuration and BlockDuration information, BlockGroup block | 864 // Absent DefaultDuration and BlockDuration information, BlockGroup block |
| 863 // durations are derived from inter-buffer track timestamp delta if within the | 865 // durations are derived from inter-buffer track timestamp delta if within the |
| 864 // cluster, and are estimated as the lowest non-zero duration seen so far if | 866 // cluster. Duration for the last block in a cluster is estimated |
| 865 // the last buffer in the track in the cluster (independently for each track | 867 // independently for each track in the cluster. For video tracks we use the |
| 866 // in the cluster). | 868 // maximum seen so far. For audio we use the the minimum. |
| 869 // TODO(chcunningham): Move audio over to use the maximum. |
| 867 const BlockInfo kBlockInfo1[] = { | 870 const BlockInfo kBlockInfo1[] = { |
| 868 {kAudioTrackNum, 0, -23, false, NULL, 0}, | 871 {kAudioTrackNum, 0, -23, false, NULL, 0}, |
| 869 {kAudioTrackNum, 23, -22, false, NULL, 0}, | 872 {kAudioTrackNum, 23, -22, false, NULL, 0}, |
| 870 {kVideoTrackNum, 33, -33, false, NULL, 0}, | 873 {kVideoTrackNum, 33, -33, false, NULL, 0}, |
| 871 {kAudioTrackNum, 45, -23, false, NULL, 0}, | 874 {kAudioTrackNum, 45, -23, false, NULL, 0}, |
| 872 {kVideoTrackNum, 66, -34, false, NULL, 0}, | 875 {kVideoTrackNum, 66, -34, false, NULL, 0}, |
| 873 // Estimated from minimum audio dur | 876 // Estimated from minimum audio dur |
| 874 {kAudioTrackNum, 68, -22, false, NULL, 0}, | 877 {kAudioTrackNum, 68, -22, false, NULL, 0}, |
| 875 // Estimated from minimum video dur | 878 // Estimated from maximum video dur |
| 876 {kVideoTrackNum, 100, -33, false, NULL, 0}, | 879 {kVideoTrackNum, 100, -34, false, NULL, 0}, |
| 877 }; | 880 }; |
| 878 | 881 |
| 879 int block_count1 = arraysize(kBlockInfo1); | 882 int block_count1 = arraysize(kBlockInfo1); |
| 880 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); | 883 scoped_ptr<Cluster> cluster1(CreateCluster(0, kBlockInfo1, block_count1)); |
| 881 | 884 |
| 882 // Send slightly less than the first full cluster so all but the last video | 885 // Send slightly less than the first full cluster so all but the last video |
| 883 // block is parsed. Verify the last fully parsed audio and video buffer are | 886 // block is parsed. Verify the last fully parsed audio and video buffer are |
| 884 // both missing from the result (parser should hold them aside for duration | 887 // both missing from the result (parser should hold them aside for duration |
| 885 // estimation prior to end of cluster detection in the absence of | 888 // estimation prior to end of cluster detection in the absence of |
| 886 // DefaultDurations.) | 889 // DefaultDurations.) |
| 887 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); | 890 int result = parser_->Parse(cluster1->data(), cluster1->size() - 1); |
| 888 EXPECT_GT(result, 0); | 891 EXPECT_GT(result, 0); |
| 889 EXPECT_LT(result, cluster1->size()); | 892 EXPECT_LT(result, cluster1->size()); |
| 890 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); | 893 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1 - 3)); |
| 891 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); | 894 EXPECT_EQ(3UL, parser_->GetAudioBuffers().size()); |
| 892 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); | 895 EXPECT_EQ(1UL, parser_->GetVideoBuffers().size()); |
| 893 | 896 |
| 894 parser_->Reset(); | 897 parser_->Reset(); |
| 895 | 898 |
| 896 // Now parse the full first cluster and verify all the blocks are parsed. | 899 // Now parse the full first cluster and verify all the blocks are parsed. |
| 897 result = parser_->Parse(cluster1->data(), cluster1->size()); | 900 result = parser_->Parse(cluster1->data(), cluster1->size()); |
| 898 EXPECT_EQ(cluster1->size(), result); | 901 EXPECT_EQ(cluster1->size(), result); |
| 899 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); | 902 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo1, block_count1)); |
| 900 | 903 |
| 901 // Verify that the estimated frame duration is tracked across clusters for | 904 // Verify that the estimated frame duration is tracked across clusters for |
| 902 // each track. | 905 // each track. |
| 903 const BlockInfo kBlockInfo2[] = { | 906 const BlockInfo kBlockInfo2[] = { |
| 904 {kAudioTrackNum, 200, -22, false, NULL, 0}, | 907 {kAudioTrackNum, 200, -22, false, NULL, 0}, |
| 905 {kVideoTrackNum, 201, -33, false, NULL, 0}, | 908 {kVideoTrackNum, 201, -34, false, NULL, 0}, |
| 906 }; | 909 }; |
| 907 | 910 |
| 908 int block_count2 = arraysize(kBlockInfo2); | 911 int block_count2 = arraysize(kBlockInfo2); |
| 909 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); | 912 scoped_ptr<Cluster> cluster2(CreateCluster(0, kBlockInfo2, block_count2)); |
| 910 result = parser_->Parse(cluster2->data(), cluster2->size()); | 913 result = parser_->Parse(cluster2->data(), cluster2->size()); |
| 911 EXPECT_EQ(cluster2->size(), result); | 914 EXPECT_EQ(cluster2->size(), result); |
| 912 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); | 915 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo2, block_count2)); |
| 913 } | 916 } |
| 914 | 917 |
| 915 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. | 918 // TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 int block_count = arraysize(kBlockInfo); | 1085 int block_count = arraysize(kBlockInfo); |
| 1083 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); | 1086 scoped_ptr<Cluster> cluster(CreateCluster(0, kBlockInfo, block_count)); |
| 1084 int result = parser_->Parse(cluster->data(), cluster->size()); | 1087 int result = parser_->Parse(cluster->data(), cluster->size()); |
| 1085 EXPECT_EQ(cluster->size(), result); | 1088 EXPECT_EQ(cluster->size(), result); |
| 1086 | 1089 |
| 1087 // Will verify that duration of buffer matches that of BlockDuration. | 1090 // Will verify that duration of buffer matches that of BlockDuration. |
| 1088 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); | 1091 ASSERT_TRUE(VerifyBuffers(parser_, kBlockInfo, block_count)); |
| 1089 } | 1092 } |
| 1090 | 1093 |
| 1091 } // namespace media | 1094 } // namespace media |
| OLD | NEW |