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

Side by Side Diff: media/mp4/track_run_iterator.cc

Issue 10832176: Add initial support for edit lists in MSE BMFF. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Counting? Who needs counting? Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/mp4/track_run_iterator.h" 5 #include "media/mp4/track_run_iterator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "media/base/stream_parser_buffer.h" 9 #include "media/base/stream_parser_buffer.h"
10 #include "media/mp4/rcheck.h" 10 #include "media/mp4/rcheck.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 TrackRunIterator::TrackRunIterator(const Movie* moov) 65 TrackRunIterator::TrackRunIterator(const Movie* moov)
66 : moov_(moov), sample_offset_(0) { 66 : moov_(moov), sample_offset_(0) {
67 CHECK(moov); 67 CHECK(moov);
68 } 68 }
69 TrackRunIterator::~TrackRunIterator() {} 69 TrackRunIterator::~TrackRunIterator() {}
70 70
71 static void PopulateSampleInfo(const TrackExtends& trex, 71 static void PopulateSampleInfo(const TrackExtends& trex,
72 const TrackFragmentHeader& tfhd, 72 const TrackFragmentHeader& tfhd,
73 const TrackFragmentRun& trun, 73 const TrackFragmentRun& trun,
74 const int64 edit_list_offset,
74 const uint32 i, 75 const uint32 i,
75 SampleInfo* sample_info) { 76 SampleInfo* sample_info) {
76 if (i < trun.sample_sizes.size()) { 77 if (i < trun.sample_sizes.size()) {
77 sample_info->size = trun.sample_sizes[i]; 78 sample_info->size = trun.sample_sizes[i];
78 } else if (tfhd.default_sample_size > 0) { 79 } else if (tfhd.default_sample_size > 0) {
79 sample_info->size = tfhd.default_sample_size; 80 sample_info->size = tfhd.default_sample_size;
80 } else { 81 } else {
81 sample_info->size = trex.default_sample_size; 82 sample_info->size = trex.default_sample_size;
82 } 83 }
83 84
84 if (i < trun.sample_durations.size()) { 85 if (i < trun.sample_durations.size()) {
85 sample_info->duration = trun.sample_durations[i]; 86 sample_info->duration = trun.sample_durations[i];
86 } else if (tfhd.default_sample_duration > 0) { 87 } else if (tfhd.default_sample_duration > 0) {
87 sample_info->duration = tfhd.default_sample_duration; 88 sample_info->duration = tfhd.default_sample_duration;
88 } else { 89 } else {
89 sample_info->duration = trex.default_sample_duration; 90 sample_info->duration = trex.default_sample_duration;
90 } 91 }
91 92
92 if (i < trun.sample_composition_time_offsets.size()) { 93 if (i < trun.sample_composition_time_offsets.size()) {
93 sample_info->cts_offset = trun.sample_composition_time_offsets[i]; 94 sample_info->cts_offset = trun.sample_composition_time_offsets[i];
94 } else { 95 } else {
95 sample_info->cts_offset = 0; 96 sample_info->cts_offset = 0;
96 } 97 }
98 sample_info->cts_offset += edit_list_offset;
97 99
98 uint32 flags; 100 uint32 flags;
99 if (i < trun.sample_flags.size()) { 101 if (i < trun.sample_flags.size()) {
100 flags = trun.sample_flags[i]; 102 flags = trun.sample_flags[i];
101 } else if (tfhd.has_default_sample_flags) { 103 } else if (tfhd.has_default_sample_flags) {
102 flags = tfhd.default_sample_flags; 104 flags = tfhd.default_sample_flags;
103 } else { 105 } else {
104 flags = trex.default_sample_flags; 106 flags = trex.default_sample_flags;
105 } 107 }
106 sample_info->is_keyframe = !(flags & kSampleIsDifferenceSampleFlagMask); 108 sample_info->is_keyframe = !(flags & kSampleIsDifferenceSampleFlagMask);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 trak->media.information.sample_table.description; 159 trak->media.information.sample_table.description;
158 if (stsd.type != kAudio && stsd.type != kVideo) { 160 if (stsd.type != kAudio && stsd.type != kVideo) {
159 DVLOG(1) << "Skipping unhandled track type"; 161 DVLOG(1) << "Skipping unhandled track type";
160 continue; 162 continue;
161 } 163 }
162 size_t desc_idx = traf.header.sample_description_index; 164 size_t desc_idx = traf.header.sample_description_index;
163 if (!desc_idx) desc_idx = trex->default_sample_description_index; 165 if (!desc_idx) desc_idx = trex->default_sample_description_index;
164 RCHECK(desc_idx > 0); // Descriptions are one-indexed in the file 166 RCHECK(desc_idx > 0); // Descriptions are one-indexed in the file
165 desc_idx -= 1; 167 desc_idx -= 1;
166 168
169 // Process edit list to remove CTS offset introduced in the presence of
170 // B-frames. Other uses of edit lists are not supported, as they are
171 // both uncommon and better served by higher-level protocols.
acolwell GONE FROM CHROMIUM 2012/08/07 20:12:13 nit: It looks like there should be a if (stuff w
strobe_ 2012/08/07 22:54:39 Done.
172 int64 edit_list_offset = 0;
173 const std::vector<EditListEntry>& edits = trak->edit.list.edits;
174 if (!edits.empty() && edits[0].media_time > 0) {
175 edit_list_offset = -edits[0].media_time;
176 }
177
167 int64 run_start_dts = traf.decode_time.decode_time; 178 int64 run_start_dts = traf.decode_time.decode_time;
168 int sample_count_sum = 0; 179 int sample_count_sum = 0;
169 180
170 for (size_t j = 0; j < traf.runs.size(); j++) { 181 for (size_t j = 0; j < traf.runs.size(); j++) {
171 const TrackFragmentRun& trun = traf.runs[j]; 182 const TrackFragmentRun& trun = traf.runs[j];
172 TrackRunInfo tri; 183 TrackRunInfo tri;
173 tri.track_id = traf.header.track_id; 184 tri.track_id = traf.header.track_id;
174 tri.timescale = trak->media.header.timescale; 185 tri.timescale = trak->media.header.timescale;
175 tri.start_dts = run_start_dts; 186 tri.start_dts = run_start_dts;
176 tri.sample_start_offset = trun.data_offset; 187 tri.sample_start_offset = trun.data_offset;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 tri.aux_info_total_size += tri.aux_info_sizes[k]; 230 tri.aux_info_total_size += tri.aux_info_sizes[k];
220 } 231 }
221 } 232 }
222 } else { 233 } else {
223 tri.aux_info_start_offset = -1; 234 tri.aux_info_start_offset = -1;
224 tri.aux_info_total_size = 0; 235 tri.aux_info_total_size = 0;
225 } 236 }
226 237
227 tri.samples.resize(trun.sample_count); 238 tri.samples.resize(trun.sample_count);
228 for (size_t k = 0; k < trun.sample_count; k++) { 239 for (size_t k = 0; k < trun.sample_count; k++) {
229 PopulateSampleInfo(*trex, traf.header, trun, k, &tri.samples[k]); 240 PopulateSampleInfo(*trex, traf.header, trun, edit_list_offset,
241 k, &tri.samples[k]);
230 run_start_dts += tri.samples[k].duration; 242 run_start_dts += tri.samples[k].duration;
231 } 243 }
232 runs_.push_back(tri); 244 runs_.push_back(tri);
233 sample_count_sum += trun.sample_count; 245 sample_count_sum += trun.sample_count;
234 } 246 }
235 } 247 }
236 248
237 std::sort(runs_.begin(), runs_.end(), CompareMinTrackRunDataOffset()); 249 std::sort(runs_.begin(), runs_.end(), CompareMinTrackRunDataOffset());
238 run_itr_ = runs_.begin(); 250 run_itr_ = runs_.begin();
239 ResetRun(); 251 ResetRun();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 std::string(reinterpret_cast<const char*>(&kid[0]), kid.size()), 431 std::string(reinterpret_cast<const char*>(&kid[0]), kid.size()),
420 std::string(reinterpret_cast<const char*>(cenc_info.iv), 432 std::string(reinterpret_cast<const char*>(cenc_info.iv),
421 arraysize(cenc_info.iv)), 433 arraysize(cenc_info.iv)),
422 std::string(), // No checksum in MP4 using CENC. 434 std::string(), // No checksum in MP4 using CENC.
423 0, // No offset to start of media data in MP4 using CENC. 435 0, // No offset to start of media data in MP4 using CENC.
424 cenc_info.subsamples)); 436 cenc_info.subsamples));
425 } 437 }
426 438
427 } // namespace mp4 439 } // namespace mp4
428 } // namespace media 440 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698