Merge lp:~phablet-team/media-hub/add-logger into lp:media-hub

Proposed by Jim Hodapp
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: 194
Merged at revision: 178
Proposed branch: lp:~phablet-team/media-hub/add-logger
Merge into: lp:media-hub
Prerequisite: lp:~robru/media-hub/pre_release_hook
Diff against target: 2581 lines (+786/-269)
28 files modified
CMakeLists.txt (+1/-1)
debian/control.in (+1/-0)
include/core/media/player.h (+23/-0)
src/core/media/CMakeLists.txt (+9/-0)
src/core/media/apparmor/ubuntu.cpp (+7/-6)
src/core/media/audio/pulse_audio_output_observer.cpp (+10/-8)
src/core/media/gstreamer/engine.cpp (+30/-29)
src/core/media/gstreamer/playbin.cpp (+39/-46)
src/core/media/logger/logger.cpp (+161/-0)
src/core/media/logger/logger.h (+131/-0)
src/core/media/non_copyable.h (+36/-0)
src/core/media/player_implementation.cpp (+39/-38)
src/core/media/player_skeleton.cpp (+6/-4)
src/core/media/player_stub.cpp (+10/-6)
src/core/media/power/state_controller.cpp (+13/-13)
src/core/media/server/server.cpp (+34/-0)
src/core/media/service.cpp (+3/-1)
src/core/media/service_implementation.cpp (+27/-26)
src/core/media/service_skeleton.cpp (+20/-19)
src/core/media/telephony/CMakeLists.txt (+1/-0)
src/core/media/telephony/call_monitor.cpp (+9/-7)
src/core/media/telephony/qtbridge.cpp (+0/-2)
src/core/media/track_list_implementation.cpp (+25/-23)
src/core/media/track_list_skeleton.cpp (+31/-32)
src/core/media/track_list_stub.cpp (+9/-7)
src/core/media/util/utils.cpp (+41/-0)
src/core/media/util/utils.h (+69/-0)
src/core/media/video/platform_default_sink.cpp (+1/-1)
To merge this branch: bzr merge lp:~phablet-team/media-hub/add-logger
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato Approve
Konrad Zapałowicz code Pending
Review via email: mp+291165@code.launchpad.net

This proposal supersedes a proposal from 2016-04-05.

Commit message

Add a proper logger to media-hub that includes traces, timestamps and other conveniences and no longer rely on cout/cerr.

Description of the change

Add a proper logger to media-hub that includes traces, timestamps and other conveniences and no longer rely on cout/cerr.

To post a comment you must log in.
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote : Posted in a previous version of this proposal

Not many issues compared to the length of the diff and frankly I'm mostly concerned about the own noncopyable class.

There is also one thing which is not bad however I would like to highlight it. I did not like the need to create stringstream in so many cases to log a line as basically this is repeating.

review: Needs Fixing (code)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : Posted in a previous version of this proposal

I have some concerns with this MP:

* I do not really like moving to the printf way of doing things. Why should be drop type safeness? It would be better to use the boost logger more "natively" with "<<" operators, changing the wrapper class to something similar to what Qt does (qDebug() << message, etc.). Even more, using printf way in the end we need to resort to using stringstream in several places where it was not needed before.

* I still see cout and cerr being used in many places. But please do not change that yet until we have an agreement on how the class Logger should be used.

* I do not think we should introduce functions in the Utils namespace that we do not use. Specially taking into account that I would prefer to avoid using the only one that seems to be used, Sprintf :)

* Line sizes in new files are > 100 in many cases

There are also a couple of inline comments.

review: Needs Fixing
Revision history for this message
Jim Hodapp (jhodapp) wrote : Posted in a previous version of this proposal

> Not many issues compared to the length of the diff and frankly I'm mostly
> concerned about the own noncopyable class.

I am using this same logger which comes from aethercast. It relies on it's own noncopyable class, so just maintaing consistency. Really, this logger should be brought into a standard library for everyone to use, but that's out of the scope of this story.

>
> There is also one thing which is not bad however I would like to highlight it.
> I did not like the need to create stringstream in so many cases to log a line
> as basically this is repeating.

Revision history for this message
Jim Hodapp (jhodapp) wrote : Posted in a previous version of this proposal

> I have some concerns with this MP:
>
> * I do not really like moving to the printf way of doing things. Why should be
> drop type safeness? It would be better to use the boost logger more "natively"
> with "<<" operators, changing the wrapper class to something similar to what
> Qt does (qDebug() << message, etc.). Even more, using printf way in the end we
> need to resort to using stringstream in several places where it was not needed
> before.

Boost still maintains complete type safety with using the printf style. See the Boost::Log docs about this if you have any questions. This private Boost::Log interface implementation comes from tvoss and we're starting to standardize on it. Not sure why it doesn't use streams but that's outside anything I can really control without rewriting the private logger interface.

>
> * I still see cout and cerr being used in many places. But please do not
> change that yet until we have an agreement on how the class Logger should be
> used.

There are some that will need to remain, but otherwise I've made sure that all superfluous ones have now been removed.

>
> * I do not think we should introduce functions in the Utils namespace that we
> do not use. Specially taking into account that I would prefer to avoid using
> the only one that seems to be used, Sprintf :)

Fixed

>
> * Line sizes in new files are > 100 in many cases

I tried not to do that, any specific ones?

>
> There are also a couple of inline comments.

Revision history for this message
Jim Hodapp (jhodapp) wrote : Posted in a previous version of this proposal

Replied/addressed inline comments.

Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote : Posted in a previous version of this proposal

Thanks for fixes & explanations, ack.

review: Approve (code)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : Posted in a previous version of this proposal

Thanks for the changes. LGTM, although I do not agree with how the Logger is designed. As discussed, we need to rethink it and come back to this when we do so.

review: Approve
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) :
review: Approve
195. By Jim Hodapp

Make sure everything is licensed under LGPL v3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-12-16 16:55:51 +0000
3+++ CMakeLists.txt 2016-04-07 00:39:05 +0000
4@@ -43,7 +43,7 @@
5 include(GNUInstallDirs)
6
7 find_package(PkgConfig)
8-find_package(Boost COMPONENTS filesystem system program_options REQUIRED)
9+find_package(Boost COMPONENTS filesystem log system thread program_options REQUIRED)
10 find_package(GLog)
11 pkg_check_modules(DBUS dbus-1 REQUIRED)
12 pkg_check_modules(DBUS_CPP dbus-cpp REQUIRED)
13
14=== modified file 'debian/control.in'
15--- debian/control.in 2015-11-22 21:01:02 +0000
16+++ debian/control.in 2016-04-07 00:39:05 +0000
17@@ -12,6 +12,7 @@
18 gstreamer1.0-plugins-good,
19 libboost-dev (>=1.53),
20 libboost-filesystem-dev (>=1.53),
21+ libboost-log-dev (>=1.53),
22 libboost-program-options-dev (>=1.53),
23 libboost-system-dev (>=1.53),
24 libdbus-1-dev,
25
26=== modified file 'include/core/media/player.h'
27--- include/core/media/player.h 2016-02-19 16:14:42 +0000
28+++ include/core/media/player.h 2016-04-07 00:39:05 +0000
29@@ -229,6 +229,29 @@
30 return out;
31 }
32
33+inline std::ostream& operator<<(std::ostream& out, Player::Error e)
34+{
35+ switch (e)
36+ {
37+ case Player::Error::no_error:
38+ return out << "Error::no_error";
39+ case Player::Error::resource_error:
40+ return out << "Error::resource_error";
41+ case Player::Error::format_error:
42+ return out << "Error::format_error";
43+ case Player::Error::network_error:
44+ return out << "Error::network_error";
45+ case Player::Error::access_denied_error:
46+ return out << "Error::access_denied_error";
47+ case Player::Error::service_missing_error:
48+ return out << "Error::service_missing_error";
49+ default:
50+ return out << "Unsupported Player error: " << e;
51+ }
52+
53+ return out;
54+}
55+
56 }
57 }
58 }
59
60=== modified file 'src/core/media/CMakeLists.txt'
61--- src/core/media/CMakeLists.txt 2015-09-04 18:46:08 +0000
62+++ src/core/media/CMakeLists.txt 2016-04-07 00:39:05 +0000
63@@ -18,6 +18,7 @@
64 media-hub-common SHARED
65
66 the_session_bus.cpp
67+ util/utils.cpp
68 )
69
70 target_link_libraries(
71@@ -42,6 +43,8 @@
72
73 ${MEDIA_HUB_HEADERS}
74
75+ logger/logger.cpp
76+
77 player.cpp
78 service.cpp
79 track.cpp
80@@ -70,6 +73,8 @@
81
82 media-hub-common
83
84+ ${Boost_LDFLAGS}
85+ ${Boost_LIBRARIES}
86 ${DBUS_LIBRARIES}
87 ${DBUS_CPP_LDFLAGS}
88 ${GLog_LIBRARY}
89@@ -87,6 +92,8 @@
90 ${MEDIA_HUB_HEADERS}
91 ${MPRIS_HEADERS}
92
93+ logger/logger.cpp
94+
95 client_death_observer.cpp
96 hashed_keyed_player_store.cpp
97 hybris_client_death_observer.cpp
98@@ -123,6 +130,8 @@
99 media-hub-client
100 media-hub-common
101 call-monitor
102+ ${Boost_LDFLAGS}
103+ ${Boost_LIBRARIES}
104 ${DBUS_LIBRARIES}
105 ${DBUS_CPP_LDFLAGS}
106 ${GLog_LIBRARY}
107
108=== modified file 'src/core/media/apparmor/ubuntu.cpp'
109--- src/core/media/apparmor/ubuntu.cpp 2016-02-23 14:17:04 +0000
110+++ src/core/media/apparmor/ubuntu.cpp 2016-04-07 00:39:05 +0000
111@@ -20,7 +20,8 @@
112
113 #include <core/media/external_services.h>
114
115-#include <iostream>
116+#include "core/media/logger/logger.h"
117+
118 #include <regex>
119
120 namespace apparmor = core::ubuntu::media::apparmor;
121@@ -107,9 +108,9 @@
122 unity_{name == unity_name},
123 has_package_name_{process_context_name(str(), match_, pkg_name_)}
124 {
125- std::cout << "apparmor profile name: " << name;
126- std::cout << ", is_unconfined(): " << is_unconfined();
127- std::cout << ", has_package_name(): " << has_package_name() << std::endl;
128+ MH_DEBUG("apparmor profile name: %s", name);
129+ MH_DEBUG("is_unconfined(): %s", (is_unconfined() ? "true" : "false"));
130+ MH_DEBUG("has_package_name(): %s", (has_package_name() ? "true" : "false"));
131 if (not is_unconfined() and not is_unity() and not has_package_name())
132 throw std::logic_error
133 {
134@@ -163,8 +164,8 @@
135
136 Uri parsed_uri = parse_uri(uri);
137
138- std::cout << "context.profile_name(): " << context.profile_name() << std::endl;
139- std::cout << "parsed_uri.path: " << parsed_uri.path << std::endl;
140+ MH_DEBUG("context.profile_name(): %s", context.profile_name());
141+ MH_DEBUG("parsed_uri.path: %s", parsed_uri.path);
142
143 // All confined apps can access their own files
144 if (parsed_uri.path.find(std::string(".local/share/" + context.package_name() + "/")) != std::string::npos ||
145
146=== modified file 'src/core/media/audio/pulse_audio_output_observer.cpp'
147--- src/core/media/audio/pulse_audio_output_observer.cpp 2015-03-19 00:04:12 +0000
148+++ src/core/media/audio/pulse_audio_output_observer.cpp 2016-04-07 00:39:05 +0000
149@@ -21,6 +21,8 @@
150
151 #include <pulse/pulseaudio.h>
152
153+#include "core/media/logger/logger.h"
154+
155 #include <cstdint>
156
157 #include <map>
158@@ -245,7 +247,7 @@
159 std::get<1>(outputs.back()) | properties.external_output_state;
160 std::get<1>(outputs.back()).changed().connect([](media::audio::OutputState state)
161 {
162- std::cout << "Connection state for port changed to: " << state << std::endl;
163+ MH_DEBUG("Connection state for port changed to: %s", state);
164 });
165 }
166
167@@ -289,8 +291,8 @@
168 void on_sink_event_with_index(std::int32_t index)
169 {
170 config.reporter->sink_event_with_index(index);
171-
172- // Update server info (active sink)
173+
174+ // Update server info (active sink)
175 pa::get_server_info_async(context, main_loop, Private::query_for_server_info_finished, this);
176
177 }
178@@ -317,15 +319,15 @@
179 if (std::get<0>(active_sink) != info->index)
180 continue;
181
182- std::cout << "Checking if port is available " << " -> " << std::boolalpha << pa::is_port_available_on_sink(info, std::get<0>(element)) << std::endl;
183- bool available = pa::is_port_available_on_sink(info, std::get<0>(element));
184-
185+ MH_INFO("Checking if port is available -> %s",
186+ pa::is_port_available_on_sink(info, std::get<0>(element)));
187+ const bool available = pa::is_port_available_on_sink(info, std::get<0>(element));
188 if (available)
189 {
190 std::get<1>(element) = audio::OutputState::Earpiece;
191 continue;
192 }
193-
194+
195 audio::OutputState state;
196 if (info->index == primary_sink_index)
197 state = audio::OutputState::Speaker;
198@@ -386,7 +388,7 @@
199 }
200 }
201
202- PulseAudioOutputObserver::Configuration config;
203+ PulseAudioOutputObserver::Configuration config;
204 pa::ThreadedMainLoopPtr main_loop;
205 pa::ContextPtr context;
206 std::int32_t primary_sink_index;
207
208=== modified file 'src/core/media/gstreamer/engine.cpp'
209--- src/core/media/gstreamer/engine.cpp 2016-02-19 16:14:42 +0000
210+++ src/core/media/gstreamer/engine.cpp 2016-04-07 00:39:05 +0000
211@@ -25,6 +25,8 @@
212 #include "meta_data_extractor.h"
213 #include "playbin.h"
214
215+#include "core/media/logger/logger.h"
216+
217 #include <cassert>
218
219 namespace media = core::ubuntu::media;
220@@ -67,8 +69,8 @@
221 {
222 if (p.second == "playbin")
223 {
224- std::cout << "State changed on playbin: "
225- << gst_element_state_get_name(p.first.new_state) << std::endl;
226+ MH_INFO("State changed on playbin: %s",
227+ gst_element_state_get_name(p.first.new_state));
228 const auto status = gst_state_to_player_status(p.first);
229 /*
230 * When state moves to "paused" the pipeline is already set. We check that we
231@@ -76,7 +78,7 @@
232 */
233 if (status == media::Player::PlaybackStatus::paused &&
234 !playbin.can_play_streams()) {
235- std::cerr << "** Cannot play: some codecs are missing" << std::endl;
236+ MH_ERROR("** Cannot play: some codecs are missing");
237 playbin.reset();
238 const media::Player::Error e = media::Player::Error::format_error;
239 error(e);
240@@ -96,20 +98,20 @@
241 switch (ewi.error->code)
242 {
243 case GST_CORE_ERROR_FAILED:
244- std::cerr << "** Encountered a GST_CORE_ERROR_FAILED" << std::endl;
245+ MH_ERROR("** Encountered a GST_CORE_ERROR_FAILED");
246 ret_error = media::Player::Error::resource_error;
247 break;
248 case GST_CORE_ERROR_NEGOTIATION:
249- std::cerr << "** Encountered a GST_CORE_ERROR_NEGOTIATION" << std::endl;
250+ MH_ERROR("** Encountered a GST_CORE_ERROR_NEGOTIATION");
251 ret_error = media::Player::Error::resource_error;
252 break;
253 case GST_CORE_ERROR_MISSING_PLUGIN:
254- std::cerr << "** Encountered a GST_CORE_ERROR_MISSING_PLUGIN" << std::endl;
255+ MH_ERROR("** Encountered a GST_CORE_ERROR_MISSING_PLUGIN");
256 ret_error = media::Player::Error::format_error;
257 break;
258 default:
259- std::cerr << "** Encountered an unhandled core error: '"
260- << ewi.debug << "' (code: " << ewi.error->code << ")" << std::endl;
261+ MH_ERROR("** Encountered an unhandled core error: '%s' (code: %d)",
262+ ewi.debug, ewi.error->code);
263 ret_error = media::Player::Error::no_error;
264 break;
265 }
266@@ -119,36 +121,36 @@
267 switch (ewi.error->code)
268 {
269 case GST_RESOURCE_ERROR_FAILED:
270- std::cerr << "** Encountered a GST_RESOURCE_ERROR_FAILED" << std::endl;
271+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_FAILED");
272 ret_error = media::Player::Error::resource_error;
273 break;
274 case GST_RESOURCE_ERROR_NOT_FOUND:
275- std::cerr << "** Encountered a GST_RESOURCE_ERROR_NOT_FOUND" << std::endl;
276+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_NOT_FOUND");
277 ret_error = media::Player::Error::resource_error;
278 break;
279 case GST_RESOURCE_ERROR_OPEN_READ:
280- std::cerr << "** Encountered a GST_RESOURCE_ERROR_OPEN_READ" << std::endl;
281+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_OPEN_READ");
282 ret_error = media::Player::Error::resource_error;
283 break;
284 case GST_RESOURCE_ERROR_OPEN_WRITE:
285- std::cerr << "** Encountered a GST_RESOURCE_ERROR_OPEN_WRITE" << std::endl;
286+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_OPEN_WRITE");
287 ret_error = media::Player::Error::resource_error;
288 break;
289 case GST_RESOURCE_ERROR_READ:
290- std::cerr << "** Encountered a GST_RESOURCE_ERROR_READ" << std::endl;
291+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_READ");
292 ret_error = media::Player::Error::resource_error;
293 break;
294 case GST_RESOURCE_ERROR_WRITE:
295- std::cerr << "** Encountered a GST_RESOURCE_ERROR_WRITE" << std::endl;
296+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_WRITE");
297 ret_error = media::Player::Error::resource_error;
298 break;
299 case GST_RESOURCE_ERROR_NOT_AUTHORIZED:
300- std::cerr << "** Encountered a GST_RESOURCE_ERROR_NOT_AUTHORIZED" << std::endl;
301+ MH_ERROR("** Encountered a GST_RESOURCE_ERROR_NOT_AUTHORIZED");
302 ret_error = media::Player::Error::access_denied_error;
303 break;
304 default:
305- std::cerr << "** Encountered an unhandled resource error: '"
306- << ewi.debug << "' (code: " << ewi.error->code << ")" << std::endl;
307+ MH_ERROR("** Encountered an unhandled resource error: '%s' (code: %d)",
308+ ewi.debug, ewi.error->code);
309 ret_error = media::Player::Error::no_error;
310 break;
311 }
312@@ -158,28 +160,28 @@
313 switch (ewi.error->code)
314 {
315 case GST_STREAM_ERROR_FAILED:
316- std::cerr << "** Encountered a GST_STREAM_ERROR_FAILED" << std::endl;
317+ MH_ERROR("** Encountered a GST_STREAM_ERROR_FAILED");
318 ret_error = media::Player::Error::resource_error;
319 break;
320 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
321- std::cerr << "** Encountered a GST_STREAM_ERROR_CODEC_NOT_FOUND" << std::endl;
322+ MH_ERROR("** Encountered a GST_STREAM_ERROR_CODEC_NOT_FOUND");
323 // Missing codecs are handled later, when state switches to "paused"
324 ret_error = media::Player::Error::no_error;
325 break;
326 case GST_STREAM_ERROR_DECODE:
327- std::cerr << "** Encountered a GST_STREAM_ERROR_DECODE" << std::endl;
328+ MH_ERROR("** Encountered a GST_STREAM_ERROR_DECODE");
329 ret_error = media::Player::Error::format_error;
330 break;
331 default:
332- std::cerr << "** Encountered an unhandled stream error: '"
333- << ewi.debug << "' (code: " << ewi.error->code << ")" << std::endl;
334+ MH_ERROR("** Encountered an unhandled stream error: '%s' code(%d)",
335+ ewi.debug, ewi.error->code);
336 ret_error = media::Player::Error::no_error;
337 break;
338 }
339 }
340
341 if (ret_error != media::Player::Error::no_error) {
342- std::cerr << "Resetting playbin pipeline after unrecoverable error" << std::endl;
343+ MH_ERROR("Resetting playbin pipeline after unrecoverable error");
344 playbin.reset();
345 }
346 return ret_error;
347@@ -201,7 +203,7 @@
348
349 void on_playbin_info(const gstreamer::Bus::Message::Detail::ErrorWarningInfo& ewi)
350 {
351- std::cerr << "Got a playbin info message (no action taken): " << ewi.debug << std::endl;
352+ MH_DEBUG("Got a playbin info message (no action taken): %s", ewi.debug);
353 }
354
355 void on_tag_available(const gstreamer::Bus::Message::Detail::Tag& tag)
356@@ -437,8 +439,7 @@
357 if (result)
358 {
359 d->state = media::Engine::State::playing;
360- cout << __PRETTY_FUNCTION__ << endl;
361- cout << "Engine: playing uri: " << d->playbin.uri() << endl;
362+ MH_INFO("Engine: playing uri: %s", d->playbin.uri());
363 d->playback_status_changed(media::Player::PlaybackStatus::playing);
364 }
365
366@@ -450,7 +451,7 @@
367 // No need to wait, and we can immediately return.
368 if (d->state == media::Engine::State::stopped)
369 {
370- std::cerr << "Current player state is already stopped - no need to change state to stopped" << std::endl;
371+ MH_DEBUG("Current player state is already stopped - no need to change state to stopped");
372 return true;
373 }
374
375@@ -458,7 +459,7 @@
376 if (result)
377 {
378 d->state = media::Engine::State::stopped;
379- cout << __PRETTY_FUNCTION__ << endl;
380+ MH_TRACE("");
381 d->playback_status_changed(media::Player::PlaybackStatus::stopped);
382 }
383
384@@ -472,7 +473,7 @@
385 if (result)
386 {
387 d->state = media::Engine::State::paused;
388- cout << __PRETTY_FUNCTION__ << endl;
389+ MH_TRACE("");
390 d->playback_status_changed(media::Player::PlaybackStatus::paused);
391 }
392
393
394=== modified file 'src/core/media/gstreamer/playbin.cpp'
395--- src/core/media/gstreamer/playbin.cpp 2016-03-07 21:05:26 +0000
396+++ src/core/media/gstreamer/playbin.cpp 2016-04-07 00:39:05 +0000
397@@ -25,7 +25,8 @@
398 #include <hybris/media/surface_texture_client_hybris.h>
399 #include <hybris/media/media_codec_layer.h>
400
401-#include "../util/uri_check.h"
402+#include "core/media/logger/logger.h"
403+#include "core/media/util/uri_check.h"
404
405 #include <utility>
406
407@@ -154,13 +155,13 @@
408 {
409 using namespace std;
410
411- cout << func << endl;
412+ MH_DEBUG("%s", func);
413 if (pb.pipeline)
414- cout << "pipeline: " << GST_OBJECT_REFCOUNT(pb.pipeline) << endl;
415+ MH_DEBUG("pipeline: %d", GST_OBJECT_REFCOUNT(pb.pipeline));
416 if (pb.video_sink)
417- cout << "video_sink: " << GST_OBJECT_REFCOUNT(pb.video_sink) << endl;
418+ MH_DEBUG("video_sink: %d", GST_OBJECT_REFCOUNT(pb.video_sink));
419 if (pb.audio_sink)
420- cout << "audio_sink: " << GST_OBJECT_REFCOUNT(pb.audio_sink) << endl;
421+ MH_DEBUG("audio_sink: %d", GST_OBJECT_REFCOUNT(pb.audio_sink));
422 }
423 #endif
424
425@@ -183,7 +184,7 @@
426
427 void gstreamer::Playbin::reset()
428 {
429- std::cout << "Client died, resetting pipeline" << std::endl;
430+ MH_INFO("Client died, resetting pipeline");
431 // When the client dies, tear down the current pipeline and get it
432 // in a state that is ready for the next client that connects to the
433 // service
434@@ -198,19 +199,19 @@
435
436 void gstreamer::Playbin::reset_pipeline()
437 {
438- std::cout << __PRETTY_FUNCTION__ << std::endl;
439- auto ret = gst_element_set_state(pipeline, GST_STATE_NULL);
440- switch(ret)
441+ MH_TRACE("");
442+ const auto ret = gst_element_set_state(pipeline, GST_STATE_NULL);
443+ switch (ret)
444 {
445 case GST_STATE_CHANGE_FAILURE:
446- std::cout << "Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;
447+ MH_WARNING("Failed to reset the pipeline state. Client reconnect may not function properly.");
448 break;
449 case GST_STATE_CHANGE_NO_PREROLL:
450 case GST_STATE_CHANGE_SUCCESS:
451 case GST_STATE_CHANGE_ASYNC:
452 break;
453 default:
454- std::cout << "Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;
455+ MH_WARNING("Failed to reset the pipeline state. Client reconnect may not function properly.");
456 }
457 file_type = MEDIA_FILE_TYPE_NONE;
458 is_missing_audio_codec = false;
459@@ -225,7 +226,7 @@
460 return;
461
462 gchar *desc = gst_missing_plugin_message_get_description(message);
463- std::cerr << "Missing plugin: " << desc << std::endl;
464+ MH_WARNING("Missing plugin: %s", desc);
465 g_free(desc);
466
467 const GstStructure *msg_data = gst_message_get_structure(message);
468@@ -234,13 +235,13 @@
469
470 GstCaps *caps;
471 if (!gst_structure_get(msg_data, "detail", GST_TYPE_CAPS, &caps, NULL)) {
472- std::cerr << __PRETTY_FUNCTION__ << ": No detail" << std::endl;
473+ MH_ERROR("No detail");
474 return;
475 }
476
477 GstStructure *caps_data = gst_caps_get_structure(caps, 0);
478 if (!caps_data) {
479- std::cerr << __PRETTY_FUNCTION__ << ": No caps data" << std::endl;
480+ MH_ERROR("No caps data");
481 return;
482 }
483
484@@ -250,7 +251,7 @@
485 else if (strstr(mime, "video"))
486 is_missing_video_codec = true;
487
488- std::cerr << "Missing decoder for " << mime << std::endl;
489+ MH_ERROR("Missing decoder for %s", mime);
490 }
491
492 void gstreamer::Playbin::on_new_message_async(const Bus::Message& message)
493@@ -324,7 +325,7 @@
494 ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME"),
495 "audio-sink");
496
497- std::cout << "audio_sink: " << ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME") << std::endl;
498+ MH_INFO("audio_sink: %s", ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME"));
499
500 g_object_set (
501 pipeline,
502@@ -339,7 +340,7 @@
503 ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),
504 "video-sink");
505
506- std::cout << "video_sink: " << ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") << std::endl;
507+ MH_INFO("video_sink: %s", ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"));
508
509 g_object_set (
510 pipeline,
511@@ -404,16 +405,17 @@
512 /** Sets the new audio stream role on the pulsesink in playbin */
513 void gstreamer::Playbin::set_audio_stream_role(media::Player::AudioStreamRole new_audio_role)
514 {
515- std::string role_str("props,media.role=" + get_audio_role_str(new_audio_role));
516- std::cout << "Audio stream role: " << role_str << std::endl;
517+ const std::string role_str("props,media.role=" + get_audio_role_str(new_audio_role));
518+ MH_INFO("Audio stream role: %s", role_str);
519
520 GstStructure *props = gst_structure_from_string (role_str.c_str(), NULL);
521- if (audio_sink != nullptr && props != nullptr) {
522+ if (audio_sink != nullptr && props != nullptr)
523+ {
524 g_object_set (audio_sink, "stream-properties", props, NULL);
525- } else {
526- std::cerr <<
527- "Warning: couldn't set audio stream role - couldn't get audio_sink from pipeline" <<
528- std::endl;
529+ }
530+ else
531+ {
532+ MH_WARNING("Couldn't set audio stream role - couldn't get audio_sink from pipeline");
533 }
534
535 gst_structure_free (props);
536@@ -475,9 +477,7 @@
537 {
538 // First decode the URI just in case it's partially encoded already
539 tmp_uri = decode_uri(uri);
540-#ifdef VERBOSE_DEBUG
541- std::cout << "File URI was encoded, now decoded: " << tmp_uri << std::endl;
542-#endif
543+ MH_DEBUG("File URI was encoded, now decoded: %s", tmp_uri);
544 }
545 tmp_uri = encode_uri(tmp_uri);
546 }
547@@ -538,7 +538,7 @@
548
549 auto ret = gst_element_set_state(pipeline, new_state);
550
551- std::cout << __PRETTY_FUNCTION__ << ": requested state change." << std::endl;
552+ MH_DEBUG("Requested state change.");
553
554 bool result = false; GstState current, pending;
555 switch(ret)
556@@ -570,15 +570,15 @@
557 }
558 catch (const std::exception& e)
559 {
560- std::cerr << "Problem querying video dimensions: " << e.what() << std::endl;
561+ MH_WARNING("Problem querying video dimensions: %s", e.what());
562 }
563 catch (...)
564 {
565- std::cerr << "Problem querying video dimensions." << std::endl;
566+ MH_WARNING("Problem querying video dimensions.");
567 }
568
569 #ifdef DEBUG_GST_PIPELINE
570- std::cout << "Dumping pipeline dot file" << std::endl;
571+ MH_DEBUG("Dumping pipeline dot file");
572 GST_DEBUG_BIN_TO_DOT_FILE((GstBin*)pipeline, GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");
573 #endif
574 }
575@@ -656,17 +656,13 @@
576 // We have a URI and it is already percent encoded
577 if (uri_scheme and strlen(uri_scheme) > 0 and uri_check->is_encoded())
578 {
579-#ifdef VERBOSE_DEBUG
580- std::cout << "Is a URI and is already percent encoded" << std::endl;
581-#endif
582+ MH_DEBUG("Is a URI and is already percent encoded");
583 encoded_uri = uri;
584 }
585 // We have a URI but it's not already percent encoded
586 else if (uri_scheme and strlen(uri_scheme) > 0 and !uri_check->is_encoded())
587 {
588-#ifdef VERBOSE_DEBUG
589- std::cout << "Is a URI and is not already percent encoded" << std::endl;
590-#endif
591+ MH_DEBUG("Is a URI and is not already percent encoded");
592 gchar *encoded = g_uri_escape_string(uri.c_str(),
593 "!$&'()*+,;=:/?[]@", // reserved chars
594 TRUE); // Allow UTF-8 chars
595@@ -681,9 +677,7 @@
596 else // We have a path and not a URI. Turn it into a full URI and encode it
597 {
598 GError *error = nullptr;
599-#ifdef VERBOSE_DEBUG
600- std::cout << "Is a path and is not already percent encoded" << std::endl;
601-#endif
602+ MH_DEBUG("Is a path and is not already percent encoded");
603 gchar *str = g_filename_to_uri(uri.c_str(), nullptr, &error);
604 if (!str)
605 {
606@@ -694,8 +688,7 @@
607 g_free(str);
608 if (error != nullptr)
609 {
610- std::cerr << "Warning: failed to get actual track content type: " << error->message
611- << std::endl;
612+ MH_WARNING("Failed to get actual track content type: %s", error->message);
613 g_error_free(error);
614 g_free(str);
615 g_free(uri_scheme);
616@@ -742,11 +735,11 @@
617 const std::string content_type {file_info_from_uri(encoded_uri)};
618 if (content_type.empty())
619 {
620- std::cerr << "Warning: failed to get actual track content type" << std::endl;
621+ MH_WARNING("Failed to get actual track content type");
622 return std::string("audio/video/");
623 }
624
625- std::cout << "Found content type: " << content_type << std::endl;
626+ MH_INFO("Found content type: %s", content_type);
627
628 return content_type;
629 }
630@@ -758,7 +751,7 @@
631
632 if (get_file_content_type(uri).find("audio/") == 0)
633 {
634- std::cout << "Found audio content" << std::endl;
635+ MH_INFO("Found audio content");
636 return true;
637 }
638
639@@ -772,7 +765,7 @@
640
641 if (get_file_content_type(uri).find("video/") == 0)
642 {
643- std::cout << "Found video content" << std::endl;
644+ MH_INFO("Found video content");
645 return true;
646 }
647
648
649=== added directory 'src/core/media/logger'
650=== added file 'src/core/media/logger/logger.cpp'
651--- src/core/media/logger/logger.cpp 1970-01-01 00:00:00 +0000
652+++ src/core/media/logger/logger.cpp 2016-04-07 00:39:05 +0000
653@@ -0,0 +1,161 @@
654+/*
655+ * Copyright © 2016 Canonical Ltd.
656+ *
657+ * This program is free software: you can redistribute it and/or modify it
658+ * under the terms of the GNU Lesser General Public License version 3,
659+ * as published by the Free Software Foundation.
660+ *
661+ * This program is distributed in the hope that it will be useful,
662+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
663+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
664+ * GNU Lesser General Public License for more details.
665+ *
666+ * You should have received a copy of the GNU Lesser General Public License
667+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
668+ *
669+ */
670+
671+#include <thread>
672+
673+#include "logger.h"
674+
675+#define BOOST_LOG_DYN_LINK
676+#include <boost/date_time.hpp>
677+#include <boost/filesystem.hpp>
678+#include <boost/log/trivial.hpp>
679+#include <boost/log/expressions.hpp>
680+#include <boost/log/support/date_time.hpp>
681+#include <boost/log/utility/manipulators.hpp>
682+#include <boost/log/utility/setup.hpp>
683+
684+namespace media = core::ubuntu::media;
685+
686+namespace {
687+namespace attrs {
688+BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "core::ubuntu::media::Severity", media::Logger::Severity)
689+BOOST_LOG_ATTRIBUTE_KEYWORD(Location, "Location", media::Logger::Location)
690+BOOST_LOG_ATTRIBUTE_KEYWORD(Timestamp, "Timestamp", boost::posix_time::ptime)
691+}
692+
693+struct BoostLogLogger : public media::Logger {
694+ BoostLogLogger() :
695+ initialized_(false) {
696+ }
697+
698+ void Init(const media::Logger::Severity &severity = media::Logger::Severity::kWarning) override {
699+ if (initialized_)
700+ return;
701+
702+ boost::log::formatter formatter = boost::log::expressions::stream
703+ << "[" << attrs::Severity << " "
704+ << boost::log::expressions::format_date_time< boost::posix_time::ptime >("Timestamp", "%Y-%m-%d %H:%M:%S.%f")
705+ << "] "
706+ << boost::log::expressions::if_(boost::log::expressions::has_attr(attrs::Location))
707+ [
708+ boost::log::expressions::stream << "[" << attrs::Location << "] "
709+ ]
710+ << boost::log::expressions::smessage;
711+
712+ boost::log::core::get()->remove_all_sinks();
713+ auto logger = boost::log::add_console_log(std::cout);
714+ logger->set_formatter(formatter);
715+
716+ // FIXME need to enable this once we found how we wrap this
717+ // properly into our service architecture. For now left as
718+ // it is.
719+ boost::ignore_unused_variable_warning(severity);
720+ // logger->set_filter(attrs::Severity < severity);
721+
722+ initialized_ = true;
723+ }
724+
725+ void Log(Severity severity, const std::string& message, const boost::optional<Location> &loc) {
726+ if (!initialized_)
727+ Init();
728+
729+ if (auto rec = boost::log::trivial::logger::get().open_record()) {
730+ boost::log::record_ostream out{rec};
731+ out << boost::log::add_value(attrs::Severity, severity)
732+ << boost::log::add_value(attrs::Timestamp, boost::posix_time::microsec_clock::universal_time())
733+ << message;
734+
735+ if (loc) {
736+ // We have to pass in a temporary as boost::log (<= 1.55) expects a
737+ // mutable reference to be passed to boost::log::add_value(...).
738+ auto tmp = *loc;
739+ out << boost::log::add_value(attrs::Location, tmp);
740+ }
741+
742+ boost::log::trivial::logger::get().push_record(std::move(rec));
743+ }
744+ }
745+
746+private:
747+ bool initialized_;
748+};
749+
750+std::shared_ptr<media::Logger>& MutableInstance() {
751+ static std::shared_ptr<media::Logger> instance{new BoostLogLogger()};
752+ return instance;
753+}
754+
755+void SetInstance(const std::shared_ptr<media::Logger>& logger) {
756+ MutableInstance() = logger;
757+}
758+}
759+
760+void media::Logger::Trace(const std::string& message, const boost::optional<Location>& location) {
761+ Log(Severity::kTrace, message, location);
762+}
763+
764+void media::Logger::Debug(const std::string& message, const boost::optional<Location>& location) {
765+ Log(Severity::kDebug, message, location);
766+}
767+
768+void media::Logger::Info(const std::string& message, const boost::optional<Location>& location) {
769+ Log(Severity::kInfo, message, location);
770+}
771+
772+void media::Logger::Warning(const std::string& message, const boost::optional<Location>& location) {
773+ Log(Severity::kWarning, message, location);
774+}
775+
776+void media::Logger::Error(const std::string& message, const boost::optional<Location>& location) {
777+ Log(Severity::kError, message, location);
778+}
779+
780+void media::Logger::Fatal(const std::string& message, const boost::optional<Location>& location) {
781+ Log(Severity::kFatal, message, location);
782+}
783+
784+namespace core {
785+namespace ubuntu {
786+namespace media {
787+
788+std::ostream& operator<<(std::ostream& strm, Logger::Severity severity) {
789+ switch (severity) {
790+ case media::Logger::Severity::kTrace: return strm << "TT";
791+ case media::Logger::Severity::kDebug: return strm << "DD";
792+ case media::Logger::Severity::kInfo: return strm << "II";
793+ case media::Logger::Severity::kWarning: return strm << "WW";
794+ case media::Logger::Severity::kError: return strm << "EE";
795+ case media::Logger::Severity::kFatal: return strm << "FF";
796+ default: return strm << static_cast<uint>(severity);
797+ }
798+}
799+
800+std::ostream& operator<<(std::ostream& out, const Logger::Location &location) {
801+ return out << Utils::Sprintf("%s:%d@%s", boost::filesystem::path(location.file).filename().string(), location.line, location.function);
802+}
803+
804+Logger& Log() {
805+ return *MutableInstance();
806+}
807+
808+void SetLogger(const std::shared_ptr<Logger>& logger) {
809+ SetInstance(logger);
810+}
811+
812+} // namespace media
813+} // namespace ubuntu
814+} // namespace core
815
816=== added file 'src/core/media/logger/logger.h'
817--- src/core/media/logger/logger.h 1970-01-01 00:00:00 +0000
818+++ src/core/media/logger/logger.h 2016-04-07 00:39:05 +0000
819@@ -0,0 +1,131 @@
820+/*
821+ * Copyright © 2016 Canonical Ltd.
822+ *
823+ * This program is free software: you can redistribute it and/or modify it
824+ * under the terms of the GNU Lesser General Public License version 3,
825+ * as published by the Free Software Foundation.
826+ *
827+ * This program is distributed in the hope that it will be useful,
828+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
829+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
830+ * GNU Lesser General Public License for more details.
831+ *
832+ * You should have received a copy of the GNU Lesser General Public License
833+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
834+ *
835+ */
836+
837+#ifndef LOGGER_H_
838+#define LOGGER_H_
839+
840+#include "core/media/non_copyable.h"
841+#include "core/media/util/utils.h"
842+
843+#include <boost/optional.hpp>
844+
845+#include <string>
846+
847+namespace core {
848+namespace ubuntu {
849+namespace media {
850+// A Logger enables persisting of messages describing & explaining the
851+// state of the system.
852+class Logger : public core::ubuntu::media::NonCopyable {
853+public:
854+ // Severity enumerates all known severity levels
855+ // applicable to log messages.
856+ enum class Severity {
857+ kTrace,
858+ kDebug,
859+ kInfo,
860+ kWarning,
861+ kError,
862+ kFatal
863+ };
864+
865+ // A Location describes the origin of a log message.
866+ struct Location {
867+ std::string file; // The name of the file that contains the log message.
868+ std::string function; // The function that contains the log message.
869+ std::uint32_t line; // The line in file that resulted in the log message.
870+ };
871+
872+ virtual void Init(const core::ubuntu::media::Logger::Severity &severity = core::ubuntu::media::Logger::Severity::kWarning) = 0;
873+
874+ virtual void Log(Severity severity, const std::string &message, const boost::optional<Location>& location) = 0;
875+
876+ virtual void Trace(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
877+ virtual void Debug(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
878+ virtual void Info(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
879+ virtual void Warning(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
880+ virtual void Error(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
881+ virtual void Fatal(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
882+
883+
884+ template<typename... T>
885+ void Tracef(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
886+ Trace(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
887+ }
888+
889+ template<typename... T>
890+ void Debugf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
891+ Debug(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
892+ }
893+
894+ template<typename... T>
895+ void Infof(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
896+ Info(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
897+ }
898+
899+ template<typename... T>
900+ void Warningf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
901+ Warning(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
902+ }
903+
904+ template<typename... T>
905+ void Errorf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
906+ Error(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
907+ }
908+
909+ template<typename... T>
910+ void Fatalf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
911+ Fatal(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
912+ }
913+
914+protected:
915+ Logger() = default;
916+};
917+
918+// operator<< inserts severity into out.
919+std::ostream& operator<<(std::ostream& out, Logger::Severity severity);
920+
921+// operator<< inserts location into out.
922+std::ostream& operator<<(std::ostream& out, const Logger::Location &location);
923+
924+// Log returns the core::ubuntu::media-wide configured logger instance.
925+// Save to call before/after main.
926+Logger& Log();
927+// SetLog installs the given logger as core::ubuntu::media-wide default logger.
928+void SetLogger(const std::shared_ptr<Logger>& logger);
929+
930+#define TRACE(...) Log().Tracef(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
931+#define DEBUG(...) Log().Debugf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
932+#define INFO(...) Log().Infof(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
933+#define WARNING(...) Log().Warningf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
934+#define ERROR(...) Log().Errorf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
935+#define FATAL(...) Log().Fatalf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
936+} // namespace media
937+} // namespace ubuntu
938+} // namespace core
939+
940+#define MH_TRACE(...) core::ubuntu::media::Log().Tracef(\
941+ core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
942+#define MH_DEBUG(...) core::ubuntu::media::Log().Debugf(\
943+ core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
944+#define MH_INFO(...) core::ubuntu::media::Log().Infof(\
945+ core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
946+#define MH_WARNING(...) core::ubuntu::media::Log().Warningf(core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
947+#define MH_ERROR(...) core::ubuntu::media::Log().Errorf(core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
948+#define MH_FATAL(...) core::ubuntu::media::Log().Fatalf(core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
949+
950+#endif
951
952=== added file 'src/core/media/non_copyable.h'
953--- src/core/media/non_copyable.h 1970-01-01 00:00:00 +0000
954+++ src/core/media/non_copyable.h 2016-04-07 00:39:05 +0000
955@@ -0,0 +1,36 @@
956+/*
957+ * Copyright © 2016 Canonical Ltd.
958+ *
959+ * This program is free software: you can redistribute it and/or modify it
960+ * under the terms of the GNU Lesser General Public License version 3,
961+ * as published by the Free Software Foundation.
962+ *
963+ * This program is distributed in the hope that it will be useful,
964+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
965+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
966+ * GNU Lesser General Public License for more details.
967+ *
968+ * You should have received a copy of the GNU Lesser General Public License
969+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
970+ *
971+ */
972+
973+#ifndef NON_COPYABLE_H_
974+#define NON_COPYABLE_H_
975+
976+namespace core {
977+namespace ubuntu {
978+namespace media {
979+// The alert reader might wonder why we don't use boost::noncopyable. The reason
980+// is simple: We would like to have a convenient virtual d'tor available.
981+struct NonCopyable {
982+ NonCopyable() = default;
983+ NonCopyable(const NonCopyable&) = delete;
984+ virtual ~NonCopyable() = default;
985+ NonCopyable& operator=(const NonCopyable&) = delete;
986+};
987+}
988+}
989+}
990+
991+#endif
992
993=== modified file 'src/core/media/player_implementation.cpp'
994--- src/core/media/player_implementation.cpp 2016-02-19 16:14:42 +0000
995+++ src/core/media/player_implementation.cpp 2016-04-07 00:39:05 +0000
996@@ -28,9 +28,10 @@
997
998 #include "gstreamer/engine.h"
999
1000+#include "core/media/logger/logger.h"
1001+
1002 #include <memory>
1003 #include <exception>
1004-#include <iostream>
1005 #include <mutex>
1006
1007 #define UNUSED __attribute__((unused))
1008@@ -75,22 +76,22 @@
1009 // Poor man's logging of release/acquire events.
1010 display_state_lock->acquired().connect([](media::power::DisplayState state)
1011 {
1012- std::cout << "Acquired new display state: " << state << std::endl;
1013+ MH_INFO("Acquired new display state: %s", state);
1014 });
1015
1016 display_state_lock->released().connect([](media::power::DisplayState state)
1017 {
1018- std::cout << "Released display state: " << state << std::endl;
1019+ MH_INFO("Released display state: %s", state);
1020 });
1021
1022 system_state_lock->acquired().connect([](media::power::SystemState state)
1023 {
1024- std::cout << "Acquired new system state: " << state << std::endl;
1025+ MH_INFO("Acquired new system state: %s", state);
1026 });
1027
1028 system_state_lock->released().connect([](media::power::SystemState state)
1029 {
1030- std::cout << "Released system state: " << state << std::endl;
1031+ MH_INFO("Released system state: %s", state);
1032 });
1033 }
1034
1035@@ -120,7 +121,7 @@
1036 */
1037 return [this](const Engine::State& state)
1038 {
1039- std::cout << "Setting state for parent: " << parent << std::endl;
1040+ MH_DEBUG("Setting state for parent: %s", parent);
1041 switch(state)
1042 {
1043 case Engine::State::ready:
1044@@ -139,7 +140,7 @@
1045 parent->meta_data_for_current_track().set(std::get<1>(engine->track_meta_data().get()));
1046 // And update our playback status.
1047 parent->playback_status().set(media::Player::playing);
1048- std::cout << "Requesting power state" << std::endl;
1049+ MH_INFO("Requesting power state");
1050 request_power_state();
1051 break;
1052 }
1053@@ -174,45 +175,44 @@
1054 {
1055 return [this](const media::Player::PlaybackStatus& status)
1056 {
1057- std::cout << "Emiting playback_status_changed signal: " << status << std::endl;
1058+ MH_INFO("Emiting playback_status_changed signal: %s", status);
1059 parent->emit_playback_status_changed(status);
1060 };
1061 }
1062
1063 void request_power_state()
1064 {
1065- std::cout << __PRETTY_FUNCTION__ << std::endl;
1066+ MH_TRACE("");
1067 try
1068 {
1069 if (parent->is_video_source())
1070 {
1071 if (++display_wakelock_count == 1)
1072 {
1073- std::cout << "Requesting new display wakelock." << std::endl;
1074+ MH_INFO("Requesting new display wakelock.");
1075 display_state_lock->request_acquire(media::power::DisplayState::on);
1076- std::cout << "Requested new display wakelock." << std::endl;
1077+ MH_INFO("Requested new display wakelock.");
1078 }
1079 }
1080 else
1081 {
1082 if (++system_wakelock_count == 1)
1083 {
1084- std::cout << "Requesting new system wakelock." << std::endl;
1085+ MH_INFO("Requesting new system wakelock.");
1086 system_state_lock->request_acquire(media::power::SystemState::active);
1087- std::cout << "Requested new system wakelock." << std::endl;
1088+ MH_INFO("Requested new system wakelock.");
1089 }
1090 }
1091 }
1092 catch(const std::exception& e)
1093 {
1094- std::cerr << "Warning: failed to request power state: ";
1095- std::cerr << e.what() << std::endl;
1096+ MH_WARNING("Failed to request power state: %s", e.what());
1097 }
1098 }
1099
1100 void clear_wakelock(const wakelock_clear_t &wakelock)
1101 {
1102- cout << __PRETTY_FUNCTION__ << endl;
1103+ MH_TRACE("");
1104 try
1105 {
1106 switch (wakelock)
1107@@ -223,7 +223,7 @@
1108 // Only actually clear the system wakelock once the count reaches zero
1109 if (--system_wakelock_count == 0)
1110 {
1111- std::cout << "Clearing system wakelock." << std::endl;
1112+ MH_INFO("Clearing system wakelock.");
1113 system_state_lock->request_release(media::power::SystemState::active);
1114 }
1115 break;
1116@@ -231,19 +231,18 @@
1117 // Only actually clear the display wakelock once the count reaches zero
1118 if (--display_wakelock_count == 0)
1119 {
1120- std::cout << "Clearing display wakelock." << std::endl;
1121+ MH_INFO("Clearing display wakelock.");
1122 display_state_lock->request_release(media::power::DisplayState::on);
1123 }
1124 break;
1125 case wakelock_clear_t::WAKELOCK_CLEAR_INVALID:
1126 default:
1127- cerr << "Can't clear invalid wakelock type" << endl;
1128+ MH_WARNING("Can't clear invalid wakelock type");
1129 }
1130 }
1131 catch(const std::exception& e)
1132 {
1133- std::cerr << "Warning: failed to clear power state: ";
1134- std::cerr << e.what() << std::endl;
1135+ MH_WARNING("Failed to request clear power state: %s", e.what());
1136 }
1137 }
1138
1139@@ -294,9 +293,9 @@
1140 {
1141 // Using a TrackList for playback, added tracks via add_track(), but open_uri hasn't
1142 // been called yet to load a media resource
1143- std::cout << "Calling d->engine->open_resource_for_uri() for first track added only: "
1144- << uri << std::endl;
1145- std::cout << "\twith a Track::Id: " << id << std::endl;
1146+ MH_INFO("Calling d->engine->open_resource_for_uri() for first track added only: %s",
1147+ uri);
1148+ MH_INFO("\twith a Track::Id: %s", id);
1149 static const bool do_pipeline_reset = false;
1150 engine->open_resource_for_uri(uri, do_pipeline_reset);
1151 }
1152@@ -311,10 +310,10 @@
1153 auto n_tracks = track_list->tracks()->size();
1154 bool has_tracks = (n_tracks > 0) ? true : false;
1155
1156- std::cout << "Updating MPRIS TrackList properties"
1157- << "; Tracks: " << n_tracks
1158- << ", has_previous: " << has_previous
1159- << ", has_next: " << has_next << std::endl;
1160+ MH_INFO("Updating MPRIS TrackList properties:");
1161+ MH_INFO("\tTracks: %d", n_tracks);
1162+ MH_INFO("\thas_previous: %d", has_previous);
1163+ MH_INFO("\thas_next: %d", has_next);
1164
1165 // Update properties
1166 parent->can_play().set(has_tracks);
1167@@ -418,7 +417,7 @@
1168 // When the client changes the loop status, make sure to update the TrackList
1169 Parent::loop_status().changed().connect([this](media::Player::LoopStatus loop_status)
1170 {
1171- std::cout << "LoopStatus: " << loop_status << std::endl;
1172+ MH_INFO("LoopStatus: %s", loop_status);
1173 d->track_list->on_loop_status_changed(loop_status);
1174 });
1175
1176@@ -465,7 +464,7 @@
1177 const Track::UriType uri = d->track_list->query_uri_for_track(d->track_list->next());
1178 if (prev_track_id != d->track_list->current() && !uri.empty())
1179 {
1180- std::cout << "Advancing to next track on playbin: " << uri << std::endl;
1181+ MH_INFO("Advancing to next track on playbin: %s", uri);
1182 static const bool do_pipeline_reset = false;
1183 d->engine->open_resource_for_uri(uri, do_pipeline_reset);
1184 }
1185@@ -508,7 +507,7 @@
1186 if (d->engine->state() != gstreamer::Engine::State::ready
1187 && d->engine->state() != gstreamer::Engine::State::stopped)
1188 {
1189- std::cout << "End of tracklist reached, stopping playback" << std::endl;
1190+ MH_INFO("End of tracklist reached, stopping playback");
1191 d->engine->stop();
1192 }
1193 });
1194@@ -528,15 +527,15 @@
1195 const Track::UriType uri = d->track_list->query_uri_for_track(id);
1196 if (!uri.empty())
1197 {
1198- std::cout << "Setting next track on playbin (on_go_to_track signal): " << uri << std::endl;
1199- std::cout << "\twith a Track::Id: " << id << std::endl;
1200+ MH_INFO("Setting next track on playbin (on_go_to_track signal): %s", uri);
1201+ MH_INFO("\twith a Track::Id: %s", id);
1202 static const bool do_pipeline_reset = true;
1203 d->engine->open_resource_for_uri(uri, do_pipeline_reset);
1204 }
1205
1206 if (auto_play)
1207 {
1208- std::cout << "Restoring playing state in on_go_to_track()" << std::endl;
1209+ MH_DEBUG("Restoring playing state");
1210 d->engine->play();
1211 }
1212
1213@@ -545,7 +544,7 @@
1214
1215 d->track_list->on_track_added().connect([this](const media::Track::Id& id)
1216 {
1217- std::cout << "** Track was added, handling in PlayerImplementation" << std::endl;
1218+ MH_TRACE("** Track was added, handling in PlayerImplementation");
1219 if (d->track_list->tracks()->size() == 1)
1220 d->open_first_track_from_tracklist(id);
1221
1222@@ -554,7 +553,7 @@
1223
1224 d->track_list->on_tracks_added().connect([this](const media::TrackList::ContainerURI& tracks)
1225 {
1226- std::cout << "** Track was added, handling in PlayerImplementation" << std::endl;
1227+ MH_TRACE("** Track was added, handling in PlayerImplementation");
1228 // If the two sizes are the same, that means the TrackList was previously empty and we need
1229 // to open the first track in the TrackList so that is_audio_source() and is_video_source()
1230 // will function correctly.
1231@@ -689,7 +688,7 @@
1232
1233 // If empty uri, give the same meaning as QMediaPlayer::setMedia("")
1234 if (uri.empty()) {
1235- cout << __PRETTY_FUNCTION__ << ": resetting current media" << endl;
1236+ MH_DEBUG("Resetting current media");
1237 return true;
1238 }
1239
1240@@ -722,19 +721,21 @@
1241 template<typename Parent>
1242 void media::PlayerImplementation<Parent>::play()
1243 {
1244+ MH_TRACE("");
1245 d->engine->play();
1246 }
1247
1248 template<typename Parent>
1249 void media::PlayerImplementation<Parent>::pause()
1250 {
1251+ MH_TRACE("");
1252 d->engine->pause();
1253 }
1254
1255 template<typename Parent>
1256 void media::PlayerImplementation<Parent>::stop()
1257 {
1258- std::cout << __PRETTY_FUNCTION__ << std::endl;
1259+ MH_TRACE("");
1260 d->engine->stop();
1261 }
1262
1263
1264=== modified file 'src/core/media/player_skeleton.cpp'
1265--- src/core/media/player_skeleton.cpp 2016-02-19 16:14:42 +0000
1266+++ src/core/media/player_skeleton.cpp 2016-04-07 00:39:05 +0000
1267@@ -31,6 +31,8 @@
1268 #include "mpris/metadata.h"
1269 #include "mpris/player.h"
1270 #include "mpris/playlists.h"
1271+
1272+#include "core/media/logger/logger.h"
1273 #include "util/uri_check.h"
1274
1275 #include <core/dbus/object.h>
1276@@ -189,7 +191,7 @@
1277 {
1278 const std::string err_str = {"Warning: Failed to open uri " + uri +
1279 " because it can't be found."};
1280- std::cerr << err_str << std::endl;
1281+ MH_ERROR("%s", err_str);
1282 reply = dbus::Message::make_error(
1283 in,
1284 mpris::Player::Error::UriNotFound::name,
1285@@ -207,7 +209,7 @@
1286 {
1287 const std::string err_str = {"Warning: Failed to authenticate necessary "
1288 "apparmor permissions to open uri: " + std::get<1>(result)};
1289- std::cerr << err_str << std::endl;
1290+ MH_ERROR("%s", err_str);
1291 reply = dbus::Message::make_error(
1292 in,
1293 mpris::Player::Error::InsufficientAppArmorPermissions::name,
1294@@ -236,7 +238,7 @@
1295 {
1296 const std::string err_str = {"Warning: Failed to open uri " + uri +
1297 " because it can't be found."};
1298- std::cerr << err_str << std::endl;
1299+ MH_ERROR("%s", err_str);
1300 reply = dbus::Message::make_error(
1301 in,
1302 mpris::Player::Error::UriNotFound::name,
1303@@ -254,7 +256,7 @@
1304 {
1305 const std::string err_str = {"Warning: Failed to authenticate necessary "
1306 "apparmor permissions to open uri: " + std::get<1>(result)};
1307- std::cerr << err_str << std::endl;
1308+ MH_ERROR("%s", err_str);
1309 reply = dbus::Message::make_error(
1310 in,
1311 mpris::Player::Error::InsufficientAppArmorPermissions::name,
1312
1313=== modified file 'src/core/media/player_stub.cpp'
1314--- src/core/media/player_stub.cpp 2016-02-19 16:14:42 +0000
1315+++ src/core/media/player_stub.cpp 2016-04-07 00:39:05 +0000
1316@@ -30,10 +30,13 @@
1317
1318 #include "mpris/player.h"
1319
1320+#include "core/media/logger/logger.h"
1321+
1322 #include <core/dbus/property.h>
1323 #include <core/dbus/types/object_path.h>
1324
1325 #include <limits>
1326+#include <sstream>
1327
1328 #define UNUSED __attribute__((unused))
1329
1330@@ -159,37 +162,38 @@
1331 {
1332 dbus.seeked_to->connect([this](std::uint64_t value)
1333 {
1334- std::cout << "SeekedTo signal arrived via the bus." << std::endl;
1335+ MH_DEBUG("SeekedTo signal arrived via the bus.");
1336 seeked_to(value);
1337 });
1338
1339 dbus.about_to_finish->connect([this]()
1340 {
1341- std::cout << "AboutToFinish signal arrived via the bus." << std::endl;
1342+ MH_DEBUG("AboutToFinish signal arrived via the bus.");
1343 about_to_finish();
1344 });
1345
1346 dbus.end_of_stream->connect([this]()
1347 {
1348- std::cout << "EndOfStream signal arrived via the bus." << std::endl;
1349+ MH_DEBUG("EndOfStream signal arrived via the bus.");
1350 end_of_stream();
1351 });
1352
1353 dbus.playback_status_changed->connect([this](const media::Player::PlaybackStatus& status)
1354 {
1355- std::cout << "PlaybackStatusChanged signal arrived via the bus (Status: " << status << ")" << std::endl;
1356+ MH_DEBUG("PlaybackStatusChanged signal arrived via the bus (status: %s)",
1357+ status);
1358 playback_status_changed(status);
1359 });
1360
1361 dbus.video_dimension_changed->connect([this](const media::video::Dimensions dimensions)
1362 {
1363- std::cout << "VideoDimensionChanged signal arrived via the bus." << std::endl;
1364+ MH_DEBUG("VideoDimensionChanged signal arrived via the bus.");
1365 video_dimension_changed(dimensions);
1366 });
1367
1368 dbus.error->connect([this](const media::Player::Error& e)
1369 {
1370- std::cout << "Error signal arrived via the bus (Error: " << e << ")" << std::endl;
1371+ MH_DEBUG("Error signal arrived via the bus (error: %s)", e);
1372 error(e);
1373 });
1374 }
1375
1376=== modified file 'src/core/media/power/state_controller.cpp'
1377--- src/core/media/power/state_controller.cpp 2015-05-27 18:37:24 +0000
1378+++ src/core/media/power/state_controller.cpp 2016-04-07 00:39:05 +0000
1379@@ -16,13 +16,13 @@
1380 * Authored by: Thomas Voß <thomas.voss@canonical.com>
1381 */
1382
1383+#include "core/media/logger/logger.h"
1384+
1385 #include <core/media/power/state_controller.h>
1386
1387 #include <core/dbus/macros.h>
1388 #include <core/dbus/object.h>
1389
1390-#include <iostream>
1391-
1392 namespace media = core::ubuntu::media;
1393
1394 namespace com { namespace canonical {
1395@@ -98,7 +98,7 @@
1396 // From core::ubuntu::media::power::StateController::Lock<DisplayState>
1397 void request_acquire(media::power::DisplayState state) override
1398 {
1399- std::cout << __PRETTY_FUNCTION__ << std::endl;
1400+ MH_TRACE("");
1401
1402 if (state == media::power::DisplayState::off)
1403 return;
1404@@ -110,7 +110,7 @@
1405 {
1406 if (result.is_error())
1407 {
1408- std::cerr << result.error().print() << std::endl;
1409+ MH_ERROR("%s", result.error().print());
1410 return;
1411 }
1412
1413@@ -149,7 +149,7 @@
1414 {
1415 if (result.is_error())
1416 {
1417- std::cerr << result.error().print() << std::endl;
1418+ MH_ERROR("%s", result.error().print());
1419 return;
1420 }
1421
1422@@ -207,7 +207,7 @@
1423 // the system to stay active.
1424 void request_acquire(media::power::SystemState state) override
1425 {
1426- std::cout << __PRETTY_FUNCTION__ << std::endl;
1427+ MH_TRACE("");
1428
1429 if (state == media::power::SystemState::suspend)
1430 return;
1431@@ -223,7 +223,7 @@
1432 }
1433 else
1434 {
1435- std::cerr << "Failed to lock system_state_cookie_store_guard and check system lock state" << std::endl;
1436+ MH_WARNING("Failed to lock system_state_cookie_store_guard and check system lock state");
1437 // Prevent system_state_cookie_store.count(state) and the actual call to requestSysState below from
1438 // getting out of sync.
1439 return;
1440@@ -236,7 +236,7 @@
1441 {
1442 if (result.is_error())
1443 {
1444- std::cerr << result.error().print() << std::endl;
1445+ MH_ERROR("%s", result.error().print());
1446 return;
1447 }
1448
1449@@ -249,7 +249,7 @@
1450 if (ul.owns_lock())
1451 sp->system_state_cookie_store[state] = result.value();
1452 else
1453- std::cerr << "Failed to lock system_state_cookie_store_guard and update system lock state" << std::endl;
1454+ MH_WARNING("Failed to lock system_state_cookie_store_guard and update system lock state");
1455 }
1456
1457 sp->signals.acquired(state);
1458@@ -275,7 +275,7 @@
1459 }
1460 else
1461 {
1462- std::cerr << "Failed to lock system_state_cookie_store_guard and check system lock state" << std::endl;
1463+ MH_WARNING("Failed to lock system_state_cookie_store_guard and check system lock state");
1464 // Prevent system_state_cookie_store.count(state) and the actual call to clearSysState below from
1465 // getting out of sync.
1466 return;
1467@@ -287,7 +287,7 @@
1468 object->invoke_method_asynchronously_with_callback<com::canonical::powerd::Interface::clearSysState, void>([this, wp, state](const core::dbus::Result<void>& result)
1469 {
1470 if (result.is_error())
1471- std::cerr << result.error().print() << std::endl;
1472+ MH_ERROR("%s", result.error().print());
1473
1474 if (auto sp = wp.lock())
1475 {
1476@@ -297,7 +297,7 @@
1477 if (ul.owns_lock())
1478 sp->system_state_cookie_store.erase(state);
1479 else
1480- std::cerr << "Failed to lock system_state_cookie_store_guard and erase system lock state" << std::endl;
1481+ MH_WARNING("Failed to lock system_state_cookie_store_guard and erase system lock state");
1482 }
1483
1484 sp->signals.released(state);
1485@@ -369,7 +369,7 @@
1486
1487 media::power::StateController::Ptr media::power::make_platform_default_state_controller(core::ubuntu::media::helper::ExternalServices& external_services)
1488 {
1489- return std::make_shared<impl::StateController>(external_services);
1490+ return std::make_shared<::impl::StateController>(external_services);
1491 }
1492
1493 // operator<< pretty prints the given display state to the given output stream.
1494
1495=== modified file 'src/core/media/server/server.cpp'
1496--- src/core/media/server/server.cpp 2015-04-10 16:13:55 +0000
1497+++ src/core/media/server/server.cpp 2016-04-07 00:39:05 +0000
1498@@ -21,6 +21,7 @@
1499 #include <core/media/track_list.h>
1500
1501 #include "core/media/hashed_keyed_player_store.h"
1502+#include "core/media/logger/logger.h"
1503 #include "core/media/service_implementation.h"
1504
1505 #include <core/posix/signal.h>
1506@@ -36,6 +37,37 @@
1507
1508 namespace
1509 {
1510+void logger_init()
1511+{
1512+ const char *level = ::getenv("MH_LOG_LEVEL");
1513+ // Default level is kInfo
1514+ media::Logger::Severity severity{media::Logger::Severity::kInfo};
1515+ if (level)
1516+ {
1517+ if (strcmp(level, "trace") == 0)
1518+ severity = media::Logger::Severity::kTrace;
1519+ else if (strcmp(level, "debug") == 0)
1520+ severity = media::Logger::Severity::kDebug;
1521+ else if (strcmp(level, "info") == 0)
1522+ severity = media::Logger::Severity::kInfo;
1523+ else if (strcmp(level, "warning") == 0)
1524+ severity = media::Logger::Severity::kWarning;
1525+ else if (strcmp(level, "error") == 0)
1526+ severity = media::Logger::Severity::kError;
1527+ else if (strcmp(level, "fatal") == 0)
1528+ severity = media::Logger::Severity::kFatal;
1529+ else
1530+ std::cerr << "Invalid log level \"" << level
1531+ << "\", setting to info. Valid options: [trace, debug, info, warning, error, fatal]. "
1532+ << std::endl;
1533+ }
1534+ else
1535+ std::cout << "Using default log level: info" << std::endl;
1536+
1537+ media::Log().Init(severity);
1538+ cout << "Log level: " << severity << std::endl;
1539+}
1540+
1541 // All platform-specific initialization routines go here.
1542 void platform_init()
1543 {
1544@@ -66,6 +98,8 @@
1545 trap->stop();
1546 });
1547
1548+ logger_init();
1549+
1550 // Init platform-specific functionality.
1551 platform_init();
1552
1553
1554=== modified file 'src/core/media/service.cpp'
1555--- src/core/media/service.cpp 2014-04-09 14:05:55 +0000
1556+++ src/core/media/service.cpp 2016-04-07 00:39:05 +0000
1557@@ -18,13 +18,15 @@
1558
1559 #include <core/media/service.h>
1560
1561+#include "core/media/logger/logger.h"
1562+
1563 #include "service_stub.h"
1564
1565 namespace media = core::ubuntu::media;
1566
1567 const std::shared_ptr<media::Service> media::Service::Client::instance()
1568 {
1569- std::cout << "Creating a new static Service instance" << std::endl;
1570+ MH_TRACE("");
1571 static std::shared_ptr<media::Service> instance{new media::ServiceStub()};
1572 return instance;
1573 }
1574
1575=== modified file 'src/core/media/service_implementation.cpp'
1576--- src/core/media/service_implementation.cpp 2016-03-02 18:32:46 +0000
1577+++ src/core/media/service_implementation.cpp 2016-04-07 00:39:05 +0000
1578@@ -33,6 +33,9 @@
1579 #include "recorder_observer.h"
1580 #include "telephony/call_monitor.h"
1581
1582+#include "util/timeout.h"
1583+#include "core/media/logger/logger.h"
1584+
1585 #include <boost/asio.hpp>
1586
1587 #include <string>
1588@@ -45,8 +48,6 @@
1589
1590 #include <pulse/pulseaudio.h>
1591
1592-#include "util/timeout.h"
1593-
1594 namespace media = core::ubuntu::media;
1595
1596 using namespace std;
1597@@ -126,16 +127,16 @@
1598 switch (state)
1599 {
1600 case audio::OutputState::Earpiece:
1601- std::cout << "AudioOutputObserver reports that output is now Headphones/Headset." << std::endl;
1602+ MH_INFO("AudioOutputObserver reports that output is now Headphones/Headset.");
1603 break;
1604 case audio::OutputState::Speaker:
1605- std::cout << "AudioOutputObserver reports that output is now Speaker." << std::endl;
1606+ MH_INFO("AudioOutputObserver reports that output is now Speaker.");
1607 // Whatever player session is currently playing, make sure it is NOT resumed after
1608 // a phonecall is hung up
1609 pause_all_multimedia_sessions(resume_play_after_phonecall);
1610 break;
1611 case audio::OutputState::External:
1612- std::cout << "AudioOutputObserver reports that output is now External." << std::endl;
1613+ MH_INFO("AudioOutputObserver reports that output is now External.");
1614 break;
1615 }
1616 d->audio_output_state = state;
1617@@ -146,13 +147,13 @@
1618 const bool resume_play_after_phonecall = true;
1619 switch (state) {
1620 case media::telephony::CallMonitor::State::OffHook:
1621- std::cout << "Got call started signal, pausing all multimedia sessions" << std::endl;
1622+ MH_INFO("Got call started signal, pausing all multimedia sessions");
1623 // Whatever player session is currently playing, make sure it gets resumed after
1624 // a phonecall is hung up
1625 pause_all_multimedia_sessions(resume_play_after_phonecall);
1626 break;
1627 case media::telephony::CallMonitor::State::OnHook:
1628- std::cout << "Got call ended signal, resuming paused multimedia sessions" << std::endl;
1629+ MH_INFO("Got call ended signal, resuming paused multimedia sessions");
1630 resume_paused_multimedia_sessions(false);
1631 break;
1632 }
1633@@ -217,10 +218,10 @@
1634 d->configuration.player_store->remove_player_for_key(key);
1635 }
1636 catch (const std::out_of_range &e) {
1637- std::cerr << "Failed to look up Player instance for key " << key
1638- << ", no valid Player instance for that key value. Removal of Player from Player store"
1639- << " might not have completed. This most likely means that media-hub-server has"
1640- << " crashed and restarted." << std::endl;
1641+ MH_WARNING("Failed to look up Player instance for key %d"
1642+ ", no valid Player instance for that key value. Removal of Player from Player store"
1643+ " might not have completed. This most likely means that media-hub-server has"
1644+ " crashed and restarted.", key);
1645 return;
1646 }
1647 });
1648@@ -264,11 +265,11 @@
1649
1650 void media::ServiceImplementation::pause_other_sessions(media::Player::PlayerKey key)
1651 {
1652- std::cout << __PRETTY_FUNCTION__ << std::endl;
1653+ MH_TRACE("");
1654
1655 if (not d->configuration.player_store->has_player_for_key(key))
1656 {
1657- cerr << "Could not find Player by key: " << key << endl;
1658+ MH_WARNING("Could not find Player by key: %d", key);
1659 return;
1660 }
1661
1662@@ -291,7 +292,7 @@
1663 current_player->audio_stream_role() == media::Player::multimedia &&
1664 other_player->audio_stream_role() == media::Player::multimedia)
1665 {
1666- cout << "Pausing Player with key: " << other_key << endl;
1667+ MH_INFO("Pausing Player with key: %d", other_key);
1668 other_player->pause();
1669 }
1670 });
1671@@ -306,8 +307,8 @@
1672 {
1673 auto paused_player_pair = std::make_pair(key, resume_play_after_phonecall);
1674 d->paused_sessions.push_back(paused_player_pair);
1675- std::cout << "Pausing Player with key: " << key << ", resuming after phone call? "
1676- << (resume_play_after_phonecall ? "yes" : "no") << std::endl;
1677+ MH_INFO("Pausing Player with key: %d, resuming after phone call? %s", key,
1678+ (resume_play_after_phonecall ? "yes" : "no"));
1679 player->pause();
1680 }
1681 });
1682@@ -324,17 +325,17 @@
1683 player = d->configuration.player_store->player_for_key(key);
1684 }
1685 catch (const std::out_of_range &e) {
1686- std::cerr << "Failed to look up Player instance for key " << key
1687- << ", no valid Player instance for that key value and cannot automatically resume"
1688- << " paused players. This most likely means that media-hub-server has crashed and"
1689- << " restarted." << std::endl;
1690+ MH_WARNING("Failed to look up Player instance for key %d"
1691+ ", no valid Player instance for that key value and cannot automatically resume"
1692+ " paused players. This most likely means that media-hub-server has crashed and"
1693+ " restarted.", key);
1694 return;
1695 }
1696 // Only resume video playback if explicitly desired
1697 if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)
1698 player->play();
1699 else
1700- std::cout << "Not auto-resuming video player session or other type of player session." << std::endl;
1701+ MH_INFO("Not auto-resuming video player session or other type of player session.");
1702 });
1703
1704 d->paused_sessions.clear();
1705@@ -350,16 +351,16 @@
1706 player = d->configuration.player_store->player_for_key(d->resume_key);
1707 }
1708 catch (const std::out_of_range &e) {
1709- std::cerr << "Failed to look up Player instance for key " << d->resume_key
1710- << ", no valid Player instance for that key value and cannot automatically resume"
1711- << " paused Player. This most likely means that media-hub-server has crashed and"
1712- << " restarted." << std::endl;
1713+ MH_WARNING("Failed to look up Player instance for key %d"
1714+ ", no valid Player instance for that key value and cannot automatically resume"
1715+ " paused Player. This most likely means that media-hub-server has crashed and"
1716+ " restarted.", d->resume_key);
1717 return;
1718 }
1719
1720 if (player->playback_status() == Player::paused)
1721 {
1722- cout << "Resuming playback of Player with key: " << d->resume_key << endl;
1723+ MH_INFO("Resuming playback of Player with key: %d", d->resume_key);
1724 player->play();
1725 d->resume_key = std::numeric_limits<std::uint32_t>::max();
1726 }
1727
1728=== modified file 'src/core/media/service_skeleton.cpp'
1729--- src/core/media/service_skeleton.cpp 2016-03-02 18:32:46 +0000
1730+++ src/core/media/service_skeleton.cpp 2016-04-07 00:39:05 +0000
1731@@ -29,6 +29,8 @@
1732 #include "the_session_bus.h"
1733 #include "xesam.h"
1734
1735+#include "core/media/logger/logger.h"
1736+
1737 #include <core/dbus/message.h>
1738 #include <core/dbus/object.h>
1739 #include <core/dbus/types/object_path.h>
1740@@ -134,9 +136,8 @@
1741 impl->access_service()->add_object_for_path(op)
1742 };
1743
1744- cout << "Session created by request of: " << msg->sender()
1745- << ", key: " << key << ", uuid: " << uuid
1746- << ", path:" << op << std::endl;
1747+ MH_DEBUG("Session created by request of: %s, key: %d, uuid: %d, path: %s",
1748+ msg->sender(), key, uuid, op);
1749
1750 try
1751 {
1752@@ -147,7 +148,7 @@
1753 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(),
1754 [this, key, msg](const media::apparmor::ubuntu::Context& context)
1755 {
1756- fprintf(stderr, "%s():%d -- app_name='%s', attached\n", __func__, __LINE__, context.str().c_str());
1757+ MH_DEBUG(" -- app_name='%s', attached", context.str());
1758 player_owner_map.emplace(std::make_pair(key, std::make_tuple(context.str(), true, msg->sender())));
1759 });
1760
1761@@ -231,7 +232,8 @@
1762 [this, msg, key, op](const media::apparmor::ubuntu::Context& context)
1763 {
1764 auto info = player_owner_map.at(key);
1765- fprintf(stderr, "%s():%d -- reattach app_name='%s', info='%s', '%s'\n", __func__, __LINE__, context.str().c_str(), std::get<0>(info).c_str(), std::get<2>(info).c_str());
1766+ MH_DEBUG(" -- reattach app_name='%s', info='%s', '%s'",
1767+ context.str(), std::get<0>(info), std::get<2>(info));
1768 if (std::get<0>(info) == context.str()) {
1769 std::get<1>(info) = true; // Set to Attached
1770 std::get<2>(info) = msg->sender(); // Register new owner
1771@@ -242,7 +244,7 @@
1772 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)
1773 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)
1774 {
1775- std::cout << "Setting current_player" << std::endl;
1776+ MH_TRACE("Setting current_player");
1777 exported.set_current_player(player);
1778 }
1779
1780@@ -305,7 +307,8 @@
1781 [this, msg, key](const media::apparmor::ubuntu::Context& context)
1782 {
1783 auto info = player_owner_map.at(key);
1784- fprintf(stderr, "%s():%d -- Destroying app_name='%s', info='%s', '%s'\n", __func__, __LINE__, context.str().c_str(), std::get<0>(info).c_str(), std::get<2>(info).c_str());
1785+ MH_DEBUG(" -- Destroying app_name='%s', info='%s', '%s'",
1786+ context.str(), std::get<0>(info), std::get<2>(info));
1787 if (std::get<0>(info) == context.str()) {
1788 player_owner_map.erase(key);
1789
1790@@ -454,7 +457,7 @@
1791 core::dbus::Message::Ptr reply;
1792 if (not configuration.player_store->has_player_for_key(key))
1793 {
1794- std::cerr << __PRETTY_FUNCTION__ << " player key not found - " << key << std::endl;
1795+ MH_WARNING("Player key not found: %d", key);
1796 reply = dbus::Message::make_error(
1797 msg,
1798 mpris::Service::Errors::PlayerKeyNotFound::name(),
1799@@ -467,10 +470,9 @@
1800 reply = dbus::Message::make_method_return(msg);
1801 }
1802 catch (const std::out_of_range &e) {
1803- std::cerr << "Failed to look up Player instance for key " << key
1804- << ", no valid Player instance for that key value and cannot set current player."
1805- << " This most likely means that media-hub-server has crashed and restarted."
1806- << std::endl;
1807+ MH_WARNING("Failed to look up Player instance for key %d\
1808+ , no valid Player instance for that key value and cannot set current player.\
1809+ This most likely means that media-hub-server has crashed and restarted.", key);
1810 reply = dbus::Message::make_error(
1811 msg,
1812 mpris::Service::Errors::PlayerKeyNotFound::name(),
1813@@ -491,10 +493,9 @@
1814 reply = dbus::Message::make_method_return(msg);
1815 }
1816 catch (const std::out_of_range &e) {
1817- std::cerr << "Failed to look up Player instance for key " << key
1818- << ", no valid Player instance for that key value and cannot pause other Players."
1819- << " This most likely means that media-hub-server has crashed and restarted."
1820- << std::endl;
1821+ MH_WARNING("Failed to look up Player instance for key %d\
1822+ , no valid Player instance for that key value and cannot set current player.\
1823+ This most likely means that media-hub-server has crashed and restarted.", key);
1824 reply = dbus::Message::make_error(
1825 msg,
1826 mpris::Service::Errors::PlayerKeyNotFound::name(),
1827@@ -529,7 +530,7 @@
1828 // TODO(tvoss): These three elements really should be configurable.
1829 defaults.identity = "core::media::Hub";
1830 defaults.desktop_entry = "mediaplayer-app";
1831- defaults.supported_mime_types = {"audio/mpeg3"};
1832+ defaults.supported_mime_types = {"audio/mpeg3", "video/mpeg4"};
1833
1834 return defaults;
1835 }
1836@@ -668,7 +669,7 @@
1837
1838 void set_current_player(const std::shared_ptr<media::Player>& cp)
1839 {
1840- std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;
1841+ MH_TRACE("");
1842 // We will not keep the object alive.
1843 current_player = cp;
1844
1845@@ -784,7 +785,7 @@
1846
1847 void reset_current_player()
1848 {
1849- std::cout << __PRETTY_FUNCTION__ << std::endl;
1850+ MH_TRACE("");
1851 // And announce that we can no longer be controlled.
1852 player.properties.can_control->set(false);
1853 current_player.reset();
1854
1855=== modified file 'src/core/media/telephony/CMakeLists.txt'
1856--- src/core/media/telephony/CMakeLists.txt 2014-10-31 07:49:33 +0000
1857+++ src/core/media/telephony/CMakeLists.txt 2016-04-07 00:39:05 +0000
1858@@ -9,6 +9,7 @@
1859
1860 include_directories(
1861 ${TP_QT5_INCLUDE_DIRS}
1862+ ${PROJECT_SOURCE_DIR}/src/
1863 )
1864
1865 add_library(call-monitor STATIC
1866
1867=== modified file 'src/core/media/telephony/call_monitor.cpp'
1868--- src/core/media/telephony/call_monitor.cpp 2015-01-26 11:01:02 +0000
1869+++ src/core/media/telephony/call_monitor.cpp 2016-04-07 00:39:05 +0000
1870@@ -19,6 +19,8 @@
1871
1872 #include "call_monitor.h"
1873
1874+#include "core/media/logger/logger.h"
1875+
1876 #include "qtbridge.h"
1877 #include <TelepathyQt/AccountManager>
1878 #include <TelepathyQt/SimpleCallObserver>
1879@@ -95,7 +97,7 @@
1880
1881 void accountManagerReady(Tp::PendingOperation* operation) {
1882 if (operation->isError()) {
1883- std::cerr << "TelepathyBridge: Operation failed (accountManagerReady)" << std::endl;
1884+ MH_ERROR("TelepathyBridge: Operation failed (accountManagerReady)");
1885 QTimer::singleShot(1000, this, SLOT(accountManagerSetup())); // again
1886 return;
1887 }
1888@@ -118,13 +120,13 @@
1889
1890 void accountReady(Tp::PendingOperation* operation) {
1891 if (operation->isError()) {
1892- std::cerr << "TelepathyAccount: Operation failed (accountReady)" << std::endl;
1893+ MH_ERROR("TelepathyAccount: Operation failed (accountReady)");
1894 return;
1895 }
1896
1897 Tp::PendingReady* pendingReady = qobject_cast<Tp::PendingReady*>(operation);
1898 if (pendingReady == 0) {
1899- std::cerr << "Rejecting account because could not understand ready status" << std::endl;
1900+ MH_ERROR("Rejecting account because could not understand ready status");
1901 return;
1902 }
1903
1904@@ -176,16 +178,16 @@
1905 {
1906 qt::core::world::enter_with_task([this]()
1907 {
1908- std::cout << "CallMonitor: Creating TelepathyBridge" << std::endl;
1909+ MH_DEBUG("CallMonitor: Creating TelepathyBridge");
1910 mBridge = new TelepathyBridge();
1911 cv.notify_all();
1912 });
1913 });
1914 }));
1915 } catch(const std::system_error& error) {
1916- std::cerr << "exception(std::system_error) in CallMonitor thread start" << error.what() << std::endl;
1917+ MH_ERROR("exception(std::system_error) in CallMonitor thread start %s", error.what());
1918 } catch(...) {
1919- std::cerr << "exception(...) in CallMonitor thread start" << std::endl;
1920+ MH_ERROR("exception(...) in CallMonitor thread start");
1921 }
1922
1923 // Wait until telepathy bridge is set, so we can hook up the change signals
1924@@ -234,7 +236,7 @@
1925
1926 media::telephony::CallMonitor::Ptr media::telephony::make_platform_default_call_monitor()
1927 {
1928- return std::make_shared<impl::CallMonitor>();
1929+ return std::make_shared<::impl::CallMonitor>();
1930 }
1931
1932 #include "call_monitor.moc"
1933
1934=== modified file 'src/core/media/telephony/qtbridge.cpp'
1935--- src/core/media/telephony/qtbridge.cpp 2014-10-31 07:49:33 +0000
1936+++ src/core/media/telephony/qtbridge.cpp 2016-04-07 00:39:05 +0000
1937@@ -26,8 +26,6 @@
1938 #include<QThread>
1939 #include<QDebug>
1940
1941-#include <iostream>
1942-
1943 namespace
1944 {
1945 QCoreApplication* app = nullptr;
1946
1947=== modified file 'src/core/media/track_list_implementation.cpp'
1948--- src/core/media/track_list_implementation.cpp 2016-02-22 18:58:52 +0000
1949+++ src/core/media/track_list_implementation.cpp 2016-04-07 00:39:05 +0000
1950@@ -18,6 +18,7 @@
1951
1952 #include <algorithm>
1953 #include <random>
1954+#include <sstream>
1955 #include <stdio.h>
1956 #include <stdlib.h>
1957 #include <tuple>
1958@@ -29,6 +30,8 @@
1959
1960 #include "engine.h"
1961
1962+#include "core/media/logger/logger.h"
1963+
1964 namespace dbus = core::dbus;
1965 namespace media = core::ubuntu::media;
1966
1967@@ -125,14 +128,14 @@
1968 const media::Track::Id& position,
1969 bool make_current)
1970 {
1971- std::cout << __PRETTY_FUNCTION__ << std::endl;
1972+ MH_TRACE("");
1973
1974 std::stringstream ss;
1975 ss << d->object->path().as_string() << "/" << d->track_counter++;
1976 Track::Id id{ss.str()};
1977
1978- std::cout << "Adding Track::Id: " << id << std::endl;
1979- std::cout << "\tURI: " << uri << std::endl;
1980+ MH_DEBUG("Adding Track::Id: %s", id);
1981+ MH_DEBUG("\tURI: %s", uri);
1982
1983 const auto current = get_current_track();
1984
1985@@ -159,7 +162,7 @@
1986 set_current_track(current);
1987 }
1988
1989- std::cout << "Signaling that we just added track id: " << id << std::endl;
1990+ MH_DEBUG("Signaling that we just added track id: %s", id);
1991 // Signal to the client that a track was added to the TrackList
1992 on_track_added()(id);
1993
1994@@ -172,7 +175,7 @@
1995
1996 void media::TrackListImplementation::add_tracks_with_uri_at(const ContainerURI& uris, const Track::Id& position)
1997 {
1998- std::cout << __PRETTY_FUNCTION__ << std::endl;
1999+ MH_TRACE("");
2000
2001 const auto current = get_current_track();
2002
2003@@ -184,8 +187,8 @@
2004 std::stringstream ss;
2005 ss << d->object->path().as_string() << "/" << d->track_counter++;
2006 Track::Id id{ss.str()};
2007- std::cout << "Adding Track::Id: " << id << std::endl;
2008- std::cout << "\tURI: " << uri << std::endl;
2009+ MH_DEBUG("Adding Track::Id: %s", id);
2010+ MH_DEBUG("\tURI: %s", uri);
2011
2012 tmp.push_back(id);
2013
2014@@ -217,7 +220,7 @@
2015
2016 set_current_track(current);
2017
2018- std::cout << "Signaling that we just added " << tmp.size() << " tracks to the TrackList" << std::endl;
2019+ MH_DEBUG("Signaling that we just added %d tracks to the TrackList", tmp.size());
2020 on_tracks_added()(tmp);
2021
2022 if (!current_id.empty())
2023@@ -227,30 +230,30 @@
2024 bool media::TrackListImplementation::move_track(const media::Track::Id& id,
2025 const media::Track::Id& to)
2026 {
2027- std::cout << __PRETTY_FUNCTION__ << std::endl;
2028+ MH_TRACE("");
2029
2030- std::cout << "-----------------------------------------------------" << std::endl;
2031+ MH_DEBUG("-----------------------------------------------------");
2032 if (id.empty() or to.empty())
2033 {
2034- std::cerr << "Can't move track since 'id' or 'to' are empty" << std::endl;
2035+ MH_ERROR("Can't move track since 'id' or 'to' are empty");
2036 return false;
2037 }
2038
2039 if (id == to)
2040 {
2041- std::cerr << "Can't move track to it's same position" << std::endl;
2042+ MH_ERROR("Can't move track to it's same position");
2043 return false;
2044 }
2045
2046 if (tracks().get().size() == 1)
2047 {
2048- std::cerr << "Can't move track since TrackList contains only one track" << std::endl;
2049+ MH_ERROR("Can't move track since TrackList contains only one track");
2050 return false;
2051 }
2052
2053 bool ret = false;
2054 const media::Track::Id current_id = *current_iterator();
2055- std::cout << "current_track id: " << current_id << std::endl;
2056+ MH_DEBUG("current_track id: %s", current_id);
2057 // Get an iterator that points to the track that is the insertion point
2058 auto insert_point_it = std::find(tracks().get().begin(), tracks().get().end(), to);
2059 if (insert_point_it != tracks().get().end())
2060@@ -260,7 +263,6 @@
2061 {
2062 // Get an iterator that points to the track to move within the TrackList
2063 auto to_move_it = std::find(tracks().get().begin(), tracks().get().end(), id);
2064- std::cout << "Erasing old track position: " << *to_move_it << std::endl;
2065 if (to_move_it != tracks().get().end())
2066 {
2067 container.erase(to_move_it);
2068@@ -282,11 +284,11 @@
2069 {
2070 throw media::TrackList::Errors::FailedToMoveTrack();
2071 }
2072- std::cout << "*** Updated current_iterator, id: " << *current_iterator() << std::endl;
2073+ MH_DEBUG("*** Updated current_iterator, id: %s", *current_iterator());
2074 }
2075 else
2076 {
2077- std::cerr << "Can't update current_iterator - failed to find track after move" << std::endl;
2078+ MH_ERROR("Can't update current_iterator - failed to find track after move");
2079 throw media::TrackList::Errors::FailedToMoveTrack();
2080 }
2081
2082@@ -295,10 +297,10 @@
2083
2084 if (result)
2085 {
2086- std::cout << "TrackList after move" << std::endl;
2087- for(auto track : tracks().get())
2088+ MH_DEBUG("TrackList after move");
2089+ for(const auto track : tracks().get())
2090 {
2091- std::cout << track << std::endl;
2092+ MH_DEBUG("%s", track);
2093 }
2094 const media::TrackList::TrackIdTuple ids = std::make_tuple(id, to);
2095 // Signal to the client that track 'id' was moved within the TrackList
2096@@ -312,7 +314,7 @@
2097 ("Failed to find source track " + id);
2098 }
2099
2100- std::cout << "-----------------------------------------------------" << std::endl;
2101+ MH_DEBUG("-----------------------------------------------------");
2102
2103 return ret;
2104 }
2105@@ -345,7 +347,7 @@
2106
2107 void media::TrackListImplementation::go_to(const media::Track::Id& track)
2108 {
2109- std::cout << __PRETTY_FUNCTION__ << std::endl;
2110+ MH_TRACE("");
2111 // Signal the Player instance to go to a specific track for playback
2112 on_go_to_track()(track);
2113 on_track_changed()(track);
2114@@ -373,7 +375,7 @@
2115
2116 void media::TrackListImplementation::reset()
2117 {
2118- std::cout << __PRETTY_FUNCTION__ << std::endl;
2119+ MH_TRACE("");
2120
2121 // Make sure playback stops
2122 on_end_of_tracklist()();
2123
2124=== modified file 'src/core/media/track_list_skeleton.cpp'
2125--- src/core/media/track_list_skeleton.cpp 2016-02-22 16:16:52 +0000
2126+++ src/core/media/track_list_skeleton.cpp 2016-04-07 00:39:05 +0000
2127@@ -29,7 +29,9 @@
2128
2129 #include "mpris/player.h"
2130 #include "mpris/track_list.h"
2131+
2132 #include "util/uri_check.h"
2133+#include "core/media/logger/logger.h"
2134
2135 #include <core/dbus/object.h>
2136 #include <core/dbus/property.h>
2137@@ -40,7 +42,6 @@
2138
2139 #include <iostream>
2140 #include <limits>
2141-#include <sstream>
2142 #include <cstdint>
2143
2144 namespace dbus = core::dbus;
2145@@ -104,7 +105,7 @@
2146
2147 void handle_add_track_with_uri_at(const core::dbus::Message::Ptr& msg)
2148 {
2149- std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;
2150+ MH_TRACE("");
2151 request_context_resolver->resolve_context_for_dbus_name_async
2152 (msg->sender(), [this, msg](const media::apparmor::ubuntu::Context& context)
2153 {
2154@@ -124,7 +125,7 @@
2155 {
2156 const std::string err_str = {"Warning: Not adding track " + uri +
2157 " to TrackList because it can't be found."};
2158- std::cerr << err_str << std::endl;
2159+ MH_WARNING("%s", err_str.c_str());
2160 reply = dbus::Message::make_error(
2161 msg,
2162 mpris::Player::Error::UriNotFound::name,
2163@@ -141,7 +142,7 @@
2164 {
2165 const std::string err_str = {"Warning: Not adding track " + uri +
2166 " to TrackList because of inadequate client apparmor permissions."};
2167- std::cerr << err_str << std::endl;
2168+ MH_WARNING("%s", err_str.c_str());
2169 reply = dbus::Message::make_error(
2170 msg,
2171 mpris::TrackList::Error::InsufficientPermissionsToAddTrack::name,
2172@@ -155,7 +156,7 @@
2173
2174 void handle_add_tracks_with_uri_at(const core::dbus::Message::Ptr& msg)
2175 {
2176- std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;
2177+ MH_TRACE("");
2178 request_context_resolver->resolve_context_for_dbus_name_async
2179 (msg->sender(), [this, msg](const media::apparmor::ubuntu::Context& context)
2180 {
2181@@ -176,7 +177,7 @@
2182 {
2183 uri_err_str = {"Warning: Not adding track " + uri +
2184 " to TrackList because it can't be found."};
2185- std::cerr << uri_err_str << std::endl;
2186+ MH_WARNING("%s", uri_err_str.c_str());
2187 reply = dbus::Message::make_error(
2188 msg,
2189 mpris::Player::Error::UriNotFound::name,
2190@@ -201,7 +202,7 @@
2191 }
2192 else
2193 {
2194- std::cerr << err_str << std::endl;
2195+ MH_WARNING("%s", err_str.c_str());
2196 reply = dbus::Message::make_error(
2197 msg,
2198 mpris::TrackList::Error::InsufficientPermissionsToAddTrack::name,
2199@@ -225,7 +226,7 @@
2200 {
2201 const std::string err_str = {"Error: Not moving track " + id +
2202 " to destination " + to};
2203- std::cerr << err_str << std::endl;
2204+ MH_WARNING("%s", err_str.c_str());
2205 reply = dbus::Message::make_error(
2206 msg,
2207 mpris::TrackList::Error::FailedToMoveTrack::name,
2208@@ -262,9 +263,9 @@
2209
2210 auto id_it = find(impl->tracks().get().begin(), impl->tracks().get().end(), track);
2211 if (id_it == impl->tracks().get().end()) {
2212- ostringstream err_str;
2213+ stringstream err_str;
2214 err_str << "Track " << track << " not found in track list";
2215- cout << __PRETTY_FUNCTION__ << " WARNING " << err_str.str() << endl;
2216+ MH_WARNING("%s", err_str.str());
2217 auto reply = dbus::Message::make_error(
2218 msg,
2219 mpris::TrackList::Error::TrackNotFound::name,
2220@@ -278,7 +279,7 @@
2221
2222 if (id_it == impl->current_iterator())
2223 {
2224- cout << "Removing current track" << endl;
2225+ MH_DEBUG("Removing current track");
2226 deleting_current = true;
2227
2228 if (current_track != empty_iterator)
2229@@ -537,10 +538,10 @@
2230
2231 media::Track::Id media::TrackListSkeleton::next()
2232 {
2233- std::cout << __PRETTY_FUNCTION__ << std::endl;
2234+ MH_TRACE("");
2235 if (tracks().get().empty()) {
2236 // TODO Change ServiceSkeleton to return with error from DBus call
2237- std::cerr << "ERROR: no tracks, cannot go to next" << std::endl;
2238+ MH_ERROR("No tracks, cannot go to next");
2239 return media::Track::Id{};
2240 }
2241
2242@@ -549,13 +550,13 @@
2243 // End of the track reached so loop around to the beginning of the track
2244 if (d->loop_status == media::Player::LoopStatus::track)
2245 {
2246- std::cout << "Looping on the current track since LoopStatus is set to track" << std::endl;
2247+ MH_INFO("Looping on the current track since LoopStatus is set to track");
2248 go_to_track = true;
2249 }
2250 // End of the tracklist reached so loop around to the beginning of the tracklist
2251 else if (d->loop_status == media::Player::LoopStatus::playlist && not has_next())
2252 {
2253- std::cout << "Looping on the tracklist since LoopStatus is set to playlist" << std::endl;
2254+ MH_INFO("Looping on the tracklist since LoopStatus is set to playlist");
2255
2256 if (shuffle())
2257 {
2258@@ -574,7 +575,7 @@
2259 {
2260 auto it = get_current_shuffled();
2261 if (++it != shuffled_tracks().end()) {
2262- cout << "Advancing to next track: " << *it << endl;
2263+ MH_INFO("Advancing to next track: %s", *it);
2264 set_current_track(*it);
2265 go_to_track = true;
2266 }
2267@@ -584,7 +585,7 @@
2268 const auto it = std::next(current_iterator());
2269 if (not is_last_track(it))
2270 {
2271- cout << "Advancing to next track: " << *it << endl;
2272+ MH_INFO("Advancing to next track: %s", *it);
2273 d->current_track = it;
2274 go_to_track = true;
2275 }
2276@@ -594,7 +595,7 @@
2277
2278 if (go_to_track)
2279 {
2280- cout << "next track id is " << *(current_iterator()) << endl;
2281+ MH_DEBUG("next track id is %s", *(current_iterator()));
2282 on_track_changed()(*(current_iterator()));
2283 const media::Track::Id id = *(current_iterator());
2284 // Signal the PlayerImplementation to play the next track
2285@@ -603,7 +604,7 @@
2286 else
2287 {
2288 // At the end of the tracklist and not set to loop
2289- cout << "End of tracklist reached" << endl;
2290+ MH_INFO("End of tracklist reached");
2291 on_end_of_tracklist()();
2292 }
2293
2294@@ -612,10 +613,10 @@
2295
2296 media::Track::Id media::TrackListSkeleton::previous()
2297 {
2298- std::cout << __PRETTY_FUNCTION__ << std::endl;
2299+ MH_TRACE("");
2300 if (tracks().get().empty()) {
2301 // TODO Change ServiceSkeleton to return with error from DBus call
2302- std::cerr << "ERROR: no tracks, cannot go to previous" << std::endl;
2303+ MH_ERROR("No tracks, cannot go to previous");
2304 return media::Track::Id{};
2305 }
2306
2307@@ -627,19 +628,19 @@
2308 // repeat it from the beginning
2309 if (d->current_position > max_position)
2310 {
2311- std::cout << "Repeating current track..." << std::endl;
2312+ MH_INFO("Repeating current track...");
2313 go_to_track = true;
2314 }
2315 // Loop on the current track forever
2316 else if (d->loop_status == media::Player::LoopStatus::track)
2317 {
2318- std::cout << "Looping on the current track..." << std::endl;
2319+ MH_INFO("Looping on the current track...");
2320 go_to_track = true;
2321 }
2322 // Loop over the whole playlist and repeat
2323 else if (d->loop_status == media::Player::LoopStatus::playlist && not has_previous())
2324 {
2325- std::cout << "Looping on the entire TrackList..." << std::endl;
2326+ MH_INFO("Looping on the entire TrackList...");
2327
2328 if (shuffle())
2329 {
2330@@ -680,7 +681,7 @@
2331 else
2332 {
2333 // At the beginning of the tracklist and not set to loop
2334- cout << "Beginning of tracklist reached" << endl;
2335+ MH_INFO("Beginning of tracklist reached");
2336 on_end_of_tracklist()();
2337 }
2338
2339@@ -698,12 +699,12 @@
2340 // a segfault when calling current()
2341 if (tracks().get().size() && (d->current_track == d->empty_iterator))
2342 {
2343- std::cout << "Wrapping d->current_track back to begin()" << std::endl;
2344+ MH_DEBUG("Wrapping d->current_track back to begin()");
2345 d->current_track = d->skeleton.properties.tracks->get().begin();
2346 }
2347 else if (tracks().get().empty())
2348 {
2349- std::cerr << "TrackList is empty therefore there is no valid current track" << std::endl;
2350+ MH_ERROR("TrackList is empty therefore there is no valid current track");
2351 }
2352
2353 return d->current_track;
2354@@ -711,11 +712,10 @@
2355
2356 bool media::TrackListSkeleton::update_current_iterator(const TrackList::ConstIterator &it)
2357 {
2358- std::cout << __PRETTY_FUNCTION__ << std::endl;
2359+ MH_TRACE("");
2360 if (it == tracks().get().end())
2361 return false;
2362
2363- std::cout << "Updating current_track iterator" << std::endl;
2364 d->current_track = it;
2365
2366 return true;
2367@@ -780,8 +780,7 @@
2368
2369 void media::TrackListSkeleton::on_shuffle_changed(bool shuffle)
2370 {
2371- cout << __PRETTY_FUNCTION__ << endl;
2372-
2373+ MH_TRACE("");
2374 set_shuffle(shuffle);
2375 }
2376
2377@@ -793,7 +792,7 @@
2378 const core::Signal<media::TrackList::ContainerTrackIdTuple>& media::TrackListSkeleton::on_track_list_replaced() const
2379 {
2380 // Print the TrackList instance
2381- std::cout << *this << std::endl;
2382+ MH_DEBUG("%s", *this);
2383 return d->signals.on_track_list_replaced;
2384 }
2385
2386
2387=== modified file 'src/core/media/track_list_stub.cpp'
2388--- src/core/media/track_list_stub.cpp 2016-02-19 16:14:42 +0000
2389+++ src/core/media/track_list_stub.cpp 2016-04-07 00:39:05 +0000
2390@@ -28,6 +28,8 @@
2391 #include "mpris/player.h"
2392 #include "mpris/track_list.h"
2393
2394+#include "core/media/logger/logger.h"
2395+
2396 #include <core/dbus/property.h>
2397 #include <core/dbus/types/object_path.h>
2398 #include <core/dbus/types/variant.h>
2399@@ -111,43 +113,43 @@
2400 {
2401 dbus.on_track_added->connect([this](const Track::Id& id)
2402 {
2403- std::cout << "OnTrackAdded signal arrived via the bus." << std::endl;
2404+ MH_DEBUG("OnTrackAdded signal arrived via the bus.");
2405 on_track_added(id);
2406 });
2407
2408 dbus.on_tracks_added->connect([this](const media::TrackList::ContainerURI& tracks)
2409 {
2410- std::cout << "OnTracksAdded signal arrived via the bus." << std::endl;
2411+ MH_DEBUG("OnTracksAdded signal arrived via the bus.");
2412 on_tracks_added(tracks);
2413 });
2414
2415 dbus.on_track_moved->connect([this](const media::TrackList::TrackIdTuple& ids)
2416 {
2417- std::cout << "OnTrackMoved signal arrived via the bus." << std::endl;
2418+ MH_DEBUG("OnTrackMoved signal arrived via the bus.");
2419 on_track_moved(ids);
2420 });
2421
2422 dbus.on_track_removed->connect([this](const Track::Id& id)
2423 {
2424- std::cout << "OnTrackRemoved signal arrived via the bus." << std::endl;
2425+ MH_DEBUG("OnTrackRemoved signal arrived via the bus.");
2426 on_track_removed(id);
2427 });
2428
2429 dbus.on_track_list_reset->connect([this](void)
2430 {
2431- std::cout << "OnTrackListReset signal arrived via the bus." << std::endl;
2432+ MH_DEBUG("OnTrackListReset signal arrived via the bus.");
2433 on_track_list_reset();
2434 });
2435
2436 dbus.on_track_list_replaced->connect([this](const media::TrackList::ContainerTrackIdTuple& list)
2437 {
2438- std::cout << "OnTrackListReplaced signal arrived via the bus." << std::endl;
2439+ MH_DEBUG("OnTrackListReplaced signal arrived via the bus.");
2440 on_track_list_replaced(list);
2441 });
2442
2443 dbus.on_track_changed->connect([this](const Track::Id& id)
2444 {
2445- std::cout << "OnTrackChanged signal arrived via the bus." << std::endl;
2446+ MH_DEBUG("OnTrackChanged signal arrived via the bus.");
2447 on_track_changed(id);
2448 });
2449 }
2450
2451=== added file 'src/core/media/util/utils.cpp'
2452--- src/core/media/util/utils.cpp 1970-01-01 00:00:00 +0000
2453+++ src/core/media/util/utils.cpp 2016-04-07 00:39:05 +0000
2454@@ -0,0 +1,41 @@
2455+/*
2456+ * Copyright © 2016 Canonical Ltd.
2457+ *
2458+ * This program is free software: you can redistribute it and/or modify it
2459+ * under the terms of the GNU Lesser General Public License version 3,
2460+ * as published by the Free Software Foundation.
2461+ *
2462+ * This program is distributed in the hope that it will be useful,
2463+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2464+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2465+ * GNU Lesser General Public License for more details.
2466+ *
2467+ * You should have received a copy of the GNU Lesser General Public License
2468+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2469+ *
2470+ */
2471+
2472+#include <boost/filesystem.hpp>
2473+#include <boost/algorithm/string.hpp>
2474+
2475+#include <memory>
2476+#include <fstream>
2477+#include <sstream>
2478+
2479+#include <cstring>
2480+#include <cstdarg>
2481+
2482+#include "utils.h"
2483+
2484+namespace media = core::ubuntu::media;
2485+
2486+uint64_t media::Utils::GetNowNs() {
2487+ struct timespec ts;
2488+ memset(&ts, 0, sizeof(ts));
2489+ clock_gettime(CLOCK_MONOTONIC, &ts);
2490+ return ts.tv_sec * 1000000000LL + ts.tv_nsec;
2491+}
2492+
2493+uint64_t media::Utils::GetNowUs() {
2494+ return GetNowNs() / 1000;
2495+}
2496
2497=== added file 'src/core/media/util/utils.h'
2498--- src/core/media/util/utils.h 1970-01-01 00:00:00 +0000
2499+++ src/core/media/util/utils.h 2016-04-07 00:39:05 +0000
2500@@ -0,0 +1,69 @@
2501+/*
2502+ * Copyright © 2016 Canonical Ltd.
2503+ *
2504+ * This program is free software: you can redistribute it and/or modify it
2505+ * under the terms of the GNU Lesser General Public License version 3,
2506+ * as published by the Free Software Foundation.
2507+ *
2508+ * This program is distributed in the hope that it will be useful,
2509+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2510+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2511+ * GNU Lesser General Public License for more details.
2512+ *
2513+ * You should have received a copy of the GNU Lesser General Public License
2514+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2515+ *
2516+ */
2517+
2518+#ifndef UTILS_H_
2519+#define UTILS_H_
2520+
2521+#include <boost/format.hpp>
2522+
2523+#include <string>
2524+#include <vector>
2525+
2526+#define MCS_STR_VALUE(str) #str
2527+
2528+namespace core {
2529+namespace ubuntu {
2530+namespace media {
2531+typedef int64_t TimestampNs;
2532+typedef int64_t TimestampUs;
2533+struct Utils
2534+{
2535+ // Merely used as a namespace.
2536+ Utils() = delete;
2537+
2538+ // Sprintf - much like what you would expect :)
2539+ template<typename... Types>
2540+ static std::string Sprintf(const std::string& fmt_str, Types&&... args);
2541+ // GetEnv - returns a variable value from the environment
2542+ static uint64_t GetNowNs();
2543+ // GetNowUs - get a timestamp in microseconds
2544+ static uint64_t GetNowUs();
2545+};
2546+
2547+namespace impl {
2548+// Base case, just return the passed in boost::format instance.
2549+inline boost::format& Sprintf(boost::format& f)
2550+{
2551+ return f;
2552+}
2553+// Sprintf recursively walks the parameter pack at compile time.
2554+template <typename Head, typename... Tail>
2555+inline boost::format& Sprintf(boost::format& f, Head const& head, Tail&&... tail) {
2556+ return Sprintf(f % head, std::forward<Tail>(tail)...);
2557+}
2558+} // namespace impl
2559+} // namespace media
2560+} // namespace ubuntu
2561+} // namespace core
2562+
2563+template <typename... Types>
2564+inline std::string core::ubuntu::media::Utils::Sprintf(const std::string& format, Types&&... args) {
2565+ boost::format f(format);
2566+ return core::ubuntu::media::impl::Sprintf(f, std::forward<Types>(args)...).str();
2567+}
2568+
2569+#endif
2570
2571=== modified file 'src/core/media/video/platform_default_sink.cpp'
2572--- src/core/media/video/platform_default_sink.cpp 2015-01-29 12:12:43 +0000
2573+++ src/core/media/video/platform_default_sink.cpp 2016-04-07 00:39:05 +0000
2574@@ -36,7 +36,7 @@
2575 // and returns true or returns false and leaves 'matrix' unchanged in case
2576 // of issues.
2577 bool transformation_matrix(float*) const
2578- {
2579+ {
2580 return true;
2581 }
2582

Subscribers

People subscribed via source and target branches

to all changes: