提交 cbafaf43 编写于 作者: Z Zhang Rui

ijkplayer: alloc ffp->is in stream_open()

上级 9d7bd3b4
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define IJKPLAYER__FF_FFINC_H #define IJKPLAYER__FF_FFINC_H
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/colorspace.h" #include "libavutil/colorspace.h"
#include "libavformat/avformat.h" #include "libavformat/avformat.h"
......
...@@ -403,7 +403,7 @@ static void free_subpicture(SubPicture *sp) ...@@ -403,7 +403,7 @@ static void free_subpicture(SubPicture *sp)
static void video_image_display(FFPlayer *ffp) static void video_image_display(FFPlayer *ffp)
{ {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
VideoPicture *vp; VideoPicture *vp;
SubPicture *sp; SubPicture *sp;
AVPicture pict; AVPicture pict;
...@@ -457,9 +457,8 @@ static void video_image_display(FFPlayer *ffp) ...@@ -457,9 +457,8 @@ static void video_image_display(FFPlayer *ffp)
// MERGE: compute_mod // MERGE: compute_mod
// MERGE: video_audio_display // MERGE: video_audio_display
static void stream_close(FFPlayer *ffp) static void stream_close(VideoState *is)
{ {
VideoState *is = &ffp->is;
VideoPicture *vp; VideoPicture *vp;
int i; int i;
/* XXX: use a special url_shutdown call to abort parse cleanly */ /* XXX: use a special url_shutdown call to abort parse cleanly */
...@@ -496,7 +495,7 @@ static void stream_close(FFPlayer *ffp) ...@@ -496,7 +495,7 @@ static void stream_close(FFPlayer *ffp)
static int video_open(FFPlayer *ffp, int force_set_video_mode, VideoPicture *vp) static int video_open(FFPlayer *ffp, int force_set_video_mode, VideoPicture *vp)
{ {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL; int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
int w, h; int w, h;
...@@ -752,7 +751,7 @@ static void update_video_pts(VideoState *is, double pts, int64_t pos, int serial ...@@ -752,7 +751,7 @@ static void update_video_pts(VideoState *is, double pts, int64_t pos, int serial
static void video_refresh(FFPlayer *opaque, double *remaining_time) static void video_refresh(FFPlayer *opaque, double *remaining_time)
{ {
FFPlayer *ffp = opaque; FFPlayer *ffp = opaque;
VideoState *is = &ffp->is; VideoState *is = ffp->is;
VideoPicture *vp; VideoPicture *vp;
double time; double time;
...@@ -925,7 +924,7 @@ display: ...@@ -925,7 +924,7 @@ display:
potential locking problems */ potential locking problems */
static void alloc_picture(FFPlayer *ffp) static void alloc_picture(FFPlayer *ffp)
{ {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
VideoPicture *vp; VideoPicture *vp;
vp = &is->pictq[is->pictq_windex]; vp = &is->pictq[is->pictq_windex];
...@@ -982,7 +981,7 @@ static void duplicate_right_border_pixels(SDL_VoutOverlay *bmp) { ...@@ -982,7 +981,7 @@ static void duplicate_right_border_pixels(SDL_VoutOverlay *bmp) {
static int queue_picture(FFPlayer *ffp, AVFrame *src_frame, double pts, int64_t pos, int serial) static int queue_picture(FFPlayer *ffp, AVFrame *src_frame, double pts, int64_t pos, int serial)
{ {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
VideoPicture *vp; VideoPicture *vp;
#if defined(DEBUG_SYNC) && 0 #if defined(DEBUG_SYNC) && 0
...@@ -1101,7 +1100,7 @@ static int queue_picture(FFPlayer *ffp, AVFrame *src_frame, double pts, int64_t ...@@ -1101,7 +1100,7 @@ static int queue_picture(FFPlayer *ffp, AVFrame *src_frame, double pts, int64_t
static int get_video_frame(FFPlayer *ffp, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial) static int get_video_frame(FFPlayer *ffp, AVFrame *frame, int64_t *pts, AVPacket *pkt, int *serial)
{ {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
int got_picture; int got_picture;
if (packet_queue_get(&is->videoq, pkt, 1, serial) < 0) if (packet_queue_get(&is->videoq, pkt, 1, serial) < 0)
...@@ -1267,7 +1266,7 @@ static int video_thread(void *arg) ...@@ -1267,7 +1266,7 @@ static int video_thread(void *arg)
{ {
AVPacket pkt = { 0 }; AVPacket pkt = { 0 };
FFPlayer *ffp = arg; FFPlayer *ffp = arg;
VideoState *is = &ffp->is; VideoState *is = ffp->is;
AVFrame *frame = avcodec_alloc_frame(); AVFrame *frame = avcodec_alloc_frame();
int64_t pts_int = AV_NOPTS_VALUE; int64_t pts_int = AV_NOPTS_VALUE;
#if CONFIG_AVFILTER #if CONFIG_AVFILTER
...@@ -1711,7 +1710,7 @@ static int audio_decode_frame(VideoState *is) ...@@ -1711,7 +1710,7 @@ static int audio_decode_frame(VideoState *is)
static void sdl_audio_callback(void *opaque, Uint8 *stream, int len) static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
{ {
FFPlayer *ffp = opaque; FFPlayer *ffp = opaque;
VideoState *is = &ffp->is; VideoState *is = ffp->is;
int audio_size, len1; int audio_size, len1;
int bytes_per_sec; int bytes_per_sec;
int frame_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, 1, is->audio_tgt.fmt, 1); int frame_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, 1, is->audio_tgt.fmt, 1);
...@@ -1806,7 +1805,7 @@ static int audio_open(FFPlayer *opaque, int64_t wanted_channel_layout, int wante ...@@ -1806,7 +1805,7 @@ static int audio_open(FFPlayer *opaque, int64_t wanted_channel_layout, int wante
/* open a given stream. Return 0 if OK */ /* open a given stream. Return 0 if OK */
static int stream_component_open(FFPlayer *ffp, int stream_index) static int stream_component_open(FFPlayer *ffp, int stream_index)
{ {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
AVFormatContext *ic = is->ic; AVFormatContext *ic = is->ic;
AVCodecContext *avctx; AVCodecContext *avctx;
AVCodec *codec; AVCodec *codec;
...@@ -2023,7 +2022,7 @@ static int is_realtime(AVFormatContext *s) ...@@ -2023,7 +2022,7 @@ static int is_realtime(AVFormatContext *s)
static int read_thread(void *arg) static int read_thread(void *arg)
{ {
FFPlayer *ffp = arg; FFPlayer *ffp = arg;
VideoState *is = &ffp->is; VideoState *is = ffp->is;
AVFormatContext *ic = NULL; AVFormatContext *ic = NULL;
int err, i, ret; int err, i, ret;
int st_index[AVMEDIA_TYPE_NB]; int st_index[AVMEDIA_TYPE_NB];
...@@ -2305,8 +2304,10 @@ static int read_thread(void *arg) ...@@ -2305,8 +2304,10 @@ static int read_thread(void *arg)
static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputFormat *iformat) static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputFormat *iformat)
{ {
VideoState *is = &ffp->is; assert(!ffp->is);
VideoState *is = av_mallocz(sizeof(VideoState));
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;
...@@ -2361,7 +2362,7 @@ static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputForma ...@@ -2361,7 +2362,7 @@ static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputForma
// MERGE: show_usage // MERGE: show_usage
// MERGE: show_help_default // MERGE: show_help_default
static void video_refresh_thread(FFPlayer *ffp) { static void video_refresh_thread(FFPlayer *ffp) {
VideoState *is = &ffp->is; VideoState *is = ffp->is;
double remaining_time = 0.0; double remaining_time = 0.0;
while (is->abort_request) { while (is->abort_request) {
if (remaining_time > 0.0) if (remaining_time > 0.0)
...@@ -2440,7 +2441,6 @@ void ijkff_global_init() ...@@ -2440,7 +2441,6 @@ void ijkff_global_init()
/* test link begin */ /* test link begin */
FFPlayer *ffp = malloc(sizeof(FFPlayer)); FFPlayer *ffp = malloc(sizeof(FFPlayer));
stream_open(ffp, NULL, NULL); stream_open(ffp, NULL, NULL);
stream_close(ffp);
video_refresh_thread(ffp); video_refresh_thread(ffp);
alloc_picture(NULL); alloc_picture(NULL);
/* test link end */ /* test link end */
...@@ -2451,11 +2451,6 @@ void ijkff_global_uninit() ...@@ -2451,11 +2451,6 @@ void ijkff_global_uninit()
if (!g_ffmpeg_global_inited) if (!g_ffmpeg_global_inited)
return; return;
/* test link begin */
FFPlayer *ffp = NULL;
stream_close(ffp);
/* test link end */
av_lockmgr_register(NULL); av_lockmgr_register(NULL);
#if CONFIG_AVFILTER #if CONFIG_AVFILTER
...@@ -2474,6 +2469,12 @@ void ijkff_destroy_ffplayer(FFPlayer **pffp) ...@@ -2474,6 +2469,12 @@ void ijkff_destroy_ffplayer(FFPlayer **pffp)
return; return;
FFPlayer *ffp = *pffp; FFPlayer *ffp = *pffp;
if (ffp && ffp->is) {
av_log(NULL, AV_LOG_WARNING, "ijkff_destroy_ffplayer: force stream_close()");
stream_close(ffp->is);
ffp->is = NULL;
}
ijkff_reset(ffp); ijkff_reset(ffp);
free(ffp); free(ffp);
*pffp = NULL; *pffp = NULL;
...@@ -2482,20 +2483,26 @@ void ijkff_destroy_ffplayer(FFPlayer **pffp) ...@@ -2482,20 +2483,26 @@ void ijkff_destroy_ffplayer(FFPlayer **pffp)
int ijkff_stream_open_l(FFPlayer *ffp, const char *file_name) int ijkff_stream_open_l(FFPlayer *ffp, const char *file_name)
{ {
assert(ffp); assert(ffp);
assert(!ffp->is);
assert(file_name); assert(file_name);
assert(!ffp->is.read_tid);
VideoState *is = stream_open(ffp, file_name, NULL); VideoState *is = stream_open(ffp, file_name, NULL);
if (!is) if (!is) {
av_log(NULL, AV_LOG_WARNING, "ijkff_stream_open_l: stream_open failed OOM");
return EIJK_OUT_OF_MEMORY; return EIJK_OUT_OF_MEMORY;
}
ffp->is = is;
return 0; return 0;
} }
int ijkff_start_l(FFPlayer *ffp) int ijkff_start_l(FFPlayer *ffp)
{ {
assert(ffp); assert(ffp);
VideoState *is = &ffp->is; VideoState *is = ffp->is;
if (!is)
return EIJK_NULL_IS_PTR;
if (is->paused) { if (is->paused) {
is->frame_timer += av_gettime() / 1000000.0 + is->video_current_pts_drift - is->video_current_pts; is->frame_timer += av_gettime() / 1000000.0 + is->video_current_pts_drift - is->video_current_pts;
if (is->read_pause_return != AVERROR(ENOSYS)) { if (is->read_pause_return != AVERROR(ENOSYS)) {
...@@ -2511,7 +2518,10 @@ int ijkff_start_l(FFPlayer *ffp) ...@@ -2511,7 +2518,10 @@ int ijkff_start_l(FFPlayer *ffp)
int ijkff_pause_l(FFPlayer *ffp) int ijkff_pause_l(FFPlayer *ffp)
{ {
assert(ffp); assert(ffp);
VideoState *is = &ffp->is; VideoState *is = ffp->is;
if (!is)
return EIJK_NULL_IS_PTR;
update_external_clock_pts(is, get_external_clock(is)); update_external_clock_pts(is, get_external_clock(is));
is->paused = 1; is->paused = 1;
return 0; return 0;
...@@ -2520,7 +2530,10 @@ int ijkff_pause_l(FFPlayer *ffp) ...@@ -2520,7 +2530,10 @@ int ijkff_pause_l(FFPlayer *ffp)
int ijkff_stop_l(FFPlayer *ffp) int ijkff_stop_l(FFPlayer *ffp)
{ {
assert(ffp); assert(ffp);
VideoState *is = &ffp->is; VideoState *is = ffp->is;
if (!is)
return EIJK_NULL_IS_PTR;
is->abort_request = 1; is->abort_request = 1;
return 0; return 0;
} }
...@@ -2528,7 +2541,11 @@ int ijkff_stop_l(FFPlayer *ffp) ...@@ -2528,7 +2541,11 @@ int ijkff_stop_l(FFPlayer *ffp)
int ijkff_wait_stop(FFPlayer *ffp) int ijkff_wait_stop(FFPlayer *ffp)
{ {
assert(ffp); assert(ffp);
VideoState *is = &ffp->is; VideoState *is = ffp->is;
if (!is)
return EIJK_NULL_IS_PTR;
stream_close(is); stream_close(is);
ffp->is = NULL;
return 0; return 0;
} }
...@@ -312,7 +312,7 @@ static SDL_Surface *screen; ...@@ -312,7 +312,7 @@ static SDL_Surface *screen;
/* ffplayer */ /* ffplayer */
typedef struct FFPlayer { typedef struct FFPlayer {
/* ffplay context */ /* ffplay context */
VideoState is; VideoState *is;
/* format/codec options */ /* format/codec options */
AVDictionary *format_opts; AVDictionary *format_opts;
...@@ -409,7 +409,7 @@ typedef struct FFPlayer { ...@@ -409,7 +409,7 @@ typedef struct FFPlayer {
inline static void ijkff_reset(FFPlayer *ffp) inline static void ijkff_reset(FFPlayer *ffp)
{ {
/* FIXME: reset ffp->is */ /* ffp->is closed in stream_close() */
/* format/codec options */ /* format/codec options */
av_dict_free(&ffp->format_opts); av_dict_free(&ffp->format_opts);
......
...@@ -27,5 +27,6 @@ ...@@ -27,5 +27,6 @@
#define EIJK_FAILED -1 #define EIJK_FAILED -1
#define EIJK_OUT_OF_MEMORY -2 #define EIJK_OUT_OF_MEMORY -2
#define EIJK_INVALID_STATE -3 #define EIJK_INVALID_STATE -3
#define EIJK_NULL_IS_PTR -4
#endif #endif
...@@ -176,7 +176,7 @@ static int ijkmp_prepare_async_l(IjkMediaPlayer *mp) ...@@ -176,7 +176,7 @@ static int ijkmp_prepare_async_l(IjkMediaPlayer *mp)
assert(mp->data_source); assert(mp->data_source);
mp->mp_state = MP_STATE_ASYNC_PREPARING; mp->mp_state = MP_STATE_ASYNC_PREPARING;
int retval = ijkff_stream_open(mp->ffplayer, mp->data_source); int retval = ijkff_stream_open_l(mp->ffplayer, mp->data_source);
if (retval < 0) { if (retval < 0) {
mp->mp_state = MP_STATE_ERROR; mp->mp_state = MP_STATE_ERROR;
return retval; return retval;
...@@ -299,7 +299,7 @@ int ijkmp_stop(IjkMediaPlayer *mp) ...@@ -299,7 +299,7 @@ int ijkmp_stop(IjkMediaPlayer *mp)
pthread_mutex_unlock(&mp->mutex); pthread_mutex_unlock(&mp->mutex);
if (retval == 0) if (retval == 0)
ijkff_wait_stop(mp); ijkff_wait_stop(mp->ffplayer);
return retval; return retval;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册