1 /*
2  * Copyright 2012, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "RemoteDisplay.h"
18 
19 #include "source/WifiDisplaySource.h"
20 
21 #include <media/IRemoteDisplayClient.h>
22 #include <media/stagefright/foundation/ADebug.h>
23 #include <media/stagefright/foundation/AMessage.h>
24 #include <media/stagefright/foundation/ANetworkSession.h>
25 
26 namespace android {
27 
RemoteDisplay(const String16 & opPackageName,const sp<IRemoteDisplayClient> & client,const char * iface)28 RemoteDisplay::RemoteDisplay(
29         const String16 &opPackageName,
30         const sp<IRemoteDisplayClient> &client,
31         const char *iface)
32     : mLooper(new ALooper),
33       mNetSession(new ANetworkSession) {
34     mLooper->setName("wfd_looper");
35 
36     mSource = new WifiDisplaySource(opPackageName, mNetSession, client);
37     mLooper->registerHandler(mSource);
38 
39     mNetSession->start();
40     mLooper->start();
41 
42     mSource->start(iface);
43 }
44 
~RemoteDisplay()45 RemoteDisplay::~RemoteDisplay() {
46 }
47 
pause()48 status_t RemoteDisplay::pause() {
49     return mSource->pause();
50 }
51 
resume()52 status_t RemoteDisplay::resume() {
53     return mSource->resume();
54 }
55 
dispose()56 status_t RemoteDisplay::dispose() {
57     mSource->stop();
58     mSource.clear();
59 
60     mLooper->stop();
61     mNetSession->stop();
62 
63     return OK;
64 }
65 
66 }  // namespace android
67