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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-12-16 16:55:51 +0000
+++ CMakeLists.txt 2016-04-07 00:39:05 +0000
@@ -43,7 +43,7 @@
43include(GNUInstallDirs)43include(GNUInstallDirs)
4444
45find_package(PkgConfig)45find_package(PkgConfig)
46find_package(Boost COMPONENTS filesystem system program_options REQUIRED)46find_package(Boost COMPONENTS filesystem log system thread program_options REQUIRED)
47find_package(GLog)47find_package(GLog)
48pkg_check_modules(DBUS dbus-1 REQUIRED)48pkg_check_modules(DBUS dbus-1 REQUIRED)
49pkg_check_modules(DBUS_CPP dbus-cpp REQUIRED)49pkg_check_modules(DBUS_CPP dbus-cpp REQUIRED)
5050
=== modified file 'debian/control.in'
--- debian/control.in 2015-11-22 21:01:02 +0000
+++ debian/control.in 2016-04-07 00:39:05 +0000
@@ -12,6 +12,7 @@
12 gstreamer1.0-plugins-good,12 gstreamer1.0-plugins-good,
13 libboost-dev (>=1.53),13 libboost-dev (>=1.53),
14 libboost-filesystem-dev (>=1.53),14 libboost-filesystem-dev (>=1.53),
15 libboost-log-dev (>=1.53),
15 libboost-program-options-dev (>=1.53),16 libboost-program-options-dev (>=1.53),
16 libboost-system-dev (>=1.53),17 libboost-system-dev (>=1.53),
17 libdbus-1-dev,18 libdbus-1-dev,
1819
=== modified file 'include/core/media/player.h'
--- include/core/media/player.h 2016-02-19 16:14:42 +0000
+++ include/core/media/player.h 2016-04-07 00:39:05 +0000
@@ -229,6 +229,29 @@
229 return out;229 return out;
230}230}
231231
232inline std::ostream& operator<<(std::ostream& out, Player::Error e)
233{
234 switch (e)
235 {
236 case Player::Error::no_error:
237 return out << "Error::no_error";
238 case Player::Error::resource_error:
239 return out << "Error::resource_error";
240 case Player::Error::format_error:
241 return out << "Error::format_error";
242 case Player::Error::network_error:
243 return out << "Error::network_error";
244 case Player::Error::access_denied_error:
245 return out << "Error::access_denied_error";
246 case Player::Error::service_missing_error:
247 return out << "Error::service_missing_error";
248 default:
249 return out << "Unsupported Player error: " << e;
250 }
251
252 return out;
253}
254
232}255}
233}256}
234}257}
235258
=== modified file 'src/core/media/CMakeLists.txt'
--- src/core/media/CMakeLists.txt 2015-09-04 18:46:08 +0000
+++ src/core/media/CMakeLists.txt 2016-04-07 00:39:05 +0000
@@ -18,6 +18,7 @@
18 media-hub-common SHARED18 media-hub-common SHARED
1919
20 the_session_bus.cpp20 the_session_bus.cpp
21 util/utils.cpp
21)22)
2223
23target_link_libraries(24target_link_libraries(
@@ -42,6 +43,8 @@
4243
43 ${MEDIA_HUB_HEADERS}44 ${MEDIA_HUB_HEADERS}
4445
46 logger/logger.cpp
47
45 player.cpp48 player.cpp
46 service.cpp49 service.cpp
47 track.cpp50 track.cpp
@@ -70,6 +73,8 @@
7073
71 media-hub-common74 media-hub-common
7275
76 ${Boost_LDFLAGS}
77 ${Boost_LIBRARIES}
73 ${DBUS_LIBRARIES}78 ${DBUS_LIBRARIES}
74 ${DBUS_CPP_LDFLAGS}79 ${DBUS_CPP_LDFLAGS}
75 ${GLog_LIBRARY}80 ${GLog_LIBRARY}
@@ -87,6 +92,8 @@
87 ${MEDIA_HUB_HEADERS}92 ${MEDIA_HUB_HEADERS}
88 ${MPRIS_HEADERS}93 ${MPRIS_HEADERS}
8994
95 logger/logger.cpp
96
90 client_death_observer.cpp97 client_death_observer.cpp
91 hashed_keyed_player_store.cpp98 hashed_keyed_player_store.cpp
92 hybris_client_death_observer.cpp99 hybris_client_death_observer.cpp
@@ -123,6 +130,8 @@
123 media-hub-client130 media-hub-client
124 media-hub-common131 media-hub-common
125 call-monitor132 call-monitor
133 ${Boost_LDFLAGS}
134 ${Boost_LIBRARIES}
126 ${DBUS_LIBRARIES}135 ${DBUS_LIBRARIES}
127 ${DBUS_CPP_LDFLAGS}136 ${DBUS_CPP_LDFLAGS}
128 ${GLog_LIBRARY}137 ${GLog_LIBRARY}
129138
=== modified file 'src/core/media/apparmor/ubuntu.cpp'
--- src/core/media/apparmor/ubuntu.cpp 2016-02-23 14:17:04 +0000
+++ src/core/media/apparmor/ubuntu.cpp 2016-04-07 00:39:05 +0000
@@ -20,7 +20,8 @@
2020
21#include <core/media/external_services.h>21#include <core/media/external_services.h>
2222
23#include <iostream>23#include "core/media/logger/logger.h"
24
24#include <regex>25#include <regex>
2526
26namespace apparmor = core::ubuntu::media::apparmor;27namespace apparmor = core::ubuntu::media::apparmor;
@@ -107,9 +108,9 @@
107 unity_{name == unity_name},108 unity_{name == unity_name},
108 has_package_name_{process_context_name(str(), match_, pkg_name_)}109 has_package_name_{process_context_name(str(), match_, pkg_name_)}
109{110{
110 std::cout << "apparmor profile name: " << name;111 MH_DEBUG("apparmor profile name: %s", name);
111 std::cout << ", is_unconfined(): " << is_unconfined();112 MH_DEBUG("is_unconfined(): %s", (is_unconfined() ? "true" : "false"));
112 std::cout << ", has_package_name(): " << has_package_name() << std::endl;113 MH_DEBUG("has_package_name(): %s", (has_package_name() ? "true" : "false"));
113 if (not is_unconfined() and not is_unity() and not has_package_name())114 if (not is_unconfined() and not is_unity() and not has_package_name())
114 throw std::logic_error115 throw std::logic_error
115 {116 {
@@ -163,8 +164,8 @@
163164
164 Uri parsed_uri = parse_uri(uri);165 Uri parsed_uri = parse_uri(uri);
165166
166 std::cout << "context.profile_name(): " << context.profile_name() << std::endl;167 MH_DEBUG("context.profile_name(): %s", context.profile_name());
167 std::cout << "parsed_uri.path: " << parsed_uri.path << std::endl;168 MH_DEBUG("parsed_uri.path: %s", parsed_uri.path);
168169
169 // All confined apps can access their own files170 // All confined apps can access their own files
170 if (parsed_uri.path.find(std::string(".local/share/" + context.package_name() + "/")) != std::string::npos ||171 if (parsed_uri.path.find(std::string(".local/share/" + context.package_name() + "/")) != std::string::npos ||
171172
=== modified file 'src/core/media/audio/pulse_audio_output_observer.cpp'
--- src/core/media/audio/pulse_audio_output_observer.cpp 2015-03-19 00:04:12 +0000
+++ src/core/media/audio/pulse_audio_output_observer.cpp 2016-04-07 00:39:05 +0000
@@ -21,6 +21,8 @@
2121
22#include <pulse/pulseaudio.h>22#include <pulse/pulseaudio.h>
2323
24#include "core/media/logger/logger.h"
25
24#include <cstdint>26#include <cstdint>
2527
26#include <map>28#include <map>
@@ -245,7 +247,7 @@
245 std::get<1>(outputs.back()) | properties.external_output_state;247 std::get<1>(outputs.back()) | properties.external_output_state;
246 std::get<1>(outputs.back()).changed().connect([](media::audio::OutputState state)248 std::get<1>(outputs.back()).changed().connect([](media::audio::OutputState state)
247 {249 {
248 std::cout << "Connection state for port changed to: " << state << std::endl;250 MH_DEBUG("Connection state for port changed to: %s", state);
249 });251 });
250 }252 }
251253
@@ -289,8 +291,8 @@
289 void on_sink_event_with_index(std::int32_t index)291 void on_sink_event_with_index(std::int32_t index)
290 {292 {
291 config.reporter->sink_event_with_index(index);293 config.reporter->sink_event_with_index(index);
292 294
293 // Update server info (active sink) 295 // Update server info (active sink)
294 pa::get_server_info_async(context, main_loop, Private::query_for_server_info_finished, this);296 pa::get_server_info_async(context, main_loop, Private::query_for_server_info_finished, this);
295297
296 }298 }
@@ -317,15 +319,15 @@
317 if (std::get<0>(active_sink) != info->index)319 if (std::get<0>(active_sink) != info->index)
318 continue;320 continue;
319321
320 std::cout << "Checking if port is available " << " -> " << std::boolalpha << pa::is_port_available_on_sink(info, std::get<0>(element)) << std::endl;322 MH_INFO("Checking if port is available -> %s",
321 bool available = pa::is_port_available_on_sink(info, std::get<0>(element));323 pa::is_port_available_on_sink(info, std::get<0>(element)));
322324 const bool available = pa::is_port_available_on_sink(info, std::get<0>(element));
323 if (available)325 if (available)
324 {326 {
325 std::get<1>(element) = audio::OutputState::Earpiece;327 std::get<1>(element) = audio::OutputState::Earpiece;
326 continue;328 continue;
327 }329 }
328 330
329 audio::OutputState state;331 audio::OutputState state;
330 if (info->index == primary_sink_index)332 if (info->index == primary_sink_index)
331 state = audio::OutputState::Speaker;333 state = audio::OutputState::Speaker;
@@ -386,7 +388,7 @@
386 }388 }
387 }389 }
388390
389 PulseAudioOutputObserver::Configuration config; 391 PulseAudioOutputObserver::Configuration config;
390 pa::ThreadedMainLoopPtr main_loop;392 pa::ThreadedMainLoopPtr main_loop;
391 pa::ContextPtr context;393 pa::ContextPtr context;
392 std::int32_t primary_sink_index;394 std::int32_t primary_sink_index;
393395
=== modified file 'src/core/media/gstreamer/engine.cpp'
--- src/core/media/gstreamer/engine.cpp 2016-02-19 16:14:42 +0000
+++ src/core/media/gstreamer/engine.cpp 2016-04-07 00:39:05 +0000
@@ -25,6 +25,8 @@
25#include "meta_data_extractor.h"25#include "meta_data_extractor.h"
26#include "playbin.h"26#include "playbin.h"
2727
28#include "core/media/logger/logger.h"
29
28#include <cassert>30#include <cassert>
2931
30namespace media = core::ubuntu::media;32namespace media = core::ubuntu::media;
@@ -67,8 +69,8 @@
67 {69 {
68 if (p.second == "playbin")70 if (p.second == "playbin")
69 {71 {
70 std::cout << "State changed on playbin: "72 MH_INFO("State changed on playbin: %s",
71 << gst_element_state_get_name(p.first.new_state) << std::endl;73 gst_element_state_get_name(p.first.new_state));
72 const auto status = gst_state_to_player_status(p.first);74 const auto status = gst_state_to_player_status(p.first);
73 /*75 /*
74 * When state moves to "paused" the pipeline is already set. We check that we76 * When state moves to "paused" the pipeline is already set. We check that we
@@ -76,7 +78,7 @@
76 */78 */
77 if (status == media::Player::PlaybackStatus::paused &&79 if (status == media::Player::PlaybackStatus::paused &&
78 !playbin.can_play_streams()) {80 !playbin.can_play_streams()) {
79 std::cerr << "** Cannot play: some codecs are missing" << std::endl;81 MH_ERROR("** Cannot play: some codecs are missing");
80 playbin.reset();82 playbin.reset();
81 const media::Player::Error e = media::Player::Error::format_error;83 const media::Player::Error e = media::Player::Error::format_error;
82 error(e);84 error(e);
@@ -96,20 +98,20 @@
96 switch (ewi.error->code)98 switch (ewi.error->code)
97 {99 {
98 case GST_CORE_ERROR_FAILED:100 case GST_CORE_ERROR_FAILED:
99 std::cerr << "** Encountered a GST_CORE_ERROR_FAILED" << std::endl;101 MH_ERROR("** Encountered a GST_CORE_ERROR_FAILED");
100 ret_error = media::Player::Error::resource_error;102 ret_error = media::Player::Error::resource_error;
101 break;103 break;
102 case GST_CORE_ERROR_NEGOTIATION:104 case GST_CORE_ERROR_NEGOTIATION:
103 std::cerr << "** Encountered a GST_CORE_ERROR_NEGOTIATION" << std::endl;105 MH_ERROR("** Encountered a GST_CORE_ERROR_NEGOTIATION");
104 ret_error = media::Player::Error::resource_error;106 ret_error = media::Player::Error::resource_error;
105 break;107 break;
106 case GST_CORE_ERROR_MISSING_PLUGIN:108 case GST_CORE_ERROR_MISSING_PLUGIN:
107 std::cerr << "** Encountered a GST_CORE_ERROR_MISSING_PLUGIN" << std::endl;109 MH_ERROR("** Encountered a GST_CORE_ERROR_MISSING_PLUGIN");
108 ret_error = media::Player::Error::format_error;110 ret_error = media::Player::Error::format_error;
109 break;111 break;
110 default:112 default:
111 std::cerr << "** Encountered an unhandled core error: '"113 MH_ERROR("** Encountered an unhandled core error: '%s' (code: %d)",
112 << ewi.debug << "' (code: " << ewi.error->code << ")" << std::endl;114 ewi.debug, ewi.error->code);
113 ret_error = media::Player::Error::no_error;115 ret_error = media::Player::Error::no_error;
114 break;116 break;
115 }117 }
@@ -119,36 +121,36 @@
119 switch (ewi.error->code)121 switch (ewi.error->code)
120 {122 {
121 case GST_RESOURCE_ERROR_FAILED:123 case GST_RESOURCE_ERROR_FAILED:
122 std::cerr << "** Encountered a GST_RESOURCE_ERROR_FAILED" << std::endl;124 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_FAILED");
123 ret_error = media::Player::Error::resource_error;125 ret_error = media::Player::Error::resource_error;
124 break;126 break;
125 case GST_RESOURCE_ERROR_NOT_FOUND:127 case GST_RESOURCE_ERROR_NOT_FOUND:
126 std::cerr << "** Encountered a GST_RESOURCE_ERROR_NOT_FOUND" << std::endl;128 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_NOT_FOUND");
127 ret_error = media::Player::Error::resource_error;129 ret_error = media::Player::Error::resource_error;
128 break;130 break;
129 case GST_RESOURCE_ERROR_OPEN_READ:131 case GST_RESOURCE_ERROR_OPEN_READ:
130 std::cerr << "** Encountered a GST_RESOURCE_ERROR_OPEN_READ" << std::endl;132 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_OPEN_READ");
131 ret_error = media::Player::Error::resource_error;133 ret_error = media::Player::Error::resource_error;
132 break;134 break;
133 case GST_RESOURCE_ERROR_OPEN_WRITE:135 case GST_RESOURCE_ERROR_OPEN_WRITE:
134 std::cerr << "** Encountered a GST_RESOURCE_ERROR_OPEN_WRITE" << std::endl;136 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_OPEN_WRITE");
135 ret_error = media::Player::Error::resource_error;137 ret_error = media::Player::Error::resource_error;
136 break;138 break;
137 case GST_RESOURCE_ERROR_READ:139 case GST_RESOURCE_ERROR_READ:
138 std::cerr << "** Encountered a GST_RESOURCE_ERROR_READ" << std::endl;140 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_READ");
139 ret_error = media::Player::Error::resource_error;141 ret_error = media::Player::Error::resource_error;
140 break;142 break;
141 case GST_RESOURCE_ERROR_WRITE:143 case GST_RESOURCE_ERROR_WRITE:
142 std::cerr << "** Encountered a GST_RESOURCE_ERROR_WRITE" << std::endl;144 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_WRITE");
143 ret_error = media::Player::Error::resource_error;145 ret_error = media::Player::Error::resource_error;
144 break;146 break;
145 case GST_RESOURCE_ERROR_NOT_AUTHORIZED:147 case GST_RESOURCE_ERROR_NOT_AUTHORIZED:
146 std::cerr << "** Encountered a GST_RESOURCE_ERROR_NOT_AUTHORIZED" << std::endl;148 MH_ERROR("** Encountered a GST_RESOURCE_ERROR_NOT_AUTHORIZED");
147 ret_error = media::Player::Error::access_denied_error;149 ret_error = media::Player::Error::access_denied_error;
148 break;150 break;
149 default:151 default:
150 std::cerr << "** Encountered an unhandled resource error: '"152 MH_ERROR("** Encountered an unhandled resource error: '%s' (code: %d)",
151 << ewi.debug << "' (code: " << ewi.error->code << ")" << std::endl;153 ewi.debug, ewi.error->code);
152 ret_error = media::Player::Error::no_error;154 ret_error = media::Player::Error::no_error;
153 break;155 break;
154 }156 }
@@ -158,28 +160,28 @@
158 switch (ewi.error->code)160 switch (ewi.error->code)
159 {161 {
160 case GST_STREAM_ERROR_FAILED:162 case GST_STREAM_ERROR_FAILED:
161 std::cerr << "** Encountered a GST_STREAM_ERROR_FAILED" << std::endl;163 MH_ERROR("** Encountered a GST_STREAM_ERROR_FAILED");
162 ret_error = media::Player::Error::resource_error;164 ret_error = media::Player::Error::resource_error;
163 break;165 break;
164 case GST_STREAM_ERROR_CODEC_NOT_FOUND:166 case GST_STREAM_ERROR_CODEC_NOT_FOUND:
165 std::cerr << "** Encountered a GST_STREAM_ERROR_CODEC_NOT_FOUND" << std::endl;167 MH_ERROR("** Encountered a GST_STREAM_ERROR_CODEC_NOT_FOUND");
166 // Missing codecs are handled later, when state switches to "paused"168 // Missing codecs are handled later, when state switches to "paused"
167 ret_error = media::Player::Error::no_error;169 ret_error = media::Player::Error::no_error;
168 break;170 break;
169 case GST_STREAM_ERROR_DECODE:171 case GST_STREAM_ERROR_DECODE:
170 std::cerr << "** Encountered a GST_STREAM_ERROR_DECODE" << std::endl;172 MH_ERROR("** Encountered a GST_STREAM_ERROR_DECODE");
171 ret_error = media::Player::Error::format_error;173 ret_error = media::Player::Error::format_error;
172 break;174 break;
173 default:175 default:
174 std::cerr << "** Encountered an unhandled stream error: '"176 MH_ERROR("** Encountered an unhandled stream error: '%s' code(%d)",
175 << ewi.debug << "' (code: " << ewi.error->code << ")" << std::endl;177 ewi.debug, ewi.error->code);
176 ret_error = media::Player::Error::no_error;178 ret_error = media::Player::Error::no_error;
177 break;179 break;
178 }180 }
179 }181 }
180182
181 if (ret_error != media::Player::Error::no_error) {183 if (ret_error != media::Player::Error::no_error) {
182 std::cerr << "Resetting playbin pipeline after unrecoverable error" << std::endl;184 MH_ERROR("Resetting playbin pipeline after unrecoverable error");
183 playbin.reset();185 playbin.reset();
184 }186 }
185 return ret_error;187 return ret_error;
@@ -201,7 +203,7 @@
201203
202 void on_playbin_info(const gstreamer::Bus::Message::Detail::ErrorWarningInfo& ewi)204 void on_playbin_info(const gstreamer::Bus::Message::Detail::ErrorWarningInfo& ewi)
203 {205 {
204 std::cerr << "Got a playbin info message (no action taken): " << ewi.debug << std::endl;206 MH_DEBUG("Got a playbin info message (no action taken): %s", ewi.debug);
205 }207 }
206208
207 void on_tag_available(const gstreamer::Bus::Message::Detail::Tag& tag)209 void on_tag_available(const gstreamer::Bus::Message::Detail::Tag& tag)
@@ -437,8 +439,7 @@
437 if (result)439 if (result)
438 {440 {
439 d->state = media::Engine::State::playing;441 d->state = media::Engine::State::playing;
440 cout << __PRETTY_FUNCTION__ << endl;442 MH_INFO("Engine: playing uri: %s", d->playbin.uri());
441 cout << "Engine: playing uri: " << d->playbin.uri() << endl;
442 d->playback_status_changed(media::Player::PlaybackStatus::playing);443 d->playback_status_changed(media::Player::PlaybackStatus::playing);
443 }444 }
444445
@@ -450,7 +451,7 @@
450 // No need to wait, and we can immediately return.451 // No need to wait, and we can immediately return.
451 if (d->state == media::Engine::State::stopped)452 if (d->state == media::Engine::State::stopped)
452 {453 {
453 std::cerr << "Current player state is already stopped - no need to change state to stopped" << std::endl;454 MH_DEBUG("Current player state is already stopped - no need to change state to stopped");
454 return true;455 return true;
455 }456 }
456457
@@ -458,7 +459,7 @@
458 if (result)459 if (result)
459 {460 {
460 d->state = media::Engine::State::stopped;461 d->state = media::Engine::State::stopped;
461 cout << __PRETTY_FUNCTION__ << endl;462 MH_TRACE("");
462 d->playback_status_changed(media::Player::PlaybackStatus::stopped);463 d->playback_status_changed(media::Player::PlaybackStatus::stopped);
463 }464 }
464465
@@ -472,7 +473,7 @@
472 if (result)473 if (result)
473 {474 {
474 d->state = media::Engine::State::paused;475 d->state = media::Engine::State::paused;
475 cout << __PRETTY_FUNCTION__ << endl;476 MH_TRACE("");
476 d->playback_status_changed(media::Player::PlaybackStatus::paused);477 d->playback_status_changed(media::Player::PlaybackStatus::paused);
477 }478 }
478479
479480
=== modified file 'src/core/media/gstreamer/playbin.cpp'
--- src/core/media/gstreamer/playbin.cpp 2016-03-07 21:05:26 +0000
+++ src/core/media/gstreamer/playbin.cpp 2016-04-07 00:39:05 +0000
@@ -25,7 +25,8 @@
25#include <hybris/media/surface_texture_client_hybris.h>25#include <hybris/media/surface_texture_client_hybris.h>
26#include <hybris/media/media_codec_layer.h>26#include <hybris/media/media_codec_layer.h>
2727
28#include "../util/uri_check.h"28#include "core/media/logger/logger.h"
29#include "core/media/util/uri_check.h"
2930
30#include <utility>31#include <utility>
3132
@@ -154,13 +155,13 @@
154{155{
155 using namespace std;156 using namespace std;
156157
157 cout << func << endl;158 MH_DEBUG("%s", func);
158 if (pb.pipeline)159 if (pb.pipeline)
159 cout << "pipeline: " << GST_OBJECT_REFCOUNT(pb.pipeline) << endl;160 MH_DEBUG("pipeline: %d", GST_OBJECT_REFCOUNT(pb.pipeline));
160 if (pb.video_sink)161 if (pb.video_sink)
161 cout << "video_sink: " << GST_OBJECT_REFCOUNT(pb.video_sink) << endl;162 MH_DEBUG("video_sink: %d", GST_OBJECT_REFCOUNT(pb.video_sink));
162 if (pb.audio_sink)163 if (pb.audio_sink)
163 cout << "audio_sink: " << GST_OBJECT_REFCOUNT(pb.audio_sink) << endl;164 MH_DEBUG("audio_sink: %d", GST_OBJECT_REFCOUNT(pb.audio_sink));
164}165}
165#endif166#endif
166167
@@ -183,7 +184,7 @@
183184
184void gstreamer::Playbin::reset()185void gstreamer::Playbin::reset()
185{186{
186 std::cout << "Client died, resetting pipeline" << std::endl;187 MH_INFO("Client died, resetting pipeline");
187 // When the client dies, tear down the current pipeline and get it188 // When the client dies, tear down the current pipeline and get it
188 // in a state that is ready for the next client that connects to the189 // in a state that is ready for the next client that connects to the
189 // service190 // service
@@ -198,19 +199,19 @@
198199
199void gstreamer::Playbin::reset_pipeline()200void gstreamer::Playbin::reset_pipeline()
200{201{
201 std::cout << __PRETTY_FUNCTION__ << std::endl;202 MH_TRACE("");
202 auto ret = gst_element_set_state(pipeline, GST_STATE_NULL);203 const auto ret = gst_element_set_state(pipeline, GST_STATE_NULL);
203 switch(ret)204 switch (ret)
204 {205 {
205 case GST_STATE_CHANGE_FAILURE:206 case GST_STATE_CHANGE_FAILURE:
206 std::cout << "Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;207 MH_WARNING("Failed to reset the pipeline state. Client reconnect may not function properly.");
207 break;208 break;
208 case GST_STATE_CHANGE_NO_PREROLL:209 case GST_STATE_CHANGE_NO_PREROLL:
209 case GST_STATE_CHANGE_SUCCESS:210 case GST_STATE_CHANGE_SUCCESS:
210 case GST_STATE_CHANGE_ASYNC:211 case GST_STATE_CHANGE_ASYNC:
211 break;212 break;
212 default:213 default:
213 std::cout << "Failed to reset the pipeline state. Client reconnect may not function properly." << std::endl;214 MH_WARNING("Failed to reset the pipeline state. Client reconnect may not function properly.");
214 }215 }
215 file_type = MEDIA_FILE_TYPE_NONE;216 file_type = MEDIA_FILE_TYPE_NONE;
216 is_missing_audio_codec = false;217 is_missing_audio_codec = false;
@@ -225,7 +226,7 @@
225 return;226 return;
226227
227 gchar *desc = gst_missing_plugin_message_get_description(message);228 gchar *desc = gst_missing_plugin_message_get_description(message);
228 std::cerr << "Missing plugin: " << desc << std::endl;229 MH_WARNING("Missing plugin: %s", desc);
229 g_free(desc);230 g_free(desc);
230231
231 const GstStructure *msg_data = gst_message_get_structure(message);232 const GstStructure *msg_data = gst_message_get_structure(message);
@@ -234,13 +235,13 @@
234235
235 GstCaps *caps;236 GstCaps *caps;
236 if (!gst_structure_get(msg_data, "detail", GST_TYPE_CAPS, &caps, NULL)) {237 if (!gst_structure_get(msg_data, "detail", GST_TYPE_CAPS, &caps, NULL)) {
237 std::cerr << __PRETTY_FUNCTION__ << ": No detail" << std::endl;238 MH_ERROR("No detail");
238 return;239 return;
239 }240 }
240241
241 GstStructure *caps_data = gst_caps_get_structure(caps, 0);242 GstStructure *caps_data = gst_caps_get_structure(caps, 0);
242 if (!caps_data) {243 if (!caps_data) {
243 std::cerr << __PRETTY_FUNCTION__ << ": No caps data" << std::endl;244 MH_ERROR("No caps data");
244 return;245 return;
245 }246 }
246247
@@ -250,7 +251,7 @@
250 else if (strstr(mime, "video"))251 else if (strstr(mime, "video"))
251 is_missing_video_codec = true;252 is_missing_video_codec = true;
252253
253 std::cerr << "Missing decoder for " << mime << std::endl;254 MH_ERROR("Missing decoder for %s", mime);
254}255}
255256
256void gstreamer::Playbin::on_new_message_async(const Bus::Message& message)257void gstreamer::Playbin::on_new_message_async(const Bus::Message& message)
@@ -324,7 +325,7 @@
324 ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME"),325 ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME"),
325 "audio-sink");326 "audio-sink");
326327
327 std::cout << "audio_sink: " << ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME") << std::endl;328 MH_INFO("audio_sink: %s", ::getenv("CORE_UBUNTU_MEDIA_SERVICE_AUDIO_SINK_NAME"));
328329
329 g_object_set (330 g_object_set (
330 pipeline,331 pipeline,
@@ -339,7 +340,7 @@
339 ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),340 ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),
340 "video-sink");341 "video-sink");
341342
342 std::cout << "video_sink: " << ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") << std::endl;343 MH_INFO("video_sink: %s", ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"));
343344
344 g_object_set (345 g_object_set (
345 pipeline,346 pipeline,
@@ -404,16 +405,17 @@
404/** Sets the new audio stream role on the pulsesink in playbin */405/** Sets the new audio stream role on the pulsesink in playbin */
405void gstreamer::Playbin::set_audio_stream_role(media::Player::AudioStreamRole new_audio_role)406void gstreamer::Playbin::set_audio_stream_role(media::Player::AudioStreamRole new_audio_role)
406{407{
407 std::string role_str("props,media.role=" + get_audio_role_str(new_audio_role));408 const std::string role_str("props,media.role=" + get_audio_role_str(new_audio_role));
408 std::cout << "Audio stream role: " << role_str << std::endl;409 MH_INFO("Audio stream role: %s", role_str);
409410
410 GstStructure *props = gst_structure_from_string (role_str.c_str(), NULL);411 GstStructure *props = gst_structure_from_string (role_str.c_str(), NULL);
411 if (audio_sink != nullptr && props != nullptr) {412 if (audio_sink != nullptr && props != nullptr)
413 {
412 g_object_set (audio_sink, "stream-properties", props, NULL);414 g_object_set (audio_sink, "stream-properties", props, NULL);
413 } else {415 }
414 std::cerr <<416 else
415 "Warning: couldn't set audio stream role - couldn't get audio_sink from pipeline" <<417 {
416 std::endl;418 MH_WARNING("Couldn't set audio stream role - couldn't get audio_sink from pipeline");
417 }419 }
418420
419 gst_structure_free (props);421 gst_structure_free (props);
@@ -475,9 +477,7 @@
475 {477 {
476 // First decode the URI just in case it's partially encoded already478 // First decode the URI just in case it's partially encoded already
477 tmp_uri = decode_uri(uri);479 tmp_uri = decode_uri(uri);
478#ifdef VERBOSE_DEBUG480 MH_DEBUG("File URI was encoded, now decoded: %s", tmp_uri);
479 std::cout << "File URI was encoded, now decoded: " << tmp_uri << std::endl;
480#endif
481 }481 }
482 tmp_uri = encode_uri(tmp_uri);482 tmp_uri = encode_uri(tmp_uri);
483 }483 }
@@ -538,7 +538,7 @@
538538
539 auto ret = gst_element_set_state(pipeline, new_state);539 auto ret = gst_element_set_state(pipeline, new_state);
540540
541 std::cout << __PRETTY_FUNCTION__ << ": requested state change." << std::endl;541 MH_DEBUG("Requested state change.");
542542
543 bool result = false; GstState current, pending;543 bool result = false; GstState current, pending;
544 switch(ret)544 switch(ret)
@@ -570,15 +570,15 @@
570 }570 }
571 catch (const std::exception& e)571 catch (const std::exception& e)
572 {572 {
573 std::cerr << "Problem querying video dimensions: " << e.what() << std::endl;573 MH_WARNING("Problem querying video dimensions: %s", e.what());
574 }574 }
575 catch (...)575 catch (...)
576 {576 {
577 std::cerr << "Problem querying video dimensions." << std::endl;577 MH_WARNING("Problem querying video dimensions.");
578 }578 }
579579
580#ifdef DEBUG_GST_PIPELINE580#ifdef DEBUG_GST_PIPELINE
581 std::cout << "Dumping pipeline dot file" << std::endl;581 MH_DEBUG("Dumping pipeline dot file");
582 GST_DEBUG_BIN_TO_DOT_FILE((GstBin*)pipeline, GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");582 GST_DEBUG_BIN_TO_DOT_FILE((GstBin*)pipeline, GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");
583#endif583#endif
584 }584 }
@@ -656,17 +656,13 @@
656 // We have a URI and it is already percent encoded656 // We have a URI and it is already percent encoded
657 if (uri_scheme and strlen(uri_scheme) > 0 and uri_check->is_encoded())657 if (uri_scheme and strlen(uri_scheme) > 0 and uri_check->is_encoded())
658 {658 {
659#ifdef VERBOSE_DEBUG659 MH_DEBUG("Is a URI and is already percent encoded");
660 std::cout << "Is a URI and is already percent encoded" << std::endl;
661#endif
662 encoded_uri = uri;660 encoded_uri = uri;
663 }661 }
664 // We have a URI but it's not already percent encoded662 // We have a URI but it's not already percent encoded
665 else if (uri_scheme and strlen(uri_scheme) > 0 and !uri_check->is_encoded())663 else if (uri_scheme and strlen(uri_scheme) > 0 and !uri_check->is_encoded())
666 {664 {
667#ifdef VERBOSE_DEBUG665 MH_DEBUG("Is a URI and is not already percent encoded");
668 std::cout << "Is a URI and is not already percent encoded" << std::endl;
669#endif
670 gchar *encoded = g_uri_escape_string(uri.c_str(),666 gchar *encoded = g_uri_escape_string(uri.c_str(),
671 "!$&'()*+,;=:/?[]@", // reserved chars667 "!$&'()*+,;=:/?[]@", // reserved chars
672 TRUE); // Allow UTF-8 chars668 TRUE); // Allow UTF-8 chars
@@ -681,9 +677,7 @@
681 else // We have a path and not a URI. Turn it into a full URI and encode it677 else // We have a path and not a URI. Turn it into a full URI and encode it
682 {678 {
683 GError *error = nullptr;679 GError *error = nullptr;
684#ifdef VERBOSE_DEBUG680 MH_DEBUG("Is a path and is not already percent encoded");
685 std::cout << "Is a path and is not already percent encoded" << std::endl;
686#endif
687 gchar *str = g_filename_to_uri(uri.c_str(), nullptr, &error);681 gchar *str = g_filename_to_uri(uri.c_str(), nullptr, &error);
688 if (!str)682 if (!str)
689 {683 {
@@ -694,8 +688,7 @@
694 g_free(str);688 g_free(str);
695 if (error != nullptr)689 if (error != nullptr)
696 {690 {
697 std::cerr << "Warning: failed to get actual track content type: " << error->message691 MH_WARNING("Failed to get actual track content type: %s", error->message);
698 << std::endl;
699 g_error_free(error);692 g_error_free(error);
700 g_free(str);693 g_free(str);
701 g_free(uri_scheme);694 g_free(uri_scheme);
@@ -742,11 +735,11 @@
742 const std::string content_type {file_info_from_uri(encoded_uri)};735 const std::string content_type {file_info_from_uri(encoded_uri)};
743 if (content_type.empty())736 if (content_type.empty())
744 {737 {
745 std::cerr << "Warning: failed to get actual track content type" << std::endl;738 MH_WARNING("Failed to get actual track content type");
746 return std::string("audio/video/");739 return std::string("audio/video/");
747 }740 }
748741
749 std::cout << "Found content type: " << content_type << std::endl;742 MH_INFO("Found content type: %s", content_type);
750743
751 return content_type;744 return content_type;
752}745}
@@ -758,7 +751,7 @@
758751
759 if (get_file_content_type(uri).find("audio/") == 0)752 if (get_file_content_type(uri).find("audio/") == 0)
760 {753 {
761 std::cout << "Found audio content" << std::endl;754 MH_INFO("Found audio content");
762 return true;755 return true;
763 }756 }
764757
@@ -772,7 +765,7 @@
772765
773 if (get_file_content_type(uri).find("video/") == 0)766 if (get_file_content_type(uri).find("video/") == 0)
774 {767 {
775 std::cout << "Found video content" << std::endl;768 MH_INFO("Found video content");
776 return true;769 return true;
777 }770 }
778771
779772
=== added directory 'src/core/media/logger'
=== added file 'src/core/media/logger/logger.cpp'
--- src/core/media/logger/logger.cpp 1970-01-01 00:00:00 +0000
+++ src/core/media/logger/logger.cpp 2016-04-07 00:39:05 +0000
@@ -0,0 +1,161 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <thread>
19
20#include "logger.h"
21
22#define BOOST_LOG_DYN_LINK
23#include <boost/date_time.hpp>
24#include <boost/filesystem.hpp>
25#include <boost/log/trivial.hpp>
26#include <boost/log/expressions.hpp>
27#include <boost/log/support/date_time.hpp>
28#include <boost/log/utility/manipulators.hpp>
29#include <boost/log/utility/setup.hpp>
30
31namespace media = core::ubuntu::media;
32
33namespace {
34namespace attrs {
35BOOST_LOG_ATTRIBUTE_KEYWORD(Severity, "core::ubuntu::media::Severity", media::Logger::Severity)
36BOOST_LOG_ATTRIBUTE_KEYWORD(Location, "Location", media::Logger::Location)
37BOOST_LOG_ATTRIBUTE_KEYWORD(Timestamp, "Timestamp", boost::posix_time::ptime)
38}
39
40struct BoostLogLogger : public media::Logger {
41 BoostLogLogger() :
42 initialized_(false) {
43 }
44
45 void Init(const media::Logger::Severity &severity = media::Logger::Severity::kWarning) override {
46 if (initialized_)
47 return;
48
49 boost::log::formatter formatter = boost::log::expressions::stream
50 << "[" << attrs::Severity << " "
51 << boost::log::expressions::format_date_time< boost::posix_time::ptime >("Timestamp", "%Y-%m-%d %H:%M:%S.%f")
52 << "] "
53 << boost::log::expressions::if_(boost::log::expressions::has_attr(attrs::Location))
54 [
55 boost::log::expressions::stream << "[" << attrs::Location << "] "
56 ]
57 << boost::log::expressions::smessage;
58
59 boost::log::core::get()->remove_all_sinks();
60 auto logger = boost::log::add_console_log(std::cout);
61 logger->set_formatter(formatter);
62
63 // FIXME need to enable this once we found how we wrap this
64 // properly into our service architecture. For now left as
65 // it is.
66 boost::ignore_unused_variable_warning(severity);
67 // logger->set_filter(attrs::Severity < severity);
68
69 initialized_ = true;
70 }
71
72 void Log(Severity severity, const std::string& message, const boost::optional<Location> &loc) {
73 if (!initialized_)
74 Init();
75
76 if (auto rec = boost::log::trivial::logger::get().open_record()) {
77 boost::log::record_ostream out{rec};
78 out << boost::log::add_value(attrs::Severity, severity)
79 << boost::log::add_value(attrs::Timestamp, boost::posix_time::microsec_clock::universal_time())
80 << message;
81
82 if (loc) {
83 // We have to pass in a temporary as boost::log (<= 1.55) expects a
84 // mutable reference to be passed to boost::log::add_value(...).
85 auto tmp = *loc;
86 out << boost::log::add_value(attrs::Location, tmp);
87 }
88
89 boost::log::trivial::logger::get().push_record(std::move(rec));
90 }
91 }
92
93private:
94 bool initialized_;
95};
96
97std::shared_ptr<media::Logger>& MutableInstance() {
98 static std::shared_ptr<media::Logger> instance{new BoostLogLogger()};
99 return instance;
100}
101
102void SetInstance(const std::shared_ptr<media::Logger>& logger) {
103 MutableInstance() = logger;
104}
105}
106
107void media::Logger::Trace(const std::string& message, const boost::optional<Location>& location) {
108 Log(Severity::kTrace, message, location);
109}
110
111void media::Logger::Debug(const std::string& message, const boost::optional<Location>& location) {
112 Log(Severity::kDebug, message, location);
113}
114
115void media::Logger::Info(const std::string& message, const boost::optional<Location>& location) {
116 Log(Severity::kInfo, message, location);
117}
118
119void media::Logger::Warning(const std::string& message, const boost::optional<Location>& location) {
120 Log(Severity::kWarning, message, location);
121}
122
123void media::Logger::Error(const std::string& message, const boost::optional<Location>& location) {
124 Log(Severity::kError, message, location);
125}
126
127void media::Logger::Fatal(const std::string& message, const boost::optional<Location>& location) {
128 Log(Severity::kFatal, message, location);
129}
130
131namespace core {
132namespace ubuntu {
133namespace media {
134
135std::ostream& operator<<(std::ostream& strm, Logger::Severity severity) {
136 switch (severity) {
137 case media::Logger::Severity::kTrace: return strm << "TT";
138 case media::Logger::Severity::kDebug: return strm << "DD";
139 case media::Logger::Severity::kInfo: return strm << "II";
140 case media::Logger::Severity::kWarning: return strm << "WW";
141 case media::Logger::Severity::kError: return strm << "EE";
142 case media::Logger::Severity::kFatal: return strm << "FF";
143 default: return strm << static_cast<uint>(severity);
144 }
145}
146
147std::ostream& operator<<(std::ostream& out, const Logger::Location &location) {
148 return out << Utils::Sprintf("%s:%d@%s", boost::filesystem::path(location.file).filename().string(), location.line, location.function);
149}
150
151Logger& Log() {
152 return *MutableInstance();
153}
154
155void SetLogger(const std::shared_ptr<Logger>& logger) {
156 SetInstance(logger);
157}
158
159} // namespace media
160} // namespace ubuntu
161} // namespace core
0162
=== added file 'src/core/media/logger/logger.h'
--- src/core/media/logger/logger.h 1970-01-01 00:00:00 +0000
+++ src/core/media/logger/logger.h 2016-04-07 00:39:05 +0000
@@ -0,0 +1,131 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef LOGGER_H_
19#define LOGGER_H_
20
21#include "core/media/non_copyable.h"
22#include "core/media/util/utils.h"
23
24#include <boost/optional.hpp>
25
26#include <string>
27
28namespace core {
29namespace ubuntu {
30namespace media {
31// A Logger enables persisting of messages describing & explaining the
32// state of the system.
33class Logger : public core::ubuntu::media::NonCopyable {
34public:
35 // Severity enumerates all known severity levels
36 // applicable to log messages.
37 enum class Severity {
38 kTrace,
39 kDebug,
40 kInfo,
41 kWarning,
42 kError,
43 kFatal
44 };
45
46 // A Location describes the origin of a log message.
47 struct Location {
48 std::string file; // The name of the file that contains the log message.
49 std::string function; // The function that contains the log message.
50 std::uint32_t line; // The line in file that resulted in the log message.
51 };
52
53 virtual void Init(const core::ubuntu::media::Logger::Severity &severity = core::ubuntu::media::Logger::Severity::kWarning) = 0;
54
55 virtual void Log(Severity severity, const std::string &message, const boost::optional<Location>& location) = 0;
56
57 virtual void Trace(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
58 virtual void Debug(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
59 virtual void Info(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
60 virtual void Warning(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
61 virtual void Error(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
62 virtual void Fatal(const std::string& message, const boost::optional<Location>& location = boost::optional<Location>{});
63
64
65 template<typename... T>
66 void Tracef(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
67 Trace(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
68 }
69
70 template<typename... T>
71 void Debugf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
72 Debug(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
73 }
74
75 template<typename... T>
76 void Infof(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
77 Info(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
78 }
79
80 template<typename... T>
81 void Warningf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
82 Warning(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
83 }
84
85 template<typename... T>
86 void Errorf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
87 Error(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
88 }
89
90 template<typename... T>
91 void Fatalf(const boost::optional<Location>& location, const std::string& pattern, T&&...args) {
92 Fatal(Utils::Sprintf(pattern, std::forward<T>(args)...), location);
93 }
94
95protected:
96 Logger() = default;
97};
98
99// operator<< inserts severity into out.
100std::ostream& operator<<(std::ostream& out, Logger::Severity severity);
101
102// operator<< inserts location into out.
103std::ostream& operator<<(std::ostream& out, const Logger::Location &location);
104
105// Log returns the core::ubuntu::media-wide configured logger instance.
106// Save to call before/after main.
107Logger& Log();
108// SetLog installs the given logger as core::ubuntu::media-wide default logger.
109void SetLogger(const std::shared_ptr<Logger>& logger);
110
111#define TRACE(...) Log().Tracef(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
112#define DEBUG(...) Log().Debugf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
113#define INFO(...) Log().Infof(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
114#define WARNING(...) Log().Warningf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
115#define ERROR(...) Log().Errorf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
116#define FATAL(...) Log().Fatalf(Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
117} // namespace media
118} // namespace ubuntu
119} // namespace core
120
121#define MH_TRACE(...) core::ubuntu::media::Log().Tracef(\
122 core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
123#define MH_DEBUG(...) core::ubuntu::media::Log().Debugf(\
124 core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
125#define MH_INFO(...) core::ubuntu::media::Log().Infof(\
126 core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
127#define MH_WARNING(...) core::ubuntu::media::Log().Warningf(core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
128#define MH_ERROR(...) core::ubuntu::media::Log().Errorf(core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
129#define MH_FATAL(...) core::ubuntu::media::Log().Fatalf(core::ubuntu::media::Logger::Location{__FILE__, __FUNCTION__, __LINE__}, __VA_ARGS__)
130
131#endif
0132
=== added file 'src/core/media/non_copyable.h'
--- src/core/media/non_copyable.h 1970-01-01 00:00:00 +0000
+++ src/core/media/non_copyable.h 2016-04-07 00:39:05 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef NON_COPYABLE_H_
19#define NON_COPYABLE_H_
20
21namespace core {
22namespace ubuntu {
23namespace media {
24// The alert reader might wonder why we don't use boost::noncopyable. The reason
25// is simple: We would like to have a convenient virtual d'tor available.
26struct NonCopyable {
27 NonCopyable() = default;
28 NonCopyable(const NonCopyable&) = delete;
29 virtual ~NonCopyable() = default;
30 NonCopyable& operator=(const NonCopyable&) = delete;
31};
32}
33}
34}
35
36#endif
037
=== modified file 'src/core/media/player_implementation.cpp'
--- src/core/media/player_implementation.cpp 2016-02-19 16:14:42 +0000
+++ src/core/media/player_implementation.cpp 2016-04-07 00:39:05 +0000
@@ -28,9 +28,10 @@
2828
29#include "gstreamer/engine.h"29#include "gstreamer/engine.h"
3030
31#include "core/media/logger/logger.h"
32
31#include <memory>33#include <memory>
32#include <exception>34#include <exception>
33#include <iostream>
34#include <mutex>35#include <mutex>
3536
36#define UNUSED __attribute__((unused))37#define UNUSED __attribute__((unused))
@@ -75,22 +76,22 @@
75 // Poor man's logging of release/acquire events.76 // Poor man's logging of release/acquire events.
76 display_state_lock->acquired().connect([](media::power::DisplayState state)77 display_state_lock->acquired().connect([](media::power::DisplayState state)
77 {78 {
78 std::cout << "Acquired new display state: " << state << std::endl;79 MH_INFO("Acquired new display state: %s", state);
79 });80 });
8081
81 display_state_lock->released().connect([](media::power::DisplayState state)82 display_state_lock->released().connect([](media::power::DisplayState state)
82 {83 {
83 std::cout << "Released display state: " << state << std::endl;84 MH_INFO("Released display state: %s", state);
84 });85 });
8586
86 system_state_lock->acquired().connect([](media::power::SystemState state)87 system_state_lock->acquired().connect([](media::power::SystemState state)
87 {88 {
88 std::cout << "Acquired new system state: " << state << std::endl;89 MH_INFO("Acquired new system state: %s", state);
89 });90 });
9091
91 system_state_lock->released().connect([](media::power::SystemState state)92 system_state_lock->released().connect([](media::power::SystemState state)
92 {93 {
93 std::cout << "Released system state: " << state << std::endl;94 MH_INFO("Released system state: %s", state);
94 });95 });
95 }96 }
9697
@@ -120,7 +121,7 @@
120 */121 */
121 return [this](const Engine::State& state)122 return [this](const Engine::State& state)
122 {123 {
123 std::cout << "Setting state for parent: " << parent << std::endl;124 MH_DEBUG("Setting state for parent: %s", parent);
124 switch(state)125 switch(state)
125 {126 {
126 case Engine::State::ready:127 case Engine::State::ready:
@@ -139,7 +140,7 @@
139 parent->meta_data_for_current_track().set(std::get<1>(engine->track_meta_data().get()));140 parent->meta_data_for_current_track().set(std::get<1>(engine->track_meta_data().get()));
140 // And update our playback status.141 // And update our playback status.
141 parent->playback_status().set(media::Player::playing);142 parent->playback_status().set(media::Player::playing);
142 std::cout << "Requesting power state" << std::endl;143 MH_INFO("Requesting power state");
143 request_power_state();144 request_power_state();
144 break;145 break;
145 }146 }
@@ -174,45 +175,44 @@
174 {175 {
175 return [this](const media::Player::PlaybackStatus& status)176 return [this](const media::Player::PlaybackStatus& status)
176 {177 {
177 std::cout << "Emiting playback_status_changed signal: " << status << std::endl;178 MH_INFO("Emiting playback_status_changed signal: %s", status);
178 parent->emit_playback_status_changed(status);179 parent->emit_playback_status_changed(status);
179 };180 };
180 }181 }
181182
182 void request_power_state()183 void request_power_state()
183 {184 {
184 std::cout << __PRETTY_FUNCTION__ << std::endl;185 MH_TRACE("");
185 try186 try
186 {187 {
187 if (parent->is_video_source())188 if (parent->is_video_source())
188 {189 {
189 if (++display_wakelock_count == 1)190 if (++display_wakelock_count == 1)
190 {191 {
191 std::cout << "Requesting new display wakelock." << std::endl;192 MH_INFO("Requesting new display wakelock.");
192 display_state_lock->request_acquire(media::power::DisplayState::on);193 display_state_lock->request_acquire(media::power::DisplayState::on);
193 std::cout << "Requested new display wakelock." << std::endl;194 MH_INFO("Requested new display wakelock.");
194 }195 }
195 }196 }
196 else197 else
197 {198 {
198 if (++system_wakelock_count == 1)199 if (++system_wakelock_count == 1)
199 {200 {
200 std::cout << "Requesting new system wakelock." << std::endl;201 MH_INFO("Requesting new system wakelock.");
201 system_state_lock->request_acquire(media::power::SystemState::active);202 system_state_lock->request_acquire(media::power::SystemState::active);
202 std::cout << "Requested new system wakelock." << std::endl;203 MH_INFO("Requested new system wakelock.");
203 }204 }
204 }205 }
205 }206 }
206 catch(const std::exception& e)207 catch(const std::exception& e)
207 {208 {
208 std::cerr << "Warning: failed to request power state: ";209 MH_WARNING("Failed to request power state: %s", e.what());
209 std::cerr << e.what() << std::endl;
210 }210 }
211 }211 }
212212
213 void clear_wakelock(const wakelock_clear_t &wakelock)213 void clear_wakelock(const wakelock_clear_t &wakelock)
214 {214 {
215 cout << __PRETTY_FUNCTION__ << endl;215 MH_TRACE("");
216 try216 try
217 {217 {
218 switch (wakelock)218 switch (wakelock)
@@ -223,7 +223,7 @@
223 // Only actually clear the system wakelock once the count reaches zero223 // Only actually clear the system wakelock once the count reaches zero
224 if (--system_wakelock_count == 0)224 if (--system_wakelock_count == 0)
225 {225 {
226 std::cout << "Clearing system wakelock." << std::endl;226 MH_INFO("Clearing system wakelock.");
227 system_state_lock->request_release(media::power::SystemState::active);227 system_state_lock->request_release(media::power::SystemState::active);
228 }228 }
229 break;229 break;
@@ -231,19 +231,18 @@
231 // Only actually clear the display wakelock once the count reaches zero231 // Only actually clear the display wakelock once the count reaches zero
232 if (--display_wakelock_count == 0)232 if (--display_wakelock_count == 0)
233 {233 {
234 std::cout << "Clearing display wakelock." << std::endl;234 MH_INFO("Clearing display wakelock.");
235 display_state_lock->request_release(media::power::DisplayState::on);235 display_state_lock->request_release(media::power::DisplayState::on);
236 }236 }
237 break;237 break;
238 case wakelock_clear_t::WAKELOCK_CLEAR_INVALID:238 case wakelock_clear_t::WAKELOCK_CLEAR_INVALID:
239 default:239 default:
240 cerr << "Can't clear invalid wakelock type" << endl;240 MH_WARNING("Can't clear invalid wakelock type");
241 }241 }
242 }242 }
243 catch(const std::exception& e)243 catch(const std::exception& e)
244 {244 {
245 std::cerr << "Warning: failed to clear power state: ";245 MH_WARNING("Failed to request clear power state: %s", e.what());
246 std::cerr << e.what() << std::endl;
247 }246 }
248 }247 }
249248
@@ -294,9 +293,9 @@
294 {293 {
295 // Using a TrackList for playback, added tracks via add_track(), but open_uri hasn't294 // Using a TrackList for playback, added tracks via add_track(), but open_uri hasn't
296 // been called yet to load a media resource295 // been called yet to load a media resource
297 std::cout << "Calling d->engine->open_resource_for_uri() for first track added only: "296 MH_INFO("Calling d->engine->open_resource_for_uri() for first track added only: %s",
298 << uri << std::endl;297 uri);
299 std::cout << "\twith a Track::Id: " << id << std::endl;298 MH_INFO("\twith a Track::Id: %s", id);
300 static const bool do_pipeline_reset = false;299 static const bool do_pipeline_reset = false;
301 engine->open_resource_for_uri(uri, do_pipeline_reset);300 engine->open_resource_for_uri(uri, do_pipeline_reset);
302 }301 }
@@ -311,10 +310,10 @@
311 auto n_tracks = track_list->tracks()->size();310 auto n_tracks = track_list->tracks()->size();
312 bool has_tracks = (n_tracks > 0) ? true : false;311 bool has_tracks = (n_tracks > 0) ? true : false;
313312
314 std::cout << "Updating MPRIS TrackList properties"313 MH_INFO("Updating MPRIS TrackList properties:");
315 << "; Tracks: " << n_tracks314 MH_INFO("\tTracks: %d", n_tracks);
316 << ", has_previous: " << has_previous315 MH_INFO("\thas_previous: %d", has_previous);
317 << ", has_next: " << has_next << std::endl;316 MH_INFO("\thas_next: %d", has_next);
318317
319 // Update properties318 // Update properties
320 parent->can_play().set(has_tracks);319 parent->can_play().set(has_tracks);
@@ -418,7 +417,7 @@
418 // When the client changes the loop status, make sure to update the TrackList417 // When the client changes the loop status, make sure to update the TrackList
419 Parent::loop_status().changed().connect([this](media::Player::LoopStatus loop_status)418 Parent::loop_status().changed().connect([this](media::Player::LoopStatus loop_status)
420 {419 {
421 std::cout << "LoopStatus: " << loop_status << std::endl;420 MH_INFO("LoopStatus: %s", loop_status);
422 d->track_list->on_loop_status_changed(loop_status);421 d->track_list->on_loop_status_changed(loop_status);
423 });422 });
424423
@@ -465,7 +464,7 @@
465 const Track::UriType uri = d->track_list->query_uri_for_track(d->track_list->next());464 const Track::UriType uri = d->track_list->query_uri_for_track(d->track_list->next());
466 if (prev_track_id != d->track_list->current() && !uri.empty())465 if (prev_track_id != d->track_list->current() && !uri.empty())
467 {466 {
468 std::cout << "Advancing to next track on playbin: " << uri << std::endl;467 MH_INFO("Advancing to next track on playbin: %s", uri);
469 static const bool do_pipeline_reset = false;468 static const bool do_pipeline_reset = false;
470 d->engine->open_resource_for_uri(uri, do_pipeline_reset);469 d->engine->open_resource_for_uri(uri, do_pipeline_reset);
471 }470 }
@@ -508,7 +507,7 @@
508 if (d->engine->state() != gstreamer::Engine::State::ready507 if (d->engine->state() != gstreamer::Engine::State::ready
509 && d->engine->state() != gstreamer::Engine::State::stopped)508 && d->engine->state() != gstreamer::Engine::State::stopped)
510 {509 {
511 std::cout << "End of tracklist reached, stopping playback" << std::endl;510 MH_INFO("End of tracklist reached, stopping playback");
512 d->engine->stop();511 d->engine->stop();
513 }512 }
514 });513 });
@@ -528,15 +527,15 @@
528 const Track::UriType uri = d->track_list->query_uri_for_track(id);527 const Track::UriType uri = d->track_list->query_uri_for_track(id);
529 if (!uri.empty())528 if (!uri.empty())
530 {529 {
531 std::cout << "Setting next track on playbin (on_go_to_track signal): " << uri << std::endl;530 MH_INFO("Setting next track on playbin (on_go_to_track signal): %s", uri);
532 std::cout << "\twith a Track::Id: " << id << std::endl;531 MH_INFO("\twith a Track::Id: %s", id);
533 static const bool do_pipeline_reset = true;532 static const bool do_pipeline_reset = true;
534 d->engine->open_resource_for_uri(uri, do_pipeline_reset);533 d->engine->open_resource_for_uri(uri, do_pipeline_reset);
535 }534 }
536535
537 if (auto_play)536 if (auto_play)
538 {537 {
539 std::cout << "Restoring playing state in on_go_to_track()" << std::endl;538 MH_DEBUG("Restoring playing state");
540 d->engine->play();539 d->engine->play();
541 }540 }
542541
@@ -545,7 +544,7 @@
545544
546 d->track_list->on_track_added().connect([this](const media::Track::Id& id)545 d->track_list->on_track_added().connect([this](const media::Track::Id& id)
547 {546 {
548 std::cout << "** Track was added, handling in PlayerImplementation" << std::endl;547 MH_TRACE("** Track was added, handling in PlayerImplementation");
549 if (d->track_list->tracks()->size() == 1)548 if (d->track_list->tracks()->size() == 1)
550 d->open_first_track_from_tracklist(id);549 d->open_first_track_from_tracklist(id);
551550
@@ -554,7 +553,7 @@
554553
555 d->track_list->on_tracks_added().connect([this](const media::TrackList::ContainerURI& tracks)554 d->track_list->on_tracks_added().connect([this](const media::TrackList::ContainerURI& tracks)
556 {555 {
557 std::cout << "** Track was added, handling in PlayerImplementation" << std::endl;556 MH_TRACE("** Track was added, handling in PlayerImplementation");
558 // If the two sizes are the same, that means the TrackList was previously empty and we need557 // If the two sizes are the same, that means the TrackList was previously empty and we need
559 // to open the first track in the TrackList so that is_audio_source() and is_video_source()558 // to open the first track in the TrackList so that is_audio_source() and is_video_source()
560 // will function correctly.559 // will function correctly.
@@ -689,7 +688,7 @@
689688
690 // If empty uri, give the same meaning as QMediaPlayer::setMedia("")689 // If empty uri, give the same meaning as QMediaPlayer::setMedia("")
691 if (uri.empty()) {690 if (uri.empty()) {
692 cout << __PRETTY_FUNCTION__ << ": resetting current media" << endl;691 MH_DEBUG("Resetting current media");
693 return true;692 return true;
694 }693 }
695694
@@ -722,19 +721,21 @@
722template<typename Parent>721template<typename Parent>
723void media::PlayerImplementation<Parent>::play()722void media::PlayerImplementation<Parent>::play()
724{723{
724 MH_TRACE("");
725 d->engine->play();725 d->engine->play();
726}726}
727727
728template<typename Parent>728template<typename Parent>
729void media::PlayerImplementation<Parent>::pause()729void media::PlayerImplementation<Parent>::pause()
730{730{
731 MH_TRACE("");
731 d->engine->pause();732 d->engine->pause();
732}733}
733734
734template<typename Parent>735template<typename Parent>
735void media::PlayerImplementation<Parent>::stop()736void media::PlayerImplementation<Parent>::stop()
736{737{
737 std::cout << __PRETTY_FUNCTION__ << std::endl;738 MH_TRACE("");
738 d->engine->stop();739 d->engine->stop();
739}740}
740741
741742
=== modified file 'src/core/media/player_skeleton.cpp'
--- src/core/media/player_skeleton.cpp 2016-02-19 16:14:42 +0000
+++ src/core/media/player_skeleton.cpp 2016-04-07 00:39:05 +0000
@@ -31,6 +31,8 @@
31#include "mpris/metadata.h"31#include "mpris/metadata.h"
32#include "mpris/player.h"32#include "mpris/player.h"
33#include "mpris/playlists.h"33#include "mpris/playlists.h"
34
35#include "core/media/logger/logger.h"
34#include "util/uri_check.h"36#include "util/uri_check.h"
3537
36#include <core/dbus/object.h>38#include <core/dbus/object.h>
@@ -189,7 +191,7 @@
189 {191 {
190 const std::string err_str = {"Warning: Failed to open uri " + uri +192 const std::string err_str = {"Warning: Failed to open uri " + uri +
191 " because it can't be found."};193 " because it can't be found."};
192 std::cerr << err_str << std::endl;194 MH_ERROR("%s", err_str);
193 reply = dbus::Message::make_error(195 reply = dbus::Message::make_error(
194 in,196 in,
195 mpris::Player::Error::UriNotFound::name,197 mpris::Player::Error::UriNotFound::name,
@@ -207,7 +209,7 @@
207 {209 {
208 const std::string err_str = {"Warning: Failed to authenticate necessary "210 const std::string err_str = {"Warning: Failed to authenticate necessary "
209 "apparmor permissions to open uri: " + std::get<1>(result)};211 "apparmor permissions to open uri: " + std::get<1>(result)};
210 std::cerr << err_str << std::endl;212 MH_ERROR("%s", err_str);
211 reply = dbus::Message::make_error(213 reply = dbus::Message::make_error(
212 in,214 in,
213 mpris::Player::Error::InsufficientAppArmorPermissions::name,215 mpris::Player::Error::InsufficientAppArmorPermissions::name,
@@ -236,7 +238,7 @@
236 {238 {
237 const std::string err_str = {"Warning: Failed to open uri " + uri +239 const std::string err_str = {"Warning: Failed to open uri " + uri +
238 " because it can't be found."};240 " because it can't be found."};
239 std::cerr << err_str << std::endl;241 MH_ERROR("%s", err_str);
240 reply = dbus::Message::make_error(242 reply = dbus::Message::make_error(
241 in,243 in,
242 mpris::Player::Error::UriNotFound::name,244 mpris::Player::Error::UriNotFound::name,
@@ -254,7 +256,7 @@
254 {256 {
255 const std::string err_str = {"Warning: Failed to authenticate necessary "257 const std::string err_str = {"Warning: Failed to authenticate necessary "
256 "apparmor permissions to open uri: " + std::get<1>(result)};258 "apparmor permissions to open uri: " + std::get<1>(result)};
257 std::cerr << err_str << std::endl;259 MH_ERROR("%s", err_str);
258 reply = dbus::Message::make_error(260 reply = dbus::Message::make_error(
259 in,261 in,
260 mpris::Player::Error::InsufficientAppArmorPermissions::name,262 mpris::Player::Error::InsufficientAppArmorPermissions::name,
261263
=== modified file 'src/core/media/player_stub.cpp'
--- src/core/media/player_stub.cpp 2016-02-19 16:14:42 +0000
+++ src/core/media/player_stub.cpp 2016-04-07 00:39:05 +0000
@@ -30,10 +30,13 @@
3030
31#include "mpris/player.h"31#include "mpris/player.h"
3232
33#include "core/media/logger/logger.h"
34
33#include <core/dbus/property.h>35#include <core/dbus/property.h>
34#include <core/dbus/types/object_path.h>36#include <core/dbus/types/object_path.h>
3537
36#include <limits>38#include <limits>
39#include <sstream>
3740
38#define UNUSED __attribute__((unused))41#define UNUSED __attribute__((unused))
3942
@@ -159,37 +162,38 @@
159 {162 {
160 dbus.seeked_to->connect([this](std::uint64_t value)163 dbus.seeked_to->connect([this](std::uint64_t value)
161 {164 {
162 std::cout << "SeekedTo signal arrived via the bus." << std::endl;165 MH_DEBUG("SeekedTo signal arrived via the bus.");
163 seeked_to(value);166 seeked_to(value);
164 });167 });
165168
166 dbus.about_to_finish->connect([this]()169 dbus.about_to_finish->connect([this]()
167 {170 {
168 std::cout << "AboutToFinish signal arrived via the bus." << std::endl;171 MH_DEBUG("AboutToFinish signal arrived via the bus.");
169 about_to_finish();172 about_to_finish();
170 });173 });
171174
172 dbus.end_of_stream->connect([this]()175 dbus.end_of_stream->connect([this]()
173 {176 {
174 std::cout << "EndOfStream signal arrived via the bus." << std::endl;177 MH_DEBUG("EndOfStream signal arrived via the bus.");
175 end_of_stream();178 end_of_stream();
176 });179 });
177180
178 dbus.playback_status_changed->connect([this](const media::Player::PlaybackStatus& status)181 dbus.playback_status_changed->connect([this](const media::Player::PlaybackStatus& status)
179 {182 {
180 std::cout << "PlaybackStatusChanged signal arrived via the bus (Status: " << status << ")" << std::endl;183 MH_DEBUG("PlaybackStatusChanged signal arrived via the bus (status: %s)",
184 status);
181 playback_status_changed(status);185 playback_status_changed(status);
182 });186 });
183187
184 dbus.video_dimension_changed->connect([this](const media::video::Dimensions dimensions)188 dbus.video_dimension_changed->connect([this](const media::video::Dimensions dimensions)
185 {189 {
186 std::cout << "VideoDimensionChanged signal arrived via the bus." << std::endl;190 MH_DEBUG("VideoDimensionChanged signal arrived via the bus.");
187 video_dimension_changed(dimensions);191 video_dimension_changed(dimensions);
188 });192 });
189193
190 dbus.error->connect([this](const media::Player::Error& e)194 dbus.error->connect([this](const media::Player::Error& e)
191 {195 {
192 std::cout << "Error signal arrived via the bus (Error: " << e << ")" << std::endl;196 MH_DEBUG("Error signal arrived via the bus (error: %s)", e);
193 error(e);197 error(e);
194 });198 });
195 }199 }
196200
=== modified file 'src/core/media/power/state_controller.cpp'
--- src/core/media/power/state_controller.cpp 2015-05-27 18:37:24 +0000
+++ src/core/media/power/state_controller.cpp 2016-04-07 00:39:05 +0000
@@ -16,13 +16,13 @@
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */17 */
1818
19#include "core/media/logger/logger.h"
20
19#include <core/media/power/state_controller.h>21#include <core/media/power/state_controller.h>
2022
21#include <core/dbus/macros.h>23#include <core/dbus/macros.h>
22#include <core/dbus/object.h>24#include <core/dbus/object.h>
2325
24#include <iostream>
25
26namespace media = core::ubuntu::media;26namespace media = core::ubuntu::media;
2727
28namespace com { namespace canonical {28namespace com { namespace canonical {
@@ -98,7 +98,7 @@
98 // From core::ubuntu::media::power::StateController::Lock<DisplayState>98 // From core::ubuntu::media::power::StateController::Lock<DisplayState>
99 void request_acquire(media::power::DisplayState state) override99 void request_acquire(media::power::DisplayState state) override
100 {100 {
101 std::cout << __PRETTY_FUNCTION__ << std::endl;101 MH_TRACE("");
102102
103 if (state == media::power::DisplayState::off)103 if (state == media::power::DisplayState::off)
104 return;104 return;
@@ -110,7 +110,7 @@
110 {110 {
111 if (result.is_error())111 if (result.is_error())
112 {112 {
113 std::cerr << result.error().print() << std::endl;113 MH_ERROR("%s", result.error().print());
114 return;114 return;
115 }115 }
116116
@@ -149,7 +149,7 @@
149 {149 {
150 if (result.is_error())150 if (result.is_error())
151 {151 {
152 std::cerr << result.error().print() << std::endl;152 MH_ERROR("%s", result.error().print());
153 return;153 return;
154 }154 }
155155
@@ -207,7 +207,7 @@
207 // the system to stay active.207 // the system to stay active.
208 void request_acquire(media::power::SystemState state) override208 void request_acquire(media::power::SystemState state) override
209 {209 {
210 std::cout << __PRETTY_FUNCTION__ << std::endl;210 MH_TRACE("");
211211
212 if (state == media::power::SystemState::suspend)212 if (state == media::power::SystemState::suspend)
213 return;213 return;
@@ -223,7 +223,7 @@
223 }223 }
224 else224 else
225 {225 {
226 std::cerr << "Failed to lock system_state_cookie_store_guard and check system lock state" << std::endl;226 MH_WARNING("Failed to lock system_state_cookie_store_guard and check system lock state");
227 // Prevent system_state_cookie_store.count(state) and the actual call to requestSysState below from227 // Prevent system_state_cookie_store.count(state) and the actual call to requestSysState below from
228 // getting out of sync.228 // getting out of sync.
229 return;229 return;
@@ -236,7 +236,7 @@
236 {236 {
237 if (result.is_error())237 if (result.is_error())
238 {238 {
239 std::cerr << result.error().print() << std::endl;239 MH_ERROR("%s", result.error().print());
240 return;240 return;
241 }241 }
242242
@@ -249,7 +249,7 @@
249 if (ul.owns_lock())249 if (ul.owns_lock())
250 sp->system_state_cookie_store[state] = result.value();250 sp->system_state_cookie_store[state] = result.value();
251 else251 else
252 std::cerr << "Failed to lock system_state_cookie_store_guard and update system lock state" << std::endl;252 MH_WARNING("Failed to lock system_state_cookie_store_guard and update system lock state");
253 }253 }
254254
255 sp->signals.acquired(state);255 sp->signals.acquired(state);
@@ -275,7 +275,7 @@
275 }275 }
276 else276 else
277 {277 {
278 std::cerr << "Failed to lock system_state_cookie_store_guard and check system lock state" << std::endl;278 MH_WARNING("Failed to lock system_state_cookie_store_guard and check system lock state");
279 // Prevent system_state_cookie_store.count(state) and the actual call to clearSysState below from279 // Prevent system_state_cookie_store.count(state) and the actual call to clearSysState below from
280 // getting out of sync.280 // getting out of sync.
281 return;281 return;
@@ -287,7 +287,7 @@
287 object->invoke_method_asynchronously_with_callback<com::canonical::powerd::Interface::clearSysState, void>([this, wp, state](const core::dbus::Result<void>& result)287 object->invoke_method_asynchronously_with_callback<com::canonical::powerd::Interface::clearSysState, void>([this, wp, state](const core::dbus::Result<void>& result)
288 {288 {
289 if (result.is_error())289 if (result.is_error())
290 std::cerr << result.error().print() << std::endl;290 MH_ERROR("%s", result.error().print());
291291
292 if (auto sp = wp.lock())292 if (auto sp = wp.lock())
293 {293 {
@@ -297,7 +297,7 @@
297 if (ul.owns_lock())297 if (ul.owns_lock())
298 sp->system_state_cookie_store.erase(state);298 sp->system_state_cookie_store.erase(state);
299 else299 else
300 std::cerr << "Failed to lock system_state_cookie_store_guard and erase system lock state" << std::endl;300 MH_WARNING("Failed to lock system_state_cookie_store_guard and erase system lock state");
301 }301 }
302302
303 sp->signals.released(state);303 sp->signals.released(state);
@@ -369,7 +369,7 @@
369369
370media::power::StateController::Ptr media::power::make_platform_default_state_controller(core::ubuntu::media::helper::ExternalServices& external_services)370media::power::StateController::Ptr media::power::make_platform_default_state_controller(core::ubuntu::media::helper::ExternalServices& external_services)
371{371{
372 return std::make_shared<impl::StateController>(external_services);372 return std::make_shared<::impl::StateController>(external_services);
373}373}
374374
375// operator<< pretty prints the given display state to the given output stream.375// operator<< pretty prints the given display state to the given output stream.
376376
=== modified file 'src/core/media/server/server.cpp'
--- src/core/media/server/server.cpp 2015-04-10 16:13:55 +0000
+++ src/core/media/server/server.cpp 2016-04-07 00:39:05 +0000
@@ -21,6 +21,7 @@
21#include <core/media/track_list.h>21#include <core/media/track_list.h>
2222
23#include "core/media/hashed_keyed_player_store.h"23#include "core/media/hashed_keyed_player_store.h"
24#include "core/media/logger/logger.h"
24#include "core/media/service_implementation.h"25#include "core/media/service_implementation.h"
2526
26#include <core/posix/signal.h>27#include <core/posix/signal.h>
@@ -36,6 +37,37 @@
3637
37namespace38namespace
38{39{
40void logger_init()
41{
42 const char *level = ::getenv("MH_LOG_LEVEL");
43 // Default level is kInfo
44 media::Logger::Severity severity{media::Logger::Severity::kInfo};
45 if (level)
46 {
47 if (strcmp(level, "trace") == 0)
48 severity = media::Logger::Severity::kTrace;
49 else if (strcmp(level, "debug") == 0)
50 severity = media::Logger::Severity::kDebug;
51 else if (strcmp(level, "info") == 0)
52 severity = media::Logger::Severity::kInfo;
53 else if (strcmp(level, "warning") == 0)
54 severity = media::Logger::Severity::kWarning;
55 else if (strcmp(level, "error") == 0)
56 severity = media::Logger::Severity::kError;
57 else if (strcmp(level, "fatal") == 0)
58 severity = media::Logger::Severity::kFatal;
59 else
60 std::cerr << "Invalid log level \"" << level
61 << "\", setting to info. Valid options: [trace, debug, info, warning, error, fatal]. "
62 << std::endl;
63 }
64 else
65 std::cout << "Using default log level: info" << std::endl;
66
67 media::Log().Init(severity);
68 cout << "Log level: " << severity << std::endl;
69}
70
39// All platform-specific initialization routines go here.71// All platform-specific initialization routines go here.
40void platform_init()72void platform_init()
41{73{
@@ -66,6 +98,8 @@
66 trap->stop();98 trap->stop();
67 });99 });
68100
101 logger_init();
102
69 // Init platform-specific functionality.103 // Init platform-specific functionality.
70 platform_init();104 platform_init();
71105
72106
=== modified file 'src/core/media/service.cpp'
--- src/core/media/service.cpp 2014-04-09 14:05:55 +0000
+++ src/core/media/service.cpp 2016-04-07 00:39:05 +0000
@@ -18,13 +18,15 @@
1818
19#include <core/media/service.h>19#include <core/media/service.h>
2020
21#include "core/media/logger/logger.h"
22
21#include "service_stub.h"23#include "service_stub.h"
2224
23namespace media = core::ubuntu::media;25namespace media = core::ubuntu::media;
2426
25const std::shared_ptr<media::Service> media::Service::Client::instance()27const std::shared_ptr<media::Service> media::Service::Client::instance()
26{28{
27 std::cout << "Creating a new static Service instance" << std::endl;29 MH_TRACE("");
28 static std::shared_ptr<media::Service> instance{new media::ServiceStub()};30 static std::shared_ptr<media::Service> instance{new media::ServiceStub()};
29 return instance;31 return instance;
30}32}
3133
=== modified file 'src/core/media/service_implementation.cpp'
--- src/core/media/service_implementation.cpp 2016-03-02 18:32:46 +0000
+++ src/core/media/service_implementation.cpp 2016-04-07 00:39:05 +0000
@@ -33,6 +33,9 @@
33#include "recorder_observer.h"33#include "recorder_observer.h"
34#include "telephony/call_monitor.h"34#include "telephony/call_monitor.h"
3535
36#include "util/timeout.h"
37#include "core/media/logger/logger.h"
38
36#include <boost/asio.hpp>39#include <boost/asio.hpp>
3740
38#include <string>41#include <string>
@@ -45,8 +48,6 @@
4548
46#include <pulse/pulseaudio.h>49#include <pulse/pulseaudio.h>
4750
48#include "util/timeout.h"
49
50namespace media = core::ubuntu::media;51namespace media = core::ubuntu::media;
5152
52using namespace std;53using namespace std;
@@ -126,16 +127,16 @@
126 switch (state)127 switch (state)
127 {128 {
128 case audio::OutputState::Earpiece:129 case audio::OutputState::Earpiece:
129 std::cout << "AudioOutputObserver reports that output is now Headphones/Headset." << std::endl;130 MH_INFO("AudioOutputObserver reports that output is now Headphones/Headset.");
130 break;131 break;
131 case audio::OutputState::Speaker:132 case audio::OutputState::Speaker:
132 std::cout << "AudioOutputObserver reports that output is now Speaker." << std::endl;133 MH_INFO("AudioOutputObserver reports that output is now Speaker.");
133 // Whatever player session is currently playing, make sure it is NOT resumed after134 // Whatever player session is currently playing, make sure it is NOT resumed after
134 // a phonecall is hung up135 // a phonecall is hung up
135 pause_all_multimedia_sessions(resume_play_after_phonecall);136 pause_all_multimedia_sessions(resume_play_after_phonecall);
136 break;137 break;
137 case audio::OutputState::External:138 case audio::OutputState::External:
138 std::cout << "AudioOutputObserver reports that output is now External." << std::endl;139 MH_INFO("AudioOutputObserver reports that output is now External.");
139 break;140 break;
140 }141 }
141 d->audio_output_state = state;142 d->audio_output_state = state;
@@ -146,13 +147,13 @@
146 const bool resume_play_after_phonecall = true;147 const bool resume_play_after_phonecall = true;
147 switch (state) {148 switch (state) {
148 case media::telephony::CallMonitor::State::OffHook:149 case media::telephony::CallMonitor::State::OffHook:
149 std::cout << "Got call started signal, pausing all multimedia sessions" << std::endl;150 MH_INFO("Got call started signal, pausing all multimedia sessions");
150 // Whatever player session is currently playing, make sure it gets resumed after151 // Whatever player session is currently playing, make sure it gets resumed after
151 // a phonecall is hung up152 // a phonecall is hung up
152 pause_all_multimedia_sessions(resume_play_after_phonecall);153 pause_all_multimedia_sessions(resume_play_after_phonecall);
153 break;154 break;
154 case media::telephony::CallMonitor::State::OnHook:155 case media::telephony::CallMonitor::State::OnHook:
155 std::cout << "Got call ended signal, resuming paused multimedia sessions" << std::endl;156 MH_INFO("Got call ended signal, resuming paused multimedia sessions");
156 resume_paused_multimedia_sessions(false);157 resume_paused_multimedia_sessions(false);
157 break;158 break;
158 }159 }
@@ -217,10 +218,10 @@
217 d->configuration.player_store->remove_player_for_key(key);218 d->configuration.player_store->remove_player_for_key(key);
218 }219 }
219 catch (const std::out_of_range &e) {220 catch (const std::out_of_range &e) {
220 std::cerr << "Failed to look up Player instance for key " << key221 MH_WARNING("Failed to look up Player instance for key %d"
221 << ", no valid Player instance for that key value. Removal of Player from Player store"222 ", no valid Player instance for that key value. Removal of Player from Player store"
222 << " might not have completed. This most likely means that media-hub-server has"223 " might not have completed. This most likely means that media-hub-server has"
223 << " crashed and restarted." << std::endl;224 " crashed and restarted.", key);
224 return;225 return;
225 }226 }
226 });227 });
@@ -264,11 +265,11 @@
264265
265void media::ServiceImplementation::pause_other_sessions(media::Player::PlayerKey key)266void media::ServiceImplementation::pause_other_sessions(media::Player::PlayerKey key)
266{267{
267 std::cout << __PRETTY_FUNCTION__ << std::endl;268 MH_TRACE("");
268269
269 if (not d->configuration.player_store->has_player_for_key(key))270 if (not d->configuration.player_store->has_player_for_key(key))
270 {271 {
271 cerr << "Could not find Player by key: " << key << endl;272 MH_WARNING("Could not find Player by key: %d", key);
272 return;273 return;
273 }274 }
274275
@@ -291,7 +292,7 @@
291 current_player->audio_stream_role() == media::Player::multimedia &&292 current_player->audio_stream_role() == media::Player::multimedia &&
292 other_player->audio_stream_role() == media::Player::multimedia)293 other_player->audio_stream_role() == media::Player::multimedia)
293 {294 {
294 cout << "Pausing Player with key: " << other_key << endl;295 MH_INFO("Pausing Player with key: %d", other_key);
295 other_player->pause();296 other_player->pause();
296 }297 }
297 });298 });
@@ -306,8 +307,8 @@
306 {307 {
307 auto paused_player_pair = std::make_pair(key, resume_play_after_phonecall);308 auto paused_player_pair = std::make_pair(key, resume_play_after_phonecall);
308 d->paused_sessions.push_back(paused_player_pair);309 d->paused_sessions.push_back(paused_player_pair);
309 std::cout << "Pausing Player with key: " << key << ", resuming after phone call? "310 MH_INFO("Pausing Player with key: %d, resuming after phone call? %s", key,
310 << (resume_play_after_phonecall ? "yes" : "no") << std::endl;311 (resume_play_after_phonecall ? "yes" : "no"));
311 player->pause();312 player->pause();
312 }313 }
313 });314 });
@@ -324,17 +325,17 @@
324 player = d->configuration.player_store->player_for_key(key);325 player = d->configuration.player_store->player_for_key(key);
325 }326 }
326 catch (const std::out_of_range &e) {327 catch (const std::out_of_range &e) {
327 std::cerr << "Failed to look up Player instance for key " << key328 MH_WARNING("Failed to look up Player instance for key %d"
328 << ", no valid Player instance for that key value and cannot automatically resume"329 ", no valid Player instance for that key value and cannot automatically resume"
329 << " paused players. This most likely means that media-hub-server has crashed and"330 " paused players. This most likely means that media-hub-server has crashed and"
330 << " restarted." << std::endl;331 " restarted.", key);
331 return;332 return;
332 }333 }
333 // Only resume video playback if explicitly desired334 // Only resume video playback if explicitly desired
334 if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)335 if ((resume_video_sessions || player->is_audio_source()) && resume_play_after_phonecall)
335 player->play();336 player->play();
336 else337 else
337 std::cout << "Not auto-resuming video player session or other type of player session." << std::endl;338 MH_INFO("Not auto-resuming video player session or other type of player session.");
338 });339 });
339340
340 d->paused_sessions.clear();341 d->paused_sessions.clear();
@@ -350,16 +351,16 @@
350 player = d->configuration.player_store->player_for_key(d->resume_key);351 player = d->configuration.player_store->player_for_key(d->resume_key);
351 }352 }
352 catch (const std::out_of_range &e) {353 catch (const std::out_of_range &e) {
353 std::cerr << "Failed to look up Player instance for key " << d->resume_key354 MH_WARNING("Failed to look up Player instance for key %d"
354 << ", no valid Player instance for that key value and cannot automatically resume"355 ", no valid Player instance for that key value and cannot automatically resume"
355 << " paused Player. This most likely means that media-hub-server has crashed and"356 " paused Player. This most likely means that media-hub-server has crashed and"
356 << " restarted." << std::endl;357 " restarted.", d->resume_key);
357 return;358 return;
358 }359 }
359360
360 if (player->playback_status() == Player::paused)361 if (player->playback_status() == Player::paused)
361 {362 {
362 cout << "Resuming playback of Player with key: " << d->resume_key << endl;363 MH_INFO("Resuming playback of Player with key: %d", d->resume_key);
363 player->play();364 player->play();
364 d->resume_key = std::numeric_limits<std::uint32_t>::max();365 d->resume_key = std::numeric_limits<std::uint32_t>::max();
365 }366 }
366367
=== modified file 'src/core/media/service_skeleton.cpp'
--- src/core/media/service_skeleton.cpp 2016-03-02 18:32:46 +0000
+++ src/core/media/service_skeleton.cpp 2016-04-07 00:39:05 +0000
@@ -29,6 +29,8 @@
29#include "the_session_bus.h"29#include "the_session_bus.h"
30#include "xesam.h"30#include "xesam.h"
3131
32#include "core/media/logger/logger.h"
33
32#include <core/dbus/message.h>34#include <core/dbus/message.h>
33#include <core/dbus/object.h>35#include <core/dbus/object.h>
34#include <core/dbus/types/object_path.h>36#include <core/dbus/types/object_path.h>
@@ -134,9 +136,8 @@
134 impl->access_service()->add_object_for_path(op)136 impl->access_service()->add_object_for_path(op)
135 };137 };
136138
137 cout << "Session created by request of: " << msg->sender()139 MH_DEBUG("Session created by request of: %s, key: %d, uuid: %d, path: %s",
138 << ", key: " << key << ", uuid: " << uuid140 msg->sender(), key, uuid, op);
139 << ", path:" << op << std::endl;
140141
141 try142 try
142 {143 {
@@ -147,7 +148,7 @@
147 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(),148 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(),
148 [this, key, msg](const media::apparmor::ubuntu::Context& context)149 [this, key, msg](const media::apparmor::ubuntu::Context& context)
149 {150 {
150 fprintf(stderr, "%s():%d -- app_name='%s', attached\n", __func__, __LINE__, context.str().c_str());151 MH_DEBUG(" -- app_name='%s', attached", context.str());
151 player_owner_map.emplace(std::make_pair(key, std::make_tuple(context.str(), true, msg->sender())));152 player_owner_map.emplace(std::make_pair(key, std::make_tuple(context.str(), true, msg->sender())));
152 });153 });
153154
@@ -231,7 +232,8 @@
231 [this, msg, key, op](const media::apparmor::ubuntu::Context& context)232 [this, msg, key, op](const media::apparmor::ubuntu::Context& context)
232 {233 {
233 auto info = player_owner_map.at(key);234 auto info = player_owner_map.at(key);
234 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());235 MH_DEBUG(" -- reattach app_name='%s', info='%s', '%s'",
236 context.str(), std::get<0>(info), std::get<2>(info));
235 if (std::get<0>(info) == context.str()) {237 if (std::get<0>(info) == context.str()) {
236 std::get<1>(info) = true; // Set to Attached238 std::get<1>(info) = true; // Set to Attached
237 std::get<2>(info) = msg->sender(); // Register new owner239 std::get<2>(info) = msg->sender(); // Register new owner
@@ -242,7 +244,7 @@
242 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)244 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)
243 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)245 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)
244 {246 {
245 std::cout << "Setting current_player" << std::endl;247 MH_TRACE("Setting current_player");
246 exported.set_current_player(player);248 exported.set_current_player(player);
247 }249 }
248250
@@ -305,7 +307,8 @@
305 [this, msg, key](const media::apparmor::ubuntu::Context& context)307 [this, msg, key](const media::apparmor::ubuntu::Context& context)
306 {308 {
307 auto info = player_owner_map.at(key);309 auto info = player_owner_map.at(key);
308 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());310 MH_DEBUG(" -- Destroying app_name='%s', info='%s', '%s'",
311 context.str(), std::get<0>(info), std::get<2>(info));
309 if (std::get<0>(info) == context.str()) {312 if (std::get<0>(info) == context.str()) {
310 player_owner_map.erase(key);313 player_owner_map.erase(key);
311314
@@ -454,7 +457,7 @@
454 core::dbus::Message::Ptr reply;457 core::dbus::Message::Ptr reply;
455 if (not configuration.player_store->has_player_for_key(key))458 if (not configuration.player_store->has_player_for_key(key))
456 {459 {
457 std::cerr << __PRETTY_FUNCTION__ << " player key not found - " << key << std::endl;460 MH_WARNING("Player key not found: %d", key);
458 reply = dbus::Message::make_error(461 reply = dbus::Message::make_error(
459 msg,462 msg,
460 mpris::Service::Errors::PlayerKeyNotFound::name(),463 mpris::Service::Errors::PlayerKeyNotFound::name(),
@@ -467,10 +470,9 @@
467 reply = dbus::Message::make_method_return(msg);470 reply = dbus::Message::make_method_return(msg);
468 }471 }
469 catch (const std::out_of_range &e) {472 catch (const std::out_of_range &e) {
470 std::cerr << "Failed to look up Player instance for key " << key473 MH_WARNING("Failed to look up Player instance for key %d\
471 << ", no valid Player instance for that key value and cannot set current player."474 , no valid Player instance for that key value and cannot set current player.\
472 << " This most likely means that media-hub-server has crashed and restarted."475 This most likely means that media-hub-server has crashed and restarted.", key);
473 << std::endl;
474 reply = dbus::Message::make_error(476 reply = dbus::Message::make_error(
475 msg,477 msg,
476 mpris::Service::Errors::PlayerKeyNotFound::name(),478 mpris::Service::Errors::PlayerKeyNotFound::name(),
@@ -491,10 +493,9 @@
491 reply = dbus::Message::make_method_return(msg);493 reply = dbus::Message::make_method_return(msg);
492 }494 }
493 catch (const std::out_of_range &e) {495 catch (const std::out_of_range &e) {
494 std::cerr << "Failed to look up Player instance for key " << key496 MH_WARNING("Failed to look up Player instance for key %d\
495 << ", no valid Player instance for that key value and cannot pause other Players."497 , no valid Player instance for that key value and cannot set current player.\
496 << " This most likely means that media-hub-server has crashed and restarted."498 This most likely means that media-hub-server has crashed and restarted.", key);
497 << std::endl;
498 reply = dbus::Message::make_error(499 reply = dbus::Message::make_error(
499 msg,500 msg,
500 mpris::Service::Errors::PlayerKeyNotFound::name(),501 mpris::Service::Errors::PlayerKeyNotFound::name(),
@@ -529,7 +530,7 @@
529 // TODO(tvoss): These three elements really should be configurable.530 // TODO(tvoss): These three elements really should be configurable.
530 defaults.identity = "core::media::Hub";531 defaults.identity = "core::media::Hub";
531 defaults.desktop_entry = "mediaplayer-app";532 defaults.desktop_entry = "mediaplayer-app";
532 defaults.supported_mime_types = {"audio/mpeg3"};533 defaults.supported_mime_types = {"audio/mpeg3", "video/mpeg4"};
533534
534 return defaults;535 return defaults;
535 }536 }
@@ -668,7 +669,7 @@
668669
669 void set_current_player(const std::shared_ptr<media::Player>& cp)670 void set_current_player(const std::shared_ptr<media::Player>& cp)
670 {671 {
671 std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;672 MH_TRACE("");
672 // We will not keep the object alive.673 // We will not keep the object alive.
673 current_player = cp;674 current_player = cp;
674675
@@ -784,7 +785,7 @@
784785
785 void reset_current_player()786 void reset_current_player()
786 {787 {
787 std::cout << __PRETTY_FUNCTION__ << std::endl;788 MH_TRACE("");
788 // And announce that we can no longer be controlled.789 // And announce that we can no longer be controlled.
789 player.properties.can_control->set(false);790 player.properties.can_control->set(false);
790 current_player.reset();791 current_player.reset();
791792
=== modified file 'src/core/media/telephony/CMakeLists.txt'
--- src/core/media/telephony/CMakeLists.txt 2014-10-31 07:49:33 +0000
+++ src/core/media/telephony/CMakeLists.txt 2016-04-07 00:39:05 +0000
@@ -9,6 +9,7 @@
99
10include_directories(10include_directories(
11 ${TP_QT5_INCLUDE_DIRS}11 ${TP_QT5_INCLUDE_DIRS}
12 ${PROJECT_SOURCE_DIR}/src/
12)13)
1314
14add_library(call-monitor STATIC15add_library(call-monitor STATIC
1516
=== modified file 'src/core/media/telephony/call_monitor.cpp'
--- src/core/media/telephony/call_monitor.cpp 2015-01-26 11:01:02 +0000
+++ src/core/media/telephony/call_monitor.cpp 2016-04-07 00:39:05 +0000
@@ -19,6 +19,8 @@
1919
20#include "call_monitor.h"20#include "call_monitor.h"
2121
22#include "core/media/logger/logger.h"
23
22#include "qtbridge.h"24#include "qtbridge.h"
23#include <TelepathyQt/AccountManager>25#include <TelepathyQt/AccountManager>
24#include <TelepathyQt/SimpleCallObserver>26#include <TelepathyQt/SimpleCallObserver>
@@ -95,7 +97,7 @@
9597
96 void accountManagerReady(Tp::PendingOperation* operation) {98 void accountManagerReady(Tp::PendingOperation* operation) {
97 if (operation->isError()) {99 if (operation->isError()) {
98 std::cerr << "TelepathyBridge: Operation failed (accountManagerReady)" << std::endl;100 MH_ERROR("TelepathyBridge: Operation failed (accountManagerReady)");
99 QTimer::singleShot(1000, this, SLOT(accountManagerSetup())); // again101 QTimer::singleShot(1000, this, SLOT(accountManagerSetup())); // again
100 return;102 return;
101 }103 }
@@ -118,13 +120,13 @@
118120
119 void accountReady(Tp::PendingOperation* operation) {121 void accountReady(Tp::PendingOperation* operation) {
120 if (operation->isError()) {122 if (operation->isError()) {
121 std::cerr << "TelepathyAccount: Operation failed (accountReady)" << std::endl;123 MH_ERROR("TelepathyAccount: Operation failed (accountReady)");
122 return;124 return;
123 }125 }
124126
125 Tp::PendingReady* pendingReady = qobject_cast<Tp::PendingReady*>(operation);127 Tp::PendingReady* pendingReady = qobject_cast<Tp::PendingReady*>(operation);
126 if (pendingReady == 0) {128 if (pendingReady == 0) {
127 std::cerr << "Rejecting account because could not understand ready status" << std::endl;129 MH_ERROR("Rejecting account because could not understand ready status");
128 return;130 return;
129 }131 }
130132
@@ -176,16 +178,16 @@
176 {178 {
177 qt::core::world::enter_with_task([this]()179 qt::core::world::enter_with_task([this]()
178 {180 {
179 std::cout << "CallMonitor: Creating TelepathyBridge" << std::endl;181 MH_DEBUG("CallMonitor: Creating TelepathyBridge");
180 mBridge = new TelepathyBridge();182 mBridge = new TelepathyBridge();
181 cv.notify_all();183 cv.notify_all();
182 });184 });
183 });185 });
184 }));186 }));
185 } catch(const std::system_error& error) {187 } catch(const std::system_error& error) {
186 std::cerr << "exception(std::system_error) in CallMonitor thread start" << error.what() << std::endl;188 MH_ERROR("exception(std::system_error) in CallMonitor thread start %s", error.what());
187 } catch(...) {189 } catch(...) {
188 std::cerr << "exception(...) in CallMonitor thread start" << std::endl;190 MH_ERROR("exception(...) in CallMonitor thread start");
189 }191 }
190192
191 // Wait until telepathy bridge is set, so we can hook up the change signals193 // Wait until telepathy bridge is set, so we can hook up the change signals
@@ -234,7 +236,7 @@
234236
235media::telephony::CallMonitor::Ptr media::telephony::make_platform_default_call_monitor()237media::telephony::CallMonitor::Ptr media::telephony::make_platform_default_call_monitor()
236{238{
237 return std::make_shared<impl::CallMonitor>();239 return std::make_shared<::impl::CallMonitor>();
238}240}
239241
240#include "call_monitor.moc"242#include "call_monitor.moc"
241243
=== modified file 'src/core/media/telephony/qtbridge.cpp'
--- src/core/media/telephony/qtbridge.cpp 2014-10-31 07:49:33 +0000
+++ src/core/media/telephony/qtbridge.cpp 2016-04-07 00:39:05 +0000
@@ -26,8 +26,6 @@
26#include<QThread>26#include<QThread>
27#include<QDebug>27#include<QDebug>
2828
29#include <iostream>
30
31namespace29namespace
32{30{
33QCoreApplication* app = nullptr;31QCoreApplication* app = nullptr;
3432
=== modified file 'src/core/media/track_list_implementation.cpp'
--- src/core/media/track_list_implementation.cpp 2016-02-22 18:58:52 +0000
+++ src/core/media/track_list_implementation.cpp 2016-04-07 00:39:05 +0000
@@ -18,6 +18,7 @@
1818
19#include <algorithm>19#include <algorithm>
20#include <random>20#include <random>
21#include <sstream>
21#include <stdio.h>22#include <stdio.h>
22#include <stdlib.h>23#include <stdlib.h>
23#include <tuple>24#include <tuple>
@@ -29,6 +30,8 @@
2930
30#include "engine.h"31#include "engine.h"
3132
33#include "core/media/logger/logger.h"
34
32namespace dbus = core::dbus;35namespace dbus = core::dbus;
33namespace media = core::ubuntu::media;36namespace media = core::ubuntu::media;
3437
@@ -125,14 +128,14 @@
125 const media::Track::Id& position,128 const media::Track::Id& position,
126 bool make_current)129 bool make_current)
127{130{
128 std::cout << __PRETTY_FUNCTION__ << std::endl;131 MH_TRACE("");
129132
130 std::stringstream ss;133 std::stringstream ss;
131 ss << d->object->path().as_string() << "/" << d->track_counter++;134 ss << d->object->path().as_string() << "/" << d->track_counter++;
132 Track::Id id{ss.str()};135 Track::Id id{ss.str()};
133136
134 std::cout << "Adding Track::Id: " << id << std::endl;137 MH_DEBUG("Adding Track::Id: %s", id);
135 std::cout << "\tURI: " << uri << std::endl;138 MH_DEBUG("\tURI: %s", uri);
136139
137 const auto current = get_current_track();140 const auto current = get_current_track();
138141
@@ -159,7 +162,7 @@
159 set_current_track(current);162 set_current_track(current);
160 }163 }
161164
162 std::cout << "Signaling that we just added track id: " << id << std::endl;165 MH_DEBUG("Signaling that we just added track id: %s", id);
163 // Signal to the client that a track was added to the TrackList166 // Signal to the client that a track was added to the TrackList
164 on_track_added()(id);167 on_track_added()(id);
165168
@@ -172,7 +175,7 @@
172175
173void media::TrackListImplementation::add_tracks_with_uri_at(const ContainerURI& uris, const Track::Id& position)176void media::TrackListImplementation::add_tracks_with_uri_at(const ContainerURI& uris, const Track::Id& position)
174{177{
175 std::cout << __PRETTY_FUNCTION__ << std::endl;178 MH_TRACE("");
176179
177 const auto current = get_current_track();180 const auto current = get_current_track();
178181
@@ -184,8 +187,8 @@
184 std::stringstream ss;187 std::stringstream ss;
185 ss << d->object->path().as_string() << "/" << d->track_counter++;188 ss << d->object->path().as_string() << "/" << d->track_counter++;
186 Track::Id id{ss.str()};189 Track::Id id{ss.str()};
187 std::cout << "Adding Track::Id: " << id << std::endl;190 MH_DEBUG("Adding Track::Id: %s", id);
188 std::cout << "\tURI: " << uri << std::endl;191 MH_DEBUG("\tURI: %s", uri);
189192
190 tmp.push_back(id);193 tmp.push_back(id);
191194
@@ -217,7 +220,7 @@
217220
218 set_current_track(current);221 set_current_track(current);
219222
220 std::cout << "Signaling that we just added " << tmp.size() << " tracks to the TrackList" << std::endl;223 MH_DEBUG("Signaling that we just added %d tracks to the TrackList", tmp.size());
221 on_tracks_added()(tmp);224 on_tracks_added()(tmp);
222225
223 if (!current_id.empty())226 if (!current_id.empty())
@@ -227,30 +230,30 @@
227bool media::TrackListImplementation::move_track(const media::Track::Id& id,230bool media::TrackListImplementation::move_track(const media::Track::Id& id,
228 const media::Track::Id& to)231 const media::Track::Id& to)
229{232{
230 std::cout << __PRETTY_FUNCTION__ << std::endl;233 MH_TRACE("");
231234
232 std::cout << "-----------------------------------------------------" << std::endl;235 MH_DEBUG("-----------------------------------------------------");
233 if (id.empty() or to.empty())236 if (id.empty() or to.empty())
234 {237 {
235 std::cerr << "Can't move track since 'id' or 'to' are empty" << std::endl;238 MH_ERROR("Can't move track since 'id' or 'to' are empty");
236 return false;239 return false;
237 }240 }
238241
239 if (id == to)242 if (id == to)
240 {243 {
241 std::cerr << "Can't move track to it's same position" << std::endl;244 MH_ERROR("Can't move track to it's same position");
242 return false;245 return false;
243 }246 }
244247
245 if (tracks().get().size() == 1)248 if (tracks().get().size() == 1)
246 {249 {
247 std::cerr << "Can't move track since TrackList contains only one track" << std::endl;250 MH_ERROR("Can't move track since TrackList contains only one track");
248 return false;251 return false;
249 }252 }
250253
251 bool ret = false;254 bool ret = false;
252 const media::Track::Id current_id = *current_iterator();255 const media::Track::Id current_id = *current_iterator();
253 std::cout << "current_track id: " << current_id << std::endl;256 MH_DEBUG("current_track id: %s", current_id);
254 // Get an iterator that points to the track that is the insertion point257 // Get an iterator that points to the track that is the insertion point
255 auto insert_point_it = std::find(tracks().get().begin(), tracks().get().end(), to);258 auto insert_point_it = std::find(tracks().get().begin(), tracks().get().end(), to);
256 if (insert_point_it != tracks().get().end())259 if (insert_point_it != tracks().get().end())
@@ -260,7 +263,6 @@
260 {263 {
261 // Get an iterator that points to the track to move within the TrackList264 // Get an iterator that points to the track to move within the TrackList
262 auto to_move_it = std::find(tracks().get().begin(), tracks().get().end(), id);265 auto to_move_it = std::find(tracks().get().begin(), tracks().get().end(), id);
263 std::cout << "Erasing old track position: " << *to_move_it << std::endl;
264 if (to_move_it != tracks().get().end())266 if (to_move_it != tracks().get().end())
265 {267 {
266 container.erase(to_move_it);268 container.erase(to_move_it);
@@ -282,11 +284,11 @@
282 {284 {
283 throw media::TrackList::Errors::FailedToMoveTrack();285 throw media::TrackList::Errors::FailedToMoveTrack();
284 }286 }
285 std::cout << "*** Updated current_iterator, id: " << *current_iterator() << std::endl;287 MH_DEBUG("*** Updated current_iterator, id: %s", *current_iterator());
286 }288 }
287 else289 else
288 {290 {
289 std::cerr << "Can't update current_iterator - failed to find track after move" << std::endl;291 MH_ERROR("Can't update current_iterator - failed to find track after move");
290 throw media::TrackList::Errors::FailedToMoveTrack();292 throw media::TrackList::Errors::FailedToMoveTrack();
291 }293 }
292294
@@ -295,10 +297,10 @@
295297
296 if (result)298 if (result)
297 {299 {
298 std::cout << "TrackList after move" << std::endl;300 MH_DEBUG("TrackList after move");
299 for(auto track : tracks().get())301 for(const auto track : tracks().get())
300 {302 {
301 std::cout << track << std::endl;303 MH_DEBUG("%s", track);
302 }304 }
303 const media::TrackList::TrackIdTuple ids = std::make_tuple(id, to);305 const media::TrackList::TrackIdTuple ids = std::make_tuple(id, to);
304 // Signal to the client that track 'id' was moved within the TrackList306 // Signal to the client that track 'id' was moved within the TrackList
@@ -312,7 +314,7 @@
312 ("Failed to find source track " + id);314 ("Failed to find source track " + id);
313 }315 }
314316
315 std::cout << "-----------------------------------------------------" << std::endl;317 MH_DEBUG("-----------------------------------------------------");
316318
317 return ret;319 return ret;
318}320}
@@ -345,7 +347,7 @@
345347
346void media::TrackListImplementation::go_to(const media::Track::Id& track)348void media::TrackListImplementation::go_to(const media::Track::Id& track)
347{349{
348 std::cout << __PRETTY_FUNCTION__ << std::endl;350 MH_TRACE("");
349 // Signal the Player instance to go to a specific track for playback351 // Signal the Player instance to go to a specific track for playback
350 on_go_to_track()(track);352 on_go_to_track()(track);
351 on_track_changed()(track);353 on_track_changed()(track);
@@ -373,7 +375,7 @@
373375
374void media::TrackListImplementation::reset()376void media::TrackListImplementation::reset()
375{377{
376 std::cout << __PRETTY_FUNCTION__ << std::endl;378 MH_TRACE("");
377379
378 // Make sure playback stops380 // Make sure playback stops
379 on_end_of_tracklist()();381 on_end_of_tracklist()();
380382
=== modified file 'src/core/media/track_list_skeleton.cpp'
--- src/core/media/track_list_skeleton.cpp 2016-02-22 16:16:52 +0000
+++ src/core/media/track_list_skeleton.cpp 2016-04-07 00:39:05 +0000
@@ -29,7 +29,9 @@
2929
30#include "mpris/player.h"30#include "mpris/player.h"
31#include "mpris/track_list.h"31#include "mpris/track_list.h"
32
32#include "util/uri_check.h"33#include "util/uri_check.h"
34#include "core/media/logger/logger.h"
3335
34#include <core/dbus/object.h>36#include <core/dbus/object.h>
35#include <core/dbus/property.h>37#include <core/dbus/property.h>
@@ -40,7 +42,6 @@
4042
41#include <iostream>43#include <iostream>
42#include <limits>44#include <limits>
43#include <sstream>
44#include <cstdint>45#include <cstdint>
4546
46namespace dbus = core::dbus;47namespace dbus = core::dbus;
@@ -104,7 +105,7 @@
104105
105 void handle_add_track_with_uri_at(const core::dbus::Message::Ptr& msg)106 void handle_add_track_with_uri_at(const core::dbus::Message::Ptr& msg)
106 {107 {
107 std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;108 MH_TRACE("");
108 request_context_resolver->resolve_context_for_dbus_name_async109 request_context_resolver->resolve_context_for_dbus_name_async
109 (msg->sender(), [this, msg](const media::apparmor::ubuntu::Context& context)110 (msg->sender(), [this, msg](const media::apparmor::ubuntu::Context& context)
110 {111 {
@@ -124,7 +125,7 @@
124 {125 {
125 const std::string err_str = {"Warning: Not adding track " + uri +126 const std::string err_str = {"Warning: Not adding track " + uri +
126 " to TrackList because it can't be found."};127 " to TrackList because it can't be found."};
127 std::cerr << err_str << std::endl;128 MH_WARNING("%s", err_str.c_str());
128 reply = dbus::Message::make_error(129 reply = dbus::Message::make_error(
129 msg,130 msg,
130 mpris::Player::Error::UriNotFound::name,131 mpris::Player::Error::UriNotFound::name,
@@ -141,7 +142,7 @@
141 {142 {
142 const std::string err_str = {"Warning: Not adding track " + uri +143 const std::string err_str = {"Warning: Not adding track " + uri +
143 " to TrackList because of inadequate client apparmor permissions."};144 " to TrackList because of inadequate client apparmor permissions."};
144 std::cerr << err_str << std::endl;145 MH_WARNING("%s", err_str.c_str());
145 reply = dbus::Message::make_error(146 reply = dbus::Message::make_error(
146 msg,147 msg,
147 mpris::TrackList::Error::InsufficientPermissionsToAddTrack::name,148 mpris::TrackList::Error::InsufficientPermissionsToAddTrack::name,
@@ -155,7 +156,7 @@
155156
156 void handle_add_tracks_with_uri_at(const core::dbus::Message::Ptr& msg)157 void handle_add_tracks_with_uri_at(const core::dbus::Message::Ptr& msg)
157 {158 {
158 std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;159 MH_TRACE("");
159 request_context_resolver->resolve_context_for_dbus_name_async160 request_context_resolver->resolve_context_for_dbus_name_async
160 (msg->sender(), [this, msg](const media::apparmor::ubuntu::Context& context)161 (msg->sender(), [this, msg](const media::apparmor::ubuntu::Context& context)
161 {162 {
@@ -176,7 +177,7 @@
176 {177 {
177 uri_err_str = {"Warning: Not adding track " + uri +178 uri_err_str = {"Warning: Not adding track " + uri +
178 " to TrackList because it can't be found."};179 " to TrackList because it can't be found."};
179 std::cerr << uri_err_str << std::endl;180 MH_WARNING("%s", uri_err_str.c_str());
180 reply = dbus::Message::make_error(181 reply = dbus::Message::make_error(
181 msg,182 msg,
182 mpris::Player::Error::UriNotFound::name,183 mpris::Player::Error::UriNotFound::name,
@@ -201,7 +202,7 @@
201 }202 }
202 else203 else
203 {204 {
204 std::cerr << err_str << std::endl;205 MH_WARNING("%s", err_str.c_str());
205 reply = dbus::Message::make_error(206 reply = dbus::Message::make_error(
206 msg,207 msg,
207 mpris::TrackList::Error::InsufficientPermissionsToAddTrack::name,208 mpris::TrackList::Error::InsufficientPermissionsToAddTrack::name,
@@ -225,7 +226,7 @@
225 {226 {
226 const std::string err_str = {"Error: Not moving track " + id +227 const std::string err_str = {"Error: Not moving track " + id +
227 " to destination " + to};228 " to destination " + to};
228 std::cerr << err_str << std::endl;229 MH_WARNING("%s", err_str.c_str());
229 reply = dbus::Message::make_error(230 reply = dbus::Message::make_error(
230 msg,231 msg,
231 mpris::TrackList::Error::FailedToMoveTrack::name,232 mpris::TrackList::Error::FailedToMoveTrack::name,
@@ -262,9 +263,9 @@
262263
263 auto id_it = find(impl->tracks().get().begin(), impl->tracks().get().end(), track);264 auto id_it = find(impl->tracks().get().begin(), impl->tracks().get().end(), track);
264 if (id_it == impl->tracks().get().end()) {265 if (id_it == impl->tracks().get().end()) {
265 ostringstream err_str;266 stringstream err_str;
266 err_str << "Track " << track << " not found in track list";267 err_str << "Track " << track << " not found in track list";
267 cout << __PRETTY_FUNCTION__ << " WARNING " << err_str.str() << endl;268 MH_WARNING("%s", err_str.str());
268 auto reply = dbus::Message::make_error(269 auto reply = dbus::Message::make_error(
269 msg,270 msg,
270 mpris::TrackList::Error::TrackNotFound::name,271 mpris::TrackList::Error::TrackNotFound::name,
@@ -278,7 +279,7 @@
278279
279 if (id_it == impl->current_iterator())280 if (id_it == impl->current_iterator())
280 {281 {
281 cout << "Removing current track" << endl;282 MH_DEBUG("Removing current track");
282 deleting_current = true;283 deleting_current = true;
283284
284 if (current_track != empty_iterator)285 if (current_track != empty_iterator)
@@ -537,10 +538,10 @@
537538
538media::Track::Id media::TrackListSkeleton::next()539media::Track::Id media::TrackListSkeleton::next()
539{540{
540 std::cout << __PRETTY_FUNCTION__ << std::endl;541 MH_TRACE("");
541 if (tracks().get().empty()) {542 if (tracks().get().empty()) {
542 // TODO Change ServiceSkeleton to return with error from DBus call543 // TODO Change ServiceSkeleton to return with error from DBus call
543 std::cerr << "ERROR: no tracks, cannot go to next" << std::endl;544 MH_ERROR("No tracks, cannot go to next");
544 return media::Track::Id{};545 return media::Track::Id{};
545 }546 }
546547
@@ -549,13 +550,13 @@
549 // End of the track reached so loop around to the beginning of the track550 // End of the track reached so loop around to the beginning of the track
550 if (d->loop_status == media::Player::LoopStatus::track)551 if (d->loop_status == media::Player::LoopStatus::track)
551 {552 {
552 std::cout << "Looping on the current track since LoopStatus is set to track" << std::endl;553 MH_INFO("Looping on the current track since LoopStatus is set to track");
553 go_to_track = true;554 go_to_track = true;
554 }555 }
555 // End of the tracklist reached so loop around to the beginning of the tracklist556 // End of the tracklist reached so loop around to the beginning of the tracklist
556 else if (d->loop_status == media::Player::LoopStatus::playlist && not has_next())557 else if (d->loop_status == media::Player::LoopStatus::playlist && not has_next())
557 {558 {
558 std::cout << "Looping on the tracklist since LoopStatus is set to playlist" << std::endl;559 MH_INFO("Looping on the tracklist since LoopStatus is set to playlist");
559560
560 if (shuffle())561 if (shuffle())
561 {562 {
@@ -574,7 +575,7 @@
574 {575 {
575 auto it = get_current_shuffled();576 auto it = get_current_shuffled();
576 if (++it != shuffled_tracks().end()) {577 if (++it != shuffled_tracks().end()) {
577 cout << "Advancing to next track: " << *it << endl;578 MH_INFO("Advancing to next track: %s", *it);
578 set_current_track(*it);579 set_current_track(*it);
579 go_to_track = true;580 go_to_track = true;
580 }581 }
@@ -584,7 +585,7 @@
584 const auto it = std::next(current_iterator());585 const auto it = std::next(current_iterator());
585 if (not is_last_track(it))586 if (not is_last_track(it))
586 {587 {
587 cout << "Advancing to next track: " << *it << endl;588 MH_INFO("Advancing to next track: %s", *it);
588 d->current_track = it;589 d->current_track = it;
589 go_to_track = true;590 go_to_track = true;
590 }591 }
@@ -594,7 +595,7 @@
594595
595 if (go_to_track)596 if (go_to_track)
596 {597 {
597 cout << "next track id is " << *(current_iterator()) << endl;598 MH_DEBUG("next track id is %s", *(current_iterator()));
598 on_track_changed()(*(current_iterator()));599 on_track_changed()(*(current_iterator()));
599 const media::Track::Id id = *(current_iterator());600 const media::Track::Id id = *(current_iterator());
600 // Signal the PlayerImplementation to play the next track601 // Signal the PlayerImplementation to play the next track
@@ -603,7 +604,7 @@
603 else604 else
604 {605 {
605 // At the end of the tracklist and not set to loop606 // At the end of the tracklist and not set to loop
606 cout << "End of tracklist reached" << endl;607 MH_INFO("End of tracklist reached");
607 on_end_of_tracklist()();608 on_end_of_tracklist()();
608 }609 }
609610
@@ -612,10 +613,10 @@
612613
613media::Track::Id media::TrackListSkeleton::previous()614media::Track::Id media::TrackListSkeleton::previous()
614{615{
615 std::cout << __PRETTY_FUNCTION__ << std::endl;616 MH_TRACE("");
616 if (tracks().get().empty()) {617 if (tracks().get().empty()) {
617 // TODO Change ServiceSkeleton to return with error from DBus call618 // TODO Change ServiceSkeleton to return with error from DBus call
618 std::cerr << "ERROR: no tracks, cannot go to previous" << std::endl;619 MH_ERROR("No tracks, cannot go to previous");
619 return media::Track::Id{};620 return media::Track::Id{};
620 }621 }
621622
@@ -627,19 +628,19 @@
627 // repeat it from the beginning628 // repeat it from the beginning
628 if (d->current_position > max_position)629 if (d->current_position > max_position)
629 {630 {
630 std::cout << "Repeating current track..." << std::endl;631 MH_INFO("Repeating current track...");
631 go_to_track = true;632 go_to_track = true;
632 }633 }
633 // Loop on the current track forever634 // Loop on the current track forever
634 else if (d->loop_status == media::Player::LoopStatus::track)635 else if (d->loop_status == media::Player::LoopStatus::track)
635 {636 {
636 std::cout << "Looping on the current track..." << std::endl;637 MH_INFO("Looping on the current track...");
637 go_to_track = true;638 go_to_track = true;
638 }639 }
639 // Loop over the whole playlist and repeat640 // Loop over the whole playlist and repeat
640 else if (d->loop_status == media::Player::LoopStatus::playlist && not has_previous())641 else if (d->loop_status == media::Player::LoopStatus::playlist && not has_previous())
641 {642 {
642 std::cout << "Looping on the entire TrackList..." << std::endl;643 MH_INFO("Looping on the entire TrackList...");
643644
644 if (shuffle())645 if (shuffle())
645 {646 {
@@ -680,7 +681,7 @@
680 else681 else
681 {682 {
682 // At the beginning of the tracklist and not set to loop683 // At the beginning of the tracklist and not set to loop
683 cout << "Beginning of tracklist reached" << endl;684 MH_INFO("Beginning of tracklist reached");
684 on_end_of_tracklist()();685 on_end_of_tracklist()();
685 }686 }
686687
@@ -698,12 +699,12 @@
698 // a segfault when calling current()699 // a segfault when calling current()
699 if (tracks().get().size() && (d->current_track == d->empty_iterator))700 if (tracks().get().size() && (d->current_track == d->empty_iterator))
700 {701 {
701 std::cout << "Wrapping d->current_track back to begin()" << std::endl;702 MH_DEBUG("Wrapping d->current_track back to begin()");
702 d->current_track = d->skeleton.properties.tracks->get().begin();703 d->current_track = d->skeleton.properties.tracks->get().begin();
703 }704 }
704 else if (tracks().get().empty())705 else if (tracks().get().empty())
705 {706 {
706 std::cerr << "TrackList is empty therefore there is no valid current track" << std::endl;707 MH_ERROR("TrackList is empty therefore there is no valid current track");
707 }708 }
708709
709 return d->current_track;710 return d->current_track;
@@ -711,11 +712,10 @@
711712
712bool media::TrackListSkeleton::update_current_iterator(const TrackList::ConstIterator &it)713bool media::TrackListSkeleton::update_current_iterator(const TrackList::ConstIterator &it)
713{714{
714 std::cout << __PRETTY_FUNCTION__ << std::endl;715 MH_TRACE("");
715 if (it == tracks().get().end())716 if (it == tracks().get().end())
716 return false;717 return false;
717718
718 std::cout << "Updating current_track iterator" << std::endl;
719 d->current_track = it;719 d->current_track = it;
720720
721 return true;721 return true;
@@ -780,8 +780,7 @@
780780
781void media::TrackListSkeleton::on_shuffle_changed(bool shuffle)781void media::TrackListSkeleton::on_shuffle_changed(bool shuffle)
782{782{
783 cout << __PRETTY_FUNCTION__ << endl;783 MH_TRACE("");
784
785 set_shuffle(shuffle);784 set_shuffle(shuffle);
786}785}
787786
@@ -793,7 +792,7 @@
793const core::Signal<media::TrackList::ContainerTrackIdTuple>& media::TrackListSkeleton::on_track_list_replaced() const792const core::Signal<media::TrackList::ContainerTrackIdTuple>& media::TrackListSkeleton::on_track_list_replaced() const
794{793{
795 // Print the TrackList instance794 // Print the TrackList instance
796 std::cout << *this << std::endl;795 MH_DEBUG("%s", *this);
797 return d->signals.on_track_list_replaced;796 return d->signals.on_track_list_replaced;
798}797}
799798
800799
=== modified file 'src/core/media/track_list_stub.cpp'
--- src/core/media/track_list_stub.cpp 2016-02-19 16:14:42 +0000
+++ src/core/media/track_list_stub.cpp 2016-04-07 00:39:05 +0000
@@ -28,6 +28,8 @@
28#include "mpris/player.h"28#include "mpris/player.h"
29#include "mpris/track_list.h"29#include "mpris/track_list.h"
3030
31#include "core/media/logger/logger.h"
32
31#include <core/dbus/property.h>33#include <core/dbus/property.h>
32#include <core/dbus/types/object_path.h>34#include <core/dbus/types/object_path.h>
33#include <core/dbus/types/variant.h>35#include <core/dbus/types/variant.h>
@@ -111,43 +113,43 @@
111 {113 {
112 dbus.on_track_added->connect([this](const Track::Id& id)114 dbus.on_track_added->connect([this](const Track::Id& id)
113 {115 {
114 std::cout << "OnTrackAdded signal arrived via the bus." << std::endl;116 MH_DEBUG("OnTrackAdded signal arrived via the bus.");
115 on_track_added(id);117 on_track_added(id);
116 });118 });
117119
118 dbus.on_tracks_added->connect([this](const media::TrackList::ContainerURI& tracks)120 dbus.on_tracks_added->connect([this](const media::TrackList::ContainerURI& tracks)
119 {121 {
120 std::cout << "OnTracksAdded signal arrived via the bus." << std::endl;122 MH_DEBUG("OnTracksAdded signal arrived via the bus.");
121 on_tracks_added(tracks);123 on_tracks_added(tracks);
122 });124 });
123125
124 dbus.on_track_moved->connect([this](const media::TrackList::TrackIdTuple& ids)126 dbus.on_track_moved->connect([this](const media::TrackList::TrackIdTuple& ids)
125 {127 {
126 std::cout << "OnTrackMoved signal arrived via the bus." << std::endl;128 MH_DEBUG("OnTrackMoved signal arrived via the bus.");
127 on_track_moved(ids);129 on_track_moved(ids);
128 });130 });
129131
130 dbus.on_track_removed->connect([this](const Track::Id& id)132 dbus.on_track_removed->connect([this](const Track::Id& id)
131 {133 {
132 std::cout << "OnTrackRemoved signal arrived via the bus." << std::endl;134 MH_DEBUG("OnTrackRemoved signal arrived via the bus.");
133 on_track_removed(id);135 on_track_removed(id);
134 });136 });
135137
136 dbus.on_track_list_reset->connect([this](void)138 dbus.on_track_list_reset->connect([this](void)
137 {139 {
138 std::cout << "OnTrackListReset signal arrived via the bus." << std::endl;140 MH_DEBUG("OnTrackListReset signal arrived via the bus.");
139 on_track_list_reset();141 on_track_list_reset();
140 });142 });
141143
142 dbus.on_track_list_replaced->connect([this](const media::TrackList::ContainerTrackIdTuple& list)144 dbus.on_track_list_replaced->connect([this](const media::TrackList::ContainerTrackIdTuple& list)
143 {145 {
144 std::cout << "OnTrackListReplaced signal arrived via the bus." << std::endl;146 MH_DEBUG("OnTrackListReplaced signal arrived via the bus.");
145 on_track_list_replaced(list);147 on_track_list_replaced(list);
146 });148 });
147149
148 dbus.on_track_changed->connect([this](const Track::Id& id)150 dbus.on_track_changed->connect([this](const Track::Id& id)
149 {151 {
150 std::cout << "OnTrackChanged signal arrived via the bus." << std::endl;152 MH_DEBUG("OnTrackChanged signal arrived via the bus.");
151 on_track_changed(id);153 on_track_changed(id);
152 });154 });
153 }155 }
154156
=== added file 'src/core/media/util/utils.cpp'
--- src/core/media/util/utils.cpp 1970-01-01 00:00:00 +0000
+++ src/core/media/util/utils.cpp 2016-04-07 00:39:05 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <boost/filesystem.hpp>
19#include <boost/algorithm/string.hpp>
20
21#include <memory>
22#include <fstream>
23#include <sstream>
24
25#include <cstring>
26#include <cstdarg>
27
28#include "utils.h"
29
30namespace media = core::ubuntu::media;
31
32uint64_t media::Utils::GetNowNs() {
33 struct timespec ts;
34 memset(&ts, 0, sizeof(ts));
35 clock_gettime(CLOCK_MONOTONIC, &ts);
36 return ts.tv_sec * 1000000000LL + ts.tv_nsec;
37}
38
39uint64_t media::Utils::GetNowUs() {
40 return GetNowNs() / 1000;
41}
042
=== added file 'src/core/media/util/utils.h'
--- src/core/media/util/utils.h 1970-01-01 00:00:00 +0000
+++ src/core/media/util/utils.h 2016-04-07 00:39:05 +0000
@@ -0,0 +1,69 @@
1/*
2 * Copyright © 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef UTILS_H_
19#define UTILS_H_
20
21#include <boost/format.hpp>
22
23#include <string>
24#include <vector>
25
26#define MCS_STR_VALUE(str) #str
27
28namespace core {
29namespace ubuntu {
30namespace media {
31typedef int64_t TimestampNs;
32typedef int64_t TimestampUs;
33struct Utils
34{
35 // Merely used as a namespace.
36 Utils() = delete;
37
38 // Sprintf - much like what you would expect :)
39 template<typename... Types>
40 static std::string Sprintf(const std::string& fmt_str, Types&&... args);
41 // GetEnv - returns a variable value from the environment
42 static uint64_t GetNowNs();
43 // GetNowUs - get a timestamp in microseconds
44 static uint64_t GetNowUs();
45};
46
47namespace impl {
48// Base case, just return the passed in boost::format instance.
49inline boost::format& Sprintf(boost::format& f)
50{
51 return f;
52}
53// Sprintf recursively walks the parameter pack at compile time.
54template <typename Head, typename... Tail>
55inline boost::format& Sprintf(boost::format& f, Head const& head, Tail&&... tail) {
56 return Sprintf(f % head, std::forward<Tail>(tail)...);
57}
58} // namespace impl
59} // namespace media
60} // namespace ubuntu
61} // namespace core
62
63template <typename... Types>
64inline std::string core::ubuntu::media::Utils::Sprintf(const std::string& format, Types&&... args) {
65 boost::format f(format);
66 return core::ubuntu::media::impl::Sprintf(f, std::forward<Types>(args)...).str();
67}
68
69#endif
070
=== modified file 'src/core/media/video/platform_default_sink.cpp'
--- src/core/media/video/platform_default_sink.cpp 2015-01-29 12:12:43 +0000
+++ src/core/media/video/platform_default_sink.cpp 2016-04-07 00:39:05 +0000
@@ -36,7 +36,7 @@
36 // and returns true or returns false and leaves 'matrix' unchanged in case36 // and returns true or returns false and leaves 'matrix' unchanged in case
37 // of issues.37 // of issues.
38 bool transformation_matrix(float*) const38 bool transformation_matrix(float*) const
39 { 39 {
40 return true;40 return true;
41 }41 }
4242

Subscribers

People subscribed via source and target branches

to all changes: