~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to src/mcs/miracastservice.cpp

Add hardware encoding and video streaming support.

The hardware encoding is currently only for Android 5.x based devices. On all others encoding will simply not work. The streaming part of aethercast (MPEGTS packetizing, RTP sending) as based on some code from Android.

Approved by PS Jenkins bot, Thomas Voß, Jim Hodapp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <cstdint>
21
21
 
22
22
#include <sys/prctl.h>
 
23
#include <signal.h>
 
24
#include <sys/time.h>
 
25
#include <sys/resource.h>
23
26
 
24
27
#include <glib.h>
25
28
#include <glib-unix.h>
31
34
 
32
35
#include <wds/logging.h>
33
36
 
 
37
#include "initgstreameronce.h"
34
38
#include "config.h"
35
39
#include "keep_alive.h"
36
40
#include "logger.h"
45
49
const std::uint16_t kMiracastDefaultRtspCtrlPort{7236};
46
50
const std::chrono::milliseconds kStateIdleTimeout{5000};
47
51
const std::chrono::seconds kShutdownGracePreriod{1};
 
52
const std::int16_t kProcessPriorityUrgentDisplay{-8};
48
53
 
49
54
// SafeLog serves as integration point to the wds::LogSystem world.
50
55
template <mcs::Logger::Severity severity>
94
99
        return 0;
95
100
    }
96
101
 
 
102
    if (options.debug)
 
103
        mcs::Log().Init(mcs::Logger::Severity::kDebug);
 
104
 
97
105
    struct Runtime {
98
106
        static gboolean OnSignalRaised(gpointer user_data) {
99
107
            auto thiz = static_cast<Runtime*>(user_data);
122
130
            g_unix_signal_add(SIGINT, OnSignalRaised, this);
123
131
            g_unix_signal_add(SIGTERM, OnSignalRaised, this);
124
132
 
 
133
            // Initialize gstreamer.
 
134
            mcs::InitGstreamerOnceOrThrow();
 
135
 
125
136
            // Redirect all wds logging to our own.
126
137
            wds::LogSystem::set_vlog_func(SafeLog<mcs::Logger::Severity::kTrace>);
127
138
            wds::LogSystem::set_log_func(SafeLog<mcs::Logger::Severity::kInfo>);
156
167
            if (prctl(PR_SET_CHILD_SUBREAPER, 1) < 0)
157
168
                g_warning("Failed to make us a subreaper of our children");
158
169
 
 
170
            // Raise our process priority to be as fast as possible
 
171
            setpriority(PRIO_PROCESS, 0, kProcessPriorityUrgentDisplay);
 
172
 
159
173
            network_manager = mcs::NetworkManagerFactory::Create();
160
174
            service = mcs::MiracastService::Create(network_manager);
161
175
            mcsa = mcs::MiracastControllerSkeleton::create(service);
202
216
        network_manager_->Setup();
203
217
    }
204
218
 
 
219
    system_controller_ = mcs::SystemController::CreatePlatformDefault();
 
220
 
205
221
    return shared_from_this();
206
222
}
207
223
 
246
262
}
247
263
 
248
264
void MiracastService::AdvanceState(NetworkDeviceState new_state) {
249
 
    IpV4Address address;
250
 
 
251
265
    DEBUG("new state %s current state %s",
252
266
          mcs::NetworkDevice::StateToStr(new_state),
253
267
          mcs::NetworkDevice::StateToStr(current_state_));
256
270
    case kAssociation:
257
271
        break;
258
272
 
 
273
    case kConfiguration:
 
274
        break;
 
275
 
259
276
    case kConnected:
260
 
        address = network_manager_->LocalAddress();
261
 
 
262
 
        source_ = MiracastSourceManager::Create(address, kMiracastDefaultRtspCtrlPort);
263
 
 
 
277
        source_ = MiracastSourceManager::Create(network_manager_->LocalAddress(), kMiracastDefaultRtspCtrlPort);
264
278
        FinishConnectAttempt();
265
 
 
266
279
        break;
267
280
 
268
281
    case kFailure:
272
285
        source_.reset();
273
286
        current_device_.reset();
274
287
 
 
288
        system_controller_->DisplayStateLock()->Release(mcs::DisplayState::On);
 
289
 
275
290
        StartIdleTimer();
276
291
        break;
277
292
 
359
374
        return;
360
375
    }
361
376
 
 
377
    system_controller_->DisplayStateLock()->Acquire(mcs::DisplayState::On);
 
378
 
362
379
    current_device_ = device;
363
380
    connect_callback_ = callback;
364
381
}