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 #include <vector> | |
| 9 | |
| 10 #include "media/mp4/box_definitions.h" | |
| 11 #include "media/mp4/box_reader.h" | |
| 12 | |
| 13 namespace media { | |
| 14 namespace mp4 { | |
| 15 | |
| 16 static const uint8 kAnnexBStartCode[] = {0, 0, 0, 1}; | |
| 17 static const int kAnnexBStartCodeSize = 4; | |
| 18 | |
| 19 static bool ConvertAVCToAnnexBInPlaceForLengthSize4(std::vector<uint8>* buf) { | |
|
strobe_
2012/06/13 21:18:13
This change fixes behavior on on Windows.
| |
| 20 const int kLengthSize = 4; | |
| 21 size_t pos = 0; | |
| 22 while (pos + kLengthSize < buf->size()) { | |
| 23 int nal_size = (*buf)[pos]; | |
| 24 nal_size = (nal_size << 8) + (*buf)[pos+1]; | |
| 25 nal_size = (nal_size << 8) + (*buf)[pos+2]; | |
| 26 nal_size = (nal_size << 8) + (*buf)[pos+3]; | |
| 27 std::copy(kAnnexBStartCode, kAnnexBStartCode + kAnnexBStartCodeSize, | |
| 28 buf->begin() + pos); | |
| 29 pos += kLengthSize + nal_size; | |
| 30 } | |
| 31 return pos == buf->size(); | |
| 32 } | |
| 33 | |
| 34 // static | |
| 35 bool AVC::ConvertToAnnexB(int length_size, std::vector<uint8>* buffer) { | |
| 36 RCHECK(length_size == 1 || length_size == 2 || length_size == 4); | |
| 37 | |
| 38 if (length_size == 4) | |
| 39 return ConvertAVCToAnnexBInPlaceForLengthSize4(buffer); | |
| 40 | |
| 41 std::vector<uint8> temp; | |
| 42 temp.swap(*buffer); | |
| 43 buffer->reserve(temp.size() + 32); | |
| 44 | |
| 45 size_t pos = 0; | |
| 46 while (pos + length_size < temp.size()) { | |
| 47 int nal_size = temp[pos]; | |
| 48 if (length_size == 2) nal_size = (nal_size << 8) + temp[pos+1]; | |
| 49 pos += length_size; | |
| 50 | |
| 51 RCHECK(pos + nal_size <= temp.size()); | |
| 52 buffer->insert(buffer->end(), kAnnexBStartCode, | |
| 53 kAnnexBStartCode + kAnnexBStartCodeSize); | |
| 54 buffer->insert(buffer->end(), temp.begin() + pos, | |
| 55 temp.begin() + pos + nal_size); | |
| 56 pos += nal_size; | |
| 57 } | |
| 58 return pos == temp.size(); | |
| 59 } | |
| 60 | |
| 61 // static | |
| 62 bool AVC::InsertParameterSets(const AVCDecoderConfigurationRecord& avc_config, | |
| 63 std::vector<uint8>* buffer) { | |
| 64 int total_size = 0; | |
| 65 for (size_t i = 0; i < avc_config.sps_list.size(); i++) | |
| 66 total_size += avc_config.sps_list[i].size() + kAnnexBStartCodeSize; | |
| 67 for (size_t i = 0; i < avc_config.pps_list.size(); i++) | |
| 68 total_size += avc_config.pps_list[i].size() + kAnnexBStartCodeSize; | |
| 69 | |
| 70 std::vector<uint8> temp; | |
| 71 temp.reserve(total_size); | |
| 72 | |
| 73 for (size_t i = 0; i < avc_config.sps_list.size(); i++) { | |
| 74 temp.insert(temp.end(), kAnnexBStartCode, | |
| 75 kAnnexBStartCode + kAnnexBStartCodeSize); | |
| 76 temp.insert(temp.end(), avc_config.sps_list[i].begin(), | |
| 77 avc_config.sps_list[i].end()); | |
| 78 } | |
| 79 | |
| 80 for (size_t i = 0; i < avc_config.pps_list.size(); i++) { | |
| 81 temp.insert(temp.end(), kAnnexBStartCode, | |
| 82 kAnnexBStartCode + kAnnexBStartCodeSize); | |
| 83 temp.insert(temp.end(), avc_config.pps_list[i].begin(), | |
| 84 avc_config.pps_list[i].end()); | |
| 85 } | |
| 86 | |
| 87 buffer->insert(buffer->begin(), temp.begin(), temp.end()); | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 // static | |
| 92 ChannelLayout AVC::ConvertAACChannelCountToChannelLayout(int count) { | |
| 93 switch (count) { | |
| 94 case 1: | |
| 95 return CHANNEL_LAYOUT_MONO; | |
| 96 case 2: | |
| 97 return CHANNEL_LAYOUT_STEREO; | |
| 98 case 3: | |
| 99 return CHANNEL_LAYOUT_SURROUND; | |
| 100 case 4: | |
| 101 return CHANNEL_LAYOUT_4_0; | |
| 102 case 5: | |
| 103 return CHANNEL_LAYOUT_5_0; | |
| 104 case 6: | |
| 105 return CHANNEL_LAYOUT_5_1; | |
| 106 case 8: | |
| 107 return CHANNEL_LAYOUT_7_1; | |
| 108 default: | |
| 109 return CHANNEL_LAYOUT_UNSUPPORTED; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 } // namespace mp4 | |
| 114 } // namespace media | |
| OLD | NEW |