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

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

Issue 10837116: Update EME MediaKeyNeededEvent.initData for ISO BMFF to match current spec. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« media/mp4/box_reader.h ('K') | « media/mp4/mp4_stream_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/mp4_stream_parser.h" 5 #include "media/mp4/mp4_stream_parser.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 (entry.format == FOURCC_ENCA && 192 (entry.format == FOURCC_ENCA &&
193 entry.sinf.format.format == FOURCC_MP4A))) { 193 entry.sinf.format.format == FOURCC_MP4A))) {
194 LOG(ERROR) << "Unsupported audio format."; 194 LOG(ERROR) << "Unsupported audio format.";
195 return false; 195 return false;
196 } 196 }
197 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3. 197 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3.
198 if (entry.esds.object_type != kISO_14496_3) { 198 if (entry.esds.object_type != kISO_14496_3) {
199 LOG(ERROR) << "Unsupported audio object type."; 199 LOG(ERROR) << "Unsupported audio object type.";
200 return false; 200 return false;
201 } 201 }
202 RCHECK(EmitKeyNeeded(entry.sinf.info.track_encryption));
203 202
204 audio_config.Initialize(kCodecAAC, entry.samplesize, 203 audio_config.Initialize(kCodecAAC, entry.samplesize,
205 aac.channel_layout(), 204 aac.channel_layout(),
206 aac.GetOutputSamplesPerSecond(has_sbr_), 205 aac.GetOutputSamplesPerSecond(has_sbr_),
207 NULL, 0, false); 206 NULL, 0, false);
208 has_audio_ = true; 207 has_audio_ = true;
209 audio_track_id_ = track->header.track_id; 208 audio_track_id_ = track->header.track_id;
210 } 209 }
211 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { 210 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) {
212 RCHECK(!samp_descr.video_entries.empty()); 211 RCHECK(!samp_descr.video_entries.empty());
213 if (desc_idx >= samp_descr.video_entries.size()) 212 if (desc_idx >= samp_descr.video_entries.size())
214 desc_idx = 0; 213 desc_idx = 0;
215 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; 214 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx];
216 215
217 if (!(entry.format == FOURCC_AVC1 || 216 if (!(entry.format == FOURCC_AVC1 ||
218 (entry.format == FOURCC_ENCV && 217 (entry.format == FOURCC_ENCV &&
219 entry.sinf.format.format == FOURCC_AVC1))) { 218 entry.sinf.format.format == FOURCC_AVC1))) {
220 LOG(ERROR) << "Unsupported video format."; 219 LOG(ERROR) << "Unsupported video format.";
221 return false; 220 return false;
222 } 221 }
223 RCHECK(EmitKeyNeeded(entry.sinf.info.track_encryption));
224 222
225 // TODO(strobe): Recover correct crop box 223 // TODO(strobe): Recover correct crop box
226 gfx::Size coded_size(entry.width, entry.height); 224 gfx::Size coded_size(entry.width, entry.height);
227 gfx::Rect visible_rect(coded_size); 225 gfx::Rect visible_rect(coded_size);
228 gfx::Size natural_size = GetNaturalSize(visible_rect.size(), 226 gfx::Size natural_size = GetNaturalSize(visible_rect.size(),
229 entry.pixel_aspect.h_spacing, 227 entry.pixel_aspect.h_spacing,
230 entry.pixel_aspect.v_spacing); 228 entry.pixel_aspect.v_spacing);
231 video_config.Initialize(kCodecH264, H264PROFILE_MAIN, VideoFrame::YV12, 229 video_config.Initialize(kCodecH264, H264PROFILE_MAIN, VideoFrame::YV12,
232 coded_size, visible_rect, natural_size, 230 coded_size, visible_rect, natural_size,
233 // No decoder-specific buffer needed for AVC; 231 // No decoder-specific buffer needed for AVC;
(...skipping 19 matching lines...) Expand all
253 moov_->header.timescale); 251 moov_->header.timescale);
254 } else if (moov_->header.duration > 0) { 252 } else if (moov_->header.duration > 0) {
255 duration = TimeDeltaFromRational(moov_->header.duration, 253 duration = TimeDeltaFromRational(moov_->header.duration,
256 moov_->header.timescale); 254 moov_->header.timescale);
257 } else { 255 } else {
258 duration = kInfiniteDuration(); 256 duration = kInfiniteDuration();
259 } 257 }
260 258
261 if (!init_cb_.is_null()) 259 if (!init_cb_.is_null())
262 base::ResetAndReturn(&init_cb_).Run(true, duration); 260 base::ResetAndReturn(&init_cb_).Run(true, duration);
261
262 RCHECK(EmitKeyNeeded(moov_->pssh));
263 return true; 263 return true;
264 } 264 }
265 265
266 bool MP4StreamParser::ParseMoof(BoxReader* reader) { 266 bool MP4StreamParser::ParseMoof(BoxReader* reader) {
267 RCHECK(moov_.get()); // Must already have initialization segment 267 RCHECK(moov_.get()); // Must already have initialization segment
268 MovieFragment moof; 268 MovieFragment moof;
269 RCHECK(moof.Parse(reader)); 269 RCHECK(moof.Parse(reader));
270 RCHECK(runs_->Init(moof)); 270 RCHECK(runs_->Init(moof));
271 RCHECK(EmitKeyNeeded(moov_->pssh));
271 new_segment_cb_.Run(runs_->GetMinDecodeTimestamp()); 272 new_segment_cb_.Run(runs_->GetMinDecodeTimestamp());
272 ChangeState(kEmittingSamples); 273 ChangeState(kEmittingSamples);
273 return true; 274 return true;
274 } 275 }
275 276
276 bool MP4StreamParser::EmitKeyNeeded(const TrackEncryption& track_encryption) { 277 bool MP4StreamParser::EmitKeyNeeded(
ddorwin 2012/09/21 04:04:28 The name implies one will always be emitted, as us
strobe_ 2012/09/21 18:29:46 Done.
277 // TODO(strobe): Send the correct value for initData. The format of initData 278 const std::vector<ProtectionSystemSpecificHeader>& headers) {
278 // has not yet been defined; see 279 // TODO(strobe): ensure that the value of init_data (all PSSH headers
279 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17673. 280 // concatenated in arbitrary order) matches the EME spec.
280 if (!track_encryption.is_encrypted) return true; 281 // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=17673.
281 scoped_array<uint8> kid(new uint8[track_encryption.default_kid.size()]); 282 if (headers.empty())
282 memcpy(kid.get(), &track_encryption.default_kid[0], 283 return true;
ddorwin 2012/09/21 04:04:28 You should probably define the return value as "se
strobe_ 2012/09/21 18:29:46 Done.
283 track_encryption.default_kid.size()); 284
284 return need_key_cb_.Run(kid.Pass(), track_encryption.default_kid.size()); 285 size_t total_size = 0;
286 for (size_t i = 0; i < headers.size(); i++)
287 total_size += headers[i].raw_box.size();
288
289 scoped_array<uint8> init_data(new uint8[total_size]);
290 size_t pos = 0;
291 for (size_t i = 0; i < headers.size(); i++) {
292 memcpy(&init_data.get()[pos], &headers[i].raw_box[0],
293 headers[i].raw_box.size());
294 pos += headers[i].raw_box.size();
295 }
296 return need_key_cb_.Run(init_data.Pass(), total_size);
ddorwin 2012/09/21 04:04:28 Future CL: We should probably change the name of t
strobe_ 2012/09/21 18:29:46 Agreed.
285 } 297 }
286 298
287 bool MP4StreamParser::PrepareAVCBuffer( 299 bool MP4StreamParser::PrepareAVCBuffer(
288 const AVCDecoderConfigurationRecord& avc_config, 300 const AVCDecoderConfigurationRecord& avc_config,
289 std::vector<uint8>* frame_buf, 301 std::vector<uint8>* frame_buf,
290 std::vector<SubsampleEntry>* subsamples) const { 302 std::vector<SubsampleEntry>* subsamples) const {
291 // Convert the AVC NALU length fields to Annex B headers, as expected by 303 // Convert the AVC NALU length fields to Annex B headers, as expected by
292 // decoding libraries. Since this may enlarge the size of the buffer, we also 304 // decoding libraries. Since this may enlarge the size of the buffer, we also
293 // update the clear byte count for each subsample if encryption is used to 305 // update the clear byte count for each subsample if encryption is used to
294 // account for the difference in size between the length prefix and Annex B 306 // account for the difference in size between the length prefix and Annex B
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 return !err; 483 return !err;
472 } 484 }
473 485
474 void MP4StreamParser::ChangeState(State new_state) { 486 void MP4StreamParser::ChangeState(State new_state) {
475 DVLOG(2) << "Changing state: " << new_state; 487 DVLOG(2) << "Changing state: " << new_state;
476 state_ = new_state; 488 state_ = new_state;
477 } 489 }
478 490
479 } // namespace mp4 491 } // namespace mp4
480 } // namespace media 492 } // namespace media
OLDNEW
« media/mp4/box_reader.h ('K') | « media/mp4/mp4_stream_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698