Home | History | Annotate | Download | only in jni
      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 #ifndef DVB_MANAGER_H_
     18 #define DVB_MANAGER_H_
     19 
     20 #include <jni.h>
     21 #include <map>
     22 
     23 #include "mutex.h"
     24 #include "tunertvinput_jni.h"
     25 
     26 class DvbManager {
     27     static const int NUM_POLLFDS = 1;
     28     static const int FE_LOCK_CHECK_INTERNAL_US = 100 * 1000;
     29     static const int FE_CONSECUTIVE_LOCK_SUCCESS_COUNT = 1;
     30     static const int DVB_ERROR_RETRY_INTERVAL_MS = 100 * 1000;
     31     static const int DVB_TUNE_STOP_DELAY_MS = 100 * 1000;
     32     static const int FE_POLL_TIMEOUT_MS = 100;
     33     static const int PAT_PID = 0;
     34     static const int DVB_API_VERSION_UNDEFINED = -1;
     35     static const int DVB_API_VERSION3 = 3;
     36     static const int DVB_API_VERSION5 = 5;
     37 
     38     static const int FILTER_TYPE_OTHER =
     39         com_android_tv_tuner_TunerHal_FILTER_TYPE_OTHER;
     40     static const int FILTER_TYPE_AUDIO =
     41         com_android_tv_tuner_TunerHal_FILTER_TYPE_AUDIO;
     42     static const int FILTER_TYPE_VIDEO =
     43         com_android_tv_tuner_TunerHal_FILTER_TYPE_VIDEO;
     44     static const int FILTER_TYPE_PCR =
     45         com_android_tv_tuner_TunerHal_FILTER_TYPE_PCR;
     46 
     47     static const int DELIVERY_SYSTEM_UNDEFINED =
     48         com_android_tv_tuner_TunerHal_DELIVERY_SYSTEM_UNDEFINED;
     49     static const int DELIVERY_SYSTEM_ATSC =
     50         com_android_tv_tuner_TunerHal_DELIVERY_SYSTEM_ATSC;
     51     static const int DELIVERY_SYSTEM_DVBC =
     52         com_android_tv_tuner_TunerHal_DDELIVERY_SYSTEM_DVBC;
     53     static const int DELIVERY_SYSTEM_DVBS =
     54         com_android_tv_tuner_TunerHal_DELIVERY_SYSTEM_DVBS;
     55     static const int DELIVERY_SYSTEM_DVBS2 =
     56         com_android_tv_tuner_TunerHal_DELIVERY_SYSTEM_DVBS2;
     57     static const int DELIVERY_SYSTEM_DVBT =
     58         com_android_tv_tuner_TunerHal_DELIVERY_SYSTEM_DVBT;
     59     static const int DELIVERY_SYSTEM_DVBT2 =
     60         com_android_tv_tuner_TunerHal_DELIVERY_SYSTEM_DVBT2;
     61 
     62     int mFeFd;
     63     int mDvrFd;
     64     int mPatFilterFd;
     65     int mDvbApiVersion;
     66     int mDeliverySystemType;
     67     bool mFeHasLock;
     68     // Flag for pending tune request. Used for canceling the current tune operation.
     69     bool volatile mHasPendingTune;
     70     std::map<int, int> mPidFilters;
     71     Mutex mFilterLock;
     72     jmethodID mOpenDvbFrontEndMethodID;
     73     jmethodID mOpenDvbDemuxMethodID;
     74     jmethodID mOpenDvbDvrMethodID;
     75 
     76 public:
     77     DvbManager(JNIEnv *env, jobject thiz);
     78     ~DvbManager();
     79     int tune(JNIEnv *env, jobject thiz,
     80             const int frequency, const char *modulationStr, int timeout_ms);
     81     int stopTune();
     82     int readTsStream(JNIEnv *env, jobject thiz,
     83             uint8_t *tsBuffer, int tsBufferSize, int timeout_ms);
     84     int startTsPidFilter(JNIEnv *env, jobject thiz, int pid, int filterType);
     85     void closeAllDvbPidFilter();
     86     void setHasPendingTune(bool hasPendingTune);
     87     int getDeliverySystemType(JNIEnv *env, jobject thiz);
     88 
     89 private:
     90     int openDvbFe(JNIEnv *env, jobject thiz);
     91     int openDvbDvr(JNIEnv *env, jobject thiz);
     92     void closePatFilter();
     93     void closeDvbFe();
     94     void closeDvbDvr();
     95     void reset();
     96     void resetExceptFe();
     97     bool isFeLocked();
     98     // Call to java method
     99     int openDvbFeFromSystemApi(JNIEnv *env, jobject thiz);
    100     int openDvbDemuxFromSystemApi(JNIEnv *env, jobject thiz);
    101     int openDvbDvrFromSystemApi(JNIEnv *env, jobject thiz);
    102 };
    103 
    104 #endif  // DVB_MANAGER_H_
    105