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

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

Issue 7290030: Fix heapchecker failure due to not deleting AVStream*[]. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 9 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) 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 "base/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "media/base/media.h" 9 #include "media/base/media.h"
10 #include "media/base/mock_callback.h" 10 #include "media/base/mock_callback.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 codecs_[VIDEO].width = 320; 50 codecs_[VIDEO].width = 320;
51 codecs_[VIDEO].height = 240; 51 codecs_[VIDEO].height = 240;
52 52
53 codecs_[AUDIO].codec_type = AVMEDIA_TYPE_AUDIO; 53 codecs_[AUDIO].codec_type = AVMEDIA_TYPE_AUDIO;
54 codecs_[AUDIO].codec_id = CODEC_ID_VORBIS; 54 codecs_[AUDIO].codec_id = CODEC_ID_VORBIS;
55 codecs_[AUDIO].channels = 2; 55 codecs_[AUDIO].channels = 2;
56 codecs_[AUDIO].sample_rate = 44100; 56 codecs_[AUDIO].sample_rate = 44100;
57 } 57 }
58 58
59 virtual ~ChunkDemuxerTest() { 59 virtual ~ChunkDemuxerTest() {
60 if (demuxer_.get()) 60 ShutdownDemuxer();
61 demuxer_->Shutdown();
62 if (format_context_.streams) {
63 delete[] format_context_.streams;
64 format_context_.streams = NULL;
65 format_context_.nb_streams = 0;
66 }
67 } 61 }
68 62
69 void ReadFile(const std::string& name, scoped_array<uint8>* buffer, 63 void ReadFile(const std::string& name, scoped_array<uint8>* buffer,
70 int* size) { 64 int* size) {
71 FilePath file_path; 65 FilePath file_path;
72 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); 66 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &file_path));
73 file_path = file_path.Append(FILE_PATH_LITERAL("media")) 67 file_path = file_path.Append(FILE_PATH_LITERAL("media"))
74 .Append(FILE_PATH_LITERAL("test")) 68 .Append(FILE_PATH_LITERAL("test"))
75 .Append(FILE_PATH_LITERAL("data")) 69 .Append(FILE_PATH_LITERAL("data"))
76 .AppendASCII(name); 70 .AppendASCII(name);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 memcpy(buf, audio_track_entry.get(), audio_track_entry_size); 127 memcpy(buf, audio_track_entry.get(), audio_track_entry_size);
134 buf += audio_track_entry_size; 128 buf += audio_track_entry_size;
135 } 129 }
136 130
137 if (has_video) { 131 if (has_video) {
138 memcpy(buf, video_track_entry.get(), video_track_entry_size); 132 memcpy(buf, video_track_entry.get(), video_track_entry_size);
139 buf += video_track_entry_size; 133 buf += video_track_entry_size;
140 } 134 }
141 } 135 }
142 136
143 void SetupAVFormatContext(bool has_audio, bool has_video) { 137 void InitDemuxer(bool has_audio, bool has_video) {
144 int i = 0;
145 format_context_.streams = new AVStream *[MAX_CODECS_INDEX];
146 if (has_audio) {
147 format_context_.streams[i] = &streams_[i];
148 streams_[i].codec = &codecs_[AUDIO];
149 streams_[i].duration = 100;
150 streams_[i].time_base.den = base::Time::kMicrosecondsPerSecond;
151 streams_[i].time_base.num = 1;
152 i++;
153 }
154
155 if (has_video) {
156 format_context_.streams[i] = &streams_[i];
157 streams_[i].codec = &codecs_[VIDEO];
158 streams_[i].duration = 100;
159 streams_[i].time_base.den = base::Time::kMicrosecondsPerSecond;
160 streams_[i].time_base.num = 1;
161 i++;
162 }
163
164 format_context_.nb_streams = i;
165 }
166
167 void InitDemuxer(bool has_audio, bool has_video) {
168 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) 138 EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL))
169 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), 139 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_),
170 Return(0))); 140 Return(0)));
171 141
172 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) 142 EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_))
173 .WillOnce(Return(0)); 143 .WillOnce(Return(0));
174 144
175 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); 145 EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_));
176 146
177 EXPECT_CALL(mock_ffmpeg_, AVRegisterLockManager(_)) 147 EXPECT_CALL(mock_ffmpeg_, AVRegisterLockManager(_))
178 .WillRepeatedly(Return(0)); 148 .WillRepeatedly(Return(0));
179 149
180 scoped_array<uint8> info_tracks; 150 scoped_array<uint8> info_tracks;
181 int info_tracks_size = 0; 151 int info_tracks_size = 0;
182 CreateInfoTracks(has_audio, has_video, &info_tracks, &info_tracks_size); 152 CreateInfoTracks(has_audio, has_video, &info_tracks, &info_tracks_size);
183 153
184 SetupAVFormatContext(has_audio, has_video); 154 SetupAVFormatContext(has_audio, has_video);
185 155
186 EXPECT_EQ(demuxer_->Init(info_tracks.get(), info_tracks_size), 156 EXPECT_EQ(demuxer_->Init(info_tracks.get(), info_tracks_size),
187 has_audio || has_video); 157 has_audio || has_video);
188 } 158 }
189 159
160 void ShutdownDemuxer() {
161 if (demuxer_) {
162 demuxer_->Shutdown();
163 }
164
165 if (format_context_.streams) {
166 delete[] format_context_.streams;
167 format_context_.streams = NULL;
168 format_context_.nb_streams = 0;
169 }
170 }
171
190 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode) { 172 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode) {
191 uint8 data[] = { 0x00 }; 173 uint8 data[] = { 0x00 };
192 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data)); 174 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data));
193 } 175 }
194 176
195 MOCK_METHOD1(Checkpoint, void(int id)); 177 MOCK_METHOD1(Checkpoint, void(int id));
196 178
197 MockFFmpeg mock_ffmpeg_; 179 MockFFmpeg mock_ffmpeg_;
198 180
199 AVFormatContext format_context_; 181 AVFormatContext format_context_;
200 AVCodecContext codecs_[MAX_CODECS_INDEX]; 182 AVCodecContext codecs_[MAX_CODECS_INDEX];
201 AVStream streams_[MAX_CODECS_INDEX]; 183 AVStream streams_[MAX_CODECS_INDEX];
202 184
203 scoped_refptr<ChunkDemuxer> demuxer_; 185 scoped_refptr<ChunkDemuxer> demuxer_;
204 186
205 private: 187 private:
188 void SetupAVFormatContext(bool has_audio, bool has_video) {
189 int i = 0;
190 format_context_.streams = new AVStream*[MAX_CODECS_INDEX];
191 if (has_audio) {
192 format_context_.streams[i] = &streams_[i];
193 streams_[i].codec = &codecs_[AUDIO];
194 streams_[i].duration = 100;
195 streams_[i].time_base.den = base::Time::kMicrosecondsPerSecond;
196 streams_[i].time_base.num = 1;
197 i++;
198 }
199
200 if (has_video) {
201 format_context_.streams[i] = &streams_[i];
202 streams_[i].codec = &codecs_[VIDEO];
203 streams_[i].duration = 100;
204 streams_[i].time_base.den = base::Time::kMicrosecondsPerSecond;
205 streams_[i].time_base.num = 1;
206 i++;
207 }
208
209 format_context_.nb_streams = i;
210 }
211
206 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 212 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
207 }; 213 };
208 214
209 TEST_F(ChunkDemuxerTest, TestInit) { 215 TEST_F(ChunkDemuxerTest, TestInit) {
210 // Test no streams, audio-only, video-only, and audio & video scenarios. 216 // Test no streams, audio-only, video-only, and audio & video scenarios.
211 for (int i = 0; i < 4; i++) { 217 for (int i = 0; i < 4; i++) {
212 bool has_audio = (i & 0x1) != 0; 218 bool has_audio = (i & 0x1) != 0;
213 bool has_video = (i & 0x2) != 0; 219 bool has_video = (i & 0x2) != 0;
214 220
215 demuxer_ = new ChunkDemuxer(); 221 demuxer_ = new ChunkDemuxer();
216 InitDemuxer(has_audio, has_video); 222 InitDemuxer(has_audio, has_video);
217 EXPECT_EQ(demuxer_->GetStream(DemuxerStream::AUDIO).get() != NULL, 223 EXPECT_EQ(demuxer_->GetStream(DemuxerStream::AUDIO).get() != NULL,
218 has_audio); 224 has_audio);
219 EXPECT_EQ(demuxer_->GetStream(DemuxerStream::VIDEO).get() != NULL, 225 EXPECT_EQ(demuxer_->GetStream(DemuxerStream::VIDEO).get() != NULL,
220 has_video); 226 has_video);
221 demuxer_->Shutdown(); 227 ShutdownDemuxer();
222 demuxer_ = NULL; 228 demuxer_ = NULL;
223 } 229 }
224 } 230 }
225 231
226 // Makes sure that Seek() reports an error if Shutdown() 232 // Makes sure that Seek() reports an error if Shutdown()
227 // is called before the first cluster is passed to the demuxer. 233 // is called before the first cluster is passed to the demuxer.
228 TEST_F(ChunkDemuxerTest, TestShutdownBeforeFirstSeekCompletes) { 234 TEST_F(ChunkDemuxerTest, TestShutdownBeforeFirstSeekCompletes) {
229 InitDemuxer(true, true); 235 InitDemuxer(true, true);
230 236
231 demuxer_->Seek(base::TimeDelta::FromSeconds(0), 237 demuxer_->Seek(base::TimeDelta::FromSeconds(0),
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 414
409 cb.SetClusterTimecode(5); 415 cb.SetClusterTimecode(5);
410 AddSimpleBlock(&cb, kAudioTrackNum, 5); 416 AddSimpleBlock(&cb, kAudioTrackNum, 5);
411 AddSimpleBlock(&cb, kVideoTrackNum, 7); 417 AddSimpleBlock(&cb, kVideoTrackNum, 7);
412 scoped_ptr<Cluster> clusterE(cb.Finish()); 418 scoped_ptr<Cluster> clusterE(cb.Finish());
413 419
414 EXPECT_FALSE(demuxer_->AddData(clusterE->data(), clusterE->size())); 420 EXPECT_FALSE(demuxer_->AddData(clusterE->data(), clusterE->size()));
415 } 421 }
416 422
417 } // namespace media 423 } // 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