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..c9c66aa9cd81290eb3d13aaea70f3d848e1a0ec6 |
| --- /dev/null |
| +++ b/media/mp4/avc.cc |
| @@ -0,0 +1,82 @@ |
| +// 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 <algorithm> |
| + |
| +#include "media/mp4/box_reader.h" |
| + |
| +namespace media { |
| +namespace mp4 { |
| + |
| +const static uint8 kAnnexBStartCode[] = {0, 0, 0, 1}; |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
lint nit: static comes first here and below
strobe_
2012/06/11 18:44:21
Done.
|
| +const static int kAnnexBStartCodeSize = 4; |
| + |
| +static bool ConvertAVCCToAnnexBInPlaceForLengthSize4(int buf_size, |
| + uint8* buf) { |
| + const int kLengthSize = 4; |
| + int pos = 0; |
| + while (pos + kLengthSize < buf_size) { |
| + int nal_size = buf[pos]; |
| + nal_size = (nal_size << 8) + buf[pos+1]; |
| + nal_size = (nal_size << 8) + buf[pos+2]; |
| + nal_size = (nal_size << 8) + buf[pos+3]; |
| + memcpy(&buf[pos], kAnnexBStartCode, kAnnexBStartCodeSize); |
| + pos += kLengthSize + nal_size; |
| + } |
| + return pos == buf_size; |
| +} |
| + |
| +bool ConvertAVCCToAnnexB(int length_size, std::vector<uint8>* buffer) { |
| + RCHECK(length_size == 1 || length_size == 2 || length_size == 4); |
| + |
| + if (length_size == 4) { |
| + return ConvertAVCCToAnnexBInPlaceForLengthSize4(buffer->size(), |
| + &((*buffer)[0])); |
| + } else { |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
drop else
strobe_
2012/06/11 18:44:21
Done.
|
| + std::vector<uint8_t> temp; |
| + temp.swap(*buffer); |
| + buffer->reserve(temp.size() + 32); |
| + |
| + size_t pos = 0; |
| + while (pos + length_size < temp.size()) { |
| + int nal_size = temp[pos]; |
| + 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(int 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; |
| + } |
| +} |
| + |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
lint nit: remove blank line.
strobe_
2012/06/11 18:44:21
Done.
|
| +} |
| +} |