提交 0ce7757b 编写于 作者: Z Zhang Rui

jni: ffplay: introduce more code

上级 3c2b2988
......@@ -26,9 +26,12 @@ LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
LOCAL_C_INCLUDES += $(MY_APP_JNI_ROOT)
LOCAL_SRC_FILES += ffplay_cmdutils.c
LOCAL_SRC_FILES += ffplay_pkt_queue.c
LOCAL_SRC_FILES += ffplay_read_thread.c
LOCAL_SRC_FILES += ffplay_subtitle_thread.c
LOCAL_SRC_FILES += ffplay_video_thread.c
LOCAL_SRC_FILES += ffplayer.c
LOCAL_SRC_FILES += thread_demux.c
LOCAL_SRC_FILES += ijkplayer.c
LOCAL_SRC_FILES += ijkplayer_jni.c
......
/*****************************************************************************
* ffplay_cmdutils.c
*****************************************************************************
*
* copyright (c) 2001 Fabrice Bellard
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "ffplay_cmdutils.h"
#include <libavutil/opt.h>
/* cmdutils.c 942 */
void print_error(const char *filename, int err)
{
char errbuf[128];
const char *errbuf_ptr = errbuf;
if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
errbuf_ptr = strerror(AVUNERROR(err));
av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
}
/* cmdutils.c 942 */
/* cmdutils.c 1731 */
static int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
{
int ret = avformat_match_stream_specifier(s, st, spec);
if (ret < 0)
av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
return ret;
}
/* cmdutils.c 1731 */
/* cmdutils.c 1739 */
AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
AVFormatContext *s, AVStream *st, AVCodec *codec)
{
AVDictionary *ret = NULL;
AVDictionaryEntry *t = NULL;
int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
: AV_OPT_FLAG_DECODING_PARAM;
char prefix = 0;
const AVClass *cc = avcodec_get_class();
if (!codec)
codec = s->oformat ? avcodec_find_encoder(codec_id)
: avcodec_find_decoder(codec_id);
switch (st->codec->codec_type) {
case AVMEDIA_TYPE_VIDEO:
prefix = 'v';
flags |= AV_OPT_FLAG_VIDEO_PARAM;
break;
case AVMEDIA_TYPE_AUDIO:
prefix = 'a';
flags |= AV_OPT_FLAG_AUDIO_PARAM;
break;
case AVMEDIA_TYPE_SUBTITLE:
prefix = 's';
flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
break;
default:
break;
}
while ((t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX))) {
char *p = strchr(t->key, ':');
/* check stream specification in opt name */
if (p)
switch (check_stream_specifier(s, st, p + 1)) {
case 1: *p = 0; break;
case 0: continue;
default: return NULL;
}
if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
(codec && codec->priv_class &&
av_opt_find(&codec->priv_class, t->key, NULL, flags,
AV_OPT_SEARCH_FAKE_OBJ)))
av_dict_set(&ret, t->key, t->value, 0);
else if (t->key[0] == prefix &&
av_opt_find(&cc, t->key + 1, NULL, flags,
AV_OPT_SEARCH_FAKE_OBJ))
av_dict_set(&ret, t->key + 1, t->value, 0);
if (p)
*p = ':';
}
return ret;
}
/* cmdutils.c 1739 */
/* cmdutils.c 1795 */
AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
AVDictionary *codec_opts)
{
int i;
AVDictionary **opts;
if (!s->nb_streams)
return NULL;
opts = av_mallocz(s->nb_streams * sizeof(*opts));
if (!opts) {
av_log(NULL, AV_LOG_ERROR,
"Could not alloc memory for stream options.\n");
return NULL;
}
for (i = 0; i < s->nb_streams; i++)
opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codec->codec_id,
s, s->streams[i], NULL);
return opts;
}
/* cmdutils.c 1795 */
/*****************************************************************************
* ffplay_cmdutils.h
*****************************************************************************
*
* copyright (c) 2001 Fabrice Bellard
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef IJKPLAYER__FFPLAY_CMDUTILS_H
#define IJKPLAYER__FFPLAY_CMDUTILS_H
#include <libavformat/avformat.h>
void print_error(const char *filename, int err);
AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts);
AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
AVFormatContext *s, AVStream *st, AVCodec *codec);
#endif
......@@ -26,8 +26,12 @@
#define IJKPLAYER__FFPLAY_DEF_H
#include <inttypes.h>
#include "libavformat/avformat.h"
#include "libavcodec/avfft.h"
#include "libswresample/swresample.h"
#include "ijksdl/ijksdl.h"
#include "ffplay_pkt_queue.h"
#include "ffplay_cmdutils.h"
#ifdef CONFIG_AVFILTER
#undef CONFIG_AVFILTER
......@@ -44,10 +48,10 @@
/* no AV sync correction is done if below the AV sync threshold */
// #define AV_SYNC_THRESHOLD 0.01
/* no AV correction is done if too big error */
// #define AV_NOSYNC_THRESHOLD 10.0
#define AV_NOSYNC_THRESHOLD 10.0
/* maximum audio speed change to get correct sync */
// #define SAMPLE_CORRECTION_PERCENT_MAX 10
#define SAMPLE_CORRECTION_PERCENT_MAX 10
/* external clock speed adjustment constants for realtime sources based on buffer fullness */
// #define EXTERNAL_CLOCK_SPEED_MIN 0.900
......@@ -55,7 +59,7 @@
// #define EXTERNAL_CLOCK_SPEED_STEP 0.001
/* we use about AUDIO_DIFF_AVG_NB A-V differences to make the average */
// #define AUDIO_DIFF_AVG_NB 20
#define AUDIO_DIFF_AVG_NB 20
/* polls for possible required screen refresh at least this often, should be less than 1/fps */
// #define REFRESH_RATE 0.01
......@@ -167,9 +171,9 @@ typedef struct VideoState {
int16_t sample_array[SAMPLE_ARRAY_SIZE];
int sample_array_index;
int last_i_start;
// RDFTContext *rdft;
RDFTContext *rdft;
int rdft_bits;
// FFTSample *rdft_data;
FFTSample *rdft_data;
int xpos;
double last_vis_time;
......@@ -223,13 +227,8 @@ typedef struct VideoState {
SDL_cond *continue_read_thread;
} VideoState;
/* PLACEHOLD: options variables has been moved to ffplayer.h */
/* current context */
// static int is_full_screen;
// static int64_t audio_callback_time;
// static AVPacket flush_pkt;
/* PLACEHOLD: options has been moved to ffplayer.h */
/* PLACEHOLD: current context has been moved to ffplayer.h */
/* PLACEHOLD: flush_pkt has been moved to pkt_queue.c */
#define FF_ALLOC_EVENT (SDL_USEREVENT)
......@@ -237,6 +236,9 @@ typedef struct VideoState {
// static SDL_Surface *screen;
void print_error(const char *filename, int err);
/* extra forward declaration */
int ijkff_read_thread(void *arg);
int ijkff_video_thread(void *arg);
int ijkff_subtitle_thread(void *arg);
#endif
......@@ -25,7 +25,7 @@
#ifndef IJKPLAYER__FFPLAY_PKT_QUEUE_H
#define IJKPLAYER__FFPLAY_PKT_QUEUE_H
#include <ijksdl/ijksdl_thread.h>
#include <ijksdl/ijksdl_mutex.h>
#include <libavformat/avformat.h>
typedef struct MyAVPacketList {
......
/*****************************************************************************
* ffplay_subtitle_thread.c
*****************************************************************************
*
* copyright (c) 2001 Fabrice Bellard
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
int ijkff_subtitle_thread(void *arg)
{
// FIXME: implement
return 0;
}
/*****************************************************************************
* ffplay_video_thread.c
*****************************************************************************
*
* copyright (c) 2001 Fabrice Bellard
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
int ijkff_video_thread(void *arg)
{
// FIXME: implement
return 0;
}
......@@ -58,15 +58,15 @@ typedef struct FFPlayer {
// int av_sync_type = AV_SYNC_AUDIO_MASTER;
int64_t start_time;
int64_t duration;
// int workaround_bugs = 1;
// int fast = 0;
int workaround_bugs;
int fast;
int genpts;
// int lowres = 0;
// int idct = FF_IDCT_AUTO;
// enum AVDiscard skip_frame = AVDISCARD_DEFAULT;
// enum AVDiscard skip_idct = AVDISCARD_DEFAULT;
// enum AVDiscard skip_loop_filter = AVDISCARD_DEFAULT;
// int error_concealment = 3;
int lowres;
int idct;
enum AVDiscard skip_frame;
enum AVDiscard skip_idct;
enum AVDiscard skip_loop_filter;
int error_concealment;
// int decoder_reorder_pts = -1;
int autoexit;
// int exit_on_keydown;
......@@ -75,9 +75,9 @@ typedef struct FFPlayer {
// int framedrop = -1;
int infinite_buffer;
enum ShowMode show_mode;
// const char *audio_codec_name;
// const char *subtitle_codec_name;
// const char *video_codec_name;
char *audio_codec_name;
char *subtitle_codec_name;
char *video_codec_name;
// double rdftspeed = 0.02;
// int64_t cursor_last_shown;
// int cursor_hidden = 0;
......@@ -85,10 +85,16 @@ typedef struct FFPlayer {
// char *vfilters = NULL;
#endif
/* current context */
//static int is_full_screen;
int64_t audio_callback_time;
/* callback */
int (*decode_interrupt_cb)(void *ctx);
} FFPlayer;
#define IJKFF_SAFE_FREE(p) do {free(p); p = NULL;} while(0)
inline static void ijkff_reset(FFPlayer *ffp)
{
/* FIXME: ffplay context reset */
......@@ -98,8 +104,7 @@ inline static void ijkff_reset(FFPlayer *ffp)
av_dict_free(&ffp->codec_opts);
/* ffplay options specified by the user */
free(ffp->input_filename);
ffp->input_filename = NULL;
IJKFF_SAFE_FREE(ffp->input_filename);
ffp->audio_disable = 0;
ffp->video_disable = 0;
ffp->subtitle_disable = 0;
......@@ -110,11 +115,25 @@ inline static void ijkff_reset(FFPlayer *ffp)
ffp->show_status = 1;
ffp->start_time = AV_NOPTS_VALUE;
ffp->duration = AV_NOPTS_VALUE;
ffp->workaround_bugs = 1;
ffp->fast = 0;
ffp->genpts = 0;
ffp->lowres = 0;
ffp->idct = FF_IDCT_AUTO;
ffp->skip_frame = AVDISCARD_DEFAULT;
ffp->skip_idct = AVDISCARD_DEFAULT;
ffp->skip_loop_filter = AVDISCARD_DEFAULT;
ffp->error_concealment = 3;
ffp->autoexit = 0;
ffp->loop = 1;
ffp->infinite_buffer = -1;
ffp->show_mode = SHOW_MODE_NONE;
IJKFF_SAFE_FREE(ffp->audio_codec_name);
IJKFF_SAFE_FREE(ffp->subtitle_codec_name);
IJKFF_SAFE_FREE(ffp->video_codec_name);
/* current context */
ffp->audio_callback_time = 0;
/* callback */
ffp->decode_interrupt_cb = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册