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 17package com.android.tv.tuner.tvinput; 18 19import android.content.Context; 20import android.media.tv.TvInputManager; 21import android.media.tv.TvInputService; 22import android.net.Uri; 23import android.support.annotation.MainThread; 24import android.support.annotation.Nullable; 25import android.support.annotation.WorkerThread; 26import android.util.Log; 27 28/** 29 * Processes DVR recordings, and deletes the previously recorded contents. 30 */ 31public class TunerRecordingSession extends TvInputService.RecordingSession { 32 private static final String TAG = "TunerRecordingSession"; 33 private static final boolean DEBUG = false; 34 35 private final TunerRecordingSessionWorker mSessionWorker; 36 37 public TunerRecordingSession(Context context, String inputId, 38 ChannelDataManager channelDataManager) { 39 super(context); 40 mSessionWorker = new TunerRecordingSessionWorker(context, inputId, channelDataManager, 41 this); 42 } 43 44 // RecordingSession 45 @MainThread 46 @Override 47 public void onTune(Uri channelUri) { 48 // TODO(dvr): support calling more than once, http://b/27171225 49 if (DEBUG) { 50 Log.d(TAG, "Requesting recording session tune: " + channelUri); 51 } 52 mSessionWorker.tune(channelUri); 53 } 54 55 @MainThread 56 @Override 57 public void onRelease() { 58 if (DEBUG) { 59 Log.d(TAG, "Requesting recording session release."); 60 } 61 mSessionWorker.release(); 62 } 63 64 @MainThread 65 @Override 66 public void onStartRecording(@Nullable Uri programUri) { 67 if (DEBUG) { 68 Log.d(TAG, "Requesting start recording."); 69 } 70 mSessionWorker.startRecording(programUri); 71 } 72 73 @MainThread 74 @Override 75 public void onStopRecording() { 76 if (DEBUG) { 77 Log.d(TAG, "Requesting stop recording."); 78 } 79 mSessionWorker.stopRecording(); 80 } 81 82 // Called from TunerRecordingSessionImpl in a worker thread. 83 @WorkerThread 84 public void onTuned(Uri channelUri) { 85 if (DEBUG) { 86 Log.d(TAG, "Notifying recording session tuned."); 87 } 88 notifyTuned(channelUri); 89 } 90 91 @WorkerThread 92 public void onRecordFinished(final Uri recordedProgramUri) { 93 if (DEBUG) { 94 Log.d(TAG, "Notifying record successfully finished."); 95 } 96 notifyRecordingStopped(recordedProgramUri); 97 } 98 99 @WorkerThread 100 public void onError(int reason) { 101 Log.w(TAG, "Notifying recording error: " + reason); 102 notifyError(reason); 103 } 104} 105