//contains the init code for both android and linux static void andzop_init(int pDebug) { int l_i; int l_mbH, l_mbW; gCurrentDecodingVideoFileIndex = 0; get_video_info(pDebug); gVideoPacketNum = 0; #ifdef SELECTIVE_DECODING for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) { LOGI(10, "allocate_selected_decoding_fields for %d, current video index %d", l_i, gCurrentDecodingVideoFileIndex); l_mbH = (gVideoCodecCtxList[l_i]->height + 15) / 16; l_mbW = (gVideoCodecCtxList[l_i]->width + 15) / 16; allocate_selected_decoding_fields(l_i, l_mbH, l_mbW); } #ifdef BG_DUMP_THREAD if (gDumpDep) { LOGI(10, "initialize dumping threads, current video index %d", gCurrentDecodingVideoFileIndex); gDepDumpThreadList = (pthread_t*)malloc(gNumOfVideoFiles *sizeof(pthread_t)); gDumpThreadParams = (DUMP_DEP_PARAMS *)malloc(sizeof(DUMP_DEP_PARAMS)*gNumOfVideoFiles); for (l_i = 0; l_i < gNumOfVideoFiles; ++l_i) { //start a background thread for dependency dumping gDumpThreadParams[l_i].videoFileIndex = l_i; if (pthread_create(&gDepDumpThreadList[l_i], NULL, dump_dependency_function, (void *)&gDumpThreadParams[l_i])) { LOGE(1, "Error: failed to create a native thread for dumping dependency"); } LOGI(10, "tttttt: dependency dumping thread started! tttttt"); } } #endif //for BG_DUMP_THREAD #ifdef PRE_LOAD_DEP //preload the first GOP at start up pthread_mutex_init(&preloadMutex, NULL); pthread_cond_init(&preloadCondVar, NULL); LOGI(10, "preload at initialization"); //TODO: initialize the ROI gRoiSh = 10; gRoiSw = 10; gRoiEh = 100; gRoiEw = 100; get_gop_info_given_gop_num(gCurrentDecodingVideoFileIndex, 1, &gNextGopStart, &gNextGopEnd); preload_pre_computation_result(gCurrentDecodingVideoFileIndex, 1); LOGI(10, "preload at initialization done"); LOGI(10, "initialize thread to preload dependencies"); if (pthread_create(&gPreloadThread, NULL, preload_dependency_function, NULL)) { LOGE(1, "Error: failed to create a native thread for preloading dependency"); exit(1); } LOGI(10, "preloading thread started!"); #endif //for PRE_LOAD_DEP #endif //for SELECTIVE_DECODING LOGI(10, "initialization done, current video index %d", gCurrentDecodingVideoFileIndex); }
//this is the function for preload thread. It should execute on the following two conditions //1. at initial set up, preload [changed, should be called directly from naInit] //2. at starting of decoding of a new GOP, preload static void *preload_dependency_function(void *arg) { int i; for (i = 0; i < NUM_OF_FRAMES_TO_DECODE; ++i) { pthread_mutex_lock(&preloadMutex); LOGI(8, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz preload thread goes to sleep zzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); //while (1) { pthread_cond_wait(&preloadCondVar, &preloadMutex); //TODO: temp comment out // if (gPreloadGopNum ) { // LOGI(8, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz not ready continue to sleep zzzzzzzzzzzzzzzzzzzzzzzzz"); //} else { // break; //} //} LOGI(8, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz preload thread wake up to load gop %d yyyyyyyyyyyy", g_decode_gop_num + 1); get_gop_info_given_gop_num(gCurrentDecodingVideoFileIndex, g_decode_gop_num + 1, &gNextGopStart, &gNextGopEnd); preload_pre_computation_result(gCurrentDecodingVideoFileIndex, g_decode_gop_num + 1); pthread_mutex_unlock(&preloadMutex); } }