avplay: Statically allocate the player state

And move the resource deallocation in stream_open failure path.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
pull/178/head
Luca Barbato 9 years ago
parent 611ba89b89
commit 6fa464f8d2
  1. 35
      avplay.c

@ -270,7 +270,8 @@ static int autorotate = 1;
/* current context */ /* current context */
static int is_full_screen; static int is_full_screen;
static PlayerState *player; static PlayerState player_state;
static PlayerState *player = &player_state;
static int64_t audio_callback_time; static int64_t audio_callback_time;
static AVPacket flush_pkt; static AVPacket flush_pkt;
@ -1229,7 +1230,6 @@ static void player_close(PlayerState *is)
if (is->img_convert_ctx) if (is->img_convert_ctx)
sws_freeContext(is->img_convert_ctx); sws_freeContext(is->img_convert_ctx);
#endif #endif
av_free(is);
} }
static void do_exit(void) static void do_exit(void)
@ -2399,8 +2399,6 @@ static int stream_setup(PlayerState *is)
return 0; return 0;
fail: fail:
stream_close(is);
return ret; return ret;
} }
@ -2541,21 +2539,18 @@ fail:
return 0; return 0;
} }
static PlayerState *stream_open(const char *filename, AVInputFormat *iformat) static int stream_open(PlayerState *is,
const char *filename, AVInputFormat *iformat)
{ {
PlayerState *is; int ret;
is = av_mallocz(sizeof(PlayerState));
if (!is)
return NULL;
av_strlcpy(is->filename, filename, sizeof(is->filename)); av_strlcpy(is->filename, filename, sizeof(is->filename));
is->iformat = iformat; is->iformat = iformat;
is->ytop = 0; is->ytop = 0;
is->xleft = 0; is->xleft = 0;
if (stream_setup(is) < 0) { if ((ret = stream_setup(is)) < 0) {
av_free(is); return ret;
return NULL;
} }
/* start video display */ /* start video display */
@ -2567,12 +2562,12 @@ static PlayerState *stream_open(const char *filename, AVInputFormat *iformat)
is->av_sync_type = av_sync_type; is->av_sync_type = av_sync_type;
is->refresh_tid = SDL_CreateThread(refresh_thread, is); is->refresh_tid = SDL_CreateThread(refresh_thread, is);
if (!is->refresh_tid)
return -1;
is->parse_tid = SDL_CreateThread(decode_thread, is); is->parse_tid = SDL_CreateThread(decode_thread, is);
if (!is->parse_tid) { if (!is->parse_tid)
av_free(is); return -1;
return NULL; return 0;
}
return is;
} }
static void stream_cycle_channel(PlayerState *is, int codec_type) static void stream_cycle_channel(PlayerState *is, int codec_type)
@ -3057,7 +3052,11 @@ int main(int argc, char **argv)
av_init_packet(&flush_pkt); av_init_packet(&flush_pkt);
flush_pkt.data = (uint8_t *)&flush_pkt; flush_pkt.data = (uint8_t *)&flush_pkt;
player = stream_open(input_filename, file_iformat); if (stream_open(player, input_filename, file_iformat) < 0) {
fprintf(stderr, "Could not setup the player\n");
stream_close(player);
exit(1);
}
event_loop(); event_loop();

Loading…
Cancel
Save