2017-10-02 22:59:05 +00:00
|
|
|
/*
|
Version 1.12 alexa-client-sdk
Changes in this update:
**Enhancements**
* Support was added for the `fr_CA` locale.
* The Executor has been optimized to run a single thread when there are active job in the queue, and to remain idle when there are not active jobs.
* An additional parameter of `alertType` has been added to the Alerts capability agent. This will allow observers of alerts to know the type of alert being delivered.
* Support for programmatic unload and load of PulseAudio Bluetooth modules was added. To enable this feature, there is a [new CMake option](https://github.com/alexa/avs-device-sdk/wiki/CMake-parameters#bluetooth): `BLUETOOTH_BLUEZ_PULSEAUDIO_OVERRIDE_ENDPOINTS`. Note that [libpulse-dev is a required dependency](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#bluetooth) of this feature.
* An observer interface was added for when an active Bluetooth device connects and disconnects.
* The `BluetoothDeviceManagerInterface` instantiation was moved from `DefaultClient` to `SampleApp` to allow applications to override it.
* The `MediaPlayerInterface` now supports repeating playback of URL sources.
* The Kitt.AI wake word engine (WWE) is now compatible with GCC5+.
* Stop of ongoing alerts, management of MessageObservers, and management of CallStateObservers have been exposed through DefaultClient.
**Bug Fixes**
* [Issue 953](https://github.com/alexa/avs-device-sdk/issues/953) - The `MediaPlayerInterface` requirement that callbacks not be made upon a callers thread has been removed.
* [Issue 1136](https://github.com/alexa/avs-device-sdk/issues/1136) - Added a missing default virtual destructor.
* [Issue 1140](https://github.com/alexa/avs-device-sdk/issues/1140) - Fixed an issue where DND states were not synchronized to the AVS cloud after device reset.
* [Issue 1143](https://github.com/alexa/avs-device-sdk/issues/1143) - Fixed an issue in which the SpeechSynthesizer couldn't enter a sleeping state.
* [Issue 1183](https://github.com/alexa/avs-device-sdk/issues/1183) - Fixed an issue where alarm is not sounding for certain timezones
* Changing an alert's volume from the Alexa app now works when an alert is playing.
* Added missing shutdown handling for ContentDecrypter to prevent the `Stop` command from triggering a crash when SAMPLE-AES encrypted content was streaming.
* Fixed a bug where if the Notifications database is empty, due to a crash or corruption, the SDK initialization process enters an infinite loop when it retries to get context from the Notifications capability agent.
* Fixed a race condition that caused `AlertsRenderer` observers to miss notification that an alert has been completed.
**Known Issues**
* `PlaylistParser` and `IterativePlaylistParser` generate two HTTP requests (one to fetch the content type, and one to fetch the audio data) for each audio stream played.
* Music playback history isn't being displayed in the Alexa app for certain account and device types.
* On GCC 8+, issues related to `-Wclass-memaccess` will trigger warnings. However, this won't cause the build to fail and these warnings can be ignored.
* Android error ("libDefaultClient.so" not found) can be resolved by upgrading to ADB version 1.0.40
* When network connection is lost, lost connection status is not returned via local TTS.
* `ACL` may encounter issues if audio attachments are received but not consumed.
* `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release.
* The Alexa app doesn't always indicate when a device is successfully connected via Bluetooth.
* Connecting a product to streaming media via Bluetooth will sometimes stop media playback within the source application. Resuming playback through the source application or toggling next/previous will correct playback.
* When a source device is streaming silence via Bluetooth, the Alexa app indicates that audio content is streaming.
* The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation is not yet supported.
* On some products, interrupted Bluetooth playback may not resume if other content is locally streamed.
* `make integration` is currently not available for Android. In order to run integration tests on Android, you'll need to manually upload the test binary file along with any input file. At that point, the adb can be used to run the integration tests.
* On Raspberry Pi running Android Things with HDMI output audio, beginning of speech is truncated when Alexa responds to user text-to-speech (TTS).
* When the sample app is restarted and network connection is lost, Reminder TTS does not play. Instead, the default alarm tone will play twice.
2019-02-26 00:45:37 +00:00
|
|
|
* Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2017-10-02 22:59:05 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
* A copy of the License is located at
|
|
|
|
*
|
|
|
|
* http://aws.amazon.com/apache2.0/
|
|
|
|
*
|
|
|
|
* or in the "license" file accompanying this file. This file is distributed
|
|
|
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
|
* express or implied. See the License for the specific language governing
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// @file AudioPlayerTest.cpp
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <future>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include <rapidjson/error/en.h>
|
|
|
|
#include <rapidjson/stringbuffer.h>
|
|
|
|
#include <rapidjson/writer.h>
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
#include <AVSCommon/Utils/Logger/ConsoleLogger.h>
|
2017-10-02 22:59:05 +00:00
|
|
|
#include <AVSCommon/Utils/JSON/JSONUtils.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockExceptionEncounteredSender.h>
|
|
|
|
#include <AVSCommon/AVS/Attachment/AttachmentManagerInterface.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockContextManager.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockDirectiveSequencer.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockDirectiveHandlerResult.h>
|
2018-01-12 23:45:42 +00:00
|
|
|
#include <AVSCommon/SDKInterfaces/MockFocusManager.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockMessageSender.h>
|
|
|
|
#include <AVSCommon/SDKInterfaces/MockPlaybackRouter.h>
|
2017-10-02 22:59:05 +00:00
|
|
|
#include <AVSCommon/AVS/Attachment/AttachmentManager.h>
|
2017-10-30 22:14:38 +00:00
|
|
|
#include <AVSCommon/Utils/Memory/Memory.h>
|
|
|
|
#include <AVSCommon/Utils/MediaPlayer/MockMediaPlayer.h>
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
#include "AudioPlayer/AudioPlayer.h"
|
|
|
|
|
|
|
|
namespace alexaClientSDK {
|
|
|
|
namespace capabilityAgents {
|
|
|
|
namespace audioPlayer {
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
using namespace avsCommon::utils::json;
|
|
|
|
using namespace avsCommon::utils;
|
|
|
|
using namespace avsCommon;
|
|
|
|
using namespace avsCommon::avs;
|
|
|
|
using namespace avsCommon::avs::attachment;
|
|
|
|
using namespace avsCommon::sdkInterfaces;
|
|
|
|
using namespace avsCommon::sdkInterfaces::test;
|
|
|
|
using namespace avsCommon::utils::mediaPlayer;
|
2017-10-30 22:14:38 +00:00
|
|
|
using namespace avsCommon::utils::memory;
|
|
|
|
using namespace avsCommon::utils::mediaPlayer::test;
|
2017-10-02 22:59:05 +00:00
|
|
|
using namespace ::testing;
|
|
|
|
using namespace rapidjson;
|
|
|
|
|
|
|
|
/// Plenty of time for a test to complete.
|
|
|
|
static std::chrono::milliseconds WAIT_TIMEOUT(1000);
|
|
|
|
|
|
|
|
/// The name of the @c FocusManager channel used by the @c AudioPlayer.
|
2018-03-09 00:55:39 +00:00
|
|
|
static const std::string CHANNEL_NAME(avsCommon::sdkInterfaces::FocusManagerInterface::CONTENT_CHANNEL_NAME);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
/// Namespace for AudioPlayer.
|
|
|
|
static const std::string NAMESPACE_AUDIO_PLAYER("AudioPlayer");
|
|
|
|
|
|
|
|
/// Name for AudioPlayer Play directive.
|
|
|
|
static const std::string NAME_PLAY("Play");
|
|
|
|
|
|
|
|
/// Name for AudioPlayer Stop directive.
|
|
|
|
static const std::string NAME_STOP("Stop");
|
|
|
|
|
|
|
|
/// Name for AudioPlayer ClearQueue directive.
|
|
|
|
static const std::string NAME_CLEARQUEUE("ClearQueue");
|
|
|
|
|
|
|
|
/// The @c NamespaceAndName to send to the @c ContextManager.
|
|
|
|
static const NamespaceAndName NAMESPACE_AND_NAME_PLAYBACK_STATE{NAMESPACE_AUDIO_PLAYER, "PlaybackState"};
|
|
|
|
|
|
|
|
/// Message Id for testing.
|
|
|
|
static const std::string MESSAGE_ID_TEST("MessageId_Test");
|
|
|
|
|
|
|
|
/// Another message Id for testing.
|
|
|
|
static const std::string MESSAGE_ID_TEST_2("MessageId_Test2");
|
|
|
|
|
|
|
|
/// PlayRequestId for testing.
|
|
|
|
static const std::string PLAY_REQUEST_ID_TEST("PlayRequestId_Test");
|
|
|
|
|
|
|
|
/// Context ID for testing
|
|
|
|
static const std::string CONTEXT_ID_TEST("ContextId_Test");
|
|
|
|
|
|
|
|
/// Context ID for testing
|
|
|
|
static const std::string CONTEXT_ID_TEST_2("ContextId_Test2");
|
|
|
|
|
|
|
|
/// Token for testing.
|
|
|
|
static const std::string TOKEN_TEST("Token_Test");
|
|
|
|
|
|
|
|
/// Previous token for testing.
|
|
|
|
static const std::string PREV_TOKEN_TEST("Prev_Token_Test");
|
|
|
|
|
|
|
|
/// Format of the audio.
|
|
|
|
static const std::string FORMAT_TEST("AUDIO_MPEG");
|
|
|
|
|
|
|
|
/// URL for testing.
|
|
|
|
static const std::string URL_TEST("cid:Test");
|
|
|
|
|
|
|
|
/// ENQUEUE playBehavior.
|
|
|
|
static const std::string NAME_ENQUEUE("ENQUEUE");
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
/// REPLACE_ALL playBehavior.
|
|
|
|
static const std::string NAME_REPLACE_ALL("REPLACE_ALL");
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/// CLEAR_ALL clearBehavior.
|
|
|
|
static const std::string NAME_CLEAR_ALL("CLEAR_ALL");
|
|
|
|
|
|
|
|
/// audioItemId for testing.
|
2017-12-09 00:07:37 +00:00
|
|
|
static const std::string AUDIO_ITEM_ID_1("testID1");
|
|
|
|
static const std::string AUDIO_ITEM_ID_2("testID2");
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
/// The @c FINISHED state of the @c AudioPlayer.
|
|
|
|
static const std::string FINISHED_STATE("FINISHED");
|
|
|
|
|
|
|
|
/// The @c PLAYING state of the @c AudioPlayer
|
|
|
|
static const std::string PLAYING_STATE{"PLAYING"};
|
|
|
|
|
|
|
|
/// The @c IDLE state of the @c AudioPlayer
|
|
|
|
static const std::string IDLE_STATE{"IDLE"};
|
|
|
|
|
|
|
|
/// The offset in milliseconds returned by the mock media player.
|
|
|
|
static const long OFFSET_IN_MILLISECONDS_TEST{100};
|
|
|
|
|
|
|
|
/// ExpiryTime for testing. Needs to be in ISO 8601 format.
|
|
|
|
static const std::string EXPIRY_TEST("481516234248151623421088");
|
|
|
|
|
|
|
|
/// progressReportDelayInMilliseconds for testing.
|
|
|
|
static const long PROGRESS_REPORT_DELAY{200};
|
|
|
|
|
|
|
|
/// progressReportIntervalInMilliseconds for testing.
|
|
|
|
static const long PROGRESS_REPORT_INTERVAL{100};
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
/// The offset in milliseconds returned by the mock media player slightly before the progressReportDelayInMilliseconds.
|
|
|
|
static const long OFFSET_IN_MILLISECONDS_BEFORE_PROGRESS_REPORT_DELAY{PROGRESS_REPORT_DELAY - 1};
|
|
|
|
|
|
|
|
/// The offset in milliseconds returned by the mock media player slightly before the progressReportDelayInMilliseconds.
|
|
|
|
static const long OFFSET_IN_MILLISECONDS_AFTER_PROGRESS_REPORT_DELAY{PROGRESS_REPORT_DELAY + 1};
|
|
|
|
|
|
|
|
/// The offset in milliseconds returned by the mock media player slightly before the
|
|
|
|
/// progressReportIntervalInMilliseconds.
|
|
|
|
static const long OFFSET_IN_MILLISECONDS_BEFORE_PROGRESS_REPORT_INTERVAL{PROGRESS_REPORT_INTERVAL - 1};
|
|
|
|
|
|
|
|
/// The offset in milliseconds returned by the mock media player slightly before the
|
|
|
|
/// progressReportIntervalInMilliseconds.
|
|
|
|
static const long OFFSET_IN_MILLISECONDS_AFTER_PROGRESS_REPORT_INTERVAL{PROGRESS_REPORT_INTERVAL + 1};
|
|
|
|
|
|
|
|
/// The time that must elapse in order to get 2.5 interval periods
|
|
|
|
static const std::chrono::milliseconds TIME_FOR_TWO_AND_A_HALF_INTERVAL_PERIODS{
|
|
|
|
std::chrono::milliseconds((2 * PROGRESS_REPORT_INTERVAL) + (PROGRESS_REPORT_INTERVAL / 2))};
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
/// Payloads for testing.
|
2018-02-12 23:31:53 +00:00
|
|
|
static std::string createEnqueuePayloadTest(long offsetInMilliseconds) {
|
|
|
|
// clang-format off
|
|
|
|
const std::string ENQUEUE_PAYLOAD_TEST =
|
2017-10-02 22:59:05 +00:00
|
|
|
"{"
|
|
|
|
"\"playBehavior\":\"" + NAME_ENQUEUE + "\","
|
|
|
|
"\"audioItem\": {"
|
2017-12-09 00:07:37 +00:00
|
|
|
"\"audioItemId\":\"" + AUDIO_ITEM_ID_1 + "\","
|
2017-10-02 22:59:05 +00:00
|
|
|
"\"stream\": {"
|
|
|
|
"\"url\":\"" + URL_TEST + "\","
|
|
|
|
"\"streamFormat\":\"" + FORMAT_TEST + "\","
|
2018-02-12 23:31:53 +00:00
|
|
|
"\"offsetInMilliseconds\":" + std::to_string(offsetInMilliseconds) + ","
|
2017-10-02 22:59:05 +00:00
|
|
|
"\"expiryTime\":\"" + EXPIRY_TEST + "\","
|
|
|
|
"\"progressReport\": {"
|
|
|
|
"\"progressReportDelayInMilliseconds\":" + std::to_string(PROGRESS_REPORT_DELAY) + ","
|
|
|
|
"\"progressReportIntervalInMilliseconds\":" + std::to_string(PROGRESS_REPORT_INTERVAL) +
|
|
|
|
"},"
|
|
|
|
"\"token\":\"" + TOKEN_TEST + "\","
|
|
|
|
"\"expectedPreviousToken\":\"\""
|
|
|
|
"}"
|
|
|
|
"}"
|
|
|
|
"}";
|
2018-02-12 23:31:53 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
return ENQUEUE_PAYLOAD_TEST;
|
|
|
|
}
|
2017-12-09 00:07:37 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
// clang-format off
|
2017-12-09 00:07:37 +00:00
|
|
|
static const std::string REPLACE_ALL_PAYLOAD_TEST =
|
|
|
|
"{"
|
|
|
|
"\"playBehavior\":\"" + NAME_REPLACE_ALL + "\","
|
|
|
|
"\"audioItem\": {"
|
|
|
|
"\"audioItemId\":\"" + AUDIO_ITEM_ID_2 + "\","
|
|
|
|
"\"stream\": {"
|
|
|
|
"\"url\":\"" + URL_TEST + "\","
|
|
|
|
"\"streamFormat\":\"" + FORMAT_TEST + "\","
|
|
|
|
"\"offsetInMilliseconds\":" + std::to_string(OFFSET_IN_MILLISECONDS_TEST) + ","
|
|
|
|
"\"expiryTime\":\"" + EXPIRY_TEST + "\","
|
|
|
|
"\"progressReport\": {"
|
|
|
|
"\"progressReportDelayInMilliseconds\":" + std::to_string(PROGRESS_REPORT_DELAY) + ","
|
|
|
|
"\"progressReportIntervalInMilliseconds\":" + std::to_string(PROGRESS_REPORT_INTERVAL) +
|
|
|
|
"},"
|
|
|
|
"\"token\":\"" + TOKEN_TEST + "\","
|
|
|
|
"\"expectedPreviousToken\":\"\""
|
|
|
|
"}"
|
|
|
|
"}"
|
|
|
|
"}";
|
2017-10-02 22:59:05 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
/// Empty payload for testing.
|
|
|
|
static const std::string EMPTY_PAYLOAD_TEST = "{}";
|
|
|
|
|
|
|
|
/// CLEAR_ALL payload for testing.
|
|
|
|
// clang-format off
|
|
|
|
static const std::string CLEAR_ALL_PAYLOAD_TEST =
|
|
|
|
"{"
|
|
|
|
"\"clearBehavior\":\"" + NAME_CLEAR_ALL + "\""
|
|
|
|
"}";
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
/// Token JSON key.
|
|
|
|
static const std::string TOKEN_KEY = "token";
|
|
|
|
|
|
|
|
/// Offset JSON key.
|
|
|
|
static const std::string OFFSET_KEY = "offsetInMilliseconds";
|
|
|
|
|
|
|
|
/// Player activity JSON key.
|
|
|
|
static const std::string ACTIVITY_KEY = "playerActivity";
|
|
|
|
|
|
|
|
/// The expected state when the @c AudioPlayer is not handling any directive.
|
|
|
|
// clang-format off
|
|
|
|
static const std::string IDLE_STATE_TEST =
|
|
|
|
"{"
|
|
|
|
"\"token\":\"\","
|
|
|
|
"\"offsetInMilliseconds\":" + std::to_string(0) + ","
|
|
|
|
"\"playerActivity\":\"" + IDLE_STATE + "\""
|
|
|
|
"}";
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
/// Provide State Token for testing.
|
|
|
|
static const unsigned int PROVIDE_STATE_TOKEN_TEST{1};
|
|
|
|
|
|
|
|
/// JSON key for the event section of a message.
|
|
|
|
static const std::string MESSAGE_EVENT_KEY = "event";
|
|
|
|
|
|
|
|
/// JSON key for the header section of a message.
|
|
|
|
static const std::string MESSAGE_HEADER_KEY = "header";
|
|
|
|
|
|
|
|
/// JSON key for the name section of a message.
|
|
|
|
static const std::string MESSAGE_NAME_KEY = "name";
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// JSON key for the payload section of a message.
|
|
|
|
static const std::string MESSAGE_PAYLOAD_KEY = "payload";
|
|
|
|
|
|
|
|
/// JSON key for the metadata section of a message.
|
|
|
|
static const std::string MESSAGE_METADATA_KEY = "metadata";
|
|
|
|
|
|
|
|
/// JSON key for "string" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_STRING_KEY = "StringKey";
|
|
|
|
|
|
|
|
/// JSON value for "string" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_STRING_VALUE = "StringValue";
|
|
|
|
|
|
|
|
/// JSON key for "uint" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_UINT_KEY = "UintKey";
|
|
|
|
|
|
|
|
/// JSON value for "uint" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_UINT_VALUE = "12345";
|
|
|
|
|
|
|
|
/// JSON key for "int" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_INT_KEY = "IntKey";
|
|
|
|
|
|
|
|
/// JSON value for "int" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_INT_VALUE = "67890";
|
|
|
|
|
|
|
|
/// JSON key for "double" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_DOUBLE_KEY = "DoubleKey";
|
|
|
|
|
|
|
|
/// JSON value for "double" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_DOUBLE_VALUE = "3.14";
|
|
|
|
|
|
|
|
/// JSON key for "boolean" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_BOOLEAN_KEY = "BooleanKey";
|
|
|
|
|
|
|
|
/// JSON value for "boolean" type field in metadata section of StreamMetadataExtracted event.
|
|
|
|
static const std::string MESSAGE_METADATA_BOOLEAN_VALUE = "true";
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/// Name of PlaybackStarted event
|
|
|
|
static const std::string PLAYBACK_STARTED_NAME = "PlaybackStarted";
|
|
|
|
|
|
|
|
/// Name of PlaybackNearlyFinished event
|
|
|
|
static const std::string PLAYBACK_NEARLY_FINISHED_NAME = "PlaybackNearlyFinished";
|
|
|
|
|
|
|
|
/// Name of PlaybackFinished event
|
|
|
|
static const std::string PLAYBACK_FINISHED_NAME = "PlaybackFinished";
|
|
|
|
|
|
|
|
/// Name of PlaybackStopped event
|
|
|
|
static const std::string PLAYBACK_STOPPED_NAME = "PlaybackStopped";
|
|
|
|
|
|
|
|
/// Name of PlaybackPaused event
|
|
|
|
static const std::string PLAYBACK_PAUSED_NAME = "PlaybackPaused";
|
|
|
|
|
|
|
|
/// Name of PlaybackFailed event
|
|
|
|
static const std::string PLAYBACK_FAILED_NAME = "PlaybackFailed";
|
|
|
|
|
|
|
|
/// Name of PlaybackResumed event
|
|
|
|
static const std::string PLAYBACK_RESUMED_NAME = "PlaybackResumed";
|
|
|
|
|
|
|
|
/// Name of PlaybackStutterStarted event
|
|
|
|
static const std::string PLAYBACK_STUTTER_STARTED_NAME = "PlaybackStutterStarted";
|
|
|
|
|
|
|
|
/// Name of PlaybackStutterFinished event
|
|
|
|
static const std::string PLAYBACK_STUTTER_FINISHED_NAME = "PlaybackStutterFinished";
|
|
|
|
|
|
|
|
/// Name of ProgressReportDelayElapsed event
|
|
|
|
static const std::string PROGRESS_REPORT_DELAY_ELAPSED_NAME = "ProgressReportDelayElapsed";
|
|
|
|
|
|
|
|
/// Name of ProgressReportIntervalElapsed event
|
|
|
|
static const std::string PROGRESS_REPORT_INTERVAL_ELAPSED_NAME = "ProgressReportIntervalElapsed";
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// Name of StreamMetadataExtracted event
|
|
|
|
static const std::string STREAM_METADATA_EXTRACTED_NAME = "StreamMetadataExtracted";
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/// String to identify log entries originating from this file.
|
|
|
|
static const std::string TAG("AudioPlayerTest");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a LogEntry using this file's TAG and the specified event string.
|
|
|
|
*
|
|
|
|
* @param The event string for this @c LogEntry.
|
|
|
|
*/
|
|
|
|
#define LX(event) alexaClientSDK::avsCommon::utils::logger::LogEntry(TAG, event)
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
class TestAudioPlayerObserver : public AudioPlayerObserverInterface {
|
2017-10-02 22:59:05 +00:00
|
|
|
public:
|
2017-10-30 22:14:38 +00:00
|
|
|
TestAudioPlayerObserver() : m_state{PlayerActivity::IDLE} {
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
2017-10-30 22:14:38 +00:00
|
|
|
bool waitFor(PlayerActivity activity, std::chrono::milliseconds timeout) {
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
return m_conditionVariable.wait_for(lock, timeout, [this, activity] { return m_state == activity; });
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
2017-10-30 22:14:38 +00:00
|
|
|
void onPlayerActivityChanged(avsCommon::avs::PlayerActivity state, const Context& context) override {
|
|
|
|
ACSDK_DEBUG(
|
|
|
|
LX("onPlayerActivityChanged")
|
|
|
|
.d("state", state)
|
|
|
|
.d("audioItemId", context.audioItemId)
|
|
|
|
.d("offsetInMs", std::chrono::duration_cast<std::chrono::milliseconds>(context.offset).count()));
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
m_state = state;
|
|
|
|
m_conditionVariable.notify_all();
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
private:
|
|
|
|
PlayerActivity m_state;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
std::condition_variable m_conditionVariable;
|
|
|
|
};
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
class AudioPlayerTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
AudioPlayerTest();
|
|
|
|
|
|
|
|
void SetUp() override;
|
|
|
|
void TearDown() override;
|
|
|
|
|
|
|
|
/// @c AudioPlayer to test
|
|
|
|
std::shared_ptr<AudioPlayer> m_audioPlayer;
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// @c A test observer to wait for @c AudioPlayer state changes
|
|
|
|
std::shared_ptr<TestAudioPlayerObserver> m_testAudioPlayerObserver;
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/// Player to send the audio to.
|
|
|
|
std::shared_ptr<MockMediaPlayer> m_mockMediaPlayer;
|
|
|
|
|
|
|
|
/// @c ContextManager to provide state and update state.
|
|
|
|
std::shared_ptr<MockContextManager> m_mockContextManager;
|
|
|
|
|
|
|
|
/// @c FocusManager to request focus to the DIALOG channel.
|
|
|
|
std::shared_ptr<MockFocusManager> m_mockFocusManager;
|
|
|
|
|
|
|
|
/// A directive handler result to send the result to.
|
|
|
|
std::unique_ptr<MockDirectiveHandlerResult> m_mockDirectiveHandlerResult;
|
|
|
|
|
|
|
|
/// A message sender used to send events to AVS.
|
|
|
|
std::shared_ptr<MockMessageSender> m_mockMessageSender;
|
|
|
|
|
|
|
|
/// An exception sender used to send exception encountered events to AVS.
|
|
|
|
std::shared_ptr<MockExceptionEncounteredSender> m_mockExceptionSender;
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
/// A playback router to notify when @c AudioPlayer becomes active.
|
|
|
|
std::shared_ptr<MockPlaybackRouter> m_mockPlaybackRouter;
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/// Attachment manager used to create a reader.
|
|
|
|
std::shared_ptr<AttachmentManager> m_attachmentManager;
|
|
|
|
|
|
|
|
/// Map for expected messages testing
|
2018-02-12 23:31:53 +00:00
|
|
|
std::map<std::string, int> m_expectedMessages;
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/// Identifier for the currently selected audio source.
|
|
|
|
MediaPlayerInterface::SourceId m_sourceId;
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/**
|
|
|
|
* This is invoked in response to a @c setState call.
|
|
|
|
*
|
|
|
|
* @return @c SUCCESS.
|
|
|
|
*/
|
|
|
|
SetStateResult wakeOnSetState();
|
|
|
|
|
|
|
|
/// Promise to be fulfilled when @c setState is called.
|
|
|
|
std::promise<void> m_wakeSetStatePromise;
|
|
|
|
|
|
|
|
/// Future to notify when @c setState is called.
|
|
|
|
std::future<void> m_wakeSetStateFuture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is invoked in response to a @c acquireChannel call.
|
|
|
|
*
|
|
|
|
* @return @c true
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool wakeOnAcquireChannel();
|
|
|
|
|
|
|
|
/// Promise to be fulfilled when @c acquireChannel is called.
|
|
|
|
std::promise<void> m_wakeAcquireChannelPromise;
|
|
|
|
|
|
|
|
/// Future to notify when @c acquireChannel is called.
|
|
|
|
std::future<void> m_wakeAcquireChannelFuture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is invoked in response to a @c releaseChannel call.
|
|
|
|
*
|
|
|
|
* @return @c true
|
|
|
|
*/
|
|
|
|
std::future<bool> wakeOnReleaseChannel();
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
/// Promise to be fulfilled when @c acquireChannel is called.
|
|
|
|
std::promise<void> m_wakeReleaseChannelPromise;
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/// Future to notify when @c releaseChannel is called.
|
|
|
|
std::future<void> m_wakeReleaseChannelFuture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fulfills the @c m_wakeSendMessagePromise. This is invoked in response to a @c sendMessage call.
|
|
|
|
*/
|
|
|
|
void wakeOnSendMessage();
|
|
|
|
|
|
|
|
/// Promise to be fulfilled when @c sendMessage is called.
|
|
|
|
std::promise<void> m_wakeSendMessagePromise;
|
|
|
|
|
|
|
|
/// Future to notify when @c sendMessage is called.
|
|
|
|
std::future<void> m_wakeSendMessageFuture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Consolidate code to send Play directive.
|
2018-02-12 23:31:53 +00:00
|
|
|
*
|
|
|
|
* @param offsetInMilliseconds The offset to use in the directive.
|
2017-10-02 22:59:05 +00:00
|
|
|
*/
|
2018-02-12 23:31:53 +00:00
|
|
|
void sendPlayDirective(long offsetInMilliseconds = OFFSET_IN_MILLISECONDS_TEST);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Consolidate code to send ClearQueue directive
|
|
|
|
*/
|
|
|
|
|
|
|
|
void sendClearQueueDirective();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that the message name matches the expected name
|
|
|
|
*
|
|
|
|
* @param request The @c MessageRequest to verify
|
|
|
|
* @param expectedName The expected name to find in the json header
|
|
|
|
*/
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
bool verifyMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request, std::string expectedName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that the sent request matches one in a Map of expectedMessages
|
|
|
|
*
|
|
|
|
* @param request The @c MessageRequest to verify
|
2018-02-12 23:31:53 +00:00
|
|
|
* @param expectedMessages The map of expected messages and a count of how many are seen
|
2017-10-30 22:14:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void verifyMessageMap(
|
2017-10-02 22:59:05 +00:00
|
|
|
std::shared_ptr<avsCommon::avs::MessageRequest> request,
|
2018-02-12 23:31:53 +00:00
|
|
|
std::map<std::string, int>* expectedMessages);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-30 22:14:38 +00:00
|
|
|
* Verify that the provided state matches the expected state
|
2017-10-02 22:59:05 +00:00
|
|
|
*
|
|
|
|
* @param jsonState The state to verify
|
|
|
|
* @param expectedState The expected state
|
|
|
|
*/
|
|
|
|
|
|
|
|
void verifyState(const std::string& providedState, const std::string& expectedState);
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
|
|
|
* Verify that the message name matches the expected name and also verify expected tags.
|
|
|
|
*
|
|
|
|
* @param request The @c MessageRequest to verify
|
2018-02-12 23:31:53 +00:00
|
|
|
* @param expectedMessages Map of expected tags and count of how many are seen.
|
2017-10-30 22:14:38 +00:00
|
|
|
*/
|
|
|
|
void verifyTags(
|
|
|
|
std::shared_ptr<avsCommon::avs::MessageRequest> request,
|
2018-02-12 23:31:53 +00:00
|
|
|
std::map<std::string, int>* expectedMessages);
|
2017-10-30 22:14:38 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
/// General purpose mutex.
|
|
|
|
std::mutex m_mutex;
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
/// Condition variable to wake on a message being sent.
|
|
|
|
std::condition_variable m_messageSentTrigger;
|
|
|
|
|
|
|
|
/// Condition variable to wake on MediaPlayer calls. This is used when a MediaPlayer call is expected to occur
|
|
|
|
/// without a corresponding change in PlayerActivity.
|
|
|
|
std::condition_variable m_mediaPlayerCallTrigger;
|
2017-10-02 22:59:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AudioPlayerTest::AudioPlayerTest() :
|
|
|
|
m_wakeSetStatePromise{},
|
|
|
|
m_wakeSetStateFuture{m_wakeSetStatePromise.get_future()},
|
|
|
|
m_wakeAcquireChannelPromise{},
|
|
|
|
m_wakeAcquireChannelFuture{m_wakeAcquireChannelPromise.get_future()},
|
2017-12-09 00:07:37 +00:00
|
|
|
m_wakeReleaseChannelPromise{},
|
|
|
|
m_wakeReleaseChannelFuture{m_wakeReleaseChannelPromise.get_future()},
|
2017-10-02 22:59:05 +00:00
|
|
|
m_wakeSendMessagePromise{},
|
|
|
|
m_wakeSendMessageFuture{m_wakeSendMessagePromise.get_future()} {
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayerTest::SetUp() {
|
|
|
|
m_mockContextManager = std::make_shared<NiceMock<MockContextManager>>();
|
|
|
|
m_mockFocusManager = std::make_shared<NiceMock<MockFocusManager>>();
|
|
|
|
m_mockMessageSender = std::make_shared<NiceMock<MockMessageSender>>();
|
|
|
|
m_mockExceptionSender = std::make_shared<NiceMock<MockExceptionEncounteredSender>>();
|
|
|
|
m_attachmentManager = std::make_shared<AttachmentManager>(AttachmentManager::AttachmentType::IN_PROCESS);
|
|
|
|
m_mockMediaPlayer = MockMediaPlayer::create();
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockPlaybackRouter = std::make_shared<NiceMock<MockPlaybackRouter>>();
|
2017-10-02 22:59:05 +00:00
|
|
|
m_audioPlayer = AudioPlayer::create(
|
|
|
|
m_mockMediaPlayer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockContextManager,
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockExceptionSender,
|
|
|
|
m_mockPlaybackRouter);
|
2017-10-30 22:14:38 +00:00
|
|
|
m_testAudioPlayerObserver = std::make_shared<TestAudioPlayerObserver>();
|
|
|
|
m_audioPlayer->addObserver(m_testAudioPlayerObserver);
|
|
|
|
m_mockDirectiveHandlerResult = std::unique_ptr<MockDirectiveHandlerResult>(new MockDirectiveHandlerResult);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(m_audioPlayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayerTest::TearDown() {
|
|
|
|
m_audioPlayer->shutdown();
|
2018-02-12 23:31:53 +00:00
|
|
|
m_mockMediaPlayer->shutdown();
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetStateResult AudioPlayerTest::wakeOnSetState() {
|
|
|
|
m_wakeSetStatePromise.set_value();
|
|
|
|
return SetStateResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AudioPlayerTest::wakeOnAcquireChannel() {
|
|
|
|
m_wakeAcquireChannelPromise.set_value();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::future<bool> AudioPlayerTest::wakeOnReleaseChannel() {
|
|
|
|
std::promise<bool> releaseChannelSuccess;
|
|
|
|
std::future<bool> returnValue = releaseChannelSuccess.get_future();
|
|
|
|
releaseChannelSuccess.set_value(true);
|
2017-12-09 00:07:37 +00:00
|
|
|
m_wakeReleaseChannelPromise.set_value();
|
2017-10-02 22:59:05 +00:00
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayerTest::wakeOnSendMessage() {
|
|
|
|
m_wakeSendMessagePromise.set_value();
|
|
|
|
}
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
void AudioPlayerTest::sendPlayDirective(long offsetInMilliseconds) {
|
2017-10-02 22:59:05 +00:00
|
|
|
auto avsMessageHeader =
|
|
|
|
std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_PLAY, MESSAGE_ID_TEST, PLAY_REQUEST_ID_TEST);
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::shared_ptr<AVSDirective> playDirective = AVSDirective::create(
|
|
|
|
"", avsMessageHeader, createEnqueuePayloadTest(offsetInMilliseconds), m_attachmentManager, CONTEXT_ID_TEST);
|
2018-03-09 00:55:39 +00:00
|
|
|
EXPECT_CALL(*(m_mockFocusManager.get()), acquireChannel(CHANNEL_NAME, _, NAMESPACE_AUDIO_PLAYER))
|
2017-10-02 22:59:05 +00:00
|
|
|
.Times(1)
|
|
|
|
.WillOnce(InvokeWithoutArgs(this, &AudioPlayerTest::wakeOnAcquireChannel));
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*m_mockDirectiveHandlerResult, setCompleted());
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(playDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST);
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_EQ(std::future_status::ready, m_wakeAcquireChannelFuture.wait_for(WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayerTest::sendClearQueueDirective() {
|
|
|
|
auto avsClearMessageHeader = std::make_shared<AVSMessageHeader>(
|
|
|
|
NAMESPACE_AUDIO_PLAYER, NAME_CLEARQUEUE, MESSAGE_ID_TEST, PLAY_REQUEST_ID_TEST);
|
|
|
|
|
|
|
|
std::shared_ptr<AVSDirective> clearQueueDirective =
|
|
|
|
AVSDirective::create("", avsClearMessageHeader, CLEAR_ALL_PAYLOAD_TEST, m_attachmentManager, CONTEXT_ID_TEST);
|
|
|
|
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(clearQueueDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST);
|
|
|
|
}
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
bool AudioPlayerTest::verifyMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request, std::string expectedName) {
|
|
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(request->getJsonContent().c_str());
|
|
|
|
EXPECT_FALSE(document.HasParseError())
|
|
|
|
<< "rapidjson detected a parsing error at offset:" + std::to_string(document.GetErrorOffset()) +
|
|
|
|
", error message: " + GetParseError_En(document.GetParseError());
|
|
|
|
|
|
|
|
auto event = document.FindMember(MESSAGE_EVENT_KEY);
|
|
|
|
EXPECT_NE(event, document.MemberEnd());
|
|
|
|
|
|
|
|
auto header = event->value.FindMember(MESSAGE_HEADER_KEY);
|
|
|
|
EXPECT_NE(header, event->value.MemberEnd());
|
|
|
|
|
|
|
|
std::string requestName;
|
|
|
|
jsonUtils::retrieveValue(header->value, MESSAGE_NAME_KEY, &requestName);
|
|
|
|
|
|
|
|
return (requestName == expectedName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayerTest::verifyMessageMap(
|
2017-10-02 22:59:05 +00:00
|
|
|
std::shared_ptr<avsCommon::avs::MessageRequest> request,
|
2018-02-12 23:31:53 +00:00
|
|
|
std::map<std::string, int>* expectedMessages) {
|
2017-10-02 22:59:05 +00:00
|
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(request->getJsonContent().c_str());
|
|
|
|
EXPECT_FALSE(document.HasParseError())
|
|
|
|
<< "rapidjson detected a parsing error at offset:" + std::to_string(document.GetErrorOffset()) +
|
|
|
|
", error message: " + GetParseError_En(document.GetParseError());
|
|
|
|
|
|
|
|
auto event = document.FindMember(MESSAGE_EVENT_KEY);
|
|
|
|
EXPECT_NE(event, document.MemberEnd());
|
|
|
|
|
|
|
|
auto header = event->value.FindMember(MESSAGE_HEADER_KEY);
|
|
|
|
EXPECT_NE(header, event->value.MemberEnd());
|
|
|
|
|
|
|
|
std::string requestName;
|
|
|
|
jsonUtils::retrieveValue(header->value, MESSAGE_NAME_KEY, &requestName);
|
|
|
|
|
|
|
|
if (expectedMessages->find(requestName) != expectedMessages->end()) {
|
2018-02-12 23:31:53 +00:00
|
|
|
expectedMessages->at(requestName) = expectedMessages->at(requestName) + 1;
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioPlayerTest::verifyState(const std::string& providedState, const std::string& expectedState) {
|
|
|
|
rapidjson::Document providedStateParsed;
|
|
|
|
providedStateParsed.Parse(providedState);
|
|
|
|
|
|
|
|
rapidjson::Document expectedStateParsed;
|
|
|
|
expectedStateParsed.Parse(expectedState);
|
|
|
|
|
|
|
|
EXPECT_EQ(providedStateParsed, expectedStateParsed);
|
|
|
|
}
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
void AudioPlayerTest::verifyTags(
|
|
|
|
std::shared_ptr<avsCommon::avs::MessageRequest> request,
|
2018-02-12 23:31:53 +00:00
|
|
|
std::map<std::string, int>* expectedMessages) {
|
2017-10-30 22:14:38 +00:00
|
|
|
rapidjson::Document document;
|
|
|
|
document.Parse(request->getJsonContent().c_str());
|
|
|
|
EXPECT_FALSE(document.HasParseError())
|
|
|
|
<< "rapidjson detected a parsing error at offset:" + std::to_string(document.GetErrorOffset()) +
|
|
|
|
", error message: " + GetParseError_En(document.GetParseError());
|
|
|
|
|
|
|
|
auto event = document.FindMember(MESSAGE_EVENT_KEY);
|
|
|
|
EXPECT_NE(event, document.MemberEnd());
|
|
|
|
|
|
|
|
auto header = event->value.FindMember(MESSAGE_HEADER_KEY);
|
|
|
|
EXPECT_NE(header, event->value.MemberEnd());
|
|
|
|
|
|
|
|
std::string requestName;
|
|
|
|
jsonUtils::retrieveValue(header->value, MESSAGE_NAME_KEY, &requestName);
|
|
|
|
|
|
|
|
if (expectedMessages->find(requestName) != expectedMessages->end()) {
|
2018-02-12 23:31:53 +00:00
|
|
|
expectedMessages->at(requestName) = expectedMessages->at(requestName) + 1;
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto payload = event->value.FindMember(MESSAGE_PAYLOAD_KEY);
|
|
|
|
EXPECT_NE(payload, event->value.MemberEnd());
|
|
|
|
|
|
|
|
auto metadata = payload->value.FindMember(MESSAGE_METADATA_KEY);
|
|
|
|
EXPECT_NE(metadata, payload->value.MemberEnd());
|
|
|
|
|
|
|
|
std::string metadata_string_value;
|
|
|
|
jsonUtils::retrieveValue(metadata->value, MESSAGE_METADATA_STRING_KEY, &metadata_string_value);
|
|
|
|
|
|
|
|
if (expectedMessages->find(metadata_string_value) != expectedMessages->end()) {
|
2018-02-12 23:31:53 +00:00
|
|
|
expectedMessages->at(metadata_string_value) = expectedMessages->at(metadata_string_value) + 1;
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string metadata_uint_value;
|
|
|
|
jsonUtils::retrieveValue(metadata->value, MESSAGE_METADATA_UINT_KEY, &metadata_uint_value);
|
|
|
|
|
|
|
|
if (expectedMessages->find(metadata_uint_value) != expectedMessages->end()) {
|
2018-02-12 23:31:53 +00:00
|
|
|
expectedMessages->at(metadata_uint_value) = expectedMessages->at(metadata_uint_value) + 1;
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string metadata_int_value;
|
|
|
|
jsonUtils::retrieveValue(metadata->value, MESSAGE_METADATA_INT_KEY, &metadata_int_value);
|
|
|
|
|
|
|
|
if (expectedMessages->find(metadata_int_value) != expectedMessages->end()) {
|
2018-02-12 23:31:53 +00:00
|
|
|
expectedMessages->at(metadata_int_value) = expectedMessages->at(metadata_int_value) + 1;
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string metadata_double_value;
|
|
|
|
jsonUtils::retrieveValue(metadata->value, MESSAGE_METADATA_DOUBLE_KEY, &metadata_double_value);
|
|
|
|
|
|
|
|
if (expectedMessages->find(metadata_double_value) != expectedMessages->end()) {
|
2018-02-12 23:31:53 +00:00
|
|
|
expectedMessages->at(metadata_double_value) = expectedMessages->at(metadata_double_value) + 1;
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool metadata_boolean_value = false;
|
|
|
|
jsonUtils::retrieveValue(metadata->value, MESSAGE_METADATA_BOOLEAN_KEY, &metadata_boolean_value);
|
|
|
|
ASSERT_TRUE(metadata_boolean_value);
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/**
|
|
|
|
* Test create() with nullptrs
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testCreateWithNullPointers) {
|
|
|
|
std::shared_ptr<AudioPlayer> testAudioPlayer;
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
testAudioPlayer = AudioPlayer::create(
|
|
|
|
nullptr,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockExceptionSender,
|
|
|
|
m_mockPlaybackRouter);
|
|
|
|
EXPECT_EQ(testAudioPlayer, nullptr);
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
testAudioPlayer = AudioPlayer::create(
|
|
|
|
m_mockMediaPlayer,
|
|
|
|
nullptr,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockContextManager,
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockExceptionSender,
|
|
|
|
m_mockPlaybackRouter);
|
2017-10-02 22:59:05 +00:00
|
|
|
EXPECT_EQ(testAudioPlayer, nullptr);
|
|
|
|
|
|
|
|
testAudioPlayer = AudioPlayer::create(
|
|
|
|
m_mockMediaPlayer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
nullptr,
|
|
|
|
m_mockContextManager,
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockExceptionSender,
|
|
|
|
m_mockPlaybackRouter);
|
2017-10-02 22:59:05 +00:00
|
|
|
EXPECT_EQ(testAudioPlayer, nullptr);
|
|
|
|
|
|
|
|
testAudioPlayer = AudioPlayer::create(
|
|
|
|
m_mockMediaPlayer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockFocusManager,
|
|
|
|
nullptr,
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockExceptionSender,
|
|
|
|
m_mockPlaybackRouter);
|
2017-10-02 22:59:05 +00:00
|
|
|
EXPECT_EQ(testAudioPlayer, nullptr);
|
|
|
|
|
|
|
|
testAudioPlayer = AudioPlayer::create(
|
|
|
|
m_mockMediaPlayer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockContextManager,
|
|
|
|
nullptr,
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockPlaybackRouter);
|
2017-10-02 22:59:05 +00:00
|
|
|
EXPECT_EQ(testAudioPlayer, nullptr);
|
|
|
|
|
|
|
|
testAudioPlayer = AudioPlayer::create(
|
2018-01-12 23:45:42 +00:00
|
|
|
m_mockMediaPlayer,
|
|
|
|
m_mockMessageSender,
|
|
|
|
m_mockFocusManager,
|
|
|
|
m_mockContextManager,
|
|
|
|
m_mockExceptionSender,
|
|
|
|
nullptr);
|
2017-10-02 22:59:05 +00:00
|
|
|
EXPECT_EQ(testAudioPlayer, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Idle to Playing
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testTransitionFromIdleToPlaying) {
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
sendPlayDirective();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Playing to Stopped with Stop Directive
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testTransitionFromPlayingToStopped) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
// now send Stop directive
|
|
|
|
auto avsStopMessageHeader =
|
|
|
|
std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_STOP, MESSAGE_ID_TEST, PLAY_REQUEST_ID_TEST);
|
|
|
|
|
|
|
|
std::shared_ptr<AVSDirective> stopDirective =
|
|
|
|
AVSDirective::create("", avsStopMessageHeader, EMPTY_PAYLOAD_TEST, m_attachmentManager, CONTEXT_ID_TEST);
|
|
|
|
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(stopDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST);
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Playing to Stopped with ClearQueue.CLEAR_ALL Directive
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testTransitionFromPlayingToStoppedWithClear) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
sendClearQueueDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Stopped to Playing after issuing second Play directive
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testTransitionFromStoppedToPlaying) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
sendClearQueueDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(AtLeast(1));
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
EXPECT_CALL(*(m_mockFocusManager.get()), acquireChannel(CHANNEL_NAME, _, NAMESPACE_AUDIO_PLAYER))
|
2017-10-30 22:14:38 +00:00
|
|
|
.Times(1)
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
|
|
|
// send a second Play directive
|
2017-10-02 22:59:05 +00:00
|
|
|
auto avsMessageHeader = std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_PLAY, MESSAGE_ID_TEST_2);
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::shared_ptr<AVSDirective> playDirective = AVSDirective::create(
|
|
|
|
"",
|
|
|
|
avsMessageHeader,
|
|
|
|
createEnqueuePayloadTest(OFFSET_IN_MILLISECONDS_TEST),
|
|
|
|
m_attachmentManager,
|
|
|
|
CONTEXT_ID_TEST_2);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(playDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST_2);
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Playing to Paused when focus changes to Dialog channel
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testTransitionFromPlayingToPaused) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
// simulate focus change
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Paused to Stopped on ClearQueue.CLEAR_ALL directive
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testTransitionFromPausedToStopped) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
// simulate focus change in order to pause
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
sendClearQueueDirective();
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test transition from Paused to Playing after resume
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testResumeAfterPaused) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
// simulate focus change in order to pause
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), resume(_)).Times(AtLeast(1));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c provideState while IDLE
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testCallingProvideStateWhenIdle) {
|
|
|
|
EXPECT_CALL(
|
|
|
|
*(m_mockContextManager.get()),
|
|
|
|
setState(NAMESPACE_AND_NAME_PLAYBACK_STATE, _, StateRefreshPolicy::NEVER, PROVIDE_STATE_TOKEN_TEST))
|
|
|
|
.Times(1)
|
|
|
|
.WillOnce(DoAll(
|
|
|
|
// need to include all four arguments, but only care about jsonState
|
|
|
|
Invoke([this](
|
|
|
|
const avs::NamespaceAndName& namespaceAndName,
|
|
|
|
const std::string& jsonState,
|
|
|
|
const avs::StateRefreshPolicy& refreshPolicy,
|
|
|
|
const unsigned int stateRequestToken) { verifyState(jsonState, IDLE_STATE_TEST); }),
|
|
|
|
InvokeWithoutArgs(this, &AudioPlayerTest::wakeOnSetState)));
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
m_audioPlayer->provideState(NAMESPACE_AND_NAME_PLAYBACK_STATE, PROVIDE_STATE_TOKEN_TEST);
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_TRUE(std::future_status::ready == m_wakeSetStateFuture.wait_for(WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c onPlaybackError and expect a PlaybackFailed message
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnPlaybackError) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({PLAYBACK_STARTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_FAILED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_STOPPED_NAME, 0});
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2017-10-02 22:59:05 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onPlaybackError(
|
|
|
|
m_mockMediaPlayer->getCurrentSourceId(), ErrorType::MEDIA_ERROR_UNKNOWN, "TEST_ERROR");
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2017-10-02 22:59:05 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2017-10-02 22:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c onPlaybackPaused and expect a PlaybackPaused message
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnPlaybackPaused) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({PLAYBACK_STARTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_PAUSED_NAME, 0});
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2017-10-02 22:59:05 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2017-10-02 22:59:05 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2017-10-02 22:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c onPlaybackResumed and expect a PlaybackResumed message
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnPlaybackResumed) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({PLAYBACK_STARTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_RESUMED_NAME, 0});
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2017-10-02 22:59:05 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onPlaybackResumed(m_mockMediaPlayer->getCurrentSourceId());
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2018-01-12 23:45:42 +00:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2018-01-12 23:45:42 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2018-01-12 23:45:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c onPlaybackFinished and expect a PLAYBACK_NEARLY_FINISHED_NAME and a PLAYBACK_FINISHED_NAME message
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnPlaybackFinished) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({PLAYBACK_STARTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_NEARLY_FINISHED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_FINISHED_NAME, 0});
|
2018-01-12 23:45:42 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2018-01-12 23:45:42 +00:00
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2018-01-12 23:45:42 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
m_audioPlayer->onPlaybackFinished(m_mockMediaPlayer->getCurrentSourceId());
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2017-10-02 22:59:05 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2017-10-02 22:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c onBufferUnderrun and expect a PlaybackStutterStarted message
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnBufferUnderrun) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({PLAYBACK_STARTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_STUTTER_STARTED_NAME, 0});
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2017-10-02 22:59:05 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onBufferUnderrun(m_mockMediaPlayer->getCurrentSourceId());
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2017-10-02 22:59:05 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2017-10-02 22:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test @c onBufferRefilled and expect a PlaybackStutterFinished message
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnBufferRefilled) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({PLAYBACK_STARTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({PLAYBACK_STUTTER_FINISHED_NAME, 0});
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2017-10-02 22:59:05 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective();
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onBufferRefilled(m_mockMediaPlayer->getCurrentSourceId());
|
2017-10-02 22:59:05 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-10-02 22:59:05 +00:00
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2017-10-02 22:59:05 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2017-10-02 22:59:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
|
|
|
* Test @c onTags and expect valid JSON.
|
|
|
|
* Build a vector of tags and pass to Observer (onTags).
|
|
|
|
* Observer will use the vector of tags and build a valid JSON object
|
|
|
|
* "StreamMetadataExtracted Event". This JSON object is verified in verifyTags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testOnTags) {
|
2018-02-12 23:31:53 +00:00
|
|
|
m_expectedMessages.insert({STREAM_METADATA_EXTRACTED_NAME, 0});
|
|
|
|
m_expectedMessages.insert({MESSAGE_METADATA_STRING_VALUE, 0});
|
|
|
|
m_expectedMessages.insert({MESSAGE_METADATA_UINT_VALUE, 0});
|
|
|
|
m_expectedMessages.insert({MESSAGE_METADATA_DOUBLE_VALUE, 0});
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
2018-01-12 23:45:42 +00:00
|
|
|
if (!m_mockMediaPlayer->waitUntilPlaybackStopped(std::chrono::milliseconds(0))) {
|
2018-02-12 23:31:53 +00:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
verifyTags(request, &m_expectedMessages);
|
2018-02-12 23:31:53 +00:00
|
|
|
m_messageSentTrigger.notify_one();
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
std::unique_ptr<AudioPlayer::VectorOfTags> ptrToVectorOfTags = make_unique<AudioPlayer::VectorOfTags>();
|
|
|
|
auto vectorOfTags = ptrToVectorOfTags.get();
|
|
|
|
|
|
|
|
// Populate vector with dummy tags
|
|
|
|
AudioPlayer::TagKeyValueType stringTag, uintTag, intTag, doubleTag, booleanTag;
|
|
|
|
stringTag.key = std::string(MESSAGE_METADATA_STRING_KEY);
|
|
|
|
stringTag.value = std::string(MESSAGE_METADATA_STRING_VALUE);
|
|
|
|
stringTag.type = AudioPlayer::TagType::STRING;
|
|
|
|
vectorOfTags->push_back(stringTag);
|
|
|
|
|
|
|
|
uintTag.key = std::string(MESSAGE_METADATA_UINT_KEY);
|
|
|
|
uintTag.value = std::string(MESSAGE_METADATA_UINT_VALUE);
|
|
|
|
uintTag.type = AudioPlayer::TagType::UINT;
|
|
|
|
vectorOfTags->push_back(uintTag);
|
|
|
|
|
|
|
|
intTag.key = std::string(MESSAGE_METADATA_INT_KEY);
|
|
|
|
intTag.value = std::string(MESSAGE_METADATA_INT_VALUE);
|
|
|
|
intTag.type = AudioPlayer::TagType::INT;
|
|
|
|
vectorOfTags->push_back(intTag);
|
|
|
|
|
|
|
|
doubleTag.key = std::string(MESSAGE_METADATA_DOUBLE_KEY);
|
|
|
|
doubleTag.value = std::string(MESSAGE_METADATA_DOUBLE_VALUE);
|
|
|
|
doubleTag.type = AudioPlayer::TagType::DOUBLE;
|
|
|
|
vectorOfTags->push_back(doubleTag);
|
|
|
|
|
|
|
|
booleanTag.key = std::string(MESSAGE_METADATA_BOOLEAN_KEY);
|
|
|
|
booleanTag.value = std::string(MESSAGE_METADATA_BOOLEAN_VALUE);
|
|
|
|
booleanTag.type = AudioPlayer::TagType::BOOLEAN;
|
|
|
|
vectorOfTags->push_back(booleanTag);
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onTags(m_mockMediaPlayer->getCurrentSourceId(), std::move(ptrToVectorOfTags));
|
2017-10-30 22:14:38 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2017-10-30 22:14:38 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
auto result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
2017-10-30 22:14:38 +00:00
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
2018-02-12 23:31:53 +00:00
|
|
|
if (messageStatus.second == 0) {
|
2017-10-30 22:14:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
/**
|
|
|
|
* Test @c cancelDirective
|
|
|
|
* Expect the @c handleDirective call to the cancelled directive returns false
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testCancelDirective) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
m_audioPlayer->CapabilityAgent::cancelDirective(MESSAGE_ID_TEST);
|
|
|
|
|
|
|
|
ASSERT_FALSE(m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST));
|
|
|
|
}
|
|
|
|
|
2017-10-30 22:14:38 +00:00
|
|
|
/**
|
2018-02-12 23:31:53 +00:00
|
|
|
* Test focus change to NONE in IDLE state
|
2017-10-30 22:14:38 +00:00
|
|
|
* Expect nothing to happen
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testFocusChangeToNoneInIdleState) {
|
|
|
|
// switching to FocusState::NONE should cause no change
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::IDLE, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-12 23:31:53 +00:00
|
|
|
* Test focus change from FOREGROUND to BACKGROUND in IDLE state
|
|
|
|
* Expect a call to pause(). This call is intended to go through MediaPlayer and cause nothing to happen
|
|
|
|
* due to a lack of a queued AudioItem.
|
2017-10-30 22:14:38 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
TEST_F(AudioPlayerTest, testFocusChangeFromForegroundToBackgroundInIdleState) {
|
|
|
|
bool pauseCalled = false;
|
2017-10-30 22:14:38 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_))
|
|
|
|
.Times(1)
|
|
|
|
.WillOnce(Invoke([this, &pauseCalled](MediaPlayerInterface::SourceId sourceId) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
pauseCalled = true;
|
|
|
|
m_mediaPlayerCallTrigger.notify_one();
|
|
|
|
return m_mockMediaPlayer->mockPause(sourceId);
|
2017-10-30 22:14:38 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
// ensure AudioPlayer is still IDLE
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::IDLE, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
ASSERT_TRUE(m_mediaPlayerCallTrigger.wait_for(lock, WAIT_TIMEOUT, [&pauseCalled] { return pauseCalled; }));
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
/**
|
|
|
|
* Test focus change in from NONE to BACKGROUND while IDLE.
|
|
|
|
* Expect a call to pause. This isn't an expected state during normal execution.
|
|
|
|
*/
|
2017-10-30 22:14:38 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
TEST_F(AudioPlayerTest, testFocusChangeFromNoneToBackgroundInIdleState) {
|
|
|
|
bool pauseCalled = false;
|
2017-10-30 22:14:38 +00:00
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_))
|
|
|
|
.Times(1)
|
|
|
|
.WillOnce(Invoke([this, &pauseCalled](MediaPlayerInterface::SourceId sourceId) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
pauseCalled = true;
|
|
|
|
m_mediaPlayerCallTrigger.notify_one();
|
|
|
|
return m_mockMediaPlayer->mockPause(sourceId);
|
|
|
|
}));
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
2018-02-12 23:31:53 +00:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
ASSERT_TRUE(m_mediaPlayerCallTrigger.wait_for(lock, WAIT_TIMEOUT, [&pauseCalled] { return pauseCalled; }));
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test focus changes in PLAYING state
|
|
|
|
* Expect to pause when switching to BACKGROUND and to stop when switching to NONE
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testFocusChangesInPlayingState) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
// already in FOREGROUND, expect no change
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect to pause in BACKGROUND
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect to resume when switching back to FOREGROUND
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), resume(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect to stop when changing focus to NONE
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test focus changes in STOPPED state
|
2018-02-12 23:31:53 +00:00
|
|
|
* Expect to remain in STOPPED state when switching to FOREGROUND (because there are no queued AudioItems) and
|
|
|
|
* to transition to PAUSED when switching to BACKGROUND.
|
2017-10-30 22:14:38 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
TEST_F(AudioPlayerTest, testFocusChangesInStoppedState) {
|
2017-10-30 22:14:38 +00:00
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
// push AudioPlayer into stopped state
|
2018-02-12 23:31:53 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
2017-10-30 22:14:38 +00:00
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
2017-10-30 22:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test focus changes in PAUSED state
|
|
|
|
* Expect to resume when switching to FOREGROUND, expect nothing when switching to BACKGROUND, expect stop when
|
|
|
|
* switching to NONE
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testFocusChangesInPausedState) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
// push AudioPlayer into paused state
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect a resume when switching back to FOREGROUND
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), resume(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// return to paused state
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect nothing to happen when switching to BACKGROUND from BACKGROUND
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect stop when switching to NONE focus
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test focus changes in BUFFER_UNDERRUN state
|
|
|
|
* Expect nothing to happen when switching to FOREGROUND, expect to pause when switching to BACKGROUND, expect to stop
|
|
|
|
* when switching to NONE
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testFocusChangesInBufferUnderrunState) {
|
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
// push AudioPlayer into buffer underrun state
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onBufferUnderrun(m_mockMediaPlayer->getCurrentSourceId());
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::BUFFER_UNDERRUN, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// nothing happens, AudioPlayer already in FOREGROUND
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::BUFFER_UNDERRUN, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect to pause if pushed to BACKGROUND
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// back to FOREGROUND and buffer underrun state
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), resume(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onBufferUnderrun(m_mockMediaPlayer->getCurrentSourceId());
|
2017-10-30 22:14:38 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::BUFFER_UNDERRUN, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// expect stop when switching to NONE focus
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test an immediate focus change to background after play() has been called
|
|
|
|
* Expect that pause() is called when @c AudioPlayer is pushed into background
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testFocusChangeToBackgroundBeforeOnPlaybackStarted) {
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(1);
|
|
|
|
sendPlayDirective();
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), stop(_)).Times(AtLeast(1));
|
|
|
|
|
|
|
|
sendClearQueueDirective();
|
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
|
2018-03-09 00:55:39 +00:00
|
|
|
EXPECT_CALL(*(m_mockFocusManager.get()), acquireChannel(CHANNEL_NAME, _, NAMESPACE_AUDIO_PLAYER))
|
2017-10-30 22:14:38 +00:00
|
|
|
.Times(1)
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
|
|
|
// send a second Play directive
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(1);
|
|
|
|
auto avsMessageHeader = std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_PLAY, MESSAGE_ID_TEST_2);
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
std::shared_ptr<AVSDirective> playDirective = AVSDirective::create(
|
|
|
|
"",
|
|
|
|
avsMessageHeader,
|
|
|
|
createEnqueuePayloadTest(OFFSET_IN_MILLISECONDS_TEST),
|
|
|
|
m_attachmentManager,
|
|
|
|
CONTEXT_ID_TEST_2);
|
2017-10-30 22:14:38 +00:00
|
|
|
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(playDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST_2);
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), pause(_)).Times(AtLeast(1));
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
2017-12-09 00:07:37 +00:00
|
|
|
/**
|
|
|
|
* Test @c onPlaybackError and expect AudioPlayer to change to STOPPED state and that it would go back to PLAYING state
|
|
|
|
* when a new REPLACE_ALL Play directive comes in.
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testPlayAfterOnPlaybackError) {
|
2018-01-12 23:45:42 +00:00
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), getOffset(_))
|
|
|
|
.WillRepeatedly(Return(m_mockMediaPlayer->getOffset(m_mockMediaPlayer->getCurrentSourceId())));
|
2017-12-09 00:07:37 +00:00
|
|
|
sendPlayDirective();
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
EXPECT_CALL(*(m_mockFocusManager.get()), releaseChannel(CHANNEL_NAME, _))
|
|
|
|
.Times(1)
|
|
|
|
.WillOnce(InvokeWithoutArgs(this, &AudioPlayerTest::wakeOnReleaseChannel));
|
2018-01-12 23:45:42 +00:00
|
|
|
m_audioPlayer->onPlaybackError(
|
|
|
|
m_mockMediaPlayer->getCurrentSourceId(), ErrorType::MEDIA_ERROR_UNKNOWN, "TEST_ERROR");
|
2017-12-09 00:07:37 +00:00
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
ASSERT_EQ(std::future_status::ready, m_wakeReleaseChannelFuture.wait_for(WAIT_TIMEOUT));
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
|
|
|
|
// send a REPLACE_ALL Play directive to see if AudioPlayer can still play the new item
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(1);
|
|
|
|
auto avsMessageHeader = std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_PLAY, MESSAGE_ID_TEST_2);
|
|
|
|
|
|
|
|
std::shared_ptr<AVSDirective> playDirective =
|
|
|
|
AVSDirective::create("", avsMessageHeader, REPLACE_ALL_PAYLOAD_TEST, m_attachmentManager, CONTEXT_ID_TEST_2);
|
|
|
|
|
|
|
|
m_wakeAcquireChannelPromise = std::promise<void>();
|
|
|
|
m_wakeAcquireChannelFuture = m_wakeAcquireChannelPromise.get_future();
|
2018-03-09 00:55:39 +00:00
|
|
|
EXPECT_CALL(*(m_mockFocusManager.get()), acquireChannel(CHANNEL_NAME, _, NAMESPACE_AUDIO_PLAYER))
|
2017-12-09 00:07:37 +00:00
|
|
|
.Times(1)
|
|
|
|
.WillOnce(InvokeWithoutArgs(this, &AudioPlayerTest::wakeOnAcquireChannel));
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(playDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST_2);
|
|
|
|
ASSERT_EQ(std::future_status::ready, m_wakeAcquireChannelFuture.wait_for(WAIT_TIMEOUT));
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
2018-01-12 23:45:42 +00:00
|
|
|
/**
|
|
|
|
* Test @c onPlaybackStarted calls the @c PlaybackRouter
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testPlaybackStartedSwitchesHandler) {
|
|
|
|
EXPECT_CALL(*m_mockPlaybackRouter, switchToDefaultHandler());
|
|
|
|
sendPlayDirective();
|
|
|
|
}
|
|
|
|
|
2018-02-12 23:31:53 +00:00
|
|
|
/**
|
|
|
|
* Test to verify that ProgressReportDelayElapsed Event is sent correctly. This test is timing sensitive.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testProgressReportDelayElapsed) {
|
|
|
|
m_expectedMessages.insert({PROGRESS_REPORT_DELAY_ELAPSED_NAME, 0});
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
|
|
|
m_messageSentTrigger.notify_one();
|
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective(OFFSET_IN_MILLISECONDS_BEFORE_PROGRESS_REPORT_DELAY);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(PROGRESS_REPORT_DELAY));
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
auto result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
|
|
|
if (messageStatus.second != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test to verify that ProgressReportDelayElapsed Event is not sent when the delay is less than the offset. This test
|
|
|
|
* is timing sensitive.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testProgressReportDelayElapsedDelayLessThanOffset) {
|
|
|
|
m_expectedMessages.insert({PROGRESS_REPORT_DELAY_ELAPSED_NAME, 0});
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
|
|
|
m_messageSentTrigger.notify_one();
|
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective(OFFSET_IN_MILLISECONDS_AFTER_PROGRESS_REPORT_DELAY);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(PROGRESS_REPORT_DELAY));
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
auto result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
|
|
|
if (messageStatus.second != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test to verify that ProgressReportIntervalElapsed Event is sent when the interval is less than the offset. There
|
|
|
|
* will be a ProgressReportIntervalElapsed Event at 100, 200 and 300 ms. This test is timing sensitive.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testProgressReportIntervalElapsed) {
|
|
|
|
m_expectedMessages.insert({PROGRESS_REPORT_INTERVAL_ELAPSED_NAME, 0});
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
|
|
|
m_messageSentTrigger.notify_one();
|
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective(OFFSET_IN_MILLISECONDS_BEFORE_PROGRESS_REPORT_INTERVAL);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(TIME_FOR_TWO_AND_A_HALF_INTERVAL_PERIODS);
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
auto result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
|
|
|
if (messageStatus.second != 3) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test to verify that ProgressReportIntervalElapsed Event is sent when the interval is less than the offset. There
|
|
|
|
* will be a ProgressReportIntervalElapsed Event at 200 and 300 ms. This test is timing sensitive.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testProgressReportIntervalElapsedIntervalLessThanOffset) {
|
|
|
|
m_expectedMessages.insert({PROGRESS_REPORT_INTERVAL_ELAPSED_NAME, 0});
|
|
|
|
|
|
|
|
EXPECT_CALL(*(m_mockMessageSender.get()), sendMessage(_))
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Invoke([this](std::shared_ptr<avsCommon::avs::MessageRequest> request) {
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
verifyMessageMap(request, &m_expectedMessages);
|
|
|
|
m_messageSentTrigger.notify_one();
|
|
|
|
}));
|
|
|
|
|
|
|
|
sendPlayDirective(OFFSET_IN_MILLISECONDS_AFTER_PROGRESS_REPORT_INTERVAL);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(TIME_FOR_TWO_AND_A_HALF_INTERVAL_PERIODS);
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
auto result = m_messageSentTrigger.wait_for(lock, WAIT_TIMEOUT, [this] {
|
|
|
|
for (auto messageStatus : m_expectedMessages) {
|
|
|
|
if (messageStatus.second != 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
ASSERT_TRUE(result);
|
|
|
|
}
|
|
|
|
|
Version 1.10 alexa-client-sdk
Changes in this update:
**Enhancements**
* New optional configuration for [EqualizerController](https://github.com/alexa/avs-device-sdk/blob/v1.10.0/Integration/AlexaClientSDKConfig.json#L154). The EqualizerController interface allows you to adjust equalizer settings on your product, such as decibel (dB) levels and modes.
* Added reference implementation of the EqualizerController for GStreamer-based (MacOS, Linux, and Raspberry Pi) and OpenSL ES-based (Android) MediaPlayers. Note: In order to use with Android, it must support OpenSL ES.
* New optional configuration for the [TemplateRuntime display card value](https://github.com/alexa/avs-device-sdk/blob/v1.10.0/Integration/AlexaClientSDKConfig.json#L144).
* A configuration file generator script, `genConfig.sh` is now included with the SDK in the **tools/Install** directory. `genConfig.sh` and it's associated arguments populate `AlexaClientSDKConfig.json` with the data required to authorize with LWA.
* Added Bluetooth A2DP source and AVRCP target support for Linux.
* Added Amazon for Business (A4B) support, which includes support for handling the new [RevokeAuthorization](https://developer.amazon.com/docs/alexa-voice-service/system.html#revokeauth) directive in the Settings interface. A new CMake option has been added to enable A4B within the SDK, `-DA4B`.
* Added locale support for IT and ES.
* The Alexa Communication Library (ACL), `CBLAUthDelegate`, and sample app have been enhanced to detect de-authorization using the new `z` command.
* Added `ExternalMediaPlayerObserver`, which receives notification of player state, track, and username changes.
* `HTTP2ConnectionInterface` was factored out of `HTTP2Transport` to enable unit testing of `HTTP2Transport` and re-use of `HTTP2Connection` logic.
**Bug Fixes**
* Fixed a bug in which `ExternalMediaPlayer` adapter playback wasn't being recognized by AVS.
* [Issue 973](https://github.com/alexa/avs-device-sdk/issues/973) - Fixed issues related to `AudioPlayer` where progress reports were being sent out of order or with incorrect offsets.
* An `EXPECTING`, state has been added to `DialogUXState` in order to handle `EXPECT_SPEECH` state for hold-to-talk devices.
* [Issue 948](https://github.com/alexa/avs-device-sdk/issues/948) - Fixed a bug in which the sample app was stuck in a listening state.
* Fixed a bug where there was a delay between receiving a `DeleteAlert` directive, and deleting the alert.
* [Issue 839](https://github.com/alexa/avs-device-sdk/issues/839) - Fixed an issue where speech was being truncated due to the `DialogUXStateAggregator` transitioning between a `THINKING` and `IDLE` state.
* Fixed a bug in which the `AudioPlayer` attempted to play when it wasn't in the `FOREGROUND` focus.
* `CapabilitiesDelegateTest` now works on Android.
* [Issue 950](https://github.com/alexa/avs-device-sdk/issues/950) - Improved Android Media Player audio quality.
* [Issue 908](https://github.com/alexa/avs-device-sdk/issues/908) - Fixed compile error on g++ 7.x in which includes were missing.
2018-10-24 17:01:29 +00:00
|
|
|
/**
|
|
|
|
* Test when @c AudioPlayer goes to BACKGROUND focus that it changes to PAUSED state. And when another PLAY directive
|
|
|
|
* with REPLACE_ALL behavior comes in, that it would go to STOPPED state, and will not start playing again until the
|
|
|
|
* focus goes back to FOREGROUND.
|
|
|
|
*/
|
|
|
|
|
|
|
|
TEST_F(AudioPlayerTest, testPlayOnlyAfterForegroundFocus) {
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), getOffset(_))
|
|
|
|
.WillRepeatedly(Return(m_mockMediaPlayer->getOffset(m_mockMediaPlayer->getCurrentSourceId())));
|
|
|
|
sendPlayDirective();
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
m_audioPlayer->onPlaybackStarted(m_mockMediaPlayer->getCurrentSourceId());
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::BACKGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PAUSED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// send a REPLACE_ALL Play directive
|
|
|
|
auto avsMessageHeader = std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_PLAY, MESSAGE_ID_TEST_2);
|
|
|
|
|
|
|
|
std::shared_ptr<AVSDirective> playDirective =
|
|
|
|
AVSDirective::create("", avsMessageHeader, REPLACE_ALL_PAYLOAD_TEST, m_attachmentManager, CONTEXT_ID_TEST_2);
|
|
|
|
|
|
|
|
m_wakeAcquireChannelPromise = std::promise<void>();
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(playDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST_2);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
{
|
|
|
|
// Enforce the sequence.
|
|
|
|
InSequence dummy;
|
|
|
|
|
|
|
|
// Make sure play() is not called
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(0);
|
|
|
|
ASSERT_FALSE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
// Now check play() is only called when focus to back to FOREGROUND
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), play(_)).Times(1);
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Version 1.11 alexa-client-sdk
Changes in this update:
**Enhancements**
* Added support for the new Alexa [DoNotDisturb](https://developer.amazon.com/docs/alexa-voice-service/donotdisturb.html) interface, which enables users to toggle the do not disturb (DND) function on their Alexa built-in products.
* The SDK now supports [Opus](https://opus-codec.org/license/) encoding, which is optional. To enable Opus, you must [set the CMake flag to `-DOPUS=ON`](https://github.com/alexa/avs-device-sdk/wiki/Build-Options#Opus-encoding), and include the [libopus library](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies) dependency in your build.
* The MediaPlayer reference implementation has been expanded to support the SAMPLE-AES and AES-128 encryption methods for HLS streaming.
* AES-128 encryption is dependent on libcrypto, which is part of the required openSSL library, and is enabled by default.
* To enable [SAMPLE-AES](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) encryption, you must set the `-DSAMPLE_AES=ON` in your CMake command, and include the [FFMPEG](https://github.com/alexa/avs-device-sdk/wiki/Dependencies#core-dependencies/Enable-SAMPLE-AES-decryption) library dependency in your build.
* A new configuration for [deviceSettings](https://github.com/alexa/avs-device-sdk/blob/v1.11.0/Integration/AlexaClientSDKConfig.json#L59) has been added.This configuration allows you to specify the location of the device settings database.
* Added locale support for es-MX.
**Bug Fixes**
* Fixed an issue where music wouldn't resume playback in the Android app.
* Now all equalizer capabilities are fully disabled when equalizer is turned off in configuration file. Previously, devices were unconditionally required to provide support for equalizer in order to run the SDK.
* [Issue 1106](https://github.com/alexa/avs-device-sdk/issues/1106) - Fixed an issue in which the `CBLAuthDelegate` wasn't using the correct timeout during request refresh.
* [Issue 1128](https://github.com/alexa/avs-device-sdk/issues/1128) - Fixed an issue in which the `AudioPlayer` instance persisted at shutdown, due to a shared dependency with the `ProgressTimer`.
* Fixed in issue that occurred when a connection to streaming content was interrupted, the SDK did not attempt to resume the connection, and appeared to assume that the content had been fully downloaded. This triggered the next track to be played, assuming it was a playlist.
* [Issue 1040](https://github.com/alexa/avs-device-sdk/issues/1040) - Fixed an issue where alarms would continue to play after user barge-in.
**Known Issues**
* `PlaylistParser` and `IterativePlaylistParser` generate two HTTP requests (one to fetch the content type, and one to fetch the audio data) for each audio stream played.
* Music playback history isn't being displayed in the Alexa app for certain account and device types.
* On GCC 8+, issues related to `-Wclass-memaccess` will trigger warnings. However, this won't cause the build to fail, and these warnings can be ignored.
* In order to use Bluetooth source and sink PulseAudio, you must manually load and unload PulseAudio modules after the SDK starts.
* The `ACL` may encounter issues if audio attachments are received but not consumed.
* `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release.
* The Alexa app doesn't always indicate when a device is successfully connected via Bluetooth.
* Connecting a product to streaming media via Bluetooth will sometimes stop media playback within the source application. Resuming playback through the source application or toggling next/previous will correct playback.
* When a source device is streaming silence via Bluetooth, the Alexa app indicates that audio content is streaming.
* The Bluetooth agent assumes that the Bluetooth adapter is always connected to a power source. Disconnecting from a power source during operation is not yet supported.
* On some products, interrupted Bluetooth playback may not resume if other content is locally streamed.
* `make integration` is currently not available for Android. In order to run integration tests on Android, you'll need to manually upload the test binary file along with any input file. At that point, the adb can be used to run the integration tests.
* On Raspberry Pi running Android Things with HDMI output audio, beginning of speech is truncated when Alexa responds to user TTS.
* When the sample app is restarted and network connection is lost, alerts don't play.
* When network connection is lost, lost connection status is not returned via local Text-to Speech (TTS).
2018-12-19 19:13:36 +00:00
|
|
|
/**
|
|
|
|
* Test when @c AudioPlayer starts to play but loses focus before the onPlaybackStarted callback is received.
|
|
|
|
* After onPlaybackStarted is received, playback should stop.
|
|
|
|
*/
|
|
|
|
TEST_F(AudioPlayerTest, testPlaybackStartedCallbackAfterFocusLost) {
|
|
|
|
EXPECT_CALL(*(m_mockMediaPlayer.get()), getOffset(_))
|
|
|
|
.WillRepeatedly(Return(m_mockMediaPlayer->getOffset(m_mockMediaPlayer->getCurrentSourceId())));
|
|
|
|
|
|
|
|
auto avsMessageHeader =
|
|
|
|
std::make_shared<AVSMessageHeader>(NAMESPACE_AUDIO_PLAYER, NAME_PLAY, MESSAGE_ID_TEST, PLAY_REQUEST_ID_TEST);
|
|
|
|
|
|
|
|
std::shared_ptr<AVSDirective> playDirective = AVSDirective::create(
|
|
|
|
"",
|
|
|
|
avsMessageHeader,
|
|
|
|
createEnqueuePayloadTest(OFFSET_IN_MILLISECONDS_TEST),
|
|
|
|
m_attachmentManager,
|
|
|
|
CONTEXT_ID_TEST);
|
|
|
|
EXPECT_CALL(*(m_mockFocusManager.get()), acquireChannel(CHANNEL_NAME, _, NAMESPACE_AUDIO_PLAYER))
|
|
|
|
.Times(1)
|
|
|
|
.WillOnce(InvokeWithoutArgs(this, &AudioPlayerTest::wakeOnAcquireChannel));
|
|
|
|
|
|
|
|
EXPECT_CALL(*m_mockDirectiveHandlerResult, setCompleted());
|
|
|
|
|
|
|
|
m_audioPlayer->CapabilityAgent::preHandleDirective(playDirective, std::move(m_mockDirectiveHandlerResult));
|
|
|
|
m_audioPlayer->CapabilityAgent::handleDirective(MESSAGE_ID_TEST);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Enforce the sequence.
|
|
|
|
InSequence dummy;
|
|
|
|
|
|
|
|
// Wait for acquireFocus().
|
|
|
|
ASSERT_EQ(std::future_status::ready, m_wakeAcquireChannelFuture.wait_for(WAIT_TIMEOUT));
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::FOREGROUND);
|
|
|
|
|
|
|
|
std::promise<void> playCalledPromise;
|
|
|
|
std::future<void> playCalled = playCalledPromise.get_future();
|
|
|
|
|
|
|
|
// Override play() behavior in MockMediaPlayer. We don't want play() to automatically call onPlaybackStarted.
|
|
|
|
ON_CALL(*m_mockMediaPlayer, play(_)).WillByDefault(InvokeWithoutArgs([&playCalledPromise] {
|
|
|
|
playCalledPromise.set_value();
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
ASSERT_THAT(playCalled.wait_for(WAIT_TIMEOUT), Ne(std::future_status::timeout));
|
|
|
|
|
|
|
|
m_audioPlayer->onFocusChanged(FocusState::NONE);
|
|
|
|
m_audioPlayer->onPlaybackStarted(m_mockMediaPlayer->getCurrentSourceId());
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::PLAYING, WAIT_TIMEOUT));
|
|
|
|
|
|
|
|
ASSERT_TRUE(m_testAudioPlayerObserver->waitFor(PlayerActivity::STOPPED, WAIT_TIMEOUT));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:59:05 +00:00
|
|
|
} // namespace test
|
|
|
|
} // namespace audioPlayer
|
|
|
|
} // namespace capabilityAgents
|
|
|
|
} // namespace alexaClientSDK
|