OLD | NEW |
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 Loading... |
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 "AudioFileReader::Read() : reader is not opened!"; |
| 117 |
115 size_t channels = this->channels(); | 118 size_t channels = this->channels(); |
116 DCHECK_EQ(audio_data.size(), channels); | 119 DCHECK_EQ(audio_data.size(), channels); |
117 if (audio_data.size() != channels) | 120 if (audio_data.size() != channels) |
118 return false; | 121 return false; |
119 | 122 |
120 DCHECK(format_context_ && codec_context_ && codec_); | |
121 if (!format_context_ || !codec_context_ || !codec_) { | |
122 DLOG(WARNING) << "AudioFileReader::Read() : reader is not opened!"; | |
123 return false; | |
124 } | |
125 | |
126 // Holds decoded audio. | 123 // Holds decoded audio. |
127 scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> av_frame(avcodec_alloc_frame()); | 124 scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> av_frame(avcodec_alloc_frame()); |
128 | 125 |
129 // Read until we hit EOF or we've read the requested number of frames. | 126 // Read until we hit EOF or we've read the requested number of frames. |
130 AVPacket packet; | 127 AVPacket packet; |
131 int result = 0; | 128 int result = 0; |
132 size_t current_frame = 0; | 129 size_t current_frame = 0; |
133 | 130 |
134 while (current_frame < number_of_frames && | 131 while (current_frame < number_of_frames && |
135 (result = av_read_frame(format_context_, &packet)) >= 0) { | 132 (result = av_read_frame(format_context_, &packet)) >= 0) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 175 } |
179 } | 176 } |
180 | 177 |
181 current_frame += frames_read; | 178 current_frame += frames_read; |
182 } | 179 } |
183 | 180 |
184 return true; | 181 return true; |
185 } | 182 } |
186 | 183 |
187 } // namespace media | 184 } // namespace media |
OLD | NEW |