Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/mp4/avc.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "media/mp4/box_reader.h" | |
| 10 | |
| 11 namespace media { | |
| 12 namespace mp4 { | |
| 13 | |
| 14 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.
| |
| 15 const static int kAnnexBStartCodeSize = 4; | |
| 16 | |
| 17 static bool ConvertAVCCToAnnexBInPlaceForLengthSize4(int buf_size, | |
| 18 uint8* buf) { | |
| 19 const int kLengthSize = 4; | |
| 20 int pos = 0; | |
| 21 while (pos + kLengthSize < buf_size) { | |
| 22 int nal_size = buf[pos]; | |
| 23 nal_size = (nal_size << 8) + buf[pos+1]; | |
| 24 nal_size = (nal_size << 8) + buf[pos+2]; | |
| 25 nal_size = (nal_size << 8) + buf[pos+3]; | |
| 26 memcpy(&buf[pos], kAnnexBStartCode, kAnnexBStartCodeSize); | |
| 27 pos += kLengthSize + nal_size; | |
| 28 } | |
| 29 return pos == buf_size; | |
| 30 } | |
| 31 | |
| 32 bool ConvertAVCCToAnnexB(int length_size, std::vector<uint8>* buffer) { | |
| 33 RCHECK(length_size == 1 || length_size == 2 || length_size == 4); | |
| 34 | |
| 35 if (length_size == 4) { | |
| 36 return ConvertAVCCToAnnexBInPlaceForLengthSize4(buffer->size(), | |
| 37 &((*buffer)[0])); | |
| 38 } else { | |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
drop else
strobe_
2012/06/11 18:44:21
Done.
| |
| 39 std::vector<uint8_t> temp; | |
| 40 temp.swap(*buffer); | |
| 41 buffer->reserve(temp.size() + 32); | |
| 42 | |
| 43 size_t pos = 0; | |
| 44 while (pos + length_size < temp.size()) { | |
| 45 int nal_size = temp[pos]; | |
| 46 if (length_size == 2) nal_size = (nal_size << 8) + temp[pos+1]; | |
| 47 pos += length_size; | |
| 48 | |
| 49 RCHECK(pos + nal_size <= temp.size()); | |
| 50 buffer->insert(buffer->end(), kAnnexBStartCode, | |
| 51 kAnnexBStartCode + kAnnexBStartCodeSize); | |
| 52 buffer->insert(buffer->end(), temp.begin() + pos, | |
| 53 temp.begin() + pos + nal_size); | |
| 54 pos += nal_size; | |
| 55 } | |
| 56 return pos == temp.size(); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 ChannelLayout ConvertAACChannelCountToChannelLayout(int count) { | |
| 61 switch (count) { | |
| 62 case 1: | |
| 63 return CHANNEL_LAYOUT_MONO; | |
| 64 case 2: | |
| 65 return CHANNEL_LAYOUT_STEREO; | |
| 66 case 3: | |
| 67 return CHANNEL_LAYOUT_SURROUND; | |
| 68 case 4: | |
| 69 return CHANNEL_LAYOUT_4_0; | |
| 70 case 5: | |
| 71 return CHANNEL_LAYOUT_5_0; | |
| 72 case 6: | |
| 73 return CHANNEL_LAYOUT_5_1; | |
| 74 case 8: | |
| 75 return CHANNEL_LAYOUT_7_1; | |
| 76 default: | |
| 77 return CHANNEL_LAYOUT_UNSUPPORTED; | |
| 78 } | |
| 79 } | |
| 80 | |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
lint nit: remove blank line.
strobe_
2012/06/11 18:44:21
Done.
| |
| 81 } | |
| 82 } | |
| OLD | NEW |