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

Side by Side Diff: media/filters/audio_file_reader.cc

Issue 10821029: Moved DCHECK() to prevent NULL deref of codec_context_. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/filters/audio_file_reader.h" 5 #include "media/filters/audio_file_reader.h"
6 6
7 #include <string> 7 #include <string>
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 codec_ = NULL; 105 codec_ = NULL;
106 106
107 if (format_context_) { 107 if (format_context_) {
108 avformat_close_input(&format_context_); 108 avformat_close_input(&format_context_);
109 format_context_ = NULL; 109 format_context_ = NULL;
110 } 110 }
111 } 111 }
112 112
113 bool AudioFileReader::Read(const std::vector<float*>& audio_data, 113 bool AudioFileReader::Read(const std::vector<float*>& audio_data,
114 size_t number_of_frames) { 114 size_t number_of_frames) {
115 DCHECK(format_context_ && codec_context_ && codec_);
116
115 size_t channels = this->channels(); 117 size_t channels = this->channels();
116 DCHECK_EQ(audio_data.size(), channels); 118 DCHECK_EQ(audio_data.size(), channels);
117 if (audio_data.size() != channels) 119 if (audio_data.size() != channels)
118 return false; 120 return false;
119 121
120 DCHECK(format_context_ && codec_context_ && codec_);
121 if (!format_context_ || !codec_context_ || !codec_) { 122 if (!format_context_ || !codec_context_ || !codec_) {
Tyler Breisacher (Chromium) 2012/07/25 21:53:03 Isn't if () redundant then? Maybe it should just s
Kyle Horimoto 2012/07/25 21:57:25 If we did that, we wouldn't hit the "return false;
Tyler Breisacher (Chromium) 2012/07/25 22:14:23 The DCHECK is saying "none of these should ever be
122 DLOG(WARNING) << "AudioFileReader::Read() : reader is not opened!"; 123 DLOG(WARNING) << "AudioFileReader::Read() : reader is not opened!";
123 return false; 124 return false;
124 } 125 }
125 126
126 // Holds decoded audio. 127 // Holds decoded audio.
127 scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> av_frame(avcodec_alloc_frame()); 128 scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> av_frame(avcodec_alloc_frame());
128 129
129 // Read until we hit EOF or we've read the requested number of frames. 130 // Read until we hit EOF or we've read the requested number of frames.
130 AVPacket packet; 131 AVPacket packet;
131 int result = 0; 132 int result = 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 179 }
179 } 180 }
180 181
181 current_frame += frames_read; 182 current_frame += frames_read;
182 } 183 }
183 184
184 return true; 185 return true;
185 } 186 }
186 187
187 } // namespace media 188 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698