Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: media/mp4/avc.cc

Issue 10536014: Implement ISO BMFF support in Media Source. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code review changes; add offset_byte_queue_unittest.cc Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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};
15 const static int kAnnexBStartCodeSize = 4;
16
17 AVCDecoderConfigurationRecord::AVCDecoderConfigurationRecord() {};
18 AVCDecoderConfigurationRecord::~AVCDecoderConfigurationRecord() {};
19
20 bool Parse(BoxReader* reader, AVCDecoderConfigurationRecord* avc_config) {
21 RCHECK(reader->Read(&avc_config->version) && avc_config->version == 1 &&
22 reader->Read(&avc_config->profile_indication) &&
23 reader->Read(&avc_config->profile_compatibility) &&
24 reader->Read(&avc_config->avc_level));
25
26 uint8 length_size_minus_one;
27 RCHECK(reader->Read(&length_size_minus_one) &&
28 (length_size_minus_one & 0xfc) == 0xfc);
29 avc_config->length_size = (length_size_minus_one & 0x3) + 1;
30
31 uint8 num_sps;
32 RCHECK(reader->Read(&num_sps) && (num_sps & 0xe0) == 0xe0);
33 num_sps &= 0x1f;
34
35 avc_config->sps_list.resize(num_sps);
36 for (int i = 0; i < num_sps; i++) {
37 uint16 sps_length;
38 RCHECK(reader->Read(&sps_length) &&
39 reader->ReadVec(&avc_config->sps_list[i], sps_length));
40 }
41
42 uint8 num_pps;
43 RCHECK(reader->Read(&num_pps));
44
45 avc_config->pps_list.resize(num_pps);
46 for (int i = 0; i < num_pps; i++) {
47 uint16 pps_length;
48 RCHECK(reader->Read(&pps_length) &&
49 reader->ReadVec(&avc_config->pps_list[i], pps_length));
50 }
51
52 return true;
53 }
54
55 static bool ConvertAVCCToAnnexBInPlaceForLengthSize4(size_t buf_size,
56 uint8* buf) {
57 const size_t kLengthSize = 4;
58 size_t pos = 0;
59 while (pos + kLengthSize < buf_size) {
60 uint32 nal_size = buf[pos];
61 nal_size = (nal_size << 8) + buf[pos+1];
62 nal_size = (nal_size << 8) + buf[pos+2];
63 nal_size = (nal_size << 8) + buf[pos+3];
64 memcpy(&buf[pos], kAnnexBStartCode, kAnnexBStartCodeSize);
65 pos += kLengthSize + nal_size;
66 }
67 return pos == buf_size;
68 }
69
70 bool ConvertAVCCToAnnexB(int length_size, std::vector<uint8>* buffer) {
71 RCHECK(length_size == 1 || length_size == 2 || length_size == 4);
72
73 if (length_size == 4) {
74 return ConvertAVCCToAnnexBInPlaceForLengthSize4(buffer->size(),
75 &((*buffer)[0]));
76 } else {
77 std::vector<uint8_t> temp;
78 temp.swap(*buffer);
79 buffer->reserve(temp.size() + 32);
80
81 size_t pos = 0;
82 while (pos + length_size < temp.size()) {
83 int nal_size = temp[pos];
84 if (length_size == 2) nal_size = (nal_size << 8) + temp[pos+1];
85 pos += length_size;
86
87 RCHECK(pos + nal_size <= temp.size());
88 buffer->insert(buffer->end(), kAnnexBStartCode,
89 kAnnexBStartCode + kAnnexBStartCodeSize);
90 buffer->insert(buffer->end(), temp.begin() + pos,
91 temp.begin() + pos + nal_size);
92 pos += nal_size;
93 }
94 return pos == temp.size();
95 }
96 }
97
98 ChannelLayout ConvertAACChannelCountToChannelLayout(int count) {
99 switch (count) {
100 case 1:
101 return CHANNEL_LAYOUT_MONO;
102 case 2:
103 return CHANNEL_LAYOUT_STEREO;
104 case 3:
105 return CHANNEL_LAYOUT_SURROUND;
106 case 4:
107 return CHANNEL_LAYOUT_4_0;
108 case 5:
109 return CHANNEL_LAYOUT_5_0;
110 case 6:
111 return CHANNEL_LAYOUT_5_1;
112 case 8:
113 return CHANNEL_LAYOUT_7_1;
114 default:
115 return CHANNEL_LAYOUT_UNSUPPORTED;
116 }
117 }
118
119 }
120 }
OLDNEW
« no previous file with comments | « media/mp4/avc.h ('k') | media/mp4/avc_unittest.cc » ('j') | media/mp4/box_reader_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698