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

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

Issue 591713002: Fix inserting SPS/PPS after AUD NALU (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback fixes 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 | « media/formats/mp4/avc.h ('k') | media/formats/mp4/avc_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/formats/mp4/avc.cc
diff --git a/media/formats/mp4/avc.cc b/media/formats/mp4/avc.cc
index 4a9a880a9b5326e184fbf808f436d08a764acfcc..33fce1d8062cf237e030de4fa9b90e9b1dcc8015 100644
--- a/media/formats/mp4/avc.cc
+++ b/media/formats/mp4/avc.cc
@@ -41,6 +41,25 @@ static bool ConvertAVCToAnnexBInPlaceForLengthSize4(std::vector<uint8>* buf) {
}
// static
+int AVC::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;
+ }
+ NOTREACHED();
+ return 0;
+}
+
+// static
bool AVC::ConvertFrameToAnnexB(int length_size, std::vector<uint8>* buffer) {
RCHECK(length_size == 1 || length_size == 2 || length_size == 4);
@@ -87,23 +106,10 @@ bool AVC::InsertParamSetsAnnexB(const AVCDecoderConfigurationRecord& avc_config,
return false;
std::vector<uint8>::iterator config_insert_point = buffer->begin();
- std::vector<SubsampleEntry>::iterator subsamples_insert_point =
- subsamples->begin();
if (nalu.nal_unit_type == H264NALU::kAUD) {
// Move insert point to just after the AUD.
config_insert_point += (nalu.data + nalu.size) - start;
-
- if (!subsamples->empty()) {
- int64 first_subsample_size =
- (*subsamples)[0].clear_bytes + (*subsamples)[0].cypher_bytes;
-
- if (first_subsample_size != (config_insert_point - buffer->begin()))
- return false;
-
- subsamples_insert_point++;
- }
-
}
// Clear |parser| and |start| since they aren't needed anymore and
@@ -112,15 +118,13 @@ bool AVC::InsertParamSetsAnnexB(const AVCDecoderConfigurationRecord& avc_config,
start = NULL;
std::vector<uint8> param_sets;
- std::vector<SubsampleEntry> config_subsamples;
- RCHECK(AVC::ConvertConfigToAnnexB(avc_config,
- &param_sets,
- &config_subsamples));
-
- if (!subsamples->empty()) {
- subsamples->insert(subsamples_insert_point,
- config_subsamples.begin(),
- config_subsamples.end());
+ RCHECK(AVC::ConvertConfigToAnnexB(avc_config, &param_sets));
+
+ if (subsamples && !subsamples->empty()) {
+ int subsample_index = FindSubsampleIndex(*buffer, subsamples,
+ &(*config_insert_point));
+ // Update the size of the subsample where SPS/PPS is to be inserted.
+ (*subsamples)[subsample_index].clear_bytes += param_sets.size();
}
buffer->insert(config_insert_point,
@@ -133,8 +137,7 @@ bool AVC::InsertParamSetsAnnexB(const AVCDecoderConfigurationRecord& avc_config,
// static
bool AVC::ConvertConfigToAnnexB(
const AVCDecoderConfigurationRecord& avc_config,
- std::vector<uint8>* buffer,
- std::vector<SubsampleEntry>* subsamples) {
+ std::vector<uint8>* buffer) {
DCHECK(buffer->empty());
buffer->clear();
int total_size = 0;
@@ -149,11 +152,6 @@ bool AVC::ConvertConfigToAnnexB(
kAnnexBStartCode + kAnnexBStartCodeSize);
buffer->insert(buffer->end(), avc_config.sps_list[i].begin(),
avc_config.sps_list[i].end());
-
- SubsampleEntry entry;
- entry.clear_bytes = kAnnexBStartCodeSize + avc_config.sps_list[i].size();
- entry.cypher_bytes = 0;
- subsamples->push_back(entry);
}
for (size_t i = 0; i < avc_config.pps_list.size(); i++) {
@@ -161,11 +159,6 @@ bool AVC::ConvertConfigToAnnexB(
kAnnexBStartCode + kAnnexBStartCodeSize);
buffer->insert(buffer->end(), avc_config.pps_list[i].begin(),
avc_config.pps_list[i].end());
-
- SubsampleEntry entry;
- entry.clear_bytes = kAnnexBStartCodeSize + avc_config.pps_list[i].size();
- entry.cypher_bytes = 0;
- subsamples->push_back(entry);
}
return true;
}
« no previous file with comments | « media/formats/mp4/avc.h ('k') | media/formats/mp4/avc_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698