Chromium Code Reviews| Index: media/mp4/avc.cc |
| diff --git a/media/mp4/avc.cc b/media/mp4/avc.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d1dc2797d6b93e09d2eea645b740261b47fa55c3 |
| --- /dev/null |
| +++ b/media/mp4/avc.cc |
| @@ -0,0 +1,119 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/mp4/avc.h" |
| + |
| +#include "media/mp4/box_reader.h" |
| +#include <algorithm> |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: system header files come right after avc.h
strobe_
2012/06/07 16:33:54
Done.
|
| + |
| +namespace media { |
| +namespace mp4 { |
| + |
| +const static uint8 kAnnexBStartCode[] = {0, 0, 0, 1}; |
| +const static size_t kAnnexBStartCodeSize = 4; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: use int
strobe_
2012/06/07 22:04:22
Done.
|
| + |
| +AVCDecoderConfigurationRecord::AVCDecoderConfigurationRecord() {}; |
| +AVCDecoderConfigurationRecord::~AVCDecoderConfigurationRecord() {}; |
| + |
| +bool Parse(BoxReader* r, AVCDecoderConfigurationRecord* avcc) { |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: rename r -> reader & avcc to something more d
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Forward declared in avc.h like the other methods.
strobe_
2012/06/07 16:33:54
Done.
strobe_
2012/06/07 16:33:54
Doing this creates an include loop with box_defini
|
| + |
| + RCHECK(r->Read(&avcc->version) && avcc->version == 1 && |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Change read signatures to include size. ie Read1By
strobe_
2012/06/07 16:33:54
In progress.
|
| + r->Read(&avcc->profile_indication) && |
| + r->Read(&avcc->profile_compatibility) && |
| + r->Read(&avcc->avc_level)); |
| + |
| + uint8 length_size_minus_one; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: use int
|
| + RCHECK(r->Read(&length_size_minus_one) && |
| + (length_size_minus_one & 0xfc) == 0xfc); |
| + avcc->length_size = (length_size_minus_one & 0x3) + 1; |
| + |
| + uint8 num_sps; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: use int
|
| + RCHECK(r->Read(&num_sps) && (num_sps & 0xe0) == 0xe0); |
| + num_sps &= 0x1f; |
| + |
| + avcc->spses.resize(num_sps); |
| + for (int i = 0; i < num_sps; i++) { |
| + uint16 sps_length; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: use int
|
| + RCHECK(r->Read(&sps_length) && |
| + r->Read(&avcc->spses[i], sps_length)); |
| + } |
| + |
| + uint8 num_pps; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit:use int here and various places below.
|
| + RCHECK(r->Read(&num_pps)); |
| + |
| + avcc->ppses.resize(num_pps); |
| + for (int i = 0; i < num_pps; i++) { |
| + uint16 pps_length; |
| + RCHECK(r->Read(&pps_length) && |
| + r->Read(&avcc->ppses[i], pps_length)); |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool ConvertAVCCToAnnexBInPlaceForLengthSize4(size_t buf_size, uint8* buf) { |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Add static if only used in this file. Otherwise ad
strobe_
2012/06/07 22:04:22
Done.
|
| + const size_t kLengthSize = 4; |
| + size_t pos = 0; |
| + while (pos + kLengthSize < buf_size) { |
| + uint32 nal_size = (((uint32) buf[pos]) << 24) |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
use static_cast<>
strobe_
2012/06/07 16:33:54
Done. (Changed to match style used in BufferReader
|
| + + (((uint32) buf[pos+1]) << 16) |
| + + (((uint32) buf[pos+2]) << 8) |
| + + buf[pos+3]; |
| + memcpy(&buf[pos], kAnnexBStartCode, kAnnexBStartCodeSize); |
| + pos += kLengthSize + nal_size; |
| + } |
| + return pos == buf_size; |
| +} |
| + |
| +bool ConvertAVCCToAnnexB(uint8 length_size, std::vector<uint8>* buffer) { |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
use int for length_size
strobe_
2012/06/07 16:33:54
Done.
|
| + RCHECK(length_size == 1 || length_size == 2 || length_size == 4); |
| + |
| + if (length_size == 4) { |
| + return ConvertAVCCToAnnexBInPlaceForLengthSize4(buffer->size(), |
| + &((*buffer)[0])); |
| + } else { |
| + std::vector<uint8_t> temp; |
| + temp.swap(*buffer); |
| + buffer->reserve(temp.size() + 32); |
| + |
| + size_t pos = 0; |
| + while (pos + length_size < temp.size()) { |
| + uint32 nal_size = temp[pos]; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
use int
strobe_
2012/06/07 16:33:54
Done.
|
| + if (length_size == 2) nal_size = (nal_size << 8) + temp[pos+1]; |
| + pos += length_size; |
| + |
| + RCHECK(pos + nal_size <= temp.size()); |
| + buffer->insert(buffer->end(), kAnnexBStartCode, |
| + kAnnexBStartCode + kAnnexBStartCodeSize); |
| + buffer->insert(buffer->end(), temp.begin() + pos, |
| + temp.begin() + pos + nal_size); |
| + pos += nal_size; |
| + } |
| + return pos == temp.size(); |
| + } |
| +} |
| + |
| +ChannelLayout ConvertAACChannelCountToChannelLayout(uint16 count) { |
| + switch (count) { |
| + case 1: |
| + return CHANNEL_LAYOUT_MONO; |
| + case 2: |
| + return CHANNEL_LAYOUT_STEREO; |
| + case 3: |
| + return CHANNEL_LAYOUT_SURROUND; |
| + case 4: |
| + return CHANNEL_LAYOUT_4_0; |
| + case 5: |
| + return CHANNEL_LAYOUT_5_0; |
| + case 6: |
| + return CHANNEL_LAYOUT_5_1; |
| + case 8: |
| + return CHANNEL_LAYOUT_7_1; |
| + default: |
| + return CHANNEL_LAYOUT_UNSUPPORTED; |
| + } |
| +} |
| + |
| +} |
| +} |