avs-device-sdk/MediaPlayer/AndroidSLESMediaPlayer/test/FFmpegStreamInputController...

135 lines
4.7 KiB
C++
Raw Normal View History

Version 1.9.0 alexa-client-sdk Changes in this update: Enhancements Added Android SDK support, which includes new implementations of the MediaPlayer, audio recorder, and logger. Added the InteractionModel interface, which enables Alexa Routines. Optional configuration changes have been introduced. Now a network interface can be specified to connect to the SDK via curl. Build options can be configured to support Android. Added GUI 1.1 support. The PlaybackController has been extended to support new control functionality, and the System interface has been updated to support SoftwareInfo. Bug Fixes Installation script execution time has been reduced. Now a single branch clone is used, such as the master branch. Issue 846 - Fixed a bug where audio stuttered on slow network connections. Removed the SpeakerManager constructor check for non-zero speakers. Issue 891 - Resolved incorrect offset in the PlaybackFinished event. Issue 727 - Fixed an issue where the sample app behaved erratically upon network disconnection/reconnection. Issue 910 - Fixed a GCC 8+ compilation issue. Note: issues related to -Wclass-memaccess will still trigger warnings, but won't fail compilation. Issue 871 Issue 880 - Fixed compiler warnings. Fixed a bug where Ted Talks would not stream via TuneIn. Fixed an issue where the PryonLiteKeywordDetector would not restart. Fixed an issue where PlaybackStutterStarted and PlaybackStutterFinished events were not being sent due to a missing Gstreamer queue element. Fixed a bug where the CapabilitiesDelegate database was not being cleared upon logout. Fixed in issue that caused the following compiler warning “class has virtual functions but non-virtual destructor”. Fixed a bug where BlueZDeviceManager was not properly destroyed. Fixed a bug that occurred when the initializer list was converted to std::unordered_set. Fixed a build error that occurred when building with BUILD_TESTING=Off. Known Issues * 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 companion 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. * On Raspberry Pi, when streaming audio via Bluetooth, sometimes the audio stream stutters. * These CapabilitiesDelegateTest tests have been temporarily disabled to prevent build errors for the Android build: CapabilitiesDelegateTest.withCapabilitiesHappyCase, CapabilitiesDelegateTest.republish, CapabilitiesDelegateTest.testClearData. * 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 the 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. * Spotify does not completely shut down when the sample app quits.
2018-08-28 21:10:18 +00:00
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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 <array>
#include <sstream>
#include <gtest/gtest.h>
extern "C" {
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavutil/common.h>
#include <libavutil/error.h>
}
#include <Audio/Data/med_alerts_notification_01._TTH_.mp3.h>
#include "AndroidSLESMediaPlayer/FFmpegStreamInputController.h"
namespace alexaClientSDK {
namespace mediaPlayer {
namespace android {
namespace test {
using namespace ::testing;
/// The size of the buffers used to read input.
static constexpr size_t BUFFER_SIZE = 1024;
/// The size of the input buffer.
static constexpr size_t INPUT_SIZE =
applicationUtilities::resources::audio::data::med_alerts_notification_01__TTH__mp3_len;
/// An input buffer with an mp3 file.
static const auto INPUT_CSTR = applicationUtilities::resources::audio::data::med_alerts_notification_01__TTH__mp3;
std::shared_ptr<std::stringstream> createStream() {
auto stream = std::make_shared<std::stringstream>();
stream->write(reinterpret_cast<const char*>(INPUT_CSTR), INPUT_SIZE);
return stream;
}
/// Test decoder input create succeed.
TEST(FFmpegStreamInputControllerTest, testCreateSucceed) {
auto stream = createStream();
auto reader = FFmpegStreamInputController::create(stream, false);
EXPECT_NE(reader, nullptr);
}
/// Test decoder input create with null input failed.
TEST(FFmpegStreamInputControllerTest, testCreateFailed) {
auto reader = FFmpegStreamInputController::create(nullptr, false);
EXPECT_EQ(reader, nullptr);
}
/// Test read from stream.
TEST(FFmpegStreamInputControllerTest, testReadSucceed) {
auto stream = createStream();
auto reader = FFmpegStreamInputController::create(stream, false);
ASSERT_NE(reader, nullptr);
auto result = reader->getCurrentFormatContext();
auto inputFormat = std::get<1>(result);
EXPECT_EQ(FFmpegStreamInputController::Result::OK, std::get<0>(result));
EXPECT_EQ(std::get<2>(result), std::chrono::milliseconds::zero());
ASSERT_TRUE(inputFormat);
std::array<uint8_t, BUFFER_SIZE> buffer;
auto read = avio_read(inputFormat->pb, buffer.data(), buffer.size());
EXPECT_EQ(static_cast<size_t>(read), buffer.size());
}
/// Test read from stream until the end.
TEST(FFmpegStreamInputControllerTest, testReadEof) {
auto stream = createStream();
auto reader = FFmpegStreamInputController::create(stream, false);
ASSERT_NE(reader, nullptr);
auto result = reader->getCurrentFormatContext();
auto inputFormat = std::get<1>(result);
EXPECT_EQ(FFmpegStreamInputController::Result::OK, std::get<0>(result));
EXPECT_EQ(std::get<2>(result), std::chrono::milliseconds::zero());
ASSERT_TRUE(inputFormat);
std::array<uint8_t, INPUT_SIZE> buffer;
auto read = avio_read(inputFormat->pb, buffer.data(), buffer.size());
EXPECT_GT(static_cast<size_t>(read), 0u);
EXPECT_EQ(avio_read(inputFormat->pb, buffer.data(), buffer.size()), AVERROR_EOF);
}
/// Test read with repeat on from a stream.
TEST(FFmpegStreamInputControllerTest, testReadRepeat) {
auto stream = createStream();
auto reader = FFmpegStreamInputController::create(stream, true);
ASSERT_NE(reader, nullptr);
auto result = reader->getCurrentFormatContext();
auto inputFormat = std::get<1>(result);
EXPECT_EQ(FFmpegStreamInputController::Result::OK, std::get<0>(result));
EXPECT_EQ(std::get<2>(result), std::chrono::milliseconds::zero());
ASSERT_TRUE(inputFormat);
std::array<uint8_t, INPUT_SIZE> buffer;
avio_read(inputFormat->pb, buffer.data(), buffer.size());
EXPECT_EQ(avio_read(inputFormat->pb, buffer.data(), buffer.size()), AVERROR_EOF);
EXPECT_TRUE(reader->hasNext());
EXPECT_TRUE(reader->next());
result = reader->getCurrentFormatContext();
inputFormat = std::get<1>(result);
EXPECT_EQ(FFmpegStreamInputController::Result::OK, std::get<0>(result));
EXPECT_EQ(std::get<2>(result), std::chrono::milliseconds::zero());
ASSERT_TRUE(inputFormat);
auto read = avio_read(inputFormat->pb, buffer.data(), buffer.size());
EXPECT_GT(static_cast<size_t>(read), 0u);
}
} // namespace test
} // namespace android
} // namespace mediaPlayer
} // namespace alexaClientSDK