Commit 5be12bf8 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Revert "Call MFShutdown in places where MFStartup is called"

This reverts commit abf9a1f5.

Reason for revert: Broke tests on Win7 dbg, see linked bug

Original change's description:
> Call MFShutdown in places where MFStartup is called
> 
> Bug: 1012527
> Fixed: 1012527
> Change-Id: Id9ef248aadb0aa24704dec973b60ea23c9e1f1ed
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032332
> Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
> Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#738063}

TBR=xhwang@chromium.org,tmathmeyer@chromium.org

Change-Id: I267213cc06b42769736c7eb337432ade7953de20
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1012527
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036057Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738130}
parent 63f2ddbb
......@@ -25,7 +25,7 @@ class DXGIDeviceScopedHandleTest : public testing::Test {
if (!test_supported_)
return;
ASSERT_NE(nullptr, session_ = InitializeMediaFoundation());
ASSERT_TRUE(InitializeMediaFoundation());
// Get a shared DXGI Device Manager from Media Foundation.
ASSERT_HRESULT_SUCCEEDED(
......@@ -60,7 +60,6 @@ class DXGIDeviceScopedHandleTest : public testing::Test {
}
}
MFSessionLifetime session_;
Microsoft::WRL::ComPtr<IMFDXGIDeviceManager> dxgi_device_man_ = nullptr;
UINT device_reset_token_ = 0;
const bool test_supported_;
......
......@@ -8,19 +8,13 @@
#include "base/logging.h"
#include "base/optional.h"
namespace media {
MFSessionLifetime InitializeMediaFoundation() {
if (MFStartup(MF_VERSION, MFSTARTUP_LITE) == S_OK)
return std::make_unique<MFSession>();
DVLOG(1) << "Media Foundation unavailable or it failed to initialize";
return nullptr;
}
MFSession::~MFSession() {
MFShutdown();
bool InitializeMediaFoundation() {
static const bool success = MFStartup(MF_VERSION, MFSTARTUP_LITE) == S_OK;
DVLOG_IF(1, !success)
<< "Media Foundation unavailable or it failed to initialize";
return success;
}
} // namespace media
......@@ -5,25 +5,15 @@
#ifndef MEDIA_BASE_WIN_MF_INITIALIZER_H_
#define MEDIA_BASE_WIN_MF_INITIALIZER_H_
#include <mfapi.h>
#include "base/logging.h"
#include "media/base/win/mf_initializer_export.h"
namespace media {
// Handy-dandy wrapper struct that kills MediaFoundation on destruction.
struct MF_INITIALIZER_EXPORT MFSession {
~MFSession();
};
using MFSessionLifetime = std::unique_ptr<MFSession>;
// Make sure that MFShutdown is called for each MFStartup that is successful.
// The public documentation stating that it needs to have a corresponding
// shutdown for all startups (even failed ones) is wrong.
MF_INITIALIZER_EXPORT MFSessionLifetime InitializeMediaFoundation()
WARN_UNUSED_RESULT;
// Makes sure MFStartup() is called exactly once. Returns true if Media
// Foundation is available and has been initialized successfully. Note that it
// is expected to return false on an "N" edition of Windows, see
// https://en.wikipedia.org/wiki/Windows_7_editions#Special-purpose_editions.
MF_INITIALIZER_EXPORT bool InitializeMediaFoundation();
} // namespace media
......
......@@ -146,8 +146,10 @@ bool PrepareVideoCaptureAttributesMediaFoundation(
// Once https://bugs.chromium.org/p/chromium/issues/detail?id=791615 is fixed,
// we must make sure that this method succeeds in capture_unittests context
// when MediaFoundation is enabled.
if (!VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation())
if (!VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation() ||
!InitializeMediaFoundation()) {
return false;
}
if (FAILED(MFCreateAttributes(attributes, count)))
return false;
......@@ -380,7 +382,6 @@ VideoCaptureDeviceFactoryWin::VideoCaptureDeviceFactoryWin()
LogVideoCaptureWinBackendUsed(
VideoCaptureWinBackendUsed::kUsingDirectShowAsFallback);
} else if (use_media_foundation_) {
session_ = InitializeMediaFoundation();
LogVideoCaptureWinBackendUsed(
VideoCaptureWinBackendUsed::kUsingMediaFoundationAsDefault);
} else {
......@@ -436,7 +437,6 @@ void VideoCaptureDeviceFactoryWin::GetDeviceDescriptors(
DCHECK(thread_checker_.CalledOnValidThread());
if (use_media_foundation_) {
DCHECK(PlatformSupportsMediaFoundation());
GetDeviceDescriptorsMediaFoundation(device_descriptors);
AugmentDescriptorListWithDirectShowOnlyDevices(device_descriptors);
} else {
......
......@@ -12,7 +12,6 @@
#include "base/macros.h"
#include "base/threading/thread.h"
#include "media/base/win/mf_initializer.h"
#include "media/capture/video/video_capture_device_factory.h"
namespace media {
......@@ -95,7 +94,6 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryWin
VideoCaptureFormats* formats);
bool use_media_foundation_;
MFSessionLifetime session_;
// In production code, when Media Foundation libraries are available,
// |mf_enum_device_sources_func_| points to MFEnumDeviceSources. It enables
// mock of Media Foundation API in unit tests.
......
......@@ -47,6 +47,7 @@
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/win/mf_helpers.h"
#include "media/base/win/mf_initializer.h"
#include "media/filters/vp9_parser.h"
#include "media/gpu/windows/d3d11_video_device_format_support.h"
#include "media/gpu/windows/dxva_picture_buffer_win.h"
......@@ -628,7 +629,7 @@ bool DXVAVideoDecodeAccelerator::Initialize(const Config& config,
RETURN_ON_FAILURE((state == kUninitialized),
"Initialize: invalid state: " << state, false);
RETURN_ON_FAILURE(session_ = InitializeMediaFoundation(),
RETURN_ON_FAILURE(InitializeMediaFoundation(),
"Could not initialize Media Foundartion", false);
config_ = config;
......
......@@ -31,7 +31,6 @@
#include "base/threading/thread.h"
#include "gpu/config/gpu_preferences.h"
#include "media/base/video_color_space.h"
#include "media/base/win/mf_initializer.h"
#include "media/gpu/gpu_video_decode_accelerator_helpers.h"
#include "media/gpu/media_gpu_export.h"
#include "media/gpu/windows/d3d11_com_defs.h"
......@@ -401,9 +400,6 @@ class MEDIA_GPU_EXPORT DXVAVideoDecodeAccelerator
// To expose client callbacks from VideoDecodeAccelerator.
VideoDecodeAccelerator::Client* client_;
// MediaFoundation session, calls MFShutdown on deletion.
MFSessionLifetime session_;
Microsoft::WRL::ComPtr<IMFTransform> decoder_;
Microsoft::WRL::ComPtr<IDirect3D9Ex> d3d9_;
......
......@@ -359,7 +359,7 @@ bool MediaFoundationVideoEncodeAccelerator::CreateHardwareEncoderMFT() {
}
}
if (!(session_ = InitializeMediaFoundation()))
if (!InitializeMediaFoundation())
return false;
uint32_t flags = MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER;
......
......@@ -18,7 +18,6 @@
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "media/base/win/mf_initializer.h"
#include "media/gpu/media_gpu_export.h"
#include "media/video/video_encode_accelerator.h"
......@@ -137,9 +136,6 @@ class MEDIA_GPU_EXPORT MediaFoundationVideoEncodeAccelerator
Microsoft::WRL::ComPtr<IMFSample> input_sample_;
Microsoft::WRL::ComPtr<IMFSample> output_sample_;
// MediaFoundation session.
MFSessionLifetime session_;
// To expose client callbacks from VideoEncodeAccelerator.
// NOTE: all calls to this object *MUST* be executed on
// |main_client_task_runner_|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment