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

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

Issue 151192: Cleanup resources allocated by FFmpeg to avoid memory and threads leaks... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | « media/filters/ffmpeg_demuxer.cc ('k') | third_party/ffmpeg/avcodec-52.sigs » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <deque> 5 #include <deque>
6 6
7 #include "media/base/filters.h" 7 #include "media/base/filters.h"
8 #include "media/base/mock_ffmpeg.h" 8 #include "media/base/mock_ffmpeg.h"
9 #include "media/base/mock_filter_host.h" 9 #include "media/base/mock_filter_host.h"
10 #include "media/base/mock_filters.h" 10 #include "media/base/mock_filters.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 MockFFmpeg::set(&mock_ffmpeg_); 108 MockFFmpeg::set(&mock_ffmpeg_);
109 } 109 }
110 110
111 virtual ~FFmpegDemuxerTest() { 111 virtual ~FFmpegDemuxerTest() {
112 // Call Stop() to shut down internal threads. 112 // Call Stop() to shut down internal threads.
113 demuxer_->Stop(); 113 demuxer_->Stop();
114 114
115 // Finish up any remaining tasks. 115 // Finish up any remaining tasks.
116 message_loop_.RunAllPending(); 116 message_loop_.RunAllPending();
117 117
118 // Release the reference to the demuxer.
119 demuxer_ = NULL;
120
121 // Filter host also holds a reference to demuxer, destroy it.
122 filter_host_.reset();
123
118 // Reset MockFFmpeg. 124 // Reset MockFFmpeg.
119 MockFFmpeg::set(NULL); 125 MockFFmpeg::set(NULL);
120 } 126 }
121 127
122 // Sets up MockFFmpeg to allow FFmpegDemuxer to successfully initialize. 128 // Sets up MockFFmpeg to allow FFmpegDemuxer to successfully initialize.
123 void InitializeDemuxerMocks() { 129 void InitializeDemuxerMocks() {
124 EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL)) 130 EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL))
125 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); 131 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0)));
126 EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_)) 132 EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_))
127 .WillOnce(Return(0)); 133 .WillOnce(Return(0));
128 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&format_context_)); 134 EXPECT_CALL(*MockFFmpeg::get(), AVCloseInputFile(&format_context_));
129 } 135 }
130 136
131 // Initializes both MockFFmpeg and FFmpegDemuxer. 137 // Initializes both MockFFmpeg and FFmpegDemuxer.
132 void InitializeDemuxer() { 138 void InitializeDemuxer() {
133 InitializeDemuxerMocks(); 139 InitializeDemuxerMocks();
134 EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); 140 EXPECT_TRUE(demuxer_->Initialize(data_source_.get()));
135 message_loop_.RunAllPending(); 141 message_loop_.RunAllPending();
136 EXPECT_TRUE(filter_host_->WaitForInitialized()); 142 EXPECT_TRUE(filter_host_->WaitForInitialized());
137 EXPECT_TRUE(filter_host_->IsInitialized()); 143 EXPECT_TRUE(filter_host_->IsInitialized());
138 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); 144 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_COULD_NOT_OPEN)); 201 EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_COULD_NOT_OPEN));
196 EXPECT_FALSE(filter_host_->IsInitialized()); 202 EXPECT_FALSE(filter_host_->IsInitialized());
197 } 203 }
198 204
199 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { 205 TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
200 // Simulate av_find_stream_info() failing. 206 // Simulate av_find_stream_info() failing.
201 EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL)) 207 EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL))
202 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); 208 .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0)));
203 EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_)) 209 EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_))
204 .WillOnce(Return(AVERROR_IO)); 210 .WillOnce(Return(AVERROR_IO));
205 EXPECT_CALL(*MockFFmpeg::get(), AVFree(&format_context_)); 211 EXPECT_CALL(*MockFFmpeg::get(), AVCloseInputFile(&format_context_));
206 212
207 EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); 213 EXPECT_TRUE(demuxer_->Initialize(data_source_.get()));
208 message_loop_.RunAllPending(); 214 message_loop_.RunAllPending();
209 EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_COULD_NOT_PARSE)); 215 EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_COULD_NOT_PARSE));
210 EXPECT_FALSE(filter_host_->IsInitialized()); 216 EXPECT_FALSE(filter_host_->IsInitialized());
211 } 217 }
212 218
213 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { 219 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
214 // Simulate media with no parseable streams. 220 // Simulate media with no parseable streams.
215 { 221 {
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 649
644 // Attempt the read... 650 // Attempt the read...
645 audio->Read(callback.release()); 651 audio->Read(callback.release());
646 message_loop_.RunAllPending(); 652 message_loop_.RunAllPending();
647 653
648 // ...and verify that |callback| was deleted. 654 // ...and verify that |callback| was deleted.
649 MockFFmpeg::get()->CheckPoint(1); 655 MockFFmpeg::get()->CheckPoint(1);
650 } 656 }
651 657
652 } // namespace media 658 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | third_party/ffmpeg/avcodec-52.sigs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698