Skip to content
Snippets Groups Projects
ffplay.c 98.9 KiB
Newer Older
  • Learn to ignore specific revisions
  •                  AV_OPT_FLAG_ENCODING_PARAM, 0);
    #endif
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        printf("\nWhile playing:\n"
               "q, ESC              quit\n"
               "f                   toggle full screen\n"
               "p, SPC              pause\n"
    
               "a                   cycle audio channel\n"
               "v                   cycle video channel\n"
    
               "s                   activate frame-step mode\n"
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
               "left/right          seek backward/forward 10 seconds\n"
               "down/up             seek backward/forward 1 minute\n"
    
               "mouse click         seek to percentage in file corresponding to fraction of width\n"
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
               );
    
    static int lockmgr(void **mtx, enum AVLockOp op)
    {
       switch(op) {
          case AV_LOCK_CREATE:
              *mtx = SDL_CreateMutex();
              if(!*mtx)
                  return 1;
              return 0;
          case AV_LOCK_OBTAIN:
              return !!SDL_LockMutex(*mtx);
          case AV_LOCK_RELEASE:
              return !!SDL_UnlockMutex(*mtx);
          case AV_LOCK_DESTROY:
              SDL_DestroyMutex(*mtx);
              return 0;
       }
       return 1;
    }
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    /* Called from the main */
    int main(int argc, char **argv)
    {
    
        av_log_set_flags(AV_LOG_SKIP_REPEATED);
    
        parse_loglevel(argc, argv, options);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        /* register all codecs, demux and protocols */
    
    Luca Abeni's avatar
    Luca Abeni committed
        avcodec_register_all();
    
    Luca Abeni's avatar
    Luca Abeni committed
        avdevice_register_all();
    
    #if CONFIG_AVFILTER
        avfilter_register_all();
    #endif
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        av_register_all();
    
    
        parse_options(NULL, argc, argv, options, opt_input_file);
    
            fprintf(stderr, "An input file must be specified\n");
    
    Anton Khirnov's avatar
    Anton Khirnov committed
            fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'\n", program_name);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
        if (display_disable) {
            video_disable = 1;
        }
    
        flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
    
        if (audio_disable)
            flags &= ~SDL_INIT_AUDIO;
    
    #if !defined(__MINGW32__) && !defined(__APPLE__)
        flags |= SDL_INIT_EVENTTHREAD; /* Not supported on Windows or Mac OS X */
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        if (SDL_Init (flags)) {
    
            fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
    
            fprintf(stderr, "(Did you set the DISPLAY variable?)\n");
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            exit(1);
        }
    
        if (!display_disable) {
    
    #if HAVE_SDL_VIDEO_SIZE
    
            const SDL_VideoInfo *vi = SDL_GetVideoInfo();
            fs_screen_width = vi->current_w;
            fs_screen_height = vi->current_h;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        }
    
        SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
        SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
        SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
    
    
        if (av_lockmgr_register(lockmgr)) {
            fprintf(stderr, "Could not initialize lock manager!\n");
            do_exit(NULL);
        }
    
    
        av_init_packet(&flush_pkt);
        flush_pkt.data= "FLUSH";
    
    
        is = stream_open(input_filename, file_iformat);
        if (!is) {
            fprintf(stderr, "Failed to initialize VideoState!\n");
            do_exit(NULL);
        }
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
        /* never returns */
    
        return 0;
    }