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

Side by Side Diff: media/formats/mp2t/es_parser_h264.cc

Issue 1490613005: media config: expand is_encrypted to a struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mojo changes; Message->base::Pickle Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/formats/mp2t/es_parser_h264.h" 5 #include "media/formats/mp2t/es_parser_h264.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_conversions.h" 8 #include "base/numerics/safe_conversions.h"
9 #include "media/base/encryption_scheme.h"
9 #include "media/base/stream_parser_buffer.h" 10 #include "media/base/stream_parser_buffer.h"
10 #include "media/base/timestamp_constants.h" 11 #include "media/base/timestamp_constants.h"
11 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
12 #include "media/filters/h264_parser.h" 13 #include "media/filters/h264_parser.h"
13 #include "media/formats/common/offset_byte_queue.h" 14 #include "media/formats/common/offset_byte_queue.h"
14 #include "media/formats/mp2t/mp2t_common.h" 15 #include "media/formats/mp2t/mp2t_common.h"
15 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 18
18 namespace media { 19 namespace media {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // does not necessarily start with an SPS/PPS/IDR. 256 // does not necessarily start with an SPS/PPS/IDR.
256 // In this case, the initial frames are conveyed to the upper layer with 257 // In this case, the initial frames are conveyed to the upper layer with
257 // an invalid VideoDecoderConfig and it's up to the upper layer 258 // an invalid VideoDecoderConfig and it's up to the upper layer
258 // to process this kind of frame accordingly. 259 // to process this kind of frame accordingly.
259 if (last_video_decoder_config_.IsValidConfig()) 260 if (last_video_decoder_config_.IsValidConfig())
260 return false; 261 return false;
261 } else { 262 } else {
262 const H264SPS* sps = h264_parser_->GetSPS(pps->seq_parameter_set_id); 263 const H264SPS* sps = h264_parser_->GetSPS(pps->seq_parameter_set_id);
263 if (!sps) 264 if (!sps)
264 return false; 265 return false;
265 RCHECK(UpdateVideoDecoderConfig(sps)); 266 EncryptionScheme scheme(false);
267 RCHECK(UpdateVideoDecoderConfig(sps, scheme));
266 } 268 }
267 269
268 // Emit a frame. 270 // Emit a frame.
269 DVLOG(LOG_LEVEL_ES) << "Emit frame: stream_pos=" << current_access_unit_pos_ 271 DVLOG(LOG_LEVEL_ES) << "Emit frame: stream_pos=" << current_access_unit_pos_
270 << " size=" << access_unit_size; 272 << " size=" << access_unit_size;
271 int es_size; 273 int es_size;
272 const uint8_t* es; 274 const uint8_t* es;
273 es_queue_->PeekAt(current_access_unit_pos_, &es, &es_size); 275 es_queue_->PeekAt(current_access_unit_pos_, &es, &es_size);
274 CHECK_GE(es_size, access_unit_size); 276 CHECK_GE(es_size, access_unit_size);
275 277
276 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId 278 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId
277 // type and allow multiple video tracks. See https://crbug.com/341581. 279 // type and allow multiple video tracks. See https://crbug.com/341581.
278 scoped_refptr<StreamParserBuffer> stream_parser_buffer = 280 scoped_refptr<StreamParserBuffer> stream_parser_buffer =
279 StreamParserBuffer::CopyFrom( 281 StreamParserBuffer::CopyFrom(
280 es, 282 es,
281 access_unit_size, 283 access_unit_size,
282 is_key_frame, 284 is_key_frame,
283 DemuxerStream::VIDEO, 285 DemuxerStream::VIDEO,
284 0); 286 0);
285 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); 287 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts);
286 stream_parser_buffer->set_timestamp(current_timing_desc.pts); 288 stream_parser_buffer->set_timestamp(current_timing_desc.pts);
287 return es_adapter_.OnNewBuffer(stream_parser_buffer); 289 return es_adapter_.OnNewBuffer(stream_parser_buffer);
288 } 290 }
289 291
290 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) { 292 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps,
293 const EncryptionScheme& scheme) {
291 // Set the SAR to 1 when not specified in the H264 stream. 294 // Set the SAR to 1 when not specified in the H264 stream.
292 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; 295 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width;
293 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; 296 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height;
294 297
295 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. 298 // TODO(damienv): a MAP unit can be either 16 or 32 pixels.
296 // although it's 16 pixels for progressive non MBAFF frames. 299 // although it's 16 pixels for progressive non MBAFF frames.
297 gfx::Size coded_size((sps->pic_width_in_mbs_minus1 + 1) * 16, 300 gfx::Size coded_size((sps->pic_width_in_mbs_minus1 + 1) * 16,
298 (sps->pic_height_in_map_units_minus1 + 1) * 16); 301 (sps->pic_height_in_map_units_minus1 + 1) * 16);
299 gfx::Rect visible_rect( 302 gfx::Rect visible_rect(
300 sps->frame_crop_left_offset, 303 sps->frame_crop_left_offset,
301 sps->frame_crop_top_offset, 304 sps->frame_crop_top_offset,
302 (coded_size.width() - sps->frame_crop_right_offset) - 305 (coded_size.width() - sps->frame_crop_right_offset) -
303 sps->frame_crop_left_offset, 306 sps->frame_crop_left_offset,
304 (coded_size.height() - sps->frame_crop_bottom_offset) - 307 (coded_size.height() - sps->frame_crop_bottom_offset) -
305 sps->frame_crop_top_offset); 308 sps->frame_crop_top_offset);
306 if (visible_rect.width() <= 0 || visible_rect.height() <= 0) 309 if (visible_rect.width() <= 0 || visible_rect.height() <= 0)
307 return false; 310 return false;
308 gfx::Size natural_size( 311 gfx::Size natural_size(
309 (visible_rect.width() * sar_width) / sar_height, 312 (visible_rect.width() * sar_width) / sar_height,
310 visible_rect.height()); 313 visible_rect.height());
311 if (natural_size.width() == 0) 314 if (natural_size.width() == 0)
312 return false; 315 return false;
313 316
314 VideoDecoderConfig video_decoder_config( 317 VideoDecoderConfig video_decoder_config(
315 kCodecH264, ProfileIDCToVideoCodecProfile(sps->profile_idc), 318 kCodecH264, ProfileIDCToVideoCodecProfile(sps->profile_idc),
316 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect, 319 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect,
317 natural_size, std::vector<uint8_t>(), false); 320 natural_size, std::vector<uint8_t>(), scheme);
318 321
319 if (!video_decoder_config.Matches(last_video_decoder_config_)) { 322 if (!video_decoder_config.Matches(last_video_decoder_config_)) {
320 DVLOG(1) << "Profile IDC: " << sps->profile_idc; 323 DVLOG(1) << "Profile IDC: " << sps->profile_idc;
321 DVLOG(1) << "Level IDC: " << sps->level_idc; 324 DVLOG(1) << "Level IDC: " << sps->level_idc;
322 DVLOG(1) << "Pic width: " << coded_size.width(); 325 DVLOG(1) << "Pic width: " << coded_size.width();
323 DVLOG(1) << "Pic height: " << coded_size.height(); 326 DVLOG(1) << "Pic height: " << coded_size.height();
324 DVLOG(1) << "log2_max_frame_num_minus4: " 327 DVLOG(1) << "log2_max_frame_num_minus4: "
325 << sps->log2_max_frame_num_minus4; 328 << sps->log2_max_frame_num_minus4;
326 DVLOG(1) << "SAR: width=" << sps->sar_width 329 DVLOG(1) << "SAR: width=" << sps->sar_width
327 << " height=" << sps->sar_height; 330 << " height=" << sps->sar_height;
328 last_video_decoder_config_ = video_decoder_config; 331 last_video_decoder_config_ = video_decoder_config;
329 es_adapter_.OnConfigChanged(video_decoder_config); 332 es_adapter_.OnConfigChanged(video_decoder_config);
330 } 333 }
331 334
332 return true; 335 return true;
333 } 336 }
334 337
335 } // namespace mp2t 338 } // namespace mp2t
336 } // namespace media 339 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698