提交 962586af 编写于 作者: Z Zhang Rui

ff_ffplay: notify msg prepared, completed, error

上级 b9d4ca54
......@@ -28,6 +28,14 @@
#include "ff_ffinc.h"
typedef struct IjkMessage {
int what;
int arg1;
int arg2;
// optional
void *data;
void (*free_data)(void *data);
int serial;
struct IjkMessage *next;
} IjkMessage;
......@@ -42,7 +50,31 @@ typedef struct IjkMessageQueue {
extern IjkMessage flush_msg;
static int ijkmsg_queue_put(IjkMessageQueue *q, IjkMessage *msg);
static void ijkmsg_init_msg(IjkMessage *msg) {
memset(msg, 0, sizeof(IjkMessage));
}
static IjkMessage *ijkmsg_obtain_msg() {
IjkMessage *msg = (IjkMessage*) malloc(sizeof(IjkMessage));
if (!msg)
return NULL;
ijkmsg_init_msg(msg);
return msg;
}
static void ijkmsg_free_msg(IjkMessage **pmsg) {
if (!pmsg || *pmsg)
return;
IjkMessage *msg = *pmsg;
if (msg->free_data && msg->data) {
msg->free_data(msg->data);
}
free(msg);
*pmsg = NULL;
}
static int ijkmsg_queue_put_private(IjkMessageQueue *q, IjkMessage *msg)
{
......
......@@ -1557,6 +1557,8 @@ static int read_thread(void *arg)
AVDictionary **opts;
int orig_nb_streams;
SDL_mutex *wait_mutex = SDL_CreateMutex();
bool prepared = false;
int last_error = 0;
memset(st_index, -1, sizeof(st_index));
is->last_video_stream = is->video_stream = -1;
......@@ -1673,7 +1675,8 @@ static int read_thread(void *arg)
if (ffp->infinite_buffer < 0 && is->realtime)
ffp->infinite_buffer = 1;
// FIXME: post prepared event
prepared = true;
ijkff_notify_msg(ffp, IJKFF_MSG_PREPARED);
for (;;) {
if (is->abort_request)
......@@ -1782,7 +1785,7 @@ static int read_thread(void *arg)
ret = AVERROR_EOF;
goto fail;
} else {
// FIXME: 0 notify complete
ijkff_notify_msg(ffp, IJKFF_MSG_COMPLETED);
}
}
eof=0;
......@@ -1793,7 +1796,7 @@ static int read_thread(void *arg)
if (ret == AVERROR_EOF || url_feof(ic->pb))
eof = 1;
if (ic->pb && ic->pb->error) {
// FIXME: 0 notify error
last_error = ic->pb->error;
break;
}
SDL_LockMutex(wait_mutex);
......@@ -1839,17 +1842,16 @@ static int read_thread(void *arg)
avformat_close_input(&is->ic);
}
if (ret != 0) {
SDL_Event event;
event.type = FF_QUIT_EVENT;
event.user.data1 = is;
SDL_PushEvent(&event);
if (!prepared || !is->abort_request) {
ffp->last_error = last_error;
ijkff_notify_msg(ffp, IJKFF_MSG_ERROR);
}
SDL_DestroyMutex(wait_mutex);
return 0;
}
static int video_refresh_thread(void *arg);
static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputFormat *iformat)
{
assert(!ffp->is);
......@@ -1895,7 +1897,7 @@ static VideoState *stream_open(FFPlayer *ffp, const char *filename, AVInputForma
is->read_tid = SDL_CreateThreadEx(&is->_read_tid, read_thread, ffp);
if (!is->read_tid) {
is->abort_request = true;
SDL_WaitThread(is->video_refresh_tid);
SDL_WaitThread(is->video_refresh_tid, NULL);
av_free(is);
return NULL;
}
......@@ -1965,6 +1967,7 @@ static int lockmgr(void **mtx, enum AVLockOp op)
****************************************************************************/
AVPacket flush_pkt;
IjkMessage flush_msg;
static bool g_ffmpeg_global_inited = false;
static void ijkff_log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
......@@ -2002,6 +2005,8 @@ void ijkff_global_init()
av_init_packet(&flush_pkt);
flush_pkt.data = (uint8_t *) &flush_pkt;
ijkmsg_init_msg(&flush_msg);
g_ffmpeg_global_inited = true;
/* test link begin */
......
......@@ -397,18 +397,12 @@ typedef struct FFPlayer {
int sar_num;
int sar_den;
int last_error;
void *msg_opaque;
void (*msg_handler)(void *opaque, int what);
} FFPlayer;
#define IJKFF_MSG_ERROR 0
#define IJKFF_MSG_PREPARED 1
#define IJKFF_MSG_COMPLETED 2
#define IJKFF_MSG_BUFFERING_START 3
#define IJKFF_MSG_BUFFERING_END 4
#define IJKFF_MSG_BUFFERING_UPDATE 5
#define IJKFF_MSG_SEEK_COMPLETED 6
#define IJKFF_SAFE_FREE(p) do {free(p); p = NULL;} while(0)
#define fftime_to_milliseconds(ts) (ts / (AV_TIME_BASE / 1000))
#define milliseconds_to_fftime(ms) (ms * (AV_TIME_BASE / 1000))
......@@ -471,8 +465,24 @@ inline static void ijkff_reset(FFPlayer *ffp)
ffp->sar_num = 0;
ffp->sar_den = 0;
ffp->last_error = 0;
ffp->msg_opaque = 0;
ffp->msg_handler = NULL;
}
#define IJKFF_MSG_ERROR 0
#define IJKFF_MSG_PREPARED 1
#define IJKFF_MSG_COMPLETED 2
#define IJKFF_MSG_VIDEO_SIZE_CHANGED 3
#define IJKFF_MSG_BUFFERING_START 4
#define IJKFF_MSG_BUFFERING_END 5
#define IJKFF_MSG_BUFFERING_UPDATE 6
#define IJKFF_MSG_SEEK_COMPLETED 7
inline static void ijkff_notify_msg(FFPlayer *ffp, int what) {
if (ffp->msg_handler)
ffp->msg_handler(ffp->msg_opaque, what);
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册