gecko-dev/dom/media/gtest/TestGroupId.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

350 строки
14 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AudioDeviceInfo.h"
#include "MediaManager.h"
#include "gmock/gmock.h"
#include "gtest/gtest-printers.h"
#include "gtest/gtest.h"
#include "mozilla/Attributes.h"
#include "mozilla/UniquePtr.h"
#include "nsTArray.h"
#include "webrtc/MediaEngineSource.h"
using ::testing::Return;
using namespace mozilla;
void PrintTo(const nsString& aValue, ::std::ostream* aStream) {
NS_ConvertUTF16toUTF8 str(aValue);
(*aStream) << str.get();
}
void PrintTo(const nsCString& aValue, ::std::ostream* aStream) {
(*aStream) << aValue.get();
}
class MockMediaEngineSource : public MediaEngineSource {
public:
MOCK_CONST_METHOD0(GetMediaSource, dom::MediaSourceEnum());
/* Unused overrides */
MOCK_CONST_METHOD0(GetName, nsString());
MOCK_CONST_METHOD0(GetUUID, nsCString());
MOCK_CONST_METHOD0(GetGroupId, nsString());
MOCK_CONST_METHOD1(GetSettings, void(dom::MediaTrackSettings&));
MOCK_METHOD4(Allocate, nsresult(const dom::MediaTrackConstraints&,
const MediaEnginePrefs&,
const ipc::PrincipalInfo&, const char**));
Bug 1454998 - Remove the notion of streams from MediaStreamGraph. r=padenot,karlt This change mainly removes the `mTracks` member from MediaStream and moves all associated members up a level, so that a MediaStream in practice represents a single track. Classes will be renamed in a future patch to reflect this. Other changes include: The new `mEnded` member of MediaStream changes meaning to only become true when all data in the stream has been processed. It stems from StreamTracks::Track::mEnded which used to become true as soon as the last bit of data had been added to a track, and there could still be data in the track that would get processed in future iterations. We are moving towards not having any future data in tracks, which is why this change is ok to make -- keeping the old behavior will soon not make sense. TrackUnionStream is changed to no longer take a list of streams as input and forward the union of their tracks to itself. Instead it's limited to having one track as input at a time. The autofinishing functionality that TrackUnionStream had before has been transformed into an autoending functionality to allow it to defer ending until its been told that it's ok to end through the control API. This lets a single TrackUnionStream span the lifetime of multiple inputs, which will be useful for making DecodedStream spec compliant with HTMLMediaElement::CaptureStream(), and for implementing the currently discussed MediaRecorder::ReplaceTrack(), to name a few potential use cases. AudioNodeStreams used to only have a track (and thus an AudioSegment) if the EXTERNAL_OUTPUT flag was enabled on them. With all MediaStreams now representing a track, AudioNodeStreams inherently have an AudioSegment as a member. It is however only used with data if the EXTERNAL_OUTPUT flag is enabled. Differential Revision: https://phabricator.services.mozilla.com/D45821 --HG-- extra : moz-landing-system : lando
2019-10-02 13:22:53 +03:00
MOCK_METHOD2(SetTrack,
Bug 1454998 - Rename streams to tracks. r=padenot,karlt,smaug This renames the following (in alphabetical order, non-exhaustive): AudioCaptureStream -> AudioCaptureTrack AudioNodeStream -> AudioNodeTrack AudioNodeExternalInputStream -> AudioNodeExternalInputTrack DirectMediaStreamTrackListener -> DirectMediaTrackListener MediaStream -> MediaTrack - Note that there's also dom::MediaTrack. Namespaces differentiate them. MediaStreamGraph -> MediaTrackGraph MediaStreamTrackListener -> MediaTrackListener MSG -> MTG (in comments) ProcessedMediaStream -> ProcessedMediaTrack SharedDummyStream -> SharedDummyTrack SourceMediaStream -> SourceMediaTrack StreamTime -> TrackTime TrackUnionStream -> ForwardedInputTrack - Because this no longer takes a union of anything, but only a single track as input. Other minor classes, members and comments have been updated to reflect these name changes. Differential Revision: https://phabricator.services.mozilla.com/D46146 --HG-- rename : dom/media/AudioCaptureStream.cpp => dom/media/AudioCaptureTrack.cpp rename : dom/media/AudioCaptureStream.h => dom/media/AudioCaptureTrack.h rename : dom/media/TrackUnionStream.cpp => dom/media/ForwardedInputTrack.cpp rename : dom/media/TrackUnionStream.h => dom/media/ForwardedInputTrack.h rename : dom/media/MediaStreamGraph.cpp => dom/media/MediaTrackGraph.cpp rename : dom/media/MediaStreamGraph.h => dom/media/MediaTrackGraph.h rename : dom/media/MediaStreamGraphImpl.h => dom/media/MediaTrackGraphImpl.h rename : dom/media/MediaStreamListener.cpp => dom/media/MediaTrackListener.cpp rename : dom/media/MediaStreamListener.h => dom/media/MediaTrackListener.h rename : dom/media/webaudio/AudioNodeExternalInputStream.cpp => dom/media/webaudio/AudioNodeExternalInputTrack.cpp rename : dom/media/webaudio/AudioNodeExternalInputStream.h => dom/media/webaudio/AudioNodeExternalInputTrack.h rename : dom/media/webaudio/AudioNodeStream.cpp => dom/media/webaudio/AudioNodeTrack.cpp rename : dom/media/webaudio/AudioNodeStream.h => dom/media/webaudio/AudioNodeTrack.h extra : moz-landing-system : lando
2019-10-02 13:23:02 +03:00
void(const RefPtr<SourceMediaTrack>&, const PrincipalHandle&));
MOCK_METHOD0(Start, nsresult());
MOCK_METHOD3(Reconfigure, nsresult(const dom::MediaTrackConstraints&,
const MediaEnginePrefs&, const char**));
MOCK_METHOD0(Stop, nsresult());
MOCK_METHOD0(Deallocate, nsresult());
};
RefPtr<AudioDeviceInfo> MakeAudioDeviceInfo(const nsString aName) {
return MakeRefPtr<AudioDeviceInfo>(
nullptr, aName, NS_LITERAL_STRING("GroupId"), NS_LITERAL_STRING("Vendor"),
AudioDeviceInfo::TYPE_OUTPUT, AudioDeviceInfo::STATE_ENABLED,
AudioDeviceInfo::PREF_NONE, AudioDeviceInfo::FMT_F32LE,
AudioDeviceInfo::FMT_F32LE, 2u, 44100u, 44100u, 44100u, 0, 0);
}
RefPtr<MediaDevice> MakeCameraDevice(const nsString& aName,
const nsString& aGroupId) {
auto v = MakeRefPtr<MockMediaEngineSource>();
EXPECT_CALL(*v, GetMediaSource())
.WillRepeatedly(Return(dom::MediaSourceEnum::Camera));
return MakeRefPtr<MediaDevice>(v, aName, NS_LITERAL_STRING(""), aGroupId,
NS_LITERAL_STRING(""));
}
RefPtr<MediaDevice> MakeMicDevice(const nsString& aName,
const nsString& aGroupId) {
auto a = MakeRefPtr<MockMediaEngineSource>();
EXPECT_CALL(*a, GetMediaSource())
.WillRepeatedly(Return(dom::MediaSourceEnum::Microphone));
return MakeRefPtr<MediaDevice>(a, aName, NS_LITERAL_STRING(""), aGroupId,
NS_LITERAL_STRING(""));
}
RefPtr<MediaDevice> MakeSpeakerDevice(const nsString& aName,
const nsString& aGroupId) {
return MakeRefPtr<MediaDevice>(MakeAudioDeviceInfo(aName),
NS_LITERAL_STRING("ID"), aGroupId,
NS_LITERAL_STRING("RawID"));
}
/* Verify that when an audio input device name contains the video input device
* name the video device group id is updated to become equal to the audio
* device group id. */
TEST(TestGroupId, MatchInput_PartOfName)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Cam-Model-GroupId")));
auto mic = MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId"));
devices.AppendElement(mic);
audios.AppendElement(mic);
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, devices[1]->mGroupID)
<< "Video group id is the same as audio input group id.";
}
/* Verify that when an audio input device name is the same as the video input
* device name the video device group id is updated to become equal to the audio
* device group id. */
TEST(TestGroupId, MatchInput_FullName)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Cam-Model-GroupId")));
auto mic = MakeMicDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Mic-Model-GroupId"));
devices.AppendElement(mic);
audios.AppendElement(mic);
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, devices[1]->mGroupID)
<< "Video group id is the same as audio input group id.";
}
/* Verify that when an audio input device name does not contain the video input
* device name the video device group id does not change. */
TEST(TestGroupId, NoMatchInput)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
nsString Cam_Model_GroupId = NS_LITERAL_STRING("Cam-Model-GroupId");
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"), Cam_Model_GroupId));
audios.AppendElement(MakeMicDevice(NS_LITERAL_STRING("Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, Cam_Model_GroupId)
<< "Video group id has not been updated.";
EXPECT_NE(devices[0]->mGroupID, audios[0]->mGroupID)
<< "Video group id is different than audio input group id.";
}
/* Verify that when more that one audio input and more than one audio output
* device name contain the video input device name the video device group id
* does not change. */
TEST(TestGroupId, NoMatch_TwoIdenticalDevices)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
nsString Cam_Model_GroupId = NS_LITERAL_STRING("Cam-Model-GroupId");
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"), Cam_Model_GroupId));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, Cam_Model_GroupId)
<< "Video group id has not been updated.";
EXPECT_NE(devices[0]->mGroupID, audios[0]->mGroupID)
<< "Video group id is different from audio input group id.";
EXPECT_NE(devices[0]->mGroupID, audios[2]->mGroupID)
<< "Video group id is different from audio output group id.";
}
/* Verify that when more that one audio input device name contain the video
* input device name the video device group id is not updated by audio input
* device group id but it continues looking at audio output devices where it
* finds a match so video input group id is updated by audio output group id. */
TEST(TestGroupId, Match_TwoIdenticalInputsMatchOutput)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
nsString Cam_Model_GroupId = NS_LITERAL_STRING("Cam-Model-GroupId");
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"), Cam_Model_GroupId));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, audios[2]->mGroupID)
<< "Video group id is the same as audio output group id.";
}
/* Verify that when more that one audio input and more than one audio output
* device names contain the video input device name the video device group id
* does not change. */
TEST(TestGroupId, NoMatch_ThreeIdenticalDevices)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
nsString Cam_Model_GroupId = NS_LITERAL_STRING("Cam-Model-GroupId");
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"), Cam_Model_GroupId));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, Cam_Model_GroupId)
<< "Video group id has not been updated.";
EXPECT_NE(devices[0]->mGroupID, audios[0]->mGroupID)
<< "Video group id is different from audio input group id.";
EXPECT_NE(devices[0]->mGroupID, audios[3]->mGroupID)
<< "Video group id is different from audio output group id.";
}
/* Verify that when an audio output device name contains the video input device
* name the video device group id is updated to become equal to the audio
* device group id. */
TEST(TestGroupId, MatchOutput)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Cam-Model-GroupId")));
audios.AppendElement(MakeMicDevice(NS_LITERAL_STRING("Mic Analog Stereo"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model Analog Stereo"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, audios[1]->mGroupID)
<< "Video group id is the same as audio output group id.";
}
/* Verify that when an audio input device name is the same as audio output
* device and video input device name the video device group id is updated to
* become equal to the audio input device group id. */
TEST(TestGroupId, InputOutputSameName)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Cam-Model-GroupId")));
audios.AppendElement(MakeMicDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Mic-Model-GroupId")));
audios.AppendElement(
MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Speaker-Model-GroupId")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, audios[0]->mGroupID)
<< "Video input group id is the same as audio input group id.";
}
/* Verify that when an audio input device name contains the video input device
* and the audio input group id is an empty string, the video device group id
* is updated to become equal to the audio device group id. */
TEST(TestGroupId, InputEmptyGroupId)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Cam-Model-GroupId")));
audios.AppendElement(
MakeMicDevice(NS_LITERAL_STRING("Vendor Model"), NS_LITERAL_STRING("")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, audios[0]->mGroupID)
<< "Video input group id is the same as audio input group id.";
}
/* Verify that when an audio output device name contains the video input device
* and the audio output group id is an empty string, the video device group id
* is updated to become equal to the audio output device group id. */
TEST(TestGroupId, OutputEmptyGroupId)
{
MediaManager::MediaDeviceSet devices;
MediaManager::MediaDeviceSet audios;
devices.AppendElement(
MakeCameraDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("Cam-Model-GroupId")));
audios.AppendElement(MakeSpeakerDevice(NS_LITERAL_STRING("Vendor Model"),
NS_LITERAL_STRING("")));
MediaManager::GuessVideoDeviceGroupIDs(devices, audios);
EXPECT_EQ(devices[0]->mGroupID, audios[0]->mGroupID)
<< "Video input group id is the same as audio output group id.";
}