avs-device-sdk/AVSCommon/Utils/test/StreamFunctionsTest.cpp

179 lines
5.1 KiB
C++
Raw Normal View History

v1.3.0 released 12/08/2017: **Enhancements** * ContextManager now passes the namespace/name of the desired state to StateProv iderInterface::provideState(). This is helpful when a single StateProvider obje ct provides multiple states, and needs to know which one ContextManager is askin g for. * The mime parser was hardened against duplicate boundaries. * Added functionality to add and remove AudioPlayer observers to the DefaultClie nt. * Unit tests for Alerts were added. * Added en-IN, en-CA and ja-JP to the SampleApp locale selection menu. * Added default alert and timer audio data to the SDK SampleApp. There is no lo nger a requirement to download these audio files and configure them in the json configuration file. * Added support in SDS Reader and AttachmentReader for seeking into the future. This allows a reader to move to an index which has not yet arrived in the SDS a nd poll/block until it arrives. * Added support for blocking Writers in the SharedDataStream class. * Changed the default status code sent by MessageRequestObserverInterface::onSen dCompleted() to SERVER_OTHER_ERROR, and mapped HTTP code 500 to SERVER_INTERNAL_ ERROR_V2. * Added support for parsing stream duration out of playlists. * Added a configuration option ("sampleApp":"displayCardsSupported") that allows the displaying of display cards to be enabled or disabled. * Named Timers and Reminders have been updated to fall back to the on-device bac kground audio sound when cloud urls cannot be accessed or rendered. **Bug Fixes** * Removed floating point dependencies from core SDK libraries. * Fixed bug in SpeechSynthesizer where it's erroneously calling stop more than once. * Fixed an issue in ContentFetcher where it could hang during destruction until an active GET request completed. * Fixed a couple of parsing bugs in LibCurlHttpContentFetcher related to case-sensitivity and mime-type handling. * Fixed a bug where MediaPlayerObserverInterface::onPlaybackResumed() wasn't being called after resuming from a pause with a pending play/resume. * Fixed a bug in LibCurlContentFetcher where it could error out if data is written to the SDS faster than it is consumed. * The GStreamer-based MediaPlayer reference implementation now uses the ACL HTTP configured client. * An API change has been made to MediaPlayerInterface::setSource(). This method now takes in an optional offset as well to allow for immediately streaming to the offset if possible. * Next and Previous buttons now work with Audible. * Pandora resume stuttering is addressed. * Pausing and resuming Amazon music no longer seeks back to the beginning of the song. * libcurl CURLOPT_NOSIGNAL option is set to 1 (https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html) to avoid crashes observed in SampleApp. * Fixed the timing of the PlaybackReportIntervalEvent and PlaybackReportDelayEvent as specified in the directives. * Fixed potential deadlocks in MediaPlayer during shutdown related to queued callbacks. * Fixed a crash in MediaPlayer that could occur if the network is disconnected during playback. * Fixed a bug where music could keep playing while Alexa is speaking. * Fixed a bug which was causing problems with pause/resume and next/previous with Amazon Music. * Fixed a bug where music could briefly start playing between speaks. * Fixed a bug where HLS playlists would stop streaming after the initial playlist had been played to completion. * Fixed a bug where Audible playback could not advance to the next chapter. * Fixed some occurrences of SDK entering the IDLE state during the transition between Listening and Speaking states. * Fixed a bug where PlaybackFinished events were not reporting the correct offset. * An API change has been made to MediaPlayerInterface::getOffset(). This method is now required to return the final offset when called after playback has stopped. * Fixed a problem where AIP was erroneously resetting its state upon getting a cancelDirective() callback. **Known Issues** * Capability agent for Notifications is not included in this release. * `ACL`'s asynchronous receipt of audio attachments may manage resources poorly in scenarios where attachments are received but not consumed. * GUI cards don't show for Kindle. * The new SpeechSynthesizerState state values GAINING_FOCUS and LOSING_FOCUS were added as part of a work-around. The will likely be removed in subsequent releases. * With the gstreamer-based MediaPlayer, after muting and unmuting, the next item starts playing rather than continuing with the current item.
2017-12-09 00:07:37 +00:00
/*
Version 1.5.0 alexa-client-sdk Changes in this update: **Enhancements** * Added the `ExternalMediaPlayer` Capability Agent. This allows playback from music providers that control their own playback queue. Example: Spotify. * Added support for AU and NZ to the `SampleApp`. * Firmware version can now be sent to Alexa via the `SoftwareInfo` event. The firmware version is specified in the config file under the `sampleApp` object as an integer value named [`firmwareVersion`](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L52). * The new `f` command was added to the `SampleApp` which allows the firmware version to be updated at run-time. * Optional configuration changes have been introduced. Now a [default log level](https://github.com/alexa/avs-device-sdk/blob/master/Integration/AlexaClientSDKConfig.json#L93) can be set for `ACSDK_LOG_MODULE` components, globally or individually. This value is specified under a new root level configuration object called `logger`, and the value itself is named `logLevel`. This allows you to limit the degree of logging to that default value, such as `ERROR`or `INFO`. **Bug Fixes** * Fixed bug where `AudioPlayer` progress reports were not being sent, or were being sent incorrectly. * [Issue 408](https://github.com/alexa/avs-device-sdk/issues/408) - Irrelevant code related to `UrlSource` was removed from the `GStreamer-based MediaPlayer` implementation. * The `TZ` variable no longer needs to be set to `UTC` when building the `SampleApp`. * Fixed a bug where `CurlEasyHandleWrapper` logged unwanted data on failure conditions. * Fixed a bug to improve `SIGPIPE` handling. * Fixed a bug where the filename and classname were mismatched. Changed `UrlToAttachmentConverter.h` to `UrlContentToAttachmentConverter.h`,and `UrlToAttachmentConverter.cpp` to `UrlContentToAttachmentConverter.cpp` **Known Issues** * The `ACL` may encounter issues if audio attachments are received but not consumed. * Display Cards for Kindle don't render. * If using the GStreamer-based `MediaPlayer` implementation, after muting and un-muting an audio item, the next item in the queue will begin playing rather than continuing playback of the originally muted audio item. * `SpeechSynthesizerState` currently uses `GAINING_FOCUS` and `LOSING_FOCUS` as a workaround for handling intermediate state. These states may be removed in a future release. * Music playback doesn't immediately stop when a user barges-in on iHeartRadio.
2018-02-12 23:31:53 +00:00
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
v1.3.0 released 12/08/2017: **Enhancements** * ContextManager now passes the namespace/name of the desired state to StateProv iderInterface::provideState(). This is helpful when a single StateProvider obje ct provides multiple states, and needs to know which one ContextManager is askin g for. * The mime parser was hardened against duplicate boundaries. * Added functionality to add and remove AudioPlayer observers to the DefaultClie nt. * Unit tests for Alerts were added. * Added en-IN, en-CA and ja-JP to the SampleApp locale selection menu. * Added default alert and timer audio data to the SDK SampleApp. There is no lo nger a requirement to download these audio files and configure them in the json configuration file. * Added support in SDS Reader and AttachmentReader for seeking into the future. This allows a reader to move to an index which has not yet arrived in the SDS a nd poll/block until it arrives. * Added support for blocking Writers in the SharedDataStream class. * Changed the default status code sent by MessageRequestObserverInterface::onSen dCompleted() to SERVER_OTHER_ERROR, and mapped HTTP code 500 to SERVER_INTERNAL_ ERROR_V2. * Added support for parsing stream duration out of playlists. * Added a configuration option ("sampleApp":"displayCardsSupported") that allows the displaying of display cards to be enabled or disabled. * Named Timers and Reminders have been updated to fall back to the on-device bac kground audio sound when cloud urls cannot be accessed or rendered. **Bug Fixes** * Removed floating point dependencies from core SDK libraries. * Fixed bug in SpeechSynthesizer where it's erroneously calling stop more than once. * Fixed an issue in ContentFetcher where it could hang during destruction until an active GET request completed. * Fixed a couple of parsing bugs in LibCurlHttpContentFetcher related to case-sensitivity and mime-type handling. * Fixed a bug where MediaPlayerObserverInterface::onPlaybackResumed() wasn't being called after resuming from a pause with a pending play/resume. * Fixed a bug in LibCurlContentFetcher where it could error out if data is written to the SDS faster than it is consumed. * The GStreamer-based MediaPlayer reference implementation now uses the ACL HTTP configured client. * An API change has been made to MediaPlayerInterface::setSource(). This method now takes in an optional offset as well to allow for immediately streaming to the offset if possible. * Next and Previous buttons now work with Audible. * Pandora resume stuttering is addressed. * Pausing and resuming Amazon music no longer seeks back to the beginning of the song. * libcurl CURLOPT_NOSIGNAL option is set to 1 (https://curl.haxx.se/libcurl/c/CURLOPT_NOSIGNAL.html) to avoid crashes observed in SampleApp. * Fixed the timing of the PlaybackReportIntervalEvent and PlaybackReportDelayEvent as specified in the directives. * Fixed potential deadlocks in MediaPlayer during shutdown related to queued callbacks. * Fixed a crash in MediaPlayer that could occur if the network is disconnected during playback. * Fixed a bug where music could keep playing while Alexa is speaking. * Fixed a bug which was causing problems with pause/resume and next/previous with Amazon Music. * Fixed a bug where music could briefly start playing between speaks. * Fixed a bug where HLS playlists would stop streaming after the initial playlist had been played to completion. * Fixed a bug where Audible playback could not advance to the next chapter. * Fixed some occurrences of SDK entering the IDLE state during the transition between Listening and Speaking states. * Fixed a bug where PlaybackFinished events were not reporting the correct offset. * An API change has been made to MediaPlayerInterface::getOffset(). This method is now required to return the final offset when called after playback has stopped. * Fixed a problem where AIP was erroneously resetting its state upon getting a cancelDirective() callback. **Known Issues** * Capability agent for Notifications is not included in this release. * `ACL`'s asynchronous receipt of audio attachments may manage resources poorly in scenarios where attachments are received but not consumed. * GUI cards don't show for Kindle. * The new SpeechSynthesizerState state values GAINING_FOCUS and LOSING_FOCUS were added as part of a work-around. The will likely be removed in subsequent releases. * With the gstreamer-based MediaPlayer, after muting and unmuting, the next item starts playing rather than continuing with the current item.
2017-12-09 00:07:37 +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.
*/
#include <gtest/gtest.h>
#include <AVSCommon/Utils/Stream/StreamFunctions.h>
namespace alexaClientSDK {
namespace avsCommon {
namespace utils {
namespace test {
/**
* Utility function to check if a stream contents match a data block
*/
static bool streamAndDataAreEqual(const std::istream& stream, const unsigned char* data, size_t length) {
std::ostringstream oss;
oss << stream.rdbuf();
return oss.str() == std::string(data, data + length);
}
static const unsigned char TEST_DATA[] = {'T', 'E', 'S', 'T', '_', 'D', 'A', 'T', 'A'};
class StreamFunctionsTest : public ::testing::Test {
public:
StreamFunctionsTest() : m_stream(stream::streamFromData(TEST_DATA, sizeof(TEST_DATA))) {
}
protected:
std::unique_ptr<std::istream> m_stream;
};
/**
* Verify that audio bytes passed in are returned exactly the same
*/
TEST_F(StreamFunctionsTest, StreamFromData) {
ASSERT_TRUE(streamAndDataAreEqual(*m_stream, TEST_DATA, sizeof(TEST_DATA)));
}
/**
* Verify that non-char data streams work correctly
*/
TEST_F(StreamFunctionsTest, DataContainsUnprintableChars) {
const std::vector<std::vector<unsigned char>> testData = {
{5, 0, 3, 6}, // NULLS in data
{0, 0, 6, 6}, // NULLS at beginning
{6, 6, 0, 0}, // NULLS at beginning
{3, 255, 5, 255, 4}, // -1
{255, 255, 5, 4}, // -1 at beginning
{3, 5, 255, 255}, // -1 at end
{0, 255}, // BOTH
{255, 0} // BOTH
};
for (const auto& data : testData) {
auto stream = stream::streamFromData(data.data(), data.size());
ASSERT_TRUE(streamAndDataAreEqual(*stream, data.data(), data.size()));
}
}
/**
* Verify that empty datasets work
*/
TEST_F(StreamFunctionsTest, EmptyVector) {
const unsigned char empty[] = {};
auto stream = stream::streamFromData(empty, sizeof(empty));
ASSERT_TRUE(streamAndDataAreEqual(*stream, empty, sizeof(empty)));
}
/**
* Verify that multiple streams created from the same source can be operated on independently
*/
TEST_F(StreamFunctionsTest, MultipleStreams) {
// get two streams to the same data
auto stream1 = stream::streamFromData(TEST_DATA, sizeof(TEST_DATA));
auto stream2 = stream::streamFromData(TEST_DATA, sizeof(TEST_DATA));
// get a single char from one stream
char c;
stream1->get(c);
// check to make sure that the streams are not locked together
ASSERT_EQ(TEST_DATA[0], c);
ASSERT_TRUE(streamAndDataAreEqual(*stream1, TEST_DATA + 1, sizeof(TEST_DATA) - 1));
ASSERT_TRUE(streamAndDataAreEqual(*stream2, TEST_DATA, sizeof(TEST_DATA)));
}
/**
* Verify that seekg works going forward
*/
TEST_F(StreamFunctionsTest, seekgBasicForward) {
const std::streampos step = 2;
m_stream->seekg(step);
ASSERT_TRUE(streamAndDataAreEqual(*m_stream, TEST_DATA + step, sizeof(TEST_DATA) - step));
}
/**
* Verify that seekg can reset
*/
TEST_F(StreamFunctionsTest, seekgBasicReset) {
// get 4 chars from char from one stream
char c;
m_stream->get(c);
m_stream->get(c);
m_stream->get(c);
m_stream->get(c);
// reset back to beginning
m_stream->seekg(0);
ASSERT_TRUE(streamAndDataAreEqual(*m_stream, TEST_DATA, sizeof(TEST_DATA)));
}
/**
* Verify that tellg works on creation
*/
TEST_F(StreamFunctionsTest, tellgBasic) {
ASSERT_EQ(0, m_stream->tellg());
}
/**
* Verify that the stream will have a bad tellg result when seeking past end
*/
TEST_F(StreamFunctionsTest, tellgPastEnd) {
m_stream->seekg(sizeof(TEST_DATA) + 1);
ASSERT_EQ(-1, m_stream->tellg());
}
/**
* Verify that the stream will have a bad tellg result when seeking before beginning
*/
TEST_F(StreamFunctionsTest, tellgBeforeBeginning) {
m_stream->seekg(-1);
ASSERT_EQ(-1, m_stream->tellg());
}
/**
* Verify that tellg is set correctly after seeking
*/
TEST_F(StreamFunctionsTest, tellgAfterSeeking) {
const std::streampos step = 2;
m_stream->seekg(step);
ASSERT_EQ(step, m_stream->tellg());
ASSERT_TRUE(streamAndDataAreEqual(*m_stream, TEST_DATA + step, sizeof(TEST_DATA) - step));
}
/**
* Verify that tellg is set correctly after reading from stream
*/
TEST_F(StreamFunctionsTest, tellgAfterReading) {
// get 4 chars from char from one stream
const int numberToRead = 4;
for (int i = 0; i < numberToRead; ++i) {
char c;
m_stream->get(c);
}
ASSERT_EQ(numberToRead, m_stream->tellg());
}
} // namespace test
} // namespace utils
} // namespace avsCommon
} // namespace alexaClientSDK