// initialize the auto update system, start the downloading void init_update() { FILE *fp; if(update_busy){ return; } // initialize variables update_busy++; update_attempt_count= 0; // no downloads have been attempted temp_counter= 0; //start with download name with 0 restart_required= 0; // no restart needed yet allow_restart= 1; // automated restart allowed // create the mutex & init the download que if(!download_mutex){ // file_update_clear_old(); // There is no reason to delete all the previous files. We only remove the ones out of date. download_mutex= SDL_CreateMutex(); download_queue_size= 0; memset(download_queue, 0, sizeof(download_queue)); download_cur_file= NULL; download_cur_md5= NULL; } // load the server list num_update_servers= 0; update_server[0]= '\0'; fp = open_file_data("mirrors.lst", "r"); if(fp == NULL){ LOG_ERROR("%s: %s \"mirrors.lst\": %s\n", reg_error_str, cant_open_file, strerror(errno)); } else { char buffer[1024]; char *ptr; ptr= fgets(buffer, sizeof(buffer), fp); while(ptr && !ferror(fp) && num_update_servers < sizeof(update_servers)){ int len= strlen(buffer); // is this line worth handling? if(len > 6 && *buffer > ' ' && *buffer != '#'){ while(isspace(buffer[len-1])){ buffer[len-1]= '\0'; len--; } if(len > 6){ update_servers[num_update_servers++]= strdup(buffer); } } // read the next line ptr= fgets(buffer, sizeof(buffer), fp); } if(fp){ fclose(fp); } } if(!num_update_servers) { // oops, no mirror file, no downloading update_servers[0]= ""; return; } // start the process if(download_mutex){ strcpy(files_lst, "files.lst"); is_this_files_lst= 1; handle_update_download(NULL); } }
int main(int argc, char *argv[]) { SDL_Event event; VideoState *is; is = av_mallocz(sizeof(VideoState)); if(argc < 2) { fprintf(stderr, "Usage: test <file>\n"); exit(1); } // Register all formats and codecs av_register_all(); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } // Make a screen to put our video #ifndef __DARWIN__ screen = SDL_SetVideoMode(640, 480, 0, 0); #else screen = SDL_SetVideoMode(640, 480, 24, 0); #endif if(!screen) { fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); } av_strlcpy(is->filename, argv[1], 1024); is->pictq_mutex = SDL_CreateMutex(); is->pictq_cond = SDL_CreateCond(); schedule_refresh(is, 40); is->av_sync_type = DEFAULT_AV_SYNC_TYPE; is->parse_tid = SDL_CreateThread(decode_thread, is); if(!is->parse_tid) { av_free(is); return -1; } for(;;) { SDL_WaitEvent(&event); switch(event.type) { case FF_QUIT_EVENT: case SDL_QUIT: is->quit = 1; /* * If the video has finished playing, then both the picture and * audio queues are waiting for more data. Make them stop * waiting and terminate normally. */ SDL_CondSignal(is->audioq.cond); SDL_CondSignal(is->videoq.cond); SDL_Quit(); exit(0); break; case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); break; default: break; } } return 0; }
/* =============== GLimp_SpawnRenderThread =============== */ qboolean GLimp_SpawnRenderThread( void (*function)( void ) ) { static qboolean warned = qfalse; if (!warned) { Com_Printf("WARNING: You enable r_smp at your own risk!\n"); warned = qtrue; } #if !defined(MACOS_X) && !defined(WIN32) && !defined (SDL_VIDEO_DRIVER_X11) return qfalse; /* better safe than sorry for now. */ #endif if (renderThread != NULL) /* hopefully just a zombie at this point... */ { Com_Printf("Already a render thread? Trying to clean it up...\n"); SDL_WaitThread(renderThread, NULL); renderThread = NULL; GLimp_ShutdownRenderThread(); } smpMutex = SDL_CreateMutex(); if (smpMutex == NULL) { Com_Printf( "smpMutex creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } renderCommandsEvent = SDL_CreateCond(); if (renderCommandsEvent == NULL) { Com_Printf( "renderCommandsEvent creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } renderCompletedEvent = SDL_CreateCond(); if (renderCompletedEvent == NULL) { Com_Printf( "renderCompletedEvent creation failed: %s\n", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } glimpRenderThread = function; renderThread = SDL_CreateThread(GLimp_RenderThreadWrapper, "RenderThread", NULL); if ( renderThread == NULL ) { ri.Printf( PRINT_ALL, "SDL_CreateThread() returned %s", SDL_GetError() ); GLimp_ShutdownRenderThread(); return qfalse; } else { // tma 01/09/07: don't think this is necessary anyway? // // !!! FIXME: No detach API available in SDL! //ret = pthread_detach( renderThread ); //if ( ret ) { //ri.Printf( PRINT_ALL, "pthread_detach returned %d: %s", ret, strerror( ret ) ); //} } return qtrue; }
Work() : done_(false) { mutex = SDL_CreateMutex(); stateCond = SDL_CreateCond(); }
/** * @brief Initializes the sound subsystem. * * @return 0 on success. */ int sound_init (void) { int ret; /* See if sound is disabled. */ if (conf.nosound) { sound_disabled = 1; music_disabled = 1; } /* Parse conf. */ if (sound_disabled && music_disabled) return 0; /* Choose sound system. */ if ((sound_sys_init == NULL) && (conf.sound_backend != NULL) && (strcmp(conf.sound_backend,"openal")==0)) { #if USE_OPENAL /* * OpenAL Sound. */ /* Creation. */ sound_sys_init = sound_al_init; sound_sys_exit = sound_al_exit; /* Sound Creation. */ sound_sys_load = sound_al_load; sound_sys_free = sound_al_free; /* Sound settings. */ sound_sys_volume = sound_al_volume; sound_sys_getVolume = sound_al_getVolume; sound_sys_getVolumeLog = sound_al_getVolumeLog; /* Sound playing. */ sound_sys_play = sound_al_play; sound_sys_playPos = sound_al_playPos; sound_sys_updatePos = sound_al_updatePos; sound_sys_updateVoice = sound_al_updateVoice; /* Sound management. */ sound_sys_update = sound_al_update; sound_sys_stop = sound_al_stop; sound_sys_pause = sound_al_pause; sound_sys_resume = sound_al_resume; sound_sys_setSpeed = sound_al_setSpeed; sound_sys_setSpeedVolume = sound_al_setSpeedVolume; /* Listener. */ sound_sys_updateListener = sound_al_updateListener; /* Groups. */ sound_sys_createGroup = sound_al_createGroup; sound_sys_playGroup = sound_al_playGroup; sound_sys_stopGroup = sound_al_stopGroup; sound_sys_pauseGroup = sound_al_pauseGroup; sound_sys_resumeGroup = sound_al_resumeGroup; sound_sys_speedGroup = sound_al_speedGroup; sound_sys_volumeGroup = sound_al_volumeGroup; /* Env. */ sound_sys_env = sound_al_env; #else /* USE_OPENAL */ WARN("OpenAL support not compiled in!"); #endif /* USE_OPENAL */ } if ((sound_sys_init == NULL) && (conf.sound_backend != NULL) && (strcmp(conf.sound_backend,"sdlmix")==0)) { #if USE_SDLMIX /* * SDL_mixer Sound. */ /* Creation. */ sound_sys_init = sound_mix_init; sound_sys_exit = sound_mix_exit; /* Sound Creation. */ sound_sys_load = sound_mix_load; sound_sys_free = sound_mix_free; /* Sound settings. */ sound_sys_volume = sound_mix_volume; sound_sys_getVolume = sound_mix_getVolume; sound_sys_getVolumeLog = sound_mix_getVolumeLog; /* Sound playing. */ sound_sys_play = sound_mix_play; sound_sys_playPos = sound_mix_playPos; sound_sys_updatePos = sound_mix_updatePos; sound_sys_updateVoice = sound_mix_updateVoice; /* Sound management. */ sound_sys_update = sound_mix_update; sound_sys_stop = sound_mix_stop; sound_sys_pause = sound_mix_pause; sound_sys_resume = sound_mix_resume; sound_sys_setSpeed = sound_mix_setSpeed; sound_sys_setSpeedVolume = sound_mix_setSpeedVolume; /* Listener. */ sound_sys_updateListener = sound_mix_updateListener; /* Groups. */ sound_sys_createGroup = sound_mix_createGroup; sound_sys_playGroup = sound_mix_playGroup; sound_sys_stopGroup = sound_mix_stopGroup; sound_sys_pauseGroup = sound_mix_pauseGroup; sound_sys_resumeGroup = sound_mix_resumeGroup; sound_sys_speedGroup = sound_mix_speedGroup; sound_sys_volumeGroup = sound_mix_volumeGroup; /* Env. */ sound_sys_env = sound_mix_env; #else /* USE_SDLMIX */ WARN("SDL_mixer support not compiled in!"); #endif /* USE_SDLMIX */ } if (sound_sys_init == NULL) { WARN("Unknown/Unavailable sound backend '%s'.", conf.sound_backend); sound_disabled = 1; WARN("Sound disabled."); music_disabled = 1; return 0; } /* Initialize sound backend. */ ret = sound_sys_init(); if (ret != 0) { sound_disabled = 1; music_disabled = 1; WARN("Sound disabled."); return ret; } /* Create voice lock. */ voice_mutex = SDL_CreateMutex(); if (voice_mutex == NULL) WARN("Unable to create voice mutex."); /* Load available sounds. */ ret = sound_makeList(); if (ret != 0) return ret; /* Initialize music. */ ret = music_init(); if (ret != 0) { music_disabled = 1; WARN("Music disabled."); } /* Set volume. */ if ((conf.sound > 1.) || (conf.sound < 0.)) WARN("Sound has invalid value, clamping to [0:1]."); sound_volume(conf.sound); /* Initialized. */ sound_initialized = 1; /* Load compression noise. */ snd_compression = sound_get( "compression" ); if (snd_compression >= 0) { snd_compressionG = sound_createGroup( 1 ); sound_speedGroup( snd_compressionG, 0 ); } return 0; }
/* Initialize SDL threading */ void init_threads(void) { struct thread_entry *thread; int n; memset(cores, 0, sizeof(cores)); memset(threads, 0, sizeof(threads)); m = SDL_CreateMutex(); if (SDL_LockMutex(m) == -1) { fprintf(stderr, "Couldn't lock mutex\n"); return; } /* Initialize all IDs */ for (n = 0; n < MAXTHREADS; n++) threads[n].id = THREAD_ID_INIT(n); /* Slot 0 is reserved for the main thread - initialize it here and then create the SDL thread - it is possible to have a quick, early shutdown try to access the structure. */ thread = &threads[0]; thread->stack = (uintptr_t *)" "; thread->stack_size = 8; thread->name = "main"; thread->state = STATE_RUNNING; thread->context.s = SDL_CreateSemaphore(0); thread->context.t = NULL; /* NULL for the implicit main thread */ cores[CURRENT_CORE].running = thread; if (thread->context.s == NULL) { fprintf(stderr, "Failed to create main semaphore\n"); return; } /* Tell all threads jump back to their start routines, unlock and exit gracefully - we'll check each one in turn for it's status. Threads _could_ terminate via remove_thread or multiple threads could exit on each unlock but that is safe. */ /* Setup jump for exit */ if (setjmp(thread_jmpbufs[0]) == 0) { THREAD_SDL_DEBUGF("Main thread: %p\n", thread); return; } SDL_UnlockMutex(m); /* Set to 'COMMAND_DONE' when other rockbox threads have exited. */ while (threads_status < THREADS_EXIT_COMMAND_DONE) SDL_Delay(10); SDL_DestroyMutex(m); /* We're the main thead - perform exit - doesn't return. */ sim_do_exit(); }
void *SystemStub_SDL::createMutex() { return SDL_CreateMutex(); }
#include "CommandScheduler.h" #include "cppsqlite3.h" #include "Logger.h" CommandScheduler* CommandScheduler::pUniqueInstance = NULL; // Reference to the unique instance. SDL_mutex* CommandScheduler::mxInstance = SDL_CreateMutex(); // Reference to instance mutex. CommandScheduler* CommandScheduler::getInstance(){ SDL_LockMutex(mxInstance); // Locks the mutex... if (pUniqueInstance == NULL){ // No instance, create one. pUniqueInstance = new CommandScheduler(); } SDL_UnlockMutex(mxInstance); // Unlocks the mutex... return pUniqueInstance; } void CommandScheduler::freeInstance(){ SDL_LockMutex(mxInstance); // Locks the mutex... if (pUniqueInstance != NULL) { delete pUniqueInstance; pUniqueInstance = NULL; } SDL_UnlockMutex(mxInstance); // Unlocks the mutex... } void CommandScheduler::setServer(Server* myServer){ SDL_LockMutex(mxServer); this->myServer = myServer; // Sets the CommandManager Server. SDL_UnlockMutex(mxServer); }
CommandScheduler::CommandScheduler() :mxServer(SDL_CreateMutex()) { }
static boolean I_AVLoadVideo(const char *filename) { int i; int videoSize; int audioSize; char *filepath; // setup packet queues videoPacketQueue = I_AVAllocQueuePacket(); audioPacketQueue = I_AVAllocQueuePacket(); // setup audio queue audioQueue.mutex = SDL_CreateMutex(); audioQueue.first = NULL; userExit = false; videoFinished = false; audioFinished = false; audioPts = 0; videoClock = 0; audioClock = 0; // not exactly looking for a wad, but this function makes // it easier to find our movie file if(!(filepath = D_FindWADByName((char*)filename))) { return false; } if(avformat_open_input(&formatCtx, filepath, NULL, NULL)) { fprintf(stderr, "I_AVLoadVideo: Couldn't load %s\n", filepath); return false; } if(avformat_find_stream_info(formatCtx, NULL)) { fprintf(stderr, "I_AVLoadVideo: Couldn't find stream info\n"); return false; } #ifdef _DEBUG av_dump_format(formatCtx, 0, filepath, 0); #endif videoStreamIdx = -1; audioStreamIdx = -1; // find the video and audio stream for(i = 0; i < (int)formatCtx->nb_streams; i++) { switch(formatCtx->streams[i]->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: if(videoStreamIdx == -1) { videoStreamIdx = i; } break; case AVMEDIA_TYPE_AUDIO: if(audioStreamIdx == -1) { audioStreamIdx = i; } break; default: break; } } if(videoStreamIdx < 0) { fprintf(stderr, "I_AVLoadVideo: Couldn't find video stream\n"); return false; } if(!I_AVSetupCodecContext(&videoCodecCtx, &videoCodec, videoStreamIdx) || !I_AVSetupCodecContext(&audioCodecCtx, &audioCodec, audioStreamIdx)) { return false; } reqWidth = videoCodecCtx->width; reqHeight = videoCodecCtx->height; // setup texture texture.colorMode = TCR_RGB; texture.origwidth = reqWidth; texture.origheight = reqHeight; texture.width = texture.origwidth; texture.height = texture.origheight; FF_DISABLE_DEPRECATION_WARNINGS videoCodecCtx->get_buffer = I_AVGetBufferProc; videoCodecCtx->release_buffer = I_AVReleaseBufferProc; FF_ENABLE_DEPRECATION_WARNINGS videoFrame = av_frame_alloc(); videoSize = avpicture_get_size(AV_PIX_FMT_YUV444P, reqWidth, reqHeight); audioSize = MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE; videoBuffer = (uint8_t*)av_calloc(1, videoSize * sizeof(uint8_t)); audioBuffer = (uint8_t*)av_calloc(1, audioSize * sizeof(uint8_t)); RB_UploadTexture(&texture, videoBuffer, TC_CLAMP, TF_LINEAR); swsCtx = sws_getContext(videoCodecCtx->width, videoCodecCtx->height, videoCodecCtx->pix_fmt, reqWidth, reqHeight, AV_PIX_FMT_YUV444P, SWS_BICUBIC, NULL, NULL, NULL); // assign appropriate parts of buffer to image planes in videoFrame // Note that videoFrame is an AVFrame, but AVFrame is a superset // of AVPicture avpicture_fill((AVPicture*)videoFrame, videoBuffer, AV_PIX_FMT_YUV444P, reqWidth, reqHeight); currentPts = av_gettime(); frameTime = 1000.0 / av_q2d(videoCodecCtx->framerate); lastFrameTime = frameTime; return true; }
void rt_mq_system_init() { rt_list_init(&_mq_list); _mq_list_mutex = SDL_CreateMutex(); }
void init_queue(PacketQueue *queue) { memset(queue, 0, sizeof(PacketQueue)); queue->mutex = SDL_CreateMutex(); queue->cond = SDL_CreateCond(); }
int main(int argc, char **argv) { /* PacketQueue *a = av_mallocz(sizeof(PacketQueue)); AVPacket *p = av_mallocz(sizeof(AVPacket)); AVPacket *b = av_mallocz(sizeof(AVPacket)); add_to_queue(a, p); add_to_queue(a, p); add_to_queue(a, p); add_to_queue(a, p); get_from_queue(a, b); add_to_queue(a, p); get_from_queue(a, b); get_from_queue(a, b); get_from_queue(a, b); get_from_queue(a, b); av_free(a); av_free(p); */ FileState *file = av_mallocz(sizeof(FileState)); VideoState *video = av_mallocz(sizeof(VideoState)); AudioState *audio = av_mallocz(sizeof(AudioState)); State *state = av_mallocz(sizeof(State)); SDL_Thread *video_decode_tid; SDL_Thread *read_pkt_tid; SDL_Thread *play_tid; state->file = file; state->video = video; state->audio = audio; if(argc < 2) { fprintf(stderr, "Usage : play <file>\n"); exit(1); } av_register_all(); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } av_strlcpy(file->fileName, argv[1], sizeof(file->fileName)); video->vFrameqMutex = SDL_CreateMutex(); video->vFrameqCond = SDL_CreateCond(); get_file_info(file); find_av_streams(file, video, audio); //find_audio_decoder(audio); init_screen(video); read_pkt_tid = SDL_CreateThread(queue_av_pkt, state); init_frame(video); video_decode_tid = SDL_CreateThread(decode_video, video); /* video->frame_timer = (double)av_gettime() / 1000000.0; video->frame_last_delay = 40e-3; video->pCodecCtx->get_buffer = our_get_buffer; video->pCodecCtx->release_buffer = our_release_buffer;*/ // play_tid = SDL_CreateThread(play_video, video); while(true) { // decode_video(video); play_video(video); } sleep(10); if(!video_decode_tid) { av_free(video_decode_tid); return -1; } if(!read_pkt_tid) { av_free(read_pkt_tid); return -1; } return 0; }
int main(int argc, char *argv[]) { SDL_Event event; VideoState *is; int i; puts("start"); global_mutex_lock = SDL_CreateMutex(); is = av_mallocz(sizeof(VideoState)); if (argc < 2){ fprintf(stderr, "Usage: test <file>\n"); exit(1); } av_register_all(); // Register all formats and codecs puts("avregister"); //if (av_register_protocol(&e2URLProtocol) < 0){ // printf("Error - URL protocol \n"); // exit(-1) //} if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)){ fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } for(i=0; i<MAX_CHANNELS;i++){ // Make a screen to put our video #ifndef __DARWIN__ screen[i] = SDL_SetVideoMode(640, 480, 0, 0); #else screen[i] = SDL_SetVideoMode(640, 480, 24, 0); #endif if (!screen[i]){ fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); } } for(i=0; i<MAX_CHANNELS;i++){ global_video_state[i] = av_mallocz(sizeof(VideoState)); global_video_state[i]->videoIndex = i; puts("screen created"); printf("i is: %d\n",i); av_strlcpy(global_video_state[i]->filename, argv[i+1], sizeof(global_video_state[i]->filename)); puts("avstrlcpy"); global_video_state[i]->pictq_mutex = SDL_CreateMutex(); global_video_state[i]->pictq_cond = SDL_CreateCond(); schedule_refresh(global_video_state[i], 40); global_video_state[i]->av_sync_type = DEFAULT_AV_SYNC_TYPE; global_video_state[i]->parse_tid = SDL_CreateThread(decode_thread, global_video_state[i]); puts("main var created"); if (!global_video_state[i]->parse_tid) { av_free(global_video_state[i]); return -1; } } av_init_packet(&f_pkt); puts("av_init_packet"); f_pkt.data = (unsigned char*)"FLUSH"; for (;;) { double inc , pos; SDL_WaitEvent(&event); switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_LEFT: inc = -10.0; goto do_seek; case SDLK_RIGHT: inc = 10.0; goto do_seek; case SDLK_UP: inc = 60.0; goto do_seek; case SDLK_DOWN: inc = -60.0; goto do_seek; do_seek: SDL_LockMutex(global_mutex_lock); if (global_video_state[global_videoIndex]){ pos = get_master_clock(global_video_state[global_videoIndex]); pos += inc; stream_seek(global_video_state[global_videoIndex],(int64_t)(pos *AV_TIME_BASE),inc); } SDL_UnlockMutex(global_mutex_lock); break; case SDLK_b: global_video_state[global_videoIndex]->color_req = 'b'; break; case SDLK_r: global_video_state[global_videoIndex]->color_req = 'r'; break; case SDLK_g: global_video_state[global_videoIndex]->color_req = 'g'; break; case SDLK_w: global_video_state[global_videoIndex]->color_req = 'w'; break; case SDLK_n: global_video_state[global_videoIndex]->color_req = 'n'; break; case SDLK_1: change_channel(1); break; case SDLK_2: change_channel(2); break; case SDLK_3: change_channel(3); break; case SDLK_4: change_vidchannel(1); break; case SDLK_5: change_vidchannel(2); break; case SDLK_6: change_vidchannel(3); break; case SDLK_7: change_audchannel(1); break; case SDLK_8: change_audchannel(2); break; case SDLK_9: change_audchannel(3); break; default: break; } break; case FF_QUIT_EVENT: case SDL_QUIT: for(i=0; i<MAX_CHANNELS; i++){ global_video_state[i]->quit = 1; SDL_CondSignal(global_video_state[i]->audioq.cond); SDL_CondSignal(global_video_state[i]->videoq.cond); } SDL_Quit(); exit(0); break; case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); break; default: break; } } return 0; }
SDL_assert_state SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file, int line) { static int assertion_running = 0; static SDL_SpinLock spinlock = 0; SDL_assert_state state = SDL_ASSERTION_IGNORE; SDL_AtomicLock(&spinlock); if (assertion_mutex == NULL) { /* never called SDL_Init()? */ assertion_mutex = SDL_CreateMutex(); if (assertion_mutex == NULL) { SDL_AtomicUnlock(&spinlock); return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ } } SDL_AtomicUnlock(&spinlock); if (SDL_LockMutex(assertion_mutex) < 0) { return SDL_ASSERTION_IGNORE; /* oh well, I guess. */ } /* doing this because Visual C is upset over assigning in the macro. */ if (data->trigger_count == 0) { data->function = func; data->filename = file; data->linenum = line; } SDL_AddAssertionToReport(data); data->trigger_count++; assertion_running++; if (assertion_running > 1) { /* assert during assert! Abort. */ if (assertion_running == 2) { SDL_AbortAssertion(); } else if (assertion_running == 3) { /* Abort asserted! */ SDL_ExitProcess(42); } else { while (1) { /* do nothing but spin; what else can you do?! */ } } } if (!data->always_ignore) { state = assertion_handler(data, assertion_userdata); } switch (state) { case SDL_ASSERTION_ABORT: SDL_AbortAssertion(); return SDL_ASSERTION_IGNORE; /* shouldn't return, but oh well. */ case SDL_ASSERTION_ALWAYS_IGNORE: state = SDL_ASSERTION_IGNORE; data->always_ignore = 1; break; case SDL_ASSERTION_IGNORE: case SDL_ASSERTION_RETRY: case SDL_ASSERTION_BREAK: break; /* macro handles these. */ } assertion_running--; SDL_UnlockMutex(assertion_mutex); return state; }
bool VideoPlayer::initPlayer(string mediaURL) { if(VideoPlayer::disabled == true) { return true; } #ifdef HAS_LIBVLC ctxPtr->libvlc = NULL; ctxPtr->m = NULL; ctxPtr->mp = NULL; ctxPtr->vlc_argv.clear(); ctxPtr->vlc_argv.push_back("--intf=dummy"); //ctxPtr->vlc_argv.push_back("--intf=http"); //ctxPtr->vlc_argv.push_back("--no-media-library"); ctxPtr->vlc_argv.push_back("--ignore-config"); /* Don't use VLC's config */ ctxPtr->vlc_argv.push_back("--no-xlib"); /* tell VLC to not use Xlib */ ctxPtr->vlc_argv.push_back("--no-video-title-show"); //ctxPtr->vlc_argv.push_back("--network-caching=10000"); if(loop == true) { ctxPtr->vlc_argv.push_back("--loop"); ctxPtr->vlc_argv.push_back("--repeat"); } #if defined(LIBVLC_VERSION_PRE_2) ctxPtr->vlc_argv_str.push_back("--plugin-path=" + pluginsPath); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); #endif #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0) char clock[64], cunlock[64], cdata[64]; char cwidth[32], cheight[32], cpitch[32]; /* * Initialise libVLC */ sprintf(clock, "%lld", (long long int)(intptr_t)lock); sprintf(cunlock, "%lld", (long long int)(intptr_t)unlock); sprintf(cdata, "%lld", (long long int)(intptr_t)ctxPtr); sprintf(cwidth, "%i", width); sprintf(cheight, "%i", height); sprintf(cpitch, "%i", colorBits); vlc_argv.push_back("--vout"); vlc_argv.push_back("vmem"); vlc_argv.push_back("--vmem-width"); ctxPtr->vlc_argv_str.push_back(cwidth); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); vlc_argv.push_back("--vmem-height"); ctxPtr->vlc_argv_str.push_back(cheight); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); vlc_argv.push_back("--vmem-pitch"); ctxPtr->vlc_argv_str.push_back(cpitch); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); vlc_argv.push_back("--vmem-chroma"); vlc_argv.push_back("RV16"); vlc_argv.push_back("--vmem-lock"); ctxPtr->vlc_argv_str.push_back(clock); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); vlc_argv.push_back("--vmem-unlock"); ctxPtr->vlc_argv_str.push_back(cunlock); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); vlc_argv.push_back("--vmem-data"); ctxPtr->vlc_argv_str.push_back(cdata); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); #endif if(verboseEnabled) ctxPtr->vlc_argv.push_back("--verbose=2"); if(verboseEnabled) ctxPtr->vlc_argv.push_back("--extraintf=logger"); //log anything #if defined(WIN32) if(verboseEnabled) _putenv("VLC_VERBOSE=2"); #endif // char const *vlc_argv[] = // { // //"--no-audio", /* skip any audio track */ // "--no-xlib", /* tell VLC to not use Xlib */ // "--no-video-title-show", // pluginParam.c_str(), // }; // int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv); #endif ctxPtr->empty = NULL; glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); // Init Texture glGenTextures(1, &ctxPtr->textureId); glBindTexture(GL_TEXTURE_2D, ctxPtr->textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ctxPtr->empty = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, colorBits, 0, 0, 0, 0); ctxPtr->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, colorBits, 0x001f, 0x07e0, 0xf800, 0); ctxPtr->mutex = SDL_CreateMutex(); #ifdef HAS_LIBVLC /* * Initialize libVLC */ if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH")); #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0) libvlc_exception_t ex; libvlc_exception_init(&ex); ctxPtr->libvlc = libvlc_new(ctxPtr->vlc_argc, &ctxPtr->vlc_argv[0],&ex); catchError(&ex); #else int vlc_argc = ctxPtr->vlc_argv.size(); ctxPtr->libvlc = libvlc_new(vlc_argc, &ctxPtr->vlc_argv[0]); #endif if(verboseEnabled) printf("In [%s] Line: %d, libvlc [%p]\n",__FUNCTION__,__LINE__,ctxPtr->libvlc); /* It is meaningless to try all this because we have to restart mg to pickup new env vars #if defined(WIN32) if(libvlc == NULL) { // For windows check registry for install path std::string strValue = getRegKey("Software\\VideoLAN\\VLC", "InstallDir"); if(strValue != "") { if(strValue.length() >= 2) { if(strValue[0] == '"') { strValue = strValue.erase(0); } if(strValue[strValue.length()-1] == '"') { strValue = strValue.erase(strValue.length()-1); } } strValue = "VLC_PLUGIN_PATH=" + strValue; _putenv(strValue.c_str()); if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH")); libvlc = libvlc_new(vlc_argc, &vlc_argv[0]); } if(libvlc == NULL) { _putenv("VLC_PLUGIN_PATH=c:\\program files\\videolan\\vlc\\plugins"); if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH")); libvlc = libvlc_new(vlc_argc, &vlc_argv[0]); } if(libvlc == NULL) { _putenv("VLC_PLUGIN_PATH=\\program files\\videolan\\vlc\\plugins"); if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH")); libvlc = libvlc_new(vlc_argc, &vlc_argv[0]); } if(libvlc == NULL) { _putenv("VLC_PLUGIN_PATH=c:\\program files (x86)\\videolan\\vlc\\plugins"); if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH")); libvlc = libvlc_new(vlc_argc, &vlc_argv[0]); } if(libvlc == NULL) { _putenv("VLC_PLUGIN_PATH=\\program files (x86)\\videolan\\vlc\\plugins"); if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH")); libvlc = libvlc_new(vlc_argc, &vlc_argv[0]); } } #endif */ if(ctxPtr->libvlc != NULL) { #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0) ctxPtr->m = libvlc_media_new(ctxPtr->libvlc, mediaURL.c_str(), &ex); if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m); catchError(&ex); ctxPtr->mp = libvlc_media_player_new_from_media(ctxPtr->m); if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,ctxPtr->mp); libvlc_media_release(ctxPtr->m); #else if(mediaURL.find(HTTP_PREFIX) == 0) { ctxPtr->mlp = libvlc_media_list_player_new(ctxPtr->libvlc); ctxPtr->ml = libvlc_media_list_new(ctxPtr->libvlc); ctxPtr->m = libvlc_media_new_location(ctxPtr->libvlc, mediaURL.c_str()); libvlc_media_list_add_media(ctxPtr->ml, ctxPtr->m); } else { ctxPtr->m = libvlc_media_new_path(ctxPtr->libvlc, mediaURL.c_str()); } /* Create a new item */ if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m); if(loop == true) { libvlc_media_add_option(ctxPtr->m, "input-repeat=-1"); } if(mediaURL.find(HTTP_PREFIX) == 0) { ctxPtr->mp = libvlc_media_player_new(ctxPtr->libvlc); } else { ctxPtr->mp = libvlc_media_player_new_from_media(ctxPtr->m); } if(verboseEnabled) printf("In [%s] Line: %d, mp [%p]\n",__FUNCTION__,__LINE__,ctxPtr->mp); libvlc_media_player_set_media(ctxPtr->mp, ctxPtr->m); libvlc_media_release(ctxPtr->m); if(mediaURL.find(HTTP_PREFIX) == 0) { // Use our media list libvlc_media_list_player_set_media_list(ctxPtr->mlp, ctxPtr->ml); // Use a given media player libvlc_media_list_player_set_media_player(ctxPtr->mlp, ctxPtr->mp); } // Get an event manager for the media player. if(mediaURL.find(HTTP_PREFIX) == 0) { libvlc_event_manager_t *eventManager = libvlc_media_list_player_event_manager(ctxPtr->mlp); if(eventManager) { // libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying, (libvlc_callback_t)trapPlayingEvent, NULL, &ex); // libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapEndReachedEvent, NULL, &ex); // libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering, (libvlc_callback_t)trapBufferingEvent, NULL, &ex); // libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapErrorEvent, NULL, &ex); int event_added = libvlc_event_attach( eventManager, libvlc_MediaListPlayerNextItemSet, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaListPlayerNextItemSet]\n"); } } } //else { //libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(mp, &ex); libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(ctxPtr->mp); if(eventManager) { int event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerSnapshotTaken, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerSnapshotTaken]\n"); } // event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerTimeChanged, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerTimeChanged]\n"); // } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerPlaying, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerPlaying]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerPaused, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerPaused]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerStopped, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerStopped]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerEndReached, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerEndReached]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerPositionChanged, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerPositionChanged]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerLengthChanged, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerLengthChanged]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerEncounteredError,callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerEncounteredError]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerPausableChanged, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerPausableChanged]\n"); } event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerSeekableChanged, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerSeekableChanged]\n"); } // event_added = libvlc_event_attach( eventManager, libvlc_MediaStateChanged, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaStateChanged]\n"); // } // event_added = libvlc_event_attach( eventManager, libvlc_MediaParsedChanged, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaParsedChanged]\n"); // } #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0) event_added = libvlc_event_attach( eventManager, libvlc_MediaPlayerVout, callbacks, ctxPtr ); if(event_added != 0) { printf("ERROR CANNOT ADD EVENT [libvlc_MediaPlayerVout]\n"); } #endif // event_added = libvlc_event_attach( eventManager, libvlc_MediaListItemAdded, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListItemAdded]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListWillAddItem, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListWillAddItem]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListItemDeleted, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListItemDeleted]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListWillDeleteItem, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListWillDeleteItem]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListViewItemAdded, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListViewItemAdded]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListViewWillAddItem, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListViewWillAddItem]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListViewItemDeleted, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListViewItemDeleted]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListViewWillDeleteItem, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListViewWillDeleteItem]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListPlayerPlayed, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListPlayerPlayed]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListPlayerNextItemSet, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListPlayerNextItemSet]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaListPlayerStopped, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaListPlayerStopped]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaDiscovererStarted, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaDiscovererStarted]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_MediaDiscovererEnded, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_MediaDiscovererEnded]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaAdded, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaAdded]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaRemoved, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaRemoved]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaChanged, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaChanged]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStarted, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStarted]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStopped, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStopped]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStatusInit, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStatusInit]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStatusOpening, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStatusOpening]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStatusPlaying, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStatusPlaying]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStatusPause, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStatusPause]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStatusEnd, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStatusEnd]\n"); // } // // event_added = libvlc_event_attach( eventManager, libvlc_VlmMediaInstanceStatusError, callbacks, ctxPtr ); // if(event_added != 0) { // printf("ERROR CANNOT ADD EVENT [libvlc_VlmMediaInstanceStatusError]\n"); // } } //} //libvlc_media_release(ctxPtr->m); #endif #if !defined(LIBVLC_VERSION_PRE_2) && !defined(LIBVLC_VERSION_PRE_1_1_0) libvlc_video_set_callbacks(ctxPtr->mp, lock, unlock, display, ctxPtr); libvlc_video_set_format(ctxPtr->mp, "RV16", width, height, SDL_GetWindowSurface(this->window)->pitch); #endif ctxPtr->isPlaying = true; #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_0) int play_result = libvlc_media_player_play(ctxPtr->mp,&ex); #else int play_result = 0; if(mediaURL.find(HTTP_PREFIX) == 0) { libvlc_media_list_player_play(ctxPtr->mlp); } else { play_result = libvlc_media_player_play(ctxPtr->mp); } // Play //int play_result = 0; //libvlc_media_list_player_play(ctxPtr->mlp); #endif //SDL_Delay(5); if(verboseEnabled) printf("In [%s] Line: %d, play_result [%d]\n",__FUNCTION__,__LINE__,play_result); successLoadingLib = (play_result == 0); } #endif return successLoadingLib; }
Event::Event(void) { mut = SDL_CreateMutex(); cond = SDL_CreateCond(); triggered = false; }
IJKFF_Pipenode *ffpipenode_create_video_decoder_from_android_mediacodec(FFPlayer *ffp, IJKFF_Pipeline *pipeline, SDL_Vout *vout) { ALOGD("ffpipenode_create_video_decoder_from_android_mediacodec()\n"); if (SDL_Android_GetApiLevel() < IJK_API_16_JELLY_BEAN) return NULL; if (!ffp || !ffp->is) return NULL; IJKFF_Pipenode *node = ffpipenode_alloc(sizeof(IJKFF_Pipenode_Opaque)); if (!node) return node; VideoState *is = ffp->is; IJKFF_Pipenode_Opaque *opaque = node->opaque; JNIEnv *env = NULL; int ret = 0; node->func_destroy = func_destroy; node->func_run_sync = func_run_sync; opaque->pipeline = pipeline; opaque->ffp = ffp; opaque->decoder = &is->viddec; opaque->weak_vout = vout; opaque->avctx = opaque->decoder->avctx; switch (opaque->avctx->codec_id) { case AV_CODEC_ID_H264: strcpy(opaque->mcc.mime_type, SDL_AMIME_VIDEO_AVC); opaque->mcc.profile = opaque->avctx->profile; opaque->mcc.level = opaque->avctx->level; break; default: ALOGE("%s:create: not H264\n", __func__); goto fail; } if (JNI_OK != SDL_JNI_SetupThreadEnv(&env)) { ALOGE("%s:create: SetupThreadEnv failed\n", __func__); goto fail; } opaque->acodec_mutex = SDL_CreateMutex(); opaque->acodec_cond = SDL_CreateCond(); opaque->acodec_first_dequeue_output_mutex = SDL_CreateMutex(); opaque->acodec_first_dequeue_output_cond = SDL_CreateCond(); ffp_packet_queue_init(&opaque->fake_pictq); ffp_packet_queue_start(&opaque->fake_pictq); if (!opaque->acodec_cond || !opaque->acodec_cond || !opaque->acodec_first_dequeue_output_mutex || !opaque->acodec_first_dequeue_output_cond) { ALOGE("%s:open_video_decoder: SDL_CreateCond() failed\n", __func__); goto fail; } ALOGI("AMediaFormat: %s, %dx%d\n", opaque->mcc.mime_type, opaque->avctx->width, opaque->avctx->height); opaque->input_aformat = SDL_AMediaFormatJava_createVideoFormat(env, opaque->mcc.mime_type, opaque->avctx->width, opaque->avctx->height); if (opaque->avctx->extradata && opaque->avctx->extradata_size > 0) { if (opaque->avctx->codec_id == AV_CODEC_ID_H264 && opaque->avctx->extradata[0] == 1) { #if AMC_USE_AVBITSTREAM_FILTER opaque->bsfc = av_bitstream_filter_init("h264_mp4toannexb"); if (!opaque->bsfc) { ALOGE("Cannot open the h264_mp4toannexb BSF!\n"); goto fail; } opaque->orig_extradata_size = opaque->avctx->extradata_size; opaque->orig_extradata = (uint8_t*) av_mallocz(opaque->avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!opaque->orig_extradata) { goto fail; } memcpy(opaque->orig_extradata, opaque->avctx->extradata, opaque->avctx->extradata_size); for(int i = 0; i < opaque->avctx->extradata_size; i+=4) { ALOGE("csd-0[%d]: %02x%02x%02x%02x\n", opaque->avctx->extradata_size, (int)opaque->avctx->extradata[i+0], (int)opaque->avctx->extradata[i+1], (int)opaque->avctx->extradata[i+2], (int)opaque->avctx->extradata[i+3]); } SDL_AMediaFormat_setBuffer(opaque->input_aformat, "csd-0", opaque->avctx->extradata, opaque->avctx->extradata_size); #else size_t sps_pps_size = 0; size_t convert_size = opaque->avctx->extradata_size + 20; uint8_t *convert_buffer = (uint8_t *)calloc(1, convert_size); if (!convert_buffer) { ALOGE("%s:sps_pps_buffer: alloc failed\n", __func__); goto fail; } if (0 != convert_sps_pps(opaque->avctx->extradata, opaque->avctx->extradata_size, convert_buffer, convert_size, &sps_pps_size, &opaque->nal_size)) { ALOGE("%s:convert_sps_pps: failed\n", __func__); goto fail; } SDL_AMediaFormat_setBuffer(opaque->input_aformat, "csd-0", convert_buffer, sps_pps_size); for(int i = 0; i < sps_pps_size; i+=4) { ALOGE("csd-0[%d]: %02x%02x%02x%02x\n", (int)sps_pps_size, (int)convert_buffer[i+0], (int)convert_buffer[i+1], (int)convert_buffer[i+2], (int)convert_buffer[i+3]); } free(convert_buffer); #endif } else { // Codec specific data // SDL_AMediaFormat_setBuffer(opaque->aformat, "csd-0", opaque->avctx->extradata, opaque->avctx->extradata_size); ALOGE("csd-0: naked\n"); } } else { ALOGE("no buffer(%d)\n", opaque->avctx->extradata_size); } ret = reconfigure_codec_l(env, node); if (ret != 0) goto fail; ffp_set_video_codec_info(ffp, MEDIACODEC_MODULE_NAME, opaque->mcc.codec_name); opaque->off_buf_out = 0; if (opaque->n_buf_out) { int i; opaque->amc_buf_out = calloc(opaque->n_buf_out, sizeof(*opaque->amc_buf_out)); assert(opaque->amc_buf_out != NULL); for (i = 0; i < opaque->n_buf_out; i++) opaque->amc_buf_out[i].pts = AV_NOPTS_VALUE; } return node; fail: ffpipenode_free_p(&node); return NULL; }
static int OPL_SDL_Init(unsigned int port_base) { // Check if SDL_mixer has been opened already // If not, we must initialize it now if (!SDLIsInitialized()) { if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Unable to set up sound.\n"); return 0; } if (Mix_OpenAudio(opl_sample_rate, AUDIO_S16SYS, 2, GetSliceSize()) < 0) { fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError()); SDL_QuitSubSystem(SDL_INIT_AUDIO); return 0; } SDL_PauseAudio(0); // When this module shuts down, it has the responsibility to // shut down SDL. sdl_was_initialized = 1; } else { sdl_was_initialized = 0; } opl_sdl_paused = 0; pause_offset = 0; // Queue structure of callbacks to invoke. callback_queue = OPL_Queue_Create(); current_time = 0; // Get the mixer frequency, format and number of channels. Mix_QuerySpec(&mixing_freq, &mixing_format, &mixing_channels); // Only supports AUDIO_S16SYS if (mixing_format != AUDIO_S16SYS || mixing_channels != 2) { fprintf(stderr, "OPL_SDL only supports native signed 16-bit LSB, " "stereo format!\n"); OPL_SDL_Shutdown(); return 0; } // Mix buffer: mix_buffer = malloc(mixing_freq * sizeof(uint32_t) * 2); // Create the emulator structure: OPL3_Reset(&opl_chip, mixing_freq); opl_opl3mode = 0; callback_mutex = SDL_CreateMutex(); callback_queue_mutex = SDL_CreateMutex(); // TODO: This should be music callback? or-? Mix_HookMusic(OPL_Mix_Callback, NULL); return 1; }
int main(int argc, char*argv[]) { if (argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) { usage(); return 0; } signal( SIGINT, &onExit); ftime(&startTime); av_register_all(); paused = 0; // Create space for all the video data VideoState *is; is = av_mallocz(sizeof(VideoState)); // Set up SDL window SDL_Event event; memset(&event, 0, sizeof(SDL_Event)); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(640, 480, 24, 0); if(!screen) { fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); } char * name = malloc(16); if(argc > 1){ strcpy(name, argv[1]); } else { printf("Enter target name of the server: "); scanf("%s", name); } char * ip = nameserver_init(name); free(name); // Get the audio & video stream information parse_nameserver_msg(ip); global_video_state = is; //init_gis(global_video_state); init_gis(is); establish_peer_connections(); //control_packet* cp = read_control_packet(); // Initialize the audio & video streams /* stream_component_open(global_video_state, &cp->audio_codec_ctx); printf("[PLAYER] Opened Audio stream\n"); stream_component_open(global_video_state, &cp->video_codec_ctx); printf("[PLAYER] Opened Video stream\n"); */ is->quit = 0; // Create thread locks is->pictq_mutex = SDL_CreateMutex(); is->pictq_cond = SDL_CreateCond(); schedule_refresh(is, 40); // Create the decode thread is->parse_tid = SDL_CreateThread(decode_thread, is); printf("[PLAYER] SDL intialized\n"); /* if(!is->parse_tid) { av_free(is); return -1; } */ pthread_create(&keyboard_thread_id, NULL, captureKeyboard, NULL); pthread_create(&stats_thread_id, NULL, calculate_player_stats, NULL); // printf("[PLAYER] Keyboard thread :%d\n", keyboard_thread_id); // while(global_video_state->quit == 0) while(1) { SDL_WaitEvent(&event); switch(event.type) { // Done decoding case FF_QUIT_EVENT: case SDL_QUIT: is->quit = 1; exit(0); break; // Get frame case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; // Refresh screen case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); break; default: break; } } printf("Frames per second: %i\n", 5); printf("[MAIN] Quit player\n"); return 0; }
void *SDLStub::createMutex() { return SDL_CreateMutex(); }
bor_mutex *mutex_create(void) { return SDL_CreateMutex(); }
void *System_CreateMutex() { return SDL_CreateMutex(); }
SDL_VoutOverlay *SDL_VoutFFmpeg_CreateOverlay(int width, int height, Uint32 format, SDL_Vout *display) { SDLTRACE("SDL_VoutFFmpeg_CreateOverlay(w=%d, h=%d, fmt=%.4s(0x%x, dp=%p)", width, height, (const char*) &format, format, display); SDL_VoutOverlay *overlay = SDL_VoutOverlay_CreateInternal(sizeof(SDL_VoutOverlay_Opaque)); if (!overlay) { ALOGE("overlay allocation failed"); return NULL; } SDL_VoutOverlay_Opaque *opaque = overlay->opaque; overlay->format = format; overlay->pitches = opaque->pitches; overlay->pixels = opaque->pixels; overlay->w = width; overlay->h = height; enum AVPixelFormat ff_format = AV_PIX_FMT_NONE; int buf_width = width; int buf_height = height; switch (format) { case SDL_FCC_I420: case SDL_FCC_YV12: { ff_format = AV_PIX_FMT_YUV420P; // FIXME: need runtime config #if defined(__ANDROID__) // 16 bytes align pitch for arm-neon image-convert buf_width = IJKALIGN(width, 16); // 1 bytes per pixel for Y-plane #elif defined(__APPLE__) // 2^n align for width buf_width = width; if (width > 0) buf_width = 1 << (sizeof(int) * 8 - __builtin_clz(width)); #else buf_width = IJKALIGN(width, 16); // unknown platform #endif opaque->planes = 3; break; } case SDL_FCC_RV16: { ff_format = AV_PIX_FMT_RGB565; buf_width = IJKALIGN(width, 8); // 2 bytes per pixel opaque->planes = 1; break; } case SDL_FCC_RV24: { ff_format = AV_PIX_FMT_RGB24; #if defined(__ANDROID__) // 16 bytes align pitch for arm-neon image-convert buf_width = IJKALIGN(width, 16); // 1 bytes per pixel for Y-plane #elif defined(__APPLE__) buf_width = width; #else buf_width = IJKALIGN(width, 16); // unknown platform #endif opaque->planes = 1; break; } case SDL_FCC_RV32: { ff_format = AV_PIX_FMT_0BGR32; buf_width = IJKALIGN(width, 4); // 4 bytes per pixel opaque->planes = 1; break; } default: ALOGE("SDL_VoutFFmpeg_CreateOverlay(...): unknown format %.4s(0x%x)", (char*)&format, format); goto fail; } opaque->frame = alloc_avframe(opaque, ff_format, buf_width, buf_height); if (!opaque->frame) { ALOGE("overlay->opaque->frame allocation failed"); goto fail; } opaque->mutex = SDL_CreateMutex(); overlay_fill(overlay, opaque->frame, opaque->planes); overlay->free_l = overlay_free_l; overlay->lock = overlay_lock; overlay->unlock = overlay_unlock; return overlay; fail: overlay_free_l(overlay); return NULL; }
/** * @brief Initializes the music subsystem. * * @return 0 on success. */ int music_init (void) { if (music_disabled) return 0; if ((conf.sound_backend != NULL) && (strcmp(conf.sound_backend,"sdlmix")==0)) { #if USE_SDLMIX /* * SDL_mixer backend. */ /* Init/exit. */ music_sys_init = music_mix_init; music_sys_exit = music_mix_exit; /* Loading. */ music_sys_load = music_mix_load; music_sys_free = music_mix_free; /* Music control. */ music_sys_volume = music_mix_volume; music_sys_getVolume = music_mix_getVolume; music_sys_load = music_mix_load; music_sys_play = music_mix_play; music_sys_stop = music_mix_stop; music_sys_pause = music_mix_pause; music_sys_resume = music_mix_resume; music_sys_setPos = music_mix_setPos; music_sys_isPlaying = music_mix_isPlaying; #else /* USE_SDLMIX */ WARN("SDL_mixer support not compiled in!"); return -1; #endif /* USE_SDLMIX */ } else if ((conf.sound_backend != NULL) && (strcmp(conf.sound_backend,"openal")==0)) { #if USE_OPENAL /* * OpenAL backend. */ /* Init/exit. */ music_sys_init = music_al_init; music_sys_exit = music_al_exit; /* Loading. */ music_sys_load = music_al_load; music_sys_free = music_al_free; /* Music control. */ music_sys_volume = music_al_volume; music_sys_getVolume = music_al_getVolume; music_sys_load = music_al_load; music_sys_play = music_al_play; music_sys_stop = music_al_stop; music_sys_pause = music_al_pause; music_sys_resume = music_al_resume; music_sys_setPos = music_al_setPos; music_sys_isPlaying = music_al_isPlaying; #else /* USE_OPENAL */ WARN("OpenAL support not compiled in!"); return -1; #endif /* USE_OPENAL*/ } else { WARN("Unknown sound backend '%s'.", conf.sound_backend); return -1; } /* Start the subsystem. */ if (music_sys_init()) return -1; /* Load the music. */ if (music_find() < 0) return -1; /* Start up Lua. */ if (music_luaInit() < 0) return -1; /* Set the volume. */ if ((conf.music > 1.) || (conf.music < 0.)) WARN("Music has invalid value, clamping to [0:1]."); music_volume(conf.music); /* Create the lock. */ music_lock = SDL_CreateMutex(); return 0; }
void SV_LogInit (void) { const size_t svHunkSize = 32768; svLogMutex = SDL_CreateMutex(); svLogHunk = STRHUNK_Create(svHunkSize); }
void packet_queue_init(PacketQueue *q) { memset(q, 0, sizeof(PacketQueue)); q->mutex = SDL_CreateMutex(); q->cond = SDL_CreateCond(); }
int VGL_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i; int total_modes; VGLMode **modes; /* Initialize all variables that we clean on shutdown */ for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_nummodes[i] = 0; SDL_modelist[i] = NULL; } /* Enable mouse and keyboard support */ if (SDL_getenv("SDL_NO_RAWKBD") == NULL) { if (VGLKeyboardInit(VGL_CODEKEYS) != 0) { SDL_SetError("Unable to initialize keyboard"); return -1; } } else { warnx("Requiest to put keyboard into a raw mode ignored"); } if (VGL_initkeymaps(STDIN_FILENO) != 0) { SDL_SetError("Unable to initialize keymap"); return -1; } if (VGL_initmouse(STDIN_FILENO) != 0) { SDL_SetError("Unable to initialize mouse"); return -1; } /* Determine the current screen size */ if (VGLCurMode != NULL) { this->info.current_w = VGLCurMode->ModeInfo.Xsize; this->info.current_h = VGLCurMode->ModeInfo.Ysize; } /* Determine the screen depth */ if (VGLCurMode != NULL) vformat->BitsPerPixel = VGLCurMode->Depth; else vformat->BitsPerPixel = 16; /* Good default */ /* Query for the list of available video modes */ total_modes = 0; modes = VGLListModes(-1, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); for (i = 0; modes[i] != NULL; i++) { if ((modes[i]->ModeInfo.Type == VIDBUF8) || (modes[i]->ModeInfo.Type == VIDBUF16) || (modes[i]->ModeInfo.Type == VIDBUF32)) { VGL_AddMode(this, modes[i]); total_modes++; } } if (total_modes == 0) { SDL_SetError("No linear video modes available"); return -1; } /* Fill in our hardware acceleration capabilities */ VGL_UpdateVideoInfo(this); /* Create the hardware surface lock mutex */ hw_lock = SDL_CreateMutex(); if (hw_lock == NULL) { SDL_SetError("Unable to create lock mutex"); VGL_VideoQuit(this); return -1; } /* We're done! */ return 0; }
int main(int argc, char *argv[]) { SDL_Event event; VideoState *is; is = av_mallocz(sizeof(VideoState)); if(argc < 2) { fprintf(stderr, "Usage: test <file>\n"); exit(1); } // Register all formats and codecs av_register_all(); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } // Make a screen to put our video #ifndef __DARWIN__ screen = SDL_SetVideoMode(640, 480, 0, 0); #else screen = SDL_SetVideoMode(640, 480, 24, 0); #endif if(!screen) { fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); } pstrcpy(is->filename, sizeof(is->filename), argv[1]); is->pictq_mutex = SDL_CreateMutex(); is->pictq_cond = SDL_CreateCond(); schedule_refresh(is, 40); is->parse_tid = SDL_CreateThread(decode_thread, is); if(!is->parse_tid) { av_free(is); return -1; } for(;;) { SDL_WaitEvent(&event); switch(event.type) { case FF_QUIT_EVENT: case SDL_QUIT: is->quit = 1; SDL_Quit(); return 0; break; case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); break; default: break; } } return 0; }