summaryrefslogtreecommitdiff
path: root/src/components/media_manager/src
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/media_manager/src')
-rw-r--r--src/components/media_manager/src/audio/a2dp_source_player_adapter.cc12
-rw-r--r--src/components/media_manager/src/audio/audio_stream_sender_thread.cc65
-rw-r--r--src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc30
-rw-r--r--src/components/media_manager/src/media_manager_impl.cc39
-rw-r--r--src/components/media_manager/src/streamer_adapter.cc2
5 files changed, 116 insertions, 32 deletions
diff --git a/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc b/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc
index 5e9d6ab0ba..91e3c5465d 100644
--- a/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc
+++ b/src/components/media_manager/src/audio/a2dp_source_player_adapter.cc
@@ -91,19 +91,19 @@ void A2DPSourcePlayerAdapter::StartActivity(int32_t application_key) {
if (application_key != current_application_) {
current_application_ = application_key;
- uint32_t device_id = 0;
+ transport_manager::DeviceHandle device_id = 0;
session_observer_.GetDataOnSessionKey(application_key, 0, NULL, &device_id);
- std::string mac_adddress;
- session_observer_.GetDataOnDeviceID(device_id, NULL, NULL, &mac_adddress);
+ std::string mac_address;
+ session_observer_.GetDataOnDeviceID(device_id, NULL, NULL, &mac_address);
- // TODO(PK): Convert mac_adddress to the
+ // TODO(PK): Convert mac_address to the
// following format : "bluez_source.XX_XX_XX_XX_XX_XX" if needed
// before passing to the A2DPSourcePlayerThread constructor
A2DPSourcePlayerThread* delegate =
- new A2DPSourcePlayerAdapter::A2DPSourcePlayerThread(mac_adddress);
+ new A2DPSourcePlayerAdapter::A2DPSourcePlayerThread(mac_address);
threads::Thread* new_activity =
- threads::CreateThread(mac_adddress.c_str(), delegate);
+ threads::CreateThread(mac_address.c_str(), delegate);
sources_[application_key] = Pair(new_activity, delegate);
new_activity->start();
}
diff --git a/src/components/media_manager/src/audio/audio_stream_sender_thread.cc b/src/components/media_manager/src/audio/audio_stream_sender_thread.cc
index 9b0057dfe8..23181e7431 100644
--- a/src/components/media_manager/src/audio/audio_stream_sender_thread.cc
+++ b/src/components/media_manager/src/audio/audio_stream_sender_thread.cc
@@ -38,8 +38,9 @@
#include <string>
#include <string.h>
#include "application_manager/application_manager.h"
-#include "application_manager/mobile_command_factory.h"
#include "application_manager/application_impl.h"
+#include "application_manager/rpc_service.h"
+#include "application_manager/commands/command.h"
#include "smart_objects/smart_object.h"
#include "interfaces/MOBILE_API.h"
#include "utils/file_system.h"
@@ -51,6 +52,7 @@
namespace media_manager {
using sync_primitives::AutoLock;
+namespace strings = application_manager::strings;
#ifdef EXTENDED_MEDIA_MODE
const int32_t AudioStreamSenderThread::kAudioPassThruTimeout = 50;
@@ -59,6 +61,15 @@ const int32_t AudioStreamSenderThread::kAudioPassThruTimeout = 1000;
#endif
const uint32_t kMqueueMessageSize = 4095;
+// Size of RIFF header contained in a .wav file: 12 bytes for 'RIFF' chunk
+// descriptor, 24 bytes for 'fmt ' sub-chunk and 8 bytes for 'data' sub-chunk
+// header.
+// The correct format of audio stream for AudioPassThru feature is to include
+// only audio sample data. Since both pre-recorded file (audio.8bit.wav) and
+// GStreamer-generated file contain RIFF header, we will skip it when reading
+// the files.
+static const uint32_t kRIFFHeaderSize = 44;
+
CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
AudioStreamSenderThread::AudioStreamSenderThread(
@@ -67,7 +78,7 @@ AudioStreamSenderThread::AudioStreamSenderThread(
application_manager::ApplicationManager& app_mngr)
: session_key_(session_key)
, fileName_(fileName)
- , offset_(0)
+ , offset_(kRIFFHeaderSize)
, shouldBeStoped_(false)
, shouldBeStoped_lock_()
, shouldBeStoped_cv_()
@@ -80,7 +91,7 @@ AudioStreamSenderThread::~AudioStreamSenderThread() {}
void AudioStreamSenderThread::threadMain() {
LOG4CXX_AUTO_TRACE(logger_);
- offset_ = 0;
+ offset_ = kRIFFHeaderSize;
while (false == getShouldBeStopped()) {
AutoLock auto_lock(shouldBeStoped_lock_);
@@ -118,15 +129,59 @@ void AudioStreamSenderThread::sendAudioChunkToMobile() {
offset_ = offset_ + to - from;
std::vector<uint8_t> data(from, to);
- application_manager_.SendAudioPassThroughNotification(session_key_, data);
+ SendAudioPassThroughNotification(session_key_, data);
binaryData.clear();
}
#if !defined(EXTENDED_MEDIA_MODE)
// without recording stream restart reading 1-sec file
- offset_ = 0;
+ offset_ = kRIFFHeaderSize;
#endif
}
+void AudioStreamSenderThread::SendAudioPassThroughNotification(
+ uint32_t session_key, std::vector<uint8_t>& binary_data) {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ if (!application_manager_.is_audio_pass_thru_active()) {
+ LOG4CXX_ERROR(logger_,
+ "Trying to send PassThroughNotification"
+ " when PassThrough is not active");
+ return;
+ }
+
+ AudioData data;
+ data.session_key = session_key;
+ data.binary_data = binary_data;
+
+ smart_objects::SmartObjectSPtr on_audio_pass =
+ std::make_shared<smart_objects::SmartObject>();
+
+ if (!on_audio_pass) {
+ LOG4CXX_ERROR(logger_, "OnAudioPassThru NULL pointer");
+ return;
+ }
+
+ LOG4CXX_DEBUG(logger_, "Fill smart object");
+
+ (*on_audio_pass)[strings::params][strings::message_type] =
+ application_manager::MessageType::kNotification;
+
+ (*on_audio_pass)[strings::params][strings::connection_key] =
+ static_cast<int32_t>(data.session_key);
+ (*on_audio_pass)[strings::params][strings::function_id] =
+ mobile_apis::FunctionID::OnAudioPassThruID;
+
+ LOG4CXX_DEBUG(logger_, "Fill binary data");
+ // binary data
+ (*on_audio_pass)[strings::params][strings::binary_data] =
+ smart_objects::SmartObject(data.binary_data);
+
+ LOG4CXX_DEBUG(logger_, "After fill binary data");
+ LOG4CXX_DEBUG(logger_, "Send data");
+ application_manager_.GetRPCService().ManageMobileCommand(
+ on_audio_pass, application_manager::commands::Command::SOURCE_SDL);
+}
+
bool AudioStreamSenderThread::getShouldBeStopped() {
AutoLock auto_lock(shouldBeStoped_lock_);
diff --git a/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc b/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
index 99548e71bd..5c12614662 100644
--- a/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
+++ b/src/components/media_manager/src/audio/from_mic_to_file_recorder_thread.cc
@@ -42,6 +42,9 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "MediaManager")
GMainLoop* FromMicToFileRecorderThread::loop = NULL;
+// As per spec, AudioPassThru recording is in monaural
+static const int kNumAudioChannels = 1;
+
FromMicToFileRecorderThread::FromMicToFileRecorderThread(
const std::string& output_file, int32_t duration)
: threads::ThreadDelegate()
@@ -119,7 +122,8 @@ void FromMicToFileRecorderThread::threadMain() {
initArgs();
GstElement* pipeline;
- GstElement* alsasrc, *wavenc, *filesink;
+ GstElement* alsasrc, *audioconvert, *capsfilter, *wavenc, *filesink;
+ GstCaps* audiocaps;
GstBus* bus;
const gchar* device = "hw:0,0";
@@ -196,11 +200,18 @@ void FromMicToFileRecorderThread::threadMain() {
// Create all of the elements to be added to the pipeline
alsasrc = gst_element_factory_make("alsasrc", "alsasrc0");
+ audioconvert = gst_element_factory_make("audioconvert", "audioconvert0");
+ capsfilter = gst_element_factory_make("capsfilter", "filter0");
wavenc = gst_element_factory_make("wavenc", "wavenc0");
filesink = gst_element_factory_make("filesink", "filesink0");
+ // create a capability to downmix the recorded audio to monaural
+ audiocaps = gst_caps_new_simple(
+ "audio/x-raw", "channels", G_TYPE_INT, kNumAudioChannels, NULL);
+
// Assert that all the elements were created
- if (!alsasrc || !wavenc || !filesink) {
+ if (!alsasrc || !audioconvert || !capsfilter || !wavenc || !filesink ||
+ !audiocaps) {
g_error("Failed creating one or more of the pipeline elements.\n");
}
@@ -209,10 +220,21 @@ void FromMicToFileRecorderThread::threadMain() {
g_object_set(G_OBJECT(filesink), "location", outfile, NULL);
// Add the elements to the pipeline
- gst_bin_add_many(GST_BIN(pipeline), alsasrc, wavenc, filesink, NULL);
+ gst_bin_add_many(GST_BIN(pipeline),
+ alsasrc,
+ audioconvert,
+ capsfilter,
+ wavenc,
+ filesink,
+ NULL);
// Link the elements
- gst_element_link_many(alsasrc, wavenc, filesink, NULL);
+ gst_element_link_many(
+ alsasrc, audioconvert, capsfilter, wavenc, filesink, NULL);
+
+ // set the capability
+ g_object_set(G_OBJECT(capsfilter), "caps", audiocaps, NULL);
+ gst_caps_unref(audiocaps);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
diff --git a/src/components/media_manager/src/media_manager_impl.cc b/src/components/media_manager/src/media_manager_impl.cc
index 6a9ded9029..ec88e910d3 100644
--- a/src/components/media_manager/src/media_manager_impl.cc
+++ b/src/components/media_manager/src/media_manager_impl.cc
@@ -98,13 +98,13 @@ void MediaManagerImpl::set_mock_mic_recorder(MediaAdapterImpl* media_adapter) {
void MediaManagerImpl::set_mock_streamer(
protocol_handler::ServiceType stype,
- ::utils::SharedPtr<MediaAdapterImpl> mock_stream) {
+ std::shared_ptr<MediaAdapterImpl> mock_stream) {
streamer_[stype] = mock_stream;
}
void MediaManagerImpl::set_mock_streamer_listener(
protocol_handler::ServiceType stype,
- ::utils::SharedPtr<MediaAdapterListener> mock_stream) {
+ std::shared_ptr<MediaAdapterListener> mock_stream) {
streamer_listener_[stype] = mock_stream;
}
@@ -120,29 +120,36 @@ void MediaManagerImpl::Init() {
#endif
if ("socket" == settings().video_server_type()) {
- streamer_[ServiceType::kMobileNav] = new SocketVideoStreamerAdapter(
- settings().server_address(), settings().video_streaming_port());
+ streamer_[ServiceType::kMobileNav] =
+ std::make_shared<SocketVideoStreamerAdapter>(
+ settings().server_address(), settings().video_streaming_port());
} else if ("pipe" == settings().video_server_type()) {
- streamer_[ServiceType::kMobileNav] = new PipeVideoStreamerAdapter(
- settings().named_video_pipe_path(), settings().app_storage_folder());
+ streamer_[ServiceType::kMobileNav] =
+ std::make_shared<PipeVideoStreamerAdapter>(
+ settings().named_video_pipe_path(),
+ settings().app_storage_folder());
} else if ("file" == settings().video_server_type()) {
- streamer_[ServiceType::kMobileNav] = new FileVideoStreamerAdapter(
- settings().video_stream_file(), settings().app_storage_folder());
+ streamer_[ServiceType::kMobileNav] =
+ std::make_shared<FileVideoStreamerAdapter>(
+ settings().video_stream_file(), settings().app_storage_folder());
}
if ("socket" == settings().audio_server_type()) {
- streamer_[ServiceType::kAudio] = new SocketAudioStreamerAdapter(
- settings().server_address(), settings().audio_streaming_port());
+ streamer_[ServiceType::kAudio] =
+ std::make_shared<SocketAudioStreamerAdapter>(
+ settings().server_address(), settings().audio_streaming_port());
} else if ("pipe" == settings().audio_server_type()) {
- streamer_[ServiceType::kAudio] = new PipeAudioStreamerAdapter(
+ streamer_[ServiceType::kAudio] = std::make_shared<PipeAudioStreamerAdapter>(
settings().named_audio_pipe_path(), settings().app_storage_folder());
} else if ("file" == settings().audio_server_type()) {
- streamer_[ServiceType::kAudio] = new FileAudioStreamerAdapter(
+ streamer_[ServiceType::kAudio] = std::make_shared<FileAudioStreamerAdapter>(
settings().audio_stream_file(), settings().app_storage_folder());
}
- streamer_listener_[ServiceType::kMobileNav] = new StreamerListener(*this);
- streamer_listener_[ServiceType::kAudio] = new StreamerListener(*this);
+ streamer_listener_[ServiceType::kMobileNav] =
+ std::make_shared<StreamerListener>(*this);
+ streamer_listener_[ServiceType::kAudio] =
+ std::make_shared<StreamerListener>(*this);
if (streamer_[ServiceType::kMobileNav]) {
streamer_[ServiceType::kMobileNav]->AddListener(
@@ -187,8 +194,8 @@ void MediaManagerImpl::StartMicrophoneRecording(int32_t application_key,
std::string file_path = settings().app_storage_folder();
file_path += "/";
file_path += output_file;
- from_mic_listener_ =
- new FromMicRecorderListener(file_path, application_manager_);
+ from_mic_listener_ = std::make_shared<FromMicRecorderListener>(
+ file_path, application_manager_);
#ifdef EXTENDED_MEDIA_MODE
if (from_mic_recorder_) {
from_mic_recorder_->AddListener(from_mic_listener_);
diff --git a/src/components/media_manager/src/streamer_adapter.cc b/src/components/media_manager/src/streamer_adapter.cc
index 90a40b1add..37cb1426dc 100644
--- a/src/components/media_manager/src/streamer_adapter.cc
+++ b/src/components/media_manager/src/streamer_adapter.cc
@@ -48,8 +48,8 @@ StreamerAdapter::~StreamerAdapter() {
streamer_->Close();
}
thread_->join();
- threads::DeleteThread(thread_);
delete streamer_;
+ threads::DeleteThread(thread_);
}
void StreamerAdapter::StartActivity(int32_t application_key) {