OLD | NEW |
---|---|
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 // does not necessarily start with an SPS/PPS/IDR. | 223 // does not necessarily start with an SPS/PPS/IDR. |
223 // In this case, the initial frames are conveyed to the upper layer with | 224 // In this case, the initial frames are conveyed to the upper layer with |
224 // an invalid VideoDecoderConfig and it's up to the upper layer | 225 // an invalid VideoDecoderConfig and it's up to the upper layer |
225 // to process this kind of frame accordingly. | 226 // to process this kind of frame accordingly. |
226 if (last_video_decoder_config_.IsValidConfig()) | 227 if (last_video_decoder_config_.IsValidConfig()) |
227 return false; | 228 return false; |
228 } else { | 229 } else { |
229 const H264SPS* sps = h264_parser_->GetSPS(pps->seq_parameter_set_id); | 230 const H264SPS* sps = h264_parser_->GetSPS(pps->seq_parameter_set_id); |
230 if (!sps) | 231 if (!sps) |
231 return false; | 232 return false; |
232 RCHECK(UpdateVideoDecoderConfig(sps)); | 233 EncryptionScheme scheme(false); |
234 RCHECK(UpdateVideoDecoderConfig(sps, scheme)); | |
ddorwin
2015/12/10 18:36:01
ditto
dougsteed
2015/12/14 21:19:02
The second CL shows why it's like this.
| |
233 } | 235 } |
234 | 236 |
235 // Emit a frame. | 237 // Emit a frame. |
236 DVLOG(LOG_LEVEL_ES) << "Emit frame: stream_pos=" << current_access_unit_pos_ | 238 DVLOG(LOG_LEVEL_ES) << "Emit frame: stream_pos=" << current_access_unit_pos_ |
237 << " size=" << access_unit_size; | 239 << " size=" << access_unit_size; |
238 int es_size; | 240 int es_size; |
239 const uint8* es; | 241 const uint8* es; |
240 es_queue_->PeekAt(current_access_unit_pos_, &es, &es_size); | 242 es_queue_->PeekAt(current_access_unit_pos_, &es, &es_size); |
241 CHECK_GE(es_size, access_unit_size); | 243 CHECK_GE(es_size, access_unit_size); |
242 | 244 |
243 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId | 245 // TODO(wolenetz/acolwell): Validate and use a common cross-parser TrackId |
244 // type and allow multiple video tracks. See https://crbug.com/341581. | 246 // type and allow multiple video tracks. See https://crbug.com/341581. |
245 scoped_refptr<StreamParserBuffer> stream_parser_buffer = | 247 scoped_refptr<StreamParserBuffer> stream_parser_buffer = |
246 StreamParserBuffer::CopyFrom( | 248 StreamParserBuffer::CopyFrom( |
247 es, | 249 es, |
248 access_unit_size, | 250 access_unit_size, |
249 is_key_frame, | 251 is_key_frame, |
250 DemuxerStream::VIDEO, | 252 DemuxerStream::VIDEO, |
251 0); | 253 0); |
252 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); | 254 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); |
253 stream_parser_buffer->set_timestamp(current_timing_desc.pts); | 255 stream_parser_buffer->set_timestamp(current_timing_desc.pts); |
256 #ifdef ENABLE_HLS_SAMPLE_AES | |
yucliu1
2015/12/10 00:12:19
Remove this block in this CL?
ddorwin
2015/12/10 18:36:01
Agreed.
dougsteed
2015/12/14 21:19:02
Yes, this was an oversight when I split my work in
| |
257 if (use_hls_sample_aes_) { | |
258 // TODO(dougsteed): temporary place-holders. | |
259 const std::string key_id = "XXXXXXXXXXXXXXXX"; | |
260 const std::string iv = "IVIVIVIVIVIVIVIV"; | |
261 scoped_ptr<DecryptConfig> decrypt_config( | |
262 new DecryptConfig(key_id, iv, subsamples)); | |
263 stream_parser_buffer->set_decrypt_config(decrypt_config.Pass()); | |
264 } | |
265 #endif | |
254 return es_adapter_.OnNewBuffer(stream_parser_buffer); | 266 return es_adapter_.OnNewBuffer(stream_parser_buffer); |
255 } | 267 } |
256 | 268 |
257 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) { | 269 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps, |
270 const EncryptionScheme& scheme) { | |
258 // Set the SAR to 1 when not specified in the H264 stream. | 271 // Set the SAR to 1 when not specified in the H264 stream. |
259 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; | 272 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; |
260 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; | 273 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; |
261 | 274 |
262 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. | 275 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. |
263 // although it's 16 pixels for progressive non MBAFF frames. | 276 // although it's 16 pixels for progressive non MBAFF frames. |
264 gfx::Size coded_size((sps->pic_width_in_mbs_minus1 + 1) * 16, | 277 gfx::Size coded_size((sps->pic_width_in_mbs_minus1 + 1) * 16, |
265 (sps->pic_height_in_map_units_minus1 + 1) * 16); | 278 (sps->pic_height_in_map_units_minus1 + 1) * 16); |
266 gfx::Rect visible_rect( | 279 gfx::Rect visible_rect( |
267 sps->frame_crop_left_offset, | 280 sps->frame_crop_left_offset, |
268 sps->frame_crop_top_offset, | 281 sps->frame_crop_top_offset, |
269 (coded_size.width() - sps->frame_crop_right_offset) - | 282 (coded_size.width() - sps->frame_crop_right_offset) - |
270 sps->frame_crop_left_offset, | 283 sps->frame_crop_left_offset, |
271 (coded_size.height() - sps->frame_crop_bottom_offset) - | 284 (coded_size.height() - sps->frame_crop_bottom_offset) - |
272 sps->frame_crop_top_offset); | 285 sps->frame_crop_top_offset); |
273 if (visible_rect.width() <= 0 || visible_rect.height() <= 0) | 286 if (visible_rect.width() <= 0 || visible_rect.height() <= 0) |
274 return false; | 287 return false; |
275 gfx::Size natural_size( | 288 gfx::Size natural_size( |
276 (visible_rect.width() * sar_width) / sar_height, | 289 (visible_rect.width() * sar_width) / sar_height, |
277 visible_rect.height()); | 290 visible_rect.height()); |
278 if (natural_size.width() == 0) | 291 if (natural_size.width() == 0) |
279 return false; | 292 return false; |
280 | 293 |
281 VideoDecoderConfig video_decoder_config( | 294 VideoDecoderConfig video_decoder_config( |
282 kCodecH264, VIDEO_CODEC_PROFILE_UNKNOWN, PIXEL_FORMAT_YV12, | 295 kCodecH264, VIDEO_CODEC_PROFILE_UNKNOWN, PIXEL_FORMAT_YV12, |
283 COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size, | 296 COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size, |
284 std::vector<uint8_t>(), false); | 297 std::vector<uint8_t>(), scheme); |
285 | 298 |
286 if (!video_decoder_config.Matches(last_video_decoder_config_)) { | 299 if (!video_decoder_config.Matches(last_video_decoder_config_)) { |
287 DVLOG(1) << "Profile IDC: " << sps->profile_idc; | 300 DVLOG(1) << "Profile IDC: " << sps->profile_idc; |
288 DVLOG(1) << "Level IDC: " << sps->level_idc; | 301 DVLOG(1) << "Level IDC: " << sps->level_idc; |
289 DVLOG(1) << "Pic width: " << coded_size.width(); | 302 DVLOG(1) << "Pic width: " << coded_size.width(); |
290 DVLOG(1) << "Pic height: " << coded_size.height(); | 303 DVLOG(1) << "Pic height: " << coded_size.height(); |
291 DVLOG(1) << "log2_max_frame_num_minus4: " | 304 DVLOG(1) << "log2_max_frame_num_minus4: " |
292 << sps->log2_max_frame_num_minus4; | 305 << sps->log2_max_frame_num_minus4; |
293 DVLOG(1) << "SAR: width=" << sps->sar_width | 306 DVLOG(1) << "SAR: width=" << sps->sar_width |
294 << " height=" << sps->sar_height; | 307 << " height=" << sps->sar_height; |
295 last_video_decoder_config_ = video_decoder_config; | 308 last_video_decoder_config_ = video_decoder_config; |
296 es_adapter_.OnConfigChanged(video_decoder_config); | 309 es_adapter_.OnConfigChanged(video_decoder_config); |
297 } | 310 } |
298 | 311 |
299 return true; | 312 return true; |
300 } | 313 } |
301 | 314 |
302 } // namespace mp2t | 315 } // namespace mp2t |
303 } // namespace media | 316 } // namespace media |
OLD | NEW |