~jhodapp/media-hub/orientation

« back to all changes in this revision

Viewing changes to src/core/media/player_implementation.cpp

  • Committer: Jim Hodapp
  • Date: 2014-08-13 01:41:00 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: jim.hodapp@canonical.com-20140813014100-d1v0it69wlm5p2pi
Remove some debugging statements and improve the code comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
        auto uscreen_stub_service = dbus::Service::use_service(bus, dbus::traits::Service<core::UScreen>::interface_name());
78
78
        uscreen_session = uscreen_stub_service->object_for_path(dbus::types::ObjectPath("/com/canonical/Unity/Screen"));
79
79
 
 
80
        /*
 
81
         * Wakelock state logic:
 
82
         *
 
83
         * PLAYING->READY: delay 4 seconds and try to clear current wakelock type
 
84
         * PLAYING->PAUSED or PLAYING->STOPPED: delay 4 seconds and try to clear current wakelock type
 
85
         * READY->PAUSED: request a new wakelock (system or display)
 
86
         * PLAYING->PAUSED: delay 4 seconds and try to clear current wakelock type
 
87
         */
80
88
        engine->state().changed().connect(
81
89
                    [parent, this](const Engine::State& state)
82
90
        {
84
92
            {
85
93
            case Engine::State::ready:
86
94
            {
87
 
                cout << "READY state" << endl;
88
95
                parent->playback_status().set(media::Player::ready);
89
96
                if (previous_state == Engine::State::playing)
90
97
                {
91
 
                    cout << "Delaying for 4 seconds before clearing all wakelocks after a PLAYING->READY transition" << endl;
92
98
                    wakelock_timeout.reset(new timeout(4000, true, std::bind(&Private::clear_wakelock,
93
99
                                    this, std::placeholders::_1), current_wakelock_type()));
94
100
                }
96
102
            }
97
103
            case Engine::State::playing:
98
104
            {
99
 
                cout << "PLAYING state" << endl;
100
105
                parent->playback_status().set(media::Player::playing);
101
106
                if (previous_state == Engine::State::stopped || previous_state == Engine::State::paused)
102
107
                {
103
 
                    cout << "Trying to request new wakelock from STOPPED->PLAYING || PAUSED->PLAYING transition" << endl;
104
108
                    request_power_state();
105
109
                }
106
110
                break;
107
111
            }
108
112
            case Engine::State::stopped:
109
113
            {
110
 
                cout << "STOPPED state" << endl;
111
114
                parent->playback_status().set(media::Player::stopped);
112
115
                break;
113
116
            }
114
117
            case Engine::State::paused:
115
118
            {
116
 
                cout << "PAUSED state" << endl;
117
119
                parent->playback_status().set(media::Player::paused);
118
120
                if (previous_state == Engine::State::ready)
119
121
                {
120
 
                    cout << "Trying to request new wakelock from READY->PAUSED transition" << endl;
121
122
                    request_power_state();
122
123
                }
123
124
                else if (previous_state == Engine::State::playing)
124
125
                {
125
 
                    cout << "Delaying for 4 seconds before clearing all wakelocks after a pause" << endl;
126
126
                    wakelock_timeout.reset(new timeout(4000, true, std::bind(&Private::clear_wakelock,
127
127
                                    this, std::placeholders::_1), current_wakelock_type()));
128
128
                }
140
140
 
141
141
    ~Private()
142
142
    {
143
 
        // Make sure that we don't hold on to the wakelocks if media-hub
144
 
        // ever gets restarted
 
143
        // Make sure that we don't hold on to the wakelocks if media-hub-server
 
144
        // ever gets restarted manually or automatically
145
145
        clear_wakelocks();
146
146
    }
147
147
 
148
148
    void request_power_state()
149
149
    {
150
 
        cout << __PRETTY_FUNCTION__ << endl;
151
150
        try
152
151
        {
153
152
            if (parent->is_video_source())
162
161
                }
163
162
 
164
163
                {
 
164
                    // Keep track of how many display wakelocks have been requested
165
165
                    std::lock_guard<std::mutex> lock(wakelock_mutex);
166
166
                    ++display_wakelock_count;
167
167
                }
178
178
                }
179
179
 
180
180
                {
 
181
                    // Keep track of how many system wakelocks have been requested
181
182
                    std::lock_guard<std::mutex> lock(wakelock_mutex);
182
183
                    ++system_wakelock_count;
183
184
                }
245
246
 
246
247
    void clear_wakelocks()
247
248
    {
248
 
        cout << __PRETTY_FUNCTION__ << endl;
 
249
        // Clear both types of wakelocks (display and system)
249
250
        if (system_wakelock_count > 0)
250
251
        {
251
252
            {