• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package com.android.tv.tuner.tvinput;
18 
19 import android.content.Context;
20 import android.net.Uri;
21 import android.support.annotation.MainThread;
22 import android.support.annotation.Nullable;
23 import android.support.annotation.WorkerThread;
24 import android.util.Log;
25 
26 import com.android.tv.common.compat.RecordingSessionCompat;
27 import com.android.tv.common.dagger.annotations.ApplicationContext;
28 import com.android.tv.tuner.tvinput.datamanager.ChannelDataManager;
29 import com.android.tv.tuner.tvinput.factory.TunerRecordingSessionFactory;
30 import com.android.tv.tuner.tvinput.factory.TunerRecordingSessionFactory.RecordingSessionReleasedCallback;
31 
32 import com.google.auto.factory.AutoFactory;
33 import com.google.auto.factory.Provided;
34 
35 /** Processes DVR recordings, and deletes the previously recorded contents. */
36 @AutoFactory(
37         className = "TunerRecordingSessionFactoryImpl",
38         implementing = TunerRecordingSessionFactory.class)
39 public class TunerRecordingSession extends RecordingSessionCompat {
40     private static final String TAG = "TunerRecordingSession";
41     private static final boolean DEBUG = false;
42 
43     private final TunerRecordingSessionWorker mSessionWorker;
44     private final RecordingSessionReleasedCallback mReleasedCallback;
45     private Uri mChannelUri;
46     private Uri mRecordingUri;
47 
TunerRecordingSession( @rovided @pplicationContext Context context, String inputId, RecordingSessionReleasedCallback releasedCallback, ChannelDataManager channelDataManager, @Provided TunerRecordingSessionWorker.Factory tunerRecordingSessionWorkerFactory)48     public TunerRecordingSession(
49             @Provided @ApplicationContext Context context,
50             String inputId,
51             RecordingSessionReleasedCallback releasedCallback,
52             ChannelDataManager channelDataManager,
53             @Provided TunerRecordingSessionWorker.Factory tunerRecordingSessionWorkerFactory) {
54         super(context);
55         mReleasedCallback = releasedCallback;
56         mSessionWorker =
57                 tunerRecordingSessionWorkerFactory.create(
58                         context, inputId, channelDataManager, this);
59     }
60 
61     // RecordingSession
62     @MainThread
63     @Override
onTune(Uri channelUri)64     public void onTune(Uri channelUri) {
65         // TODO(dvr): support calling more than once, http://b/27171225
66         if (DEBUG) {
67             Log.d(TAG, "Requesting recording session tune: " + channelUri);
68         }
69         mSessionWorker.tune(channelUri);
70     }
71 
72     @MainThread
73     @Override
onRelease()74     public void onRelease() {
75         if (DEBUG) {
76             Log.d(TAG, "Requesting recording session release.");
77         }
78         mSessionWorker.release();
79         mReleasedCallback.onReleased(this);
80     }
81 
82     @MainThread
83     @Override
onStartRecording(@ullable Uri programUri)84     public void onStartRecording(@Nullable Uri programUri) {
85         if (DEBUG) {
86             Log.d(TAG, "Requesting start recording.");
87         }
88         mSessionWorker.startRecording(programUri);
89     }
90 
91     @MainThread
92     @Override
onStopRecording()93     public void onStopRecording() {
94         if (DEBUG) {
95             Log.d(TAG, "Requesting stop recording.");
96         }
97         mSessionWorker.stopRecording();
98     }
99 
100     // Called from TunerRecordingSessionImpl in a worker thread.
101     @WorkerThread
onTuned(Uri channelUri)102     public void onTuned(Uri channelUri) {
103         if (DEBUG) {
104             Log.d(TAG, "Notifying recording session tuned.");
105         }
106         mChannelUri = channelUri;
107         notifyTuned(channelUri);
108     }
109 
110     // Called from TunerRecordingSessionImpl in a worker thread.
111     @WorkerThread
onRecordingUri(String recUri)112     public void onRecordingUri(String recUri) {
113         if (DEBUG) {
114             Log.d(TAG, "Notifying recording session URI." + recUri);
115         }
116         notifyRecordingStarted(recUri);
117     }
118 
119     @WorkerThread
onRecordFinished(final Uri recordedProgramUri)120     public void onRecordFinished(final Uri recordedProgramUri) {
121         if (DEBUG) {
122             Log.d(TAG, "Notifying record successfully finished.");
123         }
124         mRecordingUri = null;
125         notifyRecordingStopped(recordedProgramUri);
126     }
127 
128     @WorkerThread
onError(int reason)129     public void onError(int reason) {
130         Log.w(TAG, "Notifying recording error: " + reason);
131         notifyError(reason);
132     }
133 
onRecordingStatePartial(Uri recUri)134     public void onRecordingStatePartial(Uri recUri) {
135         if (DEBUG) {
136             Log.d(TAG, "Updating recording session state to Partial");
137         }
138         mRecordingUri = recUri;
139     }
140 
getChannelUri()141     public Uri getChannelUri() {
142         return mChannelUri;
143     }
144 
getRecordingUri()145     public Uri getRecordingUri() {
146         return mRecordingUri;
147     }
148 }
149