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

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: A thorough sign-ification 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};
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 }
OLDNEW
« no previous file with comments | « media/mp4/avc.h ('k') | media/mp4/avc_unittest.cc » ('j') | media/mp4/avc_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698