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

Unified Diff: media/formats/mp4/avc_unittest.cc

Issue 626193003: Implement extended syntax for AVC/h264 unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698