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

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: more ddorwin comments 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 RCHECK(UpdateVideoDecoderConfig(sps, EncryptionScheme::Unencrypted()));
266 } 267 }
267 268
268 // Emit a frame. 269 // Emit a frame.
269 DVLOG(LOG_LEVEL_ES) << "Emit frame: stream_pos=" << current_access_unit_pos_ 270 DVLOG(LOG_LEVEL_ES) << "Emit frame: stream_pos=" << current_access_unit_pos_
270 << " size=" << access_unit_size; 271 << " size=" << access_unit_size;
271 int es_size; 272 int es_size;
272 const uint8_t* es; 273 const uint8_t* es;
273 es_queue_->PeekAt(current_access_unit_pos_, &es, &es_size); 274 es_queue_->PeekAt(current_access_unit_pos_, &es, &es_size);
274 CHECK_GE(es_size, access_unit_size); 275 CHECK_GE(es_size, access_unit_size);
275 276
276 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId 277 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId
277 // type and allow multiple video tracks. See https://crbug.com/341581. 278 // type and allow multiple video tracks. See https://crbug.com/341581.
278 scoped_refptr<StreamParserBuffer> stream_parser_buffer = 279 scoped_refptr<StreamParserBuffer> stream_parser_buffer =
279 StreamParserBuffer::CopyFrom( 280 StreamParserBuffer::CopyFrom(
280 es, 281 es,
281 access_unit_size, 282 access_unit_size,
282 is_key_frame, 283 is_key_frame,
283 DemuxerStream::VIDEO, 284 DemuxerStream::VIDEO,
284 0); 285 0);
285 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); 286 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts);
286 stream_parser_buffer->set_timestamp(current_timing_desc.pts); 287 stream_parser_buffer->set_timestamp(current_timing_desc.pts);
287 return es_adapter_.OnNewBuffer(stream_parser_buffer); 288 return es_adapter_.OnNewBuffer(stream_parser_buffer);
288 } 289 }
289 290
290 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) { 291 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps,
292 const EncryptionScheme& scheme) {
291 // Set the SAR to 1 when not specified in the H264 stream. 293 // Set the SAR to 1 when not specified in the H264 stream.
292 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; 294 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width;
293 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; 295 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height;
294 296
295 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. 297 // TODO(damienv): a MAP unit can be either 16 or 32 pixels.
296 // although it's 16 pixels for progressive non MBAFF frames. 298 // although it's 16 pixels for progressive non MBAFF frames.
297 gfx::Size coded_size((sps->pic_width_in_mbs_minus1 + 1) * 16, 299 gfx::Size coded_size((sps->pic_width_in_mbs_minus1 + 1) * 16,
298 (sps->pic_height_in_map_units_minus1 + 1) * 16); 300 (sps->pic_height_in_map_units_minus1 + 1) * 16);
299 gfx::Rect visible_rect( 301 gfx::Rect visible_rect(
300 sps->frame_crop_left_offset, 302 sps->frame_crop_left_offset,
301 sps->frame_crop_top_offset, 303 sps->frame_crop_top_offset,
302 (coded_size.width() - sps->frame_crop_right_offset) - 304 (coded_size.width() - sps->frame_crop_right_offset) -
303 sps->frame_crop_left_offset, 305 sps->frame_crop_left_offset,
304 (coded_size.height() - sps->frame_crop_bottom_offset) - 306 (coded_size.height() - sps->frame_crop_bottom_offset) -
305 sps->frame_crop_top_offset); 307 sps->frame_crop_top_offset);
306 if (visible_rect.width() <= 0 || visible_rect.height() <= 0) 308 if (visible_rect.width() <= 0 || visible_rect.height() <= 0)
307 return false; 309 return false;
308 gfx::Size natural_size( 310 gfx::Size natural_size(
309 (visible_rect.width() * sar_width) / sar_height, 311 (visible_rect.width() * sar_width) / sar_height,
310 visible_rect.height()); 312 visible_rect.height());
311 if (natural_size.width() == 0) 313 if (natural_size.width() == 0)
312 return false; 314 return false;
313 315
314 VideoDecoderConfig video_decoder_config( 316 VideoDecoderConfig video_decoder_config(
315 kCodecH264, ProfileIDCToVideoCodecProfile(sps->profile_idc), 317 kCodecH264, ProfileIDCToVideoCodecProfile(sps->profile_idc),
316 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect, 318 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect,
317 natural_size, std::vector<uint8_t>(), false); 319 natural_size, std::vector<uint8_t>(), scheme);
xhwang 2016/03/03 22:33:01 We can use EmptyExtraData() here for std::vector<u
dougsteed 2016/03/04 19:07:30 Done.
318 320
319 if (!video_decoder_config.Matches(last_video_decoder_config_)) { 321 if (!video_decoder_config.Matches(last_video_decoder_config_)) {
320 DVLOG(1) << "Profile IDC: " << sps->profile_idc; 322 DVLOG(1) << "Profile IDC: " << sps->profile_idc;
321 DVLOG(1) << "Level IDC: " << sps->level_idc; 323 DVLOG(1) << "Level IDC: " << sps->level_idc;
322 DVLOG(1) << "Pic width: " << coded_size.width(); 324 DVLOG(1) << "Pic width: " << coded_size.width();
323 DVLOG(1) << "Pic height: " << coded_size.height(); 325 DVLOG(1) << "Pic height: " << coded_size.height();
324 DVLOG(1) << "log2_max_frame_num_minus4: " 326 DVLOG(1) << "log2_max_frame_num_minus4: "
325 << sps->log2_max_frame_num_minus4; 327 << sps->log2_max_frame_num_minus4;
326 DVLOG(1) << "SAR: width=" << sps->sar_width 328 DVLOG(1) << "SAR: width=" << sps->sar_width
327 << " height=" << sps->sar_height; 329 << " height=" << sps->sar_height;
328 last_video_decoder_config_ = video_decoder_config; 330 last_video_decoder_config_ = video_decoder_config;
329 es_adapter_.OnConfigChanged(video_decoder_config); 331 es_adapter_.OnConfigChanged(video_decoder_config);
330 } 332 }
331 333
332 return true; 334 return true;
333 } 335 }
334 336
335 } // namespace mp2t 337 } // namespace mp2t
336 } // namespace media 338 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698