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

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

Issue 379983002: Fix AnnexB validation logic to work with encrypted content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
Index: media/formats/mp4/avc.cc
diff --git a/media/formats/mp4/avc.cc b/media/formats/mp4/avc.cc
index 6c2bc2a6fcabab937df14a2fdf78f9bdc43ce90b..ebec41ed41c2ed79a1e29b9a58cc7e5765769638 100644
--- a/media/formats/mp4/avc.cc
+++ b/media/formats/mp4/avc.cc
@@ -76,11 +76,11 @@ bool AVC::ConvertFrameToAnnexB(int length_size, std::vector<uint8>* buffer) {
bool AVC::InsertParamSetsAnnexB(const AVCDecoderConfigurationRecord& avc_config,
std::vector<uint8>* buffer,
std::vector<SubsampleEntry>* subsamples) {
- DCHECK(AVC::IsValidAnnexB(*buffer));
+ DCHECK(AVC::IsValidAnnexB(*buffer, *subsamples));
scoped_ptr<H264Parser> parser(new H264Parser());
const uint8* start = &(*buffer)[0];
- parser->SetStream(start, buffer->size());
+ parser->SetStream(start, buffer->size(), *subsamples);
H264NALU nalu;
if (parser->AdvanceToNextNALU(&nalu) != H264Parser::kOk)
@@ -126,7 +126,7 @@ bool AVC::InsertParamSetsAnnexB(const AVCDecoderConfigurationRecord& avc_config,
buffer->insert(config_insert_point,
param_sets.begin(), param_sets.end());
- DCHECK(AVC::IsValidAnnexB(*buffer));
+ DCHECK(AVC::IsValidAnnexB(*buffer, *subsamples));
return true;
}
@@ -171,11 +171,13 @@ bool AVC::ConvertConfigToAnnexB(
}
// Verifies AnnexB NALU order according to ISO/IEC 14496-10 Section 7.4.1.2.3
-bool AVC::IsValidAnnexB(const std::vector<uint8>& buffer) {
- return IsValidAnnexB(&buffer[0], buffer.size());
+bool AVC::IsValidAnnexB(const std::vector<uint8>& buffer,
+ const std::vector<SubsampleEntry>& subsamples) {
+ return IsValidAnnexB(&buffer[0], buffer.size(), subsamples);
}
-bool AVC::IsValidAnnexB(const uint8* buffer, size_t size) {
+bool AVC::IsValidAnnexB(const uint8* buffer, size_t size,
+ const std::vector<SubsampleEntry>& subsamples) {
DVLOG(1) << __FUNCTION__;
DCHECK(buffer);
@@ -183,7 +185,7 @@ bool AVC::IsValidAnnexB(const uint8* buffer, size_t size) {
return true;
H264Parser parser;
- parser.SetStream(buffer, size);
+ parser.SetStream(buffer, size, subsamples);
typedef enum {
kAUDAllowed,
@@ -305,6 +307,73 @@ bool AVC::IsValidAnnexB(const uint8* buffer, size_t size) {
return order_state >= kAfterFirstVCL;
}
+/*
+AVC::NALUIterator::NALUIterator(const uint8* buffer, size_t size,
xhwang 2014/07/10 06:23:01 Remove?
acolwell GONE FROM CHROMIUM 2014/07/15 22:10:44 Oops. Done.
+ const std::vector<SubsampleEntry>& subsamples)
+ : buffer_(buffer),
+ subsamples_(subsamples),
+ subsample_index_(0),
+ subsample_offset_(0) {
+ parser_.SetStream(buffer, size);
+}
+
+AVC::NALUIterator::Result AVC::NALUIterator::AdvanceToNextNALU(H264NALU* nalu) {
+ for (;;) {
+ switch (parser_.AdvanceToNextNALU(nalu)) {
+ case H264Parser::kOk : {
+ if (subsamples_.empty())
+ return NALUIterator::OK;
+
+ // Compute the offset of they type field.
+ size_t nalu_type_offset = (nalu->data - buffer_);
+ bool is_inside_encrypted_section = false;
+ for(;;) {
+ if (subsample_index_ >= subsamples_.size()) {
+ DVLOG(1) << "Went beyond the end of the subsample info.";
+ return NALUIterator::ERROR;
+ }
+
+ size_t encrypted_start_offset =
+ subsample_offset_ + subsamples_[subsample_index_].clear_bytes;
+ size_t subsample_end_offset = encrypted_start_offset +
+ subsamples_[subsample_index_].cypher_bytes;
+
+ if (nalu_type_offset >= subsample_end_offset) {
+ // |nalu_type_offset| is beyond the current subsample. Move
+ // on to the next one.
+ subsample_offset_ = subsample_end_offset;
+ subsample_index_++;
+ continue;
+ }
+
+ is_inside_encrypted_section =
+ (nalu_type_offset >= encrypted_start_offset &&
+ nalu_type_offset < subsample_end_offset);
+ break;
+ }
+
+ if (is_inside_encrypted_section) {
+ DVLOG(1) << "Detected a start code inside an encrypted section."
+ << " Looking for the next start code.";
+ continue;
+ }
+
+ return NALUIterator::OK;
+ } break;
+
+ case H264Parser::kInvalidStream:
+ return NALUIterator::ERROR;
+ case H264Parser::kUnsupportedStream:
+ return NALUIterator::ERROR;
+
+ case H264Parser::kEOStream:
+ return END_OF_STREAM;
+ }
+ }
+
+ return NALUIterator::OK;
+}
+*/
} // namespace mp4
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698