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 
     63     int mFeFd;
     64     int mDemuxFd;
     65     int mDvrFd;
     66     int mPatFilterFd;
     67     int mDvbApiVersion;
     68     int mDeliverySystemType;
     69     bool mFeHasLock;
     70     // Flag for pending tune request. Used for canceling the current tune operation.
     71     bool volatile mHasPendingTune;
     72     std::map<int, int> mPidFilters;
     73     Mutex mFilterLock;
     74     jmethodID mOpenDvbFrontEndMethodID;
     75     jmethodID mOpenDvbDemuxMethodID;
     76     jmethodID mOpenDvbDvrMethodID;
     77 
     78 public:
     79     DvbManager(JNIEnv *env, jobject thiz);
     80     ~DvbManager();
     81     int tune(JNIEnv *env, jobject thiz,
     82             const int frequency, const char *modulationStr, int timeout_ms);
     83     int stopTune();
     84     int readTsStream(JNIEnv *env, jobject thiz,
     85             uint8_t *tsBuffer, int tsBufferSize, int timeout_ms);
     86     int startTsPidFilter(JNIEnv *env, jobject thiz, int pid, int filterType);
     87     void closeAllDvbPidFilter();
     88     void setHasPendingTune(bool hasPendingTune);
     89     int getDeliverySystemType(JNIEnv *env, jobject thiz);
     90 
     91 private:
     92     int openDvbFe(JNIEnv *env, jobject thiz);
     93     int openDvbDvr(JNIEnv *env, jobject thiz);
     94     void closePatFilter();
     95     void closeDvbFe();
     96     void closeDvbDvr();
     97     void reset();
     98     void resetExceptFe();
     99     bool isFeLocked();
    100     // Call to java method
    101     int openDvbFeFromSystemApi(JNIEnv *env, jobject thiz);
    102     int openDvbDemuxFromSystemApi(JNIEnv *env, jobject thiz);
    103     int openDvbDvrFromSystemApi(JNIEnv *env, jobject thiz);
    104 };
    105 
    106 #endif  // DVB_MANAGER_H_
    107