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/mp4/avc.h" | 5 #include "media/formats/mp4/avc.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/decrypt_config.h" | 10 #include "media/base/decrypt_config.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 NOTREACHED() << "AdvanceToNextNALU() returned kUnsupportedStream!"; | 300 NOTREACHED() << "AdvanceToNextNALU() returned kUnsupportedStream!"; |
301 return false; | 301 return false; |
302 | 302 |
303 case H264Parser::kEOStream: | 303 case H264Parser::kEOStream: |
304 done = true; | 304 done = true; |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 return order_state >= kAfterFirstVCL; | 308 return order_state >= kAfterFirstVCL; |
309 } | 309 } |
| 310 |
| 311 AVCBitstreamConverter::AVCBitstreamConverter( |
| 312 scoped_ptr<AVCDecoderConfigurationRecord> avc_config) |
| 313 : avc_config_(avc_config.Pass()) { |
| 314 DCHECK(avc_config_); |
| 315 } |
| 316 |
| 317 AVCBitstreamConverter::~AVCBitstreamConverter() { |
| 318 } |
| 319 |
| 320 bool AVCBitstreamConverter::ConvertFrame( |
| 321 std::vector<uint8>* frame_buf, |
| 322 bool is_keyframe, |
| 323 std::vector<SubsampleEntry>* subsamples) const { |
| 324 // Convert the AVC NALU length fields to Annex B headers, as expected by |
| 325 // decoding libraries. Since this may enlarge the size of the buffer, we also |
| 326 // update the clear byte count for each subsample if encryption is used to |
| 327 // account for the difference in size between the length prefix and Annex B |
| 328 // start code. |
| 329 RCHECK(AVC::ConvertFrameToAnnexB(avc_config_->length_size, frame_buf, |
| 330 subsamples)); |
| 331 |
| 332 if (is_keyframe) { |
| 333 // If this is a keyframe, we (re-)inject SPS and PPS headers at the start of |
| 334 // a frame. If subsample info is present, we also update the clear byte |
| 335 // count for that first subsample. |
| 336 RCHECK(AVC::InsertParamSetsAnnexB(*avc_config_, frame_buf, subsamples)); |
| 337 } |
| 338 |
| 339 DCHECK(AVC::IsValidAnnexB(*frame_buf, *subsamples)); |
| 340 return true; |
| 341 } |
| 342 |
310 } // namespace mp4 | 343 } // namespace mp4 |
311 } // namespace media | 344 } // namespace media |
OLD | NEW |