| 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/ffmpeg_glue.h" | 5 #include "media/filters/ffmpeg_glue.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "media/base/mock_filters.h" | 13 #include "media/base/mock_filters.h" |
| 14 #include "media/base/test_data_util.h" | 14 #include "media/base/test_data_util.h" |
| 15 #include "media/ffmpeg/ffmpeg_common.h" | 15 #include "media/ffmpeg/ffmpeg_common.h" |
| 16 #include "media/ffmpeg/ffmpeg_deleters.h" |
| 16 #include "media/filters/in_memory_url_protocol.h" | 17 #include "media/filters/in_memory_url_protocol.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using ::testing::_; | 20 using ::testing::_; |
| 20 using ::testing::DoAll; | 21 using ::testing::DoAll; |
| 21 using ::testing::InSequence; | 22 using ::testing::InSequence; |
| 22 using ::testing::Return; | 23 using ::testing::Return; |
| 23 using ::testing::SetArgumentPointee; | 24 using ::testing::SetArgumentPointee; |
| 24 using ::testing::StrictMock; | 25 using ::testing::StrictMock; |
| 25 | 26 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 228 } |
| 228 | 229 |
| 229 // Ensure destruction release the appropriate resources when OpenContext() is | 230 // Ensure destruction release the appropriate resources when OpenContext() is |
| 230 // called and streams exist. | 231 // called and streams exist. |
| 231 TEST_F(FFmpegGlueDestructionTest, WithOpenWithStreams) { | 232 TEST_F(FFmpegGlueDestructionTest, WithOpenWithStreams) { |
| 232 Initialize("bear-320x240.webm"); | 233 Initialize("bear-320x240.webm"); |
| 233 ASSERT_TRUE(glue_->OpenContext()); | 234 ASSERT_TRUE(glue_->OpenContext()); |
| 234 } | 235 } |
| 235 | 236 |
| 236 // Ensure destruction release the appropriate resources when OpenContext() is | 237 // Ensure destruction release the appropriate resources when OpenContext() is |
| 237 // called and streams have been opened. | 238 // called and streams have been opened. This now requires user of FFmpegGlue to |
| 239 // ensure any allocated AVCodecContext is closed prior to ~FFmpegGlue(). |
| 238 TEST_F(FFmpegGlueDestructionTest, WithOpenWithOpenStreams) { | 240 TEST_F(FFmpegGlueDestructionTest, WithOpenWithOpenStreams) { |
| 239 Initialize("bear-320x240.webm"); | 241 Initialize("bear-320x240.webm"); |
| 240 ASSERT_TRUE(glue_->OpenContext()); | 242 ASSERT_TRUE(glue_->OpenContext()); |
| 241 ASSERT_GT(glue_->format_context()->nb_streams, 0u); | 243 ASSERT_GT(glue_->format_context()->nb_streams, 0u); |
| 242 | 244 |
| 245 // Use ScopedPtrAVFreeContext to ensure |context| is closed, and use scoping |
| 246 // and ordering to ensure |context| is destructed before |glue_|. |
| 243 // Pick the audio stream (1) so this works when the ffmpeg video decoders are | 247 // Pick the audio stream (1) so this works when the ffmpeg video decoders are |
| 244 // disabled. | 248 // disabled. |
| 245 AVCodecContext* context = glue_->format_context()->streams[1]->codec; | 249 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> context( |
| 246 ASSERT_EQ(0, avcodec_open2( | 250 AVStreamToAVCodecContext(glue_->format_context()->streams[1])); |
| 247 context, avcodec_find_decoder(context->codec_id), NULL)); | 251 ASSERT_NE(nullptr, context.get()); |
| 252 ASSERT_EQ(0, avcodec_open2(context.get(), |
| 253 avcodec_find_decoder(context->codec_id), NULL)); |
| 248 } | 254 } |
| 249 | 255 |
| 250 } // namespace media | 256 } // namespace media |
| OLD | NEW |