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

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: 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 "media/mp4/box_reader.h"
8 #include <algorithm>
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit: system header files come right after avc.h
strobe_ 2012/06/07 16:33:54 Done.
9
10 namespace media {
11 namespace mp4 {
12
13 const static uint8 kAnnexBStartCode[] = {0, 0, 0, 1};
14 const static size_t kAnnexBStartCodeSize = 4;
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit: use int
strobe_ 2012/06/07 22:04:22 Done.
15
16 AVCDecoderConfigurationRecord::AVCDecoderConfigurationRecord() {};
17 AVCDecoderConfigurationRecord::~AVCDecoderConfigurationRecord() {};
18
19 bool Parse(BoxReader* r, AVCDecoderConfigurationRecord* avcc) {
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit: rename r -> reader & avcc to something more d
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 Forward declared in avc.h like the other methods.
strobe_ 2012/06/07 16:33:54 Done.
strobe_ 2012/06/07 16:33:54 Doing this creates an include loop with box_defini
20
21 RCHECK(r->Read(&avcc->version) && avcc->version == 1 &&
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 Change read signatures to include size. ie Read1By
strobe_ 2012/06/07 16:33:54 In progress.
22 r->Read(&avcc->profile_indication) &&
23 r->Read(&avcc->profile_compatibility) &&
24 r->Read(&avcc->avc_level));
25
26 uint8 length_size_minus_one;
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit: use int
27 RCHECK(r->Read(&length_size_minus_one) &&
28 (length_size_minus_one & 0xfc) == 0xfc);
29 avcc->length_size = (length_size_minus_one & 0x3) + 1;
30
31 uint8 num_sps;
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit: use int
32 RCHECK(r->Read(&num_sps) && (num_sps & 0xe0) == 0xe0);
33 num_sps &= 0x1f;
34
35 avcc->spses.resize(num_sps);
36 for (int i = 0; i < num_sps; i++) {
37 uint16 sps_length;
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit: use int
38 RCHECK(r->Read(&sps_length) &&
39 r->Read(&avcc->spses[i], sps_length));
40 }
41
42 uint8 num_pps;
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 nit:use int here and various places below.
43 RCHECK(r->Read(&num_pps));
44
45 avcc->ppses.resize(num_pps);
46 for (int i = 0; i < num_pps; i++) {
47 uint16 pps_length;
48 RCHECK(r->Read(&pps_length) &&
49 r->Read(&avcc->ppses[i], pps_length));
50 }
51
52 return true;
53 }
54
55 bool ConvertAVCCToAnnexBInPlaceForLengthSize4(size_t buf_size, uint8* buf) {
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 Add static if only used in this file. Otherwise ad
strobe_ 2012/06/07 22:04:22 Done.
56 const size_t kLengthSize = 4;
57 size_t pos = 0;
58 while (pos + kLengthSize < buf_size) {
59 uint32 nal_size = (((uint32) buf[pos]) << 24)
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 use static_cast<>
strobe_ 2012/06/07 16:33:54 Done. (Changed to match style used in BufferReader
60 + (((uint32) buf[pos+1]) << 16)
61 + (((uint32) buf[pos+2]) << 8)
62 + buf[pos+3];
63 memcpy(&buf[pos], kAnnexBStartCode, kAnnexBStartCodeSize);
64 pos += kLengthSize + nal_size;
65 }
66 return pos == buf_size;
67 }
68
69 bool ConvertAVCCToAnnexB(uint8 length_size, std::vector<uint8>* buffer) {
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 use int for length_size
strobe_ 2012/06/07 16:33:54 Done.
70 RCHECK(length_size == 1 || length_size == 2 || length_size == 4);
71
72 if (length_size == 4) {
73 return ConvertAVCCToAnnexBInPlaceForLengthSize4(buffer->size(),
74 &((*buffer)[0]));
75 } else {
76 std::vector<uint8_t> temp;
77 temp.swap(*buffer);
78 buffer->reserve(temp.size() + 32);
79
80 size_t pos = 0;
81 while (pos + length_size < temp.size()) {
82 uint32 nal_size = temp[pos];
acolwell GONE FROM CHROMIUM 2012/06/06 17:32:39 use int
strobe_ 2012/06/07 16:33:54 Done.
83 if (length_size == 2) nal_size = (nal_size << 8) + temp[pos+1];
84 pos += length_size;
85
86 RCHECK(pos + nal_size <= temp.size());
87 buffer->insert(buffer->end(), kAnnexBStartCode,
88 kAnnexBStartCode + kAnnexBStartCodeSize);
89 buffer->insert(buffer->end(), temp.begin() + pos,
90 temp.begin() + pos + nal_size);
91 pos += nal_size;
92 }
93 return pos == temp.size();
94 }
95 }
96
97 ChannelLayout ConvertAACChannelCountToChannelLayout(uint16 count) {
98 switch (count) {
99 case 1:
100 return CHANNEL_LAYOUT_MONO;
101 case 2:
102 return CHANNEL_LAYOUT_STEREO;
103 case 3:
104 return CHANNEL_LAYOUT_SURROUND;
105 case 4:
106 return CHANNEL_LAYOUT_4_0;
107 case 5:
108 return CHANNEL_LAYOUT_5_0;
109 case 6:
110 return CHANNEL_LAYOUT_5_1;
111 case 8:
112 return CHANNEL_LAYOUT_7_1;
113 default:
114 return CHANNEL_LAYOUT_UNSUPPORTED;
115 }
116 }
117
118 }
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698