OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 av_find_stream_info(format_context_); | 84 av_find_stream_info(format_context_); |
85 codec_ = avcodec_find_decoder(codec_context_->codec_id); | 85 codec_ = avcodec_find_decoder(codec_context_->codec_id); |
86 if (codec_) { | 86 if (codec_) { |
87 if ((result = avcodec_open(codec_context_, codec_)) < 0) { | 87 if ((result = avcodec_open(codec_context_, codec_)) < 0) { |
88 DLOG(WARNING) << "AudioFileReader::Open() : could not open codec -" | 88 DLOG(WARNING) << "AudioFileReader::Open() : could not open codec -" |
89 << " result: " << result; | 89 << " result: " << result; |
90 return false; | 90 return false; |
91 } | 91 } |
92 | 92 |
93 result = av_seek_frame(format_context_, 0, 0, 0); | 93 result = av_seek_frame(format_context_, 0, 0, 0); |
94 } else { | |
95 DLOG(WARNING) << "AudioFileReader::Open() : could not find codec -" | |
scherkus (not reviewing)
2011/08/30 20:25:33
the indentation is wrong here -- could you TBR a p
| |
96 << " result: " << result; | |
97 return false; | |
94 } | 98 } |
95 | 99 |
96 return true; | 100 return true; |
97 } | 101 } |
98 | 102 |
99 void AudioFileReader::Close() { | 103 void AudioFileReader::Close() { |
100 if (codec_context_ && codec_) | 104 if (codec_context_ && codec_) |
101 avcodec_close(codec_context_); | 105 avcodec_close(codec_context_); |
102 | 106 |
103 codec_context_ = NULL; | 107 codec_context_ = NULL; |
104 codec_ = NULL; | 108 codec_ = NULL; |
105 | 109 |
106 if (format_context_) { | 110 if (format_context_) { |
107 av_close_input_file(format_context_); | 111 av_close_input_file(format_context_); |
108 format_context_ = NULL; | 112 format_context_ = NULL; |
109 } | 113 } |
110 } | 114 } |
111 | 115 |
112 bool AudioFileReader::Read(const std::vector<float*>& audio_data, | 116 bool AudioFileReader::Read(const std::vector<float*>& audio_data, |
113 size_t number_of_frames) { | 117 size_t number_of_frames) { |
114 size_t channels = this->channels(); | 118 size_t channels = this->channels(); |
115 DCHECK_EQ(audio_data.size(), channels); | 119 DCHECK_EQ(audio_data.size(), channels); |
116 if (audio_data.size() != channels) | 120 if (audio_data.size() != channels) |
117 return false; | 121 return false; |
118 | 122 |
119 DCHECK(format_context_ && codec_context_); | 123 DCHECK(format_context_ && codec_context_ && codec_); |
120 if (!format_context_ || !codec_context_) { | 124 if (!format_context_ || !codec_context_ || !codec_) { |
121 DLOG(WARNING) << "AudioFileReader::Read() : reader is not opened!"; | 125 DLOG(WARNING) << "AudioFileReader::Read() : reader is not opened!"; |
122 return false; | 126 return false; |
123 } | 127 } |
124 | 128 |
125 scoped_ptr_malloc<int16, ScopedPtrAVFree> output_buffer( | 129 scoped_ptr_malloc<int16, ScopedPtrAVFree> output_buffer( |
126 static_cast<int16*>(av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE))); | 130 static_cast<int16*>(av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE))); |
127 | 131 |
128 // Read until we hit EOF or we've read the requested number of frames. | 132 // Read until we hit EOF or we've read the requested number of frames. |
129 AVPacket avpkt; | 133 AVPacket avpkt; |
130 av_init_packet(&avpkt); | 134 av_init_packet(&avpkt); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 } | 178 } |
175 } | 179 } |
176 | 180 |
177 current_frame += frames_read; | 181 current_frame += frames_read; |
178 } | 182 } |
179 | 183 |
180 return true; | 184 return true; |
181 } | 185 } |
182 | 186 |
183 } // namespace media | 187 } // namespace media |
OLD | NEW |