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

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

Issue 11471006: Log MediaSource parsing errors to the MediaLog so they can appear in chrome:media-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit. Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « media/mp4/box_reader.h ('k') | media/mp4/box_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/mp4/box_reader.h" 5 #include "media/mp4/box_reader.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 bool BufferReader::Read4sInto8s(int64* v) { 73 bool BufferReader::Read4sInto8s(int64* v) {
74 // Beware of the need for sign extension. 74 // Beware of the need for sign extension.
75 int32 tmp; 75 int32 tmp;
76 RCHECK(Read4s(&tmp)); 76 RCHECK(Read4s(&tmp));
77 *v = tmp; 77 *v = tmp;
78 return true; 78 return true;
79 } 79 }
80 80
81 81
82 BoxReader::BoxReader(const uint8* buf, const int size) 82 BoxReader::BoxReader(const uint8* buf, const int size,
83 const LogCB& log_cb)
83 : BufferReader(buf, size), 84 : BufferReader(buf, size),
85 log_cb_(log_cb),
84 type_(FOURCC_NULL), 86 type_(FOURCC_NULL),
85 version_(0), 87 version_(0),
86 flags_(0), 88 flags_(0),
87 scanned_(false) { 89 scanned_(false) {
88 } 90 }
89 91
90 BoxReader::~BoxReader() { 92 BoxReader::~BoxReader() {
91 if (scanned_ && !children_.empty()) { 93 if (scanned_ && !children_.empty()) {
92 for (ChildMap::iterator itr = children_.begin(); 94 for (ChildMap::iterator itr = children_.begin();
93 itr != children_.end(); ++itr) { 95 itr != children_.end(); ++itr) {
94 DVLOG(1) << "Skipping unknown box: " << FourCCToString(itr->first); 96 DVLOG(1) << "Skipping unknown box: " << FourCCToString(itr->first);
95 } 97 }
96 } 98 }
97 } 99 }
98 100
99 // static 101 // static
100 BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf, 102 BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf,
101 const int buf_size, 103 const int buf_size,
104 const LogCB& log_cb,
102 bool* err) { 105 bool* err) {
103 scoped_ptr<BoxReader> reader(new BoxReader(buf, buf_size)); 106 scoped_ptr<BoxReader> reader(new BoxReader(buf, buf_size, log_cb));
104 if (!reader->ReadHeader(err)) 107 if (!reader->ReadHeader(err))
105 return NULL; 108 return NULL;
106 109
107 if (!IsValidTopLevelBox(reader->type())) { 110 if (!IsValidTopLevelBox(reader->type(), log_cb)) {
108 *err = true; 111 *err = true;
109 return NULL; 112 return NULL;
110 } 113 }
111 114
112 if (reader->size() <= buf_size) 115 if (reader->size() <= buf_size)
113 return reader.release(); 116 return reader.release();
114 117
115 return NULL; 118 return NULL;
116 } 119 }
117 120
118 // static 121 // static
119 bool BoxReader::StartTopLevelBox(const uint8* buf, 122 bool BoxReader::StartTopLevelBox(const uint8* buf,
120 const int buf_size, 123 const int buf_size,
124 const LogCB& log_cb,
121 FourCC* type, 125 FourCC* type,
122 int* box_size, 126 int* box_size,
123 bool* err) { 127 bool* err) {
124 BoxReader reader(buf, buf_size); 128 BoxReader reader(buf, buf_size, log_cb);
125 if (!reader.ReadHeader(err)) return false; 129 if (!reader.ReadHeader(err)) return false;
126 if (!IsValidTopLevelBox(reader.type())) { 130 if (!IsValidTopLevelBox(reader.type(), log_cb)) {
127 *err = true; 131 *err = true;
128 return false; 132 return false;
129 } 133 }
130 *type = reader.type(); 134 *type = reader.type();
131 *box_size = reader.size(); 135 *box_size = reader.size();
132 return true; 136 return true;
133 } 137 }
134 138
135 // static 139 // static
136 bool BoxReader::IsValidTopLevelBox(const FourCC& type) { 140 bool BoxReader::IsValidTopLevelBox(const FourCC& type,
141 const LogCB& log_cb) {
137 switch (type) { 142 switch (type) {
138 case FOURCC_FTYP: 143 case FOURCC_FTYP:
139 case FOURCC_PDIN: 144 case FOURCC_PDIN:
140 case FOURCC_MOOV: 145 case FOURCC_MOOV:
141 case FOURCC_MOOF: 146 case FOURCC_MOOF:
142 case FOURCC_MFRA: 147 case FOURCC_MFRA:
143 case FOURCC_MDAT: 148 case FOURCC_MDAT:
144 case FOURCC_FREE: 149 case FOURCC_FREE:
145 case FOURCC_SKIP: 150 case FOURCC_SKIP:
146 case FOURCC_META: 151 case FOURCC_META:
147 case FOURCC_MECO: 152 case FOURCC_MECO:
148 case FOURCC_STYP: 153 case FOURCC_STYP:
149 case FOURCC_SIDX: 154 case FOURCC_SIDX:
150 case FOURCC_SSIX: 155 case FOURCC_SSIX:
151 case FOURCC_PRFT: 156 case FOURCC_PRFT:
152 return true; 157 return true;
153 default: 158 default:
154 // Hex is used to show nonprintable characters and aid in debugging 159 // Hex is used to show nonprintable characters and aid in debugging
155 LOG(WARNING) << "Unrecognized top-level box type 0x" 160 MEDIA_LOG(log_cb) << "Unrecognized top-level box type 0x"
156 << std::hex << type; 161 << std::hex << type;
157 return false; 162 return false;
158 } 163 }
159 } 164 }
160 165
161 bool BoxReader::ScanChildren() { 166 bool BoxReader::ScanChildren() {
162 DCHECK(!scanned_); 167 DCHECK(!scanned_);
163 scanned_ = true; 168 scanned_ = true;
164 169
165 bool err = false; 170 bool err = false;
166 while (pos() < size()) { 171 while (pos() < size()) {
167 BoxReader child(&buf_[pos_], size_ - pos_); 172 BoxReader child(&buf_[pos_], size_ - pos_, log_cb_);
168 if (!child.ReadHeader(&err)) break; 173 if (!child.ReadHeader(&err)) break;
169 174
170 children_.insert(std::pair<FourCC, BoxReader>(child.type(), child)); 175 children_.insert(std::pair<FourCC, BoxReader>(child.type(), child));
171 pos_ += child.size(); 176 pos_ += child.size();
172 } 177 }
173 178
174 DCHECK(!err); 179 DCHECK(!err);
175 return !err && pos() == size(); 180 return !err && pos() == size();
176 } 181 }
177 182
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 230 }
226 231
227 // Note that the pos_ head has advanced to the byte immediately after the 232 // Note that the pos_ head has advanced to the byte immediately after the
228 // header, which is where we want it. 233 // header, which is where we want it.
229 size_ = size; 234 size_ = size;
230 return true; 235 return true;
231 } 236 }
232 237
233 } // namespace mp4 238 } // namespace mp4
234 } // namespace media 239 } // namespace media
OLDNEW
« no previous file with comments | « media/mp4/box_reader.h ('k') | media/mp4/box_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698