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

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: Address review comments. Created 8 years, 3 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 (entry.format == FOURCC_ENCA && 191 (entry.format == FOURCC_ENCA &&
192 entry.sinf.format.format == FOURCC_MP4A))) { 192 entry.sinf.format.format == FOURCC_MP4A))) {
193 LOG(ERROR) << "Unsupported audio format."; 193 LOG(ERROR) << "Unsupported audio format.";
194 return false; 194 return false;
195 } 195 }
196 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3. 196 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3.
197 if (entry.esds.object_type != kISO_14496_3) { 197 if (entry.esds.object_type != kISO_14496_3) {
198 LOG(ERROR) << "Unsupported audio object type."; 198 LOG(ERROR) << "Unsupported audio object type.";
199 return false; 199 return false;
200 } 200 }
201 RCHECK(EmitKeyNeeded(entry.sinf.info.track_encryption));
202 201
203 audio_config.Initialize(kCodecAAC, entry.samplesize, 202 audio_config.Initialize(kCodecAAC, entry.samplesize,
204 aac.channel_layout(), 203 aac.channel_layout(),
205 aac.GetOutputSamplesPerSecond(has_sbr_), 204 aac.GetOutputSamplesPerSecond(has_sbr_),
206 NULL, 0, false); 205 NULL, 0, false);
207 has_audio_ = true; 206 has_audio_ = true;
208 audio_track_id_ = track->header.track_id; 207 audio_track_id_ = track->header.track_id;
209 } 208 }
210 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { 209 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) {
211 RCHECK(!samp_descr.video_entries.empty()); 210 RCHECK(!samp_descr.video_entries.empty());
212 if (desc_idx >= samp_descr.video_entries.size()) 211 if (desc_idx >= samp_descr.video_entries.size())
213 desc_idx = 0; 212 desc_idx = 0;
214 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; 213 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx];
215 214
216 if (!(entry.format == FOURCC_AVC1 || 215 if (!(entry.format == FOURCC_AVC1 ||
217 (entry.format == FOURCC_ENCV && 216 (entry.format == FOURCC_ENCV &&
218 entry.sinf.format.format == FOURCC_AVC1))) { 217 entry.sinf.format.format == FOURCC_AVC1))) {
219 LOG(ERROR) << "Unsupported video format."; 218 LOG(ERROR) << "Unsupported video format.";
220 return false; 219 return false;
221 } 220 }
222 RCHECK(EmitKeyNeeded(entry.sinf.info.track_encryption));
223 221
224 // TODO(strobe): Recover correct crop box 222 // TODO(strobe): Recover correct crop box
225 gfx::Size coded_size(entry.width, entry.height); 223 gfx::Size coded_size(entry.width, entry.height);
226 gfx::Rect visible_rect(coded_size); 224 gfx::Rect visible_rect(coded_size);
227 gfx::Size natural_size = GetNaturalSize(visible_rect.size(), 225 gfx::Size natural_size = GetNaturalSize(visible_rect.size(),
228 entry.pixel_aspect.h_spacing, 226 entry.pixel_aspect.h_spacing,
229 entry.pixel_aspect.v_spacing); 227 entry.pixel_aspect.v_spacing);
230 bool is_encrypted = entry.sinf.info.track_encryption.is_encrypted; 228 bool is_encrypted = entry.sinf.info.track_encryption.is_encrypted;
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,
(...skipping 13 matching lines...) Expand all
246 moov_->header.timescale); 244 moov_->header.timescale);
247 } else if (moov_->header.duration > 0) { 245 } else if (moov_->header.duration > 0) {
248 duration = TimeDeltaFromRational(moov_->header.duration, 246 duration = TimeDeltaFromRational(moov_->header.duration,
249 moov_->header.timescale); 247 moov_->header.timescale);
250 } else { 248 } else {
251 duration = kInfiniteDuration(); 249 duration = kInfiniteDuration();
252 } 250 }
253 251
254 if (!init_cb_.is_null()) 252 if (!init_cb_.is_null())
255 base::ResetAndReturn(&init_cb_).Run(true, duration); 253 base::ResetAndReturn(&init_cb_).Run(true, duration);
254
255 RCHECK(EmitNeedKeyIfNecessary(moov_->pssh));
256 return true; 256 return true;
257 } 257 }
258 258
259 bool MP4StreamParser::ParseMoof(BoxReader* reader) { 259 bool MP4StreamParser::ParseMoof(BoxReader* reader) {
260 RCHECK(moov_.get()); // Must already have initialization segment 260 RCHECK(moov_.get()); // Must already have initialization segment
261 MovieFragment moof; 261 MovieFragment moof;
262 RCHECK(moof.Parse(reader)); 262 RCHECK(moof.Parse(reader));
263 RCHECK(runs_->Init(moof)); 263 RCHECK(runs_->Init(moof));
264 RCHECK(EmitNeedKeyIfNecessary(moov_->pssh));
264 new_segment_cb_.Run(runs_->GetMinDecodeTimestamp()); 265 new_segment_cb_.Run(runs_->GetMinDecodeTimestamp());
265 ChangeState(kEmittingSamples); 266 ChangeState(kEmittingSamples);
266 return true; 267 return true;
267 } 268 }
268 269
269 bool MP4StreamParser::EmitKeyNeeded(const TrackEncryption& track_encryption) { 270 bool MP4StreamParser::EmitNeedKeyIfNecessary(
270 // TODO(strobe): Send the correct value for initData. The format of initData 271 const std::vector<ProtectionSystemSpecificHeader>& headers) {
271 // has not yet been defined; see 272 // TODO(strobe): ensure that the value of init_data (all PSSH headers
272 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17673. 273 // concatenated in arbitrary order) matches the EME spec.
273 if (!track_encryption.is_encrypted) return true; 274 // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=17673.
274 scoped_array<uint8> kid(new uint8[track_encryption.default_kid.size()]); 275 if (headers.empty())
275 memcpy(kid.get(), &track_encryption.default_kid[0], 276 return true;
276 track_encryption.default_kid.size()); 277
277 return need_key_cb_.Run(kid.Pass(), track_encryption.default_kid.size()); 278 size_t total_size = 0;
279 for (size_t i = 0; i < headers.size(); i++)
280 total_size += headers[i].raw_box.size();
281
282 scoped_array<uint8> init_data(new uint8[total_size]);
283 size_t pos = 0;
284 for (size_t i = 0; i < headers.size(); i++) {
285 memcpy(&init_data.get()[pos], &headers[i].raw_box[0],
286 headers[i].raw_box.size());
287 pos += headers[i].raw_box.size();
288 }
289 return need_key_cb_.Run(init_data.Pass(), total_size);
278 } 290 }
279 291
280 bool MP4StreamParser::PrepareAVCBuffer( 292 bool MP4StreamParser::PrepareAVCBuffer(
281 const AVCDecoderConfigurationRecord& avc_config, 293 const AVCDecoderConfigurationRecord& avc_config,
282 std::vector<uint8>* frame_buf, 294 std::vector<uint8>* frame_buf,
283 std::vector<SubsampleEntry>* subsamples) const { 295 std::vector<SubsampleEntry>* subsamples) const {
284 // Convert the AVC NALU length fields to Annex B headers, as expected by 296 // Convert the AVC NALU length fields to Annex B headers, as expected by
285 // decoding libraries. Since this may enlarge the size of the buffer, we also 297 // decoding libraries. Since this may enlarge the size of the buffer, we also
286 // update the clear byte count for each subsample if encryption is used to 298 // update the clear byte count for each subsample if encryption is used to
287 // account for the difference in size between the length prefix and Annex B 299 // account for the difference in size between the length prefix and Annex B
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 return !err; 495 return !err;
484 } 496 }
485 497
486 void MP4StreamParser::ChangeState(State new_state) { 498 void MP4StreamParser::ChangeState(State new_state) {
487 DVLOG(2) << "Changing state: " << new_state; 499 DVLOG(2) << "Changing state: " << new_state;
488 state_ = new_state; 500 state_ = new_state;
489 } 501 }
490 502
491 } // namespace mp4 503 } // namespace mp4
492 } // namespace media 504 } // 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