1 /*
2  * Copyright (C) 2020 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 #ifndef ANDROID_MEDIA_TRANSCODER_INTERFACE_H
18 #define ANDROID_MEDIA_TRANSCODER_INTERFACE_H
19 
20 #include <aidl/android/media/ITranscodingClientCallback.h>
21 #include <aidl/android/media/TranscodingErrorCode.h>
22 #include <aidl/android/media/TranscodingRequestParcel.h>
23 #include <media/TranscodingDefs.h>
24 
25 namespace android {
26 
27 using ::aidl::android::media::ITranscodingClientCallback;
28 using ::aidl::android::media::TranscodingErrorCode;
29 using ::aidl::android::media::TranscodingRequestParcel;
30 class TranscoderCallbackInterface;
31 
32 // Interface for the controller to call the transcoder to take actions.
33 class TranscoderInterface {
34 public:
35     virtual void start(ClientIdType clientId, SessionIdType sessionId,
36                        const TranscodingRequestParcel& request, uid_t callingUid,
37                        const std::shared_ptr<ITranscodingClientCallback>& clientCallback) = 0;
38     virtual void pause(ClientIdType clientId, SessionIdType sessionId) = 0;
39     virtual void resume(ClientIdType clientId, SessionIdType sessionId,
40                         const TranscodingRequestParcel& request, uid_t callingUid,
41                         const std::shared_ptr<ITranscodingClientCallback>& clientCallback) = 0;
42     // Stop the specified session. If abandon is true, the transcoder wrapper will be discarded
43     // after the session stops.
44     virtual void stop(ClientIdType clientId, SessionIdType sessionId, bool abandon = false) = 0;
45 
46 protected:
47     virtual ~TranscoderInterface() = default;
48 };
49 
50 // Interface for the transcoder to notify the controller of the status of
51 // the currently running session, or temporary loss of transcoding resources.
52 class TranscoderCallbackInterface {
53 public:
54     // TODO(chz): determine what parameters are needed here.
55     virtual void onStarted(ClientIdType clientId, SessionIdType sessionId) = 0;
56     virtual void onPaused(ClientIdType clientId, SessionIdType sessionId) = 0;
57     virtual void onResumed(ClientIdType clientId, SessionIdType sessionId) = 0;
58     virtual void onFinish(ClientIdType clientId, SessionIdType sessionId) = 0;
59     virtual void onError(ClientIdType clientId, SessionIdType sessionId,
60                          TranscodingErrorCode err) = 0;
61     virtual void onProgressUpdate(ClientIdType clientId, SessionIdType sessionId,
62                                   int32_t progress) = 0;
63     virtual void onHeartBeat(ClientIdType clientId, SessionIdType sessionId) = 0;
64 
65     // Called when transcoding becomes temporarily inaccessible due to loss of resource.
66     // If there is any session currently running, it will be paused. When resource contention
67     // is solved, the controller should call TranscoderInterface's to either start a new session,
68     // or resume a paused session.
69     virtual void onResourceLost(ClientIdType clientId, SessionIdType sessionId) = 0;
70 
71 protected:
72     virtual ~TranscoderCallbackInterface() = default;
73 };
74 
75 }  // namespace android
76 #endif  // ANDROID_MEDIA_TRANSCODER_INTERFACE_H
77