Chromium Code Reviews| Index: media/formats/mp4/avc_unittest.cc |
| diff --git a/media/formats/mp4/avc_unittest.cc b/media/formats/mp4/avc_unittest.cc |
| index 96a8a971d6fcc2886624f04ba1f7dfe55acc4748..364f656ad644051027734765261634de211842b3 100644 |
| --- a/media/formats/mp4/avc_unittest.cc |
| +++ b/media/formats/mp4/avc_unittest.cc |
| @@ -131,16 +131,20 @@ void StringToAnnexB(const std::string& str, std::vector<uint8>* buffer, |
| SubsampleEntry entry; |
| size_t start = buffer->size(); |
| - WriteStartCodeAndNALUType(buffer, tokens[i]); |
| + std::vector<std::string> subsample_nalus; |
| + EXPECT_GT(Tokenize(tokens[i], ",", &subsample_nalus), 0u); |
| + for (size_t j = 0; j < subsample_nalus.size(); ++j) { |
| + WriteStartCodeAndNALUType(buffer, subsample_nalus[j]); |
| + |
| + // Write junk for the payload since the current code doesn't |
| + // actually look at it. |
| + buffer->push_back(0x32); |
| + buffer->push_back(0x12); |
| + buffer->push_back(0x67); |
| + } |
| entry.clear_bytes = buffer->size() - start; |
| - // Write junk for the payload since the current code doesn't |
| - // actually look at it. |
| - buffer->push_back(0x32); |
| - buffer->push_back(0x12); |
| - buffer->push_back(0x67); |
| - |
| if (subsamples) { |
| // Simulate the encrypted bits containing something that looks |
| // like a SPS NALU. |
| @@ -155,6 +159,25 @@ void StringToAnnexB(const std::string& str, std::vector<uint8>* buffer, |
| } |
| } |
| +int FindSubsampleIndex(const std::vector<uint8>& buffer, |
| + const std::vector<SubsampleEntry>* subsamples, |
| + const uint8* ptr) { |
| + DCHECK(ptr >= &buffer[0]); |
| + DCHECK(ptr <= &buffer[buffer.size()-1]); |
| + if (!subsamples || subsamples->empty()) |
| + return 0; |
| + |
| + const uint8* p = &buffer[0]; |
| + for (size_t i = 0; i < subsamples->size(); ++i) { |
| + p += (*subsamples)[i].clear_bytes + (*subsamples)[i].cypher_bytes; |
| + if (p > ptr) { |
| + return i; |
| + } |
| + } |
| + DCHECK(false); |
|
wolenetz
2014/10/07 23:37:39
nit: NOTREACHED();
servolk
2014/10/07 23:57:18
Done.
|
| + return 0; |
| +} |
| + |
| std::string AnnexBToString(const std::vector<uint8>& buffer, |
| const std::vector<SubsampleEntry>& subsamples) { |
| std::stringstream ss; |
| @@ -164,13 +187,16 @@ std::string AnnexBToString(const std::vector<uint8>& buffer, |
| H264NALU nalu; |
| bool first = true; |
| + size_t current_subsample = 0; |
|
wolenetz
2014/10/07 23:37:39
nit: s/ple/ple_index/
servolk
2014/10/07 23:57:19
Done.
|
| while (parser.AdvanceToNextNALU(&nalu) == H264Parser::kOk) { |
| + size_t subsample = FindSubsampleIndex(buffer, &subsamples, nalu.data); |
|
wolenetz
2014/10/07 23:37:39
nit: ditto
servolk
2014/10/07 23:57:18
Done.
|
| if (!first) |
| - ss << " "; |
| + ss << (subsample == current_subsample ? "," : " "); |
| else |
| first = false; |
|
wolenetz
2014/10/07 23:37:39
nit: maybe add a DCHECK_EQ(subsample_index, curren
servolk
2014/10/07 23:57:19
Done.
|
| ss << NALUTypeToString(nalu.nal_unit_type); |
| + current_subsample = subsample; |
| } |
| return ss.str(); |
| } |
| @@ -206,7 +232,7 @@ TEST_P(AVCConversionTest, ParseCorrectly) { |
| EXPECT_TRUE(AVC::IsValidAnnexB(buf, subsamples)); |
| EXPECT_EQ(buf.size(), sizeof(kExpected)); |
| EXPECT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected))); |
| - EXPECT_EQ("P SDC", AnnexBToString(buf, subsamples)); |
| + EXPECT_EQ("P,SDC", AnnexBToString(buf, subsamples)); |
| } |
| // Intentionally write NALU sizes that are larger than the buffer. |
| @@ -304,6 +330,9 @@ TEST_F(AVCConversionTest, ValidAnnexBConstructs) { |
| "SEI SEI R14 I", |
| "SPS SPSExt SPS PPS I P", |
| "R14 SEI I", |
| + "AUD,I", |
| + "AUD,SEI I", |
| + "AUD,SEI,SPS,PPS,I" |
| }; |
| for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| @@ -318,6 +347,7 @@ TEST_F(AVCConversionTest, ValidAnnexBConstructs) { |
| TEST_F(AVCConversionTest, InvalidAnnexBConstructs) { |
| static const char* test_cases[] = { |
| "AUD", // No VCL present. |
| + "AUD,SEI", // No VCL present. |
| "SPS PPS", // No VCL present. |
| "SPS PPS AUD I", // Parameter sets must come after AUD. |
| "SPSExt SPS P", // SPS must come before SPSExt. |